:man| Alphabetical   Categories   About us 
 
PFIL (9) | Kernel routines | Unix Manual Pages | :man

NAME

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

CONTENTS

Synopsis
Description
Return Values
See Also
History
Bugs

SYNOPSIS


.In sys/param.h
.In sys/mbuf.h
.In net/if.h
.In net/pfil.h int pfil_head_register "struct pfil_head *head" int 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" void pfil_add_hook "int (*func)()" "void *arg" "int flags" "struct pfil_head *" void pfil_remove_hook "int (*func)()" "void *arg" "int flags" "struct pfil_head *" int (*func) "void *arg" "struct mbuf **mp" "struct ifnet *" "int dir" "struct inpcb *" int pfil_run_hooks "struct pfil_head *head" "struct mbuf **mp" "struct ifnet *" "int dir" "struct inpcb *"

DESCRIPTION

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 (Vt "void *") and a data link type (Vt int) in the
.Vt 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
.Vt 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
.Vt "mbuf **" argument references. The filter returns an error (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.

RETURN VALUES

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

The pfil_head_unregister function might sleep!

SEE ALSO

bpf(4), bridge(4)

HISTORY

BUGS

bridge(4)


Share this page

     Follow us

Facebook Twitter Google+ LinkedIn


 
Created by Blin Media, 2008-2013