1.\" $OpenBSD: pf.conf.5,v 1.582 2019/10/23 23:02:55 kn Exp $ 2.\" 3.\" Copyright (c) 2002, Daniel Hartmeier 4.\" Copyright (c) 2003 - 2013 Henning Brauer <henning@openbsd.org> 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 11.\" - Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" - Redistributions in binary form must reproduce the above 14.\" copyright notice, this list of conditions and the following 15.\" disclaimer in the documentation and/or other materials provided 16.\" with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 28.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29.\" POSSIBILITY OF SUCH DAMAGE. 30.\" 31.Dd $Mdocdate: October 23 2019 $ 32.Dt PF.CONF 5 33.Os 34.Sh NAME 35.Nm pf.conf 36.Nd packet filter configuration file 37.Sh DESCRIPTION 38The 39.Xr pf 4 40packet filter modifies, drops, or passes packets according to rules or 41definitions specified in 42.Nm . 43.Pp 44This is an overview of the sections in this manual page: 45.Bl -inset 46.It Sx PACKET FILTERING 47including network address translation (NAT). 48.It Sx OPTIONS 49globally tune the behaviour of the packet filtering engine. 50.It Sx QUEUEING 51provides rule-based bandwidth and traffic control. 52.It Sx TABLES 53provide a method for dealing with large numbers of addresses. 54.It Sx ANCHORS 55are containers for rules and tables. 56.It Sx STATEFUL FILTERING 57tracks packets by state. 58.It Sx TRAFFIC NORMALISATION 59includes scrub, fragment handling, and blocking spoofed traffic. 60.It Sx OPERATING SYSTEM FINGERPRINTING 61is a method for detecting a host's operating system. 62.It Sx EXAMPLES 63provides some example rulesets. 64.It Sx GRAMMAR 65provides a complete BNF grammar reference. 66.El 67.Pp 68The current line can be extended over multiple lines using a backslash 69.Pq Sq \e . 70Comments can be put anywhere in the file using a hash mark 71.Pq Sq # , 72and extend to the end of the current line. 73Care should be taken when commenting out multi-line text: 74the comment is effective until the end of the entire block. 75.Pp 76Argument names not beginning with a letter, digit, or underscore 77must be quoted. 78.Pp 79Additional configuration files can be included with the 80.Ic include 81keyword, for example: 82.Bd -literal -offset indent 83include "/etc/pf/sub.filter.conf" 84.Ed 85.Pp 86Macros can be defined that will later be expanded in context. 87Macro names must start with a letter, digit, or underscore, 88and may contain any of those characters. 89Macro names may not be reserved words (for example 90.Ic pass , 91.Cm in , 92.Cm out ) . 93Macros are not expanded inside quotes. 94.Pp 95For example: 96.Bd -literal -offset indent 97ext_if = "kue0" 98all_ifs = "{" $ext_if lo0 "}" 99pass out on $ext_if from any to any 100pass in on $ext_if proto tcp from any to any port 25 101.Ed 102.Sh PACKET FILTERING 103.Xr pf 4 104has the ability to 105.Ic block , 106.Ic pass , 107and 108.Ic match 109packets based on attributes of their layer 3 110and layer 4 headers. 111Filter rules determine which of these actions are taken; 112filter parameters specify the packets to which a rule applies. 113.Pp 114Each time a packet processed by the packet filter comes in on or 115goes out through an interface, the filter rules are evaluated in 116sequential order, from first to last. 117For 118.Ic block 119and 120.Ic pass , 121the last matching rule decides what action is taken; 122if no rule matches the packet, the default action is to pass 123the packet without creating a state. 124For 125.Ic match , 126rules are evaluated every time they match; 127the pass/block state of a packet remains unchanged. 128.Pp 129Most parameters are optional. 130If a parameter is specified, the rule only applies to packets with 131matching attributes. 132The matching for some parameters can be inverted with the 133.Cm !\& 134operator. 135Certain parameters can be expressed as lists, in which case 136.Xr pfctl 8 137generates all needed rule combinations. 138.Pp 139By default 140.Xr pf 4 141filters packets statefully: 142the first time a packet matches a 143.Ic pass 144rule, a state entry is created. 145The packet filter examines each packet to see if it matches an existing state. 146If it does, the packet is passed without evaluation of any rules. 147After the connection is closed or times out, the state entry is automatically 148removed. 149.Pp 150The following actions can be used in the filter: 151.Bl -tag -width Ds 152.It Ic block 153The packet is blocked. 154There are a number of ways in which a 155.Ic block 156rule can behave when blocking a packet. 157The default behaviour is to 158.Cm drop 159packets silently, however this can be overridden or made 160explicit either globally, by setting the 161.Cm block-policy 162option, or on a per-rule basis with one of the following options: 163.Pp 164.Bl -tag -width return-icmp6 -compact 165.It Cm drop 166The packet is silently dropped. 167.It Cm return 168This causes a TCP RST to be returned for TCP packets 169and an ICMP UNREACHABLE for other types of packets. 170.It Cm return-icmp 171.It Cm return-icmp6 172This causes ICMP messages to be returned for packets which match the rule. 173By default this is an ICMP UNREACHABLE message, however this 174can be overridden by specifying a message as a code or number. 175.It Cm return-rst 176This applies only to TCP packets, 177and issues a TCP RST which closes the connection. 178An optional parameter, 179.Cm ttl , 180may be given with a TTL value. 181.El 182.Pp 183Options returning ICMP packets currently have no effect if 184.Xr pf 4 185operates on a 186.Xr bridge 4 , 187as the code to support this feature has not yet been implemented. 188.Pp 189The simplest mechanism to block everything by default and only pass 190packets that match explicit rules is specify a first filter rule of: 191.Pp 192.Dl block all 193.It Ic match 194The packet is matched. 195This mechanism is used to provide fine grained filtering 196without altering the block/pass state of a packet. 197.Ic match 198rules differ from 199.Ic block 200and 201.Ic pass 202rules in that parameters are set every time a packet matches the 203rule, not only on the last matching rule. 204For the following parameters, 205this means that the parameter effectively becomes 206.Dq sticky 207until explicitly overridden: 208.Cm nat-to , 209.Cm binat-to , 210.Cm rdr-to , 211.Cm queue , 212.Cm rtable , 213and 214.Cm scrub . 215.Pp 216.Cm log 217is different still, 218in that the action happens every time a rule matches 219i.e. a single packet can get logged more than once. 220.It Ic pass 221The packet is passed; 222state is created unless the 223.Cm no state 224option is specified. 225.El 226.Pp 227The following parameters can be used in the filter: 228.Bl -tag -width Ds 229.It Cm in No or Cm out 230A packet always comes in on, or goes out through, one interface. 231.Cm in 232and 233.Cm out 234apply to incoming and outgoing packets; 235if neither are specified, 236the rule will match packets in both directions. 237.It Cm log Pq Cm all | matches | to Ar interface | Cm user 238In addition to any action specified, 239log the packet. 240Only the packet that establishes the state is logged, 241unless the 242.Cm no state 243option is specified. 244The logged packets are sent to a 245.Xr pflog 4 246interface, by default 247.Pa pflog0 ; 248pflog0 is monitored by the 249.Xr pflogd 8 250logging daemon which logs to the file 251.Pa /var/log/pflog 252in pcap binary format. 253.Pp 254The keywords 255.Cm all , matches , to , 256and 257.Cm user 258are optional and can be combined using commas, 259but must be enclosed in parentheses if given. 260.Pp 261Use 262.Cm all 263to force logging of all packets for a connection. 264This is not necessary when 265.Cm no state 266is explicitly specified. 267.Pp 268If 269.Cm matches 270is specified, 271it logs the packet on all subsequent matching rules. 272It is often combined with 273.Cm to Ar interface 274to avoid adding noise to the default log file. 275.Pp 276The keyword 277.Cm user 278logs the UID and PID of the 279socket on the local host used to send or receive a packet, 280in addition to the normal information. 281.Pp 282To specify a logging interface other than 283.Pa pflog0 , 284use the syntax 285.Cm to Ar interface . 286.It Cm quick 287If a packet matches a rule which has the 288.Cm quick 289option set, this rule 290is considered the last matching rule, and evaluation of subsequent rules 291is skipped. 292.It Cm on Ar interface | Cm any 293This rule applies only to packets coming in on, or going out through, this 294particular interface or interface group. 295For more information on interface groups, 296see the 297.Ic group 298keyword in 299.Xr ifconfig 8 . 300.Cm any 301will match any existing interface except loopback ones. 302.It Cm on rdomain Ar number 303This rule applies only to packets coming in on, or going out through, this 304particular routing domain. 305.It Cm inet | inet6 306This rule applies only to packets of this address family. 307.It Cm proto Ar protocol 308This rule applies only to packets of this protocol. 309Common protocols are ICMP, ICMP6, TCP, and UDP. 310For a list of all the protocol name to number mappings used by 311.Xr pfctl 8 , 312see the file 313.Pa /etc/protocols . 314.It Xo 315.Cm from Ar source 316.Cm port Ar source 317.Cm os Ar source 318.Cm to Ar dest 319.Cm port Ar dest 320.Xc 321This rule applies only to packets with the specified source and destination 322addresses and ports. 323.Pp 324Addresses can be specified in CIDR notation (matching netblocks), as 325symbolic host names, interface names or interface group names, or as any 326of the following keywords: 327.Pp 328.Bl -tag -width urpf-failed -compact 329.It Cm any 330Any address. 331.It Cm no-route 332Any address which is not currently routable. 333.It Cm route Ar label 334Any address matching the given 335.Xr route 8 336.Ar label . 337.It Cm self 338Expands to all addresses assigned to all interfaces. 339.It Pf < Ar table Ns > 340Any address matching the given 341.Ar table . 342.It Cm urpf-failed 343Any source address that fails a unicast reverse path forwarding (URPF) 344check, i.e. packets coming in on an interface other than that which holds 345the route back to the packet's source address. 346.El 347.Pp 348Ranges of addresses are specified using the 349.Sq - 350operator. 351For instance: 352.Dq 10.1.1.10 - 10.1.1.12 353means all addresses from 10.1.1.10 to 10.1.1.12, 354hence addresses 10.1.1.10, 10.1.1.11, and 10.1.1.12. 355.Pp 356Interface names, interface group names, and 357.Cm self 358can have modifiers appended: 359.Pp 360.Bl -tag -width :broadcast -compact 361.It Cm :0 362Do not include interface aliases. 363.It Cm :broadcast 364Translates to the interface's broadcast address(es). 365.It Cm :network 366Translates to the network(s) attached to the interface. 367.It Cm :peer 368Translates to the point-to-point interface's peer address(es). 369.El 370.Pp 371Host names may also have the 372.Cm :0 373modifier appended to restrict the name resolution to the first of each 374v4 and v6 address found. 375.Pp 376Host name resolution and interface to address translation are done at 377ruleset load-time. 378When the address of an interface (or host name) changes (under DHCP or PPP, 379for instance), the ruleset must be reloaded for the change to be reflected 380in the kernel. 381Surrounding the interface name (and optional modifiers) in parentheses 382changes this behaviour. 383When the interface name is surrounded by parentheses, the rule is 384automatically updated whenever the interface changes its address. 385The ruleset does not need to be reloaded. 386This is especially useful with NAT. 387.Pp 388Ports can be specified either by number or by name. 389For example, port 80 can be specified as 390.Cm www . 391For a list of all port name to number mappings used by 392.Xr pfctl 8 , 393see the file 394.Pa /etc/services . 395.Pp 396Ports and ranges of ports are specified using these operators: 397.Bd -literal -offset indent 398= (equal) 399!= (unequal) 400< (less than) 401<= (less than or equal) 402> (greater than) 403>= (greater than or equal) 404: (range including boundaries) 405>< (range excluding boundaries) 406<> (except range) 407.Ed 408.Pp 409.Sq >< , 410.Sq <> 411and 412.Sq \&: 413are binary operators (they take two arguments). 414For instance: 415.Bl -tag -width Ds 416.It Li port 2000:2004 417means 418.Sq all ports \(>= 2000 and \(<= 2004 , 419hence ports 2000, 2001, 2002, 2003, and 2004. 420.It Li port 2000 >< 2004 421means 422.Sq all ports > 2000 and < 2004 , 423hence ports 2001, 2002, and 2003. 424.It Li port 2000 <> 2004 425means 426.Sq all ports < 2000 or > 2004 , 427hence ports 1\(en1999 and 2005\(en65535. 428.El 429.Pp 430The operating system of the source host can be specified in the case of TCP 431rules with the 432.Cm os 433modifier. 434See the 435.Sx OPERATING SYSTEM FINGERPRINTING 436section for more information. 437.Pp 438The 439.Cm host , 440.Cm port , 441and 442.Cm os 443specifications are optional, as in the following examples: 444.Bd -literal -offset indent 445pass in all 446pass in from any to any 447pass in proto tcp from any port < 1024 to any 448pass in proto tcp from any to any port 25 449pass in proto tcp from 10.0.0.0/8 port >= 1024 \e 450 to ! 10.1.2.3 port != ssh 451pass in proto tcp from any os "OpenBSD" 452pass in proto tcp from route "DTAG" 453.Ed 454.El 455.Pp 456The following additional parameters can be used in the filter: 457.Pp 458.Bl -tag -width Ds -compact 459.It Cm all 460This is equivalent to 461.Ql from any to any . 462.Pp 463.It Cm allow-opts 464By default, packets with IPv4 options or IPv6 hop-by-hop or destination 465options header are blocked. 466When 467.Cm allow-opts 468is specified for a 469.Ic pass 470rule, packets that pass the filter based on that rule (last matching) 471do so even if they contain options. 472For packets that match state, the rule that initially created the 473state is used. 474The implicit pass rule, that is used when a packet does not match 475any rules, does not allow IP options or option headers. 476Note that IPv6 packets with type 0 routing headers are always dropped. 477.Pp 478.It Cm divert-packet port Ar port 479Used to send matching packets to 480.Xr divert 4 481sockets bound to port 482.Ar port . 483If the default option of fragment reassembly is enabled, scrubbing with 484.Cm reassemble tcp 485is also enabled for 486.Cm divert-packet 487rules. 488.Pp 489.It Cm divert-reply 490Used to receive replies for sockets that are bound to addresses 491which are not local to the machine. 492See 493.Xr setsockopt 2 494for information on how to bind these sockets. 495.Pp 496.It Cm divert-to Ar host Cm port Ar port 497Used to redirect packets to a local socket bound to 498.Ar host 499and 500.Ar port . 501The packets will not be modified, so 502.Xr getsockname 2 503on the socket will return the original destination address of the packet. 504.Pp 505.It Cm flags Ar a Ns / Ns Ar b | Cm any 506This rule only applies to TCP packets that have the flags 507.Ar a 508set out of set 509.Ar b . 510Flags not specified in 511.Ar b 512are ignored. 513For stateful connections, the default is 514.Cm flags S/SA . 515To indicate that flags should not be checked at all, specify 516.Cm flags any . 517The flags are: (F)IN, (S)YN, (R)ST, (P)USH, (A)CK, (U)RG, (E)CE, and C(W)R. 518.Bl -tag -width "flags /SFRA" 519.It Cm flags S/S 520Flag SYN is set. 521The other flags are ignored. 522.It Cm flags S/SA 523This is the default setting for stateful connections. 524Out of SYN and ACK, exactly SYN may be set. 525SYN, SYN+PSH, and SYN+RST match, but SYN+ACK, ACK, and ACK+RST do not. 526This is more restrictive than the previous example. 527.It Cm flags /SFRA 528If the first set is not specified, it defaults to none. 529All of SYN, FIN, RST, and ACK must be unset. 530.El 531.Pp 532Because 533.Cm flags S/SA 534is applied by default (unless 535.Cm no state 536is specified), only the initial SYN packet of a TCP handshake will create 537a state for a TCP connection. 538It is possible to be less restrictive, and allow state creation from 539intermediate 540.Pq non-SYN 541packets, by specifying 542.Cm flags any . 543This will cause 544.Xr pf 4 545to synchronize to existing connections, for instance 546if one flushes the state table. 547However, states created from such intermediate packets may be missing 548connection details such as the TCP window scaling factor. 549States which modify the packet flow, such as those affected by 550.Cm af-to , 551.Cm modulate state , 552.Cm nat-to , 553.Cm rdr-to , 554or 555.Cm synproxy state 556options, or scrubbed with 557.Cm reassemble tcp , 558will also not be recoverable from intermediate packets. 559Such connections will stall and time out. 560.Pp 561.It Cm group Ar group 562Similar to 563.Cm user , 564this rule only applies to packets of sockets owned by the specified 565.Ar group . 566.Pp 567.It Cm icmp-type Ar type Cm code Ar code 568.It Cm icmp6-type Ar type Cm code Ar code 569This rule only applies to ICMP or ICMP6 packets with the specified type 570and code. 571Text names for ICMP types and codes are listed in 572.Xr icmp 4 573and 574.Xr icmp6 4 . 575The protocol and the ICMP type indicator 576.Po 577.Cm icmp-type 578or 579.Cm icmp6-type 580.Pc 581must match. 582.Pp 583.It Cm label Ar string 584Adds a label to the rule, which can be used to identify the rule. 585For instance, 586.Ql pfctl -s labels 587shows per-rule statistics for rules that have labels. 588.Pp 589The following macros can be used in labels: 590.Pp 591.Bl -tag -width "$srcaddrXXX" -compact -offset indent 592.It Va $dstaddr 593The destination IP address. 594.It Va $dstport 595The destination port specification. 596.It Va $if 597The interface. 598.It Va $nr 599The rule number. 600.It Va $proto 601The protocol name. 602.It Va $srcaddr 603The source IP address. 604.It Va $srcport 605The source port specification. 606.El 607.Pp 608For example: 609.Bd -literal -offset indent -compact 610ips = "{ 1.2.3.4, 1.2.3.5 }" 611pass in proto tcp from any to $ips \e 612 port > 1023 label "$dstaddr:$dstport" 613.Ed 614.Pp 615Expands to: 616.Bd -literal -offset indent -compact 617pass in inet proto tcp from any to 1.2.3.4 \e 618 port > 1023 label "1.2.3.4:>1023" 619pass in inet proto tcp from any to 1.2.3.5 \e 620 port > 1023 label "1.2.3.5:>1023" 621.Ed 622.Pp 623The macro expansion for the 624.Cm label 625directive occurs only at configuration file parse time, not during runtime. 626.Pp 627.It Cm max-pkt-rate Ar number Ns / Ns Ar seconds 628Measure the rate of packets matching the rule and states created by it. 629When the specified rate is exceeded, the rule stops matching. 630Only packets in the direction in which the state was created are considered, 631so that typically requests are counted and replies are not. 632For example, 633to pass up to 100 ICMP packets per 10 seconds: 634.Bd -literal -offset indent 635block in proto icmp 636pass in proto icmp max-pkt-rate 100/10 637.Ed 638.Pp 639When the rate is exceeded, all ICMP is blocked until the rate falls below 640100 per 10 seconds again. 641.Pp 642.It Cm once 643Creates a one shot rule that will remove itself from an active ruleset after 644the first match. 645In case this is the only rule in the anchor, the anchor will be destroyed 646automatically after the rule is matched. 647.Pp 648.It Cm probability Ar number Ns % 649A probability attribute can be attached to a rule, 650with a value set between 0 and 100%, 651in which case the rule is honoured using the given probability value. 652For example, the following rule will drop 20% of incoming ICMP packets: 653.Pp 654.Dl block in proto icmp probability 20% 655.Pp 656.It Cm prio Ar number 657Only match packets which have the given queueing priority assigned. 658.Pp 659.It Oo Cm \&! Oc Ns Cm received-on Ar interface 660Only match packets which were received on the specified 661.Cm interface 662(or interface group). 663.Cm any 664will match any existing interface except loopback ones. 665.Pp 666.It Cm rtable Ar number 667Used to select an alternate routing table for the routing lookup. 668Only effective before the route lookup happened, i.e. when filtering inbound. 669.Pp 670.It Cm set delay Ar milliseconds 671Packets matching this rule will be delayed at the outbound interface by the 672given number of milliseconds. 673.Pp 674.It Cm set prio Ar priority | Pq Ar priority , priority 675Packets matching this rule will be assigned a specific queueing priority. 676Priorities are assigned as integers 0 through 7, 677with a default priority of 3. 678If the packet is transmitted on a 679.Xr vlan 4 680interface, the queueing priority will also be written as the priority 681code point in the 802.1Q VLAN header. 682If two priorities are given, TCP ACKs with no data payload and packets 683which have a TOS of 684.Cm lowdelay 685will be assigned to the second one. 686Packets with a higher priority number are processed first, 687and packets with the same priority are processed 688in the order in which they are received. 689.Pp 690For example: 691.Bd -literal -offset indent 692pass in proto tcp to port 25 set prio 2 693pass in proto tcp to port 22 set prio (2, 5) 694.Ed 695.Pp 696The interface priority queues accessed by the 697.Cm set prio 698keyword are always enabled and do not require any additional 699configuration, unlike the queues described below and in the 700.Sx QUEUEING 701section. 702.Pp 703.It Cm set queue Ar queue | Pq Ar queue , queue 704Packets matching this rule will be assigned to the specified 705.Ar queue . 706If two queues are given, packets which have a TOS of 707.Cm lowdelay 708and TCP ACKs with no data payload will be assigned to the second one. 709See 710.Sx QUEUEING 711for setup details. 712.Pp 713For example: 714.Bd -literal -offset indent 715pass in proto tcp to port 25 set queue mail 716pass in proto tcp to port 22 set queue(ssh_bulk, ssh_prio) 717.Ed 718.Pp 719.It Cm set tos Ar string | number 720Enforces a TOS for matching packets. 721.Ar string 722may be one of 723.Cm critical , 724.Cm inetcontrol , 725.Cm lowdelay , 726.Cm netcontrol , 727.Cm throughput , 728.Cm reliability , 729or one of the DiffServ Code Points: 730.Cm ef , 731.Cm af11 No ... Cm af43 , 732.Cm cs0 No ... Cm cs7 ; 733.Ar number 734may be either a hex or decimal number. 735.Pp 736.It Cm tag Ar string 737Packets matching this rule will be tagged with the specified 738.Ar string . 739The tag acts as an internal marker that can be used to 740identify these packets later on. 741This can be used, for example, to provide trust between 742interfaces and to determine if packets have been 743processed by translation rules. 744Tags are 745.Dq sticky , 746meaning that the packet will be tagged even if the rule 747is not the last matching rule. 748Further matching rules can replace the tag with a 749new one but will not remove a previously applied tag. 750A packet is only ever assigned one tag at a time. 751Tags take the same macros as labels (see above). 752.Pp 753.It Oo Cm \&! Oc Ns Cm tagged Ar string 754Used with filter or translation rules 755to specify that packets must already 756be tagged with the given 757.Ar string 758in order to match the rule. 759.Pp 760.It Cm tos Ar string | number 761This rule applies to packets with the specified TOS bits set. 762.Ar string 763may be one of 764.Cm critical , 765.Cm inetcontrol , 766.Cm lowdelay , 767.Cm netcontrol , 768.Cm throughput , 769.Cm reliability , 770or one of the DiffServ Code Points: 771.Cm ef , 772.Cm af11 No ... Cm af43 , 773.Cm cs0 No ... Cm cs7 ; 774.Ar number 775may be either a hex or decimal number. 776.Pp 777For example, the following rules are identical: 778.Bd -literal -offset indent 779pass all tos lowdelay 780pass all tos 0x10 781pass all tos 16 782.Ed 783.Pp 784.It Cm user Ar user 785This rule only applies to packets of sockets owned by the specified 786.Ar user . 787For outgoing connections initiated from the firewall, this is the user 788that opened the connection. 789For incoming connections to the firewall itself, this is the user that 790listens on the destination port. 791.Pp 792When listening sockets are bound to the wildcard address, 793.Xr pf 4 794cannot determine if a connection is destined for the firewall itself. 795To avoid false matches on just the destination port, combine a 796.Cm user 797rule with source or destination address 798.Cm self . 799.Pp 800All packets, both outgoing and incoming, of one connection are associated 801with the same user and group. 802Only TCP and UDP packets can be associated with users. 803.Pp 804The 805.Ar user 806and 807.Ar group 808arguments refer to the effective (as opposed to the real) IDs, in 809case the socket is created by a setuid/setgid process. 810User and group IDs are stored when a socket is created; 811when a process creates a listening socket as root (for instance, by 812binding to a privileged port) and subsequently changes to another 813user ID (to drop privileges), the credentials will remain root. 814.Pp 815User and group IDs can be specified as either numbers or names. 816The syntax is similar to the one for ports. 817The following example allows only selected users to open outgoing 818connections: 819.Bd -literal -offset indent 820block out proto tcp all 821pass out proto tcp from self user { < 1000, dhartmei } 822.Ed 823.El 824.Ss Translation 825Translation options modify either the source or destination address and 826port of the packets associated with a stateful connection. 827.Xr pf 4 828modifies the specified address and/or port in the packet and recalculates 829IP, TCP, and UDP checksums as necessary. 830.Pp 831If specified on a 832.Ic match 833rule, subsequent rules will see packets as they look 834after any addresses and ports have been translated. 835These rules will therefore have to filter based on the translated 836address and port number. 837.Pp 838The state entry created permits 839.Xr pf 4 840to keep track of the original address for traffic associated with that state 841and correctly direct return traffic for that connection. 842.Pp 843Different types of translation are possible with pf: 844.Bl -tag -width binat-to 845.It Cm af-to 846Translation between different address families (NAT64) is handled 847using 848.Cm af-to 849rules. 850Because address family translation overrides the routing table, it's 851only possible to use 852.Cm af-to 853on inbound rules, and a source address for the resulting translation 854must always be specified. 855.Pp 856The optional second argument is the host or subnet the original 857addresses are translated into for the destination. 858The lowest bits of the original destination address form the host 859part of the new destination address according to the specified subnet. 860It is possible to embed a complete IPv4 address into an IPv6 address 861using a network prefix of /96 or smaller. 862.Pp 863When a destination address is not specified it is assumed that the host 864part is 32-bit long. 865For IPv6 to IPv4 translation this would mean using only the lower 32 866bits of the original IPv6 destination address. 867For IPv4 to IPv6 translation the destination subnet defaults to the 868subnet of the new IPv6 source address with a prefix length of /96. 869See RFC 6052 Section 2.2 for details on how the prefix determines the 870destination address encoding. 871.Pp 872For example, the following rules are identical: 873.Bd -literal -offset indent 874pass in inet af-to inet6 from 2001:db8::1 to 2001:db8::/96 875pass in inet af-to inet6 from 2001:db8::1 876.Ed 877.Pp 878In the above example the matching IPv4 packets will be modified to 879have a source address of 2001:db8::1 and a destination address will 880get prefixed with 2001:db8::/96, e.g. 198.51.100.100 will be 881translated to 2001:db8::c633:6464. 882.Pp 883In the reverse case the following rules are identical: 884.Bd -literal -offset indent 885pass in inet6 from any to 64:ff9b::/96 af-to inet \e 886 from 198.51.100.1 to 0.0.0.0/0 887pass in inet6 from any to 64:ff9b::/96 af-to inet \e 888 from 198.51.100.1 889.Ed 890.Pp 891The destination IPv4 address is assumed to be embedded inside the 892original IPv6 destination address, e.g. 64:ff9b::c633:6464 will be 893translated to 198.51.100.100. 894.Pp 895The current implementation will only extract IPv4 addresses from the 896IPv6 addresses with a prefix length of /96 and greater. 897.It Cm binat-to 898A 899.Cm binat-to 900rule specifies a bidirectional mapping between an external IP 901netblock and an internal IP netblock. 902It expands to an outbound 903.Cm nat-to 904rule and an inbound 905.Cm rdr-to 906rule. 907.It Cm nat-to 908A 909.Cm nat-to 910option specifies that IP addresses are to be changed as the packet 911traverses the given interface. 912This technique allows one or more IP addresses 913on the translating host to support network traffic for a larger range of 914machines on an 915.Dq inside 916network. 917Although in theory any IP address can be used on the inside, it is strongly 918recommended that one of the address ranges defined by RFC 1918 be used. 919Those netblocks are: 920.Bd -literal -offset indent 92110.0.0.0 \(en 10.255.255.255 (all of net 10, i.e. 10/8) 922172.16.0.0 \(en 172.31.255.255 (i.e. 172.16/12) 923192.168.0.0 \(en 192.168.255.255 (i.e. 192.168/16) 924.Ed 925.Pp 926.Cm nat-to 927is usually applied outbound. 928If applied inbound, nat-to to a local IP address is not supported. 929.It Cm rdr-to 930The packet is redirected to another destination and possibly a 931different port. 932.Cm rdr-to 933can optionally specify port ranges instead of single ports. 934For instance: 935.Bl -tag -width Ds 936.It match in ... port 2000:2999 rdr-to ... port 4000 937redirects ports 2000 to 2999 (inclusive) to port 4000. 938.It match in ... port 2000:2999 rdr-to ... port 4000:* 939redirects port 2000 to 4000, port 2001 to 4001, ..., port 2999 to 4999. 940.El 941.Pp 942.Cm rdr-to 943is usually applied inbound. 944If applied outbound, rdr-to to a local IP address is not supported. 945.El 946.Pp 947In addition to modifying the address, some translation rules may modify 948source or destination ports for TCP or UDP connections; 949implicitly in the case of 950.Cm nat-to 951options and explicitly in the case of 952.Cm rdr-to 953ones. 954Port numbers are never translated with a 955.Cm binat-to 956rule. 957.Pp 958Translation options apply only to packets that pass through the specified 959interface, and if no interface is specified, translation is applied 960to packets on all interfaces. 961For instance, redirecting port 80 on an external interface to an internal 962web server will only work for connections originating from the outside. 963Connections to the address of the external interface from local hosts will 964not be redirected, since such packets do not actually pass through the 965external interface. 966Redirections cannot reflect packets back through the interface they arrive 967on, they can only be redirected to hosts connected to different interfaces 968or to the firewall itself. 969.Pp 970However packets may be redirected to hosts connected to the interface the 971packet arrived on by using redirection with NAT. 972For example: 973.Bd -literal -offset indent 974pass in on $int_if proto tcp from $int_net to $ext_if port 80 \e 975 rdr-to $server 976pass out on $int_if proto tcp to $server port 80 \e 977 received-on $int_if nat-to $int_if 978.Ed 979.Pp 980Note that redirecting external incoming connections to the loopback address 981will effectively allow an external host to connect to daemons 982bound solely to the loopback address, circumventing the traditional 983blocking of such connections on a real interface. 984For example: 985.Bd -literal -offset indent 986pass in on egress proto tcp from any to any port smtp \e 987 rdr-to 127.0.0.1 port spamd 988.Ed 989.Pp 990Unless this effect is desired, any of the local non-loopback addresses 991should be used instead as the redirection target, which allows external 992connections only to daemons bound to this address or not bound to 993any address. 994.Pp 995For 996.Cm af-to , 997.Cm nat-to 998and 999.Cm rdr-to 1000options for which there is a single redirection address which has a 1001subnet mask smaller than 32 for IPv4 or 128 for IPv6 (more than one IP 1002address), a variety of different methods for assigning this address can be 1003used: 1004.Bl -tag -width xxxx 1005.It Cm bitmask 1006The 1007.Cm bitmask 1008option applies the network portion of the redirection address to the address 1009to be modified (source with 1010.Cm nat-to , 1011destination with 1012.Cm rdr-to ) . 1013.It Cm least-states Op Cm sticky-address 1014The 1015.Cm least-states 1016option selects the address with the least active states from 1017a given address pool and considers given weights 1018associated with address(es). 1019Weights can be specified between 1 and 65535. 1020Addresses with higher weights are selected more often. 1021.Pp 1022.Cm sticky-address 1023can be specified to ensure that multiple connections from the 1024same source are mapped to the same redirection address. 1025Associations are destroyed as soon as there are 1026no longer states which refer to them; 1027in order to make the mappings last 1028beyond the lifetime of the states, 1029increase the global options with 1030.Ic set Cm timeout src.track . 1031.It Cm random Op Cm sticky-address 1032The 1033.Cm random 1034option selects an address at random within the defined block of addresses. 1035.Cm sticky-address 1036is as described above. 1037.It Cm round-robin Op Cm sticky-address 1038The 1039.Cm round-robin 1040option loops through the redirection address(es) and considers given weights 1041associated with address(es). 1042Weights can be specified between 1 and 65535. 1043Addresses with higher weights are selected more often. 1044.Cm sticky-address 1045is as described above. 1046.It Cm source-hash Oo Ar key Oc Op Cm sticky-address 1047The 1048.Cm source-hash 1049option uses a hash of the source address to determine the redirection address, 1050ensuring that the redirection address is always the same for a given source. 1051An optional 1052.Ar key 1053can be specified after this keyword either in hex or as a string; 1054by default 1055.Xr pfctl 8 1056randomly generates a key for source-hash every time the 1057ruleset is reloaded. 1058.Cm sticky-address 1059is as described above. 1060.It Cm static-port 1061With 1062.Cm nat-to 1063rules, the 1064.Cm static-port 1065option prevents 1066.Xr pf 4 1067from modifying the source port on TCP and UDP packets. 1068.El 1069.Pp 1070When more than one redirection address or a table is specified, 1071.Cm bitmask 1072is not permitted as a pool type. 1073.Ss Routing 1074If a packet matches a rule with one of the following route options set, 1075the packet filter will route the packet according to the type of route option. 1076When such a rule creates state, the route option is also applied to all 1077packets matching the same connection. 1078.Bl -tag -width route-to 1079.It Cm dup-to 1080The 1081.Cm dup-to 1082option creates a duplicate of the packet and routes it like 1083.Cm route-to . 1084The original packet gets routed as it normally would. 1085.It Cm reply-to 1086The 1087.Cm reply-to 1088option is similar to 1089.Cm route-to , 1090but routes packets that pass in the opposite direction (replies) to the 1091specified interface. 1092Opposite direction is only defined in the context of a state entry, and 1093.Cm reply-to 1094is useful only in rules that create state. 1095It can be used on systems with multiple external connections to 1096route all outgoing packets of a connection through the interface 1097the incoming connection arrived through (symmetric routing enforcement). 1098.It Cm route-to 1099The 1100.Cm route-to 1101option routes the packet to the specified interface with an optional address 1102for the next hop. 1103When a 1104.Cm route-to 1105rule creates state, only packets that pass in the same direction as the 1106filter rule specifies will be routed in this way. 1107Packets passing in the opposite direction (replies) are not affected 1108and are routed normally. 1109.El 1110.Pp 1111For the 1112.Cm dup-to , 1113.Cm reply-to , 1114and 1115.Cm route-to 1116route options 1117for which there is a single redirection address which has a 1118subnet mask smaller than 32 for IPv4 or 128 for IPv6 (more than one IP 1119address), 1120the methods 1121.Cm least-states , 1122.Cm random , 1123.Cm round-robin , 1124and 1125.Cm source-hash , 1126as described above, 1127can be used. 1128.Sh OPTIONS 1129.Xr pf 4 1130may be tuned for various situations using the 1131.Ic set 1132command. 1133.Bl -tag -width Ds 1134.It Ic set Cm block-policy drop | return 1135The 1136.Cm block-policy 1137option sets the default behaviour for the packet 1138.Ic block 1139action: 1140.Pp 1141.Bl -tag -width return -compact 1142.It Cm drop 1143Packet is silently dropped. 1144.It Cm return 1145A TCP RST is returned for blocked TCP packets, 1146an ICMP UNREACHABLE is returned for blocked UDP packets, 1147and all other packets are silently dropped. 1148.El 1149.Pp 1150The default value is 1151.Cm drop . 1152.It Ic set Cm debug Ar level 1153Set the debug 1154.Ar level , 1155which limits the severity of log messages printed by 1156.Xr pf 4 . 1157This should be a keyword from the following ordered list 1158(highest to lowest): 1159.Cm emerg , 1160.Cm alert , 1161.Cm crit , 1162.Cm err , 1163.Cm warning , 1164.Cm notice , 1165.Cm info , 1166and 1167.Cm debug . 1168These keywords correspond to the similar (LOG_) values specified to the 1169.Xr syslog 3 1170library routine. 1171The default value is 1172.Cm err . 1173.It Cm set Cm fingerprints Ar filename 1174Load fingerprints of known operating systems from the given 1175.Ar filename . 1176By default fingerprints of known operating systems are automatically 1177loaded from 1178.Xr pf.os 5 , 1179but can be overridden via this option. 1180Setting this option may leave a small period of time where the fingerprints 1181referenced by the currently active ruleset are inconsistent until the new 1182ruleset finishes loading. 1183The default location for fingerprints is 1184.Pa /etc/pf.os . 1185.It Ic set Cm hostid Ar number 1186The 32-bit hostid 1187.Ar number 1188identifies this firewall's state table entries to other firewalls 1189in a 1190.Xr pfsync 4 1191failover cluster. 1192By default the hostid is set to a pseudo-random value, however it may be 1193desirable to manually configure it, for example to more easily identify the 1194source of state table entries. 1195The hostid may be specified in either decimal or hexadecimal. 1196.It Ic set Cm limit Ar limit-item number 1197Sets hard limits on the memory pools used by the packet filter. 1198See 1199.Xr pool 9 1200for an explanation of memory pools. 1201.Pp 1202For example, 1203to set the maximum number of entries in the memory pool used by state table 1204entries (generated by 1205.Ic pass 1206rules which do not specify 1207.Cm no state ) 1208to 20000: 1209.Pp 1210.Dl set limit states 20000 1211.Pp 1212To set the maximum number of entries in the memory pool used for fragment 1213reassembly to 2000: 1214.Pp 1215.Dl set limit frags 2000 1216.Pp 1217This maximum may not exceed, and should be well below, the maximum number 1218of mbuf clusters 1219.Pq sysctl kern.maxclusters 1220in the system. 1221.Pp 1222To set the maximum number of entries in the memory pool used for tracking 1223source IP addresses (generated by the 1224.Cm sticky-address 1225and 1226.Cm src.track 1227options) to 2000: 1228.Pp 1229.Dl set limit src-nodes 2000 1230.Pp 1231To set limits on the memory pools used by tables: 1232.Bd -literal -offset indent 1233set limit tables 1000 1234set limit table-entries 100000 1235.Ed 1236.Pp 1237The first limits the number of tables that can exist to 1000. 1238The second limits the overall number of addresses that can be stored 1239in tables to 100000. 1240.Pp 1241Various limits can be combined on a single line: 1242.Bd -literal -offset indent 1243set limit { states 20000, frags 2000, src-nodes 2000 } 1244.Ed 1245.Pp 1246.Xr pf 4 1247has the following defaults: 1248.Bl -column table-entries PFR_KENTRY_HIWAT_SMALL platform_dependent 1249.It states Ta Dv PFSTATE_HIWAT Ta Pq 100000 1250.It tables Ta Dv PFR_KTABLE_HIWAT Ta Pq 1000 1251.It table-entries Ta Dv PFR_KENTRY_HIWAT Ta Pq 200000 1252.It table-entries Ta Dv PFR_KENTRY_HIWAT_SMALL Ta Pq 100000 1253.It frags Ta Dv NMBCLUSTERS Ns /32 Ta Pq platform dependent 1254.El 1255.Pp 1256.Dv NMBCLUSTERS 1257defines the total number of packets which can exist in-system at any one time. 1258Refer to 1259.In machine/param.h 1260for the platform-specific value. 1261.It Ic set Cm loginterface Ar interface | Cm none 1262Enable collection of packet and byte count statistics for the given 1263interface or interface group. 1264These statistics can be viewed using: 1265.Pp 1266.Dl # pfctl -s info 1267.Pp 1268In this example 1269.Xr pf 4 1270collects statistics on the interface named dc0: 1271.Pp 1272.Dl set loginterface dc0 1273.Pp 1274One can disable the loginterface using: 1275.Pp 1276.Dl set loginterface none 1277.Pp 1278The default value is 1279.Cm none . 1280.It Ic set Cm optimization Ar environment 1281Optimize state timeouts for one of the following network environments: 1282.Pp 1283.Bl -tag -width Ds -compact 1284.It Cm aggressive 1285Aggressively expire connections. 1286This can greatly reduce the memory usage of the firewall at the cost of 1287dropping idle connections early. 1288.It Cm conservative 1289Extremely conservative settings. 1290Avoid dropping legitimate connections at the 1291expense of greater memory utilization (possibly much greater on a busy 1292network) and slightly increased processor utilization. 1293.It Cm high-latency 1294A high-latency environment (such as a satellite connection). 1295.It Cm normal 1296A normal network environment. 1297Suitable for almost all networks. 1298.It Cm satellite 1299Alias for 1300.Cm high-latency . 1301.El 1302.Pp 1303The default value is 1304.Cm normal . 1305.It Ic set Cm reassemble yes | no Op Cm no-df 1306The 1307.Cm reassemble 1308option is used to enable or disable the reassembly of fragmented packets, 1309and can be set to 1310.Cm yes 1311(the default) or 1312.Cm no . 1313If 1314.Cm no-df 1315is also specified, fragments with the 1316.Dq dont-fragment 1317bit set are reassembled too, 1318instead of being dropped; 1319the reassembled packet will have the 1320.Dq dont-fragment 1321bit cleared. 1322The default value is 1323.Cm yes . 1324.It Ic set Cm ruleset-optimization Ar level 1325.Bl -tag -width profile -compact 1326.It Cm basic 1327Enable basic ruleset optimization. 1328This is the default behaviour. 1329Basic ruleset optimization does four things to improve the 1330performance of ruleset evaluations: 1331.Pp 1332.Bl -enum -compact 1333.It 1334remove duplicate rules 1335.It 1336remove rules that are a subset of another rule 1337.It 1338combine multiple rules into a table when advantageous 1339.It 1340reorder the rules to improve evaluation performance 1341.El 1342.Pp 1343.It Cm none 1344Disable the ruleset optimizer. 1345.It Cm profile 1346Uses the currently loaded ruleset as a feedback profile to tailor the 1347ordering of 1348.Cm quick 1349rules to actual network traffic. 1350.El 1351.Pp 1352It is important to note that the ruleset optimizer will modify the ruleset 1353to improve performance. 1354A side effect of the ruleset modification is that per-rule accounting 1355statistics will have different meanings than before. 1356If per-rule accounting is important for billing purposes or whatnot, 1357either the ruleset optimizer should not be used or a label field should 1358be added to all of the accounting rules to act as optimization barriers. 1359.Pp 1360Optimization can also be set as a command-line argument to 1361.Xr pfctl 8 , 1362overriding the settings in 1363.Nm . 1364.It Ic set Cm skip on Ar ifspec 1365List interfaces for which packets should not be filtered. 1366Packets passing in or out on such interfaces are passed as if pf was 1367disabled, i.e. pf does not process them in any way. 1368This can be useful on loopback and other virtual interfaces, when 1369packet filtering is not desired and can have unexpected effects. 1370.Ar ifspec 1371is only evaluated when the ruleset is loaded; interfaces created 1372later will not be skipped. 1373PF filters traffic on all interfaces by default. 1374.It Ic set Cm state-defaults Ar state-option , ... 1375The 1376.Cm state-defaults 1377option sets the state options for states created from rules 1378without an explicit 1379.Cm keep state . 1380For example: 1381.Pp 1382.Dl set state-defaults pflow, no-sync 1383.It Ic set Cm state-policy if-bound | floating 1384The 1385.Cm state-policy 1386option sets the default behaviour for states: 1387.Pp 1388.Bl -tag -width if-bound -compact 1389.It Cm if-bound 1390States are bound to an interface. 1391.It Cm floating 1392States can match packets on any interfaces (the default). 1393.El 1394.It Ic set Cm syncookies never | always | adaptive 1395When 1396.Cm syncookies 1397are active, pf will answer each and every incoming TCP SYN with a 1398syncookie SYNACK, without allocating any resources. 1399Upon reception of the client's ACK in response to the syncookie 1400SYNACK, pf will evaluate the ruleset and create state if the ruleset 1401permits it, complete the three way handshake with the target host, 1402and continue the connection with synproxy in place. 1403This allows pf to be resilient against large synflood attacks, 1404which could otherwise exhaust the state table. 1405Due to the blind answers to each and every SYN, 1406syncookies share the caveats of synproxy: 1407seemingly accepting connections that will be dropped later on. 1408.Pp 1409.Bl -tag -width adaptive -compact 1410.It Cm never 1411pf will never send syncookie SYNACKs (the default). 1412.It Cm always 1413pf will always send syncookie SYNACKs. 1414.It Cm adaptive 1415pf will enable syncookie mode when a given percentage of the state table 1416is used up by half-open TCP connections, such as those that saw the initial 1417SYN but didn't finish the three way handshake. 1418The thresholds for entering and leaving syncookie mode can be specified using: 1419.Bd -literal -offset indent 1420set syncookies adaptive (start 25%, end 12%) 1421.Ed 1422.El 1423.It Ic set Cm timeout Ar variable value 1424.Bl -tag -width "src.track" -compact 1425.It Cm frag 1426Seconds before an unassembled fragment is expired (60 by default). 1427.It Cm interval 1428Interval between purging expired states and fragments (10 seconds by default). 1429.It Cm src.track 1430Length of time to retain a source tracking entry after the last state 1431expires (0 by default, which means there is no global limit. 1432The value is defined by the rule which creates the state.). 1433.El 1434.Pp 1435When a packet matches a stateful connection, the seconds to live for the 1436connection will be updated to that of the 1437protocol and modifier 1438which corresponds to the connection state. 1439Each packet which matches this state will reset the TTL. 1440Tuning these values may improve the performance of the 1441firewall at the risk of dropping valid idle connections. 1442.Pp 1443.Bl -tag -width Ds -compact 1444.It Cm tcp.closed Pq 90 seconds by default 1445The state after one endpoint sends an RST. 1446.It Cm tcp.closing Pq 900 seconds by default 1447The state after the first FIN has been sent. 1448.It Cm tcp.established Pq 24 hours by default 1449The fully established state. 1450.It Cm tcp.finwait Pq 45 seconds by default 1451The state after both FINs have been exchanged and the connection is closed. 1452Some hosts (notably web servers on Solaris) send TCP packets even after closing 1453the connection. 1454Increasing 1455.Cm tcp.finwait 1456(and possibly 1457.Cm tcp.closing ) 1458can prevent blocking of such packets. 1459.It Cm tcp.first Pq 120 seconds by default 1460The state after the first packet. 1461.It Cm tcp.opening Pq 30 seconds by default 1462The state after the second packet but before both endpoints have 1463acknowledged the connection. 1464.El 1465.Pp 1466ICMP and UDP are handled in a fashion similar to TCP, but with a much more 1467limited set of states: 1468.Pp 1469.Bl -tag -width Ds -compact 1470.It Cm icmp.error Pq 10 seconds by default 1471The state after an ICMP error came back in response to an ICMP packet. 1472.It Cm icmp.first Pq 20 seconds by default 1473The state after the first packet. 1474.It Cm udp.first Pq 60 seconds by default 1475The state after the first packet. 1476.It Cm udp.multiple Pq 60 seconds by default 1477The state if both hosts have sent packets. 1478.It Cm udp.single Pq 30 seconds by default 1479The state if the source host sends more than one packet but the destination 1480host has never sent one back. 1481.El 1482.Pp 1483Other protocols are handled similarly to UDP: 1484.Pp 1485.Bl -tag -width xxxx -compact 1486.It Cm other.first Pq 60 seconds by default 1487.It Cm other.multiple Pq 60 seconds by default 1488.It Cm other.single Pq 30 seconds by default 1489.El 1490.Pp 1491Timeout values can be reduced adaptively as the number of state table 1492entries grows. 1493.Pp 1494.Bl -tag -width Ds -compact 1495.It Cm adaptive.start Pq 60000 states by default 1496When the number of state entries exceeds this value, adaptive scaling 1497begins. 1498All timeout values are scaled linearly with factor 1499(adaptive.end \- number of states) / (adaptive.end \- adaptive.start). 1500.It Cm adaptive.end Pq 120000 states by default 1501When reaching this number of state entries, all timeout values become 1502zero, effectively purging all state entries immediately. 1503This value is used to define the scale factor; it should not actually 1504be reached (set a lower state limit, see below). 1505.El 1506.Pp 1507Adaptive timeouts are enabled by default, with an adaptive.start value 1508equal to 60% of the state limit, and an adaptive.end value equal to 1509120% of the state limit. 1510They can be disabled by setting both adaptive.start and adaptive.end to 0. 1511.Pp 1512The adaptive timeout values can be defined both globally and for each rule. 1513When used on a per-rule basis, the values relate to the number of 1514states created by the rule, otherwise to the total number of 1515states. 1516.Pp 1517For example: 1518.Bd -literal -offset indent 1519set timeout tcp.first 120 1520set timeout tcp.established 86400 1521set timeout { adaptive.start 60000, adaptive.end 120000 } 1522set limit states 100000 1523.Ed 1524.Pp 1525With 9000 state table entries, the timeout values are scaled to 50% 1526(tcp.first 60, tcp.established 43200). 1527.El 1528.Pp 1529.Dq pfctl -F Reset 1530restores default values for following options: debug, all limit options, 1531loginterface, reassemble, skip, syncookies, all timeouts. 1532.Sh QUEUEING 1533Packets can be assigned to queues for the purpose of bandwidth 1534control. 1535At least one declaration is required to configure queues, and later 1536any packet filtering rule can reference the defined queues by name. 1537When filtering, the last referenced 1538.Ar queue 1539name is where any passed packets will be queued, while for 1540blocked packets it specifies where any resulting ICMP or TCP RST 1541packets should be queued. 1542If the referenced queue does not exist on the outgoing interface, 1543the default queue for that interface is used. 1544Queues attached to an interface build a tree, 1545thus each queue can have further child queues. 1546Only leaf queues, i.e. queues without children, can be used to assign 1547packets to. 1548The root queue must specifically reference an interface, all other queues 1549pick up the interfaces they should be created on from their parent queues. 1550.Pp 1551In the following example, a queue named std is created on the interface em0, 1552with 3 child queues ssh, mail and http: 1553.Bd -literal -offset indent 1554queue std on em0 bandwidth 100M 1555queue ssh parent std bandwidth 10M 1556queue mail parent std bandwidth 10M 1557queue http parent std bandwidth 80M default 1558.Ed 1559.Pp 1560The specified bandwidth is the target bandwidth, every queue can receive 1561more bandwidth as long as the parent still has some available. 1562The maximum bandwidth that should be assigned to a given queue can be limited 1563using the 1564.Cm max 1565keyword. 1566If a limitation isn't imposed on the root queue, borrowing can result in 1567saturating the bandwidth of the outgoing interface. 1568Similarly, a minimum (reserved) bandwidth can be specified: 1569.Pp 1570.Dl queue ssh parent std bandwidth 10M min 5M max 25M 1571.Pp 1572For each of these 3 bandwidth specifications an additional burst bandwidth and 1573time can be specified: 1574.Pp 1575.Dl queue ssh parent std bandwidth 10M burst 90M for 100ms 1576.Pp 1577All 1578.Cm bandwidth 1579values are specified as bits per second or using the suffixes 1580.Cm K , 1581.Cm M , 1582and 1583.Cm G 1584to represent kilobits, megabits, and gigabits per second, respectively. 1585The value must not exceed the interface bandwidth. 1586.Pp 1587If multiple connections are assigned the same queue, they're not guaranteed 1588to share the queue bandwidth fairly. 1589An alternative flow queue manager can be used to achieve fair sharing by 1590indicating how many simultaneous states are expected with a 1591.Cm flows 1592option, unless a minimum bandwidth has been specified as well. 1593.Pp 1594When packets are classified by the stateful inspection engine, a flow 1595identifier is assigned to all packets belonging to the state, 1596thus limiting the number of individual flows that can be recognized 1597by the resolution of a flow identifier. 1598The current implementation is able to classify traffic into 32767 distinct 1599flows. 1600However, efficient fair sharing is observed even with a much smaller number 1601of flows. 1602For example on a 10Mbit/s DSL or a cable modem uplink, the following simple 1603configuration can be used: 1604.Bd -literal -offset 4n 1605queue outq on em0 bandwidth 9M max 9M flows 1024 qlimit 1024 \e 1606 default 1607.Ed 1608.Pp 1609It's important to specify the upper bound within 90-95% of the expected 1610bandwidth and raise the default queue limit. 1611.Pp 1612If a 1613.Cm flows 1614option appears without a 1615.Cm bandwidth 1616specification, the flow queue manager is selected as the queueing discipline 1617for the corresponding interface acting as a default queue for all outgoing 1618packets. 1619In such a scenario, a queueing hierarchy is not supported. 1620.Pp 1621In addition to the bandwidth and flow specifications, queues support the 1622following options: 1623.Bl -tag -width xxxx 1624.It Cm default 1625Packets not matched by another queue are assigned to this queue. 1626Exactly one default queue per interface is required. 1627.It Cm on Ar interface 1628Specifies the interface the queue operates on. 1629If not given, it operates on all matching interfaces. 1630.It Cm parent Ar name 1631Defines which parent queue the queue should be attached to. 1632Mandatory for all queues except root queues. 1633The parent queue must exist. 1634.It Cm quantum Ar size 1635Specifies the quantum of service for the flow queue manager. 1636The lower the quantum size the more advantage is given to streams of smaller 1637packets at the expense of bulk transfers. 1638The default value is set to the configured Maximum Transmission Unit (MTU) 1639of the specified interface. 1640.It Cm qlimit Ar limit 1641The maximum number of packets held in the queue. 1642The default is 50. 1643.El 1644.Pp 1645Packets can be assigned to queues based on filter rules by using the 1646.Cm queue 1647keyword. 1648Normally only one 1649.Ar queue 1650is specified; when a second one is specified it will instead be used for 1651packets which have a TOS of 1652.Cm lowdelay 1653and for TCP ACKs with no data payload. 1654.Pp 1655To continue the previous example, the examples below would specify the 1656four referenced 1657queues, plus a few child queues. 1658Interactive 1659.Xr ssh 1 1660sessions get a queue with a minimum bandwidth; 1661.Xr scp 1 1662and 1663.Xr sftp 1 1664bulk transfers go to a separate queue. 1665The queues are then referenced by filtering rules. 1666.Bd -literal -offset 4n 1667queue rootq on em0 bandwidth 100M max 100M 1668queue http parent rootq bandwidth 60M burst 90M for 100ms 1669queue developers parent http bandwidth 45M 1670queue employees parent http bandwidth 15M 1671queue mail parent rootq bandwidth 10M 1672queue ssh parent rootq bandwidth 20M 1673queue ssh_interactive parent ssh bandwidth 10M min 5M 1674queue ssh_bulk parent ssh bandwidth 10M 1675queue std parent rootq bandwidth 20M default 1676 1677block return out on em0 inet all set queue std 1678pass out on em0 inet proto tcp from $developerhosts to any port 80 \e 1679 set queue developers 1680pass out on em0 inet proto tcp from $employeehosts to any port 80 \e 1681 set queue employees 1682pass out on em0 inet proto tcp from any to any port 22 \e 1683 set queue(ssh_bulk, ssh_interactive) 1684pass out on em0 inet proto tcp from any to any port 25 \e 1685 set queue mail 1686.Ed 1687.Sh TABLES 1688Tables are named structures which can hold a collection of addresses and 1689networks. 1690Lookups against tables in 1691.Xr pf 4 1692are relatively fast, making a single rule with tables much more efficient, 1693in terms of 1694processor usage and memory consumption, than a large number of rules which 1695differ only in IP address (either created explicitly or automatically by rule 1696expansion). 1697.Pp 1698Tables can be used as the source or destination of filter 1699or translation rules. 1700They can also be used for the redirect address of 1701.Cm nat-to 1702and 1703.Cm rdr-to 1704and in the routing options of filter rules, but not for 1705.Cm bitmask 1706pools. 1707.Pp 1708Tables can be defined with any of the following 1709.Xr pfctl 8 1710mechanisms. 1711As with macros, reserved words may not be used as table names. 1712.Bl -tag -width "manually" 1713.It manually 1714Persistent tables can be manually created with the 1715.Cm add 1716or 1717.Cm replace 1718option of 1719.Xr pfctl 8 , 1720before or after the ruleset has been loaded. 1721.It Nm 1722Table definitions can be placed directly in this file and loaded at the 1723same time as other rules are loaded, atomically. 1724Table definitions inside 1725.Nm 1726use the 1727.Ic table 1728statement, and are especially useful to define non-persistent tables. 1729The contents of a pre-existing table defined without a list of addresses 1730to initialize it is not altered when 1731.Nm 1732is loaded. 1733A table initialized with the empty list, 1734.Li { } , 1735will be cleared on load. 1736.El 1737.Pp 1738Tables may be defined with the following attributes: 1739.Bl -tag -width counters 1740.It Cm const 1741The 1742.Cm const 1743flag prevents the user from altering the contents of the table once it 1744has been created. 1745Without that flag, 1746.Xr pfctl 8 1747can be used to add or remove addresses from the table at any time, even 1748when running with 1749.Xr securelevel 7 1750= 2. 1751.It Cm counters 1752The 1753.Cm counters 1754flag enables per-address packet and byte counters, which can be displayed with 1755.Xr pfctl 8 . 1756.It Cm persist 1757The 1758.Cm persist 1759flag forces the kernel to keep the table even when no rules refer to it. 1760If the flag is not set, the kernel will automatically remove the table 1761when the last rule referring to it is flushed. 1762.El 1763.Pp 1764This example creates a table called 1765.Dq private , 1766to hold RFC 1918 private network blocks, 1767and a table called 1768.Dq badhosts , 1769which is initially empty. 1770A filter rule is set up to block all traffic coming from addresses listed in 1771either table: 1772.Bd -literal -offset indent 1773table <private> const { 10/8, 172.16/12, 192.168/16 } 1774table <badhosts> persist 1775block on fxp0 from { <private>, <badhosts> } to any 1776.Ed 1777.Pp 1778The private table cannot have its contents changed and the badhosts table 1779will exist even when no active filter rules reference it. 1780Addresses may later be added to the badhosts table, so that traffic from 1781these hosts can be blocked by using the following: 1782.Pp 1783.Dl # pfctl -t badhosts -Tadd 204.92.77.111 1784.Pp 1785A table can also be initialized with an address list specified in one or more 1786external files, using the following syntax: 1787.Bd -literal -offset indent 1788table <spam> persist file "/etc/spammers" file "/etc/openrelays" 1789block on fxp0 from <spam> to any 1790.Ed 1791.Pp 1792The files 1793.Pa /etc/spammers 1794and 1795.Pa /etc/openrelays 1796list IP addresses, one per line. 1797Any lines beginning with a 1798.Sq # 1799are treated as comments and ignored. 1800In addition to being specified by IP address, hosts may also be 1801specified by their hostname. 1802When the resolver is called to add a hostname to a table, 1803.Em all 1804resulting IPv4 and IPv6 addresses are placed into the table. 1805IP addresses can also be entered in a table by specifying a valid interface 1806name, a valid interface group, or the 1807.Cm self 1808keyword, in which case all addresses assigned to the interface(s) will be 1809added to the table. 1810.Sh ANCHORS 1811Besides the main ruleset, 1812.Nm 1813can specify anchor attachment points. 1814An anchor is a container that can hold rules, 1815address tables, and other anchors. 1816When evaluation of the main ruleset reaches an 1817.Ic anchor 1818rule, 1819.Xr pf 4 1820will proceed to evaluate all rules specified in that anchor. 1821.Pp 1822The following example blocks all packets on the external interface by default, 1823then evaluates all rules in the anchor named "spam", 1824and finally passes all outgoing connections and 1825incoming connections to port 25: 1826.Bd -literal -offset indent 1827ext_if = "kue0" 1828block on $ext_if all 1829anchor spam 1830pass out on $ext_if all 1831pass in on $ext_if proto tcp from any to $ext_if port smtp 1832.Ed 1833.Pp 1834Anchors can be manipulated through 1835.Xr pfctl 8 1836without reloading the main ruleset or other anchors. 1837This loads a single rule into the anchor, 1838which blocks all packets from a specific address: 1839.Bd -literal -offset indent 1840# echo "block in quick from 1.2.3.4 to any" | pfctl -a spam -f - 1841.Ed 1842.Pp 1843The anchor can also be populated by adding a 1844.Ic load anchor 1845rule after the anchor rule. 1846When 1847.Xr pfctl 8 1848loads 1849.Nm , 1850it will also load all the rules from the file 1851.Pa /etc/pf-spam.conf 1852into the anchor. 1853.Bd -literal -offset indent 1854anchor spam 1855load anchor spam from "/etc/pf-spam.conf" 1856.Ed 1857.Pp 1858An anchor rule can also contain a filter ruleset 1859in a brace-delimited block. 1860In that case, no separate loading of rules into the anchor 1861is required. 1862Brace delimited blocks may contain rules or other brace-delimited blocks. 1863When an anchor is populated this way the anchor name becomes optional. 1864Since the parser specification for anchor names is a string, 1865double quote characters 1866.Pq Sq \&" 1867should be placed around the anchor name. 1868.Bd -literal -offset indent 1869anchor "external" on egress { 1870 block 1871 anchor out { 1872 pass proto tcp from any to port { 25, 80, 443 } 1873 } 1874 pass in proto tcp to any port 22 1875} 1876.Ed 1877.Pp 1878Anchor rules can also specify packet filtering parameters 1879using the same syntax as filter rules. 1880When parameters are used, 1881the anchor rule is only evaluated for matching packets. 1882This allows conditional evaluation of anchors, like: 1883.Bd -literal -offset indent 1884block on $ext_if all 1885anchor spam proto tcp from any to any port smtp 1886pass out on $ext_if all 1887pass in on $ext_if proto tcp from any to $ext_if port smtp 1888.Ed 1889.Pp 1890The rules inside anchor "spam" are only evaluated 1891for TCP packets with destination port 25. 1892Hence, the following 1893will only block connections from 1.2.3.4 to port 25: 1894.Bd -literal -offset indent 1895# echo "block in quick from 1.2.3.4 to any" | pfctl -a spam -f - 1896.Ed 1897.Pp 1898Matching filter and translation rules marked with the 1899.Cm quick 1900option are final and abort the evaluation of the rules in other 1901anchors and the main ruleset. 1902If the anchor itself is marked with the 1903.Cm quick 1904option, 1905ruleset evaluation will terminate when the anchor is exited if the packet is 1906matched by any rule within the anchor. 1907.Pp 1908An anchor references other anchor attachment points 1909using the following syntax: 1910.Bl -tag -width xxxx 1911.It Ic anchor Ar name 1912Evaluates the filter rules in the specified anchor. 1913.El 1914.Pp 1915An anchor has a name which specifies the path where 1916.Xr pfctl 8 1917can be used to access the anchor to perform operations on it, such as 1918attaching child anchors to it or loading rules into it. 1919Anchors may be nested, with components separated by 1920.Sq / 1921characters, similar to how file system hierarchies are laid out. 1922The main ruleset is actually the default anchor, so filter and 1923translation rules, for example, may also be contained in any anchor. 1924.Pp 1925Anchor rules are evaluated relative to the anchor in which they are contained. 1926For example, 1927all anchor rules specified in the main ruleset will reference 1928anchor attachment points underneath the main ruleset, 1929and anchor rules specified in a file loaded from a 1930.Ic load anchor 1931rule will be attached under that anchor point. 1932.Pp 1933Anchors may end with the asterisk 1934.Pq Sq * 1935character, which signifies that all anchors attached at that point 1936should be evaluated in the alphabetical ordering of their anchor name. 1937For example, 1938the following 1939will evaluate each rule in each anchor attached to the "spam" anchor: 1940.Bd -literal -offset indent 1941anchor "spam/*" 1942.Ed 1943.Pp 1944Note that it will only evaluate anchors that are directly attached to the 1945"spam" anchor, and will not descend to evaluate anchors recursively. 1946.Pp 1947Since anchors are evaluated relative to the anchor in which they are 1948contained, there is a mechanism for accessing the parent and ancestor 1949anchors of a given anchor. 1950Similar to file system path name resolution, if the sequence 1951.Sq .. 1952appears as an anchor path component, the parent anchor of the current 1953anchor in the path evaluation at that point will become the new current 1954anchor. 1955As an example, consider the following: 1956.Bd -literal -offset indent 1957# printf 'anchor "spam/allowed"\en' | pfctl -f - 1958# printf 'anchor "../banned"\enpass\en' | pfctl -a spam/allowed -f - 1959.Ed 1960.Pp 1961Evaluation of the main ruleset will lead into the 1962spam/allowed anchor, which will evaluate the rules in the 1963spam/banned anchor, if any, before finally evaluating the 1964.Ic pass 1965rule. 1966.Sh STATEFUL FILTERING 1967.Xr pf 4 1968filters packets statefully, 1969which has several advantages. 1970For TCP connections, comparing a packet to a state involves checking 1971its sequence numbers, as well as TCP timestamps if a rule using the 1972.Cm reassemble tcp 1973parameter applies to the connection. 1974If these values are outside the narrow windows of expected 1975values, the packet is dropped. 1976This prevents spoofing attacks, such as when an attacker sends packets with 1977a fake source address/port but does not know the connection's sequence 1978numbers. 1979Similarly, 1980.Xr pf 4 1981knows how to match ICMP replies to states. 1982For example, 1983to allow echo requests (such as those created by 1984.Xr ping 8 ) 1985out statefully and match incoming echo replies correctly to states: 1986.Pp 1987.Dl pass out inet proto icmp all icmp-type echoreq 1988.Pp 1989Also, looking up states is usually faster than evaluating rules. 1990If there are 50 rules, all of them are evaluated sequentially in O(n). 1991Even with 50000 states, only 16 comparisons are needed to match a 1992state, since states are stored in a binary search tree that allows 1993searches in O(log2\~n). 1994.Pp 1995Furthermore, correct handling of ICMP error messages is critical to 1996many protocols, particularly TCP. 1997.Xr pf 4 1998matches ICMP error messages to the correct connection, checks them against 1999connection parameters, and passes them if appropriate. 2000For example if an ICMP source quench message referring to a stateful TCP 2001connection arrives, it will be matched to the state and get passed. 2002.Pp 2003Finally, state tracking is required for 2004.Cm nat-to 2005and 2006.Cm rdr-to 2007options, in order to track address and port translations and reverse the 2008translation on returning packets. 2009.Pp 2010.Xr pf 4 2011will also create state for other protocols which are effectively stateless by 2012nature. 2013UDP packets are matched to states using only host addresses and ports, 2014and other protocols are matched to states using only the host addresses. 2015.Pp 2016If stateless filtering of individual packets is desired, 2017the 2018.Cm no state 2019keyword can be used to specify that state will not be created 2020if this is the last matching rule. 2021Note that packets which match neither block nor pass rules, 2022and thus are passed by default, 2023are effectively passed as if 2024.Cm no state 2025had been specified. 2026.Pp 2027A number of parameters can also be set to affect how 2028.Xr pf 4 2029handles state tracking, 2030as detailed below. 2031.Ss State Modulation 2032Much of the security derived from TCP is attributable to how well the 2033initial sequence numbers (ISNs) are chosen. 2034Some popular stack implementations choose 2035.Em very 2036poor ISNs and thus are normally susceptible to ISN prediction exploits. 2037By applying a 2038.Cm modulate state 2039rule to a TCP connection, 2040.Xr pf 4 2041will create a high quality random sequence number for each connection 2042endpoint. 2043.Pp 2044The 2045.Cm modulate state 2046directive implicitly keeps state on the rule and is 2047only applicable to TCP connections. 2048.Pp 2049For instance: 2050.Bd -literal -offset indent 2051block all 2052pass out proto tcp from any to any modulate state 2053pass in proto tcp from any to any port 25 flags S/SFRA \e 2054 modulate state 2055.Ed 2056.Pp 2057Note that modulated connections will not recover when the state table 2058is lost (firewall reboot, flushing the state table, etc.). 2059.Xr pf 4 2060will not be able to infer a connection again after the state table flushes 2061the connection's modulator. 2062When the state is lost, the connection may be left dangling until the 2063respective endpoints time out the connection. 2064It is possible on a fast local network for the endpoints to start an ACK 2065storm while trying to resynchronize after the loss of the modulator. 2066The default 2067.Cm flags 2068settings (or a more strict equivalent) should be used on 2069.Cm modulate state 2070rules to prevent ACK storms. 2071.Pp 2072Note that alternative methods are available 2073to prevent loss of the state table 2074and allow for firewall failover. 2075See 2076.Xr carp 4 2077and 2078.Xr pfsync 4 2079for further information. 2080.Ss SYN Proxy 2081By default, 2082.Xr pf 4 2083passes packets that are part of a 2084TCP handshake between the endpoints. 2085The 2086.Cm synproxy state 2087option can be used to cause 2088.Xr pf 4 2089itself to complete the handshake with the active endpoint, perform a handshake 2090with the passive endpoint, and then forward packets between the endpoints. 2091.Pp 2092No packets are sent to the passive endpoint before the active endpoint has 2093completed the handshake, hence so-called SYN floods with spoofed source 2094addresses will not reach the passive endpoint, as the sender can't complete the 2095handshake. 2096.Pp 2097The proxy is transparent to both endpoints; they each see a single 2098connection from/to the other endpoint. 2099.Xr pf 4 2100chooses random initial sequence numbers for both handshakes. 2101Once the handshakes are completed, the sequence number modulators 2102(see previous section) are used to translate further packets of the 2103connection. 2104.Cm synproxy state 2105includes 2106.Cm modulate state . 2107.Pp 2108Rules with 2109.Cm synproxy state 2110will not work if 2111.Xr pf 4 2112operates on a 2113.Xr bridge 4 . 2114.Pp 2115Example: 2116.Bd -literal -offset indent 2117pass in proto tcp from any to any port www synproxy state 2118.Ed 2119.Ss Stateful Tracking Options 2120A number of options related to stateful tracking can be applied on a 2121per-rule basis. 2122One of 2123.Cm keep state , 2124.Cm modulate state , 2125or 2126.Cm synproxy state 2127must be specified explicitly to apply these options to a rule. 2128.Pp 2129.Bl -tag -width xxxx -compact 2130.It Cm floating 2131States can match packets on any interfaces 2132(the opposite of 2133.Cm if-bound ) . 2134This is the default. 2135.It Cm if-bound 2136States are bound to an interface 2137(the opposite of 2138.Cm floating ) . 2139.It Cm max Ar number 2140Limits the number of concurrent states the rule may create. 2141When this limit is reached, further packets that would create 2142state are dropped until existing states time out. 2143.It Cm no-sync 2144Prevent state changes for states created by this rule from appearing on the 2145.Xr pfsync 4 2146interface. 2147.It Cm pflow 2148States created by this rule are exported on the 2149.Xr pflow 4 2150interface. 2151.It Cm sloppy 2152Uses a sloppy TCP connection tracker that does not check sequence 2153numbers at all, which makes insertion and ICMP teardown attacks way 2154easier. 2155This is intended to be used in situations where one does not see all 2156packets of a connection, e.g. in asymmetric routing situations. 2157It cannot be used with 2158.Cm modulate state 2159or 2160.Cm synproxy state . 2161.It Ar timeout seconds 2162Changes the 2163.Ar timeout 2164values used for states created by this rule. 2165For a list of all valid 2166.Ar timeout 2167names, see 2168.Sx OPTIONS 2169above. 2170.El 2171.Pp 2172Multiple options can be specified, separated by commas: 2173.Bd -literal -offset indent 2174pass in proto tcp from any to any \e 2175 port www keep state \e 2176 (max 100, source-track rule, max-src-nodes 75, \e 2177 max-src-states 3, tcp.established 60, tcp.closing 5) 2178.Ed 2179.Pp 2180When the 2181.Cm source-track 2182keyword is specified, the number of states per source IP is tracked. 2183.Pp 2184.Bl -tag -width xxxx -compact 2185.It Cm source-track global 2186The number of states created by all rules that use this option is limited. 2187Each rule can specify different 2188.Cm max-src-nodes 2189and 2190.Cm max-src-states 2191options, however state entries created by any participating rule count towards 2192each individual rule's limits. 2193.It Cm source-track rule 2194The maximum number of states created by this rule is limited by the rule's 2195.Cm max-src-nodes 2196and 2197.Cm max-src-states 2198options. 2199Only state entries created by this particular rule count toward the rule's 2200limits. 2201.El 2202.Pp 2203The following limits can be set: 2204.Pp 2205.Bl -tag -width xxxx -compact 2206.It Cm max-src-nodes Ar number 2207Limits the maximum number of source addresses which can simultaneously 2208have state table entries. 2209.It Cm max-src-states Ar number 2210Limits the maximum number of simultaneous state entries that a single 2211source address can create with this rule. 2212.El 2213.Pp 2214For stateful TCP connections, limits on established connections (connections 2215which have completed the TCP 3-way handshake) can also be enforced 2216per source IP. 2217.Pp 2218.Bl -tag -width xxxx -compact 2219.It Cm max-src-conn Ar number 2220Limits the maximum number of simultaneous TCP connections which have 2221completed the 3-way handshake that a single host can make. 2222.It Cm max-src-conn-rate Ar number Ns / Ns Ar seconds 2223Limit the rate of new connections over a time interval. 2224The connection rate is an approximation calculated as a moving average. 2225.El 2226.Pp 2227When one of these limits is reached, further packets that would create 2228state are dropped until existing states time out. 2229.Pp 2230Because the 3-way handshake ensures that the source address is not being 2231spoofed, more aggressive action can be taken based on these limits. 2232With the 2233.Cm overload Pf < Ar table Ns > 2234state option, source IP addresses which hit either of the limits on 2235established connections will be added to the named 2236.Ar table . 2237This table can be used in the ruleset to block further activity from 2238the offending host, redirect it to a tarpit process, or restrict its 2239bandwidth. 2240.Pp 2241The optional 2242.Cm flush 2243keyword kills all states created by the matching rule which originate 2244from the host which exceeds these limits. 2245The 2246.Cm global 2247modifier to the 2248.Cm flush 2249command kills all states originating from the 2250offending host, regardless of which rule created the state. 2251.Pp 2252For example, the following rules will protect the webserver against 2253hosts making more than 100 connections in 10 seconds. 2254Any host which connects faster than this rate will have its address added 2255to the <bad_hosts> table and have all states originating from it flushed. 2256Any new packets arriving from this host will be dropped unconditionally 2257by the block rule. 2258.Bd -literal -offset indent 2259block quick from <bad_hosts> 2260pass in on $ext_if proto tcp to $webserver port www keep state \e 2261 (max-src-conn-rate 100/10, overload <bad_hosts> flush global) 2262.Ed 2263.Sh TRAFFIC NORMALISATION 2264Traffic normalisation is a broad umbrella term 2265for aspects of the packet filter which deal with 2266verifying packets, packet fragments, spoof traffic, 2267and other irregularities. 2268.Ss Scrub 2269Scrub involves sanitising packet content in such a way 2270that there are no ambiguities in packet interpretation on the receiving side. 2271It is invoked with the 2272.Cm scrub 2273option, added to regular rules. 2274.Pp 2275Parameters are specified enclosed in parentheses. 2276At least one of the following parameters must be specified: 2277.Bl -tag -width xxxx 2278.It Cm max-mss Ar number 2279Enforces a maximum segment size (MSS) for matching TCP packets. 2280.It Cm min-ttl Ar number 2281Enforces a minimum TTL for matching IP packets. 2282.It Cm no-df 2283Clears the 2284.Dq dont-fragment 2285bit from a matching IPv4 packet. 2286Some operating systems have NFS implementations 2287which are known to generate fragmented packets with the 2288.Dq dont-fragment 2289bit set. 2290.Xr pf 4 2291will drop such fragmented 2292.Dq dont-fragment 2293packets unless 2294.Cm no-df 2295is specified. 2296.Pp 2297Unfortunately some operating systems also generate their 2298.Dq dont-fragment 2299packets with a zero IP identification field. 2300Clearing the 2301.Dq dont-fragment 2302bit on packets with a zero IP ID may cause deleterious results if an 2303upstream router later fragments the packet. 2304Using 2305.Cm random-id 2306is recommended in combination with 2307.Cm no-df 2308to ensure unique IP identifiers. 2309.It Cm random-id 2310Replaces the IPv4 identification field with random values to compensate 2311for predictable values generated by many hosts. 2312This option only applies to packets that are not fragmented 2313after the optional fragment reassembly. 2314.It Cm reassemble tcp 2315Statefully normalises TCP connections. 2316.Cm reassemble tcp 2317performs the following normalisations: 2318.Bl -ohang 2319.It TTL 2320Neither side of the connection is allowed to reduce their IP TTL. 2321An attacker may send a packet such that it reaches the firewall, affects 2322the firewall state, and expires before reaching the destination host. 2323.Cm reassemble tcp 2324will raise the TTL of all packets back up to the highest value seen on 2325the connection. 2326.It Timestamp Modulation 2327Modern TCP stacks will send a timestamp on every TCP packet and echo 2328the other endpoint's timestamp back to them. 2329Many operating systems will merely start the timestamp at zero when 2330first booted, and increment it several times a second. 2331The uptime of the host can be deduced by reading the timestamp and multiplying 2332by a constant. 2333Also observing several different timestamps can be used to count hosts 2334behind a NAT device. 2335And spoofing TCP packets into a connection requires knowing or guessing 2336valid timestamps. 2337Timestamps merely need to be monotonically increasing and not derived off a 2338guessable base time. 2339.Cm reassemble tcp 2340will cause 2341.Cm scrub 2342to modulate the TCP timestamps with a random number. 2343.It Extended PAWS Checks 2344There is a problem with TCP on long fat pipes, in that a packet might get 2345delayed for longer than it takes the connection to wrap its 32-bit sequence 2346space. 2347In such an occurrence, the old packet would be indistinguishable from a 2348new packet and would be accepted as such. 2349The solution to this is called PAWS: Protection Against Wrapped Sequence 2350numbers. 2351It protects against it by making sure the timestamp on each packet does 2352not go backwards. 2353.Cm reassemble tcp 2354also makes sure the timestamp on the packet does not go forward more 2355than the RFC allows. 2356By doing this, 2357.Xr pf 4 2358artificially extends the security of TCP sequence numbers by 10 to 18 2359bits when the host uses appropriately randomized timestamps, since a 2360blind attacker would have to guess the timestamp as well. 2361.El 2362.El 2363.Pp 2364For example: 2365.Pp 2366.Dl match in all scrub (no-df random-id max-mss 1440) 2367.Ss Fragment Handling 2368The size of IP datagrams (packets) can be significantly larger than the 2369maximum transmission unit (MTU) of the network. 2370In cases when it is necessary or more efficient to send such large packets, 2371the large packet will be fragmented into many smaller packets that will each 2372fit onto the wire. 2373Unfortunately for a firewalling device, only the first logical fragment will 2374contain the necessary header information for the subprotocol that allows 2375.Xr pf 4 2376to filter on things such as TCP ports or to perform NAT. 2377.Pp 2378One alternative is to filter individual fragments with filter rules. 2379If packet reassembly is turned off, it is passed to the filter. 2380Filter rules with matching IP header parameters decide whether the 2381fragment is passed or blocked, in the same way as complete packets 2382are filtered. 2383Without reassembly, fragments can only be filtered based on IP header 2384fields (source/destination address, protocol), since subprotocol header 2385fields are not available (TCP/UDP port numbers, ICMP code/type). 2386The 2387.Cm fragment 2388option can be used to restrict filter rules to apply only to 2389fragments, but not complete packets. 2390Filter rules without the 2391.Cm fragment 2392option still apply to fragments, if they only specify IP header fields. 2393For instance: 2394.Bd -literal -offset indent 2395pass in proto tcp from any to any port 80 2396.Ed 2397.Pp 2398The rule above never applies to a fragment, 2399even if the fragment is part of a TCP packet with destination port 80, 2400because without reassembly this information 2401is not available for each fragment. 2402This also means that fragments cannot create new or match existing 2403state table entries, which makes stateful filtering and address 2404translation (NAT, redirection) for fragments impossible. 2405.Pp 2406In most cases, the benefits of reassembly outweigh the additional 2407memory cost, 2408so reassembly is on by default. 2409.Pp 2410The memory allocated for fragment caching can be limited using 2411.Xr pfctl 8 . 2412Once this limit is reached, fragments that would have to be cached 2413are dropped until other entries time out. 2414The timeout value can also be adjusted. 2415.Pp 2416When forwarding reassembled IPv6 packets, pf refragments them with 2417the original maximum fragment size. 2418This allows the sender to determine the optimal fragment size by 2419path MTU discovery. 2420.Ss Blocking Spoofed Traffic 2421Spoofing is the faking of IP addresses, 2422typically for malicious purposes. 2423The 2424.Ic antispoof 2425directive expands to a set of filter rules which will block all 2426traffic with a source IP from the network(s) directly connected 2427to the specified interface(s) from entering the system through 2428any other interface. 2429.Pp 2430For example: 2431.Dl antispoof for lo0 2432.Pp 2433Expands to: 2434.Bd -literal -offset indent -compact 2435block drop in on ! lo0 inet from 127.0.0.1/8 to any 2436block drop in on ! lo0 inet6 from ::1 to any 2437.Ed 2438.Pp 2439For non-loopback interfaces, there are additional rules to block incoming 2440packets with a source IP address identical to the interface's IP(s). 2441For example, assuming the interface wi0 had an IP address of 10.0.0.1 and a 2442netmask of 255.255.255.0: 2443.Pp 2444.Dl antispoof for wi0 inet 2445.Pp 2446Expands to: 2447.Bd -literal -offset indent -compact 2448block drop in on ! wi0 inet from 10.0.0.0/24 to any 2449block drop in inet from 10.0.0.1 to any 2450.Ed 2451.Pp 2452Caveat: Rules created by the 2453.Ic antispoof 2454directive interfere with packets sent over loopback interfaces 2455to local addresses. 2456One should pass these explicitly. 2457.Sh OPERATING SYSTEM FINGERPRINTING 2458Passive OS fingerprinting is a mechanism to inspect nuances of a TCP 2459connection's initial SYN packet and guess at the host's operating system. 2460Unfortunately these nuances are easily spoofed by an attacker so the 2461fingerprint is not useful in making security decisions. 2462But the fingerprint is typically accurate enough to make policy decisions 2463upon. 2464.Pp 2465The fingerprints may be specified by operating system class, by 2466version, or by subtype/patchlevel. 2467The class of an operating system is typically the vendor or genre 2468and would be 2469.Ox 2470for the 2471.Xr pf 4 2472firewall itself. 2473The version of the oldest available 2474.Ox 2475release on the main FTP site 2476would be 2.6 and the fingerprint would be written as: 2477.Pp 2478.Dl \&"OpenBSD 2.6\&" 2479.Pp 2480The subtype of an operating system is typically used to describe the 2481patchlevel if that patch led to changes in the TCP stack behavior. 2482In the case of 2483.Ox , 2484the only subtype is for a fingerprint that was 2485normalised by the 2486.Cm no-df 2487scrub option and would be specified as: 2488.Pp 2489.Dl \&"OpenBSD 3.3 no-df\&" 2490.Pp 2491Fingerprints for most popular operating systems are provided by 2492.Xr pf.os 5 . 2493Once 2494.Xr pf 4 2495is running, a complete list of known operating system fingerprints may 2496be listed by running: 2497.Pp 2498.Dl # pfctl -so 2499.Pp 2500Filter rules can enforce policy at any level of operating system specification 2501assuming a fingerprint is present. 2502Policy could limit traffic to approved operating systems or even ban traffic 2503from hosts that aren't at the latest service pack. 2504.Pp 2505The 2506.Cm unknown 2507class can also be used as the fingerprint which will match packets for 2508which no operating system fingerprint is known. 2509.Pp 2510Examples: 2511.Bd -literal -offset indent 2512pass out proto tcp from any os OpenBSD 2513block out proto tcp from any os Doors 2514block out proto tcp from any os "Doors PT" 2515block out proto tcp from any os "Doors PT SP3" 2516block out from any os "unknown" 2517pass on lo0 proto tcp from any os "OpenBSD 3.3 lo0" 2518.Ed 2519.Pp 2520Operating system fingerprinting is limited only to the TCP SYN packet. 2521This means that it will not work on other protocols and will not match 2522a currently established connection. 2523.Pp 2524Caveat: operating system fingerprints are occasionally wrong. 2525There are three problems: an attacker can trivially craft his packets to 2526appear as any operating system he chooses; 2527an operating system patch could change the stack behavior and no fingerprints 2528will match it until the database is updated; 2529and multiple operating systems may have the same fingerprint. 2530.Sh EXAMPLES 2531In this example, 2532the external interface is 2533.Pa kue0 . 2534We use a macro for the interface name, so it can be changed easily. 2535All incoming traffic is "normalised", 2536and everything is blocked and logged by default. 2537.Bd -literal -offset 4n 2538ext_if = "kue0" 2539match in all scrub (no-df max-mss 1440) 2540block return log on $ext_if all 2541.Ed 2542.Pp 2543Here we specifically block packets we don't want: 2544anything coming from source we have no back routes for; 2545packets whose ingress interface does not match the one in 2546the route back to their source address; 2547anything that does not have our address (157.161.48.183) as source; 2548broadcasts (cable modem noise); 2549and anything from reserved address space or invalid addresses. 2550.Bd -literal -offset 4n 2551block in from no-route to any 2552block in from urpf-failed to any 2553block out log quick on $ext_if from ! 157.161.48.183 to any 2554block in quick on $ext_if from any to 255.255.255.255 2555block in log quick on $ext_if from { 10.0.0.0/8, 172.16.0.0/12, \e 2556 192.168.0.0/16, 255.255.255.255/32 } to any 2557.Ed 2558.Pp 2559For ICMP, 2560pass out/in ping queries. 2561State matching is done on host addresses and ICMP ID (not type/code), 2562so replies (like 0/0 for 8/0) will match queries. 2563ICMP error messages (which always refer to a TCP/UDP packet) 2564are handled by the TCP/UDP states. 2565.Bd -literal -offset 4n 2566pass on $ext_if inet proto icmp all icmp-type 8 code 0 2567.Ed 2568.Pp 2569For UDP, 2570pass out all UDP connections. 2571DNS connections are passed in. 2572.Bd -literal -offset 4n 2573pass out on $ext_if proto udp all 2574pass in on $ext_if proto udp from any to any port domain 2575.Ed 2576.Pp 2577For TCP, 2578pass out all TCP connections and modulate state. 2579SSH, SMTP, DNS, and IDENT connections are passed in. 2580We do not allow Windows 9x SMTP connections since they are typically 2581a viral worm. 2582.Bd -literal -offset 4n 2583pass out on $ext_if proto tcp all modulate state 2584pass in on $ext_if proto tcp from any to any \e 2585 port { ssh, smtp, domain, auth } 2586block in on $ext_if proto tcp from any \e 2587 os { "Windows 95", "Windows 98" } to any port smtp 2588.Ed 2589.Pp 2590Here we pass in/out all IPv6 traffic: 2591note that we have to enable this in two different ways, 2592on both our physical interface and our tunnel. 2593.Bd -literal -offset 4n 2594pass quick on gif0 inet6 2595pass quick on $ext_if proto ipv6 2596.Ed 2597.Pp 2598This example illustrates packet tagging. 2599There are three interfaces: $int_if, $ext_if, and $wifi_if (wireless). 2600NAT is being done on $ext_if for all outgoing packets. 2601Packets in on $int_if are tagged and passed out on $ext_if. 2602All other outgoing packets 2603(i.e. packets from the wireless network) 2604are only permitted to access port 80. 2605.Bd -literal -offset 4n 2606pass in on $int_if from any to any tag INTNET 2607pass in on $wifi_if from any to any 2608 2609block out on $ext_if from any to any 2610pass out quick on $ext_if tagged INTNET 2611pass out on $ext_if proto tcp from any to any port 80 2612.Ed 2613.Pp 2614In this example, 2615we tag incoming packets as they are redirected to 2616.Xr spamd 8 . 2617The tag is used to pass those packets through the packet filter. 2618.Bd -literal -offset 4n 2619match in on $ext_if inet proto tcp from <spammers> to port smtp \e 2620 tag SPAMD rdr-to 127.0.0.1 port spamd 2621 2622block in on $ext_if 2623pass in on $ext_if inet proto tcp tagged SPAMD 2624.Ed 2625.Pp 2626This example maps incoming requests on port 80 to port 8080, on 2627which a daemon is running (because, for example, it is not run as root, 2628and therefore lacks permission to bind to port 80). 2629.Bd -literal -offset 4n 2630match in on $ext_if proto tcp from any to any port 80 \e 2631 rdr-to 127.0.0.1 port 8080 2632.Ed 2633.Pp 2634If a 2635.Ic pass 2636rule is used with the 2637.Cm quick 2638modifier, packets matching the translation rule are passed without 2639inspecting subsequent filter rules. 2640.Bd -literal -offset 4n 2641pass in quick on $ext_if proto tcp from any to any port 80 \e 2642 rdr-to 127.0.0.1 port 8080 2643.Ed 2644.Pp 2645In the example below, vlan12 is configured as 192.168.168.1; 2646the machine translates all packets coming from 192.168.168.0/24 to 204.92.77.111 2647when they are going out any interface except vlan12. 2648This has the net effect of making traffic from the 192.168.168.0/24 2649network appear as though it is the Internet routable address 2650204.92.77.111 to nodes behind any interface on the router except 2651for the nodes on vlan12. 2652Thus, 192.168.168.1 can talk to the 192.168.168.0/24 nodes. 2653.Bd -literal -offset 4n 2654match out on ! vlan12 from 192.168.168.0/24 to any nat-to 204.92.77.111 2655.Ed 2656.Pp 2657In the example below, the machine sits between a fake internal 2658144.19.74.* network, and a routable external IP of 204.92.77.100. 2659The last rule excludes protocol AH from being translated. 2660.Bd -literal -offset 4n 2661pass out on $ext_if from 144.19.74.0/24 nat-to 204.92.77.100 2662pass out on $ext_if proto ah from 144.19.74.0/24 2663.Ed 2664.Pp 2665In the example below, packets bound for one specific server, as well as those 2666generated by the sysadmins are not proxied; all other connections are. 2667.Bd -literal -offset 4n 2668pass in on $int_if proto { tcp, udp } from any to any port 80 \e 2669 rdr-to 127.0.0.1 port 80 2670pass in on $int_if proto { tcp, udp } from any to $server port 80 2671pass in on $int_if proto { tcp, udp } from $sysadmins to any port 80 2672.Ed 2673.Pp 2674This example maps outgoing packets' source port 2675to an assigned proxy port instead of an arbitrary port. 2676In this case, proxy outgoing isakmp with port 500 on the gateway. 2677.Bd -literal -offset 4n 2678match out on $ext_if inet proto udp from any port isakmp to any \e 2679 nat-to ($ext_if) port 500 2680.Ed 2681.Pp 2682One more example uses 2683.Cm rdr-to 2684to redirect a TCP and UDP port to an internal machine. 2685.Bd -literal -offset 4n 2686match in on $ext_if inet proto tcp from any to ($ext_if) port 8080 \e 2687 rdr-to 10.1.2.151 port 22 2688match in on $ext_if inet proto udp from any to ($ext_if) port 8080 \e 2689 rdr-to 10.1.2.151 port 53 2690.Ed 2691.Pp 2692In this example, a NAT gateway is set up to translate internal addresses 2693using a pool of public addresses (192.0.2.16/28). 2694A given source address is always translated to the same pool address by 2695using the 2696.Cm source-hash 2697keyword. 2698The gateway also translates incoming web server connections 2699to a group of web servers on the internal network. 2700.Bd -literal -offset 4n 2701match out on $ext_if inet from any to any nat-to 192.0.2.16/28 \e 2702 source-hash 2703match in on $ext_if proto tcp from any to any port 80 \e 2704 rdr-to { 10.1.2.155 weight 2, 10.1.2.160 weight 1, \e 2705 10.1.2.161 weight 8 } round-robin 2706.Ed 2707.Pp 2708The bidirectional address translation example uses a single 2709.Cm binat-to 2710rule that expands to a 2711.Cm nat-to 2712and an 2713.Cm rdr-to 2714rule. 2715.Bd -literal -offset 4n 2716pass on $ext_if from 10.1.2.120 to any binat-to 192.0.2.17 2717.Ed 2718.Pp 2719The previous example is identical to the following set of rules: 2720.Bd -literal -offset 4n 2721pass out on $ext_if inet from 10.1.2.120 to any \e 2722 nat-to 192.0.2.17 static-port 2723pass in on $ext_if inet from any to 192.0.2.17 rdr-to 10.1.2.120 2724.Ed 2725.Pp 2726In the example below, a router handling both address families 2727translates an internal IPv4 subnet to IPv6 using the well-known 272864:ff9b::/96 prefix: 2729.Bd -literal -offset 4n 2730pass in on $v4_if inet af-to inet6 from ($v6_if) to 64:ff9b::/96 2731.Ed 2732.Pp 2733Paired with the example above, the example below can be used on 2734another router handling both address families to translate back 2735to IPv4: 2736.Bd -literal -offset 4n 2737pass in on $v6_if inet6 to 64:ff9b::/96 af-to inet from ($v4_if) 2738.Ed 2739.Sh GRAMMAR 2740Syntax for 2741.Nm 2742in BNF: 2743.Bd -literal 2744line = ( option | pf-rule | 2745 antispoof-rule | queue-rule | anchor-rule | 2746 anchor-close | load-anchor | table-rule | include ) 2747 2748option = "set" ( [ "timeout" ( timeout | "{" timeout-list "}" ) ] | 2749 [ "ruleset-optimization" [ "none" | "basic" | 2750 "profile" ] ] | 2751 [ "optimization" [ "default" | "normal" | "high-latency" | 2752 "satellite" | "aggressive" | "conservative" ] ] 2753 [ "limit" ( limit-item | "{" limit-list "}" ) ] | 2754 [ "loginterface" ( interface-name | "none" ) ] | 2755 [ "block-policy" ( "drop" | "return" ) ] | 2756 [ "state-policy" ( "if-bound" | "floating" ) ] 2757 [ "state-defaults" state-opts ] 2758 [ "fingerprints" filename ] | 2759 [ "skip on" ifspec ] | 2760 [ "debug" ( "emerg" | "alert" | "crit" | "err" | 2761 "warning" | "notice" | "info" | "debug" ) ] | 2762 [ "reassemble" ( "yes" | "no" ) [ "no-df" ] ] ) 2763 2764pf-rule = action [ ( "in" | "out" ) ] 2765 [ "log" [ "(" logopts ")"] ] [ "quick" ] 2766 [ "on" ( ifspec | "rdomain" number ) ] [ af ] 2767 [ protospec ] [ hosts ] [ filteropts ] 2768 2769logopts = logopt [ [ "," ] logopts ] 2770logopt = "all" | "matches" | "user" | "to" interface-name 2771 2772filteropts = filteropt [ [ "," ] filteropts ] 2773filteropt = user | group | flags | icmp-type | icmp6-type | 2774 "tos" tos | 2775 ( "no" | "keep" | "modulate" | "synproxy" ) "state" 2776 [ "(" state-opts ")" ] | "scrub" "(" scrubopts ")" | 2777 "fragment" | "allow-opts" | "once" | 2778 "divert-packet" "port" port | "divert-reply" | 2779 "divert-to" host "port" port | 2780 "label" string | "tag" string | [ "!" ] "tagged" string | 2781 "max-pkt-rate" number "/" seconds | 2782 "set delay" number | 2783 "set prio" ( number | "(" number [ [ "," ] number ] ")" ) | 2784 "set queue" ( string | "(" string [ [ "," ] string ] ")" ) | 2785 "rtable" number | "probability" number"%" | "prio" number | 2786 "af-to" af "from" ( redirhost | "{" redirhost-list "}" ) 2787 [ "to" ( redirhost | "{" redirhost-list "}" ) ] | 2788 "binat-to" ( redirhost | "{" redirhost-list "}" ) 2789 [ portspec ] [ pooltype ] | 2790 "rdr-to" ( redirhost | "{" redirhost-list "}" ) 2791 [ portspec ] [ pooltype ] | 2792 "nat-to" ( redirhost | "{" redirhost-list "}" ) 2793 [ portspec ] [ pooltype ] [ "static-port" ] | 2794 [ route ] | [ "set tos" tos ] | 2795 [ [ "!" ] "received-on" ( interface-name | interface-group ) ] 2796 2797scrubopts = scrubopt [ [ "," ] scrubopts ] 2798scrubopt = "no-df" | "min-ttl" number | "max-mss" number | 2799 "reassemble tcp" | "random-id" 2800 2801antispoof-rule = "antispoof" [ "log" ] [ "quick" ] 2802 "for" ifspec [ af ] [ "label" string ] 2803 2804table-rule = "table" "<" string ">" [ tableopts ] 2805tableopts = tableopt [ tableopts ] 2806tableopt = "persist" | "const" | "counters" | 2807 "file" string | "{" [ tableaddrs ] "}" 2808tableaddrs = tableaddr-spec [ [ "," ] tableaddrs ] 2809tableaddr-spec = [ "!" ] tableaddr [ "/" mask-bits ] 2810tableaddr = hostname | ifspec | "self" | 2811 ipv4-dotted-quad | ipv6-coloned-hex 2812 2813queue-rule = "queue" string [ "on" interface-name ] queueopts-list 2814 2815anchor-rule = "anchor" [ string ] [ ( "in" | "out" ) ] [ "on" ifspec ] 2816 [ af ] [ protospec ] [ hosts ] [ filteropt-list ] [ "{" ] 2817 2818anchor-close = "}" 2819 2820load-anchor = "load anchor" string "from" filename 2821 2822queueopts-list = queueopts-list queueopts | queueopts 2823queueopts = ([ "bandwidth" bandwidth ] | [ "min" bandwidth ] | 2824 [ "max" bandwidth ] | [ "parent" string ] | 2825 [ "default" ]) | 2826 ([ "flows" number ] | [ "quantum" number ]) | 2827 [ "qlimit" number ] 2828 2829bandwidth = bandwidth-spec [ "burst" bandwidth-spec "for" number "ms" ] 2830bandwidth-spec = number ( "" | "K" | "M" | "G" ) 2831 2832action = "pass" | "match" | "block" [ return ] 2833return = "drop" | "return" | 2834 "return-rst" [ "(" "ttl" number ")" ] | 2835 "return-icmp" [ "(" icmpcode [ [ "," ] icmp6code ] ")" ] | 2836 "return-icmp6" [ "(" icmp6code ")" ] 2837icmpcode = ( icmp-code-name | icmp-code-number ) 2838icmp6code = ( icmp6-code-name | icmp6-code-number ) 2839 2840ifspec = ( [ "!" ] ( interface-name | interface-group ) ) | 2841 "{" interface-list "}" 2842interface-list = [ "!" ] ( interface-name | interface-group ) 2843 [ [ "," ] interface-list ] 2844route = ( "route-to" | "reply-to" | "dup-to" ) 2845 ( routehost | "{" routehost-list "}" ) 2846 [ pooltype ] 2847af = "inet" | "inet6" 2848 2849protospec = "proto" ( proto-name | proto-number | 2850 "{" proto-list "}" ) 2851proto-list = ( proto-name | proto-number ) [ [ "," ] proto-list ] 2852 2853hosts = "all" | 2854 "from" ( "any" | "no-route" | "urpf-failed" | "self" | 2855 host | "{" host-list "}" | "route" string ) [ port ] 2856 [ os ] 2857 "to" ( "any" | "no-route" | "self" | host | 2858 "{" host-list "}" | "route" string ) [ port ] 2859 2860ipspec = "any" | host | "{" host-list "}" 2861host = [ "!" ] ( address [ "weight" number ] | 2862 address [ "/" mask-bits ] [ "weight" number ] | 2863 "<" string ">" ) 2864redirhost = address [ "/" mask-bits ] 2865routehost = host | host "@" interface-name | 2866 "(" interface-name [ address [ "/" mask-bits ] ] ")" 2867address = ( interface-name | interface-group | 2868 "(" ( interface-name | interface-group ) ")" | 2869 hostname | ipv4-dotted-quad | ipv6-coloned-hex ) 2870host-list = host [ [ "," ] host-list ] 2871redirhost-list = redirhost [ [ "," ] redirhost-list ] 2872routehost-list = routehost [ [ "," ] routehost-list ] 2873 2874port = "port" ( unary-op | binary-op | "{" op-list "}" ) 2875portspec = "port" ( number | name ) [ ":" ( "*" | number | name ) ] 2876os = "os" ( os-name | "{" os-list "}" ) 2877user = "user" ( unary-op | binary-op | "{" op-list "}" ) 2878group = "group" ( unary-op | binary-op | "{" op-list "}" ) 2879 2880unary-op = [ "=" | "!=" | "<" | "<=" | ">" | ">=" ] 2881 ( name | number ) 2882binary-op = number ( "<>" | "><" | ":" ) number 2883op-list = ( unary-op | binary-op ) [ [ "," ] op-list ] 2884 2885os-name = operating-system-name 2886os-list = os-name [ [ "," ] os-list ] 2887 2888flags = "flags" ( [ flag-set ] "/" flag-set | "any" ) 2889flag-set = [ "F" ] [ "S" ] [ "R" ] [ "P" ] [ "A" ] [ "U" ] [ "E" ] 2890 [ "W" ] 2891 2892icmp-type = "icmp-type" ( icmp-type-code | "{" icmp-list "}" ) 2893icmp6-type = "icmp6-type" ( icmp-type-code | "{" icmp-list "}" ) 2894icmp-type-code = ( icmp-type-name | icmp-type-number ) 2895 [ "code" ( icmp-code-name | icmp-code-number ) ] 2896icmp-list = icmp-type-code [ [ "," ] icmp-list ] 2897 2898tos = ( "lowdelay" | "throughput" | "reliability" | 2899 [ "0x" ] number ) 2900 2901state-opts = state-opt [ [ "," ] state-opts ] 2902state-opt = ( "max" number | "no-sync" | timeout | "sloppy" | 2903 "pflow" | "source-track" [ ( "rule" | "global" ) ] | 2904 "max-src-nodes" number | "max-src-states" number | 2905 "max-src-conn" number | 2906 "max-src-conn-rate" number "/" number | 2907 "overload" "<" string ">" [ "flush" [ "global" ] ] | 2908 "if-bound" | "floating" ) 2909 2910timeout-list = timeout [ [ "," ] timeout-list ] 2911timeout = ( "tcp.first" | "tcp.opening" | "tcp.established" | 2912 "tcp.closing" | "tcp.finwait" | "tcp.closed" | 2913 "udp.first" | "udp.single" | "udp.multiple" | 2914 "icmp.first" | "icmp.error" | 2915 "other.first" | "other.single" | "other.multiple" | 2916 "frag" | "interval" | "src.track" | 2917 "adaptive.start" | "adaptive.end" ) number 2918 2919limit-list = limit-item [ [ "," ] limit-list ] 2920limit-item = ( "states" | "frags" | "src-nodes" | "tables" | 2921 "table-entries" ) number 2922 2923pooltype = ( "bitmask" | "least-states" | 2924 "random" | "round-robin" | 2925 "source-hash" [ ( hex-key | string-key ) ] ) 2926 [ "sticky-address" ] 2927 2928include = "include" filename 2929.Ed 2930.Sh FILES 2931.Bl -tag -width "/etc/protocolsXXX" -compact 2932.It Pa /etc/hosts 2933Host name database. 2934.It Pa /etc/pf.conf 2935Default location of the ruleset file. 2936.It Pa /etc/pf.os 2937Default location of OS fingerprints. 2938.It Pa /etc/protocols 2939Protocol name database. 2940.It Pa /etc/services 2941Service name database. 2942.El 2943.Sh SEE ALSO 2944.Xr pf 4 , 2945.Xr pflow 4 , 2946.Xr pfsync 4 , 2947.Xr pf.os 5 , 2948.Xr pfctl 8 , 2949.Xr pflogd 8 2950.Sh HISTORY 2951The 2952.Nm 2953file format first appeared in 2954.Ox 3.0 . 2955