xref: /dflybsd-src/share/man/man5/pf.conf.5 (revision 6aa338e1205b533679b84dd50b38f5664f0d9cef)
1d27abe81SAaron LI.\"	$OpenBSD: pf.conf.5,v 1.402 2008/06/11 07:21:00 jmc Exp $
2d27abe81SAaron LI.\"
3d27abe81SAaron LI.\" Copyright (c) 2002, Daniel Hartmeier
4d27abe81SAaron LI.\" All rights reserved.
5d27abe81SAaron LI.\"
6d27abe81SAaron LI.\" Redistribution and use in source and binary forms, with or without
7d27abe81SAaron LI.\" modification, are permitted provided that the following conditions
8d27abe81SAaron LI.\" are met:
9d27abe81SAaron LI.\"
10d27abe81SAaron LI.\"    - Redistributions of source code must retain the above copyright
11d27abe81SAaron LI.\"      notice, this list of conditions and the following disclaimer.
12d27abe81SAaron LI.\"    - Redistributions in binary form must reproduce the above
13d27abe81SAaron LI.\"      copyright notice, this list of conditions and the following
14d27abe81SAaron LI.\"      disclaimer in the documentation and/or other materials provided
15d27abe81SAaron LI.\"      with the distribution.
16d27abe81SAaron LI.\"
17d27abe81SAaron LI.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18d27abe81SAaron LI.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19d27abe81SAaron LI.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20d27abe81SAaron LI.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21d27abe81SAaron LI.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22d27abe81SAaron LI.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23d27abe81SAaron LI.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24d27abe81SAaron LI.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25d27abe81SAaron LI.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26d27abe81SAaron LI.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27d27abe81SAaron LI.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28d27abe81SAaron LI.\" POSSIBILITY OF SUCH DAMAGE.
29d27abe81SAaron LI.\"
30*6aa338e1SAaron LI.Dd May 1, 2022
31d27abe81SAaron LI.Dt PF.CONF 5
32d27abe81SAaron LI.Os
33d27abe81SAaron LI.Sh NAME
34d27abe81SAaron LI.Nm pf.conf
35d27abe81SAaron LI.Nd packet filter configuration file
36d27abe81SAaron LI.Sh DESCRIPTION
37d27abe81SAaron LIThe
38d27abe81SAaron LI.Xr pf 4
39d27abe81SAaron LIpacket filter modifies, drops or passes packets according to rules or
40d27abe81SAaron LIdefinitions specified in
41d27abe81SAaron LI.Nm .
42d27abe81SAaron LI.Sh STATEMENT ORDER
43d27abe81SAaron LIThere are seven types of statements in
44d27abe81SAaron LI.Nm :
45d27abe81SAaron LI.Bl -tag -width xxxx
46d27abe81SAaron LI.It Cm Macros
47d27abe81SAaron LIUser-defined variables may be defined and used later, simplifying
48d27abe81SAaron LIthe configuration file.
49d27abe81SAaron LIMacros must be defined before they are referenced in
50d27abe81SAaron LI.Nm .
51d27abe81SAaron LI.It Cm Tables
52d27abe81SAaron LITables provide a mechanism for increasing the performance and flexibility of
53d27abe81SAaron LIrules with large numbers of source or destination addresses.
54d27abe81SAaron LI.It Cm Options
55d27abe81SAaron LIOptions tune the behaviour of the packet filtering engine.
56d27abe81SAaron LI.It Cm Traffic Normalization Li (e.g.\& Em scrub )
57d27abe81SAaron LITraffic normalization protects internal machines against inconsistencies
58d27abe81SAaron LIin Internet protocols and implementations.
59d27abe81SAaron LI.It Cm Queueing
60d27abe81SAaron LIQueueing provides rule-based bandwidth control.
61d27abe81SAaron LI.It Cm Translation Li (Various forms of NAT)
62d27abe81SAaron LITranslation rules specify how addresses are to be mapped or redirected to
63d27abe81SAaron LIother addresses.
64d27abe81SAaron LI.It Cm Packet Filtering
65d27abe81SAaron LIPacket filtering provides rule-based blocking or passing of packets.
66d27abe81SAaron LI.El
67d27abe81SAaron LI.Pp
68d27abe81SAaron LIWith the exception of
69d27abe81SAaron LI.Cm macros
70d27abe81SAaron LIand
71d27abe81SAaron LI.Cm tables ,
72d27abe81SAaron LIthe types of statements should be grouped and appear in
73d27abe81SAaron LI.Nm
74d27abe81SAaron LIin the order shown above, as this matches the operation of the underlying
75d27abe81SAaron LIpacket filtering engine.
76d27abe81SAaron LIBy default
77d27abe81SAaron LI.Xr pfctl 8
78d27abe81SAaron LIenforces this order (see
79d27abe81SAaron LI.Ar set require-order
80d27abe81SAaron LIbelow).
81d27abe81SAaron LI.Pp
82d27abe81SAaron LIComments can be put anywhere in the file using a hash mark
83d27abe81SAaron LI.Pq Sq # ,
84d27abe81SAaron LIand extend to the end of the current line.
85d27abe81SAaron LI.Pp
86d27abe81SAaron LIAdditional configuration files can be included with the
87d27abe81SAaron LI.Ic include
88d27abe81SAaron LIkeyword, for example:
89d27abe81SAaron LI.Bd -literal -offset indent
90d27abe81SAaron LIinclude "/etc/pf/sub.filter.conf"
91d27abe81SAaron LI.Ed
92d27abe81SAaron LI.Sh MACROS
93d27abe81SAaron LIMacros can be defined that will later be expanded in context.
94d27abe81SAaron LIMacro names must start with a letter, and may contain letters, digits
95d27abe81SAaron LIand underscores.
96d27abe81SAaron LIMacro names may not be reserved words (for example
97d27abe81SAaron LI.Ar pass ,
98d27abe81SAaron LI.Ar in ,
99d27abe81SAaron LI.Ar out ) .
100d27abe81SAaron LIMacros are not expanded inside quotes.
101d27abe81SAaron LI.Pp
102d27abe81SAaron LIFor example,
103d27abe81SAaron LI.Bd -literal -offset indent
104d27abe81SAaron LIext_if = \&"kue0\&"
105d27abe81SAaron LIall_ifs = \&"{\&" $ext_if lo0 \&"}\&"
106d27abe81SAaron LIpass out on $ext_if from any to any
107d27abe81SAaron LIpass in  on $ext_if proto tcp from any to any port 25
108d27abe81SAaron LI.Ed
109d27abe81SAaron LI.Sh TABLES
110d27abe81SAaron LITables are named structures which can hold a collection of addresses and
111d27abe81SAaron LInetworks.
112d27abe81SAaron LILookups against tables in
113d27abe81SAaron LI.Xr pf 4
114d27abe81SAaron LIare relatively fast, making a single rule with tables much more efficient,
115d27abe81SAaron LIin terms of
116d27abe81SAaron LIprocessor usage and memory consumption, than a large number of rules which
117d27abe81SAaron LIdiffer only in IP address (either created explicitly or automatically by rule
118d27abe81SAaron LIexpansion).
119d27abe81SAaron LI.Pp
120d27abe81SAaron LITables can be used as the source or destination of filter rules,
121d27abe81SAaron LI.Ar scrub
122d27abe81SAaron LIrules
123d27abe81SAaron LIor
124d27abe81SAaron LItranslation rules such as
125d27abe81SAaron LI.Ar nat
126d27abe81SAaron LIor
127d27abe81SAaron LI.Ar rdr
128d27abe81SAaron LI(see below for details on the various rule types).
129d27abe81SAaron LITables can also be used for the redirect address of
130d27abe81SAaron LI.Ar nat
131d27abe81SAaron LIand
132d27abe81SAaron LI.Ar rdr
133d27abe81SAaron LIrules and in the routing options of filter rules, but only for
134d27abe81SAaron LI.Ar round-robin
135d27abe81SAaron LIpools.
136d27abe81SAaron LI.Pp
137d27abe81SAaron LITables can be defined with any of the following
138d27abe81SAaron LI.Xr pfctl 8
139d27abe81SAaron LImechanisms.
140d27abe81SAaron LIAs with macros, reserved words may not be used as table names.
141d27abe81SAaron LI.Bl -tag -width "manually"
142d27abe81SAaron LI.It Ar manually
143d27abe81SAaron LIPersistent tables can be manually created with the
144d27abe81SAaron LI.Ar add
145d27abe81SAaron LIor
146d27abe81SAaron LI.Ar replace
147d27abe81SAaron LIoption of
148d27abe81SAaron LI.Xr pfctl 8 ,
149d27abe81SAaron LIbefore or after the ruleset has been loaded.
150d27abe81SAaron LI.It Pa pf.conf
151d27abe81SAaron LITable definitions can be placed directly in this file, and loaded at the
152d27abe81SAaron LIsame time as other rules are loaded, atomically.
153d27abe81SAaron LITable definitions inside
154d27abe81SAaron LI.Nm
155d27abe81SAaron LIuse the
156d27abe81SAaron LI.Ar table
157d27abe81SAaron LIstatement, and are especially useful to define non-persistent tables.
158d27abe81SAaron LIThe contents of a pre-existing table defined without a list of addresses
159d27abe81SAaron LIto initialize it is not altered when
160d27abe81SAaron LI.Nm
161d27abe81SAaron LIis loaded.
162d27abe81SAaron LIA table initialized with the empty list,
163d27abe81SAaron LI.Li { } ,
164d27abe81SAaron LIwill be cleared on load.
165d27abe81SAaron LI.El
166d27abe81SAaron LI.Pp
167d27abe81SAaron LITables may be defined with the following two attributes:
168d27abe81SAaron LI.Bl -tag -width persist
169d27abe81SAaron LI.It Ar persist
170d27abe81SAaron LIThe
171d27abe81SAaron LI.Ar persist
172d27abe81SAaron LIflag forces the kernel to keep the table even when no rules refer to it.
173d27abe81SAaron LIIf the flag is not set, the kernel will automatically remove the table
174d27abe81SAaron LIwhen the last rule referring to it is flushed.
175d27abe81SAaron LI.It Ar const
176d27abe81SAaron LIThe
177d27abe81SAaron LI.Ar const
178d27abe81SAaron LIflag prevents the user from altering the contents of the table once it
179d27abe81SAaron LIhas been created.
180d27abe81SAaron LIWithout that flag,
181d27abe81SAaron LI.Xr pfctl 8
182d27abe81SAaron LIcan be used to add or remove addresses from the table at any time, even
183d27abe81SAaron LIwhen running with
184d27abe81SAaron LI.Xr securelevel 8
185d27abe81SAaron LI= 2.
186d27abe81SAaron LI.It Ar counters
187d27abe81SAaron LIThe
188d27abe81SAaron LI.Ar counters
189d27abe81SAaron LIflag enables per-address packet and byte counters which can be displayed with
190d27abe81SAaron LI.Xr pfctl 8 .
191d27abe81SAaron LI.El
192d27abe81SAaron LI.Pp
193d27abe81SAaron LIFor example,
194d27abe81SAaron LI.Bd -literal -offset indent
195d27abe81SAaron LItable \*(Ltprivate\*(Gt const { 10/8, 172.16/12, 192.168/16 }
196d27abe81SAaron LItable \*(Ltbadhosts\*(Gt persist
197d27abe81SAaron LIblock on fxp0 from { \*(Ltprivate\*(Gt, \*(Ltbadhosts\*(Gt } to any
198d27abe81SAaron LI.Ed
199d27abe81SAaron LI.Pp
200d27abe81SAaron LIcreates a table called private, to hold RFC 1918 private network
201d27abe81SAaron LIblocks, and a table called badhosts, which is initially empty.
202d27abe81SAaron LIA filter rule is set up to block all traffic coming from addresses listed in
203d27abe81SAaron LIeither table.
204d27abe81SAaron LIThe private table cannot have its contents changed and the badhosts table
205d27abe81SAaron LIwill exist even when no active filter rules reference it.
206d27abe81SAaron LIAddresses may later be added to the badhosts table, so that traffic from
207d27abe81SAaron LIthese hosts can be blocked by using
208d27abe81SAaron LI.Bd -literal -offset indent
209d27abe81SAaron LI# pfctl -t badhosts -Tadd 204.92.77.111
210d27abe81SAaron LI.Ed
211d27abe81SAaron LI.Pp
212d27abe81SAaron LIA table can also be initialized with an address list specified in one or more
213d27abe81SAaron LIexternal files, using the following syntax:
214d27abe81SAaron LI.Bd -literal -offset indent
215d27abe81SAaron LItable \*(Ltspam\*(Gt persist file \&"/etc/spammers\&" file \&"/etc/openrelays\&"
216d27abe81SAaron LIblock on fxp0 from \*(Ltspam\*(Gt to any
217d27abe81SAaron LI.Ed
218d27abe81SAaron LI.Pp
219d27abe81SAaron LIThe files
220d27abe81SAaron LI.Pa /etc/spammers
221d27abe81SAaron LIand
222d27abe81SAaron LI.Pa /etc/openrelays
223d27abe81SAaron LIlist IP addresses, one per line.
224d27abe81SAaron LIAny lines beginning with a # are treated as comments and ignored.
225d27abe81SAaron LIIn addition to being specified by IP address, hosts may also be
226d27abe81SAaron LIspecified by their hostname.
227d27abe81SAaron LIWhen the resolver is called to add a hostname to a table,
228d27abe81SAaron LI.Em all
229d27abe81SAaron LIresulting IPv4 and IPv6 addresses are placed into the table.
230d27abe81SAaron LIIP addresses can also be entered in a table by specifying a valid interface
2315304134cSAaron LIname, a valid interface group or the
232d27abe81SAaron LI.Em self
2335304134cSAaron LIkeyword, in which case all addresses assigned to the interface(s) will be
234d27abe81SAaron LIadded to the table.
235d27abe81SAaron LI.Sh OPTIONS
236d27abe81SAaron LI.Xr pf 4
237d27abe81SAaron LImay be tuned for various situations using the
238d27abe81SAaron LI.Ar set
239d27abe81SAaron LIcommand.
240d27abe81SAaron LI.Bl -tag -width xxxx
241d27abe81SAaron LI.It Ar set timeout
242d27abe81SAaron LI.Pp
243d27abe81SAaron LI.Bl -tag -width "src.track" -compact
244d27abe81SAaron LI.It Ar interval
245d27abe81SAaron LIInterval between purging expired states and fragments.
246d27abe81SAaron LI.It Ar frag
247d27abe81SAaron LISeconds before an unassembled fragment is expired.
248d27abe81SAaron LI.It Ar src.track
249d27abe81SAaron LILength of time to retain a source tracking entry after the last state
250d27abe81SAaron LIexpires.
251d27abe81SAaron LI.El
252d27abe81SAaron LI.Pp
253d27abe81SAaron LIWhen a packet matches a stateful connection, the seconds to live for the
254d27abe81SAaron LIconnection will be updated to that of the
255d27abe81SAaron LI.Ar proto.modifier
256d27abe81SAaron LIwhich corresponds to the connection state.
257d27abe81SAaron LIEach packet which matches this state will reset the TTL.
258d27abe81SAaron LITuning these values may improve the performance of the
259d27abe81SAaron LIfirewall at the risk of dropping valid idle connections.
260d27abe81SAaron LI.Pp
261d27abe81SAaron LI.Bl -tag -width xxxx -compact
262d27abe81SAaron LI.It Ar tcp.first
263d27abe81SAaron LIThe state after the first packet.
264d27abe81SAaron LI.It Ar tcp.opening
265d27abe81SAaron LIThe state before the destination host ever sends a packet.
266d27abe81SAaron LI.It Ar tcp.established
267d27abe81SAaron LIThe fully established state.
268d27abe81SAaron LI.It Ar tcp.closing
269d27abe81SAaron LIThe state after the first FIN has been sent.
270d27abe81SAaron LI.It Ar tcp.finwait
271d27abe81SAaron LIThe state after both FINs have been exchanged and the connection is closed.
272d27abe81SAaron LISome hosts (notably web servers on Solaris) send TCP packets even after closing
273d27abe81SAaron LIthe connection.
274d27abe81SAaron LIIncreasing
275d27abe81SAaron LI.Ar tcp.finwait
276d27abe81SAaron LI(and possibly
277d27abe81SAaron LI.Ar tcp.closing )
278d27abe81SAaron LIcan prevent blocking of such packets.
279d27abe81SAaron LI.It Ar tcp.closed
280d27abe81SAaron LIThe state after one endpoint sends an RST.
281d27abe81SAaron LI.El
282d27abe81SAaron LI.Pp
283d27abe81SAaron LIICMP and UDP are handled in a fashion similar to TCP, but with a much more
284d27abe81SAaron LIlimited set of states:
285d27abe81SAaron LI.Pp
286d27abe81SAaron LI.Bl -tag -width xxxx -compact
287d27abe81SAaron LI.It Ar udp.first
288d27abe81SAaron LIThe state after the first packet.
289d27abe81SAaron LI.It Ar udp.single
290d27abe81SAaron LIThe state if the source host sends more than one packet but the destination
291d27abe81SAaron LIhost has never sent one back.
292d27abe81SAaron LI.It Ar udp.multiple
293d27abe81SAaron LIThe state if both hosts have sent packets.
294d27abe81SAaron LI.It Ar icmp.first
295d27abe81SAaron LIThe state after the first packet.
296d27abe81SAaron LI.It Ar icmp.error
297d27abe81SAaron LIThe state after an ICMP error came back in response to an ICMP packet.
298d27abe81SAaron LI.El
299d27abe81SAaron LI.Pp
300d27abe81SAaron LIOther protocols are handled similarly to UDP:
301d27abe81SAaron LI.Pp
302d27abe81SAaron LI.Bl -tag -width xxxx -compact
303d27abe81SAaron LI.It Ar other.first
304d27abe81SAaron LI.It Ar other.single
305d27abe81SAaron LI.It Ar other.multiple
306d27abe81SAaron LI.El
307d27abe81SAaron LI.Pp
308d27abe81SAaron LITimeout values can be reduced adaptively as the number of state table
309d27abe81SAaron LIentries grows.
310d27abe81SAaron LI.Pp
311d27abe81SAaron LI.Bl -tag -width xxxx -compact
312d27abe81SAaron LI.It Ar adaptive.start
313d27abe81SAaron LIWhen the number of state entries exceeds this value, adaptive scaling
314d27abe81SAaron LIbegins.
315d27abe81SAaron LIAll timeout values are scaled linearly with factor
316d27abe81SAaron LI(adaptive.end - number of states) / (adaptive.end - adaptive.start).
317d27abe81SAaron LI.It Ar adaptive.end
318d27abe81SAaron LIWhen reaching this number of state entries, all timeout values become
319d27abe81SAaron LIzero, effectively purging all state entries immediately.
320d27abe81SAaron LIThis value is used to define the scale factor, it should not actually
321d27abe81SAaron LIbe reached (set a lower state limit, see below).
322d27abe81SAaron LI.El
323d27abe81SAaron LI.Pp
324d27abe81SAaron LIAdaptive timeouts are enabled by default, with an adaptive.start value
325d27abe81SAaron LIequal to 60% of the state limit, and an adaptive.end value equal to
326d27abe81SAaron LI120% of the state limit.
327d27abe81SAaron LIThey can be disabled by setting both adaptive.start and adaptive.end to 0.
328d27abe81SAaron LI.Pp
329d27abe81SAaron LIThe adaptive timeout values can be defined both globally and for each rule.
330d27abe81SAaron LIWhen used on a per-rule basis, the values relate to the number of
331d27abe81SAaron LIstates created by the rule, otherwise to the total number of
332d27abe81SAaron LIstates.
333d27abe81SAaron LI.Pp
334d27abe81SAaron LIFor example:
335d27abe81SAaron LI.Bd -literal -offset indent
336d27abe81SAaron LIset timeout tcp.first 120
337d27abe81SAaron LIset timeout tcp.established 86400
338d27abe81SAaron LIset timeout { adaptive.start 6000, adaptive.end 12000 }
339d27abe81SAaron LIset limit states 10000
340d27abe81SAaron LI.Ed
341d27abe81SAaron LI.Pp
342d27abe81SAaron LIWith 9000 state table entries, the timeout values are scaled to 50%
343d27abe81SAaron LI(tcp.first 60, tcp.established 43200).
344d27abe81SAaron LI.It Ar set loginterface
3455304134cSAaron LIEnable collection of packet and byte count statistics for the given
3465304134cSAaron LIinterface or interface group.
347d27abe81SAaron LIThese statistics can be viewed using
348d27abe81SAaron LI.Bd -literal -offset indent
349d27abe81SAaron LI# pfctl -s info
350d27abe81SAaron LI.Ed
351d27abe81SAaron LI.Pp
352d27abe81SAaron LIIn this example
353d27abe81SAaron LI.Xr pf 4
354d27abe81SAaron LIcollects statistics on the interface named dc0:
355d27abe81SAaron LI.Bd -literal -offset indent
356d27abe81SAaron LIset loginterface dc0
357d27abe81SAaron LI.Ed
358d27abe81SAaron LI.Pp
359d27abe81SAaron LIOne can disable the loginterface using:
360d27abe81SAaron LI.Bd -literal -offset indent
361d27abe81SAaron LIset loginterface none
362d27abe81SAaron LI.Ed
363d27abe81SAaron LI.It Ar set limit
3645304134cSAaron LISets hard limits on the memory pools used by the packet filter.
365d27abe81SAaron LISee
366d27abe81SAaron LI.Xr zone 9
3675304134cSAaron LIfor an explanation of memory pools.
368d27abe81SAaron LI.Pp
369d27abe81SAaron LIFor example,
370d27abe81SAaron LI.Bd -literal -offset indent
371d27abe81SAaron LIset limit states 20000
372d27abe81SAaron LI.Ed
373d27abe81SAaron LI.Pp
374d27abe81SAaron LIsets the maximum number of entries in the memory pool used by state table
375d27abe81SAaron LIentries (generated by
376d27abe81SAaron LI.Ar pass
377d27abe81SAaron LIrules which do not specify
378d27abe81SAaron LI.Ar no state )
379d27abe81SAaron LIto 20000.
380d27abe81SAaron LIUsing
381d27abe81SAaron LI.Bd -literal -offset indent
382d27abe81SAaron LIset limit frags 20000
383d27abe81SAaron LI.Ed
384d27abe81SAaron LI.Pp
385d27abe81SAaron LIsets the maximum number of entries in the memory pool used for fragment
386d27abe81SAaron LIreassembly (generated by
387d27abe81SAaron LI.Ar scrub
388d27abe81SAaron LIrules) to 20000.
389d27abe81SAaron LIUsing
390d27abe81SAaron LI.Bd -literal -offset indent
391d27abe81SAaron LIset limit src-nodes 2000
392d27abe81SAaron LI.Ed
393d27abe81SAaron LI.Pp
394d27abe81SAaron LIsets the maximum number of entries in the memory pool used for tracking
395d27abe81SAaron LIsource IP addresses (generated by the
396d27abe81SAaron LI.Ar sticky-address
397d27abe81SAaron LIand
398d27abe81SAaron LI.Ar src.track
399d27abe81SAaron LIoptions) to 2000.
4005304134cSAaron LIUsing
4015304134cSAaron LI.Bd -literal -offset indent
4025304134cSAaron LIset limit tables 1000
4035304134cSAaron LIset limit table-entries 100000
4045304134cSAaron LI.Ed
405d27abe81SAaron LI.Pp
406d27abe81SAaron LIsets limits on the memory pools used by tables.
407d27abe81SAaron LIThe first limits the number of tables that can exist to 1000.
408d27abe81SAaron LIThe second limits the overall number of addresses that can be stored
409d27abe81SAaron LIin tables to 100000.
410d27abe81SAaron LI.Pp
411d27abe81SAaron LIVarious limits can be combined on a single line:
412d27abe81SAaron LI.Bd -literal -offset indent
413d27abe81SAaron LIset limit { states 20000, frags 20000, src-nodes 2000 }
414d27abe81SAaron LI.Ed
415d27abe81SAaron LI.It Ar set ruleset-optimization
416d27abe81SAaron LI.Bl -tag -width xxxxxxxx -compact
417d27abe81SAaron LI.It Ar none
418d27abe81SAaron LIDisable the ruleset optimizer.
4195304134cSAaron LI.Pp
420d27abe81SAaron LI.It Ar basic
421d27abe81SAaron LIEnable basic ruleset optimization.
422d27abe81SAaron LIThis is the default behaviour.
423d27abe81SAaron LIBasic ruleset optimization does four things to improve the
424d27abe81SAaron LIperformance of ruleset evaluations:
425d27abe81SAaron LI.Pp
426d27abe81SAaron LI.Bl -enum -compact
427d27abe81SAaron LI.It
428d27abe81SAaron LIremove duplicate rules
429d27abe81SAaron LI.It
430d27abe81SAaron LIremove rules that are a subset of another rule
431d27abe81SAaron LI.It
432d27abe81SAaron LIcombine multiple rules into a table when advantageous
433d27abe81SAaron LI.It
434d27abe81SAaron LIre-order the rules to improve evaluation performance
435d27abe81SAaron LI.El
4365304134cSAaron LI.Pp
437d27abe81SAaron LI.It Ar profile
438d27abe81SAaron LIUses the currently loaded ruleset as a feedback profile to tailor the
439d27abe81SAaron LIordering of quick rules to actual network traffic.
440d27abe81SAaron LI.El
441d27abe81SAaron LI.Pp
442d27abe81SAaron LIIt is important to note that the ruleset optimizer will modify the ruleset
443d27abe81SAaron LIto improve performance.
444d27abe81SAaron LIA side effect of the ruleset modification is that per-rule accounting
445d27abe81SAaron LIstatistics will have different meanings than before.
446d27abe81SAaron LIIf per-rule accounting is important for billing purposes or whatnot,
447d27abe81SAaron LIeither the ruleset optimizer should not be used or a label field should
448d27abe81SAaron LIbe added to all of the accounting rules to act as optimization barriers.
449d27abe81SAaron LI.Pp
450d27abe81SAaron LIOptimization can also be set as a command-line argument to
451d27abe81SAaron LI.Xr pfctl 8 ,
452d27abe81SAaron LIoverriding the settings in
453d27abe81SAaron LI.Nm .
454d27abe81SAaron LI.It Ar set optimization
455d27abe81SAaron LIOptimize state timeouts for one of the following network environments:
456d27abe81SAaron LI.Pp
457d27abe81SAaron LI.Bl -tag -width xxxx -compact
458d27abe81SAaron LI.It Ar normal
459d27abe81SAaron LIA normal network environment.
460d27abe81SAaron LISuitable for almost all networks.
461d27abe81SAaron LI.It Ar high-latency
462d27abe81SAaron LIA high-latency environment (such as a satellite connection).
463d27abe81SAaron LI.It Ar satellite
464d27abe81SAaron LIAlias for
465d27abe81SAaron LI.Ar high-latency .
466d27abe81SAaron LI.It Ar aggressive
467d27abe81SAaron LIAggressively expire connections.
468d27abe81SAaron LIThis can greatly reduce the memory usage of the firewall at the cost of
469d27abe81SAaron LIdropping idle connections early.
470d27abe81SAaron LI.It Ar conservative
471d27abe81SAaron LIExtremely conservative settings.
472d27abe81SAaron LIAvoid dropping legitimate connections at the
473d27abe81SAaron LIexpense of greater memory utilization (possibly much greater on a busy
474d27abe81SAaron LInetwork) and slightly increased processor utilization.
475d27abe81SAaron LI.El
476d27abe81SAaron LI.Pp
477d27abe81SAaron LIFor example:
478d27abe81SAaron LI.Bd -literal -offset indent
479d27abe81SAaron LIset optimization aggressive
480d27abe81SAaron LI.Ed
481d27abe81SAaron LI.It Ar set keep-policy keep_rule
482d27abe81SAaron LIThe
483d27abe81SAaron LI.Ar keep-policy
484d27abe81SAaron LIoption sets the default state retention policy for all
485d27abe81SAaron LI.Ar pass
486d27abe81SAaron LIrules.
487d27abe81SAaron LISee
488d27abe81SAaron LI.Sx STATEFUL TRACKING OPTIONS
489d27abe81SAaron LIor
490d27abe81SAaron LI.Sx GRAMMAR
491d27abe81SAaron LI(keep) for format of
492d27abe81SAaron LI.Ar keep_rule .
493d27abe81SAaron LIAny
494d27abe81SAaron LI.Ar no Ns / Ns Ar keep Ns / Ns Ar modulate Ns / Ns Ar synproxy state
495d27abe81SAaron LIdirectives in a
496d27abe81SAaron LI.Ar pass
497d27abe81SAaron LIrule will override the default.
498d27abe81SAaron LIFor example:
499d27abe81SAaron LI.Bd -literal -offset indent
500d27abe81SAaron LIset keep-policy keep state (pickups)
501d27abe81SAaron LI.Ed
502d27abe81SAaron LI.It Ar set block-policy
503d27abe81SAaron LIThe
504d27abe81SAaron LI.Ar block-policy
505d27abe81SAaron LIoption sets the default behaviour for the packet
506d27abe81SAaron LI.Ar block
507d27abe81SAaron LIaction:
508d27abe81SAaron LI.Pp
509d27abe81SAaron LI.Bl -tag -width xxxxxxxx -compact
510d27abe81SAaron LI.It Ar drop
511d27abe81SAaron LIPacket is silently dropped.
512d27abe81SAaron LI.It Ar return
513d27abe81SAaron LIA TCP RST is returned for blocked TCP packets,
514d27abe81SAaron LIan ICMP UNREACHABLE is returned for blocked UDP packets,
515d27abe81SAaron LIand all other packets are silently dropped.
516d27abe81SAaron LI.El
517d27abe81SAaron LI.Pp
518d27abe81SAaron LIFor example:
519d27abe81SAaron LI.Bd -literal -offset indent
520d27abe81SAaron LIset block-policy return
521d27abe81SAaron LI.Ed
522d27abe81SAaron LI.It Ar set state-policy
523d27abe81SAaron LIThe
524d27abe81SAaron LI.Ar state-policy
525d27abe81SAaron LIoption sets the default behaviour for states:
526d27abe81SAaron LI.Pp
527d27abe81SAaron LI.Bl -tag -width if-bound -compact
528d27abe81SAaron LI.It Ar if-bound
529d27abe81SAaron LIStates are bound to interface.
530d27abe81SAaron LI.It Ar floating
531d27abe81SAaron LIStates can match packets on any interfaces (the default).
532d27abe81SAaron LI.El
533d27abe81SAaron LI.Pp
534d27abe81SAaron LIFor example:
535d27abe81SAaron LI.Bd -literal -offset indent
536d27abe81SAaron LIset state-policy if-bound
537d27abe81SAaron LI.Ed
538d27abe81SAaron LI.It Ar set hostid
539d27abe81SAaron LIThe 32-bit
540d27abe81SAaron LI.Ar hostid
541d27abe81SAaron LIidentifies this firewall's state table entries to other firewalls
542d27abe81SAaron LIin a
543d27abe81SAaron LI.Xr pfsync 4
544d27abe81SAaron LIfailover cluster.
545d27abe81SAaron LIBy default the hostid is set to a pseudo-random value, however it may be
546d27abe81SAaron LIdesirable to manually configure it, for example to more easily identify the
547d27abe81SAaron LIsource of state table entries.
548d27abe81SAaron LI.Bd -literal -offset indent
549d27abe81SAaron LIset hostid 1
550d27abe81SAaron LI.Ed
551d27abe81SAaron LI.Pp
552d27abe81SAaron LIThe hostid may be specified in either decimal or hexadecimal.
553d27abe81SAaron LI.It Ar set require-order
554d27abe81SAaron LIBy default
555d27abe81SAaron LI.Xr pfctl 8
556d27abe81SAaron LIenforces an ordering of the statement types in the ruleset to:
557d27abe81SAaron LI.Em options ,
558d27abe81SAaron LI.Em normalization ,
559d27abe81SAaron LI.Em queueing ,
560d27abe81SAaron LI.Em translation ,
561d27abe81SAaron LI.Em filtering .
562d27abe81SAaron LISetting this option to
563d27abe81SAaron LI.Ar no
564d27abe81SAaron LIdisables this enforcement.
565d27abe81SAaron LIThere may be non-trivial and non-obvious implications to an out of
566d27abe81SAaron LIorder ruleset.
567d27abe81SAaron LIConsider carefully before disabling the order enforcement.
568d27abe81SAaron LI.It Ar set fingerprints
569d27abe81SAaron LILoad fingerprints of known operating systems from the given filename.
570d27abe81SAaron LIBy default fingerprints of known operating systems are automatically
571d27abe81SAaron LIloaded from
572d27abe81SAaron LI.Xr pf.os 5
573d27abe81SAaron LIin
574d27abe81SAaron LI.Pa /etc
575d27abe81SAaron LIbut can be overridden via this option.
576d27abe81SAaron LISetting this option may leave a small period of time where the fingerprints
577d27abe81SAaron LIreferenced by the currently active ruleset are inconsistent until the new
578d27abe81SAaron LIruleset finishes loading.
579d27abe81SAaron LI.Pp
580d27abe81SAaron LIFor example:
581d27abe81SAaron LI.Pp
582d27abe81SAaron LI.Dl set fingerprints \&"/etc/pf.os.devel\&"
583d27abe81SAaron LI.It Ar set skip on Aq Ar ifspec
584d27abe81SAaron LIList interfaces for which packets should not be filtered.
585d27abe81SAaron LIPackets passing in or out on such interfaces are passed as if pf was
586d27abe81SAaron LIdisabled, i.e. pf does not process them in any way.
587d27abe81SAaron LIThis can be useful on loopback and other virtual interfaces, when
588d27abe81SAaron LIpacket filtering is not desired and can have unexpected effects.
589d27abe81SAaron LIFor example:
590d27abe81SAaron LI.Pp
591d27abe81SAaron LI.Dl set skip on lo0
592d27abe81SAaron LI.It Ar set debug
593d27abe81SAaron LISet the debug
594d27abe81SAaron LI.Ar level
595d27abe81SAaron LIto one of the following:
596d27abe81SAaron LI.Pp
597d27abe81SAaron LI.Bl -tag -width xxxxxxxxxxxx -compact
598d27abe81SAaron LI.It Ar none
599d27abe81SAaron LIDon't generate debug messages.
600d27abe81SAaron LI.It Ar urgent
601d27abe81SAaron LIGenerate debug messages only for serious errors.
602d27abe81SAaron LI.It Ar misc
603d27abe81SAaron LIGenerate debug messages for various errors.
604d27abe81SAaron LI.It Ar loud
605d27abe81SAaron LIGenerate debug messages for common conditions.
606d27abe81SAaron LI.El
607d27abe81SAaron LI.El
608d27abe81SAaron LI.Sh TRAFFIC NORMALIZATION
609d27abe81SAaron LITraffic normalization is used to sanitize packet content in such
610d27abe81SAaron LIa way that there are no ambiguities in packet interpretation on
611d27abe81SAaron LIthe receiving side.
612d27abe81SAaron LIThe normalizer does IP fragment reassembly to prevent attacks
613d27abe81SAaron LIthat confuse intrusion detection systems by sending overlapping
614d27abe81SAaron LIIP fragments.
615d27abe81SAaron LIPacket normalization is invoked with the
616d27abe81SAaron LI.Ar scrub
617d27abe81SAaron LIdirective.
618d27abe81SAaron LI.Pp
619d27abe81SAaron LI.Ar scrub
620d27abe81SAaron LIhas the following options:
621d27abe81SAaron LI.Bl -tag -width xxxx
622d27abe81SAaron LI.It Ar no-df
623d27abe81SAaron LIClears the
624d27abe81SAaron LI.Ar dont-fragment
625d27abe81SAaron LIbit from a matching IP packet.
626d27abe81SAaron LISome operating systems are known to generate fragmented packets with the
627d27abe81SAaron LI.Ar dont-fragment
628d27abe81SAaron LIbit set.
629d27abe81SAaron LIThis is particularly true with NFS.
630d27abe81SAaron LI.Ar Scrub
631d27abe81SAaron LIwill drop such fragmented
632d27abe81SAaron LI.Ar dont-fragment
633d27abe81SAaron LIpackets unless
634d27abe81SAaron LI.Ar no-df
635d27abe81SAaron LIis specified.
636d27abe81SAaron LI.Pp
637d27abe81SAaron LIUnfortunately some operating systems also generate their
638d27abe81SAaron LI.Ar dont-fragment
639d27abe81SAaron LIpackets with a zero IP identification field.
640d27abe81SAaron LIClearing the
641d27abe81SAaron LI.Ar dont-fragment
642d27abe81SAaron LIbit on packets with a zero IP ID may cause deleterious results if an
643d27abe81SAaron LIupstream router later fragments the packet.
644d27abe81SAaron LIUsing the
645d27abe81SAaron LI.Ar random-id
646d27abe81SAaron LImodifier (see below) is recommended in combination with the
647d27abe81SAaron LI.Ar no-df
648d27abe81SAaron LImodifier to ensure unique IP identifiers.
649d27abe81SAaron LI.It Ar min-ttl Aq Ar number
650d27abe81SAaron LIEnforces a minimum TTL for matching IP packets.
651d27abe81SAaron LI.It Ar max-mss Aq Ar number
652d27abe81SAaron LIEnforces a maximum MSS for matching TCP packets.
653d27abe81SAaron LI.It Xo Ar set-tos Aq Ar string
654d27abe81SAaron LI.No \*(Ba Aq Ar number
655d27abe81SAaron LI.Xc
656d27abe81SAaron LIEnforces a
657d27abe81SAaron LI.Em TOS
658d27abe81SAaron LIfor matching IP packets.
659d27abe81SAaron LI.Em TOS
660d27abe81SAaron LImay be
661d27abe81SAaron LIgiven as one of
662d27abe81SAaron LI.Ar lowdelay ,
663d27abe81SAaron LI.Ar throughput ,
664d27abe81SAaron LI.Ar reliability ,
665d27abe81SAaron LIor as either hex or decimal.
666d27abe81SAaron LI.It Ar random-id
667d27abe81SAaron LIReplaces the IP identification field with random values to compensate
668d27abe81SAaron LIfor predictable values generated by many hosts.
669d27abe81SAaron LIThis option only applies to packets that are not fragmented
670d27abe81SAaron LIafter the optional fragment reassembly.
671d27abe81SAaron LI.It Ar fragment reassemble
672d27abe81SAaron LIUsing
673d27abe81SAaron LI.Ar scrub
674d27abe81SAaron LIrules, fragments can be reassembled by normalization.
675d27abe81SAaron LIIn this case, fragments are buffered until they form a complete
676d27abe81SAaron LIpacket, and only the completed packet is passed on to the filter.
677d27abe81SAaron LIThe advantage is that filter rules have to deal only with complete
678d27abe81SAaron LIpackets, and can ignore fragments.
679d27abe81SAaron LIThe drawback of caching fragments is the additional memory cost.
680d27abe81SAaron LIBut the full reassembly method is the only method that currently works
681d27abe81SAaron LIwith NAT.
682d27abe81SAaron LIThis is the default behavior of a
683d27abe81SAaron LI.Ar scrub
684d27abe81SAaron LIrule if no fragmentation modifier is supplied.
685d27abe81SAaron LI.It Ar fragment crop
686d27abe81SAaron LIThe default fragment reassembly method is expensive, hence the option
687d27abe81SAaron LIto crop is provided.
688d27abe81SAaron LIIn this case,
689d27abe81SAaron LI.Xr pf 4
690d27abe81SAaron LIwill track the fragments and cache a small range descriptor.
691d27abe81SAaron LIDuplicate fragments are dropped and overlaps are cropped.
692d27abe81SAaron LIThus data will only occur once on the wire with ambiguities resolving to
693d27abe81SAaron LIthe first occurrence.
694d27abe81SAaron LIUnlike the
695d27abe81SAaron LI.Ar fragment reassemble
696d27abe81SAaron LImodifier, fragments are not buffered, they are passed as soon as they
697d27abe81SAaron LIare received.
698d27abe81SAaron LIThe
699d27abe81SAaron LI.Ar fragment crop
700d27abe81SAaron LIreassembly mechanism does not yet work with NAT.
701d27abe81SAaron LI.It Ar fragment drop-ovl
702d27abe81SAaron LIThis option is similar to the
703d27abe81SAaron LI.Ar fragment crop
704d27abe81SAaron LImodifier except that all overlapping or duplicate fragments will be
705d27abe81SAaron LIdropped, and all further corresponding fragments will be
706d27abe81SAaron LIdropped as well.
707d27abe81SAaron LI.It Ar reassemble tcp
708d27abe81SAaron LIStatefully normalizes TCP connections.
709d27abe81SAaron LI.Ar scrub reassemble tcp
710d27abe81SAaron LIrules may not have the direction (in/out) specified.
711d27abe81SAaron LI.Ar reassemble tcp
712d27abe81SAaron LIperforms the following normalizations:
713d27abe81SAaron LI.Pp
714d27abe81SAaron LI.Bl -tag -width timeout -compact
715d27abe81SAaron LI.It ttl
716d27abe81SAaron LINeither side of the connection is allowed to reduce their IP TTL.
717d27abe81SAaron LIAn attacker may send a packet such that it reaches the firewall, affects
718d27abe81SAaron LIthe firewall state, and expires before reaching the destination host.
719d27abe81SAaron LI.Ar reassemble tcp
720d27abe81SAaron LIwill raise the TTL of all packets back up to the highest value seen on
721d27abe81SAaron LIthe connection.
722d27abe81SAaron LI.It timestamp modulation
723d27abe81SAaron LIModern TCP stacks will send a timestamp on every TCP packet and echo
724d27abe81SAaron LIthe other endpoint's timestamp back to them.
725d27abe81SAaron LIMany operating systems will merely start the timestamp at zero when
726d27abe81SAaron LIfirst booted, and increment it several times a second.
727d27abe81SAaron LIThe uptime of the host can be deduced by reading the timestamp and multiplying
728d27abe81SAaron LIby a constant.
729d27abe81SAaron LIAlso observing several different timestamps can be used to count hosts
730d27abe81SAaron LIbehind a NAT device.
731d27abe81SAaron LIAnd spoofing TCP packets into a connection requires knowing or guessing
732d27abe81SAaron LIvalid timestamps.
733d27abe81SAaron LITimestamps merely need to be monotonically increasing and not derived off a
734d27abe81SAaron LIguessable base time.
735d27abe81SAaron LI.Ar reassemble tcp
736d27abe81SAaron LIwill cause
737d27abe81SAaron LI.Ar scrub
738d27abe81SAaron LIto modulate the TCP timestamps with a random number.
739d27abe81SAaron LI.It extended PAWS checks
740d27abe81SAaron LIThere is a problem with TCP on long fat pipes, in that a packet might get
741d27abe81SAaron LIdelayed for longer than it takes the connection to wrap its 32-bit sequence
742d27abe81SAaron LIspace.
743d27abe81SAaron LIIn such an occurrence, the old packet would be indistinguishable from a
744d27abe81SAaron LInew packet and would be accepted as such.
745d27abe81SAaron LIThe solution to this is called PAWS: Protection Against Wrapped Sequence
746d27abe81SAaron LInumbers.
747d27abe81SAaron LIIt protects against it by making sure the timestamp on each packet does
748d27abe81SAaron LInot go backwards.
749d27abe81SAaron LI.Ar reassemble tcp
750d27abe81SAaron LIalso makes sure the timestamp on the packet does not go forward more
751d27abe81SAaron LIthan the RFC allows.
752d27abe81SAaron LIBy doing this,
753d27abe81SAaron LI.Xr pf 4
754d27abe81SAaron LIartificially extends the security of TCP sequence numbers by 10 to 18
755d27abe81SAaron LIbits when the host uses appropriately randomized timestamps, since a
756d27abe81SAaron LIblind attacker would have to guess the timestamp as well.
757d27abe81SAaron LI.El
758d27abe81SAaron LI.El
759d27abe81SAaron LI.Pp
760d27abe81SAaron LIFor example,
761d27abe81SAaron LI.Bd -literal -offset indent
762d27abe81SAaron LIscrub in on $ext_if all fragment reassemble
763d27abe81SAaron LI.Ed
764d27abe81SAaron LI.Pp
765d27abe81SAaron LIThe
766d27abe81SAaron LI.Ar no
767d27abe81SAaron LIoption prefixed to a scrub rule causes matching packets to remain unscrubbed,
768d27abe81SAaron LImuch in the same way as
769d27abe81SAaron LI.Ar drop quick
770d27abe81SAaron LIworks in the packet filter (see below).
771d27abe81SAaron LIThis mechanism should be used when it is necessary to exclude specific packets
772d27abe81SAaron LIfrom broader scrub rules.
773d27abe81SAaron LI.Sh QUEUEING
774d27abe81SAaron LIPackets can be assigned to queues for the purpose of bandwidth
775d27abe81SAaron LIcontrol.
776d27abe81SAaron LIAt least two declarations are required to configure queues, and later
777d27abe81SAaron LIany packet filtering rule can reference the defined queues by name.
778d27abe81SAaron LIDuring the filtering component of
779d27abe81SAaron LI.Nm ,
780d27abe81SAaron LIthe last referenced
781d27abe81SAaron LI.Ar queue
782d27abe81SAaron LIname is where any packets from
783d27abe81SAaron LI.Ar pass
784d27abe81SAaron LIrules will be queued, while for
785d27abe81SAaron LI.Ar block
786d27abe81SAaron LIrules it specifies where any resulting ICMP or TCP RST
787d27abe81SAaron LIpackets should be queued.
788d27abe81SAaron LIThe
789d27abe81SAaron LI.Ar scheduler
790d27abe81SAaron LIdefines the algorithm used to decide which packets get delayed, dropped, or
791d27abe81SAaron LIsent out immediately.
792d27abe81SAaron LIThere are four
793d27abe81SAaron LI.Ar schedulers
794d27abe81SAaron LIcurrently supported.
795d27abe81SAaron LI.Bl -tag -width ".Ar fairq"
796d27abe81SAaron LI.It Ar cbq
797d27abe81SAaron LIClass Based Queueing.
798d27abe81SAaron LI.Ar Queues
799d27abe81SAaron LIattached to an interface build a tree, thus each
800d27abe81SAaron LI.Ar queue
801d27abe81SAaron LIcan have further child
802d27abe81SAaron LI.Ar queues .
803d27abe81SAaron LIEach queue can have a
804d27abe81SAaron LI.Ar priority
805d27abe81SAaron LIand a
806d27abe81SAaron LI.Ar bandwidth
807d27abe81SAaron LIassigned.
808d27abe81SAaron LI.Ar Priority
809d27abe81SAaron LImainly controls the time packets take to get sent out, while
810d27abe81SAaron LI.Ar bandwidth
811d27abe81SAaron LIhas primarily effects on throughput.
812d27abe81SAaron LI.Ar cbq
813d27abe81SAaron LIachieves both partitioning and sharing of link bandwidth
814d27abe81SAaron LIby hierarchically structured classes.
815d27abe81SAaron LIEach class has its own
816d27abe81SAaron LI.Ar queue
817d27abe81SAaron LIand is assigned its share of
818d27abe81SAaron LI.Ar bandwidth .
819d27abe81SAaron LIA child class can borrow bandwidth from its parent class
820d27abe81SAaron LIas long as excess bandwidth is available
821d27abe81SAaron LI(see the option
822d27abe81SAaron LI.Ar borrow ,
823d27abe81SAaron LIbelow).
824d27abe81SAaron LI.It Ar priq
825d27abe81SAaron LIPriority Queueing.
826d27abe81SAaron LI.Ar Queues
827d27abe81SAaron LIare flat attached to the interface, thus,
828d27abe81SAaron LI.Ar queues
829d27abe81SAaron LIcannot have further child
830d27abe81SAaron LI.Ar queues .
831d27abe81SAaron LIEach
832d27abe81SAaron LI.Ar queue
833d27abe81SAaron LIhas a unique
834d27abe81SAaron LI.Ar priority
835d27abe81SAaron LIassigned, ranging from 0 to 15.
836d27abe81SAaron LIPackets in the
837d27abe81SAaron LI.Ar queue
838d27abe81SAaron LIwith the highest
839d27abe81SAaron LI.Ar priority
840d27abe81SAaron LIare processed first.
841d27abe81SAaron LI.It Ar hfsc
842d27abe81SAaron LIHierarchical Fair Service Curve.
843d27abe81SAaron LI.Ar Queues
844d27abe81SAaron LIattached to an interface build a tree, thus each
845d27abe81SAaron LI.Ar queue
846d27abe81SAaron LIcan have further child
847d27abe81SAaron LI.Ar queues .
848d27abe81SAaron LIEach queue can have a
849d27abe81SAaron LI.Ar priority
850d27abe81SAaron LIand a
851d27abe81SAaron LI.Ar bandwidth
852d27abe81SAaron LIassigned.
853d27abe81SAaron LI.Ar Priority
854d27abe81SAaron LImainly controls the time packets take to get sent out, while
855d27abe81SAaron LI.Ar bandwidth
856d27abe81SAaron LIprimarily affects throughput.
857d27abe81SAaron LI.Ar hfsc
858d27abe81SAaron LIsupports both link-sharing and guaranteed real-time services.
859d27abe81SAaron LIIt employs a service curve based QoS model,
860d27abe81SAaron LIand its unique feature is an ability to decouple
861d27abe81SAaron LI.Ar delay
862d27abe81SAaron LIand
863d27abe81SAaron LI.Ar bandwidth
864d27abe81SAaron LIallocation.
865d27abe81SAaron LI.It Ar fairq
866d27abe81SAaron LIFair Queue.
867d27abe81SAaron LI.Ar Queues
868d27abe81SAaron LIare flat attached to the interface, thus,
869d27abe81SAaron LI.Ar queues
870d27abe81SAaron LIcannot have further child
871d27abe81SAaron LI.Ar queues .
872d27abe81SAaron LIEach queue must be given a unique
873d27abe81SAaron LI.Ar priority
874d27abe81SAaron LIand one must be marked
875d27abe81SAaron LIas the default queue.
876d27abe81SAaron LIEach queue implements a number of
877d27abe81SAaron LI.Ar buckets
878d27abe81SAaron LI(default 256) which sorts the
879d27abe81SAaron LItraffic based on a hash key generated by the
880d27abe81SAaron LI.Ar keep state
881d27abe81SAaron LIfacility in your
882d27abe81SAaron LI.Ar pass
883d27abe81SAaron LIrules.
884d27abe81SAaron LIEach bucket contains a list of packets controlled by
885d27abe81SAaron LI.Ar qlimit .
886d27abe81SAaron LIIn order for
887d27abe81SAaron LI.Ar fairq
888d27abe81SAaron LIto function properly,
889d27abe81SAaron LI.Ar keep state
890d27abe81SAaron LImust be enabled on most of the rule sets that route packets to the queue.
891d27abe81SAaron LIAny rules for which keep state is not enabled are added to the end of the
892d27abe81SAaron LIqueue.
893d27abe81SAaron LIIf you do not wish keep state to do TCP sequence space checks use
894d27abe81SAaron LI.Ar "keep state (no-pickups)"
895d27abe81SAaron LIor
896d27abe81SAaron LI.Ar "keep state (hash-only)" .
897d27abe81SAaron LI.Pp
898d27abe81SAaron LIPacket selection operates as follows:
899d27abe81SAaron LIThe queues are scanned from highest priority to lowest priority.
900d27abe81SAaron LIIf a queue has pending packets and is under its bandwidth minimum the
901d27abe81SAaron LIscan stops and a packet is selected from that queue.
902d27abe81SAaron LIIf all queues have reached their bandwidth minimum a scale factor based
903d27abe81SAaron LIon each queue's bandwidth minimum versus that queue's current bandwidth
904d27abe81SAaron LIusage is calculated and the queue with the lowest scale factor is selected.
905d27abe81SAaron LIThis effectively uses the minimum bandwidth specification as a relative
906d27abe81SAaron LIweighting for apportioning any remaining bandwidth on the link.
907d27abe81SAaron LI.Pp
908d27abe81SAaron LIThe priority mechanic is only applicable in cases where the aggregate
909d27abe81SAaron LIminimum bandwidth guarantees exceed the link bandwidth, and also has
910d27abe81SAaron LIa small effect on queue selection when prioritizing between equal scale
911d27abe81SAaron LIcalculations.
912d27abe81SAaron LI.Pp
913d27abe81SAaron LIA
914d27abe81SAaron LI.Ar fairq
915d27abe81SAaron LIround robins between its
916d27abe81SAaron LI.Ar buckets ,
917d27abe81SAaron LIextracting one packet from each bucket.
918d27abe81SAaron LIThis essentially prevents large backlogs of packets from high volume
919d27abe81SAaron LIconnections from destroying the interactive response of other connections.
920d27abe81SAaron LI.Pp
921d27abe81SAaron LIThe
922d27abe81SAaron LI.Ar bandwidth
923d27abe81SAaron LIparameter for a
924d27abe81SAaron LI.Ar fairq
925d27abe81SAaron LIis guaranteed minimum and more will be used if no higher priority traffic is
926d27abe81SAaron LIpresent.
927d27abe81SAaron LICreating a queue with one bucket as a catch-all for
928d27abe81SAaron LI.Ar pass
929d27abe81SAaron LIrules not characterized by
930d27abe81SAaron LI.Ar keep state
931d27abe81SAaron LIis supported.
932d27abe81SAaron LISuch a queue serves as a basic priority queue with a bandwidth specification.
933d27abe81SAaron LI.Pp
934d27abe81SAaron LIAlso note that when specifying rules it is always a good idea to specify
935d27abe81SAaron LIa secondary queue for any tcp rules.
936d27abe81SAaron LIThe secondary queue is selected for pure ACKs without payloads and should
937d27abe81SAaron LIgenerally be dedicated to that purpose with a minimum bandwidth specification
938d27abe81SAaron LIsufficient to max-out the bandwidth for your incoming traffic.
939d27abe81SAaron LI.El
940d27abe81SAaron LI.Pp
941d27abe81SAaron LIThe interfaces on which queueing should be activated are declared using
942d27abe81SAaron LIthe
943d27abe81SAaron LI.Ar altq on
944d27abe81SAaron LIdeclaration.
945d27abe81SAaron LI.Ar altq on
946d27abe81SAaron LIhas the following keywords:
947d27abe81SAaron LI.Bl -tag -width xxxx
948d27abe81SAaron LI.It Aq Ar interface
949d27abe81SAaron LIQueueing is enabled on the named interface.
950d27abe81SAaron LI.It Aq Ar scheduler
951d27abe81SAaron LISpecifies which queueing scheduler to use.
952d27abe81SAaron LICurrently supported values
953d27abe81SAaron LIare
954d27abe81SAaron LI.Ar cbq
955d27abe81SAaron LIfor Class Based Queueing,
956d27abe81SAaron LI.Ar priq
957d27abe81SAaron LIfor Priority Queueing,
958d27abe81SAaron LI.Ar hfsc
959d27abe81SAaron LIfor the Hierarchical Fair Service Curve scheduler, and
960d27abe81SAaron LI.Ar fairq
961d27abe81SAaron LIfor the Fair Queueing.
9625304134cSAaron LI.It Ar bandwidth Aq Ar bw
963d27abe81SAaron LIThe maximum bitrate for all queues on an
964d27abe81SAaron LIinterface may be specified using the
965d27abe81SAaron LI.Ar bandwidth
966d27abe81SAaron LIkeyword.
967d27abe81SAaron LIThe value can be specified as an absolute value or as a
968d27abe81SAaron LIpercentage of the interface bandwidth.
969d27abe81SAaron LIWhen using an absolute value, the suffixes
970d27abe81SAaron LI.Ar b ,
971d27abe81SAaron LI.Ar Kb ,
972d27abe81SAaron LI.Ar Mb ,
973d27abe81SAaron LIand
974d27abe81SAaron LI.Ar Gb
975d27abe81SAaron LIare used to represent bits, kilobits, megabits, and
976d27abe81SAaron LIgigabits per second, respectively.
977d27abe81SAaron LIThe value must not exceed the interface bandwidth.
978d27abe81SAaron LIIf
979d27abe81SAaron LI.Ar bandwidth
980d27abe81SAaron LIis not specified, the interface bandwidth is used
981d27abe81SAaron LI(but take note that some interfaces do not know their bandwidth,
982d27abe81SAaron LIor can adapt their bandwidth rates).
983d27abe81SAaron LI.Pp
984d27abe81SAaron LIWhen used with
985d27abe81SAaron LI.Ar fairq ,
986d27abe81SAaron LI.Ar bandwidth
987d27abe81SAaron LIspecifies a guaranteed minimum but the fairq is allowed to exceed it.
9885304134cSAaron LI.It Ar qlimit Aq Ar limit
989d27abe81SAaron LIThe maximum number of packets held in the queue.
990d27abe81SAaron LIThe default is 50.
991d27abe81SAaron LI.It Ar tbrsize Aq Ar size
992d27abe81SAaron LIAdjusts the size, in bytes, of the token bucket regulator.
993d27abe81SAaron LIIf not specified, heuristics based on the
994d27abe81SAaron LIinterface bandwidth are used to determine the size.
995d27abe81SAaron LI.It Ar queue Aq Ar list
996d27abe81SAaron LIDefines a list of subqueues to create on an interface.
997d27abe81SAaron LI.El
998d27abe81SAaron LI.Pp
999d27abe81SAaron LIIn the following example, the interface dc0
1000d27abe81SAaron LIshould queue up to 5 Mbit/s in four second-level queues using
1001d27abe81SAaron LIClass Based Queueing.
1002d27abe81SAaron LIThose four queues will be shown in a later example.
1003d27abe81SAaron LI.Bd -literal -offset indent
1004d27abe81SAaron LIaltq on dc0 cbq bandwidth 5Mb queue { std, http, mail, ssh }
1005d27abe81SAaron LI.Ed
1006d27abe81SAaron LI.Pp
1007d27abe81SAaron LIOnce interfaces are activated for queueing using the
1008d27abe81SAaron LI.Ar altq
1009d27abe81SAaron LIdirective, a sequence of
1010d27abe81SAaron LI.Ar queue
1011d27abe81SAaron LIdirectives may be defined.
1012d27abe81SAaron LIThe name associated with a
1013d27abe81SAaron LI.Ar queue
1014d27abe81SAaron LImust match a queue defined in the
1015d27abe81SAaron LI.Ar altq
1016d27abe81SAaron LIdirective (e.g.\& mail), or, except for the
1017d27abe81SAaron LI.Ar priq
1018d27abe81SAaron LIand
1019d27abe81SAaron LI.Ar fairq
1020d27abe81SAaron LI.Ar schedulers ,
1021d27abe81SAaron LIin a parent
1022d27abe81SAaron LI.Ar queue
1023d27abe81SAaron LIdeclaration.
1024d27abe81SAaron LIThe following keywords can be used:
1025d27abe81SAaron LI.Bl -tag -width xxxx
1026d27abe81SAaron LI.It Ar on Aq Ar interface
1027d27abe81SAaron LISpecifies the interface the queue operates on.
1028d27abe81SAaron LIIf not given, it operates on all matching interfaces.
1029d27abe81SAaron LI.It Ar bandwidth Aq Ar bw
1030d27abe81SAaron LISpecifies the maximum bitrate to be processed by the queue.
1031d27abe81SAaron LIThis value must not exceed the value of the parent
1032d27abe81SAaron LI.Ar queue
1033d27abe81SAaron LIand can be specified as an absolute value or a percentage of the parent
1034d27abe81SAaron LIqueue's bandwidth.
1035d27abe81SAaron LIIf not specified, defaults to 100% of the parent queue's bandwidth.
1036d27abe81SAaron LIThe
1037d27abe81SAaron LI.Ar priq
1038d27abe81SAaron LIscheduler does not support bandwidth specification.
1039d27abe81SAaron LIThe
1040d27abe81SAaron LI.Ar fairq
1041d27abe81SAaron LIscheduler uses the bandwidth specification as a guaranteed minimum and
1042d27abe81SAaron LImay exceed it.
1043d27abe81SAaron LI.It Ar priority Aq Ar level
1044d27abe81SAaron LIBetween queues a priority level can be set.
1045d27abe81SAaron LIFor
1046d27abe81SAaron LI.Ar cbq ,
1047d27abe81SAaron LI.Ar hfsc ,
1048d27abe81SAaron LIand
1049d27abe81SAaron LI.Ar fairq
1050d27abe81SAaron LIthe range is 0 to 7 and for
1051d27abe81SAaron LI.Ar priq ,
1052d27abe81SAaron LIthe range is 0 to 15.
1053d27abe81SAaron LIThe default for all is 1.
1054d27abe81SAaron LI.Ar Priq
1055d27abe81SAaron LIqueues with a higher priority are always served first.
1056d27abe81SAaron LI.Ar Fairq
1057d27abe81SAaron LIqueues with a higher priority are served first unless they exceed their
1058d27abe81SAaron LIbandwidth specification.
1059d27abe81SAaron LI.Ar Cbq
1060d27abe81SAaron LIand
1061d27abe81SAaron LI.Ar hfsc
1062d27abe81SAaron LIqueues with a higher priority are preferred in the case of overload.
1063d27abe81SAaron LI.It Ar qlimit Aq Ar limit
1064d27abe81SAaron LIThe maximum number of packets held in the queue.
1065d27abe81SAaron LIThe default is 50.
1066d27abe81SAaron LIWhen used with a
1067d27abe81SAaron LI.Ar fairq
1068d27abe81SAaron LIthis specified the maximum number of packets held per bucket.
1069d27abe81SAaron LI.El
1070d27abe81SAaron LI.Pp
1071d27abe81SAaron LIThe
1072d27abe81SAaron LI.Ar scheduler
1073d27abe81SAaron LIcan get additional parameters with
1074d27abe81SAaron LI.Xo Aq Ar scheduler
1075d27abe81SAaron LI.Pf ( Aq Ar parameters ) .
1076d27abe81SAaron LI.Xc
1077d27abe81SAaron LIParameters are as follows:
1078d27abe81SAaron LI.Bl -tag -width Fl
1079d27abe81SAaron LI.It Ar default
1080d27abe81SAaron LIPackets not matched by another queue are assigned to this one.
1081d27abe81SAaron LIExactly one default queue is required.
1082d27abe81SAaron LI.It Ar red
1083d27abe81SAaron LIEnable RED (Random Early Detection) on this queue.
1084d27abe81SAaron LIRED drops packets with a probability proportional to the average
1085d27abe81SAaron LIqueue length.
1086d27abe81SAaron LI.It Ar rio
1087d27abe81SAaron LIEnables RIO on this queue.
1088d27abe81SAaron LIRIO is RED with IN/OUT, thus running
1089d27abe81SAaron LIRED two times more than RIO would achieve the same effect.
1090d27abe81SAaron LI.It Ar ecn
1091d27abe81SAaron LIEnables ECN (Explicit Congestion Notification) on this queue.
1092d27abe81SAaron LIECN implies RED.
1093d27abe81SAaron LI.El
1094d27abe81SAaron LI.Pp
1095d27abe81SAaron LIThe
1096d27abe81SAaron LI.Ar fairq
1097d27abe81SAaron LI.Ar scheduler
1098d27abe81SAaron LIsupports the following additional options:
1099d27abe81SAaron LI.Bl -tag -width Fl
11005304134cSAaron LI.It Ar buckets Aq Ar number
1101d27abe81SAaron LISpecify the number of buckets, from 1 to 2048 in powers of 2.
1102d27abe81SAaron LIA bucket size of 1 causes a
1103d27abe81SAaron LI.Ar fairq
1104d27abe81SAaron LIto essentially degenerate into a priority queue.
11055304134cSAaron LI.It Ar linkshare Aq Ar sc
1106d27abe81SAaron LIThe bandwidth share of a backlogged queue.
1107d27abe81SAaron LIThis option is parsed but not yet supported.
11085304134cSAaron LI.It Ar hogs Aq Ar bandwidth
1109d27abe81SAaron LIThis option allows low bandwidth connections to burst up to the specified
1110d27abe81SAaron LIbandwidth by not advancing the round robin when taking packets out of
1111d27abe81SAaron LIthe related queue.
1112d27abe81SAaron LIWhen using this option a small value no greater than 1/20 available interface
1113d27abe81SAaron LIbandwidth is recommended.
1114d27abe81SAaron LI.El
1115d27abe81SAaron LI.Pp
1116d27abe81SAaron LIThe
1117d27abe81SAaron LI.Ar cbq
1118d27abe81SAaron LI.Ar scheduler
1119d27abe81SAaron LIsupports an additional option:
1120d27abe81SAaron LI.Bl -tag -width Fl
1121d27abe81SAaron LI.It Ar borrow
1122d27abe81SAaron LIThe queue can borrow bandwidth from the parent.
1123d27abe81SAaron LI.El
1124d27abe81SAaron LI.Pp
1125d27abe81SAaron LIThe
1126d27abe81SAaron LI.Ar hfsc
1127d27abe81SAaron LI.Ar scheduler
1128d27abe81SAaron LIsupports some additional options:
1129d27abe81SAaron LI.Bl -tag -width Fl
1130d27abe81SAaron LI.It Ar realtime Aq Ar sc
1131d27abe81SAaron LIThe minimum required bandwidth for the queue.
1132d27abe81SAaron LI.It Ar upperlimit Aq Ar sc
1133d27abe81SAaron LIThe maximum allowed bandwidth for the queue.
1134d27abe81SAaron LI.It Ar linkshare Aq Ar sc
1135d27abe81SAaron LIThe bandwidth share of a backlogged queue.
1136d27abe81SAaron LI.El
1137d27abe81SAaron LI.Pp
1138d27abe81SAaron LI.Aq Ar sc
1139d27abe81SAaron LIis an acronym for
1140d27abe81SAaron LI.Ar service curve .
1141d27abe81SAaron LI.Pp
1142d27abe81SAaron LIThe format for service curve specifications is
1143d27abe81SAaron LI.Ar m2
1144d27abe81SAaron LIor
1145d27abe81SAaron LI.Ar "(m1 d m2)" .
1146d27abe81SAaron LI.Ar m2
1147d27abe81SAaron LIcontrols the bandwidth assigned to the queue.
1148d27abe81SAaron LI.Ar m1
1149d27abe81SAaron LIand
1150d27abe81SAaron LI.Ar d
1151d27abe81SAaron LIare optional and can be used to control the initial bandwidth assignment.
1152d27abe81SAaron LIFor the first
1153d27abe81SAaron LI.Ar d
1154d27abe81SAaron LImilliseconds the queue gets the bandwidth given as
1155d27abe81SAaron LI.Ar m1 ,
1156d27abe81SAaron LIafterwards the value given in
1157d27abe81SAaron LI.Ar m2 .
1158d27abe81SAaron LI.Pp
1159d27abe81SAaron LIFurthermore, with
1160d27abe81SAaron LI.Ar cbq
1161d27abe81SAaron LIand
1162d27abe81SAaron LI.Ar hfsc ,
1163d27abe81SAaron LIchild queues can be specified as in an
1164d27abe81SAaron LI.Ar altq
1165d27abe81SAaron LIdeclaration, thus building a tree of queues using a part of
1166d27abe81SAaron LItheir parent's bandwidth.
1167d27abe81SAaron LI.Pp
1168d27abe81SAaron LIPackets can be assigned to queues based on filter rules by using the
1169d27abe81SAaron LI.Ar queue
1170d27abe81SAaron LIkeyword.
1171d27abe81SAaron LINormally only one
1172d27abe81SAaron LI.Ar queue
1173d27abe81SAaron LIis specified; when a second one is specified it will instead be used for
1174d27abe81SAaron LIpackets which have a
1175d27abe81SAaron LI.Em TOS
1176d27abe81SAaron LIof
1177d27abe81SAaron LI.Em lowdelay
1178d27abe81SAaron LIand for TCP ACKs with no data payload.
1179d27abe81SAaron LI.Pp
1180d27abe81SAaron LITo continue the previous example, the examples below would specify the
1181d27abe81SAaron LIfour referenced
1182d27abe81SAaron LIqueues, plus a few child queues.
1183d27abe81SAaron LIInteractive
1184d27abe81SAaron LI.Xr ssh 1
1185d27abe81SAaron LIsessions get priority over bulk transfers like
1186d27abe81SAaron LI.Xr scp 1
1187d27abe81SAaron LIand
1188d27abe81SAaron LI.Xr sftp 1 .
1189d27abe81SAaron LIThe queues may then be referenced by filtering rules (see
1190d27abe81SAaron LI.Sx PACKET FILTERING
1191d27abe81SAaron LIbelow).
1192d27abe81SAaron LI.Bd -literal
1193d27abe81SAaron LIqueue std bandwidth 10% cbq(default)
1194d27abe81SAaron LIqueue http bandwidth 60% priority 2 cbq(borrow red) \e
1195d27abe81SAaron LI      { employees, developers }
1196d27abe81SAaron LIqueue  developers bandwidth 75% cbq(borrow)
1197d27abe81SAaron LIqueue  employees bandwidth 15%
1198d27abe81SAaron LIqueue mail bandwidth 10% priority 0 cbq(borrow ecn)
1199d27abe81SAaron LIqueue ssh bandwidth 20% cbq(borrow) { ssh_interactive, ssh_bulk }
1200d27abe81SAaron LIqueue  ssh_interactive bandwidth 50% priority 7 cbq(borrow)
1201d27abe81SAaron LIqueue  ssh_bulk bandwidth 50% priority 0 cbq(borrow)
1202d27abe81SAaron LI
1203d27abe81SAaron LIblock return out on dc0 inet all queue std
1204d27abe81SAaron LIpass out on dc0 inet proto tcp from $developerhosts to any port 80 \e
1205d27abe81SAaron LI      queue developers
1206d27abe81SAaron LIpass out on dc0 inet proto tcp from $employeehosts to any port 80 \e
1207d27abe81SAaron LI      queue employees
1208d27abe81SAaron LIpass out on dc0 inet proto tcp from any to any port 22 \e
1209d27abe81SAaron LI      queue(ssh_bulk, ssh_interactive)
1210d27abe81SAaron LIpass out on dc0 inet proto tcp from any to any port 25 \e
1211d27abe81SAaron LI      queue mail
1212d27abe81SAaron LI.Ed
1213d27abe81SAaron LI.Sh TRANSLATION
1214d27abe81SAaron LITranslation rules modify either the source or destination address of the
1215d27abe81SAaron LIpackets associated with a stateful connection.
1216d27abe81SAaron LIA stateful connection is automatically created to track packets matching
1217d27abe81SAaron LIsuch a rule as long as they are not blocked by the filtering section of
1218d27abe81SAaron LI.Nm .
1219d27abe81SAaron LIThe translation engine modifies the specified address and/or port in the
1220d27abe81SAaron LIpacket, recalculates IP, TCP and UDP checksums as necessary, and passes it to
1221d27abe81SAaron LIthe packet filter for evaluation.
1222d27abe81SAaron LI.Pp
1223d27abe81SAaron LISince translation occurs before filtering the filter
1224d27abe81SAaron LIengine will see packets as they look after any
1225d27abe81SAaron LIaddresses and ports have been translated.
1226d27abe81SAaron LIFilter rules will therefore have to filter based on the translated
1227d27abe81SAaron LIaddress and port number.
1228d27abe81SAaron LIPackets that match a translation rule are only automatically passed if
1229d27abe81SAaron LIthe
1230d27abe81SAaron LI.Ar pass
1231d27abe81SAaron LImodifier is given, otherwise they are
1232d27abe81SAaron LIstill subject to
1233d27abe81SAaron LI.Ar block
1234d27abe81SAaron LIand
1235d27abe81SAaron LI.Ar pass
1236d27abe81SAaron LIrules.
1237d27abe81SAaron LI.Pp
1238d27abe81SAaron LIThe state entry created permits
1239d27abe81SAaron LI.Xr pf 4
1240d27abe81SAaron LIto keep track of the original address for traffic associated with that state
1241d27abe81SAaron LIand correctly direct return traffic for that connection.
1242d27abe81SAaron LI.Pp
1243d27abe81SAaron LIVarious types of translation are possible with pf:
1244d27abe81SAaron LI.Bl -tag -width xxxx
1245d27abe81SAaron LI.It Ar binat
1246d27abe81SAaron LIA
1247d27abe81SAaron LI.Ar binat
1248d27abe81SAaron LIrule specifies a bidirectional mapping between an external IP netblock
1249d27abe81SAaron LIand an internal IP netblock.
1250d27abe81SAaron LI.It Ar nat
1251d27abe81SAaron LIA
1252d27abe81SAaron LI.Ar nat
1253d27abe81SAaron LIrule specifies that IP addresses are to be changed as the packet
1254d27abe81SAaron LItraverses the given interface.
1255d27abe81SAaron LIThis technique allows one or more IP addresses
1256d27abe81SAaron LIon the translating host to support network traffic for a larger range of
1257d27abe81SAaron LImachines on an "inside" network.
1258d27abe81SAaron LIAlthough in theory any IP address can be used on the inside, it is strongly
1259d27abe81SAaron LIrecommended that one of the address ranges defined by RFC 1918 be used.
1260d27abe81SAaron LIThese netblocks are:
1261d27abe81SAaron LI.Bd -literal
1262d27abe81SAaron LI10.0.0.0 - 10.255.255.255 (all of net 10, i.e., 10/8)
1263d27abe81SAaron LI172.16.0.0 - 172.31.255.255 (i.e., 172.16/12)
1264d27abe81SAaron LI192.168.0.0 - 192.168.255.255 (i.e., 192.168/16)
1265d27abe81SAaron LI.Ed
1266d27abe81SAaron LI.It Pa rdr
1267d27abe81SAaron LIThe packet is redirected to another destination and possibly a
1268d27abe81SAaron LIdifferent port.
1269d27abe81SAaron LI.Ar rdr
1270d27abe81SAaron LIrules can optionally specify port ranges instead of single ports.
1271d27abe81SAaron LIrdr ... port 2000:2999 -\*(Gt ... port 4000
1272d27abe81SAaron LIredirects ports 2000 to 2999 (inclusive) to port 4000.
1273d27abe81SAaron LIrdr ... port 2000:2999 -\*(Gt ... port 4000:*
1274d27abe81SAaron LIredirects port 2000 to 4000, 2001 to 4001, ..., 2999 to 4999.
1275d27abe81SAaron LI.El
1276d27abe81SAaron LI.Pp
1277d27abe81SAaron LIIn addition to modifying the address, some translation rules may modify
1278d27abe81SAaron LIsource or destination ports for
1279d27abe81SAaron LI.Xr tcp 4
1280d27abe81SAaron LIor
1281d27abe81SAaron LI.Xr udp 4
1282d27abe81SAaron LIconnections; implicitly in the case of
1283d27abe81SAaron LI.Ar nat
1284d27abe81SAaron LIrules and explicitly in the case of
1285d27abe81SAaron LI.Ar rdr
1286d27abe81SAaron LIrules.
1287d27abe81SAaron LIPort numbers are never translated with a
1288d27abe81SAaron LI.Ar binat
1289d27abe81SAaron LIrule.
1290d27abe81SAaron LI.Pp
1291d27abe81SAaron LIEvaluation order of the translation rules is dependent on the type
1292d27abe81SAaron LIof the translation rules and of the direction of a packet.
1293d27abe81SAaron LI.Ar binat
1294d27abe81SAaron LIrules are always evaluated first.
1295d27abe81SAaron LIThen either the
1296d27abe81SAaron LI.Ar rdr
1297d27abe81SAaron LIrules are evaluated on an inbound packet or the
1298d27abe81SAaron LI.Ar nat
1299d27abe81SAaron LIrules on an outbound packet.
1300d27abe81SAaron LIRules of the same type are evaluated in the same order in which they
1301d27abe81SAaron LIappear in the ruleset.
1302d27abe81SAaron LIThe first matching rule decides what action is taken.
1303d27abe81SAaron LI.Pp
1304d27abe81SAaron LIThe
1305d27abe81SAaron LI.Ar no
1306d27abe81SAaron LIoption prefixed to a translation rule causes packets to remain untranslated,
1307d27abe81SAaron LImuch in the same way as
1308d27abe81SAaron LI.Ar drop quick
1309d27abe81SAaron LIworks in the packet filter (see below).
1310d27abe81SAaron LIIf no rule matches the packet it is passed to the filter engine unmodified.
1311d27abe81SAaron LI.Pp
1312d27abe81SAaron LITranslation rules apply only to packets that pass through
1313d27abe81SAaron LIthe specified interface, and if no interface is specified,
1314d27abe81SAaron LItranslation is applied to packets on all interfaces.
1315d27abe81SAaron LIFor instance, redirecting port 80 on an external interface to an internal
1316d27abe81SAaron LIweb server will only work for connections originating from the outside.
1317d27abe81SAaron LIConnections to the address of the external interface from local hosts will
1318d27abe81SAaron LInot be redirected, since such packets do not actually pass through the
1319d27abe81SAaron LIexternal interface.
1320d27abe81SAaron LIRedirections cannot reflect packets back through the interface they arrive
1321d27abe81SAaron LIon, they can only be redirected to hosts connected to different interfaces
1322d27abe81SAaron LIor to the firewall itself.
1323d27abe81SAaron LI.Pp
1324d27abe81SAaron LINote that redirecting external incoming connections to the loopback
1325d27abe81SAaron LIaddress, as in
1326d27abe81SAaron LI.Bd -literal -offset indent
1327d27abe81SAaron LIrdr on ne3 inet proto tcp to port smtp -\*(Gt 127.0.0.1 port spamd
1328d27abe81SAaron LI.Ed
1329d27abe81SAaron LI.Pp
1330d27abe81SAaron LIwill effectively allow an external host to connect to daemons
1331d27abe81SAaron LIbound solely to the loopback address, circumventing the traditional
1332d27abe81SAaron LIblocking of such connections on a real interface.
1333d27abe81SAaron LIUnless this effect is desired, any of the local non-loopback addresses
1334d27abe81SAaron LIshould be used as redirection target instead, which allows external
1335d27abe81SAaron LIconnections only to daemons bound to this address or not bound to
1336d27abe81SAaron LIany address.
1337d27abe81SAaron LI.Pp
1338d27abe81SAaron LISee
1339d27abe81SAaron LI.Sx TRANSLATION EXAMPLES
1340d27abe81SAaron LIbelow.
1341d27abe81SAaron LI.Sh PACKET FILTERING
1342d27abe81SAaron LI.Xr pf 4
1343d27abe81SAaron LIhas the ability to
1344d27abe81SAaron LI.Ar block
1345d27abe81SAaron LIand
1346d27abe81SAaron LI.Ar pass
1347d27abe81SAaron LIpackets based on attributes of their layer 3 (see
1348d27abe81SAaron LI.Xr ip 4
1349d27abe81SAaron LIand
1350d27abe81SAaron LI.Xr ip6 4 )
1351d27abe81SAaron LIand layer 4 (see
1352d27abe81SAaron LI.Xr icmp 4 ,
1353d27abe81SAaron LI.Xr icmp6 4 ,
1354d27abe81SAaron LI.Xr tcp 4 ,
1355d27abe81SAaron LI.Xr udp 4 )
1356d27abe81SAaron LIheaders.
1357d27abe81SAaron LIIn addition, packets may also be
1358d27abe81SAaron LIassigned to queues for the purpose of bandwidth control.
1359d27abe81SAaron LI.Pp
1360d27abe81SAaron LIFor each packet processed by the packet filter, the filter rules are
1361d27abe81SAaron LIevaluated in sequential order, from first to last.
1362d27abe81SAaron LIThe last matching rule decides what action is taken.
1363d27abe81SAaron LIIf no rule matches the packet, the default action is to pass
1364d27abe81SAaron LIthe packet.
1365d27abe81SAaron LI.Pp
1366d27abe81SAaron LIThe following actions can be used in the filter:
1367d27abe81SAaron LI.Bl -tag -width xxxx
1368d27abe81SAaron LI.It Ar block
1369d27abe81SAaron LIThe packet is blocked.
1370d27abe81SAaron LIThere are a number of ways in which a
1371d27abe81SAaron LI.Ar block
1372d27abe81SAaron LIrule can behave when blocking a packet.
1373d27abe81SAaron LIThe default behaviour is to
1374d27abe81SAaron LI.Ar drop
1375d27abe81SAaron LIpackets silently, however this can be overridden or made
1376d27abe81SAaron LIexplicit either globally, by setting the
1377d27abe81SAaron LI.Ar block-policy
1378d27abe81SAaron LIoption, or on a per-rule basis with one of the following options:
1379d27abe81SAaron LI.Pp
1380d27abe81SAaron LI.Bl -tag -width xxxx -compact
1381d27abe81SAaron LI.It Ar drop
1382d27abe81SAaron LIThe packet is silently dropped.
1383d27abe81SAaron LI.It Ar return-rst
1384d27abe81SAaron LIThis applies only to
1385d27abe81SAaron LI.Xr tcp 4
1386d27abe81SAaron LIpackets, and issues a TCP RST which closes the
1387d27abe81SAaron LIconnection.
1388d27abe81SAaron LI.It Ar return-icmp
1389d27abe81SAaron LI.It Ar return-icmp6
1390d27abe81SAaron LIThis causes ICMP messages to be returned for packets which match the rule.
1391d27abe81SAaron LIBy default this is an ICMP UNREACHABLE message, however this
1392d27abe81SAaron LIcan be overridden by specifying a message as a code or number.
1393d27abe81SAaron LI.It Ar return
1394d27abe81SAaron LIThis causes a TCP RST to be returned for
1395d27abe81SAaron LI.Xr tcp 4
1396d27abe81SAaron LIpackets and an ICMP UNREACHABLE for UDP and other packets.
1397d27abe81SAaron LI.El
1398d27abe81SAaron LI.Pp
1399d27abe81SAaron LIOptions returning ICMP packets currently have no effect if
1400d27abe81SAaron LI.Xr pf 4
1401d27abe81SAaron LIoperates on a
1402d27abe81SAaron LI.Xr bridge 4 ,
1403d27abe81SAaron LIas the code to support this feature has not yet been implemented.
1404d27abe81SAaron LI.Pp
1405d27abe81SAaron LIThe simplest mechanism to block everything by default and only pass
1406d27abe81SAaron LIpackets that match explicit rules is specify a first filter rule of:
1407d27abe81SAaron LI.Bd -literal -offset indent
1408d27abe81SAaron LIblock all
1409d27abe81SAaron LI.Ed
1410d27abe81SAaron LI.It Ar pass
1411d27abe81SAaron LIThe packet is passed;
1412d27abe81SAaron LIstate is created unless the
1413d27abe81SAaron LI.Ar no state
1414d27abe81SAaron LIoption is specified.
1415d27abe81SAaron LI.El
1416d27abe81SAaron LI.Pp
1417d27abe81SAaron LIBy default
1418d27abe81SAaron LI.Xr pf 4
1419d27abe81SAaron LIfilters packets statefully; the first time a packet matches a
1420d27abe81SAaron LI.Ar pass
1421d27abe81SAaron LIrule, a state entry is created; for subsequent packets the filter checks
1422d27abe81SAaron LIwhether the packet matches any state.
1423d27abe81SAaron LIIf it does, the packet is passed without evaluation of any rules.
1424d27abe81SAaron LIAfter the connection is closed or times out, the state entry is automatically
1425d27abe81SAaron LIremoved.
1426d27abe81SAaron LI.Pp
1427d27abe81SAaron LIThis has several advantages.
1428d27abe81SAaron LIFor TCP connections, comparing a packet to a state involves checking
1429d27abe81SAaron LIits sequence numbers, as well as TCP timestamps if a
1430d27abe81SAaron LI.Ar scrub reassemble tcp
1431d27abe81SAaron LIrule applies to the connection.
1432d27abe81SAaron LIIf these values are outside the narrow windows of expected
1433d27abe81SAaron LIvalues, the packet is dropped.
1434d27abe81SAaron LIThis prevents spoofing attacks, such as when an attacker sends packets with
1435d27abe81SAaron LIa fake source address/port but does not know the connection's sequence
1436d27abe81SAaron LInumbers.
1437d27abe81SAaron LISimilarly,
1438d27abe81SAaron LI.Xr pf 4
1439d27abe81SAaron LIknows how to match ICMP replies to states.
1440d27abe81SAaron LIFor example,
1441d27abe81SAaron LI.Bd -literal -offset indent
1442d27abe81SAaron LIpass out inet proto icmp all icmp-type echoreq
1443d27abe81SAaron LI.Ed
1444d27abe81SAaron LI.Pp
1445d27abe81SAaron LIallows echo requests (such as those created by
1446d27abe81SAaron LI.Xr ping 8 )
1447d27abe81SAaron LIout statefully, and matches incoming echo replies correctly to states.
1448d27abe81SAaron LI.Pp
1449d27abe81SAaron LIAlso, looking up states is usually faster than evaluating rules.
1450d27abe81SAaron LIIf there are 50 rules, all of them are evaluated sequentially in O(n).
1451d27abe81SAaron LIEven with 50000 states, only 16 comparisons are needed to match a
1452d27abe81SAaron LIstate, since states are stored in a binary search tree that allows
1453d27abe81SAaron LIsearches in O(log2 n).
1454d27abe81SAaron LI.Pp
1455d27abe81SAaron LIFurthermore, correct handling of ICMP error messages is critical to
1456d27abe81SAaron LImany protocols, particularly TCP.
1457d27abe81SAaron LI.Xr pf 4
1458d27abe81SAaron LImatches ICMP error messages to the correct connection, checks them against
1459d27abe81SAaron LIconnection parameters, and passes them if appropriate.
1460d27abe81SAaron LIFor example if an ICMP source quench message referring to a stateful TCP
1461d27abe81SAaron LIconnection arrives, it will be matched to the state and get passed.
1462d27abe81SAaron LI.Pp
1463d27abe81SAaron LIFinally, state tracking is required for
1464d27abe81SAaron LI.Ar nat , binat No and Ar rdr
1465d27abe81SAaron LIrules, in order to track address and port translations and reverse the
1466d27abe81SAaron LItranslation on returning packets.
1467d27abe81SAaron LI.Pp
1468d27abe81SAaron LI.Xr pf 4
1469d27abe81SAaron LIwill also create state for other protocols which are effectively stateless by
1470d27abe81SAaron LInature.
1471d27abe81SAaron LIUDP packets are matched to states using only host addresses and ports,
1472d27abe81SAaron LIand other protocols are matched to states using only the host addresses.
1473d27abe81SAaron LI.Pp
1474d27abe81SAaron LIIf stateless filtering of individual packets is desired,
1475d27abe81SAaron LIthe
1476d27abe81SAaron LI.Ar no state
1477d27abe81SAaron LIkeyword can be used to specify that state will not be created
1478d27abe81SAaron LIif this is the last matching rule.
1479d27abe81SAaron LIA number of parameters can also be set to affect how
1480d27abe81SAaron LI.Xr pf 4
1481d27abe81SAaron LIhandles state tracking.
1482d27abe81SAaron LISee
1483d27abe81SAaron LI.Sx STATEFUL TRACKING OPTIONS
1484d27abe81SAaron LIbelow for further details.
1485d27abe81SAaron LI.Sh PARAMETERS
1486d27abe81SAaron LIThe rule parameters specify the packets to which a rule applies.
1487d27abe81SAaron LIA packet always comes in on, or goes out through, one interface.
1488d27abe81SAaron LIMost parameters are optional.
1489d27abe81SAaron LIIf a parameter is specified, the rule only applies to packets with
1490d27abe81SAaron LImatching attributes.
1491d27abe81SAaron LICertain parameters can be expressed as lists, in which case
1492d27abe81SAaron LI.Xr pfctl 8
1493d27abe81SAaron LIgenerates all needed rule combinations.
1494d27abe81SAaron LI.Bl -tag -width xxxx
1495d27abe81SAaron LI.It Ar in No or Ar out
1496d27abe81SAaron LIThis rule applies to incoming or outgoing packets.
1497d27abe81SAaron LIIf neither
1498d27abe81SAaron LI.Ar in
1499d27abe81SAaron LInor
1500d27abe81SAaron LI.Ar out
1501d27abe81SAaron LIare specified, the rule will match packets in both directions.
1502d27abe81SAaron LI.It Ar log
1503d27abe81SAaron LIIn addition to the action specified, a log message is generated.
1504d27abe81SAaron LIOnly the packet that establishes the state is logged,
1505d27abe81SAaron LIunless the
1506d27abe81SAaron LI.Ar no state
1507d27abe81SAaron LIoption is specified.
1508d27abe81SAaron LIThe logged packets are sent to a
1509d27abe81SAaron LI.Xr pflog 4
1510d27abe81SAaron LIinterface, by default
1511d27abe81SAaron LI.Ar pflog0 .
1512d27abe81SAaron LIThis interface is monitored by the
1513d27abe81SAaron LI.Xr pflogd 8
1514d27abe81SAaron LIlogging daemon, which dumps the logged packets to the file
1515d27abe81SAaron LI.Pa /var/log/pflog
1516d27abe81SAaron LIin
1517d27abe81SAaron LI.Xr pcap 3
1518d27abe81SAaron LIbinary format.
1519d27abe81SAaron LI.It Ar log (all)
1520d27abe81SAaron LIUsed to force logging of all packets for a connection.
1521d27abe81SAaron LIThis is not necessary when
1522d27abe81SAaron LI.Ar no state
1523d27abe81SAaron LIis explicitly specified.
1524d27abe81SAaron LIAs with
1525d27abe81SAaron LI.Ar log ,
1526d27abe81SAaron LIpackets are logged to
1527d27abe81SAaron LI.Xr pflog 4 .
1528d27abe81SAaron LI.It Ar log (user)
1529d27abe81SAaron LILogs the
1530d27abe81SAaron LI.Ux
1531d27abe81SAaron LIuser ID of the user that owns the socket and the PID of the process that
1532d27abe81SAaron LIhas the socket open where the packet is sourced from or destined to
1533d27abe81SAaron LI(depending on which socket is local).
1534d27abe81SAaron LIThis is in addition to the normal information logged.
1535d27abe81SAaron LI.It Ar log (to Aq Ar interface )
1536d27abe81SAaron LISend logs to the specified
1537d27abe81SAaron LI.Xr pflog 4
1538d27abe81SAaron LIinterface instead of
1539d27abe81SAaron LI.Ar pflog0 .
1540d27abe81SAaron LI.It Ar quick
1541d27abe81SAaron LIIf a packet matches a rule which has the
1542d27abe81SAaron LI.Ar quick
1543d27abe81SAaron LIoption set, this rule
1544d27abe81SAaron LIis considered the last matching rule, and evaluation of subsequent rules
1545d27abe81SAaron LIis skipped.
1546d27abe81SAaron LI.It Ar on Aq Ar interface
1547d27abe81SAaron LIThis rule applies only to packets coming in on, or going out through, this
15485304134cSAaron LIparticular interface or interface group.
15495304134cSAaron LIFor more information on interface groups,
15505304134cSAaron LIsee the
15515304134cSAaron LI.Ic group
15525304134cSAaron LIkeyword in
15535304134cSAaron LI.Xr ifconfig 8 .
1554d27abe81SAaron LI.It Aq Ar af
1555d27abe81SAaron LIThis rule applies only to packets of this address family.
1556d27abe81SAaron LISupported values are
1557d27abe81SAaron LI.Ar inet
1558d27abe81SAaron LIand
1559d27abe81SAaron LI.Ar inet6 .
1560d27abe81SAaron LI.It Ar proto Aq Ar protocol
1561d27abe81SAaron LIThis rule applies only to packets of this protocol.
1562d27abe81SAaron LICommon protocols are
1563d27abe81SAaron LI.Xr icmp 4 ,
1564d27abe81SAaron LI.Xr icmp6 4 ,
1565d27abe81SAaron LI.Xr tcp 4 ,
1566d27abe81SAaron LIand
1567d27abe81SAaron LI.Xr udp 4 .
1568d27abe81SAaron LIFor a list of all the protocol name to number mappings used by
1569d27abe81SAaron LI.Xr pfctl 8 ,
1570d27abe81SAaron LIsee the file
1571d27abe81SAaron LI.Pa /etc/protocols .
1572d27abe81SAaron LI.It Xo
1573d27abe81SAaron LI.Ar from Aq Ar source
1574d27abe81SAaron LI.Ar port Aq Ar source
1575d27abe81SAaron LI.Ar os Aq Ar source
1576d27abe81SAaron LI.Ar to Aq Ar dest
1577d27abe81SAaron LI.Ar port Aq Ar dest
1578d27abe81SAaron LI.Xc
1579d27abe81SAaron LIThis rule applies only to packets with the specified source and destination
1580d27abe81SAaron LIaddresses and ports.
1581d27abe81SAaron LI.Pp
1582d27abe81SAaron LIAddresses can be specified in CIDR notation (matching netblocks), as
15835304134cSAaron LIsymbolic host names, interface names or interface group names, or as any
15845304134cSAaron LIof the following keywords:
1585d27abe81SAaron LI.Pp
1586d27abe81SAaron LI.Bl -tag -width xxxxxxxxxxxxxx -compact
1587d27abe81SAaron LI.It Ar any
1588d27abe81SAaron LIAny address.
1589d27abe81SAaron LI.It Ar route Aq Ar label
1590d27abe81SAaron LIAny address whose associated route has label
1591d27abe81SAaron LI.Aq Ar label .
1592d27abe81SAaron LISee
1593d27abe81SAaron LI.Xr route 4
1594d27abe81SAaron LIand
1595d27abe81SAaron LI.Xr route 8 .
1596d27abe81SAaron LI.It Ar no-route
1597d27abe81SAaron LIAny address which is not currently routable.
1598d27abe81SAaron LI.It Ar urpf-failed
1599d27abe81SAaron LIAny source address that fails a unicast reverse path forwarding (URPF)
1600d27abe81SAaron LIcheck, i.e. packets coming in on an interface other than that which holds
1601d27abe81SAaron LIthe route back to the packet's source address.
1602d27abe81SAaron LI.It Aq Ar table
1603d27abe81SAaron LIAny address that matches the given table.
1604d27abe81SAaron LI.El
1605d27abe81SAaron LI.Pp
1606d27abe81SAaron LIRanges of addresses are specified by using the
1607d27abe81SAaron LI.Sq -
1608d27abe81SAaron LIoperator.
1609d27abe81SAaron LIFor instance:
1610d27abe81SAaron LI.Dq 10.1.1.10 - 10.1.1.12
1611d27abe81SAaron LImeans all addresses from 10.1.1.10 to 10.1.1.12,
1612d27abe81SAaron LIhence addresses 10.1.1.10, 10.1.1.11, and 10.1.1.12.
1613d27abe81SAaron LI.Pp
16145304134cSAaron LIInterface names and interface group names can have modifiers appended:
1615d27abe81SAaron LI.Pp
1616d27abe81SAaron LI.Bl -tag -width xxxxxxxxxxxx -compact
1617d27abe81SAaron LI.It Ar :network
1618d27abe81SAaron LITranslates to the network(s) attached to the interface.
1619d27abe81SAaron LI.It Ar :broadcast
1620d27abe81SAaron LITranslates to the interface's broadcast address(es).
1621d27abe81SAaron LI.It Ar :peer
16225304134cSAaron LITranslates to the point-to-point interface's peer address(es).
1623d27abe81SAaron LI.It Ar :0
1624*6aa338e1SAaron LIDo not include interface aliases and link-local v6 address(es).
1625d27abe81SAaron LI.El
1626d27abe81SAaron LI.Pp
1627d27abe81SAaron LIHost names may also have the
1628d27abe81SAaron LI.Ar :0
1629d27abe81SAaron LIoption appended to restrict the name resolution to the first of each
1630*6aa338e1SAaron LIv4 and non-link-local v6 address found.
1631d27abe81SAaron LI.Pp
1632d27abe81SAaron LIHost name resolution and interface to address translation are done at
1633d27abe81SAaron LIruleset load-time.
1634d27abe81SAaron LIWhen the address of an interface (or host name) changes (under DHCP or PPP,
1635d27abe81SAaron LIfor instance), the ruleset must be reloaded for the change to be reflected
1636d27abe81SAaron LIin the kernel.
1637d27abe81SAaron LISurrounding the interface name (and optional modifiers) in parentheses
1638d27abe81SAaron LIchanges this behaviour.
1639d27abe81SAaron LIWhen the interface name is surrounded by parentheses, the rule is
1640d27abe81SAaron LIautomatically updated whenever the interface changes its address.
1641d27abe81SAaron LIThe ruleset does not need to be reloaded.
1642d27abe81SAaron LIThis is especially useful with
1643d27abe81SAaron LI.Ar nat .
1644d27abe81SAaron LI.Pp
1645d27abe81SAaron LIPorts can be specified either by number or by name.
1646d27abe81SAaron LIFor example, port 80 can be specified as
1647d27abe81SAaron LI.Em www .
1648d27abe81SAaron LIFor a list of all port name to number mappings used by
1649d27abe81SAaron LI.Xr pfctl 8 ,
1650d27abe81SAaron LIsee the file
1651d27abe81SAaron LI.Pa /etc/services .
1652d27abe81SAaron LI.Pp
1653d27abe81SAaron LIPorts and ranges of ports are specified by using these operators:
1654d27abe81SAaron LI.Bd -literal -offset indent
1655d27abe81SAaron LI=	(equal)
1656d27abe81SAaron LI!=	(unequal)
1657d27abe81SAaron LI\*(Lt	(less than)
1658d27abe81SAaron LI\*(Le	(less than or equal)
1659d27abe81SAaron LI\*(Gt	(greater than)
1660d27abe81SAaron LI\*(Ge	(greater than or equal)
1661d27abe81SAaron LI:	(range including boundaries)
1662d27abe81SAaron LI\*(Gt\*(Lt	(range excluding boundaries)
1663d27abe81SAaron LI\*(Lt\*(Gt	(except range)
1664d27abe81SAaron LI.Ed
1665d27abe81SAaron LI.Pp
1666d27abe81SAaron LI.Sq \*(Gt\*(Lt ,
1667d27abe81SAaron LI.Sq \*(Lt\*(Gt
1668d27abe81SAaron LIand
1669d27abe81SAaron LI.Sq \&:
1670d27abe81SAaron LIare binary operators (they take two arguments).
1671d27abe81SAaron LIFor instance:
1672d27abe81SAaron LI.Bl -tag -width Fl
1673d27abe81SAaron LI.It Ar port 2000:2004
1674d27abe81SAaron LImeans
1675d27abe81SAaron LI.Sq all ports \*(Ge 2000 and \*(Le 2004 ,
1676d27abe81SAaron LIhence ports 2000, 2001, 2002, 2003 and 2004.
1677d27abe81SAaron LI.It Ar port 2000 \*(Gt\*(Lt 2004
1678d27abe81SAaron LImeans
1679d27abe81SAaron LI.Sq all ports \*(Gt 2000 and \*(Lt 2004 ,
1680d27abe81SAaron LIhence ports 2001, 2002 and 2003.
1681d27abe81SAaron LI.It Ar port 2000 \*(Lt\*(Gt 2004
1682d27abe81SAaron LImeans
1683d27abe81SAaron LI.Sq all ports \*(Lt 2000 or \*(Gt 2004 ,
1684d27abe81SAaron LIhence ports 1-1999 and 2005-65535.
1685d27abe81SAaron LI.El
1686d27abe81SAaron LI.Pp
1687d27abe81SAaron LIThe operating system of the source host can be specified in the case of TCP
1688d27abe81SAaron LIrules with the
1689d27abe81SAaron LI.Ar OS
1690d27abe81SAaron LImodifier.
1691d27abe81SAaron LISee the
1692d27abe81SAaron LI.Sx OPERATING SYSTEM FINGERPRINTING
1693d27abe81SAaron LIsection for more information.
1694d27abe81SAaron LI.Pp
1695d27abe81SAaron LIThe host, port and OS specifications are optional, as in the following examples:
1696d27abe81SAaron LI.Bd -literal -offset indent
1697d27abe81SAaron LIpass in all
1698d27abe81SAaron LIpass in from any to any
1699d27abe81SAaron LIpass in proto tcp from any port \*(Le 1024 to any
1700d27abe81SAaron LIpass in proto tcp from any to any port 25
1701d27abe81SAaron LIpass in proto tcp from 10.0.0.0/8 port \*(Gt 1024 \e
1702d27abe81SAaron LI      to ! 10.1.2.3 port != ssh
1703d27abe81SAaron LIpass in proto tcp from any os "OpenBSD"
1704d27abe81SAaron LIpass in proto tcp from route "DTAG"
1705d27abe81SAaron LI.Ed
1706d27abe81SAaron LI.It Ar all
1707d27abe81SAaron LIThis is equivalent to "from any to any".
1708d27abe81SAaron LI.It Ar group Aq Ar group
1709d27abe81SAaron LISimilar to
1710d27abe81SAaron LI.Ar user ,
1711d27abe81SAaron LIthis rule only applies to packets of sockets owned by the specified group.
1712d27abe81SAaron LI.It Ar user Aq Ar user
1713d27abe81SAaron LIThis rule only applies to packets of sockets owned by the specified user.
1714d27abe81SAaron LIFor outgoing connections initiated from the firewall, this is the user
1715d27abe81SAaron LIthat opened the connection.
1716d27abe81SAaron LIFor incoming connections to the firewall itself, this is the user that
1717d27abe81SAaron LIlistens on the destination port.
1718d27abe81SAaron LIFor forwarded connections, where the firewall is not a connection endpoint,
1719d27abe81SAaron LIthe user and group are
1720d27abe81SAaron LI.Em unknown .
1721d27abe81SAaron LI.Pp
1722d27abe81SAaron LIAll packets, both outgoing and incoming, of one connection are associated
1723d27abe81SAaron LIwith the same user and group.
1724d27abe81SAaron LIOnly TCP and UDP packets can be associated with users; for other protocols
1725d27abe81SAaron LIthese parameters are ignored.
1726d27abe81SAaron LI.Pp
1727d27abe81SAaron LIUser and group refer to the effective (as opposed to the real) IDs, in
1728d27abe81SAaron LIcase the socket is created by a setuid/setgid process.
1729d27abe81SAaron LIUser and group IDs are stored when a socket is created;
1730d27abe81SAaron LIwhen a process creates a listening socket as root (for instance, by
1731d27abe81SAaron LIbinding to a privileged port) and subsequently changes to another
1732d27abe81SAaron LIuser ID (to drop privileges), the credentials will remain root.
1733d27abe81SAaron LI.Pp
1734d27abe81SAaron LIUser and group IDs can be specified as either numbers or names.
1735d27abe81SAaron LIThe syntax is similar to the one for ports.
1736d27abe81SAaron LIThe value
1737d27abe81SAaron LI.Em unknown
1738d27abe81SAaron LImatches packets of forwarded connections.
1739d27abe81SAaron LI.Em unknown
1740d27abe81SAaron LIcan only be used with the operators
1741d27abe81SAaron LI.Cm =
1742d27abe81SAaron LIand
1743d27abe81SAaron LI.Cm != .
1744d27abe81SAaron LIOther constructs like
1745d27abe81SAaron LI.Cm user \*(Ge unknown
1746d27abe81SAaron LIare invalid.
1747d27abe81SAaron LIForwarded packets with unknown user and group ID match only rules
1748d27abe81SAaron LIthat explicitly compare against
1749d27abe81SAaron LI.Em unknown
1750d27abe81SAaron LIwith the operators
1751d27abe81SAaron LI.Cm =
1752d27abe81SAaron LIor
1753d27abe81SAaron LI.Cm != .
1754d27abe81SAaron LIFor instance
1755d27abe81SAaron LI.Cm user \*(Ge 0
1756d27abe81SAaron LIdoes not match forwarded packets.
1757d27abe81SAaron LIThe following example allows only selected users to open outgoing
1758d27abe81SAaron LIconnections:
1759d27abe81SAaron LI.Bd -literal -offset indent
1760d27abe81SAaron LIblock out proto { tcp, udp } all
1761d27abe81SAaron LIpass  out proto { tcp, udp } all user { \*(Lt 1000, dhartmei }
1762d27abe81SAaron LI.Ed
1763d27abe81SAaron LI.It Xo Ar flags Aq Ar a
1764d27abe81SAaron LI.Pf / Ns Aq Ar b
1765d27abe81SAaron LI.No \*(Ba / Ns Aq Ar b
1766d27abe81SAaron LI.No \*(Ba any
1767d27abe81SAaron LI.Xc
1768d27abe81SAaron LIThis rule only applies to TCP packets that have the flags
1769d27abe81SAaron LI.Aq Ar a
1770d27abe81SAaron LIset out of set
1771d27abe81SAaron LI.Aq Ar b .
1772d27abe81SAaron LIFlags not specified in
1773d27abe81SAaron LI.Aq Ar b
1774d27abe81SAaron LIare ignored.
1775d27abe81SAaron LIFor stateful connections, the default is
1776d27abe81SAaron LI.Ar flags S/SA .
1777d27abe81SAaron LITo indicate that flags should not be checked at all, specify
1778d27abe81SAaron LI.Ar flags any .
1779d27abe81SAaron LIThe flags are: (F)IN, (S)YN, (R)ST, (P)USH, (A)CK, (U)RG, (E)CE, and C(W)R.
1780d27abe81SAaron LI.Bl -tag -width Fl
1781d27abe81SAaron LI.It Ar flags S/S
1782d27abe81SAaron LIFlag SYN is set.
1783d27abe81SAaron LIThe other flags are ignored.
1784d27abe81SAaron LI.It Ar flags S/SA
1785d27abe81SAaron LIThis is the default setting for stateful connections.
1786d27abe81SAaron LIOut of SYN and ACK, exactly SYN may be set.
1787d27abe81SAaron LISYN, SYN+PSH and SYN+RST match, but SYN+ACK, ACK and ACK+RST do not.
1788d27abe81SAaron LIThis is more restrictive than the previous example.
1789d27abe81SAaron LI.It Ar flags /SFRA
1790d27abe81SAaron LIIf the first set is not specified, it defaults to none.
1791d27abe81SAaron LIAll of SYN, FIN, RST and ACK must be unset.
1792d27abe81SAaron LI.El
1793d27abe81SAaron LI.Pp
1794d27abe81SAaron LIBecause
1795d27abe81SAaron LI.Ar flags S/SA
1796d27abe81SAaron LIis applied by default (unless
1797d27abe81SAaron LI.Ar no state
1798d27abe81SAaron LIis specified), only the initial SYN packet of a TCP handshake will create
1799d27abe81SAaron LIa state for a TCP connection.
1800d27abe81SAaron LIIt is possible to be less restrictive, and allow state creation from
1801d27abe81SAaron LIintermediate
1802d27abe81SAaron LI.Pq non-SYN
1803d27abe81SAaron LIpackets, by specifying
1804d27abe81SAaron LI.Ar flags any .
1805d27abe81SAaron LIThis will cause
1806d27abe81SAaron LI.Xr pf 4
1807d27abe81SAaron LIto synchronize to existing connections, for instance
1808d27abe81SAaron LIif one flushes the state table.
1809d27abe81SAaron LIHowever, states created from such intermediate packets may be missing
1810d27abe81SAaron LIconnection details such as the TCP window scaling factor.
1811d27abe81SAaron LIStates which modify the packet flow, such as those affected by
1812d27abe81SAaron LI.Ar nat , binat No or Ar rdr
1813d27abe81SAaron LIrules,
1814d27abe81SAaron LI.Ar modulate No or Ar synproxy state
1815d27abe81SAaron LIoptions, or scrubbed with
1816d27abe81SAaron LI.Ar reassemble tcp
1817d27abe81SAaron LIwill also not be recoverable from intermediate packets.
1818d27abe81SAaron LISuch connections will stall and time out.
1819d27abe81SAaron LI.It Xo Ar icmp-type Aq Ar type
1820d27abe81SAaron LI.Ar code Aq Ar code
1821d27abe81SAaron LI.Xc
1822d27abe81SAaron LI.It Xo Ar icmp6-type Aq Ar type
1823d27abe81SAaron LI.Ar code Aq Ar code
1824d27abe81SAaron LI.Xc
1825d27abe81SAaron LIThis rule only applies to ICMP or ICMPv6 packets with the specified type
1826d27abe81SAaron LIand code.
1827d27abe81SAaron LIText names for ICMP types and codes are listed in
1828d27abe81SAaron LI.Xr icmp 4
1829d27abe81SAaron LIand
1830d27abe81SAaron LI.Xr icmp6 4 .
1831d27abe81SAaron LIThis parameter is only valid for rules that cover protocols ICMP or
1832d27abe81SAaron LIICMP6.
1833d27abe81SAaron LIThe protocol and the ICMP type indicator
1834d27abe81SAaron LI.Po
1835d27abe81SAaron LI.Ar icmp-type
1836d27abe81SAaron LIor
1837d27abe81SAaron LI.Ar icmp6-type
1838d27abe81SAaron LI.Pc
1839d27abe81SAaron LImust match.
1840d27abe81SAaron LI.It Xo Ar tos Aq Ar string
1841d27abe81SAaron LI.No \*(Ba Aq Ar number
1842d27abe81SAaron LI.Xc
1843d27abe81SAaron LIThis rule applies to packets with the specified
1844d27abe81SAaron LI.Em TOS
1845d27abe81SAaron LIbits set.
1846d27abe81SAaron LI.Em TOS
1847d27abe81SAaron LImay be
1848d27abe81SAaron LIgiven as one of
1849d27abe81SAaron LI.Ar lowdelay ,
1850d27abe81SAaron LI.Ar throughput ,
1851d27abe81SAaron LI.Ar reliability ,
1852d27abe81SAaron LIor as either hex or decimal.
1853d27abe81SAaron LI.Pp
1854d27abe81SAaron LIFor example, the following rules are identical:
1855d27abe81SAaron LI.Bd -literal -offset indent
1856d27abe81SAaron LIpass all tos lowdelay
1857d27abe81SAaron LIpass all tos 0x10
1858d27abe81SAaron LIpass all tos 16
1859d27abe81SAaron LI.Ed
1860d27abe81SAaron LI.It Ar allow-opts
1861d27abe81SAaron LIBy default, IPv4 packets with IP options or IPv6 packets with routing
1862d27abe81SAaron LIextension headers are blocked.
1863d27abe81SAaron LIWhen
1864d27abe81SAaron LI.Ar allow-opts
1865d27abe81SAaron LIis specified for a
1866d27abe81SAaron LI.Ar pass
1867d27abe81SAaron LIrule, packets that pass the filter based on that rule (last matching)
1868d27abe81SAaron LIdo so even if they contain IP options or routing extension headers.
1869d27abe81SAaron LIFor packets that match state, the rule that initially created the
1870d27abe81SAaron LIstate is used.
1871d27abe81SAaron LIThe implicit
1872d27abe81SAaron LI.Ar pass
1873d27abe81SAaron LIrule that is used when a packet does not match any rules does not
1874d27abe81SAaron LIallow IP options.
1875d27abe81SAaron LI.It Ar label Aq Ar string
1876d27abe81SAaron LIAdds a label (name) to the rule, which can be used to identify the rule.
1877d27abe81SAaron LIFor instance,
1878d27abe81SAaron LIpfctl -s labels
1879d27abe81SAaron LIshows per-rule statistics for rules that have labels.
1880d27abe81SAaron LI.Pp
1881d27abe81SAaron LIThe following macros can be used in labels:
1882d27abe81SAaron LI.Pp
1883d27abe81SAaron LI.Bl -tag -width $srcaddr -compact -offset indent
1884d27abe81SAaron LI.It Ar $if
1885d27abe81SAaron LIThe interface.
1886d27abe81SAaron LI.It Ar $srcaddr
1887d27abe81SAaron LIThe source IP address.
1888d27abe81SAaron LI.It Ar $dstaddr
1889d27abe81SAaron LIThe destination IP address.
1890d27abe81SAaron LI.It Ar $srcport
1891d27abe81SAaron LIThe source port specification.
1892d27abe81SAaron LI.It Ar $dstport
1893d27abe81SAaron LIThe destination port specification.
1894d27abe81SAaron LI.It Ar $proto
1895d27abe81SAaron LIThe protocol name.
1896d27abe81SAaron LI.It Ar $nr
1897d27abe81SAaron LIThe rule number.
1898d27abe81SAaron LI.El
1899d27abe81SAaron LI.Pp
1900d27abe81SAaron LIFor example:
1901d27abe81SAaron LI.Bd -literal -offset indent
1902d27abe81SAaron LIips = \&"{ 1.2.3.4, 1.2.3.5 }\&"
1903d27abe81SAaron LIpass in proto tcp from any to $ips \e
1904d27abe81SAaron LI      port \*(Gt 1023 label \&"$dstaddr:$dstport\&"
1905d27abe81SAaron LI.Ed
1906d27abe81SAaron LI.Pp
1907d27abe81SAaron LIexpands to
1908d27abe81SAaron LI.Bd -literal -offset indent
1909d27abe81SAaron LIpass in inet proto tcp from any to 1.2.3.4 \e
1910d27abe81SAaron LI      port \*(Gt 1023 label \&"1.2.3.4:\*(Gt1023\&"
1911d27abe81SAaron LIpass in inet proto tcp from any to 1.2.3.5 \e
1912d27abe81SAaron LI      port \*(Gt 1023 label \&"1.2.3.5:\*(Gt1023\&"
1913d27abe81SAaron LI.Ed
1914d27abe81SAaron LI.Pp
1915d27abe81SAaron LIThe macro expansion for the
1916d27abe81SAaron LI.Ar label
1917d27abe81SAaron LIdirective occurs only at configuration file parse time, not during runtime.
1918d27abe81SAaron LI.It Xo Ar queue Aq Ar queue
1919d27abe81SAaron LI.No \*(Ba ( Aq Ar queue ,
1920d27abe81SAaron LI.Aq Ar queue )
1921d27abe81SAaron LI.Xc
1922d27abe81SAaron LIPackets matching this rule will be assigned to the specified queue.
1923d27abe81SAaron LIIf two queues are given, packets which have a
1924d27abe81SAaron LI.Em TOS
1925d27abe81SAaron LIof
1926d27abe81SAaron LI.Em lowdelay
1927d27abe81SAaron LIand TCP ACKs with no data payload will be assigned to the second one.
1928d27abe81SAaron LISee
1929d27abe81SAaron LI.Sx QUEUEING
1930d27abe81SAaron LIfor setup details.
1931d27abe81SAaron LI.Pp
1932d27abe81SAaron LIFor example:
1933d27abe81SAaron LI.Bd -literal -offset indent
1934d27abe81SAaron LIpass in proto tcp to port 25 queue mail
1935d27abe81SAaron LIpass in proto tcp to port 22 queue(ssh_bulk, ssh_prio)
1936d27abe81SAaron LI.Ed
1937d27abe81SAaron LI.It Ar tag Aq Ar string
1938d27abe81SAaron LIPackets matching this rule will be tagged with the
1939d27abe81SAaron LIspecified string.
1940d27abe81SAaron LIThe tag acts as an internal marker that can be used to
1941d27abe81SAaron LIidentify these packets later on.
1942d27abe81SAaron LIThis can be used, for example, to provide trust between
1943d27abe81SAaron LIinterfaces and to determine if packets have been
1944d27abe81SAaron LIprocessed by translation rules.
1945d27abe81SAaron LITags are
1946d27abe81SAaron LI.Qq sticky ,
1947d27abe81SAaron LImeaning that the packet will be tagged even if the rule
1948d27abe81SAaron LIis not the last matching rule.
1949d27abe81SAaron LIFurther matching rules can replace the tag with a
1950d27abe81SAaron LInew one but will not remove a previously applied tag.
1951d27abe81SAaron LIA packet is only ever assigned one tag at a time.
1952d27abe81SAaron LIPacket tagging can be done during
1953d27abe81SAaron LI.Ar nat ,
1954d27abe81SAaron LI.Ar rdr ,
1955d27abe81SAaron LIor
1956d27abe81SAaron LI.Ar binat
1957d27abe81SAaron LIrules in addition to filter rules.
1958d27abe81SAaron LITags take the same macros as labels (see above).
1959d27abe81SAaron LI.It Ar tagged Aq Ar string
1960d27abe81SAaron LIUsed with filter, translation or scrub rules
1961d27abe81SAaron LIto specify that packets must already
1962d27abe81SAaron LIbe tagged with the given tag in order to match the rule.
1963d27abe81SAaron LIInverse tag matching can also be done
1964d27abe81SAaron LIby specifying the
1965d27abe81SAaron LI.Cm !\&
1966d27abe81SAaron LIoperator before the
1967d27abe81SAaron LI.Ar tagged
1968d27abe81SAaron LIkeyword.
1969d27abe81SAaron LI.It Ar rtable Aq Ar number
1970d27abe81SAaron LIUsed to select an alternate routing table for the routing lookup.
1971d27abe81SAaron LIOnly effective before the route lookup happened, i.e. when filtering inbound.
1972d27abe81SAaron LI.It Xo Ar divert-to Aq Ar host
1973d27abe81SAaron LI.Ar port Aq Ar port
1974d27abe81SAaron LI.Xc
1975d27abe81SAaron LIUsed to redirect packets to a local socket bound to
1976d27abe81SAaron LI.Ar host
1977d27abe81SAaron LIand
1978d27abe81SAaron LI.Ar port .
1979d27abe81SAaron LIThe packets will not be modified, so
1980d27abe81SAaron LI.Xr getsockname 2
1981d27abe81SAaron LIon the socket will return the original destination address of the packet.
1982d27abe81SAaron LI.It Ar divert-reply
1983d27abe81SAaron LIUsed to receive replies for sockets that are bound to addresses
1984d27abe81SAaron LIwhich are not local to the machine.
1985d27abe81SAaron LISee
1986d27abe81SAaron LI.Xr setsockopt 2
1987d27abe81SAaron LIfor information on how to bind these sockets.
1988d27abe81SAaron LI.It Ar probability Aq Ar number
1989d27abe81SAaron LIA probability attribute can be attached to a rule, with a value set between
1990d27abe81SAaron LI0 and 1, bounds not included.
1991d27abe81SAaron LIIn that case, the rule will be honoured using the given probability value
1992d27abe81SAaron LIonly.
1993d27abe81SAaron LIFor example, the following rule will drop 20% of incoming ICMP packets:
1994d27abe81SAaron LI.Bd -literal -offset indent
1995d27abe81SAaron LIblock in proto icmp probability 20%
1996d27abe81SAaron LI.Ed
1997d27abe81SAaron LI.El
1998d27abe81SAaron LI.Sh ROUTING
1999d27abe81SAaron LIIf a packet matches a rule with a route option set, the packet filter will
2000d27abe81SAaron LIroute the packet according to the type of route option.
2001d27abe81SAaron LIWhen such a rule creates state, the route option is also applied to all
2002d27abe81SAaron LIpackets matching the same connection.
2003d27abe81SAaron LI.Bl -tag -width xxxx
2004d27abe81SAaron LI.It Ar fastroute
2005d27abe81SAaron LIThe
2006d27abe81SAaron LI.Ar fastroute
2007d27abe81SAaron LIoption does a normal route lookup to find the next hop for the packet.
2008d27abe81SAaron LI.It Ar route-to
2009d27abe81SAaron LIThe
2010d27abe81SAaron LI.Ar route-to
2011d27abe81SAaron LIoption routes the packet to the specified interface with an optional address
2012d27abe81SAaron LIfor the next hop.
2013d27abe81SAaron LIWhen a
2014d27abe81SAaron LI.Ar route-to
2015d27abe81SAaron LIrule creates state, only packets that pass in the same direction as the
2016d27abe81SAaron LIfilter rule specifies will be routed in this way.
2017d27abe81SAaron LIPackets passing in the opposite direction (replies) are not affected
2018d27abe81SAaron LIand are routed normally.
2019d27abe81SAaron LI.It Ar reply-to
2020d27abe81SAaron LIThe
2021d27abe81SAaron LI.Ar reply-to
2022d27abe81SAaron LIoption is similar to
2023d27abe81SAaron LI.Ar route-to ,
2024d27abe81SAaron LIbut routes packets that pass in the opposite direction (replies) to the
2025d27abe81SAaron LIspecified interface.
2026d27abe81SAaron LIOpposite direction is only defined in the context of a state entry, and
2027d27abe81SAaron LI.Ar reply-to
2028d27abe81SAaron LIis useful only in rules that create state.
2029d27abe81SAaron LIIt can be used on systems with multiple external connections to
2030d27abe81SAaron LIroute all outgoing packets of a connection through the interface
2031d27abe81SAaron LIthe incoming connection arrived through (symmetric routing enforcement).
2032d27abe81SAaron LI.It Ar dup-to
2033d27abe81SAaron LIThe
2034d27abe81SAaron LI.Ar dup-to
2035d27abe81SAaron LIoption creates a duplicate of the packet and routes it like
2036d27abe81SAaron LI.Ar route-to .
2037d27abe81SAaron LIThe original packet gets routed as it normally would.
2038d27abe81SAaron LI.El
2039d27abe81SAaron LI.Sh POOL OPTIONS
2040d27abe81SAaron LIFor
2041d27abe81SAaron LI.Ar nat
2042d27abe81SAaron LIand
2043d27abe81SAaron LI.Ar rdr
2044d27abe81SAaron LIrules, (as well as for the
2045d27abe81SAaron LI.Ar route-to ,
2046d27abe81SAaron LI.Ar reply-to
2047d27abe81SAaron LIand
2048d27abe81SAaron LI.Ar dup-to
2049d27abe81SAaron LIrule options) for which there is a single redirection address which has a
2050d27abe81SAaron LIsubnet mask smaller than 32 for IPv4 or 128 for IPv6 (more than one IP
2051d27abe81SAaron LIaddress), a variety of different methods for assigning this address can be
2052d27abe81SAaron LIused:
2053d27abe81SAaron LI.Bl -tag -width xxxx
2054d27abe81SAaron LI.It Ar bitmask
2055d27abe81SAaron LIThe
2056d27abe81SAaron LI.Ar bitmask
2057d27abe81SAaron LIoption applies the network portion of the redirection address to the address
2058d27abe81SAaron LIto be modified (source with
2059d27abe81SAaron LI.Ar nat ,
2060d27abe81SAaron LIdestination with
2061d27abe81SAaron LI.Ar rdr ) .
2062d27abe81SAaron LI.It Ar random
2063d27abe81SAaron LIThe
2064d27abe81SAaron LI.Ar random
2065d27abe81SAaron LIoption selects an address at random within the defined block of addresses.
2066d27abe81SAaron LI.It Ar source-hash
2067d27abe81SAaron LIThe
2068d27abe81SAaron LI.Ar source-hash
2069d27abe81SAaron LIoption uses a hash of the source address to determine the redirection address,
2070d27abe81SAaron LIensuring that the redirection address is always the same for a given source.
2071d27abe81SAaron LIAn optional key can be specified after this keyword either in hex or as a
2072d27abe81SAaron LIstring; by default
2073d27abe81SAaron LI.Xr pfctl 8
2074d27abe81SAaron LIrandomly generates a key for source-hash every time the
2075d27abe81SAaron LIruleset is reloaded.
2076d27abe81SAaron LI.It Ar round-robin
2077d27abe81SAaron LIThe
2078d27abe81SAaron LI.Ar round-robin
2079d27abe81SAaron LIoption loops through the redirection address(es).
2080d27abe81SAaron LI.Pp
2081d27abe81SAaron LIWhen more than one redirection address is specified,
2082d27abe81SAaron LI.Ar round-robin
2083d27abe81SAaron LIis the only permitted pool type.
2084d27abe81SAaron LI.It Ar static-port
2085d27abe81SAaron LIWith
2086d27abe81SAaron LI.Ar nat
2087d27abe81SAaron LIrules, the
2088d27abe81SAaron LI.Ar static-port
2089d27abe81SAaron LIoption prevents
2090d27abe81SAaron LI.Xr pf 4
2091d27abe81SAaron LIfrom modifying the source port on TCP and UDP packets.
2092d27abe81SAaron LI.El
2093d27abe81SAaron LI.Pp
2094d27abe81SAaron LIAdditionally, the
2095d27abe81SAaron LI.Ar sticky-address
2096d27abe81SAaron LIoption can be specified to help ensure that multiple connections from the
2097d27abe81SAaron LIsame source are mapped to the same redirection address.
2098d27abe81SAaron LIThis option can be used with the
2099d27abe81SAaron LI.Ar random
2100d27abe81SAaron LIand
2101d27abe81SAaron LI.Ar round-robin
2102d27abe81SAaron LIpool options.
2103d27abe81SAaron LINote that by default these associations are destroyed as soon as there are
2104d27abe81SAaron LIno longer states which refer to them; in order to make the mappings last
2105d27abe81SAaron LIbeyond the lifetime of the states, increase the global options with
2106d27abe81SAaron LI.Ar set timeout src.track .
2107d27abe81SAaron LISee
2108d27abe81SAaron LI.Sx STATEFUL TRACKING OPTIONS
2109d27abe81SAaron LIfor more ways to control the source tracking.
2110d27abe81SAaron LI.Sh STATE MODULATION
2111d27abe81SAaron LIMuch of the security derived from TCP is attributable to how well the
2112d27abe81SAaron LIinitial sequence numbers (ISNs) are chosen.
2113d27abe81SAaron LISome popular stack implementations choose
2114d27abe81SAaron LI.Em very
2115d27abe81SAaron LIpoor ISNs and thus are normally susceptible to ISN prediction exploits.
2116d27abe81SAaron LIBy applying a
2117d27abe81SAaron LI.Ar modulate state
2118d27abe81SAaron LIrule to a TCP connection,
2119d27abe81SAaron LI.Xr pf 4
2120d27abe81SAaron LIwill create a high quality random sequence number for each connection
2121d27abe81SAaron LIendpoint.
2122d27abe81SAaron LI.Pp
2123d27abe81SAaron LIThe
2124d27abe81SAaron LI.Ar modulate state
2125d27abe81SAaron LIdirective implicitly keeps state on the rule and is
2126d27abe81SAaron LIonly applicable to TCP connections.
2127d27abe81SAaron LI.Pp
2128d27abe81SAaron LIFor instance:
2129d27abe81SAaron LI.Bd -literal -offset indent
2130d27abe81SAaron LIblock all
2131d27abe81SAaron LIpass out proto tcp from any to any modulate state
2132d27abe81SAaron LIpass in  proto tcp from any to any port 25 flags S/SFRA modulate state
2133d27abe81SAaron LI.Ed
2134d27abe81SAaron LI.Pp
2135d27abe81SAaron LINote that modulated connections will not recover when the state table
2136d27abe81SAaron LIis lost (firewall reboot, flushing the state table, etc...).
2137d27abe81SAaron LI.Xr pf 4
2138d27abe81SAaron LIwill not be able to infer a connection again after the state table flushes
2139d27abe81SAaron LIthe connection's modulator.
2140d27abe81SAaron LIWhen the state is lost, the connection may be left dangling until the
2141d27abe81SAaron LIrespective endpoints time out the connection.
2142d27abe81SAaron LIIt is possible on a fast local network for the endpoints to start an ACK
2143d27abe81SAaron LIstorm while trying to resynchronize after the loss of the modulator.
2144d27abe81SAaron LIThe default
2145d27abe81SAaron LI.Ar flags
2146d27abe81SAaron LIsettings (or a more strict equivalent) should be used on
2147d27abe81SAaron LI.Ar modulate state
2148d27abe81SAaron LIrules to prevent ACK storms.
2149d27abe81SAaron LI.Pp
2150d27abe81SAaron LINote that alternative methods are available
2151d27abe81SAaron LIto prevent loss of the state table
2152d27abe81SAaron LIand allow for firewall failover.
2153d27abe81SAaron LISee
2154d27abe81SAaron LI.Xr carp 4
2155d27abe81SAaron LIand
2156d27abe81SAaron LI.Xr pfsync 4
2157d27abe81SAaron LIfor further information.
2158d27abe81SAaron LI.Sh SYN PROXY
2159d27abe81SAaron LIBy default,
2160d27abe81SAaron LI.Xr pf 4
2161d27abe81SAaron LIpasses packets that are part of a
2162d27abe81SAaron LI.Xr tcp 4
2163d27abe81SAaron LIhandshake between the endpoints.
2164d27abe81SAaron LIThe
2165d27abe81SAaron LI.Ar synproxy state
2166d27abe81SAaron LIoption can be used to cause
2167d27abe81SAaron LI.Xr pf 4
2168d27abe81SAaron LIitself to complete the handshake with the active endpoint, perform a handshake
2169d27abe81SAaron LIwith the passive endpoint, and then forward packets between the endpoints.
2170d27abe81SAaron LI.Pp
2171d27abe81SAaron LINo packets are sent to the passive endpoint before the active endpoint has
2172d27abe81SAaron LIcompleted the handshake, hence so-called SYN floods with spoofed source
2173d27abe81SAaron LIaddresses will not reach the passive endpoint, as the sender can't complete the
2174d27abe81SAaron LIhandshake.
2175d27abe81SAaron LI.Pp
2176d27abe81SAaron LIThe proxy is transparent to both endpoints, they each see a single
2177d27abe81SAaron LIconnection from/to the other endpoint.
2178d27abe81SAaron LI.Xr pf 4
2179d27abe81SAaron LIchooses random initial sequence numbers for both handshakes.
2180d27abe81SAaron LIOnce the handshakes are completed, the sequence number modulators
2181d27abe81SAaron LI(see previous section) are used to translate further packets of the
2182d27abe81SAaron LIconnection.
2183d27abe81SAaron LI.Ar synproxy state
2184d27abe81SAaron LIincludes
2185d27abe81SAaron LI.Ar modulate state .
2186d27abe81SAaron LI.Pp
2187d27abe81SAaron LIRules with
2188d27abe81SAaron LI.Ar synproxy
2189d27abe81SAaron LIwill not work if
2190d27abe81SAaron LI.Xr pf 4
2191d27abe81SAaron LIoperates on a
2192d27abe81SAaron LI.Xr bridge 4 .
2193d27abe81SAaron LI.Pp
2194d27abe81SAaron LIExample:
2195d27abe81SAaron LI.Bd -literal -offset indent
2196d27abe81SAaron LIpass in proto tcp from any to any port www synproxy state
2197d27abe81SAaron LI.Ed
2198d27abe81SAaron LI.Sh STATEFUL TRACKING OPTIONS
2199d27abe81SAaron LIA number of options related to stateful tracking can be applied on a
2200d27abe81SAaron LIper-rule basis.
2201d27abe81SAaron LI.Ar keep state ,
2202d27abe81SAaron LI.Ar modulate state
2203d27abe81SAaron LIand
2204d27abe81SAaron LI.Ar synproxy state
2205d27abe81SAaron LIsupport these options, and
2206d27abe81SAaron LI.Ar keep state
2207d27abe81SAaron LImust be specified explicitly to apply options to a rule.
2208d27abe81SAaron LI.Pp
2209d27abe81SAaron LI.Bl -tag -width xxxx -compact
2210d27abe81SAaron LI.It Ar max Aq Ar number
2211d27abe81SAaron LILimits the number of concurrent states the rule may create.
2212d27abe81SAaron LIWhen this limit is reached, further packets that would create
2213d27abe81SAaron LIstate will not match this rule until existing states time out.
2214d27abe81SAaron LI.It Ar no-sync
2215d27abe81SAaron LIPrevent state changes for states created by this rule from appearing on the
2216d27abe81SAaron LI.Xr pfsync 4
2217d27abe81SAaron LIinterface.
2218d27abe81SAaron LI.It Xo Aq Ar timeout
2219d27abe81SAaron LI.Aq Ar seconds
2220d27abe81SAaron LI.Xc
2221d27abe81SAaron LIChanges the timeout values used for states created by this rule.
2222d27abe81SAaron LIFor a list of all valid timeout names, see
2223d27abe81SAaron LI.Sx OPTIONS
2224d27abe81SAaron LIabove.
2225d27abe81SAaron LI.It Ar sloppy
2226d27abe81SAaron LIUses a sloppy TCP connection tracker that does not check sequence
2227d27abe81SAaron LInumbers at all, which makes insertion and ICMP teardown attacks way
2228d27abe81SAaron LIeasier.
2229d27abe81SAaron LIThis is intended to be used in situations where one does not see all
2230d27abe81SAaron LIpackets of a connection, e.g. in asymmetric routing situations.
2231d27abe81SAaron LICannot be used with modulate or synproxy state.
2232d27abe81SAaron LI.El
2233d27abe81SAaron LI.Pp
2234d27abe81SAaron LIMultiple options can be specified, separated by commas:
2235d27abe81SAaron LI.Bd -literal -offset indent
2236d27abe81SAaron LIpass in proto tcp from any to any \e
2237d27abe81SAaron LI      port www keep state \e
2238d27abe81SAaron LI      (max 100, source-track rule, max-src-nodes 75, \e
2239d27abe81SAaron LI      max-src-states 3, tcp.established 60, tcp.closing 5)
2240d27abe81SAaron LI.Ed
2241d27abe81SAaron LI.Pp
2242d27abe81SAaron LIWhen the
2243d27abe81SAaron LI.Ar source-track
2244d27abe81SAaron LIkeyword is specified, the number of states per source IP is tracked.
2245d27abe81SAaron LI.Pp
2246d27abe81SAaron LI.Bl -tag -width xxxx -compact
2247d27abe81SAaron LI.It Ar source-track rule
2248d27abe81SAaron LIThe maximum number of states created by this rule is limited by the rule's
2249d27abe81SAaron LI.Ar max-src-nodes
2250d27abe81SAaron LIand
2251d27abe81SAaron LI.Ar max-src-states
2252d27abe81SAaron LIoptions.
2253d27abe81SAaron LIOnly state entries created by this particular rule count toward the rule's
2254d27abe81SAaron LIlimits.
2255d27abe81SAaron LI.It Ar source-track global
2256d27abe81SAaron LIThe number of states created by all rules that use this option is limited.
2257d27abe81SAaron LIEach rule can specify different
2258d27abe81SAaron LI.Ar max-src-nodes
2259d27abe81SAaron LIand
2260d27abe81SAaron LI.Ar max-src-states
2261d27abe81SAaron LIoptions, however state entries created by any participating rule count towards
2262d27abe81SAaron LIeach individual rule's limits.
2263d27abe81SAaron LI.El
2264d27abe81SAaron LI.Pp
2265d27abe81SAaron LIThe following limits can be set:
2266d27abe81SAaron LI.Pp
2267d27abe81SAaron LI.Bl -tag -width xxxx -compact
2268d27abe81SAaron LI.It Ar max-src-nodes Aq Ar number
2269d27abe81SAaron LILimits the maximum number of source addresses which can simultaneously
2270d27abe81SAaron LIhave state table entries.
2271d27abe81SAaron LI.It Ar max-src-states Aq Ar number
2272d27abe81SAaron LILimits the maximum number of simultaneous state entries that a single
2273d27abe81SAaron LIsource address can create with this rule.
2274d27abe81SAaron LI.It Ar pickups
2275d27abe81SAaron LISpecify that mid-stream pickups are to be allowed.
2276d27abe81SAaron LIThe default is to NOT allow mid-stream pickups and implies flags
2277d27abe81SAaron LIS/SA for TCP connections.
2278d27abe81SAaron LIIf pickups are enabled, flags S/SA are not implied
2279d27abe81SAaron LIfor TCP connections and state can be created for any packet.
2280d27abe81SAaron LI.Pp
2281d27abe81SAaron LIThe implied flags parameters need not be specified in either case
2282d27abe81SAaron LIunless you explicitly wish to override them, which also allows
2283d27abe81SAaron LIyou to roll-up several protocols into a single rule.
2284d27abe81SAaron LI.Pp
2285d27abe81SAaron LICertain validations are disabled when mid-stream pickups occur.
2286d27abe81SAaron LIFor example, the window scaling options are not known for
2287d27abe81SAaron LITCP pickups and sequence space comparisons must be disabled.
2288d27abe81SAaron LI.Pp
2289d27abe81SAaron LIThis does not effect state representing fully quantified
2290d27abe81SAaron LIconnections (for which the SYN/SYN-ACK passed through the routing
2291d27abe81SAaron LIengine).
2292d27abe81SAaron LIThose connections continue to be fully validated.
2293d27abe81SAaron LI.It Ar hash-only
2294d27abe81SAaron LISpecify that mid-stream pickups are to be allowed, but unconditionally
2295d27abe81SAaron LIdisables sequence space checks even if full state is available.
2296d27abe81SAaron LI.It Ar no-pickups
2297d27abe81SAaron LISpecify that mid-stream pickups are not to be allowed.
2298d27abe81SAaron LIThis is the
2299d27abe81SAaron LIdefault and this keyword does not normally need to be specified.
2300d27abe81SAaron LIHowever, if you are concerned about rule set portability then
2301d27abe81SAaron LIspecifying this keyword will at least result in an error from
2302d27abe81SAaron LI.Xr pfctl 8
2303d27abe81SAaron LIif it doesn't understand the feature.
2304d27abe81SAaron LITCP flags of S/SA are implied
2305d27abe81SAaron LIand do not need to explicitly specified.
2306d27abe81SAaron LI.El
2307d27abe81SAaron LI.Pp
2308d27abe81SAaron LIFor stateful TCP connections, limits on established connections (connections
2309d27abe81SAaron LIwhich have completed the TCP 3-way handshake) can also be enforced
2310d27abe81SAaron LIper source IP.
2311d27abe81SAaron LI.Pp
2312d27abe81SAaron LI.Bl -tag -width xxxx -compact
2313d27abe81SAaron LI.It Ar max-src-conn Aq Ar number
2314d27abe81SAaron LILimits the maximum number of simultaneous TCP connections which have
2315d27abe81SAaron LIcompleted the 3-way handshake that a single host can make.
2316d27abe81SAaron LI.It Xo Ar max-src-conn-rate Aq Ar number
2317d27abe81SAaron LI.No / Aq Ar seconds
2318d27abe81SAaron LI.Xc
2319d27abe81SAaron LILimit the rate of new connections over a time interval.
2320d27abe81SAaron LIThe connection rate is an approximation calculated as a moving average.
2321d27abe81SAaron LI.El
2322d27abe81SAaron LI.Pp
2323d27abe81SAaron LIBecause the 3-way handshake ensures that the source address is not being
2324d27abe81SAaron LIspoofed, more aggressive action can be taken based on these limits.
2325d27abe81SAaron LIWith the
2326d27abe81SAaron LI.Ar overload Aq Ar table
2327d27abe81SAaron LIstate option, source IP addresses which hit either of the limits on
2328d27abe81SAaron LIestablished connections will be added to the named table.
2329d27abe81SAaron LIThis table can be used in the ruleset to block further activity from
2330d27abe81SAaron LIthe offending host, redirect it to a tarpit process, or restrict its
2331d27abe81SAaron LIbandwidth.
2332d27abe81SAaron LI.Pp
2333d27abe81SAaron LIThe optional
2334d27abe81SAaron LI.Ar flush
2335d27abe81SAaron LIkeyword kills all states created by the matching rule which originate
2336d27abe81SAaron LIfrom the host which exceeds these limits.
2337d27abe81SAaron LIThe
2338d27abe81SAaron LI.Ar global
2339d27abe81SAaron LImodifier to the flush command kills all states originating from the
2340d27abe81SAaron LIoffending host, regardless of which rule created the state.
2341d27abe81SAaron LI.Pp
2342d27abe81SAaron LIFor example, the following rules will protect the webserver against
2343d27abe81SAaron LIhosts making more than 100 connections in 10 seconds.
2344d27abe81SAaron LIAny host which connects faster than this rate will have its address added
2345d27abe81SAaron LIto the
2346d27abe81SAaron LI.Aq bad_hosts
2347d27abe81SAaron LItable and have all states originating from it flushed.
2348d27abe81SAaron LIAny new packets arriving from this host will be dropped unconditionally
2349d27abe81SAaron LIby the block rule.
2350d27abe81SAaron LI.Bd -literal -offset indent
2351d27abe81SAaron LIblock quick from \*(Ltbad_hosts\*(Gt
2352d27abe81SAaron LIpass in on $ext_if proto tcp to $webserver port www keep state \e
2353d27abe81SAaron LI	(max-src-conn-rate 100/10, overload \*(Ltbad_hosts\*(Gt flush global)
2354d27abe81SAaron LI.Ed
2355d27abe81SAaron LI.Sh OPERATING SYSTEM FINGERPRINTING
2356d27abe81SAaron LIPassive OS Fingerprinting is a mechanism to inspect nuances of a TCP
2357d27abe81SAaron LIconnection's initial SYN packet and guess at the host's operating system.
2358d27abe81SAaron LIUnfortunately these nuances are easily spoofed by an attacker so the
2359d27abe81SAaron LIfingerprint is not useful in making security decisions.
2360d27abe81SAaron LIBut the fingerprint is typically accurate enough to make policy decisions
2361d27abe81SAaron LIupon.
2362d27abe81SAaron LI.Pp
2363d27abe81SAaron LIThe fingerprints may be specified by operating system class, by
2364d27abe81SAaron LIversion, or by subtype/patchlevel.
2365d27abe81SAaron LIThe class of an operating system is typically the vendor or genre
2366d27abe81SAaron LIand would be
2367d27abe81SAaron LI.Ox
2368d27abe81SAaron LIfor the
2369d27abe81SAaron LI.Xr pf 4
2370d27abe81SAaron LIfirewall itself.
2371d27abe81SAaron LIThe version of the oldest available
2372d27abe81SAaron LI.Ox
2373d27abe81SAaron LIrelease on the main FTP site
2374d27abe81SAaron LIwould be 2.6 and the fingerprint would be written
2375d27abe81SAaron LI.Pp
2376d27abe81SAaron LI.Dl \&"OpenBSD 2.6\&"
2377d27abe81SAaron LI.Pp
2378d27abe81SAaron LIThe subtype of an operating system is typically used to describe the
2379d27abe81SAaron LIpatchlevel if that patch led to changes in the TCP stack behavior.
2380d27abe81SAaron LIIn the case of
2381d27abe81SAaron LI.Ox ,
2382d27abe81SAaron LIthe only subtype is for a fingerprint that was
2383d27abe81SAaron LInormalized by the
2384d27abe81SAaron LI.Ar no-df
2385d27abe81SAaron LIscrub option and would be specified as
2386d27abe81SAaron LI.Pp
2387d27abe81SAaron LI.Dl \&"OpenBSD 3.3 no-df\&"
2388d27abe81SAaron LI.Pp
2389d27abe81SAaron LIFingerprints for most popular operating systems are provided by
2390d27abe81SAaron LI.Xr pf.os 5 .
2391d27abe81SAaron LIOnce
2392d27abe81SAaron LI.Xr pf 4
2393d27abe81SAaron LIis running, a complete list of known operating system fingerprints may
2394d27abe81SAaron LIbe listed by running:
2395d27abe81SAaron LI.Pp
2396d27abe81SAaron LI.Dl # pfctl -so
2397d27abe81SAaron LI.Pp
2398d27abe81SAaron LIFilter rules can enforce policy at any level of operating system specification
2399d27abe81SAaron LIassuming a fingerprint is present.
2400d27abe81SAaron LIPolicy could limit traffic to approved operating systems or even ban traffic
2401d27abe81SAaron LIfrom hosts that aren't at the latest service pack.
2402d27abe81SAaron LI.Pp
2403d27abe81SAaron LIThe
2404d27abe81SAaron LI.Ar unknown
2405d27abe81SAaron LIclass can also be used as the fingerprint which will match packets for
2406d27abe81SAaron LIwhich no operating system fingerprint is known.
2407d27abe81SAaron LI.Pp
2408d27abe81SAaron LIExamples:
2409d27abe81SAaron LI.Bd -literal -offset indent
2410d27abe81SAaron LIpass  out proto tcp from any os OpenBSD
2411d27abe81SAaron LIblock out proto tcp from any os Doors
2412d27abe81SAaron LIblock out proto tcp from any os "Doors PT"
2413d27abe81SAaron LIblock out proto tcp from any os "Doors PT SP3"
2414d27abe81SAaron LIblock out from any os "unknown"
2415d27abe81SAaron LIpass on lo0 proto tcp from any os "OpenBSD 3.3 lo0"
2416d27abe81SAaron LI.Ed
2417d27abe81SAaron LI.Pp
2418d27abe81SAaron LIOperating system fingerprinting is limited only to the TCP SYN packet.
2419d27abe81SAaron LIThis means that it will not work on other protocols and will not match
2420d27abe81SAaron LIa currently established connection.
2421d27abe81SAaron LI.Pp
2422d27abe81SAaron LICaveat: operating system fingerprints are occasionally wrong.
2423d27abe81SAaron LIThere are three problems: an attacker can trivially craft his packets to
2424d27abe81SAaron LIappear as any operating system he chooses;
2425d27abe81SAaron LIan operating system patch could change the stack behavior and no fingerprints
2426d27abe81SAaron LIwill match it until the database is updated;
2427d27abe81SAaron LIand multiple operating systems may have the same fingerprint.
2428d27abe81SAaron LI.Sh BLOCKING SPOOFED TRAFFIC
2429d27abe81SAaron LI"Spoofing" is the faking of IP addresses, typically for malicious
2430d27abe81SAaron LIpurposes.
2431d27abe81SAaron LIThe
2432d27abe81SAaron LI.Ar antispoof
2433d27abe81SAaron LIdirective expands to a set of filter rules which will block all
2434d27abe81SAaron LItraffic with a source IP from the network(s) directly connected
2435d27abe81SAaron LIto the specified interface(s) from entering the system through
2436d27abe81SAaron LIany other interface.
2437d27abe81SAaron LI.Pp
2438d27abe81SAaron LIFor example, the line
2439d27abe81SAaron LI.Bd -literal -offset indent
2440d27abe81SAaron LIantispoof for lo0
2441d27abe81SAaron LI.Ed
2442d27abe81SAaron LI.Pp
2443d27abe81SAaron LIexpands to
2444d27abe81SAaron LI.Bd -literal -offset indent
2445d27abe81SAaron LIblock drop in on ! lo0 inet from 127.0.0.1/8 to any
2446d27abe81SAaron LIblock drop in on ! lo0 inet6 from ::1 to any
2447d27abe81SAaron LI.Ed
2448d27abe81SAaron LI.Pp
2449d27abe81SAaron LIFor non-loopback interfaces, there are additional rules to block incoming
2450d27abe81SAaron LIpackets with a source IP address identical to the interface's IP(s).
2451d27abe81SAaron LIFor example, assuming the interface wi0 had an IP address of 10.0.0.1 and a
2452d27abe81SAaron LInetmask of 255.255.255.0,
2453d27abe81SAaron LIthe line
2454d27abe81SAaron LI.Bd -literal -offset indent
2455d27abe81SAaron LIantispoof for wi0 inet
2456d27abe81SAaron LI.Ed
2457d27abe81SAaron LI.Pp
2458d27abe81SAaron LIexpands to
2459d27abe81SAaron LI.Bd -literal -offset indent
2460d27abe81SAaron LIblock drop in on ! wi0 inet from 10.0.0.0/24 to any
2461d27abe81SAaron LIblock drop in inet from 10.0.0.1 to any
2462d27abe81SAaron LI.Ed
2463d27abe81SAaron LI.Pp
2464d27abe81SAaron LICaveat: Rules created by the
2465d27abe81SAaron LI.Ar antispoof
2466d27abe81SAaron LIdirective interfere with packets sent over loopback interfaces
2467d27abe81SAaron LIto local addresses.
2468d27abe81SAaron LIOne should pass these explicitly.
2469d27abe81SAaron LI.Sh FRAGMENT HANDLING
2470d27abe81SAaron LIThe size of IP datagrams (packets) can be significantly larger than the
2471d27abe81SAaron LImaximum transmission unit (MTU) of the network.
2472d27abe81SAaron LIIn cases when it is necessary or more efficient to send such large packets,
2473d27abe81SAaron LIthe large packet will be fragmented into many smaller packets that will each
2474d27abe81SAaron LIfit onto the wire.
2475d27abe81SAaron LIUnfortunately for a firewalling device, only the first logical fragment will
2476d27abe81SAaron LIcontain the necessary header information for the subprotocol that allows
2477d27abe81SAaron LI.Xr pf 4
2478d27abe81SAaron LIto filter on things such as TCP ports or to perform NAT.
2479d27abe81SAaron LI.Pp
2480d27abe81SAaron LIBesides the use of
2481d27abe81SAaron LI.Ar scrub
2482d27abe81SAaron LIrules as described in
2483d27abe81SAaron LI.Sx TRAFFIC NORMALIZATION
2484d27abe81SAaron LIabove, there are three options for handling fragments in the packet filter.
2485d27abe81SAaron LI.Pp
2486d27abe81SAaron LIOne alternative is to filter individual fragments with filter rules.
2487d27abe81SAaron LIIf no
2488d27abe81SAaron LI.Ar scrub
2489d27abe81SAaron LIrule applies to a fragment, it is passed to the filter.
2490d27abe81SAaron LIFilter rules with matching IP header parameters decide whether the
2491d27abe81SAaron LIfragment is passed or blocked, in the same way as complete packets
2492d27abe81SAaron LIare filtered.
2493d27abe81SAaron LIWithout reassembly, fragments can only be filtered based on IP header
2494d27abe81SAaron LIfields (source/destination address, protocol), since subprotocol header
2495d27abe81SAaron LIfields are not available (TCP/UDP port numbers, ICMP code/type).
2496d27abe81SAaron LIThe
2497d27abe81SAaron LI.Ar fragment
2498d27abe81SAaron LIoption can be used to restrict filter rules to apply only to
2499d27abe81SAaron LIfragments, but not complete packets.
2500d27abe81SAaron LIFilter rules without the
2501d27abe81SAaron LI.Ar fragment
2502d27abe81SAaron LIoption still apply to fragments, if they only specify IP header fields.
2503d27abe81SAaron LIFor instance, the rule
2504d27abe81SAaron LI.Bd -literal -offset indent
2505d27abe81SAaron LIpass in proto tcp from any to any port 80
2506d27abe81SAaron LI.Ed
2507d27abe81SAaron LI.Pp
2508d27abe81SAaron LInever applies to a fragment, even if the fragment is part of a TCP
2509d27abe81SAaron LIpacket with destination port 80, because without reassembly this information
2510d27abe81SAaron LIis not available for each fragment.
2511d27abe81SAaron LIThis also means that fragments cannot create new or match existing
2512d27abe81SAaron LIstate table entries, which makes stateful filtering and address
2513d27abe81SAaron LItranslation (NAT, redirection) for fragments impossible.
2514d27abe81SAaron LI.Pp
2515d27abe81SAaron LIIt's also possible to reassemble only certain fragments by specifying
2516d27abe81SAaron LIsource or destination addresses or protocols as parameters in
2517d27abe81SAaron LI.Ar scrub
2518d27abe81SAaron LIrules.
2519d27abe81SAaron LI.Pp
2520d27abe81SAaron LIIn most cases, the benefits of reassembly outweigh the additional
2521d27abe81SAaron LImemory cost, and it's recommended to use
2522d27abe81SAaron LI.Ar scrub
2523d27abe81SAaron LIrules to reassemble
2524d27abe81SAaron LIall fragments via the
2525d27abe81SAaron LI.Ar fragment reassemble
2526d27abe81SAaron LImodifier.
2527d27abe81SAaron LI.Pp
2528d27abe81SAaron LIThe memory allocated for fragment caching can be limited using
2529d27abe81SAaron LI.Xr pfctl 8 .
2530d27abe81SAaron LIOnce this limit is reached, fragments that would have to be cached
2531d27abe81SAaron LIare dropped until other entries time out.
2532d27abe81SAaron LIThe timeout value can also be adjusted.
2533d27abe81SAaron LI.Pp
2534d27abe81SAaron LICurrently, only IPv4 fragments are supported and IPv6 fragments
2535d27abe81SAaron LIare blocked unconditionally.
2536d27abe81SAaron LI.Sh ANCHORS
2537d27abe81SAaron LIBesides the main ruleset,
2538d27abe81SAaron LI.Xr pfctl 8
2539d27abe81SAaron LIcan load rulesets into
2540d27abe81SAaron LI.Ar anchor
2541d27abe81SAaron LIattachment points.
2542d27abe81SAaron LIAn
2543d27abe81SAaron LI.Ar anchor
2544d27abe81SAaron LIis a container that can hold rules, address tables, and other anchors.
2545d27abe81SAaron LI.Pp
2546d27abe81SAaron LIAn
2547d27abe81SAaron LI.Ar anchor
2548d27abe81SAaron LIhas a name which specifies the path where
2549d27abe81SAaron LI.Xr pfctl 8
2550d27abe81SAaron LIcan be used to access the anchor to perform operations on it, such as
2551d27abe81SAaron LIattaching child anchors to it or loading rules into it.
2552d27abe81SAaron LIAnchors may be nested, with components separated by
2553d27abe81SAaron LI.Sq /
2554d27abe81SAaron LIcharacters, similar to how file system hierarchies are laid out.
2555d27abe81SAaron LIThe main ruleset is actually the default anchor, so filter and
2556d27abe81SAaron LItranslation rules, for example, may also be contained in any anchor.
2557d27abe81SAaron LI.Pp
2558d27abe81SAaron LIAn anchor can reference another
2559d27abe81SAaron LI.Ar anchor
2560d27abe81SAaron LIattachment point
2561d27abe81SAaron LIusing the following kinds
2562d27abe81SAaron LIof rules:
2563d27abe81SAaron LI.Bl -tag -width xxxx
2564d27abe81SAaron LI.It Ar nat-anchor Aq Ar name
2565d27abe81SAaron LIEvaluates the
2566d27abe81SAaron LI.Ar nat
2567d27abe81SAaron LIrules in the specified
2568d27abe81SAaron LI.Ar anchor .
2569d27abe81SAaron LI.It Ar rdr-anchor Aq Ar name
2570d27abe81SAaron LIEvaluates the
2571d27abe81SAaron LI.Ar rdr
2572d27abe81SAaron LIrules in the specified
2573d27abe81SAaron LI.Ar anchor .
2574d27abe81SAaron LI.It Ar binat-anchor Aq Ar name
2575d27abe81SAaron LIEvaluates the
2576d27abe81SAaron LI.Ar binat
2577d27abe81SAaron LIrules in the specified
2578d27abe81SAaron LI.Ar anchor .
2579d27abe81SAaron LI.It Ar anchor Aq Ar name
2580d27abe81SAaron LIEvaluates the filter rules in the specified
2581d27abe81SAaron LI.Ar anchor .
2582d27abe81SAaron LI.It Xo Ar load anchor
2583d27abe81SAaron LI.Aq Ar name
2584d27abe81SAaron LI.Ar from Aq Ar file
2585d27abe81SAaron LI.Xc
2586d27abe81SAaron LILoads the rules from the specified file into the
2587d27abe81SAaron LIanchor
2588d27abe81SAaron LI.Ar name .
2589d27abe81SAaron LI.El
2590d27abe81SAaron LI.Pp
2591d27abe81SAaron LIWhen evaluation of the main ruleset reaches an
2592d27abe81SAaron LI.Ar anchor
2593d27abe81SAaron LIrule,
2594d27abe81SAaron LI.Xr pf 4
2595d27abe81SAaron LIwill proceed to evaluate all rules specified in that anchor.
2596d27abe81SAaron LI.Pp
2597d27abe81SAaron LIMatching filter and translation rules marked with the
2598d27abe81SAaron LI.Ar quick
2599d27abe81SAaron LIoption are final and abort the evaluation of the rules in other
2600d27abe81SAaron LIanchors and the main ruleset.
2601d27abe81SAaron LIIf the
2602d27abe81SAaron LI.Ar anchor
2603d27abe81SAaron LIitself is marked with the
2604d27abe81SAaron LI.Ar quick
2605d27abe81SAaron LIoption,
2606d27abe81SAaron LIruleset evaluation will terminate when the anchor is exited if the packet is
2607d27abe81SAaron LImatched by any rule within the anchor.
2608d27abe81SAaron LI.Pp
2609d27abe81SAaron LI.Ar anchor
2610d27abe81SAaron LIrules are evaluated relative to the anchor in which they are contained.
2611d27abe81SAaron LIFor example, all
2612d27abe81SAaron LI.Ar anchor
2613d27abe81SAaron LIrules specified in the main ruleset will reference anchor
2614d27abe81SAaron LIattachment points underneath the main ruleset, and
2615d27abe81SAaron LI.Ar anchor
2616d27abe81SAaron LIrules specified in a file loaded from a
2617d27abe81SAaron LI.Ar load anchor
2618d27abe81SAaron LIrule will be attached under that anchor point.
2619d27abe81SAaron LI.Pp
2620d27abe81SAaron LIRules may be contained in
2621d27abe81SAaron LI.Ar anchor
2622d27abe81SAaron LIattachment points which do not contain any rules when the main ruleset
2623d27abe81SAaron LIis loaded, and later such anchors can be manipulated through
2624d27abe81SAaron LI.Xr pfctl 8
2625d27abe81SAaron LIwithout reloading the main ruleset or other anchors.
2626d27abe81SAaron LIFor example,
2627d27abe81SAaron LI.Bd -literal -offset indent
2628d27abe81SAaron LIext_if = \&"kue0\&"
2629d27abe81SAaron LIblock on $ext_if all
2630d27abe81SAaron LIanchor spam
2631d27abe81SAaron LIpass out on $ext_if all
2632d27abe81SAaron LIpass in on $ext_if proto tcp from any \e
2633d27abe81SAaron LI      to $ext_if port smtp
2634d27abe81SAaron LI.Ed
2635d27abe81SAaron LI.Pp
2636d27abe81SAaron LIblocks all packets on the external interface by default, then evaluates
2637d27abe81SAaron LIall rules in the
2638d27abe81SAaron LI.Ar anchor
2639d27abe81SAaron LInamed "spam", and finally passes all outgoing connections and
2640d27abe81SAaron LIincoming connections to port 25.
2641d27abe81SAaron LI.Bd -literal -offset indent
2642d27abe81SAaron LI# echo \&"block in quick from 1.2.3.4 to any\&" \&| \e
2643d27abe81SAaron LI      pfctl -a spam -f -
2644d27abe81SAaron LI.Ed
2645d27abe81SAaron LI.Pp
2646d27abe81SAaron LIThis loads a single rule into the
2647d27abe81SAaron LI.Ar anchor ,
2648d27abe81SAaron LIwhich blocks all packets from a specific address.
2649d27abe81SAaron LI.Pp
2650d27abe81SAaron LIThe anchor can also be populated by adding a
2651d27abe81SAaron LI.Ar load anchor
2652d27abe81SAaron LIrule after the
2653d27abe81SAaron LI.Ar anchor
2654d27abe81SAaron LIrule:
2655d27abe81SAaron LI.Bd -literal -offset indent
2656d27abe81SAaron LIanchor spam
2657d27abe81SAaron LIload anchor spam from "/etc/pf-spam.conf"
2658d27abe81SAaron LI.Ed
2659d27abe81SAaron LI.Pp
2660d27abe81SAaron LIWhen
2661d27abe81SAaron LI.Xr pfctl 8
2662d27abe81SAaron LIloads
2663d27abe81SAaron LI.Nm ,
2664d27abe81SAaron LIit will also load all the rules from the file
2665d27abe81SAaron LI.Pa /etc/pf-spam.conf
2666d27abe81SAaron LIinto the anchor.
2667d27abe81SAaron LI.Pp
2668d27abe81SAaron LIOptionally,
2669d27abe81SAaron LI.Ar anchor
2670d27abe81SAaron LIrules can specify packet filtering parameters using the same syntax as
2671d27abe81SAaron LIfilter rules.
2672d27abe81SAaron LIWhen parameters are used, the
2673d27abe81SAaron LI.Ar anchor
2674d27abe81SAaron LIrule is only evaluated for matching packets.
2675d27abe81SAaron LIThis allows conditional evaluation of anchors, like:
2676d27abe81SAaron LI.Bd -literal -offset indent
2677d27abe81SAaron LIblock on $ext_if all
2678d27abe81SAaron LIanchor spam proto tcp from any to any port smtp
2679d27abe81SAaron LIpass out on $ext_if all
2680d27abe81SAaron LIpass in on $ext_if proto tcp from any to $ext_if port smtp
2681d27abe81SAaron LI.Ed
2682d27abe81SAaron LI.Pp
2683d27abe81SAaron LIThe rules inside
2684d27abe81SAaron LI.Ar anchor
2685d27abe81SAaron LIspam are only evaluated for
2686d27abe81SAaron LI.Ar tcp
2687d27abe81SAaron LIpackets with destination port 25.
2688d27abe81SAaron LIHence,
2689d27abe81SAaron LI.Bd -literal -offset indent
2690d27abe81SAaron LI# echo \&"block in quick from 1.2.3.4 to any" \&| \e
2691d27abe81SAaron LI      pfctl -a spam -f -
2692d27abe81SAaron LI.Ed
2693d27abe81SAaron LI.Pp
2694d27abe81SAaron LIwill only block connections from 1.2.3.4 to port 25.
2695d27abe81SAaron LI.Pp
2696d27abe81SAaron LIAnchors may end with the asterisk
2697d27abe81SAaron LI.Pq Sq *
2698d27abe81SAaron LIcharacter, which signifies that all anchors attached at that point
2699d27abe81SAaron LIshould be evaluated in the alphabetical ordering of their anchor name.
2700d27abe81SAaron LIFor example,
2701d27abe81SAaron LI.Bd -literal -offset indent
2702d27abe81SAaron LIanchor "spam/*"
2703d27abe81SAaron LI.Ed
2704d27abe81SAaron LI.Pp
2705d27abe81SAaron LIwill evaluate each rule in each anchor attached to the
2706d27abe81SAaron LI.Li spam
2707d27abe81SAaron LIanchor.
2708d27abe81SAaron LINote that it will only evaluate anchors that are directly attached to the
2709d27abe81SAaron LI.Li spam
2710d27abe81SAaron LIanchor, and will not descend to evaluate anchors recursively.
2711d27abe81SAaron LI.Pp
2712d27abe81SAaron LISince anchors are evaluated relative to the anchor in which they are
2713d27abe81SAaron LIcontained, there is a mechanism for accessing the parent and ancestor
2714d27abe81SAaron LIanchors of a given anchor.
2715d27abe81SAaron LISimilar to file system path name resolution, if the sequence
2716d27abe81SAaron LI.Dq ..
2717d27abe81SAaron LIappears as an anchor path component, the parent anchor of the current
2718d27abe81SAaron LIanchor in the path evaluation at that point will become the new current
2719d27abe81SAaron LIanchor.
2720d27abe81SAaron LIAs an example, consider the following:
2721d27abe81SAaron LI.Bd -literal -offset indent
2722d27abe81SAaron LI# echo ' anchor "spam/allowed" ' | pfctl -f -
2723d27abe81SAaron LI# echo -e ' anchor "../banned" \en pass' | \e
2724d27abe81SAaron LI      pfctl -a spam/allowed -f -
2725d27abe81SAaron LI.Ed
2726d27abe81SAaron LI.Pp
2727d27abe81SAaron LIEvaluation of the main ruleset will lead into the
2728d27abe81SAaron LI.Li spam/allowed
2729d27abe81SAaron LIanchor, which will evaluate the rules in the
2730d27abe81SAaron LI.Li spam/banned
2731d27abe81SAaron LIanchor, if any, before finally evaluating the
2732d27abe81SAaron LI.Ar pass
2733d27abe81SAaron LIrule.
2734d27abe81SAaron LI.Pp
2735d27abe81SAaron LIFilter rule
2736d27abe81SAaron LI.Ar anchors
2737d27abe81SAaron LIcan also be loaded inline in the ruleset within a brace ('{' '}') delimited
2738d27abe81SAaron LIblock.
2739d27abe81SAaron LIBrace delimited blocks may contain rules or other brace-delimited blocks.
2740d27abe81SAaron LIWhen anchors are loaded this way the anchor name becomes optional.
2741d27abe81SAaron LI.Bd -literal -offset indent
2742d27abe81SAaron LIanchor "external" on egress {
2743d27abe81SAaron LI	block
2744d27abe81SAaron LI	anchor out {
2745d27abe81SAaron LI		pass proto tcp from any to port { 25, 80, 443 }
2746d27abe81SAaron LI	}
2747d27abe81SAaron LI	pass in proto tcp to any port 22
2748d27abe81SAaron LI}
2749d27abe81SAaron LI.Ed
2750d27abe81SAaron LI.Pp
2751d27abe81SAaron LISince the parser specification for anchor names is a string, any
2752d27abe81SAaron LIreference to an anchor name containing
2753d27abe81SAaron LI.Sq /
2754d27abe81SAaron LIcharacters will require double quote
2755d27abe81SAaron LI.Pq Sq \&"
2756d27abe81SAaron LIcharacters around the anchor name.
2757d27abe81SAaron LI.Sh TRANSLATION EXAMPLES
2758d27abe81SAaron LIThis example maps incoming requests on port 80 to port 8080, on
2759d27abe81SAaron LIwhich a daemon is running (because, for example, it is not run as root,
2760d27abe81SAaron LIand therefore lacks permission to bind to port 80).
2761d27abe81SAaron LI.Bd -literal
2762d27abe81SAaron LI# use a macro for the interface name, so it can be changed easily
2763d27abe81SAaron LIext_if = \&"ne3\&"
2764d27abe81SAaron LI
2765d27abe81SAaron LI# map daemon on 8080 to appear to be on 80
2766d27abe81SAaron LIrdr on $ext_if proto tcp from any to any port 80 -\*(Gt 127.0.0.1 port 8080
2767d27abe81SAaron LI.Ed
2768d27abe81SAaron LI.Pp
2769d27abe81SAaron LIIf the
2770d27abe81SAaron LI.Ar pass
2771d27abe81SAaron LImodifier is given, packets matching the translation rule are passed without
2772d27abe81SAaron LIinspecting the filter rules:
2773d27abe81SAaron LI.Bd -literal
2774d27abe81SAaron LIrdr pass on $ext_if proto tcp from any to any port 80 -\*(Gt 127.0.0.1 \e
2775d27abe81SAaron LI      port 8080
2776d27abe81SAaron LI.Ed
2777d27abe81SAaron LI.Pp
2778d27abe81SAaron LIIn the example below, vlan12 is configured as 192.168.168.1;
2779d27abe81SAaron LIthe machine translates all packets coming from 192.168.168.0/24 to 204.92.77.111
2780d27abe81SAaron LIwhen they are going out any interface except vlan12.
2781d27abe81SAaron LIThis has the net effect of making traffic from the 192.168.168.0/24
2782d27abe81SAaron LInetwork appear as though it is the Internet routable address
2783d27abe81SAaron LI204.92.77.111 to nodes behind any interface on the router except
2784d27abe81SAaron LIfor the nodes on vlan12.
2785d27abe81SAaron LI(Thus, 192.168.168.1 can talk to the 192.168.168.0/24 nodes.)
2786d27abe81SAaron LI.Bd -literal
2787d27abe81SAaron LInat on ! vlan12 from 192.168.168.0/24 to any -\*(Gt 204.92.77.111
2788d27abe81SAaron LI.Ed
2789d27abe81SAaron LI.Pp
2790d27abe81SAaron LIIn the example below, the machine sits between a fake internal 144.19.74.*
2791d27abe81SAaron LInetwork, and a routable external IP of 204.92.77.100.
2792d27abe81SAaron LIThe
2793d27abe81SAaron LI.Ar no nat
2794d27abe81SAaron LIrule excludes protocol AH from being translated.
2795d27abe81SAaron LI.Bd -literal
2796d27abe81SAaron LI# NO NAT
2797d27abe81SAaron LIno nat on $ext_if proto ah from 144.19.74.0/24 to any
2798d27abe81SAaron LInat on $ext_if from 144.19.74.0/24 to any -\*(Gt 204.92.77.100
2799d27abe81SAaron LI.Ed
2800d27abe81SAaron LI.Pp
2801d27abe81SAaron LIIn the example below, packets bound for one specific server, as well as those
2802d27abe81SAaron LIgenerated by the sysadmins are not proxied; all other connections are.
2803d27abe81SAaron LI.Bd -literal
2804d27abe81SAaron LI# NO RDR
2805d27abe81SAaron LIno rdr on $int_if proto { tcp, udp } from any to $server port 80
2806d27abe81SAaron LIno rdr on $int_if proto { tcp, udp } from $sysadmins to any port 80
2807d27abe81SAaron LIrdr on $int_if proto { tcp, udp } from any to any port 80 -\*(Gt 127.0.0.1 \e
2808d27abe81SAaron LI      port 80
2809d27abe81SAaron LI.Ed
2810d27abe81SAaron LI.Pp
2811d27abe81SAaron LIThis longer example uses both a NAT and a redirection.
2812d27abe81SAaron LIThe external interface has the address 157.161.48.183.
2813d27abe81SAaron LIOn localhost, we are running
2814d27abe81SAaron LI.Xr ftp-proxy 8 ,
2815d27abe81SAaron LIwaiting for FTP sessions to be redirected to it.
2816d27abe81SAaron LIThe three mandatory anchors for
2817d27abe81SAaron LI.Xr ftp-proxy 8
2818d27abe81SAaron LIare omitted from this example; see the
2819d27abe81SAaron LI.Xr ftp-proxy 8
2820d27abe81SAaron LImanpage.
2821d27abe81SAaron LI.Bd -literal
2822d27abe81SAaron LI# NAT
2823d27abe81SAaron LI# Translate outgoing packets' source addresses (any protocol).
2824d27abe81SAaron LI# In this case, any address but the gateway's external address is mapped.
2825d27abe81SAaron LInat on $ext_if inet from ! ($ext_if) to any -\*(Gt ($ext_if)
2826d27abe81SAaron LI
2827d27abe81SAaron LI# NAT PROXYING
2828d27abe81SAaron LI# Map outgoing packets' source port to an assigned proxy port instead of
2829d27abe81SAaron LI# an arbitrary port.
2830d27abe81SAaron LI# In this case, proxy outgoing isakmp with port 500 on the gateway.
2831d27abe81SAaron LInat on $ext_if inet proto udp from any port = isakmp to any -\*(Gt ($ext_if) \e
2832d27abe81SAaron LI      port 500
2833d27abe81SAaron LI
2834d27abe81SAaron LI# BINAT
2835d27abe81SAaron LI# Translate outgoing packets' source address (any protocol).
2836d27abe81SAaron LI# Translate incoming packets' destination address to an internal machine
2837d27abe81SAaron LI# (bidirectional).
2838d27abe81SAaron LIbinat on $ext_if from 10.1.2.150 to any -\*(Gt $ext_if
2839d27abe81SAaron LI
2840d27abe81SAaron LI# RDR
2841d27abe81SAaron LI# Translate incoming packets' destination addresses.
2842d27abe81SAaron LI# As an example, redirect a TCP and UDP port to an internal machine.
2843d27abe81SAaron LIrdr on $ext_if inet proto tcp from any to ($ext_if) port 8080 \e
2844d27abe81SAaron LI      -\*(Gt 10.1.2.151 port 22
2845d27abe81SAaron LIrdr on $ext_if inet proto udp from any to ($ext_if) port 8080 \e
2846d27abe81SAaron LI      -\*(Gt 10.1.2.151 port 53
2847d27abe81SAaron LI
2848d27abe81SAaron LI# RDR
2849d27abe81SAaron LI# Translate outgoing ftp control connections to send them to localhost
2850d27abe81SAaron LI# for proxying with ftp-proxy(8) running on port 8021.
2851d27abe81SAaron LIrdr on $int_if proto tcp from any to any port 21 -\*(Gt 127.0.0.1 port 8021
2852d27abe81SAaron LI.Ed
2853d27abe81SAaron LI.Pp
2854d27abe81SAaron LIIn this example, a NAT gateway is set up to translate internal addresses
2855d27abe81SAaron LIusing a pool of public addresses (192.0.2.16/28) and to redirect
2856d27abe81SAaron LIincoming web server connections to a group of web servers on the internal
2857d27abe81SAaron LInetwork.
2858d27abe81SAaron LI.Bd -literal
2859d27abe81SAaron LI# NAT LOAD BALANCE
2860d27abe81SAaron LI# Translate outgoing packets' source addresses using an address pool.
2861d27abe81SAaron LI# A given source address is always translated to the same pool address by
2862d27abe81SAaron LI# using the source-hash keyword.
2863d27abe81SAaron LInat on $ext_if inet from any to any -\*(Gt 192.0.2.16/28 source-hash
2864d27abe81SAaron LI
2865d27abe81SAaron LI# RDR ROUND ROBIN
2866d27abe81SAaron LI# Translate incoming web server connections to a group of web servers on
2867d27abe81SAaron LI# the internal network.
2868d27abe81SAaron LIrdr on $ext_if proto tcp from any to any port 80 \e
2869d27abe81SAaron LI      -\*(Gt { 10.1.2.155, 10.1.2.160, 10.1.2.161 } round-robin
2870d27abe81SAaron LI.Ed
2871d27abe81SAaron LI.Sh FILTER EXAMPLES
2872d27abe81SAaron LI.Bd -literal
2873d27abe81SAaron LI# The external interface is kue0
2874d27abe81SAaron LI# (157.161.48.183, the only routable address)
2875d27abe81SAaron LI# and the private network is 10.0.0.0/8, for which we are doing NAT.
2876d27abe81SAaron LI
2877d27abe81SAaron LI# use a macro for the interface name, so it can be changed easily
2878d27abe81SAaron LIext_if = \&"kue0\&"
2879d27abe81SAaron LI
2880d27abe81SAaron LI# normalize all incoming traffic
2881d27abe81SAaron LIscrub in on $ext_if all fragment reassemble
2882d27abe81SAaron LI
2883d27abe81SAaron LI# block and log everything by default
2884d27abe81SAaron LIblock return log on $ext_if all
2885d27abe81SAaron LI
2886d27abe81SAaron LI# block anything coming from source we have no back routes for
2887d27abe81SAaron LIblock in from no-route to any
2888d27abe81SAaron LI
2889d27abe81SAaron LI# block packets whose ingress interface does not match the one in
2890d27abe81SAaron LI# the route back to their source address
2891d27abe81SAaron LIblock in from urpf-failed to any
2892d27abe81SAaron LI
2893d27abe81SAaron LI# block and log outgoing packets that do not have our address as source,
2894d27abe81SAaron LI# they are either spoofed or something is misconfigured (NAT disabled,
2895d27abe81SAaron LI# for instance), we want to be nice and do not send out garbage.
2896d27abe81SAaron LIblock out log quick on $ext_if from ! 157.161.48.183 to any
2897d27abe81SAaron LI
2898d27abe81SAaron LI# silently drop broadcasts (cable modem noise)
2899d27abe81SAaron LIblock in quick on $ext_if from any to 255.255.255.255
2900d27abe81SAaron LI
2901d27abe81SAaron LI# block and log incoming packets from reserved address space and invalid
2902d27abe81SAaron LI# addresses, they are either spoofed or misconfigured, we cannot reply to
2903d27abe81SAaron LI# them anyway (hence, no return-rst).
2904d27abe81SAaron LIblock in log quick on $ext_if from { 10.0.0.0/8, 172.16.0.0/12, \e
2905d27abe81SAaron LI      192.168.0.0/16, 255.255.255.255/32 } to any
2906d27abe81SAaron LI
2907d27abe81SAaron LI# ICMP
2908d27abe81SAaron LI
2909d27abe81SAaron LI# pass out/in certain ICMP queries and keep state (ping)
2910d27abe81SAaron LI# state matching is done on host addresses and ICMP id (not type/code),
2911d27abe81SAaron LI# so replies (like 0/0 for 8/0) will match queries
2912d27abe81SAaron LI# ICMP error messages (which always refer to a TCP/UDP packet) are
2913d27abe81SAaron LI# handled by the TCP/UDP states
2914d27abe81SAaron LIpass on $ext_if inet proto icmp all icmp-type 8 code 0
2915d27abe81SAaron LI
2916d27abe81SAaron LI# UDP
2917d27abe81SAaron LI
2918d27abe81SAaron LI# pass out all UDP connections and keep state
2919d27abe81SAaron LIpass out on $ext_if proto udp all
2920d27abe81SAaron LI
2921d27abe81SAaron LI# pass in certain UDP connections and keep state (DNS)
2922d27abe81SAaron LIpass in on $ext_if proto udp from any to any port domain
2923d27abe81SAaron LI
2924d27abe81SAaron LI# TCP
2925d27abe81SAaron LI
2926d27abe81SAaron LI# pass out all TCP connections and modulate state
2927d27abe81SAaron LIpass out on $ext_if proto tcp all modulate state
2928d27abe81SAaron LI
2929d27abe81SAaron LI# pass in certain TCP connections and keep state (SSH, SMTP, DNS, IDENT)
2930d27abe81SAaron LIpass in on $ext_if proto tcp from any to any port { ssh, smtp, domain, \e
2931d27abe81SAaron LI      auth }
2932d27abe81SAaron LI
2933d27abe81SAaron LI# Do not allow Windows 9x SMTP connections since they are typically
2934d27abe81SAaron LI# a viral worm. Alternately we could limit these OSes to 1 connection each.
2935d27abe81SAaron LIblock in on $ext_if proto tcp from any os {"Windows 95", "Windows 98"} \e
2936d27abe81SAaron LI      to any port smtp
2937d27abe81SAaron LI
2938d27abe81SAaron LI# IPv6
2939d27abe81SAaron LI# pass in/out all IPv6 traffic: note that we have to enable this in two
2940d27abe81SAaron LI# different ways, on both our physical interface and our tunnel
2941d27abe81SAaron LIpass quick on gif0 inet6
2942d27abe81SAaron LIpass quick on $ext_if proto ipv6
2943d27abe81SAaron LI
2944d27abe81SAaron LI# Using the pickup options to keep/modulate/synproxy state
2945d27abe81SAaron LI#
2946d27abe81SAaron LI# no-pickups	(default) Do not allow connections to be picked up in the
2947d27abe81SAaron LI#		middle.  Implies flags S/SA (the 'no-pickups' option need
2948d27abe81SAaron LI#		not be specified, it is the default).
2949d27abe81SAaron LI#
2950d27abe81SAaron LI# pickups	Allow connections to be picked up in the middle, even if
2951d27abe81SAaron LI#		no window scaling information is known.  Such connections
2952d27abe81SAaron LI#		will disable sequence space checks.  Implies no flag
2953d27abe81SAaron LI#		restrictions.
2954d27abe81SAaron LI#
2955d27abe81SAaron LI# hash-only	Do not fail packets on sequence space checks.  Implies no
2956d27abe81SAaron LI#		flag restrictions.
2957d27abe81SAaron LI
2958d27abe81SAaron LIpass in on $ext_if proto tcp ... keep state (no-pickups)
2959d27abe81SAaron LIpass in on $ext_if proto tcp ... keep state (pickups)
2960d27abe81SAaron LIpass in on $ext_if proto tcp ... keep state (hash-only)
2961d27abe81SAaron LI
2962d27abe81SAaron LI# Packet Tagging
2963d27abe81SAaron LI
2964d27abe81SAaron LI# three interfaces: $int_if, $ext_if, and $wifi_if (wireless). NAT is
2965d27abe81SAaron LI# being done on $ext_if for all outgoing packets. tag packets in on
2966d27abe81SAaron LI# $int_if and pass those tagged packets out on $ext_if.  all other
2967d27abe81SAaron LI# outgoing packets (i.e., packets from the wireless network) are only
2968d27abe81SAaron LI# permitted to access port 80.
2969d27abe81SAaron LI
2970d27abe81SAaron LIpass in on $int_if from any to any tag INTNET
2971d27abe81SAaron LIpass in on $wifi_if from any to any
2972d27abe81SAaron LI
2973d27abe81SAaron LIblock out on $ext_if from any to any
2974d27abe81SAaron LIpass out quick on $ext_if tagged INTNET
2975d27abe81SAaron LIpass out on $ext_if proto tcp from any to any port 80
2976d27abe81SAaron LI
2977d27abe81SAaron LI# tag incoming packets as they are redirected to spamd(8). use the tag
2978d27abe81SAaron LI# to pass those packets through the packet filter.
2979d27abe81SAaron LI
2980d27abe81SAaron LIrdr on $ext_if inet proto tcp from \*(Ltspammers\*(Gt to port smtp \e
2981d27abe81SAaron LI	tag SPAMD -\*(Gt 127.0.0.1 port spamd
2982d27abe81SAaron LI
2983d27abe81SAaron LIblock in on $ext_if
2984d27abe81SAaron LIpass in on $ext_if inet proto tcp tagged SPAMD
2985d27abe81SAaron LI.Ed
2986d27abe81SAaron LI.Sh GRAMMAR
2987d27abe81SAaron LISyntax for
2988d27abe81SAaron LI.Nm
2989d27abe81SAaron LIin BNF:
2990d27abe81SAaron LI.Bd -literal
29915304134cSAaron LIline           = ( option | pf-rule | nat-rule | binat-rule | rdr-rule |
2992d27abe81SAaron LI                 antispoof-rule | altq-rule | queue-rule | trans-anchors |
29935304134cSAaron LI                 anchor-rule | anchor-close | load-anchor | table-rule |
29945304134cSAaron LI                 include )
2995d27abe81SAaron LI
2996d27abe81SAaron LIoption         = "set" ( [ "timeout" ( timeout | "{" timeout-list "}" ) ] |
2997d27abe81SAaron LI                 [ "ruleset-optimization" [ "none" | "basic" | "profile" ] ] |
2998d27abe81SAaron LI                 [ "optimization" [ "default" | "normal" |
2999d27abe81SAaron LI                 "high-latency" | "satellite" |
3000d27abe81SAaron LI                 "aggressive" | "conservative" ] ]
3001d27abe81SAaron LI                 [ "limit" ( limit-item | "{" limit-list "}" ) ] |
3002d27abe81SAaron LI                 [ "loginterface" ( interface-name | "none" ) ] |
3003d27abe81SAaron LI                 [ "block-policy" ( "drop" | "return" ) ] |
3004d27abe81SAaron LI                 [ "keep-policy" keep ] |
3005d27abe81SAaron LI                 [ "state-policy" ( "if-bound" | "floating" ) ]
3006d27abe81SAaron LI                 [ "require-order" ( "yes" | "no" ) ]
3007d27abe81SAaron LI                 [ "fingerprints" filename ] |
30085304134cSAaron LI                 [ "skip on" ifspec ] |
3009d27abe81SAaron LI                 [ "debug" ( "none" | "urgent" | "misc" | "loud" ) ] )
3010d27abe81SAaron LI
30115304134cSAaron LIpf-rule        = action [ ( "in" | "out" ) ]
3012d27abe81SAaron LI                 [ "log" [ "(" logopts ")"] ] [ "quick" ]
3013d27abe81SAaron LI                 [ "on" ifspec ] [ "fastroute" | route ] [ af ] [ protospec ]
3014d27abe81SAaron LI                 hosts [ filteropt-list ]
3015d27abe81SAaron LI
3016d27abe81SAaron LIlogopts        = logopt [ "," logopts ]
3017d27abe81SAaron LIlogopt         = "all" | "user" | "to" interface-name
3018d27abe81SAaron LI
3019d27abe81SAaron LIfilteropt-list = filteropt-list filteropt | filteropt
3020d27abe81SAaron LIfilteropt      = user | group | flags | icmp-type | icmp6-type | tos |
3021d27abe81SAaron LI                 keep | "fragment" | "no-df" | "min-ttl" number |
3022d27abe81SAaron LI                 "max-mss" number | "random-id" | "reassemble tcp" |
3023d27abe81SAaron LI                 fragmentation | "allow-opts" |
3024d27abe81SAaron LI                 "label" string | "tag" string | [ ! ] "tagged" string |
3025d27abe81SAaron LI                 "queue" ( string | "(" string [ [ "," ] string ] ")" ) |
3026d27abe81SAaron LI		 "probability" number"%"
3027d27abe81SAaron LI
3028d27abe81SAaron LIkeep           = "no" "state" |
3029d27abe81SAaron LI                 ( "keep" | "modulate" | "synproxy" ) "state"
3030d27abe81SAaron LI                 [ "(" state-opts ")" ]
3031d27abe81SAaron LI
3032d27abe81SAaron LInat-rule       = [ "no" ] "nat" [ "pass" [ "log" [ "(" logopts ")" ] ] ]
3033d27abe81SAaron LI                 [ "on" ifspec ] [ af ]
3034d27abe81SAaron LI                 [ protospec ] hosts [ "tag" string ] [ "tagged" string ]
3035d27abe81SAaron LI                 [ "-\*(Gt" ( redirhost | "{" redirhost-list "}" )
3036d27abe81SAaron LI                 [ portspec ] [ pooltype ] [ "static-port" ] ]
3037d27abe81SAaron LI
3038d27abe81SAaron LIbinat-rule     = [ "no" ] "binat" [ "pass" [ "log" [ "(" logopts ")" ] ] ]
3039d27abe81SAaron LI                 [ "on" interface-name ] [ af ]
3040d27abe81SAaron LI                 [ "proto" ( proto-name | proto-number ) ]
3041d27abe81SAaron LI                 "from" address [ "/" mask-bits ] "to" ipspec
3042d27abe81SAaron LI                 [ "tag" string ] [ "tagged" string ]
3043d27abe81SAaron LI                 [ "-\*(Gt" address [ "/" mask-bits ] ]
3044d27abe81SAaron LI
3045d27abe81SAaron LIrdr-rule       = [ "no" ] "rdr" [ "pass" [ "log" [ "(" logopts ")" ] ] ]
3046d27abe81SAaron LI                 [ "on" ifspec ] [ af ]
3047d27abe81SAaron LI                 [ protospec ] hosts [ "tag" string ] [ "tagged" string ]
3048d27abe81SAaron LI                 [ "-\*(Gt" ( redirhost | "{" redirhost-list "}" )
3049d27abe81SAaron LI                 [ portspec ] [ pooltype ] ]
3050d27abe81SAaron LI
3051d27abe81SAaron LIantispoof-rule = "antispoof" [ "log" ] [ "quick" ]
30525304134cSAaron LI                 "for" ifspec [ af ] [ "label" string ]
3053d27abe81SAaron LI
3054d27abe81SAaron LItable-rule     = "table" "\*(Lt" string "\*(Gt" [ tableopts-list ]
3055d27abe81SAaron LItableopts-list = tableopts-list tableopts | tableopts
3056d27abe81SAaron LItableopts      = "persist" | "const" | "counters" | "file" string |
3057d27abe81SAaron LI                 "{" [ tableaddr-list ] "}"
3058d27abe81SAaron LItableaddr-list = tableaddr-list [ "," ] tableaddr-spec | tableaddr-spec
3059d27abe81SAaron LItableaddr-spec = [ "!" ] tableaddr [ "/" mask-bits ]
30605304134cSAaron LItableaddr      = hostname | ifspec | "self" |
30615304134cSAaron LI                 ipv4-dotted-quad | ipv6-coloned-hex
3062d27abe81SAaron LI
3063d27abe81SAaron LIaltq-rule      = "altq on" interface-name queueopts-list
3064d27abe81SAaron LI                 "queue" subqueue
3065d27abe81SAaron LIqueue-rule     = "queue" string [ "on" interface-name ] queueopts-list
3066d27abe81SAaron LI                 subqueue
3067d27abe81SAaron LI
30685304134cSAaron LIanchor-rule    = "anchor" [ string ] [ ( "in" | "out" ) ] [ "on" ifspec ]
3069d27abe81SAaron LI                 [ af ] [ "proto" ] [ protospec ] [ hosts ]
3070d27abe81SAaron LI
3071d27abe81SAaron LItrans-anchors  = ( "nat-anchor" | "rdr-anchor" | "binat-anchor" ) string
3072d27abe81SAaron LI                 [ "on" ifspec ] [ af ] [ "proto" ] [ protospec ] [ hosts ]
3073d27abe81SAaron LI
3074d27abe81SAaron LIload-anchor    = "load anchor" string "from" filename
3075d27abe81SAaron LI
3076d27abe81SAaron LIqueueopts-list = queueopts-list queueopts | queueopts
30775304134cSAaron LIqueueopts      = [ "bandwidth" bandwidth-spec ] |
30785304134cSAaron LI                 [ "qlimit" number ] | [ "tbrsize" number ] |
30795304134cSAaron LI                 [ "priority" number ] | [ schedulers ]
30805304134cSAaron LIschedulers     = ( cbq-def | hfsc-def | priq-def | fairq-def )
3081d27abe81SAaron LIbandwidth-spec = "number" ( "b" | "Kb" | "Mb" | "Gb" | "%" )
3082d27abe81SAaron LI
3083d27abe81SAaron LIaction         = "pass" | "block" [ return ] | [ "no" ] "scrub"
3084d27abe81SAaron LIreturn         = "drop" | "return" | "return-rst" [ "( ttl" number ")" ] |
3085d27abe81SAaron LI                 "return-icmp" [ "(" icmpcode [ [ "," ] icmp6code ] ")" ] |
3086d27abe81SAaron LI                 "return-icmp6" [ "(" icmp6code ")" ]
30875304134cSAaron LIicmpcode       = ( icmp-code-name | icmp-code-number )
30885304134cSAaron LIicmp6code      = ( icmp6-code-name | icmp6-code-number )
3089d27abe81SAaron LI
30905304134cSAaron LIifspec         = ( [ "!" ] ( interface-name | interface-group ) ) |
30915304134cSAaron LI                 "{" interface-list "}"
30925304134cSAaron LIinterface-list = [ "!" ] ( interface-name | interface-group )
30935304134cSAaron LI                 [ [ "," ] interface-list ]
3094d27abe81SAaron LIroute          = ( "route-to" | "reply-to" | "dup-to" )
3095d27abe81SAaron LI                 ( routehost | "{" routehost-list "}" )
3096d27abe81SAaron LI                 [ pooltype ]
3097d27abe81SAaron LIaf             = "inet" | "inet6"
3098d27abe81SAaron LI
3099d27abe81SAaron LIprotospec      = "proto" ( proto-name | proto-number |
3100d27abe81SAaron LI                 "{" proto-list "}" )
3101d27abe81SAaron LIproto-list     = ( proto-name | proto-number ) [ [ "," ] proto-list ]
3102d27abe81SAaron LI
3103d27abe81SAaron LIhosts          = "all" |
3104d27abe81SAaron LI                 "from" ( "any" | "no-route" | "urpf-failed" | "self" | host |
3105d27abe81SAaron LI                 "{" host-list "}" | "route" string ) [ port ] [ os ]
3106d27abe81SAaron LI                 "to"   ( "any" | "no-route" | "self" | host |
3107d27abe81SAaron LI                 "{" host-list "}" | "route" string ) [ port ]
3108d27abe81SAaron LI
3109d27abe81SAaron LIipspec         = "any" | host | "{" host-list "}"
3110d27abe81SAaron LIhost           = [ "!" ] ( address [ "/" mask-bits ] | "\*(Lt" string "\*(Gt" )
3111d27abe81SAaron LIredirhost      = address [ "/" mask-bits ]
3112d27abe81SAaron LIroutehost      = "(" interface-name [ address [ "/" mask-bits ] ] ")"
31135304134cSAaron LIaddress        = ( interface-name | interface-group |
31145304134cSAaron LI                 "(" ( interface-name | interface-group ) ")" |
31155304134cSAaron LI                 hostname | ipv4-dotted-quad | ipv6-coloned-hex )
3116d27abe81SAaron LIhost-list      = host [ [ "," ] host-list ]
3117d27abe81SAaron LIredirhost-list = redirhost [ [ "," ] redirhost-list ]
3118d27abe81SAaron LIroutehost-list = routehost [ [ "," ] routehost-list ]
3119d27abe81SAaron LI
3120d27abe81SAaron LIport           = "port" ( unary-op | binary-op | "{" op-list "}" )
3121d27abe81SAaron LIportspec       = "port" ( number | name ) [ ":" ( "*" | number | name ) ]
3122d27abe81SAaron LIos             = "os" ( os-name | "{" os-list "}" )
3123d27abe81SAaron LIuser           = "user" ( unary-op | binary-op | "{" op-list "}" )
3124d27abe81SAaron LIgroup          = "group" ( unary-op | binary-op | "{" op-list "}" )
3125d27abe81SAaron LI
3126d27abe81SAaron LIunary-op       = [ "=" | "!=" | "\*(Lt" | "\*(Le" | "\*(Gt" | "\*(Ge" ]
3127d27abe81SAaron LI                 ( name | number )
3128d27abe81SAaron LIbinary-op      = number ( "\*(Lt\*(Gt" | "\*(Gt\*(Lt" | ":" ) number
3129d27abe81SAaron LIop-list        = ( unary-op | binary-op ) [ [ "," ] op-list ]
3130d27abe81SAaron LI
3131d27abe81SAaron LIos-name        = operating-system-name
3132d27abe81SAaron LIos-list        = os-name [ [ "," ] os-list ]
3133d27abe81SAaron LI
3134d27abe81SAaron LIflags          = "flags" ( [ flag-set ] "/" flag-set | "any" )
3135d27abe81SAaron LIflag-set       = [ "F" ] [ "S" ] [ "R" ] [ "P" ] [ "A" ] [ "U" ] [ "E" ]
3136d27abe81SAaron LI                 [ "W" ]
3137d27abe81SAaron LI
3138d27abe81SAaron LIicmp-type      = "icmp-type" ( icmp-type-code | "{" icmp-list "}" )
3139d27abe81SAaron LIicmp6-type     = "icmp6-type" ( icmp-type-code | "{" icmp-list "}" )
3140d27abe81SAaron LIicmp-type-code = ( icmp-type-name | icmp-type-number )
3141d27abe81SAaron LI                 [ "code" ( icmp-code-name | icmp-code-number ) ]
3142d27abe81SAaron LIicmp-list      = icmp-type-code [ [ "," ] icmp-list ]
3143d27abe81SAaron LI
3144d27abe81SAaron LItos            = ( "lowdelay" | "throughput" | "reliability" |
3145d27abe81SAaron LI                 [ "0x" ] number )
3146d27abe81SAaron LI
3147d27abe81SAaron LIstate-opts     = state-opt [ [ "," ] state-opts ]
3148d27abe81SAaron LIstate-opt      = "max" number | "no-sync" | timeout |
3149d27abe81SAaron LI                 "source-track" [ "rule" | "global" ] |
3150d27abe81SAaron LI                 "max-src-nodes" number | "max-src-states" number |
3151d27abe81SAaron LI                 "max-src-conn" number |
3152d27abe81SAaron LI                 "max-src-conn-rate" number "/" number |
3153d27abe81SAaron LI                 "overload" "\*(Lt" string "\*(Gt" [ "flush" ] |
3154d27abe81SAaron LI                 "if-bound" | "floating" |
3155d27abe81SAaron LI		 "pickups" | "no-pickups" | "hash-only"
3156d27abe81SAaron LI
3157d27abe81SAaron LIfragmentation  = [ "fragment reassemble" | "fragment crop" |
3158d27abe81SAaron LI                 "fragment drop-ovl" ]
3159d27abe81SAaron LI
3160d27abe81SAaron LItimeout-list   = timeout [ [ "," ] timeout-list ]
3161d27abe81SAaron LItimeout        = ( "tcp.first" | "tcp.opening" | "tcp.established" |
3162d27abe81SAaron LI                 "tcp.closing" | "tcp.finwait" | "tcp.closed" |
3163d27abe81SAaron LI                 "udp.first" | "udp.single" | "udp.multiple" |
3164d27abe81SAaron LI                 "icmp.first" | "icmp.error" |
3165d27abe81SAaron LI                 "other.first" | "other.single" | "other.multiple" |
3166d27abe81SAaron LI                 "frag" | "interval" | "src.track" |
3167d27abe81SAaron LI                 "adaptive.start" | "adaptive.end" ) number
3168d27abe81SAaron LI
3169d27abe81SAaron LIlimit-list     = limit-item [ [ "," ] limit-list ]
3170d27abe81SAaron LIlimit-item     = ( "states" | "frags" | "src-nodes" ) number
3171d27abe81SAaron LI
3172d27abe81SAaron LIpooltype       = ( "bitmask" | "random" |
3173d27abe81SAaron LI                 "source-hash" [ hex-key | string-key ] |
3174d27abe81SAaron LI                 "round-robin" ) [ sticky-address ]
3175d27abe81SAaron LI
3176d27abe81SAaron LIsubqueue       = string | "{" queue-list "}"
3177d27abe81SAaron LIqueue-list     = string [ [ "," ] string ]
3178d27abe81SAaron LI
3179d27abe81SAaron LIcbq-def        = "cbq" [ "(" cbq-opts ")" ]
3180d27abe81SAaron LIpriq-def       = "priq" [ "(" priq-opts ")" ]
3181d27abe81SAaron LIhfsc-def       = "hfsc" [ "(" hfsc-opts ")" ]
3182d27abe81SAaron LIfairq-def      = "fairq" [ "(" fairq-opts ")" ]
3183d27abe81SAaron LI
3184d27abe81SAaron LIcbq-opts       = cbq-opt [ [ "," ] cbq-opts ]
3185d27abe81SAaron LIpriq-opts      = priq-opt [ [ "," ] priq-opts ]
3186d27abe81SAaron LIhfsc-opts      = hfsc-opt [ [ "," ] hfsc-opts ]
3187d27abe81SAaron LIfairq-opts     = fairq-opt [ [ "," ] fairq-opts ]
3188d27abe81SAaron LI
3189d27abe81SAaron LIcbq-opt        = "default" | "borrow" | "red" | "ecn" | "rio"
3190d27abe81SAaron LIpriq-opt       = "default" | "red" | "ecn" | "rio"
3191d27abe81SAaron LIhfsc-opt       = "default" | "red" | "ecn" | "rio" |
3192d27abe81SAaron LI                 linkshare-sc | realtime-sc | upperlimit-sc
3193d27abe81SAaron LIfairq-opt      = "default" | "red" | "ecn" | "rio" |
3194d27abe81SAaron LI                 "buckets" number | "hogs" number | linkshare-sc
3195d27abe81SAaron LI
3196d27abe81SAaron LIlinkshare-sc   = "linkshare" sc-spec
3197d27abe81SAaron LIrealtime-sc    = "realtime" sc-spec
3198d27abe81SAaron LIupperlimit-sc  = "upperlimit" sc-spec
3199d27abe81SAaron LIsc-spec        = ( bandwidth-spec |
3200d27abe81SAaron LI                 "(" bandwidth-spec number bandwidth-spec ")" )
3201d27abe81SAaron LIinclude        = "include" filename
3202d27abe81SAaron LI.Ed
3203d27abe81SAaron LI.Sh FILES
3204d27abe81SAaron LI.Bl -tag -width ".Pa /usr/share/examples/pf" -compact
3205d27abe81SAaron LI.It Pa /etc/hosts
3206d27abe81SAaron LIHost name database.
3207d27abe81SAaron LI.It Pa /etc/pf.conf
3208d27abe81SAaron LIDefault location of the ruleset file.
3209d27abe81SAaron LI.It Pa /etc/pf.os
3210d27abe81SAaron LIDefault location of OS fingerprints.
3211d27abe81SAaron LI.It Pa /etc/protocols
3212d27abe81SAaron LIProtocol name database.
3213d27abe81SAaron LI.It Pa /etc/services
3214d27abe81SAaron LIService name database.
3215d27abe81SAaron LI.It Pa /usr/share/examples/pf
3216d27abe81SAaron LIExample rulesets.
3217d27abe81SAaron LI.El
3218d27abe81SAaron LI.Sh SEE ALSO
32195304134cSAaron LI.Xr altq 4 ,
3220d27abe81SAaron LI.Xr carp 4 ,
3221d27abe81SAaron LI.Xr icmp 4 ,
3222d27abe81SAaron LI.Xr icmp6 4 ,
3223d27abe81SAaron LI.Xr ip 4 ,
3224d27abe81SAaron LI.Xr ip6 4 ,
3225d27abe81SAaron LI.Xr pf 4 ,
3226d27abe81SAaron LI.Xr pfsync 4 ,
3227d27abe81SAaron LI.Xr route 4 ,
3228d27abe81SAaron LI.Xr tcp 4 ,
3229d27abe81SAaron LI.Xr udp 4 ,
3230d27abe81SAaron LI.Xr hosts 5 ,
3231d27abe81SAaron LI.Xr pf.os 5 ,
3232d27abe81SAaron LI.Xr protocols 5 ,
3233d27abe81SAaron LI.Xr services 5 ,
3234d27abe81SAaron LI.Xr ftp-proxy 8 ,
3235d27abe81SAaron LI.Xr pfctl 8 ,
3236d27abe81SAaron LI.Xr pflogd 8 ,
3237d27abe81SAaron LI.Xr route 8
3238d27abe81SAaron LI.Sh HISTORY
3239d27abe81SAaron LIThe
3240d27abe81SAaron LI.Nm
3241d27abe81SAaron LIfile format first appeared in
3242d27abe81SAaron LI.Ox 3.0 .
3243