1*3b3a8eb9SGleb Smirnoff.\" $OpenBSD: pf.4,v 1.62 2008/09/10 14:57:37 jmc Exp $ 2*3b3a8eb9SGleb Smirnoff.\" 3*3b3a8eb9SGleb Smirnoff.\" Copyright (C) 2001, Kjell Wooding. All rights reserved. 4*3b3a8eb9SGleb Smirnoff.\" 5*3b3a8eb9SGleb Smirnoff.\" Redistribution and use in source and binary forms, with or without 6*3b3a8eb9SGleb Smirnoff.\" modification, are permitted provided that the following conditions 7*3b3a8eb9SGleb Smirnoff.\" are met: 8*3b3a8eb9SGleb Smirnoff.\" 1. Redistributions of source code must retain the above copyright 9*3b3a8eb9SGleb Smirnoff.\" notice, this list of conditions and the following disclaimer. 10*3b3a8eb9SGleb Smirnoff.\" 2. Redistributions in binary form must reproduce the above copyright 11*3b3a8eb9SGleb Smirnoff.\" notice, this list of conditions and the following disclaimer in the 12*3b3a8eb9SGleb Smirnoff.\" documentation and/or other materials provided with the distribution. 13*3b3a8eb9SGleb Smirnoff.\" 3. Neither the name of the project nor the names of its contributors 14*3b3a8eb9SGleb Smirnoff.\" may be used to endorse or promote products derived from this software 15*3b3a8eb9SGleb Smirnoff.\" without specific prior written permission. 16*3b3a8eb9SGleb Smirnoff.\" 17*3b3a8eb9SGleb Smirnoff.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18*3b3a8eb9SGleb Smirnoff.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*3b3a8eb9SGleb Smirnoff.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*3b3a8eb9SGleb Smirnoff.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21*3b3a8eb9SGleb Smirnoff.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22*3b3a8eb9SGleb Smirnoff.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23*3b3a8eb9SGleb Smirnoff.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24*3b3a8eb9SGleb Smirnoff.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25*3b3a8eb9SGleb Smirnoff.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26*3b3a8eb9SGleb Smirnoff.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27*3b3a8eb9SGleb Smirnoff.\" SUCH DAMAGE. 28*3b3a8eb9SGleb Smirnoff.\" 29*3b3a8eb9SGleb Smirnoff.\" $FreeBSD$ 30*3b3a8eb9SGleb Smirnoff.\" 31*3b3a8eb9SGleb Smirnoff.Dd June 29 2012 32*3b3a8eb9SGleb Smirnoff.Dt PF 4 33*3b3a8eb9SGleb Smirnoff.Os 34*3b3a8eb9SGleb Smirnoff.Sh NAME 35*3b3a8eb9SGleb Smirnoff.Nm pf 36*3b3a8eb9SGleb Smirnoff.Nd packet filter 37*3b3a8eb9SGleb Smirnoff.Sh SYNOPSIS 38*3b3a8eb9SGleb Smirnoff.Cd "device pf" 39*3b3a8eb9SGleb Smirnoff.Sh DESCRIPTION 40*3b3a8eb9SGleb SmirnoffPacket filtering takes place in the kernel. 41*3b3a8eb9SGleb SmirnoffA pseudo-device, 42*3b3a8eb9SGleb Smirnoff.Pa /dev/pf , 43*3b3a8eb9SGleb Smirnoffallows userland processes to control the 44*3b3a8eb9SGleb Smirnoffbehavior of the packet filter through an 45*3b3a8eb9SGleb Smirnoff.Xr ioctl 2 46*3b3a8eb9SGleb Smirnoffinterface. 47*3b3a8eb9SGleb SmirnoffThere are commands to enable and disable the filter, load rulesets, 48*3b3a8eb9SGleb Smirnoffadd and remove individual rules or state table entries, 49*3b3a8eb9SGleb Smirnoffand retrieve statistics. 50*3b3a8eb9SGleb SmirnoffThe most commonly used functions are covered by 51*3b3a8eb9SGleb Smirnoff.Xr pfctl 8 . 52*3b3a8eb9SGleb Smirnoff.Pp 53*3b3a8eb9SGleb SmirnoffManipulations like loading a ruleset that involve more than a single 54*3b3a8eb9SGleb Smirnoff.Xr ioctl 2 55*3b3a8eb9SGleb Smirnoffcall require a so-called 56*3b3a8eb9SGleb Smirnoff.Em ticket , 57*3b3a8eb9SGleb Smirnoffwhich prevents the occurrence of 58*3b3a8eb9SGleb Smirnoffmultiple concurrent manipulations. 59*3b3a8eb9SGleb Smirnoff.Pp 60*3b3a8eb9SGleb SmirnoffFields of 61*3b3a8eb9SGleb Smirnoff.Xr ioctl 2 62*3b3a8eb9SGleb Smirnoffparameter structures that refer to packet data (like 63*3b3a8eb9SGleb Smirnoffaddresses and ports) are generally expected in network byte-order. 64*3b3a8eb9SGleb Smirnoff.Pp 65*3b3a8eb9SGleb SmirnoffRules and address tables are contained in so-called 66*3b3a8eb9SGleb Smirnoff.Em anchors . 67*3b3a8eb9SGleb SmirnoffWhen servicing an 68*3b3a8eb9SGleb Smirnoff.Xr ioctl 2 69*3b3a8eb9SGleb Smirnoffrequest, if the anchor field of the argument structure is empty, 70*3b3a8eb9SGleb Smirnoffthe kernel will use the default anchor (i.e., the main ruleset) 71*3b3a8eb9SGleb Smirnoffin operations. 72*3b3a8eb9SGleb SmirnoffAnchors are specified by name and may be nested, with components 73*3b3a8eb9SGleb Smirnoffseparated by 74*3b3a8eb9SGleb Smirnoff.Sq / 75*3b3a8eb9SGleb Smirnoffcharacters, similar to how file system hierarchies are laid out. 76*3b3a8eb9SGleb SmirnoffThe final component of the anchor path is the anchor under which 77*3b3a8eb9SGleb Smirnoffoperations will be performed. 78*3b3a8eb9SGleb Smirnoff.Sh SYSCTL VARIABLES AND LOADER TUNABLES 79*3b3a8eb9SGleb SmirnoffThe following 80*3b3a8eb9SGleb Smirnoff.Xr loader 8 81*3b3a8eb9SGleb Smirnofftunables are available. 82*3b3a8eb9SGleb Smirnoff.Bl -tag -width indent 83*3b3a8eb9SGleb Smirnoff.It Va net.pf.states_hashsize 84*3b3a8eb9SGleb SmirnoffSize of hash tables that store states. 85*3b3a8eb9SGleb SmirnoffShould be power of 2. 86*3b3a8eb9SGleb SmirnoffDefault value is 32768. 87*3b3a8eb9SGleb Smirnoff.It Va net.pf.source_nodes_hashsize 88*3b3a8eb9SGleb SmirnoffSize of hash table that store source nodes. 89*3b3a8eb9SGleb SmirnoffShould be power of 2. 90*3b3a8eb9SGleb SmirnoffDefault value is 8192. 91*3b3a8eb9SGleb Smirnoff.El 92*3b3a8eb9SGleb Smirnoff.Pp 93*3b3a8eb9SGleb SmirnoffRead only 94*3b3a8eb9SGleb Smirnoff.Xr sysctl 8 95*3b3a8eb9SGleb Smirnoffvariables with matching names are provided to obtain current values 96*3b3a8eb9SGleb Smirnoffat runtime. 97*3b3a8eb9SGleb Smirnoff.Sh IOCTL INTERFACE 98*3b3a8eb9SGleb Smirnoff.Nm 99*3b3a8eb9SGleb Smirnoffsupports the following 100*3b3a8eb9SGleb Smirnoff.Xr ioctl 2 101*3b3a8eb9SGleb Smirnoffcommands, available through 102*3b3a8eb9SGleb Smirnoff.Aq Pa net/pfvar.h : 103*3b3a8eb9SGleb Smirnoff.Bl -tag -width xxxxxx 104*3b3a8eb9SGleb Smirnoff.It Dv DIOCSTART 105*3b3a8eb9SGleb SmirnoffStart the packet filter. 106*3b3a8eb9SGleb Smirnoff.It Dv DIOCSTOP 107*3b3a8eb9SGleb SmirnoffStop the packet filter. 108*3b3a8eb9SGleb Smirnoff.It Dv DIOCSTARTALTQ 109*3b3a8eb9SGleb SmirnoffStart the ALTQ bandwidth control system (see 110*3b3a8eb9SGleb Smirnoff.Xr altq 9 ) . 111*3b3a8eb9SGleb Smirnoff.It Dv DIOCSTOPALTQ 112*3b3a8eb9SGleb SmirnoffStop the ALTQ bandwidth control system. 113*3b3a8eb9SGleb Smirnoff.It Dv DIOCBEGINADDRS Fa "struct pfioc_pooladdr *pp" 114*3b3a8eb9SGleb Smirnoff.Bd -literal 115*3b3a8eb9SGleb Smirnoffstruct pfioc_pooladdr { 116*3b3a8eb9SGleb Smirnoff u_int32_t action; 117*3b3a8eb9SGleb Smirnoff u_int32_t ticket; 118*3b3a8eb9SGleb Smirnoff u_int32_t nr; 119*3b3a8eb9SGleb Smirnoff u_int32_t r_num; 120*3b3a8eb9SGleb Smirnoff u_int8_t r_action; 121*3b3a8eb9SGleb Smirnoff u_int8_t r_last; 122*3b3a8eb9SGleb Smirnoff u_int8_t af; 123*3b3a8eb9SGleb Smirnoff char anchor[MAXPATHLEN]; 124*3b3a8eb9SGleb Smirnoff struct pf_pooladdr addr; 125*3b3a8eb9SGleb Smirnoff}; 126*3b3a8eb9SGleb Smirnoff.Ed 127*3b3a8eb9SGleb Smirnoff.Pp 128*3b3a8eb9SGleb SmirnoffClear the buffer address pool and get a 129*3b3a8eb9SGleb Smirnoff.Va ticket 130*3b3a8eb9SGleb Smirnofffor subsequent 131*3b3a8eb9SGleb Smirnoff.Dv DIOCADDADDR , 132*3b3a8eb9SGleb Smirnoff.Dv DIOCADDRULE , 133*3b3a8eb9SGleb Smirnoffand 134*3b3a8eb9SGleb Smirnoff.Dv DIOCCHANGERULE 135*3b3a8eb9SGleb Smirnoffcalls. 136*3b3a8eb9SGleb Smirnoff.It Dv DIOCADDADDR Fa "struct pfioc_pooladdr *pp" 137*3b3a8eb9SGleb Smirnoff.Pp 138*3b3a8eb9SGleb SmirnoffAdd the pool address 139*3b3a8eb9SGleb Smirnoff.Va addr 140*3b3a8eb9SGleb Smirnoffto the buffer address pool to be used in the following 141*3b3a8eb9SGleb Smirnoff.Dv DIOCADDRULE 142*3b3a8eb9SGleb Smirnoffor 143*3b3a8eb9SGleb Smirnoff.Dv DIOCCHANGERULE 144*3b3a8eb9SGleb Smirnoffcall. 145*3b3a8eb9SGleb SmirnoffAll other members of the structure are ignored. 146*3b3a8eb9SGleb Smirnoff.It Dv DIOCADDRULE Fa "struct pfioc_rule *pr" 147*3b3a8eb9SGleb Smirnoff.Bd -literal 148*3b3a8eb9SGleb Smirnoffstruct pfioc_rule { 149*3b3a8eb9SGleb Smirnoff u_int32_t action; 150*3b3a8eb9SGleb Smirnoff u_int32_t ticket; 151*3b3a8eb9SGleb Smirnoff u_int32_t pool_ticket; 152*3b3a8eb9SGleb Smirnoff u_int32_t nr; 153*3b3a8eb9SGleb Smirnoff char anchor[MAXPATHLEN]; 154*3b3a8eb9SGleb Smirnoff char anchor_call[MAXPATHLEN]; 155*3b3a8eb9SGleb Smirnoff struct pf_rule rule; 156*3b3a8eb9SGleb Smirnoff}; 157*3b3a8eb9SGleb Smirnoff.Ed 158*3b3a8eb9SGleb Smirnoff.Pp 159*3b3a8eb9SGleb SmirnoffAdd 160*3b3a8eb9SGleb Smirnoff.Va rule 161*3b3a8eb9SGleb Smirnoffat the end of the inactive ruleset. 162*3b3a8eb9SGleb SmirnoffThis call requires a 163*3b3a8eb9SGleb Smirnoff.Va ticket 164*3b3a8eb9SGleb Smirnoffobtained through a preceding 165*3b3a8eb9SGleb Smirnoff.Dv DIOCXBEGIN 166*3b3a8eb9SGleb Smirnoffcall and a 167*3b3a8eb9SGleb Smirnoff.Va pool_ticket 168*3b3a8eb9SGleb Smirnoffobtained through a 169*3b3a8eb9SGleb Smirnoff.Dv DIOCBEGINADDRS 170*3b3a8eb9SGleb Smirnoffcall. 171*3b3a8eb9SGleb Smirnoff.Dv DIOCADDADDR 172*3b3a8eb9SGleb Smirnoffmust also be called if any pool addresses are required. 173*3b3a8eb9SGleb SmirnoffThe optional 174*3b3a8eb9SGleb Smirnoff.Va anchor 175*3b3a8eb9SGleb Smirnoffname indicates the anchor in which to append the rule. 176*3b3a8eb9SGleb Smirnoff.Va nr 177*3b3a8eb9SGleb Smirnoffand 178*3b3a8eb9SGleb Smirnoff.Va action 179*3b3a8eb9SGleb Smirnoffare ignored. 180*3b3a8eb9SGleb Smirnoff.It Dv DIOCADDALTQ Fa "struct pfioc_altq *pa" 181*3b3a8eb9SGleb SmirnoffAdd an ALTQ discipline or queue. 182*3b3a8eb9SGleb Smirnoff.Bd -literal 183*3b3a8eb9SGleb Smirnoffstruct pfioc_altq { 184*3b3a8eb9SGleb Smirnoff u_int32_t action; 185*3b3a8eb9SGleb Smirnoff u_int32_t ticket; 186*3b3a8eb9SGleb Smirnoff u_int32_t nr; 187*3b3a8eb9SGleb Smirnoff struct pf_altq altq; 188*3b3a8eb9SGleb Smirnoff}; 189*3b3a8eb9SGleb Smirnoff.Ed 190*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULES Fa "struct pfioc_rule *pr" 191*3b3a8eb9SGleb SmirnoffGet a 192*3b3a8eb9SGleb Smirnoff.Va ticket 193*3b3a8eb9SGleb Smirnofffor subsequent 194*3b3a8eb9SGleb Smirnoff.Dv DIOCGETRULE 195*3b3a8eb9SGleb Smirnoffcalls and the number 196*3b3a8eb9SGleb Smirnoff.Va nr 197*3b3a8eb9SGleb Smirnoffof rules in the active ruleset. 198*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULE Fa "struct pfioc_rule *pr" 199*3b3a8eb9SGleb SmirnoffGet a 200*3b3a8eb9SGleb Smirnoff.Va rule 201*3b3a8eb9SGleb Smirnoffby its number 202*3b3a8eb9SGleb Smirnoff.Va nr 203*3b3a8eb9SGleb Smirnoffusing the 204*3b3a8eb9SGleb Smirnoff.Va ticket 205*3b3a8eb9SGleb Smirnoffobtained through a preceding 206*3b3a8eb9SGleb Smirnoff.Dv DIOCGETRULES 207*3b3a8eb9SGleb Smirnoffcall. 208*3b3a8eb9SGleb SmirnoffIf 209*3b3a8eb9SGleb Smirnoff.Va action 210*3b3a8eb9SGleb Smirnoffis set to 211*3b3a8eb9SGleb Smirnoff.Dv PF_GET_CLR_CNTR , 212*3b3a8eb9SGleb Smirnoffthe per-rule statistics on the requested rule are cleared. 213*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETADDRS Fa "struct pfioc_pooladdr *pp" 214*3b3a8eb9SGleb SmirnoffGet a 215*3b3a8eb9SGleb Smirnoff.Va ticket 216*3b3a8eb9SGleb Smirnofffor subsequent 217*3b3a8eb9SGleb Smirnoff.Dv DIOCGETADDR 218*3b3a8eb9SGleb Smirnoffcalls and the number 219*3b3a8eb9SGleb Smirnoff.Va nr 220*3b3a8eb9SGleb Smirnoffof pool addresses in the rule specified with 221*3b3a8eb9SGleb Smirnoff.Va r_action , 222*3b3a8eb9SGleb Smirnoff.Va r_num , 223*3b3a8eb9SGleb Smirnoffand 224*3b3a8eb9SGleb Smirnoff.Va anchor . 225*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETADDR Fa "struct pfioc_pooladdr *pp" 226*3b3a8eb9SGleb SmirnoffGet the pool address 227*3b3a8eb9SGleb Smirnoff.Va addr 228*3b3a8eb9SGleb Smirnoffby its number 229*3b3a8eb9SGleb Smirnoff.Va nr 230*3b3a8eb9SGleb Smirnofffrom the rule specified with 231*3b3a8eb9SGleb Smirnoff.Va r_action , 232*3b3a8eb9SGleb Smirnoff.Va r_num , 233*3b3a8eb9SGleb Smirnoffand 234*3b3a8eb9SGleb Smirnoff.Va anchor 235*3b3a8eb9SGleb Smirnoffusing the 236*3b3a8eb9SGleb Smirnoff.Va ticket 237*3b3a8eb9SGleb Smirnoffobtained through a preceding 238*3b3a8eb9SGleb Smirnoff.Dv DIOCGETADDRS 239*3b3a8eb9SGleb Smirnoffcall. 240*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETALTQS Fa "struct pfioc_altq *pa" 241*3b3a8eb9SGleb SmirnoffGet a 242*3b3a8eb9SGleb Smirnoff.Va ticket 243*3b3a8eb9SGleb Smirnofffor subsequent 244*3b3a8eb9SGleb Smirnoff.Dv DIOCGETALTQ 245*3b3a8eb9SGleb Smirnoffcalls and the number 246*3b3a8eb9SGleb Smirnoff.Va nr 247*3b3a8eb9SGleb Smirnoffof queues in the active list. 248*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETALTQ Fa "struct pfioc_altq *pa" 249*3b3a8eb9SGleb SmirnoffGet the queueing discipline 250*3b3a8eb9SGleb Smirnoff.Va altq 251*3b3a8eb9SGleb Smirnoffby its number 252*3b3a8eb9SGleb Smirnoff.Va nr 253*3b3a8eb9SGleb Smirnoffusing the 254*3b3a8eb9SGleb Smirnoff.Va ticket 255*3b3a8eb9SGleb Smirnoffobtained through a preceding 256*3b3a8eb9SGleb Smirnoff.Dv DIOCGETALTQS 257*3b3a8eb9SGleb Smirnoffcall. 258*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETQSTATS Fa "struct pfioc_qstats *pq" 259*3b3a8eb9SGleb SmirnoffGet the statistics on a queue. 260*3b3a8eb9SGleb Smirnoff.Bd -literal 261*3b3a8eb9SGleb Smirnoffstruct pfioc_qstats { 262*3b3a8eb9SGleb Smirnoff u_int32_t ticket; 263*3b3a8eb9SGleb Smirnoff u_int32_t nr; 264*3b3a8eb9SGleb Smirnoff void *buf; 265*3b3a8eb9SGleb Smirnoff int nbytes; 266*3b3a8eb9SGleb Smirnoff u_int8_t scheduler; 267*3b3a8eb9SGleb Smirnoff}; 268*3b3a8eb9SGleb Smirnoff.Ed 269*3b3a8eb9SGleb Smirnoff.Pp 270*3b3a8eb9SGleb SmirnoffThis call fills in a pointer to the buffer of statistics 271*3b3a8eb9SGleb Smirnoff.Va buf , 272*3b3a8eb9SGleb Smirnoffof length 273*3b3a8eb9SGleb Smirnoff.Va nbytes , 274*3b3a8eb9SGleb Smirnofffor the queue specified by 275*3b3a8eb9SGleb Smirnoff.Va nr . 276*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULESETS Fa "struct pfioc_ruleset *pr" 277*3b3a8eb9SGleb Smirnoff.Bd -literal 278*3b3a8eb9SGleb Smirnoffstruct pfioc_ruleset { 279*3b3a8eb9SGleb Smirnoff u_int32_t nr; 280*3b3a8eb9SGleb Smirnoff char path[MAXPATHLEN]; 281*3b3a8eb9SGleb Smirnoff char name[PF_ANCHOR_NAME_SIZE]; 282*3b3a8eb9SGleb Smirnoff}; 283*3b3a8eb9SGleb Smirnoff.Ed 284*3b3a8eb9SGleb Smirnoff.Pp 285*3b3a8eb9SGleb SmirnoffGet the number 286*3b3a8eb9SGleb Smirnoff.Va nr 287*3b3a8eb9SGleb Smirnoffof rulesets (i.e., anchors) directly attached to the anchor named by 288*3b3a8eb9SGleb Smirnoff.Va path 289*3b3a8eb9SGleb Smirnofffor use in subsequent 290*3b3a8eb9SGleb Smirnoff.Dv DIOCGETRULESET 291*3b3a8eb9SGleb Smirnoffcalls. 292*3b3a8eb9SGleb SmirnoffNested anchors, since they are not directly attached to the given 293*3b3a8eb9SGleb Smirnoffanchor, will not be included. 294*3b3a8eb9SGleb SmirnoffThis ioctl returns 295*3b3a8eb9SGleb Smirnoff.Er EINVAL 296*3b3a8eb9SGleb Smirnoffif the given anchor does not exist. 297*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETRULESET Fa "struct pfioc_ruleset *pr" 298*3b3a8eb9SGleb SmirnoffGet a ruleset (i.e., an anchor) 299*3b3a8eb9SGleb Smirnoff.Va name 300*3b3a8eb9SGleb Smirnoffby its number 301*3b3a8eb9SGleb Smirnoff.Va nr 302*3b3a8eb9SGleb Smirnofffrom the given anchor 303*3b3a8eb9SGleb Smirnoff.Va path , 304*3b3a8eb9SGleb Smirnoffthe maximum number of which can be obtained from a preceding 305*3b3a8eb9SGleb Smirnoff.Dv DIOCGETRULESETS 306*3b3a8eb9SGleb Smirnoffcall. 307*3b3a8eb9SGleb SmirnoffThis ioctl returns 308*3b3a8eb9SGleb Smirnoff.Er EINVAL 309*3b3a8eb9SGleb Smirnoffif the given anchor does not exist or 310*3b3a8eb9SGleb Smirnoff.Er EBUSY 311*3b3a8eb9SGleb Smirnoffif another process is concurrently updating a ruleset. 312*3b3a8eb9SGleb Smirnoff.It Dv DIOCADDSTATE Fa "struct pfioc_state *ps" 313*3b3a8eb9SGleb SmirnoffAdd a state entry. 314*3b3a8eb9SGleb Smirnoff.Bd -literal 315*3b3a8eb9SGleb Smirnoffstruct pfioc_state { 316*3b3a8eb9SGleb Smirnoff struct pfsync_state state; 317*3b3a8eb9SGleb Smirnoff}; 318*3b3a8eb9SGleb Smirnoff.Ed 319*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETSTATE Fa "struct pfioc_state *ps" 320*3b3a8eb9SGleb SmirnoffExtract the entry identified by the 321*3b3a8eb9SGleb Smirnoff.Va id 322*3b3a8eb9SGleb Smirnoffand 323*3b3a8eb9SGleb Smirnoff.Va creatorid 324*3b3a8eb9SGleb Smirnofffields of the 325*3b3a8eb9SGleb Smirnoff.Va state 326*3b3a8eb9SGleb Smirnoffstructure from the state table. 327*3b3a8eb9SGleb Smirnoff.It Dv DIOCKILLSTATES Fa "struct pfioc_state_kill *psk" 328*3b3a8eb9SGleb SmirnoffRemove matching entries from the state table. 329*3b3a8eb9SGleb SmirnoffThis ioctl returns the number of killed states in 330*3b3a8eb9SGleb Smirnoff.Va psk_killed . 331*3b3a8eb9SGleb Smirnoff.Bd -literal 332*3b3a8eb9SGleb Smirnoffstruct pfioc_state_kill { 333*3b3a8eb9SGleb Smirnoff struct pf_state_cmp psk_pfcmp; 334*3b3a8eb9SGleb Smirnoff sa_family_t psk_af; 335*3b3a8eb9SGleb Smirnoff int psk_proto; 336*3b3a8eb9SGleb Smirnoff struct pf_rule_addr psk_src; 337*3b3a8eb9SGleb Smirnoff struct pf_rule_addr psk_dst; 338*3b3a8eb9SGleb Smirnoff char psk_ifname[IFNAMSIZ]; 339*3b3a8eb9SGleb Smirnoff char psk_label[PF_RULE_LABEL_SIZE]; 340*3b3a8eb9SGleb Smirnoff u_int psk_killed; 341*3b3a8eb9SGleb Smirnoff}; 342*3b3a8eb9SGleb Smirnoff.Ed 343*3b3a8eb9SGleb Smirnoff.It Dv DIOCCLRSTATES Fa "struct pfioc_state_kill *psk" 344*3b3a8eb9SGleb SmirnoffClear all states. 345*3b3a8eb9SGleb SmirnoffIt works like 346*3b3a8eb9SGleb Smirnoff.Dv DIOCKILLSTATES , 347*3b3a8eb9SGleb Smirnoffbut ignores the 348*3b3a8eb9SGleb Smirnoff.Va psk_af , 349*3b3a8eb9SGleb Smirnoff.Va psk_proto , 350*3b3a8eb9SGleb Smirnoff.Va psk_src , 351*3b3a8eb9SGleb Smirnoffand 352*3b3a8eb9SGleb Smirnoff.Va psk_dst 353*3b3a8eb9SGleb Smirnofffields of the 354*3b3a8eb9SGleb Smirnoff.Vt pfioc_state_kill 355*3b3a8eb9SGleb Smirnoffstructure. 356*3b3a8eb9SGleb Smirnoff.It Dv DIOCSETSTATUSIF Fa "struct pfioc_if *pi" 357*3b3a8eb9SGleb SmirnoffSpecify the interface for which statistics are accumulated. 358*3b3a8eb9SGleb Smirnoff.Bd -literal 359*3b3a8eb9SGleb Smirnoffstruct pfioc_if { 360*3b3a8eb9SGleb Smirnoff char ifname[IFNAMSIZ]; 361*3b3a8eb9SGleb Smirnoff}; 362*3b3a8eb9SGleb Smirnoff.Ed 363*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETSTATUS Fa "struct pf_status *s" 364*3b3a8eb9SGleb SmirnoffGet the internal packet filter statistics. 365*3b3a8eb9SGleb Smirnoff.Bd -literal 366*3b3a8eb9SGleb Smirnoffstruct pf_status { 367*3b3a8eb9SGleb Smirnoff u_int64_t counters[PFRES_MAX]; 368*3b3a8eb9SGleb Smirnoff u_int64_t lcounters[LCNT_MAX]; 369*3b3a8eb9SGleb Smirnoff u_int64_t fcounters[FCNT_MAX]; 370*3b3a8eb9SGleb Smirnoff u_int64_t scounters[SCNT_MAX]; 371*3b3a8eb9SGleb Smirnoff u_int64_t pcounters[2][2][3]; 372*3b3a8eb9SGleb Smirnoff u_int64_t bcounters[2][2]; 373*3b3a8eb9SGleb Smirnoff u_int32_t running; 374*3b3a8eb9SGleb Smirnoff u_int32_t states; 375*3b3a8eb9SGleb Smirnoff u_int32_t src_nodes; 376*3b3a8eb9SGleb Smirnoff u_int32_t since; 377*3b3a8eb9SGleb Smirnoff u_int32_t debug; 378*3b3a8eb9SGleb Smirnoff u_int32_t hostid; 379*3b3a8eb9SGleb Smirnoff char ifname[IFNAMSIZ]; 380*3b3a8eb9SGleb Smirnoff u_int8_t pf_chksum[MD5_DIGEST_LENGTH]; 381*3b3a8eb9SGleb Smirnoff}; 382*3b3a8eb9SGleb Smirnoff.Ed 383*3b3a8eb9SGleb Smirnoff.It Dv DIOCCLRSTATUS 384*3b3a8eb9SGleb SmirnoffClear the internal packet filter statistics. 385*3b3a8eb9SGleb Smirnoff.It Dv DIOCNATLOOK Fa "struct pfioc_natlook *pnl" 386*3b3a8eb9SGleb SmirnoffLook up a state table entry by source and destination addresses and ports. 387*3b3a8eb9SGleb Smirnoff.Bd -literal 388*3b3a8eb9SGleb Smirnoffstruct pfioc_natlook { 389*3b3a8eb9SGleb Smirnoff struct pf_addr saddr; 390*3b3a8eb9SGleb Smirnoff struct pf_addr daddr; 391*3b3a8eb9SGleb Smirnoff struct pf_addr rsaddr; 392*3b3a8eb9SGleb Smirnoff struct pf_addr rdaddr; 393*3b3a8eb9SGleb Smirnoff u_int16_t sport; 394*3b3a8eb9SGleb Smirnoff u_int16_t dport; 395*3b3a8eb9SGleb Smirnoff u_int16_t rsport; 396*3b3a8eb9SGleb Smirnoff u_int16_t rdport; 397*3b3a8eb9SGleb Smirnoff sa_family_t af; 398*3b3a8eb9SGleb Smirnoff u_int8_t proto; 399*3b3a8eb9SGleb Smirnoff u_int8_t direction; 400*3b3a8eb9SGleb Smirnoff}; 401*3b3a8eb9SGleb Smirnoff.Ed 402*3b3a8eb9SGleb Smirnoff.It Dv DIOCSETDEBUG Fa "u_int32_t *level" 403*3b3a8eb9SGleb SmirnoffSet the debug level. 404*3b3a8eb9SGleb Smirnoff.Bd -literal 405*3b3a8eb9SGleb Smirnoffenum { PF_DEBUG_NONE, PF_DEBUG_URGENT, PF_DEBUG_MISC, 406*3b3a8eb9SGleb Smirnoff PF_DEBUG_NOISY }; 407*3b3a8eb9SGleb Smirnoff.Ed 408*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETSTATES Fa "struct pfioc_states *ps" 409*3b3a8eb9SGleb SmirnoffGet state table entries. 410*3b3a8eb9SGleb Smirnoff.Bd -literal 411*3b3a8eb9SGleb Smirnoffstruct pfioc_states { 412*3b3a8eb9SGleb Smirnoff int ps_len; 413*3b3a8eb9SGleb Smirnoff union { 414*3b3a8eb9SGleb Smirnoff caddr_t psu_buf; 415*3b3a8eb9SGleb Smirnoff struct pf_state *psu_states; 416*3b3a8eb9SGleb Smirnoff } ps_u; 417*3b3a8eb9SGleb Smirnoff#define ps_buf ps_u.psu_buf 418*3b3a8eb9SGleb Smirnoff#define ps_states ps_u.psu_states 419*3b3a8eb9SGleb Smirnoff}; 420*3b3a8eb9SGleb Smirnoff.Ed 421*3b3a8eb9SGleb Smirnoff.Pp 422*3b3a8eb9SGleb SmirnoffIf 423*3b3a8eb9SGleb Smirnoff.Va ps_len 424*3b3a8eb9SGleb Smirnoffis non-zero on entry, as many states as possible that can fit into this 425*3b3a8eb9SGleb Smirnoffsize will be copied into the supplied buffer 426*3b3a8eb9SGleb Smirnoff.Va ps_states . 427*3b3a8eb9SGleb SmirnoffOn exit, 428*3b3a8eb9SGleb Smirnoff.Va ps_len 429*3b3a8eb9SGleb Smirnoffis always set to the total size required to hold all state table entries 430*3b3a8eb9SGleb Smirnoff(i.e., it is set to 431*3b3a8eb9SGleb Smirnoff.Li sizeof(struct pf_state) * nr ) . 432*3b3a8eb9SGleb Smirnoff.It Dv DIOCCHANGERULE Fa "struct pfioc_rule *pcr" 433*3b3a8eb9SGleb SmirnoffAdd or remove the 434*3b3a8eb9SGleb Smirnoff.Va rule 435*3b3a8eb9SGleb Smirnoffin the ruleset specified by 436*3b3a8eb9SGleb Smirnoff.Va rule.action . 437*3b3a8eb9SGleb Smirnoff.Pp 438*3b3a8eb9SGleb SmirnoffThe type of operation to be performed is indicated by 439*3b3a8eb9SGleb Smirnoff.Va action , 440*3b3a8eb9SGleb Smirnoffwhich can be any of the following: 441*3b3a8eb9SGleb Smirnoff.Bd -literal 442*3b3a8eb9SGleb Smirnoffenum { PF_CHANGE_NONE, PF_CHANGE_ADD_HEAD, PF_CHANGE_ADD_TAIL, 443*3b3a8eb9SGleb Smirnoff PF_CHANGE_ADD_BEFORE, PF_CHANGE_ADD_AFTER, 444*3b3a8eb9SGleb Smirnoff PF_CHANGE_REMOVE, PF_CHANGE_GET_TICKET }; 445*3b3a8eb9SGleb Smirnoff.Ed 446*3b3a8eb9SGleb Smirnoff.Pp 447*3b3a8eb9SGleb Smirnoff.Va ticket 448*3b3a8eb9SGleb Smirnoffmust be set to the value obtained with 449*3b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_GET_TICKET 450*3b3a8eb9SGleb Smirnofffor all actions except 451*3b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_GET_TICKET . 452*3b3a8eb9SGleb Smirnoff.Va pool_ticket 453*3b3a8eb9SGleb Smirnoffmust be set to the value obtained with the 454*3b3a8eb9SGleb Smirnoff.Dv DIOCBEGINADDRS 455*3b3a8eb9SGleb Smirnoffcall for all actions except 456*3b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_REMOVE 457*3b3a8eb9SGleb Smirnoffand 458*3b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_GET_TICKET . 459*3b3a8eb9SGleb Smirnoff.Va anchor 460*3b3a8eb9SGleb Smirnoffindicates to which anchor the operation applies. 461*3b3a8eb9SGleb Smirnoff.Va nr 462*3b3a8eb9SGleb Smirnoffindicates the rule number against which 463*3b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_ADD_BEFORE , 464*3b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_ADD_AFTER , 465*3b3a8eb9SGleb Smirnoffor 466*3b3a8eb9SGleb Smirnoff.Dv PF_CHANGE_REMOVE 467*3b3a8eb9SGleb Smirnoffactions are applied. 468*3b3a8eb9SGleb Smirnoff.\" It Dv DIOCCHANGEALTQ Fa "struct pfioc_altq *pcr" 469*3b3a8eb9SGleb Smirnoff.It Dv DIOCCHANGEADDR Fa "struct pfioc_pooladdr *pca" 470*3b3a8eb9SGleb SmirnoffAdd or remove the pool address 471*3b3a8eb9SGleb Smirnoff.Va addr 472*3b3a8eb9SGleb Smirnofffrom the rule specified by 473*3b3a8eb9SGleb Smirnoff.Va r_action , 474*3b3a8eb9SGleb Smirnoff.Va r_num , 475*3b3a8eb9SGleb Smirnoffand 476*3b3a8eb9SGleb Smirnoff.Va anchor . 477*3b3a8eb9SGleb Smirnoff.It Dv DIOCSETTIMEOUT Fa "struct pfioc_tm *pt" 478*3b3a8eb9SGleb Smirnoff.Bd -literal 479*3b3a8eb9SGleb Smirnoffstruct pfioc_tm { 480*3b3a8eb9SGleb Smirnoff int timeout; 481*3b3a8eb9SGleb Smirnoff int seconds; 482*3b3a8eb9SGleb Smirnoff}; 483*3b3a8eb9SGleb Smirnoff.Ed 484*3b3a8eb9SGleb Smirnoff.Pp 485*3b3a8eb9SGleb SmirnoffSet the state timeout of 486*3b3a8eb9SGleb Smirnoff.Va timeout 487*3b3a8eb9SGleb Smirnoffto 488*3b3a8eb9SGleb Smirnoff.Va seconds . 489*3b3a8eb9SGleb SmirnoffThe old value will be placed into 490*3b3a8eb9SGleb Smirnoff.Va seconds . 491*3b3a8eb9SGleb SmirnoffFor possible values of 492*3b3a8eb9SGleb Smirnoff.Va timeout , 493*3b3a8eb9SGleb Smirnoffconsult the 494*3b3a8eb9SGleb Smirnoff.Dv PFTM_* 495*3b3a8eb9SGleb Smirnoffvalues in 496*3b3a8eb9SGleb Smirnoff.Aq Pa net/pfvar.h . 497*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETTIMEOUT Fa "struct pfioc_tm *pt" 498*3b3a8eb9SGleb SmirnoffGet the state timeout of 499*3b3a8eb9SGleb Smirnoff.Va timeout . 500*3b3a8eb9SGleb SmirnoffThe value will be placed into the 501*3b3a8eb9SGleb Smirnoff.Va seconds 502*3b3a8eb9SGleb Smirnofffield. 503*3b3a8eb9SGleb Smirnoff.It Dv DIOCCLRRULECTRS 504*3b3a8eb9SGleb SmirnoffClear per-rule statistics. 505*3b3a8eb9SGleb Smirnoff.It Dv DIOCSETLIMIT Fa "struct pfioc_limit *pl" 506*3b3a8eb9SGleb SmirnoffSet the hard limits on the memory pools used by the packet filter. 507*3b3a8eb9SGleb Smirnoff.Bd -literal 508*3b3a8eb9SGleb Smirnoffstruct pfioc_limit { 509*3b3a8eb9SGleb Smirnoff int index; 510*3b3a8eb9SGleb Smirnoff unsigned limit; 511*3b3a8eb9SGleb Smirnoff}; 512*3b3a8eb9SGleb Smirnoff 513*3b3a8eb9SGleb Smirnoffenum { PF_LIMIT_STATES, PF_LIMIT_SRC_NODES, PF_LIMIT_FRAGS, 514*3b3a8eb9SGleb Smirnoff PF_LIMIT_TABLE_ENTRIES, PF_LIMIT_MAX }; 515*3b3a8eb9SGleb Smirnoff.Ed 516*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETLIMIT Fa "struct pfioc_limit *pl" 517*3b3a8eb9SGleb SmirnoffGet the hard 518*3b3a8eb9SGleb Smirnoff.Va limit 519*3b3a8eb9SGleb Smirnofffor the memory pool indicated by 520*3b3a8eb9SGleb Smirnoff.Va index . 521*3b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRTABLES Fa "struct pfioc_table *io" 522*3b3a8eb9SGleb SmirnoffClear all tables. 523*3b3a8eb9SGleb SmirnoffAll the ioctls that manipulate radix tables 524*3b3a8eb9SGleb Smirnoffuse the same structure described below. 525*3b3a8eb9SGleb SmirnoffFor 526*3b3a8eb9SGleb Smirnoff.Dv DIOCRCLRTABLES , 527*3b3a8eb9SGleb Smirnoff.Va pfrio_ndel 528*3b3a8eb9SGleb Smirnoffcontains on exit the number of tables deleted. 529*3b3a8eb9SGleb Smirnoff.Bd -literal 530*3b3a8eb9SGleb Smirnoffstruct pfioc_table { 531*3b3a8eb9SGleb Smirnoff struct pfr_table pfrio_table; 532*3b3a8eb9SGleb Smirnoff void *pfrio_buffer; 533*3b3a8eb9SGleb Smirnoff int pfrio_esize; 534*3b3a8eb9SGleb Smirnoff int pfrio_size; 535*3b3a8eb9SGleb Smirnoff int pfrio_size2; 536*3b3a8eb9SGleb Smirnoff int pfrio_nadd; 537*3b3a8eb9SGleb Smirnoff int pfrio_ndel; 538*3b3a8eb9SGleb Smirnoff int pfrio_nchange; 539*3b3a8eb9SGleb Smirnoff int pfrio_flags; 540*3b3a8eb9SGleb Smirnoff u_int32_t pfrio_ticket; 541*3b3a8eb9SGleb Smirnoff}; 542*3b3a8eb9SGleb Smirnoff#define pfrio_exists pfrio_nadd 543*3b3a8eb9SGleb Smirnoff#define pfrio_nzero pfrio_nadd 544*3b3a8eb9SGleb Smirnoff#define pfrio_nmatch pfrio_nadd 545*3b3a8eb9SGleb Smirnoff#define pfrio_naddr pfrio_size2 546*3b3a8eb9SGleb Smirnoff#define pfrio_setflag pfrio_size2 547*3b3a8eb9SGleb Smirnoff#define pfrio_clrflag pfrio_nadd 548*3b3a8eb9SGleb Smirnoff.Ed 549*3b3a8eb9SGleb Smirnoff.It Dv DIOCRADDTABLES Fa "struct pfioc_table *io" 550*3b3a8eb9SGleb SmirnoffCreate one or more tables. 551*3b3a8eb9SGleb SmirnoffOn entry, 552*3b3a8eb9SGleb Smirnoff.Va pfrio_buffer 553*3b3a8eb9SGleb Smirnoffmust point to an array of 554*3b3a8eb9SGleb Smirnoff.Vt struct pfr_table 555*3b3a8eb9SGleb Smirnoffcontaining at least 556*3b3a8eb9SGleb Smirnoff.Vt pfrio_size 557*3b3a8eb9SGleb Smirnoffelements. 558*3b3a8eb9SGleb Smirnoff.Vt pfrio_esize 559*3b3a8eb9SGleb Smirnoffmust be the size of 560*3b3a8eb9SGleb Smirnoff.Vt struct pfr_table . 561*3b3a8eb9SGleb SmirnoffOn exit, 562*3b3a8eb9SGleb Smirnoff.Va pfrio_nadd 563*3b3a8eb9SGleb Smirnoffcontains the number of tables effectively created. 564*3b3a8eb9SGleb Smirnoff.Bd -literal 565*3b3a8eb9SGleb Smirnoffstruct pfr_table { 566*3b3a8eb9SGleb Smirnoff char pfrt_anchor[MAXPATHLEN]; 567*3b3a8eb9SGleb Smirnoff char pfrt_name[PF_TABLE_NAME_SIZE]; 568*3b3a8eb9SGleb Smirnoff u_int32_t pfrt_flags; 569*3b3a8eb9SGleb Smirnoff u_int8_t pfrt_fback; 570*3b3a8eb9SGleb Smirnoff}; 571*3b3a8eb9SGleb Smirnoff.Ed 572*3b3a8eb9SGleb Smirnoff.It Dv DIOCRDELTABLES Fa "struct pfioc_table *io" 573*3b3a8eb9SGleb SmirnoffDelete one or more tables. 574*3b3a8eb9SGleb SmirnoffOn entry, 575*3b3a8eb9SGleb Smirnoff.Va pfrio_buffer 576*3b3a8eb9SGleb Smirnoffmust point to an array of 577*3b3a8eb9SGleb Smirnoff.Vt struct pfr_table 578*3b3a8eb9SGleb Smirnoffcontaining at least 579*3b3a8eb9SGleb Smirnoff.Vt pfrio_size 580*3b3a8eb9SGleb Smirnoffelements. 581*3b3a8eb9SGleb Smirnoff.Vt pfrio_esize 582*3b3a8eb9SGleb Smirnoffmust be the size of 583*3b3a8eb9SGleb Smirnoff.Vt struct pfr_table . 584*3b3a8eb9SGleb SmirnoffOn exit, 585*3b3a8eb9SGleb Smirnoff.Va pfrio_ndel 586*3b3a8eb9SGleb Smirnoffcontains the number of tables effectively deleted. 587*3b3a8eb9SGleb Smirnoff.It Dv DIOCRGETTABLES Fa "struct pfioc_table *io" 588*3b3a8eb9SGleb SmirnoffGet the list of all tables. 589*3b3a8eb9SGleb SmirnoffOn entry, 590*3b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size] 591*3b3a8eb9SGleb Smirnoffcontains a valid writeable buffer for 592*3b3a8eb9SGleb Smirnoff.Vt pfr_table 593*3b3a8eb9SGleb Smirnoffstructures. 594*3b3a8eb9SGleb SmirnoffOn exit, 595*3b3a8eb9SGleb Smirnoff.Va pfrio_size 596*3b3a8eb9SGleb Smirnoffcontains the number of tables written into the buffer. 597*3b3a8eb9SGleb SmirnoffIf the buffer is too small, the kernel does not store anything but just 598*3b3a8eb9SGleb Smirnoffreturns the required buffer size, without error. 599*3b3a8eb9SGleb Smirnoff.It Dv DIOCRGETTSTATS Fa "struct pfioc_table *io" 600*3b3a8eb9SGleb SmirnoffThis call is like 601*3b3a8eb9SGleb Smirnoff.Dv DIOCRGETTABLES 602*3b3a8eb9SGleb Smirnoffbut is used to get an array of 603*3b3a8eb9SGleb Smirnoff.Vt pfr_tstats 604*3b3a8eb9SGleb Smirnoffstructures. 605*3b3a8eb9SGleb Smirnoff.Bd -literal 606*3b3a8eb9SGleb Smirnoffstruct pfr_tstats { 607*3b3a8eb9SGleb Smirnoff struct pfr_table pfrts_t; 608*3b3a8eb9SGleb Smirnoff u_int64_t pfrts_packets 609*3b3a8eb9SGleb Smirnoff [PFR_DIR_MAX][PFR_OP_TABLE_MAX]; 610*3b3a8eb9SGleb Smirnoff u_int64_t pfrts_bytes 611*3b3a8eb9SGleb Smirnoff [PFR_DIR_MAX][PFR_OP_TABLE_MAX]; 612*3b3a8eb9SGleb Smirnoff u_int64_t pfrts_match; 613*3b3a8eb9SGleb Smirnoff u_int64_t pfrts_nomatch; 614*3b3a8eb9SGleb Smirnoff long pfrts_tzero; 615*3b3a8eb9SGleb Smirnoff int pfrts_cnt; 616*3b3a8eb9SGleb Smirnoff int pfrts_refcnt[PFR_REFCNT_MAX]; 617*3b3a8eb9SGleb Smirnoff}; 618*3b3a8eb9SGleb Smirnoff#define pfrts_name pfrts_t.pfrt_name 619*3b3a8eb9SGleb Smirnoff#define pfrts_flags pfrts_t.pfrt_flags 620*3b3a8eb9SGleb Smirnoff.Ed 621*3b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRTSTATS Fa "struct pfioc_table *io" 622*3b3a8eb9SGleb SmirnoffClear the statistics of one or more tables. 623*3b3a8eb9SGleb SmirnoffOn entry, 624*3b3a8eb9SGleb Smirnoff.Va pfrio_buffer 625*3b3a8eb9SGleb Smirnoffmust point to an array of 626*3b3a8eb9SGleb Smirnoff.Vt struct pfr_table 627*3b3a8eb9SGleb Smirnoffcontaining at least 628*3b3a8eb9SGleb Smirnoff.Vt pfrio_size 629*3b3a8eb9SGleb Smirnoffelements. 630*3b3a8eb9SGleb Smirnoff.Vt pfrio_esize 631*3b3a8eb9SGleb Smirnoffmust be the size of 632*3b3a8eb9SGleb Smirnoff.Vt struct pfr_table . 633*3b3a8eb9SGleb SmirnoffOn exit, 634*3b3a8eb9SGleb Smirnoff.Va pfrio_nzero 635*3b3a8eb9SGleb Smirnoffcontains the number of tables effectively cleared. 636*3b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRADDRS Fa "struct pfioc_table *io" 637*3b3a8eb9SGleb SmirnoffClear all addresses in a table. 638*3b3a8eb9SGleb SmirnoffOn entry, 639*3b3a8eb9SGleb Smirnoff.Va pfrio_table 640*3b3a8eb9SGleb Smirnoffcontains the table to clear. 641*3b3a8eb9SGleb SmirnoffOn exit, 642*3b3a8eb9SGleb Smirnoff.Va pfrio_ndel 643*3b3a8eb9SGleb Smirnoffcontains the number of addresses removed. 644*3b3a8eb9SGleb Smirnoff.It Dv DIOCRADDADDRS Fa "struct pfioc_table *io" 645*3b3a8eb9SGleb SmirnoffAdd one or more addresses to a table. 646*3b3a8eb9SGleb SmirnoffOn entry, 647*3b3a8eb9SGleb Smirnoff.Va pfrio_table 648*3b3a8eb9SGleb Smirnoffcontains the table ID and 649*3b3a8eb9SGleb Smirnoff.Va pfrio_buffer 650*3b3a8eb9SGleb Smirnoffmust point to an array of 651*3b3a8eb9SGleb Smirnoff.Vt struct pfr_addr 652*3b3a8eb9SGleb Smirnoffcontaining at least 653*3b3a8eb9SGleb Smirnoff.Vt pfrio_size 654*3b3a8eb9SGleb Smirnoffelements to add to the table. 655*3b3a8eb9SGleb Smirnoff.Vt pfrio_esize 656*3b3a8eb9SGleb Smirnoffmust be the size of 657*3b3a8eb9SGleb Smirnoff.Vt struct pfr_addr . 658*3b3a8eb9SGleb SmirnoffOn exit, 659*3b3a8eb9SGleb Smirnoff.Va pfrio_nadd 660*3b3a8eb9SGleb Smirnoffcontains the number of addresses effectively added. 661*3b3a8eb9SGleb Smirnoff.Bd -literal 662*3b3a8eb9SGleb Smirnoffstruct pfr_addr { 663*3b3a8eb9SGleb Smirnoff union { 664*3b3a8eb9SGleb Smirnoff struct in_addr _pfra_ip4addr; 665*3b3a8eb9SGleb Smirnoff struct in6_addr _pfra_ip6addr; 666*3b3a8eb9SGleb Smirnoff } pfra_u; 667*3b3a8eb9SGleb Smirnoff u_int8_t pfra_af; 668*3b3a8eb9SGleb Smirnoff u_int8_t pfra_net; 669*3b3a8eb9SGleb Smirnoff u_int8_t pfra_not; 670*3b3a8eb9SGleb Smirnoff u_int8_t pfra_fback; 671*3b3a8eb9SGleb Smirnoff}; 672*3b3a8eb9SGleb Smirnoff#define pfra_ip4addr pfra_u._pfra_ip4addr 673*3b3a8eb9SGleb Smirnoff#define pfra_ip6addr pfra_u._pfra_ip6addr 674*3b3a8eb9SGleb Smirnoff.Ed 675*3b3a8eb9SGleb Smirnoff.It Dv DIOCRDELADDRS Fa "struct pfioc_table *io" 676*3b3a8eb9SGleb SmirnoffDelete one or more addresses from a table. 677*3b3a8eb9SGleb SmirnoffOn entry, 678*3b3a8eb9SGleb Smirnoff.Va pfrio_table 679*3b3a8eb9SGleb Smirnoffcontains the table ID and 680*3b3a8eb9SGleb Smirnoff.Va pfrio_buffer 681*3b3a8eb9SGleb Smirnoffmust point to an array of 682*3b3a8eb9SGleb Smirnoff.Vt struct pfr_addr 683*3b3a8eb9SGleb Smirnoffcontaining at least 684*3b3a8eb9SGleb Smirnoff.Vt pfrio_size 685*3b3a8eb9SGleb Smirnoffelements to delete from the table. 686*3b3a8eb9SGleb Smirnoff.Vt pfrio_esize 687*3b3a8eb9SGleb Smirnoffmust be the size of 688*3b3a8eb9SGleb Smirnoff.Vt struct pfr_addr . 689*3b3a8eb9SGleb SmirnoffOn exit, 690*3b3a8eb9SGleb Smirnoff.Va pfrio_ndel 691*3b3a8eb9SGleb Smirnoffcontains the number of addresses effectively deleted. 692*3b3a8eb9SGleb Smirnoff.It Dv DIOCRSETADDRS Fa "struct pfioc_table *io" 693*3b3a8eb9SGleb SmirnoffReplace the content of a table by a new address list. 694*3b3a8eb9SGleb SmirnoffThis is the most complicated command, which uses all the structure members. 695*3b3a8eb9SGleb Smirnoff.Pp 696*3b3a8eb9SGleb SmirnoffOn entry, 697*3b3a8eb9SGleb Smirnoff.Va pfrio_table 698*3b3a8eb9SGleb Smirnoffcontains the table ID and 699*3b3a8eb9SGleb Smirnoff.Va pfrio_buffer 700*3b3a8eb9SGleb Smirnoffmust point to an array of 701*3b3a8eb9SGleb Smirnoff.Vt struct pfr_addr 702*3b3a8eb9SGleb Smirnoffcontaining at least 703*3b3a8eb9SGleb Smirnoff.Vt pfrio_size 704*3b3a8eb9SGleb Smirnoffelements which become the new contents of the table. 705*3b3a8eb9SGleb Smirnoff.Vt pfrio_esize 706*3b3a8eb9SGleb Smirnoffmust be the size of 707*3b3a8eb9SGleb Smirnoff.Vt struct pfr_addr . 708*3b3a8eb9SGleb SmirnoffAdditionally, if 709*3b3a8eb9SGleb Smirnoff.Va pfrio_size2 710*3b3a8eb9SGleb Smirnoffis non-zero, 711*3b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size..pfrio_size2] 712*3b3a8eb9SGleb Smirnoffmust be a writeable buffer, into which the kernel can copy the 713*3b3a8eb9SGleb Smirnoffaddresses that have been deleted during the replace operation. 714*3b3a8eb9SGleb SmirnoffOn exit, 715*3b3a8eb9SGleb Smirnoff.Va pfrio_ndel , 716*3b3a8eb9SGleb Smirnoff.Va pfrio_nadd , 717*3b3a8eb9SGleb Smirnoffand 718*3b3a8eb9SGleb Smirnoff.Va pfrio_nchange 719*3b3a8eb9SGleb Smirnoffcontain the number of addresses deleted, added, and changed by the 720*3b3a8eb9SGleb Smirnoffkernel. 721*3b3a8eb9SGleb SmirnoffIf 722*3b3a8eb9SGleb Smirnoff.Va pfrio_size2 723*3b3a8eb9SGleb Smirnoffwas set on entry, 724*3b3a8eb9SGleb Smirnoff.Va pfrio_size2 725*3b3a8eb9SGleb Smirnoffwill point to the size of the buffer used, exactly like 726*3b3a8eb9SGleb Smirnoff.Dv DIOCRGETADDRS . 727*3b3a8eb9SGleb Smirnoff.It Dv DIOCRGETADDRS Fa "struct pfioc_table *io" 728*3b3a8eb9SGleb SmirnoffGet all the addresses of a table. 729*3b3a8eb9SGleb SmirnoffOn entry, 730*3b3a8eb9SGleb Smirnoff.Va pfrio_table 731*3b3a8eb9SGleb Smirnoffcontains the table ID and 732*3b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size] 733*3b3a8eb9SGleb Smirnoffcontains a valid writeable buffer for 734*3b3a8eb9SGleb Smirnoff.Vt pfr_addr 735*3b3a8eb9SGleb Smirnoffstructures. 736*3b3a8eb9SGleb SmirnoffOn exit, 737*3b3a8eb9SGleb Smirnoff.Va pfrio_size 738*3b3a8eb9SGleb Smirnoffcontains the number of addresses written into the buffer. 739*3b3a8eb9SGleb SmirnoffIf the buffer was too small, the kernel does not store anything but just 740*3b3a8eb9SGleb Smirnoffreturns the required buffer size, without returning an error. 741*3b3a8eb9SGleb Smirnoff.It Dv DIOCRGETASTATS Fa "struct pfioc_table *io" 742*3b3a8eb9SGleb SmirnoffThis call is like 743*3b3a8eb9SGleb Smirnoff.Dv DIOCRGETADDRS 744*3b3a8eb9SGleb Smirnoffbut is used to get an array of 745*3b3a8eb9SGleb Smirnoff.Vt pfr_astats 746*3b3a8eb9SGleb Smirnoffstructures. 747*3b3a8eb9SGleb Smirnoff.Bd -literal 748*3b3a8eb9SGleb Smirnoffstruct pfr_astats { 749*3b3a8eb9SGleb Smirnoff struct pfr_addr pfras_a; 750*3b3a8eb9SGleb Smirnoff u_int64_t pfras_packets 751*3b3a8eb9SGleb Smirnoff [PFR_DIR_MAX][PFR_OP_ADDR_MAX]; 752*3b3a8eb9SGleb Smirnoff u_int64_t pfras_bytes 753*3b3a8eb9SGleb Smirnoff [PFR_DIR_MAX][PFR_OP_ADDR_MAX]; 754*3b3a8eb9SGleb Smirnoff long pfras_tzero; 755*3b3a8eb9SGleb Smirnoff}; 756*3b3a8eb9SGleb Smirnoff.Ed 757*3b3a8eb9SGleb Smirnoff.It Dv DIOCRCLRASTATS Fa "struct pfioc_table *io" 758*3b3a8eb9SGleb SmirnoffClear the statistics of one or more addresses. 759*3b3a8eb9SGleb SmirnoffOn entry, 760*3b3a8eb9SGleb Smirnoff.Va pfrio_table 761*3b3a8eb9SGleb Smirnoffcontains the table ID and 762*3b3a8eb9SGleb Smirnoff.Va pfrio_buffer 763*3b3a8eb9SGleb Smirnoffmust point to an array of 764*3b3a8eb9SGleb Smirnoff.Vt struct pfr_addr 765*3b3a8eb9SGleb Smirnoffcontaining at least 766*3b3a8eb9SGleb Smirnoff.Vt pfrio_size 767*3b3a8eb9SGleb Smirnoffelements to be cleared from the table. 768*3b3a8eb9SGleb Smirnoff.Vt pfrio_esize 769*3b3a8eb9SGleb Smirnoffmust be the size of 770*3b3a8eb9SGleb Smirnoff.Vt struct pfr_addr . 771*3b3a8eb9SGleb SmirnoffOn exit, 772*3b3a8eb9SGleb Smirnoff.Va pfrio_nzero 773*3b3a8eb9SGleb Smirnoffcontains the number of addresses effectively cleared. 774*3b3a8eb9SGleb Smirnoff.It Dv DIOCRTSTADDRS Fa "struct pfioc_table *io" 775*3b3a8eb9SGleb SmirnoffTest if the given addresses match a table. 776*3b3a8eb9SGleb SmirnoffOn entry, 777*3b3a8eb9SGleb Smirnoff.Va pfrio_table 778*3b3a8eb9SGleb Smirnoffcontains the table ID and 779*3b3a8eb9SGleb Smirnoff.Va pfrio_buffer 780*3b3a8eb9SGleb Smirnoffmust point to an array of 781*3b3a8eb9SGleb Smirnoff.Vt struct pfr_addr 782*3b3a8eb9SGleb Smirnoffcontaining at least 783*3b3a8eb9SGleb Smirnoff.Vt pfrio_size 784*3b3a8eb9SGleb Smirnoffelements, each of which will be tested for a match in the table. 785*3b3a8eb9SGleb Smirnoff.Vt pfrio_esize 786*3b3a8eb9SGleb Smirnoffmust be the size of 787*3b3a8eb9SGleb Smirnoff.Vt struct pfr_addr . 788*3b3a8eb9SGleb SmirnoffOn exit, the kernel updates the 789*3b3a8eb9SGleb Smirnoff.Vt pfr_addr 790*3b3a8eb9SGleb Smirnoffarray by setting the 791*3b3a8eb9SGleb Smirnoff.Va pfra_fback 792*3b3a8eb9SGleb Smirnoffmember appropriately. 793*3b3a8eb9SGleb Smirnoff.It Dv DIOCRSETTFLAGS Fa "struct pfioc_table *io" 794*3b3a8eb9SGleb SmirnoffChange the 795*3b3a8eb9SGleb Smirnoff.Dv PFR_TFLAG_CONST 796*3b3a8eb9SGleb Smirnoffor 797*3b3a8eb9SGleb Smirnoff.Dv PFR_TFLAG_PERSIST 798*3b3a8eb9SGleb Smirnoffflags of a table. 799*3b3a8eb9SGleb SmirnoffOn entry, 800*3b3a8eb9SGleb Smirnoff.Va pfrio_buffer 801*3b3a8eb9SGleb Smirnoffmust point to an array of 802*3b3a8eb9SGleb Smirnoff.Vt struct pfr_table 803*3b3a8eb9SGleb Smirnoffcontaining at least 804*3b3a8eb9SGleb Smirnoff.Vt pfrio_size 805*3b3a8eb9SGleb Smirnoffelements. 806*3b3a8eb9SGleb Smirnoff.Va pfrio_esize 807*3b3a8eb9SGleb Smirnoffmust be the size of 808*3b3a8eb9SGleb Smirnoff.Vt struct pfr_table . 809*3b3a8eb9SGleb Smirnoff.Va pfrio_setflag 810*3b3a8eb9SGleb Smirnoffmust contain the flags to add, while 811*3b3a8eb9SGleb Smirnoff.Va pfrio_clrflag 812*3b3a8eb9SGleb Smirnoffmust contain the flags to remove. 813*3b3a8eb9SGleb SmirnoffOn exit, 814*3b3a8eb9SGleb Smirnoff.Va pfrio_nchange 815*3b3a8eb9SGleb Smirnoffand 816*3b3a8eb9SGleb Smirnoff.Va pfrio_ndel 817*3b3a8eb9SGleb Smirnoffcontain the number of tables altered or deleted by the kernel. 818*3b3a8eb9SGleb SmirnoffYes, tables can be deleted if one removes the 819*3b3a8eb9SGleb Smirnoff.Dv PFR_TFLAG_PERSIST 820*3b3a8eb9SGleb Smirnoffflag of an unreferenced table. 821*3b3a8eb9SGleb Smirnoff.It Dv DIOCRINADEFINE Fa "struct pfioc_table *io" 822*3b3a8eb9SGleb SmirnoffDefines a table in the inactive set. 823*3b3a8eb9SGleb SmirnoffOn entry, 824*3b3a8eb9SGleb Smirnoff.Va pfrio_table 825*3b3a8eb9SGleb Smirnoffcontains the table ID and 826*3b3a8eb9SGleb Smirnoff.Va pfrio_buffer[pfrio_size] 827*3b3a8eb9SGleb Smirnoffcontains an array of 828*3b3a8eb9SGleb Smirnoff.Vt pfr_addr 829*3b3a8eb9SGleb Smirnoffstructures to put in the table. 830*3b3a8eb9SGleb SmirnoffA valid ticket must also be supplied to 831*3b3a8eb9SGleb Smirnoff.Va pfrio_ticket . 832*3b3a8eb9SGleb SmirnoffOn exit, 833*3b3a8eb9SGleb Smirnoff.Va pfrio_nadd 834*3b3a8eb9SGleb Smirnoffcontains 0 if the table was already defined in the inactive list 835*3b3a8eb9SGleb Smirnoffor 1 if a new table has been created. 836*3b3a8eb9SGleb Smirnoff.Va pfrio_naddr 837*3b3a8eb9SGleb Smirnoffcontains the number of addresses effectively put in the table. 838*3b3a8eb9SGleb Smirnoff.It Dv DIOCXBEGIN Fa "struct pfioc_trans *io" 839*3b3a8eb9SGleb Smirnoff.Bd -literal 840*3b3a8eb9SGleb Smirnoffstruct pfioc_trans { 841*3b3a8eb9SGleb Smirnoff int size; /* number of elements */ 842*3b3a8eb9SGleb Smirnoff int esize; /* size of each element in bytes */ 843*3b3a8eb9SGleb Smirnoff struct pfioc_trans_e { 844*3b3a8eb9SGleb Smirnoff int rs_num; 845*3b3a8eb9SGleb Smirnoff char anchor[MAXPATHLEN]; 846*3b3a8eb9SGleb Smirnoff u_int32_t ticket; 847*3b3a8eb9SGleb Smirnoff } *array; 848*3b3a8eb9SGleb Smirnoff}; 849*3b3a8eb9SGleb Smirnoff.Ed 850*3b3a8eb9SGleb Smirnoff.Pp 851*3b3a8eb9SGleb SmirnoffClear all the inactive rulesets specified in the 852*3b3a8eb9SGleb Smirnoff.Vt pfioc_trans_e 853*3b3a8eb9SGleb Smirnoffarray. 854*3b3a8eb9SGleb SmirnoffFor each ruleset, a ticket is returned for subsequent "add rule" ioctls, 855*3b3a8eb9SGleb Smirnoffas well as for the 856*3b3a8eb9SGleb Smirnoff.Dv DIOCXCOMMIT 857*3b3a8eb9SGleb Smirnoffand 858*3b3a8eb9SGleb Smirnoff.Dv DIOCXROLLBACK 859*3b3a8eb9SGleb Smirnoffcalls. 860*3b3a8eb9SGleb Smirnoff.Pp 861*3b3a8eb9SGleb SmirnoffRuleset types, identified by 862*3b3a8eb9SGleb Smirnoff.Va rs_num , 863*3b3a8eb9SGleb Smirnoffinclude the following: 864*3b3a8eb9SGleb Smirnoff.Pp 865*3b3a8eb9SGleb Smirnoff.Bl -tag -width PF_RULESET_FILTER -offset ind -compact 866*3b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_SCRUB 867*3b3a8eb9SGleb SmirnoffScrub (packet normalization) rules. 868*3b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_FILTER 869*3b3a8eb9SGleb SmirnoffFilter rules. 870*3b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_NAT 871*3b3a8eb9SGleb SmirnoffNAT (Network Address Translation) rules. 872*3b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_BINAT 873*3b3a8eb9SGleb SmirnoffBidirectional NAT rules. 874*3b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_RDR 875*3b3a8eb9SGleb SmirnoffRedirect rules. 876*3b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_ALTQ 877*3b3a8eb9SGleb SmirnoffALTQ disciplines. 878*3b3a8eb9SGleb Smirnoff.It Dv PF_RULESET_TABLE 879*3b3a8eb9SGleb SmirnoffAddress tables. 880*3b3a8eb9SGleb Smirnoff.El 881*3b3a8eb9SGleb Smirnoff.It Dv DIOCXCOMMIT Fa "struct pfioc_trans *io" 882*3b3a8eb9SGleb SmirnoffAtomically switch a vector of inactive rulesets to the active rulesets. 883*3b3a8eb9SGleb SmirnoffThis call is implemented as a standard two-phase commit, which will either 884*3b3a8eb9SGleb Smirnofffail for all rulesets or completely succeed. 885*3b3a8eb9SGleb SmirnoffAll tickets need to be valid. 886*3b3a8eb9SGleb SmirnoffThis ioctl returns 887*3b3a8eb9SGleb Smirnoff.Er EBUSY 888*3b3a8eb9SGleb Smirnoffif another process is concurrently updating some of the same rulesets. 889*3b3a8eb9SGleb Smirnoff.It Dv DIOCXROLLBACK Fa "struct pfioc_trans *io" 890*3b3a8eb9SGleb SmirnoffClean up the kernel by undoing all changes that have taken place on the 891*3b3a8eb9SGleb Smirnoffinactive rulesets since the last 892*3b3a8eb9SGleb Smirnoff.Dv DIOCXBEGIN . 893*3b3a8eb9SGleb Smirnoff.Dv DIOCXROLLBACK 894*3b3a8eb9SGleb Smirnoffwill silently ignore rulesets for which the ticket is invalid. 895*3b3a8eb9SGleb Smirnoff.It Dv DIOCSETHOSTID Fa "u_int32_t *hostid" 896*3b3a8eb9SGleb SmirnoffSet the host ID, which is used by 897*3b3a8eb9SGleb Smirnoff.Xr pfsync 4 898*3b3a8eb9SGleb Smirnoffto identify which host created state table entries. 899*3b3a8eb9SGleb Smirnoff.It Dv DIOCOSFPFLUSH 900*3b3a8eb9SGleb SmirnoffFlush the passive OS fingerprint table. 901*3b3a8eb9SGleb Smirnoff.It Dv DIOCOSFPADD Fa "struct pf_osfp_ioctl *io" 902*3b3a8eb9SGleb Smirnoff.Bd -literal 903*3b3a8eb9SGleb Smirnoffstruct pf_osfp_ioctl { 904*3b3a8eb9SGleb Smirnoff struct pf_osfp_entry { 905*3b3a8eb9SGleb Smirnoff SLIST_ENTRY(pf_osfp_entry) fp_entry; 906*3b3a8eb9SGleb Smirnoff pf_osfp_t fp_os; 907*3b3a8eb9SGleb Smirnoff char fp_class_nm[PF_OSFP_LEN]; 908*3b3a8eb9SGleb Smirnoff char fp_version_nm[PF_OSFP_LEN]; 909*3b3a8eb9SGleb Smirnoff char fp_subtype_nm[PF_OSFP_LEN]; 910*3b3a8eb9SGleb Smirnoff } fp_os; 911*3b3a8eb9SGleb Smirnoff pf_tcpopts_t fp_tcpopts; 912*3b3a8eb9SGleb Smirnoff u_int16_t fp_wsize; 913*3b3a8eb9SGleb Smirnoff u_int16_t fp_psize; 914*3b3a8eb9SGleb Smirnoff u_int16_t fp_mss; 915*3b3a8eb9SGleb Smirnoff u_int16_t fp_flags; 916*3b3a8eb9SGleb Smirnoff u_int8_t fp_optcnt; 917*3b3a8eb9SGleb Smirnoff u_int8_t fp_wscale; 918*3b3a8eb9SGleb Smirnoff u_int8_t fp_ttl; 919*3b3a8eb9SGleb Smirnoff int fp_getnum; 920*3b3a8eb9SGleb Smirnoff}; 921*3b3a8eb9SGleb Smirnoff.Ed 922*3b3a8eb9SGleb Smirnoff.Pp 923*3b3a8eb9SGleb SmirnoffAdd a passive OS fingerprint to the table. 924*3b3a8eb9SGleb SmirnoffSet 925*3b3a8eb9SGleb Smirnoff.Va fp_os.fp_os 926*3b3a8eb9SGleb Smirnoffto the packed fingerprint, 927*3b3a8eb9SGleb Smirnoff.Va fp_os.fp_class_nm 928*3b3a8eb9SGleb Smirnoffto the name of the class (Linux, Windows, etc), 929*3b3a8eb9SGleb Smirnoff.Va fp_os.fp_version_nm 930*3b3a8eb9SGleb Smirnoffto the name of the version (NT, 95, 98), and 931*3b3a8eb9SGleb Smirnoff.Va fp_os.fp_subtype_nm 932*3b3a8eb9SGleb Smirnoffto the name of the subtype or patchlevel. 933*3b3a8eb9SGleb SmirnoffThe members 934*3b3a8eb9SGleb Smirnoff.Va fp_mss , 935*3b3a8eb9SGleb Smirnoff.Va fp_wsize , 936*3b3a8eb9SGleb Smirnoff.Va fp_psize , 937*3b3a8eb9SGleb Smirnoff.Va fp_ttl , 938*3b3a8eb9SGleb Smirnoff.Va fp_optcnt , 939*3b3a8eb9SGleb Smirnoffand 940*3b3a8eb9SGleb Smirnoff.Va fp_wscale 941*3b3a8eb9SGleb Smirnoffare set to the TCP MSS, the TCP window size, the IP length, the IP TTL, 942*3b3a8eb9SGleb Smirnoffthe number of TCP options, and the TCP window scaling constant of the 943*3b3a8eb9SGleb SmirnoffTCP SYN packet, respectively. 944*3b3a8eb9SGleb Smirnoff.Pp 945*3b3a8eb9SGleb SmirnoffThe 946*3b3a8eb9SGleb Smirnoff.Va fp_flags 947*3b3a8eb9SGleb Smirnoffmember is filled according to the 948*3b3a8eb9SGleb Smirnoff.Aq Pa net/pfvar.h 949*3b3a8eb9SGleb Smirnoffinclude file 950*3b3a8eb9SGleb Smirnoff.Dv PF_OSFP_* 951*3b3a8eb9SGleb Smirnoffdefines. 952*3b3a8eb9SGleb SmirnoffThe 953*3b3a8eb9SGleb Smirnoff.Va fp_tcpopts 954*3b3a8eb9SGleb Smirnoffmember contains packed TCP options. 955*3b3a8eb9SGleb SmirnoffEach option uses 956*3b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_BITS 957*3b3a8eb9SGleb Smirnoffbits in the packed value. 958*3b3a8eb9SGleb SmirnoffOptions include any of 959*3b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_NOP , 960*3b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_SACK , 961*3b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_WSCALE , 962*3b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_MSS , 963*3b3a8eb9SGleb Smirnoffor 964*3b3a8eb9SGleb Smirnoff.Dv PF_OSFP_TCPOPT_TS . 965*3b3a8eb9SGleb Smirnoff.Pp 966*3b3a8eb9SGleb SmirnoffThe 967*3b3a8eb9SGleb Smirnoff.Va fp_getnum 968*3b3a8eb9SGleb Smirnoffmember is not used with this ioctl. 969*3b3a8eb9SGleb Smirnoff.Pp 970*3b3a8eb9SGleb SmirnoffThe structure's slack space must be zeroed for correct operation; 971*3b3a8eb9SGleb Smirnoff.Xr memset 3 972*3b3a8eb9SGleb Smirnoffthe whole structure to zero before filling and sending to the kernel. 973*3b3a8eb9SGleb Smirnoff.It Dv DIOCOSFPGET Fa "struct pf_osfp_ioctl *io" 974*3b3a8eb9SGleb SmirnoffGet the passive OS fingerprint number 975*3b3a8eb9SGleb Smirnoff.Va fp_getnum 976*3b3a8eb9SGleb Smirnofffrom the kernel's fingerprint list. 977*3b3a8eb9SGleb SmirnoffThe rest of the structure members will come back filled. 978*3b3a8eb9SGleb SmirnoffGet the whole list by repeatedly incrementing the 979*3b3a8eb9SGleb Smirnoff.Va fp_getnum 980*3b3a8eb9SGleb Smirnoffnumber until the ioctl returns 981*3b3a8eb9SGleb Smirnoff.Er EBUSY . 982*3b3a8eb9SGleb Smirnoff.It Dv DIOCGETSRCNODES Fa "struct pfioc_src_nodes *psn" 983*3b3a8eb9SGleb Smirnoff.Bd -literal 984*3b3a8eb9SGleb Smirnoffstruct pfioc_src_nodes { 985*3b3a8eb9SGleb Smirnoff int psn_len; 986*3b3a8eb9SGleb Smirnoff union { 987*3b3a8eb9SGleb Smirnoff caddr_t psu_buf; 988*3b3a8eb9SGleb Smirnoff struct pf_src_node *psu_src_nodes; 989*3b3a8eb9SGleb Smirnoff } psn_u; 990*3b3a8eb9SGleb Smirnoff#define psn_buf psn_u.psu_buf 991*3b3a8eb9SGleb Smirnoff#define psn_src_nodes psn_u.psu_src_nodes 992*3b3a8eb9SGleb Smirnoff}; 993*3b3a8eb9SGleb Smirnoff.Ed 994*3b3a8eb9SGleb Smirnoff.Pp 995*3b3a8eb9SGleb SmirnoffGet the list of source nodes kept by sticky addresses and source 996*3b3a8eb9SGleb Smirnofftracking. 997*3b3a8eb9SGleb SmirnoffThe ioctl must be called once with 998*3b3a8eb9SGleb Smirnoff.Va psn_len 999*3b3a8eb9SGleb Smirnoffset to 0. 1000*3b3a8eb9SGleb SmirnoffIf the ioctl returns without error, 1001*3b3a8eb9SGleb Smirnoff.Va psn_len 1002*3b3a8eb9SGleb Smirnoffwill be set to the size of the buffer required to hold all the 1003*3b3a8eb9SGleb Smirnoff.Va pf_src_node 1004*3b3a8eb9SGleb Smirnoffstructures held in the table. 1005*3b3a8eb9SGleb SmirnoffA buffer of this size should then be allocated, and a pointer to this buffer 1006*3b3a8eb9SGleb Smirnoffplaced in 1007*3b3a8eb9SGleb Smirnoff.Va psn_buf . 1008*3b3a8eb9SGleb SmirnoffThe ioctl must then be called again to fill this buffer with the actual 1009*3b3a8eb9SGleb Smirnoffsource node data. 1010*3b3a8eb9SGleb SmirnoffAfter that call, 1011*3b3a8eb9SGleb Smirnoff.Va psn_len 1012*3b3a8eb9SGleb Smirnoffwill be set to the length of the buffer actually used. 1013*3b3a8eb9SGleb Smirnoff.It Dv DIOCCLRSRCNODES 1014*3b3a8eb9SGleb SmirnoffClear the tree of source tracking nodes. 1015*3b3a8eb9SGleb Smirnoff.It Dv DIOCIGETIFACES Fa "struct pfioc_iface *io" 1016*3b3a8eb9SGleb SmirnoffGet the list of interfaces and interface drivers known to 1017*3b3a8eb9SGleb Smirnoff.Nm . 1018*3b3a8eb9SGleb SmirnoffAll the ioctls that manipulate interfaces 1019*3b3a8eb9SGleb Smirnoffuse the same structure described below: 1020*3b3a8eb9SGleb Smirnoff.Bd -literal 1021*3b3a8eb9SGleb Smirnoffstruct pfioc_iface { 1022*3b3a8eb9SGleb Smirnoff char pfiio_name[IFNAMSIZ]; 1023*3b3a8eb9SGleb Smirnoff void *pfiio_buffer; 1024*3b3a8eb9SGleb Smirnoff int pfiio_esize; 1025*3b3a8eb9SGleb Smirnoff int pfiio_size; 1026*3b3a8eb9SGleb Smirnoff int pfiio_nzero; 1027*3b3a8eb9SGleb Smirnoff int pfiio_flags; 1028*3b3a8eb9SGleb Smirnoff}; 1029*3b3a8eb9SGleb Smirnoff.Ed 1030*3b3a8eb9SGleb Smirnoff.Pp 1031*3b3a8eb9SGleb SmirnoffIf not empty, 1032*3b3a8eb9SGleb Smirnoff.Va pfiio_name 1033*3b3a8eb9SGleb Smirnoffcan be used to restrict the search to a specific interface or driver. 1034*3b3a8eb9SGleb Smirnoff.Va pfiio_buffer[pfiio_size] 1035*3b3a8eb9SGleb Smirnoffis the user-supplied buffer for returning the data. 1036*3b3a8eb9SGleb SmirnoffOn entry, 1037*3b3a8eb9SGleb Smirnoff.Va pfiio_size 1038*3b3a8eb9SGleb Smirnoffcontains the number of 1039*3b3a8eb9SGleb Smirnoff.Vt pfi_kif 1040*3b3a8eb9SGleb Smirnoffentries that can fit into the buffer. 1041*3b3a8eb9SGleb SmirnoffThe kernel will replace this value by the real number of entries it wants 1042*3b3a8eb9SGleb Smirnoffto return. 1043*3b3a8eb9SGleb Smirnoff.Va pfiio_esize 1044*3b3a8eb9SGleb Smirnoffshould be set to 1045*3b3a8eb9SGleb Smirnoff.Li sizeof(struct pfi_kif) . 1046*3b3a8eb9SGleb Smirnoff.Pp 1047*3b3a8eb9SGleb SmirnoffThe data is returned in the 1048*3b3a8eb9SGleb Smirnoff.Vt pfi_kif 1049*3b3a8eb9SGleb Smirnoffstructure described below: 1050*3b3a8eb9SGleb Smirnoff.Bd -literal 1051*3b3a8eb9SGleb Smirnoffstruct pfi_kif { 1052*3b3a8eb9SGleb Smirnoff RB_ENTRY(pfi_kif) pfik_tree; 1053*3b3a8eb9SGleb Smirnoff char pfik_name[IFNAMSIZ]; 1054*3b3a8eb9SGleb Smirnoff u_int64_t pfik_packets[2][2][2]; 1055*3b3a8eb9SGleb Smirnoff u_int64_t pfik_bytes[2][2][2]; 1056*3b3a8eb9SGleb Smirnoff u_int32_t pfik_tzero; 1057*3b3a8eb9SGleb Smirnoff int pfik_flags; 1058*3b3a8eb9SGleb Smirnoff struct pf_state_tree_lan_ext pfik_lan_ext; 1059*3b3a8eb9SGleb Smirnoff struct pf_state_tree_ext_gwy pfik_ext_gwy; 1060*3b3a8eb9SGleb Smirnoff TAILQ_ENTRY(pfi_kif) pfik_w_states; 1061*3b3a8eb9SGleb Smirnoff void *pfik_ah_cookie; 1062*3b3a8eb9SGleb Smirnoff struct ifnet *pfik_ifp; 1063*3b3a8eb9SGleb Smirnoff struct ifg_group *pfik_group; 1064*3b3a8eb9SGleb Smirnoff int pfik_states; 1065*3b3a8eb9SGleb Smirnoff int pfik_rules; 1066*3b3a8eb9SGleb Smirnoff TAILQ_HEAD(, pfi_dynaddr) pfik_dynaddrs; 1067*3b3a8eb9SGleb Smirnoff}; 1068*3b3a8eb9SGleb Smirnoff.Ed 1069*3b3a8eb9SGleb Smirnoff.It Dv DIOCSETIFFLAG Fa "struct pfioc_iface *io" 1070*3b3a8eb9SGleb SmirnoffSet the user setable flags (described above) of the 1071*3b3a8eb9SGleb Smirnoff.Nm 1072*3b3a8eb9SGleb Smirnoffinternal interface description. 1073*3b3a8eb9SGleb SmirnoffThe filtering process is the same as for 1074*3b3a8eb9SGleb Smirnoff.Dv DIOCIGETIFACES . 1075*3b3a8eb9SGleb Smirnoff.Bd -literal 1076*3b3a8eb9SGleb Smirnoff#define PFI_IFLAG_SKIP 0x0100 /* skip filtering on interface */ 1077*3b3a8eb9SGleb Smirnoff.Ed 1078*3b3a8eb9SGleb Smirnoff.It Dv DIOCCLRIFFLAG Fa "struct pfioc_iface *io" 1079*3b3a8eb9SGleb SmirnoffWorks as 1080*3b3a8eb9SGleb Smirnoff.Dv DIOCSETIFFLAG 1081*3b3a8eb9SGleb Smirnoffabove but clears the flags. 1082*3b3a8eb9SGleb Smirnoff.It Dv DIOCKILLSRCNODES Fa "struct pfioc_iface *io" 1083*3b3a8eb9SGleb SmirnoffExplicitly remove source tracking nodes. 1084*3b3a8eb9SGleb Smirnoff.El 1085*3b3a8eb9SGleb Smirnoff.Sh FILES 1086*3b3a8eb9SGleb Smirnoff.Bl -tag -width /dev/pf -compact 1087*3b3a8eb9SGleb Smirnoff.It Pa /dev/pf 1088*3b3a8eb9SGleb Smirnoffpacket filtering device. 1089*3b3a8eb9SGleb Smirnoff.El 1090*3b3a8eb9SGleb Smirnoff.Sh EXAMPLES 1091*3b3a8eb9SGleb SmirnoffThe following example demonstrates how to use the 1092*3b3a8eb9SGleb Smirnoff.Dv DIOCNATLOOK 1093*3b3a8eb9SGleb Smirnoffcommand to find the internal host/port of a NATed connection: 1094*3b3a8eb9SGleb Smirnoff.Bd -literal 1095*3b3a8eb9SGleb Smirnoff#include <sys/types.h> 1096*3b3a8eb9SGleb Smirnoff#include <sys/socket.h> 1097*3b3a8eb9SGleb Smirnoff#include <sys/ioctl.h> 1098*3b3a8eb9SGleb Smirnoff#include <sys/fcntl.h> 1099*3b3a8eb9SGleb Smirnoff#include <net/if.h> 1100*3b3a8eb9SGleb Smirnoff#include <netinet/in.h> 1101*3b3a8eb9SGleb Smirnoff#include <net/pfvar.h> 1102*3b3a8eb9SGleb Smirnoff#include <err.h> 1103*3b3a8eb9SGleb Smirnoff#include <stdio.h> 1104*3b3a8eb9SGleb Smirnoff#include <stdlib.h> 1105*3b3a8eb9SGleb Smirnoff 1106*3b3a8eb9SGleb Smirnoffu_int32_t 1107*3b3a8eb9SGleb Smirnoffread_address(const char *s) 1108*3b3a8eb9SGleb Smirnoff{ 1109*3b3a8eb9SGleb Smirnoff int a, b, c, d; 1110*3b3a8eb9SGleb Smirnoff 1111*3b3a8eb9SGleb Smirnoff sscanf(s, "%i.%i.%i.%i", &a, &b, &c, &d); 1112*3b3a8eb9SGleb Smirnoff return htonl(a << 24 | b << 16 | c << 8 | d); 1113*3b3a8eb9SGleb Smirnoff} 1114*3b3a8eb9SGleb Smirnoff 1115*3b3a8eb9SGleb Smirnoffvoid 1116*3b3a8eb9SGleb Smirnoffprint_address(u_int32_t a) 1117*3b3a8eb9SGleb Smirnoff{ 1118*3b3a8eb9SGleb Smirnoff a = ntohl(a); 1119*3b3a8eb9SGleb Smirnoff printf("%d.%d.%d.%d", a >> 24 & 255, a >> 16 & 255, 1120*3b3a8eb9SGleb Smirnoff a >> 8 & 255, a & 255); 1121*3b3a8eb9SGleb Smirnoff} 1122*3b3a8eb9SGleb Smirnoff 1123*3b3a8eb9SGleb Smirnoffint 1124*3b3a8eb9SGleb Smirnoffmain(int argc, char *argv[]) 1125*3b3a8eb9SGleb Smirnoff{ 1126*3b3a8eb9SGleb Smirnoff struct pfioc_natlook nl; 1127*3b3a8eb9SGleb Smirnoff int dev; 1128*3b3a8eb9SGleb Smirnoff 1129*3b3a8eb9SGleb Smirnoff if (argc != 5) { 1130*3b3a8eb9SGleb Smirnoff printf("%s <gwy addr> <gwy port> <ext addr> <ext port>\\n", 1131*3b3a8eb9SGleb Smirnoff argv[0]); 1132*3b3a8eb9SGleb Smirnoff return 1; 1133*3b3a8eb9SGleb Smirnoff } 1134*3b3a8eb9SGleb Smirnoff 1135*3b3a8eb9SGleb Smirnoff dev = open("/dev/pf", O_RDWR); 1136*3b3a8eb9SGleb Smirnoff if (dev == -1) 1137*3b3a8eb9SGleb Smirnoff err(1, "open(\\"/dev/pf\\") failed"); 1138*3b3a8eb9SGleb Smirnoff 1139*3b3a8eb9SGleb Smirnoff memset(&nl, 0, sizeof(struct pfioc_natlook)); 1140*3b3a8eb9SGleb Smirnoff nl.saddr.v4.s_addr = read_address(argv[1]); 1141*3b3a8eb9SGleb Smirnoff nl.sport = htons(atoi(argv[2])); 1142*3b3a8eb9SGleb Smirnoff nl.daddr.v4.s_addr = read_address(argv[3]); 1143*3b3a8eb9SGleb Smirnoff nl.dport = htons(atoi(argv[4])); 1144*3b3a8eb9SGleb Smirnoff nl.af = AF_INET; 1145*3b3a8eb9SGleb Smirnoff nl.proto = IPPROTO_TCP; 1146*3b3a8eb9SGleb Smirnoff nl.direction = PF_IN; 1147*3b3a8eb9SGleb Smirnoff 1148*3b3a8eb9SGleb Smirnoff if (ioctl(dev, DIOCNATLOOK, &nl)) 1149*3b3a8eb9SGleb Smirnoff err(1, "DIOCNATLOOK"); 1150*3b3a8eb9SGleb Smirnoff 1151*3b3a8eb9SGleb Smirnoff printf("internal host "); 1152*3b3a8eb9SGleb Smirnoff print_address(nl.rsaddr.v4.s_addr); 1153*3b3a8eb9SGleb Smirnoff printf(":%u\\n", ntohs(nl.rsport)); 1154*3b3a8eb9SGleb Smirnoff return 0; 1155*3b3a8eb9SGleb Smirnoff} 1156*3b3a8eb9SGleb Smirnoff.Ed 1157*3b3a8eb9SGleb Smirnoff.Sh SEE ALSO 1158*3b3a8eb9SGleb Smirnoff.Xr ioctl 2 , 1159*3b3a8eb9SGleb Smirnoff.Xr altq 4 , 1160*3b3a8eb9SGleb Smirnoff.Xr if_bridge 4 , 1161*3b3a8eb9SGleb Smirnoff.Xr pflog 4 , 1162*3b3a8eb9SGleb Smirnoff.Xr pflow 4 , 1163*3b3a8eb9SGleb Smirnoff.Xr pfsync 4 , 1164*3b3a8eb9SGleb Smirnoff.Xr pfctl 8 , 1165*3b3a8eb9SGleb Smirnoff.Xr altq 9 1166*3b3a8eb9SGleb Smirnoff.Sh HISTORY 1167*3b3a8eb9SGleb SmirnoffThe 1168*3b3a8eb9SGleb Smirnoff.Nm 1169*3b3a8eb9SGleb Smirnoffpacket filtering mechanism first appeared in 1170*3b3a8eb9SGleb Smirnoff.Ox 3.0 1171*3b3a8eb9SGleb Smirnoffand then 1172*3b3a8eb9SGleb Smirnoff.Fx 5.2 . 1173*3b3a8eb9SGleb Smirnoff.Pp 1174*3b3a8eb9SGleb SmirnoffThis implementation matches 1175*3b3a8eb9SGleb Smirnoff.Ox 4.5 . 1176