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