13b3a8eb9SGleb Smirnoff.\" $OpenBSD: pf.conf.5,v 1.406 2009/01/31 19:37:12 sobrado Exp $ 23b3a8eb9SGleb Smirnoff.\" 33b3a8eb9SGleb Smirnoff.\" Copyright (c) 2002, Daniel Hartmeier 43b3a8eb9SGleb Smirnoff.\" All rights reserved. 53b3a8eb9SGleb Smirnoff.\" 63b3a8eb9SGleb Smirnoff.\" Redistribution and use in source and binary forms, with or without 73b3a8eb9SGleb Smirnoff.\" modification, are permitted provided that the following conditions 83b3a8eb9SGleb Smirnoff.\" are met: 93b3a8eb9SGleb Smirnoff.\" 103b3a8eb9SGleb Smirnoff.\" - Redistributions of source code must retain the above copyright 113b3a8eb9SGleb Smirnoff.\" notice, this list of conditions and the following disclaimer. 123b3a8eb9SGleb Smirnoff.\" - Redistributions in binary form must reproduce the above 133b3a8eb9SGleb Smirnoff.\" copyright notice, this list of conditions and the following 143b3a8eb9SGleb Smirnoff.\" disclaimer in the documentation and/or other materials provided 153b3a8eb9SGleb Smirnoff.\" with the distribution. 163b3a8eb9SGleb Smirnoff.\" 173b3a8eb9SGleb Smirnoff.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 183b3a8eb9SGleb Smirnoff.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 193b3a8eb9SGleb Smirnoff.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 203b3a8eb9SGleb Smirnoff.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 213b3a8eb9SGleb Smirnoff.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 223b3a8eb9SGleb Smirnoff.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 233b3a8eb9SGleb Smirnoff.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 243b3a8eb9SGleb Smirnoff.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 253b3a8eb9SGleb Smirnoff.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 263b3a8eb9SGleb Smirnoff.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 273b3a8eb9SGleb Smirnoff.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 283b3a8eb9SGleb Smirnoff.\" POSSIBILITY OF SUCH DAMAGE. 293b3a8eb9SGleb Smirnoff.\" 30*618a8766SKristof Provost.Dd February 11, 2025 313b3a8eb9SGleb Smirnoff.Dt PF.CONF 5 323b3a8eb9SGleb Smirnoff.Os 333b3a8eb9SGleb Smirnoff.Sh NAME 343b3a8eb9SGleb Smirnoff.Nm pf.conf 353b3a8eb9SGleb Smirnoff.Nd packet filter configuration file 363b3a8eb9SGleb Smirnoff.Sh DESCRIPTION 373b3a8eb9SGleb SmirnoffThe 383b3a8eb9SGleb Smirnoff.Xr pf 4 393b3a8eb9SGleb Smirnoffpacket filter modifies, drops or passes packets according to rules or 403b3a8eb9SGleb Smirnoffdefinitions specified in 413b3a8eb9SGleb Smirnoff.Nm pf.conf . 423b3a8eb9SGleb Smirnoff.Sh STATEMENT ORDER 43ab2886f0SKristof ProvostThere are eight types of statements in 443b3a8eb9SGleb Smirnoff.Nm pf.conf : 453b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx 463b3a8eb9SGleb Smirnoff.It Cm Macros 473b3a8eb9SGleb SmirnoffUser-defined variables may be defined and used later, simplifying 483b3a8eb9SGleb Smirnoffthe configuration file. 493b3a8eb9SGleb SmirnoffMacros must be defined before they are referenced in 503b3a8eb9SGleb Smirnoff.Nm pf.conf . 513b3a8eb9SGleb Smirnoff.It Cm Tables 523b3a8eb9SGleb SmirnoffTables provide a mechanism for increasing the performance and flexibility of 533b3a8eb9SGleb Smirnoffrules with large numbers of source or destination addresses. 543b3a8eb9SGleb Smirnoff.It Cm Options 553b3a8eb9SGleb SmirnoffOptions tune the behaviour of the packet filtering engine. 56ab2886f0SKristof Provost.It Cm Ethernet Filtering 57ab2886f0SKristof ProvostEthernet filtering provides rule-based blocking or passing of Ethernet packets. 583b3a8eb9SGleb Smirnoff.It Cm Traffic Normalization Li (e.g. Em scrub ) 593b3a8eb9SGleb SmirnoffTraffic normalization protects internal machines against inconsistencies 603b3a8eb9SGleb Smirnoffin Internet protocols and implementations. 613b3a8eb9SGleb Smirnoff.It Cm Queueing 623b3a8eb9SGleb SmirnoffQueueing provides rule-based bandwidth control. 633b3a8eb9SGleb Smirnoff.It Cm Translation Li (Various forms of NAT) 643b3a8eb9SGleb SmirnoffTranslation rules specify how addresses are to be mapped or redirected to 653b3a8eb9SGleb Smirnoffother addresses. 663b3a8eb9SGleb Smirnoff.It Cm Packet Filtering 673b3a8eb9SGleb SmirnoffPacket filtering provides rule-based blocking or passing of packets. 683b3a8eb9SGleb Smirnoff.El 693b3a8eb9SGleb Smirnoff.Pp 703b3a8eb9SGleb SmirnoffWith the exception of 713b3a8eb9SGleb Smirnoff.Cm macros 723b3a8eb9SGleb Smirnoffand 733b3a8eb9SGleb Smirnoff.Cm tables , 743b3a8eb9SGleb Smirnoffthe types of statements should be grouped and appear in 753b3a8eb9SGleb Smirnoff.Nm pf.conf 763b3a8eb9SGleb Smirnoffin the order shown above, as this matches the operation of the underlying 773b3a8eb9SGleb Smirnoffpacket filtering engine. 783b3a8eb9SGleb SmirnoffBy default 793b3a8eb9SGleb Smirnoff.Xr pfctl 8 803b3a8eb9SGleb Smirnoffenforces this order (see 813b3a8eb9SGleb Smirnoff.Ar set require-order 823b3a8eb9SGleb Smirnoffbelow). 833b3a8eb9SGleb Smirnoff.Pp 843b3a8eb9SGleb SmirnoffComments can be put anywhere in the file using a hash mark 853b3a8eb9SGleb Smirnoff.Pq Sq # , 863b3a8eb9SGleb Smirnoffand extend to the end of the current line. 873b3a8eb9SGleb Smirnoff.Pp 883b3a8eb9SGleb SmirnoffAdditional configuration files can be included with the 893b3a8eb9SGleb Smirnoff.Ic include 903b3a8eb9SGleb Smirnoffkeyword, for example: 913b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 923b3a8eb9SGleb Smirnoffinclude "/etc/pf/sub.filter.conf" 933b3a8eb9SGleb Smirnoff.Ed 943b3a8eb9SGleb Smirnoff.Sh MACROS 953b3a8eb9SGleb SmirnoffMacros can be defined that will later be expanded in context. 963b3a8eb9SGleb SmirnoffMacro names must start with a letter, and may contain letters, digits 973b3a8eb9SGleb Smirnoffand underscores. 983b3a8eb9SGleb SmirnoffMacro names may not be reserved words (for example 993b3a8eb9SGleb Smirnoff.Ar pass , 1003b3a8eb9SGleb Smirnoff.Ar in , 1013b3a8eb9SGleb Smirnoff.Ar out ) . 1023b3a8eb9SGleb SmirnoffMacros are not expanded inside quotes. 1033b3a8eb9SGleb Smirnoff.Pp 1043b3a8eb9SGleb SmirnoffFor example, 1053b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 1063b3a8eb9SGleb Smirnoffext_if = \&"kue0\&" 1073b3a8eb9SGleb Smirnoffall_ifs = \&"{\&" $ext_if lo0 \&"}\&" 1083b3a8eb9SGleb Smirnoffpass out on $ext_if from any to any 1093b3a8eb9SGleb Smirnoffpass in on $ext_if proto tcp from any to any port 25 1103b3a8eb9SGleb Smirnoff.Ed 1113b3a8eb9SGleb Smirnoff.Sh TABLES 1123b3a8eb9SGleb SmirnoffTables are named structures which can hold a collection of addresses and 1133b3a8eb9SGleb Smirnoffnetworks. 1143b3a8eb9SGleb SmirnoffLookups against tables in 1153b3a8eb9SGleb Smirnoff.Xr pf 4 1163b3a8eb9SGleb Smirnoffare relatively fast, making a single rule with tables much more efficient, 1173b3a8eb9SGleb Smirnoffin terms of 1183b3a8eb9SGleb Smirnoffprocessor usage and memory consumption, than a large number of rules which 1193b3a8eb9SGleb Smirnoffdiffer only in IP address (either created explicitly or automatically by rule 1203b3a8eb9SGleb Smirnoffexpansion). 1213b3a8eb9SGleb Smirnoff.Pp 1223b3a8eb9SGleb SmirnoffTables can be used as the source or destination of filter rules, 1233b3a8eb9SGleb Smirnoff.Ar scrub 1243b3a8eb9SGleb Smirnoffrules 1253b3a8eb9SGleb Smirnoffor 1263b3a8eb9SGleb Smirnofftranslation rules such as 1273b3a8eb9SGleb Smirnoff.Ar nat 1283b3a8eb9SGleb Smirnoffor 1293b3a8eb9SGleb Smirnoff.Ar rdr 1303b3a8eb9SGleb Smirnoff(see below for details on the various rule types). 1313b3a8eb9SGleb SmirnoffTables can also be used for the redirect address of 1323b3a8eb9SGleb Smirnoff.Ar nat 1333b3a8eb9SGleb Smirnoffand 1343b3a8eb9SGleb Smirnoff.Ar rdr 1353b3a8eb9SGleb Smirnoffrules and in the routing options of filter rules, but only for 1363b3a8eb9SGleb Smirnoff.Ar round-robin 1373b3a8eb9SGleb Smirnoffpools. 1383b3a8eb9SGleb Smirnoff.Pp 1393b3a8eb9SGleb SmirnoffTables can be defined with any of the following 1403b3a8eb9SGleb Smirnoff.Xr pfctl 8 1413b3a8eb9SGleb Smirnoffmechanisms. 1423b3a8eb9SGleb SmirnoffAs with macros, reserved words may not be used as table names. 1433b3a8eb9SGleb Smirnoff.Bl -tag -width "manually" 1443b3a8eb9SGleb Smirnoff.It Ar manually 1453b3a8eb9SGleb SmirnoffPersistent tables can be manually created with the 1463b3a8eb9SGleb Smirnoff.Ar add 1473b3a8eb9SGleb Smirnoffor 1483b3a8eb9SGleb Smirnoff.Ar replace 1493b3a8eb9SGleb Smirnoffoption of 1503b3a8eb9SGleb Smirnoff.Xr pfctl 8 , 1513b3a8eb9SGleb Smirnoffbefore or after the ruleset has been loaded. 1523b3a8eb9SGleb Smirnoff.It Pa pf.conf 1533b3a8eb9SGleb SmirnoffTable definitions can be placed directly in this file, and loaded at the 1543b3a8eb9SGleb Smirnoffsame time as other rules are loaded, atomically. 1553b3a8eb9SGleb SmirnoffTable definitions inside 1563b3a8eb9SGleb Smirnoff.Nm pf.conf 1573b3a8eb9SGleb Smirnoffuse the 1583b3a8eb9SGleb Smirnoff.Ar table 1593b3a8eb9SGleb Smirnoffstatement, and are especially useful to define non-persistent tables. 1603b3a8eb9SGleb SmirnoffThe contents of a pre-existing table defined without a list of addresses 1613b3a8eb9SGleb Smirnoffto initialize it is not altered when 1623b3a8eb9SGleb Smirnoff.Nm pf.conf 1633b3a8eb9SGleb Smirnoffis loaded. 1643b3a8eb9SGleb SmirnoffA table initialized with the empty list, 1653b3a8eb9SGleb Smirnoff.Li { } , 1663b3a8eb9SGleb Smirnoffwill be cleared on load. 1673b3a8eb9SGleb Smirnoff.El 1683b3a8eb9SGleb Smirnoff.Pp 1693b3a8eb9SGleb SmirnoffTables may be defined with the following attributes: 1703b3a8eb9SGleb Smirnoff.Bl -tag -width persist 1713b3a8eb9SGleb Smirnoff.It Ar persist 1723b3a8eb9SGleb SmirnoffThe 1733b3a8eb9SGleb Smirnoff.Ar persist 1743b3a8eb9SGleb Smirnoffflag forces the kernel to keep the table even when no rules refer to it. 1753b3a8eb9SGleb SmirnoffIf the flag is not set, the kernel will automatically remove the table 1763b3a8eb9SGleb Smirnoffwhen the last rule referring to it is flushed. 1773b3a8eb9SGleb Smirnoff.It Ar const 1783b3a8eb9SGleb SmirnoffThe 1793b3a8eb9SGleb Smirnoff.Ar const 1803b3a8eb9SGleb Smirnoffflag prevents the user from altering the contents of the table once it 1813b3a8eb9SGleb Smirnoffhas been created. 1823b3a8eb9SGleb SmirnoffWithout that flag, 1833b3a8eb9SGleb Smirnoff.Xr pfctl 8 1843b3a8eb9SGleb Smirnoffcan be used to add or remove addresses from the table at any time, even 1853b3a8eb9SGleb Smirnoffwhen running with 1863b3a8eb9SGleb Smirnoff.Xr securelevel 7 1873b3a8eb9SGleb Smirnoff= 2. 1883b3a8eb9SGleb Smirnoff.It Ar counters 1893b3a8eb9SGleb SmirnoffThe 1903b3a8eb9SGleb Smirnoff.Ar counters 1913b3a8eb9SGleb Smirnoffflag enables per-address packet and byte counters which can be displayed with 1923b3a8eb9SGleb Smirnoff.Xr pfctl 8 . 19321121f9bSMark JohnstonNote that this feature carries significant memory overhead for large tables. 1943b3a8eb9SGleb Smirnoff.El 1953b3a8eb9SGleb Smirnoff.Pp 1963b3a8eb9SGleb SmirnoffFor example, 1973b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 1983b3a8eb9SGleb Smirnofftable \*(Ltprivate\*(Gt const { 10/8, 172.16/12, 192.168/16 } 1993b3a8eb9SGleb Smirnofftable \*(Ltbadhosts\*(Gt persist 2003b3a8eb9SGleb Smirnoffblock on fxp0 from { \*(Ltprivate\*(Gt, \*(Ltbadhosts\*(Gt } to any 2013b3a8eb9SGleb Smirnoff.Ed 2023b3a8eb9SGleb Smirnoff.Pp 2033b3a8eb9SGleb Smirnoffcreates a table called private, to hold RFC 1918 private network 2043b3a8eb9SGleb Smirnoffblocks, and a table called badhosts, which is initially empty. 2053b3a8eb9SGleb SmirnoffA filter rule is set up to block all traffic coming from addresses listed in 2063b3a8eb9SGleb Smirnoffeither table. 2073b3a8eb9SGleb SmirnoffThe private table cannot have its contents changed and the badhosts table 2083b3a8eb9SGleb Smirnoffwill exist even when no active filter rules reference it. 2093b3a8eb9SGleb SmirnoffAddresses may later be added to the badhosts table, so that traffic from 2103b3a8eb9SGleb Smirnoffthese hosts can be blocked by using 2113b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 2123b3a8eb9SGleb Smirnoff# pfctl -t badhosts -Tadd 204.92.77.111 2133b3a8eb9SGleb Smirnoff.Ed 2143b3a8eb9SGleb Smirnoff.Pp 2153b3a8eb9SGleb SmirnoffA table can also be initialized with an address list specified in one or more 2163b3a8eb9SGleb Smirnoffexternal files, using the following syntax: 2173b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 2183b3a8eb9SGleb Smirnofftable \*(Ltspam\*(Gt persist file \&"/etc/spammers\&" file \&"/etc/openrelays\&" 2193b3a8eb9SGleb Smirnoffblock on fxp0 from \*(Ltspam\*(Gt to any 2203b3a8eb9SGleb Smirnoff.Ed 2213b3a8eb9SGleb Smirnoff.Pp 2223b3a8eb9SGleb SmirnoffThe files 2233b3a8eb9SGleb Smirnoff.Pa /etc/spammers 2243b3a8eb9SGleb Smirnoffand 2253b3a8eb9SGleb Smirnoff.Pa /etc/openrelays 2263b3a8eb9SGleb Smirnofflist IP addresses, one per line. 2273b3a8eb9SGleb SmirnoffAny lines beginning with a # are treated as comments and ignored. 2283b3a8eb9SGleb SmirnoffIn addition to being specified by IP address, hosts may also be 2293b3a8eb9SGleb Smirnoffspecified by their hostname. 2303b3a8eb9SGleb SmirnoffWhen the resolver is called to add a hostname to a table, 2313b3a8eb9SGleb Smirnoff.Em all 2323b3a8eb9SGleb Smirnoffresulting IPv4 and IPv6 addresses are placed into the table. 2333b3a8eb9SGleb SmirnoffIP addresses can also be entered in a table by specifying a valid interface 2343b3a8eb9SGleb Smirnoffname, a valid interface group or the 2353b3a8eb9SGleb Smirnoff.Em self 2363b3a8eb9SGleb Smirnoffkeyword, in which case all addresses assigned to the interface(s) will be 2373b3a8eb9SGleb Smirnoffadded to the table. 2383b3a8eb9SGleb Smirnoff.Sh OPTIONS 2393b3a8eb9SGleb Smirnoff.Xr pf 4 2403b3a8eb9SGleb Smirnoffmay be tuned for various situations using the 2413b3a8eb9SGleb Smirnoff.Ar set 2423b3a8eb9SGleb Smirnoffcommand. 2433b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx 2443b3a8eb9SGleb Smirnoff.It Ar set timeout 2453b3a8eb9SGleb Smirnoff.Pp 2463b3a8eb9SGleb Smirnoff.Bl -tag -width "src.track" -compact 2473b3a8eb9SGleb Smirnoff.It Ar interval 2483b3a8eb9SGleb SmirnoffInterval between purging expired states and fragments. 2493b3a8eb9SGleb Smirnoff.It Ar frag 2503b3a8eb9SGleb SmirnoffSeconds before an unassembled fragment is expired. 2513b3a8eb9SGleb Smirnoff.It Ar src.track 2523b3a8eb9SGleb SmirnoffLength of time to retain a source tracking entry after the last state 2533b3a8eb9SGleb Smirnoffexpires. 2543b3a8eb9SGleb Smirnoff.El 2553b3a8eb9SGleb Smirnoff.Pp 2563b3a8eb9SGleb SmirnoffWhen a packet matches a stateful connection, the seconds to live for the 2573b3a8eb9SGleb Smirnoffconnection will be updated to that of the 2583b3a8eb9SGleb Smirnoff.Ar proto.modifier 2593b3a8eb9SGleb Smirnoffwhich corresponds to the connection state. 2603b3a8eb9SGleb SmirnoffEach packet which matches this state will reset the TTL. 2613b3a8eb9SGleb SmirnoffTuning these values may improve the performance of the 2623b3a8eb9SGleb Smirnofffirewall at the risk of dropping valid idle connections. 2633b3a8eb9SGleb Smirnoff.Pp 2643b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx -compact 2653b3a8eb9SGleb Smirnoff.It Ar tcp.first 2663b3a8eb9SGleb SmirnoffThe state after the first packet. 2673b3a8eb9SGleb Smirnoff.It Ar tcp.opening 2680300b49aSKristof ProvostThe state after the second packet but before both endpoints have 2690300b49aSKristof Provostacknowledged the connection. 2703b3a8eb9SGleb Smirnoff.It Ar tcp.established 2713b3a8eb9SGleb SmirnoffThe fully established state. 2723b3a8eb9SGleb Smirnoff.It Ar tcp.closing 2733b3a8eb9SGleb SmirnoffThe state after the first FIN has been sent. 2743b3a8eb9SGleb Smirnoff.It Ar tcp.finwait 2753b3a8eb9SGleb SmirnoffThe state after both FINs have been exchanged and the connection is closed. 2763b3a8eb9SGleb SmirnoffSome hosts (notably web servers on Solaris) send TCP packets even after closing 2773b3a8eb9SGleb Smirnoffthe connection. 2783b3a8eb9SGleb SmirnoffIncreasing 2793b3a8eb9SGleb Smirnoff.Ar tcp.finwait 2803b3a8eb9SGleb Smirnoff(and possibly 2813b3a8eb9SGleb Smirnoff.Ar tcp.closing ) 2823b3a8eb9SGleb Smirnoffcan prevent blocking of such packets. 2833b3a8eb9SGleb Smirnoff.It Ar tcp.closed 2843b3a8eb9SGleb SmirnoffThe state after one endpoint sends an RST. 2853b3a8eb9SGleb Smirnoff.El 2863b3a8eb9SGleb Smirnoff.Pp 287ca9dbde8SKristof ProvostSCTP timeout are handled similar to TCP, but with its own set of states: 288ca9dbde8SKristof Provost.Pp 289ca9dbde8SKristof Provost.Bl -tag -width xxxx -compact 290ca9dbde8SKristof Provost.It Ar sctp.first 291ca9dbde8SKristof ProvostThe state after the first packet. 292ca9dbde8SKristof Provost.It Ar sctp.opening 293ca9dbde8SKristof ProvostThe state before the destination host ever sends a packet. 294ca9dbde8SKristof Provost.It Ar sctp.established 295ca9dbde8SKristof ProvostThe fully established state. 296ca9dbde8SKristof Provost.It Ar sctp.closing 297ca9dbde8SKristof ProvostThe state after the first SHUTDOWN chunk has been sent. 298ca9dbde8SKristof Provost.It Ar sctp.closed 299ca9dbde8SKristof ProvostThe state after SHUTDOWN_ACK has been exchanged and the connection is closed. 300ca9dbde8SKristof Provost.El 301ca9dbde8SKristof Provost.Pp 3023b3a8eb9SGleb SmirnoffICMP and UDP are handled in a fashion similar to TCP, but with a much more 3033b3a8eb9SGleb Smirnofflimited set of states: 3043b3a8eb9SGleb Smirnoff.Pp 3053b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx -compact 3063b3a8eb9SGleb Smirnoff.It Ar udp.first 3073b3a8eb9SGleb SmirnoffThe state after the first packet. 3083b3a8eb9SGleb Smirnoff.It Ar udp.single 3093b3a8eb9SGleb SmirnoffThe state if the source host sends more than one packet but the destination 3103b3a8eb9SGleb Smirnoffhost has never sent one back. 3113b3a8eb9SGleb Smirnoff.It Ar udp.multiple 3123b3a8eb9SGleb SmirnoffThe state if both hosts have sent packets. 3133b3a8eb9SGleb Smirnoff.It Ar icmp.first 3143b3a8eb9SGleb SmirnoffThe state after the first packet. 3153b3a8eb9SGleb Smirnoff.It Ar icmp.error 3163b3a8eb9SGleb SmirnoffThe state after an ICMP error came back in response to an ICMP packet. 3173b3a8eb9SGleb Smirnoff.El 3183b3a8eb9SGleb Smirnoff.Pp 3193b3a8eb9SGleb SmirnoffOther protocols are handled similarly to UDP: 3203b3a8eb9SGleb Smirnoff.Pp 3213b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx -compact 3223b3a8eb9SGleb Smirnoff.It Ar other.first 3233b3a8eb9SGleb Smirnoff.It Ar other.single 3243b3a8eb9SGleb Smirnoff.It Ar other.multiple 3253b3a8eb9SGleb Smirnoff.El 3263b3a8eb9SGleb Smirnoff.Pp 3273b3a8eb9SGleb SmirnoffTimeout values can be reduced adaptively as the number of state table 3283b3a8eb9SGleb Smirnoffentries grows. 3293b3a8eb9SGleb Smirnoff.Pp 3303b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx -compact 3313b3a8eb9SGleb Smirnoff.It Ar adaptive.start 3323b3a8eb9SGleb SmirnoffWhen the number of state entries exceeds this value, adaptive scaling 3333b3a8eb9SGleb Smirnoffbegins. 3343b3a8eb9SGleb SmirnoffAll timeout values are scaled linearly with factor 3353b3a8eb9SGleb Smirnoff(adaptive.end - number of states) / (adaptive.end - adaptive.start). 3363b3a8eb9SGleb Smirnoff.It Ar adaptive.end 3373b3a8eb9SGleb SmirnoffWhen reaching this number of state entries, all timeout values become 3383b3a8eb9SGleb Smirnoffzero, effectively purging all state entries immediately. 3393b3a8eb9SGleb SmirnoffThis value is used to define the scale factor, it should not actually 3403b3a8eb9SGleb Smirnoffbe reached (set a lower state limit, see below). 3413b3a8eb9SGleb Smirnoff.El 3423b3a8eb9SGleb Smirnoff.Pp 3433b3a8eb9SGleb SmirnoffAdaptive timeouts are enabled by default, with an adaptive.start value 3443b3a8eb9SGleb Smirnoffequal to 60% of the state limit, and an adaptive.end value equal to 3453b3a8eb9SGleb Smirnoff120% of the state limit. 3463b3a8eb9SGleb SmirnoffThey can be disabled by setting both adaptive.start and adaptive.end to 0. 3473b3a8eb9SGleb Smirnoff.Pp 3483b3a8eb9SGleb SmirnoffThe adaptive timeout values can be defined both globally and for each rule. 3493b3a8eb9SGleb SmirnoffWhen used on a per-rule basis, the values relate to the number of 3503b3a8eb9SGleb Smirnoffstates created by the rule, otherwise to the total number of 3513b3a8eb9SGleb Smirnoffstates. 3523b3a8eb9SGleb Smirnoff.Pp 3533b3a8eb9SGleb SmirnoffFor example: 3543b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 3553b3a8eb9SGleb Smirnoffset timeout tcp.first 120 3563b3a8eb9SGleb Smirnoffset timeout tcp.established 86400 3573b3a8eb9SGleb Smirnoffset timeout { adaptive.start 6000, adaptive.end 12000 } 3583b3a8eb9SGleb Smirnoffset limit states 10000 3593b3a8eb9SGleb Smirnoff.Ed 3603b3a8eb9SGleb Smirnoff.Pp 3613b3a8eb9SGleb SmirnoffWith 9000 state table entries, the timeout values are scaled to 50% 3623b3a8eb9SGleb Smirnoff(tcp.first 60, tcp.established 43200). 3633b3a8eb9SGleb Smirnoff.It Ar set loginterface 3643b3a8eb9SGleb SmirnoffEnable collection of packet and byte count statistics for the given 3653b3a8eb9SGleb Smirnoffinterface or interface group. 3663b3a8eb9SGleb SmirnoffThese statistics can be viewed using 3673b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 3683b3a8eb9SGleb Smirnoff# pfctl -s info 3693b3a8eb9SGleb Smirnoff.Ed 3703b3a8eb9SGleb Smirnoff.Pp 3713b3a8eb9SGleb SmirnoffIn this example 3723b3a8eb9SGleb Smirnoff.Xr pf 4 3733b3a8eb9SGleb Smirnoffcollects statistics on the interface named dc0: 3743b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 3753b3a8eb9SGleb Smirnoffset loginterface dc0 3763b3a8eb9SGleb Smirnoff.Ed 3773b3a8eb9SGleb Smirnoff.Pp 3783b3a8eb9SGleb SmirnoffOne can disable the loginterface using: 3793b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 3803b3a8eb9SGleb Smirnoffset loginterface none 3813b3a8eb9SGleb Smirnoff.Ed 3823b3a8eb9SGleb Smirnoff.It Ar set limit 3833b3a8eb9SGleb SmirnoffSets hard limits on the memory pools used by the packet filter. 3843b3a8eb9SGleb SmirnoffSee 3853b3a8eb9SGleb Smirnoff.Xr zone 9 3863b3a8eb9SGleb Smirnofffor an explanation of memory pools. 3873b3a8eb9SGleb Smirnoff.Pp 3883b3a8eb9SGleb SmirnoffFor example, 3893b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 3903b3a8eb9SGleb Smirnoffset limit states 20000 3913b3a8eb9SGleb Smirnoff.Ed 3923b3a8eb9SGleb Smirnoff.Pp 3933b3a8eb9SGleb Smirnoffsets the maximum number of entries in the memory pool used by state table 3943b3a8eb9SGleb Smirnoffentries (generated by 3953b3a8eb9SGleb Smirnoff.Ar pass 3963b3a8eb9SGleb Smirnoffrules which do not specify 3973b3a8eb9SGleb Smirnoff.Ar no state ) 3983b3a8eb9SGleb Smirnoffto 20000. 3993b3a8eb9SGleb SmirnoffUsing 4003b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 4013b3a8eb9SGleb Smirnoffset limit frags 20000 4023b3a8eb9SGleb Smirnoff.Ed 4033b3a8eb9SGleb Smirnoff.Pp 4043b3a8eb9SGleb Smirnoffsets the maximum number of entries in the memory pool used for fragment 4055ed470bdSKajetan Staszkiewiczreassembly (generated by the 4065ed470bdSKajetan Staszkiewicz.Ar set reassemble 4075ed470bdSKajetan Staszkiewiczoption or 4083b3a8eb9SGleb Smirnoff.Ar scrub 4093b3a8eb9SGleb Smirnoffrules) to 20000. 4103b3a8eb9SGleb SmirnoffUsing 4113b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 4123b3a8eb9SGleb Smirnoffset limit src-nodes 2000 4133b3a8eb9SGleb Smirnoff.Ed 4143b3a8eb9SGleb Smirnoff.Pp 4153b3a8eb9SGleb Smirnoffsets the maximum number of entries in the memory pool used for tracking 4163b3a8eb9SGleb Smirnoffsource IP addresses (generated by the 4173b3a8eb9SGleb Smirnoff.Ar sticky-address 4183b3a8eb9SGleb Smirnoffand 4193b3a8eb9SGleb Smirnoff.Ar src.track 4203b3a8eb9SGleb Smirnoffoptions) to 2000. 4213b3a8eb9SGleb SmirnoffUsing 4223b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 4233b3a8eb9SGleb Smirnoffset limit table-entries 100000 4243b3a8eb9SGleb Smirnoff.Ed 4253b3a8eb9SGleb Smirnoff.Pp 426ea6d6addSKristof Provostsets the limit on the overall number of addresses that can be stored 4273b3a8eb9SGleb Smirnoffin tables to 100000. 4283b3a8eb9SGleb Smirnoff.Pp 4293b3a8eb9SGleb SmirnoffVarious limits can be combined on a single line: 4303b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 4313b3a8eb9SGleb Smirnoffset limit { states 20000, frags 20000, src-nodes 2000 } 4323b3a8eb9SGleb Smirnoff.Ed 4333b3a8eb9SGleb Smirnoff.It Ar set ruleset-optimization 4343b3a8eb9SGleb Smirnoff.Bl -tag -width xxxxxxxx -compact 4353b3a8eb9SGleb Smirnoff.It Ar none 4363b3a8eb9SGleb SmirnoffDisable the ruleset optimizer. 4373b3a8eb9SGleb Smirnoff.It Ar basic 4383b3a8eb9SGleb SmirnoffEnable basic ruleset optimization. 4393b3a8eb9SGleb SmirnoffThis is the default behaviour. 4403b3a8eb9SGleb SmirnoffBasic ruleset optimization does four things to improve the 4413b3a8eb9SGleb Smirnoffperformance of ruleset evaluations: 4423b3a8eb9SGleb Smirnoff.Pp 4433b3a8eb9SGleb Smirnoff.Bl -enum -compact 4443b3a8eb9SGleb Smirnoff.It 4453b3a8eb9SGleb Smirnoffremove duplicate rules 4463b3a8eb9SGleb Smirnoff.It 4473b3a8eb9SGleb Smirnoffremove rules that are a subset of another rule 4483b3a8eb9SGleb Smirnoff.It 4493b3a8eb9SGleb Smirnoffcombine multiple rules into a table when advantageous 4503b3a8eb9SGleb Smirnoff.It 4513b3a8eb9SGleb Smirnoffre-order the rules to improve evaluation performance 4523b3a8eb9SGleb Smirnoff.El 4533b3a8eb9SGleb Smirnoff.Pp 4543b3a8eb9SGleb Smirnoff.It Ar profile 4553b3a8eb9SGleb SmirnoffUses the currently loaded ruleset as a feedback profile to tailor the 4563b3a8eb9SGleb Smirnoffordering of quick rules to actual network traffic. 4573b3a8eb9SGleb Smirnoff.El 4583b3a8eb9SGleb Smirnoff.Pp 4593b3a8eb9SGleb SmirnoffIt is important to note that the ruleset optimizer will modify the ruleset 4603b3a8eb9SGleb Smirnoffto improve performance. 4613b3a8eb9SGleb SmirnoffA side effect of the ruleset modification is that per-rule accounting 4623b3a8eb9SGleb Smirnoffstatistics will have different meanings than before. 4633b3a8eb9SGleb SmirnoffIf per-rule accounting is important for billing purposes or whatnot, 4643b3a8eb9SGleb Smirnoffeither the ruleset optimizer should not be used or a label field should 4653b3a8eb9SGleb Smirnoffbe added to all of the accounting rules to act as optimization barriers. 4663b3a8eb9SGleb Smirnoff.Pp 4673b3a8eb9SGleb SmirnoffOptimization can also be set as a command-line argument to 4683b3a8eb9SGleb Smirnoff.Xr pfctl 8 , 4693b3a8eb9SGleb Smirnoffoverriding the settings in 4703b3a8eb9SGleb Smirnoff.Nm . 4713b3a8eb9SGleb Smirnoff.It Ar set optimization 4723b3a8eb9SGleb SmirnoffOptimize state timeouts for one of the following network environments: 4733b3a8eb9SGleb Smirnoff.Pp 4743b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx -compact 4753b3a8eb9SGleb Smirnoff.It Ar normal 4763b3a8eb9SGleb SmirnoffA normal network environment. 4773b3a8eb9SGleb SmirnoffSuitable for almost all networks. 4783b3a8eb9SGleb Smirnoff.It Ar high-latency 4793b3a8eb9SGleb SmirnoffA high-latency environment (such as a satellite connection). 4803b3a8eb9SGleb Smirnoff.It Ar satellite 4813b3a8eb9SGleb SmirnoffAlias for 4823b3a8eb9SGleb Smirnoff.Ar high-latency . 4833b3a8eb9SGleb Smirnoff.It Ar aggressive 4843b3a8eb9SGleb SmirnoffAggressively expire connections. 4853b3a8eb9SGleb SmirnoffThis can greatly reduce the memory usage of the firewall at the cost of 4863b3a8eb9SGleb Smirnoffdropping idle connections early. 4873b3a8eb9SGleb Smirnoff.It Ar conservative 4883b3a8eb9SGleb SmirnoffExtremely conservative settings. 4893b3a8eb9SGleb SmirnoffAvoid dropping legitimate connections at the 4903b3a8eb9SGleb Smirnoffexpense of greater memory utilization (possibly much greater on a busy 4913b3a8eb9SGleb Smirnoffnetwork) and slightly increased processor utilization. 4923b3a8eb9SGleb Smirnoff.El 4933b3a8eb9SGleb Smirnoff.Pp 4943b3a8eb9SGleb SmirnoffFor example: 4953b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 4963b3a8eb9SGleb Smirnoffset optimization aggressive 4973b3a8eb9SGleb Smirnoff.Ed 4985ed470bdSKajetan Staszkiewicz.It Ar set reassemble yes | no Op Cm no-df 4995ed470bdSKajetan StaszkiewiczThe 5005ed470bdSKajetan Staszkiewicz.Cm reassemble 5015ed470bdSKajetan Staszkiewiczoption is used to enable or disable the reassembly of fragmented packets, 5025ed470bdSKajetan Staszkiewiczand can be set to 5035ed470bdSKajetan Staszkiewicz.Cm yes 5045ed470bdSKajetan Staszkiewiczor 5055ed470bdSKajetan Staszkiewicz.Cm no . 5065ed470bdSKajetan StaszkiewiczIf 5075ed470bdSKajetan Staszkiewicz.Cm no-df 5085ed470bdSKajetan Staszkiewiczis also specified, fragments with the 5095ed470bdSKajetan Staszkiewicz.Dq dont-fragment 5105ed470bdSKajetan Staszkiewiczbit set are reassembled too, 5115ed470bdSKajetan Staszkiewiczinstead of being dropped; 5125ed470bdSKajetan Staszkiewiczthe reassembled packet will have the 5135ed470bdSKajetan Staszkiewicz.Dq dont-fragment 5145ed470bdSKajetan Staszkiewiczbit cleared. 5155ed470bdSKajetan StaszkiewiczThe default value is 5165ed470bdSKajetan Staszkiewicz.Cm no . 5175ed470bdSKajetan Staszkiewicz.Pp 5185ed470bdSKajetan StaszkiewiczThis option is ignored if there are pre-FreeBSD 14 5195ed470bdSKajetan Staszkiewicz.Cm scrub 5205ed470bdSKajetan Staszkiewiczrules present. 5213b3a8eb9SGleb Smirnoff.It Ar set block-policy 5223b3a8eb9SGleb SmirnoffThe 5233b3a8eb9SGleb Smirnoff.Ar block-policy 5243b3a8eb9SGleb Smirnoffoption sets the default behaviour for the packet 5253b3a8eb9SGleb Smirnoff.Ar block 5263b3a8eb9SGleb Smirnoffaction: 5273b3a8eb9SGleb Smirnoff.Pp 5283b3a8eb9SGleb Smirnoff.Bl -tag -width xxxxxxxx -compact 5293b3a8eb9SGleb Smirnoff.It Ar drop 5303b3a8eb9SGleb SmirnoffPacket is silently dropped. 5313b3a8eb9SGleb Smirnoff.It Ar return 5323b3a8eb9SGleb SmirnoffA TCP RST is returned for blocked TCP packets, 53347d0c1feSKristof Provostan SCTP ABORT chunk is returned for blocked SCTP packets, 5343b3a8eb9SGleb Smirnoffan ICMP UNREACHABLE is returned for blocked UDP packets, 5353b3a8eb9SGleb Smirnoffand all other packets are silently dropped. 5363b3a8eb9SGleb Smirnoff.El 5373b3a8eb9SGleb Smirnoff.Pp 5383b3a8eb9SGleb SmirnoffFor example: 5393b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 5403b3a8eb9SGleb Smirnoffset block-policy return 5413b3a8eb9SGleb Smirnoff.Ed 542150182e3SKristof Provost.It Ar set fail-policy 543150182e3SKristof ProvostThe 544150182e3SKristof Provost.Ar fail-policy 54530a85ff3SGordon Berglingoption sets the behaviour of rules which should pass a packet but were 54630a85ff3SGordon Berglingunable to do so. 54730a85ff3SGordon BerglingThis might happen when a nat or route-to rule uses an empty table as list 548150182e3SKristof Provostof targets or if a rule fails to create state or source node. 549150182e3SKristof ProvostThe following 550150182e3SKristof Provost.Ar block 551150182e3SKristof Provostactions are possible: 552150182e3SKristof Provost.Pp 553150182e3SKristof Provost.Bl -tag -width xxxxxxxx -compact 554150182e3SKristof Provost.It Ar drop 555150182e3SKristof ProvostIncoming packet is silently dropped. 556150182e3SKristof Provost.It Ar return 557150182e3SKristof ProvostIncoming packet is dropped and TCP RST is returned for TCP packets, 55847d0c1feSKristof Provostan SCTP ABORT chunk is returned for blocked SCTP packets, 559150182e3SKristof Provostan ICMP UNREACHABLE is returned for UDP packets, 560150182e3SKristof Provostand no response is sent for other packets. 561150182e3SKristof Provost.El 562150182e3SKristof Provost.Pp 563150182e3SKristof ProvostFor example: 564150182e3SKristof Provost.Bd -literal -offset indent 565150182e3SKristof Provostset fail-policy return 566150182e3SKristof Provost.Ed 5673b3a8eb9SGleb Smirnoff.It Ar set state-policy 5683b3a8eb9SGleb SmirnoffThe 5693b3a8eb9SGleb Smirnoff.Ar state-policy 5703b3a8eb9SGleb Smirnoffoption sets the default behaviour for states: 5713b3a8eb9SGleb Smirnoff.Pp 5723b3a8eb9SGleb Smirnoff.Bl -tag -width group-bound -compact 5733b3a8eb9SGleb Smirnoff.It Ar if-bound 5743b3a8eb9SGleb SmirnoffStates are bound to interface. 5753b3a8eb9SGleb Smirnoff.It Ar floating 5763b3a8eb9SGleb SmirnoffStates can match packets on any interfaces (the default). 5773b3a8eb9SGleb Smirnoff.El 5783b3a8eb9SGleb Smirnoff.Pp 5793b3a8eb9SGleb SmirnoffFor example: 5803b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 5813b3a8eb9SGleb Smirnoffset state-policy if-bound 5823b3a8eb9SGleb Smirnoff.Ed 58320f015f0SKristof Provost.It Ar set syncookies never | always | adaptive 58420f015f0SKristof ProvostWhen 58520f015f0SKristof Provost.Cm syncookies 58620f015f0SKristof Provostare active, pf will answer each incoming TCP SYN with a syncookie SYNACK, 58720f015f0SKristof Provostwithout allocating any resources. 58820f015f0SKristof ProvostUpon reception of the client's ACK in response to the syncookie 58920f015f0SKristof ProvostSYNACK, pf will evaluate the ruleset and create state if the ruleset 59020f015f0SKristof Provostpermits it, complete the three way handshake with the target host and 59120f015f0SKristof Provostcontinue the connection with synproxy in place. 59220f015f0SKristof ProvostThis allows pf to be resilient against large synflood attacks which would 59320f015f0SKristof Provostrun the state table against its limits otherwise. 59420f015f0SKristof ProvostDue to the blind answers to every incoming SYN syncookies share the caveats of 59520f015f0SKristof Provostsynproxy, namely seemingly accepting connections that will be dropped later on. 59620f015f0SKristof Provost.Pp 59720f015f0SKristof Provost.Bl -tag -width adaptive -compact 59820f015f0SKristof Provost.It Cm never 59920f015f0SKristof Provostpf will never send syncookie SYNACKs (the default). 60020f015f0SKristof Provost.It Cm always 60120f015f0SKristof Provostpf will always send syncookie SYNACKs. 60220f015f0SKristof Provost.It Cm adaptive 60320f015f0SKristof Provostpf will enable syncookie mode when a given percentage of the state table 60420f015f0SKristof Provostis used up by half-open TCP connections, as in, those that saw the initial 60520f015f0SKristof ProvostSYN but didn't finish the three way handshake. 60620f015f0SKristof ProvostThe thresholds for entering and leaving syncookie mode can be specified using 60720f015f0SKristof Provost.Bd -literal -offset indent 60820f015f0SKristof Provostset syncookies adaptive (start 25%, end 12%) 60920f015f0SKristof Provost.Ed 61020f015f0SKristof Provost.El 6113b3a8eb9SGleb Smirnoff.It Ar set state-defaults 6123b3a8eb9SGleb SmirnoffThe 6133b3a8eb9SGleb Smirnoff.Ar state-defaults 6143b3a8eb9SGleb Smirnoffoption sets the state options for states created from rules 6153b3a8eb9SGleb Smirnoffwithout an explicit 6163b3a8eb9SGleb Smirnoff.Ar keep state . 6173b3a8eb9SGleb SmirnoffFor example: 6183b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 619e65e2095SKristof Provostset state-defaults no-sync 6203b3a8eb9SGleb Smirnoff.Ed 6213b3a8eb9SGleb Smirnoff.It Ar set hostid 6223b3a8eb9SGleb SmirnoffThe 32-bit 6233b3a8eb9SGleb Smirnoff.Ar hostid 6243b3a8eb9SGleb Smirnoffidentifies this firewall's state table entries to other firewalls 6253b3a8eb9SGleb Smirnoffin a 6263b3a8eb9SGleb Smirnoff.Xr pfsync 4 6273b3a8eb9SGleb Smirnofffailover cluster. 6283b3a8eb9SGleb SmirnoffBy default the hostid is set to a pseudo-random value, however it may be 6293b3a8eb9SGleb Smirnoffdesirable to manually configure it, for example to more easily identify the 6303b3a8eb9SGleb Smirnoffsource of state table entries. 6313b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 6323b3a8eb9SGleb Smirnoffset hostid 1 6333b3a8eb9SGleb Smirnoff.Ed 6343b3a8eb9SGleb Smirnoff.Pp 6353b3a8eb9SGleb SmirnoffThe hostid may be specified in either decimal or hexadecimal. 6363b3a8eb9SGleb Smirnoff.It Ar set require-order 6373b3a8eb9SGleb SmirnoffBy default 6383b3a8eb9SGleb Smirnoff.Xr pfctl 8 6393b3a8eb9SGleb Smirnoffenforces an ordering of the statement types in the ruleset to: 6403b3a8eb9SGleb Smirnoff.Em options , 6413b3a8eb9SGleb Smirnoff.Em normalization , 6423b3a8eb9SGleb Smirnoff.Em queueing , 6433b3a8eb9SGleb Smirnoff.Em translation , 6443b3a8eb9SGleb Smirnoff.Em filtering . 6453b3a8eb9SGleb SmirnoffSetting this option to 6463b3a8eb9SGleb Smirnoff.Ar no 6473b3a8eb9SGleb Smirnoffdisables this enforcement. 6483b3a8eb9SGleb SmirnoffThere may be non-trivial and non-obvious implications to an out of 6493b3a8eb9SGleb Smirnofforder ruleset. 6503b3a8eb9SGleb SmirnoffConsider carefully before disabling the order enforcement. 6513b3a8eb9SGleb Smirnoff.It Ar set fingerprints 6523b3a8eb9SGleb SmirnoffLoad fingerprints of known operating systems from the given filename. 6533b3a8eb9SGleb SmirnoffBy default fingerprints of known operating systems are automatically 6543b3a8eb9SGleb Smirnoffloaded from 6553b3a8eb9SGleb Smirnoff.Xr pf.os 5 6563b3a8eb9SGleb Smirnoffin 6573b3a8eb9SGleb Smirnoff.Pa /etc 6583b3a8eb9SGleb Smirnoffbut can be overridden via this option. 6593b3a8eb9SGleb SmirnoffSetting this option may leave a small period of time where the fingerprints 6603b3a8eb9SGleb Smirnoffreferenced by the currently active ruleset are inconsistent until the new 6613b3a8eb9SGleb Smirnoffruleset finishes loading. 6623b3a8eb9SGleb Smirnoff.Pp 6633b3a8eb9SGleb SmirnoffFor example: 6643b3a8eb9SGleb Smirnoff.Pp 6653b3a8eb9SGleb Smirnoff.Dl set fingerprints \&"/etc/pf.os.devel\&" 6663b3a8eb9SGleb Smirnoff.It Ar set skip on Aq Ar ifspec 6673b3a8eb9SGleb SmirnoffList interfaces for which packets should not be filtered. 6683b3a8eb9SGleb SmirnoffPackets passing in or out on such interfaces are passed as if pf was 6693b3a8eb9SGleb Smirnoffdisabled, i.e. pf does not process them in any way. 6703b3a8eb9SGleb SmirnoffThis can be useful on loopback and other virtual interfaces, when 6713b3a8eb9SGleb Smirnoffpacket filtering is not desired and can have unexpected effects. 6723b3a8eb9SGleb SmirnoffFor example: 6733b3a8eb9SGleb Smirnoff.Pp 6743b3a8eb9SGleb Smirnoff.Dl set skip on lo0 6753b3a8eb9SGleb Smirnoff.It Ar set debug 6763b3a8eb9SGleb SmirnoffSet the debug 6773b3a8eb9SGleb Smirnoff.Ar level 6783b3a8eb9SGleb Smirnoffto one of the following: 6793b3a8eb9SGleb Smirnoff.Pp 6803b3a8eb9SGleb Smirnoff.Bl -tag -width xxxxxxxxxxxx -compact 6813b3a8eb9SGleb Smirnoff.It Ar none 6823b3a8eb9SGleb SmirnoffDon't generate debug messages. 6833b3a8eb9SGleb Smirnoff.It Ar urgent 6843b3a8eb9SGleb SmirnoffGenerate debug messages only for serious errors. 6853b3a8eb9SGleb Smirnoff.It Ar misc 6863b3a8eb9SGleb SmirnoffGenerate debug messages for various errors. 6873b3a8eb9SGleb Smirnoff.It Ar loud 6883b3a8eb9SGleb SmirnoffGenerate debug messages for common conditions. 6893b3a8eb9SGleb Smirnoff.El 69042ec75f8SKristof Provost.It Ar set keepcounters 69142ec75f8SKristof ProvostPreserve rule counters across rule updates. 69242ec75f8SKristof ProvostUsually rule counters are reset to zero on every update of the ruleset. 69342ec75f8SKristof ProvostWith 69442ec75f8SKristof Provost.Ar keepcounters 69542ec75f8SKristof Provostset pf will attempt to find matching rules between old and new rulesets 69642ec75f8SKristof Provostand preserve the rule counters. 6973b3a8eb9SGleb Smirnoff.El 698ab2886f0SKristof Provost.Sh ETHERNET FILTERING 699ab2886f0SKristof Provost.Xr pf 4 700ab2886f0SKristof Provosthas the ability to 701ab2886f0SKristof Provost.Ar block 702ab2886f0SKristof Provostand 703ab2886f0SKristof Provost.Ar pass 704ab2886f0SKristof Provostpackets based on attributes of their Ethernet (layer 2) header. 705ab2886f0SKristof Provost.Pp 706ab2886f0SKristof ProvostFor each packet processed by the packet filter, the filter rules are 707ab2886f0SKristof Provostevaluated in sequential order, from first to last. 708ab2886f0SKristof ProvostThe last matching rule decides what action is taken. 709ab2886f0SKristof ProvostIf no rule matches the packet, the default action is to pass 710cdf415ecSKristof Provostthe packet without creating a state. 711ab2886f0SKristof Provost.Pp 712bdb82431SMaxim KonovalovThe following actions can be used in the filter: 713ab2886f0SKristof Provost.Bl -tag -width xxxx 714ab2886f0SKristof Provost.It Ar block 715ab2886f0SKristof ProvostThe packet is blocked. 716ab2886f0SKristof ProvostUnlike for layer 3 traffic the packet is always silently dropped. 717ab2886f0SKristof Provost.It Ar pass 718ab2886f0SKristof ProvostThe packet is passed; 719ab2886f0SKristof Provostno state is created for layer 2 traffic. 720ab2886f0SKristof Provost.El 721ab2886f0SKristof Provost.Sh PARAMETERS 722ab2886f0SKristof ProvostThe rule parameters specify the packets to which a rule applies. 723ab2886f0SKristof ProvostA packet always comes in on, or goes out through, one interface. 724ab2886f0SKristof ProvostMost parameters are optional. 725ab2886f0SKristof ProvostIf a parameter is specified, the rule only applies to packets with 726ab2886f0SKristof Provostmatching attributes. 727ab2886f0SKristof ProvostCertain parameters can be expressed as lists, in which case 728ab2886f0SKristof Provost.Xr pfctl 8 729ab2886f0SKristof Provostgenerates all needed rule combinations. 730ab2886f0SKristof Provost.Bl -tag -width xxxx 731ab2886f0SKristof Provost.It Ar in No or Ar out 732ab2886f0SKristof ProvostThis rule applies to incoming or outgoing packets. 733ab2886f0SKristof ProvostIf neither 734ab2886f0SKristof Provost.Ar in 735ab2886f0SKristof Provostnor 736ab2886f0SKristof Provost.Ar out 737ab2886f0SKristof Provostare specified, the rule will match packets in both directions. 738ab2886f0SKristof Provost.It Ar quick 739ab2886f0SKristof ProvostIf a packet matches a rule which has the 740ab2886f0SKristof Provost.Ar quick 741ab2886f0SKristof Provostoption set, this rule 742ab2886f0SKristof Provostis considered the last matching rule, and evaluation of subsequent rules 743ab2886f0SKristof Provostis skipped. 7444bfffd8cSKristof Provost.It Ar on Aq Ar ifspec 745ab2886f0SKristof ProvostThis rule applies only to packets coming in on, or going out through, this 746ab2886f0SKristof Provostparticular interface or interface group. 747ab2886f0SKristof ProvostFor more information on interface groups, 748ab2886f0SKristof Provostsee the 749ab2886f0SKristof Provost.Ic group 750ab2886f0SKristof Provostkeyword in 751ab2886f0SKristof Provost.Xr ifconfig 8 . 752*618a8766SKristof Provost.Ar any 753*618a8766SKristof Provostwill match any existing interface except loopback ones. 7548a8af942SKristof Provost.It Ar bridge-to Aq interface 7558a8af942SKristof ProvostPackets matching this rule will be sent out of the specified interface without 756bdb82431SMaxim Konovalovfurther processing. 757ab2886f0SKristof Provost.It Ar proto Aq Ar protocol 758ab2886f0SKristof ProvostThis rule applies only to packets of this protocol. 759ab2886f0SKristof ProvostNote that Ethernet protocol numbers are different from those used in 760ab2886f0SKristof Provost.Xr ip 4 761ab2886f0SKristof Provostand 762ab2886f0SKristof Provost.Xr ip6 4 . 763ab2886f0SKristof Provost.It Xo 764ab2886f0SKristof Provost.Ar from Aq Ar source 765ab2886f0SKristof Provost.Ar to Aq Ar dest 766ab2886f0SKristof Provost.Xc 767ab2886f0SKristof ProvostThis rule applies only to packets with the specified source and destination 768ab2886f0SKristof ProvostMAC addresses. 769ab2886f0SKristof Provost.It Xo Ar queue Aq Ar queue 770ab2886f0SKristof Provost.Xc 771ab2886f0SKristof ProvostPackets matching this rule will be assigned to the specified queue. 772ab2886f0SKristof ProvostSee 773ab2886f0SKristof Provost.Sx QUEUEING 774ab2886f0SKristof Provostfor setup details. 775ab2886f0SKristof Provost.Pp 776ab2886f0SKristof Provost.It Ar tag Aq Ar string 777ab2886f0SKristof ProvostPackets matching this rule will be tagged with the 778ab2886f0SKristof Provostspecified string. 779ab2886f0SKristof ProvostThe tag acts as an internal marker that can be used to 780ab2886f0SKristof Provostidentify these packets later on. 781ab2886f0SKristof ProvostThis can be used, for example, to provide trust between 782ab2886f0SKristof Provostinterfaces and to determine if packets have been 783ab2886f0SKristof Provostprocessed by translation rules. 784ab2886f0SKristof ProvostTags are 785ab2886f0SKristof Provost.Qq sticky , 786ab2886f0SKristof Provostmeaning that the packet will be tagged even if the rule 787ab2886f0SKristof Provostis not the last matching rule. 788ab2886f0SKristof ProvostFurther matching rules can replace the tag with a 789ab2886f0SKristof Provostnew one but will not remove a previously applied tag. 790ab2886f0SKristof ProvostA packet is only ever assigned one tag at a time. 7911f61367fSKristof Provost.It Ar tagged Aq Ar string 7921f61367fSKristof ProvostUsed to specify that packets must already be tagged with the given tag in order 7931f61367fSKristof Provostto match the rule. 7941f61367fSKristof ProvostInverse tag matching can also be done by specifying the ! operator before the 7951f61367fSKristof Provosttagged keyword. 7965ed470bdSKajetan Staszkiewicz.El 7973b3a8eb9SGleb Smirnoff.Sh TRAFFIC NORMALIZATION 7985ed470bdSKajetan StaszkiewiczTraffic normalization is a broad umbrella term 7995ed470bdSKajetan Staszkiewiczfor aspects of the packet filter which deal with 8005ed470bdSKajetan Staszkiewiczverifying packets, packet fragments, spoofed traffic, 8015ed470bdSKajetan Staszkiewiczand other irregularities. 8025ed470bdSKajetan Staszkiewicz.Ss Scrub 8035ed470bdSKajetan StaszkiewiczScrub involves sanitising packet content in such a way 8045ed470bdSKajetan Staszkiewiczthat there are no ambiguities in packet interpretation on the receiving side. 8055ed470bdSKajetan StaszkiewiczIt is invoked with the 8065ed470bdSKajetan Staszkiewicz.Cm scrub 8075ed470bdSKajetan Staszkiewiczoption, added to filter rules. 8083b3a8eb9SGleb Smirnoff.Pp 8095ed470bdSKajetan StaszkiewiczParameters are specified enclosed in parentheses. 8105ed470bdSKajetan StaszkiewiczAt least one of the following parameters must be specified: 8113b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx 8123b3a8eb9SGleb Smirnoff.It Ar no-df 8133b3a8eb9SGleb SmirnoffClears the 8143b3a8eb9SGleb Smirnoff.Ar dont-fragment 8153b3a8eb9SGleb Smirnoffbit from a matching IP packet. 8163b3a8eb9SGleb SmirnoffSome operating systems are known to generate fragmented packets with the 8173b3a8eb9SGleb Smirnoff.Ar dont-fragment 8183b3a8eb9SGleb Smirnoffbit set. 8193b3a8eb9SGleb SmirnoffThis is particularly true with NFS. 8203b3a8eb9SGleb Smirnoff.Ar Scrub 8213b3a8eb9SGleb Smirnoffwill drop such fragmented 8223b3a8eb9SGleb Smirnoff.Ar dont-fragment 8233b3a8eb9SGleb Smirnoffpackets unless 8243b3a8eb9SGleb Smirnoff.Ar no-df 8253b3a8eb9SGleb Smirnoffis specified. 8263b3a8eb9SGleb Smirnoff.Pp 8273b3a8eb9SGleb SmirnoffUnfortunately some operating systems also generate their 8283b3a8eb9SGleb Smirnoff.Ar dont-fragment 8293b3a8eb9SGleb Smirnoffpackets with a zero IP identification field. 8303b3a8eb9SGleb SmirnoffClearing the 8313b3a8eb9SGleb Smirnoff.Ar dont-fragment 8323b3a8eb9SGleb Smirnoffbit on packets with a zero IP ID may cause deleterious results if an 8333b3a8eb9SGleb Smirnoffupstream router later fragments the packet. 8343b3a8eb9SGleb SmirnoffUsing the 8353b3a8eb9SGleb Smirnoff.Ar random-id 8363b3a8eb9SGleb Smirnoffmodifier (see below) is recommended in combination with the 8373b3a8eb9SGleb Smirnoff.Ar no-df 8383b3a8eb9SGleb Smirnoffmodifier to ensure unique IP identifiers. 8393b3a8eb9SGleb Smirnoff.It Ar min-ttl Aq Ar number 8403b3a8eb9SGleb SmirnoffEnforces a minimum TTL for matching IP packets. 8413b3a8eb9SGleb Smirnoff.It Ar max-mss Aq Ar number 8423b3a8eb9SGleb SmirnoffEnforces a maximum MSS for matching TCP packets. 8433b3a8eb9SGleb Smirnoff.It Xo Ar set-tos Aq Ar string 8443b3a8eb9SGleb Smirnoff.No \*(Ba Aq Ar number 8453b3a8eb9SGleb Smirnoff.Xc 8463b3a8eb9SGleb SmirnoffEnforces a 8473b3a8eb9SGleb Smirnoff.Em TOS 8483b3a8eb9SGleb Smirnofffor matching IP packets. 8493b3a8eb9SGleb Smirnoff.Em TOS 8503b3a8eb9SGleb Smirnoffmay be 8513b3a8eb9SGleb Smirnoffgiven as one of 8521f495578SKristof Provost.Ar critical , 8531f495578SKristof Provost.Ar inetcontrol , 8543b3a8eb9SGleb Smirnoff.Ar lowdelay , 8551f495578SKristof Provost.Ar netcontrol , 8563b3a8eb9SGleb Smirnoff.Ar throughput , 8573b3a8eb9SGleb Smirnoff.Ar reliability , 8581f495578SKristof Provostor one of the DiffServ Code Points: 8591f495578SKristof Provost.Ar ef , 860b4e3f3c2SKristof Provost.Ar va , 8611f495578SKristof Provost.Ar af11 No ... Ar af43 , 8621f495578SKristof Provost.Ar cs0 No ... Ar cs7 ; 8633b3a8eb9SGleb Smirnoffor as either hex or decimal. 8643b3a8eb9SGleb Smirnoff.It Ar random-id 8653b3a8eb9SGleb SmirnoffReplaces the IP identification field with random values to compensate 8663b3a8eb9SGleb Smirnofffor predictable values generated by many hosts. 8673b3a8eb9SGleb SmirnoffThis option only applies to packets that are not fragmented 8683b3a8eb9SGleb Smirnoffafter the optional fragment reassembly. 8693b3a8eb9SGleb Smirnoff.It Ar reassemble tcp 8703b3a8eb9SGleb SmirnoffStatefully normalizes TCP connections. 8713b3a8eb9SGleb Smirnoff.Ar reassemble tcp 8723b3a8eb9SGleb Smirnoffperforms the following normalizations: 8733b3a8eb9SGleb Smirnoff.Pp 8743b3a8eb9SGleb Smirnoff.Bl -tag -width timeout -compact 8753b3a8eb9SGleb Smirnoff.It ttl 8763b3a8eb9SGleb SmirnoffNeither side of the connection is allowed to reduce their IP TTL. 8773b3a8eb9SGleb SmirnoffAn attacker may send a packet such that it reaches the firewall, affects 8783b3a8eb9SGleb Smirnoffthe firewall state, and expires before reaching the destination host. 8793b3a8eb9SGleb Smirnoff.Ar reassemble tcp 8803b3a8eb9SGleb Smirnoffwill raise the TTL of all packets back up to the highest value seen on 8813b3a8eb9SGleb Smirnoffthe connection. 8823b3a8eb9SGleb Smirnoff.It timestamp modulation 8833b3a8eb9SGleb SmirnoffModern TCP stacks will send a timestamp on every TCP packet and echo 8843b3a8eb9SGleb Smirnoffthe other endpoint's timestamp back to them. 8853b3a8eb9SGleb SmirnoffMany operating systems will merely start the timestamp at zero when 8863b3a8eb9SGleb Smirnofffirst booted, and increment it several times a second. 8873b3a8eb9SGleb SmirnoffThe uptime of the host can be deduced by reading the timestamp and multiplying 8883b3a8eb9SGleb Smirnoffby a constant. 8893b3a8eb9SGleb SmirnoffAlso observing several different timestamps can be used to count hosts 8903b3a8eb9SGleb Smirnoffbehind a NAT device. 8913b3a8eb9SGleb SmirnoffAnd spoofing TCP packets into a connection requires knowing or guessing 8923b3a8eb9SGleb Smirnoffvalid timestamps. 8933b3a8eb9SGleb SmirnoffTimestamps merely need to be monotonically increasing and not derived off a 8943b3a8eb9SGleb Smirnoffguessable base time. 8953b3a8eb9SGleb Smirnoff.Ar reassemble tcp 8963b3a8eb9SGleb Smirnoffwill cause 8973b3a8eb9SGleb Smirnoff.Ar scrub 8983b3a8eb9SGleb Smirnoffto modulate the TCP timestamps with a random number. 8993b3a8eb9SGleb Smirnoff.It extended PAWS checks 9003b3a8eb9SGleb SmirnoffThere is a problem with TCP on long fat pipes, in that a packet might get 9013b3a8eb9SGleb Smirnoffdelayed for longer than it takes the connection to wrap its 32-bit sequence 9023b3a8eb9SGleb Smirnoffspace. 9033b3a8eb9SGleb SmirnoffIn such an occurrence, the old packet would be indistinguishable from a 9043b3a8eb9SGleb Smirnoffnew packet and would be accepted as such. 9053b3a8eb9SGleb SmirnoffThe solution to this is called PAWS: Protection Against Wrapped Sequence 9063b3a8eb9SGleb Smirnoffnumbers. 9073b3a8eb9SGleb SmirnoffIt protects against it by making sure the timestamp on each packet does 9083b3a8eb9SGleb Smirnoffnot go backwards. 9093b3a8eb9SGleb Smirnoff.Ar reassemble tcp 9103b3a8eb9SGleb Smirnoffalso makes sure the timestamp on the packet does not go forward more 9113b3a8eb9SGleb Smirnoffthan the RFC allows. 9123b3a8eb9SGleb SmirnoffBy doing this, 9133b3a8eb9SGleb Smirnoff.Xr pf 4 9143b3a8eb9SGleb Smirnoffartificially extends the security of TCP sequence numbers by 10 to 18 9153b3a8eb9SGleb Smirnoffbits when the host uses appropriately randomized timestamps, since a 9163b3a8eb9SGleb Smirnoffblind attacker would have to guess the timestamp as well. 9173b3a8eb9SGleb Smirnoff.El 9183b3a8eb9SGleb Smirnoff.El 9193b3a8eb9SGleb Smirnoff.Pp 9203b3a8eb9SGleb SmirnoffFor example, 9213b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 9225ed470bdSKajetan Staszkiewiczmatch in all scrub (no-df random-id max-mss 1440) 9235ed470bdSKajetan Staszkiewicz.Ed 9245ed470bdSKajetan Staszkiewicz.Ss Scrub ruleset (pre-FreeBSD 14) 9255ed470bdSKajetan StaszkiewiczIn order to maintain compatibility with older releases of FreeBSD 9265ed470bdSKajetan Staszkiewicz.Ar scrub 9275ed470bdSKajetan Staszkiewiczrules can also be specified in their own ruleset. 9285ed470bdSKajetan StaszkiewiczIn such case they are invoked with the 9295ed470bdSKajetan Staszkiewicz.Ar scrub 9305ed470bdSKajetan Staszkiewiczdirective. 9315ed470bdSKajetan StaszkiewiczIf there are such rules present they determine packet reassembly behaviour. 9325ed470bdSKajetan StaszkiewiczWhen no such rules are present the option 9335ed470bdSKajetan Staszkiewicz.Ar set reassembly 9345ed470bdSKajetan Staszkiewicztakes precedence. 9355ed470bdSKajetan StaszkiewiczThe 9365ed470bdSKajetan Staszkiewicz.Ar scrub 9375ed470bdSKajetan Staszkiewiczrules can take all parameters specified above for a 9385ed470bdSKajetan Staszkiewicz.Ar scrub 9395ed470bdSKajetan Staszkiewiczoption of filter rules and 2 more parameters controlling fragment reassembly: 9405ed470bdSKajetan Staszkiewicz.Bl -tag -width xxxx 9415ed470bdSKajetan Staszkiewicz.It Ar fragment reassemble 9425ed470bdSKajetan StaszkiewiczUsing 9435ed470bdSKajetan Staszkiewicz.Ar scrub 9445ed470bdSKajetan Staszkiewiczrules, fragments can be reassembled by normalization. 9455ed470bdSKajetan StaszkiewiczIn this case, fragments are buffered until they form a complete 9465ed470bdSKajetan Staszkiewiczpacket, and only the completed packet is passed on to the filter. 9475ed470bdSKajetan StaszkiewiczThe advantage is that filter rules have to deal only with complete 9485ed470bdSKajetan Staszkiewiczpackets, and can ignore fragments. 9495ed470bdSKajetan StaszkiewiczThe drawback of caching fragments is the additional memory cost. 9505ed470bdSKajetan StaszkiewiczThis is the default behaviour unless no fragment reassemble is specified. 9515ed470bdSKajetan Staszkiewicz.It Ar no fragment reassemble 9525ed470bdSKajetan StaszkiewiczDo not reassemble fragments. 9535ed470bdSKajetan Staszkiewicz.El 9545ed470bdSKajetan Staszkiewicz.Pp 9555ed470bdSKajetan StaszkiewiczFor example, 9565ed470bdSKajetan Staszkiewicz.Bd -literal -offset indent 9573b3a8eb9SGleb Smirnoffscrub in on $ext_if all fragment reassemble 9583b3a8eb9SGleb Smirnoff.Ed 9593b3a8eb9SGleb Smirnoff.Pp 9603b3a8eb9SGleb SmirnoffThe 9613b3a8eb9SGleb Smirnoff.Ar no 9623b3a8eb9SGleb Smirnoffoption prefixed to a scrub rule causes matching packets to remain unscrubbed, 9633b3a8eb9SGleb Smirnoffmuch in the same way as 9643b3a8eb9SGleb Smirnoff.Ar drop quick 9653b3a8eb9SGleb Smirnoffworks in the packet filter (see below). 9663b3a8eb9SGleb SmirnoffThis mechanism should be used when it is necessary to exclude specific packets 9673b3a8eb9SGleb Smirnofffrom broader scrub rules. 9685ed470bdSKajetan Staszkiewicz.Pp 9695ed470bdSKajetan Staszkiewicz.Ar scrub 9705ed470bdSKajetan Staszkiewiczrules in the 9715ed470bdSKajetan Staszkiewicz.Ar scrub 9725ed470bdSKajetan Staszkiewiczruleset are evaluated for every packet before stateful filtering. 9735ed470bdSKajetan StaszkiewiczThis means excessive usage of them will cause performance penalty. 9745ed470bdSKajetan Staszkiewicz.Ar scrub reassemble tcp 9755ed470bdSKajetan Staszkiewiczrules must not have the direction (in/out) specified. 97600a7a05bSKristof Provost.Sh QUEUEING with ALTQ 9773b3a8eb9SGleb SmirnoffThe ALTQ system is currently not available in the GENERIC kernel nor as 9783b3a8eb9SGleb Smirnoffloadable modules. 9793b3a8eb9SGleb SmirnoffIn order to use the herein after called queueing options one has to use a 9803b3a8eb9SGleb Smirnoffcustom built kernel. 9813b3a8eb9SGleb SmirnoffPlease refer to 9823b3a8eb9SGleb Smirnoff.Xr altq 4 9833b3a8eb9SGleb Smirnoffto learn about the related kernel options. 9843b3a8eb9SGleb Smirnoff.Pp 9853b3a8eb9SGleb SmirnoffPackets can be assigned to queues for the purpose of bandwidth 9863b3a8eb9SGleb Smirnoffcontrol. 9873b3a8eb9SGleb SmirnoffAt least two declarations are required to configure queues, and later 9883b3a8eb9SGleb Smirnoffany packet filtering rule can reference the defined queues by name. 9893b3a8eb9SGleb SmirnoffDuring the filtering component of 9903b3a8eb9SGleb Smirnoff.Nm pf.conf , 9913b3a8eb9SGleb Smirnoffthe last referenced 9923b3a8eb9SGleb Smirnoff.Ar queue 9933b3a8eb9SGleb Smirnoffname is where any packets from 9943b3a8eb9SGleb Smirnoff.Ar pass 9953b3a8eb9SGleb Smirnoffrules will be queued, while for 9963b3a8eb9SGleb Smirnoff.Ar block 9973b3a8eb9SGleb Smirnoffrules it specifies where any resulting ICMP or TCP RST 9983b3a8eb9SGleb Smirnoffpackets should be queued. 9993b3a8eb9SGleb SmirnoffThe 10003b3a8eb9SGleb Smirnoff.Ar scheduler 10013b3a8eb9SGleb Smirnoffdefines the algorithm used to decide which packets get delayed, dropped, or 10023b3a8eb9SGleb Smirnoffsent out immediately. 10033b3a8eb9SGleb SmirnoffThere are three 10043b3a8eb9SGleb Smirnoff.Ar schedulers 10053b3a8eb9SGleb Smirnoffcurrently supported. 10063b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx 10073b3a8eb9SGleb Smirnoff.It Ar cbq 10083b3a8eb9SGleb SmirnoffClass Based Queueing. 10093b3a8eb9SGleb Smirnoff.Ar Queues 10103b3a8eb9SGleb Smirnoffattached to an interface build a tree, thus each 10113b3a8eb9SGleb Smirnoff.Ar queue 10123b3a8eb9SGleb Smirnoffcan have further child 10133b3a8eb9SGleb Smirnoff.Ar queues . 10143b3a8eb9SGleb SmirnoffEach queue can have a 10153b3a8eb9SGleb Smirnoff.Ar priority 10163b3a8eb9SGleb Smirnoffand a 10173b3a8eb9SGleb Smirnoff.Ar bandwidth 10183b3a8eb9SGleb Smirnoffassigned. 10193b3a8eb9SGleb Smirnoff.Ar Priority 10203b3a8eb9SGleb Smirnoffmainly controls the time packets take to get sent out, while 10213b3a8eb9SGleb Smirnoff.Ar bandwidth 10223b3a8eb9SGleb Smirnoffhas primarily effects on throughput. 10233b3a8eb9SGleb Smirnoff.Ar cbq 10243b3a8eb9SGleb Smirnoffachieves both partitioning and sharing of link bandwidth 10253b3a8eb9SGleb Smirnoffby hierarchically structured classes. 10263b3a8eb9SGleb SmirnoffEach class has its own 10273b3a8eb9SGleb Smirnoff.Ar queue 10283b3a8eb9SGleb Smirnoffand is assigned its share of 10293b3a8eb9SGleb Smirnoff.Ar bandwidth . 10303b3a8eb9SGleb SmirnoffA child class can borrow bandwidth from its parent class 10313b3a8eb9SGleb Smirnoffas long as excess bandwidth is available 10323b3a8eb9SGleb Smirnoff(see the option 10333b3a8eb9SGleb Smirnoff.Ar borrow , 10343b3a8eb9SGleb Smirnoffbelow). 10353b3a8eb9SGleb Smirnoff.It Ar priq 10363b3a8eb9SGleb SmirnoffPriority Queueing. 10373b3a8eb9SGleb Smirnoff.Ar Queues 10383b3a8eb9SGleb Smirnoffare flat attached to the interface, thus, 10393b3a8eb9SGleb Smirnoff.Ar queues 10403b3a8eb9SGleb Smirnoffcannot have further child 10413b3a8eb9SGleb Smirnoff.Ar queues . 10423b3a8eb9SGleb SmirnoffEach 10433b3a8eb9SGleb Smirnoff.Ar queue 10443b3a8eb9SGleb Smirnoffhas a unique 10453b3a8eb9SGleb Smirnoff.Ar priority 10463b3a8eb9SGleb Smirnoffassigned, ranging from 0 to 15. 10473b3a8eb9SGleb SmirnoffPackets in the 10483b3a8eb9SGleb Smirnoff.Ar queue 10493b3a8eb9SGleb Smirnoffwith the highest 10503b3a8eb9SGleb Smirnoff.Ar priority 10513b3a8eb9SGleb Smirnoffare processed first. 10523b3a8eb9SGleb Smirnoff.It Ar hfsc 10533b3a8eb9SGleb SmirnoffHierarchical Fair Service Curve. 10543b3a8eb9SGleb Smirnoff.Ar Queues 10553b3a8eb9SGleb Smirnoffattached to an interface build a tree, thus each 10563b3a8eb9SGleb Smirnoff.Ar queue 10573b3a8eb9SGleb Smirnoffcan have further child 10583b3a8eb9SGleb Smirnoff.Ar queues . 10593b3a8eb9SGleb SmirnoffEach queue can have a 10603b3a8eb9SGleb Smirnoff.Ar priority 10613b3a8eb9SGleb Smirnoffand a 10623b3a8eb9SGleb Smirnoff.Ar bandwidth 10633b3a8eb9SGleb Smirnoffassigned. 10643b3a8eb9SGleb Smirnoff.Ar Priority 10653b3a8eb9SGleb Smirnoffmainly controls the time packets take to get sent out, while 10663b3a8eb9SGleb Smirnoff.Ar bandwidth 10673b3a8eb9SGleb Smirnoffprimarily affects throughput. 10683b3a8eb9SGleb Smirnoff.Ar hfsc 10693b3a8eb9SGleb Smirnoffsupports both link-sharing and guaranteed real-time services. 10703b3a8eb9SGleb SmirnoffIt employs a service curve based QoS model, 10713b3a8eb9SGleb Smirnoffand its unique feature is an ability to decouple 10723b3a8eb9SGleb Smirnoff.Ar delay 10733b3a8eb9SGleb Smirnoffand 10743b3a8eb9SGleb Smirnoff.Ar bandwidth 10753b3a8eb9SGleb Smirnoffallocation. 10763b3a8eb9SGleb Smirnoff.El 10773b3a8eb9SGleb Smirnoff.Pp 10783b3a8eb9SGleb SmirnoffThe interfaces on which queueing should be activated are declared using 10793b3a8eb9SGleb Smirnoffthe 10803b3a8eb9SGleb Smirnoff.Ar altq on 10813b3a8eb9SGleb Smirnoffdeclaration. 10823b3a8eb9SGleb Smirnoff.Ar altq on 10833b3a8eb9SGleb Smirnoffhas the following keywords: 10843b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx 10853b3a8eb9SGleb Smirnoff.It Aq Ar interface 10863b3a8eb9SGleb SmirnoffQueueing is enabled on the named interface. 10873b3a8eb9SGleb Smirnoff.It Aq Ar scheduler 10883b3a8eb9SGleb SmirnoffSpecifies which queueing scheduler to use. 10893b3a8eb9SGleb SmirnoffCurrently supported values 10903b3a8eb9SGleb Smirnoffare 10913b3a8eb9SGleb Smirnoff.Ar cbq 10923b3a8eb9SGleb Smirnofffor Class Based Queueing, 10933b3a8eb9SGleb Smirnoff.Ar priq 10943b3a8eb9SGleb Smirnofffor Priority Queueing and 10953b3a8eb9SGleb Smirnoff.Ar hfsc 10963b3a8eb9SGleb Smirnofffor the Hierarchical Fair Service Curve scheduler. 10973b3a8eb9SGleb Smirnoff.It Ar bandwidth Aq Ar bw 10983b3a8eb9SGleb SmirnoffThe maximum bitrate for all queues on an 10993b3a8eb9SGleb Smirnoffinterface may be specified using the 11003b3a8eb9SGleb Smirnoff.Ar bandwidth 11013b3a8eb9SGleb Smirnoffkeyword. 11023b3a8eb9SGleb SmirnoffThe value can be specified as an absolute value or as a 11033b3a8eb9SGleb Smirnoffpercentage of the interface bandwidth. 11043b3a8eb9SGleb SmirnoffWhen using an absolute value, the suffixes 11053b3a8eb9SGleb Smirnoff.Ar b , 11063b3a8eb9SGleb Smirnoff.Ar Kb , 11073b3a8eb9SGleb Smirnoff.Ar Mb , 11083b3a8eb9SGleb Smirnoffand 11093b3a8eb9SGleb Smirnoff.Ar Gb 11103b3a8eb9SGleb Smirnoffare used to represent bits, kilobits, megabits, and 11113b3a8eb9SGleb Smirnoffgigabits per second, respectively. 11123b3a8eb9SGleb SmirnoffThe value must not exceed the interface bandwidth. 11133b3a8eb9SGleb SmirnoffIf 11143b3a8eb9SGleb Smirnoff.Ar bandwidth 11153b3a8eb9SGleb Smirnoffis not specified, the interface bandwidth is used 11163b3a8eb9SGleb Smirnoff(but take note that some interfaces do not know their bandwidth, 11173b3a8eb9SGleb Smirnoffor can adapt their bandwidth rates). 11183b3a8eb9SGleb Smirnoff.It Ar qlimit Aq Ar limit 11193b3a8eb9SGleb SmirnoffThe maximum number of packets held in the queue. 11203b3a8eb9SGleb SmirnoffThe default is 50. 11213b3a8eb9SGleb Smirnoff.It Ar tbrsize Aq Ar size 11223b3a8eb9SGleb SmirnoffAdjusts the size, in bytes, of the token bucket regulator. 11233b3a8eb9SGleb SmirnoffIf not specified, heuristics based on the 11243b3a8eb9SGleb Smirnoffinterface bandwidth are used to determine the size. 11253b3a8eb9SGleb Smirnoff.It Ar queue Aq Ar list 11263b3a8eb9SGleb SmirnoffDefines a list of subqueues to create on an interface. 11273b3a8eb9SGleb Smirnoff.El 11283b3a8eb9SGleb Smirnoff.Pp 11293b3a8eb9SGleb SmirnoffIn the following example, the interface dc0 11303b3a8eb9SGleb Smirnoffshould queue up to 5Mbps in four second-level queues using 11313b3a8eb9SGleb SmirnoffClass Based Queueing. 11323b3a8eb9SGleb SmirnoffThose four queues will be shown in a later example. 11333b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 11343b3a8eb9SGleb Smirnoffaltq on dc0 cbq bandwidth 5Mb queue { std, http, mail, ssh } 11353b3a8eb9SGleb Smirnoff.Ed 11363b3a8eb9SGleb Smirnoff.Pp 11373b3a8eb9SGleb SmirnoffOnce interfaces are activated for queueing using the 11383b3a8eb9SGleb Smirnoff.Ar altq 11393b3a8eb9SGleb Smirnoffdirective, a sequence of 11403b3a8eb9SGleb Smirnoff.Ar queue 11413b3a8eb9SGleb Smirnoffdirectives may be defined. 11423b3a8eb9SGleb SmirnoffThe name associated with a 11433b3a8eb9SGleb Smirnoff.Ar queue 11443b3a8eb9SGleb Smirnoffmust match a queue defined in the 11453b3a8eb9SGleb Smirnoff.Ar altq 11463b3a8eb9SGleb Smirnoffdirective (e.g. mail), or, except for the 11473b3a8eb9SGleb Smirnoff.Ar priq 11483b3a8eb9SGleb Smirnoff.Ar scheduler , 11493b3a8eb9SGleb Smirnoffin a parent 11503b3a8eb9SGleb Smirnoff.Ar queue 11513b3a8eb9SGleb Smirnoffdeclaration. 11523b3a8eb9SGleb SmirnoffThe following keywords can be used: 11533b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx 11543b3a8eb9SGleb Smirnoff.It Ar on Aq Ar interface 11553b3a8eb9SGleb SmirnoffSpecifies the interface the queue operates on. 11563b3a8eb9SGleb SmirnoffIf not given, it operates on all matching interfaces. 11573b3a8eb9SGleb Smirnoff.It Ar bandwidth Aq Ar bw 11583b3a8eb9SGleb SmirnoffSpecifies the maximum bitrate to be processed by the queue. 11593b3a8eb9SGleb SmirnoffThis value must not exceed the value of the parent 11603b3a8eb9SGleb Smirnoff.Ar queue 11613b3a8eb9SGleb Smirnoffand can be specified as an absolute value or a percentage of the parent 11623b3a8eb9SGleb Smirnoffqueue's bandwidth. 11633b3a8eb9SGleb SmirnoffIf not specified, defaults to 100% of the parent queue's bandwidth. 11643b3a8eb9SGleb SmirnoffThe 11653b3a8eb9SGleb Smirnoff.Ar priq 11663b3a8eb9SGleb Smirnoffscheduler does not support bandwidth specification. 11673b3a8eb9SGleb Smirnoff.It Ar priority Aq Ar level 11683b3a8eb9SGleb SmirnoffBetween queues a priority level can be set. 11693b3a8eb9SGleb SmirnoffFor 11703b3a8eb9SGleb Smirnoff.Ar cbq 11713b3a8eb9SGleb Smirnoffand 11723b3a8eb9SGleb Smirnoff.Ar hfsc , 11733b3a8eb9SGleb Smirnoffthe range is 0 to 7 and for 11743b3a8eb9SGleb Smirnoff.Ar priq , 11753b3a8eb9SGleb Smirnoffthe range is 0 to 15. 11763b3a8eb9SGleb SmirnoffThe default for all is 1. 11773b3a8eb9SGleb Smirnoff.Ar Priq 11783b3a8eb9SGleb Smirnoffqueues with a higher priority are always served first. 11793b3a8eb9SGleb Smirnoff.Ar Cbq 11803b3a8eb9SGleb Smirnoffand 11813b3a8eb9SGleb Smirnoff.Ar Hfsc 11823b3a8eb9SGleb Smirnoffqueues with a higher priority are preferred in the case of overload. 11833b3a8eb9SGleb Smirnoff.It Ar qlimit Aq Ar limit 11843b3a8eb9SGleb SmirnoffThe maximum number of packets held in the queue. 11853b3a8eb9SGleb SmirnoffThe default is 50. 11863b3a8eb9SGleb Smirnoff.El 11873b3a8eb9SGleb Smirnoff.Pp 11883b3a8eb9SGleb SmirnoffThe 11893b3a8eb9SGleb Smirnoff.Ar scheduler 11903b3a8eb9SGleb Smirnoffcan get additional parameters with 11913b3a8eb9SGleb Smirnoff.Xo Aq Ar scheduler 11923b3a8eb9SGleb Smirnoff.Pf ( Aq Ar parameters ) . 11933b3a8eb9SGleb Smirnoff.Xc 11943b3a8eb9SGleb SmirnoffParameters are as follows: 11953b3a8eb9SGleb Smirnoff.Bl -tag -width Fl 11963b3a8eb9SGleb Smirnoff.It Ar default 11973b3a8eb9SGleb SmirnoffPackets not matched by another queue are assigned to this one. 11983b3a8eb9SGleb SmirnoffExactly one default queue is required. 11993b3a8eb9SGleb Smirnoff.It Ar red 12003b3a8eb9SGleb SmirnoffEnable RED (Random Early Detection) on this queue. 12013b3a8eb9SGleb SmirnoffRED drops packets with a probability proportional to the average 12023b3a8eb9SGleb Smirnoffqueue length. 12033b3a8eb9SGleb Smirnoff.It Ar rio 12043b3a8eb9SGleb SmirnoffEnables RIO on this queue. 12053b3a8eb9SGleb SmirnoffRIO is RED with IN/OUT, thus running 12063b3a8eb9SGleb SmirnoffRED two times more than RIO would achieve the same effect. 12073b3a8eb9SGleb SmirnoffRIO is currently not supported in the GENERIC kernel. 12083b3a8eb9SGleb Smirnoff.It Ar ecn 12093b3a8eb9SGleb SmirnoffEnables ECN (Explicit Congestion Notification) on this queue. 12103b3a8eb9SGleb SmirnoffECN implies RED. 12113b3a8eb9SGleb Smirnoff.El 12123b3a8eb9SGleb Smirnoff.Pp 12133b3a8eb9SGleb SmirnoffThe 12143b3a8eb9SGleb Smirnoff.Ar cbq 12153b3a8eb9SGleb Smirnoff.Ar scheduler 12163b3a8eb9SGleb Smirnoffsupports an additional option: 12173b3a8eb9SGleb Smirnoff.Bl -tag -width Fl 12183b3a8eb9SGleb Smirnoff.It Ar borrow 12193b3a8eb9SGleb SmirnoffThe queue can borrow bandwidth from the parent. 12203b3a8eb9SGleb Smirnoff.El 12213b3a8eb9SGleb Smirnoff.Pp 12223b3a8eb9SGleb SmirnoffThe 12233b3a8eb9SGleb Smirnoff.Ar hfsc 12243b3a8eb9SGleb Smirnoff.Ar scheduler 12253b3a8eb9SGleb Smirnoffsupports some additional options: 12263b3a8eb9SGleb Smirnoff.Bl -tag -width Fl 12273b3a8eb9SGleb Smirnoff.It Ar realtime Aq Ar sc 12283b3a8eb9SGleb SmirnoffThe minimum required bandwidth for the queue. 12293b3a8eb9SGleb Smirnoff.It Ar upperlimit Aq Ar sc 12303b3a8eb9SGleb SmirnoffThe maximum allowed bandwidth for the queue. 12313b3a8eb9SGleb Smirnoff.It Ar linkshare Aq Ar sc 12323b3a8eb9SGleb SmirnoffThe bandwidth share of a backlogged queue. 12333b3a8eb9SGleb Smirnoff.El 12343b3a8eb9SGleb Smirnoff.Pp 12353b3a8eb9SGleb Smirnoff.Aq Ar sc 12363b3a8eb9SGleb Smirnoffis an acronym for 12373b3a8eb9SGleb Smirnoff.Ar service curve . 12383b3a8eb9SGleb Smirnoff.Pp 12393b3a8eb9SGleb SmirnoffThe format for service curve specifications is 12403b3a8eb9SGleb Smirnoff.Ar ( m1 , d , m2 ) . 12413b3a8eb9SGleb Smirnoff.Ar m2 12423b3a8eb9SGleb Smirnoffcontrols the bandwidth assigned to the queue. 12433b3a8eb9SGleb Smirnoff.Ar m1 12443b3a8eb9SGleb Smirnoffand 12453b3a8eb9SGleb Smirnoff.Ar d 12463b3a8eb9SGleb Smirnoffare optional and can be used to control the initial bandwidth assignment. 12473b3a8eb9SGleb SmirnoffFor the first 12483b3a8eb9SGleb Smirnoff.Ar d 12493b3a8eb9SGleb Smirnoffmilliseconds the queue gets the bandwidth given as 12503b3a8eb9SGleb Smirnoff.Ar m1 , 12513b3a8eb9SGleb Smirnoffafterwards the value given in 12523b3a8eb9SGleb Smirnoff.Ar m2 . 12533b3a8eb9SGleb Smirnoff.Pp 12543b3a8eb9SGleb SmirnoffFurthermore, with 12553b3a8eb9SGleb Smirnoff.Ar cbq 12563b3a8eb9SGleb Smirnoffand 12573b3a8eb9SGleb Smirnoff.Ar hfsc , 12583b3a8eb9SGleb Smirnoffchild queues can be specified as in an 12593b3a8eb9SGleb Smirnoff.Ar altq 12603b3a8eb9SGleb Smirnoffdeclaration, thus building a tree of queues using a part of 12613b3a8eb9SGleb Smirnofftheir parent's bandwidth. 12623b3a8eb9SGleb Smirnoff.Pp 12633b3a8eb9SGleb SmirnoffPackets can be assigned to queues based on filter rules by using the 12643b3a8eb9SGleb Smirnoff.Ar queue 12653b3a8eb9SGleb Smirnoffkeyword. 12663b3a8eb9SGleb SmirnoffNormally only one 12673b3a8eb9SGleb Smirnoff.Ar queue 12683b3a8eb9SGleb Smirnoffis specified; when a second one is specified it will instead be used for 12693b3a8eb9SGleb Smirnoffpackets which have a 12703b3a8eb9SGleb Smirnoff.Em TOS 12713b3a8eb9SGleb Smirnoffof 12723b3a8eb9SGleb Smirnoff.Em lowdelay 12733b3a8eb9SGleb Smirnoffand for TCP ACKs with no data payload. 12743b3a8eb9SGleb Smirnoff.Pp 12753b3a8eb9SGleb SmirnoffTo continue the previous example, the examples below would specify the 12763b3a8eb9SGleb Smirnofffour referenced 12773b3a8eb9SGleb Smirnoffqueues, plus a few child queues. 12783b3a8eb9SGleb SmirnoffInteractive 12793b3a8eb9SGleb Smirnoff.Xr ssh 1 12803b3a8eb9SGleb Smirnoffsessions get priority over bulk transfers like 12813b3a8eb9SGleb Smirnoff.Xr scp 1 12823b3a8eb9SGleb Smirnoffand 12833b3a8eb9SGleb Smirnoff.Xr sftp 1 . 12843b3a8eb9SGleb SmirnoffThe queues may then be referenced by filtering rules (see 12853b3a8eb9SGleb Smirnoff.Sx PACKET FILTERING 12863b3a8eb9SGleb Smirnoffbelow). 12873b3a8eb9SGleb Smirnoff.Bd -literal 12883b3a8eb9SGleb Smirnoffqueue std bandwidth 10% cbq(default) 12893b3a8eb9SGleb Smirnoffqueue http bandwidth 60% priority 2 cbq(borrow red) \e 12903b3a8eb9SGleb Smirnoff { employees, developers } 12913b3a8eb9SGleb Smirnoffqueue developers bandwidth 75% cbq(borrow) 12923b3a8eb9SGleb Smirnoffqueue employees bandwidth 15% 12933b3a8eb9SGleb Smirnoffqueue mail bandwidth 10% priority 0 cbq(borrow ecn) 12943b3a8eb9SGleb Smirnoffqueue ssh bandwidth 20% cbq(borrow) { ssh_interactive, ssh_bulk } 12953b3a8eb9SGleb Smirnoffqueue ssh_interactive bandwidth 50% priority 7 cbq(borrow) 12963b3a8eb9SGleb Smirnoffqueue ssh_bulk bandwidth 50% priority 0 cbq(borrow) 12973b3a8eb9SGleb Smirnoff 12983b3a8eb9SGleb Smirnoffblock return out on dc0 inet all queue std 12993b3a8eb9SGleb Smirnoffpass out on dc0 inet proto tcp from $developerhosts to any port 80 \e 13003b3a8eb9SGleb Smirnoff queue developers 13013b3a8eb9SGleb Smirnoffpass out on dc0 inet proto tcp from $employeehosts to any port 80 \e 13023b3a8eb9SGleb Smirnoff queue employees 13033b3a8eb9SGleb Smirnoffpass out on dc0 inet proto tcp from any to any port 22 \e 13043b3a8eb9SGleb Smirnoff queue(ssh_bulk, ssh_interactive) 13053b3a8eb9SGleb Smirnoffpass out on dc0 inet proto tcp from any to any port 25 \e 13063b3a8eb9SGleb Smirnoff queue mail 13073b3a8eb9SGleb Smirnoff.Ed 130800a7a05bSKristof Provost.Sh QUEUEING with dummynet 130900a7a05bSKristof ProvostQueueing can also be done with 131000a7a05bSKristof Provost.Xr dummynet 4 . 131100a7a05bSKristof ProvostQueues and pipes can be created with 131200a7a05bSKristof Provost.Xr dnctl 8 . 131300a7a05bSKristof Provost.Pp 131400a7a05bSKristof ProvostPackets can be assigned to queues and pipes using 131500a7a05bSKristof Provost.Ar dnqueue 131600a7a05bSKristof Provostand 131700a7a05bSKristof Provost.Ar dnpipe 131800a7a05bSKristof Provostrespectively. 131900a7a05bSKristof Provost.Pp 132000a7a05bSKristof ProvostBoth 132100a7a05bSKristof Provost.Ar dnqueue 132200a7a05bSKristof Provostand 132300a7a05bSKristof Provost.Ar dnpipe 132400a7a05bSKristof Provosttake either a single pipe or queue number or two numbers as arguments. 132500a7a05bSKristof ProvostThe first pipe or queue number will be used to shape the traffic in the rule 132600a7a05bSKristof Provostdirection, the second will be used to shape the traffic in the reverse 132700a7a05bSKristof Provostdirection. 132800a7a05bSKristof ProvostIf the rule does not specify a direction the first packet to create state will 132900a7a05bSKristof Provostbe shaped according to the first number, and the response traffic according to 133000a7a05bSKristof Provostthe second. 133100a7a05bSKristof Provost.Pp 133200a7a05bSKristof ProvostIf the 133300a7a05bSKristof Provost.Xr dummynet 4 133400a7a05bSKristof Provostmodule is not loaded any traffic sent into a queue or pipe will be dropped. 13353b3a8eb9SGleb Smirnoff.Sh TRANSLATION 13363b3a8eb9SGleb SmirnoffTranslation rules modify either the source or destination address of the 13373b3a8eb9SGleb Smirnoffpackets associated with a stateful connection. 13383b3a8eb9SGleb SmirnoffA stateful connection is automatically created to track packets matching 13393b3a8eb9SGleb Smirnoffsuch a rule as long as they are not blocked by the filtering section of 13403b3a8eb9SGleb Smirnoff.Nm pf.conf . 13413b3a8eb9SGleb SmirnoffThe translation engine modifies the specified address and/or port in the 134247d0c1feSKristof Provostpacket, recalculates IP, TCP and UDP checksums as necessary, and passes 134347d0c1feSKristof Provostit to the packet filter for evaluation. 13443b3a8eb9SGleb Smirnoff.Pp 13453b3a8eb9SGleb SmirnoffSince translation occurs before filtering the filter 13463b3a8eb9SGleb Smirnoffengine will see packets as they look after any 13473b3a8eb9SGleb Smirnoffaddresses and ports have been translated. 13483b3a8eb9SGleb SmirnoffFilter rules will therefore have to filter based on the translated 13493b3a8eb9SGleb Smirnoffaddress and port number. 13503b3a8eb9SGleb SmirnoffPackets that match a translation rule are only automatically passed if 13513b3a8eb9SGleb Smirnoffthe 13523b3a8eb9SGleb Smirnoff.Ar pass 13533b3a8eb9SGleb Smirnoffmodifier is given, otherwise they are 13543b3a8eb9SGleb Smirnoffstill subject to 13553b3a8eb9SGleb Smirnoff.Ar block 13563b3a8eb9SGleb Smirnoffand 13573b3a8eb9SGleb Smirnoff.Ar pass 13583b3a8eb9SGleb Smirnoffrules. 13593b3a8eb9SGleb Smirnoff.Pp 13603b3a8eb9SGleb SmirnoffThe state entry created permits 13613b3a8eb9SGleb Smirnoff.Xr pf 4 13623b3a8eb9SGleb Smirnoffto keep track of the original address for traffic associated with that state 13633b3a8eb9SGleb Smirnoffand correctly direct return traffic for that connection. 13643b3a8eb9SGleb Smirnoff.Pp 13653b3a8eb9SGleb SmirnoffVarious types of translation are possible with pf: 13663b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx 1367eaf484fdSKristof Provost.It Ar af-to 1368eaf484fdSKristof ProvostTranslation between different address families (NAT64) is handled 1369eaf484fdSKristof Provostusing 1370eaf484fdSKristof Provost.Ar af-to 1371eaf484fdSKristof Provostrules. 1372eaf484fdSKristof ProvostBecause address family translation overrides the routing table, it's 1373eaf484fdSKristof Provostonly possible to use 1374eaf484fdSKristof Provost.Ar af-to 1375eaf484fdSKristof Provoston inbound rules, and a source address of the resulting translation 1376eaf484fdSKristof Provostmust always be specified. 1377eaf484fdSKristof Provost.Pp 1378eaf484fdSKristof ProvostThe optional second argument is the host or subnet the original 1379eaf484fdSKristof Provostaddresses are translated into for the destination. 1380eaf484fdSKristof ProvostThe lowest bits of the original destination address form the host 1381eaf484fdSKristof Provostpart of the new destination address according to the specified subnet. 1382eaf484fdSKristof ProvostIt is possible to embed a complete IPv4 address into an IPv6 address 1383eaf484fdSKristof Provostusing a network prefix of /96 or smaller. 1384eaf484fdSKristof Provost.Pp 1385eaf484fdSKristof ProvostWhen a destination address is not specified it is assumed that the host 1386eaf484fdSKristof Provostpart is 32-bit long. 1387eaf484fdSKristof ProvostFor IPv6 to IPv4 translation this would mean using only the lower 32 1388eaf484fdSKristof Provostbits of the original IPv6 destination address. 1389eaf484fdSKristof ProvostFor IPv4 to IPv6 translation the destination subnet defaults to the 1390eaf484fdSKristof Provostsubnet of the new IPv6 source address with a prefix length of /96. 1391eaf484fdSKristof ProvostSee RFC 6052 Section 2.2 for details on how the prefix determines the 1392eaf484fdSKristof Provostdestination address encoding. 1393eaf484fdSKristof Provost.Pp 1394eaf484fdSKristof ProvostFor example, the following rules are identical: 1395eaf484fdSKristof Provost.Bd -literal -offset indent 1396eaf484fdSKristof Provostpass in inet af-to inet6 from 2001:db8::1 to 2001:db8::/96 1397eaf484fdSKristof Provostpass in inet af-to inet6 from 2001:db8::1 1398eaf484fdSKristof Provost.Ed 1399eaf484fdSKristof Provost.Pp 1400eaf484fdSKristof ProvostIn the above example the matching IPv4 packets will be modified to 1401eaf484fdSKristof Provosthave a source address of 2001:db8::1 and a destination address will 1402eaf484fdSKristof Provostget prefixed with 2001:db8::/96, e.g. 198.51.100.100 will be 1403eaf484fdSKristof Provosttranslated to 2001:db8::c633:6464. 1404eaf484fdSKristof Provost.Pp 1405eaf484fdSKristof ProvostIn the reverse case the following rules are identical: 1406eaf484fdSKristof Provost.Bd -literal -offset indent 1407eaf484fdSKristof Provostpass in inet6 af-to inet from 198.51.100.1 to 0.0.0.0/0 1408eaf484fdSKristof Provostpass in inet6 af-to inet from 198.51.100.1 1409eaf484fdSKristof Provost.Ed 1410eaf484fdSKristof Provost.Pp 1411eaf484fdSKristof ProvostThe destination IPv4 address is assumed to be embedded inside the 1412eaf484fdSKristof Provostoriginal IPv6 destination address, e.g. 64:ff9b::c633:6464 will be 1413eaf484fdSKristof Provosttranslated to 198.51.100.100. 1414eaf484fdSKristof Provost.Pp 1415eaf484fdSKristof ProvostThe current implementation will only extract IPv4 addresses from the 1416eaf484fdSKristof ProvostIPv6 addresses with a prefix length of /96 and greater. 14173b3a8eb9SGleb Smirnoff.It Ar binat 14183b3a8eb9SGleb SmirnoffA 14193b3a8eb9SGleb Smirnoff.Ar binat 14203b3a8eb9SGleb Smirnoffrule specifies a bidirectional mapping between an external IP netblock 14213b3a8eb9SGleb Smirnoffand an internal IP netblock. 14223b3a8eb9SGleb Smirnoff.It Ar nat 14233b3a8eb9SGleb SmirnoffA 14243b3a8eb9SGleb Smirnoff.Ar nat 14253b3a8eb9SGleb Smirnoffrule specifies that IP addresses are to be changed as the packet 14263b3a8eb9SGleb Smirnofftraverses the given interface. 14273b3a8eb9SGleb SmirnoffThis technique allows one or more IP addresses 14283b3a8eb9SGleb Smirnoffon the translating host to support network traffic for a larger range of 14293b3a8eb9SGleb Smirnoffmachines on an "inside" network. 14303b3a8eb9SGleb SmirnoffAlthough in theory any IP address can be used on the inside, it is strongly 14313b3a8eb9SGleb Smirnoffrecommended that one of the address ranges defined by RFC 1918 be used. 14323b3a8eb9SGleb SmirnoffThese netblocks are: 14333b3a8eb9SGleb Smirnoff.Bd -literal 14343b3a8eb9SGleb Smirnoff10.0.0.0 - 10.255.255.255 (all of net 10, i.e., 10/8) 14353b3a8eb9SGleb Smirnoff172.16.0.0 - 172.31.255.255 (i.e., 172.16/12) 14363b3a8eb9SGleb Smirnoff192.168.0.0 - 192.168.255.255 (i.e., 192.168/16) 14373b3a8eb9SGleb Smirnoff.Ed 14383b3a8eb9SGleb Smirnoff.It Pa rdr 14393b3a8eb9SGleb SmirnoffThe packet is redirected to another destination and possibly a 14403b3a8eb9SGleb Smirnoffdifferent port. 14413b3a8eb9SGleb Smirnoff.Ar rdr 14423b3a8eb9SGleb Smirnoffrules can optionally specify port ranges instead of single ports. 14433b3a8eb9SGleb Smirnoffrdr ... port 2000:2999 -\*(Gt ... port 4000 14443b3a8eb9SGleb Smirnoffredirects ports 2000 to 2999 (inclusive) to port 4000. 14453b3a8eb9SGleb Smirnoffrdr ... port 2000:2999 -\*(Gt ... port 4000:* 14463b3a8eb9SGleb Smirnoffredirects port 2000 to 4000, 2001 to 4001, ..., 2999 to 4999. 14473b3a8eb9SGleb Smirnoff.El 14483b3a8eb9SGleb Smirnoff.Pp 14493b3a8eb9SGleb SmirnoffIn addition to modifying the address, some translation rules may modify 14503b3a8eb9SGleb Smirnoffsource or destination ports for 14513b3a8eb9SGleb Smirnoff.Xr tcp 4 14523b3a8eb9SGleb Smirnoffor 14533b3a8eb9SGleb Smirnoff.Xr udp 4 14543b3a8eb9SGleb Smirnoffconnections; implicitly in the case of 14553b3a8eb9SGleb Smirnoff.Ar nat 14569897a669SMark Johnstonrules and both implicitly and explicitly in the case of 14573b3a8eb9SGleb Smirnoff.Ar rdr 14583b3a8eb9SGleb Smirnoffrules. 14599897a669SMark JohnstonA 14609897a669SMark Johnston.Ar rdr 14619897a669SMark Johnstonrule may cause the source port to be modified if doing so avoids a conflict 14629897a669SMark Johnstonwith an existing connection. 1463339a1977SMark JohnstonA random source port in the range 50001-65535 is chosen in this case; to 1464339a1977SMark Johnstonavoid excessive CPU consumption, the number of searches for a free port is 1465339a1977SMark Johnstonlimited by the 1466339a1977SMark Johnston.Va net.pf.rdr_srcport_rewrite_tries 1467339a1977SMark Johnstonsysctl. 14683b3a8eb9SGleb SmirnoffPort numbers are never translated with a 14693b3a8eb9SGleb Smirnoff.Ar binat 14703b3a8eb9SGleb Smirnoffrule. 14713b3a8eb9SGleb Smirnoff.Pp 14723b3a8eb9SGleb SmirnoffEvaluation order of the translation rules is dependent on the type 14733b3a8eb9SGleb Smirnoffof the translation rules and of the direction of a packet. 14743b3a8eb9SGleb Smirnoff.Ar binat 14753b3a8eb9SGleb Smirnoffrules are always evaluated first. 14763b3a8eb9SGleb SmirnoffThen either the 14773b3a8eb9SGleb Smirnoff.Ar rdr 14783b3a8eb9SGleb Smirnoffrules are evaluated on an inbound packet or the 14793b3a8eb9SGleb Smirnoff.Ar nat 14803b3a8eb9SGleb Smirnoffrules on an outbound packet. 14813b3a8eb9SGleb SmirnoffRules of the same type are evaluated in the same order in which they 14823b3a8eb9SGleb Smirnoffappear in the ruleset. 14833b3a8eb9SGleb SmirnoffThe first matching rule decides what action is taken. 14843b3a8eb9SGleb Smirnoff.Pp 14853b3a8eb9SGleb SmirnoffThe 14863b3a8eb9SGleb Smirnoff.Ar no 14873b3a8eb9SGleb Smirnoffoption prefixed to a translation rule causes packets to remain untranslated, 14883b3a8eb9SGleb Smirnoffmuch in the same way as 14893b3a8eb9SGleb Smirnoff.Ar drop quick 14903b3a8eb9SGleb Smirnoffworks in the packet filter (see below). 14913b3a8eb9SGleb SmirnoffIf no rule matches the packet it is passed to the filter engine unmodified. 14923b3a8eb9SGleb Smirnoff.Pp 14933b3a8eb9SGleb SmirnoffTranslation rules apply only to packets that pass through 14943b3a8eb9SGleb Smirnoffthe specified interface, and if no interface is specified, 14953b3a8eb9SGleb Smirnofftranslation is applied to packets on all interfaces. 14963b3a8eb9SGleb SmirnoffFor instance, redirecting port 80 on an external interface to an internal 14973b3a8eb9SGleb Smirnoffweb server will only work for connections originating from the outside. 14983b3a8eb9SGleb SmirnoffConnections to the address of the external interface from local hosts will 14993b3a8eb9SGleb Smirnoffnot be redirected, since such packets do not actually pass through the 15003b3a8eb9SGleb Smirnoffexternal interface. 15013b3a8eb9SGleb SmirnoffRedirections cannot reflect packets back through the interface they arrive 15023b3a8eb9SGleb Smirnoffon, they can only be redirected to hosts connected to different interfaces 15033b3a8eb9SGleb Smirnoffor to the firewall itself. 15043b3a8eb9SGleb Smirnoff.Pp 15053b3a8eb9SGleb SmirnoffNote that redirecting external incoming connections to the loopback 15063b3a8eb9SGleb Smirnoffaddress, as in 15073b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 15083b3a8eb9SGleb Smirnoffrdr on ne3 inet proto tcp to port smtp -\*(Gt 127.0.0.1 port spamd 15093b3a8eb9SGleb Smirnoff.Ed 15103b3a8eb9SGleb Smirnoff.Pp 15113b3a8eb9SGleb Smirnoffwill effectively allow an external host to connect to daemons 15123b3a8eb9SGleb Smirnoffbound solely to the loopback address, circumventing the traditional 15133b3a8eb9SGleb Smirnoffblocking of such connections on a real interface. 15143b3a8eb9SGleb SmirnoffUnless this effect is desired, any of the local non-loopback addresses 15153b3a8eb9SGleb Smirnoffshould be used as redirection target instead, which allows external 15163b3a8eb9SGleb Smirnoffconnections only to daemons bound to this address or not bound to 15173b3a8eb9SGleb Smirnoffany address. 15183b3a8eb9SGleb Smirnoff.Pp 15193b3a8eb9SGleb SmirnoffSee 15203b3a8eb9SGleb Smirnoff.Sx TRANSLATION EXAMPLES 15213b3a8eb9SGleb Smirnoffbelow. 15223b3a8eb9SGleb Smirnoff.Sh PACKET FILTERING 15233b3a8eb9SGleb Smirnoff.Xr pf 4 15243b3a8eb9SGleb Smirnoffhas the ability to 15253b3a8eb9SGleb Smirnoff.Ar block 15260351b987SKristof Provost, 15273b3a8eb9SGleb Smirnoff.Ar pass 15280351b987SKristof Provostand 15290351b987SKristof Provost.Ar match 15303b3a8eb9SGleb Smirnoffpackets based on attributes of their layer 3 (see 15313b3a8eb9SGleb Smirnoff.Xr ip 4 15323b3a8eb9SGleb Smirnoffand 15333b3a8eb9SGleb Smirnoff.Xr ip6 4 ) 15343b3a8eb9SGleb Smirnoffand layer 4 (see 15353b3a8eb9SGleb Smirnoff.Xr icmp 4 , 15363b3a8eb9SGleb Smirnoff.Xr icmp6 4 , 15373b3a8eb9SGleb Smirnoff.Xr tcp 4 , 153847d0c1feSKristof Provost.Xr sctp 4 , 15393b3a8eb9SGleb Smirnoff.Xr udp 4 ) 15403b3a8eb9SGleb Smirnoffheaders. 15413b3a8eb9SGleb SmirnoffIn addition, packets may also be 15423b3a8eb9SGleb Smirnoffassigned to queues for the purpose of bandwidth control. 15433b3a8eb9SGleb Smirnoff.Pp 15443b3a8eb9SGleb SmirnoffFor each packet processed by the packet filter, the filter rules are 15453b3a8eb9SGleb Smirnoffevaluated in sequential order, from first to last. 15460351b987SKristof ProvostFor 15470351b987SKristof Provost.Ar block 15480351b987SKristof Provostand 15490351b987SKristof Provost.Ar pass 15500351b987SKristof Provost, the last matching rule decides what action is taken. 15510351b987SKristof ProvostFor 15520351b987SKristof Provost.Ar match 1553bdb82431SMaxim Konovalov, rules are evaluated every time they match; the pass/block state of a packet 15540351b987SKristof Provostremains unchanged. 15553b3a8eb9SGleb SmirnoffIf no rule matches the packet, the default action is to pass 15563b3a8eb9SGleb Smirnoffthe packet. 15573b3a8eb9SGleb Smirnoff.Pp 15583b3a8eb9SGleb SmirnoffThe following actions can be used in the filter: 15593b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx 15603b3a8eb9SGleb Smirnoff.It Ar block 15613b3a8eb9SGleb SmirnoffThe packet is blocked. 15623b3a8eb9SGleb SmirnoffThere are a number of ways in which a 15633b3a8eb9SGleb Smirnoff.Ar block 15643b3a8eb9SGleb Smirnoffrule can behave when blocking a packet. 15653b3a8eb9SGleb SmirnoffThe default behaviour is to 15663b3a8eb9SGleb Smirnoff.Ar drop 15673b3a8eb9SGleb Smirnoffpackets silently, however this can be overridden or made 15683b3a8eb9SGleb Smirnoffexplicit either globally, by setting the 15693b3a8eb9SGleb Smirnoff.Ar block-policy 15703b3a8eb9SGleb Smirnoffoption, or on a per-rule basis with one of the following options: 15713b3a8eb9SGleb Smirnoff.Pp 15723b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx -compact 15733b3a8eb9SGleb Smirnoff.It Ar drop 15743b3a8eb9SGleb SmirnoffThe packet is silently dropped. 15753b3a8eb9SGleb Smirnoff.It Ar return-rst 15763b3a8eb9SGleb SmirnoffThis applies only to 15773b3a8eb9SGleb Smirnoff.Xr tcp 4 15783b3a8eb9SGleb Smirnoffpackets, and issues a TCP RST which closes the 15793b3a8eb9SGleb Smirnoffconnection. 15803b3a8eb9SGleb Smirnoff.It Ar return-icmp 15813b3a8eb9SGleb Smirnoff.It Ar return-icmp6 15823b3a8eb9SGleb SmirnoffThis causes ICMP messages to be returned for packets which match the rule. 15833b3a8eb9SGleb SmirnoffBy default this is an ICMP UNREACHABLE message, however this 15843b3a8eb9SGleb Smirnoffcan be overridden by specifying a message as a code or number. 15853b3a8eb9SGleb Smirnoff.It Ar return 15863b3a8eb9SGleb SmirnoffThis causes a TCP RST to be returned for 15873b3a8eb9SGleb Smirnoff.Xr tcp 4 158847d0c1feSKristof Provostpackets, an SCTP ABORT for SCTP 158947d0c1feSKristof Provostand an ICMP UNREACHABLE for UDP and other packets. 15903b3a8eb9SGleb Smirnoff.El 15913b3a8eb9SGleb Smirnoff.Pp 15923b3a8eb9SGleb SmirnoffOptions returning ICMP packets currently have no effect if 15933b3a8eb9SGleb Smirnoff.Xr pf 4 15943b3a8eb9SGleb Smirnoffoperates on a 15953b3a8eb9SGleb Smirnoff.Xr if_bridge 4 , 15963b3a8eb9SGleb Smirnoffas the code to support this feature has not yet been implemented. 15973b3a8eb9SGleb Smirnoff.Pp 15983b3a8eb9SGleb SmirnoffThe simplest mechanism to block everything by default and only pass 15993b3a8eb9SGleb Smirnoffpackets that match explicit rules is specify a first filter rule of: 16003b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 16013b3a8eb9SGleb Smirnoffblock all 16023b3a8eb9SGleb Smirnoff.Ed 16030351b987SKristof Provost.It Ar match 16040351b987SKristof ProvostThe packet is matched. 16050351b987SKristof ProvostThis mechanism is used to provide fine grained filtering without altering the 16060351b987SKristof Provostblock/pass state of a packet. 16070351b987SKristof Provost.Ar match 16080351b987SKristof Provostrules differ from 16090351b987SKristof Provost.Ar block 16100351b987SKristof Provostand 16110351b987SKristof Provost.Ar pass 16125ed470bdSKajetan Staszkiewiczrules in that parameters are set for every rule a packet matches, not only 16130351b987SKristof Provoston the last matching rule. 16140351b987SKristof ProvostFor the following parameters, this means that the parameter effectively becomes 16150351b987SKristof Provost"sticky" until explicitly overridden: 161600a7a05bSKristof Provost.Ar queue , 161700a7a05bSKristof Provost.Ar dnpipe , 16185ed470bdSKajetan Staszkiewicz.Ar dnqueue , 16195ed470bdSKajetan Staszkiewicz.Ar rtable , 16205ed470bdSKajetan Staszkiewicz.Ar scrub 16210351b987SKristof Provost. 16223b3a8eb9SGleb Smirnoff.It Ar pass 16233b3a8eb9SGleb SmirnoffThe packet is passed; 16243b3a8eb9SGleb Smirnoffstate is created unless the 16253b3a8eb9SGleb Smirnoff.Ar no state 16263b3a8eb9SGleb Smirnoffoption is specified. 16273b3a8eb9SGleb Smirnoff.El 16283b3a8eb9SGleb Smirnoff.Pp 16293b3a8eb9SGleb SmirnoffBy default 16303b3a8eb9SGleb Smirnoff.Xr pf 4 16313b3a8eb9SGleb Smirnofffilters packets statefully; the first time a packet matches a 16323b3a8eb9SGleb Smirnoff.Ar pass 16333b3a8eb9SGleb Smirnoffrule, a state entry is created; for subsequent packets the filter checks 16343b3a8eb9SGleb Smirnoffwhether the packet matches any state. 16353b3a8eb9SGleb SmirnoffIf it does, the packet is passed without evaluation of any rules. 16363b3a8eb9SGleb SmirnoffAfter the connection is closed or times out, the state entry is automatically 16373b3a8eb9SGleb Smirnoffremoved. 16383b3a8eb9SGleb Smirnoff.Pp 16393b3a8eb9SGleb SmirnoffThis has several advantages. 16403b3a8eb9SGleb SmirnoffFor TCP connections, comparing a packet to a state involves checking 16413b3a8eb9SGleb Smirnoffits sequence numbers, as well as TCP timestamps if a 16423b3a8eb9SGleb Smirnoff.Ar scrub reassemble tcp 16433b3a8eb9SGleb Smirnoffrule applies to the connection. 16443b3a8eb9SGleb SmirnoffIf these values are outside the narrow windows of expected 16453b3a8eb9SGleb Smirnoffvalues, the packet is dropped. 16463b3a8eb9SGleb SmirnoffThis prevents spoofing attacks, such as when an attacker sends packets with 16473b3a8eb9SGleb Smirnoffa fake source address/port but does not know the connection's sequence 16483b3a8eb9SGleb Smirnoffnumbers. 16493b3a8eb9SGleb SmirnoffSimilarly, 16503b3a8eb9SGleb Smirnoff.Xr pf 4 16513b3a8eb9SGleb Smirnoffknows how to match ICMP replies to states. 16523b3a8eb9SGleb SmirnoffFor example, 16533b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 16543b3a8eb9SGleb Smirnoffpass out inet proto icmp all icmp-type echoreq 16553b3a8eb9SGleb Smirnoff.Ed 16563b3a8eb9SGleb Smirnoff.Pp 16573b3a8eb9SGleb Smirnoffallows echo requests (such as those created by 16583b3a8eb9SGleb Smirnoff.Xr ping 8 ) 16593b3a8eb9SGleb Smirnoffout statefully, and matches incoming echo replies correctly to states. 16603b3a8eb9SGleb Smirnoff.Pp 16613b3a8eb9SGleb SmirnoffAlso, looking up states is usually faster than evaluating rules. 16623b3a8eb9SGleb SmirnoffIf there are 50 rules, all of them are evaluated sequentially in O(n). 16633b3a8eb9SGleb SmirnoffEven with 50000 states, only 16 comparisons are needed to match a 16643b3a8eb9SGleb Smirnoffstate, since states are stored in a binary search tree that allows 16653b3a8eb9SGleb Smirnoffsearches in O(log2 n). 16663b3a8eb9SGleb Smirnoff.Pp 16673b3a8eb9SGleb SmirnoffFurthermore, correct handling of ICMP error messages is critical to 16683b3a8eb9SGleb Smirnoffmany protocols, particularly TCP. 16693b3a8eb9SGleb Smirnoff.Xr pf 4 16703b3a8eb9SGleb Smirnoffmatches ICMP error messages to the correct connection, checks them against 16713b3a8eb9SGleb Smirnoffconnection parameters, and passes them if appropriate. 16723b3a8eb9SGleb SmirnoffFor example if an ICMP source quench message referring to a stateful TCP 16733b3a8eb9SGleb Smirnoffconnection arrives, it will be matched to the state and get passed. 16743b3a8eb9SGleb Smirnoff.Pp 16753b3a8eb9SGleb SmirnoffFinally, state tracking is required for 16763b3a8eb9SGleb Smirnoff.Ar nat , binat No and Ar rdr 16773b3a8eb9SGleb Smirnoffrules, in order to track address and port translations and reverse the 16783b3a8eb9SGleb Smirnofftranslation on returning packets. 16793b3a8eb9SGleb Smirnoff.Pp 16803b3a8eb9SGleb Smirnoff.Xr pf 4 16813b3a8eb9SGleb Smirnoffwill also create state for other protocols which are effectively stateless by 16823b3a8eb9SGleb Smirnoffnature. 16833b3a8eb9SGleb SmirnoffUDP packets are matched to states using only host addresses and ports, 16843b3a8eb9SGleb Smirnoffand other protocols are matched to states using only the host addresses. 16853b3a8eb9SGleb Smirnoff.Pp 16863b3a8eb9SGleb SmirnoffIf stateless filtering of individual packets is desired, 16873b3a8eb9SGleb Smirnoffthe 16883b3a8eb9SGleb Smirnoff.Ar no state 16893b3a8eb9SGleb Smirnoffkeyword can be used to specify that state will not be created 16903b3a8eb9SGleb Smirnoffif this is the last matching rule. 16913b3a8eb9SGleb SmirnoffA number of parameters can also be set to affect how 16923b3a8eb9SGleb Smirnoff.Xr pf 4 16933b3a8eb9SGleb Smirnoffhandles state tracking. 16943b3a8eb9SGleb SmirnoffSee 16953b3a8eb9SGleb Smirnoff.Sx STATEFUL TRACKING OPTIONS 16963b3a8eb9SGleb Smirnoffbelow for further details. 16973b3a8eb9SGleb Smirnoff.Sh PARAMETERS 16983b3a8eb9SGleb SmirnoffThe rule parameters specify the packets to which a rule applies. 16993b3a8eb9SGleb SmirnoffA packet always comes in on, or goes out through, one interface. 17003b3a8eb9SGleb SmirnoffMost parameters are optional. 17013b3a8eb9SGleb SmirnoffIf a parameter is specified, the rule only applies to packets with 17023b3a8eb9SGleb Smirnoffmatching attributes. 17033b3a8eb9SGleb SmirnoffCertain parameters can be expressed as lists, in which case 17043b3a8eb9SGleb Smirnoff.Xr pfctl 8 17053b3a8eb9SGleb Smirnoffgenerates all needed rule combinations. 17063b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx 17073b3a8eb9SGleb Smirnoff.It Ar in No or Ar out 17083b3a8eb9SGleb SmirnoffThis rule applies to incoming or outgoing packets. 17093b3a8eb9SGleb SmirnoffIf neither 17103b3a8eb9SGleb Smirnoff.Ar in 17113b3a8eb9SGleb Smirnoffnor 17123b3a8eb9SGleb Smirnoff.Ar out 17133b3a8eb9SGleb Smirnoffare specified, the rule will match packets in both directions. 17143b3a8eb9SGleb Smirnoff.It Ar log 17153b3a8eb9SGleb SmirnoffIn addition to the action specified, a log message is generated. 17163b3a8eb9SGleb SmirnoffOnly the packet that establishes the state is logged, 17173b3a8eb9SGleb Smirnoffunless the 17183b3a8eb9SGleb Smirnoff.Ar no state 17193b3a8eb9SGleb Smirnoffoption is specified. 17203b3a8eb9SGleb SmirnoffThe logged packets are sent to a 17213b3a8eb9SGleb Smirnoff.Xr pflog 4 17223b3a8eb9SGleb Smirnoffinterface, by default 17233b3a8eb9SGleb Smirnoff.Ar pflog0 . 17243b3a8eb9SGleb SmirnoffThis interface is monitored by the 17253b3a8eb9SGleb Smirnoff.Xr pflogd 8 17263b3a8eb9SGleb Smirnofflogging daemon, which dumps the logged packets to the file 17273b3a8eb9SGleb Smirnoff.Pa /var/log/pflog 17283b3a8eb9SGleb Smirnoffin 17293b3a8eb9SGleb Smirnoff.Xr pcap 3 17303b3a8eb9SGleb Smirnoffbinary format. 17313b3a8eb9SGleb Smirnoff.It Ar log (all) 17323b3a8eb9SGleb SmirnoffUsed to force logging of all packets for a connection. 17333b3a8eb9SGleb SmirnoffThis is not necessary when 17343b3a8eb9SGleb Smirnoff.Ar no state 17353b3a8eb9SGleb Smirnoffis explicitly specified. 17363b3a8eb9SGleb SmirnoffAs with 17373b3a8eb9SGleb Smirnoff.Ar log , 17383b3a8eb9SGleb Smirnoffpackets are logged to 17393b3a8eb9SGleb Smirnoff.Xr pflog 4 . 1740f3ab00c2SKristof Provost.It Ar log (matches) 1741f3ab00c2SKristof ProvostUsed to force logging of this packet on all subsequent matching rules. 17423b3a8eb9SGleb Smirnoff.It Ar log (user) 17433b3a8eb9SGleb SmirnoffLogs the 17443b3a8eb9SGleb Smirnoff.Ux 17453b3a8eb9SGleb Smirnoffuser ID of the user that owns the socket and the PID of the process that 17463b3a8eb9SGleb Smirnoffhas the socket open where the packet is sourced from or destined to 17473b3a8eb9SGleb Smirnoff(depending on which socket is local). 17483b3a8eb9SGleb SmirnoffThis is in addition to the normal information logged. 17493b3a8eb9SGleb Smirnoff.Pp 17503b3a8eb9SGleb SmirnoffOnly the first packet 17513b3a8eb9SGleb Smirnofflogged via 17523b3a8eb9SGleb Smirnoff.Ar log (all, user) 17533b3a8eb9SGleb Smirnoffwill have the user credentials logged when using stateful matching. 17543b3a8eb9SGleb Smirnoff.It Ar log (to Aq Ar interface ) 17553b3a8eb9SGleb SmirnoffSend logs to the specified 17563b3a8eb9SGleb Smirnoff.Xr pflog 4 17573b3a8eb9SGleb Smirnoffinterface instead of 17583b3a8eb9SGleb Smirnoff.Ar pflog0 . 17593b3a8eb9SGleb Smirnoff.It Ar quick 17603b3a8eb9SGleb SmirnoffIf a packet matches a rule which has the 17613b3a8eb9SGleb Smirnoff.Ar quick 17623b3a8eb9SGleb Smirnoffoption set, this rule 17633b3a8eb9SGleb Smirnoffis considered the last matching rule, and evaluation of subsequent rules 17643b3a8eb9SGleb Smirnoffis skipped. 17653b3a8eb9SGleb Smirnoff.It Ar on Aq Ar interface 17663b3a8eb9SGleb SmirnoffThis rule applies only to packets coming in on, or going out through, this 17673b3a8eb9SGleb Smirnoffparticular interface or interface group. 17683b3a8eb9SGleb SmirnoffFor more information on interface groups, 17693b3a8eb9SGleb Smirnoffsee the 17703b3a8eb9SGleb Smirnoff.Ic group 17713b3a8eb9SGleb Smirnoffkeyword in 17723b3a8eb9SGleb Smirnoff.Xr ifconfig 8 . 1773*618a8766SKristof Provost.Ar any 1774*618a8766SKristof Provostwill match any existing interface except loopback ones. 17753b3a8eb9SGleb Smirnoff.It Aq Ar af 17763b3a8eb9SGleb SmirnoffThis rule applies only to packets of this address family. 17773b3a8eb9SGleb SmirnoffSupported values are 17783b3a8eb9SGleb Smirnoff.Ar inet 17793b3a8eb9SGleb Smirnoffand 17803b3a8eb9SGleb Smirnoff.Ar inet6 . 17813b3a8eb9SGleb Smirnoff.It Ar proto Aq Ar protocol 17823b3a8eb9SGleb SmirnoffThis rule applies only to packets of this protocol. 17833b3a8eb9SGleb SmirnoffCommon protocols are 17843b3a8eb9SGleb Smirnoff.Xr icmp 4 , 17853b3a8eb9SGleb Smirnoff.Xr icmp6 4 , 17863b3a8eb9SGleb Smirnoff.Xr tcp 4 , 178747d0c1feSKristof Provost.Xr sctp 4 , 17883b3a8eb9SGleb Smirnoffand 17893b3a8eb9SGleb Smirnoff.Xr udp 4 . 17903b3a8eb9SGleb SmirnoffFor a list of all the protocol name to number mappings used by 17913b3a8eb9SGleb Smirnoff.Xr pfctl 8 , 17923b3a8eb9SGleb Smirnoffsee the file 179337b983c0SJoel Dahl.Pa /etc/protocols . 17943b3a8eb9SGleb Smirnoff.It Xo 17953b3a8eb9SGleb Smirnoff.Ar from Aq Ar source 17963b3a8eb9SGleb Smirnoff.Ar port Aq Ar source 17973b3a8eb9SGleb Smirnoff.Ar os Aq Ar source 17983b3a8eb9SGleb Smirnoff.Ar to Aq Ar dest 17993b3a8eb9SGleb Smirnoff.Ar port Aq Ar dest 18003b3a8eb9SGleb Smirnoff.Xc 18013b3a8eb9SGleb SmirnoffThis rule applies only to packets with the specified source and destination 18023b3a8eb9SGleb Smirnoffaddresses and ports. 18033b3a8eb9SGleb Smirnoff.Pp 18043b3a8eb9SGleb SmirnoffAddresses can be specified in CIDR notation (matching netblocks), as 18053b3a8eb9SGleb Smirnoffsymbolic host names, interface names or interface group names, or as any 18063b3a8eb9SGleb Smirnoffof the following keywords: 18073b3a8eb9SGleb Smirnoff.Pp 18083b3a8eb9SGleb Smirnoff.Bl -tag -width xxxxxxxxxxxxxx -compact 18093b3a8eb9SGleb Smirnoff.It Ar any 18103b3a8eb9SGleb SmirnoffAny address. 18113b3a8eb9SGleb Smirnoff.It Ar no-route 18123b3a8eb9SGleb SmirnoffAny address which is not currently routable. 18133b3a8eb9SGleb Smirnoff.It Ar urpf-failed 18143b3a8eb9SGleb SmirnoffAny source address that fails a unicast reverse path forwarding (URPF) 18153b3a8eb9SGleb Smirnoffcheck, i.e. packets coming in on an interface other than that which holds 18163b3a8eb9SGleb Smirnoffthe route back to the packet's source address. 1817b6a5e221SKristof Provost.It Ar self 1818b6a5e221SKristof ProvostExpands to all addresses assigned to all interfaces. 18193b3a8eb9SGleb Smirnoff.It Aq Ar table 18203b3a8eb9SGleb SmirnoffAny address that matches the given table. 18213b3a8eb9SGleb Smirnoff.El 18223b3a8eb9SGleb Smirnoff.Pp 18233b3a8eb9SGleb SmirnoffRanges of addresses are specified by using the 18243b3a8eb9SGleb Smirnoff.Sq - 18253b3a8eb9SGleb Smirnoffoperator. 18263b3a8eb9SGleb SmirnoffFor instance: 18273b3a8eb9SGleb Smirnoff.Dq 10.1.1.10 - 10.1.1.12 18283b3a8eb9SGleb Smirnoffmeans all addresses from 10.1.1.10 to 10.1.1.12, 18293b3a8eb9SGleb Smirnoffhence addresses 10.1.1.10, 10.1.1.11, and 10.1.1.12. 18303b3a8eb9SGleb Smirnoff.Pp 1831b6a5e221SKristof ProvostInterface names and interface group names, and 1832b6a5e221SKristof Provost.Ar self 1833b6a5e221SKristof Provostcan have modifiers appended: 18343b3a8eb9SGleb Smirnoff.Pp 18353b3a8eb9SGleb Smirnoff.Bl -tag -width xxxxxxxxxxxx -compact 18363b3a8eb9SGleb Smirnoff.It Ar :network 18373b3a8eb9SGleb SmirnoffTranslates to the network(s) attached to the interface. 18383b3a8eb9SGleb Smirnoff.It Ar :broadcast 18393b3a8eb9SGleb SmirnoffTranslates to the interface's broadcast address(es). 18403b3a8eb9SGleb Smirnoff.It Ar :peer 18413b3a8eb9SGleb SmirnoffTranslates to the point-to-point interface's peer address(es). 18423b3a8eb9SGleb Smirnoff.It Ar :0 18433b3a8eb9SGleb SmirnoffDo not include interface aliases. 18443b3a8eb9SGleb Smirnoff.El 18453b3a8eb9SGleb Smirnoff.Pp 18463b3a8eb9SGleb SmirnoffHost names may also have the 18473b3a8eb9SGleb Smirnoff.Ar :0 18483b3a8eb9SGleb Smirnoffoption appended to restrict the name resolution to the first of each 184999eb0055SKristof Provostv4 and non-link-local v6 address found. 18503b3a8eb9SGleb Smirnoff.Pp 18513b3a8eb9SGleb SmirnoffHost name resolution and interface to address translation are done at 18523b3a8eb9SGleb Smirnoffruleset load-time. 18533b3a8eb9SGleb SmirnoffWhen the address of an interface (or host name) changes (under DHCP or PPP, 18543b3a8eb9SGleb Smirnofffor instance), the ruleset must be reloaded for the change to be reflected 18553b3a8eb9SGleb Smirnoffin the kernel. 18563b3a8eb9SGleb SmirnoffSurrounding the interface name (and optional modifiers) in parentheses 18573b3a8eb9SGleb Smirnoffchanges this behaviour. 18583b3a8eb9SGleb SmirnoffWhen the interface name is surrounded by parentheses, the rule is 18593b3a8eb9SGleb Smirnoffautomatically updated whenever the interface changes its address. 18603b3a8eb9SGleb SmirnoffThe ruleset does not need to be reloaded. 18613b3a8eb9SGleb SmirnoffThis is especially useful with 18623b3a8eb9SGleb Smirnoff.Ar nat . 18633b3a8eb9SGleb Smirnoff.Pp 18643b3a8eb9SGleb SmirnoffPorts can be specified either by number or by name. 18653b3a8eb9SGleb SmirnoffFor example, port 80 can be specified as 18663b3a8eb9SGleb Smirnoff.Em www . 18673b3a8eb9SGleb SmirnoffFor a list of all port name to number mappings used by 18683b3a8eb9SGleb Smirnoff.Xr pfctl 8 , 18693b3a8eb9SGleb Smirnoffsee the file 18703b3a8eb9SGleb Smirnoff.Pa /etc/services . 18713b3a8eb9SGleb Smirnoff.Pp 18723b3a8eb9SGleb SmirnoffPorts and ranges of ports are specified by using these operators: 18733b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 18743b3a8eb9SGleb Smirnoff= (equal) 18753b3a8eb9SGleb Smirnoff!= (unequal) 18763b3a8eb9SGleb Smirnoff\*(Lt (less than) 187785c333a9SKristof Provost<= (less than or equal) 18783b3a8eb9SGleb Smirnoff\*(Gt (greater than) 187985c333a9SKristof Provost>= (greater than or equal) 18803b3a8eb9SGleb Smirnoff: (range including boundaries) 18813b3a8eb9SGleb Smirnoff\*(Gt\*(Lt (range excluding boundaries) 18823b3a8eb9SGleb Smirnoff\*(Lt\*(Gt (except range) 18833b3a8eb9SGleb Smirnoff.Ed 18843b3a8eb9SGleb Smirnoff.Pp 18853b3a8eb9SGleb Smirnoff.Sq \*(Gt\*(Lt , 18863b3a8eb9SGleb Smirnoff.Sq \*(Lt\*(Gt 18873b3a8eb9SGleb Smirnoffand 18883b3a8eb9SGleb Smirnoff.Sq \&: 18893b3a8eb9SGleb Smirnoffare binary operators (they take two arguments). 18903b3a8eb9SGleb SmirnoffFor instance: 18913b3a8eb9SGleb Smirnoff.Bl -tag -width Fl 18923b3a8eb9SGleb Smirnoff.It Ar port 2000:2004 18933b3a8eb9SGleb Smirnoffmeans 18943b3a8eb9SGleb Smirnoff.Sq all ports \*(Ge 2000 and \*(Le 2004 , 18953b3a8eb9SGleb Smirnoffhence ports 2000, 2001, 2002, 2003 and 2004. 18963b3a8eb9SGleb Smirnoff.It Ar port 2000 \*(Gt\*(Lt 2004 18973b3a8eb9SGleb Smirnoffmeans 18983b3a8eb9SGleb Smirnoff.Sq all ports \*(Gt 2000 and \*(Lt 2004 , 18993b3a8eb9SGleb Smirnoffhence ports 2001, 2002 and 2003. 19003b3a8eb9SGleb Smirnoff.It Ar port 2000 \*(Lt\*(Gt 2004 19013b3a8eb9SGleb Smirnoffmeans 19023b3a8eb9SGleb Smirnoff.Sq all ports \*(Lt 2000 or \*(Gt 2004 , 19033b3a8eb9SGleb Smirnoffhence ports 1-1999 and 2005-65535. 19043b3a8eb9SGleb Smirnoff.El 19053b3a8eb9SGleb Smirnoff.Pp 19063b3a8eb9SGleb SmirnoffThe operating system of the source host can be specified in the case of TCP 19073b3a8eb9SGleb Smirnoffrules with the 19083b3a8eb9SGleb Smirnoff.Ar OS 19093b3a8eb9SGleb Smirnoffmodifier. 19103b3a8eb9SGleb SmirnoffSee the 19113b3a8eb9SGleb Smirnoff.Sx OPERATING SYSTEM FINGERPRINTING 19123b3a8eb9SGleb Smirnoffsection for more information. 19133b3a8eb9SGleb Smirnoff.Pp 19143b3a8eb9SGleb SmirnoffThe host, port and OS specifications are optional, as in the following examples: 19153b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 19163b3a8eb9SGleb Smirnoffpass in all 19173b3a8eb9SGleb Smirnoffpass in from any to any 19184c4a7a8dSKristof Provostpass in proto tcp from any port \*(Lt 1024 to any 19193b3a8eb9SGleb Smirnoffpass in proto tcp from any to any port 25 192085c333a9SKristof Provostpass in proto tcp from 10.0.0.0/8 port >= 1024 \e 19213b3a8eb9SGleb Smirnoff to ! 10.1.2.3 port != ssh 19223b3a8eb9SGleb Smirnoffpass in proto tcp from any os "OpenBSD" 19233b3a8eb9SGleb Smirnoff.Ed 19243b3a8eb9SGleb Smirnoff.It Ar all 19253b3a8eb9SGleb SmirnoffThis is equivalent to "from any to any". 19263b3a8eb9SGleb Smirnoff.It Ar group Aq Ar group 19273b3a8eb9SGleb SmirnoffSimilar to 19283b3a8eb9SGleb Smirnoff.Ar user , 19293b3a8eb9SGleb Smirnoffthis rule only applies to packets of sockets owned by the specified group. 19303b3a8eb9SGleb Smirnoff.It Ar user Aq Ar user 19313b3a8eb9SGleb SmirnoffThis rule only applies to packets of sockets owned by the specified user. 19323b3a8eb9SGleb SmirnoffFor outgoing connections initiated from the firewall, this is the user 19333b3a8eb9SGleb Smirnoffthat opened the connection. 19343b3a8eb9SGleb SmirnoffFor incoming connections to the firewall itself, this is the user that 19353b3a8eb9SGleb Smirnofflistens on the destination port. 19363b3a8eb9SGleb SmirnoffFor forwarded connections, where the firewall is not a connection endpoint, 19373b3a8eb9SGleb Smirnoffthe user and group are 19383b3a8eb9SGleb Smirnoff.Em unknown . 19393b3a8eb9SGleb Smirnoff.Pp 19403b3a8eb9SGleb SmirnoffAll packets, both outgoing and incoming, of one connection are associated 19413b3a8eb9SGleb Smirnoffwith the same user and group. 19423b3a8eb9SGleb SmirnoffOnly TCP and UDP packets can be associated with users; for other protocols 19433b3a8eb9SGleb Smirnoffthese parameters are ignored. 19443b3a8eb9SGleb Smirnoff.Pp 19453b3a8eb9SGleb SmirnoffUser and group refer to the effective (as opposed to the real) IDs, in 19463b3a8eb9SGleb Smirnoffcase the socket is created by a setuid/setgid process. 19473b3a8eb9SGleb SmirnoffUser and group IDs are stored when a socket is created; 19483b3a8eb9SGleb Smirnoffwhen a process creates a listening socket as root (for instance, by 19493b3a8eb9SGleb Smirnoffbinding to a privileged port) and subsequently changes to another 19503b3a8eb9SGleb Smirnoffuser ID (to drop privileges), the credentials will remain root. 19513b3a8eb9SGleb Smirnoff.Pp 19523b3a8eb9SGleb SmirnoffUser and group IDs can be specified as either numbers or names. 19533b3a8eb9SGleb SmirnoffThe syntax is similar to the one for ports. 19543b3a8eb9SGleb SmirnoffThe value 19553b3a8eb9SGleb Smirnoff.Em unknown 19563b3a8eb9SGleb Smirnoffmatches packets of forwarded connections. 19573b3a8eb9SGleb Smirnoff.Em unknown 19583b3a8eb9SGleb Smirnoffcan only be used with the operators 19593b3a8eb9SGleb Smirnoff.Cm = 19603b3a8eb9SGleb Smirnoffand 19613b3a8eb9SGleb Smirnoff.Cm != . 19623b3a8eb9SGleb SmirnoffOther constructs like 19633b3a8eb9SGleb Smirnoff.Cm user \*(Ge unknown 19643b3a8eb9SGleb Smirnoffare invalid. 19653b3a8eb9SGleb SmirnoffForwarded packets with unknown user and group ID match only rules 19663b3a8eb9SGleb Smirnoffthat explicitly compare against 19673b3a8eb9SGleb Smirnoff.Em unknown 19683b3a8eb9SGleb Smirnoffwith the operators 19693b3a8eb9SGleb Smirnoff.Cm = 19703b3a8eb9SGleb Smirnoffor 19713b3a8eb9SGleb Smirnoff.Cm != . 19723b3a8eb9SGleb SmirnoffFor instance 19733b3a8eb9SGleb Smirnoff.Cm user \*(Ge 0 19743b3a8eb9SGleb Smirnoffdoes not match forwarded packets. 19753b3a8eb9SGleb SmirnoffThe following example allows only selected users to open outgoing 19763b3a8eb9SGleb Smirnoffconnections: 19773b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 19783b3a8eb9SGleb Smirnoffblock out proto { tcp, udp } all 19793b3a8eb9SGleb Smirnoffpass out proto { tcp, udp } all user { \*(Lt 1000, dhartmei } 19803b3a8eb9SGleb Smirnoff.Ed 19813b3a8eb9SGleb Smirnoff.It Xo Ar flags Aq Ar a 19823b3a8eb9SGleb Smirnoff.Pf / Ns Aq Ar b 19833b3a8eb9SGleb Smirnoff.No \*(Ba / Ns Aq Ar b 19843b3a8eb9SGleb Smirnoff.No \*(Ba any 19853b3a8eb9SGleb Smirnoff.Xc 19863b3a8eb9SGleb SmirnoffThis rule only applies to TCP packets that have the flags 19873b3a8eb9SGleb Smirnoff.Aq Ar a 19883b3a8eb9SGleb Smirnoffset out of set 19893b3a8eb9SGleb Smirnoff.Aq Ar b . 19903b3a8eb9SGleb SmirnoffFlags not specified in 19913b3a8eb9SGleb Smirnoff.Aq Ar b 19923b3a8eb9SGleb Smirnoffare ignored. 19933b3a8eb9SGleb SmirnoffFor stateful connections, the default is 19943b3a8eb9SGleb Smirnoff.Ar flags S/SA . 19953b3a8eb9SGleb SmirnoffTo indicate that flags should not be checked at all, specify 19963b3a8eb9SGleb Smirnoff.Ar flags any . 19973b3a8eb9SGleb SmirnoffThe flags are: (F)IN, (S)YN, (R)ST, (P)USH, (A)CK, (U)RG, (E)CE, and C(W)R. 19983b3a8eb9SGleb Smirnoff.Bl -tag -width Fl 19993b3a8eb9SGleb Smirnoff.It Ar flags S/S 20003b3a8eb9SGleb SmirnoffFlag SYN is set. 20013b3a8eb9SGleb SmirnoffThe other flags are ignored. 20023b3a8eb9SGleb Smirnoff.It Ar flags S/SA 20033b3a8eb9SGleb SmirnoffThis is the default setting for stateful connections. 20043b3a8eb9SGleb SmirnoffOut of SYN and ACK, exactly SYN may be set. 20053b3a8eb9SGleb SmirnoffSYN, SYN+PSH and SYN+RST match, but SYN+ACK, ACK and ACK+RST do not. 20063b3a8eb9SGleb SmirnoffThis is more restrictive than the previous example. 20073b3a8eb9SGleb Smirnoff.It Ar flags /SFRA 20083b3a8eb9SGleb SmirnoffIf the first set is not specified, it defaults to none. 20093b3a8eb9SGleb SmirnoffAll of SYN, FIN, RST and ACK must be unset. 20103b3a8eb9SGleb Smirnoff.El 20113b3a8eb9SGleb Smirnoff.Pp 20123b3a8eb9SGleb SmirnoffBecause 20133b3a8eb9SGleb Smirnoff.Ar flags S/SA 20143b3a8eb9SGleb Smirnoffis applied by default (unless 20153b3a8eb9SGleb Smirnoff.Ar no state 20163b3a8eb9SGleb Smirnoffis specified), only the initial SYN packet of a TCP handshake will create 20173b3a8eb9SGleb Smirnoffa state for a TCP connection. 20183b3a8eb9SGleb SmirnoffIt is possible to be less restrictive, and allow state creation from 20193b3a8eb9SGleb Smirnoffintermediate 20203b3a8eb9SGleb Smirnoff.Pq non-SYN 20213b3a8eb9SGleb Smirnoffpackets, by specifying 20223b3a8eb9SGleb Smirnoff.Ar flags any . 20233b3a8eb9SGleb SmirnoffThis will cause 20243b3a8eb9SGleb Smirnoff.Xr pf 4 20253b3a8eb9SGleb Smirnoffto synchronize to existing connections, for instance 20263b3a8eb9SGleb Smirnoffif one flushes the state table. 20273b3a8eb9SGleb SmirnoffHowever, states created from such intermediate packets may be missing 20283b3a8eb9SGleb Smirnoffconnection details such as the TCP window scaling factor. 20293b3a8eb9SGleb SmirnoffStates which modify the packet flow, such as those affected by 2030eaf484fdSKristof Provost.Ar af-to, 2031eaf484fdSKristof Provost.Ar nat, 2032eaf484fdSKristof Provost.Ar binat or 2033eaf484fdSKristof Provost.Ar rdr 20343b3a8eb9SGleb Smirnoffrules, 20353b3a8eb9SGleb Smirnoff.Ar modulate No or Ar synproxy state 20363b3a8eb9SGleb Smirnoffoptions, or scrubbed with 20373b3a8eb9SGleb Smirnoff.Ar reassemble tcp 20383b3a8eb9SGleb Smirnoffwill also not be recoverable from intermediate packets. 20393b3a8eb9SGleb SmirnoffSuch connections will stall and time out. 20403b3a8eb9SGleb Smirnoff.It Xo Ar icmp-type Aq Ar type 20413b3a8eb9SGleb Smirnoff.Ar code Aq Ar code 20423b3a8eb9SGleb Smirnoff.Xc 20433b3a8eb9SGleb Smirnoff.It Xo Ar icmp6-type Aq Ar type 20443b3a8eb9SGleb Smirnoff.Ar code Aq Ar code 20453b3a8eb9SGleb Smirnoff.Xc 20463b3a8eb9SGleb SmirnoffThis rule only applies to ICMP or ICMPv6 packets with the specified type 20473b3a8eb9SGleb Smirnoffand code. 20483b3a8eb9SGleb SmirnoffText names for ICMP types and codes are listed in 20493b3a8eb9SGleb Smirnoff.Xr icmp 4 20503b3a8eb9SGleb Smirnoffand 20513b3a8eb9SGleb Smirnoff.Xr icmp6 4 . 20523b3a8eb9SGleb SmirnoffThis parameter is only valid for rules that cover protocols ICMP or 20533b3a8eb9SGleb SmirnoffICMP6. 20543b3a8eb9SGleb SmirnoffThe protocol and the ICMP type indicator 20553b3a8eb9SGleb Smirnoff.Po 20563b3a8eb9SGleb Smirnoff.Ar icmp-type 20573b3a8eb9SGleb Smirnoffor 20583b3a8eb9SGleb Smirnoff.Ar icmp6-type 20593b3a8eb9SGleb Smirnoff.Pc 20603b3a8eb9SGleb Smirnoffmust match. 20613b3a8eb9SGleb Smirnoff.It Xo Ar tos Aq Ar string 20623b3a8eb9SGleb Smirnoff.No \*(Ba Aq Ar number 20633b3a8eb9SGleb Smirnoff.Xc 20643b3a8eb9SGleb SmirnoffThis rule applies to packets with the specified 20653b3a8eb9SGleb Smirnoff.Em TOS 20663b3a8eb9SGleb Smirnoffbits set. 20673b3a8eb9SGleb Smirnoff.Em TOS 20683b3a8eb9SGleb Smirnoffmay be 20693b3a8eb9SGleb Smirnoffgiven as one of 20701f495578SKristof Provost.Ar critical , 20711f495578SKristof Provost.Ar inetcontrol , 20723b3a8eb9SGleb Smirnoff.Ar lowdelay , 20731f495578SKristof Provost.Ar netcontrol , 20743b3a8eb9SGleb Smirnoff.Ar throughput , 20753b3a8eb9SGleb Smirnoff.Ar reliability , 20761f495578SKristof Provostor one of the DiffServ Code Points: 20771f495578SKristof Provost.Ar ef , 2078b4e3f3c2SKristof Provost.Ar va , 20791f495578SKristof Provost.Ar af11 No ... Ar af43 , 20801f495578SKristof Provost.Ar cs0 No ... Ar cs7 ; 20813b3a8eb9SGleb Smirnoffor as either hex or decimal. 20823b3a8eb9SGleb Smirnoff.Pp 20833b3a8eb9SGleb SmirnoffFor example, the following rules are identical: 20843b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 20853b3a8eb9SGleb Smirnoffpass all tos lowdelay 20863b3a8eb9SGleb Smirnoffpass all tos 0x10 20873b3a8eb9SGleb Smirnoffpass all tos 16 20883b3a8eb9SGleb Smirnoff.Ed 20893b3a8eb9SGleb Smirnoff.It Ar allow-opts 20903b3a8eb9SGleb SmirnoffBy default, IPv4 packets with IP options or IPv6 packets with routing 20913b3a8eb9SGleb Smirnoffextension headers are blocked. 20923b3a8eb9SGleb SmirnoffWhen 20933b3a8eb9SGleb Smirnoff.Ar allow-opts 20943b3a8eb9SGleb Smirnoffis specified for a 20953b3a8eb9SGleb Smirnoff.Ar pass 20963b3a8eb9SGleb Smirnoffrule, packets that pass the filter based on that rule (last matching) 20973b3a8eb9SGleb Smirnoffdo so even if they contain IP options or routing extension headers. 20983b3a8eb9SGleb SmirnoffFor packets that match state, the rule that initially created the 20993b3a8eb9SGleb Smirnoffstate is used. 21003b3a8eb9SGleb SmirnoffThe implicit 21013b3a8eb9SGleb Smirnoff.Ar pass 21023b3a8eb9SGleb Smirnoffrule that is used when a packet does not match any rules does not 21033b3a8eb9SGleb Smirnoffallow IP options. 21043b3a8eb9SGleb Smirnoff.It Ar label Aq Ar string 21053b3a8eb9SGleb SmirnoffAdds a label (name) to the rule, which can be used to identify the rule. 21063b3a8eb9SGleb SmirnoffFor instance, 21073b3a8eb9SGleb Smirnoffpfctl -s labels 21083b3a8eb9SGleb Smirnoffshows per-rule statistics for rules that have labels. 21093b3a8eb9SGleb Smirnoff.Pp 21103b3a8eb9SGleb SmirnoffThe following macros can be used in labels: 21113b3a8eb9SGleb Smirnoff.Pp 21123b3a8eb9SGleb Smirnoff.Bl -tag -width $srcaddr -compact -offset indent 21133b3a8eb9SGleb Smirnoff.It Ar $if 21143b3a8eb9SGleb SmirnoffThe interface. 21153b3a8eb9SGleb Smirnoff.It Ar $srcaddr 21163b3a8eb9SGleb SmirnoffThe source IP address. 21173b3a8eb9SGleb Smirnoff.It Ar $dstaddr 21183b3a8eb9SGleb SmirnoffThe destination IP address. 21193b3a8eb9SGleb Smirnoff.It Ar $srcport 21203b3a8eb9SGleb SmirnoffThe source port specification. 21213b3a8eb9SGleb Smirnoff.It Ar $dstport 21223b3a8eb9SGleb SmirnoffThe destination port specification. 21233b3a8eb9SGleb Smirnoff.It Ar $proto 21243b3a8eb9SGleb SmirnoffThe protocol name. 21253b3a8eb9SGleb Smirnoff.It Ar $nr 21263b3a8eb9SGleb SmirnoffThe rule number. 21273b3a8eb9SGleb Smirnoff.El 21283b3a8eb9SGleb Smirnoff.Pp 21293b3a8eb9SGleb SmirnoffFor example: 21303b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 21313b3a8eb9SGleb Smirnoffips = \&"{ 1.2.3.4, 1.2.3.5 }\&" 21323b3a8eb9SGleb Smirnoffpass in proto tcp from any to $ips \e 21333b3a8eb9SGleb Smirnoff port \*(Gt 1023 label \&"$dstaddr:$dstport\&" 21343b3a8eb9SGleb Smirnoff.Ed 21353b3a8eb9SGleb Smirnoff.Pp 21363b3a8eb9SGleb Smirnoffexpands to 21373b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 21383b3a8eb9SGleb Smirnoffpass in inet proto tcp from any to 1.2.3.4 \e 21393b3a8eb9SGleb Smirnoff port \*(Gt 1023 label \&"1.2.3.4:\*(Gt1023\&" 21403b3a8eb9SGleb Smirnoffpass in inet proto tcp from any to 1.2.3.5 \e 21413b3a8eb9SGleb Smirnoff port \*(Gt 1023 label \&"1.2.3.5:\*(Gt1023\&" 21423b3a8eb9SGleb Smirnoff.Ed 21433b3a8eb9SGleb Smirnoff.Pp 21443b3a8eb9SGleb SmirnoffThe macro expansion for the 21453b3a8eb9SGleb Smirnoff.Ar label 21463b3a8eb9SGleb Smirnoffdirective occurs only at configuration file parse time, not during runtime. 214776c5eeccSKristof Provost.It Ar ridentifier Aq Ar number 214876c5eeccSKristof ProvostAdd an identifier (number) to the rule, which can be used to correlate the rule 214976c5eeccSKristof Provostto pflog entries, even after ruleset updates. 21503b3a8eb9SGleb Smirnoff.It Xo Ar queue Aq Ar queue 21513b3a8eb9SGleb Smirnoff.No \*(Ba ( Aq Ar queue , 21523b3a8eb9SGleb Smirnoff.Aq Ar queue ) 21533b3a8eb9SGleb Smirnoff.Xc 21543b3a8eb9SGleb SmirnoffPackets matching this rule will be assigned to the specified queue. 21553b3a8eb9SGleb SmirnoffIf two queues are given, packets which have a 21563b3a8eb9SGleb Smirnoff.Em TOS 21573b3a8eb9SGleb Smirnoffof 21583b3a8eb9SGleb Smirnoff.Em lowdelay 21593b3a8eb9SGleb Smirnoffand TCP ACKs with no data payload will be assigned to the second one. 21603b3a8eb9SGleb SmirnoffSee 21613b3a8eb9SGleb Smirnoff.Sx QUEUEING 21623b3a8eb9SGleb Smirnofffor setup details. 21633b3a8eb9SGleb Smirnoff.Pp 21643b3a8eb9SGleb SmirnoffFor example: 21653b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 21663b3a8eb9SGleb Smirnoffpass in proto tcp to port 25 queue mail 21673b3a8eb9SGleb Smirnoffpass in proto tcp to port 22 queue(ssh_bulk, ssh_prio) 21683b3a8eb9SGleb Smirnoff.Ed 21693e248e0fSKristof Provost.It Cm set prio Ar priority | Pq Ar priority , priority 21703e248e0fSKristof ProvostPackets matching this rule will be assigned a specific queueing priority. 21713e248e0fSKristof ProvostPriorities are assigned as integers 0 through 7. 21723e248e0fSKristof ProvostIf the packet is transmitted on a 21733e248e0fSKristof Provost.Xr vlan 4 21743e248e0fSKristof Provostinterface, the queueing priority will be written as the priority 21753e248e0fSKristof Provostcode point in the 802.1Q VLAN header. 21763e248e0fSKristof ProvostIf two priorities are given, packets which have a TOS of 21773e248e0fSKristof Provost.Cm lowdelay 21783e248e0fSKristof Provostand TCP ACKs with no data payload will be assigned to the second one. 21793e248e0fSKristof Provost.Pp 21803e248e0fSKristof ProvostFor example: 21813e248e0fSKristof Provost.Bd -literal -offset indent 21823e248e0fSKristof Provostpass in proto tcp to port 25 set prio 2 21833e248e0fSKristof Provostpass in proto tcp to port 22 set prio (2, 5) 21843e248e0fSKristof Provost.Ed 2185e80f2a10SKristof Provost.It Ar received-on Aq Ar interface 2186e80f2a10SKristof ProvostOnly match packets which were received on the specified 2187e80f2a10SKristof Provost.Ar interface 2188e80f2a10SKristof Provost(or interface group). 2189*618a8766SKristof Provost.Ar any 2190*618a8766SKristof Provostwill match any existing interface except loopback ones. 21913b3a8eb9SGleb Smirnoff.It Ar tag Aq Ar string 21923b3a8eb9SGleb SmirnoffPackets matching this rule will be tagged with the 21933b3a8eb9SGleb Smirnoffspecified string. 21943b3a8eb9SGleb SmirnoffThe tag acts as an internal marker that can be used to 21953b3a8eb9SGleb Smirnoffidentify these packets later on. 21963b3a8eb9SGleb SmirnoffThis can be used, for example, to provide trust between 21973b3a8eb9SGleb Smirnoffinterfaces and to determine if packets have been 21983b3a8eb9SGleb Smirnoffprocessed by translation rules. 21993b3a8eb9SGleb SmirnoffTags are 22003b3a8eb9SGleb Smirnoff.Qq sticky , 22013b3a8eb9SGleb Smirnoffmeaning that the packet will be tagged even if the rule 22023b3a8eb9SGleb Smirnoffis not the last matching rule. 22033b3a8eb9SGleb SmirnoffFurther matching rules can replace the tag with a 22043b3a8eb9SGleb Smirnoffnew one but will not remove a previously applied tag. 22053b3a8eb9SGleb SmirnoffA packet is only ever assigned one tag at a time. 22063b3a8eb9SGleb SmirnoffPacket tagging can be done during 22073b3a8eb9SGleb Smirnoff.Ar nat , 22083b3a8eb9SGleb Smirnoff.Ar rdr , 22093b3a8eb9SGleb Smirnoff.Ar binat 2210ab2886f0SKristof Provostor 2211ab2886f0SKristof Provost.Ar ether 22123b3a8eb9SGleb Smirnoffrules in addition to filter rules. 22133b3a8eb9SGleb SmirnoffTags take the same macros as labels (see above). 22143b3a8eb9SGleb Smirnoff.It Ar tagged Aq Ar string 22153b3a8eb9SGleb SmirnoffUsed with filter, translation or scrub rules 22163b3a8eb9SGleb Smirnoffto specify that packets must already 22173b3a8eb9SGleb Smirnoffbe tagged with the given tag in order to match the rule. 22183b3a8eb9SGleb SmirnoffInverse tag matching can also be done 22193b3a8eb9SGleb Smirnoffby specifying the 22203b3a8eb9SGleb Smirnoff.Cm !\& 22213b3a8eb9SGleb Smirnoffoperator before the 22223b3a8eb9SGleb Smirnoff.Ar tagged 22233b3a8eb9SGleb Smirnoffkeyword. 22243b3a8eb9SGleb Smirnoff.It Ar rtable Aq Ar number 22253b3a8eb9SGleb SmirnoffUsed to select an alternate routing table for the routing lookup. 22263b3a8eb9SGleb SmirnoffOnly effective before the route lookup happened, i.e. when filtering inbound. 22273b3a8eb9SGleb Smirnoff.It Xo Ar divert-to Aq Ar host 22283b3a8eb9SGleb Smirnoff.Ar port Aq Ar port 22293b3a8eb9SGleb Smirnoff.Xc 22307e1affa2SIgor OstapenkoUsed to 22317e1affa2SIgor Ostapenko.Xr divert 4 22327e1affa2SIgor Ostapenkopackets to the given divert 22333b3a8eb9SGleb Smirnoff.Ar port . 22347e1affa2SIgor OstapenkoHistorically 22357e1affa2SIgor Ostapenko.Ox pf has another meaning for this, and 22367e1affa2SIgor Ostapenko.Fx pf uses 22377e1affa2SIgor Ostapenkothis syntax to support 22387e1affa2SIgor Ostapenko.Xr divert 4 instead. Hence, 22397e1affa2SIgor Ostapenko.Ar host 22407e1affa2SIgor Ostapenkohas no meaning and can be set to anything like 127.0.0.1. 22417e1affa2SIgor OstapenkoIf a packet is re-injected and does not change direction then it will not be 22427e1affa2SIgor Ostapenkore-diverted. 22433b3a8eb9SGleb Smirnoff.It Ar divert-reply 22447e1affa2SIgor OstapenkoIt has no meaning in 22457e1affa2SIgor Ostapenko.Fx pf . 22463b3a8eb9SGleb Smirnoff.It Ar probability Aq Ar number 22473b3a8eb9SGleb SmirnoffA probability attribute can be attached to a rule, with a value set between 22483b3a8eb9SGleb Smirnoff0 and 1, bounds not included. 22493b3a8eb9SGleb SmirnoffIn that case, the rule will be honoured using the given probability value 22503b3a8eb9SGleb Smirnoffonly. 22513b3a8eb9SGleb SmirnoffFor example, the following rule will drop 20% of incoming ICMP packets: 22523b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 22533b3a8eb9SGleb Smirnoffblock in proto icmp probability 20% 22543b3a8eb9SGleb Smirnoff.Ed 22553e248e0fSKristof Provost.It Ar prio Aq Ar number 22563e248e0fSKristof ProvostOnly match packets which have the given queueing priority assigned. 22573b3a8eb9SGleb Smirnoff.El 22583b3a8eb9SGleb Smirnoff.Sh ROUTING 22593b3a8eb9SGleb SmirnoffIf a packet matches a rule with a route option set, the packet filter will 22603b3a8eb9SGleb Smirnoffroute the packet according to the type of route option. 22613b3a8eb9SGleb SmirnoffWhen such a rule creates state, the route option is also applied to all 22623b3a8eb9SGleb Smirnoffpackets matching the same connection. 22633b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx 22643b3a8eb9SGleb Smirnoff.It Ar route-to 22653b3a8eb9SGleb SmirnoffThe 22663b3a8eb9SGleb Smirnoff.Ar route-to 22673b3a8eb9SGleb Smirnoffoption routes the packet to the specified interface with an optional address 22683b3a8eb9SGleb Smirnofffor the next hop. 22693b3a8eb9SGleb SmirnoffWhen a 22703b3a8eb9SGleb Smirnoff.Ar route-to 22713b3a8eb9SGleb Smirnoffrule creates state, only packets that pass in the same direction as the 22723b3a8eb9SGleb Smirnofffilter rule specifies will be routed in this way. 22733b3a8eb9SGleb SmirnoffPackets passing in the opposite direction (replies) are not affected 22743b3a8eb9SGleb Smirnoffand are routed normally. 22753b3a8eb9SGleb Smirnoff.It Ar reply-to 22763b3a8eb9SGleb SmirnoffThe 22773b3a8eb9SGleb Smirnoff.Ar reply-to 22783b3a8eb9SGleb Smirnoffoption is similar to 22793b3a8eb9SGleb Smirnoff.Ar route-to , 22803b3a8eb9SGleb Smirnoffbut routes packets that pass in the opposite direction (replies) to the 22813b3a8eb9SGleb Smirnoffspecified interface. 22823b3a8eb9SGleb SmirnoffOpposite direction is only defined in the context of a state entry, and 22833b3a8eb9SGleb Smirnoff.Ar reply-to 22843b3a8eb9SGleb Smirnoffis useful only in rules that create state. 22853b3a8eb9SGleb SmirnoffIt can be used on systems with multiple external connections to 22863b3a8eb9SGleb Smirnoffroute all outgoing packets of a connection through the interface 22873b3a8eb9SGleb Smirnoffthe incoming connection arrived through (symmetric routing enforcement). 22883b3a8eb9SGleb Smirnoff.It Ar dup-to 22893b3a8eb9SGleb SmirnoffThe 22903b3a8eb9SGleb Smirnoff.Ar dup-to 22913b3a8eb9SGleb Smirnoffoption creates a duplicate of the packet and routes it like 22923b3a8eb9SGleb Smirnoff.Ar route-to . 22933b3a8eb9SGleb SmirnoffThe original packet gets routed as it normally would. 22943b3a8eb9SGleb Smirnoff.El 22953b3a8eb9SGleb Smirnoff.Sh POOL OPTIONS 22963b3a8eb9SGleb SmirnoffFor 22973b3a8eb9SGleb Smirnoff.Ar nat 22983b3a8eb9SGleb Smirnoffand 22993b3a8eb9SGleb Smirnoff.Ar rdr 23003b3a8eb9SGleb Smirnoffrules, (as well as for the 23013b3a8eb9SGleb Smirnoff.Ar route-to , 23023b3a8eb9SGleb Smirnoff.Ar reply-to 23033b3a8eb9SGleb Smirnoffand 23043b3a8eb9SGleb Smirnoff.Ar dup-to 23053b3a8eb9SGleb Smirnoffrule options) for which there is a single redirection address which has a 23063b3a8eb9SGleb Smirnoffsubnet mask smaller than 32 for IPv4 or 128 for IPv6 (more than one IP 23073b3a8eb9SGleb Smirnoffaddress), a variety of different methods for assigning this address can be 23083b3a8eb9SGleb Smirnoffused: 23093b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx 23103b3a8eb9SGleb Smirnoff.It Ar bitmask 23113b3a8eb9SGleb SmirnoffThe 23123b3a8eb9SGleb Smirnoff.Ar bitmask 23133b3a8eb9SGleb Smirnoffoption applies the network portion of the redirection address to the address 23143b3a8eb9SGleb Smirnoffto be modified (source with 23153b3a8eb9SGleb Smirnoff.Ar nat , 23163b3a8eb9SGleb Smirnoffdestination with 23173b3a8eb9SGleb Smirnoff.Ar rdr ) . 23183b3a8eb9SGleb Smirnoff.It Ar random 23193b3a8eb9SGleb SmirnoffThe 23203b3a8eb9SGleb Smirnoff.Ar random 23213b3a8eb9SGleb Smirnoffoption selects an address at random within the defined block of addresses. 23223b3a8eb9SGleb Smirnoff.It Ar source-hash 23233b3a8eb9SGleb SmirnoffThe 23243b3a8eb9SGleb Smirnoff.Ar source-hash 23253b3a8eb9SGleb Smirnoffoption uses a hash of the source address to determine the redirection address, 23263b3a8eb9SGleb Smirnoffensuring that the redirection address is always the same for a given source. 23273b3a8eb9SGleb SmirnoffAn optional key can be specified after this keyword either in hex or as a 23283b3a8eb9SGleb Smirnoffstring; by default 23293b3a8eb9SGleb Smirnoff.Xr pfctl 8 23303b3a8eb9SGleb Smirnoffrandomly generates a key for source-hash every time the 23313b3a8eb9SGleb Smirnoffruleset is reloaded. 23323b3a8eb9SGleb Smirnoff.It Ar round-robin 23333b3a8eb9SGleb SmirnoffThe 23343b3a8eb9SGleb Smirnoff.Ar round-robin 23353b3a8eb9SGleb Smirnoffoption loops through the redirection address(es). 23363b3a8eb9SGleb Smirnoff.Pp 23373b3a8eb9SGleb SmirnoffWhen more than one redirection address is specified, 23383b3a8eb9SGleb Smirnoff.Ar round-robin 23393b3a8eb9SGleb Smirnoffis the only permitted pool type. 23403b3a8eb9SGleb Smirnoff.It Ar static-port 23413b3a8eb9SGleb SmirnoffWith 23423b3a8eb9SGleb Smirnoff.Ar nat 23433b3a8eb9SGleb Smirnoffrules, the 23443b3a8eb9SGleb Smirnoff.Ar static-port 23453b3a8eb9SGleb Smirnoffoption prevents 23463b3a8eb9SGleb Smirnoff.Xr pf 4 23473b3a8eb9SGleb Smirnofffrom modifying the source port on TCP and UDP packets. 23482aa21096SKurosawa Takahiro.It Xo Ar map-e-portset Aq Ar psid-offset 23492aa21096SKurosawa Takahiro.No / Aq Ar psid-len 23502aa21096SKurosawa Takahiro.No / Aq Ar psid 23512aa21096SKurosawa Takahiro.Xc 23522aa21096SKurosawa TakahiroWith 23532aa21096SKurosawa Takahiro.Ar nat 23542aa21096SKurosawa Takahirorules, the 23552aa21096SKurosawa Takahiro.Ar map-e-portset 23562aa21096SKurosawa Takahirooption enables the source port translation of MAP-E (RFC 7597) Customer Edge. 23572aa21096SKurosawa TakahiroIn order to make the host act as a MAP-E Customer Edge, setting up a tunneling 23582aa21096SKurosawa Takahirointerface and pass rules for encapsulated packets are required in addition 23592aa21096SKurosawa Takahiroto the map-e-portset nat rule. 23602aa21096SKurosawa Takahiro.Pp 23612aa21096SKurosawa TakahiroFor example: 23622aa21096SKurosawa Takahiro.Bd -literal -offset indent 23632aa21096SKurosawa Takahironat on $gif_mape_if from $int_if:network to any \e 23642aa21096SKurosawa Takahiro -> $ipv4_mape_src map-e-portset 6/8/0x34 23652aa21096SKurosawa Takahiro.Ed 23662aa21096SKurosawa Takahiro.Pp 23672aa21096SKurosawa Takahirosets PSID offset 6, PSID length 8, PSID 0x34. 2368725003daSEd Maste.It Ar endpoint-independent 2369725003daSEd MasteWith 2370725003daSEd Maste.Ar nat 2371725003daSEd Masterules, the 2372725003daSEd Maste.Ar endpoint-independent 2373725003daSEd Masteoption caues 2374725003daSEd Maste.Xr pf 4 2375725003daSEd Masteto always map connections from a UDP source address and port to the same 2376725003daSEd MasteNAT address and port. 2377725003daSEd MasteThis feature implements "full-cone" NAT behavior. 23783b3a8eb9SGleb Smirnoff.El 23793b3a8eb9SGleb Smirnoff.Pp 23803b3a8eb9SGleb SmirnoffAdditionally, the 23813b3a8eb9SGleb Smirnoff.Ar sticky-address 23823b3a8eb9SGleb Smirnoffoption can be specified to help ensure that multiple connections from the 23833b3a8eb9SGleb Smirnoffsame source are mapped to the same redirection address. 23843b3a8eb9SGleb SmirnoffThis option can be used with the 23853b3a8eb9SGleb Smirnoff.Ar random 23863b3a8eb9SGleb Smirnoffand 23873b3a8eb9SGleb Smirnoff.Ar round-robin 23883b3a8eb9SGleb Smirnoffpool options. 23893b3a8eb9SGleb SmirnoffNote that by default these associations are destroyed as soon as there are 23903b3a8eb9SGleb Smirnoffno longer states which refer to them; in order to make the mappings last 23913b3a8eb9SGleb Smirnoffbeyond the lifetime of the states, increase the global options with 23923b3a8eb9SGleb Smirnoff.Ar set timeout src.track . 23933b3a8eb9SGleb SmirnoffSee 23943b3a8eb9SGleb Smirnoff.Sx STATEFUL TRACKING OPTIONS 23953b3a8eb9SGleb Smirnofffor more ways to control the source tracking. 23963b3a8eb9SGleb Smirnoff.Sh STATE MODULATION 23973b3a8eb9SGleb SmirnoffMuch of the security derived from TCP is attributable to how well the 23983b3a8eb9SGleb Smirnoffinitial sequence numbers (ISNs) are chosen. 23993b3a8eb9SGleb SmirnoffSome popular stack implementations choose 24003b3a8eb9SGleb Smirnoff.Em very 24013b3a8eb9SGleb Smirnoffpoor ISNs and thus are normally susceptible to ISN prediction exploits. 24023b3a8eb9SGleb SmirnoffBy applying a 24033b3a8eb9SGleb Smirnoff.Ar modulate state 24043b3a8eb9SGleb Smirnoffrule to a TCP connection, 24053b3a8eb9SGleb Smirnoff.Xr pf 4 24063b3a8eb9SGleb Smirnoffwill create a high quality random sequence number for each connection 24073b3a8eb9SGleb Smirnoffendpoint. 24083b3a8eb9SGleb Smirnoff.Pp 24093b3a8eb9SGleb SmirnoffThe 24103b3a8eb9SGleb Smirnoff.Ar modulate state 24113b3a8eb9SGleb Smirnoffdirective implicitly keeps state on the rule and is 24123b3a8eb9SGleb Smirnoffonly applicable to TCP connections. 24133b3a8eb9SGleb Smirnoff.Pp 24143b3a8eb9SGleb SmirnoffFor instance: 24153b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 24163b3a8eb9SGleb Smirnoffblock all 24173b3a8eb9SGleb Smirnoffpass out proto tcp from any to any modulate state 24183b3a8eb9SGleb Smirnoffpass in proto tcp from any to any port 25 flags S/SFRA modulate state 24193b3a8eb9SGleb Smirnoff.Ed 24203b3a8eb9SGleb Smirnoff.Pp 24213b3a8eb9SGleb SmirnoffNote that modulated connections will not recover when the state table 24223b3a8eb9SGleb Smirnoffis lost (firewall reboot, flushing the state table, etc...). 24233b3a8eb9SGleb Smirnoff.Xr pf 4 24243b3a8eb9SGleb Smirnoffwill not be able to infer a connection again after the state table flushes 24253b3a8eb9SGleb Smirnoffthe connection's modulator. 24263b3a8eb9SGleb SmirnoffWhen the state is lost, the connection may be left dangling until the 24273b3a8eb9SGleb Smirnoffrespective endpoints time out the connection. 24283b3a8eb9SGleb SmirnoffIt is possible on a fast local network for the endpoints to start an ACK 24293b3a8eb9SGleb Smirnoffstorm while trying to resynchronize after the loss of the modulator. 24303b3a8eb9SGleb SmirnoffThe default 24313b3a8eb9SGleb Smirnoff.Ar flags 24323b3a8eb9SGleb Smirnoffsettings (or a more strict equivalent) should be used on 24333b3a8eb9SGleb Smirnoff.Ar modulate state 24343b3a8eb9SGleb Smirnoffrules to prevent ACK storms. 24353b3a8eb9SGleb Smirnoff.Pp 24363b3a8eb9SGleb SmirnoffNote that alternative methods are available 24373b3a8eb9SGleb Smirnoffto prevent loss of the state table 24383b3a8eb9SGleb Smirnoffand allow for firewall failover. 24393b3a8eb9SGleb SmirnoffSee 24403b3a8eb9SGleb Smirnoff.Xr carp 4 24413b3a8eb9SGleb Smirnoffand 24423b3a8eb9SGleb Smirnoff.Xr pfsync 4 24433b3a8eb9SGleb Smirnofffor further information. 24443b3a8eb9SGleb Smirnoff.Sh SYN PROXY 24453b3a8eb9SGleb SmirnoffBy default, 24463b3a8eb9SGleb Smirnoff.Xr pf 4 24473b3a8eb9SGleb Smirnoffpasses packets that are part of a 24483b3a8eb9SGleb Smirnoff.Xr tcp 4 24493b3a8eb9SGleb Smirnoffhandshake between the endpoints. 24503b3a8eb9SGleb SmirnoffThe 24513b3a8eb9SGleb Smirnoff.Ar synproxy state 24523b3a8eb9SGleb Smirnoffoption can be used to cause 24533b3a8eb9SGleb Smirnoff.Xr pf 4 24543b3a8eb9SGleb Smirnoffitself to complete the handshake with the active endpoint, perform a handshake 24553b3a8eb9SGleb Smirnoffwith the passive endpoint, and then forward packets between the endpoints. 24563b3a8eb9SGleb Smirnoff.Pp 24573b3a8eb9SGleb SmirnoffNo packets are sent to the passive endpoint before the active endpoint has 24583b3a8eb9SGleb Smirnoffcompleted the handshake, hence so-called SYN floods with spoofed source 24593b3a8eb9SGleb Smirnoffaddresses will not reach the passive endpoint, as the sender can't complete the 24603b3a8eb9SGleb Smirnoffhandshake. 24613b3a8eb9SGleb Smirnoff.Pp 24623b3a8eb9SGleb SmirnoffThe proxy is transparent to both endpoints, they each see a single 24633b3a8eb9SGleb Smirnoffconnection from/to the other endpoint. 24643b3a8eb9SGleb Smirnoff.Xr pf 4 24653b3a8eb9SGleb Smirnoffchooses random initial sequence numbers for both handshakes. 24663b3a8eb9SGleb SmirnoffOnce the handshakes are completed, the sequence number modulators 24673b3a8eb9SGleb Smirnoff(see previous section) are used to translate further packets of the 24683b3a8eb9SGleb Smirnoffconnection. 24693b3a8eb9SGleb Smirnoff.Ar synproxy state 24703b3a8eb9SGleb Smirnoffincludes 24713b3a8eb9SGleb Smirnoff.Ar modulate state . 24723b3a8eb9SGleb Smirnoff.Pp 24733b3a8eb9SGleb SmirnoffRules with 24743b3a8eb9SGleb Smirnoff.Ar synproxy 24753b3a8eb9SGleb Smirnoffwill not work if 24763b3a8eb9SGleb Smirnoff.Xr pf 4 24773b3a8eb9SGleb Smirnoffoperates on a 24783b3a8eb9SGleb Smirnoff.Xr bridge 4 . 24793b3a8eb9SGleb Smirnoff.Pp 24803b3a8eb9SGleb SmirnoffExample: 24813b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 24823b3a8eb9SGleb Smirnoffpass in proto tcp from any to any port www synproxy state 24833b3a8eb9SGleb Smirnoff.Ed 24843b3a8eb9SGleb Smirnoff.Sh STATEFUL TRACKING OPTIONS 24853b3a8eb9SGleb SmirnoffA number of options related to stateful tracking can be applied on a 24863b3a8eb9SGleb Smirnoffper-rule basis. 24873b3a8eb9SGleb Smirnoff.Ar keep state , 24883b3a8eb9SGleb Smirnoff.Ar modulate state 24893b3a8eb9SGleb Smirnoffand 24903b3a8eb9SGleb Smirnoff.Ar synproxy state 24913b3a8eb9SGleb Smirnoffsupport these options, and 24923b3a8eb9SGleb Smirnoff.Ar keep state 24933b3a8eb9SGleb Smirnoffmust be specified explicitly to apply options to a rule. 24943b3a8eb9SGleb Smirnoff.Pp 24953b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx -compact 24963b3a8eb9SGleb Smirnoff.It Ar max Aq Ar number 24973b3a8eb9SGleb SmirnoffLimits the number of concurrent states the rule may create. 24983b3a8eb9SGleb SmirnoffWhen this limit is reached, further packets that would create 2499d01949e8SKristof Provoststate are dropped until existing states time out. 25003b3a8eb9SGleb Smirnoff.It Ar no-sync 25013b3a8eb9SGleb SmirnoffPrevent state changes for states created by this rule from appearing on the 25023b3a8eb9SGleb Smirnoff.Xr pfsync 4 25033b3a8eb9SGleb Smirnoffinterface. 25043b3a8eb9SGleb Smirnoff.It Xo Aq Ar timeout 25053b3a8eb9SGleb Smirnoff.Aq Ar seconds 25063b3a8eb9SGleb Smirnoff.Xc 25073b3a8eb9SGleb SmirnoffChanges the timeout values used for states created by this rule. 25083b3a8eb9SGleb SmirnoffFor a list of all valid timeout names, see 25093b3a8eb9SGleb Smirnoff.Sx OPTIONS 25103b3a8eb9SGleb Smirnoffabove. 25113b3a8eb9SGleb Smirnoff.It Ar sloppy 25123b3a8eb9SGleb SmirnoffUses a sloppy TCP connection tracker that does not check sequence 25133b3a8eb9SGleb Smirnoffnumbers at all, which makes insertion and ICMP teardown attacks way 25143b3a8eb9SGleb Smirnoffeasier. 25153b3a8eb9SGleb SmirnoffThis is intended to be used in situations where one does not see all 25163b3a8eb9SGleb Smirnoffpackets of a connection, e.g. in asymmetric routing situations. 25173b3a8eb9SGleb SmirnoffCannot be used with modulate or synproxy state. 2518baf9b6d0SKristof Provost.It Ar pflow 2519baf9b6d0SKristof ProvostStates created by this rule are exported on the 2520baf9b6d0SKristof Provost.Xr pflow 4 2521baf9b6d0SKristof Provostinterface. 2522e4f2733dSKristof Provost.It Ar allow-related 2523e4f2733dSKristof ProvostAutomatically allow connections related to this one, regardless of rules that 2524e4f2733dSKristof Provostmight otherwise affect them. 2525e4f2733dSKristof ProvostThis currently only applies to SCTP multihomed connection. 25263b3a8eb9SGleb Smirnoff.El 25273b3a8eb9SGleb Smirnoff.Pp 25283b3a8eb9SGleb SmirnoffMultiple options can be specified, separated by commas: 25293b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 25303b3a8eb9SGleb Smirnoffpass in proto tcp from any to any \e 25313b3a8eb9SGleb Smirnoff port www keep state \e 25323b3a8eb9SGleb Smirnoff (max 100, source-track rule, max-src-nodes 75, \e 25333b3a8eb9SGleb Smirnoff max-src-states 3, tcp.established 60, tcp.closing 5) 25343b3a8eb9SGleb Smirnoff.Ed 25353b3a8eb9SGleb Smirnoff.Pp 25363b3a8eb9SGleb SmirnoffWhen the 25373b3a8eb9SGleb Smirnoff.Ar source-track 25383b3a8eb9SGleb Smirnoffkeyword is specified, the number of states per source IP is tracked. 25393b3a8eb9SGleb Smirnoff.Pp 25403b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx -compact 25413b3a8eb9SGleb Smirnoff.It Ar source-track rule 25423b3a8eb9SGleb SmirnoffThe maximum number of states created by this rule is limited by the rule's 25433b3a8eb9SGleb Smirnoff.Ar max-src-nodes 25443b3a8eb9SGleb Smirnoffand 25453b3a8eb9SGleb Smirnoff.Ar max-src-states 25463b3a8eb9SGleb Smirnoffoptions. 25473b3a8eb9SGleb SmirnoffOnly state entries created by this particular rule count toward the rule's 25483b3a8eb9SGleb Smirnofflimits. 25493b3a8eb9SGleb Smirnoff.It Ar source-track global 25503b3a8eb9SGleb SmirnoffThe number of states created by all rules that use this option is limited. 25513b3a8eb9SGleb SmirnoffEach rule can specify different 25523b3a8eb9SGleb Smirnoff.Ar max-src-nodes 25533b3a8eb9SGleb Smirnoffand 25543b3a8eb9SGleb Smirnoff.Ar max-src-states 25553b3a8eb9SGleb Smirnoffoptions, however state entries created by any participating rule count towards 25563b3a8eb9SGleb Smirnoffeach individual rule's limits. 25573b3a8eb9SGleb Smirnoff.El 25583b3a8eb9SGleb Smirnoff.Pp 25593b3a8eb9SGleb SmirnoffThe following limits can be set: 25603b3a8eb9SGleb Smirnoff.Pp 25613b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx -compact 25623b3a8eb9SGleb Smirnoff.It Ar max-src-nodes Aq Ar number 25633b3a8eb9SGleb SmirnoffLimits the maximum number of source addresses which can simultaneously 25643b3a8eb9SGleb Smirnoffhave state table entries. 25653b3a8eb9SGleb Smirnoff.It Ar max-src-states Aq Ar number 25663b3a8eb9SGleb SmirnoffLimits the maximum number of simultaneous state entries that a single 25673b3a8eb9SGleb Smirnoffsource address can create with this rule. 25683b3a8eb9SGleb Smirnoff.El 25693b3a8eb9SGleb Smirnoff.Pp 25703b3a8eb9SGleb SmirnoffFor stateful TCP connections, limits on established connections (connections 25713b3a8eb9SGleb Smirnoffwhich have completed the TCP 3-way handshake) can also be enforced 25723b3a8eb9SGleb Smirnoffper source IP. 25733b3a8eb9SGleb Smirnoff.Pp 25743b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx -compact 25753b3a8eb9SGleb Smirnoff.It Ar max-src-conn Aq Ar number 25763b3a8eb9SGleb SmirnoffLimits the maximum number of simultaneous TCP connections which have 25773b3a8eb9SGleb Smirnoffcompleted the 3-way handshake that a single host can make. 25783b3a8eb9SGleb Smirnoff.It Xo Ar max-src-conn-rate Aq Ar number 25793b3a8eb9SGleb Smirnoff.No / Aq Ar seconds 25803b3a8eb9SGleb Smirnoff.Xc 25813b3a8eb9SGleb SmirnoffLimit the rate of new connections over a time interval. 25823b3a8eb9SGleb SmirnoffThe connection rate is an approximation calculated as a moving average. 25833b3a8eb9SGleb Smirnoff.El 25843b3a8eb9SGleb Smirnoff.Pp 2585d01949e8SKristof ProvostWhen one of these limits is reached, further packets that would create 2586d01949e8SKristof Provoststate are dropped until existing states time out. 2587d01949e8SKristof Provost.Pp 25883b3a8eb9SGleb SmirnoffBecause the 3-way handshake ensures that the source address is not being 25893b3a8eb9SGleb Smirnoffspoofed, more aggressive action can be taken based on these limits. 25903b3a8eb9SGleb SmirnoffWith the 25913b3a8eb9SGleb Smirnoff.Ar overload Aq Ar table 25923b3a8eb9SGleb Smirnoffstate option, source IP addresses which hit either of the limits on 25933b3a8eb9SGleb Smirnoffestablished connections will be added to the named table. 25943b3a8eb9SGleb SmirnoffThis table can be used in the ruleset to block further activity from 25953b3a8eb9SGleb Smirnoffthe offending host, redirect it to a tarpit process, or restrict its 25963b3a8eb9SGleb Smirnoffbandwidth. 25973b3a8eb9SGleb Smirnoff.Pp 25983b3a8eb9SGleb SmirnoffThe optional 25993b3a8eb9SGleb Smirnoff.Ar flush 26003b3a8eb9SGleb Smirnoffkeyword kills all states created by the matching rule which originate 26013b3a8eb9SGleb Smirnofffrom the host which exceeds these limits. 26023b3a8eb9SGleb SmirnoffThe 26033b3a8eb9SGleb Smirnoff.Ar global 26043b3a8eb9SGleb Smirnoffmodifier to the flush command kills all states originating from the 26053b3a8eb9SGleb Smirnoffoffending host, regardless of which rule created the state. 26063b3a8eb9SGleb Smirnoff.Pp 26073b3a8eb9SGleb SmirnoffFor example, the following rules will protect the webserver against 26083b3a8eb9SGleb Smirnoffhosts making more than 100 connections in 10 seconds. 26093b3a8eb9SGleb SmirnoffAny host which connects faster than this rate will have its address added 26103b3a8eb9SGleb Smirnoffto the 26113b3a8eb9SGleb Smirnoff.Aq bad_hosts 26123b3a8eb9SGleb Smirnofftable and have all states originating from it flushed. 26133b3a8eb9SGleb SmirnoffAny new packets arriving from this host will be dropped unconditionally 26143b3a8eb9SGleb Smirnoffby the block rule. 26153b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 26163b3a8eb9SGleb Smirnoffblock quick from \*(Ltbad_hosts\*(Gt 26173b3a8eb9SGleb Smirnoffpass in on $ext_if proto tcp to $webserver port www keep state \e 26183b3a8eb9SGleb Smirnoff (max-src-conn-rate 100/10, overload \*(Ltbad_hosts\*(Gt flush global) 26193b3a8eb9SGleb Smirnoff.Ed 26203b3a8eb9SGleb Smirnoff.Sh OPERATING SYSTEM FINGERPRINTING 26213b3a8eb9SGleb SmirnoffPassive OS Fingerprinting is a mechanism to inspect nuances of a TCP 26223b3a8eb9SGleb Smirnoffconnection's initial SYN packet and guess at the host's operating system. 26233b3a8eb9SGleb SmirnoffUnfortunately these nuances are easily spoofed by an attacker so the 26243b3a8eb9SGleb Smirnofffingerprint is not useful in making security decisions. 26253b3a8eb9SGleb SmirnoffBut the fingerprint is typically accurate enough to make policy decisions 26263b3a8eb9SGleb Smirnoffupon. 26273b3a8eb9SGleb Smirnoff.Pp 26283b3a8eb9SGleb SmirnoffThe fingerprints may be specified by operating system class, by 26293b3a8eb9SGleb Smirnoffversion, or by subtype/patchlevel. 26303b3a8eb9SGleb SmirnoffThe class of an operating system is typically the vendor or genre 26313b3a8eb9SGleb Smirnoffand would be 26323b3a8eb9SGleb Smirnoff.Ox 26333b3a8eb9SGleb Smirnofffor the 26343b3a8eb9SGleb Smirnoff.Xr pf 4 26353b3a8eb9SGleb Smirnofffirewall itself. 26363b3a8eb9SGleb SmirnoffThe version of the oldest available 26373b3a8eb9SGleb Smirnoff.Ox 26383b3a8eb9SGleb Smirnoffrelease on the main FTP site 26393b3a8eb9SGleb Smirnoffwould be 2.6 and the fingerprint would be written 26403b3a8eb9SGleb Smirnoff.Pp 26413b3a8eb9SGleb Smirnoff.Dl \&"OpenBSD 2.6\&" 26423b3a8eb9SGleb Smirnoff.Pp 26433b3a8eb9SGleb SmirnoffThe subtype of an operating system is typically used to describe the 26443b3a8eb9SGleb Smirnoffpatchlevel if that patch led to changes in the TCP stack behavior. 26453b3a8eb9SGleb SmirnoffIn the case of 26463b3a8eb9SGleb Smirnoff.Ox , 26473b3a8eb9SGleb Smirnoffthe only subtype is for a fingerprint that was 26483b3a8eb9SGleb Smirnoffnormalized by the 26493b3a8eb9SGleb Smirnoff.Ar no-df 26503b3a8eb9SGleb Smirnoffscrub option and would be specified as 26513b3a8eb9SGleb Smirnoff.Pp 26523b3a8eb9SGleb Smirnoff.Dl \&"OpenBSD 3.3 no-df\&" 26533b3a8eb9SGleb Smirnoff.Pp 26543b3a8eb9SGleb SmirnoffFingerprints for most popular operating systems are provided by 26553b3a8eb9SGleb Smirnoff.Xr pf.os 5 . 26563b3a8eb9SGleb SmirnoffOnce 26573b3a8eb9SGleb Smirnoff.Xr pf 4 26583b3a8eb9SGleb Smirnoffis running, a complete list of known operating system fingerprints may 26593b3a8eb9SGleb Smirnoffbe listed by running: 26603b3a8eb9SGleb Smirnoff.Pp 26613b3a8eb9SGleb Smirnoff.Dl # pfctl -so 26623b3a8eb9SGleb Smirnoff.Pp 26633b3a8eb9SGleb SmirnoffFilter rules can enforce policy at any level of operating system specification 26643b3a8eb9SGleb Smirnoffassuming a fingerprint is present. 26653b3a8eb9SGleb SmirnoffPolicy could limit traffic to approved operating systems or even ban traffic 26663b3a8eb9SGleb Smirnofffrom hosts that aren't at the latest service pack. 26673b3a8eb9SGleb Smirnoff.Pp 26683b3a8eb9SGleb SmirnoffThe 26693b3a8eb9SGleb Smirnoff.Ar unknown 26703b3a8eb9SGleb Smirnoffclass can also be used as the fingerprint which will match packets for 26713b3a8eb9SGleb Smirnoffwhich no operating system fingerprint is known. 26723b3a8eb9SGleb Smirnoff.Pp 26733b3a8eb9SGleb SmirnoffExamples: 26743b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 26753b3a8eb9SGleb Smirnoffpass out proto tcp from any os OpenBSD 26763b3a8eb9SGleb Smirnoffblock out proto tcp from any os Doors 26773b3a8eb9SGleb Smirnoffblock out proto tcp from any os "Doors PT" 26783b3a8eb9SGleb Smirnoffblock out proto tcp from any os "Doors PT SP3" 26793b3a8eb9SGleb Smirnoffblock out from any os "unknown" 26803b3a8eb9SGleb Smirnoffpass on lo0 proto tcp from any os "OpenBSD 3.3 lo0" 26813b3a8eb9SGleb Smirnoff.Ed 26823b3a8eb9SGleb Smirnoff.Pp 26833b3a8eb9SGleb SmirnoffOperating system fingerprinting is limited only to the TCP SYN packet. 26843b3a8eb9SGleb SmirnoffThis means that it will not work on other protocols and will not match 26853b3a8eb9SGleb Smirnoffa currently established connection. 26863b3a8eb9SGleb Smirnoff.Pp 26873b3a8eb9SGleb SmirnoffCaveat: operating system fingerprints are occasionally wrong. 26883b3a8eb9SGleb SmirnoffThere are three problems: an attacker can trivially craft his packets to 26893b3a8eb9SGleb Smirnoffappear as any operating system he chooses; 26903b3a8eb9SGleb Smirnoffan operating system patch could change the stack behavior and no fingerprints 26913b3a8eb9SGleb Smirnoffwill match it until the database is updated; 26923b3a8eb9SGleb Smirnoffand multiple operating systems may have the same fingerprint. 26933b3a8eb9SGleb Smirnoff.Sh BLOCKING SPOOFED TRAFFIC 26943b3a8eb9SGleb Smirnoff"Spoofing" is the faking of IP addresses, typically for malicious 26953b3a8eb9SGleb Smirnoffpurposes. 26963b3a8eb9SGleb SmirnoffThe 26973b3a8eb9SGleb Smirnoff.Ar antispoof 26983b3a8eb9SGleb Smirnoffdirective expands to a set of filter rules which will block all 26993b3a8eb9SGleb Smirnofftraffic with a source IP from the network(s) directly connected 27003b3a8eb9SGleb Smirnoffto the specified interface(s) from entering the system through 27013b3a8eb9SGleb Smirnoffany other interface. 27023b3a8eb9SGleb Smirnoff.Pp 27033b3a8eb9SGleb SmirnoffFor example, the line 27043b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 27053b3a8eb9SGleb Smirnoffantispoof for lo0 27063b3a8eb9SGleb Smirnoff.Ed 27073b3a8eb9SGleb Smirnoff.Pp 27083b3a8eb9SGleb Smirnoffexpands to 27093b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 27103b3a8eb9SGleb Smirnoffblock drop in on ! lo0 inet from 127.0.0.1/8 to any 27113b3a8eb9SGleb Smirnoffblock drop in on ! lo0 inet6 from ::1 to any 27123b3a8eb9SGleb Smirnoff.Ed 27133b3a8eb9SGleb Smirnoff.Pp 27143b3a8eb9SGleb SmirnoffFor non-loopback interfaces, there are additional rules to block incoming 27153b3a8eb9SGleb Smirnoffpackets with a source IP address identical to the interface's IP(s). 27163b3a8eb9SGleb SmirnoffFor example, assuming the interface wi0 had an IP address of 10.0.0.1 and a 27173b3a8eb9SGleb Smirnoffnetmask of 255.255.255.0, 27183b3a8eb9SGleb Smirnoffthe line 27193b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 27203b3a8eb9SGleb Smirnoffantispoof for wi0 inet 27213b3a8eb9SGleb Smirnoff.Ed 27223b3a8eb9SGleb Smirnoff.Pp 27233b3a8eb9SGleb Smirnoffexpands to 27243b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 27253b3a8eb9SGleb Smirnoffblock drop in on ! wi0 inet from 10.0.0.0/24 to any 27263b3a8eb9SGleb Smirnoffblock drop in inet from 10.0.0.1 to any 27273b3a8eb9SGleb Smirnoff.Ed 27283b3a8eb9SGleb Smirnoff.Pp 27293b3a8eb9SGleb SmirnoffCaveat: Rules created by the 27303b3a8eb9SGleb Smirnoff.Ar antispoof 27313b3a8eb9SGleb Smirnoffdirective interfere with packets sent over loopback interfaces 27323b3a8eb9SGleb Smirnoffto local addresses. 27333b3a8eb9SGleb SmirnoffOne should pass these explicitly. 27343b3a8eb9SGleb Smirnoff.Sh FRAGMENT HANDLING 27353b3a8eb9SGleb SmirnoffThe size of IP datagrams (packets) can be significantly larger than the 27363b3a8eb9SGleb Smirnoffmaximum transmission unit (MTU) of the network. 27373b3a8eb9SGleb SmirnoffIn cases when it is necessary or more efficient to send such large packets, 27383b3a8eb9SGleb Smirnoffthe large packet will be fragmented into many smaller packets that will each 27393b3a8eb9SGleb Smirnofffit onto the wire. 27403b3a8eb9SGleb SmirnoffUnfortunately for a firewalling device, only the first logical fragment will 27413b3a8eb9SGleb Smirnoffcontain the necessary header information for the subprotocol that allows 27423b3a8eb9SGleb Smirnoff.Xr pf 4 27433b3a8eb9SGleb Smirnoffto filter on things such as TCP ports or to perform NAT. 27443b3a8eb9SGleb Smirnoff.Pp 27453b3a8eb9SGleb SmirnoffBesides the use of 27465ed470bdSKajetan Staszkiewicz.Ar set reassemble 27475ed470bdSKajetan Staszkiewiczoption or 27483b3a8eb9SGleb Smirnoff.Ar scrub 27493b3a8eb9SGleb Smirnoffrules as described in 27503b3a8eb9SGleb Smirnoff.Sx TRAFFIC NORMALIZATION 27513b3a8eb9SGleb Smirnoffabove, there are three options for handling fragments in the packet filter. 27523b3a8eb9SGleb Smirnoff.Pp 27533b3a8eb9SGleb SmirnoffOne alternative is to filter individual fragments with filter rules. 27543b3a8eb9SGleb SmirnoffIf no 27553b3a8eb9SGleb Smirnoff.Ar scrub 27565ed470bdSKajetan Staszkiewiczrule applies to a fragment or 27575ed470bdSKajetan Staszkiewicz.Ar set reassemble 27585ed470bdSKajetan Staszkiewiczis set to 27595ed470bdSKajetan Staszkiewicz.Cm no 27605ed470bdSKajetan Staszkiewicz, it is passed to the filter. 27613b3a8eb9SGleb SmirnoffFilter rules with matching IP header parameters decide whether the 27623b3a8eb9SGleb Smirnofffragment is passed or blocked, in the same way as complete packets 27633b3a8eb9SGleb Smirnoffare filtered. 27643b3a8eb9SGleb SmirnoffWithout reassembly, fragments can only be filtered based on IP header 27653b3a8eb9SGleb Smirnofffields (source/destination address, protocol), since subprotocol header 27663b3a8eb9SGleb Smirnofffields are not available (TCP/UDP port numbers, ICMP code/type). 27673b3a8eb9SGleb SmirnoffThe 27683b3a8eb9SGleb Smirnoff.Ar fragment 27693b3a8eb9SGleb Smirnoffoption can be used to restrict filter rules to apply only to 27703b3a8eb9SGleb Smirnofffragments, but not complete packets. 27713b3a8eb9SGleb SmirnoffFilter rules without the 27723b3a8eb9SGleb Smirnoff.Ar fragment 27733b3a8eb9SGleb Smirnoffoption still apply to fragments, if they only specify IP header fields. 27743b3a8eb9SGleb SmirnoffFor instance, the rule 27753b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 27763b3a8eb9SGleb Smirnoffpass in proto tcp from any to any port 80 27773b3a8eb9SGleb Smirnoff.Ed 27783b3a8eb9SGleb Smirnoff.Pp 27793b3a8eb9SGleb Smirnoffnever applies to a fragment, even if the fragment is part of a TCP 27803b3a8eb9SGleb Smirnoffpacket with destination port 80, because without reassembly this information 27813b3a8eb9SGleb Smirnoffis not available for each fragment. 27823b3a8eb9SGleb SmirnoffThis also means that fragments cannot create new or match existing 27833b3a8eb9SGleb Smirnoffstate table entries, which makes stateful filtering and address 27843b3a8eb9SGleb Smirnofftranslation (NAT, redirection) for fragments impossible. 27853b3a8eb9SGleb Smirnoff.Pp 27863b3a8eb9SGleb SmirnoffIt's also possible to reassemble only certain fragments by specifying 27873b3a8eb9SGleb Smirnoffsource or destination addresses or protocols as parameters in 27883b3a8eb9SGleb Smirnoff.Ar scrub 27893b3a8eb9SGleb Smirnoffrules. 27903b3a8eb9SGleb Smirnoff.Pp 27913b3a8eb9SGleb SmirnoffIn most cases, the benefits of reassembly outweigh the additional 27923b3a8eb9SGleb Smirnoffmemory cost, and it's recommended to use 27935ed470bdSKajetan Staszkiewicz.Ar set reassemble 27945ed470bdSKajetan Staszkiewiczoption or 27953b3a8eb9SGleb Smirnoff.Ar scrub 27965ed470bdSKajetan Staszkiewiczrules with the 27973b3a8eb9SGleb Smirnoff.Ar fragment reassemble 27985ed470bdSKajetan Staszkiewiczmodifier to reassemble 27995ed470bdSKajetan Staszkiewiczall fragments. 28003b3a8eb9SGleb Smirnoff.Pp 28013b3a8eb9SGleb SmirnoffThe memory allocated for fragment caching can be limited using 28023b3a8eb9SGleb Smirnoff.Xr pfctl 8 . 28033b3a8eb9SGleb SmirnoffOnce this limit is reached, fragments that would have to be cached 28043b3a8eb9SGleb Smirnoffare dropped until other entries time out. 28053b3a8eb9SGleb SmirnoffThe timeout value can also be adjusted. 28063b3a8eb9SGleb Smirnoff.Pp 2807e600320bSKristof ProvostWhen forwarding reassembled IPv6 packets, pf refragments them with 2808e600320bSKristof Provostthe original maximum fragment size. 2809e600320bSKristof ProvostThis allows the sender to determine the optimal fragment size by 2810e600320bSKristof Provostpath MTU discovery. 28113b3a8eb9SGleb Smirnoff.Sh ANCHORS 28123b3a8eb9SGleb SmirnoffBesides the main ruleset, 28133b3a8eb9SGleb Smirnoff.Xr pfctl 8 28143b3a8eb9SGleb Smirnoffcan load rulesets into 28153b3a8eb9SGleb Smirnoff.Ar anchor 28163b3a8eb9SGleb Smirnoffattachment points. 28173b3a8eb9SGleb SmirnoffAn 28183b3a8eb9SGleb Smirnoff.Ar anchor 28193b3a8eb9SGleb Smirnoffis a container that can hold rules, address tables, and other anchors. 28203b3a8eb9SGleb Smirnoff.Pp 28213b3a8eb9SGleb SmirnoffAn 28223b3a8eb9SGleb Smirnoff.Ar anchor 28233b3a8eb9SGleb Smirnoffhas a name which specifies the path where 28243b3a8eb9SGleb Smirnoff.Xr pfctl 8 28253b3a8eb9SGleb Smirnoffcan be used to access the anchor to perform operations on it, such as 28263b3a8eb9SGleb Smirnoffattaching child anchors to it or loading rules into it. 28273b3a8eb9SGleb SmirnoffAnchors may be nested, with components separated by 28283b3a8eb9SGleb Smirnoff.Sq / 28293b3a8eb9SGleb Smirnoffcharacters, similar to how file system hierarchies are laid out. 28303b3a8eb9SGleb SmirnoffThe main ruleset is actually the default anchor, so filter and 28313b3a8eb9SGleb Smirnofftranslation rules, for example, may also be contained in any anchor. 28323b3a8eb9SGleb Smirnoff.Pp 28333b3a8eb9SGleb SmirnoffAn anchor can reference another 28343b3a8eb9SGleb Smirnoff.Ar anchor 28353b3a8eb9SGleb Smirnoffattachment point 28363b3a8eb9SGleb Smirnoffusing the following kinds 28373b3a8eb9SGleb Smirnoffof rules: 28383b3a8eb9SGleb Smirnoff.Bl -tag -width xxxx 28393b3a8eb9SGleb Smirnoff.It Ar nat-anchor Aq Ar name 28403b3a8eb9SGleb SmirnoffEvaluates the 28413b3a8eb9SGleb Smirnoff.Ar nat 28423b3a8eb9SGleb Smirnoffrules in the specified 28433b3a8eb9SGleb Smirnoff.Ar anchor . 28443b3a8eb9SGleb Smirnoff.It Ar rdr-anchor Aq Ar name 28453b3a8eb9SGleb SmirnoffEvaluates the 28463b3a8eb9SGleb Smirnoff.Ar rdr 28473b3a8eb9SGleb Smirnoffrules in the specified 28483b3a8eb9SGleb Smirnoff.Ar anchor . 28493b3a8eb9SGleb Smirnoff.It Ar binat-anchor Aq Ar name 28503b3a8eb9SGleb SmirnoffEvaluates the 28513b3a8eb9SGleb Smirnoff.Ar binat 28523b3a8eb9SGleb Smirnoffrules in the specified 28533b3a8eb9SGleb Smirnoff.Ar anchor . 28543b3a8eb9SGleb Smirnoff.It Ar anchor Aq Ar name 28553b3a8eb9SGleb SmirnoffEvaluates the filter rules in the specified 28563b3a8eb9SGleb Smirnoff.Ar anchor . 28573b3a8eb9SGleb Smirnoff.It Xo Ar load anchor 28583b3a8eb9SGleb Smirnoff.Aq Ar name 28593b3a8eb9SGleb Smirnoff.Ar from Aq Ar file 28603b3a8eb9SGleb Smirnoff.Xc 28613b3a8eb9SGleb SmirnoffLoads the rules from the specified file into the 28623b3a8eb9SGleb Smirnoffanchor 28633b3a8eb9SGleb Smirnoff.Ar name . 28643b3a8eb9SGleb Smirnoff.El 28653b3a8eb9SGleb Smirnoff.Pp 28663b3a8eb9SGleb SmirnoffWhen evaluation of the main ruleset reaches an 28673b3a8eb9SGleb Smirnoff.Ar anchor 28683b3a8eb9SGleb Smirnoffrule, 28693b3a8eb9SGleb Smirnoff.Xr pf 4 28703b3a8eb9SGleb Smirnoffwill proceed to evaluate all rules specified in that anchor. 28713b3a8eb9SGleb Smirnoff.Pp 28723b3a8eb9SGleb SmirnoffMatching filter and translation rules marked with the 28733b3a8eb9SGleb Smirnoff.Ar quick 28743b3a8eb9SGleb Smirnoffoption are final and abort the evaluation of the rules in other 28753b3a8eb9SGleb Smirnoffanchors and the main ruleset. 28763b3a8eb9SGleb SmirnoffIf the 28773b3a8eb9SGleb Smirnoff.Ar anchor 28783b3a8eb9SGleb Smirnoffitself is marked with the 28793b3a8eb9SGleb Smirnoff.Ar quick 28803b3a8eb9SGleb Smirnoffoption, 28813b3a8eb9SGleb Smirnoffruleset evaluation will terminate when the anchor is exited if the packet is 28823b3a8eb9SGleb Smirnoffmatched by any rule within the anchor. 28833b3a8eb9SGleb Smirnoff.Pp 28843b3a8eb9SGleb Smirnoff.Ar anchor 28853b3a8eb9SGleb Smirnoffrules are evaluated relative to the anchor in which they are contained. 28863b3a8eb9SGleb SmirnoffFor example, all 28873b3a8eb9SGleb Smirnoff.Ar anchor 28883b3a8eb9SGleb Smirnoffrules specified in the main ruleset will reference anchor 28893b3a8eb9SGleb Smirnoffattachment points underneath the main ruleset, and 28903b3a8eb9SGleb Smirnoff.Ar anchor 28913b3a8eb9SGleb Smirnoffrules specified in a file loaded from a 28923b3a8eb9SGleb Smirnoff.Ar load anchor 28933b3a8eb9SGleb Smirnoffrule will be attached under that anchor point. 28943b3a8eb9SGleb Smirnoff.Pp 28953b3a8eb9SGleb SmirnoffRules may be contained in 28963b3a8eb9SGleb Smirnoff.Ar anchor 28973b3a8eb9SGleb Smirnoffattachment points which do not contain any rules when the main ruleset 28983b3a8eb9SGleb Smirnoffis loaded, and later such anchors can be manipulated through 28993b3a8eb9SGleb Smirnoff.Xr pfctl 8 29003b3a8eb9SGleb Smirnoffwithout reloading the main ruleset or other anchors. 29013b3a8eb9SGleb SmirnoffFor example, 29023b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 29033b3a8eb9SGleb Smirnoffext_if = \&"kue0\&" 29043b3a8eb9SGleb Smirnoffblock on $ext_if all 29053b3a8eb9SGleb Smirnoffanchor spam 29063b3a8eb9SGleb Smirnoffpass out on $ext_if all 29073b3a8eb9SGleb Smirnoffpass in on $ext_if proto tcp from any \e 29083b3a8eb9SGleb Smirnoff to $ext_if port smtp 29093b3a8eb9SGleb Smirnoff.Ed 29103b3a8eb9SGleb Smirnoff.Pp 29113b3a8eb9SGleb Smirnoffblocks all packets on the external interface by default, then evaluates 29123b3a8eb9SGleb Smirnoffall rules in the 29133b3a8eb9SGleb Smirnoff.Ar anchor 29143b3a8eb9SGleb Smirnoffnamed "spam", and finally passes all outgoing connections and 29153b3a8eb9SGleb Smirnoffincoming connections to port 25. 29163b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 29173b3a8eb9SGleb Smirnoff# echo \&"block in quick from 1.2.3.4 to any\&" \&| \e 29183b3a8eb9SGleb Smirnoff pfctl -a spam -f - 29193b3a8eb9SGleb Smirnoff.Ed 29203b3a8eb9SGleb Smirnoff.Pp 29213b3a8eb9SGleb SmirnoffThis loads a single rule into the 29223b3a8eb9SGleb Smirnoff.Ar anchor , 29233b3a8eb9SGleb Smirnoffwhich blocks all packets from a specific address. 29243b3a8eb9SGleb Smirnoff.Pp 29253b3a8eb9SGleb SmirnoffThe anchor can also be populated by adding a 29263b3a8eb9SGleb Smirnoff.Ar load anchor 29273b3a8eb9SGleb Smirnoffrule after the 29283b3a8eb9SGleb Smirnoff.Ar anchor 29293b3a8eb9SGleb Smirnoffrule: 29303b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 29313b3a8eb9SGleb Smirnoffanchor spam 29323b3a8eb9SGleb Smirnoffload anchor spam from "/etc/pf-spam.conf" 29333b3a8eb9SGleb Smirnoff.Ed 29343b3a8eb9SGleb Smirnoff.Pp 29353b3a8eb9SGleb SmirnoffWhen 29363b3a8eb9SGleb Smirnoff.Xr pfctl 8 29373b3a8eb9SGleb Smirnoffloads 29383b3a8eb9SGleb Smirnoff.Nm pf.conf , 29393b3a8eb9SGleb Smirnoffit will also load all the rules from the file 29403b3a8eb9SGleb Smirnoff.Pa /etc/pf-spam.conf 29413b3a8eb9SGleb Smirnoffinto the anchor. 29423b3a8eb9SGleb Smirnoff.Pp 29433b3a8eb9SGleb SmirnoffOptionally, 29443b3a8eb9SGleb Smirnoff.Ar anchor 29453b3a8eb9SGleb Smirnoffrules can specify packet filtering parameters using the same syntax as 29463b3a8eb9SGleb Smirnofffilter rules. 29473b3a8eb9SGleb SmirnoffWhen parameters are used, the 29483b3a8eb9SGleb Smirnoff.Ar anchor 29493b3a8eb9SGleb Smirnoffrule is only evaluated for matching packets. 29503b3a8eb9SGleb SmirnoffThis allows conditional evaluation of anchors, like: 29513b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 29523b3a8eb9SGleb Smirnoffblock on $ext_if all 29533b3a8eb9SGleb Smirnoffanchor spam proto tcp from any to any port smtp 29543b3a8eb9SGleb Smirnoffpass out on $ext_if all 29553b3a8eb9SGleb Smirnoffpass in on $ext_if proto tcp from any to $ext_if port smtp 29563b3a8eb9SGleb Smirnoff.Ed 29573b3a8eb9SGleb Smirnoff.Pp 29583b3a8eb9SGleb SmirnoffThe rules inside 29593b3a8eb9SGleb Smirnoff.Ar anchor 29603b3a8eb9SGleb Smirnoffspam are only evaluated for 29613b3a8eb9SGleb Smirnoff.Ar tcp 29623b3a8eb9SGleb Smirnoffpackets with destination port 25. 29633b3a8eb9SGleb SmirnoffHence, 29643b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 29653b3a8eb9SGleb Smirnoff# echo \&"block in quick from 1.2.3.4 to any" \&| \e 29663b3a8eb9SGleb Smirnoff pfctl -a spam -f - 29673b3a8eb9SGleb Smirnoff.Ed 29683b3a8eb9SGleb Smirnoff.Pp 29693b3a8eb9SGleb Smirnoffwill only block connections from 1.2.3.4 to port 25. 29703b3a8eb9SGleb Smirnoff.Pp 29713b3a8eb9SGleb SmirnoffAnchors may end with the asterisk 29723b3a8eb9SGleb Smirnoff.Pq Sq * 29733b3a8eb9SGleb Smirnoffcharacter, which signifies that all anchors attached at that point 29743b3a8eb9SGleb Smirnoffshould be evaluated in the alphabetical ordering of their anchor name. 29753b3a8eb9SGleb SmirnoffFor example, 29763b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 29773b3a8eb9SGleb Smirnoffanchor "spam/*" 29783b3a8eb9SGleb Smirnoff.Ed 29793b3a8eb9SGleb Smirnoff.Pp 29803b3a8eb9SGleb Smirnoffwill evaluate each rule in each anchor attached to the 29813b3a8eb9SGleb Smirnoff.Li spam 29823b3a8eb9SGleb Smirnoffanchor. 29833b3a8eb9SGleb SmirnoffNote that it will only evaluate anchors that are directly attached to the 29843b3a8eb9SGleb Smirnoff.Li spam 29853b3a8eb9SGleb Smirnoffanchor, and will not descend to evaluate anchors recursively. 29863b3a8eb9SGleb Smirnoff.Pp 29873b3a8eb9SGleb SmirnoffSince anchors are evaluated relative to the anchor in which they are 29883b3a8eb9SGleb Smirnoffcontained, there is a mechanism for accessing the parent and ancestor 29893b3a8eb9SGleb Smirnoffanchors of a given anchor. 29903b3a8eb9SGleb SmirnoffSimilar to file system path name resolution, if the sequence 29913b3a8eb9SGleb Smirnoff.Dq .. 29923b3a8eb9SGleb Smirnoffappears as an anchor path component, the parent anchor of the current 29933b3a8eb9SGleb Smirnoffanchor in the path evaluation at that point will become the new current 29943b3a8eb9SGleb Smirnoffanchor. 29953b3a8eb9SGleb SmirnoffAs an example, consider the following: 29963b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 29973b3a8eb9SGleb Smirnoff# echo ' anchor "spam/allowed" ' | pfctl -f - 29983b3a8eb9SGleb Smirnoff# echo -e ' anchor "../banned" \en pass' | \e 29993b3a8eb9SGleb Smirnoff pfctl -a spam/allowed -f - 30003b3a8eb9SGleb Smirnoff.Ed 30013b3a8eb9SGleb Smirnoff.Pp 30023b3a8eb9SGleb SmirnoffEvaluation of the main ruleset will lead into the 30033b3a8eb9SGleb Smirnoff.Li spam/allowed 30043b3a8eb9SGleb Smirnoffanchor, which will evaluate the rules in the 30053b3a8eb9SGleb Smirnoff.Li spam/banned 30063b3a8eb9SGleb Smirnoffanchor, if any, before finally evaluating the 30073b3a8eb9SGleb Smirnoff.Ar pass 30083b3a8eb9SGleb Smirnoffrule. 30093b3a8eb9SGleb Smirnoff.Pp 30103b3a8eb9SGleb SmirnoffFilter rule 30113b3a8eb9SGleb Smirnoff.Ar anchors 30123b3a8eb9SGleb Smirnoffcan also be loaded inline in the ruleset within a brace ('{' '}') delimited 30133b3a8eb9SGleb Smirnoffblock. 30143b3a8eb9SGleb SmirnoffBrace delimited blocks may contain rules or other brace-delimited blocks. 30153b3a8eb9SGleb SmirnoffWhen anchors are loaded this way the anchor name becomes optional. 30163b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 301798730c7fSKristof Provostanchor "external" on $ext_if { 30183b3a8eb9SGleb Smirnoff block 30193b3a8eb9SGleb Smirnoff anchor out { 30203b3a8eb9SGleb Smirnoff pass proto tcp from any to port { 25, 80, 443 } 30213b3a8eb9SGleb Smirnoff } 30223b3a8eb9SGleb Smirnoff pass in proto tcp to any port 22 30233b3a8eb9SGleb Smirnoff} 30243b3a8eb9SGleb Smirnoff.Ed 30253b3a8eb9SGleb Smirnoff.Pp 30263b3a8eb9SGleb SmirnoffSince the parser specification for anchor names is a string, any 30273b3a8eb9SGleb Smirnoffreference to an anchor name containing 30283b3a8eb9SGleb Smirnoff.Sq / 30293b3a8eb9SGleb Smirnoffcharacters will require double quote 30303b3a8eb9SGleb Smirnoff.Pq Sq \&" 30313b3a8eb9SGleb Smirnoffcharacters around the anchor name. 303247d0c1feSKristof Provost.Sh SCTP CONSIDERATIONS 303347d0c1feSKristof Provost.Xr pf 4 303447d0c1feSKristof Provostsupports 303547d0c1feSKristof Provost.Xr sctp 4 303647d0c1feSKristof Provostconnections. 303747d0c1feSKristof ProvostIt can match ports, track state and NAT SCTP traffic. 303847d0c1feSKristof ProvostHowever, it will not alter port numbers during nat or rdr translations. 303947d0c1feSKristof ProvostDoing so would break SCTP multihoming. 30403b3a8eb9SGleb Smirnoff.Sh TRANSLATION EXAMPLES 30413b3a8eb9SGleb SmirnoffThis example maps incoming requests on port 80 to port 8080, on 30423b3a8eb9SGleb Smirnoffwhich a daemon is running (because, for example, it is not run as root, 30433b3a8eb9SGleb Smirnoffand therefore lacks permission to bind to port 80). 30443b3a8eb9SGleb Smirnoff.Bd -literal 30453b3a8eb9SGleb Smirnoff# use a macro for the interface name, so it can be changed easily 30463b3a8eb9SGleb Smirnoffext_if = \&"ne3\&" 30473b3a8eb9SGleb Smirnoff 30483b3a8eb9SGleb Smirnoff# map daemon on 8080 to appear to be on 80 30493b3a8eb9SGleb Smirnoffrdr on $ext_if proto tcp from any to any port 80 -\*(Gt 127.0.0.1 port 8080 30503b3a8eb9SGleb Smirnoff.Ed 30513b3a8eb9SGleb Smirnoff.Pp 30523b3a8eb9SGleb SmirnoffIf the 30533b3a8eb9SGleb Smirnoff.Ar pass 30543b3a8eb9SGleb Smirnoffmodifier is given, packets matching the translation rule are passed without 30553b3a8eb9SGleb Smirnoffinspecting the filter rules: 30563b3a8eb9SGleb Smirnoff.Bd -literal 30573b3a8eb9SGleb Smirnoffrdr pass on $ext_if proto tcp from any to any port 80 -\*(Gt 127.0.0.1 \e 30583b3a8eb9SGleb Smirnoff port 8080 30593b3a8eb9SGleb Smirnoff.Ed 30603b3a8eb9SGleb Smirnoff.Pp 30613b3a8eb9SGleb SmirnoffIn the example below, vlan12 is configured as 192.168.168.1; 30623b3a8eb9SGleb Smirnoffthe machine translates all packets coming from 192.168.168.0/24 to 204.92.77.111 30633b3a8eb9SGleb Smirnoffwhen they are going out any interface except vlan12. 30643b3a8eb9SGleb SmirnoffThis has the net effect of making traffic from the 192.168.168.0/24 30653b3a8eb9SGleb Smirnoffnetwork appear as though it is the Internet routable address 30663b3a8eb9SGleb Smirnoff204.92.77.111 to nodes behind any interface on the router except 30673b3a8eb9SGleb Smirnofffor the nodes on vlan12. 30683b3a8eb9SGleb Smirnoff(Thus, 192.168.168.1 can talk to the 192.168.168.0/24 nodes.) 30693b3a8eb9SGleb Smirnoff.Bd -literal 30703b3a8eb9SGleb Smirnoffnat on ! vlan12 from 192.168.168.0/24 to any -\*(Gt 204.92.77.111 30713b3a8eb9SGleb Smirnoff.Ed 30723b3a8eb9SGleb Smirnoff.Pp 30733b3a8eb9SGleb SmirnoffIn the example below, the machine sits between a fake internal 144.19.74.* 30743b3a8eb9SGleb Smirnoffnetwork, and a routable external IP of 204.92.77.100. 30753b3a8eb9SGleb SmirnoffThe 30763b3a8eb9SGleb Smirnoff.Ar no nat 30773b3a8eb9SGleb Smirnoffrule excludes protocol AH from being translated. 30783b3a8eb9SGleb Smirnoff.Bd -literal 30793b3a8eb9SGleb Smirnoff# NO NAT 30803b3a8eb9SGleb Smirnoffno nat on $ext_if proto ah from 144.19.74.0/24 to any 30813b3a8eb9SGleb Smirnoffnat on $ext_if from 144.19.74.0/24 to any -\*(Gt 204.92.77.100 30823b3a8eb9SGleb Smirnoff.Ed 30833b3a8eb9SGleb Smirnoff.Pp 30843b3a8eb9SGleb SmirnoffIn the example below, packets bound for one specific server, as well as those 30853b3a8eb9SGleb Smirnoffgenerated by the sysadmins are not proxied; all other connections are. 30863b3a8eb9SGleb Smirnoff.Bd -literal 30873b3a8eb9SGleb Smirnoff# NO RDR 30883b3a8eb9SGleb Smirnoffno rdr on $int_if proto { tcp, udp } from any to $server port 80 30893b3a8eb9SGleb Smirnoffno rdr on $int_if proto { tcp, udp } from $sysadmins to any port 80 30903b3a8eb9SGleb Smirnoffrdr on $int_if proto { tcp, udp } from any to any port 80 -\*(Gt 127.0.0.1 \e 30913b3a8eb9SGleb Smirnoff port 80 30923b3a8eb9SGleb Smirnoff.Ed 30933b3a8eb9SGleb Smirnoff.Pp 30943b3a8eb9SGleb SmirnoffThis longer example uses both a NAT and a redirection. 30953b3a8eb9SGleb SmirnoffThe external interface has the address 157.161.48.183. 30963b3a8eb9SGleb SmirnoffOn localhost, we are running 30973b3a8eb9SGleb Smirnoff.Xr ftp-proxy 8 , 30983b3a8eb9SGleb Smirnoffwaiting for FTP sessions to be redirected to it. 30993b3a8eb9SGleb SmirnoffThe three mandatory anchors for 31003b3a8eb9SGleb Smirnoff.Xr ftp-proxy 8 31013b3a8eb9SGleb Smirnoffare omitted from this example; see the 31023b3a8eb9SGleb Smirnoff.Xr ftp-proxy 8 31033b3a8eb9SGleb Smirnoffmanpage. 31043b3a8eb9SGleb Smirnoff.Bd -literal 31053b3a8eb9SGleb Smirnoff# NAT 31063b3a8eb9SGleb Smirnoff# Translate outgoing packets' source addresses (any protocol). 31073b3a8eb9SGleb Smirnoff# In this case, any address but the gateway's external address is mapped. 31083b3a8eb9SGleb Smirnoffnat on $ext_if inet from ! ($ext_if) to any -\*(Gt ($ext_if) 31093b3a8eb9SGleb Smirnoff 31103b3a8eb9SGleb Smirnoff# NAT PROXYING 31113b3a8eb9SGleb Smirnoff# Map outgoing packets' source port to an assigned proxy port instead of 31123b3a8eb9SGleb Smirnoff# an arbitrary port. 31133b3a8eb9SGleb Smirnoff# In this case, proxy outgoing isakmp with port 500 on the gateway. 31143b3a8eb9SGleb Smirnoffnat on $ext_if inet proto udp from any port = isakmp to any -\*(Gt ($ext_if) \e 31153b3a8eb9SGleb Smirnoff port 500 31163b3a8eb9SGleb Smirnoff 31173b3a8eb9SGleb Smirnoff# BINAT 31183b3a8eb9SGleb Smirnoff# Translate outgoing packets' source address (any protocol). 31193b3a8eb9SGleb Smirnoff# Translate incoming packets' destination address to an internal machine 31203b3a8eb9SGleb Smirnoff# (bidirectional). 31213b3a8eb9SGleb Smirnoffbinat on $ext_if from 10.1.2.150 to any -\*(Gt $ext_if 31223b3a8eb9SGleb Smirnoff 31232da12891SPoul-Henning Kamp# Translate packets arriving on $peer_if addressed to 172.22.16.0/20 31242da12891SPoul-Henning Kamp# to the corresponding address in 172.21.16.0/20 (bidirectional). 31252da12891SPoul-Henning Kampbinat on $peer_if from 172.21.16.0/20 to any -> 172.22.16.0/20 31262da12891SPoul-Henning Kamp 31273b3a8eb9SGleb Smirnoff# RDR 31283b3a8eb9SGleb Smirnoff# Translate incoming packets' destination addresses. 31293b3a8eb9SGleb Smirnoff# As an example, redirect a TCP and UDP port to an internal machine. 31303b3a8eb9SGleb Smirnoffrdr on $ext_if inet proto tcp from any to ($ext_if) port 8080 \e 31313b3a8eb9SGleb Smirnoff -\*(Gt 10.1.2.151 port 22 31323b3a8eb9SGleb Smirnoffrdr on $ext_if inet proto udp from any to ($ext_if) port 8080 \e 31333b3a8eb9SGleb Smirnoff -\*(Gt 10.1.2.151 port 53 31343b3a8eb9SGleb Smirnoff 31353b3a8eb9SGleb Smirnoff# RDR 31363b3a8eb9SGleb Smirnoff# Translate outgoing ftp control connections to send them to localhost 31373b3a8eb9SGleb Smirnoff# for proxying with ftp-proxy(8) running on port 8021. 31383b3a8eb9SGleb Smirnoffrdr on $int_if proto tcp from any to any port 21 -\*(Gt 127.0.0.1 port 8021 31393b3a8eb9SGleb Smirnoff.Ed 31403b3a8eb9SGleb Smirnoff.Pp 31413b3a8eb9SGleb SmirnoffIn this example, a NAT gateway is set up to translate internal addresses 31423b3a8eb9SGleb Smirnoffusing a pool of public addresses (192.0.2.16/28) and to redirect 31433b3a8eb9SGleb Smirnoffincoming web server connections to a group of web servers on the internal 31443b3a8eb9SGleb Smirnoffnetwork. 31453b3a8eb9SGleb Smirnoff.Bd -literal 31463b3a8eb9SGleb Smirnoff# NAT LOAD BALANCE 31473b3a8eb9SGleb Smirnoff# Translate outgoing packets' source addresses using an address pool. 31483b3a8eb9SGleb Smirnoff# A given source address is always translated to the same pool address by 31493b3a8eb9SGleb Smirnoff# using the source-hash keyword. 31503b3a8eb9SGleb Smirnoffnat on $ext_if inet from any to any -\*(Gt 192.0.2.16/28 source-hash 31513b3a8eb9SGleb Smirnoff 31523b3a8eb9SGleb Smirnoff# RDR ROUND ROBIN 31533b3a8eb9SGleb Smirnoff# Translate incoming web server connections to a group of web servers on 31543b3a8eb9SGleb Smirnoff# the internal network. 31553b3a8eb9SGleb Smirnoffrdr on $ext_if proto tcp from any to any port 80 \e 31563b3a8eb9SGleb Smirnoff -\*(Gt { 10.1.2.155, 10.1.2.160, 10.1.2.161 } round-robin 31573b3a8eb9SGleb Smirnoff.Ed 31583b3a8eb9SGleb Smirnoff.Sh FILTER EXAMPLES 31593b3a8eb9SGleb Smirnoff.Bd -literal 31603b3a8eb9SGleb Smirnoff# The external interface is kue0 31613b3a8eb9SGleb Smirnoff# (157.161.48.183, the only routable address) 31623b3a8eb9SGleb Smirnoff# and the private network is 10.0.0.0/8, for which we are doing NAT. 31633b3a8eb9SGleb Smirnoff 31645ed470bdSKajetan Staszkiewicz# Reassemble incoming traffic 31655ed470bdSKajetan Staszkiewiczset reassemble yes 31665ed470bdSKajetan Staszkiewicz 31673b3a8eb9SGleb Smirnoff# use a macro for the interface name, so it can be changed easily 31683b3a8eb9SGleb Smirnoffext_if = \&"kue0\&" 31693b3a8eb9SGleb Smirnoff 31703b3a8eb9SGleb Smirnoff# block and log everything by default 31713b3a8eb9SGleb Smirnoffblock return log on $ext_if all 31723b3a8eb9SGleb Smirnoff 31733b3a8eb9SGleb Smirnoff# block anything coming from source we have no back routes for 31743b3a8eb9SGleb Smirnoffblock in from no-route to any 31753b3a8eb9SGleb Smirnoff 31763b3a8eb9SGleb Smirnoff# block packets whose ingress interface does not match the one in 31773b3a8eb9SGleb Smirnoff# the route back to their source address 31783b3a8eb9SGleb Smirnoffblock in from urpf-failed to any 31793b3a8eb9SGleb Smirnoff 31803b3a8eb9SGleb Smirnoff# block and log outgoing packets that do not have our address as source, 31813b3a8eb9SGleb Smirnoff# they are either spoofed or something is misconfigured (NAT disabled, 31823b3a8eb9SGleb Smirnoff# for instance), we want to be nice and do not send out garbage. 31833b3a8eb9SGleb Smirnoffblock out log quick on $ext_if from ! 157.161.48.183 to any 31843b3a8eb9SGleb Smirnoff 31853b3a8eb9SGleb Smirnoff# silently drop broadcasts (cable modem noise) 31863b3a8eb9SGleb Smirnoffblock in quick on $ext_if from any to 255.255.255.255 31873b3a8eb9SGleb Smirnoff 31883b3a8eb9SGleb Smirnoff# block and log incoming packets from reserved address space and invalid 31893b3a8eb9SGleb Smirnoff# addresses, they are either spoofed or misconfigured, we cannot reply to 31903b3a8eb9SGleb Smirnoff# them anyway (hence, no return-rst). 31913b3a8eb9SGleb Smirnoffblock in log quick on $ext_if from { 10.0.0.0/8, 172.16.0.0/12, \e 31923b3a8eb9SGleb Smirnoff 192.168.0.0/16, 255.255.255.255/32 } to any 31933b3a8eb9SGleb Smirnoff 31943b3a8eb9SGleb Smirnoff# ICMP 31953b3a8eb9SGleb Smirnoff 31963b3a8eb9SGleb Smirnoff# pass out/in certain ICMP queries and keep state (ping) 31973b3a8eb9SGleb Smirnoff# state matching is done on host addresses and ICMP id (not type/code), 31983b3a8eb9SGleb Smirnoff# so replies (like 0/0 for 8/0) will match queries 31993b3a8eb9SGleb Smirnoff# ICMP error messages (which always refer to a TCP/UDP packet) are 32003b3a8eb9SGleb Smirnoff# handled by the TCP/UDP states 32013b3a8eb9SGleb Smirnoffpass on $ext_if inet proto icmp all icmp-type 8 code 0 32023b3a8eb9SGleb Smirnoff 32033b3a8eb9SGleb Smirnoff# UDP 32043b3a8eb9SGleb Smirnoff 32053b3a8eb9SGleb Smirnoff# pass out all UDP connections and keep state 32063b3a8eb9SGleb Smirnoffpass out on $ext_if proto udp all 32073b3a8eb9SGleb Smirnoff 32083b3a8eb9SGleb Smirnoff# pass in certain UDP connections and keep state (DNS) 32093b3a8eb9SGleb Smirnoffpass in on $ext_if proto udp from any to any port domain 32103b3a8eb9SGleb Smirnoff 32113b3a8eb9SGleb Smirnoff# TCP 32123b3a8eb9SGleb Smirnoff 32133b3a8eb9SGleb Smirnoff# pass out all TCP connections and modulate state 32143b3a8eb9SGleb Smirnoffpass out on $ext_if proto tcp all modulate state 32153b3a8eb9SGleb Smirnoff 32163b3a8eb9SGleb Smirnoff# pass in certain TCP connections and keep state (SSH, SMTP, DNS, IDENT) 32173b3a8eb9SGleb Smirnoffpass in on $ext_if proto tcp from any to any port { ssh, smtp, domain, \e 32183b3a8eb9SGleb Smirnoff auth } 32193b3a8eb9SGleb Smirnoff 32203b3a8eb9SGleb Smirnoff# Do not allow Windows 9x SMTP connections since they are typically 32213b3a8eb9SGleb Smirnoff# a viral worm. Alternately we could limit these OSes to 1 connection each. 32223b3a8eb9SGleb Smirnoffblock in on $ext_if proto tcp from any os {"Windows 95", "Windows 98"} \e 32233b3a8eb9SGleb Smirnoff to any port smtp 32243b3a8eb9SGleb Smirnoff 32253b3a8eb9SGleb Smirnoff# IPv6 32263b3a8eb9SGleb Smirnoff# pass in/out all IPv6 traffic: note that we have to enable this in two 32273b3a8eb9SGleb Smirnoff# different ways, on both our physical interface and our tunnel 32283b3a8eb9SGleb Smirnoffpass quick on gif0 inet6 32293b3a8eb9SGleb Smirnoffpass quick on $ext_if proto ipv6 32303b3a8eb9SGleb Smirnoff 32313b3a8eb9SGleb Smirnoff# Packet Tagging 32323b3a8eb9SGleb Smirnoff 32333b3a8eb9SGleb Smirnoff# three interfaces: $int_if, $ext_if, and $wifi_if (wireless). NAT is 32343b3a8eb9SGleb Smirnoff# being done on $ext_if for all outgoing packets. tag packets in on 32353b3a8eb9SGleb Smirnoff# $int_if and pass those tagged packets out on $ext_if. all other 32363b3a8eb9SGleb Smirnoff# outgoing packets (i.e., packets from the wireless network) are only 32373b3a8eb9SGleb Smirnoff# permitted to access port 80. 32383b3a8eb9SGleb Smirnoff 32393b3a8eb9SGleb Smirnoffpass in on $int_if from any to any tag INTNET 32403b3a8eb9SGleb Smirnoffpass in on $wifi_if from any to any 32413b3a8eb9SGleb Smirnoff 32423b3a8eb9SGleb Smirnoffblock out on $ext_if from any to any 32433b3a8eb9SGleb Smirnoffpass out quick on $ext_if tagged INTNET 32443b3a8eb9SGleb Smirnoffpass out on $ext_if proto tcp from any to any port 80 32453b3a8eb9SGleb Smirnoff 32463b3a8eb9SGleb Smirnoff# tag incoming packets as they are redirected to spamd(8). use the tag 32473b3a8eb9SGleb Smirnoff# to pass those packets through the packet filter. 32483b3a8eb9SGleb Smirnoff 32493b3a8eb9SGleb Smirnoffrdr on $ext_if inet proto tcp from \*(Ltspammers\*(Gt to port smtp \e 32503b3a8eb9SGleb Smirnoff tag SPAMD -\*(Gt 127.0.0.1 port spamd 32513b3a8eb9SGleb Smirnoff 32523b3a8eb9SGleb Smirnoffblock in on $ext_if 32533b3a8eb9SGleb Smirnoffpass in on $ext_if inet proto tcp tagged SPAMD 32543b3a8eb9SGleb Smirnoff.Ed 3255eaf484fdSKristof Provost.Pp 3256eaf484fdSKristof ProvostIn the example below, a router handling both address families 3257eaf484fdSKristof Provosttranslates an internal IPv4 subnet to IPv6 using the well-known 3258eaf484fdSKristof Provost64:ff9b::/96 prefix: 3259eaf484fdSKristof Provost.Bd -literal -offset 4n 3260eaf484fdSKristof Provostpass in on $v4_if inet af-to inet6 from ($v6_if) to 64:ff9b::/96 3261eaf484fdSKristof Provost.Ed 3262eaf484fdSKristof Provost.Pp 3263eaf484fdSKristof ProvostPaired with the example above, the example below can be used on 3264eaf484fdSKristof Provostanother router handling both address families to translate back 3265eaf484fdSKristof Provostto IPv4: 3266eaf484fdSKristof Provost.Bd -literal -offset 4n 3267eaf484fdSKristof Provostpass in on $v6_if inet6 to 64:ff9b::/96 af-to inet from ($v4_if) 3268eaf484fdSKristof Provost.Ed 32693b3a8eb9SGleb Smirnoff.Sh GRAMMAR 32703b3a8eb9SGleb SmirnoffSyntax for 32713b3a8eb9SGleb Smirnoff.Nm 32723b3a8eb9SGleb Smirnoffin BNF: 32733b3a8eb9SGleb Smirnoff.Bd -literal 3274ab2886f0SKristof Provostline = ( option | ether-rule | pf-rule | nat-rule | binat-rule | 3275ab2886f0SKristof Provost rdr-rule | antispoof-rule | altq-rule | queue-rule | 3276ab2886f0SKristof Provost trans-anchors | anchor-rule | anchor-close | load-anchor | 3277ab2886f0SKristof Provost table-rule | include ) 32783b3a8eb9SGleb Smirnoff 32793b3a8eb9SGleb Smirnoffoption = "set" ( [ "timeout" ( timeout | "{" timeout-list "}" ) ] | 32803b3a8eb9SGleb Smirnoff [ "ruleset-optimization" [ "none" | "basic" | "profile" ]] | 32813b3a8eb9SGleb Smirnoff [ "optimization" [ "default" | "normal" | 32823b3a8eb9SGleb Smirnoff "high-latency" | "satellite" | 32833b3a8eb9SGleb Smirnoff "aggressive" | "conservative" ] ] 32843b3a8eb9SGleb Smirnoff [ "limit" ( limit-item | "{" limit-list "}" ) ] | 32853b3a8eb9SGleb Smirnoff [ "loginterface" ( interface-name | "none" ) ] | 32863b3a8eb9SGleb Smirnoff [ "block-policy" ( "drop" | "return" ) ] | 32873b3a8eb9SGleb Smirnoff [ "state-policy" ( "if-bound" | "floating" ) ] 32883b3a8eb9SGleb Smirnoff [ "state-defaults" state-opts ] 32893b3a8eb9SGleb Smirnoff [ "require-order" ( "yes" | "no" ) ] 32903b3a8eb9SGleb Smirnoff [ "fingerprints" filename ] | 32913b3a8eb9SGleb Smirnoff [ "skip on" ifspec ] | 329242ec75f8SKristof Provost [ "debug" ( "none" | "urgent" | "misc" | "loud" ) ] 329342ec75f8SKristof Provost [ "keepcounters" ] ) 32943b3a8eb9SGleb Smirnoff 3295ab2886f0SKristof Provostether-rule = "ether" etheraction [ ( "in" | "out" ) ] 32968a8af942SKristof Provost [ "quick" ] [ "on" ifspec ] [ "bridge-to" interface-name ] 32978a8af942SKristof Provost [ etherprotospec ] etherhosts [ "l3" hosts ] 32988a8af942SKristof Provost [ etherfilteropt-list ] 3299ab2886f0SKristof Provost 33003b3a8eb9SGleb Smirnoffpf-rule = action [ ( "in" | "out" ) ] 33013b3a8eb9SGleb Smirnoff [ "log" [ "(" logopts ")"] ] [ "quick" ] 3302813196a1SKristof Provost [ "on" ifspec ] [ route ] [ af ] [ protospec ] 33033b3a8eb9SGleb Smirnoff hosts [ filteropt-list ] 33043b3a8eb9SGleb Smirnoff 33053b3a8eb9SGleb Smirnofflogopts = logopt [ "," logopts ] 3306f3ab00c2SKristof Provostlogopt = "all" | "matches" | "user" | "to" interface-name 33073b3a8eb9SGleb Smirnoff 3308ab2886f0SKristof Provostetherfilteropt-list = etherfilteropt-list etherfilteropt | etherfilteropt 3309ef661d4aSChristian McDonaldetherfilteropt = "tag" string | "tagged" string | "queue" ( string ) | 3310ef661d4aSChristian McDonald "ridentifier" number | "label" string 3311ab2886f0SKristof Provost 33123b3a8eb9SGleb Smirnofffilteropt-list = filteropt-list filteropt | filteropt 33133b3a8eb9SGleb Smirnofffilteropt = user | group | flags | icmp-type | icmp6-type | "tos" tos | 3314eaf484fdSKristof Provost "af-to" af "from" ( redirhost | "{" redirhost-list "}" ) 3315eaf484fdSKristof Provost [ "to" ( redirhost | "{" redirhost-list "}" ) ] | 33163b3a8eb9SGleb Smirnoff ( "no" | "keep" | "modulate" | "synproxy" ) "state" 33173b3a8eb9SGleb Smirnoff [ "(" state-opts ")" ] | 33183b3a8eb9SGleb Smirnoff "fragment" | "no-df" | "min-ttl" number | "set-tos" tos | 33193b3a8eb9SGleb Smirnoff "max-mss" number | "random-id" | "reassemble tcp" | 33203b3a8eb9SGleb Smirnoff fragmentation | "allow-opts" | 33213b3a8eb9SGleb Smirnoff "label" string | "tag" string | [ ! ] "tagged" string | 33223e248e0fSKristof Provost "set prio" ( number | "(" number [ [ "," ] number ] ")" ) | 33233b3a8eb9SGleb Smirnoff "queue" ( string | "(" string [ [ "," ] string ] ")" ) | 332400a7a05bSKristof Provost "rtable" number | "probability" number"%" | "prio" number | 332500a7a05bSKristof Provost "dnpipe" ( number | "(" number "," number ")" ) | 332676c5eeccSKristof Provost "dnqueue" ( number | "(" number "," number ")" ) | 3327e80f2a10SKristof Provost "ridentifier" number | 33288b5cee40SKristof Provost [ ! ] "received-on" ( interface-name | interface-group ) 33293b3a8eb9SGleb Smirnoff 33303b3a8eb9SGleb Smirnoffnat-rule = [ "no" ] "nat" [ "pass" [ "log" [ "(" logopts ")" ] ] ] 33313b3a8eb9SGleb Smirnoff [ "on" ifspec ] [ af ] 33323b3a8eb9SGleb Smirnoff [ protospec ] hosts [ "tag" string ] [ "tagged" string ] 33333b3a8eb9SGleb Smirnoff [ "-\*(Gt" ( redirhost | "{" redirhost-list "}" ) 33342aa21096SKurosawa Takahiro [ portspec ] [ pooltype ] [ "static-port" ] 33352aa21096SKurosawa Takahiro [ "map-e-portset" number "/" number "/" number ] ] 33363b3a8eb9SGleb Smirnoff 33373b3a8eb9SGleb Smirnoffbinat-rule = [ "no" ] "binat" [ "pass" [ "log" [ "(" logopts ")" ] ] ] 33383b3a8eb9SGleb Smirnoff [ "on" interface-name ] [ af ] 33393b3a8eb9SGleb Smirnoff [ "proto" ( proto-name | proto-number ) ] 33403b3a8eb9SGleb Smirnoff "from" address [ "/" mask-bits ] "to" ipspec 33413b3a8eb9SGleb Smirnoff [ "tag" string ] [ "tagged" string ] 33423b3a8eb9SGleb Smirnoff [ "-\*(Gt" address [ "/" mask-bits ] ] 33433b3a8eb9SGleb Smirnoff 33443b3a8eb9SGleb Smirnoffrdr-rule = [ "no" ] "rdr" [ "pass" [ "log" [ "(" logopts ")" ] ] ] 33453b3a8eb9SGleb Smirnoff [ "on" ifspec ] [ af ] 33463b3a8eb9SGleb Smirnoff [ protospec ] hosts [ "tag" string ] [ "tagged" string ] 33473b3a8eb9SGleb Smirnoff [ "-\*(Gt" ( redirhost | "{" redirhost-list "}" ) 33483b3a8eb9SGleb Smirnoff [ portspec ] [ pooltype ] ] 33493b3a8eb9SGleb Smirnoff 33503b3a8eb9SGleb Smirnoffantispoof-rule = "antispoof" [ "log" ] [ "quick" ] 33513b3a8eb9SGleb Smirnoff "for" ifspec [ af ] [ "label" string ] 335276c5eeccSKristof Provost [ "ridentifier" number ] 33533b3a8eb9SGleb Smirnoff 33543b3a8eb9SGleb Smirnofftable-rule = "table" "\*(Lt" string "\*(Gt" [ tableopts-list ] 33553b3a8eb9SGleb Smirnofftableopts-list = tableopts-list tableopts | tableopts 33563b3a8eb9SGleb Smirnofftableopts = "persist" | "const" | "counters" | "file" string | 33573b3a8eb9SGleb Smirnoff "{" [ tableaddr-list ] "}" 33583b3a8eb9SGleb Smirnofftableaddr-list = tableaddr-list [ "," ] tableaddr-spec | tableaddr-spec 33593b3a8eb9SGleb Smirnofftableaddr-spec = [ "!" ] tableaddr [ "/" mask-bits ] 33603b3a8eb9SGleb Smirnofftableaddr = hostname | ifspec | "self" | 33613b3a8eb9SGleb Smirnoff ipv4-dotted-quad | ipv6-coloned-hex 33623b3a8eb9SGleb Smirnoff 33633b3a8eb9SGleb Smirnoffaltq-rule = "altq on" interface-name queueopts-list 33643b3a8eb9SGleb Smirnoff "queue" subqueue 33653b3a8eb9SGleb Smirnoffqueue-rule = "queue" string [ "on" interface-name ] queueopts-list 33663b3a8eb9SGleb Smirnoff subqueue 33673b3a8eb9SGleb Smirnoff 33683b3a8eb9SGleb Smirnoffanchor-rule = "anchor" [ string ] [ ( "in" | "out" ) ] [ "on" ifspec ] 33693b3a8eb9SGleb Smirnoff [ af ] [ protospec ] [ hosts ] [ filteropt-list ] [ "{" ] 33703b3a8eb9SGleb Smirnoff 33713b3a8eb9SGleb Smirnoffanchor-close = "}" 33723b3a8eb9SGleb Smirnoff 33733b3a8eb9SGleb Smirnofftrans-anchors = ( "nat-anchor" | "rdr-anchor" | "binat-anchor" ) string 33743b3a8eb9SGleb Smirnoff [ "on" ifspec ] [ af ] [ "proto" ] [ protospec ] [ hosts ] 33753b3a8eb9SGleb Smirnoff 33763b3a8eb9SGleb Smirnoffload-anchor = "load anchor" string "from" filename 33773b3a8eb9SGleb Smirnoff 33783b3a8eb9SGleb Smirnoffqueueopts-list = queueopts-list queueopts | queueopts 33793b3a8eb9SGleb Smirnoffqueueopts = [ "bandwidth" bandwidth-spec ] | 33803b3a8eb9SGleb Smirnoff [ "qlimit" number ] | [ "tbrsize" number ] | 33813b3a8eb9SGleb Smirnoff [ "priority" number ] | [ schedulers ] 33823b3a8eb9SGleb Smirnoffschedulers = ( cbq-def | priq-def | hfsc-def ) 33833b3a8eb9SGleb Smirnoffbandwidth-spec = "number" ( "b" | "Kb" | "Mb" | "Gb" | "%" ) 33843b3a8eb9SGleb Smirnoff 3385ab2886f0SKristof Provostetheraction = "pass" | "block" 338639282ef3SKajetan Staszkiewiczaction = "pass" | "match" | "block" [ return ] | [ "no" ] "scrub" 33873b3a8eb9SGleb Smirnoffreturn = "drop" | "return" | "return-rst" [ "( ttl" number ")" ] | 33883b3a8eb9SGleb Smirnoff "return-icmp" [ "(" icmpcode [ [ "," ] icmp6code ] ")" ] | 33893b3a8eb9SGleb Smirnoff "return-icmp6" [ "(" icmp6code ")" ] 33903b3a8eb9SGleb Smirnofficmpcode = ( icmp-code-name | icmp-code-number ) 33913b3a8eb9SGleb Smirnofficmp6code = ( icmp6-code-name | icmp6-code-number ) 33923b3a8eb9SGleb Smirnoff 33933b3a8eb9SGleb Smirnoffifspec = ( [ "!" ] ( interface-name | interface-group ) ) | 33943b3a8eb9SGleb Smirnoff "{" interface-list "}" 33953b3a8eb9SGleb Smirnoffinterface-list = [ "!" ] ( interface-name | interface-group ) 33963b3a8eb9SGleb Smirnoff [ [ "," ] interface-list ] 33973b3a8eb9SGleb Smirnoffroute = ( "route-to" | "reply-to" | "dup-to" ) 33983b3a8eb9SGleb Smirnoff ( routehost | "{" routehost-list "}" ) 33993b3a8eb9SGleb Smirnoff [ pooltype ] 34003b3a8eb9SGleb Smirnoffaf = "inet" | "inet6" 34013b3a8eb9SGleb Smirnoff 34024bfffd8cSKristof Provostetherprotospec = "proto" ( proto-number | "{" etherproto-list "}" ) 34034bfffd8cSKristof Provostetherproto-list = proto-number [ [ "," ] etherproto-list ] 34043b3a8eb9SGleb Smirnoffprotospec = "proto" ( proto-name | proto-number | 34053b3a8eb9SGleb Smirnoff "{" proto-list "}" ) 34063b3a8eb9SGleb Smirnoffproto-list = ( proto-name | proto-number ) [ [ "," ] proto-list ] 34073b3a8eb9SGleb Smirnoff 3408ab2886f0SKristof Provostetherhosts = "from" macaddress "to" macaddress 3409b590f17aSKristof Provostmacaddress = mac | mac "/" masklen | mac "&" mask 3410b590f17aSKristof Provost 34113b3a8eb9SGleb Smirnoffhosts = "all" | 34123b3a8eb9SGleb Smirnoff "from" ( "any" | "no-route" | "urpf-failed" | "self" | host | 34133b3a8eb9SGleb Smirnoff "{" host-list "}" ) [ port ] [ os ] 34143b3a8eb9SGleb Smirnoff "to" ( "any" | "no-route" | "self" | host | 34153b3a8eb9SGleb Smirnoff "{" host-list "}" ) [ port ] 34163b3a8eb9SGleb Smirnoff 34173b3a8eb9SGleb Smirnoffipspec = "any" | host | "{" host-list "}" 34183b3a8eb9SGleb Smirnoffhost = [ "!" ] ( address [ "/" mask-bits ] | "\*(Lt" string "\*(Gt" ) 34193b3a8eb9SGleb Smirnoffredirhost = address [ "/" mask-bits ] 34203b3a8eb9SGleb Smirnoffroutehost = "(" interface-name [ address [ "/" mask-bits ] ] ")" 34213b3a8eb9SGleb Smirnoffaddress = ( interface-name | interface-group | 34223b3a8eb9SGleb Smirnoff "(" ( interface-name | interface-group ) ")" | 34233b3a8eb9SGleb Smirnoff hostname | ipv4-dotted-quad | ipv6-coloned-hex ) 34243b3a8eb9SGleb Smirnoffhost-list = host [ [ "," ] host-list ] 34253b3a8eb9SGleb Smirnoffredirhost-list = redirhost [ [ "," ] redirhost-list ] 34263b3a8eb9SGleb Smirnoffroutehost-list = routehost [ [ "," ] routehost-list ] 34273b3a8eb9SGleb Smirnoff 34283b3a8eb9SGleb Smirnoffport = "port" ( unary-op | binary-op | "{" op-list "}" ) 34293b3a8eb9SGleb Smirnoffportspec = "port" ( number | name ) [ ":" ( "*" | number | name ) ] 34303b3a8eb9SGleb Smirnoffos = "os" ( os-name | "{" os-list "}" ) 34313b3a8eb9SGleb Smirnoffuser = "user" ( unary-op | binary-op | "{" op-list "}" ) 34323b3a8eb9SGleb Smirnoffgroup = "group" ( unary-op | binary-op | "{" op-list "}" ) 34333b3a8eb9SGleb Smirnoff 343485c333a9SKristof Provostunary-op = [ "=" | "!=" | "\*(Lt" | "<=" | "\*(Gt" | ">=" ] 34353b3a8eb9SGleb Smirnoff ( name | number ) 34363b3a8eb9SGleb Smirnoffbinary-op = number ( "\*(Lt\*(Gt" | "\*(Gt\*(Lt" | ":" ) number 34373b3a8eb9SGleb Smirnoffop-list = ( unary-op | binary-op ) [ [ "," ] op-list ] 34383b3a8eb9SGleb Smirnoff 34393b3a8eb9SGleb Smirnoffos-name = operating-system-name 34403b3a8eb9SGleb Smirnoffos-list = os-name [ [ "," ] os-list ] 34413b3a8eb9SGleb Smirnoff 34423b3a8eb9SGleb Smirnoffflags = "flags" ( [ flag-set ] "/" flag-set | "any" ) 34433b3a8eb9SGleb Smirnoffflag-set = [ "F" ] [ "S" ] [ "R" ] [ "P" ] [ "A" ] [ "U" ] [ "E" ] 34443b3a8eb9SGleb Smirnoff [ "W" ] 34453b3a8eb9SGleb Smirnoff 34463b3a8eb9SGleb Smirnofficmp-type = "icmp-type" ( icmp-type-code | "{" icmp-list "}" ) 34473b3a8eb9SGleb Smirnofficmp6-type = "icmp6-type" ( icmp-type-code | "{" icmp-list "}" ) 34483b3a8eb9SGleb Smirnofficmp-type-code = ( icmp-type-name | icmp-type-number ) 34493b3a8eb9SGleb Smirnoff [ "code" ( icmp-code-name | icmp-code-number ) ] 34503b3a8eb9SGleb Smirnofficmp-list = icmp-type-code [ [ "," ] icmp-list ] 34513b3a8eb9SGleb Smirnoff 34523b3a8eb9SGleb Smirnofftos = ( "lowdelay" | "throughput" | "reliability" | 34533b3a8eb9SGleb Smirnoff [ "0x" ] number ) 34543b3a8eb9SGleb Smirnoff 34553b3a8eb9SGleb Smirnoffstate-opts = state-opt [ [ "," ] state-opts ] 3456e65e2095SKristof Provoststate-opt = ( "max" number | "no-sync" | timeout | "sloppy" | 34573b3a8eb9SGleb Smirnoff "source-track" [ ( "rule" | "global" ) ] | 34583b3a8eb9SGleb Smirnoff "max-src-nodes" number | "max-src-states" number | 34593b3a8eb9SGleb Smirnoff "max-src-conn" number | 34603b3a8eb9SGleb Smirnoff "max-src-conn-rate" number "/" number | 34613b3a8eb9SGleb Smirnoff "overload" "\*(Lt" string "\*(Gt" [ "flush" ] | 3462baf9b6d0SKristof Provost "if-bound" | "floating" | "pflow" ) 34633b3a8eb9SGleb Smirnoff 346464b3b4d6SKristof Provostfragmentation = [ "fragment reassemble" ] 34653b3a8eb9SGleb Smirnoff 34663b3a8eb9SGleb Smirnofftimeout-list = timeout [ [ "," ] timeout-list ] 34673b3a8eb9SGleb Smirnofftimeout = ( "tcp.first" | "tcp.opening" | "tcp.established" | 34683b3a8eb9SGleb Smirnoff "tcp.closing" | "tcp.finwait" | "tcp.closed" | 3469ca9dbde8SKristof Provost "sctp.first" | "sctp.opening" | "sctp.established" | 3470ca9dbde8SKristof Provost "sctp.closing" | "sctp.closed" | 34713b3a8eb9SGleb Smirnoff "udp.first" | "udp.single" | "udp.multiple" | 34723b3a8eb9SGleb Smirnoff "icmp.first" | "icmp.error" | 34733b3a8eb9SGleb Smirnoff "other.first" | "other.single" | "other.multiple" | 34743b3a8eb9SGleb Smirnoff "frag" | "interval" | "src.track" | 34753b3a8eb9SGleb Smirnoff "adaptive.start" | "adaptive.end" ) number 34763b3a8eb9SGleb Smirnoff 34773b3a8eb9SGleb Smirnofflimit-list = limit-item [ [ "," ] limit-list ] 34783b3a8eb9SGleb Smirnofflimit-item = ( "states" | "frags" | "src-nodes" ) number 34793b3a8eb9SGleb Smirnoff 34803b3a8eb9SGleb Smirnoffpooltype = ( "bitmask" | "random" | 34813b3a8eb9SGleb Smirnoff "source-hash" [ ( hex-key | string-key ) ] | 34823b3a8eb9SGleb Smirnoff "round-robin" ) [ sticky-address ] 34833b3a8eb9SGleb Smirnoff 34843b3a8eb9SGleb Smirnoffsubqueue = string | "{" queue-list "}" 34853b3a8eb9SGleb Smirnoffqueue-list = string [ [ "," ] string ] 34863b3a8eb9SGleb Smirnoffcbq-def = "cbq" [ "(" cbq-opt [ [ "," ] cbq-opt ] ")" ] 34873b3a8eb9SGleb Smirnoffpriq-def = "priq" [ "(" priq-opt [ [ "," ] priq-opt ] ")" ] 34883b3a8eb9SGleb Smirnoffhfsc-def = "hfsc" [ "(" hfsc-opt [ [ "," ] hfsc-opt ] ")" ] 34893b3a8eb9SGleb Smirnoffcbq-opt = ( "default" | "borrow" | "red" | "ecn" | "rio" ) 34903b3a8eb9SGleb Smirnoffpriq-opt = ( "default" | "red" | "ecn" | "rio" ) 34913b3a8eb9SGleb Smirnoffhfsc-opt = ( "default" | "red" | "ecn" | "rio" | 34923b3a8eb9SGleb Smirnoff linkshare-sc | realtime-sc | upperlimit-sc ) 34933b3a8eb9SGleb Smirnofflinkshare-sc = "linkshare" sc-spec 34943b3a8eb9SGleb Smirnoffrealtime-sc = "realtime" sc-spec 34953b3a8eb9SGleb Smirnoffupperlimit-sc = "upperlimit" sc-spec 34963b3a8eb9SGleb Smirnoffsc-spec = ( bandwidth-spec | 34973b3a8eb9SGleb Smirnoff "(" bandwidth-spec number bandwidth-spec ")" ) 34983b3a8eb9SGleb Smirnoffinclude = "include" filename 34993b3a8eb9SGleb Smirnoff.Ed 35003b3a8eb9SGleb Smirnoff.Sh FILES 35013b3a8eb9SGleb Smirnoff.Bl -tag -width "/etc/protocols" -compact 35023b3a8eb9SGleb Smirnoff.It Pa /etc/hosts 35033b3a8eb9SGleb SmirnoffHost name database. 35043b3a8eb9SGleb Smirnoff.It Pa /etc/pf.conf 35053b3a8eb9SGleb SmirnoffDefault location of the ruleset file. 35061b35da5aSBenedict ReuschlingThe file has to be created manually as it is not installed with a 35071b35da5aSBenedict Reuschlingstandard installation. 35083b3a8eb9SGleb Smirnoff.It Pa /etc/pf.os 35093b3a8eb9SGleb SmirnoffDefault location of OS fingerprints. 35103b3a8eb9SGleb Smirnoff.It Pa /etc/protocols 35113b3a8eb9SGleb SmirnoffProtocol name database. 35123b3a8eb9SGleb Smirnoff.It Pa /etc/services 35133b3a8eb9SGleb SmirnoffService name database. 35143b3a8eb9SGleb Smirnoff.El 35153b3a8eb9SGleb Smirnoff.Sh SEE ALSO 35163b3a8eb9SGleb Smirnoff.Xr altq 4 , 35173b3a8eb9SGleb Smirnoff.Xr carp 4 , 35183b3a8eb9SGleb Smirnoff.Xr icmp 4 , 35193b3a8eb9SGleb Smirnoff.Xr icmp6 4 , 35203b3a8eb9SGleb Smirnoff.Xr ip 4 , 35213b3a8eb9SGleb Smirnoff.Xr ip6 4 , 35223b3a8eb9SGleb Smirnoff.Xr pf 4 , 3523baf9b6d0SKristof Provost.Xr pflow 4 , 35243b3a8eb9SGleb Smirnoff.Xr pfsync 4 , 352547d0c1feSKristof Provost.Xr sctp 4 , 35266e1fc011SGraham Percival.Xr tcp 4 , 35273b3a8eb9SGleb Smirnoff.Xr udp 4 , 35283b3a8eb9SGleb Smirnoff.Xr hosts 5 , 35293b3a8eb9SGleb Smirnoff.Xr pf.os 5 , 35303b3a8eb9SGleb Smirnoff.Xr protocols 5 , 35313b3a8eb9SGleb Smirnoff.Xr services 5 , 35323b3a8eb9SGleb Smirnoff.Xr ftp-proxy 8 , 35333b3a8eb9SGleb Smirnoff.Xr pfctl 8 , 3534a5e1109aSGlen Barber.Xr pflogd 8 35353b3a8eb9SGleb Smirnoff.Sh HISTORY 35363b3a8eb9SGleb SmirnoffThe 35373b3a8eb9SGleb Smirnoff.Nm 35383b3a8eb9SGleb Smirnofffile format first appeared in 35393b3a8eb9SGleb Smirnoff.Ox 3.0 . 3540