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