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