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