p Packet filtering points are created with .Fn pfil_head_create . Filtering points are identified by a data link .Vt ( int ) .Fa type and a .Vt ( void * ) .Fa key . If a packet filtering point already exists for that data link .Fa type and .Fa key then the .Fn pfil_head_create function returns .Dv NULL . Packet filters use the .Fn pfil_head_get function specifying the data link .Fa type and the .Fa key to look up the filtering point with which they register themselves. The .Fa key is unique to the filtering point. The data link .Fa type is a .Xr bpf 4 .Dv DLT_ Ns Ar type constant indicating what kind of header is present on the packet at the filtering point. Filtering points may be destroyed with the .Fn pfil_head_destroy function.
p Packet filters register/unregister themselves with a filtering point with the .Fn pfil_add_hook and .Fn pfil_remove_hook functions, respectively. The head is looked up using the .Fn pfil_head_get function, which takes the data link .Fa type and the .Fa key that the packet filter expects. Filters may provide an argument to be passed to the filter when invoked on a packet.
p When a filter is invoked, the packet appears just as if it .Dq came off the wire . That is, all protocol fields are in network byte order. The filter is called with its specified argument, the pointer to the pointer to the mbuf containing the packet, the pointer to the network interface that the packet is traversing, and the direction (either .Dv PFIL_IN or .Dv PFIL_OUT , see also below) that the packet is traveling. The filter may change which mbuf the .Vt "mbuf **" argument references. The filter returns an errno if the packet processing is to stop, or 0 if the processing is to continue. If the packet processing is to stop, it is the responsibility of the filter to free the packet.
p The .Fa flags parameter, used in the .Fn pfil_add_hook and .Fn pfil_remove_hook functions, indicates when the filter should be called. The flags are:
p l -tag -offset indent -width ".Dv PFIL_ALL" -compact t Dv PFIL_IN call me on incoming packets t Dv PFIL_OUT call me on outgoing packets t Dv PFIL_ALL call me on all of the above .El
p By the same token, event handlers register/unregister themselves with the .Fn pfil_add_ihook and .Fn pfil_remove_ihook functions, respectively. The event handler is called with its specified argument, the event id (either .Dv PFIL_IFNET_ATTACH or .Dv PFIL_IFNET_DETACH , see also below) or ioctl number, and the pointer to the network interface or the pointer to the ifaddr.
p The .Fa flags parameter, used in the .Fn pfil_add_ihook and .Fn pfil_remove_ihook functions, indicates when the filter should be called. The flags are:
p l -tag -offset indent -width ".Dv PFIL_IFADDR" -compact t Dv PFIL_IFADDR call me on interface reconfig .Fa ( cmd is ioctl #) t Dv PFIL_IFNET call me on interface attach/detach .Fa ( cmd is either .Dv PFIL_IFNET_ATTACH or .Dv PFIL_IFNET_DETACH ) .El .Sh SEE ALSO .Xr bpf 4 .Sh HISTORY The .Nm interface first appeared in .Nx 1.3 . The .Nm input and output lists were originally implemented as n sys/queue.h .Dv LIST structures; however this was changed in .Nx 1.4 to .Dv TAILQ structures. This change was to allow the input and output filters to be processed in reverse order, to allow the same path to be taken, in or out of the kernel.
p The .Nm interface was changed in 1.4T to accept a 3rd parameter to both .Fn pfil_add_hook and .Fn pfil_remove_hook , introducing the capability of per-protocol filtering. This was done primarily in order to support filtering of IPv6.
p In 1.5K, the .Nm framework was changed to work with an arbitrary number of filtering points, as well as be less IP-centric.
p .Fn pfil_add_ihook and .Fn pfil_remove_ihook were added in .Nx 8.0 . .Sh AUTHORS .An -nosplit The .Nm interface was designed and implemented by .An Matthew R. Green , with help from .An Darren Reed , .An Jason R. Thorpe , and .An Charles M. Hannum . .An Darren Reed added support for IPv6 in addition to IPv4. .An Jason R. Thorpe added support for multiple hooks and other clean up. .Sh BUGS The current .Nm implementation will need changes to suit a threaded kernel model.