*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->FreeBSD man pages -> pfil (9)              



NAME    [Toc]    [Back]

     pfil, pfil_head_register, pfil_head_unregister, pfil_head_get,
     pfil_hook_get, pfil_add_hook, pfil_remove_hook, pfil_run_hooks -- packet
     filter interface

SYNOPSIS    [Toc]    [Back]

     #include <sys/param.h>
     #include <sys/mbuf.h>
     #include <net/if.h>
     #include <net/pfil.h>

     pfil_head_register(struct pfil_head *head);

     pfil_head_unregister(struct pfil_head *head);

     struct pfil_head *
     pfil_head_get(int af, u_long dlt);

     struct packet_filter_hook *
     pfil_hook_get(int dir, struct pfil_head *head);

     pfil_add_hook(int (*func)(), void *arg, int flags, struct pfil_head *);

     pfil_remove_hook(int (*func)(), void *arg, int flags,
	 struct pfil_head *);

     (*func)(void *arg, struct mbuf **mp, struct ifnet *, int dir);

     pfil_run_hooks(struct pfil_head *head, struct mbuf **mp, struct ifnet *,
	 int dir);

DESCRIPTION    [Toc]    [Back]

     The pfil framework allows for a specified function to be invoked for
     every incoming or outgoing packet for a particular network I/O stream.
     These hooks may be used to implement a firewall or perform packet transformations.

     Packet filtering points are registered with pfil_head_register().	Filtering
 points are identified by a key (void *) and a data link type (int)
     in the pfil_head structure.  Packet filters use the key and data link
     type to look up the filtering point with which they register themselves.
     The key is unique to the filtering point.	The data link type is a bpf(4)
     DLT constant indicating what kind of header is present on the packet at
     the filtering point.  Filtering points may be unregistered with the
     pfil_head_unregister() function.

     Packet filters register/unregister themselves with a filtering point with
     the pfil_add_hook() and pfil_remove_hook() functions, respectively.  The
     head is looked up using the pfil_head_get() function, which takes the key
     and data link type that the packet filter expects.  Filters may provide
     an argument to be passed to the filter when invoked on a packet.

     When a filter is invoked, the packet appears just as if it ``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 (PFIL_IN or PFIL_OUT)
     that the packet is traveling.  The filter may change which mbuf the 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

     The pfil interface is enabled in the kernel via the PFIL_HOOKS option.

RETURN VALUES    [Toc]    [Back]

     If successful, pfil_head_get() returns the pfil_head structure for the
     given key/dlt.  pfil_add_hook() and pfil_remove_hook() return 0 if successful.
 If called with flag PFIL_WAITOK, pfil_remove_hook() is expected
     to always succeed.

     pfil_head_unregister() might sleep!

HISTORY    [Toc]    [Back]

     The pfil interface first appeared in NetBSD 1.3.  The pfil input and output
 lists were originally implemented as <sys/queue.h>
     LIST structures; however this was changed in NetBSD 1.4 to 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.

     The pfil interface was changed in 1.4T to accept a 3rd parameter to both
     pfil_add_hook() and pfil_remove_hook(), introducing the capability of
     per-protocol filtering.  This was done primarily in order to support filtering
 of IPv6.

     In 1.5K, the pfil framework was changed to work with an arbitrary number
     of filtering points, as well as be less IP-centric.

     Fine-grained locking was adding in FreeBSD 5.2.

BUGS    [Toc]    [Back]

     pfil_hook_get() is only safe for internal use.

     FreeBSD implements only hooks for AF_INET and AF_INET6.  Packets diverted
     through these hooks have data in host byte order contrary to the above

     The bridge(4) diverts inbound AF_INET traffic, but contrary to the above
     statements, the data is provided in host byte order.

     When a pfil_head is being modified no traffic is diverted (to avoid deadlock).
  This means that unwanted traffic may flow for a short period of

SEE ALSO    [Toc]    [Back]

     bpf(4), bridge(4)

FreeBSD 5.2.1		       September 8, 2003		 FreeBSD 5.2.1
[ Back ]
 Similar pages
Name OS Title
pflog OpenBSD packet filter logging interface
pfsync OpenBSD packet filter state table logging interface
ipfstat FreeBSD reports on packet filter statistics and filter list
pf OpenBSD packet filter
iptables Linux IP packet filter administration
bpf OpenBSD Berkeley Packet Filter
packetfilter Tru64 Ethernet packet filter
bpf Tru64 BSD Packet Filter Extensions
bpf FreeBSD Berkeley Packet Filter
pflogd OpenBSD packet filter logging daemon
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service