xref: /freebsd/share/man/man4/pf.4 (revision 3e609fd481c07802fe837ed834c3710b8c19493c)
13b3a8eb9SGleb Smirnoff.\"	$OpenBSD: pf.4,v 1.62 2008/09/10 14:57:37 jmc Exp $
23b3a8eb9SGleb Smirnoff.\"
33b3a8eb9SGleb Smirnoff.\" Copyright (C) 2001, Kjell Wooding.  All rights reserved.
43b3a8eb9SGleb Smirnoff.\"
53b3a8eb9SGleb Smirnoff.\" Redistribution and use in source and binary forms, with or without
63b3a8eb9SGleb Smirnoff.\" modification, are permitted provided that the following conditions
73b3a8eb9SGleb Smirnoff.\" are met:
83b3a8eb9SGleb Smirnoff.\" 1. Redistributions of source code must retain the above copyright
93b3a8eb9SGleb Smirnoff.\"    notice, this list of conditions and the following disclaimer.
103b3a8eb9SGleb Smirnoff.\" 2. Redistributions in binary form must reproduce the above copyright
113b3a8eb9SGleb Smirnoff.\"    notice, this list of conditions and the following disclaimer in the
123b3a8eb9SGleb Smirnoff.\"    documentation and/or other materials provided with the distribution.
133b3a8eb9SGleb Smirnoff.\" 3. Neither the name of the project nor the names of its contributors
143b3a8eb9SGleb Smirnoff.\"    may be used to endorse or promote products derived from this software
153b3a8eb9SGleb Smirnoff.\"    without specific prior written permission.
163b3a8eb9SGleb Smirnoff.\"
173b3a8eb9SGleb Smirnoff.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
183b3a8eb9SGleb Smirnoff.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
193b3a8eb9SGleb Smirnoff.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
203b3a8eb9SGleb Smirnoff.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
213b3a8eb9SGleb Smirnoff.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
223b3a8eb9SGleb Smirnoff.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
233b3a8eb9SGleb Smirnoff.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
243b3a8eb9SGleb Smirnoff.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
253b3a8eb9SGleb Smirnoff.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
263b3a8eb9SGleb Smirnoff.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
273b3a8eb9SGleb Smirnoff.\" SUCH DAMAGE.
283b3a8eb9SGleb Smirnoff.\"
291117b320SZhenlei Huang.Dd September 22, 2023
303b3a8eb9SGleb Smirnoff.Dt PF 4
313b3a8eb9SGleb Smirnoff.Os
323b3a8eb9SGleb Smirnoff.Sh NAME
333b3a8eb9SGleb Smirnoff.Nm pf
343b3a8eb9SGleb Smirnoff.Nd packet filter
353b3a8eb9SGleb Smirnoff.Sh SYNOPSIS
363b3a8eb9SGleb Smirnoff.Cd "device pf"
377f7ef494SGleb Smirnoff.Cd "options PF_DEFAULT_TO_DROP"
383b3a8eb9SGleb Smirnoff.Sh DESCRIPTION
393b3a8eb9SGleb SmirnoffPacket filtering takes place in the kernel.
403b3a8eb9SGleb SmirnoffA pseudo-device,
413b3a8eb9SGleb Smirnoff.Pa /dev/pf ,
423b3a8eb9SGleb Smirnoffallows userland processes to control the
433b3a8eb9SGleb Smirnoffbehavior of the packet filter through an
443b3a8eb9SGleb Smirnoff.Xr ioctl 2
453b3a8eb9SGleb Smirnoffinterface.
463b3a8eb9SGleb SmirnoffThere are commands to enable and disable the filter, load rulesets,
473b3a8eb9SGleb Smirnoffadd and remove individual rules or state table entries,
483b3a8eb9SGleb Smirnoffand retrieve statistics.
493b3a8eb9SGleb SmirnoffThe most commonly used functions are covered by
503b3a8eb9SGleb Smirnoff.Xr pfctl 8 .
513b3a8eb9SGleb Smirnoff.Pp
523b3a8eb9SGleb SmirnoffManipulations like loading a ruleset that involve more than a single
533b3a8eb9SGleb Smirnoff.Xr ioctl 2
543b3a8eb9SGleb Smirnoffcall require a so-called
553b3a8eb9SGleb Smirnoff.Em ticket ,
563b3a8eb9SGleb Smirnoffwhich prevents the occurrence of
573b3a8eb9SGleb Smirnoffmultiple concurrent manipulations.
583b3a8eb9SGleb Smirnoff.Pp
593b3a8eb9SGleb SmirnoffFields of
603b3a8eb9SGleb Smirnoff.Xr ioctl 2
613b3a8eb9SGleb Smirnoffparameter structures that refer to packet data (like
623b3a8eb9SGleb Smirnoffaddresses and ports) are generally expected in network byte-order.
633b3a8eb9SGleb Smirnoff.Pp
643b3a8eb9SGleb SmirnoffRules and address tables are contained in so-called
653b3a8eb9SGleb Smirnoff.Em anchors .
663b3a8eb9SGleb SmirnoffWhen servicing an
673b3a8eb9SGleb Smirnoff.Xr ioctl 2
683b3a8eb9SGleb Smirnoffrequest, if the anchor field of the argument structure is empty,
693b3a8eb9SGleb Smirnoffthe kernel will use the default anchor (i.e., the main ruleset)
703b3a8eb9SGleb Smirnoffin operations.
713b3a8eb9SGleb SmirnoffAnchors are specified by name and may be nested, with components
723b3a8eb9SGleb Smirnoffseparated by
733b3a8eb9SGleb Smirnoff.Sq /
743b3a8eb9SGleb Smirnoffcharacters, similar to how file system hierarchies are laid out.
753b3a8eb9SGleb SmirnoffThe final component of the anchor path is the anchor under which
763b3a8eb9SGleb Smirnoffoperations will be performed.
773b3a8eb9SGleb Smirnoff.Sh SYSCTL VARIABLES AND LOADER TUNABLES
783b3a8eb9SGleb SmirnoffThe following
793b3a8eb9SGleb Smirnoff.Xr loader 8
803b3a8eb9SGleb Smirnofftunables are available.
813b3a8eb9SGleb Smirnoff.Bl -tag -width indent
823b3a8eb9SGleb Smirnoff.It Va net.pf.states_hashsize
833b3a8eb9SGleb SmirnoffSize of hash tables that store states.
843b3a8eb9SGleb SmirnoffShould be power of 2.
8591e0f2d2SKristof ProvostDefault value is 131072.
863b3a8eb9SGleb Smirnoff.It Va net.pf.source_nodes_hashsize
873b3a8eb9SGleb SmirnoffSize of hash table that store source nodes.
883b3a8eb9SGleb SmirnoffShould be power of 2.
8991e0f2d2SKristof ProvostDefault value is 32768.
90c531c1d1SZhenlei Huang.It Va net.pf.default_to_drop
91c531c1d1SZhenlei HuangThis value overrides
92c531c1d1SZhenlei Huang.Cd "options PF_DEFAULT_TO_DROP"
93c531c1d1SZhenlei Huangfrom kernel configuration file.
943b3a8eb9SGleb Smirnoff.El
953b3a8eb9SGleb Smirnoff.Pp
963b3a8eb9SGleb SmirnoffRead only
973b3a8eb9SGleb Smirnoff.Xr sysctl 8
983b3a8eb9SGleb Smirnoffvariables with matching names are provided to obtain current values
993b3a8eb9SGleb Smirnoffat runtime.
1007f7ef494SGleb Smirnoff.Sh KERNEL OPTIONS
1017f7ef494SGleb SmirnoffThe following options in the kernel configuration file are related to
1027f7ef494SGleb Smirnoff.Nm
1037f7ef494SGleb Smirnoffoperation:
1047f7ef494SGleb Smirnoff.Pp
1057f7ef494SGleb Smirnoff.Bl -tag -width ".Dv PF_DEFAULT_TO_DROP" -compact
1067f7ef494SGleb Smirnoff.It Dv PF_DEFAULT_TO_DROP
1077f7ef494SGleb SmirnoffChange default policy to drop by default
1087f7ef494SGleb Smirnoff.El
1093b3a8eb9SGleb Smirnoff.Sh IOCTL INTERFACE
1103b3a8eb9SGleb Smirnoff.Nm
1113b3a8eb9SGleb Smirnoffsupports the following
1123b3a8eb9SGleb Smirnoff.Xr ioctl 2
1133b3a8eb9SGleb Smirnoffcommands, available through
1143b3a8eb9SGleb Smirnoff.Aq Pa net/pfvar.h :
1153b3a8eb9SGleb Smirnoff.Bl -tag -width xxxxxx
1163b3a8eb9SGleb Smirnoff.It Dv DIOCSTART
1173b3a8eb9SGleb SmirnoffStart the packet filter.
1183b3a8eb9SGleb Smirnoff.It Dv DIOCSTOP
1193b3a8eb9SGleb SmirnoffStop the packet filter.
1203b3a8eb9SGleb Smirnoff.It Dv DIOCSTARTALTQ
1213b3a8eb9SGleb SmirnoffStart the ALTQ bandwidth control system (see
1223b3a8eb9SGleb Smirnoff.Xr altq 9 ) .
1233b3a8eb9SGleb Smirnoff.It Dv DIOCSTOPALTQ
1243b3a8eb9SGleb SmirnoffStop the ALTQ bandwidth control system.
1253b3a8eb9SGleb Smirnoff.It Dv DIOCBEGINADDRS Fa "struct pfioc_pooladdr *pp"
1263b3a8eb9SGleb Smirnoff.Bd -literal
1273b3a8eb9SGleb Smirnoffstruct pfioc_pooladdr {
1283b3a8eb9SGleb Smirnoff	u_int32_t		action;
1293b3a8eb9SGleb Smirnoff	u_int32_t		ticket;
1303b3a8eb9SGleb Smirnoff	u_int32_t		nr;
1313b3a8eb9SGleb Smirnoff	u_int32_t		r_num;
1323b3a8eb9SGleb Smirnoff	u_int8_t		r_action;
1333b3a8eb9SGleb Smirnoff	u_int8_t		r_last;
1343b3a8eb9SGleb Smirnoff	u_int8_t		af;
1353b3a8eb9SGleb Smirnoff	char			anchor[MAXPATHLEN];
1363b3a8eb9SGleb Smirnoff	struct pf_pooladdr	addr;
1373b3a8eb9SGleb Smirnoff};
1383b3a8eb9SGleb Smirnoff.Ed
1393b3a8eb9SGleb Smirnoff.Pp
1403b3a8eb9SGleb SmirnoffClear the buffer address pool and get a
1413b3a8eb9SGleb Smirnoff.Va ticket
1423b3a8eb9SGleb Smirnofffor subsequent
1433b3a8eb9SGleb Smirnoff.Dv DIOCADDADDR ,
144cc535c95SWill Andrews.Dv DIOCADDRULE ,
1453b3a8eb9SGleb Smirnoffand
146cc535c95SWill Andrews.Dv DIOCCHANGERULE
1473b3a8eb9SGleb Smirnoffcalls.
1483b3a8eb9SGleb Smirnoff.It Dv DIOCADDADDR Fa "struct pfioc_pooladdr *pp"
1493b3a8eb9SGleb Smirnoff.Pp
1503b3a8eb9SGleb SmirnoffAdd the pool address
1513b3a8eb9SGleb Smirnoff.Va addr
1523b3a8eb9SGleb Smirnoffto the buffer address pool to be used in the following
1533b3a8eb9SGleb Smirnoff.Dv DIOCADDRULE
154cc535c95SWill Andrewsor
155cc535c95SWill Andrews.Dv DIOCCHANGERULE
1563b3a8eb9SGleb Smirnoffcall.
1573b3a8eb9SGleb SmirnoffAll other members of the structure are ignored.
1583b3a8eb9SGleb Smirnoff.It Dv DIOCADDRULE Fa "struct pfioc_rule *pr"
1593b3a8eb9SGleb Smirnoff.Bd -literal
1603b3a8eb9SGleb Smirnoffstruct pfioc_rule {
1613b3a8eb9SGleb Smirnoff	u_int32_t	action;
1623b3a8eb9SGleb Smirnoff	u_int32_t	ticket;
1633b3a8eb9SGleb Smirnoff	u_int32_t	pool_ticket;
1643b3a8eb9SGleb Smirnoff	u_int32_t	nr;
1653b3a8eb9SGleb Smirnoff	char		anchor[MAXPATHLEN];
1663b3a8eb9SGleb Smirnoff	char		anchor_call[MAXPATHLEN];
1673b3a8eb9SGleb Smirnoff	struct pf_rule	rule;
1683b3a8eb9SGleb Smirnoff};
1693b3a8eb9SGleb Smirnoff.Ed
1703b3a8eb9SGleb Smirnoff.Pp
1713b3a8eb9SGleb SmirnoffAdd
1723b3a8eb9SGleb Smirnoff.Va rule
1733b3a8eb9SGleb Smirnoffat the end of the inactive ruleset.
1743b3a8eb9SGleb SmirnoffThis call requires a
1753b3a8eb9SGleb Smirnoff.Va ticket
1763b3a8eb9SGleb Smirnoffobtained through a preceding
1773b3a8eb9SGleb Smirnoff.Dv DIOCXBEGIN
1783b3a8eb9SGleb Smirnoffcall and a
1793b3a8eb9SGleb Smirnoff.Va pool_ticket
1803b3a8eb9SGleb Smirnoffobtained through a
1813b3a8eb9SGleb Smirnoff.Dv DIOCBEGINADDRS
1823b3a8eb9SGleb Smirnoffcall.
1833b3a8eb9SGleb Smirnoff.Dv DIOCADDADDR
1843b3a8eb9SGleb Smirnoffmust also be called if any pool addresses are required.
1853b3a8eb9SGleb SmirnoffThe optional
1863b3a8eb9SGleb Smirnoff.Va anchor
1873b3a8eb9SGleb Smirnoffname indicates the anchor in which to append the rule.
1883b3a8eb9SGleb Smirnoff.Va nr
1893b3a8eb9SGleb Smirnoffand
1903b3a8eb9SGleb Smirnoff.Va action
1913b3a8eb9SGleb Smirnoffare ignored.
1923b3a8eb9SGleb Smirnoff.It Dv DIOCADDALTQ Fa "struct pfioc_altq *pa"
1933b3a8eb9SGleb SmirnoffAdd an ALTQ discipline or queue.
1943b3a8eb9SGleb Smirnoff.Bd -literal
1953b3a8eb9SGleb Smirnoffstruct pfioc_altq {
1963b3a8eb9SGleb Smirnoff	u_int32_t	action;
1973b3a8eb9SGleb Smirnoff	u_int32_t	ticket;
1983b3a8eb9SGleb Smirnoff	u_int32_t	nr;
1993b3a8eb9SGleb Smirnoff	struct pf_altq  altq;
2003b3a8eb9SGleb Smirnoff};
2013b3a8eb9SGleb Smirnoff.Ed
2023b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULES Fa "struct pfioc_rule *pr"
2033b3a8eb9SGleb SmirnoffGet a
2043b3a8eb9SGleb Smirnoff.Va ticket
2053b3a8eb9SGleb Smirnofffor subsequent
2063b3a8eb9SGleb Smirnoff.Dv DIOCGETRULE
2073b3a8eb9SGleb Smirnoffcalls and the number
2083b3a8eb9SGleb Smirnoff.Va nr
2093b3a8eb9SGleb Smirnoffof rules in the active ruleset.
2103b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULE Fa "struct pfioc_rule *pr"
2113b3a8eb9SGleb SmirnoffGet a
2123b3a8eb9SGleb Smirnoff.Va rule
2133b3a8eb9SGleb Smirnoffby its number
2143b3a8eb9SGleb Smirnoff.Va nr
2153b3a8eb9SGleb Smirnoffusing the
2163b3a8eb9SGleb Smirnoff.Va ticket
2173b3a8eb9SGleb Smirnoffobtained through a preceding
2183b3a8eb9SGleb Smirnoff.Dv DIOCGETRULES
2193b3a8eb9SGleb Smirnoffcall.
2203b3a8eb9SGleb SmirnoffIf
2213b3a8eb9SGleb Smirnoff.Va action
2223b3a8eb9SGleb Smirnoffis set to
2233b3a8eb9SGleb Smirnoff.Dv PF_GET_CLR_CNTR ,
2243b3a8eb9SGleb Smirnoffthe per-rule statistics on the requested rule are cleared.
2253b3a8eb9SGleb Smirnoff.It Dv DIOCGETADDRS Fa "struct pfioc_pooladdr *pp"
2263b3a8eb9SGleb SmirnoffGet a
2273b3a8eb9SGleb Smirnoff.Va ticket
2283b3a8eb9SGleb Smirnofffor subsequent
2293b3a8eb9SGleb Smirnoff.Dv DIOCGETADDR
2303b3a8eb9SGleb Smirnoffcalls and the number
2313b3a8eb9SGleb Smirnoff.Va nr
2323b3a8eb9SGleb Smirnoffof pool addresses in the rule specified with
2333b3a8eb9SGleb Smirnoff.Va r_action ,
2343b3a8eb9SGleb Smirnoff.Va r_num ,
2353b3a8eb9SGleb Smirnoffand
2363b3a8eb9SGleb Smirnoff.Va anchor .
2373b3a8eb9SGleb Smirnoff.It Dv DIOCGETADDR Fa "struct pfioc_pooladdr *pp"
2383b3a8eb9SGleb SmirnoffGet the pool address
2393b3a8eb9SGleb Smirnoff.Va addr
2403b3a8eb9SGleb Smirnoffby its number
2413b3a8eb9SGleb Smirnoff.Va nr
2423b3a8eb9SGleb Smirnofffrom the rule specified with
2433b3a8eb9SGleb Smirnoff.Va r_action ,
2443b3a8eb9SGleb Smirnoff.Va r_num ,
2453b3a8eb9SGleb Smirnoffand
2463b3a8eb9SGleb Smirnoff.Va anchor
2473b3a8eb9SGleb Smirnoffusing the
2483b3a8eb9SGleb Smirnoff.Va ticket
2493b3a8eb9SGleb Smirnoffobtained through a preceding
2503b3a8eb9SGleb Smirnoff.Dv DIOCGETADDRS
2513b3a8eb9SGleb Smirnoffcall.
2523b3a8eb9SGleb Smirnoff.It Dv DIOCGETALTQS Fa "struct pfioc_altq *pa"
2533b3a8eb9SGleb SmirnoffGet a
2543b3a8eb9SGleb Smirnoff.Va ticket
2553b3a8eb9SGleb Smirnofffor subsequent
2563b3a8eb9SGleb Smirnoff.Dv DIOCGETALTQ
2573b3a8eb9SGleb Smirnoffcalls and the number
2583b3a8eb9SGleb Smirnoff.Va nr
2593b3a8eb9SGleb Smirnoffof queues in the active list.
2603b3a8eb9SGleb Smirnoff.It Dv DIOCGETALTQ Fa "struct pfioc_altq *pa"
2613b3a8eb9SGleb SmirnoffGet the queueing discipline
2623b3a8eb9SGleb Smirnoff.Va altq
2633b3a8eb9SGleb Smirnoffby its number
2643b3a8eb9SGleb Smirnoff.Va nr
2653b3a8eb9SGleb Smirnoffusing the
2663b3a8eb9SGleb Smirnoff.Va ticket
2673b3a8eb9SGleb Smirnoffobtained through a preceding
2683b3a8eb9SGleb Smirnoff.Dv DIOCGETALTQS
2693b3a8eb9SGleb Smirnoffcall.
2703b3a8eb9SGleb Smirnoff.It Dv DIOCGETQSTATS Fa "struct pfioc_qstats *pq"
2713b3a8eb9SGleb SmirnoffGet the statistics on a queue.
2723b3a8eb9SGleb Smirnoff.Bd -literal
2733b3a8eb9SGleb Smirnoffstruct pfioc_qstats {
2743b3a8eb9SGleb Smirnoff	u_int32_t	 ticket;
2753b3a8eb9SGleb Smirnoff	u_int32_t	 nr;
2763b3a8eb9SGleb Smirnoff	void		*buf;
2773b3a8eb9SGleb Smirnoff	int		 nbytes;
2783b3a8eb9SGleb Smirnoff	u_int8_t	 scheduler;
2793b3a8eb9SGleb Smirnoff};
2803b3a8eb9SGleb Smirnoff.Ed
2813b3a8eb9SGleb Smirnoff.Pp
2823b3a8eb9SGleb SmirnoffThis call fills in a pointer to the buffer of statistics
2833b3a8eb9SGleb Smirnoff.Va buf ,
2843b3a8eb9SGleb Smirnoffof length
2853b3a8eb9SGleb Smirnoff.Va nbytes ,
2863b3a8eb9SGleb Smirnofffor the queue specified by
2873b3a8eb9SGleb Smirnoff.Va nr .
2883b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULESETS Fa "struct pfioc_ruleset *pr"
2893b3a8eb9SGleb Smirnoff.Bd -literal
2903b3a8eb9SGleb Smirnoffstruct pfioc_ruleset {
2913b3a8eb9SGleb Smirnoff	u_int32_t	 nr;
2923b3a8eb9SGleb Smirnoff	char		 path[MAXPATHLEN];
2933b3a8eb9SGleb Smirnoff	char		 name[PF_ANCHOR_NAME_SIZE];
2943b3a8eb9SGleb Smirnoff};
2953b3a8eb9SGleb Smirnoff.Ed
2963b3a8eb9SGleb Smirnoff.Pp
2973b3a8eb9SGleb SmirnoffGet the number
2983b3a8eb9SGleb Smirnoff.Va nr
2993b3a8eb9SGleb Smirnoffof rulesets (i.e., anchors) directly attached to the anchor named by
3003b3a8eb9SGleb Smirnoff.Va path
3013b3a8eb9SGleb Smirnofffor use in subsequent
3023b3a8eb9SGleb Smirnoff.Dv DIOCGETRULESET
3033b3a8eb9SGleb Smirnoffcalls.
3043b3a8eb9SGleb SmirnoffNested anchors, since they are not directly attached to the given
3053b3a8eb9SGleb Smirnoffanchor, will not be included.
3063b3a8eb9SGleb SmirnoffThis ioctl returns
307df56c806SKristof Provost.Er ENOENT
308df56c806SKristof Provostif the parent anchor given at
309df56c806SKristof Provost.Va path
310df56c806SKristof Provostdoes not exist.
3113b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULESET Fa "struct pfioc_ruleset *pr"
3123b3a8eb9SGleb SmirnoffGet a ruleset (i.e., an anchor)
3133b3a8eb9SGleb Smirnoff.Va name
3143b3a8eb9SGleb Smirnoffby its number
3153b3a8eb9SGleb Smirnoff.Va nr
3163b3a8eb9SGleb Smirnofffrom the given anchor
3173b3a8eb9SGleb Smirnoff.Va path ,
3183b3a8eb9SGleb Smirnoffthe maximum number of which can be obtained from a preceding
3193b3a8eb9SGleb Smirnoff.Dv DIOCGETRULESETS
3203b3a8eb9SGleb Smirnoffcall.
3213b3a8eb9SGleb SmirnoffThis ioctl returns
322df56c806SKristof Provost.Er ENOENT
323df56c806SKristof Provostif the parent anchor given by
324df56c806SKristof Provost.Va path
325df56c806SKristof Provostdoes not exist or
3263b3a8eb9SGleb Smirnoff.Er EBUSY
327df56c806SKristof Provostif the index passed in by
328df56c806SKristof Provost.Va nr
329df56c806SKristof Provostis greater than the number of anchors.
330cc535c95SWill Andrews.It Dv DIOCADDSTATE Fa "struct pfioc_state *ps"
331cc535c95SWill AndrewsAdd a state entry.
332cc535c95SWill Andrews.Bd -literal
333cc535c95SWill Andrewsstruct pfioc_state {
334cc535c95SWill Andrews	struct pfsync_state	state;
335cc535c95SWill Andrews};
336cc535c95SWill Andrews.Ed
3371732afaaSKristof Provost.It Dv DIOCGETSTATENV Fa "struct pfioc_nv *nv"
338cc535c95SWill AndrewsExtract the entry identified by the
339cc535c95SWill Andrews.Va id
340cc535c95SWill Andrewsand
341cc535c95SWill Andrews.Va creatorid
342cc535c95SWill Andrewsfields of the
343cc535c95SWill Andrews.Va state
3441732afaaSKristof Provostnvlist from the state table.
3452e8edbc2SKristof Provost.It Dv DIOCKILLSTATESNV Fa "struct pfioc_nv nv"
3463b3a8eb9SGleb SmirnoffRemove matching entries from the state table.
3473b3a8eb9SGleb SmirnoffThis ioctl returns the number of killed states in
3482e8edbc2SKristof Provost.Va "killed" .
3493b3a8eb9SGleb Smirnoff.Bd -literal
3502e8edbc2SKristof Provostnvlist pf_state_cmp {
3512e8edbc2SKristof Provost	number			id;
3522e8edbc2SKristof Provost	number			creatorid;
3532e8edbc2SKristof Provost	number			direction;
3542e8edbc2SKristof Provost};
3552e8edbc2SKristof Provost
3562e8edbc2SKristof Provostnvlist pf_kill {
3572e8edbc2SKristof Provost	nvlist pf_state_cmp	cmp;
3582e8edbc2SKristof Provost	number			af;
3592e8edbc2SKristof Provost	number			proto;
3602e8edbc2SKristof Provost	nvlist pf_rule_addr	src;
3612e8edbc2SKristof Provost	nvlist pf_rule_addr	dst;
3622e8edbc2SKristof Provost	string			ifname[IFNAMSIZ];
3632e8edbc2SKristof Provost	string			label[PF_RULE_LABEL_SIZE];
3643b3a8eb9SGleb Smirnoff};
3653b3a8eb9SGleb Smirnoff.Ed
3662e8edbc2SKristof Provost.It Dv DIOCCLRSTATESNV Fa "struct pfioc_nv nv"
3673b3a8eb9SGleb SmirnoffClear all states.
3683b3a8eb9SGleb SmirnoffIt works like
3692e8edbc2SKristof Provost.Dv DIOCKILLSTATESNV ,
3703b3a8eb9SGleb Smirnoffbut ignores the
3712e8edbc2SKristof Provost.Va af ,
3722e8edbc2SKristof Provost.Va proto ,
3732e8edbc2SKristof Provost.Va src ,
3743b3a8eb9SGleb Smirnoffand
3752e8edbc2SKristof Provost.Va dst
3763b3a8eb9SGleb Smirnofffields of the
3772e8edbc2SKristof Provost.Vt pf_kill
3782e8edbc2SKristof Provostnvlist.
3793b3a8eb9SGleb Smirnoff.It Dv DIOCSETSTATUSIF Fa "struct pfioc_if *pi"
3803b3a8eb9SGleb SmirnoffSpecify the interface for which statistics are accumulated.
3813b3a8eb9SGleb Smirnoff.Bd -literal
3823b3a8eb9SGleb Smirnoffstruct pfioc_if {
3833b3a8eb9SGleb Smirnoff	char		 ifname[IFNAMSIZ];
3843b3a8eb9SGleb Smirnoff};
3853b3a8eb9SGleb Smirnoff.Ed
3863b3a8eb9SGleb Smirnoff.It Dv DIOCGETSTATUS Fa "struct pf_status *s"
3873b3a8eb9SGleb SmirnoffGet the internal packet filter statistics.
3883b3a8eb9SGleb Smirnoff.Bd -literal
3893b3a8eb9SGleb Smirnoffstruct pf_status {
3903b3a8eb9SGleb Smirnoff	u_int64_t	counters[PFRES_MAX];
3913b3a8eb9SGleb Smirnoff	u_int64_t	lcounters[LCNT_MAX];
3923b3a8eb9SGleb Smirnoff	u_int64_t	fcounters[FCNT_MAX];
3933b3a8eb9SGleb Smirnoff	u_int64_t	scounters[SCNT_MAX];
3943b3a8eb9SGleb Smirnoff	u_int64_t	pcounters[2][2][3];
3953b3a8eb9SGleb Smirnoff	u_int64_t	bcounters[2][2];
3963b3a8eb9SGleb Smirnoff	u_int32_t	running;
3973b3a8eb9SGleb Smirnoff	u_int32_t	states;
3983b3a8eb9SGleb Smirnoff	u_int32_t	src_nodes;
3993b3a8eb9SGleb Smirnoff	u_int32_t	since;
4003b3a8eb9SGleb Smirnoff	u_int32_t	debug;
4013b3a8eb9SGleb Smirnoff	u_int32_t	hostid;
4023b3a8eb9SGleb Smirnoff	char		ifname[IFNAMSIZ];
4033b3a8eb9SGleb Smirnoff	u_int8_t	pf_chksum[MD5_DIGEST_LENGTH];
4043b3a8eb9SGleb Smirnoff};
4053b3a8eb9SGleb Smirnoff.Ed
4063b3a8eb9SGleb Smirnoff.It Dv DIOCCLRSTATUS
4073b3a8eb9SGleb SmirnoffClear the internal packet filter statistics.
4083b3a8eb9SGleb Smirnoff.It Dv DIOCNATLOOK Fa "struct pfioc_natlook *pnl"
4093b3a8eb9SGleb SmirnoffLook up a state table entry by source and destination addresses and ports.
4103b3a8eb9SGleb Smirnoff.Bd -literal
4113b3a8eb9SGleb Smirnoffstruct pfioc_natlook {
4123b3a8eb9SGleb Smirnoff	struct pf_addr	 saddr;
4133b3a8eb9SGleb Smirnoff	struct pf_addr	 daddr;
4143b3a8eb9SGleb Smirnoff	struct pf_addr	 rsaddr;
4153b3a8eb9SGleb Smirnoff	struct pf_addr	 rdaddr;
4163b3a8eb9SGleb Smirnoff	u_int16_t	 sport;
4173b3a8eb9SGleb Smirnoff	u_int16_t	 dport;
4183b3a8eb9SGleb Smirnoff	u_int16_t	 rsport;
4193b3a8eb9SGleb Smirnoff	u_int16_t	 rdport;
4203b3a8eb9SGleb Smirnoff	sa_family_t	 af;
4213b3a8eb9SGleb Smirnoff	u_int8_t	 proto;
4223b3a8eb9SGleb Smirnoff	u_int8_t	 direction;
4233b3a8eb9SGleb Smirnoff};
4243b3a8eb9SGleb Smirnoff.Ed
4253b3a8eb9SGleb Smirnoff.It Dv DIOCSETDEBUG Fa "u_int32_t *level"
4263b3a8eb9SGleb SmirnoffSet the debug level.
4273b3a8eb9SGleb Smirnoff.Bd -literal
4283b3a8eb9SGleb Smirnoffenum	{ PF_DEBUG_NONE, PF_DEBUG_URGENT, PF_DEBUG_MISC,
4293b3a8eb9SGleb Smirnoff	  PF_DEBUG_NOISY };
4303b3a8eb9SGleb Smirnoff.Ed
4310592a4c8SKristof Provost.It Dv DIOCGETSTATESNV Fa "struct pfioc_nv *nv"
4323b3a8eb9SGleb SmirnoffGet state table entries.
4333b3a8eb9SGleb Smirnoff.Bd -literal
4340592a4c8SKristof Provostnvlist pf_state_key {
4350592a4c8SKristof Provost	nvlist pf_addr	addr[2];
4360592a4c8SKristof Provost	number		port[2];
4370592a4c8SKristof Provost	number		af;
4380592a4c8SKristof Provost	number		proto;
4390592a4c8SKristof Provost};
4400592a4c8SKristof Provost
4410592a4c8SKristof Provostnvlist pf_state_scrub {
4420592a4c8SKristof Provost	bool	timestamp;
4430592a4c8SKristof Provost	number	ttl;
4440592a4c8SKristof Provost	number	ts_mod;
4450592a4c8SKristof Provost};
4460592a4c8SKristof Provost
4470592a4c8SKristof Provostnvlist pf_state_peer {
4480592a4c8SKristof Provost	nvlist pf_state_scrub	scrub;
4490592a4c8SKristof Provost	number			seqlo;
4500592a4c8SKristof Provost	number			seqhi;
4510592a4c8SKristof Provost	number			seqdiff;
4520592a4c8SKristof Provost	number			max_win;
4530592a4c8SKristof Provost	number			mss;
4540592a4c8SKristof Provost	number			state;
4550592a4c8SKristof Provost	number			wscale;
4560592a4c8SKristof Provost};
4570592a4c8SKristof Provost
4580592a4c8SKristof Provostnvlist pf_state {
4590592a4c8SKristof Provost	number			id;
4600592a4c8SKristof Provost	string			ifname;
4610592a4c8SKristof Provost	nvlist pf_state_key	stack_key;
4620592a4c8SKristof Provost	nvlist pf_state_key	wire_key;
4630592a4c8SKristof Provost	nvlist pf_state_peer	src;
4640592a4c8SKristof Provost	nvlist pf_state_peer	dst;
4650592a4c8SKristof Provost	nvlist pf_addr		rt_addr;
4660592a4c8SKristof Provost	number			rule;
4670592a4c8SKristof Provost	number			anchor;
4680592a4c8SKristof Provost	number			nat_rule;
4690592a4c8SKristof Provost	number			expire;
4700592a4c8SKristof Provost	number			packets[2];
4710592a4c8SKristof Provost	number			bytes[2];
4720592a4c8SKristof Provost	number			creatorid;
4730592a4c8SKristof Provost	number			direction;
4740592a4c8SKristof Provost	number			log;
4750592a4c8SKristof Provost	number			state_flags;
4760592a4c8SKristof Provost	number			timeout;
4770592a4c8SKristof Provost	number			sync_flags;
4780592a4c8SKristof Provost};
4790592a4c8SKristof Provost
4800592a4c8SKristof Provostnvlist pf_states {
4810592a4c8SKristof Provost	number		count;
4820592a4c8SKristof Provost	nvlist pf_state	states[];
4833b3a8eb9SGleb Smirnoff};
4843b3a8eb9SGleb Smirnoff.Ed
4853b3a8eb9SGleb Smirnoff.Pp
4863b3a8eb9SGleb SmirnoffIf
4870592a4c8SKristof Provost.Va pfioc_nv.size
4880592a4c8SKristof Provostis insufficiently large, as many states as possible that can fit into this
4890592a4c8SKristof Provostsize will be copied into the supplied buffer.
490cc535c95SWill Andrews.It Dv DIOCCHANGERULE Fa "struct pfioc_rule *pcr"
491cc535c95SWill AndrewsAdd or remove the
492cc535c95SWill Andrews.Va rule
493cc535c95SWill Andrewsin the ruleset specified by
494cc535c95SWill Andrews.Va rule.action .
4953b3a8eb9SGleb Smirnoff.Pp
4963b3a8eb9SGleb SmirnoffThe type of operation to be performed is indicated by
4973b3a8eb9SGleb Smirnoff.Va action ,
4983b3a8eb9SGleb Smirnoffwhich can be any of the following:
4993b3a8eb9SGleb Smirnoff.Bd -literal
5003b3a8eb9SGleb Smirnoffenum	{ PF_CHANGE_NONE, PF_CHANGE_ADD_HEAD, PF_CHANGE_ADD_TAIL,
5013b3a8eb9SGleb Smirnoff	  PF_CHANGE_ADD_BEFORE, PF_CHANGE_ADD_AFTER,
5023b3a8eb9SGleb Smirnoff	  PF_CHANGE_REMOVE, PF_CHANGE_GET_TICKET };
5033b3a8eb9SGleb Smirnoff.Ed
5043b3a8eb9SGleb Smirnoff.Pp
5053b3a8eb9SGleb Smirnoff.Va ticket
5063b3a8eb9SGleb Smirnoffmust be set to the value obtained with
5073b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_GET_TICKET
5083b3a8eb9SGleb Smirnofffor all actions except
5093b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_GET_TICKET .
5103b3a8eb9SGleb Smirnoff.Va pool_ticket
5113b3a8eb9SGleb Smirnoffmust be set to the value obtained with the
5123b3a8eb9SGleb Smirnoff.Dv DIOCBEGINADDRS
5133b3a8eb9SGleb Smirnoffcall for all actions except
5143b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_REMOVE
5153b3a8eb9SGleb Smirnoffand
5163b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_GET_TICKET .
5173b3a8eb9SGleb Smirnoff.Va anchor
5183b3a8eb9SGleb Smirnoffindicates to which anchor the operation applies.
5193b3a8eb9SGleb Smirnoff.Va nr
5203b3a8eb9SGleb Smirnoffindicates the rule number against which
5213b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_ADD_BEFORE ,
5223b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_ADD_AFTER ,
5233b3a8eb9SGleb Smirnoffor
5243b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_REMOVE
5253b3a8eb9SGleb Smirnoffactions are applied.
526cc535c95SWill Andrews.\" It Dv DIOCCHANGEALTQ Fa "struct pfioc_altq *pcr"
527cc535c95SWill Andrews.It Dv DIOCCHANGEADDR Fa "struct pfioc_pooladdr *pca"
528cc535c95SWill AndrewsAdd or remove the pool address
529cc535c95SWill Andrews.Va addr
530cc535c95SWill Andrewsfrom the rule specified by
531cc535c95SWill Andrews.Va r_action ,
532cc535c95SWill Andrews.Va r_num ,
533cc535c95SWill Andrewsand
534cc535c95SWill Andrews.Va anchor .
5353b3a8eb9SGleb Smirnoff.It Dv DIOCSETTIMEOUT Fa "struct pfioc_tm *pt"
5363b3a8eb9SGleb Smirnoff.Bd -literal
5373b3a8eb9SGleb Smirnoffstruct pfioc_tm {
5383b3a8eb9SGleb Smirnoff	int		 timeout;
5393b3a8eb9SGleb Smirnoff	int		 seconds;
5403b3a8eb9SGleb Smirnoff};
5413b3a8eb9SGleb Smirnoff.Ed
5423b3a8eb9SGleb Smirnoff.Pp
5433b3a8eb9SGleb SmirnoffSet the state timeout of
5443b3a8eb9SGleb Smirnoff.Va timeout
5453b3a8eb9SGleb Smirnoffto
5463b3a8eb9SGleb Smirnoff.Va seconds .
5473b3a8eb9SGleb SmirnoffThe old value will be placed into
5483b3a8eb9SGleb Smirnoff.Va seconds .
5493b3a8eb9SGleb SmirnoffFor possible values of
5503b3a8eb9SGleb Smirnoff.Va timeout ,
5513b3a8eb9SGleb Smirnoffconsult the
5523b3a8eb9SGleb Smirnoff.Dv PFTM_*
5533b3a8eb9SGleb Smirnoffvalues in
5543b3a8eb9SGleb Smirnoff.Aq Pa net/pfvar.h .
5553b3a8eb9SGleb Smirnoff.It Dv DIOCGETTIMEOUT Fa "struct pfioc_tm *pt"
5563b3a8eb9SGleb SmirnoffGet the state timeout of
5573b3a8eb9SGleb Smirnoff.Va timeout .
5583b3a8eb9SGleb SmirnoffThe value will be placed into the
5593b3a8eb9SGleb Smirnoff.Va seconds
5603b3a8eb9SGleb Smirnofffield.
561cc535c95SWill Andrews.It Dv DIOCCLRRULECTRS
562cc535c95SWill AndrewsClear per-rule statistics.
5633b3a8eb9SGleb Smirnoff.It Dv DIOCSETLIMIT Fa "struct pfioc_limit *pl"
5643b3a8eb9SGleb SmirnoffSet the hard limits on the memory pools used by the packet filter.
5653b3a8eb9SGleb Smirnoff.Bd -literal
5663b3a8eb9SGleb Smirnoffstruct pfioc_limit {
5673b3a8eb9SGleb Smirnoff	int		index;
5683b3a8eb9SGleb Smirnoff	unsigned	limit;
5693b3a8eb9SGleb Smirnoff};
5703b3a8eb9SGleb Smirnoff
5713b3a8eb9SGleb Smirnoffenum	{ PF_LIMIT_STATES, PF_LIMIT_SRC_NODES, PF_LIMIT_FRAGS,
5723b3a8eb9SGleb Smirnoff	  PF_LIMIT_TABLE_ENTRIES, PF_LIMIT_MAX };
5733b3a8eb9SGleb Smirnoff.Ed
5743b3a8eb9SGleb Smirnoff.It Dv DIOCGETLIMIT Fa "struct pfioc_limit *pl"
5753b3a8eb9SGleb SmirnoffGet the hard
5763b3a8eb9SGleb Smirnoff.Va limit
5773b3a8eb9SGleb Smirnofffor the memory pool indicated by
5783b3a8eb9SGleb Smirnoff.Va index .
5793b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRTABLES Fa "struct pfioc_table *io"
5803b3a8eb9SGleb SmirnoffClear all tables.
5813b3a8eb9SGleb SmirnoffAll the ioctls that manipulate radix tables
5823b3a8eb9SGleb Smirnoffuse the same structure described below.
5833b3a8eb9SGleb SmirnoffFor
5843b3a8eb9SGleb Smirnoff.Dv DIOCRCLRTABLES ,
5853b3a8eb9SGleb Smirnoff.Va pfrio_ndel
5863b3a8eb9SGleb Smirnoffcontains on exit the number of tables deleted.
5873b3a8eb9SGleb Smirnoff.Bd -literal
5883b3a8eb9SGleb Smirnoffstruct pfioc_table {
5893b3a8eb9SGleb Smirnoff	struct pfr_table	 pfrio_table;
5903b3a8eb9SGleb Smirnoff	void			*pfrio_buffer;
5913b3a8eb9SGleb Smirnoff	int			 pfrio_esize;
5923b3a8eb9SGleb Smirnoff	int			 pfrio_size;
5933b3a8eb9SGleb Smirnoff	int			 pfrio_size2;
5943b3a8eb9SGleb Smirnoff	int			 pfrio_nadd;
5953b3a8eb9SGleb Smirnoff	int			 pfrio_ndel;
5963b3a8eb9SGleb Smirnoff	int			 pfrio_nchange;
5973b3a8eb9SGleb Smirnoff	int			 pfrio_flags;
5983b3a8eb9SGleb Smirnoff	u_int32_t		 pfrio_ticket;
5993b3a8eb9SGleb Smirnoff};
6003b3a8eb9SGleb Smirnoff#define pfrio_exists    pfrio_nadd
6013b3a8eb9SGleb Smirnoff#define pfrio_nzero     pfrio_nadd
6023b3a8eb9SGleb Smirnoff#define pfrio_nmatch    pfrio_nadd
6033b3a8eb9SGleb Smirnoff#define pfrio_naddr     pfrio_size2
6043b3a8eb9SGleb Smirnoff#define pfrio_setflag   pfrio_size2
6053b3a8eb9SGleb Smirnoff#define pfrio_clrflag   pfrio_nadd
6063b3a8eb9SGleb Smirnoff.Ed
6073b3a8eb9SGleb Smirnoff.It Dv DIOCRADDTABLES Fa "struct pfioc_table *io"
6083b3a8eb9SGleb SmirnoffCreate one or more tables.
6093b3a8eb9SGleb SmirnoffOn entry,
6103b3a8eb9SGleb Smirnoff.Va pfrio_buffer
6113b3a8eb9SGleb Smirnoffmust point to an array of
6123b3a8eb9SGleb Smirnoff.Vt struct pfr_table
6133b3a8eb9SGleb Smirnoffcontaining at least
6143b3a8eb9SGleb Smirnoff.Vt pfrio_size
6153b3a8eb9SGleb Smirnoffelements.
6163b3a8eb9SGleb Smirnoff.Vt pfrio_esize
6173b3a8eb9SGleb Smirnoffmust be the size of
6183b3a8eb9SGleb Smirnoff.Vt struct pfr_table .
6193b3a8eb9SGleb SmirnoffOn exit,
6203b3a8eb9SGleb Smirnoff.Va pfrio_nadd
6213b3a8eb9SGleb Smirnoffcontains the number of tables effectively created.
6223b3a8eb9SGleb Smirnoff.Bd -literal
6233b3a8eb9SGleb Smirnoffstruct pfr_table {
6243b3a8eb9SGleb Smirnoff	char		pfrt_anchor[MAXPATHLEN];
6253b3a8eb9SGleb Smirnoff	char		pfrt_name[PF_TABLE_NAME_SIZE];
6263b3a8eb9SGleb Smirnoff	u_int32_t	pfrt_flags;
6273b3a8eb9SGleb Smirnoff	u_int8_t	pfrt_fback;
6283b3a8eb9SGleb Smirnoff};
6293b3a8eb9SGleb Smirnoff.Ed
6303b3a8eb9SGleb Smirnoff.It Dv DIOCRDELTABLES Fa "struct pfioc_table *io"
6313b3a8eb9SGleb SmirnoffDelete one or more tables.
6323b3a8eb9SGleb SmirnoffOn entry,
6333b3a8eb9SGleb Smirnoff.Va pfrio_buffer
6343b3a8eb9SGleb Smirnoffmust point to an array of
6353b3a8eb9SGleb Smirnoff.Vt struct pfr_table
6363b3a8eb9SGleb Smirnoffcontaining at least
6373b3a8eb9SGleb Smirnoff.Vt pfrio_size
6383b3a8eb9SGleb Smirnoffelements.
6393b3a8eb9SGleb Smirnoff.Vt pfrio_esize
6403b3a8eb9SGleb Smirnoffmust be the size of
6413b3a8eb9SGleb Smirnoff.Vt struct pfr_table .
6423b3a8eb9SGleb SmirnoffOn exit,
6433b3a8eb9SGleb Smirnoff.Va pfrio_ndel
6443b3a8eb9SGleb Smirnoffcontains the number of tables effectively deleted.
6453b3a8eb9SGleb Smirnoff.It Dv DIOCRGETTABLES Fa "struct pfioc_table *io"
6463b3a8eb9SGleb SmirnoffGet the list of all tables.
6473b3a8eb9SGleb SmirnoffOn entry,
6483b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size]
6493b3a8eb9SGleb Smirnoffcontains a valid writeable buffer for
6503b3a8eb9SGleb Smirnoff.Vt pfr_table
6513b3a8eb9SGleb Smirnoffstructures.
6523b3a8eb9SGleb SmirnoffOn exit,
6533b3a8eb9SGleb Smirnoff.Va pfrio_size
6543b3a8eb9SGleb Smirnoffcontains the number of tables written into the buffer.
6553b3a8eb9SGleb SmirnoffIf the buffer is too small, the kernel does not store anything but just
6563b3a8eb9SGleb Smirnoffreturns the required buffer size, without error.
6573b3a8eb9SGleb Smirnoff.It Dv DIOCRGETTSTATS Fa "struct pfioc_table *io"
6583b3a8eb9SGleb SmirnoffThis call is like
6593b3a8eb9SGleb Smirnoff.Dv DIOCRGETTABLES
6603b3a8eb9SGleb Smirnoffbut is used to get an array of
6613b3a8eb9SGleb Smirnoff.Vt pfr_tstats
6623b3a8eb9SGleb Smirnoffstructures.
6633b3a8eb9SGleb Smirnoff.Bd -literal
6643b3a8eb9SGleb Smirnoffstruct pfr_tstats {
6653b3a8eb9SGleb Smirnoff	struct pfr_table pfrts_t;
6663b3a8eb9SGleb Smirnoff	u_int64_t	 pfrts_packets
6673b3a8eb9SGleb Smirnoff			     [PFR_DIR_MAX][PFR_OP_TABLE_MAX];
6683b3a8eb9SGleb Smirnoff	u_int64_t	 pfrts_bytes
6693b3a8eb9SGleb Smirnoff			     [PFR_DIR_MAX][PFR_OP_TABLE_MAX];
6703b3a8eb9SGleb Smirnoff	u_int64_t	 pfrts_match;
6713b3a8eb9SGleb Smirnoff	u_int64_t	 pfrts_nomatch;
6723b3a8eb9SGleb Smirnoff	long		 pfrts_tzero;
6733b3a8eb9SGleb Smirnoff	int		 pfrts_cnt;
6743b3a8eb9SGleb Smirnoff	int		 pfrts_refcnt[PFR_REFCNT_MAX];
6753b3a8eb9SGleb Smirnoff};
6763b3a8eb9SGleb Smirnoff#define pfrts_name	 pfrts_t.pfrt_name
6773b3a8eb9SGleb Smirnoff#define pfrts_flags	 pfrts_t.pfrt_flags
6783b3a8eb9SGleb Smirnoff.Ed
6793b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRTSTATS Fa "struct pfioc_table *io"
6803b3a8eb9SGleb SmirnoffClear the statistics of one or more tables.
6813b3a8eb9SGleb SmirnoffOn entry,
6823b3a8eb9SGleb Smirnoff.Va pfrio_buffer
6833b3a8eb9SGleb Smirnoffmust point to an array of
6843b3a8eb9SGleb Smirnoff.Vt struct pfr_table
6853b3a8eb9SGleb Smirnoffcontaining at least
6863b3a8eb9SGleb Smirnoff.Vt pfrio_size
6873b3a8eb9SGleb Smirnoffelements.
6883b3a8eb9SGleb Smirnoff.Vt pfrio_esize
6893b3a8eb9SGleb Smirnoffmust be the size of
6903b3a8eb9SGleb Smirnoff.Vt struct pfr_table .
6913b3a8eb9SGleb SmirnoffOn exit,
6923b3a8eb9SGleb Smirnoff.Va pfrio_nzero
6933b3a8eb9SGleb Smirnoffcontains the number of tables effectively cleared.
6943b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRADDRS Fa "struct pfioc_table *io"
6953b3a8eb9SGleb SmirnoffClear all addresses in a table.
6963b3a8eb9SGleb SmirnoffOn entry,
6973b3a8eb9SGleb Smirnoff.Va pfrio_table
6983b3a8eb9SGleb Smirnoffcontains the table to clear.
6993b3a8eb9SGleb SmirnoffOn exit,
7003b3a8eb9SGleb Smirnoff.Va pfrio_ndel
7013b3a8eb9SGleb Smirnoffcontains the number of addresses removed.
7023b3a8eb9SGleb Smirnoff.It Dv DIOCRADDADDRS Fa "struct pfioc_table *io"
7033b3a8eb9SGleb SmirnoffAdd one or more addresses to a table.
7043b3a8eb9SGleb SmirnoffOn entry,
7053b3a8eb9SGleb Smirnoff.Va pfrio_table
7063b3a8eb9SGleb Smirnoffcontains the table ID and
7073b3a8eb9SGleb Smirnoff.Va pfrio_buffer
7083b3a8eb9SGleb Smirnoffmust point to an array of
7093b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
7103b3a8eb9SGleb Smirnoffcontaining at least
7113b3a8eb9SGleb Smirnoff.Vt pfrio_size
7123b3a8eb9SGleb Smirnoffelements to add to the table.
7133b3a8eb9SGleb Smirnoff.Vt pfrio_esize
7143b3a8eb9SGleb Smirnoffmust be the size of
7153b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
7163b3a8eb9SGleb SmirnoffOn exit,
7173b3a8eb9SGleb Smirnoff.Va pfrio_nadd
7183b3a8eb9SGleb Smirnoffcontains the number of addresses effectively added.
7193b3a8eb9SGleb Smirnoff.Bd -literal
7203b3a8eb9SGleb Smirnoffstruct pfr_addr {
7213b3a8eb9SGleb Smirnoff	union {
7223b3a8eb9SGleb Smirnoff		struct in_addr	 _pfra_ip4addr;
7233b3a8eb9SGleb Smirnoff		struct in6_addr	 _pfra_ip6addr;
7243b3a8eb9SGleb Smirnoff	}		 pfra_u;
7253b3a8eb9SGleb Smirnoff	u_int8_t	 pfra_af;
7263b3a8eb9SGleb Smirnoff	u_int8_t	 pfra_net;
7273b3a8eb9SGleb Smirnoff	u_int8_t	 pfra_not;
7283b3a8eb9SGleb Smirnoff	u_int8_t	 pfra_fback;
7293b3a8eb9SGleb Smirnoff};
7303b3a8eb9SGleb Smirnoff#define pfra_ip4addr    pfra_u._pfra_ip4addr
7313b3a8eb9SGleb Smirnoff#define pfra_ip6addr    pfra_u._pfra_ip6addr
7323b3a8eb9SGleb Smirnoff.Ed
7333b3a8eb9SGleb Smirnoff.It Dv DIOCRDELADDRS Fa "struct pfioc_table *io"
7343b3a8eb9SGleb SmirnoffDelete one or more addresses from a table.
7353b3a8eb9SGleb SmirnoffOn entry,
7363b3a8eb9SGleb Smirnoff.Va pfrio_table
7373b3a8eb9SGleb Smirnoffcontains the table ID and
7383b3a8eb9SGleb Smirnoff.Va pfrio_buffer
7393b3a8eb9SGleb Smirnoffmust point to an array of
7403b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
7413b3a8eb9SGleb Smirnoffcontaining at least
7423b3a8eb9SGleb Smirnoff.Vt pfrio_size
7433b3a8eb9SGleb Smirnoffelements to delete from the table.
7443b3a8eb9SGleb Smirnoff.Vt pfrio_esize
7453b3a8eb9SGleb Smirnoffmust be the size of
7463b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
7473b3a8eb9SGleb SmirnoffOn exit,
7483b3a8eb9SGleb Smirnoff.Va pfrio_ndel
7493b3a8eb9SGleb Smirnoffcontains the number of addresses effectively deleted.
7503b3a8eb9SGleb Smirnoff.It Dv DIOCRSETADDRS Fa "struct pfioc_table *io"
7513b3a8eb9SGleb SmirnoffReplace the content of a table by a new address list.
7523b3a8eb9SGleb SmirnoffThis is the most complicated command, which uses all the structure members.
7533b3a8eb9SGleb Smirnoff.Pp
7543b3a8eb9SGleb SmirnoffOn entry,
7553b3a8eb9SGleb Smirnoff.Va pfrio_table
7563b3a8eb9SGleb Smirnoffcontains the table ID and
7573b3a8eb9SGleb Smirnoff.Va pfrio_buffer
7583b3a8eb9SGleb Smirnoffmust point to an array of
7593b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
7603b3a8eb9SGleb Smirnoffcontaining at least
7613b3a8eb9SGleb Smirnoff.Vt pfrio_size
7623b3a8eb9SGleb Smirnoffelements which become the new contents of the table.
7633b3a8eb9SGleb Smirnoff.Vt pfrio_esize
7643b3a8eb9SGleb Smirnoffmust be the size of
7653b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
7663b3a8eb9SGleb SmirnoffAdditionally, if
7673b3a8eb9SGleb Smirnoff.Va pfrio_size2
7683b3a8eb9SGleb Smirnoffis non-zero,
7693b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size..pfrio_size2]
7703b3a8eb9SGleb Smirnoffmust be a writeable buffer, into which the kernel can copy the
7713b3a8eb9SGleb Smirnoffaddresses that have been deleted during the replace operation.
7723b3a8eb9SGleb SmirnoffOn exit,
7733b3a8eb9SGleb Smirnoff.Va pfrio_ndel ,
7743b3a8eb9SGleb Smirnoff.Va pfrio_nadd ,
7753b3a8eb9SGleb Smirnoffand
7763b3a8eb9SGleb Smirnoff.Va pfrio_nchange
7773b3a8eb9SGleb Smirnoffcontain the number of addresses deleted, added, and changed by the
7783b3a8eb9SGleb Smirnoffkernel.
7793b3a8eb9SGleb SmirnoffIf
7803b3a8eb9SGleb Smirnoff.Va pfrio_size2
7813b3a8eb9SGleb Smirnoffwas set on entry,
7823b3a8eb9SGleb Smirnoff.Va pfrio_size2
7833b3a8eb9SGleb Smirnoffwill point to the size of the buffer used, exactly like
7843b3a8eb9SGleb Smirnoff.Dv DIOCRGETADDRS .
7853b3a8eb9SGleb Smirnoff.It Dv DIOCRGETADDRS Fa "struct pfioc_table *io"
7863b3a8eb9SGleb SmirnoffGet all the addresses of a table.
7873b3a8eb9SGleb SmirnoffOn entry,
7883b3a8eb9SGleb Smirnoff.Va pfrio_table
7893b3a8eb9SGleb Smirnoffcontains the table ID and
7903b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size]
7913b3a8eb9SGleb Smirnoffcontains a valid writeable buffer for
7923b3a8eb9SGleb Smirnoff.Vt pfr_addr
7933b3a8eb9SGleb Smirnoffstructures.
7943b3a8eb9SGleb SmirnoffOn exit,
7953b3a8eb9SGleb Smirnoff.Va pfrio_size
7963b3a8eb9SGleb Smirnoffcontains the number of addresses written into the buffer.
7973b3a8eb9SGleb SmirnoffIf the buffer was too small, the kernel does not store anything but just
7983b3a8eb9SGleb Smirnoffreturns the required buffer size, without returning an error.
7993b3a8eb9SGleb Smirnoff.It Dv DIOCRGETASTATS Fa "struct pfioc_table *io"
8003b3a8eb9SGleb SmirnoffThis call is like
8013b3a8eb9SGleb Smirnoff.Dv DIOCRGETADDRS
8023b3a8eb9SGleb Smirnoffbut is used to get an array of
8033b3a8eb9SGleb Smirnoff.Vt pfr_astats
8043b3a8eb9SGleb Smirnoffstructures.
8053b3a8eb9SGleb Smirnoff.Bd -literal
8063b3a8eb9SGleb Smirnoffstruct pfr_astats {
8073b3a8eb9SGleb Smirnoff	struct pfr_addr	 pfras_a;
8083b3a8eb9SGleb Smirnoff	u_int64_t	 pfras_packets
8093b3a8eb9SGleb Smirnoff			     [PFR_DIR_MAX][PFR_OP_ADDR_MAX];
8103b3a8eb9SGleb Smirnoff	u_int64_t	 pfras_bytes
8113b3a8eb9SGleb Smirnoff			     [PFR_DIR_MAX][PFR_OP_ADDR_MAX];
8123b3a8eb9SGleb Smirnoff	long		 pfras_tzero;
8133b3a8eb9SGleb Smirnoff};
8143b3a8eb9SGleb Smirnoff.Ed
8153b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRASTATS Fa "struct pfioc_table *io"
8163b3a8eb9SGleb SmirnoffClear the statistics of one or more addresses.
8173b3a8eb9SGleb SmirnoffOn entry,
8183b3a8eb9SGleb Smirnoff.Va pfrio_table
8193b3a8eb9SGleb Smirnoffcontains the table ID and
8203b3a8eb9SGleb Smirnoff.Va pfrio_buffer
8213b3a8eb9SGleb Smirnoffmust point to an array of
8223b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
8233b3a8eb9SGleb Smirnoffcontaining at least
8243b3a8eb9SGleb Smirnoff.Vt pfrio_size
8253b3a8eb9SGleb Smirnoffelements to be cleared from the table.
8263b3a8eb9SGleb Smirnoff.Vt pfrio_esize
8273b3a8eb9SGleb Smirnoffmust be the size of
8283b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
8293b3a8eb9SGleb SmirnoffOn exit,
8303b3a8eb9SGleb Smirnoff.Va pfrio_nzero
8313b3a8eb9SGleb Smirnoffcontains the number of addresses effectively cleared.
8323b3a8eb9SGleb Smirnoff.It Dv DIOCRTSTADDRS Fa "struct pfioc_table *io"
8333b3a8eb9SGleb SmirnoffTest if the given addresses match a table.
8343b3a8eb9SGleb SmirnoffOn entry,
8353b3a8eb9SGleb Smirnoff.Va pfrio_table
8363b3a8eb9SGleb Smirnoffcontains the table ID and
8373b3a8eb9SGleb Smirnoff.Va pfrio_buffer
8383b3a8eb9SGleb Smirnoffmust point to an array of
8393b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
8403b3a8eb9SGleb Smirnoffcontaining at least
8413b3a8eb9SGleb Smirnoff.Vt pfrio_size
8423b3a8eb9SGleb Smirnoffelements, each of which will be tested for a match in the table.
8433b3a8eb9SGleb Smirnoff.Vt pfrio_esize
8443b3a8eb9SGleb Smirnoffmust be the size of
8453b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
8463b3a8eb9SGleb SmirnoffOn exit, the kernel updates the
8473b3a8eb9SGleb Smirnoff.Vt pfr_addr
8483b3a8eb9SGleb Smirnoffarray by setting the
8493b3a8eb9SGleb Smirnoff.Va pfra_fback
8503b3a8eb9SGleb Smirnoffmember appropriately.
8513b3a8eb9SGleb Smirnoff.It Dv DIOCRSETTFLAGS Fa "struct pfioc_table *io"
8523b3a8eb9SGleb SmirnoffChange the
8533b3a8eb9SGleb Smirnoff.Dv PFR_TFLAG_CONST
8543b3a8eb9SGleb Smirnoffor
8553b3a8eb9SGleb Smirnoff.Dv PFR_TFLAG_PERSIST
8563b3a8eb9SGleb Smirnoffflags of a table.
8573b3a8eb9SGleb SmirnoffOn entry,
8583b3a8eb9SGleb Smirnoff.Va pfrio_buffer
8593b3a8eb9SGleb Smirnoffmust point to an array of
8603b3a8eb9SGleb Smirnoff.Vt struct pfr_table
8613b3a8eb9SGleb Smirnoffcontaining at least
8623b3a8eb9SGleb Smirnoff.Vt pfrio_size
8633b3a8eb9SGleb Smirnoffelements.
8643b3a8eb9SGleb Smirnoff.Va pfrio_esize
8653b3a8eb9SGleb Smirnoffmust be the size of
8663b3a8eb9SGleb Smirnoff.Vt struct pfr_table .
8673b3a8eb9SGleb Smirnoff.Va pfrio_setflag
8683b3a8eb9SGleb Smirnoffmust contain the flags to add, while
8693b3a8eb9SGleb Smirnoff.Va pfrio_clrflag
8703b3a8eb9SGleb Smirnoffmust contain the flags to remove.
8713b3a8eb9SGleb SmirnoffOn exit,
8723b3a8eb9SGleb Smirnoff.Va pfrio_nchange
8733b3a8eb9SGleb Smirnoffand
8743b3a8eb9SGleb Smirnoff.Va pfrio_ndel
8753b3a8eb9SGleb Smirnoffcontain the number of tables altered or deleted by the kernel.
8763b3a8eb9SGleb SmirnoffYes, tables can be deleted if one removes the
8773b3a8eb9SGleb Smirnoff.Dv PFR_TFLAG_PERSIST
8783b3a8eb9SGleb Smirnoffflag of an unreferenced table.
8793b3a8eb9SGleb Smirnoff.It Dv DIOCRINADEFINE Fa "struct pfioc_table *io"
8803b3a8eb9SGleb SmirnoffDefines a table in the inactive set.
8813b3a8eb9SGleb SmirnoffOn entry,
8823b3a8eb9SGleb Smirnoff.Va pfrio_table
8833b3a8eb9SGleb Smirnoffcontains the table ID and
8843b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size]
8853b3a8eb9SGleb Smirnoffcontains an array of
8863b3a8eb9SGleb Smirnoff.Vt pfr_addr
8873b3a8eb9SGleb Smirnoffstructures to put in the table.
8883b3a8eb9SGleb SmirnoffA valid ticket must also be supplied to
8893b3a8eb9SGleb Smirnoff.Va pfrio_ticket .
8903b3a8eb9SGleb SmirnoffOn exit,
8913b3a8eb9SGleb Smirnoff.Va pfrio_nadd
8923b3a8eb9SGleb Smirnoffcontains 0 if the table was already defined in the inactive list
8933b3a8eb9SGleb Smirnoffor 1 if a new table has been created.
8943b3a8eb9SGleb Smirnoff.Va pfrio_naddr
8953b3a8eb9SGleb Smirnoffcontains the number of addresses effectively put in the table.
8963b3a8eb9SGleb Smirnoff.It Dv DIOCXBEGIN Fa "struct pfioc_trans *io"
8973b3a8eb9SGleb Smirnoff.Bd -literal
8983b3a8eb9SGleb Smirnoffstruct pfioc_trans {
8993b3a8eb9SGleb Smirnoff	int		 size;	/* number of elements */
9003b3a8eb9SGleb Smirnoff	int		 esize;	/* size of each element in bytes */
9013b3a8eb9SGleb Smirnoff	struct pfioc_trans_e {
9023b3a8eb9SGleb Smirnoff		int		rs_num;
9033b3a8eb9SGleb Smirnoff		char		anchor[MAXPATHLEN];
9043b3a8eb9SGleb Smirnoff		u_int32_t	ticket;
9053b3a8eb9SGleb Smirnoff	}		*array;
9063b3a8eb9SGleb Smirnoff};
9073b3a8eb9SGleb Smirnoff.Ed
9083b3a8eb9SGleb Smirnoff.Pp
9093b3a8eb9SGleb SmirnoffClear all the inactive rulesets specified in the
9103b3a8eb9SGleb Smirnoff.Vt pfioc_trans_e
9113b3a8eb9SGleb Smirnoffarray.
9123b3a8eb9SGleb SmirnoffFor each ruleset, a ticket is returned for subsequent "add rule" ioctls,
9133b3a8eb9SGleb Smirnoffas well as for the
9143b3a8eb9SGleb Smirnoff.Dv DIOCXCOMMIT
9153b3a8eb9SGleb Smirnoffand
9163b3a8eb9SGleb Smirnoff.Dv DIOCXROLLBACK
9173b3a8eb9SGleb Smirnoffcalls.
9183b3a8eb9SGleb Smirnoff.Pp
9193b3a8eb9SGleb SmirnoffRuleset types, identified by
9203b3a8eb9SGleb Smirnoff.Va rs_num ,
9213b3a8eb9SGleb Smirnoffinclude the following:
9223b3a8eb9SGleb Smirnoff.Pp
9233b3a8eb9SGleb Smirnoff.Bl -tag -width PF_RULESET_FILTER -offset ind -compact
9243b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_SCRUB
9253b3a8eb9SGleb SmirnoffScrub (packet normalization) rules.
9263b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_FILTER
9273b3a8eb9SGleb SmirnoffFilter rules.
9283b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_NAT
9293b3a8eb9SGleb SmirnoffNAT (Network Address Translation) rules.
9303b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_BINAT
9313b3a8eb9SGleb SmirnoffBidirectional NAT rules.
9323b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_RDR
9333b3a8eb9SGleb SmirnoffRedirect rules.
9343b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_ALTQ
9353b3a8eb9SGleb SmirnoffALTQ disciplines.
9363b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_TABLE
9373b3a8eb9SGleb SmirnoffAddress tables.
9383b3a8eb9SGleb Smirnoff.El
9393b3a8eb9SGleb Smirnoff.It Dv DIOCXCOMMIT Fa "struct pfioc_trans *io"
9403b3a8eb9SGleb SmirnoffAtomically switch a vector of inactive rulesets to the active rulesets.
9413b3a8eb9SGleb SmirnoffThis call is implemented as a standard two-phase commit, which will either
9423b3a8eb9SGleb Smirnofffail for all rulesets or completely succeed.
9433b3a8eb9SGleb SmirnoffAll tickets need to be valid.
9443b3a8eb9SGleb SmirnoffThis ioctl returns
9453b3a8eb9SGleb Smirnoff.Er EBUSY
9463b3a8eb9SGleb Smirnoffif another process is concurrently updating some of the same rulesets.
9473b3a8eb9SGleb Smirnoff.It Dv DIOCXROLLBACK Fa "struct pfioc_trans *io"
9483b3a8eb9SGleb SmirnoffClean up the kernel by undoing all changes that have taken place on the
9493b3a8eb9SGleb Smirnoffinactive rulesets since the last
9503b3a8eb9SGleb Smirnoff.Dv DIOCXBEGIN .
9513b3a8eb9SGleb Smirnoff.Dv DIOCXROLLBACK
9523b3a8eb9SGleb Smirnoffwill silently ignore rulesets for which the ticket is invalid.
9533b3a8eb9SGleb Smirnoff.It Dv DIOCSETHOSTID Fa "u_int32_t *hostid"
9543b3a8eb9SGleb SmirnoffSet the host ID, which is used by
9553b3a8eb9SGleb Smirnoff.Xr pfsync 4
9563b3a8eb9SGleb Smirnoffto identify which host created state table entries.
9573b3a8eb9SGleb Smirnoff.It Dv DIOCOSFPFLUSH
9583b3a8eb9SGleb SmirnoffFlush the passive OS fingerprint table.
9593b3a8eb9SGleb Smirnoff.It Dv DIOCOSFPADD Fa "struct pf_osfp_ioctl *io"
9603b3a8eb9SGleb Smirnoff.Bd -literal
9613b3a8eb9SGleb Smirnoffstruct pf_osfp_ioctl {
9623b3a8eb9SGleb Smirnoff	struct pf_osfp_entry {
9633b3a8eb9SGleb Smirnoff		SLIST_ENTRY(pf_osfp_entry) fp_entry;
9643b3a8eb9SGleb Smirnoff		pf_osfp_t		fp_os;
9653b3a8eb9SGleb Smirnoff		char			fp_class_nm[PF_OSFP_LEN];
9663b3a8eb9SGleb Smirnoff		char			fp_version_nm[PF_OSFP_LEN];
9673b3a8eb9SGleb Smirnoff		char			fp_subtype_nm[PF_OSFP_LEN];
9683b3a8eb9SGleb Smirnoff	} 			fp_os;
9693b3a8eb9SGleb Smirnoff	pf_tcpopts_t		fp_tcpopts;
9703b3a8eb9SGleb Smirnoff	u_int16_t		fp_wsize;
9713b3a8eb9SGleb Smirnoff	u_int16_t		fp_psize;
9723b3a8eb9SGleb Smirnoff	u_int16_t		fp_mss;
9733b3a8eb9SGleb Smirnoff	u_int16_t		fp_flags;
9743b3a8eb9SGleb Smirnoff	u_int8_t		fp_optcnt;
9753b3a8eb9SGleb Smirnoff	u_int8_t		fp_wscale;
9763b3a8eb9SGleb Smirnoff	u_int8_t		fp_ttl;
9773b3a8eb9SGleb Smirnoff	int			fp_getnum;
9783b3a8eb9SGleb Smirnoff};
9793b3a8eb9SGleb Smirnoff.Ed
9803b3a8eb9SGleb Smirnoff.Pp
9813b3a8eb9SGleb SmirnoffAdd a passive OS fingerprint to the table.
9823b3a8eb9SGleb SmirnoffSet
9833b3a8eb9SGleb Smirnoff.Va fp_os.fp_os
9843b3a8eb9SGleb Smirnoffto the packed fingerprint,
9853b3a8eb9SGleb Smirnoff.Va fp_os.fp_class_nm
9863b3a8eb9SGleb Smirnoffto the name of the class (Linux, Windows, etc),
9873b3a8eb9SGleb Smirnoff.Va fp_os.fp_version_nm
9883b3a8eb9SGleb Smirnoffto the name of the version (NT, 95, 98), and
9893b3a8eb9SGleb Smirnoff.Va fp_os.fp_subtype_nm
9903b3a8eb9SGleb Smirnoffto the name of the subtype or patchlevel.
9913b3a8eb9SGleb SmirnoffThe members
9923b3a8eb9SGleb Smirnoff.Va fp_mss ,
9933b3a8eb9SGleb Smirnoff.Va fp_wsize ,
9943b3a8eb9SGleb Smirnoff.Va fp_psize ,
9953b3a8eb9SGleb Smirnoff.Va fp_ttl ,
9963b3a8eb9SGleb Smirnoff.Va fp_optcnt ,
9973b3a8eb9SGleb Smirnoffand
9983b3a8eb9SGleb Smirnoff.Va fp_wscale
9993b3a8eb9SGleb Smirnoffare set to the TCP MSS, the TCP window size, the IP length, the IP TTL,
10003b3a8eb9SGleb Smirnoffthe number of TCP options, and the TCP window scaling constant of the
10013b3a8eb9SGleb SmirnoffTCP SYN packet, respectively.
10023b3a8eb9SGleb Smirnoff.Pp
10033b3a8eb9SGleb SmirnoffThe
10043b3a8eb9SGleb Smirnoff.Va fp_flags
10053b3a8eb9SGleb Smirnoffmember is filled according to the
10063b3a8eb9SGleb Smirnoff.Aq Pa net/pfvar.h
10073b3a8eb9SGleb Smirnoffinclude file
10083b3a8eb9SGleb Smirnoff.Dv PF_OSFP_*
10093b3a8eb9SGleb Smirnoffdefines.
10103b3a8eb9SGleb SmirnoffThe
10113b3a8eb9SGleb Smirnoff.Va fp_tcpopts
10123b3a8eb9SGleb Smirnoffmember contains packed TCP options.
10133b3a8eb9SGleb SmirnoffEach option uses
10143b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_BITS
10153b3a8eb9SGleb Smirnoffbits in the packed value.
10163b3a8eb9SGleb SmirnoffOptions include any of
10173b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_NOP ,
10183b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_SACK ,
10193b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_WSCALE ,
10203b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_MSS ,
10213b3a8eb9SGleb Smirnoffor
10223b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_TS .
10233b3a8eb9SGleb Smirnoff.Pp
10243b3a8eb9SGleb SmirnoffThe
10253b3a8eb9SGleb Smirnoff.Va fp_getnum
10263b3a8eb9SGleb Smirnoffmember is not used with this ioctl.
10273b3a8eb9SGleb Smirnoff.Pp
10283b3a8eb9SGleb SmirnoffThe structure's slack space must be zeroed for correct operation;
10293b3a8eb9SGleb Smirnoff.Xr memset 3
10303b3a8eb9SGleb Smirnoffthe whole structure to zero before filling and sending to the kernel.
10313b3a8eb9SGleb Smirnoff.It Dv DIOCOSFPGET Fa "struct pf_osfp_ioctl *io"
10323b3a8eb9SGleb SmirnoffGet the passive OS fingerprint number
10333b3a8eb9SGleb Smirnoff.Va fp_getnum
10343b3a8eb9SGleb Smirnofffrom the kernel's fingerprint list.
10353b3a8eb9SGleb SmirnoffThe rest of the structure members will come back filled.
10363b3a8eb9SGleb SmirnoffGet the whole list by repeatedly incrementing the
10373b3a8eb9SGleb Smirnoff.Va fp_getnum
10383b3a8eb9SGleb Smirnoffnumber until the ioctl returns
10393b3a8eb9SGleb Smirnoff.Er EBUSY .
10403b3a8eb9SGleb Smirnoff.It Dv DIOCGETSRCNODES Fa "struct pfioc_src_nodes *psn"
10413b3a8eb9SGleb Smirnoff.Bd -literal
10423b3a8eb9SGleb Smirnoffstruct pfioc_src_nodes {
10433b3a8eb9SGleb Smirnoff	int	psn_len;
10443b3a8eb9SGleb Smirnoff	union {
10453b3a8eb9SGleb Smirnoff		caddr_t		psu_buf;
10463b3a8eb9SGleb Smirnoff		struct pf_src_node	*psu_src_nodes;
10473b3a8eb9SGleb Smirnoff	} psn_u;
10483b3a8eb9SGleb Smirnoff#define psn_buf		psn_u.psu_buf
10493b3a8eb9SGleb Smirnoff#define psn_src_nodes	psn_u.psu_src_nodes
10503b3a8eb9SGleb Smirnoff};
10513b3a8eb9SGleb Smirnoff.Ed
10523b3a8eb9SGleb Smirnoff.Pp
10533b3a8eb9SGleb SmirnoffGet the list of source nodes kept by sticky addresses and source
10543b3a8eb9SGleb Smirnofftracking.
10553b3a8eb9SGleb SmirnoffThe ioctl must be called once with
10563b3a8eb9SGleb Smirnoff.Va psn_len
10573b3a8eb9SGleb Smirnoffset to 0.
10583b3a8eb9SGleb SmirnoffIf the ioctl returns without error,
10593b3a8eb9SGleb Smirnoff.Va psn_len
10603b3a8eb9SGleb Smirnoffwill be set to the size of the buffer required to hold all the
10613b3a8eb9SGleb Smirnoff.Va pf_src_node
10623b3a8eb9SGleb Smirnoffstructures held in the table.
10633b3a8eb9SGleb SmirnoffA buffer of this size should then be allocated, and a pointer to this buffer
10643b3a8eb9SGleb Smirnoffplaced in
10653b3a8eb9SGleb Smirnoff.Va psn_buf .
10663b3a8eb9SGleb SmirnoffThe ioctl must then be called again to fill this buffer with the actual
10673b3a8eb9SGleb Smirnoffsource node data.
10683b3a8eb9SGleb SmirnoffAfter that call,
10693b3a8eb9SGleb Smirnoff.Va psn_len
10703b3a8eb9SGleb Smirnoffwill be set to the length of the buffer actually used.
10713b3a8eb9SGleb Smirnoff.It Dv DIOCCLRSRCNODES
10723b3a8eb9SGleb SmirnoffClear the tree of source tracking nodes.
10733b3a8eb9SGleb Smirnoff.It Dv DIOCIGETIFACES Fa "struct pfioc_iface *io"
10743b3a8eb9SGleb SmirnoffGet the list of interfaces and interface drivers known to
10753b3a8eb9SGleb Smirnoff.Nm .
10763b3a8eb9SGleb SmirnoffAll the ioctls that manipulate interfaces
10773b3a8eb9SGleb Smirnoffuse the same structure described below:
10783b3a8eb9SGleb Smirnoff.Bd -literal
10793b3a8eb9SGleb Smirnoffstruct pfioc_iface {
10803b3a8eb9SGleb Smirnoff	char			 pfiio_name[IFNAMSIZ];
10813b3a8eb9SGleb Smirnoff	void			*pfiio_buffer;
10823b3a8eb9SGleb Smirnoff	int			 pfiio_esize;
10833b3a8eb9SGleb Smirnoff	int			 pfiio_size;
10843b3a8eb9SGleb Smirnoff	int			 pfiio_nzero;
10853b3a8eb9SGleb Smirnoff	int			 pfiio_flags;
10863b3a8eb9SGleb Smirnoff};
10873b3a8eb9SGleb Smirnoff.Ed
10883b3a8eb9SGleb Smirnoff.Pp
10893b3a8eb9SGleb SmirnoffIf not empty,
10903b3a8eb9SGleb Smirnoff.Va pfiio_name
10913b3a8eb9SGleb Smirnoffcan be used to restrict the search to a specific interface or driver.
10923b3a8eb9SGleb Smirnoff.Va pfiio_buffer[pfiio_size]
10933b3a8eb9SGleb Smirnoffis the user-supplied buffer for returning the data.
10943b3a8eb9SGleb SmirnoffOn entry,
10953b3a8eb9SGleb Smirnoff.Va pfiio_size
10963b3a8eb9SGleb Smirnoffcontains the number of
10973b3a8eb9SGleb Smirnoff.Vt pfi_kif
10983b3a8eb9SGleb Smirnoffentries that can fit into the buffer.
10993b3a8eb9SGleb SmirnoffThe kernel will replace this value by the real number of entries it wants
11003b3a8eb9SGleb Smirnoffto return.
11013b3a8eb9SGleb Smirnoff.Va pfiio_esize
11023b3a8eb9SGleb Smirnoffshould be set to
11033b3a8eb9SGleb Smirnoff.Li sizeof(struct pfi_kif) .
11043b3a8eb9SGleb Smirnoff.Pp
11053b3a8eb9SGleb SmirnoffThe data is returned in the
11063b3a8eb9SGleb Smirnoff.Vt pfi_kif
11073b3a8eb9SGleb Smirnoffstructure described below:
11083b3a8eb9SGleb Smirnoff.Bd -literal
11093b3a8eb9SGleb Smirnoffstruct pfi_kif {
11103b3a8eb9SGleb Smirnoff	char				 pfik_name[IFNAMSIZ];
111164b30b7aSKristof Provost	union {
111264b30b7aSKristof Provost		RB_ENTRY(pfi_kif)	 pfik_tree;
111364b30b7aSKristof Provost		LIST_ENTRY(pfi_kif)	 pfik_list;
111464b30b7aSKristof Provost	};
11153b3a8eb9SGleb Smirnoff	u_int64_t			 pfik_packets[2][2][2];
11163b3a8eb9SGleb Smirnoff	u_int64_t			 pfik_bytes[2][2][2];
11173b3a8eb9SGleb Smirnoff	u_int32_t			 pfik_tzero;
111864b30b7aSKristof Provost	u_int				 pfik_flags;
11193b3a8eb9SGleb Smirnoff	struct ifnet			*pfik_ifp;
11203b3a8eb9SGleb Smirnoff	struct ifg_group		*pfik_group;
112164b30b7aSKristof Provost	u_int				 pfik_rulerefs;
11223b3a8eb9SGleb Smirnoff	TAILQ_HEAD(, pfi_dynaddr)	 pfik_dynaddrs;
11233b3a8eb9SGleb Smirnoff};
11243b3a8eb9SGleb Smirnoff.Ed
11253b3a8eb9SGleb Smirnoff.It Dv DIOCSETIFFLAG Fa "struct pfioc_iface *io"
1126646fa387SEdward Tomasz NapieralaSet the user settable flags (described above) of the
11273b3a8eb9SGleb Smirnoff.Nm
11283b3a8eb9SGleb Smirnoffinternal interface description.
11293b3a8eb9SGleb SmirnoffThe filtering process is the same as for
11303b3a8eb9SGleb Smirnoff.Dv DIOCIGETIFACES .
11313b3a8eb9SGleb Smirnoff.Bd -literal
11323b3a8eb9SGleb Smirnoff#define PFI_IFLAG_SKIP	0x0100	/* skip filtering on interface */
11333b3a8eb9SGleb Smirnoff.Ed
11343b3a8eb9SGleb Smirnoff.It Dv DIOCCLRIFFLAG Fa "struct pfioc_iface *io"
11353b3a8eb9SGleb SmirnoffWorks as
11363b3a8eb9SGleb Smirnoff.Dv DIOCSETIFFLAG
11373b3a8eb9SGleb Smirnoffabove but clears the flags.
11383b3a8eb9SGleb Smirnoff.It Dv DIOCKILLSRCNODES Fa "struct pfioc_iface *io"
11393b3a8eb9SGleb SmirnoffExplicitly remove source tracking nodes.
11403b3a8eb9SGleb Smirnoff.El
11413b3a8eb9SGleb Smirnoff.Sh FILES
11423b3a8eb9SGleb Smirnoff.Bl -tag -width /dev/pf -compact
11433b3a8eb9SGleb Smirnoff.It Pa /dev/pf
11443b3a8eb9SGleb Smirnoffpacket filtering device.
11453b3a8eb9SGleb Smirnoff.El
11463b3a8eb9SGleb Smirnoff.Sh EXAMPLES
11473b3a8eb9SGleb SmirnoffThe following example demonstrates how to use the
11483b3a8eb9SGleb Smirnoff.Dv DIOCNATLOOK
11493b3a8eb9SGleb Smirnoffcommand to find the internal host/port of a NATed connection:
11503b3a8eb9SGleb Smirnoff.Bd -literal
11513b3a8eb9SGleb Smirnoff#include <sys/types.h>
11523b3a8eb9SGleb Smirnoff#include <sys/socket.h>
11533b3a8eb9SGleb Smirnoff#include <sys/ioctl.h>
11543b3a8eb9SGleb Smirnoff#include <sys/fcntl.h>
11553b3a8eb9SGleb Smirnoff#include <net/if.h>
11563b3a8eb9SGleb Smirnoff#include <netinet/in.h>
11573b3a8eb9SGleb Smirnoff#include <net/pfvar.h>
11583b3a8eb9SGleb Smirnoff#include <err.h>
11593b3a8eb9SGleb Smirnoff#include <stdio.h>
11603b3a8eb9SGleb Smirnoff#include <stdlib.h>
11613b3a8eb9SGleb Smirnoff
11623b3a8eb9SGleb Smirnoffu_int32_t
11633b3a8eb9SGleb Smirnoffread_address(const char *s)
11643b3a8eb9SGleb Smirnoff{
11653b3a8eb9SGleb Smirnoff	int a, b, c, d;
11663b3a8eb9SGleb Smirnoff
11673b3a8eb9SGleb Smirnoff	sscanf(s, "%i.%i.%i.%i", &a, &b, &c, &d);
11683b3a8eb9SGleb Smirnoff	return htonl(a << 24 | b << 16 | c << 8 | d);
11693b3a8eb9SGleb Smirnoff}
11703b3a8eb9SGleb Smirnoff
11713b3a8eb9SGleb Smirnoffvoid
11723b3a8eb9SGleb Smirnoffprint_address(u_int32_t a)
11733b3a8eb9SGleb Smirnoff{
11743b3a8eb9SGleb Smirnoff	a = ntohl(a);
11753b3a8eb9SGleb Smirnoff	printf("%d.%d.%d.%d", a >> 24 & 255, a >> 16 & 255,
11763b3a8eb9SGleb Smirnoff	    a >> 8 & 255, a & 255);
11773b3a8eb9SGleb Smirnoff}
11783b3a8eb9SGleb Smirnoff
11793b3a8eb9SGleb Smirnoffint
11803b3a8eb9SGleb Smirnoffmain(int argc, char *argv[])
11813b3a8eb9SGleb Smirnoff{
11823b3a8eb9SGleb Smirnoff	struct pfioc_natlook nl;
11833b3a8eb9SGleb Smirnoff	int dev;
11843b3a8eb9SGleb Smirnoff
11853b3a8eb9SGleb Smirnoff	if (argc != 5) {
11863b3a8eb9SGleb Smirnoff		printf("%s <gwy addr> <gwy port> <ext addr> <ext port>\\n",
11873b3a8eb9SGleb Smirnoff		    argv[0]);
11883b3a8eb9SGleb Smirnoff		return 1;
11893b3a8eb9SGleb Smirnoff	}
11903b3a8eb9SGleb Smirnoff
11913b3a8eb9SGleb Smirnoff	dev = open("/dev/pf", O_RDWR);
11923b3a8eb9SGleb Smirnoff	if (dev == -1)
11933b3a8eb9SGleb Smirnoff		err(1, "open(\\"/dev/pf\\") failed");
11943b3a8eb9SGleb Smirnoff
11953b3a8eb9SGleb Smirnoff	memset(&nl, 0, sizeof(struct pfioc_natlook));
11963b3a8eb9SGleb Smirnoff	nl.saddr.v4.s_addr	= read_address(argv[1]);
11973b3a8eb9SGleb Smirnoff	nl.sport		= htons(atoi(argv[2]));
11983b3a8eb9SGleb Smirnoff	nl.daddr.v4.s_addr	= read_address(argv[3]);
11993b3a8eb9SGleb Smirnoff	nl.dport		= htons(atoi(argv[4]));
12003b3a8eb9SGleb Smirnoff	nl.af			= AF_INET;
12013b3a8eb9SGleb Smirnoff	nl.proto		= IPPROTO_TCP;
12023b3a8eb9SGleb Smirnoff	nl.direction		= PF_IN;
12033b3a8eb9SGleb Smirnoff
12043b3a8eb9SGleb Smirnoff	if (ioctl(dev, DIOCNATLOOK, &nl))
12053b3a8eb9SGleb Smirnoff		err(1, "DIOCNATLOOK");
12063b3a8eb9SGleb Smirnoff
12073b3a8eb9SGleb Smirnoff	printf("internal host ");
12083b3a8eb9SGleb Smirnoff	print_address(nl.rsaddr.v4.s_addr);
12093b3a8eb9SGleb Smirnoff	printf(":%u\\n", ntohs(nl.rsport));
12103b3a8eb9SGleb Smirnoff	return 0;
12113b3a8eb9SGleb Smirnoff}
12123b3a8eb9SGleb Smirnoff.Ed
12133b3a8eb9SGleb Smirnoff.Sh SEE ALSO
12143b3a8eb9SGleb Smirnoff.Xr ioctl 2 ,
12153b3a8eb9SGleb Smirnoff.Xr altq 4 ,
12163b3a8eb9SGleb Smirnoff.Xr if_bridge 4 ,
12173b3a8eb9SGleb Smirnoff.Xr pflog 4 ,
12183b3a8eb9SGleb Smirnoff.Xr pfsync 4 ,
12193b3a8eb9SGleb Smirnoff.Xr pfctl 8 ,
12203b3a8eb9SGleb Smirnoff.Xr altq 9
12213b3a8eb9SGleb Smirnoff.Sh HISTORY
12223b3a8eb9SGleb SmirnoffThe
12233b3a8eb9SGleb Smirnoff.Nm
12243b3a8eb9SGleb Smirnoffpacket filtering mechanism first appeared in
12253b3a8eb9SGleb Smirnoff.Ox 3.0
12263b3a8eb9SGleb Smirnoffand then
12273b3a8eb9SGleb Smirnoff.Fx 5.2 .
12283b3a8eb9SGleb Smirnoff.Pp
1229be51503dSGleb SmirnoffThis implementation is derived from
12303b3a8eb9SGleb Smirnoff.Ox 4.5 .
1231*3e609fd4SEd MasteA number of individual features, improvements, bug fixes and security fixes
1232*3e609fd4SEd Mastehave been ported from later versions of
1233*3e609fd4SEd Maste.Ox .
1234be51503dSGleb SmirnoffIt has been heavily modified to be capable of running in multithreaded
1235be51503dSGleb Smirnoff.Fx
1236be51503dSGleb Smirnoffkernel and scale its performance on multiple CPUs.
1237