1.\" $OpenBSD: pf.conf.5,v 1.406 2009/01/31 19:37:12 sobrado Exp $ 2.\" 3.\" Copyright (c) 2002, Daniel Hartmeier 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 10.\" - Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" - Redistributions in binary form must reproduce the above 13.\" copyright notice, this list of conditions and the following 14.\" disclaimer in the documentation and/or other materials provided 15.\" with the distribution. 16.\" 17.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 20.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 21.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 22.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 27.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd July 30, 2025 31.Dt PF.CONF 5 32.Os 33.Sh NAME 34.Nm pf.conf 35.Nd packet filter configuration file 36.Sh DESCRIPTION 37The 38.Xr pf 4 39packet filter modifies, drops or passes packets according to rules or 40definitions specified in 41.Nm pf.conf . 42.Sh STATEMENT ORDER 43There are eight types of statements in 44.Nm pf.conf : 45.Bl -tag -width xxxx 46.It Cm Macros 47User-defined variables may be defined and used later, simplifying 48the configuration file. 49Macros must be defined before they are referenced in 50.Nm pf.conf . 51.It Cm Tables 52Tables provide a mechanism for increasing the performance and flexibility of 53rules with large numbers of source or destination addresses. 54.It Cm Options 55Options tune the behaviour of the packet filtering engine. 56.It Cm Ethernet Filtering 57Ethernet filtering provides rule-based blocking or passing of Ethernet packets. 58.It Cm Traffic Normalization Li (e.g. Em scrub ) 59Traffic normalization protects internal machines against inconsistencies 60in Internet protocols and implementations. 61.It Cm Queueing 62Queueing provides rule-based bandwidth control. 63.It Cm Translation Li (Various forms of NAT) 64Translation rules specify how addresses are to be mapped or redirected to 65other addresses. 66.It Cm Packet Filtering 67Packet filtering provides rule-based blocking or passing of packets. 68.El 69.Pp 70With the exception of 71.Cm macros 72and 73.Cm tables , 74the types of statements should be grouped and appear in 75.Nm pf.conf 76in the order shown above, as this matches the operation of the underlying 77packet filtering engine. 78By default 79.Xr pfctl 8 80enforces this order (see 81.Ar set require-order 82below). 83.Pp 84Comments can be put anywhere in the file using a hash mark 85.Pq Sq # , 86and extend to the end of the current line. 87.Pp 88Additional configuration files can be included with the 89.Ic include 90keyword, for example: 91.Bd -literal -offset indent 92include "/etc/pf/sub.filter.conf" 93.Ed 94.Sh MACROS 95Macros can be defined that will later be expanded in context. 96Macro names must start with a letter, and may contain letters, digits 97and underscores. 98Macro names may not be reserved words (for example 99.Ar pass , 100.Ar in , 101.Ar out ) . 102Macros are not expanded inside quotes. 103Ranges of network addresses used in macros that will be expanded in lists 104later on must be quoted with additional simple quotes. 105.Pp 106For example, 107.Bd -literal -offset indent 108ext_if = \&"kue0\&" 109all_ifs = \&"{\&" $ext_if lo0 \&"}\&" 110pass out on $ext_if from any to any 111pass in on $ext_if proto tcp from any to any port 25 112 113usr_lan_range = "'192.0.2.0/24'" 114srv_lan_range = "'198.51.100.0 - 198.51.100.255'" 115nat_ranges = \&"{\&" $usr_lan_range $srv_lan_range \&"}\&" 116nat on $ext_if from $nat_ranges to any -> ($ext_if) 117.Ed 118.Sh TABLES 119Tables are named structures which can hold a collection of addresses and 120networks. 121Lookups against tables in 122.Xr pf 4 123are relatively fast, making a single rule with tables much more efficient, 124in terms of 125processor usage and memory consumption, than a large number of rules which 126differ only in IP address (either created explicitly or automatically by rule 127expansion). 128.Pp 129Tables can be used as the source or destination of filter rules, 130.Ar scrub 131rules 132or 133translation rules such as 134.Ar nat 135or 136.Ar rdr 137(see below for details on the various rule types). 138Tables can also be used for the redirect address of 139.Ar nat 140and 141.Ar rdr 142and in the routing options of filter rules, but not for 143.Ar bitmask 144pools. 145.Pp 146Tables can be defined with any of the following 147.Xr pfctl 8 148mechanisms. 149As with macros, reserved words may not be used as table names. 150.Bl -tag -width "manually" 151.It Ar manually 152Persistent tables can be manually created with the 153.Ar add 154or 155.Ar replace 156option of 157.Xr pfctl 8 , 158before or after the ruleset has been loaded. 159.It Pa pf.conf 160Table definitions can be placed directly in this file, and loaded at the 161same time as other rules are loaded, atomically. 162Table definitions inside 163.Nm pf.conf 164use the 165.Ar table 166statement, and are especially useful to define non-persistent tables. 167The contents of a pre-existing table defined without a list of addresses 168to initialize it is not altered when 169.Nm pf.conf 170is loaded. 171A table initialized with the empty list, 172.Li { } , 173will be cleared on load. 174.El 175.Pp 176Tables may be defined with the following attributes: 177.Bl -tag -width counters 178.It Ar persist 179The 180.Ar persist 181flag forces the kernel to keep the table even when no rules refer to it. 182If the flag is not set, the kernel will automatically remove the table 183when the last rule referring to it is flushed. 184.It Ar const 185The 186.Ar const 187flag prevents the user from altering the contents of the table once it 188has been created. 189Without that flag, 190.Xr pfctl 8 191can be used to add or remove addresses from the table at any time, even 192when running with 193.Xr securelevel 7 194= 2. 195.It Ar counters 196The 197.Ar counters 198flag enables per-address packet and byte counters which can be displayed with 199.Xr pfctl 8 . 200Note that this feature carries significant memory overhead for large tables. 201.El 202.Pp 203For example, 204.Bd -literal -offset indent 205table <private> const { 10/8, 172.16/12, 192.168/16 } 206table <badhosts> persist 207block on fxp0 from { <private>, <badhosts> } to any 208.Ed 209.Pp 210creates a table called private, to hold RFC 1918 private network 211blocks, and a table called badhosts, which is initially empty. 212A filter rule is set up to block all traffic coming from addresses listed in 213either table. 214The private table cannot have its contents changed and the badhosts table 215will exist even when no active filter rules reference it. 216Addresses may later be added to the badhosts table, so that traffic from 217these hosts can be blocked by using 218.Bd -literal -offset indent 219# pfctl -t badhosts -Tadd 204.92.77.111 220.Ed 221.Pp 222A table can also be initialized with an address list specified in one or more 223external files, using the following syntax: 224.Bd -literal -offset indent 225table <spam> persist file \&"/etc/spammers\&" file \&"/etc/openrelays\&" 226block on fxp0 from <spam> to any 227.Ed 228.Pp 229The files 230.Pa /etc/spammers 231and 232.Pa /etc/openrelays 233list IP addresses, one per line. 234Any lines beginning with a # are treated as comments and ignored. 235In addition to being specified by IP address, hosts may also be 236specified by their hostname. 237When the resolver is called to add a hostname to a table, 238.Em all 239resulting IPv4 and IPv6 addresses are placed into the table. 240IP addresses can also be entered in a table by specifying a valid interface 241name, a valid interface group or the 242.Em self 243keyword, in which case all addresses assigned to the interface(s) will be 244added to the table. 245.Sh OPTIONS 246.Xr pf 4 247may be tuned for various situations using the 248.Ar set 249command. 250.Bl -tag -width xxxx 251.It Ar set timeout 252.Pp 253.Bl -tag -width "src.track" -compact 254.It Ar interval 255Interval between purging expired states and fragments. 256.It Ar frag 257Seconds before an unassembled fragment is expired. 258.It Ar src.track 259Length of time to retain a source tracking entry after the last state 260expires. 261.El 262.Pp 263When a packet matches a stateful connection, the seconds to live for the 264connection will be updated to that of the 265.Ar proto.modifier 266which corresponds to the connection state. 267Each packet which matches this state will reset the TTL. 268Tuning these values may improve the performance of the 269firewall at the risk of dropping valid idle connections. 270.Pp 271.Bl -tag -width xxxx -compact 272.It Ar tcp.first 273The state after the first packet. 274.It Ar tcp.opening 275The state after the second packet but before both endpoints have 276acknowledged the connection. 277.It Ar tcp.established 278The fully established state. 279.It Ar tcp.closing 280The state after the first FIN has been sent. 281.It Ar tcp.finwait 282The state after both FINs have been exchanged and the connection is closed. 283Some hosts (notably web servers on Solaris) send TCP packets even after closing 284the connection. 285Increasing 286.Ar tcp.finwait 287(and possibly 288.Ar tcp.closing ) 289can prevent blocking of such packets. 290.It Ar tcp.closed 291The state after one endpoint sends an RST. 292.El 293.Pp 294SCTP timeout are handled similar to TCP, but with its own set of states: 295.Pp 296.Bl -tag -width xxxx -compact 297.It Ar sctp.first 298The state after the first packet. 299.It Ar sctp.opening 300The state before the destination host ever sends a packet. 301.It Ar sctp.established 302The fully established state. 303.It Ar sctp.closing 304The state after the first SHUTDOWN chunk has been sent. 305.It Ar sctp.closed 306The state after SHUTDOWN_ACK has been exchanged and the connection is closed. 307.El 308.Pp 309ICMP and UDP are handled in a fashion similar to TCP, but with a much more 310limited set of states: 311.Pp 312.Bl -tag -width xxxx -compact 313.It Ar udp.first 314The state after the first packet. 315.It Ar udp.single 316The state if the source host sends more than one packet but the destination 317host has never sent one back. 318.It Ar udp.multiple 319The state if both hosts have sent packets. 320.It Ar icmp.first 321The state after the first packet. 322.It Ar icmp.error 323The state after an ICMP error came back in response to an ICMP packet. 324.El 325.Pp 326Other protocols are handled similarly to UDP: 327.Pp 328.Bl -tag -width xxxx -compact 329.It Ar other.first 330.It Ar other.single 331.It Ar other.multiple 332.El 333.Pp 334Timeout values can be reduced adaptively as the number of state table 335entries grows. 336.Pp 337.Bl -tag -width xxxx -compact 338.It Ar adaptive.start 339When the number of state entries exceeds this value, adaptive scaling 340begins. 341All timeout values are scaled linearly with factor 342(adaptive.end - number of states) / (adaptive.end - adaptive.start). 343.It Ar adaptive.end 344When reaching this number of state entries, all timeout values become 345zero, effectively purging all state entries immediately. 346This value is used to define the scale factor, it should not actually 347be reached (set a lower state limit, see below). 348.El 349.Pp 350Adaptive timeouts are enabled by default, with an adaptive.start value 351equal to 60% of the state limit, and an adaptive.end value equal to 352120% of the state limit. 353They can be disabled by setting both adaptive.start and adaptive.end to 0. 354.Pp 355The adaptive timeout values can be defined both globally and for each rule. 356When used on a per-rule basis, the values relate to the number of 357states created by the rule, otherwise to the total number of 358states. 359.Pp 360For example: 361.Bd -literal -offset indent 362set timeout tcp.first 120 363set timeout tcp.established 86400 364set timeout { adaptive.start 60000, adaptive.end 120000 } 365set limit states 100000 366.Ed 367.Pp 368With 90000 state table entries, the timeout values are scaled to 50% 369(tcp.first 60, tcp.established 43200). 370.It Ar set loginterface 371Enable collection of packet and byte count statistics for the given 372interface or interface group. 373These statistics can be viewed using 374.Bd -literal -offset indent 375# pfctl -s info 376.Ed 377.Pp 378In this example 379.Xr pf 4 380collects statistics on the interface named dc0: 381.Bd -literal -offset indent 382set loginterface dc0 383.Ed 384.Pp 385One can disable the loginterface using: 386.Bd -literal -offset indent 387set loginterface none 388.Ed 389.It Ar set limit 390Sets hard limits on the memory pools used by the packet filter. 391See 392.Xr zone 9 393for an explanation of memory pools. 394.Pp 395Limits can be set on the following: 396.Bl -tag -width pktdelay_pkts 397.It Cm states 398Set the maximum number of entries in the memory pool used by state table 399entries (those generated by 400.Ar pass 401rules which do not specify 402.Cm no state ) . 403The default is 100000. 404.It Cm src-nodes 405Set the maximum number of entries in the memory pool used for tracking 406source IP addresses (generated by the 407.Ar sticky-address 408and 409.Ar src.track 410options). 411The default is 10000. 412.It Cm table-entries 413Set the number of addresses that can be stored in tables. 414The default is 200000. 415.It Cm anchors 416Set the number of anchors that can exist. 417The default is 512. 418.It Cm eth-anchors 419Set the number of anchors that can exist. 420The default is 512. 421.El 422.Pp 423Multiple limits can be combined on a single line: 424.Bd -literal -offset indent 425set limit { states 20000, frags 2000, src-nodes 2000 } 426.Ed 427.It Ar set ruleset-optimization 428.Bl -tag -width xxxxxxxx -compact 429.It Ar none 430Disable the ruleset optimizer. 431.It Ar basic 432Enable basic ruleset optimization. 433This is the default behaviour. 434Basic ruleset optimization does four things to improve the 435performance of ruleset evaluations: 436.Pp 437.Bl -enum -compact 438.It 439remove duplicate rules 440.It 441remove rules that are a subset of another rule 442.It 443combine multiple rules into a table when advantageous 444.It 445re-order the rules to improve evaluation performance 446.El 447.Pp 448.It Ar profile 449Uses the currently loaded ruleset as a feedback profile to tailor the 450ordering of quick rules to actual network traffic. 451.El 452.Pp 453It is important to note that the ruleset optimizer will modify the ruleset 454to improve performance. 455A side effect of the ruleset modification is that per-rule accounting 456statistics will have different meanings than before. 457If per-rule accounting is important for billing purposes or whatnot, 458either the ruleset optimizer should not be used or a label field should 459be added to all of the accounting rules to act as optimization barriers. 460.Pp 461Optimization can also be set as a command-line argument to 462.Xr pfctl 8 , 463overriding the settings in 464.Nm . 465.It Ar set optimization 466Optimize state timeouts for one of the following network environments: 467.Pp 468.Bl -tag -width xxxx -compact 469.It Ar normal 470A normal network environment. 471Suitable for almost all networks. 472.It Ar high-latency 473A high-latency environment (such as a satellite connection). 474.It Ar satellite 475Alias for 476.Ar high-latency . 477.It Ar aggressive 478Aggressively expire connections. 479This can greatly reduce the memory usage of the firewall at the cost of 480dropping idle connections early. 481.It Ar conservative 482Extremely conservative settings. 483Avoid dropping legitimate connections at the 484expense of greater memory utilization (possibly much greater on a busy 485network) and slightly increased processor utilization. 486.El 487.Pp 488For example: 489.Bd -literal -offset indent 490set optimization aggressive 491.Ed 492.It Ar set reassemble yes | no Op Cm no-df 493The 494.Cm reassemble 495option is used to enable or disable the reassembly of fragmented packets, 496and can be set to 497.Cm yes 498or 499.Cm no . 500If 501.Cm no-df 502is also specified, fragments with the 503.Dq dont-fragment 504bit set are reassembled too, 505instead of being dropped; 506the reassembled packet will have the 507.Dq dont-fragment 508bit cleared. 509The default value is 510.Cm no . 511.Pp 512This option is ignored if there are pre-FreeBSD 14 513.Cm scrub 514rules present. 515.It Ar set block-policy 516The 517.Ar block-policy 518option sets the default behaviour for the packet 519.Ar block 520action: 521.Pp 522.Bl -tag -width xxxxxxxx -compact 523.It Ar drop 524Packet is silently dropped. 525.It Ar return 526A TCP RST is returned for blocked TCP packets, 527an SCTP ABORT chunk is returned for blocked SCTP packets, 528an ICMP UNREACHABLE is returned for blocked UDP packets, 529and all other packets are silently dropped. 530.El 531.Pp 532The default value is 533.Cm drop . 534.Pp 535For example: 536.Bd -literal -offset indent 537set block-policy return 538.Ed 539.It Ar set fail-policy 540The 541.Ar fail-policy 542option sets the behaviour of rules which should pass a packet but were 543unable to do so. 544This might happen when a nat or route-to rule uses an empty table as list 545of targets or if a rule fails to create state or source node. 546The following 547.Ar block 548actions are possible: 549.Pp 550.Bl -tag -width xxxxxxxx -compact 551.It Ar drop 552Incoming packet is silently dropped. 553.It Ar return 554Incoming packet is dropped and TCP RST is returned for TCP packets, 555an SCTP ABORT chunk is returned for blocked SCTP packets, 556an ICMP UNREACHABLE is returned for UDP packets, 557and no response is sent for other packets. 558.El 559.Pp 560For example: 561.Bd -literal -offset indent 562set fail-policy return 563.Ed 564.It Ar set state-policy 565The 566.Ar state-policy 567option sets the default behaviour for states: 568.Pp 569.Bl -tag -width group-bound -compact 570.It Ar if-bound 571States are bound to interface. 572.It Ar floating 573States can match packets on any interfaces (the default). 574.El 575.Pp 576For example: 577.Bd -literal -offset indent 578set state-policy if-bound 579.Ed 580.It Ar set syncookies never | always | adaptive 581When 582.Cm syncookies 583are active, pf will answer each incoming TCP SYN with a syncookie SYNACK, 584without allocating any resources. 585Upon reception of the client's ACK in response to the syncookie 586SYNACK, pf will evaluate the ruleset and create state if the ruleset 587permits it, complete the three way handshake with the target host and 588continue the connection with synproxy in place. 589This allows pf to be resilient against large synflood attacks which would 590run the state table against its limits otherwise. 591Due to the blind answers to every incoming SYN syncookies share the caveats of 592synproxy, namely seemingly accepting connections that will be dropped later on. 593.Pp 594.Bl -tag -width adaptive -compact 595.It Cm never 596pf will never send syncookie SYNACKs (the default). 597.It Cm always 598pf will always send syncookie SYNACKs. 599.It Cm adaptive 600pf will enable syncookie mode when a given percentage of the state table 601is used up by half-open TCP connections, as in, those that saw the initial 602SYN but didn't finish the three way handshake. 603The thresholds for entering and leaving syncookie mode can be specified using 604.Bd -literal -offset indent 605set syncookies adaptive (start 25%, end 12%) 606.Ed 607.El 608.It Ar set state-defaults 609The 610.Ar state-defaults 611option sets the state options for states created from rules 612without an explicit 613.Ar keep state . 614For example: 615.Bd -literal -offset indent 616set state-defaults no-sync 617.Ed 618.It Ar set hostid 619The 32-bit 620.Ar hostid 621identifies this firewall's state table entries to other firewalls 622in a 623.Xr pfsync 4 624failover cluster. 625By default the hostid is set to a pseudo-random value, however it may be 626desirable to manually configure it, for example to more easily identify the 627source of state table entries. 628.Bd -literal -offset indent 629set hostid 1 630.Ed 631.Pp 632The hostid may be specified in either decimal or hexadecimal. 633.It Ar set require-order 634By default 635.Xr pfctl 8 636enforces an ordering of the statement types in the ruleset to: 637.Em options , 638.Em normalization , 639.Em queueing , 640.Em translation , 641.Em filtering . 642Setting this option to 643.Ar no 644disables this enforcement. 645There may be non-trivial and non-obvious implications to an out of 646order ruleset. 647Consider carefully before disabling the order enforcement. 648.It Ar set fingerprints 649Load fingerprints of known operating systems from the given filename. 650By default fingerprints of known operating systems are automatically 651loaded from 652.Xr pf.os 5 653in 654.Pa /etc 655but can be overridden via this option. 656Setting this option may leave a small period of time where the fingerprints 657referenced by the currently active ruleset are inconsistent until the new 658ruleset finishes loading. 659The default location for fingerprints is 660.Pa /etc/pf.os . 661.Pp 662For example: 663.Pp 664.Dl set fingerprints \&"/etc/pf.os.devel\&" 665.It Ar set skip on Aq Ar ifspec 666List interfaces for which packets should not be filtered. 667Packets passing in or out on such interfaces are passed as if pf was 668disabled, i.e. pf does not process them in any way. 669This can be useful on loopback and other virtual interfaces, when 670packet filtering is not desired and can have unexpected effects. 671For example: 672.Pp 673.Dl set skip on lo0 674.It Ar set debug 675Set the debug 676.Ar level 677to one of the following: 678.Pp 679.Bl -tag -width xxxxxxxxxxxx -compact 680.It Ar none 681Don't generate debug messages. 682.It Ar urgent 683Generate debug messages only for serious errors. 684.It Ar misc 685Generate debug messages for various errors. 686.It Ar loud 687Generate debug messages for common conditions. 688.El 689.It Ar set keepcounters 690Preserve rule counters across rule updates. 691Usually rule counters are reset to zero on every update of the ruleset. 692With 693.Ar keepcounters 694set pf will attempt to find matching rules between old and new rulesets 695and preserve the rule counters. 696.El 697.Sh ETHERNET FILTERING 698.Xr pf 4 699has the ability to 700.Ar block 701and 702.Ar pass 703packets based on attributes of their Ethernet (layer 2) header. 704.Pp 705Each time a packet processed by the packet filter comes in on or 706goes out through an interface, the filter rules are evaluated in 707sequential order, from first to last. 708The last matching rule decides what action is taken. 709If no rule matches the packet, the default action is to pass 710the packet without creating a state. 711.Pp 712The following actions can be used in the filter: 713.Bl -tag -width xxxx 714.It Ar block 715The packet is blocked. 716Unlike for layer 3 traffic the packet is always silently dropped. 717.It Ar pass 718The packet is passed; 719no state is created for layer 2 traffic. 720.El 721.Ss Parameters applicable to layer 2 rules 722The rule parameters specify the packets to which a rule applies. 723A packet always comes in on, or goes out through, one interface. 724Most parameters are optional. 725If a parameter is specified, the rule only applies to packets with 726matching attributes. 727The matching for some parameters can be inverted with the 728.Cm !\& 729operator. 730Certain parameters can be expressed as lists, in which case 731.Xr pfctl 8 732generates all needed rule combinations. 733.Bl -tag -width xxxx 734.It Ar in No or Ar out 735This rule applies to incoming or outgoing packets. 736If neither 737.Ar in 738nor 739.Ar out 740are specified, the rule will match packets in both directions. 741.It Ar quick 742If a packet matches a rule which has the 743.Ar quick 744option set, this rule 745is considered the last matching rule, and evaluation of subsequent rules 746is skipped. 747.It Ar on Aq Ar ifspec 748This rule applies only to packets coming in on, or going out through, this 749particular interface or interface group. 750For more information on interface groups, 751see the 752.Ic group 753keyword in 754.Xr ifconfig 8 . 755.Ar any 756will match any existing interface except loopback ones. 757.It Ar bridge-to Aq interface 758Packets matching this rule will be sent out of the specified interface without 759further processing. 760.It Ar proto Aq Ar protocol 761This rule applies only to packets of this protocol. 762Note that Ethernet protocol numbers are different from those used in 763.Xr ip 4 764and 765.Xr ip6 4 . 766.It Xo 767.Ar from Aq Ar source 768.Ar to Aq Ar dest 769.Xc 770This rule applies only to packets with the specified source and destination 771MAC addresses. 772.It Xo Ar queue Aq Ar queue 773.Xc 774Packets matching this rule will be assigned to the specified queue. 775See 776.Sx QUEUEING 777for setup details. 778.Pp 779.It Ar tag Aq Ar string 780Packets matching this rule will be tagged with the 781specified string. 782The tag acts as an internal marker that can be used to 783identify these packets later on. 784This can be used, for example, to provide trust between 785interfaces and to determine if packets have been 786processed by translation rules. 787Tags are 788.Qq sticky , 789meaning that the packet will be tagged even if the rule 790is not the last matching rule. 791Further matching rules can replace the tag with a 792new one but will not remove a previously applied tag. 793A packet is only ever assigned one tag at a time. 794.It Ar tagged Aq Ar string 795Used to specify that packets must already be tagged with the given tag in order 796to match the rule. 797Inverse tag matching can also be done by specifying the ! operator before the 798tagged keyword. 799.El 800.Sh TRAFFIC NORMALIZATION 801Traffic normalization is a broad umbrella term 802for aspects of the packet filter which deal with 803verifying packets, packet fragments, spoofed traffic, 804and other irregularities. 805.Ss Scrub 806Scrub involves sanitising packet content in such a way 807that there are no ambiguities in packet interpretation on the receiving side. 808It is invoked with the 809.Cm scrub 810option, added to filter rules. 811.Pp 812Parameters are specified enclosed in parentheses. 813At least one of the following parameters must be specified: 814.Bl -tag -width xxxx 815.It Ar no-df 816Clears the 817.Ar dont-fragment 818bit from a matching IP packet. 819Some operating systems are known to generate fragmented packets with the 820.Ar dont-fragment 821bit set. 822This is particularly true with NFS. 823.Ar Scrub 824will drop such fragmented 825.Ar dont-fragment 826packets unless 827.Ar no-df 828is specified. 829.Pp 830Unfortunately some operating systems also generate their 831.Ar dont-fragment 832packets with a zero IP identification field. 833Clearing the 834.Ar dont-fragment 835bit on packets with a zero IP ID may cause deleterious results if an 836upstream router later fragments the packet. 837Using the 838.Ar random-id 839modifier (see below) is recommended in combination with the 840.Ar no-df 841modifier to ensure unique IP identifiers. 842.It Ar min-ttl Aq Ar number 843Enforces a minimum TTL for matching IP packets. 844.It Ar max-mss Aq Ar number 845Reduces the maximum segment size (MSS) 846on TCP SYN packets to be no greater than 847.Ar number . 848This is sometimes required in scenarios where the two endpoints 849of a TCP connection are not able to carry similar sized packets 850and the resulting mismatch can lead to packet fragmentation or loss. 851Note that setting the MSS this way can have undesirable effects, 852such as interfering with the OS detection features of 853.Xr pf 4 . 854.It Xo Ar set-tos Aq Ar string 855.No \*(Ba Aq Ar number 856.Xc 857Enforces a 858.Em TOS 859for matching IP packets. 860.Em TOS 861may be 862given as one of 863.Ar critical , 864.Ar inetcontrol , 865.Ar lowdelay , 866.Ar netcontrol , 867.Ar throughput , 868.Ar reliability , 869or one of the DiffServ Code Points: 870.Ar ef , 871.Ar va , 872.Ar af11 No ... Ar af43 , 873.Ar cs0 No ... Ar cs7 ; 874or as either hex or decimal. 875.It Ar random-id 876Replaces the IP identification field with random values to compensate 877for predictable values generated by many hosts. 878This option only applies to packets that are not fragmented 879after the optional fragment reassembly. 880.It Ar reassemble tcp 881Statefully normalizes TCP connections. 882.Ar reassemble tcp 883performs the following normalizations: 884.Pp 885.Bl -tag -width timeout -compact 886.It ttl 887Neither side of the connection is allowed to reduce their IP TTL. 888An attacker may send a packet such that it reaches the firewall, affects 889the firewall state, and expires before reaching the destination host. 890.Ar reassemble tcp 891will raise the TTL of all packets back up to the highest value seen on 892the connection. 893.It timestamp modulation 894Modern TCP stacks will send a timestamp on every TCP packet and echo 895the other endpoint's timestamp back to them. 896Many operating systems will merely start the timestamp at zero when 897first booted, and increment it several times a second. 898The uptime of the host can be deduced by reading the timestamp and multiplying 899by a constant. 900Also observing several different timestamps can be used to count hosts 901behind a NAT device. 902And spoofing TCP packets into a connection requires knowing or guessing 903valid timestamps. 904Timestamps merely need to be monotonically increasing and not derived off a 905guessable base time. 906.Ar reassemble tcp 907will cause 908.Ar scrub 909to modulate the TCP timestamps with a random number. 910.It extended PAWS checks 911There is a problem with TCP on long fat pipes, in that a packet might get 912delayed for longer than it takes the connection to wrap its 32-bit sequence 913space. 914In such an occurrence, the old packet would be indistinguishable from a 915new packet and would be accepted as such. 916The solution to this is called PAWS: Protection Against Wrapped Sequence 917numbers. 918It protects against it by making sure the timestamp on each packet does 919not go backwards. 920.Ar reassemble tcp 921also makes sure the timestamp on the packet does not go forward more 922than the RFC allows. 923By doing this, 924.Xr pf 4 925artificially extends the security of TCP sequence numbers by 10 to 18 926bits when the host uses appropriately randomized timestamps, since a 927blind attacker would have to guess the timestamp as well. 928.El 929.El 930.Pp 931For example, 932.Bd -literal -offset indent 933match in all scrub (no-df random-id max-mss 1440) 934.Ed 935.Ss Scrub ruleset (pre-FreeBSD 14) 936In order to maintain compatibility with older releases of FreeBSD 937.Ar scrub 938rules can also be specified in their own ruleset. 939In such case they are invoked with the 940.Ar scrub 941directive. 942If there are such rules present they determine packet reassembly behaviour. 943When no such rules are present the option 944.Ar set reassembly 945takes precedence. 946The 947.Ar scrub 948rules can take all parameters specified above for a 949.Ar scrub 950option of filter rules and 2 more parameters controlling fragment reassembly: 951.Bl -tag -width xxxx 952.It Ar fragment reassemble 953Using 954.Ar scrub 955rules, fragments can be reassembled by normalization. 956In this case, fragments are buffered until they form a complete 957packet, and only the completed packet is passed on to the filter. 958The advantage is that filter rules have to deal only with complete 959packets, and can ignore fragments. 960The drawback of caching fragments is the additional memory cost. 961This is the default behaviour unless no fragment reassemble is specified. 962.It Ar no fragment reassemble 963Do not reassemble fragments. 964.El 965.Pp 966For example, 967.Bd -literal -offset indent 968scrub in on $ext_if all fragment reassemble 969.Ed 970.Pp 971The 972.Ar no 973option prefixed to a scrub rule causes matching packets to remain unscrubbed, 974much in the same way as 975.Ar drop quick 976works in the packet filter (see below). 977This mechanism should be used when it is necessary to exclude specific packets 978from broader scrub rules. 979.Pp 980.Ar scrub 981rules in the 982.Ar scrub 983ruleset are evaluated for every packet before stateful filtering. 984This means excessive usage of them will cause performance penalty. 985.Ar scrub reassemble tcp 986rules must not have the direction (in/out) specified. 987.Sh QUEUEING with ALTQ 988The ALTQ system is currently not available in the GENERIC kernel nor as 989loadable modules. 990In order to use the herein after called queueing options one has to use a 991custom built kernel. 992Please refer to 993.Xr altq 4 994to learn about the related kernel options. 995.Pp 996Packets can be assigned to queues for the purpose of bandwidth 997control. 998At least two declarations are required to configure queues, and later 999any packet filtering rule can reference the defined queues by name. 1000During the filtering component of 1001.Nm pf.conf , 1002the last referenced 1003.Ar queue 1004name is where any packets from 1005.Ar pass 1006rules will be queued, while for 1007.Ar block 1008rules it specifies where any resulting ICMP or TCP RST 1009packets should be queued. 1010The 1011.Ar scheduler 1012defines the algorithm used to decide which packets get delayed, dropped, or 1013sent out immediately. 1014There are three 1015.Ar schedulers 1016currently supported. 1017.Bl -tag -width xxxx 1018.It Ar cbq 1019Class Based Queueing. 1020.Ar Queues 1021attached to an interface build a tree, thus each 1022.Ar queue 1023can have further child 1024.Ar queues . 1025Each queue can have a 1026.Ar priority 1027and a 1028.Ar bandwidth 1029assigned. 1030.Ar Priority 1031mainly controls the time packets take to get sent out, while 1032.Ar bandwidth 1033has primarily effects on throughput. 1034.Ar cbq 1035achieves both partitioning and sharing of link bandwidth 1036by hierarchically structured classes. 1037Each class has its own 1038.Ar queue 1039and is assigned its share of 1040.Ar bandwidth . 1041A child class can borrow bandwidth from its parent class 1042as long as excess bandwidth is available 1043(see the option 1044.Ar borrow , 1045below). 1046.It Ar priq 1047Priority Queueing. 1048.Ar Queues 1049are flat attached to the interface, thus, 1050.Ar queues 1051cannot have further child 1052.Ar queues . 1053Each 1054.Ar queue 1055has a unique 1056.Ar priority 1057assigned, ranging from 0 to 15. 1058Packets in the 1059.Ar queue 1060with the highest 1061.Ar priority 1062are processed first. 1063.It Ar hfsc 1064Hierarchical Fair Service Curve. 1065.Ar Queues 1066attached to an interface build a tree, thus each 1067.Ar queue 1068can have further child 1069.Ar queues . 1070Each queue can have a 1071.Ar priority 1072and a 1073.Ar bandwidth 1074assigned. 1075.Ar Priority 1076mainly controls the time packets take to get sent out, while 1077.Ar bandwidth 1078primarily affects throughput. 1079.Ar hfsc 1080supports both link-sharing and guaranteed real-time services. 1081It employs a service curve based QoS model, 1082and its unique feature is an ability to decouple 1083.Ar delay 1084and 1085.Ar bandwidth 1086allocation. 1087.El 1088.Pp 1089The interfaces on which queueing should be activated are declared using 1090the 1091.Ar altq on 1092declaration. 1093.Ar altq on 1094has the following keywords: 1095.Bl -tag -width xxxx 1096.It Aq Ar interface 1097Queueing is enabled on the named interface. 1098.It Aq Ar scheduler 1099Specifies which queueing scheduler to use. 1100Currently supported values 1101are 1102.Ar cbq 1103for Class Based Queueing, 1104.Ar priq 1105for Priority Queueing and 1106.Ar hfsc 1107for the Hierarchical Fair Service Curve scheduler. 1108.It Ar bandwidth Aq Ar bw 1109The maximum bitrate for all queues on an 1110interface may be specified using the 1111.Ar bandwidth 1112keyword. 1113The value can be specified as an absolute value or as a 1114percentage of the interface bandwidth. 1115When using an absolute value, the suffixes 1116.Ar b , 1117.Ar Kb , 1118.Ar Mb , 1119and 1120.Ar Gb 1121are used to represent bits, kilobits, megabits, and 1122gigabits per second, respectively. 1123The value must not exceed the interface bandwidth. 1124If 1125.Ar bandwidth 1126is not specified, the interface bandwidth is used 1127(but take note that some interfaces do not know their bandwidth, 1128or can adapt their bandwidth rates). 1129.It Ar qlimit Aq Ar limit 1130The maximum number of packets held in the queue. 1131The default is 50. 1132.It Ar tbrsize Aq Ar size 1133Adjusts the size, in bytes, of the token bucket regulator. 1134If not specified, heuristics based on the 1135interface bandwidth are used to determine the size. 1136.It Ar queue Aq Ar list 1137Defines a list of subqueues to create on an interface. 1138.El 1139.Pp 1140In the following example, the interface dc0 1141should queue up to 5Mbps in four second-level queues using 1142Class Based Queueing. 1143Those four queues will be shown in a later example. 1144.Bd -literal -offset indent 1145altq on dc0 cbq bandwidth 5Mb queue { std, http, mail, ssh } 1146.Ed 1147.Pp 1148Once interfaces are activated for queueing using the 1149.Ar altq 1150directive, a sequence of 1151.Ar queue 1152directives may be defined. 1153The name associated with a 1154.Ar queue 1155must match a queue defined in the 1156.Ar altq 1157directive (e.g. mail), or, except for the 1158.Ar priq 1159.Ar scheduler , 1160in a parent 1161.Ar queue 1162declaration. 1163The following keywords can be used: 1164.Bl -tag -width xxxx 1165.It Ar on Aq Ar interface 1166Specifies the interface the queue operates on. 1167If not given, it operates on all matching interfaces. 1168.It Ar bandwidth Aq Ar bw 1169Specifies the maximum bitrate to be processed by the queue. 1170This value must not exceed the value of the parent 1171.Ar queue 1172and can be specified as an absolute value or a percentage of the parent 1173queue's bandwidth. 1174If not specified, defaults to 100% of the parent queue's bandwidth. 1175The 1176.Ar priq 1177scheduler does not support bandwidth specification. 1178.It Ar priority Aq Ar level 1179Between queues a priority level can be set. 1180For 1181.Ar cbq 1182and 1183.Ar hfsc , 1184the range is 0 to 7 and for 1185.Ar priq , 1186the range is 0 to 15. 1187The default for all is 1. 1188.Ar Priq 1189queues with a higher priority are always served first. 1190.Ar Cbq 1191and 1192.Ar Hfsc 1193queues with a higher priority are preferred in the case of overload. 1194.It Ar qlimit Aq Ar limit 1195The maximum number of packets held in the queue. 1196The default is 50. 1197.El 1198.Pp 1199The 1200.Ar scheduler 1201can get additional parameters with 1202.Xo Aq Ar scheduler 1203.Pf ( Aq Ar parameters ) . 1204.Xc 1205Parameters are as follows: 1206.Bl -tag -width Fl 1207.It Ar default 1208Packets not matched by another queue are assigned to this one. 1209Exactly one default queue is required. 1210.It Ar red 1211Enable RED (Random Early Detection) on this queue. 1212RED drops packets with a probability proportional to the average 1213queue length. 1214.It Ar rio 1215Enables RIO on this queue. 1216RIO is RED with IN/OUT, thus running 1217RED two times more than RIO would achieve the same effect. 1218RIO is currently not supported in the GENERIC kernel. 1219.It Ar ecn 1220Enables ECN (Explicit Congestion Notification) on this queue. 1221ECN implies RED. 1222.El 1223.Pp 1224The 1225.Ar cbq 1226.Ar scheduler 1227supports an additional option: 1228.Bl -tag -width Fl 1229.It Ar borrow 1230The queue can borrow bandwidth from the parent. 1231.El 1232.Pp 1233The 1234.Ar hfsc 1235.Ar scheduler 1236supports some additional options: 1237.Bl -tag -width Fl 1238.It Ar realtime Aq Ar sc 1239The minimum required bandwidth for the queue. 1240.It Ar upperlimit Aq Ar sc 1241The maximum allowed bandwidth for the queue. 1242.It Ar linkshare Aq Ar sc 1243The bandwidth share of a backlogged queue. 1244.El 1245.Pp 1246.Aq Ar sc 1247is an acronym for 1248.Ar service curve . 1249.Pp 1250The format for service curve specifications is 1251.Ar ( m1 , d , m2 ) . 1252.Ar m2 1253controls the bandwidth assigned to the queue. 1254.Ar m1 1255and 1256.Ar d 1257are optional and can be used to control the initial bandwidth assignment. 1258For the first 1259.Ar d 1260milliseconds the queue gets the bandwidth given as 1261.Ar m1 , 1262afterwards the value given in 1263.Ar m2 . 1264.Pp 1265Furthermore, with 1266.Ar cbq 1267and 1268.Ar hfsc , 1269child queues can be specified as in an 1270.Ar altq 1271declaration, thus building a tree of queues using a part of 1272their parent's bandwidth. 1273.Pp 1274Packets can be assigned to queues based on filter rules by using the 1275.Ar queue 1276keyword. 1277Normally only one 1278.Ar queue 1279is specified; when a second one is specified it will instead be used for 1280packets which have a 1281.Em TOS 1282of 1283.Em lowdelay 1284and for TCP ACKs with no data payload. 1285.Pp 1286To continue the previous example, the examples below would specify the 1287four referenced 1288queues, plus a few child queues. 1289Interactive 1290.Xr ssh 1 1291sessions get priority over bulk transfers like 1292.Xr scp 1 1293and 1294.Xr sftp 1 . 1295The queues may then be referenced by filtering rules (see 1296.Sx PACKET FILTERING 1297below). 1298.Bd -literal 1299queue std bandwidth 10% cbq(default) 1300queue http bandwidth 60% priority 2 cbq(borrow red) \e 1301 { employees, developers } 1302queue developers bandwidth 75% cbq(borrow) 1303queue employees bandwidth 15% 1304queue mail bandwidth 10% priority 0 cbq(borrow ecn) 1305queue ssh bandwidth 20% cbq(borrow) { ssh_interactive, ssh_bulk } 1306queue ssh_interactive bandwidth 50% priority 7 cbq(borrow) 1307queue ssh_bulk bandwidth 50% priority 0 cbq(borrow) 1308 1309block return out on dc0 inet all queue std 1310pass out on dc0 inet proto tcp from $developerhosts to any port 80 \e 1311 queue developers 1312pass out on dc0 inet proto tcp from $employeehosts to any port 80 \e 1313 queue employees 1314pass out on dc0 inet proto tcp from any to any port 22 \e 1315 queue(ssh_bulk, ssh_interactive) 1316pass out on dc0 inet proto tcp from any to any port 25 \e 1317 queue mail 1318.Ed 1319.Sh QUEUEING with dummynet 1320Queueing can also be done with 1321.Xr dummynet 4 . 1322Queues and pipes can be created with 1323.Xr dnctl 8 . 1324.Pp 1325Packets can be assigned to queues and pipes using 1326.Ar dnqueue 1327and 1328.Ar dnpipe 1329respectively. 1330.Pp 1331Both 1332.Ar dnqueue 1333and 1334.Ar dnpipe 1335take either a single pipe or queue number or two numbers as arguments. 1336The first pipe or queue number will be used to shape the traffic in the rule 1337direction, the second will be used to shape the traffic in the reverse 1338direction. 1339If the rule does not specify a direction the first packet to create state will 1340be shaped according to the first number, and the response traffic according to 1341the second. 1342.Pp 1343If the 1344.Xr dummynet 4 1345module is not loaded any traffic sent into a queue or pipe will be dropped. 1346.Sh TRANSLATION 1347Translation options modify either the source or destination address and 1348port of the packets associated with a stateful connection. 1349.Xr pf 4 1350modifies the specified address and/or port in the packet and recalculates 1351IP, TCP, and UDP checksums as necessary. 1352.Pp 1353If specified on a 1354.Ic match 1355rule, subsequent rules will see packets as they look 1356after any addresses and ports have been translated. 1357These rules will therefore have to filter based on the translated 1358address and port number. 1359.Pp 1360The state entry created permits 1361.Xr pf 4 1362to keep track of the original address for traffic associated with that state 1363and correctly direct return traffic for that connection. 1364.Pp 1365Various types of translation are possible with pf: 1366.Bl -tag -width xxxx 1367.It Ar af-to 1368Translation between different address families (NAT64) is handled 1369using 1370.Ar af-to 1371rules. 1372Because address family translation overrides the routing table, it's 1373only possible to use 1374.Ar af-to 1375on inbound rules, and a source address of the resulting translation 1376must always be specified. 1377.Pp 1378The optional second argument is the host or subnet the original 1379addresses are translated into for the destination. 1380The lowest bits of the original destination address form the host 1381part of the new destination address according to the specified subnet. 1382It is possible to embed a complete IPv4 address into an IPv6 address 1383using a network prefix of /96 or smaller. 1384.Pp 1385When a destination address is not specified, it is assumed that the host 1386part is 32-bit long. 1387For IPv6 to IPv4 translation this would mean using only the lower 32 1388bits of the original IPv6 destination address. 1389For IPv4 to IPv6 translation the destination subnet defaults to the 1390subnet of the new IPv6 source address with a prefix length of /96. 1391See RFC 6052 Section 2.2 for details on how the prefix determines the 1392destination address encoding. 1393.Pp 1394For example, the following rules are identical: 1395.Bd -literal -offset indent 1396pass in inet af-to inet6 from 2001:db8::1 to 2001:db8::/96 1397pass in inet af-to inet6 from 2001:db8::1 1398.Ed 1399.Pp 1400In the above example the matching IPv4 packets will be modified to 1401have a source address of 2001:db8::1 and a destination address will 1402get prefixed with 2001:db8::/96, e.g. 198.51.100.100 will be 1403translated to 2001:db8::c633:6464. 1404.Pp 1405In the reverse case the following rules are identical: 1406.Bd -literal -offset indent 1407pass in inet6 from any to 64:ff9b::/96 af-to inet \e 1408 from 198.51.100.1 to 0.0.0.0/0 1409pass in inet6 from any to 64:ff9b::/96 af-to inet \e 1410 from 198.51.100.1 1411.Ed 1412.Pp 1413The destination IPv4 address is assumed to be embedded inside the 1414original IPv6 destination address, e.g. 64:ff9b::c633:6464 will be 1415translated to 198.51.100.100. 1416.Pp 1417The current implementation will only extract IPv4 addresses from the 1418IPv6 addresses with a prefix length of /96 and greater. 1419.It Ar binat 1420A 1421.Ar binat-to 1422rule specifies a bidirectional mapping between an external IP netblock 1423and an internal IP netblock. 1424It expands to an outbound 1425.Ar nat-to 1426rule and an inbound 1427.Ar rdr-to 1428rule. 1429.It Ar nat-to 1430A 1431.Ar nat-to 1432option specifies that IP addresses are to be changed as the packet 1433traverses the given interface. 1434This technique allows one or more IP addresses 1435on the translating host to support network traffic for a larger range of 1436machines on an "inside" network. 1437Although in theory any IP address can be used on the inside, it is strongly 1438recommended that one of the address ranges defined by RFC 1918 be used. 1439These netblocks are: 1440.Bd -literal -offset indent 144110.0.0.0 - 10.255.255.255 (all of net 10.0.0.0, i.e., 10.0.0.0/8) 1442172.16.0.0 - 172.31.255.255 (i.e., 172.16.0.0/12) 1443192.168.0.0 - 192.168.255.255 (i.e., 192.168.0.0/16) 1444.Ed 1445.Pp 1446.Ar nat-to 1447is usually applied outbound. 1448If applied inbound, nat-to to a local IP address is not supported. 1449.It Pa rdr-to 1450The packet is redirected to another destination and possibly a 1451different port. 1452.Ar rdr-to 1453can optionally specify port ranges instead of single ports. 1454For instance: 1455.Bd -literal -offset indent 1456match in ... port 2000:2999 rdr-to ... port 4000 1457.Ed 1458redirects ports 2000 to 2999 (inclusive) to port 4000. 1459.Bd -literal -offset indent 1460qmatch in ... port 2000:2999 rdr-to ... port 4000:* 1461.Ed 1462redirects port 2000 to 4000, 2001 to 4001, ..., 2999 to 4999. 1463.El 1464.Pp 1465.Ar rdr-to 1466is usually applied inbound. 1467If applied outbound, rdr-to to a local IP address is not supported. 1468In addition to modifying the address, some translation rules may modify 1469source or destination ports for 1470.Xr tcp 4 1471or 1472.Xr udp 4 1473connections; implicitly in the case of 1474.Ar nat-to 1475options and both implicitly and explicitly in the case of 1476.Ar rdr-to 1477ones. 1478A 1479.Ar rdr-to 1480opion may cause the source port to be modified if doing so avoids a conflict 1481with an existing connection. 1482A random source port in the range 50001-65535 is chosen in this case. 1483Port numbers are never translated with a 1484.Ar binat-to 1485option. 1486.Pp 1487Note that redirecting external incoming connections to the loopback 1488address, as in 1489.Bd -literal -offset indent 1490pass in on egress proto tcp from any to any port smtp \e 1491 rdr-to 127.0.0.1 port spamd 1492.Ed 1493.Pp 1494will effectively allow an external host to connect to daemons 1495bound solely to the loopback address, circumventing the traditional 1496blocking of such connections on a real interface. 1497Unless this effect is desired, any of the local non-loopback addresses 1498should be used as redirection target instead, which allows external 1499connections only to daemons bound to this address or not bound to 1500any address. 1501.Pp 1502See 1503.Sx TRANSLATION EXAMPLES 1504below. 1505.Ss NAT ruleset (pre-FreeBSD 15) 1506In order to maintain compatibility with older releases of FreeBSD 1507.Ar NAT 1508rules can also be specified in their own ruleset. 1509A stateful connection is automatically created to track packets matching 1510such a rule as long as they are not blocked by the filtering section of 1511.Nm pf.conf . 1512Since translation occurs before filtering the filter 1513engine will see packets as they look after any 1514addresses and ports have been translated. 1515Filter rules will therefore have to filter based on the translated 1516address and port number. 1517Packets that match a translation rule are only automatically passed if 1518the 1519.Ar pass 1520modifier is given, otherwise they are 1521still subject to 1522.Ar block 1523and 1524.Ar pass 1525rules. 1526.Pp 1527The following rules can be defined in the NAT ruleset: 1528.Ar binat , 1529.Ar nat , 1530and 1531.Ar rdr . 1532They have the same effect as 1533.Ar binat-to , 1534.Ar nat-to 1535and 1536.Ar rdr-to 1537options for filter rules. 1538.Pp 1539The 1540.Ar no 1541option prefixed to a translation rule causes packets to remain untranslated, 1542much in the same way as 1543.Ar drop quick 1544works in the packet filter. 1545If no rule matches the packet it is passed to the filter engine unmodified. 1546.Pp 1547Evaluation order of the translation rules is dependent on the type 1548of the translation rules and of the direction of a packet. 1549.Ar binat 1550rules are always evaluated first. 1551Then either the 1552.Ar rdr 1553rules are evaluated on an inbound packet or the 1554.Ar nat 1555rules on an outbound packet. 1556Rules of the same type are evaluated in the same order in which they 1557appear in the ruleset. 1558The first matching rule decides what action is taken. 1559.Pp 1560Translation rules apply only to packets that pass through 1561the specified interface, and if no interface is specified, 1562translation is applied to packets on all interfaces. 1563For instance, redirecting port 80 on an external interface to an internal 1564web server will only work for connections originating from the outside. 1565Connections to the address of the external interface from local hosts will 1566not be redirected, since such packets do not actually pass through the 1567external interface. 1568Redirections cannot reflect packets back through the interface they arrive 1569on, they can only be redirected to hosts connected to different interfaces 1570or to the firewall itself. 1571.Pp 1572See 1573.Sx COMPATIBILITY TRANSLATION EXAMPLES 1574below. 1575.Sh PACKET FILTERING 1576.Xr pf 4 1577has the ability to 1578.Ar block 1579, 1580.Ar pass 1581and 1582.Ar match 1583packets based on attributes of their layer 3 (see 1584.Xr ip 4 1585and 1586.Xr ip6 4 ) 1587and layer 4 (see 1588.Xr icmp 4 , 1589.Xr icmp6 4 , 1590.Xr tcp 4 , 1591.Xr sctp 4 , 1592.Xr udp 4 ) 1593headers. 1594In addition, packets may also be 1595assigned to queues for the purpose of bandwidth control. 1596.Pp 1597For each packet processed by the packet filter, the filter rules are 1598evaluated in sequential order, from first to last. 1599For 1600.Ar block 1601and 1602.Ar pass 1603, the last matching rule decides what action is taken. 1604For 1605.Ar match 1606, rules are evaluated every time they match; the pass/block state of a packet 1607remains unchanged. 1608If no rule matches the packet, the default action is to pass 1609the packet. 1610.Pp 1611The following actions can be used in the filter: 1612.Bl -tag -width xxxx 1613.It Ar block 1614The packet is blocked. 1615There are a number of ways in which a 1616.Ar block 1617rule can behave when blocking a packet. 1618The default behaviour is to 1619.Ar drop 1620packets silently, however this can be overridden or made 1621explicit either globally, by setting the 1622.Ar block-policy 1623option, or on a per-rule basis with one of the following options: 1624.Pp 1625.Bl -tag -width xxxx -compact 1626.It Ar drop 1627The packet is silently dropped. 1628.It Ar return-rst 1629This applies only to 1630.Xr tcp 4 1631packets, and issues a TCP RST which closes the 1632connection. 1633.It Ar return-icmp 1634.It Ar return-icmp6 1635This causes ICMP messages to be returned for packets which match the rule. 1636By default this is an ICMP UNREACHABLE message, however this 1637can be overridden by specifying a message as a code or number. 1638.It Ar return 1639This causes a TCP RST to be returned for 1640.Xr tcp 4 1641packets, an SCTP ABORT for SCTP 1642and an ICMP UNREACHABLE for UDP and other packets. 1643.El 1644.Pp 1645Options returning ICMP packets currently have no effect if 1646.Xr pf 4 1647operates on a 1648.Xr if_bridge 4 , 1649as the code to support this feature has not yet been implemented. 1650.Pp 1651The simplest mechanism to block everything by default and only pass 1652packets that match explicit rules is specify a first filter rule of: 1653.Bd -literal -offset indent 1654block all 1655.Ed 1656.It Ar match 1657The packet is matched. 1658This mechanism is used to provide fine grained filtering without altering the 1659block/pass state of a packet. 1660.Ar match 1661rules differ from 1662.Ar block 1663and 1664.Ar pass 1665rules in that parameters are set for every rule a packet matches, not only 1666on the last matching rule. 1667For the following parameters, this means that the parameter effectively becomes 1668"sticky" until explicitly overridden: 1669.Ar nat-to , 1670.Ar binat-to , 1671.Ar rdr-to , 1672.Ar queue , 1673.Ar dnpipe , 1674.Ar dnqueue , 1675.Ar rtable , 1676.Ar scrub 1677. 1678.It Ar pass 1679The packet is passed; 1680state is created unless the 1681.Ar no state 1682option is specified. 1683.El 1684.Pp 1685By default 1686.Xr pf 4 1687filters packets statefully; the first time a packet matches a 1688.Ar pass 1689rule, a state entry is created; for subsequent packets the filter checks 1690whether the packet matches any state. 1691If it does, the packet is passed without evaluation of any rules. 1692After the connection is closed or times out, the state entry is automatically 1693removed. 1694.Pp 1695This has several advantages. 1696For TCP connections, comparing a packet to a state involves checking 1697its sequence numbers, as well as TCP timestamps if a 1698.Ar scrub reassemble tcp 1699rule applies to the connection. 1700If these values are outside the narrow windows of expected 1701values, the packet is dropped. 1702This prevents spoofing attacks, such as when an attacker sends packets with 1703a fake source address/port but does not know the connection's sequence 1704numbers. 1705Similarly, 1706.Xr pf 4 1707knows how to match ICMP replies to states. 1708For example, 1709.Bd -literal -offset indent 1710pass out inet proto icmp all icmp-type echoreq 1711.Ed 1712.Pp 1713allows echo requests (such as those created by 1714.Xr ping 8 ) 1715out statefully, and matches incoming echo replies correctly to states. 1716.Pp 1717Also, looking up states is usually faster than evaluating rules. 1718.Pp 1719Furthermore, correct handling of ICMP error messages is critical to 1720many protocols, particularly TCP. 1721.Xr pf 4 1722matches ICMP error messages to the correct connection, checks them against 1723connection parameters, and passes them if appropriate. 1724For example if an ICMP source quench message referring to a stateful TCP 1725connection arrives, it will be matched to the state and get passed. 1726.Pp 1727Finally, state tracking is required for 1728.Ar nat , binat No and Ar rdr 1729rules, in order to track address and port translations and reverse the 1730translation on returning packets. 1731.Pp 1732.Xr pf 4 1733will also create state for other protocols which are effectively stateless by 1734nature. 1735UDP packets are matched to states using only host addresses and ports, 1736and other protocols are matched to states using only the host addresses. 1737.Pp 1738If stateless filtering of individual packets is desired, 1739the 1740.Ar no state 1741keyword can be used to specify that state will not be created 1742if this is the last matching rule. 1743A number of parameters can also be set to affect how 1744.Xr pf 4 1745handles state tracking. 1746See 1747.Sx STATEFUL TRACKING OPTIONS 1748below for further details. 1749.Ss Parameters 1750The rule parameters specify the packets to which a rule applies. 1751A packet always comes in on, or goes out through, one interface. 1752Most parameters are optional. 1753If a parameter is specified, the rule only applies to packets with 1754matching attributes. 1755Certain parameters can be expressed as lists, in which case 1756.Xr pfctl 8 1757generates all needed rule combinations. 1758.Bl -tag -width xxxx 1759.It Ar in No or Ar out 1760This rule applies to incoming or outgoing packets. 1761If neither 1762.Ar in 1763nor 1764.Ar out 1765are specified, the rule will match packets in both directions. 1766.It Ar log Pq Cm all | matches | to Ao Ar interface Ac | Cm user 1767In addition to any action specified, 1768log the packet. 1769Only the packet that establishes the state is logged, 1770unless the 1771.Ar no state 1772option is specified. 1773The logged packets are sent to a 1774.Xr pflog 4 1775interface, by default pflog0; 1776pflog0 is monitored by the 1777.Xr pflogd 8 1778logging daemon which logs to the file 1779.Pa /var/log/pflog 1780in 1781.Xr pcap 3 1782binary format. 1783.Pp 1784The keywords 1785.Cm all , matches , to , 1786and 1787.Cm user 1788are optional and can be combined using commas, 1789but must be enclosed in parentheses if given. 1790.Pp 1791Use 1792.Cm all 1793to force logging of all packets for a connection. 1794This is not necessary when 1795.Ar no state 1796is explicitly specified. 1797.Pp 1798If 1799.Cm matches 1800is specified, 1801it logs the packet on all subsequent matching rules. 1802It is often combined with 1803.Cm to Aq Ar interface 1804to avoid adding noise to the default log file. 1805.Pp 1806The keyword 1807.Cm user 1808logs the 1809.Ux 1810user ID of the user that owns the socket and the PID of the process that 1811has the socket open where the packet is sourced from or destined to 1812(depending on which socket is local). 1813This is in addition to the normal information logged. 1814.Pp 1815Only the first packet 1816logged via 1817.Ar log (all, user) 1818will have the user credentials logged when using stateful matching. 1819.Pp 1820To specify a logging interface other than pflog0, 1821use the syntax 1822.Cm to Aq Ar interface . 1823.It Ar quick 1824If a packet matches a rule which has the 1825.Ar quick 1826option set, this rule 1827is considered the last matching rule, and evaluation of subsequent rules 1828is skipped. 1829.It Ar on Aq Ar interface 1830This rule applies only to packets coming in on, or going out through, this 1831particular interface or interface group. 1832For more information on interface groups, 1833see the 1834.Ic group 1835keyword in 1836.Xr ifconfig 8 . 1837.Ar any 1838will match any existing interface except loopback ones. 1839.It Aq Ar af 1840This rule applies only to packets of this address family. 1841Supported values are 1842.Ar inet 1843and 1844.Ar inet6 . 1845.It Ar proto Aq Ar protocol 1846This rule applies only to packets of this protocol. 1847Common protocols are 1848.Xr icmp 4 , 1849.Xr icmp6 4 , 1850.Xr tcp 4 , 1851.Xr sctp 4 , 1852and 1853.Xr udp 4 . 1854For a list of all the protocol name to number mappings used by 1855.Xr pfctl 8 , 1856see the file 1857.Pa /etc/protocols . 1858.It Xo 1859.Ar from Aq Ar source 1860.Ar port Aq Ar source 1861.Ar os Aq Ar source 1862.Ar to Aq Ar dest 1863.Ar port Aq Ar dest 1864.Xc 1865This rule applies only to packets with the specified source and destination 1866addresses and ports. 1867.Pp 1868Addresses can be specified in CIDR notation (matching netblocks), as 1869symbolic host names, interface names or interface group names, or as any 1870of the following keywords: 1871.Pp 1872.Bl -tag -width xxxxxxxxxxxxxx -compact 1873.It Ar any 1874Any address. 1875.It Ar no-route 1876Any address which is not currently routable. 1877.It Ar urpf-failed 1878Any source address that fails a unicast reverse path forwarding (URPF) 1879check, i.e. packets coming in on an interface other than that which holds 1880the route back to the packet's source address. 1881.It Ar self 1882Expands to all addresses assigned to all interfaces. 1883.It Aq Ar table 1884Any address that matches the given table. 1885.El 1886.Pp 1887Ranges of addresses are specified by using the 1888.Sq - 1889operator. 1890For instance: 1891.Dq 10.1.1.10 - 10.1.1.12 1892means all addresses from 10.1.1.10 to 10.1.1.12, 1893hence addresses 10.1.1.10, 10.1.1.11, and 10.1.1.12. 1894.Pp 1895Interface names and interface group names, and 1896.Ar self 1897can have modifiers appended: 1898.Pp 1899.Bl -tag -width xxxxxxxxxxxx -compact 1900.It Ar :network 1901Translates to the network(s) attached to the interface. 1902.It Ar :broadcast 1903Translates to the interface's broadcast address(es). 1904.It Ar :peer 1905Translates to the point-to-point interface's peer address(es). 1906.It Ar :0 1907Do not include interface aliases. 1908.El 1909.Pp 1910Host names may also have the 1911.Ar :0 1912option appended to restrict the name resolution to the first of each 1913v4 and non-link-local v6 address found. 1914.Pp 1915Host name resolution and interface to address translation are done at 1916ruleset load-time. 1917When the address of an interface (or host name) changes (under DHCP or PPP, 1918for instance), the ruleset must be reloaded for the change to be reflected 1919in the kernel. 1920Surrounding the interface name (and optional modifiers) in parentheses 1921changes this behaviour. 1922When the interface name is surrounded by parentheses, the rule is 1923automatically updated whenever the interface changes its address. 1924The ruleset does not need to be reloaded. 1925This is especially useful with 1926.Ar nat . 1927.Pp 1928Ports can be specified either by number or by name. 1929For example, port 80 can be specified as 1930.Em www . 1931For a list of all port name to number mappings used by 1932.Xr pfctl 8 , 1933see the file 1934.Pa /etc/services . 1935.Pp 1936Ports and ranges of ports are specified by using these operators: 1937.Bd -literal -offset indent 1938= (equal) 1939!= (unequal) 1940< (less than) 1941<= (less than or equal) 1942> (greater than) 1943>= (greater than or equal) 1944: (range including boundaries) 1945>< (range excluding boundaries) 1946<> (except range) 1947.Ed 1948.Pp 1949.Sq >< , 1950.Sq <> 1951and 1952.Sq \&: 1953are binary operators (they take two arguments). 1954For instance: 1955.Bl -tag -width Fl 1956.It Ar port 2000:2004 1957means 1958.Sq all ports >= 2000 and <= 2004 , 1959hence ports 2000, 2001, 2002, 2003 and 2004. 1960.It Ar port 2000 >< 2004 1961means 1962.Sq all ports > 2000 and < 2004 , 1963hence ports 2001, 2002 and 2003. 1964.It Ar port 2000 <> 2004 1965means 1966.Sq all ports < 2000 or > 2004 , 1967hence ports 1-1999 and 2005-65535. 1968.El 1969.Pp 1970The operating system of the source host can be specified in the case of TCP 1971rules with the 1972.Ar OS 1973modifier. 1974See the 1975.Sx OPERATING SYSTEM FINGERPRINTING 1976section for more information. 1977.Pp 1978The host, port and OS specifications are optional, as in the following examples: 1979.Bd -literal -offset indent 1980pass in all 1981pass in from any to any 1982pass in proto tcp from any port < 1024 to any 1983pass in proto tcp from any to any port 25 1984pass in proto tcp from 10.0.0.0/8 port >= 1024 \e 1985 to ! 10.1.2.3 port != ssh 1986pass in proto tcp from any os "OpenBSD" 1987.Ed 1988.It Ar all 1989This is equivalent to "from any to any". 1990.It Ar group Aq Ar group 1991Similar to 1992.Ar user , 1993this rule only applies to packets of sockets owned by the specified group. 1994.It Ar user Aq Ar user 1995This rule only applies to packets of sockets owned by the specified user. 1996For outgoing connections initiated from the firewall, this is the user 1997that opened the connection. 1998For incoming connections to the firewall itself, this is the user that 1999listens on the destination port. 2000For forwarded connections, where the firewall is not a connection endpoint, 2001the user and group are 2002.Em unknown . 2003.Pp 2004All packets, both outgoing and incoming, of one connection are associated 2005with the same user and group. 2006Only TCP and UDP packets can be associated with users; for other protocols 2007these parameters are ignored. 2008.Pp 2009User and group refer to the effective (as opposed to the real) IDs, in 2010case the socket is created by a setuid/setgid process. 2011User and group IDs are stored when a socket is created; 2012when a process creates a listening socket as root (for instance, by 2013binding to a privileged port) and subsequently changes to another 2014user ID (to drop privileges), the credentials will remain root. 2015.Pp 2016User and group IDs can be specified as either numbers or names. 2017The syntax is similar to the one for ports. 2018The value 2019.Em unknown 2020matches packets of forwarded connections. 2021.Em unknown 2022can only be used with the operators 2023.Cm = 2024and 2025.Cm != . 2026Other constructs like 2027.Cm user \*(Ge unknown 2028are invalid. 2029Forwarded packets with unknown user and group ID match only rules 2030that explicitly compare against 2031.Em unknown 2032with the operators 2033.Cm = 2034or 2035.Cm != . 2036For instance 2037.Cm user \*(Ge 0 2038does not match forwarded packets. 2039The following example allows only selected users to open outgoing 2040connections: 2041.Bd -literal -offset indent 2042block out proto { tcp, udp } all 2043pass out proto { tcp, udp } all user { < 1000, dhartmei } 2044.Ed 2045.Pp 2046The example below permits users with uid between 1000 and 1500 2047to open connections: 2048.Bd -literal -offset indent 2049block out proto tcp all 2050pass out proto tcp from self user { 999 >< 1501 } 2051.Ed 2052.Pp 2053The 2054.Sq \&: 2055operator, which works for port number matching, does not work for 2056.Cm user 2057and 2058.Cm group 2059match. 2060.It Xo Ar flags Aq Ar a 2061.Pf / Ns Aq Ar b 2062.No \*(Ba / Ns Aq Ar b 2063.No \*(Ba any 2064.Xc 2065This rule only applies to TCP packets that have the flags 2066.Aq Ar a 2067set out of set 2068.Aq Ar b . 2069Flags not specified in 2070.Aq Ar b 2071are ignored. 2072For stateful connections, the default is 2073.Ar flags S/SA . 2074To indicate that flags should not be checked at all, specify 2075.Ar flags any . 2076The flags are: (F)IN, (S)YN, (R)ST, (P)USH, (A)CK, (U)RG, (E)CE, and C(W)R. 2077.Bl -tag -width Fl 2078.It Ar flags S/S 2079Flag SYN is set. 2080The other flags are ignored. 2081.It Ar flags S/SA 2082This is the default setting for stateful connections. 2083Out of SYN and ACK, exactly SYN may be set. 2084SYN, SYN+PSH and SYN+RST match, but SYN+ACK, ACK and ACK+RST do not. 2085This is more restrictive than the previous example. 2086.It Ar flags /SFRA 2087If the first set is not specified, it defaults to none. 2088All of SYN, FIN, RST and ACK must be unset. 2089.El 2090.Pp 2091Because 2092.Ar flags S/SA 2093is applied by default (unless 2094.Ar no state 2095is specified), only the initial SYN packet of a TCP handshake will create 2096a state for a TCP connection. 2097It is possible to be less restrictive, and allow state creation from 2098intermediate 2099.Pq non-SYN 2100packets, by specifying 2101.Ar flags any . 2102This will cause 2103.Xr pf 4 2104to synchronize to existing connections, for instance 2105if one flushes the state table. 2106However, states created from such intermediate packets may be missing 2107connection details such as the TCP window scaling factor. 2108States which modify the packet flow, such as those affected by 2109.Ar af-to , 2110.Ar nat , 2111.Ar binat or 2112.Ar rdr 2113rules, 2114.Ar modulate No or Ar synproxy state 2115options, or scrubbed with 2116.Ar reassemble tcp 2117will also not be recoverable from intermediate packets. 2118Such connections will stall and time out. 2119.It Xo Ar icmp-type Aq Ar type 2120.Ar Op code Aq Ar code 2121.Xc 2122.It Xo Ar icmp6-type Aq Ar type 2123.Ar Op code Aq Ar code 2124.Xc 2125This rule only applies to ICMP or ICMPv6 packets with the specified type 2126and code. 2127Text names for ICMP types and codes are listed in 2128.Xr icmp 4 2129and 2130.Xr icmp6 4 . 2131This parameter is only valid for rules that cover protocols ICMP or 2132ICMP6. 2133The protocol and the ICMP type indicator 2134.Po 2135.Ar icmp-type 2136or 2137.Ar icmp6-type 2138.Pc 2139must match. 2140.It Xo Ar tos Aq Ar string 2141.No \*(Ba Aq Ar number 2142.Xc 2143This rule applies to packets with the specified 2144.Em TOS 2145bits set. 2146.Em TOS 2147may be 2148given as one of 2149.Ar critical , 2150.Ar inetcontrol , 2151.Ar lowdelay , 2152.Ar netcontrol , 2153.Ar throughput , 2154.Ar reliability , 2155or one of the DiffServ Code Points: 2156.Ar ef , 2157.Ar va , 2158.Ar af11 No ... Ar af43 , 2159.Ar cs0 No ... Ar cs7 ; 2160or as either hex or decimal. 2161.Pp 2162For example, the following rules are identical: 2163.Bd -literal -offset indent 2164pass all tos lowdelay 2165pass all tos 0x10 2166pass all tos 16 2167.Ed 2168.It Ar allow-opts 2169By default, packets with IPv4 options or IPv6 hop-by-hop or destination 2170options header are blocked. 2171When 2172.Ar allow-opts 2173is specified for a 2174.Ar pass 2175rule, packets that pass the filter based on that rule (last matching) 2176do so even if they contain options. 2177For packets that match state, the rule that initially created the 2178state is used. 2179The implicit 2180.Ar pass 2181rule, that is used when a packet does not match 2182any rules, does not allow IP options or option headers. 2183Note that IPv6 packets with type 0 routing headers are always dropped. 2184.It Ar label Aq Ar string 2185Adds a label (name) to the rule, which can be used to identify the rule. 2186For instance, 2187pfctl -s labels 2188shows per-rule statistics for rules that have labels. 2189.Pp 2190The following macros can be used in labels: 2191.Pp 2192.Bl -tag -width $srcaddr -compact -offset indent 2193.It Ar $if 2194The interface. 2195.It Ar $srcaddr 2196The source IP address. 2197.It Ar $dstaddr 2198The destination IP address. 2199.It Ar $srcport 2200The source port specification. 2201.It Ar $dstport 2202The destination port specification. 2203.It Ar $proto 2204The protocol name. 2205.It Ar $nr 2206The rule number. 2207.El 2208.Pp 2209For example: 2210.Bd -literal -offset indent 2211ips = \&"{ 1.2.3.4, 1.2.3.5 }\&" 2212pass in proto tcp from any to $ips \e 2213 port > 1023 label \&"$dstaddr:$dstport\&" 2214.Ed 2215.Pp 2216expands to 2217.Bd -literal -offset indent 2218pass in inet proto tcp from any to 1.2.3.4 \e 2219 port > 1023 label \&"1.2.3.4:>1023\&" 2220pass in inet proto tcp from any to 1.2.3.5 \e 2221 port > 1023 label \&"1.2.3.5:>1023\&" 2222.Ed 2223.Pp 2224The macro expansion for the 2225.Ar label 2226directive occurs only at configuration file parse time, not during runtime. 2227.It Ar ridentifier Aq Ar number 2228Add an identifier (number) to the rule, which can be used to correlate the rule 2229to pflog entries, even after ruleset updates. 2230.It Cm max-pkt-rate Ar number Ns / Ns Ar seconds 2231Measure the rate of packets matching the rule and states created by it. 2232When the specified rate is exceeded, the rule stops matching. 2233Only packets in the direction in which the state was created are considered, 2234so that typically requests are counted and replies are not. 2235For example, 2236to pass up to 100 ICMP packets per 10 seconds: 2237.Bd -literal -offset indent 2238block in proto icmp 2239pass in proto icmp max-pkt-rate 100/10 2240.Ed 2241.Pp 2242When the rate is exceeded, all ICMP is blocked until the rate falls below 2243100 per 10 seconds again. 2244.Pp 2245.It Ar max-pkt-size Aq Ar number 2246Limit each packet to be no more than the specified number of bytes. 2247This includes the IP header, but not any layer 2 header. 2248.It Xo Ar queue Aq Ar queue 2249.No \*(Ba ( Aq Ar queue , 2250.Aq Ar queue ) 2251.Xc 2252Packets matching this rule will be assigned to the specified queue. 2253If two queues are given, packets which have a 2254.Em TOS 2255of 2256.Em lowdelay 2257and TCP ACKs with no data payload will be assigned to the second one. 2258See 2259.Sx QUEUEING 2260for setup details. 2261.Pp 2262For example: 2263.Bd -literal -offset indent 2264pass in proto tcp to port 25 queue mail 2265pass in proto tcp to port 22 queue(ssh_bulk, ssh_prio) 2266.Ed 2267.It Cm set prio Ar priority | Pq Ar priority , priority 2268Packets matching this rule will be assigned a specific queueing priority. 2269Priorities are assigned as integers 0 through 7. 2270If the packet is transmitted on a 2271.Xr vlan 4 2272interface, the queueing priority will be written as the priority 2273code point in the 802.1Q VLAN header. 2274If two priorities are given, TCP ACKs with no data payload and packets 2275which have a TOS of 2276.Cm lowdelay 2277will be assigned to the second one. 2278.Pp 2279For example: 2280.Bd -literal -offset indent 2281pass in proto tcp to port 25 set prio 2 2282pass in proto tcp to port 22 set prio (2, 5) 2283.Ed 2284.It Oo Cm \&! Oc Ns Cm received-on Ar interface 2285Only match packets which were received on the specified 2286.Ar interface 2287(or interface group). 2288.Ar any 2289will match any existing interface except loopback ones. 2290.It Ar tag Aq Ar string 2291Packets matching this rule will be tagged with the 2292specified string. 2293The tag acts as an internal marker that can be used to 2294identify these packets later on. 2295This can be used, for example, to provide trust between 2296interfaces and to determine if packets have been 2297processed by translation rules. 2298Tags are 2299.Qq sticky , 2300meaning that the packet will be tagged even if the rule 2301is not the last matching rule. 2302Further matching rules can replace the tag with a 2303new one but will not remove a previously applied tag. 2304A packet is only ever assigned one tag at a time. 2305Packet tagging can be done during 2306.Ar nat , 2307.Ar rdr , 2308.Ar binat 2309or 2310.Ar ether 2311rules in addition to filter rules. 2312Tags take the same macros as labels (see above). 2313.It Ar tagged Aq Ar string 2314Used with filter, translation or scrub rules 2315to specify that packets must already 2316be tagged with the given tag in order to match the rule. 2317.It Ar rtable Aq Ar number 2318Used to select an alternate routing table for the routing lookup. 2319Only effective before the route lookup happened, i.e. when filtering inbound. 2320.It Xo Ar divert-to Aq Ar host 2321.Ar port Aq Ar port 2322.Xc 2323Used to 2324.Xr divert 4 2325packets to the given divert 2326.Ar port . 2327Historically 2328.Ox pf has another meaning for this, and 2329.Fx pf uses 2330this syntax to support 2331.Xr divert 4 instead. Hence, 2332.Ar host 2333has no meaning and can be set to anything like 127.0.0.1. 2334If a packet is re-injected and does not change direction then it will not be 2335re-diverted. 2336.It Ar divert-reply 2337It has no meaning in 2338.Fx pf . 2339.It Ar probability Aq Ar number 2340A probability attribute can be attached to a rule, with a value set between 23410 and 1, bounds not included. 2342In that case, the rule will be honoured using the given probability value 2343only. 2344For example, the following rule will drop 20% of incoming ICMP packets: 2345.Bd -literal -offset indent 2346block in proto icmp probability 20% 2347.Ed 2348.It Ar prio Aq Ar number 2349Only match packets which have the given queueing priority assigned. 2350.El 2351.Sh ROUTING 2352If a packet matches a rule with a route option set, the packet filter will 2353route the packet according to the type of route option. 2354When such a rule creates state, the route option is also applied to all 2355packets matching the same connection. 2356.Bl -tag -width xxxx 2357.It Ar route-to 2358The 2359.Ar route-to 2360option routes the packet to the specified interface with an optional address 2361for the next hop. 2362When a 2363.Ar route-to 2364rule creates state, only packets that pass in the same direction as the 2365filter rule specifies will be routed in this way. 2366Packets passing in the opposite direction (replies) are not affected 2367and are routed normally. 2368.It Ar reply-to 2369The 2370.Ar reply-to 2371option is similar to 2372.Ar route-to , 2373but routes packets that pass in the opposite direction (replies) to the 2374specified interface. 2375Opposite direction is only defined in the context of a state entry, and 2376.Ar reply-to 2377is useful only in rules that create state. 2378It can be used on systems with multiple external connections to 2379route all outgoing packets of a connection through the interface 2380the incoming connection arrived through (symmetric routing enforcement). 2381.It Ar dup-to 2382The 2383.Ar dup-to 2384option creates a duplicate of the packet and routes it like 2385.Ar route-to . 2386The original packet gets routed as it normally would. 2387.El 2388.Sh POOL OPTIONS 2389For 2390.Ar nat 2391and 2392.Ar rdr 2393rules, (as well as for the 2394.Ar route-to , 2395.Ar reply-to 2396and 2397.Ar dup-to 2398rule options) for which there is a single redirection address which has a 2399subnet mask smaller than 32 for IPv4 or 128 for IPv6 (more than one IP 2400address), a variety of different methods for assigning this address can be 2401used: 2402.Bl -tag -width xxxx 2403.It Ar bitmask 2404The 2405.Ar bitmask 2406option applies the network portion of the redirection address to the address 2407to be modified (source with 2408.Ar nat , 2409destination with 2410.Ar rdr ) . 2411.It Ar random 2412The 2413.Ar random 2414option selects an address at random within the defined block of addresses. 2415.It Ar source-hash 2416The 2417.Ar source-hash 2418option uses a hash of the source address to determine the redirection address, 2419ensuring that the redirection address is always the same for a given source. 2420An optional key can be specified after this keyword either in hex or as a 2421string; by default 2422.Xr pfctl 8 2423randomly generates a key for source-hash every time the 2424ruleset is reloaded. 2425.It Ar round-robin 2426The 2427.Ar round-robin 2428option loops through the redirection address(es). 2429.Pp 2430When more than one redirection address is specified, 2431.Ar bitmask 2432is not permitted as a pool type. 2433.It Ar static-port 2434With 2435.Ar nat 2436rules, the 2437.Ar static-port 2438option prevents 2439.Xr pf 4 2440from modifying the source port on TCP and UDP packets. 2441.It Xo Ar map-e-portset Aq Ar psid-offset 2442.No / Aq Ar psid-len 2443.No / Aq Ar psid 2444.Xc 2445With 2446.Ar nat 2447rules, the 2448.Ar map-e-portset 2449option enables the source port translation of MAP-E (RFC 7597) Customer Edge. 2450In order to make the host act as a MAP-E Customer Edge, setting up a tunneling 2451interface and pass rules for encapsulated packets are required in addition 2452to the map-e-portset nat rule. 2453.Pp 2454For example: 2455.Bd -literal -offset indent 2456nat on $gif_mape_if from $int_if:network to any \e 2457 -> $ipv4_mape_src map-e-portset 6/8/0x34 2458.Ed 2459.Pp 2460sets PSID offset 6, PSID length 8, PSID 0x34. 2461.It Ar endpoint-independent 2462With 2463.Ar nat 2464rules, the 2465.Ar endpoint-independent 2466option caues 2467.Xr pf 4 2468to always map connections from a UDP source address and port to the same 2469NAT address and port. 2470This feature implements "full-cone" NAT behavior. 2471.El 2472.Pp 2473Additionally, options 2474.Ar sticky-address 2475and 2476.Ar prefer-ipv6-nexthop 2477can be specified to influence how IP addresses selected from pools. 2478.Pp 2479The 2480.Ar sticky-address 2481option can be specified to help ensure that multiple connections from the 2482same source are mapped to the same redirection address. 2483This option can be used with the 2484.Ar random 2485and 2486.Ar round-robin 2487pool options. 2488Note that by default these associations are destroyed as soon as there are 2489no longer states which refer to them; in order to make the mappings last 2490beyond the lifetime of the states, increase the global options with 2491.Ar set timeout src.track . 2492See 2493.Sx STATEFUL TRACKING OPTIONS 2494for more ways to control the source tracking. 2495.Pp 2496The 2497.Ar prefer-ipv6-nexthop 2498option allows for IPv6 addresses to be used as the nexthop 2499for IPv4 packets routed with the 2500.Ar route-to 2501rule option. If a table is used with IPv4 and IPv6 addresses, first the IPv6 addresses 2502will be used in round-robin fashion, then IPv4 addresses. 2503.Sh STATE MODULATION 2504Much of the security derived from TCP is attributable to how well the 2505initial sequence numbers (ISNs) are chosen. 2506Some popular stack implementations choose 2507.Em very 2508poor ISNs and thus are normally susceptible to ISN prediction exploits. 2509By applying a 2510.Ar modulate state 2511rule to a TCP connection, 2512.Xr pf 4 2513will create a high quality random sequence number for each connection 2514endpoint. 2515.Pp 2516The 2517.Ar modulate state 2518directive implicitly keeps state on the rule and is 2519only applicable to TCP connections. 2520.Pp 2521For instance: 2522.Bd -literal -offset indent 2523block all 2524pass out proto tcp from any to any modulate state 2525pass in proto tcp from any to any port 25 flags S/SFRA modulate state 2526.Ed 2527.Pp 2528Note that modulated connections will not recover when the state table 2529is lost (firewall reboot, flushing the state table, etc...). 2530.Xr pf 4 2531will not be able to infer a connection again after the state table flushes 2532the connection's modulator. 2533When the state is lost, the connection may be left dangling until the 2534respective endpoints time out the connection. 2535It is possible on a fast local network for the endpoints to start an ACK 2536storm while trying to resynchronize after the loss of the modulator. 2537The default 2538.Ar flags 2539settings (or a more strict equivalent) should be used on 2540.Ar modulate state 2541rules to prevent ACK storms. 2542.Pp 2543Note that alternative methods are available 2544to prevent loss of the state table 2545and allow for firewall failover. 2546See 2547.Xr carp 4 2548and 2549.Xr pfsync 4 2550for further information. 2551.Sh SYN PROXY 2552By default, 2553.Xr pf 4 2554passes packets that are part of a 2555.Xr tcp 4 2556handshake between the endpoints. 2557The 2558.Ar synproxy state 2559option can be used to cause 2560.Xr pf 4 2561itself to complete the handshake with the active endpoint, perform a handshake 2562with the passive endpoint, and then forward packets between the endpoints. 2563.Pp 2564No packets are sent to the passive endpoint before the active endpoint has 2565completed the handshake, hence so-called SYN floods with spoofed source 2566addresses will not reach the passive endpoint, as the sender can't complete the 2567handshake. 2568.Pp 2569The proxy is transparent to both endpoints, they each see a single 2570connection from/to the other endpoint. 2571.Xr pf 4 2572chooses random initial sequence numbers for both handshakes. 2573Once the handshakes are completed, the sequence number modulators 2574(see previous section) are used to translate further packets of the 2575connection. 2576.Ar synproxy state 2577includes 2578.Ar modulate state . 2579.Pp 2580Rules with 2581.Ar synproxy 2582will not work if 2583.Xr pf 4 2584operates on a 2585.Xr bridge 4 . 2586Also they act on incoming SYN packets only. 2587.Pp 2588Example: 2589.Bd -literal -offset indent 2590pass in proto tcp from any to any port www synproxy state 2591.Ed 2592.Sh STATEFUL TRACKING OPTIONS 2593A number of options related to stateful tracking can be applied on a 2594per-rule basis. 2595.Ar keep state , 2596.Ar modulate state 2597and 2598.Ar synproxy state 2599support these options, and 2600.Ar keep state 2601must be specified explicitly to apply options to a rule. 2602.Pp 2603.Bl -tag -width xxxx -compact 2604.It Ar max Aq Ar number 2605Limits the number of concurrent states the rule may create. 2606When this limit is reached, further packets that would create 2607state are dropped until existing states time out. 2608.It Ar no-sync 2609Prevent state changes for states created by this rule from appearing on the 2610.Xr pfsync 4 2611interface. 2612.It Xo Aq Ar timeout 2613.Aq Ar seconds 2614.Xc 2615Changes the timeout values used for states created by this rule. 2616For a list of all valid timeout names, see 2617.Sx OPTIONS 2618above. 2619.It Ar sloppy 2620Uses a sloppy TCP connection tracker that does not check sequence 2621numbers at all, which makes insertion and ICMP teardown attacks way 2622easier. 2623This is intended to be used in situations where one does not see all 2624packets of a connection, e.g. in asymmetric routing situations. 2625Cannot be used with modulate or synproxy state. 2626.It Ar pflow 2627States created by this rule are exported on the 2628.Xr pflow 4 2629interface. 2630.It Ar allow-related 2631Automatically allow connections related to this one, regardless of rules that 2632might otherwise affect them. 2633This currently only applies to SCTP multihomed connection. 2634.El 2635.Pp 2636Multiple options can be specified, separated by commas: 2637.Bd -literal -offset indent 2638pass in proto tcp from any to any \e 2639 port www keep state \e 2640 (max 100, source-track rule, max-src-nodes 75, \e 2641 max-src-states 3, tcp.established 60, tcp.closing 5) 2642.Ed 2643.Pp 2644When the 2645.Ar source-track 2646keyword is specified, the number of states per source IP is tracked. 2647.Pp 2648.Bl -tag -width xxxx -compact 2649.It Ar source-track rule 2650The maximum number of states created by this rule is limited by the rule's 2651.Ar max-src-nodes 2652and 2653.Ar max-src-states 2654options. 2655Only state entries created by this particular rule count toward the rule's 2656limits. 2657.It Ar source-track global 2658The number of states created by all rules that use this option is limited. 2659Each rule can specify different 2660.Ar max-src-nodes 2661and 2662.Ar max-src-states 2663options, however state entries created by any participating rule count towards 2664each individual rule's limits. 2665.El 2666.Pp 2667The following limits can be set: 2668.Pp 2669.Bl -tag -width xxxx -compact 2670.It Ar max-src-nodes Aq Ar number 2671Limits the maximum number of source addresses which can simultaneously 2672have state table entries. 2673.It Ar max-src-states Aq Ar number 2674Limits the maximum number of simultaneous state entries that a single 2675source address can create with this rule. 2676.El 2677.Pp 2678For stateful TCP connections, limits on established connections (connections 2679which have completed the TCP 3-way handshake) can also be enforced 2680per source IP. 2681.Pp 2682.Bl -tag -width xxxx -compact 2683.It Ar max-src-conn Aq Ar number 2684Limits the maximum number of simultaneous TCP connections which have 2685completed the 3-way handshake that a single host can make. 2686.It Xo Ar max-src-conn-rate Aq Ar number 2687.No / Aq Ar seconds 2688.Xc 2689Limit the rate of new connections over a time interval. 2690The connection rate is an approximation calculated as a moving average. 2691.El 2692.Pp 2693When one of these limits is reached, further packets that would create 2694state are dropped until existing states time out. 2695.Pp 2696Because the 3-way handshake ensures that the source address is not being 2697spoofed, more aggressive action can be taken based on these limits. 2698With the 2699.Ar overload Aq Ar table 2700state option, source IP addresses which hit either of the limits on 2701established connections will be added to the named table. 2702This table can be used in the ruleset to block further activity from 2703the offending host, redirect it to a tarpit process, or restrict its 2704bandwidth. 2705.Pp 2706The optional 2707.Ar flush 2708keyword kills all states created by the matching rule which originate 2709from the host which exceeds these limits. 2710The 2711.Ar global 2712modifier to the flush command kills all states originating from the 2713offending host, regardless of which rule created the state. 2714.Pp 2715For example, the following rules will protect the webserver against 2716hosts making more than 100 connections in 10 seconds. 2717Any host which connects faster than this rate will have its address added 2718to the 2719.Aq bad_hosts 2720table and have all states originating from it flushed. 2721Any new packets arriving from this host will be dropped unconditionally 2722by the block rule. 2723.Bd -literal -offset indent 2724block quick from <bad_hosts> 2725pass in on $ext_if proto tcp to $webserver port www keep state \e 2726 (max-src-conn-rate 100/10, overload <bad_hosts> flush global) 2727.Ed 2728.Sh OPERATING SYSTEM FINGERPRINTING 2729Passive OS Fingerprinting is a mechanism to inspect nuances of a TCP 2730connection's initial SYN packet and guess at the host's operating system. 2731Unfortunately these nuances are easily spoofed by an attacker so the 2732fingerprint is not useful in making security decisions. 2733But the fingerprint is typically accurate enough to make policy decisions 2734upon. 2735.Pp 2736The fingerprints may be specified by operating system class, by 2737version, or by subtype/patchlevel. 2738The class of an operating system is typically the vendor or genre 2739and would be 2740.Ox 2741for the 2742.Xr pf 4 2743firewall itself. 2744The version of the oldest available 2745.Ox 2746release on the main FTP site 2747would be 2.6 and the fingerprint would be written 2748.Pp 2749.Dl \&"OpenBSD 2.6\&" 2750.Pp 2751The subtype of an operating system is typically used to describe the 2752patchlevel if that patch led to changes in the TCP stack behavior. 2753In the case of 2754.Ox , 2755the only subtype is for a fingerprint that was 2756normalized by the 2757.Ar no-df 2758scrub option and would be specified as 2759.Pp 2760.Dl \&"OpenBSD 3.3 no-df\&" 2761.Pp 2762Fingerprints for most popular operating systems are provided by 2763.Xr pf.os 5 . 2764Once 2765.Xr pf 4 2766is running, a complete list of known operating system fingerprints may 2767be listed by running: 2768.Pp 2769.Dl # pfctl -so 2770.Pp 2771Filter rules can enforce policy at any level of operating system specification 2772assuming a fingerprint is present. 2773Policy could limit traffic to approved operating systems or even ban traffic 2774from hosts that aren't at the latest service pack. 2775.Pp 2776The 2777.Ar unknown 2778class can also be used as the fingerprint which will match packets for 2779which no operating system fingerprint is known. 2780.Pp 2781Examples: 2782.Bd -literal -offset indent 2783pass out proto tcp from any os OpenBSD 2784block out proto tcp from any os Doors 2785block out proto tcp from any os "Doors PT" 2786block out proto tcp from any os "Doors PT SP3" 2787block out from any os "unknown" 2788pass on lo0 proto tcp from any os "OpenBSD 3.3 lo0" 2789.Ed 2790.Pp 2791Operating system fingerprinting is limited only to the TCP SYN packet. 2792This means that it will not work on other protocols and will not match 2793a currently established connection. 2794.Pp 2795Caveat: operating system fingerprints are occasionally wrong. 2796There are three problems: an attacker can trivially craft packets to 2797appear as any operating system; 2798an operating system patch could change the stack behavior and no fingerprints 2799will match it until the database is updated; 2800and multiple operating systems may have the same fingerprint. 2801.Sh BLOCKING SPOOFED TRAFFIC 2802"Spoofing" is the faking of IP addresses, typically for malicious 2803purposes. 2804The 2805.Ar antispoof 2806directive expands to a set of filter rules which will block all 2807traffic with a source IP from the network(s) directly connected 2808to the specified interface(s) from entering the system through 2809any other interface. 2810.Pp 2811For example, the line 2812.Bd -literal -offset indent 2813antispoof for lo0 2814.Ed 2815.Pp 2816expands to 2817.Bd -literal -offset indent 2818block drop in on ! lo0 inet from 127.0.0.1/8 to any 2819block drop in on ! lo0 inet6 from ::1 to any 2820.Ed 2821.Pp 2822For non-loopback interfaces, there are additional rules to block incoming 2823packets with a source IP address identical to the interface's IP(s). 2824For example, assuming the interface wi0 had an IP address of 10.0.0.1 and a 2825netmask of 255.255.255.0, 2826the line 2827.Bd -literal -offset indent 2828antispoof for wi0 inet 2829.Ed 2830.Pp 2831expands to 2832.Bd -literal -offset indent 2833block drop in on ! wi0 inet from 10.0.0.0/24 to any 2834block drop in inet from 10.0.0.1 to any 2835.Ed 2836.Pp 2837Caveat: Rules created by the 2838.Ar antispoof 2839directive interfere with packets sent over loopback interfaces 2840to local addresses. 2841One should pass these explicitly. 2842.Sh FRAGMENT HANDLING 2843The size of IP datagrams (packets) can be significantly larger than the 2844maximum transmission unit (MTU) of the network. 2845In cases when it is necessary or more efficient to send such large packets, 2846the large packet will be fragmented into many smaller packets that will each 2847fit onto the wire. 2848Unfortunately for a firewalling device, only the first logical fragment will 2849contain the necessary header information for the subprotocol that allows 2850.Xr pf 4 2851to filter on things such as TCP ports or to perform NAT. 2852.Pp 2853Besides the use of 2854.Ar set reassemble 2855option or 2856.Ar scrub 2857rules as described in 2858.Sx TRAFFIC NORMALIZATION 2859above, there are three options for handling fragments in the packet filter. 2860.Pp 2861One alternative is to filter individual fragments with filter rules. 2862If no 2863.Ar scrub 2864rule applies to a fragment or 2865.Ar set reassemble 2866is set to 2867.Cm no 2868, it is passed to the filter. 2869Filter rules with matching IP header parameters decide whether the 2870fragment is passed or blocked, in the same way as complete packets 2871are filtered. 2872Without reassembly, fragments can only be filtered based on IP header 2873fields (source/destination address, protocol), since subprotocol header 2874fields are not available (TCP/UDP port numbers, ICMP code/type). 2875The 2876.Ar fragment 2877option can be used to restrict filter rules to apply only to 2878fragments, but not complete packets. 2879Filter rules without the 2880.Ar fragment 2881option still apply to fragments, if they only specify IP header fields. 2882For instance, the rule 2883.Bd -literal -offset indent 2884pass in proto tcp from any to any port 80 2885.Ed 2886.Pp 2887never applies to a fragment, even if the fragment is part of a TCP 2888packet with destination port 80, because without reassembly this information 2889is not available for each fragment. 2890This also means that fragments cannot create new or match existing 2891state table entries, which makes stateful filtering and address 2892translation (NAT, redirection) for fragments impossible. 2893.Pp 2894It's also possible to reassemble only certain fragments by specifying 2895source or destination addresses or protocols as parameters in 2896.Ar scrub 2897rules. 2898.Pp 2899In most cases, the benefits of reassembly outweigh the additional 2900memory cost, and it's recommended to use 2901.Ar set reassemble 2902option or 2903.Ar scrub 2904rules with the 2905.Ar fragment reassemble 2906modifier to reassemble 2907all fragments. 2908.Pp 2909The memory allocated for fragment caching can be limited using 2910.Xr pfctl 8 . 2911Once this limit is reached, fragments that would have to be cached 2912are dropped until other entries time out. 2913The timeout value can also be adjusted. 2914.Pp 2915When forwarding reassembled IPv6 packets, pf refragments them with 2916the original maximum fragment size. 2917This allows the sender to determine the optimal fragment size by 2918path MTU discovery. 2919.Sh ANCHORS 2920Besides the main ruleset, 2921.Xr pfctl 8 2922can load rulesets into 2923.Ar anchor 2924attachment points. 2925An 2926.Ar anchor 2927is a container that can hold rules, address tables, and other anchors. 2928.Pp 2929An 2930.Ar anchor 2931has a name which specifies the path where 2932.Xr pfctl 8 2933can be used to access the anchor to perform operations on it, such as 2934attaching child anchors to it or loading rules into it. 2935Anchors may be nested, with components separated by 2936.Sq / 2937characters, similar to how file system hierarchies are laid out. 2938The main ruleset is actually the default anchor, so filter and 2939translation rules, for example, may also be contained in any anchor. 2940.Pp 2941An anchor can reference another 2942.Ar anchor 2943attachment point 2944using the following kinds 2945of rules: 2946.Bl -tag -width xxxx 2947.It Ar nat-anchor Aq Ar name 2948Evaluates the 2949.Ar nat 2950rules in the specified 2951.Ar anchor . 2952.It Ar rdr-anchor Aq Ar name 2953Evaluates the 2954.Ar rdr 2955rules in the specified 2956.Ar anchor . 2957.It Ar binat-anchor Aq Ar name 2958Evaluates the 2959.Ar binat 2960rules in the specified 2961.Ar anchor . 2962.It Ar anchor Aq Ar name 2963Evaluates the filter rules in the specified 2964.Ar anchor . 2965.It Xo Ar load anchor 2966.Aq Ar name 2967.Ar from Aq Ar file 2968.Xc 2969Loads the rules from the specified file into the 2970anchor 2971.Ar name . 2972.El 2973.Pp 2974When evaluation of the main ruleset reaches an 2975.Ar anchor 2976rule, 2977.Xr pf 4 2978will proceed to evaluate all rules specified in that anchor. 2979.Pp 2980Matching filter and translation rules marked with the 2981.Ar quick 2982option are final and abort the evaluation of the rules in other 2983anchors and the main ruleset. 2984If the 2985.Ar anchor 2986itself is marked with the 2987.Ar quick 2988option, 2989ruleset evaluation will terminate when the anchor is exited if the packet is 2990matched by any rule within the anchor. 2991.Pp 2992.Ar anchor 2993rules are evaluated relative to the anchor in which they are contained. 2994For example, all 2995.Ar anchor 2996rules specified in the main ruleset will reference anchor 2997attachment points underneath the main ruleset, and 2998.Ar anchor 2999rules specified in a file loaded from a 3000.Ar load anchor 3001rule will be attached under that anchor point. 3002.Pp 3003Rules may be contained in 3004.Ar anchor 3005attachment points which do not contain any rules when the main ruleset 3006is loaded, and later such anchors can be manipulated through 3007.Xr pfctl 8 3008without reloading the main ruleset or other anchors. 3009For example, 3010.Bd -literal -offset indent 3011ext_if = \&"kue0\&" 3012block on $ext_if all 3013anchor spam 3014pass out on $ext_if all 3015pass in on $ext_if proto tcp from any \e 3016 to $ext_if port smtp 3017.Ed 3018.Pp 3019blocks all packets on the external interface by default, then evaluates 3020all rules in the 3021.Ar anchor 3022named "spam", and finally passes all outgoing connections and 3023incoming connections to port 25. 3024.Bd -literal -offset indent 3025# echo \&"block in quick from 1.2.3.4 to any\&" \&| \e 3026 pfctl -a spam -f - 3027.Ed 3028.Pp 3029This loads a single rule into the 3030.Ar anchor , 3031which blocks all packets from a specific address. 3032.Pp 3033The anchor can also be populated by adding a 3034.Ar load anchor 3035rule after the 3036.Ar anchor 3037rule: 3038.Bd -literal -offset indent 3039anchor spam 3040load anchor spam from "/etc/pf-spam.conf" 3041.Ed 3042.Pp 3043When 3044.Xr pfctl 8 3045loads 3046.Nm pf.conf , 3047it will also load all the rules from the file 3048.Pa /etc/pf-spam.conf 3049into the anchor. 3050.Pp 3051Optionally, 3052.Ar anchor 3053rules can specify packet filtering parameters using the same syntax as 3054filter rules. 3055When parameters are used, the 3056.Ar anchor 3057rule is only evaluated for matching packets. 3058This allows conditional evaluation of anchors, like: 3059.Bd -literal -offset indent 3060block on $ext_if all 3061anchor spam proto tcp from any to any port smtp 3062pass out on $ext_if all 3063pass in on $ext_if proto tcp from any to $ext_if port smtp 3064.Ed 3065.Pp 3066The rules inside 3067.Ar anchor 3068spam are only evaluated for 3069.Ar tcp 3070packets with destination port 25. 3071Hence, 3072.Bd -literal -offset indent 3073# echo \&"block in quick from 1.2.3.4 to any" \&| \e 3074 pfctl -a spam -f - 3075.Ed 3076.Pp 3077will only block connections from 1.2.3.4 to port 25. 3078.Pp 3079Anchors may end with the asterisk 3080.Pq Sq * 3081character, which signifies that all anchors attached at that point 3082should be evaluated in the alphabetical ordering of their anchor name. 3083For example, 3084.Bd -literal -offset indent 3085anchor "spam/*" 3086.Ed 3087.Pp 3088will evaluate each rule in each anchor attached to the 3089.Li spam 3090anchor. 3091Note that it will only evaluate anchors that are directly attached to the 3092.Li spam 3093anchor, and will not descend to evaluate anchors recursively. 3094.Pp 3095Since anchors are evaluated relative to the anchor in which they are 3096contained, there is a mechanism for accessing the parent and ancestor 3097anchors of a given anchor. 3098Similar to file system path name resolution, if the sequence 3099.Dq .. 3100appears as an anchor path component, the parent anchor of the current 3101anchor in the path evaluation at that point will become the new current 3102anchor. 3103As an example, consider the following: 3104.Bd -literal -offset indent 3105# echo ' anchor "spam/allowed" ' | pfctl -f - 3106# echo -e ' anchor "../banned" \en pass' | \e 3107 pfctl -a spam/allowed -f - 3108.Ed 3109.Pp 3110Evaluation of the main ruleset will lead into the 3111.Li spam/allowed 3112anchor, which will evaluate the rules in the 3113.Li spam/banned 3114anchor, if any, before finally evaluating the 3115.Ar pass 3116rule. 3117.Pp 3118An 3119.Ar anchor 3120rule can also contain a filter ruleset in a brace-delimited block. 3121In that case, no separate loading of rules into the anchor 3122is required. 3123Brace delimited blocks may contain rules or other brace-delimited blocks. 3124When an anchor is populated this way, the anchor name becomes optional. 3125.Bd -literal -offset indent 3126anchor "external" on $ext_if { 3127 block 3128 anchor out { 3129 pass proto tcp from any to port { 25, 80, 443 } 3130 } 3131 pass in proto tcp to any port 22 3132} 3133.Ed 3134.Pp 3135Since the parser specification for anchor names is a string, any 3136reference to an anchor name containing 3137.Sq / 3138characters will require double quote 3139.Pq Sq \&" 3140characters around the anchor name. 3141.Sh SCTP CONSIDERATIONS 3142.Xr pf 4 3143supports 3144.Xr sctp 4 3145connections. 3146It can match ports, track state and NAT SCTP traffic. 3147However, it will not alter port numbers during nat or rdr translations. 3148Doing so would break SCTP multihoming. 3149.Sh TRANSLATION EXAMPLES 3150This example maps incoming requests on port 80 to port 8080, on 3151which a daemon is running (because, for example, it is not run as root, 3152and therefore lacks permission to bind to port 80). 3153.Bd -literal -offset indent 3154# use a macro for the interface name, so it can be changed easily 3155ext_if = \&"ne3\&" 3156 3157# map daemon on 8080 to appear to be on 80 3158match in on $ext_if proto tcp from any to any port 80 \e 3159 rdr-to 127.0.0.1 port 8080 3160.Ed 3161.Pp 3162If a 3163.Ar pass 3164rule is used with the 3165.Ar quick 3166modifier, packets matching the translation rule are passed without 3167inspecting subsequent filter rules: 3168.Bd -literal -offset indent 3169pass in quick on $ext_if proto tcp from any to any port 80 \e 3170 rdr-to 127.0.0.1 port 8080 3171.Ed 3172.Pp 3173In the example below, vlan12 is configured as 192.168.168.1; 3174the machine translates all packets coming from 192.168.168.0/24 to 204.92.77.111 3175when they are going out any interface except vlan12. 3176This has the net effect of making traffic from the 192.168.168.0/24 3177network appear as though it is the Internet routable address 3178204.92.77.111 to nodes behind any interface on the router except 3179for the nodes on vlan12. 3180(Thus, 192.168.168.1 can talk to the 192.168.168.0/24 nodes.) 3181.Bd -literal -offset indent 3182match out on ! vlan12 from 192.168.168.0/24 to any nat-to 204.92.77.111 3183.Ed 3184.Pp 3185This longer example uses both a NAT and a redirection. 3186The external interface has the address 157.161.48.183. 3187On localhost, we are running 3188.Xr ftp-proxy 8 , 3189waiting for FTP sessions to be redirected to it. 3190The three mandatory anchors for 3191.Xr ftp-proxy 8 3192are omitted from this example; see the 3193.Xr ftp-proxy 8 3194manpage. 3195.Bd -literal -offset indent 3196# NAT 3197# Translate outgoing packets' source addresses (any protocol). 3198# In this case, any address but the gateway's external address is mapped. 3199pass out on $ext_if inet from ! ($ext_if) to any nat-to ($ext_if) 3200 3201# NAT PROXYING 3202# Map outgoing packets' source port to an assigned proxy port instead of 3203# an arbitrary port. 3204# In this case, proxy outgoing isakmp with port 500 on the gateway. 3205pass out on $ext_if inet proto udp from any port = isakmp to any \e 3206 nat-to ($ext_if) port 500 3207 3208# BINAT 3209# Translate outgoing packets' source address (any protocol). 3210# Translate incoming packets' destination address to an internal machine 3211# (bidirectional). 3212pass on $ext_if from 10.1.2.150 to any binat-to $ext_if 3213 3214# Translate packets arriving on $peer_if addressed to 172.22.16.0/20 3215# to the corresponding address in 172.21.16.0/20 (bidirectional). 3216pass on $peer_if from 172.21.16.0/20 to any binat-to 172.22.16.0/20 3217 3218# RDR 3219# Translate incoming packets' destination addresses. 3220# As an example, redirect a TCP and UDP port to an internal machine. 3221pass in on $ext_if inet proto tcp from any to ($ext_if) port 8080 \e 3222 rdr-to 10.1.2.151 port 22 3223pass in on $ext_if inet proto udp from any to ($ext_if) port 8080 \e 3224 rdr-to 10.1.2.151 port 53 3225 3226# RDR 3227# Translate outgoing ftp control connections to send them to localhost 3228# for proxying with ftp-proxy(8) running on port 8021. 3229pass in on $int_if proto tcp from any to any port 21 \e 3230 rdr-to 127.0.0.1 port 8021 3231.Ed 3232.Pp 3233In this example, a NAT gateway is set up to translate internal addresses 3234using a pool of public addresses (192.0.2.16/28) and to redirect 3235incoming web server connections to a group of web servers on the internal 3236network. 3237.Bd -literal -offset indent 3238# NAT LOAD BALANCE 3239# Translate outgoing packets' source addresses using an address pool. 3240# A given source address is always translated to the same pool address by 3241# using the source-hash keyword. 3242pass out on $ext_if inet from any to any nat-to 192.0.2.16/28 source-hash 3243 3244# RDR ROUND ROBIN 3245# Translate incoming web server connections to a group of web servers on 3246# the internal network. 3247pass in on $ext_if proto tcp from any to any port 80 \e 3248 rdr-to { 10.1.2.155, 10.1.2.160, 10.1.2.161 } round-robin 3249.Ed 3250.Sh COMPATIBILITY TRANSLATION EXAMPLES 3251In the example below, the machine sits between a fake internal 144.19.74.* 3252network, and a routable external IP of 204.92.77.100. 3253The 3254.Ar no nat 3255rule excludes protocol AH from being translated. 3256.Bd -literal -offset indent 3257# NAT 3258no nat on $ext_if proto ah from 144.19.74.0/24 to any 3259nat on $ext_if from 144.19.74.0/24 to any -> 204.92.77.100 3260.Ed 3261.Pp 3262In the example below, packets bound for one specific server, as well as those 3263generated by the sysadmins are not proxied; all other connections are. 3264.Bd -literal -offset indent 3265# RDR 3266no rdr on $int_if proto { tcp, udp } from any to $server port 80 3267no rdr on $int_if proto { tcp, udp } from $sysadmins to any port 80 3268rdr on $int_if proto { tcp, udp } from any to any port 80 \e 3269 -> 127.0.0.1 port 80 3270.Ed 3271.Sh FILTER EXAMPLES 3272.Bd -literal -offset indent 3273# The external interface is kue0 3274# (157.161.48.183, the only routable address) 3275# and the private network is 10.0.0.0/8, for which we are doing NAT. 3276 3277# Reassemble incoming traffic 3278set reassemble yes 3279 3280# use a macro for the interface name, so it can be changed easily 3281ext_if = \&"kue0\&" 3282 3283# block and log everything by default 3284block return log on $ext_if all 3285 3286# block anything coming from source we have no back routes for 3287block in from no-route to any 3288 3289# block packets whose ingress interface does not match the one in 3290# the route back to their source address 3291block in from urpf-failed to any 3292 3293# block and log outgoing packets that do not have our address as source, 3294# they are either spoofed or something is misconfigured (NAT disabled, 3295# for instance), we want to be nice and do not send out garbage. 3296block out log quick on $ext_if from ! 157.161.48.183 to any 3297 3298# silently drop broadcasts (cable modem noise) 3299block in quick on $ext_if from any to 255.255.255.255 3300 3301# block and log incoming packets from reserved address space and invalid 3302# addresses, they are either spoofed or misconfigured, we cannot reply to 3303# them anyway (hence, no return-rst). 3304block in log quick on $ext_if from { 10.0.0.0/8, 172.16.0.0/12, \e 3305 192.168.0.0/16, 255.255.255.255/32 } to any 3306 3307# ICMP 3308 3309# pass out/in certain ICMP queries and keep state (ping) 3310# state matching is done on host addresses and ICMP id (not type/code), 3311# so replies (like 0/0 for 8/0) will match queries 3312# ICMP error messages (which always refer to a TCP/UDP packet) are 3313# handled by the TCP/UDP states 3314pass on $ext_if inet proto icmp all icmp-type 8 code 0 3315 3316# UDP 3317 3318# pass out all UDP connections and keep state 3319pass out on $ext_if proto udp all 3320 3321# pass in certain UDP connections and keep state (DNS) 3322pass in on $ext_if proto udp from any to any port domain 3323 3324# TCP 3325 3326# pass out all TCP connections and modulate state 3327pass out on $ext_if proto tcp all modulate state 3328 3329# pass in certain TCP connections and keep state (SSH, SMTP, DNS, IDENT) 3330pass in on $ext_if proto tcp from any to any port { ssh, smtp, domain, \e 3331 auth } 3332 3333# Do not allow Windows 9x SMTP connections since they are typically 3334# a viral worm. Alternately we could limit these OSes to 1 connection each. 3335block in on $ext_if proto tcp from any os {"Windows 95", "Windows 98"} \e 3336 to any port smtp 3337 3338# IPv6 3339# pass in/out all IPv6 traffic: note that we have to enable this in two 3340# different ways, on both our physical interface and our tunnel 3341pass quick on gif0 inet6 3342pass quick on $ext_if proto ipv6 3343 3344# Packet Tagging 3345 3346# three interfaces: $int_if, $ext_if, and $wifi_if (wireless). NAT is 3347# being done on $ext_if for all outgoing packets. tag packets in on 3348# $int_if and pass those tagged packets out on $ext_if. all other 3349# outgoing packets (i.e., packets from the wireless network) are only 3350# permitted to access port 80. 3351 3352pass in on $int_if from any to any tag INTNET 3353pass in on $wifi_if from any to any 3354 3355block out on $ext_if from any to any 3356pass out quick on $ext_if tagged INTNET 3357pass out on $ext_if proto tcp from any to any port 80 3358 3359# tag incoming packets as they are redirected to spamd(8). use the tag 3360# to pass those packets through the packet filter. 3361 3362rdr on $ext_if inet proto tcp from <spammers> to port smtp \e 3363 tag SPAMD -> 127.0.0.1 port spamd 3364 3365block in on $ext_if 3366pass in on $ext_if inet proto tcp tagged SPAMD 3367.Ed 3368.Pp 3369In the example below, a router handling both address families 3370translates an internal IPv4 subnet to IPv6 using the well-known 337164:ff9b::/96 prefix: 3372.Bd -literal -offset 4n 3373pass in on $v4_if inet af-to inet6 from ($v6_if) to 64:ff9b::/96 3374.Ed 3375.Pp 3376Paired with the example above, the example below can be used on 3377another router handling both address families to translate back 3378to IPv4: 3379.Bd -literal -offset 4n 3380pass in on $v6_if inet6 to 64:ff9b::/96 af-to inet from ($v4_if) 3381.Ed 3382.Sh GRAMMAR 3383Syntax for 3384.Nm 3385in BNF: 3386.Bd -literal 3387line = ( option | ether-rule | pf-rule | nat-rule | binat-rule | 3388 rdr-rule | antispoof-rule | altq-rule | queue-rule | 3389 trans-anchors | anchor-rule | anchor-close | load-anchor | 3390 table-rule | include ) 3391 3392option = "set" ( [ "timeout" ( timeout | "{" timeout-list "}" ) ] | 3393 [ "ruleset-optimization" [ "none" | "basic" | "profile" ]] | 3394 [ "optimization" [ "default" | "normal" | 3395 "high-latency" | "satellite" | 3396 "aggressive" | "conservative" ] ] 3397 [ "limit" ( limit-item | "{" limit-list "}" ) ] | 3398 [ "loginterface" ( interface-name | "none" ) ] | 3399 [ "block-policy" ( "drop" | "return" ) ] | 3400 [ "state-policy" ( "if-bound" | "floating" ) ] 3401 [ "state-defaults" state-opts ] 3402 [ "require-order" ( "yes" | "no" ) ] 3403 [ "fingerprints" filename ] | 3404 [ "skip on" ifspec ] | 3405 [ "debug" ( "none" | "urgent" | "misc" | "loud" ) ] 3406 [ "keepcounters" ] ) 3407 3408ether-rule = "ether" etheraction [ ( "in" | "out" ) ] 3409 [ "quick" ] [ "on" ifspec ] [ "bridge-to" interface-name ] 3410 [ etherprotospec ] [ etherhosts ] [ "l3" hosts ] 3411 [ etherfilteropt-list ] 3412 3413pf-rule = action [ ( "in" | "out" ) ] 3414 [ "log" [ "(" logopts ")"] ] [ "quick" ] 3415 [ "on" ifspec ] [ route ] [ af ] [ protospec ] 3416 [ hosts ] [ filteropt-list ] 3417 3418logopts = logopt [ "," logopts ] 3419logopt = "all" | "matches" | "user" | "to" interface-name 3420 3421etherfilteropt-list = etherfilteropt-list etherfilteropt | etherfilteropt 3422etherfilteropt = "tag" string | "tagged" string | "queue" ( string ) | 3423 "ridentifier" number | "label" string 3424 3425filteropt-list = filteropt-list filteropt | filteropt 3426filteropt = user | group | flags | icmp-type | icmp6-type | "tos" tos | 3427 "af-to" af "from" ( redirhost | "{" redirhost-list "}" ) 3428 [ "to" ( redirhost | "{" redirhost-list "}" ) ] | 3429 ( "no" | "keep" | "modulate" | "synproxy" ) "state" 3430 [ "(" state-opts ")" ] | 3431 "fragment" | "no-df" | "min-ttl" number | "set-tos" tos | 3432 "max-mss" number | "random-id" | "reassemble tcp" | 3433 fragmentation | "allow-opts" | 3434 "label" string | "tag" string | [ "!" ] "tagged" string | 3435 "max-pkt-rate" number "/" seconds | 3436 "set prio" ( number | "(" number [ [ "," ] number ] ")" ) | 3437 "max-pkt-size" number | 3438 "queue" ( string | "(" string [ [ "," ] string ] ")" ) | 3439 "rtable" number | "probability" number"%" | "prio" number | 3440 "dnpipe" ( number | "(" number "," number ")" ) | 3441 "dnqueue" ( number | "(" number "," number ")" ) | 3442 "ridentifier" number | 3443 [ ! ] "received-on" ( interface-name | interface-group ) 3444 3445nat-rule = [ "no" ] "nat" [ "pass" [ "log" [ "(" logopts ")" ] ] ] 3446 [ "on" ifspec ] [ af ] 3447 [ protospec ] hosts [ "tag" string ] [ "tagged" string ] 3448 [ "->" ( redirhost | "{" redirhost-list "}" ) 3449 [ portspec ] [ pooltype ] [ "static-port" ] 3450 [ "map-e-portset" number "/" number "/" number ] ] 3451 3452binat-rule = [ "no" ] "binat" [ "pass" [ "log" [ "(" logopts ")" ] ] ] 3453 [ "on" interface-name ] [ af ] 3454 [ "proto" ( proto-name | proto-number ) ] 3455 "from" address [ "/" mask-bits ] "to" ipspec 3456 [ "tag" string ] [ "tagged" string ] 3457 [ "->" address [ "/" mask-bits ] ] 3458 3459rdr-rule = [ "no" ] "rdr" [ "pass" [ "log" [ "(" logopts ")" ] ] ] 3460 [ "on" ifspec ] [ af ] 3461 [ protospec ] hosts [ "tag" string ] [ "tagged" string ] 3462 [ "->" ( redirhost | "{" redirhost-list "}" ) 3463 [ portspec ] [ pooltype ] ] 3464 3465antispoof-rule = "antispoof" [ "log" ] [ "quick" ] 3466 "for" ifspec [ af ] [ "label" string ] 3467 [ "ridentifier" number ] 3468 3469table-rule = "table" "<" string ">" [ tableopts-list ] 3470tableopts-list = tableopts-list tableopts | tableopts 3471tableopts = "persist" | "const" | "counters" | "file" string | 3472 "{" [ tableaddr-list ] "}" 3473tableaddr-list = tableaddr-list [ "," ] tableaddr-spec | tableaddr-spec 3474tableaddr-spec = [ "!" ] tableaddr [ "/" mask-bits ] 3475tableaddr = hostname | ifspec | "self" | 3476 ipv4-dotted-quad | ipv6-coloned-hex 3477 3478altq-rule = "altq on" interface-name queueopts-list 3479 "queue" subqueue 3480queue-rule = "queue" string [ "on" interface-name ] queueopts-list 3481 subqueue 3482 3483anchor-rule = "anchor" [ string ] [ ( "in" | "out" ) ] [ "on" ifspec ] 3484 [ af ] [ protospec ] [ hosts ] [ filteropt-list ] [ "{" ] 3485 3486anchor-close = "}" 3487 3488trans-anchors = ( "nat-anchor" | "rdr-anchor" | "binat-anchor" ) string 3489 [ "on" ifspec ] [ af ] [ "proto" ] [ protospec ] [ hosts ] 3490 3491load-anchor = "load anchor" string "from" filename 3492 3493queueopts-list = queueopts-list queueopts | queueopts 3494queueopts = [ "bandwidth" bandwidth-spec ] | 3495 [ "qlimit" number ] | [ "tbrsize" number ] | 3496 [ "priority" number ] | [ schedulers ] 3497schedulers = ( cbq-def | priq-def | hfsc-def ) 3498bandwidth-spec = "number" ( "b" | "Kb" | "Mb" | "Gb" | "%" ) 3499 3500etheraction = "pass" | "block" 3501action = "pass" | "match" | "block" [ return ] | [ "no" ] "scrub" 3502return = "drop" | "return" | "return-rst" [ "( ttl" number ")" ] | 3503 "return-icmp" [ "(" icmpcode [ [ "," ] icmp6code ] ")" ] | 3504 "return-icmp6" [ "(" icmp6code ")" ] 3505icmpcode = ( icmp-code-name | icmp-code-number ) 3506icmp6code = ( icmp6-code-name | icmp6-code-number ) 3507 3508ifspec = ( [ "!" ] ( interface-name | interface-group ) ) | 3509 "{" interface-list "}" 3510interface-list = [ "!" ] ( interface-name | interface-group ) 3511 [ [ "," ] interface-list ] 3512route = ( "route-to" | "reply-to" | "dup-to" ) 3513 ( routehost | "{" routehost-list "}" ) 3514 [ pooltype ] 3515af = "inet" | "inet6" 3516 3517etherprotospec = "proto" ( proto-number | "{" etherproto-list "}" ) 3518etherproto-list = proto-number [ [ "," ] etherproto-list ] 3519protospec = "proto" ( proto-name | proto-number | 3520 "{" proto-list "}" ) 3521proto-list = ( proto-name | proto-number ) [ [ "," ] proto-list ] 3522 3523etherhosts = "from" macaddress "to" macaddress 3524macaddress = mac | mac "/" masklen | mac "&" mask 3525 3526hosts = "all" | 3527 "from" ( "any" | "no-route" | "urpf-failed" | "self" | host | 3528 "{" host-list "}" ) [ port ] [ os ] 3529 "to" ( "any" | "no-route" | "self" | host | 3530 "{" host-list "}" ) [ port ] 3531 3532ipspec = "any" | host | "{" host-list "}" 3533host = [ "!" ] ( address [ "/" mask-bits ] | "<" string ">" ) 3534redirhost = address [ "/" mask-bits ] 3535routehost = "(" interface-name [ address [ "/" mask-bits ] ] ")" 3536address = ( interface-name | interface-group | 3537 "(" ( interface-name | interface-group ) ")" | 3538 hostname | ipv4-dotted-quad | ipv6-coloned-hex ) 3539host-list = host [ [ "," ] host-list ] 3540redirhost-list = redirhost [ [ "," ] redirhost-list ] 3541routehost-list = routehost [ [ "," ] routehost-list ] 3542 3543port = "port" ( unary-op | binary-op | "{" op-list "}" ) 3544portspec = "port" ( number | name ) [ ":" ( "*" | number | name ) ] 3545os = "os" ( os-name | "{" os-list "}" ) 3546user = "user" ( unary-op | binary-op | "{" op-list "}" ) 3547group = "group" ( unary-op | binary-op | "{" op-list "}" ) 3548 3549unary-op = [ "=" | "!=" | "<" | "<=" | ">" | ">=" ] 3550 ( name | number ) 3551binary-op = number ( "<>" | "><" | ":" ) number 3552op-list = ( unary-op | binary-op ) [ [ "," ] op-list ] 3553 3554os-name = operating-system-name 3555os-list = os-name [ [ "," ] os-list ] 3556 3557flags = "flags" ( [ flag-set ] "/" flag-set | "any" ) 3558flag-set = [ "F" ] [ "S" ] [ "R" ] [ "P" ] [ "A" ] [ "U" ] [ "E" ] 3559 [ "W" ] 3560 3561icmp-type = "icmp-type" ( icmp-type-code | "{" icmp-list "}" ) 3562icmp6-type = "icmp6-type" ( icmp-type-code | "{" icmp-list "}" ) 3563icmp-type-code = ( icmp-type-name | icmp-type-number ) 3564 [ "code" ( icmp-code-name | icmp-code-number ) ] 3565icmp-list = icmp-type-code [ [ "," ] icmp-list ] 3566 3567tos = ( "lowdelay" | "throughput" | "reliability" | 3568 [ "0x" ] number ) 3569 3570state-opts = state-opt [ [ "," ] state-opts ] 3571state-opt = ( "max" number | "no-sync" | timeout | "sloppy" | 3572 "source-track" [ ( "rule" | "global" ) ] | 3573 "max-src-nodes" number | "max-src-states" number | 3574 "max-src-conn" number | 3575 "max-src-conn-rate" number "/" number | 3576 "overload" "<" string ">" [ "flush" ] | 3577 "if-bound" | "floating" | "pflow" ) 3578 3579fragmentation = [ "fragment reassemble" ] 3580 3581timeout-list = timeout [ [ "," ] timeout-list ] 3582timeout = ( "tcp.first" | "tcp.opening" | "tcp.established" | 3583 "tcp.closing" | "tcp.finwait" | "tcp.closed" | 3584 "sctp.first" | "sctp.opening" | "sctp.established" | 3585 "sctp.closing" | "sctp.closed" | 3586 "udp.first" | "udp.single" | "udp.multiple" | 3587 "icmp.first" | "icmp.error" | 3588 "other.first" | "other.single" | "other.multiple" | 3589 "frag" | "interval" | "src.track" | 3590 "adaptive.start" | "adaptive.end" ) number 3591 3592limit-list = limit-item [ [ "," ] limit-list ] 3593limit-item = ( "states" | "frags" | "src-nodes" ) number 3594 3595pooltype = ( "bitmask" | "random" | 3596 "source-hash" [ ( hex-key | string-key ) ] | 3597 "round-robin" ) [ sticky-address | prefer-ipv6-nexthop ] 3598 3599subqueue = string | "{" queue-list "}" 3600queue-list = string [ [ "," ] string ] 3601cbq-def = "cbq" [ "(" cbq-opt [ [ "," ] cbq-opt ] ")" ] 3602priq-def = "priq" [ "(" priq-opt [ [ "," ] priq-opt ] ")" ] 3603hfsc-def = "hfsc" [ "(" hfsc-opt [ [ "," ] hfsc-opt ] ")" ] 3604cbq-opt = ( "default" | "borrow" | "red" | "ecn" | "rio" ) 3605priq-opt = ( "default" | "red" | "ecn" | "rio" ) 3606hfsc-opt = ( "default" | "red" | "ecn" | "rio" | 3607 linkshare-sc | realtime-sc | upperlimit-sc ) 3608linkshare-sc = "linkshare" sc-spec 3609realtime-sc = "realtime" sc-spec 3610upperlimit-sc = "upperlimit" sc-spec 3611sc-spec = ( bandwidth-spec | 3612 "(" bandwidth-spec number bandwidth-spec ")" ) 3613include = "include" filename 3614.Ed 3615.Sh FILES 3616.Bl -tag -width "/etc/protocols" -compact 3617.It Pa /etc/hosts 3618Host name database. 3619.It Pa /etc/pf.conf 3620Default location of the ruleset file. 3621The file has to be created manually as it is not installed with a 3622standard installation. 3623.It Pa /etc/pf.os 3624Default location of OS fingerprints. 3625.It Pa /etc/protocols 3626Protocol name database. 3627.It Pa /etc/services 3628Service name database. 3629.El 3630.Sh SEE ALSO 3631.Xr altq 4 , 3632.Xr carp 4 , 3633.Xr icmp 4 , 3634.Xr icmp6 4 , 3635.Xr ip 4 , 3636.Xr ip6 4 , 3637.Xr pf 4 , 3638.Xr pflow 4 , 3639.Xr pfsync 4 , 3640.Xr sctp 4 , 3641.Xr tcp 4 , 3642.Xr udp 4 , 3643.Xr hosts 5 , 3644.Xr pf.os 5 , 3645.Xr protocols 5 , 3646.Xr services 5 , 3647.Xr ftp-proxy 8 , 3648.Xr pfctl 8 , 3649.Xr pflogd 8 3650.Sh HISTORY 3651The 3652.Nm 3653file format first appeared in 3654.Ox 3.0 . 3655