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