xref: /dflybsd-src/share/man/man4/pf.4 (revision 566ca7464eb5d6900eb6973a39e44199a578ca36)
14696a7e0SJan Lentfer.\"	$OpenBSD: pf.4,v 1.60 2007/12/02 12:08:04 pascoe Exp $
2f1e85027SSimon Schubert.\"
3f1e85027SSimon Schubert.\" Copyright (C) 2001, Kjell Wooding.  All rights reserved.
4f1e85027SSimon Schubert.\"
5f1e85027SSimon Schubert.\" Redistribution and use in source and binary forms, with or without
6f1e85027SSimon Schubert.\" modification, are permitted provided that the following conditions
7f1e85027SSimon Schubert.\" are met:
8f1e85027SSimon Schubert.\" 1. Redistributions of source code must retain the above copyright
9f1e85027SSimon Schubert.\"    notice, this list of conditions and the following disclaimer.
10f1e85027SSimon Schubert.\" 2. Redistributions in binary form must reproduce the above copyright
11f1e85027SSimon Schubert.\"    notice, this list of conditions and the following disclaimer in the
12f1e85027SSimon Schubert.\"    documentation and/or other materials provided with the distribution.
13f1e85027SSimon Schubert.\" 3. Neither the name of the project nor the names of its contributors
14f1e85027SSimon Schubert.\"    may be used to endorse or promote products derived from this software
15f1e85027SSimon Schubert.\"    without specific prior written permission.
16f1e85027SSimon Schubert.\"
17f1e85027SSimon Schubert.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18f1e85027SSimon Schubert.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19f1e85027SSimon Schubert.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20f1e85027SSimon Schubert.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21f1e85027SSimon Schubert.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22f1e85027SSimon Schubert.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23f1e85027SSimon Schubert.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24f1e85027SSimon Schubert.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25f1e85027SSimon Schubert.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26f1e85027SSimon Schubert.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27f1e85027SSimon Schubert.\" SUCH DAMAGE.
28f1e85027SSimon Schubert.\"
294696a7e0SJan Lentfer.Dd January 2, 2011
30f1e85027SSimon Schubert.Dt PF 4
31f1e85027SSimon Schubert.Os
32f1e85027SSimon Schubert.Sh NAME
33f1e85027SSimon Schubert.Nm pf
34f1e85027SSimon Schubert.Nd packet filter
35f1e85027SSimon Schubert.Sh SYNOPSIS
36f1e85027SSimon Schubert.Cd "device pf"
37f1e85027SSimon Schubert.Sh DESCRIPTION
38f1e85027SSimon SchubertPacket filtering takes place in the kernel.
39f1e85027SSimon SchubertA pseudo-device,
40f1e85027SSimon Schubert.Pa /dev/pf ,
41f1e85027SSimon Schubertallows userland processes to control the
42f1e85027SSimon Schubertbehavior of the packet filter through an
43f1e85027SSimon Schubert.Xr ioctl 2
44f1e85027SSimon Schubertinterface.
45f1e85027SSimon SchubertThere are commands to enable and disable the filter, load rulesets,
46f1e85027SSimon Schubertadd and remove individual rules or state table entries,
47f1e85027SSimon Schubertand retrieve statistics.
48f1e85027SSimon SchubertThe most commonly used functions are covered by
49f1e85027SSimon Schubert.Xr pfctl 8 .
50f1e85027SSimon Schubert.Pp
51f1e85027SSimon SchubertManipulations like loading a ruleset that involve more than a single
5270224baaSJan Lentfer.Xr ioctl 2
5370224baaSJan Lentfercall require a so-called
5470224baaSJan Lentfer.Em ticket ,
5570224baaSJan Lentferwhich prevents the occurrence of
56f1e85027SSimon Schubertmultiple concurrent manipulations.
57f1e85027SSimon Schubert.Pp
5870224baaSJan LentferFields of
59f1e85027SSimon Schubert.Xr ioctl 2
6070224baaSJan Lentferparameter structures that refer to packet data (like
6170224baaSJan Lentferaddresses and ports) are generally expected in network byte-order.
6270224baaSJan Lentfer.Pp
6370224baaSJan LentferRules and address tables are contained in so-called
6470224baaSJan Lentfer.Em anchors .
6570224baaSJan LentferWhen servicing an
6670224baaSJan Lentfer.Xr ioctl 2
6770224baaSJan Lentferrequest, if the anchor field of the argument structure is empty,
6870224baaSJan Lentferthe kernel will use the default anchor (i.e., the main ruleset)
6970224baaSJan Lentferin operations.
7070224baaSJan LentferAnchors are specified by name and may be nested, with components
7170224baaSJan Lentferseparated by
7270224baaSJan Lentfer.Sq /
7370224baaSJan Lentfercharacters, similar to how file system hierarchies are laid out.
7470224baaSJan LentferThe final component of the anchor path is the anchor under which
7570224baaSJan Lentferoperations will be performed.
7670224baaSJan Lentfer.Sh IOCTL INTERFACE
7770224baaSJan Lentfer.Nm
7870224baaSJan Lentfersupports the following
7970224baaSJan Lentfer.Xr ioctl 2
8070224baaSJan Lentfercommands, available through
8170224baaSJan Lentfer.Aq Pa net/pfvar.h :
82f1e85027SSimon Schubert.Bl -tag -width xxxxxx
83f1e85027SSimon Schubert.It Dv DIOCSTART
8470224baaSJan LentferStart the packet filter.
85f1e85027SSimon Schubert.It Dv DIOCSTOP
8670224baaSJan LentferStop the packet filter.
87f1e85027SSimon Schubert.It Dv DIOCSTARTALTQ
8870224baaSJan LentferStart the ALTQ bandwidth control system (see
8970224baaSJan Lentfer.Xr altq 9 ) .
90f1e85027SSimon Schubert.It Dv DIOCSTOPALTQ
9170224baaSJan LentferStop the ALTQ bandwidth control system.
9270224baaSJan Lentfer.It Dv DIOCBEGINADDRS Fa "struct pfioc_pooladdr *pp"
93f1e85027SSimon Schubert.Bd -literal
94f1e85027SSimon Schubertstruct pfioc_pooladdr {
95f1e85027SSimon Schubert	u_int32_t		action;
96f1e85027SSimon Schubert	u_int32_t		ticket;
97f1e85027SSimon Schubert	u_int32_t		nr;
98f1e85027SSimon Schubert	u_int32_t		r_num;
99f1e85027SSimon Schubert	u_int8_t		r_action;
100f1e85027SSimon Schubert	u_int8_t		r_last;
101f1e85027SSimon Schubert	u_int8_t		af;
10270224baaSJan Lentfer	char			anchor[MAXPATHLEN];
103f1e85027SSimon Schubert	struct pf_pooladdr	addr;
104f1e85027SSimon Schubert};
105f1e85027SSimon Schubert.Ed
106f1e85027SSimon Schubert.Pp
10770224baaSJan LentferClear the buffer address pool and get a
108f1e85027SSimon Schubert.Va ticket
109b1c94e87SSascha Wildnerfor subsequent
110b1c94e87SSascha Wildner.Dv DIOCADDADDR ,
11170224baaSJan Lentfer.Dv DIOCADDRULE ,
112b1c94e87SSascha Wildnerand
113b1c94e87SSascha Wildner.Dv DIOCCHANGERULE
114b1c94e87SSascha Wildnercalls.
11570224baaSJan Lentfer.It Dv DIOCADDADDR Fa "struct pfioc_pooladdr *pp"
116f1e85027SSimon Schubert.Pp
11770224baaSJan LentferAdd the pool address
118f1e85027SSimon Schubert.Va addr
119f1e85027SSimon Schubertto the buffer address pool to be used in the following
120b1c94e87SSascha Wildner.Dv DIOCADDRULE
121b1c94e87SSascha Wildneror
122b1c94e87SSascha Wildner.Dv DIOCCHANGERULE
123b1c94e87SSascha Wildnercall.
124f1e85027SSimon SchubertAll other members of the structure are ignored.
12570224baaSJan Lentfer.It Dv DIOCADDRULE Fa "struct pfioc_rule *pr"
126f1e85027SSimon Schubert.Bd -literal
127f1e85027SSimon Schubertstruct pfioc_rule {
128f1e85027SSimon Schubert	u_int32_t	action;
129f1e85027SSimon Schubert	u_int32_t	ticket;
130f1e85027SSimon Schubert	u_int32_t	pool_ticket;
131f1e85027SSimon Schubert	u_int32_t	nr;
13270224baaSJan Lentfer	char		anchor[MAXPATHLEN];
13370224baaSJan Lentfer	char		anchor_call[MAXPATHLEN];
134f1e85027SSimon Schubert	struct pf_rule	rule;
135f1e85027SSimon Schubert};
136f1e85027SSimon Schubert.Ed
137f1e85027SSimon Schubert.Pp
13870224baaSJan LentferAdd
139f1e85027SSimon Schubert.Va rule
140f1e85027SSimon Schubertat the end of the inactive ruleset.
14170224baaSJan LentferThis call requires a
142f1e85027SSimon Schubert.Va ticket
14370224baaSJan Lentferobtained through a preceding
144b1c94e87SSascha Wildner.Dv DIOCXBEGIN
14570224baaSJan Lentfercall and a
146f1e85027SSimon Schubert.Va pool_ticket
14770224baaSJan Lentferobtained through a
148b1c94e87SSascha Wildner.Dv DIOCBEGINADDRS
149b1c94e87SSascha Wildnercall.
150b1c94e87SSascha Wildner.Dv DIOCADDADDR
151b1c94e87SSascha Wildnermust also be called if any pool addresses are required.
152f1e85027SSimon SchubertThe optional
153f1e85027SSimon Schubert.Va anchor
15470224baaSJan Lentfername indicates the anchor in which to append the rule.
155f1e85027SSimon Schubert.Va nr
156f1e85027SSimon Schubertand
157f1e85027SSimon Schubert.Va action
158f1e85027SSimon Schubertare ignored.
15970224baaSJan Lentfer.It Dv DIOCADDALTQ Fa "struct pfioc_altq *pa"
16070224baaSJan LentferAdd an ALTQ discipline or queue.
161f1e85027SSimon Schubert.Bd -literal
162f1e85027SSimon Schubertstruct pfioc_altq {
163f1e85027SSimon Schubert	u_int32_t	action;
164f1e85027SSimon Schubert	u_int32_t	ticket;
165f1e85027SSimon Schubert	u_int32_t	nr;
166f1e85027SSimon Schubert	struct pf_altq  altq;
167f1e85027SSimon Schubert};
168f1e85027SSimon Schubert.Ed
16970224baaSJan Lentfer.It Dv DIOCGETRULES Fa "struct pfioc_rule *pr"
17070224baaSJan LentferGet a
171f1e85027SSimon Schubert.Va ticket
172b1c94e87SSascha Wildnerfor subsequent
173b1c94e87SSascha Wildner.Dv DIOCGETRULE
17470224baaSJan Lentfercalls and the number
175f1e85027SSimon Schubert.Va nr
176f1e85027SSimon Schubertof rules in the active ruleset.
17770224baaSJan Lentfer.It Dv DIOCGETRULE Fa "struct pfioc_rule *pr"
17870224baaSJan LentferGet a
179f1e85027SSimon Schubert.Va rule
18070224baaSJan Lentferby its number
181f1e85027SSimon Schubert.Va nr
18270224baaSJan Lentferusing the
183f1e85027SSimon Schubert.Va ticket
184b1c94e87SSascha Wildnerobtained through a preceding
185b1c94e87SSascha Wildner.Dv DIOCGETRULES
186b1c94e87SSascha Wildnercall.
18770224baaSJan LentferIf
18870224baaSJan Lentfer.Va action
18970224baaSJan Lentferis set to
19070224baaSJan Lentfer.Dv PF_GET_CLR_CNTR ,
19170224baaSJan Lentferthe per-rule statistics on the requested rule are cleared.
19270224baaSJan Lentfer.It Dv DIOCGETADDRS Fa "struct pfioc_pooladdr *pp"
19370224baaSJan LentferGet a
194f1e85027SSimon Schubert.Va ticket
195b1c94e87SSascha Wildnerfor subsequent
196b1c94e87SSascha Wildner.Dv DIOCGETADDR
19770224baaSJan Lentfercalls and the number
198f1e85027SSimon Schubert.Va nr
199f1e85027SSimon Schubertof pool addresses in the rule specified with
200f1e85027SSimon Schubert.Va r_action ,
201f1e85027SSimon Schubert.Va r_num ,
202f1e85027SSimon Schubertand
20370224baaSJan Lentfer.Va anchor .
20470224baaSJan Lentfer.It Dv DIOCGETADDR Fa "struct pfioc_pooladdr *pp"
20570224baaSJan LentferGet the pool address
206f1e85027SSimon Schubert.Va addr
20770224baaSJan Lentferby its number
208f1e85027SSimon Schubert.Va nr
209f1e85027SSimon Schubertfrom the rule specified with
210f1e85027SSimon Schubert.Va r_action ,
211f1e85027SSimon Schubert.Va r_num ,
212f1e85027SSimon Schubertand
21370224baaSJan Lentfer.Va anchor
21470224baaSJan Lentferusing the
215f1e85027SSimon Schubert.Va ticket
216b1c94e87SSascha Wildnerobtained through a preceding
217b1c94e87SSascha Wildner.Dv DIOCGETADDRS
218b1c94e87SSascha Wildnercall.
21970224baaSJan Lentfer.It Dv DIOCGETALTQS Fa "struct pfioc_altq *pa"
22070224baaSJan LentferGet a
221f1e85027SSimon Schubert.Va ticket
222b1c94e87SSascha Wildnerfor subsequent
223b1c94e87SSascha Wildner.Dv DIOCGETALTQ
22470224baaSJan Lentfercalls and the number
225f1e85027SSimon Schubert.Va nr
226f1e85027SSimon Schubertof queues in the active list.
22770224baaSJan Lentfer.It Dv DIOCGETALTQ Fa "struct pfioc_altq *pa"
22870224baaSJan LentferGet the queueing discipline
229f1e85027SSimon Schubert.Va altq
23070224baaSJan Lentferby its number
231f1e85027SSimon Schubert.Va nr
23270224baaSJan Lentferusing the
233f1e85027SSimon Schubert.Va ticket
234b1c94e87SSascha Wildnerobtained through a preceding
235b1c94e87SSascha Wildner.Dv DIOCGETALTQS
236b1c94e87SSascha Wildnercall.
23770224baaSJan Lentfer.It Dv DIOCGETQSTATS Fa "struct pfioc_qstats *pq"
23870224baaSJan LentferGet the statistics on a queue.
239f1e85027SSimon Schubert.Bd -literal
240f1e85027SSimon Schubertstruct pfioc_qstats {
241f1e85027SSimon Schubert	u_int32_t	 ticket;
242f1e85027SSimon Schubert	u_int32_t	 nr;
243f1e85027SSimon Schubert	void		*buf;
244f1e85027SSimon Schubert	int		 nbytes;
245f1e85027SSimon Schubert	u_int8_t	 scheduler;
246f1e85027SSimon Schubert};
247f1e85027SSimon Schubert.Ed
248f1e85027SSimon Schubert.Pp
24970224baaSJan LentferThis call fills in a pointer to the buffer of statistics
25070224baaSJan Lentfer.Va buf ,
251f1e85027SSimon Schubertof length
25270224baaSJan Lentfer.Va nbytes ,
253f1e85027SSimon Schubertfor the queue specified by
254f1e85027SSimon Schubert.Va nr .
25570224baaSJan Lentfer.It Dv DIOCGETRULESETS Fa "struct pfioc_ruleset *pr"
25670224baaSJan Lentfer.Bd -literal
25770224baaSJan Lentferstruct pfioc_ruleset {
25870224baaSJan Lentfer	u_int32_t	 nr;
25970224baaSJan Lentfer	char		 path[MAXPATHLEN];
26070224baaSJan Lentfer	char		 name[PF_ANCHOR_NAME_SIZE];
26170224baaSJan Lentfer};
26270224baaSJan Lentfer.Ed
26370224baaSJan Lentfer.Pp
26470224baaSJan LentferGet the number
26570224baaSJan Lentfer.Va nr
26670224baaSJan Lentferof rulesets (i.e., anchors) directly attached to the anchor named by
26770224baaSJan Lentfer.Va path
26870224baaSJan Lentferfor use in subsequent
26970224baaSJan Lentfer.Dv DIOCGETRULESET
27070224baaSJan Lentfercalls.
27170224baaSJan LentferNested anchors, since they are not directly attached to the given
27270224baaSJan Lentferanchor, will not be included.
27370224baaSJan LentferThis ioctl returns
27470224baaSJan Lentfer.Er EINVAL
27570224baaSJan Lentferif the given anchor does not exist.
27670224baaSJan Lentfer.It Dv DIOCGETRULESET Fa "struct pfioc_ruleset *pr"
27770224baaSJan LentferGet a ruleset (i.e., an anchor)
27870224baaSJan Lentfer.Va name
27970224baaSJan Lentferby its number
28070224baaSJan Lentfer.Va nr
28170224baaSJan Lentferfrom the given anchor
28270224baaSJan Lentfer.Va path ,
28370224baaSJan Lentferthe maximum number of which can be obtained from a preceding
28470224baaSJan Lentfer.Dv DIOCGETRULESETS
28570224baaSJan Lentfercall.
28670224baaSJan LentferThis ioctl returns
28770224baaSJan Lentfer.Er EINVAL
28870224baaSJan Lentferif the given anchor does not exist or
28970224baaSJan Lentfer.Er EBUSY
29070224baaSJan Lentferif another process is concurrently updating a ruleset.
29170224baaSJan Lentfer.It Dv DIOCADDSTATE Fa "struct pfioc_state *ps"
29270224baaSJan LentferAdd a state entry.
293f1e85027SSimon Schubert.Bd -literal
294f1e85027SSimon Schubertstruct pfioc_state {
2954696a7e0SJan Lentfer	struct pfsync_state	state;
296f1e85027SSimon Schubert};
297f1e85027SSimon Schubert.Ed
29870224baaSJan Lentfer.It Dv DIOCGETSTATE Fa "struct pfioc_state *ps"
2994696a7e0SJan LentferExtract the entry identified by the
3004696a7e0SJan Lentfer.Va id
3014696a7e0SJan Lentferand
3024696a7e0SJan Lentfer.Va creatorid
3034696a7e0SJan Lentferfields of the
3044696a7e0SJan Lentfer.Va state
3054696a7e0SJan Lentferstructure from the state table.
30670224baaSJan Lentfer.It Dv DIOCKILLSTATES Fa "struct pfioc_state_kill *psk"
30770224baaSJan LentferRemove matching entries from the state table.
30870224baaSJan LentferThis ioctl returns the number of killed states in
30970224baaSJan Lentfer.Va psk_af .
310f1e85027SSimon Schubert.Bd -literal
311f1e85027SSimon Schubertstruct pfioc_state_kill {
31270224baaSJan Lentfer	sa_family_t		psk_af;
313f1e85027SSimon Schubert	int			psk_proto;
314f1e85027SSimon Schubert	struct pf_rule_addr	psk_src;
315f1e85027SSimon Schubert	struct pf_rule_addr	psk_dst;
316f1e85027SSimon Schubert	char			psk_ifname[IFNAMSIZ];
317f1e85027SSimon Schubert};
318f1e85027SSimon Schubert.Ed
31970224baaSJan Lentfer.It Dv DIOCCLRSTATES Fa "struct pfioc_state_kill *psk"
32070224baaSJan LentferClear all states.
321f1e85027SSimon SchubertIt works like
322f1e85027SSimon Schubert.Dv DIOCKILLSTATES ,
32370224baaSJan Lentferbut ignores the
32470224baaSJan Lentfer.Va psk_af ,
32570224baaSJan Lentfer.Va psk_proto ,
32670224baaSJan Lentfer.Va psk_src ,
32770224baaSJan Lentferand
32870224baaSJan Lentfer.Va psk_dst
32970224baaSJan Lentferfields of the
33070224baaSJan Lentfer.Vt pfioc_state_kill
331f1e85027SSimon Schubertstructure.
33270224baaSJan Lentfer.It Dv DIOCSETSTATUSIF Fa "struct pfioc_if *pi"
33370224baaSJan LentferSpecify the interface for which statistics are accumulated.
334f1e85027SSimon Schubert.Bd -literal
335f1e85027SSimon Schubertstruct pfioc_if {
336f1e85027SSimon Schubert	char		 ifname[IFNAMSIZ];
337f1e85027SSimon Schubert};
338f1e85027SSimon Schubert.Ed
33970224baaSJan Lentfer.It Dv DIOCGETSTATUS Fa "struct pf_status *s"
34070224baaSJan LentferGet the internal packet filter statistics.
341f1e85027SSimon Schubert.Bd -literal
342f1e85027SSimon Schubertstruct pf_status {
343f1e85027SSimon Schubert	u_int64_t	counters[PFRES_MAX];
34470224baaSJan Lentfer	u_int64_t	lcounters[LCNT_MAX];
345f1e85027SSimon Schubert	u_int64_t	fcounters[FCNT_MAX];
346f1e85027SSimon Schubert	u_int64_t	scounters[SCNT_MAX];
347f1e85027SSimon Schubert	u_int64_t	pcounters[2][2][3];
348f1e85027SSimon Schubert	u_int64_t	bcounters[2][2];
3494696a7e0SJan Lentfer	u_int64_t	stateid;
350f1e85027SSimon Schubert	u_int32_t	running;
351f1e85027SSimon Schubert	u_int32_t	states;
352f1e85027SSimon Schubert	u_int32_t	src_nodes;
353f1e85027SSimon Schubert	u_int32_t	since;
354f1e85027SSimon Schubert	u_int32_t	debug;
3554696a7e0SJan Lentfer	u_int32_t	hostid;
356f1e85027SSimon Schubert	char		ifname[IFNAMSIZ];
35770224baaSJan Lentfer	u_int8_t	pf_chksum[MD5_DIGEST_LENGTH];
358f1e85027SSimon Schubert};
359f1e85027SSimon Schubert.Ed
360f1e85027SSimon Schubert.It Dv DIOCCLRSTATUS
36170224baaSJan LentferClear the internal packet filter statistics.
36270224baaSJan Lentfer.It Dv DIOCNATLOOK Fa "struct pfioc_natlook *pnl"
36370224baaSJan LentferLook up a state table entry by source and destination addresses and ports.
364f1e85027SSimon Schubert.Bd -literal
365f1e85027SSimon Schubertstruct pfioc_natlook {
366f1e85027SSimon Schubert	struct pf_addr	 saddr;
367f1e85027SSimon Schubert	struct pf_addr	 daddr;
368f1e85027SSimon Schubert	struct pf_addr	 rsaddr;
369f1e85027SSimon Schubert	struct pf_addr	 rdaddr;
370f1e85027SSimon Schubert	u_int16_t	 sport;
371f1e85027SSimon Schubert	u_int16_t	 dport;
372f1e85027SSimon Schubert	u_int16_t	 rsport;
373f1e85027SSimon Schubert	u_int16_t	 rdport;
374f1e85027SSimon Schubert	sa_family_t	 af;
375f1e85027SSimon Schubert	u_int8_t	 proto;
376f1e85027SSimon Schubert	u_int8_t	 direction;
377f1e85027SSimon Schubert};
378f1e85027SSimon Schubert.Ed
37970224baaSJan Lentfer.It Dv DIOCSETDEBUG Fa "u_int32_t *level"
38070224baaSJan LentferSet the debug level.
381f1e85027SSimon Schubert.Bd -literal
38270224baaSJan Lentferenum	{ PF_DEBUG_NONE, PF_DEBUG_URGENT, PF_DEBUG_MISC,
38370224baaSJan Lentfer	  PF_DEBUG_NOISY };
384f1e85027SSimon Schubert.Ed
38570224baaSJan Lentfer.It Dv DIOCGETSTATES Fa "struct pfioc_states *ps"
38670224baaSJan LentferGet state table entries.
387f1e85027SSimon Schubert.Bd -literal
388f1e85027SSimon Schubertstruct pfioc_states {
389f1e85027SSimon Schubert	int	ps_len;
390f1e85027SSimon Schubert	union {
391f1e85027SSimon Schubert		caddr_t		 psu_buf;
392f1e85027SSimon Schubert		struct pf_state *psu_states;
393f1e85027SSimon Schubert	} ps_u;
394f1e85027SSimon Schubert#define ps_buf		ps_u.psu_buf
395f1e85027SSimon Schubert#define ps_states	ps_u.psu_states
396f1e85027SSimon Schubert};
397f1e85027SSimon Schubert.Ed
39870224baaSJan Lentfer.Pp
39970224baaSJan LentferIf
40070224baaSJan Lentfer.Va ps_len
40170224baaSJan Lentferis non-zero on entry, as many states as possible that can fit into this
40270224baaSJan Lentfersize will be copied into the supplied buffer
40370224baaSJan Lentfer.Va ps_states .
40470224baaSJan LentferOn exit,
40570224baaSJan Lentfer.Va ps_len
40670224baaSJan Lentferis always set to the total size required to hold all state table entries
40770224baaSJan Lentfer(i.e., it is set to
40870224baaSJan Lentfer.Li sizeof(struct pf_state) * nr ) .
40970224baaSJan Lentfer.It Dv DIOCCHANGERULE Fa "struct pfioc_rule *pcr"
41070224baaSJan LentferAdd or remove the
411f1e85027SSimon Schubert.Va rule
412f1e85027SSimon Schubertin the ruleset specified by
413f1e85027SSimon Schubert.Va rule.action .
414f1e85027SSimon Schubert.Pp
415f1e85027SSimon SchubertThe type of operation to be performed is indicated by
41670224baaSJan Lentfer.Va action ,
41770224baaSJan Lentferwhich can be any of the following:
41870224baaSJan Lentfer.Bd -literal
41970224baaSJan Lentferenum	{ PF_CHANGE_NONE, PF_CHANGE_ADD_HEAD, PF_CHANGE_ADD_TAIL,
42070224baaSJan Lentfer	  PF_CHANGE_ADD_BEFORE, PF_CHANGE_ADD_AFTER,
42170224baaSJan Lentfer	  PF_CHANGE_REMOVE, PF_CHANGE_GET_TICKET };
42270224baaSJan Lentfer.Ed
423f1e85027SSimon Schubert.Pp
424f1e85027SSimon Schubert.Va ticket
42570224baaSJan Lentfermust be set to the value obtained with
42670224baaSJan Lentfer.Dv PF_CHANGE_GET_TICKET
42770224baaSJan Lentferfor all actions except
42870224baaSJan Lentfer.Dv PF_CHANGE_GET_TICKET .
429f1e85027SSimon Schubert.Va pool_ticket
430b1c94e87SSascha Wildnermust be set to the value obtained with the
431b1c94e87SSascha Wildner.Dv DIOCBEGINADDRS
43270224baaSJan Lentfercall for all actions except
43370224baaSJan Lentfer.Dv PF_CHANGE_REMOVE
434f1e85027SSimon Schubertand
43570224baaSJan Lentfer.Dv PF_CHANGE_GET_TICKET .
43670224baaSJan Lentfer.Va anchor
43770224baaSJan Lentferindicates to which anchor the operation applies.
438f1e85027SSimon Schubert.Va nr
43970224baaSJan Lentferindicates the rule number against which
44070224baaSJan Lentfer.Dv PF_CHANGE_ADD_BEFORE ,
44170224baaSJan Lentfer.Dv PF_CHANGE_ADD_AFTER ,
44270224baaSJan Lentferor
44370224baaSJan Lentfer.Dv PF_CHANGE_REMOVE
44470224baaSJan Lentferactions are applied.
44570224baaSJan Lentfer.\" It Dv DIOCCHANGEALTQ Fa "struct pfioc_altq *pcr"
44670224baaSJan Lentfer.It Dv DIOCCHANGEADDR Fa "struct pfioc_pooladdr *pca"
44770224baaSJan LentferAdd or remove the pool address
448f1e85027SSimon Schubert.Va addr
44970224baaSJan Lentferfrom the rule specified by
450f1e85027SSimon Schubert.Va r_action ,
451f1e85027SSimon Schubert.Va r_num ,
452f1e85027SSimon Schubertand
45370224baaSJan Lentfer.Va anchor .
45470224baaSJan Lentfer.It Dv DIOCSETTIMEOUT Fa "struct pfioc_tm *pt"
455f1e85027SSimon Schubert.Bd -literal
456f1e85027SSimon Schubertstruct pfioc_tm {
457f1e85027SSimon Schubert	int		 timeout;
458f1e85027SSimon Schubert	int		 seconds;
459f1e85027SSimon Schubert};
460f1e85027SSimon Schubert.Ed
46170224baaSJan Lentfer.Pp
46270224baaSJan LentferSet the state timeout of
46370224baaSJan Lentfer.Va timeout
46470224baaSJan Lentferto
46570224baaSJan Lentfer.Va seconds .
46670224baaSJan LentferThe old value will be placed into
46770224baaSJan Lentfer.Va seconds .
46870224baaSJan LentferFor possible values of
46970224baaSJan Lentfer.Va timeout ,
47070224baaSJan Lentferconsult the
47170224baaSJan Lentfer.Dv PFTM_*
47270224baaSJan Lentfervalues in
47370224baaSJan Lentfer.Aq Pa net/pfvar.h .
47470224baaSJan Lentfer.It Dv DIOCGETTIMEOUT Fa "struct pfioc_tm *pt"
47570224baaSJan LentferGet the state timeout of
47670224baaSJan Lentfer.Va timeout .
47770224baaSJan LentferThe value will be placed into the
47870224baaSJan Lentfer.Va seconds
47970224baaSJan Lentferfield.
480f1e85027SSimon Schubert.It Dv DIOCCLRRULECTRS
481f1e85027SSimon SchubertClear per-rule statistics.
48270224baaSJan Lentfer.It Dv DIOCSETLIMIT Fa "struct pfioc_limit *pl"
48370224baaSJan LentferSet the hard limits on the memory pools used by the packet filter.
484f1e85027SSimon Schubert.Bd -literal
485f1e85027SSimon Schubertstruct pfioc_limit {
486f1e85027SSimon Schubert	int		index;
487f1e85027SSimon Schubert	unsigned	limit;
488f1e85027SSimon Schubert};
48970224baaSJan Lentfer
49070224baaSJan Lentferenum	{ PF_LIMIT_STATES, PF_LIMIT_SRC_NODES, PF_LIMIT_FRAGS,
49170224baaSJan Lentfer	  PF_LIMIT_TABLES, PF_LIMIT_TABLE_ENTRIES, PF_LIMIT_MAX };
492f1e85027SSimon Schubert.Ed
49370224baaSJan Lentfer.It Dv DIOCGETLIMIT Fa "struct pfioc_limit *pl"
49470224baaSJan LentferGet the hard
49570224baaSJan Lentfer.Va limit
49670224baaSJan Lentferfor the memory pool indicated by
49770224baaSJan Lentfer.Va index .
49870224baaSJan Lentfer.It Dv DIOCRCLRTABLES Fa "struct pfioc_table *io"
499f1e85027SSimon SchubertClear all tables.
50070224baaSJan LentferAll the ioctls that manipulate radix tables
501f1e85027SSimon Schubertuse the same structure described below.
502f1e85027SSimon SchubertFor
50370224baaSJan Lentfer.Dv DIOCRCLRTABLES ,
50470224baaSJan Lentfer.Va pfrio_ndel
50570224baaSJan Lentfercontains on exit the number of tables deleted.
506f1e85027SSimon Schubert.Bd -literal
507f1e85027SSimon Schubertstruct pfioc_table {
508f1e85027SSimon Schubert	struct pfr_table	 pfrio_table;
509f1e85027SSimon Schubert	void			*pfrio_buffer;
510f1e85027SSimon Schubert	int			 pfrio_esize;
511f1e85027SSimon Schubert	int			 pfrio_size;
512f1e85027SSimon Schubert	int			 pfrio_size2;
513f1e85027SSimon Schubert	int			 pfrio_nadd;
514f1e85027SSimon Schubert	int			 pfrio_ndel;
515f1e85027SSimon Schubert	int			 pfrio_nchange;
516f1e85027SSimon Schubert	int			 pfrio_flags;
51770224baaSJan Lentfer	u_int32_t		 pfrio_ticket;
518f1e85027SSimon Schubert};
519f1e85027SSimon Schubert#define pfrio_exists    pfrio_nadd
520f1e85027SSimon Schubert#define pfrio_nzero     pfrio_nadd
521f1e85027SSimon Schubert#define pfrio_nmatch    pfrio_nadd
522f1e85027SSimon Schubert#define pfrio_naddr     pfrio_size2
523f1e85027SSimon Schubert#define pfrio_setflag   pfrio_size2
524f1e85027SSimon Schubert#define pfrio_clrflag   pfrio_nadd
525f1e85027SSimon Schubert.Ed
52670224baaSJan Lentfer.It Dv DIOCRADDTABLES Fa "struct pfioc_table *io"
52770224baaSJan LentferCreate one or more tables.
52870224baaSJan LentferOn entry,
52970224baaSJan Lentfer.Va pfrio_buffer
53070224baaSJan Lentfermust point to an array of
53170224baaSJan Lentfer.Vt struct pfr_table
53270224baaSJan Lentfercontaining at least
53370224baaSJan Lentfer.Vt pfrio_size
53470224baaSJan Lentferelements.
53570224baaSJan Lentfer.Vt pfrio_esize
53670224baaSJan Lentfermust be the size of
53770224baaSJan Lentfer.Vt struct pfr_table .
53870224baaSJan LentferOn exit,
53970224baaSJan Lentfer.Va pfrio_nadd
54070224baaSJan Lentfercontains the number of tables effectively created.
541f1e85027SSimon Schubert.Bd -literal
542f1e85027SSimon Schubertstruct pfr_table {
54370224baaSJan Lentfer	char		pfrt_anchor[MAXPATHLEN];
544f1e85027SSimon Schubert	char		pfrt_name[PF_TABLE_NAME_SIZE];
545f1e85027SSimon Schubert	u_int32_t	pfrt_flags;
546f1e85027SSimon Schubert	u_int8_t	pfrt_fback;
547f1e85027SSimon Schubert};
548f1e85027SSimon Schubert.Ed
54970224baaSJan Lentfer.It Dv DIOCRDELTABLES Fa "struct pfioc_table *io"
55070224baaSJan LentferDelete one or more tables.
55170224baaSJan LentferOn entry,
55270224baaSJan Lentfer.Va pfrio_buffer
55370224baaSJan Lentfermust point to an array of
55470224baaSJan Lentfer.Vt struct pfr_table
55570224baaSJan Lentfercontaining at least
55670224baaSJan Lentfer.Vt pfrio_size
55770224baaSJan Lentferelements.
55870224baaSJan Lentfer.Vt pfrio_esize
55970224baaSJan Lentfermust be the size of
56070224baaSJan Lentfer.Vt struct pfr_table .
56170224baaSJan LentferOn exit,
56270224baaSJan Lentfer.Va pfrio_ndel
56370224baaSJan Lentfercontains the number of tables effectively deleted.
56470224baaSJan Lentfer.It Dv DIOCRGETTABLES Fa "struct pfioc_table *io"
565f1e85027SSimon SchubertGet the list of all tables.
56670224baaSJan LentferOn entry,
56770224baaSJan Lentfer.Va pfrio_buffer[pfrio_size]
56870224baaSJan Lentfercontains a valid writeable buffer for
56970224baaSJan Lentfer.Vt pfr_table
57070224baaSJan Lentferstructures.
57170224baaSJan LentferOn exit,
57270224baaSJan Lentfer.Va pfrio_size
57370224baaSJan Lentfercontains the number of tables written into the buffer.
574f1e85027SSimon SchubertIf the buffer is too small, the kernel does not store anything but just
575f1e85027SSimon Schubertreturns the required buffer size, without error.
57670224baaSJan Lentfer.It Dv DIOCRGETTSTATS Fa "struct pfioc_table *io"
57770224baaSJan LentferThis call is like
57870224baaSJan Lentfer.Dv DIOCRGETTABLES
57970224baaSJan Lentferbut is used to get an array of
58070224baaSJan Lentfer.Vt pfr_tstats
58170224baaSJan Lentferstructures.
582f1e85027SSimon Schubert.Bd -literal
583f1e85027SSimon Schubertstruct pfr_tstats {
584f1e85027SSimon Schubert	struct pfr_table pfrts_t;
585f1e85027SSimon Schubert	u_int64_t	 pfrts_packets
586f1e85027SSimon Schubert			     [PFR_DIR_MAX][PFR_OP_TABLE_MAX];
587f1e85027SSimon Schubert	u_int64_t	 pfrts_bytes
588f1e85027SSimon Schubert			     [PFR_DIR_MAX][PFR_OP_TABLE_MAX];
589f1e85027SSimon Schubert	u_int64_t	 pfrts_match;
590f1e85027SSimon Schubert	u_int64_t	 pfrts_nomatch;
591f1e85027SSimon Schubert	long		 pfrts_tzero;
592f1e85027SSimon Schubert	int		 pfrts_cnt;
593f1e85027SSimon Schubert	int		 pfrts_refcnt[PFR_REFCNT_MAX];
594f1e85027SSimon Schubert};
595f1e85027SSimon Schubert#define pfrts_name	 pfrts_t.pfrt_name
596f1e85027SSimon Schubert#define pfrts_flags	 pfrts_t.pfrt_flags
597f1e85027SSimon Schubert.Ed
59870224baaSJan Lentfer.It Dv DIOCRCLRTSTATS Fa "struct pfioc_table *io"
59970224baaSJan LentferClear the statistics of one or more tables.
60070224baaSJan LentferOn entry,
60170224baaSJan Lentfer.Va pfrio_buffer
60270224baaSJan Lentfermust point to an array of
60370224baaSJan Lentfer.Vt struct pfr_table
60470224baaSJan Lentfercontaining at least
60570224baaSJan Lentfer.Vt pfrio_size
60670224baaSJan Lentferelements.
60770224baaSJan Lentfer.Vt pfrio_esize
60870224baaSJan Lentfermust be the size of
60970224baaSJan Lentfer.Vt struct pfr_table .
61070224baaSJan LentferOn exit,
61170224baaSJan Lentfer.Va pfrio_nzero
61270224baaSJan Lentfercontains the number of tables effectively cleared.
61370224baaSJan Lentfer.It Dv DIOCRCLRADDRS Fa "struct pfioc_table *io"
614f1e85027SSimon SchubertClear all addresses in a table.
61570224baaSJan LentferOn entry,
61670224baaSJan Lentfer.Va pfrio_table
61770224baaSJan Lentfercontains the table to clear.
61870224baaSJan LentferOn exit,
61970224baaSJan Lentfer.Va pfrio_ndel
62070224baaSJan Lentfercontains the number of addresses removed.
62170224baaSJan Lentfer.It Dv DIOCRADDADDRS Fa "struct pfioc_table *io"
622f1e85027SSimon SchubertAdd one or more addresses to a table.
62370224baaSJan LentferOn entry,
62470224baaSJan Lentfer.Va pfrio_table
62570224baaSJan Lentfercontains the table ID and
62670224baaSJan Lentfer.Va pfrio_buffer
62770224baaSJan Lentfermust point to an array of
62870224baaSJan Lentfer.Vt struct pfr_addr
62970224baaSJan Lentfercontaining at least
63070224baaSJan Lentfer.Vt pfrio_size
63170224baaSJan Lentferelements to add to the table.
63270224baaSJan Lentfer.Vt pfrio_esize
63370224baaSJan Lentfermust be the size of
63470224baaSJan Lentfer.Vt struct pfr_addr .
63570224baaSJan LentferOn exit,
63670224baaSJan Lentfer.Va pfrio_nadd
63770224baaSJan Lentfercontains the number of addresses effectively added.
638f1e85027SSimon Schubert.Bd -literal
639f1e85027SSimon Schubertstruct pfr_addr {
640f1e85027SSimon Schubert	union {
641f1e85027SSimon Schubert		struct in_addr	 _pfra_ip4addr;
642f1e85027SSimon Schubert		struct in6_addr	 _pfra_ip6addr;
643f1e85027SSimon Schubert	}		 pfra_u;
644f1e85027SSimon Schubert	u_int8_t	 pfra_af;
645f1e85027SSimon Schubert	u_int8_t	 pfra_net;
646f1e85027SSimon Schubert	u_int8_t	 pfra_not;
647f1e85027SSimon Schubert	u_int8_t	 pfra_fback;
648f1e85027SSimon Schubert};
649f1e85027SSimon Schubert#define pfra_ip4addr    pfra_u._pfra_ip4addr
650f1e85027SSimon Schubert#define pfra_ip6addr    pfra_u._pfra_ip6addr
651f1e85027SSimon Schubert.Ed
65270224baaSJan Lentfer.It Dv DIOCRDELADDRS Fa "struct pfioc_table *io"
653f1e85027SSimon SchubertDelete one or more addresses from a table.
65470224baaSJan LentferOn entry,
65570224baaSJan Lentfer.Va pfrio_table
65670224baaSJan Lentfercontains the table ID and
65770224baaSJan Lentfer.Va pfrio_buffer
65870224baaSJan Lentfermust point to an array of
65970224baaSJan Lentfer.Vt struct pfr_addr
66070224baaSJan Lentfercontaining at least
66170224baaSJan Lentfer.Vt pfrio_size
66270224baaSJan Lentferelements to delete from the table.
66370224baaSJan Lentfer.Vt pfrio_esize
66470224baaSJan Lentfermust be the size of
66570224baaSJan Lentfer.Vt struct pfr_addr .
66670224baaSJan LentferOn exit,
66770224baaSJan Lentfer.Va pfrio_ndel
66870224baaSJan Lentfercontains the number of addresses effectively deleted.
66970224baaSJan Lentfer.It Dv DIOCRSETADDRS Fa "struct pfioc_table *io"
670f1e85027SSimon SchubertReplace the content of a table by a new address list.
671f1e85027SSimon SchubertThis is the most complicated command, which uses all the structure members.
67270224baaSJan Lentfer.Pp
67370224baaSJan LentferOn entry,
67470224baaSJan Lentfer.Va pfrio_table
67570224baaSJan Lentfercontains the table ID and
67670224baaSJan Lentfer.Va pfrio_buffer
67770224baaSJan Lentfermust point to an array of
67870224baaSJan Lentfer.Vt struct pfr_addr
67970224baaSJan Lentfercontaining at least
68070224baaSJan Lentfer.Vt pfrio_size
68170224baaSJan Lentferelements which become the new contents of the table.
68270224baaSJan Lentfer.Vt pfrio_esize
68370224baaSJan Lentfermust be the size of
68470224baaSJan Lentfer.Vt struct pfr_addr .
68570224baaSJan LentferAdditionally, if
68670224baaSJan Lentfer.Va pfrio_size2
68770224baaSJan Lentferis non-zero,
68870224baaSJan Lentfer.Va pfrio_buffer[pfrio_size..pfrio_size2]
68970224baaSJan Lentfermust be a writeable buffer, into which the kernel can copy the
69070224baaSJan Lentferaddresses that have been deleted during the replace operation.
69170224baaSJan LentferOn exit,
69270224baaSJan Lentfer.Va pfrio_ndel ,
69370224baaSJan Lentfer.Va pfrio_nadd ,
69470224baaSJan Lentferand
69570224baaSJan Lentfer.Va pfrio_nchange
69670224baaSJan Lentfercontain the number of addresses deleted, added, and changed by the
69770224baaSJan Lentferkernel.
69870224baaSJan LentferIf
69970224baaSJan Lentfer.Va pfrio_size2
70070224baaSJan Lentferwas set on entry,
70170224baaSJan Lentfer.Va pfrio_size2
70270224baaSJan Lentferwill point to the size of the buffer used, exactly like
703f1e85027SSimon Schubert.Dv DIOCRGETADDRS .
70470224baaSJan Lentfer.It Dv DIOCRGETADDRS Fa "struct pfioc_table *io"
705f1e85027SSimon SchubertGet all the addresses of a table.
70670224baaSJan LentferOn entry,
70770224baaSJan Lentfer.Va pfrio_table
70870224baaSJan Lentfercontains the table ID and
70970224baaSJan Lentfer.Va pfrio_buffer[pfrio_size]
71070224baaSJan Lentfercontains a valid writeable buffer for
71170224baaSJan Lentfer.Vt pfr_addr
71270224baaSJan Lentferstructures.
71370224baaSJan LentferOn exit,
71470224baaSJan Lentfer.Va pfrio_size
71570224baaSJan Lentfercontains the number of addresses written into the buffer.
716f1e85027SSimon SchubertIf the buffer was too small, the kernel does not store anything but just
71770224baaSJan Lentferreturns the required buffer size, without returning an error.
71870224baaSJan Lentfer.It Dv DIOCRGETASTATS Fa "struct pfioc_table *io"
71970224baaSJan LentferThis call is like
72070224baaSJan Lentfer.Dv DIOCRGETADDRS
72170224baaSJan Lentferbut is used to get an array of
72270224baaSJan Lentfer.Vt pfr_astats
72370224baaSJan Lentferstructures.
724f1e85027SSimon Schubert.Bd -literal
725f1e85027SSimon Schubertstruct pfr_astats {
726f1e85027SSimon Schubert	struct pfr_addr	 pfras_a;
727f1e85027SSimon Schubert	u_int64_t	 pfras_packets
728f1e85027SSimon Schubert			     [PFR_DIR_MAX][PFR_OP_ADDR_MAX];
729f1e85027SSimon Schubert	u_int64_t	 pfras_bytes
730f1e85027SSimon Schubert			     [PFR_DIR_MAX][PFR_OP_ADDR_MAX];
731f1e85027SSimon Schubert	long		 pfras_tzero;
732f1e85027SSimon Schubert};
733f1e85027SSimon Schubert.Ed
73470224baaSJan Lentfer.It Dv DIOCRCLRASTATS Fa "struct pfioc_table *io"
73570224baaSJan LentferClear the statistics of one or more addresses.
73670224baaSJan LentferOn entry,
73770224baaSJan Lentfer.Va pfrio_table
73870224baaSJan Lentfercontains the table ID and
73970224baaSJan Lentfer.Va pfrio_buffer
74070224baaSJan Lentfermust point to an array of
74170224baaSJan Lentfer.Vt struct pfr_addr
74270224baaSJan Lentfercontaining at least
74370224baaSJan Lentfer.Vt pfrio_size
74470224baaSJan Lentferelements to be cleared from the table.
74570224baaSJan Lentfer.Vt pfrio_esize
74670224baaSJan Lentfermust be the size of
74770224baaSJan Lentfer.Vt struct pfr_addr .
74870224baaSJan LentferOn exit,
74970224baaSJan Lentfer.Va pfrio_nzero
75070224baaSJan Lentfercontains the number of addresses effectively cleared.
75170224baaSJan Lentfer.It Dv DIOCRTSTADDRS Fa "struct pfioc_table *io"
752f1e85027SSimon SchubertTest if the given addresses match a table.
75370224baaSJan LentferOn entry,
75470224baaSJan Lentfer.Va pfrio_table
75570224baaSJan Lentfercontains the table ID and
75670224baaSJan Lentfer.Va pfrio_buffer
75770224baaSJan Lentfermust point to an array of
75870224baaSJan Lentfer.Vt struct pfr_addr
75970224baaSJan Lentfercontaining at least
76070224baaSJan Lentfer.Vt pfrio_size
76170224baaSJan Lentferelements, each of which will be tested for a match in the table.
76270224baaSJan Lentfer.Vt pfrio_esize
76370224baaSJan Lentfermust be the size of
76470224baaSJan Lentfer.Vt struct pfr_addr .
76570224baaSJan LentferOn exit, the kernel updates the
76670224baaSJan Lentfer.Vt pfr_addr
76770224baaSJan Lentferarray by setting the
76870224baaSJan Lentfer.Va pfra_fback
769f1e85027SSimon Schubertmember appropriately.
77070224baaSJan Lentfer.It Dv DIOCRSETTFLAGS Fa "struct pfioc_table *io"
771f1e85027SSimon SchubertChange the
77270224baaSJan Lentfer.Dv PFR_TFLAG_CONST
773f1e85027SSimon Schubertor
77470224baaSJan Lentfer.Dv PFR_TFLAG_PERSIST
77570224baaSJan Lentferflags of a table.
77670224baaSJan LentferOn entry,
77770224baaSJan Lentfer.Va pfrio_buffer
77870224baaSJan Lentfermust point to an array of
77970224baaSJan Lentfer.Vt struct pfr_table
78070224baaSJan Lentfercontaining at least
78170224baaSJan Lentfer.Vt pfrio_size
78270224baaSJan Lentferelements.
78370224baaSJan Lentfer.Va pfrio_esize
78470224baaSJan Lentfermust be the size of
78570224baaSJan Lentfer.Vt struct pfr_table .
78670224baaSJan Lentfer.Va pfrio_setflag
78770224baaSJan Lentfermust contain the flags to add, while
78870224baaSJan Lentfer.Va pfrio_clrflag
78970224baaSJan Lentfermust contain the flags to remove.
79070224baaSJan LentferOn exit,
79170224baaSJan Lentfer.Va pfrio_nchange
79270224baaSJan Lentferand
79370224baaSJan Lentfer.Va pfrio_ndel
79470224baaSJan Lentfercontain the number of tables altered or deleted by the kernel.
795f1e85027SSimon SchubertYes, tables can be deleted if one removes the
79670224baaSJan Lentfer.Dv PFR_TFLAG_PERSIST
797f1e85027SSimon Schubertflag of an unreferenced table.
79870224baaSJan Lentfer.It Dv DIOCRINADEFINE Fa "struct pfioc_table *io"
799f1e85027SSimon SchubertDefines a table in the inactive set.
80070224baaSJan LentferOn entry,
80170224baaSJan Lentfer.Va pfrio_table
80270224baaSJan Lentfercontains the table ID and
80370224baaSJan Lentfer.Va pfrio_buffer[pfrio_size]
80470224baaSJan Lentfercontains an array of
80570224baaSJan Lentfer.Vt pfr_addr
80670224baaSJan Lentferstructures to put in the table.
80770224baaSJan LentferA valid ticket must also be supplied to
80870224baaSJan Lentfer.Va pfrio_ticket .
80970224baaSJan LentferOn exit,
81070224baaSJan Lentfer.Va pfrio_nadd
81170224baaSJan Lentfercontains 0 if the table was already defined in the inactive list
81270224baaSJan Lentferor 1 if a new table has been created.
81370224baaSJan Lentfer.Va pfrio_naddr
81470224baaSJan Lentfercontains the number of addresses effectively put in the table.
81570224baaSJan Lentfer.It Dv DIOCXBEGIN Fa "struct pfioc_trans *io"
816f1e85027SSimon Schubert.Bd -literal
817f1e85027SSimon Schubertstruct pfioc_trans {
818f1e85027SSimon Schubert	int		 size;	/* number of elements */
819f1e85027SSimon Schubert	int		 esize;	/* size of each element in bytes */
820f1e85027SSimon Schubert	struct pfioc_trans_e {
821f1e85027SSimon Schubert		int		rs_num;
82270224baaSJan Lentfer		char		anchor[MAXPATHLEN];
823f1e85027SSimon Schubert		u_int32_t	ticket;
824f1e85027SSimon Schubert	}		*array;
825f1e85027SSimon Schubert};
826f1e85027SSimon Schubert.Ed
827f1e85027SSimon Schubert.Pp
82870224baaSJan LentferClear all the inactive rulesets specified in the
82970224baaSJan Lentfer.Vt pfioc_trans_e
830f1e85027SSimon Schubertarray.
83170224baaSJan LentferFor each ruleset, a ticket is returned for subsequent "add rule" ioctls,
832f1e85027SSimon Schubertas well as for the
833f1e85027SSimon Schubert.Dv DIOCXCOMMIT
834f1e85027SSimon Schubertand
835f1e85027SSimon Schubert.Dv DIOCXROLLBACK
836f1e85027SSimon Schubertcalls.
83770224baaSJan Lentfer.Pp
83870224baaSJan LentferRuleset types, identified by
83970224baaSJan Lentfer.Va rs_num ,
84070224baaSJan Lentferinclude the following:
84170224baaSJan Lentfer.Pp
84270224baaSJan Lentfer.Bl -tag -width PF_RULESET_FILTER -offset ind -compact
84370224baaSJan Lentfer.It Dv PF_RULESET_SCRUB
84470224baaSJan LentferScrub (packet normalization) rules.
84570224baaSJan Lentfer.It Dv PF_RULESET_FILTER
84670224baaSJan LentferFilter rules.
84770224baaSJan Lentfer.It Dv PF_RULESET_NAT
84870224baaSJan LentferNAT (Network Address Translation) rules.
84970224baaSJan Lentfer.It Dv PF_RULESET_BINAT
85070224baaSJan LentferBidirectional NAT rules.
85170224baaSJan Lentfer.It Dv PF_RULESET_RDR
85270224baaSJan LentferRedirect rules.
85370224baaSJan Lentfer.It Dv PF_RULESET_ALTQ
85470224baaSJan LentferALTQ disciplines.
85570224baaSJan Lentfer.It Dv PF_RULESET_TABLE
85670224baaSJan LentferAddress tables.
85770224baaSJan Lentfer.El
85870224baaSJan Lentfer.It Dv DIOCXCOMMIT Fa "struct pfioc_trans *io"
859f1e85027SSimon SchubertAtomically switch a vector of inactive rulesets to the active rulesets.
86070224baaSJan LentferThis call is implemented as a standard two-phase commit, which will either
86170224baaSJan Lentferfail for all rulesets or completely succeed.
862f1e85027SSimon SchubertAll tickets need to be valid.
86370224baaSJan LentferThis ioctl returns
8644a865848SSascha Wildner.Er EBUSY
86570224baaSJan Lentferif another process is concurrently updating some of the same rulesets.
86670224baaSJan Lentfer.It Dv DIOCXROLLBACK Fa "struct pfioc_trans *io"
867f1e85027SSimon SchubertClean up the kernel by undoing all changes that have taken place on the
868f1e85027SSimon Schubertinactive rulesets since the last
869f1e85027SSimon Schubert.Dv DIOCXBEGIN .
870f1e85027SSimon Schubert.Dv DIOCXROLLBACK
871f1e85027SSimon Schubertwill silently ignore rulesets for which the ticket is invalid.
87270224baaSJan Lentfer.It Dv DIOCSETHOSTID Fa "u_int32_t *hostid"
87370224baaSJan LentferSet the host ID, which is used by
87470224baaSJan Lentfer.Xr pfsync 4
87570224baaSJan Lentferto identify which host created state table entries.
87670224baaSJan Lentfer.It Dv DIOCOSFPFLUSH
877f1e85027SSimon SchubertFlush the passive OS fingerprint table.
87870224baaSJan Lentfer.It Dv DIOCOSFPADD Fa "struct pf_osfp_ioctl *io"
879f1e85027SSimon Schubert.Bd -literal
880f1e85027SSimon Schubertstruct pf_osfp_ioctl {
881f1e85027SSimon Schubert	struct pf_osfp_entry {
882f1e85027SSimon Schubert		SLIST_ENTRY(pf_osfp_entry) fp_entry;
883f1e85027SSimon Schubert		pf_osfp_t		fp_os;
884f1e85027SSimon Schubert		char			fp_class_nm[PF_OSFP_LEN];
885f1e85027SSimon Schubert		char			fp_version_nm[PF_OSFP_LEN];
886f1e85027SSimon Schubert		char			fp_subtype_nm[PF_OSFP_LEN];
887f1e85027SSimon Schubert	} 			fp_os;
88870224baaSJan Lentfer	pf_tcpopts_t		fp_tcpopts;
889f1e85027SSimon Schubert	u_int16_t		fp_wsize;
890f1e85027SSimon Schubert	u_int16_t		fp_psize;
89170224baaSJan Lentfer	u_int16_t		fp_mss;
89270224baaSJan Lentfer	u_int16_t		fp_flags;
89370224baaSJan Lentfer	u_int8_t		fp_optcnt;
894f1e85027SSimon Schubert	u_int8_t		fp_wscale;
89570224baaSJan Lentfer	u_int8_t		fp_ttl;
896f1e85027SSimon Schubert	int			fp_getnum;
897f1e85027SSimon Schubert};
898f1e85027SSimon Schubert.Ed
899f1e85027SSimon Schubert.Pp
900f1e85027SSimon SchubertAdd a passive OS fingerprint to the table.
901f1e85027SSimon SchubertSet
902f1e85027SSimon Schubert.Va fp_os.fp_os
903f1e85027SSimon Schubertto the packed fingerprint,
904f1e85027SSimon Schubert.Va fp_os.fp_class_nm
905f1e85027SSimon Schubertto the name of the class (Linux, Windows, etc),
906f1e85027SSimon Schubert.Va fp_os.fp_version_nm
907f1e85027SSimon Schubertto the name of the version (NT, 95, 98), and
908f1e85027SSimon Schubert.Va fp_os.fp_subtype_nm
909f1e85027SSimon Schubertto the name of the subtype or patchlevel.
910f1e85027SSimon SchubertThe members
911f1e85027SSimon Schubert.Va fp_mss ,
912f1e85027SSimon Schubert.Va fp_wsize ,
913f1e85027SSimon Schubert.Va fp_psize ,
914f1e85027SSimon Schubert.Va fp_ttl ,
91570224baaSJan Lentfer.Va fp_optcnt ,
916f1e85027SSimon Schubertand
917f1e85027SSimon Schubert.Va fp_wscale
91870224baaSJan Lentferare set to the TCP MSS, the TCP window size, the IP length, the IP TTL,
91970224baaSJan Lentferthe number of TCP options, and the TCP window scaling constant of the
92070224baaSJan LentferTCP SYN packet, respectively.
92170224baaSJan Lentfer.Pp
922f1e85027SSimon SchubertThe
923f1e85027SSimon Schubert.Va fp_flags
92444cb301eSSascha Wildnermember is filled according to the
92570224baaSJan Lentfer.Aq Pa net/pfvar.h
92670224baaSJan Lentferinclude file
92770224baaSJan Lentfer.Dv PF_OSFP_*
92870224baaSJan Lentferdefines.
92970224baaSJan LentferThe
93070224baaSJan Lentfer.Va fp_tcpopts
93170224baaSJan Lentfermember contains packed TCP options.
93270224baaSJan LentferEach option uses
93370224baaSJan Lentfer.Dv PF_OSFP_TCPOPT_BITS
93470224baaSJan Lentferbits in the packed value.
93570224baaSJan LentferOptions include any of
93670224baaSJan Lentfer.Dv PF_OSFP_TCPOPT_NOP ,
93770224baaSJan Lentfer.Dv PF_OSFP_TCPOPT_SACK ,
93870224baaSJan Lentfer.Dv PF_OSFP_TCPOPT_WSCALE ,
93970224baaSJan Lentfer.Dv PF_OSFP_TCPOPT_MSS ,
94070224baaSJan Lentferor
94170224baaSJan Lentfer.Dv PF_OSFP_TCPOPT_TS .
94270224baaSJan Lentfer.Pp
943f1e85027SSimon SchubertThe
944f1e85027SSimon Schubert.Va fp_getnum
94570224baaSJan Lentfermember is not used with this ioctl.
946f1e85027SSimon Schubert.Pp
94770224baaSJan LentferThe structure's slack space must be zeroed for correct operation;
94870224baaSJan Lentfer.Xr memset 3
949f1e85027SSimon Schubertthe whole structure to zero before filling and sending to the kernel.
95070224baaSJan Lentfer.It Dv DIOCOSFPGET Fa "struct pf_osfp_ioctl *io"
951f1e85027SSimon SchubertGet the passive OS fingerprint number
952f1e85027SSimon Schubert.Va fp_getnum
953f1e85027SSimon Schubertfrom the kernel's fingerprint list.
954f1e85027SSimon SchubertThe rest of the structure members will come back filled.
955f1e85027SSimon SchubertGet the whole list by repeatedly incrementing the
956f1e85027SSimon Schubert.Va fp_getnum
9574a865848SSascha Wildnernumber until the ioctl returns
9584a865848SSascha Wildner.Er EBUSY .
95970224baaSJan Lentfer.It Dv DIOCGETSRCNODES Fa "struct pfioc_src_nodes *psn"
960f1e85027SSimon Schubert.Bd -literal
961f1e85027SSimon Schubertstruct pfioc_src_nodes {
962f1e85027SSimon Schubert	int	psn_len;
963f1e85027SSimon Schubert	union {
964f1e85027SSimon Schubert		caddr_t		psu_buf;
965f1e85027SSimon Schubert		struct pf_src_node	*psu_src_nodes;
966f1e85027SSimon Schubert	} psn_u;
967f1e85027SSimon Schubert#define psn_buf		psn_u.psu_buf
968f1e85027SSimon Schubert#define psn_src_nodes	psn_u.psu_src_nodes
969f1e85027SSimon Schubert};
970f1e85027SSimon Schubert.Ed
971f1e85027SSimon Schubert.Pp
97270224baaSJan LentferGet the list of source nodes kept by sticky addresses and source
97370224baaSJan Lentfertracking.
974f1e85027SSimon SchubertThe ioctl must be called once with
975f1e85027SSimon Schubert.Va psn_len
976f1e85027SSimon Schubertset to 0.
977f1e85027SSimon SchubertIf the ioctl returns without error,
978f1e85027SSimon Schubert.Va psn_len
979f1e85027SSimon Schubertwill be set to the size of the buffer required to hold all the
980f1e85027SSimon Schubert.Va pf_src_node
981f1e85027SSimon Schubertstructures held in the table.
982f1e85027SSimon SchubertA buffer of this size should then be allocated, and a pointer to this buffer
983f1e85027SSimon Schubertplaced in
984f1e85027SSimon Schubert.Va psn_buf .
985f1e85027SSimon SchubertThe ioctl must then be called again to fill this buffer with the actual
986f1e85027SSimon Schubertsource node data.
98770224baaSJan LentferAfter that call,
988f1e85027SSimon Schubert.Va psn_len
989f1e85027SSimon Schubertwill be set to the length of the buffer actually used.
99070224baaSJan Lentfer.It Dv DIOCCLRSRCNODES
991f1e85027SSimon SchubertClear the tree of source tracking nodes.
99270224baaSJan Lentfer.It Dv DIOCIGETIFACES Fa "struct pfioc_iface *io"
99370224baaSJan LentferGet the list of interfaces and interface drivers known to
994f1e85027SSimon Schubert.Nm .
99570224baaSJan LentferAll the ioctls that manipulate interfaces
996f1e85027SSimon Schubertuse the same structure described below:
997f1e85027SSimon Schubert.Bd -literal
998f1e85027SSimon Schubertstruct pfioc_iface {
999f1e85027SSimon Schubert	char			 pfiio_name[IFNAMSIZ];
1000f1e85027SSimon Schubert	void			*pfiio_buffer;
1001f1e85027SSimon Schubert	int			 pfiio_esize;
1002f1e85027SSimon Schubert	int			 pfiio_size;
1003f1e85027SSimon Schubert	int			 pfiio_nzero;
1004f1e85027SSimon Schubert	int			 pfiio_flags;
1005f1e85027SSimon Schubert};
1006f1e85027SSimon Schubert.Ed
1007f1e85027SSimon Schubert.Pp
1008f1e85027SSimon SchubertIf not empty,
1009f1e85027SSimon Schubert.Va pfiio_name
1010f1e85027SSimon Schubertcan be used to restrict the search to a specific interface or driver.
1011f1e85027SSimon Schubert.Va pfiio_buffer[pfiio_size]
1012f1e85027SSimon Schubertis the user-supplied buffer for returning the data.
1013f1e85027SSimon SchubertOn entry,
1014f1e85027SSimon Schubert.Va pfiio_size
101570224baaSJan Lentfercontains the number of
101670224baaSJan Lentfer.Vt pfi_kif
1017f1e85027SSimon Schubertentries that can fit into the buffer.
1018f1e85027SSimon SchubertThe kernel will replace this value by the real number of entries it wants
1019f1e85027SSimon Schubertto return.
1020f1e85027SSimon Schubert.Va pfiio_esize
1021f1e85027SSimon Schubertshould be set to
102270224baaSJan Lentfer.Li sizeof(struct pfi_kif) .
102370224baaSJan Lentfer.Pp
1024f1e85027SSimon SchubertThe data is returned in the
102570224baaSJan Lentfer.Vt pfi_kif
1026f1e85027SSimon Schubertstructure described below:
1027f1e85027SSimon Schubert.Bd -literal
102870224baaSJan Lentferstruct pfi_kif {
102970224baaSJan Lentfer	RB_ENTRY(pfi_kif)		 pfik_tree;
103070224baaSJan Lentfer	char				 pfik_name[IFNAMSIZ];
103170224baaSJan Lentfer	u_int64_t			 pfik_packets[2][2][2];
103270224baaSJan Lentfer	u_int64_t			 pfik_bytes[2][2][2];
103370224baaSJan Lentfer	u_int32_t			 pfik_tzero;
103470224baaSJan Lentfer	int				 pfik_flags;
103570224baaSJan Lentfer	struct pf_state_tree_lan_ext	 pfik_lan_ext;
103670224baaSJan Lentfer	struct pf_state_tree_ext_gwy	 pfik_ext_gwy;
103770224baaSJan Lentfer	TAILQ_ENTRY(pfi_kif)		 pfik_w_states;
103870224baaSJan Lentfer	void				*pfik_ah_cookie;
103970224baaSJan Lentfer	struct ifnet			*pfik_ifp;
104070224baaSJan Lentfer	struct ifg_group		*pfik_group;
104170224baaSJan Lentfer	int				 pfik_states;
104270224baaSJan Lentfer	int				 pfik_rules;
104370224baaSJan Lentfer	TAILQ_HEAD(, pfi_dynaddr)	 pfik_dynaddrs;
1044f1e85027SSimon Schubert};
1045f1e85027SSimon Schubert.Ed
104670224baaSJan Lentfer.It Dv DIOCSETIFFLAG Fa "struct pfioc_iface *io"
1047*566ca746SSascha WildnerSet the user settable flags (described above) of the
104870224baaSJan Lentfer.Nm
104970224baaSJan Lentferinternal interface description.
1050f1e85027SSimon SchubertThe filtering process is the same as for
1051f1e85027SSimon Schubert.Dv DIOCIGETIFACES .
105270224baaSJan Lentfer.Bd -literal
105370224baaSJan Lentfer#define PFI_IFLAG_SKIP		0x0100	/* skip filtering on interface */
105470224baaSJan Lentfer.Ed
105570224baaSJan Lentfer.It Dv DIOCCLRIFFLAG Fa "struct pfioc_iface *io"
105670224baaSJan LentferWorks as
105770224baaSJan Lentfer.Dv DIOCSETIFFLAG
105870224baaSJan Lentferabove but clears the flags.
105970224baaSJan Lentfer.El
106070224baaSJan Lentfer.Sh FILES
106170224baaSJan Lentfer.Bl -tag -width /dev/pf -compact
106270224baaSJan Lentfer.It Pa /dev/pf
106370224baaSJan Lentferpacket filtering device.
1064f1e85027SSimon Schubert.El
1065f1e85027SSimon Schubert.Sh EXAMPLES
1066b1c94e87SSascha WildnerThe following example demonstrates how to use the
1067b1c94e87SSascha Wildner.Dv DIOCNATLOOK
106870224baaSJan Lentfercommand to find the internal host/port of a NATed connection:
1069f1e85027SSimon Schubert.Bd -literal
1070f1e85027SSimon Schubert#include <sys/types.h>
1071f1e85027SSimon Schubert#include <sys/socket.h>
1072f1e85027SSimon Schubert#include <sys/ioctl.h>
1073f1e85027SSimon Schubert#include <sys/fcntl.h>
1074f1e85027SSimon Schubert#include <net/if.h>
1075f1e85027SSimon Schubert#include <netinet/in.h>
1076f1e85027SSimon Schubert#include <net/pfvar.h>
1077f1e85027SSimon Schubert#include <err.h>
1078f1e85027SSimon Schubert#include <stdio.h>
1079f1e85027SSimon Schubert#include <stdlib.h>
1080f1e85027SSimon Schubert
1081f1e85027SSimon Schubertu_int32_t
1082f1e85027SSimon Schubertread_address(const char *s)
1083f1e85027SSimon Schubert{
1084f1e85027SSimon Schubert	int a, b, c, d;
1085f1e85027SSimon Schubert
1086f1e85027SSimon Schubert	sscanf(s, "%i.%i.%i.%i", &a, &b, &c, &d);
1087f1e85027SSimon Schubert	return htonl(a << 24 | b << 16 | c << 8 | d);
1088f1e85027SSimon Schubert}
1089f1e85027SSimon Schubert
1090f1e85027SSimon Schubertvoid
1091f1e85027SSimon Schubertprint_address(u_int32_t a)
1092f1e85027SSimon Schubert{
1093f1e85027SSimon Schubert	a = ntohl(a);
1094f1e85027SSimon Schubert	printf("%d.%d.%d.%d", a >> 24 & 255, a >> 16 & 255,
1095f1e85027SSimon Schubert	    a >> 8 & 255, a & 255);
1096f1e85027SSimon Schubert}
1097f1e85027SSimon Schubert
1098f1e85027SSimon Schubertint
1099f1e85027SSimon Schubertmain(int argc, char *argv[])
1100f1e85027SSimon Schubert{
1101f1e85027SSimon Schubert	struct pfioc_natlook nl;
1102f1e85027SSimon Schubert	int dev;
1103f1e85027SSimon Schubert
1104f1e85027SSimon Schubert	if (argc != 5) {
1105f1e85027SSimon Schubert		printf("%s <gwy addr> <gwy port> <ext addr> <ext port>\\n",
1106f1e85027SSimon Schubert		    argv[0]);
1107f1e85027SSimon Schubert		return 1;
1108f1e85027SSimon Schubert	}
1109f1e85027SSimon Schubert
1110f1e85027SSimon Schubert	dev = open("/dev/pf", O_RDWR);
1111f1e85027SSimon Schubert	if (dev == -1)
1112f1e85027SSimon Schubert		err(1, "open(\\"/dev/pf\\") failed");
1113f1e85027SSimon Schubert
1114f1e85027SSimon Schubert	memset(&nl, 0, sizeof(struct pfioc_natlook));
1115f1e85027SSimon Schubert	nl.saddr.v4.s_addr	= read_address(argv[1]);
1116f1e85027SSimon Schubert	nl.sport		= htons(atoi(argv[2]));
1117f1e85027SSimon Schubert	nl.daddr.v4.s_addr	= read_address(argv[3]);
1118f1e85027SSimon Schubert	nl.dport		= htons(atoi(argv[4]));
1119f1e85027SSimon Schubert	nl.af			= AF_INET;
1120f1e85027SSimon Schubert	nl.proto		= IPPROTO_TCP;
1121f1e85027SSimon Schubert	nl.direction		= PF_IN;
1122f1e85027SSimon Schubert
1123f1e85027SSimon Schubert	if (ioctl(dev, DIOCNATLOOK, &nl))
1124f1e85027SSimon Schubert		err(1, "DIOCNATLOOK");
1125f1e85027SSimon Schubert
1126f1e85027SSimon Schubert	printf("internal host ");
1127f1e85027SSimon Schubert	print_address(nl.rsaddr.v4.s_addr);
1128f1e85027SSimon Schubert	printf(":%u\\n", ntohs(nl.rsport));
1129f1e85027SSimon Schubert	return 0;
1130f1e85027SSimon Schubert}
1131f1e85027SSimon Schubert.Ed
1132f1e85027SSimon Schubert.Sh SEE ALSO
1133f1e85027SSimon Schubert.Xr ioctl 2 ,
1134f1e85027SSimon Schubert.Xr bridge 4 ,
1135f1e85027SSimon Schubert.Xr pflog 4 ,
1136f1e85027SSimon Schubert.Xr pfsync 4 ,
113770224baaSJan Lentfer.Xr pfctl 8 ,
113870224baaSJan Lentfer.Xr altq 9
1139f1e85027SSimon Schubert.Sh HISTORY
1140f1e85027SSimon SchubertThe
1141f1e85027SSimon Schubert.Nm
1142f1e85027SSimon Schubertpacket filtering mechanism first appeared in
1143f1e85027SSimon Schubert.Ox 3.0
1144f1e85027SSimon Schubertand was imported into
1145f1e85027SSimon Schubert.Dx 1.1
1146f1e85027SSimon Schubertby Devon H. O'Dell and Simon Schubert.
1147