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