xref: /netbsd-src/share/man/man9/pfil.9 (revision d0fed6c87ddc40a8bffa6f99e7433ddfc864dd83)
1.\"	$NetBSD: pfil.9,v 1.4 1997/04/13 13:48:51 mrg Exp $
2.\"
3.\" Copyright (c) 1996 Matthew R. Green.
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"        This product includes software developed by Matthew R. Green for
17.\"        the NetBSD Project.
18.\" 4. Neither the name of The NetBSD Foundation nor the names of its
19.\"    contributors may be used to endorse or promote products derived
20.\"    from this software without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
26.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32.\" POSSIBILITY OF SUCH DAMAGE.
33.\"
34.Dd August 4, 1996
35.Dt PFIL 9
36.Os NetBSD
37.Sh NAME
38.Nm pfil
39.Nd packet filter interface
40.Sh SYNOPSIS
41.Fd #include <sys/param.h>
42.Fd #include <netinet/ip.h>
43.Ft struct packet_filter_hook *
44.Fn pfil_hook_get int
45.Ft void
46.Fn pfil_add_hook "int (*func)()" "int flags"
47.Ft void
48.Fn pfil_remove_hook "int (*func)()" "int flags"
49.\"(void *, int, struct ifnet *, int, struct mbuf **)
50.Sh DESCRIPTION
51The
52.Nm
53interface allows a function to be called on every incoming or outgoing
54packets.  The hooks for these are embedded in the
55.Fn ip_input
56and
57.Fn ip_output
58routines.  The
59.Fn pfil_hook_get
60function returns the first member of a particular hook, either the in or out
61list.  The
62.Fn pfil_add_hook
63function takes a function of the form below as it's first argument, and the
64flags for which lists to add the function to.  The possible values for these
65flags are some combination of PFIL_IN and PFIL_OUT.  The
66.Fn pfil_remove_hook
67removes a hook from the specified lists.
68.Pp
69The
70.Va func
71argument is a function with the following prototype.
72.Pp
73.Fn func "void *data" "int hlen" "struct ifnet *net" "int dir" "struct mbuf **m"
74.Pp
75The
76.Va data
77describes the packet.  Currently, this may only be a pointer to a ip structure.  The
78.Va net
79and
80.Va m
81arguments describe the network interface and the mbuf holding data for this
82packet.  The
83.Va dir
84is the direction; 0 for incoming packets and 1 for outgoing packets.  if the function
85returns non-zero, this signals an error and no further processing of this packet is
86performed.  The function should set errno to indicate the nature of the error.
87It is the hook's responsibiliy to free the chain if the packet is being dropped.
88.Pp
89The
90.Nm
91interface is enabled in the kernel via the
92.Sy PFIL_HOOKS
93option.
94.Sh RETURN VALUES
95If successful
96.Fn pfil_hook_get
97returns the first member of the packet filter list,
98.Fn pfil_add_hook
99and
100.Fn pfil_remove_hook
101are expected to always succeed.
102.Sh HISTORY
103The
104.Nm
105interface first appeared in
106.Nx 1.3
107.Sh BUGS
108The current
109.Nm
110implementation will need changes to suit a threaded kernel model.
111.Sh SEE ALSO
112.Xr bpf 4 .
113