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