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 28, 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 Ar once 2262Create a one shot rule. 2263The first matching packet marks the rule as expired. 2264Expired rules are skipped and hidden, unless 2265.Xr pfctl 8 2266is used in debug or verbose mode. 2267.Pp 2268.It Xo Ar queue Aq Ar queue 2269.No \*(Ba ( Aq Ar queue , 2270.Aq Ar queue ) 2271.Xc 2272Packets matching this rule will be assigned to the specified queue. 2273If two queues are given, packets which have a 2274.Em TOS 2275of 2276.Em lowdelay 2277and TCP ACKs with no data payload will be assigned to the second one. 2278See 2279.Sx QUEUEING 2280for setup details. 2281.Pp 2282For example: 2283.Bd -literal -offset indent 2284pass in proto tcp to port 25 queue mail 2285pass in proto tcp to port 22 queue(ssh_bulk, ssh_prio) 2286.Ed 2287.It Cm set prio Ar priority | Pq Ar priority , priority 2288Packets matching this rule will be assigned a specific queueing priority. 2289Priorities are assigned as integers 0 through 7. 2290If the packet is transmitted on a 2291.Xr vlan 4 2292interface, the queueing priority will be written as the priority 2293code point in the 802.1Q VLAN header. 2294If two priorities are given, TCP ACKs with no data payload and packets 2295which have a TOS of 2296.Cm lowdelay 2297will be assigned to the second one. 2298.Pp 2299For example: 2300.Bd -literal -offset indent 2301pass in proto tcp to port 25 set prio 2 2302pass in proto tcp to port 22 set prio (2, 5) 2303.Ed 2304.It Oo Cm \&! Oc Ns Cm received-on Ar interface 2305Only match packets which were received on the specified 2306.Ar interface 2307(or interface group). 2308.Ar any 2309will match any existing interface except loopback ones. 2310.It Ar tag Aq Ar string 2311Packets matching this rule will be tagged with the 2312specified string. 2313The tag acts as an internal marker that can be used to 2314identify these packets later on. 2315This can be used, for example, to provide trust between 2316interfaces and to determine if packets have been 2317processed by translation rules. 2318Tags are 2319.Qq sticky , 2320meaning that the packet will be tagged even if the rule 2321is not the last matching rule. 2322Further matching rules can replace the tag with a 2323new one but will not remove a previously applied tag. 2324A packet is only ever assigned one tag at a time. 2325Packet tagging can be done during 2326.Ar nat , 2327.Ar rdr , 2328.Ar binat 2329or 2330.Ar ether 2331rules in addition to filter rules. 2332Tags take the same macros as labels (see above). 2333.It Ar tagged Aq Ar string 2334Used with filter, translation or scrub rules 2335to specify that packets must already 2336be tagged with the given tag in order to match the rule. 2337.It Ar rtable Aq Ar number 2338Used to select an alternate routing table for the routing lookup. 2339Only effective before the route lookup happened, i.e. when filtering inbound. 2340.It Xo Ar divert-to Aq Ar host 2341.Ar port Aq Ar port 2342.Xc 2343Used to 2344.Xr divert 4 2345packets to the given divert 2346.Ar port . 2347Historically 2348.Ox pf has another meaning for this, and 2349.Fx pf uses 2350this syntax to support 2351.Xr divert 4 instead. Hence, 2352.Ar host 2353has no meaning and can be set to anything like 127.0.0.1. 2354If a packet is re-injected and does not change direction then it will not be 2355re-diverted. 2356.It Ar divert-reply 2357It has no meaning in 2358.Fx pf . 2359.It Ar probability Aq Ar number 2360A probability attribute can be attached to a rule, with a value set between 23610 and 1, bounds not included. 2362In that case, the rule will be honoured using the given probability value 2363only. 2364For example, the following rule will drop 20% of incoming ICMP packets: 2365.Bd -literal -offset indent 2366block in proto icmp probability 20% 2367.Ed 2368.It Ar prio Aq Ar number 2369Only match packets which have the given queueing priority assigned. 2370.El 2371.Sh ROUTING 2372If a packet matches a rule with a route option set, the packet filter will 2373route the packet according to the type of route option. 2374When such a rule creates state, the route option is also applied to all 2375packets matching the same connection. 2376.Bl -tag -width xxxx 2377.It Ar route-to 2378The 2379.Ar route-to 2380option routes the packet to the specified interface with an optional address 2381for the next hop. 2382When a 2383.Ar route-to 2384rule creates state, only packets that pass in the same direction as the 2385filter rule specifies will be routed in this way. 2386Packets passing in the opposite direction (replies) are not affected 2387and are routed normally. 2388.It Ar reply-to 2389The 2390.Ar reply-to 2391option is similar to 2392.Ar route-to , 2393but routes packets that pass in the opposite direction (replies) to the 2394specified interface. 2395Opposite direction is only defined in the context of a state entry, and 2396.Ar reply-to 2397is useful only in rules that create state. 2398It can be used on systems with multiple external connections to 2399route all outgoing packets of a connection through the interface 2400the incoming connection arrived through (symmetric routing enforcement). 2401.It Ar dup-to 2402The 2403.Ar dup-to 2404option creates a duplicate of the packet and routes it like 2405.Ar route-to . 2406The original packet gets routed as it normally would. 2407.El 2408.Sh POOL OPTIONS 2409For 2410.Ar nat 2411and 2412.Ar rdr 2413rules, (as well as for the 2414.Ar route-to , 2415.Ar reply-to 2416and 2417.Ar dup-to 2418rule options) for which there is a single redirection address which has a 2419subnet mask smaller than 32 for IPv4 or 128 for IPv6 (more than one IP 2420address), a variety of different methods for assigning this address can be 2421used: 2422.Bl -tag -width xxxx 2423.It Ar bitmask 2424The 2425.Ar bitmask 2426option applies the network portion of the redirection address to the address 2427to be modified (source with 2428.Ar nat , 2429destination with 2430.Ar rdr ) . 2431.It Ar random 2432The 2433.Ar random 2434option selects an address at random within the defined block of addresses. 2435.It Ar source-hash 2436The 2437.Ar source-hash 2438option uses a hash of the source address to determine the redirection address, 2439ensuring that the redirection address is always the same for a given source. 2440An optional key can be specified after this keyword either in hex or as a 2441string; by default 2442.Xr pfctl 8 2443randomly generates a key for source-hash every time the 2444ruleset is reloaded. 2445.It Ar round-robin 2446The 2447.Ar round-robin 2448option loops through the redirection address(es). 2449.Pp 2450When more than one redirection address is specified, 2451.Ar bitmask 2452is not permitted as a pool type. 2453.It Ar static-port 2454With 2455.Ar nat 2456rules, the 2457.Ar static-port 2458option prevents 2459.Xr pf 4 2460from modifying the source port on TCP and UDP packets. 2461.It Xo Ar map-e-portset Aq Ar psid-offset 2462.No / Aq Ar psid-len 2463.No / Aq Ar psid 2464.Xc 2465With 2466.Ar nat 2467rules, the 2468.Ar map-e-portset 2469option enables the source port translation of MAP-E (RFC 7597) Customer Edge. 2470In order to make the host act as a MAP-E Customer Edge, setting up a tunneling 2471interface and pass rules for encapsulated packets are required in addition 2472to the map-e-portset nat rule. 2473.Pp 2474For example: 2475.Bd -literal -offset indent 2476nat on $gif_mape_if from $int_if:network to any \e 2477 -> $ipv4_mape_src map-e-portset 6/8/0x34 2478.Ed 2479.Pp 2480sets PSID offset 6, PSID length 8, PSID 0x34. 2481.It Ar endpoint-independent 2482With 2483.Ar nat 2484rules, the 2485.Ar endpoint-independent 2486option caues 2487.Xr pf 4 2488to always map connections from a UDP source address and port to the same 2489NAT address and port. 2490This feature implements "full-cone" NAT behavior. 2491.El 2492.Pp 2493Additionally, options 2494.Ar sticky-address 2495and 2496.Ar prefer-ipv6-nexthop 2497can be specified to influence how IP addresses selected from pools. 2498.Pp 2499The 2500.Ar sticky-address 2501option can be specified to help ensure that multiple connections from the 2502same source are mapped to the same redirection address. 2503This option can be used with the 2504.Ar random 2505and 2506.Ar round-robin 2507pool options. 2508Note that by default these associations are destroyed as soon as there are 2509no longer states which refer to them; in order to make the mappings last 2510beyond the lifetime of the states, increase the global options with 2511.Ar set timeout src.track . 2512See 2513.Sx STATEFUL TRACKING OPTIONS 2514for more ways to control the source tracking. 2515.Pp 2516The 2517.Ar prefer-ipv6-nexthop 2518option allows for IPv6 addresses to be used as the nexthop 2519for IPv4 packets routed with the 2520.Ar route-to 2521rule option. If a table is used with IPv4 and IPv6 addresses, first the IPv6 addresses 2522will be used in round-robin fashion, then IPv4 addresses. 2523.Sh STATE MODULATION 2524Much of the security derived from TCP is attributable to how well the 2525initial sequence numbers (ISNs) are chosen. 2526Some popular stack implementations choose 2527.Em very 2528poor ISNs and thus are normally susceptible to ISN prediction exploits. 2529By applying a 2530.Ar modulate state 2531rule to a TCP connection, 2532.Xr pf 4 2533will create a high quality random sequence number for each connection 2534endpoint. 2535.Pp 2536The 2537.Ar modulate state 2538directive implicitly keeps state on the rule and is 2539only applicable to TCP connections. 2540.Pp 2541For instance: 2542.Bd -literal -offset indent 2543block all 2544pass out proto tcp from any to any modulate state 2545pass in proto tcp from any to any port 25 flags S/SFRA modulate state 2546.Ed 2547.Pp 2548Note that modulated connections will not recover when the state table 2549is lost (firewall reboot, flushing the state table, etc...). 2550.Xr pf 4 2551will not be able to infer a connection again after the state table flushes 2552the connection's modulator. 2553When the state is lost, the connection may be left dangling until the 2554respective endpoints time out the connection. 2555It is possible on a fast local network for the endpoints to start an ACK 2556storm while trying to resynchronize after the loss of the modulator. 2557The default 2558.Ar flags 2559settings (or a more strict equivalent) should be used on 2560.Ar modulate state 2561rules to prevent ACK storms. 2562.Pp 2563Note that alternative methods are available 2564to prevent loss of the state table 2565and allow for firewall failover. 2566See 2567.Xr carp 4 2568and 2569.Xr pfsync 4 2570for further information. 2571.Sh SYN PROXY 2572By default, 2573.Xr pf 4 2574passes packets that are part of a 2575.Xr tcp 4 2576handshake between the endpoints. 2577The 2578.Ar synproxy state 2579option can be used to cause 2580.Xr pf 4 2581itself to complete the handshake with the active endpoint, perform a handshake 2582with the passive endpoint, and then forward packets between the endpoints. 2583.Pp 2584No packets are sent to the passive endpoint before the active endpoint has 2585completed the handshake, hence so-called SYN floods with spoofed source 2586addresses will not reach the passive endpoint, as the sender can't complete the 2587handshake. 2588.Pp 2589The proxy is transparent to both endpoints, they each see a single 2590connection from/to the other endpoint. 2591.Xr pf 4 2592chooses random initial sequence numbers for both handshakes. 2593Once the handshakes are completed, the sequence number modulators 2594(see previous section) are used to translate further packets of the 2595connection. 2596.Ar synproxy state 2597includes 2598.Ar modulate state . 2599.Pp 2600Rules with 2601.Ar synproxy 2602will not work if 2603.Xr pf 4 2604operates on a 2605.Xr bridge 4 . 2606Also they act on incoming SYN packets only. 2607.Pp 2608Example: 2609.Bd -literal -offset indent 2610pass in proto tcp from any to any port www synproxy state 2611.Ed 2612.Sh STATEFUL TRACKING OPTIONS 2613A number of options related to stateful tracking can be applied on a 2614per-rule basis. 2615.Ar keep state , 2616.Ar modulate state 2617and 2618.Ar synproxy state 2619support these options, and 2620.Ar keep state 2621must be specified explicitly to apply options to a rule. 2622.Pp 2623.Bl -tag -width xxxx -compact 2624.It Ar max Aq Ar number 2625Limits the number of concurrent states the rule may create. 2626When this limit is reached, further packets that would create 2627state are dropped until existing states time out. 2628.It Ar no-sync 2629Prevent state changes for states created by this rule from appearing on the 2630.Xr pfsync 4 2631interface. 2632.It Xo Aq Ar timeout 2633.Aq Ar seconds 2634.Xc 2635Changes the timeout values used for states created by this rule. 2636For a list of all valid timeout names, see 2637.Sx OPTIONS 2638above. 2639.It Ar sloppy 2640Uses a sloppy TCP connection tracker that does not check sequence 2641numbers at all, which makes insertion and ICMP teardown attacks way 2642easier. 2643This is intended to be used in situations where one does not see all 2644packets of a connection, e.g. in asymmetric routing situations. 2645Cannot be used with modulate or synproxy state. 2646.It Ar pflow 2647States created by this rule are exported on the 2648.Xr pflow 4 2649interface. 2650.It Ar allow-related 2651Automatically allow connections related to this one, regardless of rules that 2652might otherwise affect them. 2653This currently only applies to SCTP multihomed connection. 2654.El 2655.Pp 2656Multiple options can be specified, separated by commas: 2657.Bd -literal -offset indent 2658pass in proto tcp from any to any \e 2659 port www keep state \e 2660 (max 100, source-track rule, max-src-nodes 75, \e 2661 max-src-states 3, tcp.established 60, tcp.closing 5) 2662.Ed 2663.Pp 2664When the 2665.Ar source-track 2666keyword is specified, the number of states per source IP is tracked. 2667.Pp 2668.Bl -tag -width xxxx -compact 2669.It Ar source-track rule 2670The maximum number of states created by this rule is limited by the rule's 2671.Ar max-src-nodes 2672and 2673.Ar max-src-states 2674options. 2675Only state entries created by this particular rule count toward the rule's 2676limits. 2677.It Ar source-track global 2678The number of states created by all rules that use this option is limited. 2679Each rule can specify different 2680.Ar max-src-nodes 2681and 2682.Ar max-src-states 2683options, however state entries created by any participating rule count towards 2684each individual rule's limits. 2685.El 2686.Pp 2687The following limits can be set: 2688.Pp 2689.Bl -tag -width xxxx -compact 2690.It Ar max-src-nodes Aq Ar number 2691Limits the maximum number of source addresses which can simultaneously 2692have state table entries. 2693.It Ar max-src-states Aq Ar number 2694Limits the maximum number of simultaneous state entries that a single 2695source address can create with this rule. 2696.El 2697.Pp 2698For stateful TCP connections, limits on established connections (connections 2699which have completed the TCP 3-way handshake) can also be enforced 2700per source IP. 2701.Pp 2702.Bl -tag -width xxxx -compact 2703.It Ar max-src-conn Aq Ar number 2704Limits the maximum number of simultaneous TCP connections which have 2705completed the 3-way handshake that a single host can make. 2706.It Xo Ar max-src-conn-rate Aq Ar number 2707.No / Aq Ar seconds 2708.Xc 2709Limit the rate of new connections over a time interval. 2710The connection rate is an approximation calculated as a moving average. 2711.El 2712.Pp 2713When one of these limits is reached, further packets that would create 2714state are dropped until existing states time out. 2715.Pp 2716Because the 3-way handshake ensures that the source address is not being 2717spoofed, more aggressive action can be taken based on these limits. 2718With the 2719.Ar overload Aq Ar table 2720state option, source IP addresses which hit either of the limits on 2721established connections will be added to the named table. 2722This table can be used in the ruleset to block further activity from 2723the offending host, redirect it to a tarpit process, or restrict its 2724bandwidth. 2725.Pp 2726The optional 2727.Ar flush 2728keyword kills all states created by the matching rule which originate 2729from the host which exceeds these limits. 2730The 2731.Ar global 2732modifier to the flush command kills all states originating from the 2733offending host, regardless of which rule created the state. 2734.Pp 2735For example, the following rules will protect the webserver against 2736hosts making more than 100 connections in 10 seconds. 2737Any host which connects faster than this rate will have its address added 2738to the 2739.Aq bad_hosts 2740table and have all states originating from it flushed. 2741Any new packets arriving from this host will be dropped unconditionally 2742by the block rule. 2743.Bd -literal -offset indent 2744block quick from <bad_hosts> 2745pass in on $ext_if proto tcp to $webserver port www keep state \e 2746 (max-src-conn-rate 100/10, overload <bad_hosts> flush global) 2747.Ed 2748.Sh OPERATING SYSTEM FINGERPRINTING 2749Passive OS Fingerprinting is a mechanism to inspect nuances of a TCP 2750connection's initial SYN packet and guess at the host's operating system. 2751Unfortunately these nuances are easily spoofed by an attacker so the 2752fingerprint is not useful in making security decisions. 2753But the fingerprint is typically accurate enough to make policy decisions 2754upon. 2755.Pp 2756The fingerprints may be specified by operating system class, by 2757version, or by subtype/patchlevel. 2758The class of an operating system is typically the vendor or genre 2759and would be 2760.Ox 2761for the 2762.Xr pf 4 2763firewall itself. 2764The version of the oldest available 2765.Ox 2766release on the main FTP site 2767would be 2.6 and the fingerprint would be written 2768.Pp 2769.Dl \&"OpenBSD 2.6\&" 2770.Pp 2771The subtype of an operating system is typically used to describe the 2772patchlevel if that patch led to changes in the TCP stack behavior. 2773In the case of 2774.Ox , 2775the only subtype is for a fingerprint that was 2776normalized by the 2777.Ar no-df 2778scrub option and would be specified as 2779.Pp 2780.Dl \&"OpenBSD 3.3 no-df\&" 2781.Pp 2782Fingerprints for most popular operating systems are provided by 2783.Xr pf.os 5 . 2784Once 2785.Xr pf 4 2786is running, a complete list of known operating system fingerprints may 2787be listed by running: 2788.Pp 2789.Dl # pfctl -so 2790.Pp 2791Filter rules can enforce policy at any level of operating system specification 2792assuming a fingerprint is present. 2793Policy could limit traffic to approved operating systems or even ban traffic 2794from hosts that aren't at the latest service pack. 2795.Pp 2796The 2797.Ar unknown 2798class can also be used as the fingerprint which will match packets for 2799which no operating system fingerprint is known. 2800.Pp 2801Examples: 2802.Bd -literal -offset indent 2803pass out proto tcp from any os OpenBSD 2804block out proto tcp from any os Doors 2805block out proto tcp from any os "Doors PT" 2806block out proto tcp from any os "Doors PT SP3" 2807block out from any os "unknown" 2808pass on lo0 proto tcp from any os "OpenBSD 3.3 lo0" 2809.Ed 2810.Pp 2811Operating system fingerprinting is limited only to the TCP SYN packet. 2812This means that it will not work on other protocols and will not match 2813a currently established connection. 2814.Pp 2815Caveat: operating system fingerprints are occasionally wrong. 2816There are three problems: an attacker can trivially craft packets to 2817appear as any operating system; 2818an operating system patch could change the stack behavior and no fingerprints 2819will match it until the database is updated; 2820and multiple operating systems may have the same fingerprint. 2821.Sh BLOCKING SPOOFED TRAFFIC 2822"Spoofing" is the faking of IP addresses, typically for malicious 2823purposes. 2824The 2825.Ar antispoof 2826directive expands to a set of filter rules which will block all 2827traffic with a source IP from the network(s) directly connected 2828to the specified interface(s) from entering the system through 2829any other interface. 2830.Pp 2831For example, the line 2832.Bd -literal -offset indent 2833antispoof for lo0 2834.Ed 2835.Pp 2836expands to 2837.Bd -literal -offset indent 2838block drop in on ! lo0 inet from 127.0.0.1/8 to any 2839block drop in on ! lo0 inet6 from ::1 to any 2840.Ed 2841.Pp 2842For non-loopback interfaces, there are additional rules to block incoming 2843packets with a source IP address identical to the interface's IP(s). 2844For example, assuming the interface wi0 had an IP address of 10.0.0.1 and a 2845netmask of 255.255.255.0, 2846the line 2847.Bd -literal -offset indent 2848antispoof for wi0 inet 2849.Ed 2850.Pp 2851expands to 2852.Bd -literal -offset indent 2853block drop in on ! wi0 inet from 10.0.0.0/24 to any 2854block drop in inet from 10.0.0.1 to any 2855.Ed 2856.Pp 2857Caveat: Rules created by the 2858.Ar antispoof 2859directive interfere with packets sent over loopback interfaces 2860to local addresses. 2861One should pass these explicitly. 2862.Sh FRAGMENT HANDLING 2863The size of IP datagrams (packets) can be significantly larger than the 2864maximum transmission unit (MTU) of the network. 2865In cases when it is necessary or more efficient to send such large packets, 2866the large packet will be fragmented into many smaller packets that will each 2867fit onto the wire. 2868Unfortunately for a firewalling device, only the first logical fragment will 2869contain the necessary header information for the subprotocol that allows 2870.Xr pf 4 2871to filter on things such as TCP ports or to perform NAT. 2872.Pp 2873Besides the use of 2874.Ar set reassemble 2875option or 2876.Ar scrub 2877rules as described in 2878.Sx TRAFFIC NORMALIZATION 2879above, there are three options for handling fragments in the packet filter. 2880.Pp 2881One alternative is to filter individual fragments with filter rules. 2882If no 2883.Ar scrub 2884rule applies to a fragment or 2885.Ar set reassemble 2886is set to 2887.Cm no 2888, it is passed to the filter. 2889Filter rules with matching IP header parameters decide whether the 2890fragment is passed or blocked, in the same way as complete packets 2891are filtered. 2892Without reassembly, fragments can only be filtered based on IP header 2893fields (source/destination address, protocol), since subprotocol header 2894fields are not available (TCP/UDP port numbers, ICMP code/type). 2895The 2896.Ar fragment 2897option can be used to restrict filter rules to apply only to 2898fragments, but not complete packets. 2899Filter rules without the 2900.Ar fragment 2901option still apply to fragments, if they only specify IP header fields. 2902For instance, the rule 2903.Bd -literal -offset indent 2904pass in proto tcp from any to any port 80 2905.Ed 2906.Pp 2907never applies to a fragment, even if the fragment is part of a TCP 2908packet with destination port 80, because without reassembly this information 2909is not available for each fragment. 2910This also means that fragments cannot create new or match existing 2911state table entries, which makes stateful filtering and address 2912translation (NAT, redirection) for fragments impossible. 2913.Pp 2914It's also possible to reassemble only certain fragments by specifying 2915source or destination addresses or protocols as parameters in 2916.Ar scrub 2917rules. 2918.Pp 2919In most cases, the benefits of reassembly outweigh the additional 2920memory cost, and it's recommended to use 2921.Ar set reassemble 2922option or 2923.Ar scrub 2924rules with the 2925.Ar fragment reassemble 2926modifier to reassemble 2927all fragments. 2928.Pp 2929The memory allocated for fragment caching can be limited using 2930.Xr pfctl 8 . 2931Once this limit is reached, fragments that would have to be cached 2932are dropped until other entries time out. 2933The timeout value can also be adjusted. 2934.Pp 2935When forwarding reassembled IPv6 packets, pf refragments them with 2936the original maximum fragment size. 2937This allows the sender to determine the optimal fragment size by 2938path MTU discovery. 2939.Sh ANCHORS 2940Besides the main ruleset, 2941.Xr pfctl 8 2942can load rulesets into 2943.Ar anchor 2944attachment points. 2945An 2946.Ar anchor 2947is a container that can hold rules, address tables, and other anchors. 2948.Pp 2949An 2950.Ar anchor 2951has a name which specifies the path where 2952.Xr pfctl 8 2953can be used to access the anchor to perform operations on it, such as 2954attaching child anchors to it or loading rules into it. 2955Anchors may be nested, with components separated by 2956.Sq / 2957characters, similar to how file system hierarchies are laid out. 2958The main ruleset is actually the default anchor, so filter and 2959translation rules, for example, may also be contained in any anchor. 2960.Pp 2961An anchor can reference another 2962.Ar anchor 2963attachment point 2964using the following kinds 2965of rules: 2966.Bl -tag -width xxxx 2967.It Ar nat-anchor Aq Ar name 2968Evaluates the 2969.Ar nat 2970rules in the specified 2971.Ar anchor . 2972.It Ar rdr-anchor Aq Ar name 2973Evaluates the 2974.Ar rdr 2975rules in the specified 2976.Ar anchor . 2977.It Ar binat-anchor Aq Ar name 2978Evaluates the 2979.Ar binat 2980rules in the specified 2981.Ar anchor . 2982.It Ar anchor Aq Ar name 2983Evaluates the filter rules in the specified 2984.Ar anchor . 2985.It Xo Ar load anchor 2986.Aq Ar name 2987.Ar from Aq Ar file 2988.Xc 2989Loads the rules from the specified file into the 2990anchor 2991.Ar name . 2992.El 2993.Pp 2994When evaluation of the main ruleset reaches an 2995.Ar anchor 2996rule, 2997.Xr pf 4 2998will proceed to evaluate all rules specified in that anchor. 2999.Pp 3000Matching filter and translation rules marked with the 3001.Ar quick 3002option are final and abort the evaluation of the rules in other 3003anchors and the main ruleset. 3004If the 3005.Ar anchor 3006itself is marked with the 3007.Ar quick 3008option, 3009ruleset evaluation will terminate when the anchor is exited if the packet is 3010matched by any rule within the anchor. 3011.Pp 3012.Ar anchor 3013rules are evaluated relative to the anchor in which they are contained. 3014For example, all 3015.Ar anchor 3016rules specified in the main ruleset will reference anchor 3017attachment points underneath the main ruleset, and 3018.Ar anchor 3019rules specified in a file loaded from a 3020.Ar load anchor 3021rule will be attached under that anchor point. 3022.Pp 3023Rules may be contained in 3024.Ar anchor 3025attachment points which do not contain any rules when the main ruleset 3026is loaded, and later such anchors can be manipulated through 3027.Xr pfctl 8 3028without reloading the main ruleset or other anchors. 3029For example, 3030.Bd -literal -offset indent 3031ext_if = \&"kue0\&" 3032block on $ext_if all 3033anchor spam 3034pass out on $ext_if all 3035pass in on $ext_if proto tcp from any \e 3036 to $ext_if port smtp 3037.Ed 3038.Pp 3039blocks all packets on the external interface by default, then evaluates 3040all rules in the 3041.Ar anchor 3042named "spam", and finally passes all outgoing connections and 3043incoming connections to port 25. 3044.Bd -literal -offset indent 3045# echo \&"block in quick from 1.2.3.4 to any\&" \&| \e 3046 pfctl -a spam -f - 3047.Ed 3048.Pp 3049This loads a single rule into the 3050.Ar anchor , 3051which blocks all packets from a specific address. 3052.Pp 3053The anchor can also be populated by adding a 3054.Ar load anchor 3055rule after the 3056.Ar anchor 3057rule: 3058.Bd -literal -offset indent 3059anchor spam 3060load anchor spam from "/etc/pf-spam.conf" 3061.Ed 3062.Pp 3063When 3064.Xr pfctl 8 3065loads 3066.Nm pf.conf , 3067it will also load all the rules from the file 3068.Pa /etc/pf-spam.conf 3069into the anchor. 3070.Pp 3071Optionally, 3072.Ar anchor 3073rules can specify packet filtering parameters using the same syntax as 3074filter rules. 3075When parameters are used, the 3076.Ar anchor 3077rule is only evaluated for matching packets. 3078This allows conditional evaluation of anchors, like: 3079.Bd -literal -offset indent 3080block on $ext_if all 3081anchor spam proto tcp from any to any port smtp 3082pass out on $ext_if all 3083pass in on $ext_if proto tcp from any to $ext_if port smtp 3084.Ed 3085.Pp 3086The rules inside 3087.Ar anchor 3088spam are only evaluated for 3089.Ar tcp 3090packets with destination port 25. 3091Hence, 3092.Bd -literal -offset indent 3093# echo \&"block in quick from 1.2.3.4 to any" \&| \e 3094 pfctl -a spam -f - 3095.Ed 3096.Pp 3097will only block connections from 1.2.3.4 to port 25. 3098.Pp 3099Anchors may end with the asterisk 3100.Pq Sq * 3101character, which signifies that all anchors attached at that point 3102should be evaluated in the alphabetical ordering of their anchor name. 3103For example, 3104.Bd -literal -offset indent 3105anchor "spam/*" 3106.Ed 3107.Pp 3108will evaluate each rule in each anchor attached to the 3109.Li spam 3110anchor. 3111Note that it will only evaluate anchors that are directly attached to the 3112.Li spam 3113anchor, and will not descend to evaluate anchors recursively. 3114.Pp 3115Since anchors are evaluated relative to the anchor in which they are 3116contained, there is a mechanism for accessing the parent and ancestor 3117anchors of a given anchor. 3118Similar to file system path name resolution, if the sequence 3119.Dq .. 3120appears as an anchor path component, the parent anchor of the current 3121anchor in the path evaluation at that point will become the new current 3122anchor. 3123As an example, consider the following: 3124.Bd -literal -offset indent 3125# echo ' anchor "spam/allowed" ' | pfctl -f - 3126# echo -e ' anchor "../banned" \en pass' | \e 3127 pfctl -a spam/allowed -f - 3128.Ed 3129.Pp 3130Evaluation of the main ruleset will lead into the 3131.Li spam/allowed 3132anchor, which will evaluate the rules in the 3133.Li spam/banned 3134anchor, if any, before finally evaluating the 3135.Ar pass 3136rule. 3137.Pp 3138An 3139.Ar anchor 3140rule can also contain a filter ruleset in a brace-delimited block. 3141In that case, no separate loading of rules into the anchor 3142is required. 3143Brace delimited blocks may contain rules or other brace-delimited blocks. 3144When an anchor is populated this way, the anchor name becomes optional. 3145.Bd -literal -offset indent 3146anchor "external" on $ext_if { 3147 block 3148 anchor out { 3149 pass proto tcp from any to port { 25, 80, 443 } 3150 } 3151 pass in proto tcp to any port 22 3152} 3153.Ed 3154.Pp 3155Since the parser specification for anchor names is a string, any 3156reference to an anchor name containing 3157.Sq / 3158characters will require double quote 3159.Pq Sq \&" 3160characters around the anchor name. 3161.Sh SCTP CONSIDERATIONS 3162.Xr pf 4 3163supports 3164.Xr sctp 4 3165connections. 3166It can match ports, track state and NAT SCTP traffic. 3167However, it will not alter port numbers during nat or rdr translations. 3168Doing so would break SCTP multihoming. 3169.Sh TRANSLATION EXAMPLES 3170This example maps incoming requests on port 80 to port 8080, on 3171which a daemon is running (because, for example, it is not run as root, 3172and therefore lacks permission to bind to port 80). 3173.Bd -literal -offset indent 3174# use a macro for the interface name, so it can be changed easily 3175ext_if = \&"ne3\&" 3176 3177# map daemon on 8080 to appear to be on 80 3178match in on $ext_if proto tcp from any to any port 80 \e 3179 rdr-to 127.0.0.1 port 8080 3180.Ed 3181.Pp 3182If a 3183.Ar pass 3184rule is used with the 3185.Ar quick 3186modifier, packets matching the translation rule are passed without 3187inspecting subsequent filter rules: 3188.Bd -literal -offset indent 3189pass in quick on $ext_if proto tcp from any to any port 80 \e 3190 rdr-to 127.0.0.1 port 8080 3191.Ed 3192.Pp 3193In the example below, vlan12 is configured as 192.168.168.1; 3194the machine translates all packets coming from 192.168.168.0/24 to 204.92.77.111 3195when they are going out any interface except vlan12. 3196This has the net effect of making traffic from the 192.168.168.0/24 3197network appear as though it is the Internet routable address 3198204.92.77.111 to nodes behind any interface on the router except 3199for the nodes on vlan12. 3200(Thus, 192.168.168.1 can talk to the 192.168.168.0/24 nodes.) 3201.Bd -literal -offset indent 3202match out on ! vlan12 from 192.168.168.0/24 to any nat-to 204.92.77.111 3203.Ed 3204.Pp 3205This longer example uses both a NAT and a redirection. 3206The external interface has the address 157.161.48.183. 3207On localhost, we are running 3208.Xr ftp-proxy 8 , 3209waiting for FTP sessions to be redirected to it. 3210The three mandatory anchors for 3211.Xr ftp-proxy 8 3212are omitted from this example; see the 3213.Xr ftp-proxy 8 3214manpage. 3215.Bd -literal -offset indent 3216# NAT 3217# Translate outgoing packets' source addresses (any protocol). 3218# In this case, any address but the gateway's external address is mapped. 3219pass out on $ext_if inet from ! ($ext_if) to any nat-to ($ext_if) 3220 3221# NAT PROXYING 3222# Map outgoing packets' source port to an assigned proxy port instead of 3223# an arbitrary port. 3224# In this case, proxy outgoing isakmp with port 500 on the gateway. 3225pass out on $ext_if inet proto udp from any port = isakmp to any \e 3226 nat-to ($ext_if) port 500 3227 3228# BINAT 3229# Translate outgoing packets' source address (any protocol). 3230# Translate incoming packets' destination address to an internal machine 3231# (bidirectional). 3232pass on $ext_if from 10.1.2.150 to any binat-to $ext_if 3233 3234# Translate packets arriving on $peer_if addressed to 172.22.16.0/20 3235# to the corresponding address in 172.21.16.0/20 (bidirectional). 3236pass on $peer_if from 172.21.16.0/20 to any binat-to 172.22.16.0/20 3237 3238# RDR 3239# Translate incoming packets' destination addresses. 3240# As an example, redirect a TCP and UDP port to an internal machine. 3241pass in on $ext_if inet proto tcp from any to ($ext_if) port 8080 \e 3242 rdr-to 10.1.2.151 port 22 3243pass in on $ext_if inet proto udp from any to ($ext_if) port 8080 \e 3244 rdr-to 10.1.2.151 port 53 3245 3246# RDR 3247# Translate outgoing ftp control connections to send them to localhost 3248# for proxying with ftp-proxy(8) running on port 8021. 3249pass in on $int_if proto tcp from any to any port 21 \e 3250 rdr-to 127.0.0.1 port 8021 3251.Ed 3252.Pp 3253In this example, a NAT gateway is set up to translate internal addresses 3254using a pool of public addresses (192.0.2.16/28) and to redirect 3255incoming web server connections to a group of web servers on the internal 3256network. 3257.Bd -literal -offset indent 3258# NAT LOAD BALANCE 3259# Translate outgoing packets' source addresses using an address pool. 3260# A given source address is always translated to the same pool address by 3261# using the source-hash keyword. 3262pass out on $ext_if inet from any to any nat-to 192.0.2.16/28 source-hash 3263 3264# RDR ROUND ROBIN 3265# Translate incoming web server connections to a group of web servers on 3266# the internal network. 3267pass in on $ext_if proto tcp from any to any port 80 \e 3268 rdr-to { 10.1.2.155, 10.1.2.160, 10.1.2.161 } round-robin 3269.Ed 3270.Sh COMPATIBILITY TRANSLATION EXAMPLES 3271In the example below, the machine sits between a fake internal 144.19.74.* 3272network, and a routable external IP of 204.92.77.100. 3273The 3274.Ar no nat 3275rule excludes protocol AH from being translated. 3276.Bd -literal -offset indent 3277# NAT 3278no nat on $ext_if proto ah from 144.19.74.0/24 to any 3279nat on $ext_if from 144.19.74.0/24 to any -> 204.92.77.100 3280.Ed 3281.Pp 3282In the example below, packets bound for one specific server, as well as those 3283generated by the sysadmins are not proxied; all other connections are. 3284.Bd -literal -offset indent 3285# RDR 3286no rdr on $int_if proto { tcp, udp } from any to $server port 80 3287no rdr on $int_if proto { tcp, udp } from $sysadmins to any port 80 3288rdr on $int_if proto { tcp, udp } from any to any port 80 \e 3289 -> 127.0.0.1 port 80 3290.Ed 3291.Sh FILTER EXAMPLES 3292.Bd -literal -offset indent 3293# The external interface is kue0 3294# (157.161.48.183, the only routable address) 3295# and the private network is 10.0.0.0/8, for which we are doing NAT. 3296 3297# Reassemble incoming traffic 3298set reassemble yes 3299 3300# use a macro for the interface name, so it can be changed easily 3301ext_if = \&"kue0\&" 3302 3303# block and log everything by default 3304block return log on $ext_if all 3305 3306# block anything coming from source we have no back routes for 3307block in from no-route to any 3308 3309# block packets whose ingress interface does not match the one in 3310# the route back to their source address 3311block in from urpf-failed to any 3312 3313# block and log outgoing packets that do not have our address as source, 3314# they are either spoofed or something is misconfigured (NAT disabled, 3315# for instance), we want to be nice and do not send out garbage. 3316block out log quick on $ext_if from ! 157.161.48.183 to any 3317 3318# silently drop broadcasts (cable modem noise) 3319block in quick on $ext_if from any to 255.255.255.255 3320 3321# block and log incoming packets from reserved address space and invalid 3322# addresses, they are either spoofed or misconfigured, we cannot reply to 3323# them anyway (hence, no return-rst). 3324block in log quick on $ext_if from { 10.0.0.0/8, 172.16.0.0/12, \e 3325 192.168.0.0/16, 255.255.255.255/32 } to any 3326 3327# ICMP 3328 3329# pass out/in certain ICMP queries and keep state (ping) 3330# state matching is done on host addresses and ICMP id (not type/code), 3331# so replies (like 0/0 for 8/0) will match queries 3332# ICMP error messages (which always refer to a TCP/UDP packet) are 3333# handled by the TCP/UDP states 3334pass on $ext_if inet proto icmp all icmp-type 8 code 0 3335 3336# UDP 3337 3338# pass out all UDP connections and keep state 3339pass out on $ext_if proto udp all 3340 3341# pass in certain UDP connections and keep state (DNS) 3342pass in on $ext_if proto udp from any to any port domain 3343 3344# TCP 3345 3346# pass out all TCP connections and modulate state 3347pass out on $ext_if proto tcp all modulate state 3348 3349# pass in certain TCP connections and keep state (SSH, SMTP, DNS, IDENT) 3350pass in on $ext_if proto tcp from any to any port { ssh, smtp, domain, \e 3351 auth } 3352 3353# Do not allow Windows 9x SMTP connections since they are typically 3354# a viral worm. Alternately we could limit these OSes to 1 connection each. 3355block in on $ext_if proto tcp from any os {"Windows 95", "Windows 98"} \e 3356 to any port smtp 3357 3358# IPv6 3359# pass in/out all IPv6 traffic: note that we have to enable this in two 3360# different ways, on both our physical interface and our tunnel 3361pass quick on gif0 inet6 3362pass quick on $ext_if proto ipv6 3363 3364# Packet Tagging 3365 3366# three interfaces: $int_if, $ext_if, and $wifi_if (wireless). NAT is 3367# being done on $ext_if for all outgoing packets. tag packets in on 3368# $int_if and pass those tagged packets out on $ext_if. all other 3369# outgoing packets (i.e., packets from the wireless network) are only 3370# permitted to access port 80. 3371 3372pass in on $int_if from any to any tag INTNET 3373pass in on $wifi_if from any to any 3374 3375block out on $ext_if from any to any 3376pass out quick on $ext_if tagged INTNET 3377pass out on $ext_if proto tcp from any to any port 80 3378 3379# tag incoming packets as they are redirected to spamd(8). use the tag 3380# to pass those packets through the packet filter. 3381 3382rdr on $ext_if inet proto tcp from <spammers> to port smtp \e 3383 tag SPAMD -> 127.0.0.1 port spamd 3384 3385block in on $ext_if 3386pass in on $ext_if inet proto tcp tagged SPAMD 3387.Ed 3388.Pp 3389In the example below, a router handling both address families 3390translates an internal IPv4 subnet to IPv6 using the well-known 339164:ff9b::/96 prefix: 3392.Bd -literal -offset 4n 3393pass in on $v4_if inet af-to inet6 from ($v6_if) to 64:ff9b::/96 3394.Ed 3395.Pp 3396Paired with the example above, the example below can be used on 3397another router handling both address families to translate back 3398to IPv4: 3399.Bd -literal -offset 4n 3400pass in on $v6_if inet6 to 64:ff9b::/96 af-to inet from ($v4_if) 3401.Ed 3402.Sh GRAMMAR 3403Syntax for 3404.Nm 3405in BNF: 3406.Bd -literal 3407line = ( option | ether-rule | pf-rule | nat-rule | binat-rule | 3408 rdr-rule | antispoof-rule | altq-rule | queue-rule | 3409 trans-anchors | anchor-rule | anchor-close | load-anchor | 3410 table-rule | include ) 3411 3412option = "set" ( [ "timeout" ( timeout | "{" timeout-list "}" ) ] | 3413 [ "ruleset-optimization" [ "none" | "basic" | "profile" ]] | 3414 [ "optimization" [ "default" | "normal" | 3415 "high-latency" | "satellite" | 3416 "aggressive" | "conservative" ] ] 3417 [ "limit" ( limit-item | "{" limit-list "}" ) ] | 3418 [ "loginterface" ( interface-name | "none" ) ] | 3419 [ "block-policy" ( "drop" | "return" ) ] | 3420 [ "state-policy" ( "if-bound" | "floating" ) ] 3421 [ "state-defaults" state-opts ] 3422 [ "require-order" ( "yes" | "no" ) ] 3423 [ "fingerprints" filename ] | 3424 [ "skip on" ifspec ] | 3425 [ "debug" ( "none" | "urgent" | "misc" | "loud" ) ] 3426 [ "keepcounters" ] ) 3427 3428ether-rule = "ether" etheraction [ ( "in" | "out" ) ] 3429 [ "quick" ] [ "on" ifspec ] [ "bridge-to" interface-name ] 3430 [ etherprotospec ] [ etherhosts ] [ "l3" hosts ] 3431 [ etherfilteropt-list ] 3432 3433pf-rule = action [ ( "in" | "out" ) ] 3434 [ "log" [ "(" logopts ")"] ] [ "quick" ] 3435 [ "on" ifspec ] [ route ] [ af ] [ protospec ] 3436 [ hosts ] [ filteropt-list ] 3437 3438logopts = logopt [ "," logopts ] 3439logopt = "all" | "matches" | "user" | "to" interface-name 3440 3441etherfilteropt-list = etherfilteropt-list etherfilteropt | etherfilteropt 3442etherfilteropt = "tag" string | "tagged" string | "queue" ( string ) | 3443 "ridentifier" number | "label" string 3444 3445filteropt-list = filteropt-list filteropt | filteropt 3446filteropt = user | group | flags | icmp-type | icmp6-type | "tos" tos | 3447 "af-to" af "from" ( redirhost | "{" redirhost-list "}" ) 3448 [ "to" ( redirhost | "{" redirhost-list "}" ) ] | 3449 ( "no" | "keep" | "modulate" | "synproxy" ) "state" 3450 [ "(" state-opts ")" ] | 3451 "fragment" | "no-df" | "min-ttl" number | "set-tos" tos | 3452 "max-mss" number | "random-id" | "reassemble tcp" | 3453 fragmentation | "allow-opts" | "once" | 3454 "label" string | "tag" string | [ "!" ] "tagged" string | 3455 "max-pkt-rate" number "/" seconds | 3456 "set prio" ( number | "(" number [ [ "," ] number ] ")" ) | 3457 "max-pkt-size" number | 3458 "queue" ( string | "(" string [ [ "," ] string ] ")" ) | 3459 "rtable" number | "probability" number"%" | "prio" number | 3460 "dnpipe" ( number | "(" number "," number ")" ) | 3461 "dnqueue" ( number | "(" number "," number ")" ) | 3462 "ridentifier" number | 3463 [ ! ] "received-on" ( interface-name | interface-group ) 3464 3465nat-rule = [ "no" ] "nat" [ "pass" [ "log" [ "(" logopts ")" ] ] ] 3466 [ "on" ifspec ] [ af ] 3467 [ protospec ] hosts [ "tag" string ] [ "tagged" string ] 3468 [ "->" ( redirhost | "{" redirhost-list "}" ) 3469 [ portspec ] [ pooltype ] [ "static-port" ] 3470 [ "map-e-portset" number "/" number "/" number ] ] 3471 3472binat-rule = [ "no" ] "binat" [ "pass" [ "log" [ "(" logopts ")" ] ] ] 3473 [ "on" interface-name ] [ af ] 3474 [ "proto" ( proto-name | proto-number ) ] 3475 "from" address [ "/" mask-bits ] "to" ipspec 3476 [ "tag" string ] [ "tagged" string ] 3477 [ "->" address [ "/" mask-bits ] ] 3478 3479rdr-rule = [ "no" ] "rdr" [ "pass" [ "log" [ "(" logopts ")" ] ] ] 3480 [ "on" ifspec ] [ af ] 3481 [ protospec ] hosts [ "tag" string ] [ "tagged" string ] 3482 [ "->" ( redirhost | "{" redirhost-list "}" ) 3483 [ portspec ] [ pooltype ] ] 3484 3485antispoof-rule = "antispoof" [ "log" ] [ "quick" ] 3486 "for" ifspec [ af ] [ "label" string ] 3487 [ "ridentifier" number ] 3488 3489table-rule = "table" "<" string ">" [ tableopts-list ] 3490tableopts-list = tableopts-list tableopts | tableopts 3491tableopts = "persist" | "const" | "counters" | "file" string | 3492 "{" [ tableaddr-list ] "}" 3493tableaddr-list = tableaddr-list [ "," ] tableaddr-spec | tableaddr-spec 3494tableaddr-spec = [ "!" ] tableaddr [ "/" mask-bits ] 3495tableaddr = hostname | ifspec | "self" | 3496 ipv4-dotted-quad | ipv6-coloned-hex 3497 3498altq-rule = "altq on" interface-name queueopts-list 3499 "queue" subqueue 3500queue-rule = "queue" string [ "on" interface-name ] queueopts-list 3501 subqueue 3502 3503anchor-rule = "anchor" [ string ] [ ( "in" | "out" ) ] [ "on" ifspec ] 3504 [ af ] [ protospec ] [ hosts ] [ filteropt-list ] [ "{" ] 3505 3506anchor-close = "}" 3507 3508trans-anchors = ( "nat-anchor" | "rdr-anchor" | "binat-anchor" ) string 3509 [ "on" ifspec ] [ af ] [ "proto" ] [ protospec ] [ hosts ] 3510 3511load-anchor = "load anchor" string "from" filename 3512 3513queueopts-list = queueopts-list queueopts | queueopts 3514queueopts = [ "bandwidth" bandwidth-spec ] | 3515 [ "qlimit" number ] | [ "tbrsize" number ] | 3516 [ "priority" number ] | [ schedulers ] 3517schedulers = ( cbq-def | priq-def | hfsc-def ) 3518bandwidth-spec = "number" ( "b" | "Kb" | "Mb" | "Gb" | "%" ) 3519 3520etheraction = "pass" | "block" 3521action = "pass" | "match" | "block" [ return ] | [ "no" ] "scrub" 3522return = "drop" | "return" | "return-rst" [ "( ttl" number ")" ] | 3523 "return-icmp" [ "(" icmpcode [ [ "," ] icmp6code ] ")" ] | 3524 "return-icmp6" [ "(" icmp6code ")" ] 3525icmpcode = ( icmp-code-name | icmp-code-number ) 3526icmp6code = ( icmp6-code-name | icmp6-code-number ) 3527 3528ifspec = ( [ "!" ] ( interface-name | interface-group ) ) | 3529 "{" interface-list "}" 3530interface-list = [ "!" ] ( interface-name | interface-group ) 3531 [ [ "," ] interface-list ] 3532route = ( "route-to" | "reply-to" | "dup-to" ) 3533 ( routehost | "{" routehost-list "}" ) 3534 [ pooltype ] 3535af = "inet" | "inet6" 3536 3537etherprotospec = "proto" ( proto-number | "{" etherproto-list "}" ) 3538etherproto-list = proto-number [ [ "," ] etherproto-list ] 3539protospec = "proto" ( proto-name | proto-number | 3540 "{" proto-list "}" ) 3541proto-list = ( proto-name | proto-number ) [ [ "," ] proto-list ] 3542 3543etherhosts = "from" macaddress "to" macaddress 3544macaddress = mac | mac "/" masklen | mac "&" mask 3545 3546hosts = "all" | 3547 "from" ( "any" | "no-route" | "urpf-failed" | "self" | host | 3548 "{" host-list "}" ) [ port ] [ os ] 3549 "to" ( "any" | "no-route" | "self" | host | 3550 "{" host-list "}" ) [ port ] 3551 3552ipspec = "any" | host | "{" host-list "}" 3553host = [ "!" ] ( address [ "/" mask-bits ] | "<" string ">" ) 3554redirhost = address [ "/" mask-bits ] 3555routehost = "(" interface-name [ address [ "/" mask-bits ] ] ")" 3556address = ( interface-name | interface-group | 3557 "(" ( interface-name | interface-group ) ")" | 3558 hostname | ipv4-dotted-quad | ipv6-coloned-hex ) 3559host-list = host [ [ "," ] host-list ] 3560redirhost-list = redirhost [ [ "," ] redirhost-list ] 3561routehost-list = routehost [ [ "," ] routehost-list ] 3562 3563port = "port" ( unary-op | binary-op | "{" op-list "}" ) 3564portspec = "port" ( number | name ) [ ":" ( "*" | number | name ) ] 3565os = "os" ( os-name | "{" os-list "}" ) 3566user = "user" ( unary-op | binary-op | "{" op-list "}" ) 3567group = "group" ( unary-op | binary-op | "{" op-list "}" ) 3568 3569unary-op = [ "=" | "!=" | "<" | "<=" | ">" | ">=" ] 3570 ( name | number ) 3571binary-op = number ( "<>" | "><" | ":" ) number 3572op-list = ( unary-op | binary-op ) [ [ "," ] op-list ] 3573 3574os-name = operating-system-name 3575os-list = os-name [ [ "," ] os-list ] 3576 3577flags = "flags" ( [ flag-set ] "/" flag-set | "any" ) 3578flag-set = [ "F" ] [ "S" ] [ "R" ] [ "P" ] [ "A" ] [ "U" ] [ "E" ] 3579 [ "W" ] 3580 3581icmp-type = "icmp-type" ( icmp-type-code | "{" icmp-list "}" ) 3582icmp6-type = "icmp6-type" ( icmp-type-code | "{" icmp-list "}" ) 3583icmp-type-code = ( icmp-type-name | icmp-type-number ) 3584 [ "code" ( icmp-code-name | icmp-code-number ) ] 3585icmp-list = icmp-type-code [ [ "," ] icmp-list ] 3586 3587tos = ( "lowdelay" | "throughput" | "reliability" | 3588 [ "0x" ] number ) 3589 3590state-opts = state-opt [ [ "," ] state-opts ] 3591state-opt = ( "max" number | "no-sync" | timeout | "sloppy" | 3592 "source-track" [ ( "rule" | "global" ) ] | 3593 "max-src-nodes" number | "max-src-states" number | 3594 "max-src-conn" number | 3595 "max-src-conn-rate" number "/" number | 3596 "overload" "<" string ">" [ "flush" ] | 3597 "if-bound" | "floating" | "pflow" ) 3598 3599fragmentation = [ "fragment reassemble" ] 3600 3601timeout-list = timeout [ [ "," ] timeout-list ] 3602timeout = ( "tcp.first" | "tcp.opening" | "tcp.established" | 3603 "tcp.closing" | "tcp.finwait" | "tcp.closed" | "tcp.tsdiff" | 3604 "sctp.first" | "sctp.opening" | "sctp.established" | 3605 "sctp.closing" | "sctp.closed" | 3606 "udp.first" | "udp.single" | "udp.multiple" | 3607 "icmp.first" | "icmp.error" | 3608 "other.first" | "other.single" | "other.multiple" | 3609 "frag" | "interval" | "src.track" | 3610 "adaptive.start" | "adaptive.end" ) number 3611 3612limit-list = limit-item [ [ "," ] limit-list ] 3613limit-item = ( "states" | "frags" | "src-nodes" ) number 3614 3615pooltype = ( "bitmask" | "random" | 3616 "source-hash" [ ( hex-key | string-key ) ] | 3617 "round-robin" ) [ sticky-address | prefer-ipv6-nexthop ] 3618 3619subqueue = string | "{" queue-list "}" 3620queue-list = string [ [ "," ] string ] 3621cbq-def = "cbq" [ "(" cbq-opt [ [ "," ] cbq-opt ] ")" ] 3622priq-def = "priq" [ "(" priq-opt [ [ "," ] priq-opt ] ")" ] 3623hfsc-def = "hfsc" [ "(" hfsc-opt [ [ "," ] hfsc-opt ] ")" ] 3624cbq-opt = ( "default" | "borrow" | "red" | "ecn" | "rio" ) 3625priq-opt = ( "default" | "red" | "ecn" | "rio" ) 3626hfsc-opt = ( "default" | "red" | "ecn" | "rio" | 3627 linkshare-sc | realtime-sc | upperlimit-sc ) 3628linkshare-sc = "linkshare" sc-spec 3629realtime-sc = "realtime" sc-spec 3630upperlimit-sc = "upperlimit" sc-spec 3631sc-spec = ( bandwidth-spec | 3632 "(" bandwidth-spec number bandwidth-spec ")" ) 3633include = "include" filename 3634.Ed 3635.Sh FILES 3636.Bl -tag -width "/etc/protocols" -compact 3637.It Pa /etc/hosts 3638Host name database. 3639.It Pa /etc/pf.conf 3640Default location of the ruleset file. 3641The file has to be created manually as it is not installed with a 3642standard installation. 3643.It Pa /etc/pf.os 3644Default location of OS fingerprints. 3645.It Pa /etc/protocols 3646Protocol name database. 3647.It Pa /etc/services 3648Service name database. 3649.El 3650.Sh SEE ALSO 3651.Xr altq 4 , 3652.Xr carp 4 , 3653.Xr icmp 4 , 3654.Xr icmp6 4 , 3655.Xr ip 4 , 3656.Xr ip6 4 , 3657.Xr pf 4 , 3658.Xr pflow 4 , 3659.Xr pfsync 4 , 3660.Xr sctp 4 , 3661.Xr tcp 4 , 3662.Xr udp 4 , 3663.Xr hosts 5 , 3664.Xr pf.os 5 , 3665.Xr protocols 5 , 3666.Xr services 5 , 3667.Xr ftp-proxy 8 , 3668.Xr pfctl 8 , 3669.Xr pflogd 8 3670.Sh HISTORY 3671The 3672.Nm 3673file format first appeared in 3674.Ox 3.0 . 3675