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