xref: /freebsd/share/man/man4/pf.4 (revision 0592a4c83d67547644763fb023abd5eb28e57f92)
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.\"
293b3a8eb9SGleb Smirnoff.\" $FreeBSD$
303b3a8eb9SGleb Smirnoff.\"
31abbcba9cSKristof Provost.Dd May 7, 2021
323b3a8eb9SGleb Smirnoff.Dt PF 4
333b3a8eb9SGleb Smirnoff.Os
343b3a8eb9SGleb Smirnoff.Sh NAME
353b3a8eb9SGleb Smirnoff.Nm pf
363b3a8eb9SGleb Smirnoff.Nd packet filter
373b3a8eb9SGleb Smirnoff.Sh SYNOPSIS
383b3a8eb9SGleb Smirnoff.Cd "device pf"
397f7ef494SGleb Smirnoff.Cd "options PF_DEFAULT_TO_DROP"
403b3a8eb9SGleb Smirnoff.Sh DESCRIPTION
413b3a8eb9SGleb SmirnoffPacket filtering takes place in the kernel.
423b3a8eb9SGleb SmirnoffA pseudo-device,
433b3a8eb9SGleb Smirnoff.Pa /dev/pf ,
443b3a8eb9SGleb Smirnoffallows userland processes to control the
453b3a8eb9SGleb Smirnoffbehavior of the packet filter through an
463b3a8eb9SGleb Smirnoff.Xr ioctl 2
473b3a8eb9SGleb Smirnoffinterface.
483b3a8eb9SGleb SmirnoffThere are commands to enable and disable the filter, load rulesets,
493b3a8eb9SGleb Smirnoffadd and remove individual rules or state table entries,
503b3a8eb9SGleb Smirnoffand retrieve statistics.
513b3a8eb9SGleb SmirnoffThe most commonly used functions are covered by
523b3a8eb9SGleb Smirnoff.Xr pfctl 8 .
533b3a8eb9SGleb Smirnoff.Pp
543b3a8eb9SGleb SmirnoffManipulations like loading a ruleset that involve more than a single
553b3a8eb9SGleb Smirnoff.Xr ioctl 2
563b3a8eb9SGleb Smirnoffcall require a so-called
573b3a8eb9SGleb Smirnoff.Em ticket ,
583b3a8eb9SGleb Smirnoffwhich prevents the occurrence of
593b3a8eb9SGleb Smirnoffmultiple concurrent manipulations.
603b3a8eb9SGleb Smirnoff.Pp
613b3a8eb9SGleb SmirnoffFields of
623b3a8eb9SGleb Smirnoff.Xr ioctl 2
633b3a8eb9SGleb Smirnoffparameter structures that refer to packet data (like
643b3a8eb9SGleb Smirnoffaddresses and ports) are generally expected in network byte-order.
653b3a8eb9SGleb Smirnoff.Pp
663b3a8eb9SGleb SmirnoffRules and address tables are contained in so-called
673b3a8eb9SGleb Smirnoff.Em anchors .
683b3a8eb9SGleb SmirnoffWhen servicing an
693b3a8eb9SGleb Smirnoff.Xr ioctl 2
703b3a8eb9SGleb Smirnoffrequest, if the anchor field of the argument structure is empty,
713b3a8eb9SGleb Smirnoffthe kernel will use the default anchor (i.e., the main ruleset)
723b3a8eb9SGleb Smirnoffin operations.
733b3a8eb9SGleb SmirnoffAnchors are specified by name and may be nested, with components
743b3a8eb9SGleb Smirnoffseparated by
753b3a8eb9SGleb Smirnoff.Sq /
763b3a8eb9SGleb Smirnoffcharacters, similar to how file system hierarchies are laid out.
773b3a8eb9SGleb SmirnoffThe final component of the anchor path is the anchor under which
783b3a8eb9SGleb Smirnoffoperations will be performed.
793b3a8eb9SGleb Smirnoff.Sh SYSCTL VARIABLES AND LOADER TUNABLES
803b3a8eb9SGleb SmirnoffThe following
813b3a8eb9SGleb Smirnoff.Xr loader 8
823b3a8eb9SGleb Smirnofftunables are available.
833b3a8eb9SGleb Smirnoff.Bl -tag -width indent
843b3a8eb9SGleb Smirnoff.It Va net.pf.states_hashsize
853b3a8eb9SGleb SmirnoffSize of hash tables that store states.
863b3a8eb9SGleb SmirnoffShould be power of 2.
8791e0f2d2SKristof ProvostDefault value is 131072.
883b3a8eb9SGleb Smirnoff.It Va net.pf.source_nodes_hashsize
893b3a8eb9SGleb SmirnoffSize of hash table that store source nodes.
903b3a8eb9SGleb SmirnoffShould be power of 2.
9191e0f2d2SKristof ProvostDefault value is 32768.
923b3a8eb9SGleb Smirnoff.El
933b3a8eb9SGleb Smirnoff.Pp
943b3a8eb9SGleb SmirnoffRead only
953b3a8eb9SGleb Smirnoff.Xr sysctl 8
963b3a8eb9SGleb Smirnoffvariables with matching names are provided to obtain current values
973b3a8eb9SGleb Smirnoffat runtime.
987f7ef494SGleb Smirnoff.Sh KERNEL OPTIONS
997f7ef494SGleb SmirnoffThe following options in the kernel configuration file are related to
1007f7ef494SGleb Smirnoff.Nm
1017f7ef494SGleb Smirnoffoperation:
1027f7ef494SGleb Smirnoff.Pp
1037f7ef494SGleb Smirnoff.Bl -tag -width ".Dv PF_DEFAULT_TO_DROP" -compact
1047f7ef494SGleb Smirnoff.It Dv PF_DEFAULT_TO_DROP
1057f7ef494SGleb SmirnoffChange default policy to drop by default
1067f7ef494SGleb Smirnoff.El
1073b3a8eb9SGleb Smirnoff.Sh IOCTL INTERFACE
1083b3a8eb9SGleb Smirnoff.Nm
1093b3a8eb9SGleb Smirnoffsupports the following
1103b3a8eb9SGleb Smirnoff.Xr ioctl 2
1113b3a8eb9SGleb Smirnoffcommands, available through
1123b3a8eb9SGleb Smirnoff.Aq Pa net/pfvar.h :
1133b3a8eb9SGleb Smirnoff.Bl -tag -width xxxxxx
1143b3a8eb9SGleb Smirnoff.It Dv DIOCSTART
1153b3a8eb9SGleb SmirnoffStart the packet filter.
1163b3a8eb9SGleb Smirnoff.It Dv DIOCSTOP
1173b3a8eb9SGleb SmirnoffStop the packet filter.
1183b3a8eb9SGleb Smirnoff.It Dv DIOCSTARTALTQ
1193b3a8eb9SGleb SmirnoffStart the ALTQ bandwidth control system (see
1203b3a8eb9SGleb Smirnoff.Xr altq 9 ) .
1213b3a8eb9SGleb Smirnoff.It Dv DIOCSTOPALTQ
1223b3a8eb9SGleb SmirnoffStop the ALTQ bandwidth control system.
1233b3a8eb9SGleb Smirnoff.It Dv DIOCBEGINADDRS Fa "struct pfioc_pooladdr *pp"
1243b3a8eb9SGleb Smirnoff.Bd -literal
1253b3a8eb9SGleb Smirnoffstruct pfioc_pooladdr {
1263b3a8eb9SGleb Smirnoff	u_int32_t		action;
1273b3a8eb9SGleb Smirnoff	u_int32_t		ticket;
1283b3a8eb9SGleb Smirnoff	u_int32_t		nr;
1293b3a8eb9SGleb Smirnoff	u_int32_t		r_num;
1303b3a8eb9SGleb Smirnoff	u_int8_t		r_action;
1313b3a8eb9SGleb Smirnoff	u_int8_t		r_last;
1323b3a8eb9SGleb Smirnoff	u_int8_t		af;
1333b3a8eb9SGleb Smirnoff	char			anchor[MAXPATHLEN];
1343b3a8eb9SGleb Smirnoff	struct pf_pooladdr	addr;
1353b3a8eb9SGleb Smirnoff};
1363b3a8eb9SGleb Smirnoff.Ed
1373b3a8eb9SGleb Smirnoff.Pp
1383b3a8eb9SGleb SmirnoffClear the buffer address pool and get a
1393b3a8eb9SGleb Smirnoff.Va ticket
1403b3a8eb9SGleb Smirnofffor subsequent
1413b3a8eb9SGleb Smirnoff.Dv DIOCADDADDR ,
142cc535c95SWill Andrews.Dv DIOCADDRULE ,
1433b3a8eb9SGleb Smirnoffand
144cc535c95SWill Andrews.Dv DIOCCHANGERULE
1453b3a8eb9SGleb Smirnoffcalls.
1463b3a8eb9SGleb Smirnoff.It Dv DIOCADDADDR Fa "struct pfioc_pooladdr *pp"
1473b3a8eb9SGleb Smirnoff.Pp
1483b3a8eb9SGleb SmirnoffAdd the pool address
1493b3a8eb9SGleb Smirnoff.Va addr
1503b3a8eb9SGleb Smirnoffto the buffer address pool to be used in the following
1513b3a8eb9SGleb Smirnoff.Dv DIOCADDRULE
152cc535c95SWill Andrewsor
153cc535c95SWill Andrews.Dv DIOCCHANGERULE
1543b3a8eb9SGleb Smirnoffcall.
1553b3a8eb9SGleb SmirnoffAll other members of the structure are ignored.
1563b3a8eb9SGleb Smirnoff.It Dv DIOCADDRULE Fa "struct pfioc_rule *pr"
1573b3a8eb9SGleb Smirnoff.Bd -literal
1583b3a8eb9SGleb Smirnoffstruct pfioc_rule {
1593b3a8eb9SGleb Smirnoff	u_int32_t	action;
1603b3a8eb9SGleb Smirnoff	u_int32_t	ticket;
1613b3a8eb9SGleb Smirnoff	u_int32_t	pool_ticket;
1623b3a8eb9SGleb Smirnoff	u_int32_t	nr;
1633b3a8eb9SGleb Smirnoff	char		anchor[MAXPATHLEN];
1643b3a8eb9SGleb Smirnoff	char		anchor_call[MAXPATHLEN];
1653b3a8eb9SGleb Smirnoff	struct pf_rule	rule;
1663b3a8eb9SGleb Smirnoff};
1673b3a8eb9SGleb Smirnoff.Ed
1683b3a8eb9SGleb Smirnoff.Pp
1693b3a8eb9SGleb SmirnoffAdd
1703b3a8eb9SGleb Smirnoff.Va rule
1713b3a8eb9SGleb Smirnoffat the end of the inactive ruleset.
1723b3a8eb9SGleb SmirnoffThis call requires a
1733b3a8eb9SGleb Smirnoff.Va ticket
1743b3a8eb9SGleb Smirnoffobtained through a preceding
1753b3a8eb9SGleb Smirnoff.Dv DIOCXBEGIN
1763b3a8eb9SGleb Smirnoffcall and a
1773b3a8eb9SGleb Smirnoff.Va pool_ticket
1783b3a8eb9SGleb Smirnoffobtained through a
1793b3a8eb9SGleb Smirnoff.Dv DIOCBEGINADDRS
1803b3a8eb9SGleb Smirnoffcall.
1813b3a8eb9SGleb Smirnoff.Dv DIOCADDADDR
1823b3a8eb9SGleb Smirnoffmust also be called if any pool addresses are required.
1833b3a8eb9SGleb SmirnoffThe optional
1843b3a8eb9SGleb Smirnoff.Va anchor
1853b3a8eb9SGleb Smirnoffname indicates the anchor in which to append the rule.
1863b3a8eb9SGleb Smirnoff.Va nr
1873b3a8eb9SGleb Smirnoffand
1883b3a8eb9SGleb Smirnoff.Va action
1893b3a8eb9SGleb Smirnoffare ignored.
1903b3a8eb9SGleb Smirnoff.It Dv DIOCADDALTQ Fa "struct pfioc_altq *pa"
1913b3a8eb9SGleb SmirnoffAdd an ALTQ discipline or queue.
1923b3a8eb9SGleb Smirnoff.Bd -literal
1933b3a8eb9SGleb Smirnoffstruct pfioc_altq {
1943b3a8eb9SGleb Smirnoff	u_int32_t	action;
1953b3a8eb9SGleb Smirnoff	u_int32_t	ticket;
1963b3a8eb9SGleb Smirnoff	u_int32_t	nr;
1973b3a8eb9SGleb Smirnoff	struct pf_altq  altq;
1983b3a8eb9SGleb Smirnoff};
1993b3a8eb9SGleb Smirnoff.Ed
2003b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULES Fa "struct pfioc_rule *pr"
2013b3a8eb9SGleb SmirnoffGet a
2023b3a8eb9SGleb Smirnoff.Va ticket
2033b3a8eb9SGleb Smirnofffor subsequent
2043b3a8eb9SGleb Smirnoff.Dv DIOCGETRULE
2053b3a8eb9SGleb Smirnoffcalls and the number
2063b3a8eb9SGleb Smirnoff.Va nr
2073b3a8eb9SGleb Smirnoffof rules in the active ruleset.
2083b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULE Fa "struct pfioc_rule *pr"
2093b3a8eb9SGleb SmirnoffGet a
2103b3a8eb9SGleb Smirnoff.Va rule
2113b3a8eb9SGleb Smirnoffby its number
2123b3a8eb9SGleb Smirnoff.Va nr
2133b3a8eb9SGleb Smirnoffusing the
2143b3a8eb9SGleb Smirnoff.Va ticket
2153b3a8eb9SGleb Smirnoffobtained through a preceding
2163b3a8eb9SGleb Smirnoff.Dv DIOCGETRULES
2173b3a8eb9SGleb Smirnoffcall.
2183b3a8eb9SGleb SmirnoffIf
2193b3a8eb9SGleb Smirnoff.Va action
2203b3a8eb9SGleb Smirnoffis set to
2213b3a8eb9SGleb Smirnoff.Dv PF_GET_CLR_CNTR ,
2223b3a8eb9SGleb Smirnoffthe per-rule statistics on the requested rule are cleared.
2233b3a8eb9SGleb Smirnoff.It Dv DIOCGETADDRS Fa "struct pfioc_pooladdr *pp"
2243b3a8eb9SGleb SmirnoffGet a
2253b3a8eb9SGleb Smirnoff.Va ticket
2263b3a8eb9SGleb Smirnofffor subsequent
2273b3a8eb9SGleb Smirnoff.Dv DIOCGETADDR
2283b3a8eb9SGleb Smirnoffcalls and the number
2293b3a8eb9SGleb Smirnoff.Va nr
2303b3a8eb9SGleb Smirnoffof pool addresses in the rule specified with
2313b3a8eb9SGleb Smirnoff.Va r_action ,
2323b3a8eb9SGleb Smirnoff.Va r_num ,
2333b3a8eb9SGleb Smirnoffand
2343b3a8eb9SGleb Smirnoff.Va anchor .
2353b3a8eb9SGleb Smirnoff.It Dv DIOCGETADDR Fa "struct pfioc_pooladdr *pp"
2363b3a8eb9SGleb SmirnoffGet the pool address
2373b3a8eb9SGleb Smirnoff.Va addr
2383b3a8eb9SGleb Smirnoffby its number
2393b3a8eb9SGleb Smirnoff.Va nr
2403b3a8eb9SGleb Smirnofffrom the rule specified with
2413b3a8eb9SGleb Smirnoff.Va r_action ,
2423b3a8eb9SGleb Smirnoff.Va r_num ,
2433b3a8eb9SGleb Smirnoffand
2443b3a8eb9SGleb Smirnoff.Va anchor
2453b3a8eb9SGleb Smirnoffusing the
2463b3a8eb9SGleb Smirnoff.Va ticket
2473b3a8eb9SGleb Smirnoffobtained through a preceding
2483b3a8eb9SGleb Smirnoff.Dv DIOCGETADDRS
2493b3a8eb9SGleb Smirnoffcall.
2503b3a8eb9SGleb Smirnoff.It Dv DIOCGETALTQS Fa "struct pfioc_altq *pa"
2513b3a8eb9SGleb SmirnoffGet a
2523b3a8eb9SGleb Smirnoff.Va ticket
2533b3a8eb9SGleb Smirnofffor subsequent
2543b3a8eb9SGleb Smirnoff.Dv DIOCGETALTQ
2553b3a8eb9SGleb Smirnoffcalls and the number
2563b3a8eb9SGleb Smirnoff.Va nr
2573b3a8eb9SGleb Smirnoffof queues in the active list.
2583b3a8eb9SGleb Smirnoff.It Dv DIOCGETALTQ Fa "struct pfioc_altq *pa"
2593b3a8eb9SGleb SmirnoffGet the queueing discipline
2603b3a8eb9SGleb Smirnoff.Va altq
2613b3a8eb9SGleb Smirnoffby its number
2623b3a8eb9SGleb Smirnoff.Va nr
2633b3a8eb9SGleb Smirnoffusing the
2643b3a8eb9SGleb Smirnoff.Va ticket
2653b3a8eb9SGleb Smirnoffobtained through a preceding
2663b3a8eb9SGleb Smirnoff.Dv DIOCGETALTQS
2673b3a8eb9SGleb Smirnoffcall.
2683b3a8eb9SGleb Smirnoff.It Dv DIOCGETQSTATS Fa "struct pfioc_qstats *pq"
2693b3a8eb9SGleb SmirnoffGet the statistics on a queue.
2703b3a8eb9SGleb Smirnoff.Bd -literal
2713b3a8eb9SGleb Smirnoffstruct pfioc_qstats {
2723b3a8eb9SGleb Smirnoff	u_int32_t	 ticket;
2733b3a8eb9SGleb Smirnoff	u_int32_t	 nr;
2743b3a8eb9SGleb Smirnoff	void		*buf;
2753b3a8eb9SGleb Smirnoff	int		 nbytes;
2763b3a8eb9SGleb Smirnoff	u_int8_t	 scheduler;
2773b3a8eb9SGleb Smirnoff};
2783b3a8eb9SGleb Smirnoff.Ed
2793b3a8eb9SGleb Smirnoff.Pp
2803b3a8eb9SGleb SmirnoffThis call fills in a pointer to the buffer of statistics
2813b3a8eb9SGleb Smirnoff.Va buf ,
2823b3a8eb9SGleb Smirnoffof length
2833b3a8eb9SGleb Smirnoff.Va nbytes ,
2843b3a8eb9SGleb Smirnofffor the queue specified by
2853b3a8eb9SGleb Smirnoff.Va nr .
2863b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULESETS Fa "struct pfioc_ruleset *pr"
2873b3a8eb9SGleb Smirnoff.Bd -literal
2883b3a8eb9SGleb Smirnoffstruct pfioc_ruleset {
2893b3a8eb9SGleb Smirnoff	u_int32_t	 nr;
2903b3a8eb9SGleb Smirnoff	char		 path[MAXPATHLEN];
2913b3a8eb9SGleb Smirnoff	char		 name[PF_ANCHOR_NAME_SIZE];
2923b3a8eb9SGleb Smirnoff};
2933b3a8eb9SGleb Smirnoff.Ed
2943b3a8eb9SGleb Smirnoff.Pp
2953b3a8eb9SGleb SmirnoffGet the number
2963b3a8eb9SGleb Smirnoff.Va nr
2973b3a8eb9SGleb Smirnoffof rulesets (i.e., anchors) directly attached to the anchor named by
2983b3a8eb9SGleb Smirnoff.Va path
2993b3a8eb9SGleb Smirnofffor use in subsequent
3003b3a8eb9SGleb Smirnoff.Dv DIOCGETRULESET
3013b3a8eb9SGleb Smirnoffcalls.
3023b3a8eb9SGleb SmirnoffNested anchors, since they are not directly attached to the given
3033b3a8eb9SGleb Smirnoffanchor, will not be included.
3043b3a8eb9SGleb SmirnoffThis ioctl returns
3053b3a8eb9SGleb Smirnoff.Er EINVAL
3063b3a8eb9SGleb Smirnoffif the given anchor does not exist.
3073b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULESET Fa "struct pfioc_ruleset *pr"
3083b3a8eb9SGleb SmirnoffGet a ruleset (i.e., an anchor)
3093b3a8eb9SGleb Smirnoff.Va name
3103b3a8eb9SGleb Smirnoffby its number
3113b3a8eb9SGleb Smirnoff.Va nr
3123b3a8eb9SGleb Smirnofffrom the given anchor
3133b3a8eb9SGleb Smirnoff.Va path ,
3143b3a8eb9SGleb Smirnoffthe maximum number of which can be obtained from a preceding
3153b3a8eb9SGleb Smirnoff.Dv DIOCGETRULESETS
3163b3a8eb9SGleb Smirnoffcall.
3173b3a8eb9SGleb SmirnoffThis ioctl returns
3183b3a8eb9SGleb Smirnoff.Er EINVAL
3193b3a8eb9SGleb Smirnoffif the given anchor does not exist or
3203b3a8eb9SGleb Smirnoff.Er EBUSY
3213b3a8eb9SGleb Smirnoffif another process is concurrently updating a ruleset.
322cc535c95SWill Andrews.It Dv DIOCADDSTATE Fa "struct pfioc_state *ps"
323cc535c95SWill AndrewsAdd a state entry.
324cc535c95SWill Andrews.Bd -literal
325cc535c95SWill Andrewsstruct pfioc_state {
326cc535c95SWill Andrews	struct pfsync_state	state;
327cc535c95SWill Andrews};
328cc535c95SWill Andrews.Ed
3291732afaaSKristof Provost.It Dv DIOCGETSTATENV Fa "struct pfioc_nv *nv"
330cc535c95SWill AndrewsExtract the entry identified by the
331cc535c95SWill Andrews.Va id
332cc535c95SWill Andrewsand
333cc535c95SWill Andrews.Va creatorid
334cc535c95SWill Andrewsfields of the
335cc535c95SWill Andrews.Va state
3361732afaaSKristof Provostnvlist from the state table.
3373b3a8eb9SGleb Smirnoff.It Dv DIOCKILLSTATES Fa "struct pfioc_state_kill *psk"
3383b3a8eb9SGleb SmirnoffRemove matching entries from the state table.
3393b3a8eb9SGleb SmirnoffThis ioctl returns the number of killed states in
3403b3a8eb9SGleb Smirnoff.Va psk_killed .
3413b3a8eb9SGleb Smirnoff.Bd -literal
3423b3a8eb9SGleb Smirnoffstruct pfioc_state_kill {
3433b3a8eb9SGleb Smirnoff	struct pf_state_cmp	psk_pfcmp;
3443b3a8eb9SGleb Smirnoff	sa_family_t		psk_af;
3453b3a8eb9SGleb Smirnoff	int			psk_proto;
3463b3a8eb9SGleb Smirnoff	struct pf_rule_addr	psk_src;
3473b3a8eb9SGleb Smirnoff	struct pf_rule_addr	psk_dst;
3483b3a8eb9SGleb Smirnoff	char			psk_ifname[IFNAMSIZ];
3493b3a8eb9SGleb Smirnoff	char			psk_label[PF_RULE_LABEL_SIZE];
3503b3a8eb9SGleb Smirnoff	u_int			psk_killed;
3513b3a8eb9SGleb Smirnoff};
3523b3a8eb9SGleb Smirnoff.Ed
3533b3a8eb9SGleb Smirnoff.It Dv DIOCCLRSTATES Fa "struct pfioc_state_kill *psk"
3543b3a8eb9SGleb SmirnoffClear all states.
3553b3a8eb9SGleb SmirnoffIt works like
3563b3a8eb9SGleb Smirnoff.Dv DIOCKILLSTATES ,
3573b3a8eb9SGleb Smirnoffbut ignores the
3583b3a8eb9SGleb Smirnoff.Va psk_af ,
3593b3a8eb9SGleb Smirnoff.Va psk_proto ,
3603b3a8eb9SGleb Smirnoff.Va psk_src ,
3613b3a8eb9SGleb Smirnoffand
3623b3a8eb9SGleb Smirnoff.Va psk_dst
3633b3a8eb9SGleb Smirnofffields of the
3643b3a8eb9SGleb Smirnoff.Vt pfioc_state_kill
3653b3a8eb9SGleb Smirnoffstructure.
3663b3a8eb9SGleb Smirnoff.It Dv DIOCSETSTATUSIF Fa "struct pfioc_if *pi"
3673b3a8eb9SGleb SmirnoffSpecify the interface for which statistics are accumulated.
3683b3a8eb9SGleb Smirnoff.Bd -literal
3693b3a8eb9SGleb Smirnoffstruct pfioc_if {
3703b3a8eb9SGleb Smirnoff	char		 ifname[IFNAMSIZ];
3713b3a8eb9SGleb Smirnoff};
3723b3a8eb9SGleb Smirnoff.Ed
3733b3a8eb9SGleb Smirnoff.It Dv DIOCGETSTATUS Fa "struct pf_status *s"
3743b3a8eb9SGleb SmirnoffGet the internal packet filter statistics.
3753b3a8eb9SGleb Smirnoff.Bd -literal
3763b3a8eb9SGleb Smirnoffstruct pf_status {
3773b3a8eb9SGleb Smirnoff	u_int64_t	counters[PFRES_MAX];
3783b3a8eb9SGleb Smirnoff	u_int64_t	lcounters[LCNT_MAX];
3793b3a8eb9SGleb Smirnoff	u_int64_t	fcounters[FCNT_MAX];
3803b3a8eb9SGleb Smirnoff	u_int64_t	scounters[SCNT_MAX];
3813b3a8eb9SGleb Smirnoff	u_int64_t	pcounters[2][2][3];
3823b3a8eb9SGleb Smirnoff	u_int64_t	bcounters[2][2];
3833b3a8eb9SGleb Smirnoff	u_int32_t	running;
3843b3a8eb9SGleb Smirnoff	u_int32_t	states;
3853b3a8eb9SGleb Smirnoff	u_int32_t	src_nodes;
3863b3a8eb9SGleb Smirnoff	u_int32_t	since;
3873b3a8eb9SGleb Smirnoff	u_int32_t	debug;
3883b3a8eb9SGleb Smirnoff	u_int32_t	hostid;
3893b3a8eb9SGleb Smirnoff	char		ifname[IFNAMSIZ];
3903b3a8eb9SGleb Smirnoff	u_int8_t	pf_chksum[MD5_DIGEST_LENGTH];
3913b3a8eb9SGleb Smirnoff};
3923b3a8eb9SGleb Smirnoff.Ed
3933b3a8eb9SGleb Smirnoff.It Dv DIOCCLRSTATUS
3943b3a8eb9SGleb SmirnoffClear the internal packet filter statistics.
3953b3a8eb9SGleb Smirnoff.It Dv DIOCNATLOOK Fa "struct pfioc_natlook *pnl"
3963b3a8eb9SGleb SmirnoffLook up a state table entry by source and destination addresses and ports.
3973b3a8eb9SGleb Smirnoff.Bd -literal
3983b3a8eb9SGleb Smirnoffstruct pfioc_natlook {
3993b3a8eb9SGleb Smirnoff	struct pf_addr	 saddr;
4003b3a8eb9SGleb Smirnoff	struct pf_addr	 daddr;
4013b3a8eb9SGleb Smirnoff	struct pf_addr	 rsaddr;
4023b3a8eb9SGleb Smirnoff	struct pf_addr	 rdaddr;
4033b3a8eb9SGleb Smirnoff	u_int16_t	 sport;
4043b3a8eb9SGleb Smirnoff	u_int16_t	 dport;
4053b3a8eb9SGleb Smirnoff	u_int16_t	 rsport;
4063b3a8eb9SGleb Smirnoff	u_int16_t	 rdport;
4073b3a8eb9SGleb Smirnoff	sa_family_t	 af;
4083b3a8eb9SGleb Smirnoff	u_int8_t	 proto;
4093b3a8eb9SGleb Smirnoff	u_int8_t	 direction;
4103b3a8eb9SGleb Smirnoff};
4113b3a8eb9SGleb Smirnoff.Ed
4123b3a8eb9SGleb Smirnoff.It Dv DIOCSETDEBUG Fa "u_int32_t *level"
4133b3a8eb9SGleb SmirnoffSet the debug level.
4143b3a8eb9SGleb Smirnoff.Bd -literal
4153b3a8eb9SGleb Smirnoffenum	{ PF_DEBUG_NONE, PF_DEBUG_URGENT, PF_DEBUG_MISC,
4163b3a8eb9SGleb Smirnoff	  PF_DEBUG_NOISY };
4173b3a8eb9SGleb Smirnoff.Ed
418*0592a4c8SKristof Provost.It Dv DIOCGETSTATESNV Fa "struct pfioc_nv *nv"
4193b3a8eb9SGleb SmirnoffGet state table entries.
4203b3a8eb9SGleb Smirnoff.Bd -literal
421*0592a4c8SKristof Provostnvlist pf_state_key {
422*0592a4c8SKristof Provost	nvlist pf_addr	addr[2];
423*0592a4c8SKristof Provost	number		port[2];
424*0592a4c8SKristof Provost	number		af;
425*0592a4c8SKristof Provost	number		proto;
426*0592a4c8SKristof Provost};
427*0592a4c8SKristof Provost
428*0592a4c8SKristof Provostnvlist pf_state_scrub {
429*0592a4c8SKristof Provost	bool	timestamp;
430*0592a4c8SKristof Provost	number	ttl;
431*0592a4c8SKristof Provost	number	ts_mod;
432*0592a4c8SKristof Provost};
433*0592a4c8SKristof Provost
434*0592a4c8SKristof Provostnvlist pf_state_peer {
435*0592a4c8SKristof Provost	nvlist pf_state_scrub	scrub;
436*0592a4c8SKristof Provost	number			seqlo;
437*0592a4c8SKristof Provost	number			seqhi;
438*0592a4c8SKristof Provost	number			seqdiff;
439*0592a4c8SKristof Provost	number			max_win;
440*0592a4c8SKristof Provost	number			mss;
441*0592a4c8SKristof Provost	number			state;
442*0592a4c8SKristof Provost	number			wscale;
443*0592a4c8SKristof Provost};
444*0592a4c8SKristof Provost
445*0592a4c8SKristof Provostnvlist pf_state {
446*0592a4c8SKristof Provost	number			id;
447*0592a4c8SKristof Provost	string			ifname;
448*0592a4c8SKristof Provost	nvlist pf_state_key	stack_key;
449*0592a4c8SKristof Provost	nvlist pf_state_key	wire_key;
450*0592a4c8SKristof Provost	nvlist pf_state_peer	src;
451*0592a4c8SKristof Provost	nvlist pf_state_peer	dst;
452*0592a4c8SKristof Provost	nvlist pf_addr		rt_addr;
453*0592a4c8SKristof Provost	number			rule;
454*0592a4c8SKristof Provost	number			anchor;
455*0592a4c8SKristof Provost	number			nat_rule;
456*0592a4c8SKristof Provost	number			expire;
457*0592a4c8SKristof Provost	number			packets[2];
458*0592a4c8SKristof Provost	number			bytes[2];
459*0592a4c8SKristof Provost	number			creatorid;
460*0592a4c8SKristof Provost	number			direction;
461*0592a4c8SKristof Provost	number			log;
462*0592a4c8SKristof Provost	number			state_flags;
463*0592a4c8SKristof Provost	number			timeout;
464*0592a4c8SKristof Provost	number			sync_flags;
465*0592a4c8SKristof Provost};
466*0592a4c8SKristof Provost
467*0592a4c8SKristof Provostnvlist pf_states {
468*0592a4c8SKristof Provost	number		count;
469*0592a4c8SKristof Provost	nvlist pf_state	states[];
4703b3a8eb9SGleb Smirnoff};
4713b3a8eb9SGleb Smirnoff.Ed
4723b3a8eb9SGleb Smirnoff.Pp
4733b3a8eb9SGleb SmirnoffIf
474*0592a4c8SKristof Provost.Va pfioc_nv.size
475*0592a4c8SKristof Provostis insufficiently large, as many states as possible that can fit into this
476*0592a4c8SKristof Provostsize will be copied into the supplied buffer.
477cc535c95SWill Andrews.It Dv DIOCCHANGERULE Fa "struct pfioc_rule *pcr"
478cc535c95SWill AndrewsAdd or remove the
479cc535c95SWill Andrews.Va rule
480cc535c95SWill Andrewsin the ruleset specified by
481cc535c95SWill Andrews.Va rule.action .
4823b3a8eb9SGleb Smirnoff.Pp
4833b3a8eb9SGleb SmirnoffThe type of operation to be performed is indicated by
4843b3a8eb9SGleb Smirnoff.Va action ,
4853b3a8eb9SGleb Smirnoffwhich can be any of the following:
4863b3a8eb9SGleb Smirnoff.Bd -literal
4873b3a8eb9SGleb Smirnoffenum	{ PF_CHANGE_NONE, PF_CHANGE_ADD_HEAD, PF_CHANGE_ADD_TAIL,
4883b3a8eb9SGleb Smirnoff	  PF_CHANGE_ADD_BEFORE, PF_CHANGE_ADD_AFTER,
4893b3a8eb9SGleb Smirnoff	  PF_CHANGE_REMOVE, PF_CHANGE_GET_TICKET };
4903b3a8eb9SGleb Smirnoff.Ed
4913b3a8eb9SGleb Smirnoff.Pp
4923b3a8eb9SGleb Smirnoff.Va ticket
4933b3a8eb9SGleb Smirnoffmust be set to the value obtained with
4943b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_GET_TICKET
4953b3a8eb9SGleb Smirnofffor all actions except
4963b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_GET_TICKET .
4973b3a8eb9SGleb Smirnoff.Va pool_ticket
4983b3a8eb9SGleb Smirnoffmust be set to the value obtained with the
4993b3a8eb9SGleb Smirnoff.Dv DIOCBEGINADDRS
5003b3a8eb9SGleb Smirnoffcall for all actions except
5013b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_REMOVE
5023b3a8eb9SGleb Smirnoffand
5033b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_GET_TICKET .
5043b3a8eb9SGleb Smirnoff.Va anchor
5053b3a8eb9SGleb Smirnoffindicates to which anchor the operation applies.
5063b3a8eb9SGleb Smirnoff.Va nr
5073b3a8eb9SGleb Smirnoffindicates the rule number against which
5083b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_ADD_BEFORE ,
5093b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_ADD_AFTER ,
5103b3a8eb9SGleb Smirnoffor
5113b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_REMOVE
5123b3a8eb9SGleb Smirnoffactions are applied.
513cc535c95SWill Andrews.\" It Dv DIOCCHANGEALTQ Fa "struct pfioc_altq *pcr"
514cc535c95SWill Andrews.It Dv DIOCCHANGEADDR Fa "struct pfioc_pooladdr *pca"
515cc535c95SWill AndrewsAdd or remove the pool address
516cc535c95SWill Andrews.Va addr
517cc535c95SWill Andrewsfrom the rule specified by
518cc535c95SWill Andrews.Va r_action ,
519cc535c95SWill Andrews.Va r_num ,
520cc535c95SWill Andrewsand
521cc535c95SWill Andrews.Va anchor .
5223b3a8eb9SGleb Smirnoff.It Dv DIOCSETTIMEOUT Fa "struct pfioc_tm *pt"
5233b3a8eb9SGleb Smirnoff.Bd -literal
5243b3a8eb9SGleb Smirnoffstruct pfioc_tm {
5253b3a8eb9SGleb Smirnoff	int		 timeout;
5263b3a8eb9SGleb Smirnoff	int		 seconds;
5273b3a8eb9SGleb Smirnoff};
5283b3a8eb9SGleb Smirnoff.Ed
5293b3a8eb9SGleb Smirnoff.Pp
5303b3a8eb9SGleb SmirnoffSet the state timeout of
5313b3a8eb9SGleb Smirnoff.Va timeout
5323b3a8eb9SGleb Smirnoffto
5333b3a8eb9SGleb Smirnoff.Va seconds .
5343b3a8eb9SGleb SmirnoffThe old value will be placed into
5353b3a8eb9SGleb Smirnoff.Va seconds .
5363b3a8eb9SGleb SmirnoffFor possible values of
5373b3a8eb9SGleb Smirnoff.Va timeout ,
5383b3a8eb9SGleb Smirnoffconsult the
5393b3a8eb9SGleb Smirnoff.Dv PFTM_*
5403b3a8eb9SGleb Smirnoffvalues in
5413b3a8eb9SGleb Smirnoff.Aq Pa net/pfvar.h .
5423b3a8eb9SGleb Smirnoff.It Dv DIOCGETTIMEOUT Fa "struct pfioc_tm *pt"
5433b3a8eb9SGleb SmirnoffGet the state timeout of
5443b3a8eb9SGleb Smirnoff.Va timeout .
5453b3a8eb9SGleb SmirnoffThe value will be placed into the
5463b3a8eb9SGleb Smirnoff.Va seconds
5473b3a8eb9SGleb Smirnofffield.
548cc535c95SWill Andrews.It Dv DIOCCLRRULECTRS
549cc535c95SWill AndrewsClear per-rule statistics.
5503b3a8eb9SGleb Smirnoff.It Dv DIOCSETLIMIT Fa "struct pfioc_limit *pl"
5513b3a8eb9SGleb SmirnoffSet the hard limits on the memory pools used by the packet filter.
5523b3a8eb9SGleb Smirnoff.Bd -literal
5533b3a8eb9SGleb Smirnoffstruct pfioc_limit {
5543b3a8eb9SGleb Smirnoff	int		index;
5553b3a8eb9SGleb Smirnoff	unsigned	limit;
5563b3a8eb9SGleb Smirnoff};
5573b3a8eb9SGleb Smirnoff
5583b3a8eb9SGleb Smirnoffenum	{ PF_LIMIT_STATES, PF_LIMIT_SRC_NODES, PF_LIMIT_FRAGS,
5593b3a8eb9SGleb Smirnoff	  PF_LIMIT_TABLE_ENTRIES, PF_LIMIT_MAX };
5603b3a8eb9SGleb Smirnoff.Ed
5613b3a8eb9SGleb Smirnoff.It Dv DIOCGETLIMIT Fa "struct pfioc_limit *pl"
5623b3a8eb9SGleb SmirnoffGet the hard
5633b3a8eb9SGleb Smirnoff.Va limit
5643b3a8eb9SGleb Smirnofffor the memory pool indicated by
5653b3a8eb9SGleb Smirnoff.Va index .
5663b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRTABLES Fa "struct pfioc_table *io"
5673b3a8eb9SGleb SmirnoffClear all tables.
5683b3a8eb9SGleb SmirnoffAll the ioctls that manipulate radix tables
5693b3a8eb9SGleb Smirnoffuse the same structure described below.
5703b3a8eb9SGleb SmirnoffFor
5713b3a8eb9SGleb Smirnoff.Dv DIOCRCLRTABLES ,
5723b3a8eb9SGleb Smirnoff.Va pfrio_ndel
5733b3a8eb9SGleb Smirnoffcontains on exit the number of tables deleted.
5743b3a8eb9SGleb Smirnoff.Bd -literal
5753b3a8eb9SGleb Smirnoffstruct pfioc_table {
5763b3a8eb9SGleb Smirnoff	struct pfr_table	 pfrio_table;
5773b3a8eb9SGleb Smirnoff	void			*pfrio_buffer;
5783b3a8eb9SGleb Smirnoff	int			 pfrio_esize;
5793b3a8eb9SGleb Smirnoff	int			 pfrio_size;
5803b3a8eb9SGleb Smirnoff	int			 pfrio_size2;
5813b3a8eb9SGleb Smirnoff	int			 pfrio_nadd;
5823b3a8eb9SGleb Smirnoff	int			 pfrio_ndel;
5833b3a8eb9SGleb Smirnoff	int			 pfrio_nchange;
5843b3a8eb9SGleb Smirnoff	int			 pfrio_flags;
5853b3a8eb9SGleb Smirnoff	u_int32_t		 pfrio_ticket;
5863b3a8eb9SGleb Smirnoff};
5873b3a8eb9SGleb Smirnoff#define pfrio_exists    pfrio_nadd
5883b3a8eb9SGleb Smirnoff#define pfrio_nzero     pfrio_nadd
5893b3a8eb9SGleb Smirnoff#define pfrio_nmatch    pfrio_nadd
5903b3a8eb9SGleb Smirnoff#define pfrio_naddr     pfrio_size2
5913b3a8eb9SGleb Smirnoff#define pfrio_setflag   pfrio_size2
5923b3a8eb9SGleb Smirnoff#define pfrio_clrflag   pfrio_nadd
5933b3a8eb9SGleb Smirnoff.Ed
5943b3a8eb9SGleb Smirnoff.It Dv DIOCRADDTABLES Fa "struct pfioc_table *io"
5953b3a8eb9SGleb SmirnoffCreate one or more tables.
5963b3a8eb9SGleb SmirnoffOn entry,
5973b3a8eb9SGleb Smirnoff.Va pfrio_buffer
5983b3a8eb9SGleb Smirnoffmust point to an array of
5993b3a8eb9SGleb Smirnoff.Vt struct pfr_table
6003b3a8eb9SGleb Smirnoffcontaining at least
6013b3a8eb9SGleb Smirnoff.Vt pfrio_size
6023b3a8eb9SGleb Smirnoffelements.
6033b3a8eb9SGleb Smirnoff.Vt pfrio_esize
6043b3a8eb9SGleb Smirnoffmust be the size of
6053b3a8eb9SGleb Smirnoff.Vt struct pfr_table .
6063b3a8eb9SGleb SmirnoffOn exit,
6073b3a8eb9SGleb Smirnoff.Va pfrio_nadd
6083b3a8eb9SGleb Smirnoffcontains the number of tables effectively created.
6093b3a8eb9SGleb Smirnoff.Bd -literal
6103b3a8eb9SGleb Smirnoffstruct pfr_table {
6113b3a8eb9SGleb Smirnoff	char		pfrt_anchor[MAXPATHLEN];
6123b3a8eb9SGleb Smirnoff	char		pfrt_name[PF_TABLE_NAME_SIZE];
6133b3a8eb9SGleb Smirnoff	u_int32_t	pfrt_flags;
6143b3a8eb9SGleb Smirnoff	u_int8_t	pfrt_fback;
6153b3a8eb9SGleb Smirnoff};
6163b3a8eb9SGleb Smirnoff.Ed
6173b3a8eb9SGleb Smirnoff.It Dv DIOCRDELTABLES Fa "struct pfioc_table *io"
6183b3a8eb9SGleb SmirnoffDelete one or more tables.
6193b3a8eb9SGleb SmirnoffOn entry,
6203b3a8eb9SGleb Smirnoff.Va pfrio_buffer
6213b3a8eb9SGleb Smirnoffmust point to an array of
6223b3a8eb9SGleb Smirnoff.Vt struct pfr_table
6233b3a8eb9SGleb Smirnoffcontaining at least
6243b3a8eb9SGleb Smirnoff.Vt pfrio_size
6253b3a8eb9SGleb Smirnoffelements.
6263b3a8eb9SGleb Smirnoff.Vt pfrio_esize
6273b3a8eb9SGleb Smirnoffmust be the size of
6283b3a8eb9SGleb Smirnoff.Vt struct pfr_table .
6293b3a8eb9SGleb SmirnoffOn exit,
6303b3a8eb9SGleb Smirnoff.Va pfrio_ndel
6313b3a8eb9SGleb Smirnoffcontains the number of tables effectively deleted.
6323b3a8eb9SGleb Smirnoff.It Dv DIOCRGETTABLES Fa "struct pfioc_table *io"
6333b3a8eb9SGleb SmirnoffGet the list of all tables.
6343b3a8eb9SGleb SmirnoffOn entry,
6353b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size]
6363b3a8eb9SGleb Smirnoffcontains a valid writeable buffer for
6373b3a8eb9SGleb Smirnoff.Vt pfr_table
6383b3a8eb9SGleb Smirnoffstructures.
6393b3a8eb9SGleb SmirnoffOn exit,
6403b3a8eb9SGleb Smirnoff.Va pfrio_size
6413b3a8eb9SGleb Smirnoffcontains the number of tables written into the buffer.
6423b3a8eb9SGleb SmirnoffIf the buffer is too small, the kernel does not store anything but just
6433b3a8eb9SGleb Smirnoffreturns the required buffer size, without error.
6443b3a8eb9SGleb Smirnoff.It Dv DIOCRGETTSTATS Fa "struct pfioc_table *io"
6453b3a8eb9SGleb SmirnoffThis call is like
6463b3a8eb9SGleb Smirnoff.Dv DIOCRGETTABLES
6473b3a8eb9SGleb Smirnoffbut is used to get an array of
6483b3a8eb9SGleb Smirnoff.Vt pfr_tstats
6493b3a8eb9SGleb Smirnoffstructures.
6503b3a8eb9SGleb Smirnoff.Bd -literal
6513b3a8eb9SGleb Smirnoffstruct pfr_tstats {
6523b3a8eb9SGleb Smirnoff	struct pfr_table pfrts_t;
6533b3a8eb9SGleb Smirnoff	u_int64_t	 pfrts_packets
6543b3a8eb9SGleb Smirnoff			     [PFR_DIR_MAX][PFR_OP_TABLE_MAX];
6553b3a8eb9SGleb Smirnoff	u_int64_t	 pfrts_bytes
6563b3a8eb9SGleb Smirnoff			     [PFR_DIR_MAX][PFR_OP_TABLE_MAX];
6573b3a8eb9SGleb Smirnoff	u_int64_t	 pfrts_match;
6583b3a8eb9SGleb Smirnoff	u_int64_t	 pfrts_nomatch;
6593b3a8eb9SGleb Smirnoff	long		 pfrts_tzero;
6603b3a8eb9SGleb Smirnoff	int		 pfrts_cnt;
6613b3a8eb9SGleb Smirnoff	int		 pfrts_refcnt[PFR_REFCNT_MAX];
6623b3a8eb9SGleb Smirnoff};
6633b3a8eb9SGleb Smirnoff#define pfrts_name	 pfrts_t.pfrt_name
6643b3a8eb9SGleb Smirnoff#define pfrts_flags	 pfrts_t.pfrt_flags
6653b3a8eb9SGleb Smirnoff.Ed
6663b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRTSTATS Fa "struct pfioc_table *io"
6673b3a8eb9SGleb SmirnoffClear the statistics of one or more tables.
6683b3a8eb9SGleb SmirnoffOn entry,
6693b3a8eb9SGleb Smirnoff.Va pfrio_buffer
6703b3a8eb9SGleb Smirnoffmust point to an array of
6713b3a8eb9SGleb Smirnoff.Vt struct pfr_table
6723b3a8eb9SGleb Smirnoffcontaining at least
6733b3a8eb9SGleb Smirnoff.Vt pfrio_size
6743b3a8eb9SGleb Smirnoffelements.
6753b3a8eb9SGleb Smirnoff.Vt pfrio_esize
6763b3a8eb9SGleb Smirnoffmust be the size of
6773b3a8eb9SGleb Smirnoff.Vt struct pfr_table .
6783b3a8eb9SGleb SmirnoffOn exit,
6793b3a8eb9SGleb Smirnoff.Va pfrio_nzero
6803b3a8eb9SGleb Smirnoffcontains the number of tables effectively cleared.
6813b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRADDRS Fa "struct pfioc_table *io"
6823b3a8eb9SGleb SmirnoffClear all addresses in a table.
6833b3a8eb9SGleb SmirnoffOn entry,
6843b3a8eb9SGleb Smirnoff.Va pfrio_table
6853b3a8eb9SGleb Smirnoffcontains the table to clear.
6863b3a8eb9SGleb SmirnoffOn exit,
6873b3a8eb9SGleb Smirnoff.Va pfrio_ndel
6883b3a8eb9SGleb Smirnoffcontains the number of addresses removed.
6893b3a8eb9SGleb Smirnoff.It Dv DIOCRADDADDRS Fa "struct pfioc_table *io"
6903b3a8eb9SGleb SmirnoffAdd one or more addresses to a table.
6913b3a8eb9SGleb SmirnoffOn entry,
6923b3a8eb9SGleb Smirnoff.Va pfrio_table
6933b3a8eb9SGleb Smirnoffcontains the table ID and
6943b3a8eb9SGleb Smirnoff.Va pfrio_buffer
6953b3a8eb9SGleb Smirnoffmust point to an array of
6963b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
6973b3a8eb9SGleb Smirnoffcontaining at least
6983b3a8eb9SGleb Smirnoff.Vt pfrio_size
6993b3a8eb9SGleb Smirnoffelements to add to the table.
7003b3a8eb9SGleb Smirnoff.Vt pfrio_esize
7013b3a8eb9SGleb Smirnoffmust be the size of
7023b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
7033b3a8eb9SGleb SmirnoffOn exit,
7043b3a8eb9SGleb Smirnoff.Va pfrio_nadd
7053b3a8eb9SGleb Smirnoffcontains the number of addresses effectively added.
7063b3a8eb9SGleb Smirnoff.Bd -literal
7073b3a8eb9SGleb Smirnoffstruct pfr_addr {
7083b3a8eb9SGleb Smirnoff	union {
7093b3a8eb9SGleb Smirnoff		struct in_addr	 _pfra_ip4addr;
7103b3a8eb9SGleb Smirnoff		struct in6_addr	 _pfra_ip6addr;
7113b3a8eb9SGleb Smirnoff	}		 pfra_u;
7123b3a8eb9SGleb Smirnoff	u_int8_t	 pfra_af;
7133b3a8eb9SGleb Smirnoff	u_int8_t	 pfra_net;
7143b3a8eb9SGleb Smirnoff	u_int8_t	 pfra_not;
7153b3a8eb9SGleb Smirnoff	u_int8_t	 pfra_fback;
7163b3a8eb9SGleb Smirnoff};
7173b3a8eb9SGleb Smirnoff#define pfra_ip4addr    pfra_u._pfra_ip4addr
7183b3a8eb9SGleb Smirnoff#define pfra_ip6addr    pfra_u._pfra_ip6addr
7193b3a8eb9SGleb Smirnoff.Ed
7203b3a8eb9SGleb Smirnoff.It Dv DIOCRDELADDRS Fa "struct pfioc_table *io"
7213b3a8eb9SGleb SmirnoffDelete one or more addresses from a table.
7223b3a8eb9SGleb SmirnoffOn entry,
7233b3a8eb9SGleb Smirnoff.Va pfrio_table
7243b3a8eb9SGleb Smirnoffcontains the table ID and
7253b3a8eb9SGleb Smirnoff.Va pfrio_buffer
7263b3a8eb9SGleb Smirnoffmust point to an array of
7273b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
7283b3a8eb9SGleb Smirnoffcontaining at least
7293b3a8eb9SGleb Smirnoff.Vt pfrio_size
7303b3a8eb9SGleb Smirnoffelements to delete from the table.
7313b3a8eb9SGleb Smirnoff.Vt pfrio_esize
7323b3a8eb9SGleb Smirnoffmust be the size of
7333b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
7343b3a8eb9SGleb SmirnoffOn exit,
7353b3a8eb9SGleb Smirnoff.Va pfrio_ndel
7363b3a8eb9SGleb Smirnoffcontains the number of addresses effectively deleted.
7373b3a8eb9SGleb Smirnoff.It Dv DIOCRSETADDRS Fa "struct pfioc_table *io"
7383b3a8eb9SGleb SmirnoffReplace the content of a table by a new address list.
7393b3a8eb9SGleb SmirnoffThis is the most complicated command, which uses all the structure members.
7403b3a8eb9SGleb Smirnoff.Pp
7413b3a8eb9SGleb SmirnoffOn entry,
7423b3a8eb9SGleb Smirnoff.Va pfrio_table
7433b3a8eb9SGleb Smirnoffcontains the table ID and
7443b3a8eb9SGleb Smirnoff.Va pfrio_buffer
7453b3a8eb9SGleb Smirnoffmust point to an array of
7463b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
7473b3a8eb9SGleb Smirnoffcontaining at least
7483b3a8eb9SGleb Smirnoff.Vt pfrio_size
7493b3a8eb9SGleb Smirnoffelements which become the new contents of the table.
7503b3a8eb9SGleb Smirnoff.Vt pfrio_esize
7513b3a8eb9SGleb Smirnoffmust be the size of
7523b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
7533b3a8eb9SGleb SmirnoffAdditionally, if
7543b3a8eb9SGleb Smirnoff.Va pfrio_size2
7553b3a8eb9SGleb Smirnoffis non-zero,
7563b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size..pfrio_size2]
7573b3a8eb9SGleb Smirnoffmust be a writeable buffer, into which the kernel can copy the
7583b3a8eb9SGleb Smirnoffaddresses that have been deleted during the replace operation.
7593b3a8eb9SGleb SmirnoffOn exit,
7603b3a8eb9SGleb Smirnoff.Va pfrio_ndel ,
7613b3a8eb9SGleb Smirnoff.Va pfrio_nadd ,
7623b3a8eb9SGleb Smirnoffand
7633b3a8eb9SGleb Smirnoff.Va pfrio_nchange
7643b3a8eb9SGleb Smirnoffcontain the number of addresses deleted, added, and changed by the
7653b3a8eb9SGleb Smirnoffkernel.
7663b3a8eb9SGleb SmirnoffIf
7673b3a8eb9SGleb Smirnoff.Va pfrio_size2
7683b3a8eb9SGleb Smirnoffwas set on entry,
7693b3a8eb9SGleb Smirnoff.Va pfrio_size2
7703b3a8eb9SGleb Smirnoffwill point to the size of the buffer used, exactly like
7713b3a8eb9SGleb Smirnoff.Dv DIOCRGETADDRS .
7723b3a8eb9SGleb Smirnoff.It Dv DIOCRGETADDRS Fa "struct pfioc_table *io"
7733b3a8eb9SGleb SmirnoffGet all the addresses of a table.
7743b3a8eb9SGleb SmirnoffOn entry,
7753b3a8eb9SGleb Smirnoff.Va pfrio_table
7763b3a8eb9SGleb Smirnoffcontains the table ID and
7773b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size]
7783b3a8eb9SGleb Smirnoffcontains a valid writeable buffer for
7793b3a8eb9SGleb Smirnoff.Vt pfr_addr
7803b3a8eb9SGleb Smirnoffstructures.
7813b3a8eb9SGleb SmirnoffOn exit,
7823b3a8eb9SGleb Smirnoff.Va pfrio_size
7833b3a8eb9SGleb Smirnoffcontains the number of addresses written into the buffer.
7843b3a8eb9SGleb SmirnoffIf the buffer was too small, the kernel does not store anything but just
7853b3a8eb9SGleb Smirnoffreturns the required buffer size, without returning an error.
7863b3a8eb9SGleb Smirnoff.It Dv DIOCRGETASTATS Fa "struct pfioc_table *io"
7873b3a8eb9SGleb SmirnoffThis call is like
7883b3a8eb9SGleb Smirnoff.Dv DIOCRGETADDRS
7893b3a8eb9SGleb Smirnoffbut is used to get an array of
7903b3a8eb9SGleb Smirnoff.Vt pfr_astats
7913b3a8eb9SGleb Smirnoffstructures.
7923b3a8eb9SGleb Smirnoff.Bd -literal
7933b3a8eb9SGleb Smirnoffstruct pfr_astats {
7943b3a8eb9SGleb Smirnoff	struct pfr_addr	 pfras_a;
7953b3a8eb9SGleb Smirnoff	u_int64_t	 pfras_packets
7963b3a8eb9SGleb Smirnoff			     [PFR_DIR_MAX][PFR_OP_ADDR_MAX];
7973b3a8eb9SGleb Smirnoff	u_int64_t	 pfras_bytes
7983b3a8eb9SGleb Smirnoff			     [PFR_DIR_MAX][PFR_OP_ADDR_MAX];
7993b3a8eb9SGleb Smirnoff	long		 pfras_tzero;
8003b3a8eb9SGleb Smirnoff};
8013b3a8eb9SGleb Smirnoff.Ed
8023b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRASTATS Fa "struct pfioc_table *io"
8033b3a8eb9SGleb SmirnoffClear the statistics of one or more addresses.
8043b3a8eb9SGleb SmirnoffOn entry,
8053b3a8eb9SGleb Smirnoff.Va pfrio_table
8063b3a8eb9SGleb Smirnoffcontains the table ID and
8073b3a8eb9SGleb Smirnoff.Va pfrio_buffer
8083b3a8eb9SGleb Smirnoffmust point to an array of
8093b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
8103b3a8eb9SGleb Smirnoffcontaining at least
8113b3a8eb9SGleb Smirnoff.Vt pfrio_size
8123b3a8eb9SGleb Smirnoffelements to be cleared from the table.
8133b3a8eb9SGleb Smirnoff.Vt pfrio_esize
8143b3a8eb9SGleb Smirnoffmust be the size of
8153b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
8163b3a8eb9SGleb SmirnoffOn exit,
8173b3a8eb9SGleb Smirnoff.Va pfrio_nzero
8183b3a8eb9SGleb Smirnoffcontains the number of addresses effectively cleared.
8193b3a8eb9SGleb Smirnoff.It Dv DIOCRTSTADDRS Fa "struct pfioc_table *io"
8203b3a8eb9SGleb SmirnoffTest if the given addresses match a table.
8213b3a8eb9SGleb SmirnoffOn entry,
8223b3a8eb9SGleb Smirnoff.Va pfrio_table
8233b3a8eb9SGleb Smirnoffcontains the table ID and
8243b3a8eb9SGleb Smirnoff.Va pfrio_buffer
8253b3a8eb9SGleb Smirnoffmust point to an array of
8263b3a8eb9SGleb Smirnoff.Vt struct pfr_addr
8273b3a8eb9SGleb Smirnoffcontaining at least
8283b3a8eb9SGleb Smirnoff.Vt pfrio_size
8293b3a8eb9SGleb Smirnoffelements, each of which will be tested for a match in the table.
8303b3a8eb9SGleb Smirnoff.Vt pfrio_esize
8313b3a8eb9SGleb Smirnoffmust be the size of
8323b3a8eb9SGleb Smirnoff.Vt struct pfr_addr .
8333b3a8eb9SGleb SmirnoffOn exit, the kernel updates the
8343b3a8eb9SGleb Smirnoff.Vt pfr_addr
8353b3a8eb9SGleb Smirnoffarray by setting the
8363b3a8eb9SGleb Smirnoff.Va pfra_fback
8373b3a8eb9SGleb Smirnoffmember appropriately.
8383b3a8eb9SGleb Smirnoff.It Dv DIOCRSETTFLAGS Fa "struct pfioc_table *io"
8393b3a8eb9SGleb SmirnoffChange the
8403b3a8eb9SGleb Smirnoff.Dv PFR_TFLAG_CONST
8413b3a8eb9SGleb Smirnoffor
8423b3a8eb9SGleb Smirnoff.Dv PFR_TFLAG_PERSIST
8433b3a8eb9SGleb Smirnoffflags of a table.
8443b3a8eb9SGleb SmirnoffOn entry,
8453b3a8eb9SGleb Smirnoff.Va pfrio_buffer
8463b3a8eb9SGleb Smirnoffmust point to an array of
8473b3a8eb9SGleb Smirnoff.Vt struct pfr_table
8483b3a8eb9SGleb Smirnoffcontaining at least
8493b3a8eb9SGleb Smirnoff.Vt pfrio_size
8503b3a8eb9SGleb Smirnoffelements.
8513b3a8eb9SGleb Smirnoff.Va pfrio_esize
8523b3a8eb9SGleb Smirnoffmust be the size of
8533b3a8eb9SGleb Smirnoff.Vt struct pfr_table .
8543b3a8eb9SGleb Smirnoff.Va pfrio_setflag
8553b3a8eb9SGleb Smirnoffmust contain the flags to add, while
8563b3a8eb9SGleb Smirnoff.Va pfrio_clrflag
8573b3a8eb9SGleb Smirnoffmust contain the flags to remove.
8583b3a8eb9SGleb SmirnoffOn exit,
8593b3a8eb9SGleb Smirnoff.Va pfrio_nchange
8603b3a8eb9SGleb Smirnoffand
8613b3a8eb9SGleb Smirnoff.Va pfrio_ndel
8623b3a8eb9SGleb Smirnoffcontain the number of tables altered or deleted by the kernel.
8633b3a8eb9SGleb SmirnoffYes, tables can be deleted if one removes the
8643b3a8eb9SGleb Smirnoff.Dv PFR_TFLAG_PERSIST
8653b3a8eb9SGleb Smirnoffflag of an unreferenced table.
8663b3a8eb9SGleb Smirnoff.It Dv DIOCRINADEFINE Fa "struct pfioc_table *io"
8673b3a8eb9SGleb SmirnoffDefines a table in the inactive set.
8683b3a8eb9SGleb SmirnoffOn entry,
8693b3a8eb9SGleb Smirnoff.Va pfrio_table
8703b3a8eb9SGleb Smirnoffcontains the table ID and
8713b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size]
8723b3a8eb9SGleb Smirnoffcontains an array of
8733b3a8eb9SGleb Smirnoff.Vt pfr_addr
8743b3a8eb9SGleb Smirnoffstructures to put in the table.
8753b3a8eb9SGleb SmirnoffA valid ticket must also be supplied to
8763b3a8eb9SGleb Smirnoff.Va pfrio_ticket .
8773b3a8eb9SGleb SmirnoffOn exit,
8783b3a8eb9SGleb Smirnoff.Va pfrio_nadd
8793b3a8eb9SGleb Smirnoffcontains 0 if the table was already defined in the inactive list
8803b3a8eb9SGleb Smirnoffor 1 if a new table has been created.
8813b3a8eb9SGleb Smirnoff.Va pfrio_naddr
8823b3a8eb9SGleb Smirnoffcontains the number of addresses effectively put in the table.
8833b3a8eb9SGleb Smirnoff.It Dv DIOCXBEGIN Fa "struct pfioc_trans *io"
8843b3a8eb9SGleb Smirnoff.Bd -literal
8853b3a8eb9SGleb Smirnoffstruct pfioc_trans {
8863b3a8eb9SGleb Smirnoff	int		 size;	/* number of elements */
8873b3a8eb9SGleb Smirnoff	int		 esize;	/* size of each element in bytes */
8883b3a8eb9SGleb Smirnoff	struct pfioc_trans_e {
8893b3a8eb9SGleb Smirnoff		int		rs_num;
8903b3a8eb9SGleb Smirnoff		char		anchor[MAXPATHLEN];
8913b3a8eb9SGleb Smirnoff		u_int32_t	ticket;
8923b3a8eb9SGleb Smirnoff	}		*array;
8933b3a8eb9SGleb Smirnoff};
8943b3a8eb9SGleb Smirnoff.Ed
8953b3a8eb9SGleb Smirnoff.Pp
8963b3a8eb9SGleb SmirnoffClear all the inactive rulesets specified in the
8973b3a8eb9SGleb Smirnoff.Vt pfioc_trans_e
8983b3a8eb9SGleb Smirnoffarray.
8993b3a8eb9SGleb SmirnoffFor each ruleset, a ticket is returned for subsequent "add rule" ioctls,
9003b3a8eb9SGleb Smirnoffas well as for the
9013b3a8eb9SGleb Smirnoff.Dv DIOCXCOMMIT
9023b3a8eb9SGleb Smirnoffand
9033b3a8eb9SGleb Smirnoff.Dv DIOCXROLLBACK
9043b3a8eb9SGleb Smirnoffcalls.
9053b3a8eb9SGleb Smirnoff.Pp
9063b3a8eb9SGleb SmirnoffRuleset types, identified by
9073b3a8eb9SGleb Smirnoff.Va rs_num ,
9083b3a8eb9SGleb Smirnoffinclude the following:
9093b3a8eb9SGleb Smirnoff.Pp
9103b3a8eb9SGleb Smirnoff.Bl -tag -width PF_RULESET_FILTER -offset ind -compact
9113b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_SCRUB
9123b3a8eb9SGleb SmirnoffScrub (packet normalization) rules.
9133b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_FILTER
9143b3a8eb9SGleb SmirnoffFilter rules.
9153b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_NAT
9163b3a8eb9SGleb SmirnoffNAT (Network Address Translation) rules.
9173b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_BINAT
9183b3a8eb9SGleb SmirnoffBidirectional NAT rules.
9193b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_RDR
9203b3a8eb9SGleb SmirnoffRedirect rules.
9213b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_ALTQ
9223b3a8eb9SGleb SmirnoffALTQ disciplines.
9233b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_TABLE
9243b3a8eb9SGleb SmirnoffAddress tables.
9253b3a8eb9SGleb Smirnoff.El
9263b3a8eb9SGleb Smirnoff.It Dv DIOCXCOMMIT Fa "struct pfioc_trans *io"
9273b3a8eb9SGleb SmirnoffAtomically switch a vector of inactive rulesets to the active rulesets.
9283b3a8eb9SGleb SmirnoffThis call is implemented as a standard two-phase commit, which will either
9293b3a8eb9SGleb Smirnofffail for all rulesets or completely succeed.
9303b3a8eb9SGleb SmirnoffAll tickets need to be valid.
9313b3a8eb9SGleb SmirnoffThis ioctl returns
9323b3a8eb9SGleb Smirnoff.Er EBUSY
9333b3a8eb9SGleb Smirnoffif another process is concurrently updating some of the same rulesets.
9343b3a8eb9SGleb Smirnoff.It Dv DIOCXROLLBACK Fa "struct pfioc_trans *io"
9353b3a8eb9SGleb SmirnoffClean up the kernel by undoing all changes that have taken place on the
9363b3a8eb9SGleb Smirnoffinactive rulesets since the last
9373b3a8eb9SGleb Smirnoff.Dv DIOCXBEGIN .
9383b3a8eb9SGleb Smirnoff.Dv DIOCXROLLBACK
9393b3a8eb9SGleb Smirnoffwill silently ignore rulesets for which the ticket is invalid.
9403b3a8eb9SGleb Smirnoff.It Dv DIOCSETHOSTID Fa "u_int32_t *hostid"
9413b3a8eb9SGleb SmirnoffSet the host ID, which is used by
9423b3a8eb9SGleb Smirnoff.Xr pfsync 4
9433b3a8eb9SGleb Smirnoffto identify which host created state table entries.
9443b3a8eb9SGleb Smirnoff.It Dv DIOCOSFPFLUSH
9453b3a8eb9SGleb SmirnoffFlush the passive OS fingerprint table.
9463b3a8eb9SGleb Smirnoff.It Dv DIOCOSFPADD Fa "struct pf_osfp_ioctl *io"
9473b3a8eb9SGleb Smirnoff.Bd -literal
9483b3a8eb9SGleb Smirnoffstruct pf_osfp_ioctl {
9493b3a8eb9SGleb Smirnoff	struct pf_osfp_entry {
9503b3a8eb9SGleb Smirnoff		SLIST_ENTRY(pf_osfp_entry) fp_entry;
9513b3a8eb9SGleb Smirnoff		pf_osfp_t		fp_os;
9523b3a8eb9SGleb Smirnoff		char			fp_class_nm[PF_OSFP_LEN];
9533b3a8eb9SGleb Smirnoff		char			fp_version_nm[PF_OSFP_LEN];
9543b3a8eb9SGleb Smirnoff		char			fp_subtype_nm[PF_OSFP_LEN];
9553b3a8eb9SGleb Smirnoff	} 			fp_os;
9563b3a8eb9SGleb Smirnoff	pf_tcpopts_t		fp_tcpopts;
9573b3a8eb9SGleb Smirnoff	u_int16_t		fp_wsize;
9583b3a8eb9SGleb Smirnoff	u_int16_t		fp_psize;
9593b3a8eb9SGleb Smirnoff	u_int16_t		fp_mss;
9603b3a8eb9SGleb Smirnoff	u_int16_t		fp_flags;
9613b3a8eb9SGleb Smirnoff	u_int8_t		fp_optcnt;
9623b3a8eb9SGleb Smirnoff	u_int8_t		fp_wscale;
9633b3a8eb9SGleb Smirnoff	u_int8_t		fp_ttl;
9643b3a8eb9SGleb Smirnoff	int			fp_getnum;
9653b3a8eb9SGleb Smirnoff};
9663b3a8eb9SGleb Smirnoff.Ed
9673b3a8eb9SGleb Smirnoff.Pp
9683b3a8eb9SGleb SmirnoffAdd a passive OS fingerprint to the table.
9693b3a8eb9SGleb SmirnoffSet
9703b3a8eb9SGleb Smirnoff.Va fp_os.fp_os
9713b3a8eb9SGleb Smirnoffto the packed fingerprint,
9723b3a8eb9SGleb Smirnoff.Va fp_os.fp_class_nm
9733b3a8eb9SGleb Smirnoffto the name of the class (Linux, Windows, etc),
9743b3a8eb9SGleb Smirnoff.Va fp_os.fp_version_nm
9753b3a8eb9SGleb Smirnoffto the name of the version (NT, 95, 98), and
9763b3a8eb9SGleb Smirnoff.Va fp_os.fp_subtype_nm
9773b3a8eb9SGleb Smirnoffto the name of the subtype or patchlevel.
9783b3a8eb9SGleb SmirnoffThe members
9793b3a8eb9SGleb Smirnoff.Va fp_mss ,
9803b3a8eb9SGleb Smirnoff.Va fp_wsize ,
9813b3a8eb9SGleb Smirnoff.Va fp_psize ,
9823b3a8eb9SGleb Smirnoff.Va fp_ttl ,
9833b3a8eb9SGleb Smirnoff.Va fp_optcnt ,
9843b3a8eb9SGleb Smirnoffand
9853b3a8eb9SGleb Smirnoff.Va fp_wscale
9863b3a8eb9SGleb Smirnoffare set to the TCP MSS, the TCP window size, the IP length, the IP TTL,
9873b3a8eb9SGleb Smirnoffthe number of TCP options, and the TCP window scaling constant of the
9883b3a8eb9SGleb SmirnoffTCP SYN packet, respectively.
9893b3a8eb9SGleb Smirnoff.Pp
9903b3a8eb9SGleb SmirnoffThe
9913b3a8eb9SGleb Smirnoff.Va fp_flags
9923b3a8eb9SGleb Smirnoffmember is filled according to the
9933b3a8eb9SGleb Smirnoff.Aq Pa net/pfvar.h
9943b3a8eb9SGleb Smirnoffinclude file
9953b3a8eb9SGleb Smirnoff.Dv PF_OSFP_*
9963b3a8eb9SGleb Smirnoffdefines.
9973b3a8eb9SGleb SmirnoffThe
9983b3a8eb9SGleb Smirnoff.Va fp_tcpopts
9993b3a8eb9SGleb Smirnoffmember contains packed TCP options.
10003b3a8eb9SGleb SmirnoffEach option uses
10013b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_BITS
10023b3a8eb9SGleb Smirnoffbits in the packed value.
10033b3a8eb9SGleb SmirnoffOptions include any of
10043b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_NOP ,
10053b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_SACK ,
10063b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_WSCALE ,
10073b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_MSS ,
10083b3a8eb9SGleb Smirnoffor
10093b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_TS .
10103b3a8eb9SGleb Smirnoff.Pp
10113b3a8eb9SGleb SmirnoffThe
10123b3a8eb9SGleb Smirnoff.Va fp_getnum
10133b3a8eb9SGleb Smirnoffmember is not used with this ioctl.
10143b3a8eb9SGleb Smirnoff.Pp
10153b3a8eb9SGleb SmirnoffThe structure's slack space must be zeroed for correct operation;
10163b3a8eb9SGleb Smirnoff.Xr memset 3
10173b3a8eb9SGleb Smirnoffthe whole structure to zero before filling and sending to the kernel.
10183b3a8eb9SGleb Smirnoff.It Dv DIOCOSFPGET Fa "struct pf_osfp_ioctl *io"
10193b3a8eb9SGleb SmirnoffGet the passive OS fingerprint number
10203b3a8eb9SGleb Smirnoff.Va fp_getnum
10213b3a8eb9SGleb Smirnofffrom the kernel's fingerprint list.
10223b3a8eb9SGleb SmirnoffThe rest of the structure members will come back filled.
10233b3a8eb9SGleb SmirnoffGet the whole list by repeatedly incrementing the
10243b3a8eb9SGleb Smirnoff.Va fp_getnum
10253b3a8eb9SGleb Smirnoffnumber until the ioctl returns
10263b3a8eb9SGleb Smirnoff.Er EBUSY .
10273b3a8eb9SGleb Smirnoff.It Dv DIOCGETSRCNODES Fa "struct pfioc_src_nodes *psn"
10283b3a8eb9SGleb Smirnoff.Bd -literal
10293b3a8eb9SGleb Smirnoffstruct pfioc_src_nodes {
10303b3a8eb9SGleb Smirnoff	int	psn_len;
10313b3a8eb9SGleb Smirnoff	union {
10323b3a8eb9SGleb Smirnoff		caddr_t		psu_buf;
10333b3a8eb9SGleb Smirnoff		struct pf_src_node	*psu_src_nodes;
10343b3a8eb9SGleb Smirnoff	} psn_u;
10353b3a8eb9SGleb Smirnoff#define psn_buf		psn_u.psu_buf
10363b3a8eb9SGleb Smirnoff#define psn_src_nodes	psn_u.psu_src_nodes
10373b3a8eb9SGleb Smirnoff};
10383b3a8eb9SGleb Smirnoff.Ed
10393b3a8eb9SGleb Smirnoff.Pp
10403b3a8eb9SGleb SmirnoffGet the list of source nodes kept by sticky addresses and source
10413b3a8eb9SGleb Smirnofftracking.
10423b3a8eb9SGleb SmirnoffThe ioctl must be called once with
10433b3a8eb9SGleb Smirnoff.Va psn_len
10443b3a8eb9SGleb Smirnoffset to 0.
10453b3a8eb9SGleb SmirnoffIf the ioctl returns without error,
10463b3a8eb9SGleb Smirnoff.Va psn_len
10473b3a8eb9SGleb Smirnoffwill be set to the size of the buffer required to hold all the
10483b3a8eb9SGleb Smirnoff.Va pf_src_node
10493b3a8eb9SGleb Smirnoffstructures held in the table.
10503b3a8eb9SGleb SmirnoffA buffer of this size should then be allocated, and a pointer to this buffer
10513b3a8eb9SGleb Smirnoffplaced in
10523b3a8eb9SGleb Smirnoff.Va psn_buf .
10533b3a8eb9SGleb SmirnoffThe ioctl must then be called again to fill this buffer with the actual
10543b3a8eb9SGleb Smirnoffsource node data.
10553b3a8eb9SGleb SmirnoffAfter that call,
10563b3a8eb9SGleb Smirnoff.Va psn_len
10573b3a8eb9SGleb Smirnoffwill be set to the length of the buffer actually used.
10583b3a8eb9SGleb Smirnoff.It Dv DIOCCLRSRCNODES
10593b3a8eb9SGleb SmirnoffClear the tree of source tracking nodes.
10603b3a8eb9SGleb Smirnoff.It Dv DIOCIGETIFACES Fa "struct pfioc_iface *io"
10613b3a8eb9SGleb SmirnoffGet the list of interfaces and interface drivers known to
10623b3a8eb9SGleb Smirnoff.Nm .
10633b3a8eb9SGleb SmirnoffAll the ioctls that manipulate interfaces
10643b3a8eb9SGleb Smirnoffuse the same structure described below:
10653b3a8eb9SGleb Smirnoff.Bd -literal
10663b3a8eb9SGleb Smirnoffstruct pfioc_iface {
10673b3a8eb9SGleb Smirnoff	char			 pfiio_name[IFNAMSIZ];
10683b3a8eb9SGleb Smirnoff	void			*pfiio_buffer;
10693b3a8eb9SGleb Smirnoff	int			 pfiio_esize;
10703b3a8eb9SGleb Smirnoff	int			 pfiio_size;
10713b3a8eb9SGleb Smirnoff	int			 pfiio_nzero;
10723b3a8eb9SGleb Smirnoff	int			 pfiio_flags;
10733b3a8eb9SGleb Smirnoff};
10743b3a8eb9SGleb Smirnoff.Ed
10753b3a8eb9SGleb Smirnoff.Pp
10763b3a8eb9SGleb SmirnoffIf not empty,
10773b3a8eb9SGleb Smirnoff.Va pfiio_name
10783b3a8eb9SGleb Smirnoffcan be used to restrict the search to a specific interface or driver.
10793b3a8eb9SGleb Smirnoff.Va pfiio_buffer[pfiio_size]
10803b3a8eb9SGleb Smirnoffis the user-supplied buffer for returning the data.
10813b3a8eb9SGleb SmirnoffOn entry,
10823b3a8eb9SGleb Smirnoff.Va pfiio_size
10833b3a8eb9SGleb Smirnoffcontains the number of
10843b3a8eb9SGleb Smirnoff.Vt pfi_kif
10853b3a8eb9SGleb Smirnoffentries that can fit into the buffer.
10863b3a8eb9SGleb SmirnoffThe kernel will replace this value by the real number of entries it wants
10873b3a8eb9SGleb Smirnoffto return.
10883b3a8eb9SGleb Smirnoff.Va pfiio_esize
10893b3a8eb9SGleb Smirnoffshould be set to
10903b3a8eb9SGleb Smirnoff.Li sizeof(struct pfi_kif) .
10913b3a8eb9SGleb Smirnoff.Pp
10923b3a8eb9SGleb SmirnoffThe data is returned in the
10933b3a8eb9SGleb Smirnoff.Vt pfi_kif
10943b3a8eb9SGleb Smirnoffstructure described below:
10953b3a8eb9SGleb Smirnoff.Bd -literal
10963b3a8eb9SGleb Smirnoffstruct pfi_kif {
10973b3a8eb9SGleb Smirnoff	RB_ENTRY(pfi_kif)		 pfik_tree;
10983b3a8eb9SGleb Smirnoff	char				 pfik_name[IFNAMSIZ];
10993b3a8eb9SGleb Smirnoff	u_int64_t			 pfik_packets[2][2][2];
11003b3a8eb9SGleb Smirnoff	u_int64_t			 pfik_bytes[2][2][2];
11013b3a8eb9SGleb Smirnoff	u_int32_t			 pfik_tzero;
11023b3a8eb9SGleb Smirnoff	int				 pfik_flags;
11033b3a8eb9SGleb Smirnoff	struct pf_state_tree_lan_ext	 pfik_lan_ext;
11043b3a8eb9SGleb Smirnoff	struct pf_state_tree_ext_gwy	 pfik_ext_gwy;
11053b3a8eb9SGleb Smirnoff	TAILQ_ENTRY(pfi_kif)		 pfik_w_states;
11063b3a8eb9SGleb Smirnoff	void				*pfik_ah_cookie;
11073b3a8eb9SGleb Smirnoff	struct ifnet			*pfik_ifp;
11083b3a8eb9SGleb Smirnoff	struct ifg_group		*pfik_group;
11093b3a8eb9SGleb Smirnoff	int				 pfik_states;
11103b3a8eb9SGleb Smirnoff	int				 pfik_rules;
11113b3a8eb9SGleb Smirnoff	TAILQ_HEAD(, pfi_dynaddr)	 pfik_dynaddrs;
11123b3a8eb9SGleb Smirnoff};
11133b3a8eb9SGleb Smirnoff.Ed
11143b3a8eb9SGleb Smirnoff.It Dv DIOCSETIFFLAG Fa "struct pfioc_iface *io"
1115646fa387SEdward Tomasz NapieralaSet the user settable flags (described above) of the
11163b3a8eb9SGleb Smirnoff.Nm
11173b3a8eb9SGleb Smirnoffinternal interface description.
11183b3a8eb9SGleb SmirnoffThe filtering process is the same as for
11193b3a8eb9SGleb Smirnoff.Dv DIOCIGETIFACES .
11203b3a8eb9SGleb Smirnoff.Bd -literal
11213b3a8eb9SGleb Smirnoff#define PFI_IFLAG_SKIP	0x0100	/* skip filtering on interface */
11223b3a8eb9SGleb Smirnoff.Ed
11233b3a8eb9SGleb Smirnoff.It Dv DIOCCLRIFFLAG Fa "struct pfioc_iface *io"
11243b3a8eb9SGleb SmirnoffWorks as
11253b3a8eb9SGleb Smirnoff.Dv DIOCSETIFFLAG
11263b3a8eb9SGleb Smirnoffabove but clears the flags.
11273b3a8eb9SGleb Smirnoff.It Dv DIOCKILLSRCNODES Fa "struct pfioc_iface *io"
11283b3a8eb9SGleb SmirnoffExplicitly remove source tracking nodes.
11293b3a8eb9SGleb Smirnoff.El
11303b3a8eb9SGleb Smirnoff.Sh FILES
11313b3a8eb9SGleb Smirnoff.Bl -tag -width /dev/pf -compact
11323b3a8eb9SGleb Smirnoff.It Pa /dev/pf
11333b3a8eb9SGleb Smirnoffpacket filtering device.
11343b3a8eb9SGleb Smirnoff.El
11353b3a8eb9SGleb Smirnoff.Sh EXAMPLES
11363b3a8eb9SGleb SmirnoffThe following example demonstrates how to use the
11373b3a8eb9SGleb Smirnoff.Dv DIOCNATLOOK
11383b3a8eb9SGleb Smirnoffcommand to find the internal host/port of a NATed connection:
11393b3a8eb9SGleb Smirnoff.Bd -literal
11403b3a8eb9SGleb Smirnoff#include <sys/types.h>
11413b3a8eb9SGleb Smirnoff#include <sys/socket.h>
11423b3a8eb9SGleb Smirnoff#include <sys/ioctl.h>
11433b3a8eb9SGleb Smirnoff#include <sys/fcntl.h>
11443b3a8eb9SGleb Smirnoff#include <net/if.h>
11453b3a8eb9SGleb Smirnoff#include <netinet/in.h>
11463b3a8eb9SGleb Smirnoff#include <net/pfvar.h>
11473b3a8eb9SGleb Smirnoff#include <err.h>
11483b3a8eb9SGleb Smirnoff#include <stdio.h>
11493b3a8eb9SGleb Smirnoff#include <stdlib.h>
11503b3a8eb9SGleb Smirnoff
11513b3a8eb9SGleb Smirnoffu_int32_t
11523b3a8eb9SGleb Smirnoffread_address(const char *s)
11533b3a8eb9SGleb Smirnoff{
11543b3a8eb9SGleb Smirnoff	int a, b, c, d;
11553b3a8eb9SGleb Smirnoff
11563b3a8eb9SGleb Smirnoff	sscanf(s, "%i.%i.%i.%i", &a, &b, &c, &d);
11573b3a8eb9SGleb Smirnoff	return htonl(a << 24 | b << 16 | c << 8 | d);
11583b3a8eb9SGleb Smirnoff}
11593b3a8eb9SGleb Smirnoff
11603b3a8eb9SGleb Smirnoffvoid
11613b3a8eb9SGleb Smirnoffprint_address(u_int32_t a)
11623b3a8eb9SGleb Smirnoff{
11633b3a8eb9SGleb Smirnoff	a = ntohl(a);
11643b3a8eb9SGleb Smirnoff	printf("%d.%d.%d.%d", a >> 24 & 255, a >> 16 & 255,
11653b3a8eb9SGleb Smirnoff	    a >> 8 & 255, a & 255);
11663b3a8eb9SGleb Smirnoff}
11673b3a8eb9SGleb Smirnoff
11683b3a8eb9SGleb Smirnoffint
11693b3a8eb9SGleb Smirnoffmain(int argc, char *argv[])
11703b3a8eb9SGleb Smirnoff{
11713b3a8eb9SGleb Smirnoff	struct pfioc_natlook nl;
11723b3a8eb9SGleb Smirnoff	int dev;
11733b3a8eb9SGleb Smirnoff
11743b3a8eb9SGleb Smirnoff	if (argc != 5) {
11753b3a8eb9SGleb Smirnoff		printf("%s <gwy addr> <gwy port> <ext addr> <ext port>\\n",
11763b3a8eb9SGleb Smirnoff		    argv[0]);
11773b3a8eb9SGleb Smirnoff		return 1;
11783b3a8eb9SGleb Smirnoff	}
11793b3a8eb9SGleb Smirnoff
11803b3a8eb9SGleb Smirnoff	dev = open("/dev/pf", O_RDWR);
11813b3a8eb9SGleb Smirnoff	if (dev == -1)
11823b3a8eb9SGleb Smirnoff		err(1, "open(\\"/dev/pf\\") failed");
11833b3a8eb9SGleb Smirnoff
11843b3a8eb9SGleb Smirnoff	memset(&nl, 0, sizeof(struct pfioc_natlook));
11853b3a8eb9SGleb Smirnoff	nl.saddr.v4.s_addr	= read_address(argv[1]);
11863b3a8eb9SGleb Smirnoff	nl.sport		= htons(atoi(argv[2]));
11873b3a8eb9SGleb Smirnoff	nl.daddr.v4.s_addr	= read_address(argv[3]);
11883b3a8eb9SGleb Smirnoff	nl.dport		= htons(atoi(argv[4]));
11893b3a8eb9SGleb Smirnoff	nl.af			= AF_INET;
11903b3a8eb9SGleb Smirnoff	nl.proto		= IPPROTO_TCP;
11913b3a8eb9SGleb Smirnoff	nl.direction		= PF_IN;
11923b3a8eb9SGleb Smirnoff
11933b3a8eb9SGleb Smirnoff	if (ioctl(dev, DIOCNATLOOK, &nl))
11943b3a8eb9SGleb Smirnoff		err(1, "DIOCNATLOOK");
11953b3a8eb9SGleb Smirnoff
11963b3a8eb9SGleb Smirnoff	printf("internal host ");
11973b3a8eb9SGleb Smirnoff	print_address(nl.rsaddr.v4.s_addr);
11983b3a8eb9SGleb Smirnoff	printf(":%u\\n", ntohs(nl.rsport));
11993b3a8eb9SGleb Smirnoff	return 0;
12003b3a8eb9SGleb Smirnoff}
12013b3a8eb9SGleb Smirnoff.Ed
12023b3a8eb9SGleb Smirnoff.Sh SEE ALSO
12033b3a8eb9SGleb Smirnoff.Xr ioctl 2 ,
12043b3a8eb9SGleb Smirnoff.Xr altq 4 ,
12053b3a8eb9SGleb Smirnoff.Xr if_bridge 4 ,
12063b3a8eb9SGleb Smirnoff.Xr pflog 4 ,
12073b3a8eb9SGleb Smirnoff.Xr pfsync 4 ,
12083b3a8eb9SGleb Smirnoff.Xr pfctl 8 ,
12093b3a8eb9SGleb Smirnoff.Xr altq 9
12103b3a8eb9SGleb Smirnoff.Sh HISTORY
12113b3a8eb9SGleb SmirnoffThe
12123b3a8eb9SGleb Smirnoff.Nm
12133b3a8eb9SGleb Smirnoffpacket filtering mechanism first appeared in
12143b3a8eb9SGleb Smirnoff.Ox 3.0
12153b3a8eb9SGleb Smirnoffand then
12163b3a8eb9SGleb Smirnoff.Fx 5.2 .
12173b3a8eb9SGleb Smirnoff.Pp
1218be51503dSGleb SmirnoffThis implementation is derived from
12193b3a8eb9SGleb Smirnoff.Ox 4.5 .
1220be51503dSGleb SmirnoffIt has been heavily modified to be capable of running in multithreaded
1221be51503dSGleb Smirnoff.Fx
1222be51503dSGleb Smirnoffkernel and scale its performance on multiple CPUs.
1223