<< Previous Contents Index Next >>

5.3. Berkeley Packet Filter (BPF)

The Berkeley Packet Filter is a mechanism built into the BSD kernel to capture packets passing through its network interfaces. The ipacc BPF interface uses this mechanism to extract flows into a ring-buffer for later processing.

The BPF process accesses the /dev/bpfn devices, and reads inbound packets, building up an internal flow cache and writing flows as they expire to the ring buffer.

BPF is only available on BSD systems (e.g. FreeBSD). For packet capture on other systems, the packet capture library (libpcap) interface should be used.

5.3.1. Setting up BPF on BSD systems

For BPF to work, the BPF devices must be compiled into the kernel. The kernel configuration file /usr/src/sys/i386/conf/name should contain a line that reads:

If it is commented out or missing, one should re-insert it and recompile and re-install the kernel.

Note that the standard generic kernel, defined on FreeBSD in /usr/src/sys/i386/conf/GENERIC, should not be modified; create a new kernel with a new name. See your distribution documentation for information on compiling and installing kernels.

There should also be BPF devices in /dev:

Note that unless the collector process is run as root, these will not be accessible under their default permissions. The access modes must be changed to permit access to the user that ipacc processes will be run as. To do this, the ipacc user can be added to the wheel group, by changing /etc/group so that the line:

reads:

and then the BPF devices can be made group read/writable:

Alternatively, an additional group may be created to allow ipacc to access the BPF devices without adding ipacc to the wheel group.

Under FreeBSD version 5, the devfs file system is used for the /dev directory tree, creating device entries dynamically. Such dynamic assignments can't be relied on to keep manually set ownership and permissions, and must be set using the devfs configuration tools. The easiest way to set this up is to add to /etc/devfs.conf:

and run the command /etc/rc.d/devfs start to put it into effect. (The latter command will be automatically run on system startup.) An own bpf0 owner:group line in /etc/devfs.conf can be used to set the owner and group if that is required.

5.3.2. Configuring BPF collection

The collect bpf interface flags ... statement enables BPF collection on a data source. Multiple collect bpf statements may be used to allow collection from more than one interface. The interface is the name of the network interface to sniff, and is the same as that used by ifconfig when configuring and querying network interfaces.

flags can be:

promiscuous  Place interface in promiscuous mode, i.e. the interface will receive all traffic seen on the interface, regardless of whether the traffic was directed at the collector host; this is useful in configurations which passively "sniff" passing traffic, and are not directly involved in routing. Note that if another program puts the same interface into promiscuous mode, the collector may see traffic not intended for it.
inbound  Ignore all outbound traffic, i.e. traffic with a source MAC address matching the interface MAC address, should be ignored. By default, traffic in both directions is counted, which may result in traffic being counted twice.
outbound  Ignore inbound traffic, i.e. traffic with a source MAC address that does not match that of the interface.
broadcasts  Include traffic sent to (or from) the broadcast MAC address (FF:FF:FF:FF:FF:FF). By default, broadcasts are ignored.
multicasts  Include traffic sent to or from a multicast MAC address. By default, multicast traffic is ignored.
address mac-address
Specify the MAC address of the interface for inbound and outbound checks, in xx:xx:xx:xx:xx:xx format (whare x is a hex digit). This is required on Debian Woody or other Linux systems where the old glibc version supplied does not include the getifaddrs() routine to obtain MAC addresses of interfaces.

The size of the BPF buffer is set by the bpf bufsize size statement, and defaults to 64k. Heavy or highly bursty traffic patterns may require a larger buffer size, e.g. 1 megabyte. Note that large buffers may also be needed if the collector system is often heavily loaded, as scheduling delays may mean that a burst of traffic may overflow the buffer before the collector can run again to process it. The size parameter is in bytes, and may be specified as a quantity.

For example, a BPF configuration, with interface dc1 listening to a shared hub might read:

An example of a BPF configuration where the collector is acting as a router, with three interfaces, under heavy load:

5.3.3. Flow cache tuning

The BPF and libpcap flow cache can be tuned for performance vs timeliness of updates. Cache entries are flushed (writing a record to the ring buffer) if they expire or if space is required to add a new entry.

The flow-cache size entries statement determines the maximum number of active flows that can be cached in memory at any time, and should be sized on realistic values. The default is 1024. The parameter is treated as a quantity.

The flow-cache active time and flow-cache inactive time statements determine how long active and inactive flows are retained. An active flow is defined as one that has received data within the inactive timeout, whereas an inactive flow is one where both timeouts have expired. Note that ipacc uses a rolling expiry algorithm, so the flow expiry times are approximate. Times are specified as intervals. The defaults are 60 seconds for an active flow and 20 seconds for an inactive flow.

The flow-cache search count specifies the number of flows that are searched when looking for a cache slot to insert a new entry into. A higher number means that if cache slots are tight, there is a better chance of finding an inactive flow slot to add a new flow into (at the expense of a longer search), whereas a lower number means a shorter search but may require flushing an active flow to make room for the new flow. The default is 8. The parameter is treated as a quantity.


<< Previous Contents Index Next >>