summaryrefslogtreecommitdiffstats
path: root/share/man/man9/pfil.9
blob: 3273d5f4393e843b415a0e2171cfc188b61d9e28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
.\" Copyright (c) 1996 Matthew R. Green
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. The name of the author may not be used to endorse or promote products
.\"    derived from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
.Dd August 4, 1996
.Dt PFIL 9
.Os
.Sh NAME
.Nm pfil ,
.Nm pfil_hook_get ,
.Nm pfil_add_hook ,
.Nm pfil_remove_hook
.Nd packet filter interface
.Sh SYNOPSIS
.In sys/param.h
.In sys/mbuf.h
.In sys/socket.h
.In net/if.h
.In net/pfil.h
.Ft "struct packet_filter_hook *"
.Fn pfil_hook_get "int flag" "struct pfil_head *ph"
.Ft int
.Fo pfil_add_hook
.Fa "int \*[lp]*func\*[rp]\*[lp]void *, int, struct ifnet *, int, struct mbuf **\*[rp]"
.Fa "int flags"
.Fa "struct pfil_head *ph"
.Fc
.Ft int
.Fo pfil_remove_hook
.Fa "int \*[lp]*func\*[rp]\*[lp]void *, int, struct ifnet *, int, struct mbuf **\*[rp]"
.Fa "int flags"
.Fa "struct pfil_head *ph"
.Fc
.Sh DESCRIPTION
The
.Nm
interface allows a function to be called on every incoming or outgoing
packets.
The hooks for these are embedded in the
.Fn ip_input
and
.Fn ip_output
routines.
The
.Fn pfil_hook_get
function returns the first member of a particular hook, either the in or out
list.
The
.Fn pfil_add_hook
function takes a function of the form below as its first argument, and the
flags for which lists to add the function to.
The possible values for these
flags are some combination of
.Dv PFIL_IN
and
.Dv PFIL_OUT .
The
.Fn pfil_remove_hook
removes a hook from the specified lists.
.Pp
The
.Fa func
argument is a function with the following prototype.
.Pp
.Ft int
.Fn func "void *data" "int hlen" "struct ifnet *net" "int dir" "struct mbuf **m"
.Pp
The
.Fa data
describes the packet.
Currently, this may only be a pointer to an
.Vt ip
structure.
The
.Fa net
and
.Fa m
arguments describe the network interface and the mbuf holding data for this
packet.
The
.Fa dir
is the direction; 0 for incoming packets and 1 for outgoing packets.
If the function
returns non-zero, this signals an error and no further processing of this packet is
performed.
The function should set
.Va errno
to indicate the nature of the error.
It is the hook's responsibility to free the chain if the packet is being dropped.
.Pp
The
.Nm
interface is enabled in the kernel via the
.Cd PFIL_HOOKS
option.
.Sh RETURN VALUES
If successful,
.Fn pfil_hook_get
returns the first member of the packet filter list,
.Fn pfil_add_hook
and
.Fn pfil_remove_hook
are expected to always succeed.
.Sh HISTORY
The
.Nm
interface first appeared in
.Nx 1.3 .
The
.Nm
input and output lists were originally implemented as
.Aq Pa 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.
.Pp
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.
.Sh BUGS
The current
.Nm
implementation will need changes to suit a threaded kernel model.
.Sh SEE ALSO
.Xr bpf 4
OpenPOWER on IntegriCloud