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