1.\" $NetBSD: pf.conf.5,v 1.16 2009/10/14 17:44:25 joerg 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 Ar from Ao Ar source Ac Ar port Ao Ar source Ac Ar os Ao Ar source Ac \ 1411Ar to Ao Ar dest Ac Ar port Aq Ar dest 1412This rule applies only to packets with the specified source and destination 1413addresses and ports. 1414.Pp 1415Addresses can be specified in CIDR notation (matching netblocks), as 1416symbolic host names, interface names or interface group names, or as any 1417of the following keywords: 1418.Pp 1419.Bl -tag -width xxxxxxxxxxxxxx -compact 1420.It Ar any 1421Any address. 1422.It Ar route Aq Ar label 1423Any address whose associated route has label 1424.Aq Ar label . 1425See 1426.Xr route 4 1427and 1428.Xr route 8 . 1429.It Ar no-route 1430Any address which is not currently routable. 1431.It Ar urpf-failed 1432Any source address that fails a unicast reverse path forwarding (URPF) 1433check, i.e. packets coming in on an interface other than that which holds 1434the route back to the packet's source address. 1435.It Aq Ar table 1436Any address that matches the given table. 1437.El 1438.Pp 1439Interface names and interface group names can have modifiers appended: 1440.Pp 1441.Bl -tag -width xxxxxxxxxxxx -compact 1442.It Ar :network 1443Translates to the network(s) attached to the interface. 1444.It Ar :broadcast 1445Translates to the interface's broadcast address(es). 1446.It Ar :peer 1447Translates to the point to point interface's peer address(es). 1448.It Ar :0 1449Do not include interface aliases. 1450.El 1451.Pp 1452Host names may also have the 1453.Ar :0 1454option appended to restrict the name resolution to the first of each 1455v4 and v6 address found. 1456.Pp 1457Host name resolution and interface to address translation are done at 1458ruleset load-time. 1459When the address of an interface (or host name) changes (under DHCP or PPP, 1460for instance), the ruleset must be reloaded for the change to be reflected 1461in the kernel. 1462Surrounding the interface name (and optional modifiers) in parentheses 1463changes this behaviour. 1464When the interface name is surrounded by parentheses, the rule is 1465automatically updated whenever the interface changes its address. 1466The ruleset does not need to be reloaded. 1467This is especially useful with 1468.Ar nat . 1469.Pp 1470Ports can be specified either by number or by name. 1471For example, port 80 can be specified as 1472.Em www . 1473For a list of all port name to number mappings used by 1474.Xr pfctl 8 , 1475see the file 1476.Pa /etc/services . 1477.Pp 1478Ports and ranges of ports are specified by using these operators: 1479.Bd -literal -offset indent 1480= (equal) 1481!= (unequal) 1482\*(Lt (less than) 1483\*(Le (less than or equal) 1484\*(Gt (greater than) 1485\*(Ge (greater than or equal) 1486: (range including boundaries) 1487\*(Gt\*(Lt (range excluding boundaries) 1488\*(Lt\*(Gt (except range) 1489.Ed 1490.Pp 1491.Sq \*(Gt\*(Lt , 1492.Sq \*(Lt\*(Gt 1493and 1494.Sq \&: 1495are binary operators (they take two arguments). 1496For instance: 1497.Bl -tag -width Fl 1498.It Ar port 2000:2004 1499means 1500.Sq all ports \*(Ge 2000 and \*(Le 2004 , 1501hence ports 2000, 2001, 2002, 2003 and 2004. 1502.It Ar port 2000 \*(Gt\*(Lt 2004 1503means 1504.Sq all ports \*(Gt 2000 and \*(Lt 2004 , 1505hence ports 2001, 2002 and 2003. 1506.It Ar port 2000 \*(Lt\*(Gt 2004 1507means 1508.Sq all ports \*(Lt 2000 or \*(Gt 2004 , 1509hence ports 1-1999 and 2005-65535. 1510.El 1511.Pp 1512The operating system of the source host can be specified in the case of TCP 1513rules with the 1514.Ar OS 1515modifier. 1516See the 1517.Sx OPERATING SYSTEM FINGERPRINTING 1518section for more information. 1519.Pp 1520The host, port and OS specifications are optional, as in the following examples: 1521.Bd -literal -offset indent 1522pass in all 1523pass in from any to any 1524pass in proto tcp from any port \*(Le 1024 to any 1525pass in proto tcp from any to any port 25 1526pass in proto tcp from 10.0.0.0/8 port \*(Gt 1024 \e 1527 to ! 10.1.2.3 port != ssh 1528pass in proto tcp from any os "OpenBSD" 1529pass in proto tcp from route "DTAG" 1530.Ed 1531.It Ar all 1532This is equivalent to "from any to any". 1533.It Ar group Aq Ar group 1534This functionality is not supported in this version of 1535.Nx . 1536.\" Similar to 1537.\" .Ar user , 1538.\" this rule only applies to packets of sockets owned by the specified group. 1539.It Ar user Aq Ar user 1540This rule only applies to packets of sockets owned by the specified user. 1541For outgoing connections initiated from the firewall, this is the user 1542that opened the connection. 1543For incoming connections to the firewall itself, this is the user that 1544listens on the destination port. 1545For forwarded connections, where the firewall is not a connection endpoint, 1546the user and group are 1547.Em unknown . 1548.Pp 1549All packets, both outgoing and incoming, of one connection are associated 1550with the same user and group. 1551Only TCP and UDP packets can be associated with users; for other protocols 1552these parameters are ignored. 1553.Pp 1554User and group refer to the effective (as opposed to the real) IDs, in 1555case the socket is created by a setuid/setgid process. 1556User and group IDs are stored when a socket is created; 1557when a process creates a listening socket as root (for instance, by 1558binding to a privileged port) and subsequently changes to another 1559user ID (to drop privileges), the credentials will remain root. 1560.Pp 1561User and group IDs can be specified as either numbers or names. 1562The syntax is similar to the one for ports. 1563The value 1564.Em unknown 1565matches packets of forwarded connections. 1566.Em unknown 1567can only be used with the operators 1568.Cm = 1569and 1570.Cm != . 1571Other constructs like 1572.Cm user \*(Ge unknown 1573are invalid. 1574Forwarded packets with unknown user and group ID match only rules 1575that explicitly compare against 1576.Em unknown 1577with the operators 1578.Cm = 1579or 1580.Cm != . 1581For instance 1582.Cm user \*(Ge 0 1583does not match forwarded packets. 1584The following example allows only selected users to open outgoing 1585connections: 1586.Bd -literal -offset indent 1587block out proto { tcp, udp } all 1588pass out proto { tcp, udp } all user { \*(Lt 1000, dhartmei } 1589.Ed 1590.It Ar flags Ao Ar a Ac Pf / Ns Ao Ar b Ac No \*(Ba / Ns \ 1591Ao Ar b Ac No \*(Ba any 1592This rule only applies to TCP packets that have the flags 1593.Aq Ar a 1594set out of set 1595.Aq Ar b . 1596Flags not specified in 1597.Aq Ar b 1598are ignored. 1599For stateful connections, the default is 1600.Ar flags S/SA . 1601To indicate that flags should not be checked at all, specify 1602.Ar flags any . 1603The flags are: (F)IN, (S)YN, (R)ST, (P)USH, (A)CK, (U)RG, (E)CE, and C(W)R. 1604.Bl -tag -width Fl 1605.It Ar flags S/S 1606Flag SYN is set. 1607The other flags are ignored. 1608.It Ar flags S/SA 1609This is the default setting for stateful connections. 1610Out of SYN and ACK, exactly SYN may be set. 1611SYN, SYN+PSH and SYN+RST match, but SYN+ACK, ACK and ACK+RST do not. 1612This is more restrictive than the previous example. 1613.It Ar flags /SFRA 1614If the first set is not specified, it defaults to none. 1615All of SYN, FIN, RST and ACK must be unset. 1616.El 1617.Pp 1618Because 1619.Ar flags S/SA 1620is applied by default (unless 1621.Ar no state 1622is specified), only the initial SYN packet of a TCP handshake will create 1623a state for a TCP connection. 1624It is possible to be less restrictive, and allow state creation from 1625intermediate 1626.Pq non-SYN 1627packets, by specifying 1628.Ar flags any . 1629This will cause 1630.Xr pf 4 1631to synchronize to existing connections, for instance 1632if one flushes the state table. 1633However, states created from such intermediate packets may be missing 1634connection details such as the TCP window scaling factor. 1635States which modify the packet flow, such as those affected by 1636.Ar nat , binat No or Ar rdr 1637rules, 1638.Ar modulate No or Ar synproxy state 1639options, or scrubbed with 1640.Ar reassemble tcp 1641will also not be recoverable from intermediate packets. 1642Such connections will stall and time out. 1643.It Ar icmp-type Ao Ar type Ac Ar code Ao Ar code Ac 1644.It Ar icmp6-type Ao Ar type Ac Ar code Ao Ar code Ac 1645This rule only applies to ICMP or ICMPv6 packets with the specified type 1646and code. 1647Text names for ICMP types and codes are listed in 1648.Xr icmp 4 1649and 1650.Xr icmp6 4 . 1651This parameter is only valid for rules that cover protocols ICMP or 1652ICMP6. 1653The protocol and the ICMP type indicator 1654.Po 1655.Ar icmp-type 1656or 1657.Ar icmp6-type 1658.Pc 1659must match. 1660.It Ar tos Ao Ar string Ac No \*(Ba Aq Ar number 1661This rule applies to packets with the specified 1662.Em TOS 1663bits set. 1664.Em TOS 1665may be 1666given as one of 1667.Ar lowdelay , 1668.Ar throughput , 1669.Ar reliability , 1670or as either hex or decimal. 1671.Pp 1672For example, the following rules are identical: 1673.Bd -literal -offset indent 1674pass all tos lowdelay 1675pass all tos 0x10 1676pass all tos 16 1677.Ed 1678.It Ar allow-opts 1679By default, IPv4 packets with IP options or IPv6 packets with routing 1680extension headers are blocked. 1681When 1682.Ar allow-opts 1683is specified for a 1684.Ar pass 1685rule, packets that pass the filter based on that rule (last matching) 1686do so even if they contain IP options or routing extension headers. 1687For packets that match state, the rule that initially created the 1688state is used. 1689The implicit 1690.Ar pass 1691rule that is used when a packet does not match any rules does not 1692allow IP options. 1693.It Ar label Aq Ar string 1694Adds a label (name) to the rule, which can be used to identify the rule. 1695For instance, 1696pfctl -s labels 1697shows per-rule statistics for rules that have labels. 1698.Pp 1699The following macros can be used in labels: 1700.Pp 1701.Bl -tag -width $srcaddr -compact -offset indent 1702.It Ar $if 1703The interface. 1704.It Ar $srcaddr 1705The source IP address. 1706.It Ar $dstaddr 1707The destination IP address. 1708.It Ar $srcport 1709The source port specification. 1710.It Ar $dstport 1711The destination port specification. 1712.It Ar $proto 1713The protocol name. 1714.It Ar $nr 1715The rule number. 1716.El 1717.Pp 1718For example: 1719.Bd -literal -offset indent 1720ips = \&"{ 1.2.3.4, 1.2.3.5 }\&" 1721pass in proto tcp from any to $ips \e 1722 port \*(Gt 1023 label \&"$dstaddr:$dstport\&" 1723.Ed 1724.Pp 1725expands to 1726.Bd -literal -offset indent 1727pass in inet proto tcp from any to 1.2.3.4 \e 1728 port \*(Gt 1023 label \&"1.2.3.4:\*(Gt1023\&" 1729pass in inet proto tcp from any to 1.2.3.5 \e 1730 port \*(Gt 1023 label \&"1.2.3.5:\*(Gt1023\&" 1731.Ed 1732.Pp 1733The macro expansion for the 1734.Ar label 1735directive occurs only at configuration file parse time, not during runtime. 1736.It Ar queue Ao Ar queue Ac No \*(Ba ( Ao Ar queue Ac , Aq Ar queue ) 1737Packets matching this rule will be assigned to the specified queue. 1738If two queues are given, packets which have a 1739.Em TOS 1740of 1741.Em lowdelay 1742and TCP ACKs with no data payload will be assigned to the second one. 1743See 1744.Sx QUEUEING 1745for setup details. 1746.Pp 1747For example: 1748.Bd -literal -offset indent 1749pass in proto tcp to port 25 queue mail 1750pass in proto tcp to port 22 queue(ssh_bulk, ssh_prio) 1751.Ed 1752.It Ar tag Aq Ar string 1753Packets matching this rule will be tagged with the 1754specified string. 1755The tag acts as an internal marker that can be used to 1756identify these packets later on. 1757This can be used, for example, to provide trust between 1758interfaces and to determine if packets have been 1759processed by translation rules. 1760Tags are 1761.Qq sticky , 1762meaning that the packet will be tagged even if the rule 1763is not the last matching rule. 1764Further matching rules can replace the tag with a 1765new one but will not remove a previously applied tag. 1766A packet is only ever assigned one tag at a time. 1767Packet tagging can be done during 1768.Ar nat , 1769.Ar rdr , 1770or 1771.Ar binat 1772rules in addition to filter rules. 1773Tags take the same macros as labels (see above). 1774.It Ar tagged Aq Ar string 1775Used with filter or translation rules to specify that packets must already 1776be tagged with the given tag in order to match the rule. 1777Inverse tag matching can also be done 1778by specifying the 1779.Cm !\& 1780operator before the 1781.Ar tagged 1782keyword. 1783.It Ar rtable Aq Ar number 1784Used to select an alternate routing table for the routing lookup. 1785Only effective before the route lookup happened, i.e. when filtering inbound. 1786.It Ar probability Aq Ar number 1787A probability attribute can be attached to a rule, with a value set between 17880 and 1, bounds not included. 1789In that case, the rule will be honoured using the given probability value 1790only. 1791For example, the following rule will drop 20% of incoming ICMP packets: 1792.Bd -literal -offset indent 1793block in proto icmp probability 20% 1794.Ed 1795.El 1796.Sh ROUTING 1797If a packet matches a rule with a route option set, the packet filter will 1798route the packet according to the type of route option. 1799When such a rule creates state, the route option is also applied to all 1800packets matching the same connection. 1801.Bl -tag -width xxxx 1802.It Ar fastroute 1803The 1804.Ar fastroute 1805option does a normal route lookup to find the next hop for the packet. 1806.It Ar route-to 1807The 1808.Ar route-to 1809option routes the packet to the specified interface with an optional address 1810for the next hop. 1811When a 1812.Ar route-to 1813rule creates state, only packets that pass in the same direction as the 1814filter rule specifies will be routed in this way. 1815Packets passing in the opposite direction (replies) are not affected 1816and are routed normally. 1817.It Ar reply-to 1818The 1819.Ar reply-to 1820option is similar to 1821.Ar route-to , 1822but routes packets that pass in the opposite direction (replies) to the 1823specified interface. 1824Opposite direction is only defined in the context of a state entry, and 1825.Ar reply-to 1826is useful only in rules that create state. 1827It can be used on systems with multiple external connections to 1828route all outgoing packets of a connection through the interface 1829the incoming connection arrived through (symmetric routing enforcement). 1830.It Ar dup-to 1831The 1832.Ar dup-to 1833option creates a duplicate of the packet and routes it like 1834.Ar route-to . 1835The original packet gets routed as it normally would. 1836.El 1837.Sh POOL OPTIONS 1838For 1839.Ar nat 1840and 1841.Ar rdr 1842rules, (as well as for the 1843.Ar route-to , 1844.Ar reply-to 1845and 1846.Ar dup-to 1847rule options) for which there is a single redirection address which has a 1848subnet mask smaller than 32 for IPv4 or 128 for IPv6 (more than one IP 1849address), a variety of different methods for assigning this address can be 1850used: 1851.Bl -tag -width xxxx 1852.It Ar bitmask 1853The 1854.Ar bitmask 1855option applies the network portion of the redirection address to the address 1856to be modified (source with 1857.Ar nat , 1858destination with 1859.Ar rdr ) . 1860.It Ar random 1861The 1862.Ar random 1863option selects an address at random within the defined block of addresses. 1864.It Ar source-hash 1865The 1866.Ar source-hash 1867option uses a hash of the source address to determine the redirection address, 1868ensuring that the redirection address is always the same for a given source. 1869An optional key can be specified after this keyword either in hex or as a 1870string; by default 1871.Xr pfctl 8 1872randomly generates a key for source-hash every time the 1873ruleset is reloaded. 1874.It Ar round-robin 1875The 1876.Ar round-robin 1877option loops through the redirection address(es). 1878.Pp 1879When more than one redirection address is specified, 1880.Ar round-robin 1881is the only permitted pool type. 1882.It Ar static-port 1883With 1884.Ar nat 1885rules, the 1886.Ar static-port 1887option prevents 1888.Xr pf 4 1889from modifying the source port on TCP and UDP packets. 1890.El 1891.Pp 1892Additionally, the 1893.Ar sticky-address 1894option can be specified to help ensure that multiple connections from the 1895same source are mapped to the same redirection address. 1896This option can be used with the 1897.Ar random 1898and 1899.Ar round-robin 1900pool options. 1901Note that by default these associations are destroyed as soon as there are 1902no longer states which refer to them; in order to make the mappings last 1903beyond the lifetime of the states, increase the global options with 1904.Ar set timeout src.track . 1905See 1906.Sx STATEFUL TRACKING OPTIONS 1907for more ways to control the source tracking. 1908.Sh STATE MODULATION 1909Much of the security derived from TCP is attributable to how well the 1910initial sequence numbers (ISNs) are chosen. 1911Some popular stack implementations choose 1912.Em very 1913poor ISNs and thus are normally susceptible to ISN prediction exploits. 1914By applying a 1915.Ar modulate state 1916rule to a TCP connection, 1917.Xr pf 4 1918will create a high quality random sequence number for each connection 1919endpoint. 1920.Pp 1921The 1922.Ar modulate state 1923directive implicitly keeps state on the rule and is 1924only applicable to TCP connections. 1925.Pp 1926For instance: 1927.Bd -literal -offset indent 1928block all 1929pass out proto tcp from any to any modulate state 1930pass in proto tcp from any to any port 25 flags S/SFRA modulate state 1931.Ed 1932.Pp 1933Note that modulated connections will not recover when the state table 1934is lost (firewall reboot, flushing the state table, etc...). 1935.Xr pf 4 1936will not be able to infer a connection again after the state table flushes 1937the connection's modulator. 1938When the state is lost, the connection may be left dangling until the 1939respective endpoints time out the connection. 1940It is possible on a fast local network for the endpoints to start an ACK 1941storm while trying to resynchronize after the loss of the modulator. 1942The default 1943.Ar flags 1944settings (or a more strict equivalent) should be used on 1945.Ar modulate state 1946rules to prevent ACK storms. 1947.Pp 1948Note that alternative methods are available 1949to prevent loss of the state table 1950and allow for firewall failover. 1951See 1952.Xr carp 4 1953and 1954.Xr pfsync 4 1955for further information. 1956.Sh SYN PROXY 1957By default, 1958.Xr pf 4 1959passes packets that are part of a 1960.Xr tcp 4 1961handshake between the endpoints. 1962The 1963.Ar synproxy state 1964option can be used to cause 1965.Xr pf 4 1966itself to complete the handshake with the active endpoint, perform a handshake 1967with the passive endpoint, and then forward packets between the endpoints. 1968.Pp 1969No packets are sent to the passive endpoint before the active endpoint has 1970completed the handshake, hence so-called SYN floods with spoofed source 1971addresses will not reach the passive endpoint, as the sender can't complete the 1972handshake. 1973.Pp 1974The proxy is transparent to both endpoints, they each see a single 1975connection from/to the other endpoint. 1976.Xr pf 4 1977chooses random initial sequence numbers for both handshakes. 1978Once the handshakes are completed, the sequence number modulators 1979(see previous section) are used to translate further packets of the 1980connection. 1981.Ar synproxy state 1982includes 1983.Ar modulate state . 1984.Pp 1985Rules with 1986.Ar synproxy 1987will not work if 1988.Xr pf 4 1989operates on a 1990.Xr bridge 4 . 1991.Pp 1992Example: 1993.Bd -literal -offset indent 1994pass in proto tcp from any to any port www synproxy state 1995.Ed 1996.Sh STATEFUL TRACKING OPTIONS 1997A number of options related to stateful tracking can be applied on a 1998per-rule basis. 1999.Ar keep state , 2000.Ar modulate state 2001and 2002.Ar synproxy state 2003support these options, and 2004.Ar keep state 2005must be specified explicitly to apply options to a rule. 2006.Pp 2007.Bl -tag -width xxxx -compact 2008.It Ar max Aq Ar number 2009Limits the number of concurrent states the rule may create. 2010When this limit is reached, further packets matching the rule that would 2011create state are dropped, until existing states time out. 2012.\" .It Ar no-sync 2013.\" Prevent state changes for states created by this rule from appearing on the 2014.\" .Xr pfsync 4 2015.\" interface. 2016.It Ao Ar timeout Ac Aq Ar seconds 2017Changes the timeout values used for states created by this rule. 2018For a list of all valid timeout names, see 2019.Sx OPTIONS 2020above. 2021.El 2022.Pp 2023Multiple options can be specified, separated by commas: 2024.Bd -literal -offset indent 2025pass in proto tcp from any to any \e 2026 port www keep state \e 2027 (max 100, source-track rule, max-src-nodes 75, \e 2028 max-src-states 3, tcp.established 60, tcp.closing 5) 2029.Ed 2030.Pp 2031When the 2032.Ar source-track 2033keyword is specified, the number of states per source IP is tracked. 2034.Pp 2035.Bl -tag -width xxxx -compact 2036.It Ar source-track rule 2037The maximum number of states created by this rule is limited by the rule's 2038.Ar max-src-nodes 2039and 2040.Ar max-src-states 2041options. 2042Only state entries created by this particular rule count toward the rule's 2043limits. 2044.It Ar source-track global 2045The number of states created by all rules that use this option is limited. 2046Each rule can specify different 2047.Ar max-src-nodes 2048and 2049.Ar max-src-states 2050options, however state entries created by any participating rule count towards 2051each individual rule's limits. 2052.El 2053.Pp 2054The following limits can be set: 2055.Pp 2056.Bl -tag -width xxxx -compact 2057.It Ar max-src-nodes Aq Ar number 2058Limits the maximum number of source addresses which can simultaneously 2059have state table entries. 2060.It Ar max-src-states Aq Ar number 2061Limits the maximum number of simultaneous state entries that a single 2062source address can create with this rule. 2063.El 2064.Pp 2065For stateful TCP connections, limits on established connections (connections 2066which have completed the TCP 3-way handshake) can also be enforced 2067per source IP. 2068.Pp 2069.Bl -tag -width xxxx -compact 2070.It Ar max-src-conn Aq Ar number 2071Limits the maximum number of simultaneous TCP connections which have 2072completed the 3-way handshake that a single host can make. 2073.It Ar max-src-conn-rate Ao Ar number Ac No / Aq Ar seconds 2074Limit the rate of new connections over a time interval. 2075The connection rate is an approximation calculated as a moving average. 2076.El 2077.Pp 2078Because the 3-way handshake ensures that the source address is not being 2079spoofed, more aggressive action can be taken based on these limits. 2080With the 2081.Ar overload Aq Ar table 2082state option, source IP addresses which hit either of the limits on 2083established connections will be added to the named table. 2084This table can be used in the ruleset to block further activity from 2085the offending host, redirect it to a tarpit process, or restrict its 2086bandwidth. 2087.Pp 2088The optional 2089.Ar flush 2090keyword kills all states created by the matching rule which originate 2091from the host which exceeds these limits. 2092The 2093.Ar global 2094modifier to the flush command kills all states originating from the 2095offending host, regardless of which rule created the state. 2096.Pp 2097For example, the following rules will protect the webserver against 2098hosts making more than 100 connections in 10 seconds. 2099Any host which connects faster than this rate will have its address added 2100to the 2101.Aq bad_hosts 2102table and have all states originating from it flushed. 2103Any new packets arriving from this host will be dropped unconditionally 2104by the block rule. 2105.Bd -literal -offset indent 2106block quick from \*(Ltbad_hosts\*(Gt 2107pass in on $ext_if proto tcp to $webserver port www keep state \e 2108 (max-src-conn-rate 100/10, overload \*(Ltbad_hosts\*(Gt flush global) 2109.Ed 2110.Pp 2111You can adjust the state policy on individual 2112.Ar nat 2113and 2114.Ar rdr 2115translation rules by adding a keyword 2116.Ar if-bound , 2117.Ar group-bound 2118or 2119.Ar floating 2120at the end of the rule. 2121For example, a rule such as this, 2122.Bd -literal -offset indent 2123nat on sip0 from 10/8 to ! 10/8 -> 192.168.1.4/32 if-bound 2124.Ed 2125.Pp 2126will create states that only match packets on sip0. 2127.Sh OPERATING SYSTEM FINGERPRINTING 2128Passive OS Fingerprinting is a mechanism to inspect nuances of a TCP 2129connection's initial SYN packet and guess at the host's operating system. 2130Unfortunately these nuances are easily spoofed by an attacker so the 2131fingerprint is not useful in making security decisions. 2132But the fingerprint is typically accurate enough to make policy decisions 2133upon. 2134.Pp 2135The fingerprints may be specified by operating system class, by 2136version, or by subtype/patchlevel. 2137The class of an operating system is typically the vendor or genre 2138and would be 2139.Ox 2140for the 2141.Xr pf 4 2142firewall itself. 2143The version of the oldest available 2144.Ox 2145release on the main FTP site 2146would be 2.6 and the fingerprint would be written 2147.Pp 2148.Dl \&"OpenBSD 2.6\&" 2149.Pp 2150The subtype of an operating system is typically used to describe the 2151patchlevel if that patch led to changes in the TCP stack behavior. 2152In the case of 2153.Ox , 2154the only subtype is for a fingerprint that was 2155normalized by the 2156.Ar no-df 2157scrub option and would be specified as 2158.Pp 2159.Dl \&"OpenBSD 3.3 no-df\&" 2160.Pp 2161Fingerprints for most popular operating systems are provided by 2162.Xr pf.os 5 . 2163Once 2164.Xr pf 4 2165is running, a complete list of known operating system fingerprints may 2166be listed by running: 2167.Pp 2168.Dl # pfctl -so 2169.Pp 2170Filter rules can enforce policy at any level of operating system specification 2171assuming a fingerprint is present. 2172Policy could limit traffic to approved operating systems or even ban traffic 2173from hosts that aren't at the latest service pack. 2174.Pp 2175The 2176.Ar unknown 2177class can also be used as the fingerprint which will match packets for 2178which no operating system fingerprint is known. 2179.Pp 2180Examples: 2181.Bd -literal -offset indent 2182pass out proto tcp from any os OpenBSD 2183block out proto tcp from any os Doors 2184block out proto tcp from any os "Doors PT" 2185block out proto tcp from any os "Doors PT SP3" 2186block out from any os "unknown" 2187pass on lo0 proto tcp from any os "OpenBSD 3.3 lo0" 2188.Ed 2189.Pp 2190Operating system fingerprinting is limited only to the TCP SYN packet. 2191This means that it will not work on other protocols and will not match 2192a currently established connection. 2193.Pp 2194Caveat: operating system fingerprints are occasionally wrong. 2195There are three problems: an attacker can trivially craft his packets to 2196appear as any operating system he chooses; 2197an operating system patch could change the stack behavior and no fingerprints 2198will match it until the database is updated; 2199and multiple operating systems may have the same fingerprint. 2200.Sh BLOCKING SPOOFED TRAFFIC 2201"Spoofing" is the faking of IP addresses, typically for malicious 2202purposes. 2203The 2204.Ar antispoof 2205directive expands to a set of filter rules which will block all 2206traffic with a source IP from the network(s) directly connected 2207to the specified interface(s) from entering the system through 2208any other interface. 2209.Pp 2210For example, the line 2211.Bd -literal -offset indent 2212antispoof for lo0 2213.Ed 2214.Pp 2215expands to 2216.Bd -literal -offset indent 2217block drop in on ! lo0 inet from 127.0.0.1/8 to any 2218block drop in on ! lo0 inet6 from ::1 to any 2219.Ed 2220.Pp 2221For non-loopback interfaces, there are additional rules to block incoming 2222packets with a source IP address identical to the interface's IP(s). 2223For example, assuming the interface wi0 had an IP address of 10.0.0.1 and a 2224netmask of 255.255.255.0, 2225the line 2226.Bd -literal -offset indent 2227antispoof for wi0 inet 2228.Ed 2229.Pp 2230expands to 2231.Bd -literal -offset indent 2232block drop in on ! wi0 inet from 10.0.0.0/24 to any 2233block drop in inet from 10.0.0.1 to any 2234.Ed 2235.Pp 2236Caveat: Rules created by the 2237.Ar antispoof 2238directive interfere with packets sent over loopback interfaces 2239to local addresses. 2240One should pass these explicitly. 2241.Sh FRAGMENT HANDLING 2242The size of IP datagrams (packets) can be significantly larger than the 2243maximum transmission unit (MTU) of the network. 2244In cases when it is necessary or more efficient to send such large packets, 2245the large packet will be fragmented into many smaller packets that will each 2246fit onto the wire. 2247Unfortunately for a firewalling device, only the first logical fragment will 2248contain the necessary header information for the subprotocol that allows 2249.Xr pf 4 2250to filter on things such as TCP ports or to perform NAT. 2251.Pp 2252Besides the use of 2253.Ar scrub 2254rules as described in 2255.Sx TRAFFIC NORMALIZATION 2256above, there are three options for handling fragments in the packet filter. 2257.Pp 2258One alternative is to filter individual fragments with filter rules. 2259If no 2260.Ar scrub 2261rule applies to a fragment, it is passed to the filter. 2262Filter rules with matching IP header parameters decide whether the 2263fragment is passed or blocked, in the same way as complete packets 2264are filtered. 2265Without reassembly, fragments can only be filtered based on IP header 2266fields (source/destination address, protocol), since subprotocol header 2267fields are not available (TCP/UDP port numbers, ICMP code/type). 2268The 2269.Ar fragment 2270option can be used to restrict filter rules to apply only to 2271fragments, but not complete packets. 2272Filter rules without the 2273.Ar fragment 2274option still apply to fragments, if they only specify IP header fields. 2275For instance, the rule 2276.Bd -literal -offset indent 2277pass in proto tcp from any to any port 80 2278.Ed 2279.Pp 2280never applies to a fragment, even if the fragment is part of a TCP 2281packet with destination port 80, because without reassembly this information 2282is not available for each fragment. 2283This also means that fragments cannot create new or match existing 2284state table entries, which makes stateful filtering and address 2285translation (NAT, redirection) for fragments impossible. 2286.Pp 2287It's also possible to reassemble only certain fragments by specifying 2288source or destination addresses or protocols as parameters in 2289.Ar scrub 2290rules. 2291.Pp 2292In most cases, the benefits of reassembly outweigh the additional 2293memory cost, and it's recommended to use 2294.Ar scrub 2295rules to reassemble 2296all fragments via the 2297.Ar fragment reassemble 2298modifier. 2299.Pp 2300The memory allocated for fragment caching can be limited using 2301.Xr pfctl 8 . 2302Once this limit is reached, fragments that would have to be cached 2303are dropped until other entries time out. 2304The timeout value can also be adjusted. 2305.Pp 2306Currently, only IPv4 fragments are supported and IPv6 fragments 2307are blocked unconditionally. 2308.Sh ANCHORS 2309Besides the main ruleset, 2310.Xr pfctl 8 2311can load rulesets into 2312.Ar anchor 2313attachment points. 2314An 2315.Ar anchor 2316is a container that can hold rules, address tables, and other anchors. 2317.Pp 2318An 2319.Ar anchor 2320has a name which specifies the path where 2321.Xr pfctl 8 2322can be used to access the anchor to perform operations on it, such as 2323attaching child anchors to it or loading rules into it. 2324Anchors may be nested, with components separated by 2325.Sq / 2326characters, similar to how file system hierarchies are laid out. 2327The main ruleset is actually the default anchor, so filter and 2328translation rules, for example, may also be contained in any anchor. 2329.Pp 2330An anchor can reference another 2331.Ar anchor 2332attachment point 2333using the following kinds 2334of rules: 2335.Bl -tag -width xxxx 2336.It Ar nat-anchor Aq Ar name 2337Evaluates the 2338.Ar nat 2339rules in the specified 2340.Ar anchor . 2341.It Ar rdr-anchor Aq Ar name 2342Evaluates the 2343.Ar rdr 2344rules in the specified 2345.Ar anchor . 2346.It Ar binat-anchor Aq Ar name 2347Evaluates the 2348.Ar binat 2349rules in the specified 2350.Ar anchor . 2351.It Ar anchor Aq Ar name 2352Evaluates the filter rules in the specified 2353.Ar anchor . 2354.It Ar load anchor Ao Ar name Ac Ar from Aq Ar file 2355Loads the rules from the specified file into the 2356anchor 2357.Ar name . 2358.El 2359.Pp 2360When evaluation of the main ruleset reaches an 2361.Ar anchor 2362rule, 2363.Xr pf 4 2364will proceed to evaluate all rules specified in that anchor. 2365.Pp 2366Matching filter and translation rules marked with the 2367.Ar quick 2368option are final and abort the evaluation of the rules in other 2369anchors and the main ruleset. 2370If the 2371.Ar anchor 2372itself is marked with the 2373.Ar quick 2374option, 2375ruleset evaluation will terminate when the anchor is exited if the packet is 2376matched by any rule within the anchor. 2377.Pp 2378.Ar anchor 2379rules are evaluated relative to the anchor in which they are contained. 2380For example, all 2381.Ar anchor 2382rules specified in the main ruleset will reference anchor 2383attachment points underneath the main ruleset, and 2384.Ar anchor 2385rules specified in a file loaded from a 2386.Ar load anchor 2387rule will be attached under that anchor point. 2388.Pp 2389Rules may be contained in 2390.Ar anchor 2391attachment points which do not contain any rules when the main ruleset 2392is loaded, and later such anchors can be manipulated through 2393.Xr pfctl 8 2394without reloading the main ruleset or other anchors. 2395For example, 2396.Bd -literal -offset indent 2397ext_if = \&"kue0\&" 2398block on $ext_if all 2399anchor spam 2400pass out on $ext_if all 2401pass in on $ext_if proto tcp from any \e 2402 to $ext_if port smtp 2403.Ed 2404.Pp 2405blocks all packets on the external interface by default, then evaluates 2406all rules in the 2407.Ar anchor 2408named "spam", and finally passes all outgoing connections and 2409incoming connections to port 25. 2410.Bd -literal -offset indent 2411# echo \&"block in quick from 1.2.3.4 to any\&" \&| \e 2412 pfctl -a spam -f - 2413.Ed 2414.Pp 2415This loads a single rule into the 2416.Ar anchor , 2417which blocks all packets from a specific address. 2418.Pp 2419The anchor can also be populated by adding a 2420.Ar load anchor 2421rule after the 2422.Ar anchor 2423rule: 2424.Bd -literal -offset indent 2425anchor spam 2426load anchor spam from "/etc/pf-spam.conf" 2427.Ed 2428.Pp 2429When 2430.Xr pfctl 8 2431loads 2432.Nm pf.conf , 2433it will also load all the rules from the file 2434.Pa /etc/pf-spam.conf 2435into the anchor. 2436.Pp 2437Optionally, 2438.Ar anchor 2439rules can specify the parameter's 2440direction, interface, address family, protocol and source/destination 2441address/port 2442using the same syntax as filter rules. 2443When parameters are used, the 2444.Ar anchor 2445rule is only evaluated for matching packets. 2446This allows conditional evaluation of anchors, like: 2447.Bd -literal -offset indent 2448block on $ext_if all 2449anchor spam proto tcp from any to any port smtp 2450pass out on $ext_if all 2451pass in on $ext_if proto tcp from any to $ext_if port smtp 2452.Ed 2453.Pp 2454The rules inside 2455.Ar anchor 2456spam are only evaluated for 2457.Ar tcp 2458packets with destination port 25. 2459Hence, 2460.Bd -literal -offset indent 2461# echo \&"block in quick from 1.2.3.4 to any" \&| \e 2462 pfctl -a spam -f - 2463.Ed 2464.Pp 2465will only block connections from 1.2.3.4 to port 25. 2466.Pp 2467Anchors may end with the asterisk 2468.Pq Sq * 2469character, which signifies that all anchors attached at that point 2470should be evaluated in the alphabetical ordering of their anchor name. 2471For example, 2472.Bd -literal -offset indent 2473anchor "spam/*" 2474.Ed 2475.Pp 2476will evaluate each rule in each anchor attached to the 2477.Li spam 2478anchor. 2479Note that it will only evaluate anchors that are directly attached to the 2480.Li spam 2481anchor, and will not descend to evaluate anchors recursively. 2482.Pp 2483Since anchors are evaluated relative to the anchor in which they are 2484contained, there is a mechanism for accessing the parent and ancestor 2485anchors of a given anchor. 2486Similar to file system path name resolution, if the sequence 2487.Dq .. 2488appears as an anchor path component, the parent anchor of the current 2489anchor in the path evaluation at that point will become the new current 2490anchor. 2491As an example, consider the following: 2492.Bd -literal -offset indent 2493# echo ' anchor "spam/allowed" ' | pfctl -f - 2494# echo -e ' anchor "../banned" \en pass' | \e 2495 pfctl -a spam/allowed -f - 2496.Ed 2497.Pp 2498Evaluation of the main ruleset will lead into the 2499.Li spam/allowed 2500anchor, which will evaluate the rules in the 2501.Li spam/banned 2502anchor, if any, before finally evaluating the 2503.Ar pass 2504rule. 2505.Pp 2506Filter rule 2507.Ar anchors 2508can also be loaded inline in the ruleset within a brace ('{' '}') delimited 2509block. 2510Brace delimited blocks may contain rules or other brace-delimited blocks. 2511When anchors are loaded this way the anchor name becomes optional. 2512.Bd -literal -offset indent 2513anchor "external" on egress { 2514 block 2515 anchor out { 2516 pass proto tcp from any to port { 25, 80, 443 } 2517 } 2518 pass in proto tcp to any port 22 2519} 2520.Ed 2521.Pp 2522Since the parser specification for anchor names is a string, any 2523reference to an anchor name containing solidus 2524.Pq Sq / 2525characters will require double quote 2526.Pq Sq \&" 2527characters around the anchor name. 2528.Sh TRANSLATION EXAMPLES 2529This example maps incoming requests on port 80 to port 8080, on 2530which a daemon is running (because, for example, it is not run as root, 2531and therefore lacks permission to bind to port 80). 2532.Bd -literal 2533# use a macro for the interface name, so it can be changed easily 2534ext_if = \&"ne3\&" 2535 2536# map daemon on 8080 to appear to be on 80 2537rdr on $ext_if proto tcp from any to any port 80 -\*(Gt 127.0.0.1 port 8080 2538.Ed 2539.Pp 2540If the 2541.Ar pass 2542modifier is given, packets matching the translation rule are passed without 2543inspecting the filter rules: 2544.Bd -literal 2545rdr pass on $ext_if proto tcp from any to any port 80 -\*(Gt 127.0.0.1 \e 2546 port 8080 2547.Ed 2548.Pp 2549In the example below, vlan12 is configured as 192.168.168.1; 2550the machine translates all packets coming from 192.168.168.0/24 to 204.92.77.111 2551when they are going out any interface except vlan12. 2552This has the net effect of making traffic from the 192.168.168.0/24 2553network appear as though it is the Internet routable address 2554204.92.77.111 to nodes behind any interface on the router except 2555for the nodes on vlan12. 2556(Thus, 192.168.168.1 can talk to the 192.168.168.0/24 nodes.) 2557.Bd -literal 2558nat on ! vlan12 from 192.168.168.0/24 to any -\*(Gt 204.92.77.111 2559.Ed 2560.Pp 2561In the example below, the machine sits between a fake internal 144.19.74.* 2562network, and a routable external IP of 204.92.77.100. 2563The 2564.Ar no nat 2565rule excludes protocol AH from being translated. 2566.Bd -literal 2567# NO NAT 2568no nat on $ext_if proto ah from 144.19.74.0/24 to any 2569nat on $ext_if from 144.19.74.0/24 to any -\*(Gt 204.92.77.100 2570.Ed 2571.Pp 2572In the example below, packets bound for one specific server, as well as those 2573generated by the sysadmins are not proxied; all other connections are. 2574.Bd -literal 2575# NO RDR 2576no rdr on $int_if proto { tcp, udp } from any to $server port 80 2577no rdr on $int_if proto { tcp, udp } from $sysadmins to any port 80 2578rdr on $int_if proto { tcp, udp } from any to any port 80 -\*(Gt 127.0.0.1 \e 2579 port 80 2580.Ed 2581.Pp 2582This longer example uses both a NAT and a redirection. 2583The external interface has the address 157.161.48.183. 2584On localhost, we are running 2585.Xr ftp-proxy 8 , 2586waiting for FTP sessions to be redirected to it. 2587The three mandatory anchors for 2588.Xr ftp-proxy 8 2589are omitted from this example; see the 2590.Xr ftp-proxy 8 2591manpage. 2592.Bd -literal 2593# NAT 2594# Translate outgoing packets' source addresses (any protocol). 2595# In this case, any address but the gateway's external address is mapped. 2596nat on $ext_if inet from ! ($ext_if) to any -\*(Gt ($ext_if) 2597 2598# NAT PROXYING 2599# Map outgoing packets' source port to an assigned proxy port instead of 2600# an arbitrary port. 2601# In this case, proxy outgoing isakmp with port 500 on the gateway. 2602nat on $ext_if inet proto udp from any port = isakmp to any -\*(Gt ($ext_if) \e 2603 port 500 2604 2605# BINAT 2606# Translate outgoing packets' source address (any protocol). 2607# Translate incoming packets' destination address to an internal machine 2608# (bidirectional). 2609binat on $ext_if from 10.1.2.150 to any -\*(Gt $ext_if 2610 2611# RDR 2612# Translate incoming packets' destination addresses. 2613# As an example, redirect a TCP and UDP port to an internal machine. 2614rdr on $ext_if inet proto tcp from any to ($ext_if) port 8080 \e 2615 -\*(Gt 10.1.2.151 port 22 2616rdr on $ext_if inet proto udp from any to ($ext_if) port 8080 \e 2617 -\*(Gt 10.1.2.151 port 53 2618 2619# RDR 2620# Translate outgoing ftp control connections to send them to localhost 2621# for proxying with ftp-proxy(8) running on port 8021. 2622rdr on $int_if proto tcp from any to any port 21 -\*(Gt 127.0.0.1 port 8021 2623.Ed 2624.Pp 2625In this example, a NAT gateway is set up to translate internal addresses 2626using a pool of public addresses (192.0.2.16/28) and to redirect 2627incoming web server connections to a group of web servers on the internal 2628network. 2629.Bd -literal 2630# NAT LOAD BALANCE 2631# Translate outgoing packets' source addresses using an address pool. 2632# A given source address is always translated to the same pool address by 2633# using the source-hash keyword. 2634nat on $ext_if inet from any to any -\*(Gt 192.0.2.16/28 source-hash 2635 2636# RDR ROUND ROBIN 2637# Translate incoming web server connections to a group of web servers on 2638# the internal network. 2639rdr on $ext_if proto tcp from any to any port 80 \e 2640 -\*(Gt { 10.1.2.155, 10.1.2.160, 10.1.2.161 } round-robin 2641.Ed 2642.Sh FILTER EXAMPLES 2643.Bd -literal 2644# The external interface is kue0 2645# (157.161.48.183, the only routable address) 2646# and the private network is 10.0.0.0/8, for which we are doing NAT. 2647 2648# use a macro for the interface name, so it can be changed easily 2649ext_if = \&"kue0\&" 2650 2651# normalize all incoming traffic 2652scrub in on $ext_if all fragment reassemble 2653 2654# block and log everything by default 2655block return log on $ext_if all 2656 2657# block anything coming from source we have no back routes for 2658block in from no-route to any 2659 2660# block packets whose ingress interface does not match the one in 2661# the route back to their source address 2662block in from urpf-failed to any 2663 2664# block and log outgoing packets that do not have our address as source, 2665# they are either spoofed or something is misconfigured (NAT disabled, 2666# for instance), we want to be nice and do not send out garbage. 2667block out log quick on $ext_if from ! 157.161.48.183 to any 2668 2669# silently drop broadcasts (cable modem noise) 2670block in quick on $ext_if from any to 255.255.255.255 2671 2672# block and log incoming packets from reserved address space and invalid 2673# addresses, they are either spoofed or misconfigured, we cannot reply to 2674# them anyway (hence, no return-rst). 2675block in log quick on $ext_if from { 10.0.0.0/8, 172.16.0.0/12, \e 2676 192.168.0.0/16, 255.255.255.255/32 } to any 2677 2678# ICMP 2679 2680# pass out/in certain ICMP queries and keep state (ping) 2681# state matching is done on host addresses and ICMP id (not type/code), 2682# so replies (like 0/0 for 8/0) will match queries 2683# ICMP error messages (which always refer to a TCP/UDP packet) are 2684# handled by the TCP/UDP states 2685pass on $ext_if inet proto icmp all icmp-type 8 code 0 2686 2687# UDP 2688 2689# pass out all UDP connections and keep state 2690pass out on $ext_if proto udp all 2691 2692# pass in certain UDP connections and keep state (DNS) 2693pass in on $ext_if proto udp from any to any port domain 2694 2695# TCP 2696 2697# pass out all TCP connections and modulate state 2698pass out on $ext_if proto tcp all modulate state 2699 2700# pass in certain TCP connections and keep state (SSH, SMTP, DNS, IDENT) 2701pass in on $ext_if proto tcp from any to any port { ssh, smtp, domain, \e 2702 auth } 2703 2704# Do not allow Windows 9x SMTP connections since they are typically 2705# a viral worm. Alternately we could limit these OSes to 1 connection each. 2706block in on $ext_if proto tcp from any os {"Windows 95", "Windows 98"} \e 2707 to any port smtp 2708 2709# IPv6 2710# pass in/out all IPv6 traffic: note that we have to enable this in two 2711# different ways, on both our physical interface and our tunnel 2712pass quick on gif0 inet6 2713pass quick on $ext_if proto ipv6 2714 2715# Packet Tagging 2716 2717# three interfaces: $int_if, $ext_if, and $wifi_if (wireless). NAT is 2718# being done on $ext_if for all outgoing packets. tag packets in on 2719# $int_if and pass those tagged packets out on $ext_if. all other 2720# outgoing packets (i.e., packets from the wireless network) are only 2721# permitted to access port 80. 2722 2723pass in on $int_if from any to any tag INTNET 2724pass in on $wifi_if from any to any 2725 2726block out on $ext_if from any to any 2727pass out quick on $ext_if tagged INTNET 2728pass out on $ext_if proto tcp from any to any port 80 2729 2730# tag incoming packets as they are redirected to spamd(8). use the tag 2731# to pass those packets through the packet filter. 2732 2733rdr on $ext_if inet proto tcp from \*(Ltspammers\*(Gt to port smtp \e 2734 tag SPAMD -\*(Gt 127.0.0.1 port spamd 2735 2736block in on $ext_if 2737pass in on $ext_if inet proto tcp tagged SPAMD 2738.Ed 2739.Sh GRAMMAR 2740Syntax for 2741.Nm 2742in BNF: 2743.Bd -literal 2744line = ( option | pf-rule | nat-rule | binat-rule | rdr-rule | 2745 antispoof-rule | altq-rule | queue-rule | trans-anchors | 2746 anchor-rule | anchor-close | load-anchor | table-rule | ) 2747 2748option = "set" ( [ "timeout" ( timeout | "{" timeout-list "}" ) ] | 2749 [ "ruleset-optimization" [ "none" | "basic" | "profile" ]] | 2750 [ "optimization" [ "default" | "normal" | 2751 "high-latency" | "satellite" | 2752 "aggressive" | "conservative" ] ] 2753 [ "limit" ( limit-item | "{" limit-list "}" ) ] | 2754 [ "loginterface" ( interface-name | "none" ) ] | 2755 [ "block-policy" ( "drop" | "return" ) ] | 2756 [ "state-policy" ( "if-bound" | "floating" ) ] 2757 [ "require-order" ( "yes" | "no" ) ] 2758 [ "fingerprints" filename ] | 2759 [ "skip on" ifspec ] | 2760 [ "debug" ( "none" | "urgent" | "misc" | "loud" ) ] ) 2761 2762pf-rule = action [ ( "in" | "out" ) ] 2763 [ "log" [ "(" logopts ")"] ] [ "quick" ] 2764 [ "on" ifspec ] [ "fastroute" | route ] [ af ] [ protospec ] 2765 hosts [ filteropt-list ] 2766 2767logopts = logopt [ "," logopts ] 2768logopt = "all" | "user" | "to" interface-name 2769 2770filteropt-list = filteropt-list filteropt | filteropt 2771filteropt = user | group | flags | icmp-type | icmp6-type | tos | 2772 ( "no" | "keep" | "modulate" | "synproxy" ) "state" 2773 [ "(" state-opts ")" ] | 2774 "fragment" | "no-df" | "min-ttl" number | 2775 "max-mss" number | "random-id" | "reassemble tcp" | 2776 fragmentation | "allow-opts" | 2777 "label" string | "tag" string | [ ! ] "tagged" string | 2778 "queue" ( string | "(" string [ [ "," ] string ] ")" ) | 2779 "rtable" number | "probability" number"%" 2780 2781nat-rule = [ "no" ] "nat" [ "pass" [ "log" [ "(" logopts ")" ] ] ] 2782 [ "on" ifspec ] [ af ] 2783 [ protospec ] hosts [ "tag" string ] [ "tagged" string ] 2784 [ "-\*(Gt" ( redirhost | "{" redirhost-list "}" ) 2785 [ portspec ] [ pooltype ] [ "static-port" ] ] 2786 [ ( "if-bound" | "group-bound" | "floating" ) ] 2787 2788binat-rule = [ "no" ] "binat" [ "pass" [ "log" [ "(" logopts ")" ] ] ] 2789 [ "on" interface-name ] [ af ] 2790 [ "proto" ( proto-name | proto-number ) ] 2791 "from" address [ "/" mask-bits ] "to" ipspec 2792 [ "tag" string ] [ "tagged" string ] 2793 [ "-\*(Gt" address [ "/" mask-bits ] ] 2794 2795rdr-rule = [ "no" ] "rdr" [ "pass" [ "log" [ "(" logopts ")" ] ] ] 2796 [ "on" ifspec ] [ af ] 2797 [ protospec ] hosts [ "tag" string ] [ "tagged" string ] 2798 [ "-\*(Gt" ( redirhost | "{" redirhost-list "}" ) 2799 [ portspec ] [ pooltype ] ] 2800 [ ( "if-bound" | "group-bound" | "floating" ) ] 2801 2802antispoof-rule = "antispoof" [ "log" ] [ "quick" ] 2803 "for" ifspec [ af ] [ "label" string ] 2804 2805table-rule = "table" "\*(Lt" string "\*(Gt" [ tableopts-list ] 2806tableopts-list = tableopts-list tableopts | tableopts 2807tableopts = "persist" | "const" | "file" string | 2808 "{" [ tableaddr-list ] "}" 2809tableaddr-list = tableaddr-list [ "," ] tableaddr-spec | tableaddr-spec 2810tableaddr-spec = [ "!" ] tableaddr [ "/" mask-bits ] 2811tableaddr = hostname | ifspec | "self" | 2812 ipv4-dotted-quad | ipv6-coloned-hex 2813 2814altq-rule = "altq on" interface-name queueopts-list 2815 "queue" subqueue 2816queue-rule = "queue" string [ "on" interface-name ] queueopts-list 2817 subqueue 2818 2819anchor-rule = "anchor" [ string ] [ ( "in" | "out" ) ] [ "on" ifspec ] 2820 [ af ] [ protospec ] [ hosts ] [ "{" ] 2821 2822anchor-close = "}" 2823 2824trans-anchors = ( "nat-anchor" | "rdr-anchor" | "binat-anchor" ) string 2825 [ "on" ifspec ] [ af ] [ "proto" ] [ protospec ] [ hosts ] 2826 2827load-anchor = "load anchor" string "from" filename 2828 2829queueopts-list = queueopts-list queueopts | queueopts 2830queueopts = [ "bandwidth" bandwidth-spec ] | 2831 [ "qlimit" number ] | [ "tbrsize" number ] | 2832 [ "priority" number ] | [ schedulers ] 2833schedulers = ( cbq-def | priq-def | hfsc-def ) 2834bandwidth-spec = "number" ( "b" | "Kb" | "Mb" | "Gb" | "%" ) 2835 2836action = "pass" | "block" [ return ] | [ "no" ] "scrub" 2837return = "drop" | "return" | "return-rst" [ "( ttl" number ")" ] | 2838 "return-icmp" [ "(" icmpcode [ [ "," ] icmp6code ] ")" ] | 2839 "return-icmp6" [ "(" icmp6code ")" ] 2840icmpcode = ( icmp-code-name | icmp-code-number ) 2841icmp6code = ( icmp6-code-name | icmp6-code-number ) 2842 2843ifspec = ( [ "!" ] ( interface-name | interface-group ) ) | 2844 "{" interface-list "}" 2845interface-list = [ "!" ] ( interface-name | interface-group ) 2846 [ [ "," ] interface-list ] 2847route = ( "route-to" | "reply-to" | "dup-to" ) 2848 ( routehost | "{" routehost-list "}" ) 2849 [ pooltype ] 2850af = "inet" | "inet6" 2851 2852protospec = "proto" ( proto-name | proto-number | 2853 "{" proto-list "}" ) 2854proto-list = ( proto-name | proto-number ) [ [ "," ] proto-list ] 2855 2856hosts = "all" | 2857 "from" ( "any" | "no-route" | "urpf-failed" | "self" | host | 2858 "{" host-list "}" | "route" string ) [ port ] [ os ] 2859 "to" ( "any" | "no-route" | "self" | host | 2860 "{" host-list "}" | "route" string ) [ port ] 2861 2862ipspec = "any" | host | "{" host-list "}" 2863host = [ "!" ] ( address [ "/" mask-bits ] | "\*(Lt" string "\*(Gt" ) 2864redirhost = address [ "/" mask-bits ] 2865routehost = "(" interface-name [ address [ "/" mask-bits ] ] ")" 2866address = ( interface-name | interface-group | 2867 "(" ( interface-name | interface-group ) ")" | 2868 hostname | ipv4-dotted-quad | ipv6-coloned-hex ) 2869host-list = host [ [ "," ] host-list ] 2870redirhost-list = redirhost [ [ "," ] redirhost-list ] 2871routehost-list = routehost [ [ "," ] routehost-list ] 2872 2873port = "port" ( unary-op | binary-op | "{" op-list "}" ) 2874portspec = "port" ( number | name ) [ ":" ( "*" | number | name ) ] 2875os = "os" ( os-name | "{" os-list "}" ) 2876user = "user" ( unary-op | binary-op | "{" op-list "}" ) 2877.\" group = "group" ( unary-op | binary-op | "{" op-list "}" ) 2878 2879unary-op = [ "=" | "!=" | "\*(Lt" | "\*(Le" | "\*(Gt" | "\*(Ge" ] 2880 ( name | number ) 2881binary-op = number ( "\*(Lt\*(Gt" | "\*(Gt\*(Lt" | ":" ) number 2882op-list = ( unary-op | binary-op ) [ [ "," ] op-list ] 2883 2884os-name = operating-system-name 2885os-list = os-name [ [ "," ] os-list ] 2886 2887flags = "flags" ( [ flag-set ] "/" flag-set | "any" ) 2888flag-set = [ "F" ] [ "S" ] [ "R" ] [ "P" ] [ "A" ] [ "U" ] [ "E" ] 2889 [ "W" ] 2890 2891icmp-type = "icmp-type" ( icmp-type-code | "{" icmp-list "}" ) 2892icmp6-type = "icmp6-type" ( icmp-type-code | "{" icmp-list "}" ) 2893icmp-type-code = ( icmp-type-name | icmp-type-number ) 2894 [ "code" ( icmp-code-name | icmp-code-number ) ] 2895icmp-list = icmp-type-code [ [ "," ] icmp-list ] 2896 2897tos = "tos" ( "lowdelay" | "throughput" | "reliability" | 2898 [ "0x" ] number ) 2899 2900state-opts = state-opt [ [ "," ] state-opts ] 2901state-opt = ( "max" number | timeout | 2902 "source-track" [ ( "rule" | "global" ) ] | 2903 "max-src-nodes" number | "max-src-states" number | 2904 "max-src-conn" number | 2905 "max-src-conn-rate" number "/" number | 2906 "overload" "\*(Lt" string "\*(Gt" [ "flush" ] | 2907 "if-bound" | "floating" ) 2908 2909fragmentation = [ "fragment reassemble" | "fragment crop" | 2910 "fragment drop-ovl" ] 2911 2912timeout-list = timeout [ [ "," ] timeout-list ] 2913timeout = ( "tcp.first" | "tcp.opening" | "tcp.established" | 2914 "tcp.closing" | "tcp.finwait" | "tcp.closed" | 2915 "udp.first" | "udp.single" | "udp.multiple" | 2916 "icmp.first" | "icmp.error" | 2917 "other.first" | "other.single" | "other.multiple" | 2918 "frag" | "interval" | "src.track" | 2919 "adaptive.start" | "adaptive.end" ) number 2920 2921limit-list = limit-item [ [ "," ] limit-list ] 2922limit-item = ( "states" | "frags" | "src-nodes" ) number 2923 2924pooltype = ( "bitmask" | "random" | 2925 "source-hash" [ ( hex-key | string-key ) ] | 2926 "round-robin" ) [ sticky-address ] 2927 2928subqueue = string | "{" queue-list "}" 2929queue-list = string [ [ "," ] string ] 2930cbq-def = "cbq" [ "(" cbq-opt [ [ "," ] cbq-opt ] ")" ] 2931priq-def = "priq" [ "(" priq-opt [ [ "," ] priq-opt ] ")" ] 2932hfsc-def = "hfsc" [ "(" hfsc-opt [ [ "," ] hfsc-opt ] ")" ] 2933cbq-opt = ( "default" | "borrow" | "red" | "ecn" | "rio" ) 2934priq-opt = ( "default" | "red" | "ecn" | "rio" ) 2935hfsc-opt = ( "default" | "red" | "ecn" | "rio" | 2936 linkshare-sc | realtime-sc | upperlimit-sc ) 2937linkshare-sc = "linkshare" sc-spec 2938realtime-sc = "realtime" sc-spec 2939upperlimit-sc = "upperlimit" sc-spec 2940sc-spec = ( bandwidth-spec | 2941 "(" bandwidth-spec number bandwidth-spec ")" ) 2942.Ed 2943.Sh FILES 2944.Bl -tag -width "/etc/protocols" -compact 2945.It Pa /etc/hosts 2946Host name database. 2947.It Pa /etc/pf.conf 2948Default location of the ruleset file. 2949.It Pa /etc/pf.os 2950Default location of OS fingerprints. 2951.It Pa /etc/protocols 2952Protocol name database. 2953.It Pa /etc/services 2954Service name database. 2955.It Pa /usr/share/examples/pf 2956Example rulesets. 2957.El 2958.Sh SEE ALSO 2959.Xr carp 4 , 2960.Xr icmp 4 , 2961.Xr icmp6 4 , 2962.Xr ip 4 , 2963.Xr ip6 4 , 2964.Xr pf 4 , 2965.\" .Xr pfsync 4 , 2966.Xr route 4 , 2967.Xr tcp 4 , 2968.Xr udp 4 , 2969.Xr hosts 5 , 2970.Xr pf.os 5 , 2971.Xr protocols 5 , 2972.Xr services 5 , 2973.Xr ftp-proxy 8 , 2974.Xr pfctl 8 , 2975.Xr pflogd 8 , 2976.Xr route 8 2977.Sh HISTORY 2978The 2979.Nm 2980file format first appeared in 2981.Ox 3.0 . 2982