xref: /freebsd/share/man/man4/pf.4 (revision 7e7f88001d7dfec83cd7568369be6a587d4a51ff)
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.\"
29390dc369STom Jones.Dd September 6, 2024
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
83a9ac25d6SKristof ProvostSize of hash table that stores states.
843b3a8eb9SGleb SmirnoffShould be power of 2.
8591e0f2d2SKristof ProvostDefault value is 131072.
863b3a8eb9SGleb Smirnoff.It Va net.pf.source_nodes_hashsize
87a9ac25d6SKristof ProvostSize of hash table that stores source nodes.
883b3a8eb9SGleb SmirnoffShould be power of 2.
8991e0f2d2SKristof ProvostDefault value is 32768.
90a9ac25d6SKristof Provost.It Va net.pf.rule_tag_hashsize
91a9ac25d6SKristof ProvostSize of the hash table that stores tags.
92390dc369STom Jones.It Va net.pf.udpendpoint_hashsize
93390dc369STom JonesSize of hash table that store UDP endpoint mappings.
94390dc369STom JonesShould be power of 2.
95390dc369STom JonesDefault value is 32768.
96c531c1d1SZhenlei Huang.It Va net.pf.default_to_drop
97c531c1d1SZhenlei HuangThis value overrides
98c531c1d1SZhenlei Huang.Cd "options PF_DEFAULT_TO_DROP"
99c531c1d1SZhenlei Huangfrom kernel configuration file.
100a9ac25d6SKristof Provost.It Va net.pf.filter_local
101a9ac25d6SKristof ProvostThis tells
102a9ac25d6SKristof Provost.Nm
103a9ac25d6SKristof Provostto also filter on the loopback output hook.
104a9ac25d6SKristof ProvostThis is typically used to allow redirect rules to adjust the source address.
105339a1977SMark Johnston.It Va net.pf.request_maxcount
106a9ac25d6SKristof ProvostThe maximum number of items in a single ioctl call.
107339a1977SMark Johnston.It Va net.pf.rdr_srcport_rewrite_tries
108339a1977SMark JohnstonThe maximum number of times to try and find a free source port when handling
109339a1977SMark Johnstonredirects.
110339a1977SMark JohnstonSuch rules are typically applied to external traffic, so an exhaustive search
111339a1977SMark Johnstonmay be too expensive.
1123b3a8eb9SGleb Smirnoff.El
1133b3a8eb9SGleb Smirnoff.Pp
1143b3a8eb9SGleb SmirnoffRead only
1153b3a8eb9SGleb Smirnoff.Xr sysctl 8
1163b3a8eb9SGleb Smirnoffvariables with matching names are provided to obtain current values
1173b3a8eb9SGleb Smirnoffat runtime.
1187f7ef494SGleb Smirnoff.Sh KERNEL OPTIONS
1197f7ef494SGleb SmirnoffThe following options in the kernel configuration file are related to
1207f7ef494SGleb Smirnoff.Nm
1217f7ef494SGleb Smirnoffoperation:
1227f7ef494SGleb Smirnoff.Pp
1237f7ef494SGleb Smirnoff.Bl -tag -width ".Dv PF_DEFAULT_TO_DROP" -compact
1247f7ef494SGleb Smirnoff.It Dv PF_DEFAULT_TO_DROP
1257f7ef494SGleb SmirnoffChange default policy to drop by default
1267f7ef494SGleb Smirnoff.El
1273b3a8eb9SGleb Smirnoff.Sh IOCTL INTERFACE
1283b3a8eb9SGleb Smirnoff.Nm
1293b3a8eb9SGleb Smirnoffsupports the following
1303b3a8eb9SGleb Smirnoff.Xr ioctl 2
1313b3a8eb9SGleb Smirnoffcommands, available through
1323b3a8eb9SGleb Smirnoff.Aq Pa net/pfvar.h :
1333b3a8eb9SGleb Smirnoff.Bl -tag -width xxxxxx
1343b3a8eb9SGleb Smirnoff.It Dv DIOCSTART
1353b3a8eb9SGleb SmirnoffStart the packet filter.
1363b3a8eb9SGleb Smirnoff.It Dv DIOCSTOP
1373b3a8eb9SGleb SmirnoffStop the packet filter.
1383b3a8eb9SGleb Smirnoff.It Dv DIOCSTARTALTQ
1393b3a8eb9SGleb SmirnoffStart the ALTQ bandwidth control system (see
1403b3a8eb9SGleb Smirnoff.Xr altq 9 ) .
1413b3a8eb9SGleb Smirnoff.It Dv DIOCSTOPALTQ
1423b3a8eb9SGleb SmirnoffStop the ALTQ bandwidth control system.
1433b3a8eb9SGleb Smirnoff.It Dv DIOCBEGINADDRS Fa "struct pfioc_pooladdr *pp"
1443b3a8eb9SGleb Smirnoff.Bd -literal
1453b3a8eb9SGleb Smirnoffstruct pfioc_pooladdr {
1463b3a8eb9SGleb Smirnoff	u_int32_t		action;
1473b3a8eb9SGleb Smirnoff	u_int32_t		ticket;
1483b3a8eb9SGleb Smirnoff	u_int32_t		nr;
1493b3a8eb9SGleb Smirnoff	u_int32_t		r_num;
1503b3a8eb9SGleb Smirnoff	u_int8_t		r_action;
1513b3a8eb9SGleb Smirnoff	u_int8_t		r_last;
1523b3a8eb9SGleb Smirnoff	u_int8_t		af;
1533b3a8eb9SGleb Smirnoff	char			anchor[MAXPATHLEN];
1543b3a8eb9SGleb Smirnoff	struct pf_pooladdr	addr;
1553b3a8eb9SGleb Smirnoff};
1563b3a8eb9SGleb Smirnoff.Ed
1573b3a8eb9SGleb Smirnoff.Pp
1583b3a8eb9SGleb SmirnoffClear the buffer address pool and get a
1593b3a8eb9SGleb Smirnoff.Va ticket
1603b3a8eb9SGleb Smirnofffor subsequent
1613b3a8eb9SGleb Smirnoff.Dv DIOCADDADDR ,
162cc535c95SWill Andrews.Dv DIOCADDRULE ,
1633b3a8eb9SGleb Smirnoffand
164cc535c95SWill Andrews.Dv DIOCCHANGERULE
1653b3a8eb9SGleb Smirnoffcalls.
1663b3a8eb9SGleb Smirnoff.It Dv DIOCADDADDR Fa "struct pfioc_pooladdr *pp"
1673b3a8eb9SGleb Smirnoff.Pp
1683b3a8eb9SGleb SmirnoffAdd the pool address
1693b3a8eb9SGleb Smirnoff.Va addr
1703b3a8eb9SGleb Smirnoffto the buffer address pool to be used in the following
1713b3a8eb9SGleb Smirnoff.Dv DIOCADDRULE
172cc535c95SWill Andrewsor
173cc535c95SWill Andrews.Dv DIOCCHANGERULE
1743b3a8eb9SGleb Smirnoffcall.
1753b3a8eb9SGleb SmirnoffAll other members of the structure are ignored.
1763b3a8eb9SGleb Smirnoff.It Dv DIOCADDRULE Fa "struct pfioc_rule *pr"
1773b3a8eb9SGleb Smirnoff.Bd -literal
1783b3a8eb9SGleb Smirnoffstruct pfioc_rule {
1793b3a8eb9SGleb Smirnoff	u_int32_t	action;
1803b3a8eb9SGleb Smirnoff	u_int32_t	ticket;
1813b3a8eb9SGleb Smirnoff	u_int32_t	pool_ticket;
1823b3a8eb9SGleb Smirnoff	u_int32_t	nr;
1833b3a8eb9SGleb Smirnoff	char		anchor[MAXPATHLEN];
1843b3a8eb9SGleb Smirnoff	char		anchor_call[MAXPATHLEN];
1853b3a8eb9SGleb Smirnoff	struct pf_rule	rule;
1863b3a8eb9SGleb Smirnoff};
1873b3a8eb9SGleb Smirnoff.Ed
1883b3a8eb9SGleb Smirnoff.Pp
1893b3a8eb9SGleb SmirnoffAdd
1903b3a8eb9SGleb Smirnoff.Va rule
1913b3a8eb9SGleb Smirnoffat the end of the inactive ruleset.
1923b3a8eb9SGleb SmirnoffThis call requires a
1933b3a8eb9SGleb Smirnoff.Va ticket
1943b3a8eb9SGleb Smirnoffobtained through a preceding
1953b3a8eb9SGleb Smirnoff.Dv DIOCXBEGIN
1963b3a8eb9SGleb Smirnoffcall and a
1973b3a8eb9SGleb Smirnoff.Va pool_ticket
1983b3a8eb9SGleb Smirnoffobtained through a
1993b3a8eb9SGleb Smirnoff.Dv DIOCBEGINADDRS
2003b3a8eb9SGleb Smirnoffcall.
2013b3a8eb9SGleb Smirnoff.Dv DIOCADDADDR
2023b3a8eb9SGleb Smirnoffmust also be called if any pool addresses are required.
2033b3a8eb9SGleb SmirnoffThe optional
2043b3a8eb9SGleb Smirnoff.Va anchor
2053b3a8eb9SGleb Smirnoffname indicates the anchor in which to append the rule.
2063b3a8eb9SGleb Smirnoff.Va nr
2073b3a8eb9SGleb Smirnoffand
2083b3a8eb9SGleb Smirnoff.Va action
2093b3a8eb9SGleb Smirnoffare ignored.
2103b3a8eb9SGleb Smirnoff.It Dv DIOCADDALTQ Fa "struct pfioc_altq *pa"
2113b3a8eb9SGleb SmirnoffAdd an ALTQ discipline or queue.
2123b3a8eb9SGleb Smirnoff.Bd -literal
2133b3a8eb9SGleb Smirnoffstruct pfioc_altq {
2143b3a8eb9SGleb Smirnoff	u_int32_t	action;
2153b3a8eb9SGleb Smirnoff	u_int32_t	ticket;
2163b3a8eb9SGleb Smirnoff	u_int32_t	nr;
2173b3a8eb9SGleb Smirnoff	struct pf_altq  altq;
2183b3a8eb9SGleb Smirnoff};
2193b3a8eb9SGleb Smirnoff.Ed
2203b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULES Fa "struct pfioc_rule *pr"
2213b3a8eb9SGleb SmirnoffGet a
2223b3a8eb9SGleb Smirnoff.Va ticket
2233b3a8eb9SGleb Smirnofffor subsequent
2243b3a8eb9SGleb Smirnoff.Dv DIOCGETRULE
2253b3a8eb9SGleb Smirnoffcalls and the number
2263b3a8eb9SGleb Smirnoff.Va nr
2273b3a8eb9SGleb Smirnoffof rules in the active ruleset.
2283b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULE Fa "struct pfioc_rule *pr"
2293b3a8eb9SGleb SmirnoffGet a
2303b3a8eb9SGleb Smirnoff.Va rule
2313b3a8eb9SGleb Smirnoffby its number
2323b3a8eb9SGleb Smirnoff.Va nr
2333b3a8eb9SGleb Smirnoffusing the
2343b3a8eb9SGleb Smirnoff.Va ticket
2353b3a8eb9SGleb Smirnoffobtained through a preceding
2363b3a8eb9SGleb Smirnoff.Dv DIOCGETRULES
2373b3a8eb9SGleb Smirnoffcall.
2383b3a8eb9SGleb SmirnoffIf
2393b3a8eb9SGleb Smirnoff.Va action
2403b3a8eb9SGleb Smirnoffis set to
2413b3a8eb9SGleb Smirnoff.Dv PF_GET_CLR_CNTR ,
2423b3a8eb9SGleb Smirnoffthe per-rule statistics on the requested rule are cleared.
2433b3a8eb9SGleb Smirnoff.It Dv DIOCGETADDRS Fa "struct pfioc_pooladdr *pp"
2443b3a8eb9SGleb SmirnoffGet a
2453b3a8eb9SGleb Smirnoff.Va ticket
2463b3a8eb9SGleb Smirnofffor subsequent
2473b3a8eb9SGleb Smirnoff.Dv DIOCGETADDR
2483b3a8eb9SGleb Smirnoffcalls and the number
2493b3a8eb9SGleb Smirnoff.Va nr
2503b3a8eb9SGleb Smirnoffof pool addresses in the rule specified with
2513b3a8eb9SGleb Smirnoff.Va r_action ,
2523b3a8eb9SGleb Smirnoff.Va r_num ,
2533b3a8eb9SGleb Smirnoffand
2543b3a8eb9SGleb Smirnoff.Va anchor .
2553b3a8eb9SGleb Smirnoff.It Dv DIOCGETADDR Fa "struct pfioc_pooladdr *pp"
2563b3a8eb9SGleb SmirnoffGet the pool address
2573b3a8eb9SGleb Smirnoff.Va addr
2583b3a8eb9SGleb Smirnoffby its number
2593b3a8eb9SGleb Smirnoff.Va nr
2603b3a8eb9SGleb Smirnofffrom the rule specified with
2613b3a8eb9SGleb Smirnoff.Va r_action ,
2623b3a8eb9SGleb Smirnoff.Va r_num ,
2633b3a8eb9SGleb Smirnoffand
2643b3a8eb9SGleb Smirnoff.Va anchor
2653b3a8eb9SGleb Smirnoffusing the
2663b3a8eb9SGleb Smirnoff.Va ticket
2673b3a8eb9SGleb Smirnoffobtained through a preceding
2683b3a8eb9SGleb Smirnoff.Dv DIOCGETADDRS
2693b3a8eb9SGleb Smirnoffcall.
2703b3a8eb9SGleb Smirnoff.It Dv DIOCGETALTQS Fa "struct pfioc_altq *pa"
2713b3a8eb9SGleb SmirnoffGet a
2723b3a8eb9SGleb Smirnoff.Va ticket
2733b3a8eb9SGleb Smirnofffor subsequent
2743b3a8eb9SGleb Smirnoff.Dv DIOCGETALTQ
2753b3a8eb9SGleb Smirnoffcalls and the number
2763b3a8eb9SGleb Smirnoff.Va nr
2773b3a8eb9SGleb Smirnoffof queues in the active list.
2783b3a8eb9SGleb Smirnoff.It Dv DIOCGETALTQ Fa "struct pfioc_altq *pa"
2793b3a8eb9SGleb SmirnoffGet the queueing discipline
2803b3a8eb9SGleb Smirnoff.Va altq
2813b3a8eb9SGleb Smirnoffby its number
2823b3a8eb9SGleb Smirnoff.Va nr
2833b3a8eb9SGleb Smirnoffusing the
2843b3a8eb9SGleb Smirnoff.Va ticket
2853b3a8eb9SGleb Smirnoffobtained through a preceding
2863b3a8eb9SGleb Smirnoff.Dv DIOCGETALTQS
2873b3a8eb9SGleb Smirnoffcall.
2883b3a8eb9SGleb Smirnoff.It Dv DIOCGETQSTATS Fa "struct pfioc_qstats *pq"
2893b3a8eb9SGleb SmirnoffGet the statistics on a queue.
2903b3a8eb9SGleb Smirnoff.Bd -literal
2913b3a8eb9SGleb Smirnoffstruct pfioc_qstats {
2923b3a8eb9SGleb Smirnoff	u_int32_t	 ticket;
2933b3a8eb9SGleb Smirnoff	u_int32_t	 nr;
2943b3a8eb9SGleb Smirnoff	void		*buf;
2953b3a8eb9SGleb Smirnoff	int		 nbytes;
2963b3a8eb9SGleb Smirnoff	u_int8_t	 scheduler;
2973b3a8eb9SGleb Smirnoff};
2983b3a8eb9SGleb Smirnoff.Ed
2993b3a8eb9SGleb Smirnoff.Pp
3003b3a8eb9SGleb SmirnoffThis call fills in a pointer to the buffer of statistics
3013b3a8eb9SGleb Smirnoff.Va buf ,
3023b3a8eb9SGleb Smirnoffof length
3033b3a8eb9SGleb Smirnoff.Va nbytes ,
3043b3a8eb9SGleb Smirnofffor the queue specified by
3053b3a8eb9SGleb Smirnoff.Va nr .
3063b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULESETS Fa "struct pfioc_ruleset *pr"
3073b3a8eb9SGleb Smirnoff.Bd -literal
3083b3a8eb9SGleb Smirnoffstruct pfioc_ruleset {
3093b3a8eb9SGleb Smirnoff	u_int32_t	 nr;
3103b3a8eb9SGleb Smirnoff	char		 path[MAXPATHLEN];
3113b3a8eb9SGleb Smirnoff	char		 name[PF_ANCHOR_NAME_SIZE];
3123b3a8eb9SGleb Smirnoff};
3133b3a8eb9SGleb Smirnoff.Ed
3143b3a8eb9SGleb Smirnoff.Pp
3153b3a8eb9SGleb SmirnoffGet the number
3163b3a8eb9SGleb Smirnoff.Va nr
3173b3a8eb9SGleb Smirnoffof rulesets (i.e., anchors) directly attached to the anchor named by
3183b3a8eb9SGleb Smirnoff.Va path
3193b3a8eb9SGleb Smirnofffor use in subsequent
3203b3a8eb9SGleb Smirnoff.Dv DIOCGETRULESET
3213b3a8eb9SGleb Smirnoffcalls.
3223b3a8eb9SGleb SmirnoffNested anchors, since they are not directly attached to the given
3233b3a8eb9SGleb Smirnoffanchor, will not be included.
3243b3a8eb9SGleb SmirnoffThis ioctl returns
325df56c806SKristof Provost.Er ENOENT
326df56c806SKristof Provostif the parent anchor given at
327df56c806SKristof Provost.Va path
328df56c806SKristof Provostdoes not exist.
3293b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULESET Fa "struct pfioc_ruleset *pr"
3303b3a8eb9SGleb SmirnoffGet a ruleset (i.e., an anchor)
3313b3a8eb9SGleb Smirnoff.Va name
3323b3a8eb9SGleb Smirnoffby its number
3333b3a8eb9SGleb Smirnoff.Va nr
3343b3a8eb9SGleb Smirnofffrom the given anchor
3353b3a8eb9SGleb Smirnoff.Va path ,
3363b3a8eb9SGleb Smirnoffthe maximum number of which can be obtained from a preceding
3373b3a8eb9SGleb Smirnoff.Dv DIOCGETRULESETS
3383b3a8eb9SGleb Smirnoffcall.
3393b3a8eb9SGleb SmirnoffThis ioctl returns
340df56c806SKristof Provost.Er ENOENT
341df56c806SKristof Provostif the parent anchor given by
342df56c806SKristof Provost.Va path
343df56c806SKristof Provostdoes not exist or
3443b3a8eb9SGleb Smirnoff.Er EBUSY
345df56c806SKristof Provostif the index passed in by
346df56c806SKristof Provost.Va nr
347df56c806SKristof Provostis greater than the number of anchors.
348cc535c95SWill Andrews.It Dv DIOCADDSTATE Fa "struct pfioc_state *ps"
349cc535c95SWill AndrewsAdd a state entry.
350cc535c95SWill Andrews.Bd -literal
351cc535c95SWill Andrewsstruct pfioc_state {
352cc535c95SWill Andrews	struct pfsync_state	state;
353cc535c95SWill Andrews};
354cc535c95SWill Andrews.Ed
3551732afaaSKristof Provost.It Dv DIOCGETSTATENV Fa "struct pfioc_nv *nv"
356cc535c95SWill AndrewsExtract the entry identified by the
357cc535c95SWill Andrews.Va id
358cc535c95SWill Andrewsand
359cc535c95SWill Andrews.Va creatorid
360cc535c95SWill Andrewsfields of the
361cc535c95SWill Andrews.Va state
3621732afaaSKristof Provostnvlist from the state table.
3632e8edbc2SKristof Provost.It Dv DIOCKILLSTATESNV Fa "struct pfioc_nv nv"
3643b3a8eb9SGleb SmirnoffRemove matching entries from the state table.
3653b3a8eb9SGleb SmirnoffThis ioctl returns the number of killed states in
3662e8edbc2SKristof Provost.Va "killed" .
3673b3a8eb9SGleb Smirnoff.Bd -literal
3682e8edbc2SKristof Provostnvlist pf_state_cmp {
3692e8edbc2SKristof Provost	number			id;
3702e8edbc2SKristof Provost	number			creatorid;
3712e8edbc2SKristof Provost	number			direction;
3722e8edbc2SKristof Provost};
3732e8edbc2SKristof Provost
3742e8edbc2SKristof Provostnvlist pf_kill {
3752e8edbc2SKristof Provost	nvlist pf_state_cmp	cmp;
3762e8edbc2SKristof Provost	number			af;
3772e8edbc2SKristof Provost	number			proto;
3782e8edbc2SKristof Provost	nvlist pf_rule_addr	src;
3792e8edbc2SKristof Provost	nvlist pf_rule_addr	dst;
3802e8edbc2SKristof Provost	string			ifname[IFNAMSIZ];
3812e8edbc2SKristof Provost	string			label[PF_RULE_LABEL_SIZE];
3823b3a8eb9SGleb Smirnoff};
3833b3a8eb9SGleb Smirnoff.Ed
3842e8edbc2SKristof Provost.It Dv DIOCCLRSTATESNV Fa "struct pfioc_nv nv"
3853b3a8eb9SGleb SmirnoffClear all states.
3863b3a8eb9SGleb SmirnoffIt works like
3872e8edbc2SKristof Provost.Dv DIOCKILLSTATESNV ,
3883b3a8eb9SGleb Smirnoffbut ignores the
3892e8edbc2SKristof Provost.Va af ,
3902e8edbc2SKristof Provost.Va proto ,
3912e8edbc2SKristof Provost.Va src ,
3923b3a8eb9SGleb Smirnoffand
3932e8edbc2SKristof Provost.Va dst
3943b3a8eb9SGleb Smirnofffields of the
3952e8edbc2SKristof Provost.Vt pf_kill
3962e8edbc2SKristof Provostnvlist.
3973b3a8eb9SGleb Smirnoff.It Dv DIOCSETSTATUSIF Fa "struct pfioc_if *pi"
3983b3a8eb9SGleb SmirnoffSpecify the interface for which statistics are accumulated.
3993b3a8eb9SGleb Smirnoff.Bd -literal
4003b3a8eb9SGleb Smirnoffstruct pfioc_if {
4013b3a8eb9SGleb Smirnoff	char		 ifname[IFNAMSIZ];
4023b3a8eb9SGleb Smirnoff};
4033b3a8eb9SGleb Smirnoff.Ed
4043b3a8eb9SGleb Smirnoff.It Dv DIOCGETSTATUS Fa "struct pf_status *s"
4053b3a8eb9SGleb SmirnoffGet the internal packet filter statistics.
4063b3a8eb9SGleb Smirnoff.Bd -literal
4073b3a8eb9SGleb Smirnoffstruct pf_status {
4083b3a8eb9SGleb Smirnoff	u_int64_t	counters[PFRES_MAX];
4093b3a8eb9SGleb Smirnoff	u_int64_t	lcounters[LCNT_MAX];
4103b3a8eb9SGleb Smirnoff	u_int64_t	fcounters[FCNT_MAX];
4113b3a8eb9SGleb Smirnoff	u_int64_t	scounters[SCNT_MAX];
4123b3a8eb9SGleb Smirnoff	u_int64_t	pcounters[2][2][3];
4133b3a8eb9SGleb Smirnoff	u_int64_t	bcounters[2][2];
4143b3a8eb9SGleb Smirnoff	u_int32_t	running;
4153b3a8eb9SGleb Smirnoff	u_int32_t	states;
4163b3a8eb9SGleb Smirnoff	u_int32_t	src_nodes;
4173b3a8eb9SGleb Smirnoff	u_int32_t	since;
4183b3a8eb9SGleb Smirnoff	u_int32_t	debug;
4193b3a8eb9SGleb Smirnoff	u_int32_t	hostid;
4203b3a8eb9SGleb Smirnoff	char		ifname[IFNAMSIZ];
4213b3a8eb9SGleb Smirnoff	u_int8_t	pf_chksum[MD5_DIGEST_LENGTH];
4223b3a8eb9SGleb Smirnoff};
4233b3a8eb9SGleb Smirnoff.Ed
4243b3a8eb9SGleb Smirnoff.It Dv DIOCCLRSTATUS
4253b3a8eb9SGleb SmirnoffClear the internal packet filter statistics.
4263b3a8eb9SGleb Smirnoff.It Dv DIOCNATLOOK Fa "struct pfioc_natlook *pnl"
4273b3a8eb9SGleb SmirnoffLook up a state table entry by source and destination addresses and ports.
4283b3a8eb9SGleb Smirnoff.Bd -literal
4293b3a8eb9SGleb Smirnoffstruct pfioc_natlook {
4303b3a8eb9SGleb Smirnoff	struct pf_addr	 saddr;
4313b3a8eb9SGleb Smirnoff	struct pf_addr	 daddr;
4323b3a8eb9SGleb Smirnoff	struct pf_addr	 rsaddr;
4333b3a8eb9SGleb Smirnoff	struct pf_addr	 rdaddr;
4343b3a8eb9SGleb Smirnoff	u_int16_t	 sport;
4353b3a8eb9SGleb Smirnoff	u_int16_t	 dport;
4363b3a8eb9SGleb Smirnoff	u_int16_t	 rsport;
4373b3a8eb9SGleb Smirnoff	u_int16_t	 rdport;
4383b3a8eb9SGleb Smirnoff	sa_family_t	 af;
4393b3a8eb9SGleb Smirnoff	u_int8_t	 proto;
4403b3a8eb9SGleb Smirnoff	u_int8_t	 direction;
4413b3a8eb9SGleb Smirnoff};
4423b3a8eb9SGleb Smirnoff.Ed
4433b3a8eb9SGleb Smirnoff.It Dv DIOCSETDEBUG Fa "u_int32_t *level"
4443b3a8eb9SGleb SmirnoffSet the debug level.
4453b3a8eb9SGleb Smirnoff.Bd -literal
4463b3a8eb9SGleb Smirnoffenum	{ PF_DEBUG_NONE, PF_DEBUG_URGENT, PF_DEBUG_MISC,
4473b3a8eb9SGleb Smirnoff	  PF_DEBUG_NOISY };
4483b3a8eb9SGleb Smirnoff.Ed
4496869f90bSKristof Provost.It Dv DIOCGETSTATESV2 Fa "struct pfioc_states_v2 *ps"
4503b3a8eb9SGleb SmirnoffGet state table entries.
4513b3a8eb9SGleb Smirnoff.Bd -literal
4526869f90bSKristof Provoststruct pfioc_states_v2 {
4536869f90bSKristof Provost	int		ps_len;
4546869f90bSKristof Provost	uint64_t	ps_req_version;
4556869f90bSKristof Provost	union {
4566869f90bSKristof Provost		void			*ps_buf;
4576869f90bSKristof Provost		struct pf_state_export	*ps_states;
4586869f90bSKristof Provost	};
4590592a4c8SKristof Provost};
4600592a4c8SKristof Provost
4616869f90bSKristof Provoststruct pf_state_export {
4626869f90bSKristof Provost	uint64_t	 version;
4636869f90bSKristof Provost	uint64_t	 id;
4646869f90bSKristof Provost	char		 ifname[IFNAMSIZ];
4656869f90bSKristof Provost	char		 orig_ifname[IFNAMSIZ];
4666869f90bSKristof Provost	struct pf_state_key_export	 key[2];
4676869f90bSKristof Provost	struct pf_state_peer_export	 src;
4686869f90bSKristof Provost	struct pf_state_peer_export	 dst;
4696869f90bSKristof Provost	struct pf_addr	 rt_addr;
4706869f90bSKristof Provost	uint32_t	 rule;
4716869f90bSKristof Provost	uint32_t	 anchor;
4726869f90bSKristof Provost	uint32_t	 nat_rule;
4736869f90bSKristof Provost	uint32_t	 creation;
4746869f90bSKristof Provost	uint32_t	 expire;
4756869f90bSKristof Provost	uint32_t	 spare0;
4766869f90bSKristof Provost	uint64_t	 packets[2];
4776869f90bSKristof Provost	uint64_t	 bytes[2];
4786869f90bSKristof Provost	uint32_t	 creatorid;
4796869f90bSKristof Provost	uint32_t	 spare1;
4806869f90bSKristof Provost	sa_family_t	 af;
4816869f90bSKristof Provost	uint8_t		 proto;
4826869f90bSKristof Provost	uint8_t		 direction;
4836869f90bSKristof Provost	uint8_t		 log;
4846869f90bSKristof Provost	uint8_t		 state_flags_compat;
4856869f90bSKristof Provost	uint8_t		 timeout;
4866869f90bSKristof Provost	uint8_t		 sync_flags;
4876869f90bSKristof Provost	uint8_t		 updates;
4886869f90bSKristof Provost	uint16_t	 state_flags;
4896869f90bSKristof Provost	uint16_t	 qid;
4906869f90bSKristof Provost	uint16_t	 pqid;
4916869f90bSKristof Provost	uint16_t	 dnpipe;
4926869f90bSKristof Provost	uint16_t	 dnrpipe;
4936869f90bSKristof Provost	int32_t		 rtableid;
4946869f90bSKristof Provost	uint8_t		 min_ttl;
4956869f90bSKristof Provost	uint8_t		 set_tos;
4966869f90bSKristof Provost	uint16_t	 max_mss;
4976869f90bSKristof Provost	uint8_t		 set_prio[2];
4986869f90bSKristof Provost	uint8_t		 rt;
4996869f90bSKristof Provost	char		 rt_ifname[IFNAMSIZ];
5006869f90bSKristof Provost	uint8_t		 spare[72];
5013b3a8eb9SGleb Smirnoff};
5023b3a8eb9SGleb Smirnoff.Ed
503cc535c95SWill Andrews.It Dv DIOCCHANGERULE Fa "struct pfioc_rule *pcr"
504cc535c95SWill AndrewsAdd or remove the
505cc535c95SWill Andrews.Va rule
506cc535c95SWill Andrewsin the ruleset specified by
507cc535c95SWill Andrews.Va rule.action .
5083b3a8eb9SGleb Smirnoff.Pp
5093b3a8eb9SGleb SmirnoffThe type of operation to be performed is indicated by
5103b3a8eb9SGleb Smirnoff.Va action ,
5113b3a8eb9SGleb Smirnoffwhich can be any of the following:
5123b3a8eb9SGleb Smirnoff.Bd -literal
5133b3a8eb9SGleb Smirnoffenum	{ PF_CHANGE_NONE, PF_CHANGE_ADD_HEAD, PF_CHANGE_ADD_TAIL,
5143b3a8eb9SGleb Smirnoff	  PF_CHANGE_ADD_BEFORE, PF_CHANGE_ADD_AFTER,
5153b3a8eb9SGleb Smirnoff	  PF_CHANGE_REMOVE, PF_CHANGE_GET_TICKET };
5163b3a8eb9SGleb Smirnoff.Ed
5173b3a8eb9SGleb Smirnoff.Pp
5183b3a8eb9SGleb Smirnoff.Va ticket
5193b3a8eb9SGleb Smirnoffmust be set to the value obtained with
5203b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_GET_TICKET
5213b3a8eb9SGleb Smirnofffor all actions except
5223b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_GET_TICKET .
5233b3a8eb9SGleb Smirnoff.Va pool_ticket
5243b3a8eb9SGleb Smirnoffmust be set to the value obtained with the
5253b3a8eb9SGleb Smirnoff.Dv DIOCBEGINADDRS
5263b3a8eb9SGleb Smirnoffcall for all actions except
5273b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_REMOVE
5283b3a8eb9SGleb Smirnoffand
5293b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_GET_TICKET .
5303b3a8eb9SGleb Smirnoff.Va anchor
5313b3a8eb9SGleb Smirnoffindicates to which anchor the operation applies.
5323b3a8eb9SGleb Smirnoff.Va nr
5333b3a8eb9SGleb Smirnoffindicates the rule number against which
5343b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_ADD_BEFORE ,
5353b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_ADD_AFTER ,
5363b3a8eb9SGleb Smirnoffor
5373b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_REMOVE
5383b3a8eb9SGleb Smirnoffactions are applied.
539cc535c95SWill Andrews.\" It Dv DIOCCHANGEALTQ Fa "struct pfioc_altq *pcr"
540cc535c95SWill Andrews.It Dv DIOCCHANGEADDR Fa "struct pfioc_pooladdr *pca"
541cc535c95SWill AndrewsAdd or remove the pool address
542cc535c95SWill Andrews.Va addr
543cc535c95SWill Andrewsfrom the rule specified by
544cc535c95SWill Andrews.Va r_action ,
545cc535c95SWill Andrews.Va r_num ,
546cc535c95SWill Andrewsand
547cc535c95SWill Andrews.Va anchor .
5483b3a8eb9SGleb Smirnoff.It Dv DIOCSETTIMEOUT Fa "struct pfioc_tm *pt"
5493b3a8eb9SGleb Smirnoff.Bd -literal
5503b3a8eb9SGleb Smirnoffstruct pfioc_tm {
5513b3a8eb9SGleb Smirnoff	int		 timeout;
5523b3a8eb9SGleb Smirnoff	int		 seconds;
5533b3a8eb9SGleb Smirnoff};
5543b3a8eb9SGleb Smirnoff.Ed
5553b3a8eb9SGleb Smirnoff.Pp
5563b3a8eb9SGleb SmirnoffSet the state timeout of
5573b3a8eb9SGleb Smirnoff.Va timeout
5583b3a8eb9SGleb Smirnoffto
5593b3a8eb9SGleb Smirnoff.Va seconds .
5603b3a8eb9SGleb SmirnoffThe old value will be placed into
5613b3a8eb9SGleb Smirnoff.Va seconds .
5623b3a8eb9SGleb SmirnoffFor possible values of
5633b3a8eb9SGleb Smirnoff.Va timeout ,
5643b3a8eb9SGleb Smirnoffconsult the
5653b3a8eb9SGleb Smirnoff.Dv PFTM_*
5663b3a8eb9SGleb Smirnoffvalues in
5673b3a8eb9SGleb Smirnoff.Aq Pa net/pfvar.h .
5683b3a8eb9SGleb Smirnoff.It Dv DIOCGETTIMEOUT Fa "struct pfioc_tm *pt"
5693b3a8eb9SGleb SmirnoffGet the state timeout of
5703b3a8eb9SGleb Smirnoff.Va timeout .
5713b3a8eb9SGleb SmirnoffThe value will be placed into the
5723b3a8eb9SGleb Smirnoff.Va seconds
5733b3a8eb9SGleb Smirnofffield.
574cc535c95SWill Andrews.It Dv DIOCCLRRULECTRS
575cc535c95SWill AndrewsClear per-rule statistics.
5763b3a8eb9SGleb Smirnoff.It Dv DIOCSETLIMIT Fa "struct pfioc_limit *pl"
5773b3a8eb9SGleb SmirnoffSet the hard limits on the memory pools used by the packet filter.
5783b3a8eb9SGleb Smirnoff.Bd -literal
5793b3a8eb9SGleb Smirnoffstruct pfioc_limit {
5803b3a8eb9SGleb Smirnoff	int		index;
5813b3a8eb9SGleb Smirnoff	unsigned	limit;
5823b3a8eb9SGleb Smirnoff};
5833b3a8eb9SGleb Smirnoff
5843b3a8eb9SGleb Smirnoffenum	{ PF_LIMIT_STATES, PF_LIMIT_SRC_NODES, PF_LIMIT_FRAGS,
5853b3a8eb9SGleb Smirnoff	  PF_LIMIT_TABLE_ENTRIES, PF_LIMIT_MAX };
5863b3a8eb9SGleb Smirnoff.Ed
5873b3a8eb9SGleb Smirnoff.It Dv DIOCGETLIMIT Fa "struct pfioc_limit *pl"
5883b3a8eb9SGleb SmirnoffGet the hard
5893b3a8eb9SGleb Smirnoff.Va limit
5903b3a8eb9SGleb Smirnofffor the memory pool indicated by
5913b3a8eb9SGleb Smirnoff.Va index .
5923b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRTABLES Fa "struct pfioc_table *io"
5933b3a8eb9SGleb SmirnoffClear all tables.
5943b3a8eb9SGleb SmirnoffAll the ioctls that manipulate radix tables
5953b3a8eb9SGleb Smirnoffuse the same structure described below.
5963b3a8eb9SGleb SmirnoffFor
5973b3a8eb9SGleb Smirnoff.Dv DIOCRCLRTABLES ,
5983b3a8eb9SGleb Smirnoff.Va pfrio_ndel
5993b3a8eb9SGleb Smirnoffcontains on exit the number of tables deleted.
6003b3a8eb9SGleb Smirnoff.Bd -literal
6013b3a8eb9SGleb Smirnoffstruct pfioc_table {
6023b3a8eb9SGleb Smirnoff	struct pfr_table	 pfrio_table;
6033b3a8eb9SGleb Smirnoff	void			*pfrio_buffer;
6043b3a8eb9SGleb Smirnoff	int			 pfrio_esize;
6053b3a8eb9SGleb Smirnoff	int			 pfrio_size;
6063b3a8eb9SGleb Smirnoff	int			 pfrio_size2;
6073b3a8eb9SGleb Smirnoff	int			 pfrio_nadd;
6083b3a8eb9SGleb Smirnoff	int			 pfrio_ndel;
6093b3a8eb9SGleb Smirnoff	int			 pfrio_nchange;
6103b3a8eb9SGleb Smirnoff	int			 pfrio_flags;
6113b3a8eb9SGleb Smirnoff	u_int32_t		 pfrio_ticket;
6123b3a8eb9SGleb Smirnoff};
6133b3a8eb9SGleb Smirnoff#define pfrio_exists    pfrio_nadd
6143b3a8eb9SGleb Smirnoff#define pfrio_nzero     pfrio_nadd
6153b3a8eb9SGleb Smirnoff#define pfrio_nmatch    pfrio_nadd
6163b3a8eb9SGleb Smirnoff#define pfrio_naddr     pfrio_size2
6173b3a8eb9SGleb Smirnoff#define pfrio_setflag   pfrio_size2
6183b3a8eb9SGleb Smirnoff#define pfrio_clrflag   pfrio_nadd
6193b3a8eb9SGleb Smirnoff.Ed
6203b3a8eb9SGleb Smirnoff.It Dv DIOCRADDTABLES Fa "struct pfioc_table *io"
6213b3a8eb9SGleb SmirnoffCreate one or more tables.
6223b3a8eb9SGleb SmirnoffOn entry,
6233b3a8eb9SGleb Smirnoff.Va pfrio_buffer
6243b3a8eb9SGleb Smirnoffmust point to an array of
6253b3a8eb9SGleb Smirnoff.Vt struct pfr_table
6263b3a8eb9SGleb Smirnoffcontaining at least
6273b3a8eb9SGleb Smirnoff.Vt pfrio_size
6283b3a8eb9SGleb Smirnoffelements.
6293b3a8eb9SGleb Smirnoff.Vt pfrio_esize
6303b3a8eb9SGleb Smirnoffmust be the size of
6313b3a8eb9SGleb Smirnoff.Vt struct pfr_table .
6323b3a8eb9SGleb SmirnoffOn exit,
6333b3a8eb9SGleb Smirnoff.Va pfrio_nadd
6343b3a8eb9SGleb Smirnoffcontains the number of tables effectively created.
6353b3a8eb9SGleb Smirnoff.Bd -literal
6363b3a8eb9SGleb Smirnoffstruct pfr_table {
6373b3a8eb9SGleb Smirnoff	char		pfrt_anchor[MAXPATHLEN];
6383b3a8eb9SGleb Smirnoff	char		pfrt_name[PF_TABLE_NAME_SIZE];
6393b3a8eb9SGleb Smirnoff	u_int32_t	pfrt_flags;
6403b3a8eb9SGleb Smirnoff	u_int8_t	pfrt_fback;
6413b3a8eb9SGleb Smirnoff};
6423b3a8eb9SGleb Smirnoff.Ed
6433b3a8eb9SGleb Smirnoff.It Dv DIOCRDELTABLES Fa "struct pfioc_table *io"
6443b3a8eb9SGleb SmirnoffDelete one or more tables.
6453b3a8eb9SGleb SmirnoffOn entry,
6463b3a8eb9SGleb Smirnoff.Va pfrio_buffer
6473b3a8eb9SGleb Smirnoffmust point to an array of
6483b3a8eb9SGleb Smirnoff.Vt struct pfr_table
6493b3a8eb9SGleb Smirnoffcontaining at least
6503b3a8eb9SGleb Smirnoff.Vt pfrio_size
6513b3a8eb9SGleb Smirnoffelements.
6523b3a8eb9SGleb Smirnoff.Vt pfrio_esize
6533b3a8eb9SGleb Smirnoffmust be the size of
6543b3a8eb9SGleb Smirnoff.Vt struct pfr_table .
6553b3a8eb9SGleb SmirnoffOn exit,
6563b3a8eb9SGleb Smirnoff.Va pfrio_ndel
6573b3a8eb9SGleb Smirnoffcontains the number of tables effectively deleted.
6583b3a8eb9SGleb Smirnoff.It Dv DIOCRGETTABLES Fa "struct pfioc_table *io"
6593b3a8eb9SGleb SmirnoffGet the list of all tables.
6603b3a8eb9SGleb SmirnoffOn entry,
6613b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size]
6623b3a8eb9SGleb Smirnoffcontains a valid writeable buffer for
6633b3a8eb9SGleb Smirnoff.Vt pfr_table
6643b3a8eb9SGleb Smirnoffstructures.
6653b3a8eb9SGleb SmirnoffOn exit,
6663b3a8eb9SGleb Smirnoff.Va pfrio_size
6673b3a8eb9SGleb Smirnoffcontains the number of tables written into the buffer.
6683b3a8eb9SGleb SmirnoffIf the buffer is too small, the kernel does not store anything but just
6693b3a8eb9SGleb Smirnoffreturns the required buffer size, without error.
6703b3a8eb9SGleb Smirnoff.It Dv DIOCRGETTSTATS Fa "struct pfioc_table *io"
6713b3a8eb9SGleb SmirnoffThis call is like
6723b3a8eb9SGleb Smirnoff.Dv DIOCRGETTABLES
6733b3a8eb9SGleb Smirnoffbut is used to get an array of
6743b3a8eb9SGleb Smirnoff.Vt pfr_tstats
6753b3a8eb9SGleb Smirnoffstructures.
6763b3a8eb9SGleb Smirnoff.Bd -literal
6773b3a8eb9SGleb Smirnoffstruct pfr_tstats {
6783b3a8eb9SGleb Smirnoff	struct pfr_table pfrts_t;
6793b3a8eb9SGleb Smirnoff	u_int64_t	 pfrts_packets
6803b3a8eb9SGleb Smirnoff			     [PFR_DIR_MAX][PFR_OP_TABLE_MAX];
6813b3a8eb9SGleb Smirnoff	u_int64_t	 pfrts_bytes
6823b3a8eb9SGleb Smirnoff			     [PFR_DIR_MAX][PFR_OP_TABLE_MAX];
6833b3a8eb9SGleb Smirnoff	u_int64_t	 pfrts_match;
6843b3a8eb9SGleb Smirnoff	u_int64_t	 pfrts_nomatch;
685*7e7f8800SKristof Provost	time_t		 pfrts_tzero;
6863b3a8eb9SGleb Smirnoff	int		 pfrts_cnt;
6873b3a8eb9SGleb Smirnoff	int		 pfrts_refcnt[PFR_REFCNT_MAX];
6883b3a8eb9SGleb Smirnoff};
6893b3a8eb9SGleb Smirnoff#define pfrts_name	 pfrts_t.pfrt_name
6903b3a8eb9SGleb Smirnoff#define pfrts_flags	 pfrts_t.pfrt_flags
6913b3a8eb9SGleb Smirnoff.Ed
6923b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRTSTATS Fa "struct pfioc_table *io"
6933b3a8eb9SGleb SmirnoffClear the statistics of one or more tables.
6943b3a8eb9SGleb SmirnoffOn entry,
6953b3a8eb9SGleb Smirnoff.Va pfrio_buffer
6963b3a8eb9SGleb Smirnoffmust point to an array of
6973b3a8eb9SGleb Smirnoff.Vt struct pfr_table
6983b3a8eb9SGleb Smirnoffcontaining at least
6993b3a8eb9SGleb Smirnoff.Vt pfrio_size
7003b3a8eb9SGleb Smirnoffelements.
7013b3a8eb9SGleb Smirnoff.Vt pfrio_esize
7023b3a8eb9SGleb Smirnoffmust be the size of
7033b3a8eb9SGleb Smirnoff.Vt struct pfr_table .
7043b3a8eb9SGleb SmirnoffOn exit,
7053b3a8eb9SGleb Smirnoff.Va pfrio_nzero
7063b3a8eb9SGleb Smirnoffcontains the number of tables effectively cleared.
7073b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRADDRS Fa "struct pfioc_table *io"
7083b3a8eb9SGleb SmirnoffClear all addresses in a table.
7093b3a8eb9SGleb SmirnoffOn entry,
7103b3a8eb9SGleb Smirnoff.Va pfrio_table
7113b3a8eb9SGleb Smirnoffcontains the table to clear.
7123b3a8eb9SGleb SmirnoffOn exit,
7133b3a8eb9SGleb Smirnoff.Va pfrio_ndel
7143b3a8eb9SGleb Smirnoffcontains the number of addresses removed.
7153b3a8eb9SGleb Smirnoff.It Dv DIOCRADDADDRS Fa "struct pfioc_table *io"
7163b3a8eb9SGleb SmirnoffAdd one or more addresses to a table.
7173b3a8eb9SGleb SmirnoffOn entry,
7183b3a8eb9SGleb Smirnoff.Va pfrio_table
7193b3a8eb9SGleb Smirnoffcontains the table ID and
7203b3a8eb9SGleb Smirnoff.Va pfrio_buffer
7213b3a8eb9SGleb Smirnoffmust point to an array of
7223b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
7233b3a8eb9SGleb Smirnoffcontaining at least
7243b3a8eb9SGleb Smirnoff.Vt pfrio_size
7253b3a8eb9SGleb Smirnoffelements to add to the table.
7263b3a8eb9SGleb Smirnoff.Vt pfrio_esize
7273b3a8eb9SGleb Smirnoffmust be the size of
7283b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
7293b3a8eb9SGleb SmirnoffOn exit,
7303b3a8eb9SGleb Smirnoff.Va pfrio_nadd
7313b3a8eb9SGleb Smirnoffcontains the number of addresses effectively added.
7323b3a8eb9SGleb Smirnoff.Bd -literal
7333b3a8eb9SGleb Smirnoffstruct pfr_addr {
7343b3a8eb9SGleb Smirnoff	union {
7353b3a8eb9SGleb Smirnoff		struct in_addr	 _pfra_ip4addr;
7363b3a8eb9SGleb Smirnoff		struct in6_addr	 _pfra_ip6addr;
7373b3a8eb9SGleb Smirnoff	}		 pfra_u;
7383b3a8eb9SGleb Smirnoff	u_int8_t	 pfra_af;
7393b3a8eb9SGleb Smirnoff	u_int8_t	 pfra_net;
7403b3a8eb9SGleb Smirnoff	u_int8_t	 pfra_not;
7413b3a8eb9SGleb Smirnoff	u_int8_t	 pfra_fback;
7423b3a8eb9SGleb Smirnoff};
7433b3a8eb9SGleb Smirnoff#define pfra_ip4addr    pfra_u._pfra_ip4addr
7443b3a8eb9SGleb Smirnoff#define pfra_ip6addr    pfra_u._pfra_ip6addr
7453b3a8eb9SGleb Smirnoff.Ed
7463b3a8eb9SGleb Smirnoff.It Dv DIOCRDELADDRS Fa "struct pfioc_table *io"
7473b3a8eb9SGleb SmirnoffDelete one or more addresses from a table.
7483b3a8eb9SGleb SmirnoffOn entry,
7493b3a8eb9SGleb Smirnoff.Va pfrio_table
7503b3a8eb9SGleb Smirnoffcontains the table ID and
7513b3a8eb9SGleb Smirnoff.Va pfrio_buffer
7523b3a8eb9SGleb Smirnoffmust point to an array of
7533b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
7543b3a8eb9SGleb Smirnoffcontaining at least
7553b3a8eb9SGleb Smirnoff.Vt pfrio_size
7563b3a8eb9SGleb Smirnoffelements to delete from the table.
7573b3a8eb9SGleb Smirnoff.Vt pfrio_esize
7583b3a8eb9SGleb Smirnoffmust be the size of
7593b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
7603b3a8eb9SGleb SmirnoffOn exit,
7613b3a8eb9SGleb Smirnoff.Va pfrio_ndel
7623b3a8eb9SGleb Smirnoffcontains the number of addresses effectively deleted.
7633b3a8eb9SGleb Smirnoff.It Dv DIOCRSETADDRS Fa "struct pfioc_table *io"
7643b3a8eb9SGleb SmirnoffReplace the content of a table by a new address list.
7653b3a8eb9SGleb SmirnoffThis is the most complicated command, which uses all the structure members.
7663b3a8eb9SGleb Smirnoff.Pp
7673b3a8eb9SGleb SmirnoffOn entry,
7683b3a8eb9SGleb Smirnoff.Va pfrio_table
7693b3a8eb9SGleb Smirnoffcontains the table ID and
7703b3a8eb9SGleb Smirnoff.Va pfrio_buffer
7713b3a8eb9SGleb Smirnoffmust point to an array of
7723b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
7733b3a8eb9SGleb Smirnoffcontaining at least
7743b3a8eb9SGleb Smirnoff.Vt pfrio_size
7753b3a8eb9SGleb Smirnoffelements which become the new contents of the table.
7763b3a8eb9SGleb Smirnoff.Vt pfrio_esize
7773b3a8eb9SGleb Smirnoffmust be the size of
7783b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
7793b3a8eb9SGleb SmirnoffAdditionally, if
7803b3a8eb9SGleb Smirnoff.Va pfrio_size2
7813b3a8eb9SGleb Smirnoffis non-zero,
7823b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size..pfrio_size2]
7833b3a8eb9SGleb Smirnoffmust be a writeable buffer, into which the kernel can copy the
7843b3a8eb9SGleb Smirnoffaddresses that have been deleted during the replace operation.
7853b3a8eb9SGleb SmirnoffOn exit,
7863b3a8eb9SGleb Smirnoff.Va pfrio_ndel ,
7873b3a8eb9SGleb Smirnoff.Va pfrio_nadd ,
7883b3a8eb9SGleb Smirnoffand
7893b3a8eb9SGleb Smirnoff.Va pfrio_nchange
7903b3a8eb9SGleb Smirnoffcontain the number of addresses deleted, added, and changed by the
7913b3a8eb9SGleb Smirnoffkernel.
7923b3a8eb9SGleb SmirnoffIf
7933b3a8eb9SGleb Smirnoff.Va pfrio_size2
7943b3a8eb9SGleb Smirnoffwas set on entry,
7953b3a8eb9SGleb Smirnoff.Va pfrio_size2
7963b3a8eb9SGleb Smirnoffwill point to the size of the buffer used, exactly like
7973b3a8eb9SGleb Smirnoff.Dv DIOCRGETADDRS .
7983b3a8eb9SGleb Smirnoff.It Dv DIOCRGETADDRS Fa "struct pfioc_table *io"
7993b3a8eb9SGleb SmirnoffGet all the addresses of a table.
8003b3a8eb9SGleb SmirnoffOn entry,
8013b3a8eb9SGleb Smirnoff.Va pfrio_table
8023b3a8eb9SGleb Smirnoffcontains the table ID and
8033b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size]
8043b3a8eb9SGleb Smirnoffcontains a valid writeable buffer for
8053b3a8eb9SGleb Smirnoff.Vt pfr_addr
8063b3a8eb9SGleb Smirnoffstructures.
8073b3a8eb9SGleb SmirnoffOn exit,
8083b3a8eb9SGleb Smirnoff.Va pfrio_size
8093b3a8eb9SGleb Smirnoffcontains the number of addresses written into the buffer.
8103b3a8eb9SGleb SmirnoffIf the buffer was too small, the kernel does not store anything but just
8113b3a8eb9SGleb Smirnoffreturns the required buffer size, without returning an error.
8123b3a8eb9SGleb Smirnoff.It Dv DIOCRGETASTATS Fa "struct pfioc_table *io"
8133b3a8eb9SGleb SmirnoffThis call is like
8143b3a8eb9SGleb Smirnoff.Dv DIOCRGETADDRS
8153b3a8eb9SGleb Smirnoffbut is used to get an array of
8163b3a8eb9SGleb Smirnoff.Vt pfr_astats
8173b3a8eb9SGleb Smirnoffstructures.
8183b3a8eb9SGleb Smirnoff.Bd -literal
8193b3a8eb9SGleb Smirnoffstruct pfr_astats {
8203b3a8eb9SGleb Smirnoff	struct pfr_addr	 pfras_a;
8213b3a8eb9SGleb Smirnoff	u_int64_t	 pfras_packets
8223b3a8eb9SGleb Smirnoff			     [PFR_DIR_MAX][PFR_OP_ADDR_MAX];
8233b3a8eb9SGleb Smirnoff	u_int64_t	 pfras_bytes
8243b3a8eb9SGleb Smirnoff			     [PFR_DIR_MAX][PFR_OP_ADDR_MAX];
825*7e7f8800SKristof Provost	time_t		 pfras_tzero;
8263b3a8eb9SGleb Smirnoff};
8273b3a8eb9SGleb Smirnoff.Ed
8283b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRASTATS Fa "struct pfioc_table *io"
8293b3a8eb9SGleb SmirnoffClear the statistics of one or more addresses.
8303b3a8eb9SGleb SmirnoffOn entry,
8313b3a8eb9SGleb Smirnoff.Va pfrio_table
8323b3a8eb9SGleb Smirnoffcontains the table ID and
8333b3a8eb9SGleb Smirnoff.Va pfrio_buffer
8343b3a8eb9SGleb Smirnoffmust point to an array of
8353b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
8363b3a8eb9SGleb Smirnoffcontaining at least
8373b3a8eb9SGleb Smirnoff.Vt pfrio_size
8383b3a8eb9SGleb Smirnoffelements to be cleared from the table.
8393b3a8eb9SGleb Smirnoff.Vt pfrio_esize
8403b3a8eb9SGleb Smirnoffmust be the size of
8413b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
8423b3a8eb9SGleb SmirnoffOn exit,
8433b3a8eb9SGleb Smirnoff.Va pfrio_nzero
8443b3a8eb9SGleb Smirnoffcontains the number of addresses effectively cleared.
8453b3a8eb9SGleb Smirnoff.It Dv DIOCRTSTADDRS Fa "struct pfioc_table *io"
8463b3a8eb9SGleb SmirnoffTest if the given addresses match a table.
8473b3a8eb9SGleb SmirnoffOn entry,
8483b3a8eb9SGleb Smirnoff.Va pfrio_table
8493b3a8eb9SGleb Smirnoffcontains the table ID and
8503b3a8eb9SGleb Smirnoff.Va pfrio_buffer
8513b3a8eb9SGleb Smirnoffmust point to an array of
8523b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
8533b3a8eb9SGleb Smirnoffcontaining at least
8543b3a8eb9SGleb Smirnoff.Vt pfrio_size
8553b3a8eb9SGleb Smirnoffelements, each of which will be tested for a match in the table.
8563b3a8eb9SGleb Smirnoff.Vt pfrio_esize
8573b3a8eb9SGleb Smirnoffmust be the size of
8583b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
8593b3a8eb9SGleb SmirnoffOn exit, the kernel updates the
8603b3a8eb9SGleb Smirnoff.Vt pfr_addr
8613b3a8eb9SGleb Smirnoffarray by setting the
8623b3a8eb9SGleb Smirnoff.Va pfra_fback
8633b3a8eb9SGleb Smirnoffmember appropriately.
8643b3a8eb9SGleb Smirnoff.It Dv DIOCRSETTFLAGS Fa "struct pfioc_table *io"
8653b3a8eb9SGleb SmirnoffChange the
8663b3a8eb9SGleb Smirnoff.Dv PFR_TFLAG_CONST
8673b3a8eb9SGleb Smirnoffor
8683b3a8eb9SGleb Smirnoff.Dv PFR_TFLAG_PERSIST
8693b3a8eb9SGleb Smirnoffflags of a table.
8703b3a8eb9SGleb SmirnoffOn entry,
8713b3a8eb9SGleb Smirnoff.Va pfrio_buffer
8723b3a8eb9SGleb Smirnoffmust point to an array of
8733b3a8eb9SGleb Smirnoff.Vt struct pfr_table
8743b3a8eb9SGleb Smirnoffcontaining at least
8753b3a8eb9SGleb Smirnoff.Vt pfrio_size
8763b3a8eb9SGleb Smirnoffelements.
8773b3a8eb9SGleb Smirnoff.Va pfrio_esize
8783b3a8eb9SGleb Smirnoffmust be the size of
8793b3a8eb9SGleb Smirnoff.Vt struct pfr_table .
8803b3a8eb9SGleb Smirnoff.Va pfrio_setflag
8813b3a8eb9SGleb Smirnoffmust contain the flags to add, while
8823b3a8eb9SGleb Smirnoff.Va pfrio_clrflag
8833b3a8eb9SGleb Smirnoffmust contain the flags to remove.
8843b3a8eb9SGleb SmirnoffOn exit,
8853b3a8eb9SGleb Smirnoff.Va pfrio_nchange
8863b3a8eb9SGleb Smirnoffand
8873b3a8eb9SGleb Smirnoff.Va pfrio_ndel
8883b3a8eb9SGleb Smirnoffcontain the number of tables altered or deleted by the kernel.
8893b3a8eb9SGleb SmirnoffYes, tables can be deleted if one removes the
8903b3a8eb9SGleb Smirnoff.Dv PFR_TFLAG_PERSIST
8913b3a8eb9SGleb Smirnoffflag of an unreferenced table.
8923b3a8eb9SGleb Smirnoff.It Dv DIOCRINADEFINE Fa "struct pfioc_table *io"
8933b3a8eb9SGleb SmirnoffDefines a table in the inactive set.
8943b3a8eb9SGleb SmirnoffOn entry,
8953b3a8eb9SGleb Smirnoff.Va pfrio_table
8963b3a8eb9SGleb Smirnoffcontains the table ID and
8973b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size]
8983b3a8eb9SGleb Smirnoffcontains an array of
8993b3a8eb9SGleb Smirnoff.Vt pfr_addr
9003b3a8eb9SGleb Smirnoffstructures to put in the table.
9013b3a8eb9SGleb SmirnoffA valid ticket must also be supplied to
9023b3a8eb9SGleb Smirnoff.Va pfrio_ticket .
9033b3a8eb9SGleb SmirnoffOn exit,
9043b3a8eb9SGleb Smirnoff.Va pfrio_nadd
9053b3a8eb9SGleb Smirnoffcontains 0 if the table was already defined in the inactive list
9063b3a8eb9SGleb Smirnoffor 1 if a new table has been created.
9073b3a8eb9SGleb Smirnoff.Va pfrio_naddr
9083b3a8eb9SGleb Smirnoffcontains the number of addresses effectively put in the table.
9093b3a8eb9SGleb Smirnoff.It Dv DIOCXBEGIN Fa "struct pfioc_trans *io"
9103b3a8eb9SGleb Smirnoff.Bd -literal
9113b3a8eb9SGleb Smirnoffstruct pfioc_trans {
9123b3a8eb9SGleb Smirnoff	int		 size;	/* number of elements */
9133b3a8eb9SGleb Smirnoff	int		 esize;	/* size of each element in bytes */
9143b3a8eb9SGleb Smirnoff	struct pfioc_trans_e {
9153b3a8eb9SGleb Smirnoff		int		rs_num;
9163b3a8eb9SGleb Smirnoff		char		anchor[MAXPATHLEN];
9173b3a8eb9SGleb Smirnoff		u_int32_t	ticket;
9183b3a8eb9SGleb Smirnoff	}		*array;
9193b3a8eb9SGleb Smirnoff};
9203b3a8eb9SGleb Smirnoff.Ed
9213b3a8eb9SGleb Smirnoff.Pp
9223b3a8eb9SGleb SmirnoffClear all the inactive rulesets specified in the
9233b3a8eb9SGleb Smirnoff.Vt pfioc_trans_e
9243b3a8eb9SGleb Smirnoffarray.
9253b3a8eb9SGleb SmirnoffFor each ruleset, a ticket is returned for subsequent "add rule" ioctls,
9263b3a8eb9SGleb Smirnoffas well as for the
9273b3a8eb9SGleb Smirnoff.Dv DIOCXCOMMIT
9283b3a8eb9SGleb Smirnoffand
9293b3a8eb9SGleb Smirnoff.Dv DIOCXROLLBACK
9303b3a8eb9SGleb Smirnoffcalls.
9313b3a8eb9SGleb Smirnoff.Pp
9323b3a8eb9SGleb SmirnoffRuleset types, identified by
9333b3a8eb9SGleb Smirnoff.Va rs_num ,
9343b3a8eb9SGleb Smirnoffinclude the following:
9353b3a8eb9SGleb Smirnoff.Pp
9363b3a8eb9SGleb Smirnoff.Bl -tag -width PF_RULESET_FILTER -offset ind -compact
9373b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_SCRUB
9383b3a8eb9SGleb SmirnoffScrub (packet normalization) rules.
9393b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_FILTER
9403b3a8eb9SGleb SmirnoffFilter rules.
9413b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_NAT
9423b3a8eb9SGleb SmirnoffNAT (Network Address Translation) rules.
9433b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_BINAT
9443b3a8eb9SGleb SmirnoffBidirectional NAT rules.
9453b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_RDR
9463b3a8eb9SGleb SmirnoffRedirect rules.
9473b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_ALTQ
9483b3a8eb9SGleb SmirnoffALTQ disciplines.
9493b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_TABLE
9503b3a8eb9SGleb SmirnoffAddress tables.
9513b3a8eb9SGleb Smirnoff.El
9523b3a8eb9SGleb Smirnoff.It Dv DIOCXCOMMIT Fa "struct pfioc_trans *io"
9533b3a8eb9SGleb SmirnoffAtomically switch a vector of inactive rulesets to the active rulesets.
9543b3a8eb9SGleb SmirnoffThis call is implemented as a standard two-phase commit, which will either
9553b3a8eb9SGleb Smirnofffail for all rulesets or completely succeed.
9563b3a8eb9SGleb SmirnoffAll tickets need to be valid.
9573b3a8eb9SGleb SmirnoffThis ioctl returns
9583b3a8eb9SGleb Smirnoff.Er EBUSY
9593b3a8eb9SGleb Smirnoffif another process is concurrently updating some of the same rulesets.
9603b3a8eb9SGleb Smirnoff.It Dv DIOCXROLLBACK Fa "struct pfioc_trans *io"
9613b3a8eb9SGleb SmirnoffClean up the kernel by undoing all changes that have taken place on the
9623b3a8eb9SGleb Smirnoffinactive rulesets since the last
9633b3a8eb9SGleb Smirnoff.Dv DIOCXBEGIN .
9643b3a8eb9SGleb Smirnoff.Dv DIOCXROLLBACK
9653b3a8eb9SGleb Smirnoffwill silently ignore rulesets for which the ticket is invalid.
9663b3a8eb9SGleb Smirnoff.It Dv DIOCSETHOSTID Fa "u_int32_t *hostid"
9673b3a8eb9SGleb SmirnoffSet the host ID, which is used by
9683b3a8eb9SGleb Smirnoff.Xr pfsync 4
9693b3a8eb9SGleb Smirnoffto identify which host created state table entries.
9703b3a8eb9SGleb Smirnoff.It Dv DIOCOSFPFLUSH
9713b3a8eb9SGleb SmirnoffFlush the passive OS fingerprint table.
9723b3a8eb9SGleb Smirnoff.It Dv DIOCOSFPADD Fa "struct pf_osfp_ioctl *io"
9733b3a8eb9SGleb Smirnoff.Bd -literal
9743b3a8eb9SGleb Smirnoffstruct pf_osfp_ioctl {
9753b3a8eb9SGleb Smirnoff	struct pf_osfp_entry {
9763b3a8eb9SGleb Smirnoff		SLIST_ENTRY(pf_osfp_entry) fp_entry;
9773b3a8eb9SGleb Smirnoff		pf_osfp_t		fp_os;
9783b3a8eb9SGleb Smirnoff		char			fp_class_nm[PF_OSFP_LEN];
9793b3a8eb9SGleb Smirnoff		char			fp_version_nm[PF_OSFP_LEN];
9803b3a8eb9SGleb Smirnoff		char			fp_subtype_nm[PF_OSFP_LEN];
9813b3a8eb9SGleb Smirnoff	} 			fp_os;
9823b3a8eb9SGleb Smirnoff	pf_tcpopts_t		fp_tcpopts;
9833b3a8eb9SGleb Smirnoff	u_int16_t		fp_wsize;
9843b3a8eb9SGleb Smirnoff	u_int16_t		fp_psize;
9853b3a8eb9SGleb Smirnoff	u_int16_t		fp_mss;
9863b3a8eb9SGleb Smirnoff	u_int16_t		fp_flags;
9873b3a8eb9SGleb Smirnoff	u_int8_t		fp_optcnt;
9883b3a8eb9SGleb Smirnoff	u_int8_t		fp_wscale;
9893b3a8eb9SGleb Smirnoff	u_int8_t		fp_ttl;
9903b3a8eb9SGleb Smirnoff	int			fp_getnum;
9913b3a8eb9SGleb Smirnoff};
9923b3a8eb9SGleb Smirnoff.Ed
9933b3a8eb9SGleb Smirnoff.Pp
9943b3a8eb9SGleb SmirnoffAdd a passive OS fingerprint to the table.
9953b3a8eb9SGleb SmirnoffSet
9963b3a8eb9SGleb Smirnoff.Va fp_os.fp_os
9973b3a8eb9SGleb Smirnoffto the packed fingerprint,
9983b3a8eb9SGleb Smirnoff.Va fp_os.fp_class_nm
9993b3a8eb9SGleb Smirnoffto the name of the class (Linux, Windows, etc),
10003b3a8eb9SGleb Smirnoff.Va fp_os.fp_version_nm
10013b3a8eb9SGleb Smirnoffto the name of the version (NT, 95, 98), and
10023b3a8eb9SGleb Smirnoff.Va fp_os.fp_subtype_nm
10033b3a8eb9SGleb Smirnoffto the name of the subtype or patchlevel.
10043b3a8eb9SGleb SmirnoffThe members
10053b3a8eb9SGleb Smirnoff.Va fp_mss ,
10063b3a8eb9SGleb Smirnoff.Va fp_wsize ,
10073b3a8eb9SGleb Smirnoff.Va fp_psize ,
10083b3a8eb9SGleb Smirnoff.Va fp_ttl ,
10093b3a8eb9SGleb Smirnoff.Va fp_optcnt ,
10103b3a8eb9SGleb Smirnoffand
10113b3a8eb9SGleb Smirnoff.Va fp_wscale
10123b3a8eb9SGleb Smirnoffare set to the TCP MSS, the TCP window size, the IP length, the IP TTL,
10133b3a8eb9SGleb Smirnoffthe number of TCP options, and the TCP window scaling constant of the
10143b3a8eb9SGleb SmirnoffTCP SYN packet, respectively.
10153b3a8eb9SGleb Smirnoff.Pp
10163b3a8eb9SGleb SmirnoffThe
10173b3a8eb9SGleb Smirnoff.Va fp_flags
10183b3a8eb9SGleb Smirnoffmember is filled according to the
10193b3a8eb9SGleb Smirnoff.Aq Pa net/pfvar.h
10203b3a8eb9SGleb Smirnoffinclude file
10213b3a8eb9SGleb Smirnoff.Dv PF_OSFP_*
10223b3a8eb9SGleb Smirnoffdefines.
10233b3a8eb9SGleb SmirnoffThe
10243b3a8eb9SGleb Smirnoff.Va fp_tcpopts
10253b3a8eb9SGleb Smirnoffmember contains packed TCP options.
10263b3a8eb9SGleb SmirnoffEach option uses
10273b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_BITS
10283b3a8eb9SGleb Smirnoffbits in the packed value.
10293b3a8eb9SGleb SmirnoffOptions include any of
10303b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_NOP ,
10313b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_SACK ,
10323b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_WSCALE ,
10333b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_MSS ,
10343b3a8eb9SGleb Smirnoffor
10353b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_TS .
10363b3a8eb9SGleb Smirnoff.Pp
10373b3a8eb9SGleb SmirnoffThe
10383b3a8eb9SGleb Smirnoff.Va fp_getnum
10393b3a8eb9SGleb Smirnoffmember is not used with this ioctl.
10403b3a8eb9SGleb Smirnoff.Pp
10413b3a8eb9SGleb SmirnoffThe structure's slack space must be zeroed for correct operation;
10423b3a8eb9SGleb Smirnoff.Xr memset 3
10433b3a8eb9SGleb Smirnoffthe whole structure to zero before filling and sending to the kernel.
10443b3a8eb9SGleb Smirnoff.It Dv DIOCOSFPGET Fa "struct pf_osfp_ioctl *io"
10453b3a8eb9SGleb SmirnoffGet the passive OS fingerprint number
10463b3a8eb9SGleb Smirnoff.Va fp_getnum
10473b3a8eb9SGleb Smirnofffrom the kernel's fingerprint list.
10483b3a8eb9SGleb SmirnoffThe rest of the structure members will come back filled.
10493b3a8eb9SGleb SmirnoffGet the whole list by repeatedly incrementing the
10503b3a8eb9SGleb Smirnoff.Va fp_getnum
10513b3a8eb9SGleb Smirnoffnumber until the ioctl returns
10523b3a8eb9SGleb Smirnoff.Er EBUSY .
10533b3a8eb9SGleb Smirnoff.It Dv DIOCGETSRCNODES Fa "struct pfioc_src_nodes *psn"
10543b3a8eb9SGleb Smirnoff.Bd -literal
10553b3a8eb9SGleb Smirnoffstruct pfioc_src_nodes {
10563b3a8eb9SGleb Smirnoff	int	psn_len;
10573b3a8eb9SGleb Smirnoff	union {
10583b3a8eb9SGleb Smirnoff		caddr_t		psu_buf;
10593b3a8eb9SGleb Smirnoff		struct pf_src_node	*psu_src_nodes;
10603b3a8eb9SGleb Smirnoff	} psn_u;
10613b3a8eb9SGleb Smirnoff#define psn_buf		psn_u.psu_buf
10623b3a8eb9SGleb Smirnoff#define psn_src_nodes	psn_u.psu_src_nodes
10633b3a8eb9SGleb Smirnoff};
10643b3a8eb9SGleb Smirnoff.Ed
10653b3a8eb9SGleb Smirnoff.Pp
10663b3a8eb9SGleb SmirnoffGet the list of source nodes kept by sticky addresses and source
10673b3a8eb9SGleb Smirnofftracking.
10683b3a8eb9SGleb SmirnoffThe ioctl must be called once with
10693b3a8eb9SGleb Smirnoff.Va psn_len
10703b3a8eb9SGleb Smirnoffset to 0.
10713b3a8eb9SGleb SmirnoffIf the ioctl returns without error,
10723b3a8eb9SGleb Smirnoff.Va psn_len
10733b3a8eb9SGleb Smirnoffwill be set to the size of the buffer required to hold all the
10743b3a8eb9SGleb Smirnoff.Va pf_src_node
10753b3a8eb9SGleb Smirnoffstructures held in the table.
10763b3a8eb9SGleb SmirnoffA buffer of this size should then be allocated, and a pointer to this buffer
10773b3a8eb9SGleb Smirnoffplaced in
10783b3a8eb9SGleb Smirnoff.Va psn_buf .
10793b3a8eb9SGleb SmirnoffThe ioctl must then be called again to fill this buffer with the actual
10803b3a8eb9SGleb Smirnoffsource node data.
10813b3a8eb9SGleb SmirnoffAfter that call,
10823b3a8eb9SGleb Smirnoff.Va psn_len
10833b3a8eb9SGleb Smirnoffwill be set to the length of the buffer actually used.
10843b3a8eb9SGleb Smirnoff.It Dv DIOCCLRSRCNODES
10853b3a8eb9SGleb SmirnoffClear the tree of source tracking nodes.
10863b3a8eb9SGleb Smirnoff.It Dv DIOCIGETIFACES Fa "struct pfioc_iface *io"
10873b3a8eb9SGleb SmirnoffGet the list of interfaces and interface drivers known to
10883b3a8eb9SGleb Smirnoff.Nm .
10893b3a8eb9SGleb SmirnoffAll the ioctls that manipulate interfaces
10903b3a8eb9SGleb Smirnoffuse the same structure described below:
10913b3a8eb9SGleb Smirnoff.Bd -literal
10923b3a8eb9SGleb Smirnoffstruct pfioc_iface {
10933b3a8eb9SGleb Smirnoff	char			 pfiio_name[IFNAMSIZ];
10943b3a8eb9SGleb Smirnoff	void			*pfiio_buffer;
10953b3a8eb9SGleb Smirnoff	int			 pfiio_esize;
10963b3a8eb9SGleb Smirnoff	int			 pfiio_size;
10973b3a8eb9SGleb Smirnoff	int			 pfiio_nzero;
10983b3a8eb9SGleb Smirnoff	int			 pfiio_flags;
10993b3a8eb9SGleb Smirnoff};
11003b3a8eb9SGleb Smirnoff.Ed
11013b3a8eb9SGleb Smirnoff.Pp
11023b3a8eb9SGleb SmirnoffIf not empty,
11033b3a8eb9SGleb Smirnoff.Va pfiio_name
11043b3a8eb9SGleb Smirnoffcan be used to restrict the search to a specific interface or driver.
11053b3a8eb9SGleb Smirnoff.Va pfiio_buffer[pfiio_size]
11063b3a8eb9SGleb Smirnoffis the user-supplied buffer for returning the data.
11073b3a8eb9SGleb SmirnoffOn entry,
11083b3a8eb9SGleb Smirnoff.Va pfiio_size
11093b3a8eb9SGleb Smirnoffcontains the number of
11103b3a8eb9SGleb Smirnoff.Vt pfi_kif
11113b3a8eb9SGleb Smirnoffentries that can fit into the buffer.
11123b3a8eb9SGleb SmirnoffThe kernel will replace this value by the real number of entries it wants
11133b3a8eb9SGleb Smirnoffto return.
11143b3a8eb9SGleb Smirnoff.Va pfiio_esize
11153b3a8eb9SGleb Smirnoffshould be set to
11163b3a8eb9SGleb Smirnoff.Li sizeof(struct pfi_kif) .
11173b3a8eb9SGleb Smirnoff.Pp
11183b3a8eb9SGleb SmirnoffThe data is returned in the
11193b3a8eb9SGleb Smirnoff.Vt pfi_kif
11203b3a8eb9SGleb Smirnoffstructure described below:
11213b3a8eb9SGleb Smirnoff.Bd -literal
11223b3a8eb9SGleb Smirnoffstruct pfi_kif {
11233b3a8eb9SGleb Smirnoff	char				 pfik_name[IFNAMSIZ];
112464b30b7aSKristof Provost	union {
112564b30b7aSKristof Provost		RB_ENTRY(pfi_kif)	 pfik_tree;
112664b30b7aSKristof Provost		LIST_ENTRY(pfi_kif)	 pfik_list;
112764b30b7aSKristof Provost	};
11283b3a8eb9SGleb Smirnoff	u_int64_t			 pfik_packets[2][2][2];
11293b3a8eb9SGleb Smirnoff	u_int64_t			 pfik_bytes[2][2][2];
11303b3a8eb9SGleb Smirnoff	u_int32_t			 pfik_tzero;
113164b30b7aSKristof Provost	u_int				 pfik_flags;
11323b3a8eb9SGleb Smirnoff	struct ifnet			*pfik_ifp;
11333b3a8eb9SGleb Smirnoff	struct ifg_group		*pfik_group;
113464b30b7aSKristof Provost	u_int				 pfik_rulerefs;
11353b3a8eb9SGleb Smirnoff	TAILQ_HEAD(, pfi_dynaddr)	 pfik_dynaddrs;
11363b3a8eb9SGleb Smirnoff};
11373b3a8eb9SGleb Smirnoff.Ed
11383b3a8eb9SGleb Smirnoff.It Dv DIOCSETIFFLAG Fa "struct pfioc_iface *io"
1139646fa387SEdward Tomasz NapieralaSet the user settable flags (described above) of the
11403b3a8eb9SGleb Smirnoff.Nm
11413b3a8eb9SGleb Smirnoffinternal interface description.
11423b3a8eb9SGleb SmirnoffThe filtering process is the same as for
11433b3a8eb9SGleb Smirnoff.Dv DIOCIGETIFACES .
11443b3a8eb9SGleb Smirnoff.Bd -literal
11453b3a8eb9SGleb Smirnoff#define PFI_IFLAG_SKIP	0x0100	/* skip filtering on interface */
11463b3a8eb9SGleb Smirnoff.Ed
11473b3a8eb9SGleb Smirnoff.It Dv DIOCCLRIFFLAG Fa "struct pfioc_iface *io"
11483b3a8eb9SGleb SmirnoffWorks as
11493b3a8eb9SGleb Smirnoff.Dv DIOCSETIFFLAG
11503b3a8eb9SGleb Smirnoffabove but clears the flags.
11513b3a8eb9SGleb Smirnoff.It Dv DIOCKILLSRCNODES Fa "struct pfioc_iface *io"
11523b3a8eb9SGleb SmirnoffExplicitly remove source tracking nodes.
11533b3a8eb9SGleb Smirnoff.El
11543b3a8eb9SGleb Smirnoff.Sh FILES
11553b3a8eb9SGleb Smirnoff.Bl -tag -width /dev/pf -compact
11563b3a8eb9SGleb Smirnoff.It Pa /dev/pf
11573b3a8eb9SGleb Smirnoffpacket filtering device.
11583b3a8eb9SGleb Smirnoff.El
11593b3a8eb9SGleb Smirnoff.Sh EXAMPLES
11603b3a8eb9SGleb SmirnoffThe following example demonstrates how to use the
11613b3a8eb9SGleb Smirnoff.Dv DIOCNATLOOK
11623b3a8eb9SGleb Smirnoffcommand to find the internal host/port of a NATed connection:
11633b3a8eb9SGleb Smirnoff.Bd -literal
11643b3a8eb9SGleb Smirnoff#include <sys/types.h>
11653b3a8eb9SGleb Smirnoff#include <sys/socket.h>
11663b3a8eb9SGleb Smirnoff#include <sys/ioctl.h>
11673b3a8eb9SGleb Smirnoff#include <sys/fcntl.h>
11683b3a8eb9SGleb Smirnoff#include <net/if.h>
11693b3a8eb9SGleb Smirnoff#include <netinet/in.h>
11703b3a8eb9SGleb Smirnoff#include <net/pfvar.h>
11713b3a8eb9SGleb Smirnoff#include <err.h>
11723b3a8eb9SGleb Smirnoff#include <stdio.h>
11733b3a8eb9SGleb Smirnoff#include <stdlib.h>
11743b3a8eb9SGleb Smirnoff
11753b3a8eb9SGleb Smirnoffu_int32_t
11763b3a8eb9SGleb Smirnoffread_address(const char *s)
11773b3a8eb9SGleb Smirnoff{
11783b3a8eb9SGleb Smirnoff	int a, b, c, d;
11793b3a8eb9SGleb Smirnoff
11803b3a8eb9SGleb Smirnoff	sscanf(s, "%i.%i.%i.%i", &a, &b, &c, &d);
11813b3a8eb9SGleb Smirnoff	return htonl(a << 24 | b << 16 | c << 8 | d);
11823b3a8eb9SGleb Smirnoff}
11833b3a8eb9SGleb Smirnoff
11843b3a8eb9SGleb Smirnoffvoid
11853b3a8eb9SGleb Smirnoffprint_address(u_int32_t a)
11863b3a8eb9SGleb Smirnoff{
11873b3a8eb9SGleb Smirnoff	a = ntohl(a);
11883b3a8eb9SGleb Smirnoff	printf("%d.%d.%d.%d", a >> 24 & 255, a >> 16 & 255,
11893b3a8eb9SGleb Smirnoff	    a >> 8 & 255, a & 255);
11903b3a8eb9SGleb Smirnoff}
11913b3a8eb9SGleb Smirnoff
11923b3a8eb9SGleb Smirnoffint
11933b3a8eb9SGleb Smirnoffmain(int argc, char *argv[])
11943b3a8eb9SGleb Smirnoff{
11953b3a8eb9SGleb Smirnoff	struct pfioc_natlook nl;
11963b3a8eb9SGleb Smirnoff	int dev;
11973b3a8eb9SGleb Smirnoff
11983b3a8eb9SGleb Smirnoff	if (argc != 5) {
11993b3a8eb9SGleb Smirnoff		printf("%s <gwy addr> <gwy port> <ext addr> <ext port>\\n",
12003b3a8eb9SGleb Smirnoff		    argv[0]);
12013b3a8eb9SGleb Smirnoff		return 1;
12023b3a8eb9SGleb Smirnoff	}
12033b3a8eb9SGleb Smirnoff
12043b3a8eb9SGleb Smirnoff	dev = open("/dev/pf", O_RDWR);
12053b3a8eb9SGleb Smirnoff	if (dev == -1)
12063b3a8eb9SGleb Smirnoff		err(1, "open(\\"/dev/pf\\") failed");
12073b3a8eb9SGleb Smirnoff
12083b3a8eb9SGleb Smirnoff	memset(&nl, 0, sizeof(struct pfioc_natlook));
12093b3a8eb9SGleb Smirnoff	nl.saddr.v4.s_addr	= read_address(argv[1]);
12103b3a8eb9SGleb Smirnoff	nl.sport		= htons(atoi(argv[2]));
12113b3a8eb9SGleb Smirnoff	nl.daddr.v4.s_addr	= read_address(argv[3]);
12123b3a8eb9SGleb Smirnoff	nl.dport		= htons(atoi(argv[4]));
12133b3a8eb9SGleb Smirnoff	nl.af			= AF_INET;
12143b3a8eb9SGleb Smirnoff	nl.proto		= IPPROTO_TCP;
12153b3a8eb9SGleb Smirnoff	nl.direction		= PF_IN;
12163b3a8eb9SGleb Smirnoff
12173b3a8eb9SGleb Smirnoff	if (ioctl(dev, DIOCNATLOOK, &nl))
12183b3a8eb9SGleb Smirnoff		err(1, "DIOCNATLOOK");
12193b3a8eb9SGleb Smirnoff
12203b3a8eb9SGleb Smirnoff	printf("internal host ");
12213b3a8eb9SGleb Smirnoff	print_address(nl.rsaddr.v4.s_addr);
12223b3a8eb9SGleb Smirnoff	printf(":%u\\n", ntohs(nl.rsport));
12233b3a8eb9SGleb Smirnoff	return 0;
12243b3a8eb9SGleb Smirnoff}
12253b3a8eb9SGleb Smirnoff.Ed
12263b3a8eb9SGleb Smirnoff.Sh SEE ALSO
12273b3a8eb9SGleb Smirnoff.Xr ioctl 2 ,
12283b3a8eb9SGleb Smirnoff.Xr altq 4 ,
12293b3a8eb9SGleb Smirnoff.Xr if_bridge 4 ,
12303b3a8eb9SGleb Smirnoff.Xr pflog 4 ,
12313b3a8eb9SGleb Smirnoff.Xr pfsync 4 ,
12323b3a8eb9SGleb Smirnoff.Xr pfctl 8 ,
12333b3a8eb9SGleb Smirnoff.Xr altq 9
12343b3a8eb9SGleb Smirnoff.Sh HISTORY
12353b3a8eb9SGleb SmirnoffThe
12363b3a8eb9SGleb Smirnoff.Nm
12373b3a8eb9SGleb Smirnoffpacket filtering mechanism first appeared in
12383b3a8eb9SGleb Smirnoff.Ox 3.0
12393b3a8eb9SGleb Smirnoffand then
12403b3a8eb9SGleb Smirnoff.Fx 5.2 .
12413b3a8eb9SGleb Smirnoff.Pp
1242be51503dSGleb SmirnoffThis implementation is derived from
12433b3a8eb9SGleb Smirnoff.Ox 4.5 .
12443e609fd4SEd MasteA number of individual features, improvements, bug fixes and security fixes
12453e609fd4SEd Mastehave been ported from later versions of
12463e609fd4SEd Maste.Ox .
1247be51503dSGleb SmirnoffIt has been heavily modified to be capable of running in multithreaded
1248be51503dSGleb Smirnoff.Fx
1249be51503dSGleb Smirnoffkernel and scale its performance on multiple CPUs.
1250