1993-08-02 21:48:44 +04:00
|
|
|
.\" -*- nroff -*-
|
|
|
|
.\"
|
2000-05-27 06:23:19 +04:00
|
|
|
.\" $NetBSD: bpf.4,v 1.12 2000/05/27 02:23:19 enami Exp $
|
1994-11-30 19:22:03 +03:00
|
|
|
.\"
|
1996-12-04 07:46:04 +03:00
|
|
|
.\" Copyright (c) 1990, 1991, 1992, 1993, 1994
|
|
|
|
.\" The Regents of the University of California. All rights reserved.
|
1993-04-10 00:24:12 +04:00
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that: (1) source code distributions
|
|
|
|
.\" retain the above copyright notice and this paragraph in its entirety, (2)
|
|
|
|
.\" distributions including binary code include the above copyright notice and
|
|
|
|
.\" this paragraph in its entirety in the documentation or other materials
|
|
|
|
.\" provided with the distribution, and (3) all advertising materials mentioning
|
|
|
|
.\" features or use of this software display the following acknowledgement:
|
|
|
|
.\" ``This product includes software developed by the University of California,
|
|
|
|
.\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
|
|
|
.\" the University nor the names of its contributors may be used to endorse
|
|
|
|
.\" or promote products derived from this software without specific prior
|
|
|
|
.\" written permission.
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
|
|
|
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
|
|
|
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
.\"
|
|
|
|
.\" This document is derived in part from the enet man page (enet.4)
|
|
|
|
.\" distributed with 4.3BSD Unix.
|
|
|
|
.\"
|
2000-05-27 06:23:19 +04:00
|
|
|
.Dd June 28, 1994
|
|
|
|
.Dt BPF 4
|
|
|
|
.Os
|
1999-12-16 01:07:30 +03:00
|
|
|
.Sh NAME
|
|
|
|
.Nm bpf
|
|
|
|
.Nd Berkeley Packet Filter raw network interface
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Cd "pseudo-device bpfilter 16"
|
|
|
|
.Sh DESCRIPTION
|
1993-04-10 00:24:12 +04:00
|
|
|
The Berkeley Packet Filter
|
1996-12-04 07:46:04 +03:00
|
|
|
provides a raw interface to data link layers in a protocol
|
1993-04-10 00:24:12 +04:00
|
|
|
independent fashion.
|
|
|
|
All packets on the network, even those destined for other hosts,
|
|
|
|
are accessible through this mechanism.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
The packet filter appears as a character special device,
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pa /dev/bpf0 ,
|
|
|
|
.Pa /dev/bpf1 ,
|
1993-04-10 00:24:12 +04:00
|
|
|
etc.
|
1996-12-04 07:46:04 +03:00
|
|
|
After opening the device, the file descriptor must be bound to a
|
2000-05-27 06:23:19 +04:00
|
|
|
specific network interface with the
|
|
|
|
.Dv BIOSETIF
|
|
|
|
ioctl.
|
1993-04-10 00:24:12 +04:00
|
|
|
A given interface can be shared be multiple listeners, and the filter
|
|
|
|
underlying each descriptor will see an identical packet stream.
|
1996-12-04 07:46:04 +03:00
|
|
|
The total number of open
|
1993-04-10 00:24:12 +04:00
|
|
|
files is limited to the value given in the kernel configuration; the
|
|
|
|
example given in the SYNOPSIS above sets the limit to 16.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
1996-12-04 07:46:04 +03:00
|
|
|
A separate device file is required for each minor device.
|
|
|
|
If a file is in use, the open will fail and
|
2000-05-27 06:23:19 +04:00
|
|
|
.Va errno
|
1993-04-10 00:24:12 +04:00
|
|
|
will be set to EBUSY.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
Associated with each open instance of a
|
2000-05-27 06:23:19 +04:00
|
|
|
.Nm
|
1993-04-10 00:24:12 +04:00
|
|
|
file is a user-settable packet filter.
|
1996-12-04 07:46:04 +03:00
|
|
|
Whenever a packet is received by an interface,
|
1993-04-10 00:24:12 +04:00
|
|
|
all file descriptors listening on that interface apply their filter.
|
|
|
|
Each descriptor that accepts the packet receives its own copy.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
Reads from these files return the next group of packets
|
|
|
|
that have matched the filter.
|
|
|
|
To improve performance, the buffer passed to read must be
|
1996-12-04 07:46:04 +03:00
|
|
|
the same size as the buffers used internally by
|
2000-05-27 06:23:19 +04:00
|
|
|
.Nm "" .
|
|
|
|
This size is returned by the
|
|
|
|
.Dv BIOCGBLEN
|
|
|
|
ioctl (see below), and under
|
|
|
|
BSD, can be set with
|
|
|
|
.Dv BIOCSBLEN .
|
1993-04-10 00:24:12 +04:00
|
|
|
Note that an individual packet larger than this size is necessarily
|
|
|
|
truncated.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
The packet filter will support any link level protocol that has fixed length
|
|
|
|
headers. Currently, only Ethernet, SLIP and PPP drivers have been
|
|
|
|
modified to interact with
|
2000-05-27 06:23:19 +04:00
|
|
|
.Nm "" .
|
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
Since packet data is in network byte order, applications should use the
|
2000-05-27 06:23:19 +04:00
|
|
|
.Xr byteorder 3
|
1993-04-10 00:24:12 +04:00
|
|
|
macros to extract multi-byte values.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
1996-12-04 07:46:04 +03:00
|
|
|
A packet can be sent out on the network by writing to a
|
2000-05-27 06:23:19 +04:00
|
|
|
.Nm
|
1993-04-10 00:24:12 +04:00
|
|
|
file descriptor. The writes are unbuffered, meaning only one
|
|
|
|
packet can be processed per write.
|
|
|
|
Currently, only writes to Ethernets and SLIP links are supported.
|
1999-12-16 01:07:30 +03:00
|
|
|
.Sh IOCTLS
|
1996-12-04 07:46:04 +03:00
|
|
|
The
|
2000-05-27 06:23:19 +04:00
|
|
|
.Xr ioctl 2
|
1993-04-10 00:24:12 +04:00
|
|
|
command codes below are defined in <net/bpf.h>. All commands require
|
|
|
|
these includes:
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
.Fd #include <sys/types.h>
|
|
|
|
.Fd #include <sys/time.h>
|
|
|
|
.Fd #include <sys/ioctl.h>
|
|
|
|
.Fd #include <net/bpf.h>
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Additionally, BIOCGETIF and BIOCSETIF require
|
|
|
|
.Pa <net/if.h> .
|
|
|
|
.Pp
|
1996-12-04 07:46:04 +03:00
|
|
|
The (third) argument to the
|
2000-05-27 06:23:19 +04:00
|
|
|
.Xr ioctl 2
|
1993-04-10 00:24:12 +04:00
|
|
|
should be a pointer to the type indicated.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bl -tag -width -offset indent
|
|
|
|
.It Dv "BIOCGBLEN (u_int)"
|
1993-04-10 00:24:12 +04:00
|
|
|
Returns the required buffer length for reads on
|
2000-05-27 06:23:19 +04:00
|
|
|
.Nm
|
1993-04-10 00:24:12 +04:00
|
|
|
files.
|
2000-05-27 06:23:19 +04:00
|
|
|
.It Dv "BIOCSBLEN (u_int)"
|
1996-12-04 07:46:04 +03:00
|
|
|
Sets the buffer length for reads on
|
2000-05-27 06:23:19 +04:00
|
|
|
.Nm
|
1993-04-10 00:24:12 +04:00
|
|
|
files. The buffer must be set before the file is attached to an interface
|
2000-05-27 06:23:19 +04:00
|
|
|
with
|
|
|
|
.Dv BIOCSETIF .
|
1996-12-04 07:46:04 +03:00
|
|
|
If the requested buffer size cannot be accommodated, the closest
|
1993-04-10 00:24:12 +04:00
|
|
|
allowable size will be set and returned in the argument.
|
|
|
|
A read call will result in EIO if it is passed a buffer that is not this size.
|
2000-05-27 06:23:19 +04:00
|
|
|
.It Dv BIOCGDLT (u_int)
|
1996-12-04 07:46:04 +03:00
|
|
|
Returns the type of the data link layer underlying the attached interface.
|
1993-04-10 00:24:12 +04:00
|
|
|
EINVAL is returned if no interface has been specified.
|
2000-05-27 06:23:19 +04:00
|
|
|
The device types, prefixed with
|
|
|
|
.Dq DLT_ ,
|
|
|
|
are defined in <net/bpf.h>.
|
|
|
|
.It Dv BIOCPROMISC
|
1993-04-10 00:24:12 +04:00
|
|
|
Forces the interface into promiscuous mode.
|
|
|
|
All packets, not just those destined for the local host, are processed.
|
|
|
|
Since more than one file can be listening on a given interface,
|
|
|
|
a listener that opened its interface non-promiscuously may receive
|
1996-12-04 07:46:04 +03:00
|
|
|
packets promiscuously. This problem can be remedied with an
|
1993-04-10 00:24:12 +04:00
|
|
|
appropriate filter.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
1996-12-04 07:46:04 +03:00
|
|
|
The interface remains in promiscuous mode until all files listening
|
1993-04-10 00:24:12 +04:00
|
|
|
promiscuously are closed.
|
2000-05-27 06:23:19 +04:00
|
|
|
.It Dv BIOCFLUSH
|
1993-04-10 00:24:12 +04:00
|
|
|
Flushes the buffer of incoming packets,
|
2000-05-27 06:23:19 +04:00
|
|
|
and resets the statistics that are returned by
|
|
|
|
.Dv BIOCGSTATS .
|
|
|
|
.It Dv BIOCGETIF (struct ifreq)
|
1993-04-10 00:24:12 +04:00
|
|
|
Returns the name of the hardware interface that the file is listening on.
|
1997-03-22 05:59:11 +03:00
|
|
|
The name is returned in the ifr_name field of
|
2000-05-27 06:23:19 +04:00
|
|
|
.Fa ifr .
|
1993-04-10 00:24:12 +04:00
|
|
|
All other fields are undefined.
|
2000-05-27 06:23:19 +04:00
|
|
|
.It Dv BIOCSETIF (struct ifreq)
|
1993-04-10 00:24:12 +04:00
|
|
|
Sets the hardware interface associate with the file. This
|
|
|
|
command must be performed before any packets can be read.
|
|
|
|
The device is indicated by name using the
|
2000-05-27 06:23:19 +04:00
|
|
|
.Dv ifr_name
|
1996-12-04 07:46:04 +03:00
|
|
|
field of the
|
2000-05-27 06:23:19 +04:00
|
|
|
.Fa ifreq .
|
|
|
|
Additionally, performs the actions of
|
|
|
|
.Dv BIOCFLUSH .
|
|
|
|
.It Dv BIOCSRTIMEOUT, BIOCGRTIMEOUT (struct timeval)
|
1993-04-10 00:24:12 +04:00
|
|
|
Set or get the read timeout parameter.
|
1996-12-04 07:46:04 +03:00
|
|
|
The
|
2000-05-27 06:23:19 +04:00
|
|
|
.Fa timeval
|
1993-04-10 00:24:12 +04:00
|
|
|
specifies the length of time to wait before timing
|
|
|
|
out on a read request.
|
|
|
|
This parameter is initialized to zero by
|
2000-05-27 06:23:19 +04:00
|
|
|
.Xr open 2 ,
|
1993-04-10 00:24:12 +04:00
|
|
|
indicating no timeout.
|
2000-05-27 06:23:19 +04:00
|
|
|
.It Dv BIOCGSTATS (struct bpf_stat)
|
1993-04-10 00:24:12 +04:00
|
|
|
Returns the following structure of packet statistics:
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bd -literal -offset indent
|
1993-04-10 00:24:12 +04:00
|
|
|
struct bpf_stat {
|
|
|
|
u_int bs_recv;
|
|
|
|
u_int bs_drop;
|
|
|
|
};
|
2000-05-27 06:23:19 +04:00
|
|
|
.Ed
|
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
The fields are:
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bl -tag -width bs_recv -offset indent
|
|
|
|
.It Va bs_recv
|
1993-04-10 00:24:12 +04:00
|
|
|
the number of packets received by the descriptor since opened or reset
|
|
|
|
(including any buffered since the last read call);
|
|
|
|
and
|
2000-05-27 06:23:19 +04:00
|
|
|
.It Va bs_drop
|
1996-12-04 07:46:04 +03:00
|
|
|
the number of packets which were accepted by the filter but dropped by the
|
1993-04-10 00:24:12 +04:00
|
|
|
kernel because of buffer overflows
|
|
|
|
(i.e., the application's reads aren't keeping up with the packet traffic).
|
2000-05-27 06:23:19 +04:00
|
|
|
.El
|
|
|
|
.It Dv BIOCIMMEDIATE (u_int)
|
|
|
|
Enable or disable
|
|
|
|
.Dq immediate mode ,
|
|
|
|
based on the truth value of the argument.
|
1996-12-04 07:46:04 +03:00
|
|
|
When immediate mode is enabled, reads return immediately upon packet
|
1993-04-10 00:24:12 +04:00
|
|
|
reception. Otherwise, a read will block until either the kernel buffer
|
|
|
|
becomes full or a timeout occurs.
|
|
|
|
This is useful for programs like
|
2000-05-27 06:23:19 +04:00
|
|
|
.Xr rarpd 8 ,
|
1993-04-10 00:24:12 +04:00
|
|
|
which must respond to messages in real time.
|
|
|
|
The default for a new file is off.
|
2000-05-27 06:23:19 +04:00
|
|
|
.It Dv BIOCSETF (struct bpf_program)
|
1996-12-04 07:46:04 +03:00
|
|
|
Sets the filter program used by the kernel to discard uninteresting
|
1993-04-10 00:24:12 +04:00
|
|
|
packets. An array of instructions and its length is passed in using
|
|
|
|
the following structure:
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bd -literal -offset indent
|
1993-04-10 00:24:12 +04:00
|
|
|
struct bpf_program {
|
|
|
|
int bf_len;
|
|
|
|
struct bpf_insn *bf_insns;
|
|
|
|
};
|
2000-05-27 06:23:19 +04:00
|
|
|
.Ed
|
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
The filter program is pointed to by the
|
2000-05-27 06:23:19 +04:00
|
|
|
.Va bf_insns
|
|
|
|
field while its length in units of
|
|
|
|
.Sq struct bpf_insn
|
|
|
|
is given by the
|
|
|
|
.Va bf_len
|
1993-04-10 00:24:12 +04:00
|
|
|
field.
|
2000-05-27 06:23:19 +04:00
|
|
|
Also, the actions of
|
|
|
|
.Dv BIOCFLUSH
|
|
|
|
are performed.
|
|
|
|
.Pp
|
|
|
|
See section
|
|
|
|
.Sy FILTER MACHINE
|
|
|
|
for an explanation of the filter language.
|
|
|
|
.It Dv BIOCVERSION (struct bpf_version)
|
1996-12-04 07:46:04 +03:00
|
|
|
Returns the major and minor version numbers of the filter language currently
|
1993-04-10 00:24:12 +04:00
|
|
|
recognized by the kernel. Before installing a filter, applications must check
|
|
|
|
that the current version is compatible with the running kernel. Version
|
|
|
|
numbers are compatible if the major numbers match and the application minor
|
|
|
|
is less than or equal to the kernel minor. The kernel version number is
|
|
|
|
returned in the following structure:
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bd -literal -offset indent
|
1993-04-10 00:24:12 +04:00
|
|
|
struct bpf_version {
|
|
|
|
u_short bv_major;
|
|
|
|
u_short bv_minor;
|
|
|
|
};
|
2000-05-27 06:23:19 +04:00
|
|
|
.Ed
|
|
|
|
.Pp
|
1996-12-04 07:46:04 +03:00
|
|
|
The current version numbers are given by
|
2000-05-27 06:23:19 +04:00
|
|
|
.Dv BPF_MAJOR_VERSION
|
1996-12-04 07:46:04 +03:00
|
|
|
and
|
2000-05-27 06:23:19 +04:00
|
|
|
.Dv BPF_MINOR_VERSION
|
1993-04-10 00:24:12 +04:00
|
|
|
from <net/bpf.h>.
|
|
|
|
An incompatible filter
|
|
|
|
may result in undefined behavior (most likely, an error returned by
|
2000-05-27 06:23:19 +04:00
|
|
|
.Xr ioctl 2
|
1993-04-10 00:24:12 +04:00
|
|
|
or haphazard packet matching).
|
2000-05-27 06:23:19 +04:00
|
|
|
.It Dv BIOCSRSIG BIOCGRSIG (u_int signal)
|
1995-09-27 21:31:50 +03:00
|
|
|
Set or get the receive signal. This signal will be sent to the process or process group
|
|
|
|
specified by FIOSETOWN. It defaults to SIGIO.
|
2000-05-27 06:23:19 +04:00
|
|
|
.El
|
1999-12-16 01:07:30 +03:00
|
|
|
.Sh STANDARD IOCTLS
|
2000-05-27 06:23:19 +04:00
|
|
|
.Nm
|
1995-09-27 21:31:50 +03:00
|
|
|
now supports several standard
|
2000-05-27 06:23:19 +04:00
|
|
|
.Xr ioctl 2 's
|
1995-09-27 21:31:50 +03:00
|
|
|
which allow the user to do async and/or non-blocking I/O to an open
|
|
|
|
.I bpf
|
|
|
|
file descriptor.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bl -tag -width -offset indent
|
|
|
|
.It Dv FIONREAD (int)
|
1995-09-27 21:31:50 +03:00
|
|
|
Returns the number of bytes that are immediately available for reading.
|
2000-05-27 06:23:19 +04:00
|
|
|
.It Dv SIOCGIFADDR (struct ifreq)
|
1995-09-27 21:31:50 +03:00
|
|
|
Returns the address associated with the interface.
|
2000-05-27 06:23:19 +04:00
|
|
|
.It Dv FIONBIO (int)
|
1995-09-27 21:31:50 +03:00
|
|
|
Set or clear non-blocking I/O. If arg is non-zero, then doing a
|
2000-05-27 06:23:19 +04:00
|
|
|
.Xr read 2
|
1995-09-27 21:31:50 +03:00
|
|
|
when no data is available will return -1 and
|
2000-05-27 06:23:19 +04:00
|
|
|
.Va errno
|
1995-09-27 21:31:50 +03:00
|
|
|
will be set to EWOULDBLOCK.
|
|
|
|
If arg is zero, non-blocking I/O is disabled. Note: setting this
|
2000-05-27 06:23:19 +04:00
|
|
|
overrides the timeout set by
|
|
|
|
.Dv BIOCSRTIMEOUT .
|
|
|
|
.It Dv FIOASYNC (int)
|
1995-09-27 21:31:50 +03:00
|
|
|
Enable or disable async I/O. When enabled (arg is non-zero), the process or
|
|
|
|
process group specified by FIOSETOWN will start receiving SIGIO's when packets
|
2000-05-27 06:23:19 +04:00
|
|
|
arrive.
|
|
|
|
Note that you must do an FIOSETOWN in order for this to take affect, as
|
1995-09-27 21:31:50 +03:00
|
|
|
the system will not default this for you.
|
2000-05-27 06:23:19 +04:00
|
|
|
The signal may be changed via
|
|
|
|
.Dv BIOCSRSIG .
|
|
|
|
.It Dv FIOSETOWN FIOGETOWN (int)
|
1995-09-27 21:31:50 +03:00
|
|
|
Set or get the process or process group (if negative) that should receive SIGIO
|
2000-05-27 06:23:19 +04:00
|
|
|
when packets are available.
|
|
|
|
The signal may be changed using
|
|
|
|
.Dv BIOCSRSIG
|
|
|
|
(see above).
|
|
|
|
.El
|
1999-12-16 01:07:30 +03:00
|
|
|
.Sh BPF HEADER
|
1996-12-04 07:46:04 +03:00
|
|
|
The following structure is prepended to each packet returned by
|
2000-05-27 06:23:19 +04:00
|
|
|
.Xr read 2 :
|
|
|
|
.Bd -literal -offset indent
|
1993-04-10 00:24:12 +04:00
|
|
|
struct bpf_hdr {
|
|
|
|
struct timeval bh_tstamp;
|
|
|
|
u_long bh_caplen;
|
|
|
|
u_long bh_datalen;
|
|
|
|
u_short bh_hdrlen;
|
|
|
|
};
|
2000-05-27 06:23:19 +04:00
|
|
|
.Ed
|
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
The fields, whose values are stored in host order, and are:
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bl -tag -width bh_datalen -offset indent
|
|
|
|
.It Va bh_tstamp
|
1993-04-10 00:24:12 +04:00
|
|
|
The time at which the packet was processed by the packet filter.
|
2000-05-27 06:23:19 +04:00
|
|
|
.It Va bh_caplen
|
1993-04-10 00:24:12 +04:00
|
|
|
The length of the captured portion of the packet. This is the minimum of
|
|
|
|
the truncation amount specified by the filter and the length of the packet.
|
2000-05-27 06:23:19 +04:00
|
|
|
.It Va bh_datalen
|
1993-04-10 00:24:12 +04:00
|
|
|
The length of the packet off the wire.
|
|
|
|
This value is independent of the truncation amount specified by the filter.
|
2000-05-27 06:23:19 +04:00
|
|
|
.It Va bh_hdrlen
|
1993-04-10 00:24:12 +04:00
|
|
|
The length of the BPF header, which may not be equal to
|
2000-05-27 06:23:19 +04:00
|
|
|
.Em sizeof(struct bpf_hdr) .
|
|
|
|
.El
|
|
|
|
.Pp
|
1996-12-04 07:46:04 +03:00
|
|
|
The
|
2000-05-27 06:23:19 +04:00
|
|
|
.Va bh_hdrlen
|
1993-04-10 00:24:12 +04:00
|
|
|
field exists to account for
|
|
|
|
padding between the header and the link level protocol.
|
|
|
|
The purpose here is to guarantee proper alignment of the packet
|
1996-12-04 07:46:04 +03:00
|
|
|
data structures, which is required on alignment sensitive
|
1993-04-10 00:24:12 +04:00
|
|
|
architectures and and improves performance on many other architectures.
|
1996-12-04 07:46:04 +03:00
|
|
|
The packet filter insures that the
|
2000-05-27 06:23:19 +04:00
|
|
|
.Va bpf_hdr
|
|
|
|
and the
|
|
|
|
.Em network layer
|
|
|
|
header will be word aligned. Suitable precautions
|
1993-04-10 00:24:12 +04:00
|
|
|
must be taken when accessing the link layer protocol fields on alignment
|
|
|
|
restricted machines. (This isn't a problem on an Ethernet, since
|
|
|
|
the type field is a short falling on an even offset,
|
|
|
|
and the addresses are probably accessed in a bytewise fashion).
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
Additionally, individual packets are padded so that each starts
|
|
|
|
on a word boundary. This requires that an application
|
|
|
|
has some knowledge of how to get from packet to packet.
|
2000-05-27 06:23:19 +04:00
|
|
|
The macro
|
|
|
|
.Dv BPF_WORDALIGN
|
|
|
|
is defined in
|
|
|
|
.Pa <net/bpf.h>
|
|
|
|
to facilitate this process.
|
|
|
|
It rounds up its argument
|
1993-04-10 00:24:12 +04:00
|
|
|
to the nearest word aligned value (where a word is BPF_ALIGNMENT bytes wide).
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
|
|
|
For example, if
|
|
|
|
.Sq Va p
|
|
|
|
points to the start of a packet, this expression
|
1993-04-10 00:24:12 +04:00
|
|
|
will advance it to the next packet:
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
|
|
|
.Dl p = (char *)p + BPF_WORDALIGN(p->bh_hdrlen + p->bh_caplen)
|
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
For the alignment mechanisms to work properly, the
|
1996-12-04 07:46:04 +03:00
|
|
|
buffer passed to
|
2000-05-27 06:23:19 +04:00
|
|
|
.Xr read 2
|
1996-12-04 07:46:04 +03:00
|
|
|
must itself be word aligned.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Xr malloc 3
|
1993-04-10 00:24:12 +04:00
|
|
|
will always return an aligned buffer.
|
1999-12-16 01:07:30 +03:00
|
|
|
.Sh FILTER MACHINE
|
1993-04-10 00:24:12 +04:00
|
|
|
A filter program is an array of instructions, with all branches forwardly
|
2000-05-27 06:23:19 +04:00
|
|
|
directed, terminated by a
|
|
|
|
.Sy return
|
|
|
|
instruction.
|
1993-04-10 00:24:12 +04:00
|
|
|
Each instruction performs some action on the pseudo-machine state,
|
|
|
|
which consists of an accumulator, index register, scratch memory store,
|
|
|
|
and implicit program counter.
|
|
|
|
|
|
|
|
The following structure defines the instruction format:
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bd -literal -offset indent
|
1993-04-10 00:24:12 +04:00
|
|
|
struct bpf_insn {
|
|
|
|
u_short code;
|
|
|
|
u_char jt;
|
|
|
|
u_char jf;
|
|
|
|
long k;
|
|
|
|
};
|
2000-05-27 06:23:19 +04:00
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Va k
|
|
|
|
field is used in different ways by different instructions,
|
|
|
|
and the
|
|
|
|
.Va jt
|
|
|
|
and
|
|
|
|
.Va jf
|
|
|
|
fields are used as offsets
|
1996-12-04 07:46:04 +03:00
|
|
|
by the branch instructions.
|
1993-04-10 00:24:12 +04:00
|
|
|
The opcodes are encoded in a semi-hierarchical fashion.
|
1996-12-04 07:46:04 +03:00
|
|
|
There are eight classes of instructions: BPF_LD, BPF_LDX, BPF_ST, BPF_STX,
|
|
|
|
BPF_ALU, BPF_JMP, BPF_RET, and BPF_MISC. Various other mode and
|
1993-04-10 00:24:12 +04:00
|
|
|
operator bits are or'd into the class to give the actual instructions.
|
|
|
|
The classes and modes are defined in <net/bpf.h>.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
Below are the semantics for each defined BPF instruction.
|
|
|
|
We use the convention that A is the accumulator, X is the index register,
|
|
|
|
P[] packet data, and M[] scratch memory store.
|
2000-05-27 06:23:19 +04:00
|
|
|
P[i:n] gives the data at byte offset
|
|
|
|
.Dq i
|
|
|
|
in the packet,
|
1993-04-10 00:24:12 +04:00
|
|
|
interpreted as a word (n=4),
|
|
|
|
unsigned halfword (n=2), or unsigned byte (n=1).
|
|
|
|
M[i] gives the i'th word in the scratch memory store, which is only
|
|
|
|
addressed in word units. The memory store is indexed from 0 to BPF_MEMWORDS-1.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Va k ,
|
|
|
|
.Va jt ,
|
|
|
|
and
|
|
|
|
.Va jf
|
|
|
|
are the corresponding fields in the
|
|
|
|
instruction definition.
|
|
|
|
.Dq len
|
|
|
|
refers to the length of the packet.
|
|
|
|
.Bl -tag -width -offset indent
|
|
|
|
.It Sy BPF_LD
|
1993-04-10 00:24:12 +04:00
|
|
|
These instructions copy a value into the accumulator. The type of the
|
2000-05-27 06:23:19 +04:00
|
|
|
source operand is specified by an
|
|
|
|
.Dq addressing mode
|
|
|
|
and can be a constant
|
|
|
|
.No ( Ns Sy BBPF_IMM Ns ),
|
|
|
|
packet data at a fixed offset
|
|
|
|
.No ( Ns Sy BPF_ABS Ns ),
|
|
|
|
packet data at a variable offset
|
|
|
|
.No ( Ns Sy BPF_IND Ns ),
|
|
|
|
the packet length
|
|
|
|
.No ( Ns Sy BPF_LEN Ns ),
|
|
|
|
or a word in the scratch memory store
|
|
|
|
.No ( Ns Sy BPF_MEM Ns ).
|
|
|
|
For
|
|
|
|
.Sy BPF_IND
|
|
|
|
and
|
|
|
|
.Sy BPF_ABS ,
|
|
|
|
the data size must be specified as a word
|
|
|
|
.No ( Ns Sy BPF_W Ns ),
|
|
|
|
halfword
|
|
|
|
.No ( Ns Sy BPF_H Ns ),
|
|
|
|
or byte
|
|
|
|
.No ( Ns Sy BPF_B Ns ).
|
1993-04-10 00:24:12 +04:00
|
|
|
The semantics of all the recognized BPF_LD instructions follow.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bl -column "BPF_LD+BPF_W+BPF_ABS" "A <- P[k:4]" -width -offset indent
|
|
|
|
.It Sy BPF_LD+BPF_W+BPF_ABS Ta A <- P[k:4]
|
|
|
|
.It Li Sy BPF_LD+BPF_H+BPF_ABS Ta A <- P[k:2]
|
|
|
|
.It Li Sy BPF_LD+BPF_B+BPF_ABS Ta A <- P[k:1]
|
|
|
|
.It Li Sy BPF_LD+BPF_W+BPF_IND Ta A <- P[X+k:4]
|
|
|
|
.It Li Sy BPF_LD+BPF_H+BPF_IND Ta A <- P[X+k:2]
|
|
|
|
.It Li Sy BPF_LD+BPF_B+BPF_IND Ta A <- P[X+k:1]
|
|
|
|
.It Li Sy BPF_LD+BPF_W+BPF_LEN Ta A <- len
|
|
|
|
.It Li Sy BPF_LD+BPF_IMM Ta A <- k
|
|
|
|
.It Li Sy BPF_LD+BPF_MEM Ta A <- M[k]
|
|
|
|
.El
|
|
|
|
.It Sy BPF_LDX
|
1993-04-10 00:24:12 +04:00
|
|
|
These instructions load a value into the index register. Note that
|
1996-12-04 07:46:04 +03:00
|
|
|
the addressing modes are more restricted than those of the accumulator loads,
|
1993-04-10 00:24:12 +04:00
|
|
|
but they include
|
2000-05-27 06:23:19 +04:00
|
|
|
.Sy BPF_MSH ,
|
1993-04-10 00:24:12 +04:00
|
|
|
a hack for efficiently loading the IP header length.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bl -column "BPF_LDX+BPF_W+BPF_IMM" "X <- k" -width -offset indent
|
|
|
|
.It Sy BPF_LDX+BPF_W+BPF_IMM Ta X <- k
|
|
|
|
.It Li Sy BPF_LDX+BPF_W+BPF_MEM Ta X <- M[k]
|
|
|
|
.It Li Sy BPF_LDX+BPF_W+BPF_LEN Ta X <- len
|
|
|
|
.It Li Sy BPF_LDX+BPF_B+BPF_MSH Ta X <- 4*(P[k:1]&0xf)
|
|
|
|
.El
|
|
|
|
.It Sy BPF_ST
|
1993-04-10 00:24:12 +04:00
|
|
|
This instruction stores the accumulator into the scratch memory.
|
|
|
|
We do not need an addressing mode since there is only one possibility
|
|
|
|
for the destination.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bl -column "BPF_ST" "M[k] <- A" -width -offset indent
|
|
|
|
.It Sy BPF_ST Ta M[k] <- A
|
|
|
|
.El
|
|
|
|
.It Sy BPF_STX
|
1993-04-10 00:24:12 +04:00
|
|
|
This instruction stores the index register in the scratch memory store.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bl -column "BPF_STX" "M[k] <- X" -width -offset indent
|
|
|
|
.It Sy BPF_STX Ta M[k] <- X
|
|
|
|
.El
|
|
|
|
.It Sy BPF_ALU
|
1993-04-10 00:24:12 +04:00
|
|
|
The alu instructions perform operations between the accumulator and
|
|
|
|
index register or constant, and store the result back in the accumulator.
|
2000-05-27 06:23:19 +04:00
|
|
|
For binary operations, a source mode is required
|
|
|
|
.No ( Ns Sy BPF_K
|
|
|
|
or
|
|
|
|
.Sy BPF_X Ns ).
|
|
|
|
.Bl -column "BPF_ALU+BPF_ADD+BPF_K" "A <- A + k" -width -offset indent
|
|
|
|
.It Sy BPF_ALU+BPF_ADD+BPF_K Ta A <- A + k
|
|
|
|
.It Li Sy BPF_ALU+BPF_SUB+BPF_K Ta A <- A - k
|
|
|
|
.It Li Sy BPF_ALU+BPF_MUL+BPF_K Ta A <- A * k
|
|
|
|
.It Li Sy BPF_ALU+BPF_DIV+BPF_K Ta A <- A / k
|
|
|
|
.It Li Sy BPF_ALU+BPF_AND+BPF_K Ta A <- A & k
|
|
|
|
.It Li Sy BPF_ALU+BPF_OR+BPF_K Ta A <- A | k
|
|
|
|
.It Li Sy BPF_ALU+BPF_LSH+BPF_K Ta A <- A << k
|
|
|
|
.It Li Sy BPF_ALU+BPF_RSH+BPF_K Ta A <- A >> k
|
|
|
|
.It Li Sy BPF_ALU+BPF_ADD+BPF_X Ta A <- A + X
|
|
|
|
.It Li Sy BPF_ALU+BPF_SUB+BPF_X Ta A <- A - X
|
|
|
|
.It Li Sy BPF_ALU+BPF_MUL+BPF_X Ta A <- A * X
|
|
|
|
.It Li Sy BPF_ALU+BPF_DIV+BPF_X Ta A <- A / X
|
|
|
|
.It Li Sy BPF_ALU+BPF_AND+BPF_X Ta A <- A & X
|
|
|
|
.It Li Sy BPF_ALU+BPF_OR+BPF_X Ta A <- A | X
|
|
|
|
.It Li Sy BPF_ALU+BPF_LSH+BPF_X Ta A <- A << X
|
|
|
|
.It Li Sy BPF_ALU+BPF_RSH+BPF_X Ta A <- A >> X
|
|
|
|
.It Li Sy BPF_ALU+BPF_NEG Ta A <- -A
|
|
|
|
.El
|
|
|
|
.It Sy BPF_JMP
|
1993-04-10 00:24:12 +04:00
|
|
|
The jump instructions alter flow of control. Conditional jumps
|
2000-05-27 06:23:19 +04:00
|
|
|
compare the accumulator against a constant
|
|
|
|
.No ( Ns Sy BPF_K Ns )
|
|
|
|
or the index register
|
|
|
|
.No ( Ns Sy BPF_X Ns ).
|
|
|
|
If the result is true (or non-zero),
|
1993-04-10 00:24:12 +04:00
|
|
|
the true branch is taken, otherwise the false branch is taken.
|
|
|
|
Jump offsets are encoded in 8 bits so the longest jump is 256 instructions.
|
2000-05-27 06:23:19 +04:00
|
|
|
However, the jump always
|
|
|
|
.No ( Ns Sy BPF_JA Ns )
|
|
|
|
opcode uses the 32 bit
|
|
|
|
.Va k
|
1993-04-10 00:24:12 +04:00
|
|
|
field as the offset, allowing arbitrarily distant destinations.
|
|
|
|
All conditionals use unsigned comparison conventions.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bl -column "BPF_JMP+BPF_JGE+BPF_K" "pc += (A >= k) ? jt : jf" -width -offset indent
|
|
|
|
.It Sy BPF_JMP+BPF_JA Ta pc += k
|
|
|
|
.It Li Sy BPF_JMP+BPF_JGT+BPF_K Ta "pc += (A > k) ? jt : jf"
|
|
|
|
.It Li Sy BPF_JMP+BPF_JGE+BPF_K Ta "pc += (A >= k) ? jt : jf"
|
|
|
|
.It Li Sy BPF_JMP+BPF_JEQ+BPF_K Ta "pc += (A == k) ? jt : jf"
|
|
|
|
.It Li Sy BPF_JMP+BPF_JSET+BPF_K Ta "pc += (A & k) ? jt : jf"
|
|
|
|
.It Li Sy BPF_JMP+BPF_JGT+BPF_X Ta "pc += (A > X) ? jt : jf"
|
|
|
|
.It Li Sy BPF_JMP+BPF_JGE+BPF_X Ta "pc += (A >= X) ? jt : jf"
|
|
|
|
.It Li Sy BPF_JMP+BPF_JEQ+BPF_X Ta "pc += (A == X) ? jt : jf"
|
|
|
|
.It Li Sy BPF_JMP+BPF_JSET+BPF_X Ta "pc += (A & X) ? jt : jf"
|
|
|
|
.El
|
|
|
|
.It Sy BPF_RET
|
1993-04-10 00:24:12 +04:00
|
|
|
The return instructions terminate the filter program and specify the amount
|
|
|
|
of packet to accept (i.e., they return the truncation amount). A return
|
|
|
|
value of zero indicates that the packet should be ignored.
|
2000-05-27 06:23:19 +04:00
|
|
|
The return value is either a constant
|
|
|
|
.No ( Ns Sy BPF_K Ns )
|
|
|
|
or the accumulator
|
|
|
|
.No ( Ns Sy BPF_A Ns ).
|
|
|
|
.Bl -column "BPF_RET+BPF_A" "accept A bytes" -width -offset indent
|
|
|
|
.It Sy BPF_RET+BPF_A Ta accept A bytes
|
|
|
|
.It Li Sy BPF_RET+BPF_K Ta accept k bytes
|
|
|
|
.El
|
|
|
|
.It Sy BPF_MISC
|
1993-04-10 00:24:12 +04:00
|
|
|
The miscellaneous category was created for anything that doesn't
|
|
|
|
fit into the above classes, and for any new instructions that might need to
|
1996-12-04 07:46:04 +03:00
|
|
|
be added. Currently, these are the register transfer instructions
|
1993-04-10 00:24:12 +04:00
|
|
|
that copy the index register to the accumulator or vice versa.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bl -column "BPF_MISC+BPF_TAX" "X <- A" -width -offset indent
|
|
|
|
.It Sy BPF_MISC+BPF_TAX Ta X <- A
|
|
|
|
.It Li Sy BPF_MISC+BPF_TXA Ta A <- X
|
|
|
|
.El
|
|
|
|
.El
|
|
|
|
.Pp
|
1996-12-04 07:46:04 +03:00
|
|
|
The BPF interface provides the following macros to facilitate
|
1993-04-10 00:24:12 +04:00
|
|
|
array initializers:
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
.Sy BPF_STMT Ns (opcode, operand)
|
|
|
|
.Sy BPF_JUMP Ns (opcode, operand, true_offset, false_offset)
|
|
|
|
.Ed
|
|
|
|
.Pp
|
1999-12-16 01:07:30 +03:00
|
|
|
.Sh EXAMPLES
|
1993-04-10 00:24:12 +04:00
|
|
|
The following filter is taken from the Reverse ARP Daemon. It accepts
|
|
|
|
only Reverse ARP requests.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bd -literal -offset indent
|
1993-04-10 00:24:12 +04:00
|
|
|
struct bpf_insn insns[] = {
|
|
|
|
BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12),
|
|
|
|
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_REVARP, 0, 3),
|
|
|
|
BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 20),
|
|
|
|
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, REVARP_REQUEST, 0, 1),
|
1996-12-04 07:46:04 +03:00
|
|
|
BPF_STMT(BPF_RET+BPF_K, sizeof(struct ether_arp) +
|
2000-05-27 06:23:19 +04:00
|
|
|
sizeof(struct ether_header)),
|
1993-04-10 00:24:12 +04:00
|
|
|
BPF_STMT(BPF_RET+BPF_K, 0),
|
|
|
|
};
|
2000-05-27 06:23:19 +04:00
|
|
|
.Ed
|
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
This filter accepts only IP packets between host 128.3.112.15 and
|
|
|
|
128.3.112.35.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bd -literal -offset indent
|
1993-04-10 00:24:12 +04:00
|
|
|
struct bpf_insn insns[] = {
|
|
|
|
BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12),
|
|
|
|
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_IP, 0, 8),
|
1993-07-15 18:53:52 +04:00
|
|
|
BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 26),
|
1993-04-10 00:24:12 +04:00
|
|
|
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 2),
|
1993-07-15 18:53:52 +04:00
|
|
|
BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 30),
|
1993-04-10 00:24:12 +04:00
|
|
|
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 3, 4),
|
|
|
|
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 0, 3),
|
1993-07-15 18:53:52 +04:00
|
|
|
BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 30),
|
1993-04-10 00:24:12 +04:00
|
|
|
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 1),
|
|
|
|
BPF_STMT(BPF_RET+BPF_K, (u_int)-1),
|
|
|
|
BPF_STMT(BPF_RET+BPF_K, 0),
|
|
|
|
};
|
2000-05-27 06:23:19 +04:00
|
|
|
.Ed
|
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
Finally, this filter returns only TCP finger packets. We must parse
|
2000-05-27 06:23:19 +04:00
|
|
|
the IP header to reach the TCP header. The
|
|
|
|
.Sy BPF_JSET
|
|
|
|
instruction checks that the IP fragment offset is 0 so we are sure
|
1993-04-10 00:24:12 +04:00
|
|
|
that we have a TCP header.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Bd -literal -offset indent
|
1993-04-10 00:24:12 +04:00
|
|
|
struct bpf_insn insns[] = {
|
|
|
|
BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12),
|
|
|
|
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_IP, 0, 10),
|
|
|
|
BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 23),
|
|
|
|
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, IPPROTO_TCP, 0, 8),
|
|
|
|
BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 20),
|
|
|
|
BPF_JUMP(BPF_JMP+BPF_JSET+BPF_K, 0x1fff, 6, 0),
|
|
|
|
BPF_STMT(BPF_LDX+BPF_B+BPF_MSH, 14),
|
|
|
|
BPF_STMT(BPF_LD+BPF_H+BPF_IND, 14),
|
|
|
|
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 79, 2, 0),
|
|
|
|
BPF_STMT(BPF_LD+BPF_H+BPF_IND, 16),
|
|
|
|
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 79, 0, 1),
|
|
|
|
BPF_STMT(BPF_RET+BPF_K, (u_int)-1),
|
|
|
|
BPF_STMT(BPF_RET+BPF_K, 0),
|
|
|
|
};
|
2000-05-27 06:23:19 +04:00
|
|
|
.Ed
|
1999-12-16 01:07:30 +03:00
|
|
|
.Sh SEE ALSO
|
2000-05-27 06:23:19 +04:00
|
|
|
.Xr ioctl 2 ,
|
|
|
|
.Xr read 2 ,
|
|
|
|
.Xr select 2 ,
|
|
|
|
.Xr signal 3 ,
|
|
|
|
.Xr tcpdump 8
|
|
|
|
.Rs
|
|
|
|
.%T "The BSD Packet Filter: A New Architecture for User-level Packet Capture".
|
|
|
|
.%A McCanne, S. and Jacobson V.
|
|
|
|
.%J Proceedings of the 1993 Winter USENIX
|
|
|
|
.%C Technical Conference, San Diego, CA.
|
|
|
|
.Re
|
1999-12-16 01:07:30 +03:00
|
|
|
.Sh FILES
|
1993-04-10 00:24:12 +04:00
|
|
|
/dev/bpf0, /dev/bpf1, ...
|
1999-12-16 01:07:30 +03:00
|
|
|
.Sh BUGS
|
2000-05-27 06:23:19 +04:00
|
|
|
The read buffer must be of a fixed size (returned by the
|
|
|
|
.Dv BIOCGBLEN
|
|
|
|
ioctl).
|
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
A file that does not request promiscuous mode may receive promiscuously
|
|
|
|
received packets as a side effect of another file requesting this
|
|
|
|
mode on the same hardware interface. This could be fixed in the kernel
|
1996-12-04 07:46:04 +03:00
|
|
|
with additional processing overhead. However, we favor the model where
|
|
|
|
all files must assume that the interface is promiscuous, and if
|
1993-04-10 00:24:12 +04:00
|
|
|
so desired, must utilize a filter to reject foreign packets.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
Data link protocols with variable length headers are not currently supported.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
1993-04-10 00:24:12 +04:00
|
|
|
Under SunOS, if a BPF application reads more than 2^31 bytes of
|
|
|
|
data, read will fail in EINVAL. You can either fix the bug in SunOS,
|
|
|
|
or lseek to 0 when read fails for this reason.
|
2000-05-27 06:23:19 +04:00
|
|
|
.Pp
|
|
|
|
.Dq Immediate mode
|
|
|
|
and the
|
|
|
|
.Dq read timeout
|
|
|
|
are misguided features.
|
1996-12-04 07:46:04 +03:00
|
|
|
This functionality can be emulated with non-blocking mode and
|
2000-05-27 06:23:19 +04:00
|
|
|
.Xr select 2 .
|
1999-12-16 01:07:30 +03:00
|
|
|
.Sh HISTORY
|
1993-04-10 00:24:12 +04:00
|
|
|
The Enet packet filter was created in 1980 by Mike Accetta and
|
|
|
|
Rick Rashid at Carnegie-Mellon University. Jeffrey Mogul, at
|
1996-12-04 07:46:04 +03:00
|
|
|
Stanford, ported the code to BSD and continued its development from
|
1993-04-10 00:24:12 +04:00
|
|
|
1983 on. Since then, it has evolved into the Ultrix Packet Filter
|
|
|
|
at DEC, a STREAMS NIT module under SunOS 4.1, and BPF.
|
1999-12-16 01:07:30 +03:00
|
|
|
.Sh AUTHORS
|
1993-04-10 00:24:12 +04:00
|
|
|
Steven McCanne, of Lawrence Berkeley Laboratory, implemented BPF in
|
1996-12-04 07:46:04 +03:00
|
|
|
Summer 1990. The design was in collaboration with Van Jacobson,
|
|
|
|
also of Lawrence Berkeley Laboratory.
|