Change 'then' to 'than' in comparisons.
[dragonfly.git] / usr.sbin / pfctl / pf.conf.5
1 .\"     $OpenBSD: pf.conf.5,v 1.291 2004/02/04 19:38:30 jmc Exp $
2 .\"     $DragonFly: src/usr.sbin/pfctl/pf.conf.5,v 1.16 2008/10/17 11:30:24 swildner Exp $
3 .\"
4 .\" Copyright (c) 2002, Daniel Hartmeier
5 .\" All rights reserved.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\"
11 .\"    - Redistributions of source code must retain the above copyright
12 .\"      notice, this list of conditions and the following disclaimer.
13 .\"    - Redistributions in binary form must reproduce the above
14 .\"      copyright notice, this list of conditions and the following
15 .\"      disclaimer in the documentation and/or other materials provided
16 .\"      with the distribution.
17 .\"
18 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 .\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 .\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 .\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 .\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 .\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 .\" POSSIBILITY OF SUCH DAMAGE.
30 .\"
31 .Dd April 6, 2008
32 .Dt PF.CONF 5
33 .Os
34 .Sh NAME
35 .Nm pf.conf
36 .Nd packet filter configuration file
37 .Sh DESCRIPTION
38 The
39 .Xr pf 4
40 packet filter modifies, drops or passes packets according to rules or
41 definitions specified in
42 .Nm .
43 .Sh STATEMENT ORDER
44 There are seven types of statements in
45 .Nm :
46 .Bl -tag -width xxxx
47 .It Cm Macros
48 User-defined variables may be defined and used later, simplifying
49 the configuration file.
50 Macros must be defined before they are referenced in
51 .Nm .
52 .It Cm Tables
53 Tables provide a mechanism for increasing the performance and flexibility of
54 rules with large numbers of source or destination addresses.
55 .It Cm Options
56 Options tune the behaviour of the packet filtering engine.
57 .It Cm Traffic Normalization Li (e.g.\& Em scrub )
58 Traffic normalization protects internal machines against inconsistencies
59 in Internet protocols and implementations.
60 .It Cm Queueing
61 Queueing provides rule-based bandwidth control.
62 .It Cm Translation Li (Various forms of NAT)
63 Translation rules specify how addresses are to be mapped or redirected to
64 other addresses.
65 .It Cm Packet Filtering
66 Stateful and stateless packet filtering provides rule-based blocking or
67 passing of packets.
68 .El
69 .Pp
70 With the exception of
71 .Cm macros
72 and
73 .Cm tables ,
74 the types of statements should be grouped and appear in
75 .Nm
76 in the order shown above, as this matches the operation of the underlying
77 packet filtering engine.
78 By default
79 .Xr pfctl 8
80 enforces this order (see
81 .Ar set require-order
82 below).
83 .Sh MACROS
84 Much like
85 .Xr cpp 1
86 or
87 .Xr m4 1 ,
88 macros can be defined that will later be expanded in context.
89 Macro names must start with a letter, and may contain letters, digits
90 and underscores.
91 Macro names may not be reserved words (for example
92 .Ar pass ,
93 .Ar in ,
94 .Ar out ) .
95 Macros are not expanded inside quotes.
96 .Pp
97 For example,
98 .Bd -literal -offset indent
99 ext_if = \&"kue0\&"
100 all_ifs = \&"{\&" $ext_if lo0 \&"}\&"
101 pass out on $ext_if from any to any keep state
102 pass in  on $ext_if proto tcp from any to any port 25 keep state
103 .Ed
104 .Sh TABLES
105 Tables are named structures which can hold a collection of addresses and
106 networks.
107 Lookups against tables in
108 .Xr pf 4
109 are relatively fast, making a single rule with tables much more efficient,
110 in terms of
111 processor usage and memory consumption, than a large number of rules which
112 differ only in IP address (either created explicitly or automatically by rule
113 expansion).
114 .Pp
115 Tables can be used as the source or destination of filter rules,
116 .Ar scrub
117 rules
118 or
119 translation rules such as
120 .Ar nat
121 or
122 .Ar rdr
123 (see below for details on the various rule types).
124 Tables can also be used for the redirect address of
125 .Ar nat
126 and
127 .Ar rdr
128 rules and in the routing options of filter rules, but only for
129 .Ar round-robin
130 pools.
131 .Pp
132 Tables can be defined with any of the following
133 .Xr pfctl 8
134 mechanisms.
135 As with macros, reserved words may not be used as table names.
136 .Bl -tag -width "manually"
137 .It Ar manually
138 Persistent tables can be manually created with the
139 .Ar add
140 or
141 .Ar replace
142 option of
143 .Xr pfctl 8 ,
144 before or after the ruleset has been loaded.
145 .It Pa pf.conf
146 Table definitions can be placed directly in this file, and loaded at the
147 same time as other rules are loaded, atomically.
148 Table definitions inside
149 .Nm
150 use the
151 .Ar table
152 statement, and are especially useful to define non-persistent tables.
153 The contents of a pre-existing table defined without a list of addresses
154 to initialize it is not altered when
155 .Nm
156 is loaded.
157 A table initialized with the empty list,
158 .Li { } ,
159 will be cleared on load.
160 .El
161 .Pp
162 Tables may be defined with the following two attributes:
163 .Bl -tag -width persist
164 .It Ar persist
165 The
166 .Ar persist
167 flag forces the kernel to keep the table even when no rules refer to it.
168 If the flag is not set, the kernel will automatically remove the table
169 when the last rule referring to it is flushed.
170 .It Ar const
171 The
172 .Ar const
173 flag prevents the user from altering the contents of the table once it
174 has been created.
175 Without that flag,
176 .Xr pfctl 8
177 can be used to add or remove addresses from the table at any time, even
178 when running with
179 .Xr securelevel 8
180 = 2.
181 .El
182 .Pp
183 For example,
184 .Bd -literal -offset indent
185 table <private> const { 10/8, 172.16/12, 192.168/16 }
186 table <badhosts> persist
187 block on fxp0 from { <private>, <badhosts> } to any
188 .Ed
189 .Pp
190 creates a table called private, to hold RFC 1918 private network
191 blocks, and a table called badhosts, which is initially empty.
192 A filter rule is set up to block all traffic coming from addresses listed in
193 either table.
194 The private table cannot have its contents changed and the badhosts table
195 will exist even when no active filter rules reference it.
196 Addresses may later be added to the badhosts table, so that traffic from
197 these hosts can be blocked by using
198 .Bd -literal -offset indent
199 # pfctl -t badhosts -Tadd 204.92.77.111
200 .Ed
201 .Pp
202 A table can also be initialized with an address list specified in one or more
203 external files, using the following syntax:
204 .Bd -literal -offset indent
205 table <spam> persist file \&"/etc/spammers\&" file \&"/etc/openrelays\&"
206 block on fxp0 from <spam> to any
207 .Ed
208 .Pp
209 The files
210 .Pa /etc/spammers
211 and
212 .Pa /etc/openrelays
213 list IP addresses, one per line.
214 Any lines beginning with a # are treated as comments and ignored.
215 In addition to being specified by IP address, hosts may also be
216 specified by their hostname.
217 When the resolver is called to add a hostname to a table,
218 .Em all
219 resulting IPv4 and IPv6 addresses are placed into the table.
220 IP addresses can also be entered in a table by specifying a valid interface
221 name or the
222 .Em self
223 keyword, in which case all addresses assigned to the interface(s) will be
224 added to the table.
225 .Sh OPTIONS
226 .Xr pf 4
227 may be tuned for various situations using the
228 .Ar set
229 command.
230 .Bl -tag -width xxxx
231 .It Ar set timeout
232 .Pp
233 .Bl -tag -width interval -compact
234 .It Ar interval
235 Interval between purging expired states and fragments.
236 .It Ar frag
237 Seconds before an unassembled fragment is expired.
238 .It Ar src.track
239 Length of time to retain a source tracking entry after the last state
240 expires.
241 .El
242 .Pp
243 When a packet matches a stateful connection, the seconds to live for the
244 connection will be updated to that of the
245 .Ar proto.modifier
246 which corresponds to the connection state.
247 Each packet which matches this state will reset the TTL.
248 Tuning these values may improve the performance of the
249 firewall at the risk of dropping valid idle connections.
250 .Pp
251 .Bl -tag -width xxxx -compact
252 .It Ar tcp.first
253 The state after the first packet.
254 .It Ar tcp.opening
255 The state before the destination host ever sends a packet.
256 .It Ar tcp.established
257 The fully established state.
258 .It Ar tcp.closing
259 The state after the first FIN has been sent.
260 .It Ar tcp.finwait
261 The state after both FINs have been exchanged and the connection is closed.
262 Some hosts (notably web servers on Solaris) send TCP packets even after closing
263 the connection.
264 Increasing
265 .Ar tcp.finwait
266 (and possibly
267 .Ar tcp.closing )
268 can prevent blocking of such packets.
269 .It Ar tcp.closed
270 The state after one endpoint sends an RST.
271 .El
272 .Pp
273 ICMP and UDP are handled in a fashion similar to TCP, but with a much more
274 limited set of states:
275 .Pp
276 .Bl -tag -width xxxx -compact
277 .It Ar udp.first
278 The state after the first packet.
279 .It Ar udp.single
280 The state if the source host sends more than one packet but the destination
281 host has never sent one back.
282 .It Ar udp.multiple
283 The state if both hosts have sent packets.
284 .It Ar icmp.first
285 The state after the first packet.
286 .It Ar icmp.error
287 The state after an ICMP error came back in response to an ICMP packet.
288 .El
289 .Pp
290 Other protocols are handled similarly to UDP:
291 .Pp
292 .Bl -tag -width xxxx -compact
293 .It Ar other.first
294 .It Ar other.single
295 .It Ar other.multiple
296 .El
297 .Pp
298 Timeout values can be reduced adaptively as the number of state table
299 entries grows.
300 .Pp
301 .Bl -tag -width xxxx -compact
302 .It Ar adaptive.start
303 When the number of state entries exceeds this value, adaptive scaling
304 begins.
305 All timeout values are scaled linearly with factor
306 (adaptive.end - number of states) / (adaptive.end - adaptive.start).
307 .It Ar adaptive.end
308 When reaching this number of state entries, all timeout values become
309 zero, effectively purging all state entries immediately.
310 This value is used to define the scale factor, it should not actually
311 be reached (set a lower state limit, see below).
312 .El
313 .Pp
314 These values can be defined both globally and for each rule.
315 When used on a per-rule basis, the values relate to the number of
316 states created by the rule, otherwise to the total number of
317 states.
318 .Pp
319 For example:
320 .Bd -literal -offset indent
321 set timeout tcp.first 120
322 set timeout tcp.established 86400
323 set timeout { adaptive.start 6000, adaptive.end 12000 }
324 set limit states 10000
325 .Ed
326 .Pp
327 With 9000 state table entries, the timeout values are scaled to 50%
328 (tcp.first 60, tcp.established 43200).
329 .Pp
330 .It Ar set loginterface
331 Enable collection of packet and byte count statistics for the given interface.
332 These statistics can be viewed using
333 .Bd -literal -offset indent
334 # pfctl -s info
335 .Ed
336 .Pp
337 In this example
338 .Xr pf 4
339 collects statistics on the interface named dc0:
340 .Bd -literal -offset indent
341 set loginterface dc0
342 .Ed
343 .Pp
344 One can disable the loginterface using:
345 .Bd -literal -offset indent
346 set loginterface none
347 .Ed
348 .Pp
349 .It Ar set limit
350 Sets hard limits on the memory zones used by the packet filter.
351 See
352 .Xr zone 9
353 for an explanation of memory zones.
354 .Pp
355 For example,
356 .Bd -literal -offset indent
357 set limit states 20000
358 .Ed
359 .Pp
360 sets the maximum number of entries in the memory pool used by state table
361 entries (generated by
362 .Ar keep state
363 rules) to 20000.
364 Using
365 .Bd -literal -offset indent
366 set limit frags 20000
367 .Ed
368 .Pp
369 sets the maximum number of entries in the memory pool used for fragment
370 reassembly (generated by
371 .Ar scrub
372 rules) to 20000.
373 Finally,
374 .Bd -literal -offset indent
375 set limit src-nodes 2000
376 .Ed
377 .Pp
378 sets the maximum number of entries in the memory pool used for tracking
379 source IP addresses (generated by the
380 .Ar sticky-address
381 and
382 .Ar source-track
383 options) to 2000.
384 .Pp
385 These can be combined:
386 .Bd -literal -offset indent
387 set limit { states 20000, frags 20000, src-nodes 2000 }
388 .Ed
389 .Pp
390 .It Ar set optimization
391 Optimize the engine for one of the following network environments:
392 .Pp
393 .Bl -tag -width xxxx -compact
394 .It Ar normal
395 A normal network environment.
396 Suitable for almost all networks.
397 .It Ar high-latency
398 A high-latency environment (such as a satellite connection).
399 .It Ar satellite
400 Alias for
401 .Ar high-latency .
402 .It Ar aggressive
403 Aggressively expire connections.
404 This can greatly reduce the memory usage of the firewall at the cost of
405 dropping idle connections early.
406 .It Ar conservative
407 Extremely conservative settings.
408 Avoid dropping legitimate connections at the
409 expense of greater memory utilization (possibly much greater on a busy
410 network) and slightly increased processor utilization.
411 .El
412 .Pp
413 For example:
414 .Bd -literal -offset indent
415 set optimization aggressive
416 .Ed
417 .Pp
418 .It Ar set keep-policy keep_rule
419 The
420 .Ar keep-policy
421 option sets the default state retention policy for all
422 .Ar pass
423 rules.
424 See
425 .Sx STATEFUL TRACKING OPTIONS
426 or
427 .Sx GRAMMAR
428 (keep) for format of
429 .Ar keep_rule .
430 Any
431 .Ar no Ns / Ns Ar keep Ns / Ns Ar modulate Ns / Ns Ar synproxy state
432 directives in a
433 .Ar pass
434 rule will override the default.
435 For example:
436 .Bd -literal -offset indent
437 set keep-policy keep state (pickups)
438 .Ed
439 .Pp
440 .It Ar set block-policy
441 The
442 .Ar block-policy
443 option sets the default behaviour for the packet
444 .Ar block
445 action:
446 .Pp
447 .Bl -tag -width xxxxxxxx -compact
448 .It Ar drop
449 Packet is silently dropped.
450 .It Ar return
451 A TCP RST is returned for blocked TCP packets,
452 an ICMP UNREACHABLE is returned for blocked UDP packets,
453 and all other packets are silently dropped.
454 .El
455 .Pp
456 For example:
457 .Bd -literal -offset indent
458 set block-policy return
459 .Ed
460 .It Ar set state-policy
461 The
462 .Ar state-policy
463 option sets the default behaviour for states:
464 .Pp
465 .Bl -tag -width group-bound -compact
466 .It Ar if-bound
467 States are bound to interface.
468 .It Ar group-bound
469 States are bound to interface group (i.e., ppp)
470 .It Ar floating
471 States can match packets on any interfaces (the default).
472 .El
473 .Pp
474 For example:
475 .Bd -literal -offset indent
476 set state-policy if-bound
477 .Ed
478 .It Ar set require-order
479 By default
480 .Xr pfctl 8
481 enforces an ordering of the statement types in the ruleset to:
482 .Em options ,
483 .Em normalization ,
484 .Em queueing ,
485 .Em translation ,
486 .Em filtering .
487 Setting this option to
488 .Ar no
489 disables this enforcement.
490 There may be non-trivial and non-obvious implications to an out of
491 order ruleset.
492 Consider carefully before disabling the order enforcement.
493 .It Ar set fingerprints
494 Load fingerprints of known operating systems from the given filename.
495 By default fingerprints of known operating systems are automatically
496 loaded from
497 .Xr pf.os 5
498 in
499 .Pa /etc
500 but can be overridden via this option.
501 Setting this option may leave a small period of time where the fingerprints
502 referenced by the currently active ruleset are inconsistent until the new
503 ruleset finishes loading.
504 .Pp
505 For example:
506 .Pp
507 .Dl set fingerprints \&"/etc/pf.os.devel\&"
508 .Pp
509 .It Ar set debug
510 Set the debug
511 .Ar level
512 to one of the following:
513 .Pp
514 .Bl -tag -width xxxxxxxxxxxx -compact
515 .It Ar none
516 Don't generate debug messages.
517 .It Ar urgent
518 Generate debug messages only for serious errors.
519 .It Ar misc
520 Generate debug messages for various errors.
521 .It Ar loud
522 Generate debug messages for common conditions.
523 .El
524 .El
525 .Sh TRAFFIC NORMALIZATION
526 Traffic normalization is used to sanitize packet content in such
527 a way that there are no ambiguities in packet interpretation on
528 the receiving side.
529 The normalizer does IP fragment reassembly to prevent attacks
530 that confuse intrusion detection systems by sending overlapping
531 IP fragments.
532 Packet normalization is invoked with the
533 .Ar scrub
534 directive.
535 .Pp
536 .Ar scrub
537 has the following options:
538 .Bl -tag -width xxxx
539 .It Ar no-df
540 Clears the
541 .Ar dont-fragment
542 bit from a matching IP packet.
543 Some operating systems are known to generate fragmented packets with the
544 .Ar dont-fragment
545 bit set.
546 This is particularly true with NFS.
547 .Ar Scrub
548 will drop such fragmented
549 .Ar dont-fragment
550 packets unless
551 .Ar no-df
552 is specified.
553 .Pp
554 Unfortunately some operating systems also generate their
555 .Ar dont-fragment
556 packets with a zero IP identification field.
557 Clearing the
558 .Ar dont-fragment
559 bit on packets with a zero IP ID may cause deleterious results if an
560 upstream router later fragments the packet.
561 Using the
562 .Ar random-id
563 modifier (see below) is recommended in combination with the
564 .Ar no-df
565 modifier to ensure unique IP identifiers.
566 .It Ar min-ttl <number>
567 Enforces a minimum TTL for matching IP packets.
568 .It Ar max-mss <number>
569 Enforces a maximum MSS for matching TCP packets.
570 .It Ar random-id
571 Replaces the IP identification field with random values to compensate
572 for predictable values generated by many hosts.
573 This option only applies to outgoing packets that are not fragmented
574 after the optional fragment reassembly.
575 .It Ar fragment reassemble
576 Using
577 .Ar scrub
578 rules, fragments can be reassembled by normalization.
579 In this case, fragments are buffered until they form a complete
580 packet, and only the completed packet is passed on to the filter.
581 The advantage is that filter rules have to deal only with complete
582 packets, and can ignore fragments.
583 The drawback of caching fragments is the additional memory cost.
584 But the full reassembly method is the only method that currently works
585 with NAT.
586 This is the default behavior of a
587 .Ar scrub
588 rule if no fragmentation modifier is supplied.
589 .It Ar fragment crop
590 The default fragment reassembly method is expensive, hence the option
591 to crop is provided.
592 In this case,
593 .Xr pf 4
594 will track the fragments and cache a small range descriptor.
595 Duplicate fragments are dropped and overlaps are cropped.
596 Thus data will only occur once on the wire with ambiguities resolving to
597 the first occurrence.
598 Unlike the
599 .Ar fragment reassemble
600 modifier, fragments are not buffered, they are passed as soon as they
601 are received.
602 The
603 .Ar fragment crop
604 reassembly mechanism does not yet work with NAT.
605 .Pp
606 .It Ar fragment drop-ovl
607 This option is similar to the
608 .Ar fragment crop
609 modifier except that all overlapping or duplicate fragments will be
610 dropped, and all further corresponding fragments will be
611 dropped as well.
612 .It Ar reassemble tcp
613 Statefully normalizes TCP connections.
614 .Ar scrub reassemble tcp
615 rules may not have the direction (in/out) specified.
616 .Ar reassemble tcp
617 performs the following normalizations:
618 .Pp
619 .Bl -tag -width timeout -compact
620 .It ttl
621 Neither side of the connection is allowed to reduce their IP TTL.
622 An attacker may send a packet such that it reaches the firewall, affects
623 the firewall state, and expires before reaching the destination host.
624 .Ar reassemble tcp
625 will raise the TTL of all packets back up to the highest value seen on
626 the connection.
627 .It timeout modulation
628 Modern TCP stacks will send a timestamp on every TCP packet and echo
629 the other endpoint's timestamp back to them.
630 Many operating systems will merely start the timestamp at zero when
631 first booted, and increment it several times a second.
632 The uptime of the host can be deduced by reading the timestamp and multiplying
633 by a constant.
634 Also observing several different timestamps can be used to count hosts
635 behind a NAT device.
636 And spoofing TCP packets into a connection requires knowing or guessing
637 valid timestamps.
638 Timestamps merely need to be monotonically increasing and not derived off a
639 guessable base time.
640 .Ar reassemble tcp
641 will cause
642 .Ar scrub
643 to modulate the TCP timestamps with a random number.
644 .El
645 .El
646 .Pp
647 For example,
648 .Bd -literal -offset indent
649 scrub in on $ext_if all fragment reassemble
650 .Ed
651 .Sh QUEUEING
652 Packets can be assigned to queues for the purpose of bandwidth
653 control.
654 At least two declarations are required to configure queues, and later
655 any packet filtering rule can reference the defined queues by name.
656 During the filtering component of
657 .Nm ,
658 the last referenced
659 .Ar queue
660 name is where any packets from
661 .Ar pass
662 rules will be queued, while for
663 .Ar block
664 rules it specifies where any resulting ICMP or TCP RST
665 packets should be queued.
666 The
667 .Ar scheduler
668 defines the algorithm used to decide which packets get delayed, dropped, or
669 sent out immediately.
670 There are four
671 .Ar schedulers
672 currently supported.
673 .Bl -tag -width xxxx
674 .It Ar cbq
675 Class Based Queueing.
676 .Ar Queues
677 attached to an interface build a tree, thus each
678 .Ar queue
679 can have further child
680 .Ar queues .
681 Each queue can have a
682 .Ar priority
683 and a
684 .Ar bandwidth
685 assigned.
686 .Ar Priority
687 mainly controls the time packets take to get sent out, while
688 .Ar bandwidth
689 has primarily effects on throughput.
690 .It Ar priq
691 Priority Queueing.
692 .Ar Queues
693 are flat attached to the interface, thus,
694 .Ar queues
695 cannot have further child
696 .Ar queues .
697 Each
698 .Ar queue
699 has a unique
700 .Ar priority
701 assigned, ranging from 0 to 15.
702 Packets in the
703 .Ar queue
704 with the highest
705 .Ar priority
706 are processed first.
707 .It Ar hfsc
708 Hierarchical Fair Service Curve.
709 .Ar Queues
710 attached to an interface build a tree, thus each
711 .Ar queue
712 can have further child
713 .Ar queues .
714 Each queue can have a
715 .Ar priority
716 and a
717 .Ar bandwidth
718 assigned.
719 .Ar Priority
720 mainly controls the time packets take to get sent out, while
721 .Ar bandwidth
722 has primarily effects on throughput.
723 .It Ar fairq
724 Fair Queue.
725 .Ar Queues
726 are flat attached to the interface, thus,
727 .Ar queues
728 cannot have further child
729 .Ar queues .
730 Each queue must be given a unique
731 .Ar priority
732 and one must be marked
733 as the default queue.
734 Each queue implements a number of
735 .Ar buckets
736 (default 256) which sorts the
737 traffic based on a hash key generated by the
738 .Ar keep state
739 facility in your
740 .Ar pass
741 rules.
742 Each bucket contains a list of packets controlled by
743 .Ar qlimit .
744 In order for
745 .Ar fairq
746 to function properly,
747 .Ar keep state
748 must be enabled on most of the rule sets that route packets to the queue.
749 Any rules for which keep state is not enabled are added to the end of the
750 queue.
751 If you do not wish keep state to do TCP sequence space checks use
752 .Ar "keep state (no-pickups)"
753 or
754 .Ar "keep state (hash-only)" .
755 .Pp
756 Packet selection operates as follows:
757 The queues are scanned from highest priority to lowest priority.
758 If a queue has pending packets and has not reached its bandwidth limit the
759 scan stops and a packet is selected from that queue.
760 If a queue has reached its bandwidth limit the scan continues searching for
761 other, lower priority queues which have not.
762 If no queue is found to be
763 suitable then the highest priority queue with pending packets is used
764 regardless of whether it has reached its bandwidth limit or not.
765 .Pp
766 A
767 .Ar fairq
768 round robins between its
769 .Ar buckets ,
770 extracting one packet from each bucket.
771 This essentially prevents large backlogs of packets from high volume
772 connections from destroying the interactive response of other connections.
773 .Pp
774 The
775 .Ar bandwidth
776 parameter for a
777 .Ar fairq
778 is guaranteed minimum and more will be used if no higher priority traffic is
779 present.
780 Creating a queue with one bucket as a catch-all for
781 .Ar pass
782 rules not characterized by
783 .Ar keep state
784 is supported.
785 Such a queue serves as a basic priority queue with a bandwidth specification.
786 .El
787 .Pp
788 The interfaces on which queueing should be activated are declared using
789 the
790 .Ar altq on
791 declaration.
792 .Ar altq on
793 has the following keywords:
794 .Bl -tag -width xxxx
795 .It Ar <interface>
796 Queueing is enabled on the named interface.
797 .It Ar <scheduler>
798 Specifies which queueing scheduler to use.
799 Currently supported values
800 are
801 .Ar cbq
802 for Class Based Queueing,
803 .Ar priq
804 for Priority Queueing,
805 .Ar hfsc
806 for the Hierarchical Fair Service Curve scheduler, and
807 .Ar fairq
808 for the Fair Queueing.
809 .It Ar bandwidth <bw>
810 The maximum bitrate for all queues on an
811 interface may be specified using the
812 .Ar bandwidth
813 keyword.
814 The value can be specified as an absolute value or as a
815 percentage of the interface bandwidth.
816 When using an absolute value, the suffixes
817 .Ar b ,
818 .Ar Kb ,
819 .Ar Mb ,
820 and
821 .Ar Gb
822 are used to represent bits, kilobits, megabits, and
823 gigabits per second, respectively.
824 The value must not exceed the interface bandwidth.
825 If
826 .Ar bandwidth
827 is not specified, the interface bandwidth is used.
828 .Pp
829 When used with
830 .Ar fairq ,
831 .Ar bandwidth
832 specifies a guaranteed minimum but the fairq is allowed to exceed it.
833 .It Ar qlimit <limit>
834 The maximum number of packets held in the queue.
835 The default is 50.
836 .It Ar tbrsize <size>
837 Adjusts the size, in bytes, of the token bucket regulator.
838 If not specified, heuristics based on the
839 interface bandwidth are used to determine the size.
840 .It Ar queue <list>
841 Defines a list of subqueues to create on an interface.
842 .El
843 .Pp
844 In the following example, the interface dc0
845 should queue up to 5 Mbit/s in four second-level queues using
846 Class Based Queueing.
847 Those four queues will be shown in a later example.
848 .Bd -literal -offset indent
849 altq on dc0 cbq bandwidth 5Mb queue { std, http, mail, ssh }
850 .Ed
851 .Pp
852 Once interfaces are activated for queueing using the
853 .Ar altq
854 directive, a sequence of
855 .Ar queue
856 directives may be defined.
857 The name associated with a
858 .Ar queue
859 must match a queue defined in the
860 .Ar altq
861 directive (e.g.\& mail), or, except for the
862 .Ar priq
863 and
864 .Ar fairq
865 .Ar schedulers ,
866 in a parent
867 .Ar queue
868 declaration.
869 The following keywords can be used:
870 .Bl -tag -width xxxx
871 .It Ar on <interface>
872 Specifies the interface the queue operates on.
873 If not given, it operates on all matching interfaces.
874 .It Ar bandwidth <bw>
875 Specifies the maximum bitrate to be processed by the queue.
876 This value must not exceed the value of the parent
877 .Ar queue
878 and can be specified as an absolute value or a percentage of the parent
879 queue's bandwidth.
880 The
881 .Ar priq
882 scheduler does not support bandwidth specification.
883 The
884 .Ar fairq
885 scheduler uses the bandwidth specification as a guaranteed minimum and
886 may exceed it.
887 .It Ar priority <level>
888 Between queues a priority level can be set.
889 For
890 .Ar cbq ,
891 .Ar hfsc ,
892 and
893 .Ar fairq
894 the range is 0 to 7 and for
895 .Ar priq ,
896 the range is 0 to 15.
897 The default for all is 1.
898 .Ar Priq
899 queues with a higher priority are always served first.
900 .Ar Fairq
901 queues with a higher priority are served first unless they exceed their
902 bandwidth specification.
903 .Ar Cbq
904 and
905 .Ar hfsc
906 queues with a higher priority are preferred in the case of overload.
907 .It Ar qlimit <limit>
908 The maximum number of packets held in the queue.
909 The default is 50.
910 When used with a
911 .Ar fairq
912 this specified the maximum number of packets held per bucket.
913 .El
914 .Pp
915 The
916 .Ar scheduler
917 can get additional parameters with
918 .Ar "<scheduler>(<parameters>)" .
919 Parameters are as follows:
920 .Bl -tag -width Fl
921 .It Ar default
922 Packets not matched by another queue are assigned to this one.
923 Exactly one default queue is required.
924 .It Ar red
925 Enable RED (Random Early Detection) on this queue.
926 RED drops packets with a probability proportional to the average
927 queue length.
928 .It Ar rio
929 Enables RIO on this queue.
930 RIO is RED with IN/OUT, thus running
931 RED two times more than RIO would achieve the same effect.
932 .It Ar ecn
933 Enables ECN (Explicit Congestion Notification) on this queue.
934 ECN implies RED.
935 .El
936 .Pp
937 The
938 .Ar fairq
939 .Ar scheduler
940 supports the following additional options:
941 .Bl -tag -width Fl
942 .It Ar buckets <number>
943 Specify the number of buckets, from 1 to 2048 in powers of 2.
944 A bucket size of 1 causes a
945 .Ar fairq
946 to essentially degenerate into a priority queue.
947 .It Ar linkshare <sc>
948 The bandwidth share of a backlogged queue.
949 This option is parsed but not yet supported.
950 .It Ar hogs <bandwidth>
951 This option allows low bandwidth connections to burst up to the specified
952 bandwidth by not advancing the round robin when taking packets out of
953 the related queue.
954 When using this option a small value no greater than 1/20 available interface
955 bandwidth is recommended.
956 .El
957 .Pp
958 The
959 .Ar cbq
960 .Ar scheduler
961 supports an additional option:
962 .Bl -tag -width Fl
963 .It Ar borrow
964 The queue can borrow bandwidth from the parent.
965 .El
966 .Pp
967 The
968 .Ar hfsc
969 .Ar scheduler
970 supports some additional options:
971 .Bl -tag -width Fl
972 .It Ar realtime <sc>
973 The minimum required bandwidth for the queue.
974 .It Ar upperlimit <sc>
975 The maximum allowed bandwidth for the queue.
976 .It Ar linkshare <sc>
977 The bandwidth share of a backlogged queue.
978 .El
979 .Pp
980 .Ar <sc>
981 is an acronym for
982 .Ar service curve .
983 .Pp
984 The format for service curve specifications is
985 .Ar m2
986 or
987 .Ar "(m1 d m2)" .
988 .Ar m2
989 controls the bandwidth assigned to the queue.
990 .Ar m1
991 and
992 .Ar d
993 are optional and can be used to control the initial bandwidth assignment.
994 For the first
995 .Ar d
996 milliseconds the queue gets the bandwidth given as
997 .Ar m1 ,
998 afterwards the value given in
999 .Ar m2 .
1000 .Pp
1001 Furthermore, with
1002 .Ar cbq
1003 and
1004 .Ar hfsc ,
1005 child queues can be specified as in an
1006 .Ar altq
1007 declaration, thus building a tree of queues using a part of
1008 their parent's bandwidth.
1009 .Pp
1010 Packets can be assigned to queues based on filter rules by using the
1011 .Ar queue
1012 keyword.
1013 Normally only one
1014 .Ar queue
1015 is specified; when a second one is specified it will instead be used for
1016 packets which have a
1017 .Em TOS
1018 of
1019 .Em lowdelay
1020 and for TCP ACKs with no data payload.
1021 .Pp
1022 To continue the previous example, the examples below would specify the
1023 four referenced
1024 queues, plus a few child queues.
1025 Interactive
1026 .Xr ssh 1
1027 sessions get priority over bulk transfers like
1028 .Xr scp 1
1029 and
1030 .Xr sftp 1 .
1031 The queues may then be referenced by filtering rules (see
1032 .Sx PACKET FILTERING
1033 below).
1034 .Bd -literal
1035 queue std bandwidth 10% cbq(default)
1036 queue http bandwidth 60% priority 2 cbq(borrow red) \e
1037       { employees, developers }
1038 queue  developers bandwidth 75% cbq(borrow)
1039 queue  employees bandwidth 15%
1040 queue mail bandwidth 10% priority 0 cbq(borrow ecn)
1041 queue ssh bandwidth 20% cbq(borrow) { ssh_interactive, ssh_bulk }
1042 queue  ssh_interactive priority 7
1043 queue  ssh_bulk priority 0
1044
1045 block return out on dc0 inet all queue std
1046 pass out on dc0 inet proto tcp from $developerhosts to any port 80 \e
1047       keep state queue developers
1048 pass out on dc0 inet proto tcp from $employeehosts to any port 80 \e
1049       keep state queue employees
1050 pass out on dc0 inet proto tcp from any to any port 22 \e
1051       keep state queue(ssh_bulk, ssh_interactive)
1052 pass out on dc0 inet proto tcp from any to any port 25 \e
1053       keep state queue mail
1054 .Ed
1055 .Sh TRANSLATION
1056 Translation rules modify either the source or destination address of the
1057 packets associated with a stateful connection.
1058 A stateful connection is automatically created to track packets matching
1059 such a rule as long as they are not blocked by the filtering section of
1060 .Nm .
1061 The translation engine modifies the specified address and/or port in the
1062 packet, recalculates IP, TCP and UDP checksums as necessary, and passes it to
1063 the packet filter for evaluation.
1064 .Pp
1065 Since translation occurs before filtering the filter
1066 engine will see packets as they look after any
1067 addresses and ports have been translated.
1068 Filter rules will therefore have to filter based on the translated
1069 address and port number.
1070 Packets that match a translation rule are only automatically passed if
1071 the
1072 .Ar pass
1073 modifier is given, otherwise they are
1074 still subject to
1075 .Ar block
1076 and
1077 .Ar pass
1078 rules.
1079 .Pp
1080 The state entry created permits
1081 .Xr pf 4
1082 to keep track of the original address for traffic associated with that state
1083 and correctly direct return traffic for that connection.
1084 .Pp
1085 Various types of translation are possible with pf:
1086 .Bl -tag -width xxxx
1087 .It Ar binat
1088 A
1089 .Ar binat
1090 rule specifies a bidirectional mapping between an external IP netblock
1091 and an internal IP netblock.
1092 .It Ar nat
1093 A
1094 .Ar nat
1095 rule specifies that IP addresses are to be changed as the packet
1096 traverses the given interface.
1097 This technique allows one or more IP addresses
1098 on the translating host to support network traffic for a larger range of
1099 machines on an "inside" network.
1100 Although in theory any IP address can be used on the inside, it is strongly
1101 recommended that one of the address ranges defined by RFC 1918 be used.
1102 These netblocks are:
1103 .Bd -literal
1104 10.0.0.0 - 10.255.255.255 (all of net 10, i.e., 10/8)
1105 172.16.0.0 - 172.31.255.255 (i.e., 172.16/12)
1106 192.168.0.0 - 192.168.255.255 (i.e., 192.168/16)
1107 .Ed
1108 .It Pa rdr
1109 The packet is redirected to another destination and possibly a
1110 different port.
1111 .Ar rdr
1112 rules can optionally specify port ranges instead of single ports.
1113 rdr ... port 2000:2999 -> ... port 4000
1114 redirects ports 2000 to 2999 (inclusive) to port 4000.
1115 rdr ... port 2000:2999 -> ... port 4000:*
1116 redirects port 2000 to 4000, 2001 to 4001, ..., 2999 to 4999.
1117 .El
1118 .Pp
1119 In addition to modifying the address, some translation rules may modify
1120 source or destination ports for
1121 .Xr tcp 4
1122 or
1123 .Xr udp 4
1124 connections; implicitly in the case of
1125 .Ar nat
1126 rules and explicitly in the case of
1127 .Ar rdr
1128 rules.
1129 Port numbers are never translated with a
1130 .Ar binat
1131 rule.
1132 .Pp
1133 For each packet processed by the translator, the translation rules are
1134 evaluated in sequential order, from first to last.
1135 The first matching rule decides what action is taken.
1136 .Pp
1137 The
1138 .Ar no
1139 option prefixed to a translation rule causes packets to remain untranslated,
1140 much in the same way as
1141 .Ar drop quick
1142 works in the packet filter (see below).
1143 If no rule matches the packet it is passed to the filter engine unmodified.
1144 .Pp
1145 Translation rules apply only to packets that pass through
1146 the specified interface, and if no interface is specified,
1147 translation is applied to packets on all interfaces.
1148 For instance, redirecting port 80 on an external interface to an internal
1149 web server will only work for connections originating from the outside.
1150 Connections to the address of the external interface from local hosts will
1151 not be redirected, since such packets do not actually pass through the
1152 external interface.
1153 Redirections cannot reflect packets back through the interface they arrive
1154 on, they can only be redirected to hosts connected to different interfaces
1155 or to the firewall itself.
1156 .Pp
1157 Note that redirecting external incoming connections to the loopback
1158 address, as in
1159 .Bd -literal -offset indent
1160 rdr on ne3 inet proto tcp to port 8025 -> 127.0.0.1 port 25
1161 .Ed
1162 .Pp
1163 will effectively allow an external host to connect to daemons
1164 bound solely to the loopback address, circumventing the traditional
1165 blocking of such connections on a real interface.
1166 Unless this effect is desired, any of the local non-loopback addresses
1167 should be used as redirection target instead, which allows external
1168 connections only to daemons bound to this address or not bound to
1169 any address.
1170 .Pp
1171 See
1172 .Sx TRANSLATION EXAMPLES
1173 below.
1174 .Sh PACKET FILTERING
1175 .Xr pf 4
1176 has the ability to
1177 .Ar block
1178 and
1179 .Ar pass
1180 packets based on attributes of their layer 3 (see
1181 .Xr ip 4
1182 and
1183 .Xr ip6 4 )
1184 and layer 4 (see
1185 .Xr icmp 4 ,
1186 .Xr icmp6 4 ,
1187 .Xr tcp 4 ,
1188 .Xr udp 4 )
1189 headers.
1190 In addition, packets may also be
1191 assigned to queues for the purpose of bandwidth control.
1192 .Pp
1193 For each packet processed by the packet filter, the filter rules are
1194 evaluated in sequential order, from first to last.
1195 The last matching rule decides what action is taken.
1196 .Pp
1197 The following actions can be used in the filter:
1198 .Bl -tag -width xxxx
1199 .It Ar block
1200 The packet is blocked.
1201 There are a number of ways in which a
1202 .Ar block
1203 rule can behave when blocking a packet.
1204 The default behaviour is to
1205 .Ar drop
1206 packets silently, however this can be overridden or made
1207 explicit either globally, by setting the
1208 .Ar block-policy
1209 option, or on a per-rule basis with one of the following options:
1210 .Pp
1211 .Bl -tag -width xxxx -compact
1212 .It Ar drop
1213 The packet is silently dropped.
1214 .It Ar return-rst
1215 This applies only to
1216 .Xr tcp 4
1217 packets, and issues a TCP RST which closes the
1218 connection.
1219 .It Ar return-icmp
1220 .It Ar return-icmp6
1221 This causes ICMP messages to be returned for packets which match the rule.
1222 By default this is an ICMP UNREACHABLE message, however this
1223 can be overridden by specifying a message as a code or number.
1224 .It Ar return
1225 This causes a TCP RST to be returned for
1226 .Xr tcp 4
1227 packets and an ICMP UNREACHABLE for UDP and other packets.
1228 .El
1229 .Pp
1230 Options returning packets have no effect if
1231 .Xr pf 4
1232 operates on a
1233 .Xr bridge 4 .
1234 .It Ar pass
1235 The packet is passed.
1236 .El
1237 .Pp
1238 If no rule matches the packet, the default action is
1239 .Ar pass .
1240 .Pp
1241 To block everything by default and only pass packets
1242 that match explicit rules, one uses
1243 .Bd -literal -offset indent
1244 block all
1245 .Ed
1246 .Pp
1247 as the first filter rule.
1248 .Pp
1249 See
1250 .Sx FILTER EXAMPLES
1251 below.
1252 .Sh PARAMETERS
1253 The rule parameters specify the packets to which a rule applies.
1254 A packet always comes in on, or goes out through, one interface.
1255 Most parameters are optional.
1256 If a parameter is specified, the rule only applies to packets with
1257 matching attributes.
1258 Certain parameters can be expressed as lists, in which case
1259 .Xr pfctl 8
1260 generates all needed rule combinations.
1261 .Bl -tag -width xxxx
1262 .It Ar in No or Ar out
1263 This rule applies to incoming or outgoing packets.
1264 If neither
1265 .Ar in
1266 nor
1267 .Ar out
1268 are specified, the rule will match packets in both directions.
1269 .It Ar log
1270 In addition to the action specified, a log message is generated.
1271 All packets for that connection are logged, unless the
1272 .Ar keep state ,
1273 .Ar modulate state
1274 or
1275 .Ar synproxy state
1276 options are specified, in which case only the
1277 packet that establishes the state is logged.
1278 (See
1279 .Ar keep state ,
1280 .Ar modulate state
1281 and
1282 .Ar synproxy state
1283 below).
1284 The logged packets are sent to the
1285 .Xr pflog 4
1286 interface.
1287 This interface is monitored by the
1288 .Xr pflogd 8
1289 logging daemon, which dumps the logged packets to the file
1290 .Pa /var/log/pflog
1291 in
1292 .Xr pcap 3
1293 binary format.
1294 .It Ar log-all
1295 Used with
1296 .Ar keep state ,
1297 .Ar modulate state
1298 or
1299 .Ar synproxy state
1300 rules to force logging of all packets for a connection.
1301 As with
1302 .Ar log ,
1303 packets are logged to
1304 .Xr pflog 4 .
1305 .It Ar quick
1306 If a packet matches a rule which has the
1307 .Ar quick
1308 option set, this rule
1309 is considered the last matching rule, and evaluation of subsequent rules
1310 is skipped.
1311 .It Ar on <interface>
1312 This rule applies only to packets coming in on, or going out through, this
1313 particular interface.
1314 It is also possible to simply give the interface driver name, like ppp or fxp,
1315 to make the rule match packets flowing through a group of interfaces.
1316 .It Ar <af>
1317 This rule applies only to packets of this address family.
1318 Supported values are
1319 .Ar inet
1320 and
1321 .Ar inet6 .
1322 .It Ar proto <protocol>
1323 This rule applies only to packets of this protocol.
1324 Common protocols are
1325 .Xr icmp 4 ,
1326 .Xr icmp6 4 ,
1327 .Xr tcp 4 ,
1328 and
1329 .Xr udp 4 .
1330 For a list of all the protocol name to number mappings used by
1331 .Xr pfctl 8 ,
1332 see the file
1333 .Pa /etc/protocols .
1334 .It Xo
1335 .Ar from <source> port <source> os <source>
1336 .Ar to <dest> port <dest>
1337 .Xc
1338 This rule applies only to packets with the specified source and destination
1339 addresses and ports.
1340 .Pp
1341 Addresses can be specified in CIDR notation (matching netblocks), as
1342 symbolic host names or interface names, or as any of the following keywords:
1343 .Pp
1344 .Bl -tag -width xxxxxxxxxxxx -compact
1345 .It Ar any
1346 Any address.
1347 .It Ar no-route
1348 Any address which is not currently routable.
1349 .It Ar <table>
1350 Any address that matches the given table.
1351 .El
1352 .Pp
1353 Interface names can have modifiers appended:
1354 .Pp
1355 .Bl -tag -width xxxxxxxxxxxx -compact
1356 .It Ar :network
1357 Translates to the network(s) attached to the interface.
1358 .It Ar :broadcast
1359 Translates to the interface's broadcast address(es).
1360 .It Ar :peer
1361 Translates to the point to point interface's peer address(es).
1362 .It Ar :0
1363 Do not include interface aliases.
1364 .El
1365 .Pp
1366 Host names may also have the
1367 .Ar :0
1368 option appended to restrict the name resolution to the first of each
1369 v4 and v6 address found.
1370 .Pp
1371 Host name resolution and interface to address translation are done at
1372 ruleset load-time.
1373 When the address of an interface (or host name) changes (under DHCP or PPP,
1374 for instance), the ruleset must be reloaded for the change to be reflected
1375 in the kernel.
1376 Surrounding the interface name (and optional modifiers) in parentheses
1377 changes this behaviour.
1378 When the interface name is surrounded by parentheses, the rule is
1379 automatically updated whenever the interface changes its address.
1380 The ruleset does not need to be reloaded.
1381 This is especially useful with
1382 .Ar nat .
1383 .Pp
1384 Ports can be specified either by number or by name.
1385 For example, port 80 can be specified as
1386 .Em www .
1387 For a list of all port name to number mappings used by
1388 .Xr pfctl 8 ,
1389 see the file
1390 .Pa /etc/services .
1391 .Pp
1392 Ports and ranges of ports are specified by using these operators:
1393 .Bd -literal -offset indent
1394 =       (equal)
1395 !=      (unequal)
1396 <       (less than)
1397 <=      (less than or equal)
1398 >       (greater than)
1399 >=      (greater than or equal)
1400 :       (range including boundaries)
1401 ><      (range excluding boundaries)
1402 <>      (except range)
1403 .Ed
1404 .Pp
1405 ><, <> and :
1406 are binary operators (they take two arguments).
1407 For instance:
1408 .Bl -tag -width Fl
1409 .It Ar port 2000:2004
1410 means
1411 .Sq all ports \(>= 2000 and \(<= 2004 ,
1412 hence ports 2000, 2001, 2002, 2003 and 2004.
1413 .It Ar port 2000 >< 2004
1414 means
1415 .Sq all ports > 2000 and < 2004 ,
1416 hence ports 2001, 2002 and 2003.
1417 .It Ar port 2000 <> 2004
1418 means
1419 .Sq all ports < 2000 or > 2004 ,
1420 hence ports 1-1999 and 2005-65535.
1421 .El
1422 .Pp
1423 The operating system of the source host can be specified in the case of TCP
1424 rules with the
1425 .Ar OS
1426 modifier.
1427 See the
1428 .Sx OPERATING SYSTEM FINGERPRINTING
1429 section for more information.
1430 .Pp
1431 The host, port and OS specifications are optional, as in the following examples:
1432 .Bd -literal -offset indent
1433 pass in all
1434 pass in from any to any
1435 pass in proto tcp from any port <= 1024 to any
1436 pass in proto tcp from any to any port 25
1437 pass in proto tcp from 10.0.0.0/8 port > 1024 \e
1438       to ! 10.1.2.3 port != ssh
1439 pass in proto tcp from any os "OpenBSD" flags S/SA
1440 .Ed
1441 .It Ar all
1442 This is equivalent to "from any to any".
1443 .It Ar group <group>
1444 Similar to
1445 .Ar user ,
1446 this rule only applies to packets of sockets owned by the specified group.
1447 .It Ar user <user>
1448 This rule only applies to packets of sockets owned by the specified user.
1449 For outgoing connections initiated from the firewall, this is the user
1450 that opened the connection.
1451 For incoming connections to the firewall itself, this is the user that
1452 listens on the destination port.
1453 For forwarded connections, where the firewall is not a connection endpoint,
1454 the user and group are
1455 .Em unknown .
1456 .Pp
1457 All packets, both outgoing and incoming, of one connection are associated
1458 with the same user and group.
1459 Only TCP and UDP packets can be associated with users; for other protocols
1460 these parameters are ignored.
1461 .Pp
1462 User and group refer to the effective (as opposed to the real) IDs, in
1463 case the socket is created by a setuid/setgid process.
1464 User and group IDs are stored when a socket is created;
1465 when a process creates a listening socket as root (for instance, by
1466 binding to a privileged port) and subsequently changes to another
1467 user ID (to drop privileges), the credentials will remain root.
1468 .Pp
1469 User and group IDs can be specified as either numbers or names.
1470 The syntax is similar to the one for ports.
1471 The value
1472 .Em unknown
1473 matches packets of forwarded connections.
1474 .Em unknown
1475 can only be used with the operators
1476 .Cm =
1477 and
1478 .Cm != .
1479 Other constructs like
1480 .Cm user >= unknown
1481 are invalid.
1482 Forwarded packets with unknown user and group ID match only rules
1483 that explicitly compare against
1484 .Em unknown
1485 with the operators
1486 .Cm =
1487 or
1488 .Cm != .
1489 For instance
1490 .Cm user >= 0
1491 does not match forwarded packets.
1492 The following example allows only selected users to open outgoing
1493 connections:
1494 .Bd -literal -offset indent
1495 block out proto { tcp, udp } all
1496 pass  out proto { tcp, udp } all \e
1497       user { < 1000, dhartmei } keep state
1498 .Ed
1499 .It Ar flags <a>/<b> | /<b>
1500 This rule only applies to TCP packets that have the flags
1501 .Ar <a>
1502 set out of set
1503 .Ar <b> .
1504 Flags not specified in
1505 .Ar <b>
1506 are ignored.
1507 The flags are: (F)IN, (S)YN, (R)ST, (P)USH, (A)CK, (U)RG, (E)CE, and C(W)R.
1508 .Bl -tag -width Fl
1509 .It Ar flags S/S
1510 Flag SYN is set.
1511 The other flags are ignored.
1512 .It Ar flags S/SA
1513 Out of SYN and ACK, exactly SYN may be set.
1514 SYN, SYN+PSH and SYN+RST match, but SYN+ACK, ACK and ACK+RST do not.
1515 This is more restrictive than the previous example.
1516 .It Ar flags /SFRA
1517 If the first set is not specified, it defaults to none.
1518 All of SYN, FIN, RST and ACK must be unset.
1519 .El
1520 .It Ar icmp-type <type> code <code>
1521 .It Ar icmp6-type <type> code <code>
1522 This rule only applies to ICMP or ICMPv6 packets with the specified type
1523 and code.
1524 This parameter is only valid for rules that cover protocols ICMP or
1525 ICMP6.
1526 The protocol and the ICMP type indicator (icmp-type or icmp6-type)
1527 must match.
1528 .It Ar allow-opts
1529 By default, packets which contain IP options are blocked.
1530 When
1531 .Ar allow-opts
1532 is specified for a
1533 .Ar pass
1534 rule, packets that pass the filter based on that rule (last matching)
1535 do so even if they contain IP options.
1536 For packets that match state, the rule that initially created the
1537 state is used.
1538 The implicit
1539 .Ar pass
1540 rule that is used when a packet does not match any rules does not
1541 allow IP options.
1542 .It Ar label <string>
1543 Adds a label (name) to the rule, which can be used to identify the rule.
1544 For instance,
1545 pfctl -s labels
1546 shows per-rule statistics for rules that have labels.
1547 .Pp
1548 The following macros can be used in labels:
1549 .Pp
1550 .Bl -tag -width $srcaddr -compact -offset indent
1551 .It Ar $if
1552 The interface.
1553 .It Ar $srcaddr
1554 The source IP address.
1555 .It Ar $dstaddr
1556 The destination IP address.
1557 .It Ar $srcport
1558 The source port specification.
1559 .It Ar $dstport
1560 The destination port specification.
1561 .It Ar $proto
1562 The protocol name.
1563 .It Ar $nr
1564 The rule number.
1565 .El
1566 .Pp
1567 For example:
1568 .Bd -literal -offset indent
1569 ips = \&"{ 1.2.3.4, 1.2.3.5 }\&"
1570 pass in proto tcp from any to $ips \e
1571       port > 1023 label \&"$dstaddr:$dstport\&"
1572 .Ed
1573 .Pp
1574 expands to
1575 .Bd -literal -offset indent
1576 pass in inet proto tcp from any to 1.2.3.4 \e
1577       port > 1023 label \&"1.2.3.4:>1023\&"
1578 pass in inet proto tcp from any to 1.2.3.5 \e
1579       port > 1023 label \&"1.2.3.5:>1023\&"
1580 .Ed
1581 .Pp
1582 The macro expansion for the
1583 .Ar label
1584 directive occurs only at configuration file parse time, not during runtime.
1585 .It Ar queue <queue> | ( <queue> , <queue> )
1586 Packets matching this rule will be assigned to the specified queue.
1587 If two queues are given, packets which have a
1588 .Em tos
1589 of
1590 .Em lowdelay
1591 and TCP ACKs with no data payload will be assigned to the second one.
1592 See
1593 .Sx QUEUEING
1594 for setup details.
1595 .Pp
1596 For example:
1597 .Bd -literal -offset indent
1598 pass in proto tcp to port 25 queue mail
1599 pass in proto tcp to port 22 queue(ssh_bulk, ssh_prio)
1600 .Ed
1601 .It Ar tag <string>
1602 Packets matching this rule will be tagged with the
1603 specified string.
1604 The tag acts as an internal marker that can be used to
1605 identify these packets later on.
1606 This can be used, for example, to provide trust between
1607 interfaces and to determine if packets have been
1608 processed by translation rules.
1609 Tags are
1610 .Qq sticky ,
1611 meaning that the packet will be tagged even if the rule
1612 is not the last matching rule.
1613 Further matching rules can replace the tag with a
1614 new one but will not remove a previously applied tag.
1615 A packet is only ever assigned one tag at a time.
1616 .Ar pass
1617 rules that use the
1618 .Ar tag
1619 keyword must also use
1620 .Ar keep state ,
1621 .Ar modulate state
1622 or
1623 .Ar synproxy state .
1624 Packet tagging can be done during
1625 .Ar nat ,
1626 .Ar rdr ,
1627 or
1628 .Ar binat
1629 rules in addition to filter rules.
1630 Tags take the same macros as labels (see above).
1631 .It Ar tagged <string>
1632 Used with filter rules to specify that packets must already
1633 be tagged with the given tag in order to match the rule.
1634 Inverse tag matching can also be done
1635 by specifying the
1636 .Cm !\&
1637 operator before the
1638 .Ar tagged
1639 keyword.
1640 .It Ar probability <number>
1641 A probability attribute can be attached to a rule, with a value set between
1642 0 and 1, bounds not included.
1643 In that case, the rule will be honoured using the given probability value
1644 only.
1645 For example, the following rule will drop 20% of incoming ICMP packets:
1646 .Bd -literal -offset indent
1647 block in proto icmp probability 20%
1648 .Ed
1649 .El
1650 .Sh ROUTING
1651 If a packet matches a rule with a route option set, the packet filter will
1652 route the packet according to the type of route option.
1653 When such a rule creates state, the route option is also applied to all
1654 packets matching the same connection.
1655 .Bl -tag -width xxxx
1656 .It Ar fastroute
1657 The
1658 .Ar fastroute
1659 option does a normal route lookup to find the next hop for the packet.
1660 .It Ar route-to
1661 The
1662 .Ar route-to
1663 option routes the packet to the specified interface with an optional address
1664 for the next hop.
1665 When a
1666 .Ar route-to
1667 rule creates state, only packets that pass in the same direction as the
1668 filter rule specifies will be routed in this way.
1669 Packets passing in the opposite direction (replies) are not affected
1670 and are routed normally.
1671 .It Ar reply-to
1672 The
1673 .Ar reply-to
1674 option is similar to
1675 .Ar route-to ,
1676 but routes packets that pass in the opposite direction (replies) to the
1677 specified interface.
1678 Opposite direction is only defined in the context of a state entry, and
1679 .Ar route-to
1680 is useful only in rules that create state.
1681 It can be used on systems with multiple external connections to
1682 route all outgoing packets of a connection through the interface
1683 the incoming connection arrived through (symmetric routing enforcement).
1684 .It Ar dup-to
1685 The
1686 .Ar dup-to
1687 option creates a duplicate of the packet and routes it like
1688 .Ar route-to .
1689 The original packet gets routed as it normally would.
1690 .El
1691 .Sh POOL OPTIONS
1692 For
1693 .Ar nat
1694 and
1695 .Ar rdr
1696 rules, (as well as for the
1697 .Ar route-to ,
1698 .Ar reply-to
1699 and
1700 .Ar dup-to
1701 rule options) for which there is a single redirection address which has a
1702 subnet mask smaller than 32 for IPv4 or 128 for IPv6 (more than one IP
1703 address), a variety of different methods for assigning this address can be
1704 used:
1705 .Bl -tag -width xxxx
1706 .It Ar bitmask
1707 The
1708 .Ar bitmask
1709 option applies the network portion of the redirection address to the address
1710 to be modified (source with
1711 .Ar nat ,
1712 destination with
1713 .Ar rdr ) .
1714 .It Ar random
1715 The
1716 .Ar random
1717 option selects an address at random within the defined block of addresses.
1718 .It Ar source-hash
1719 The
1720 .Ar source-hash
1721 option uses a hash of the source address to determine the redirection address,
1722 ensuring that the redirection address is always the same for a given source.
1723 An optional key can be specified after this keyword either in hex or as a
1724 string; by default
1725 .Xr pfctl 8
1726 randomly generates a key for source-hash every time the
1727 ruleset is reloaded.
1728 .It Ar round-robin
1729 The
1730 .Ar round-robin
1731 option loops through the redirection address(es).
1732 .Pp
1733 When more than one redirection address is specified,
1734 .Ar round-robin
1735 is the only permitted pool type.
1736 .It Ar static-port
1737 With
1738 .Ar nat
1739 rules, the
1740 .Ar static-port
1741 option prevents
1742 .Xr pf 4
1743 from modifying the source port on TCP and UDP packets.
1744 .El
1745 .Pp
1746 Additionally, the
1747 .Ar sticky-address
1748 option can be specified to help ensure that multiple connections from the
1749 same source are mapped to the same redirection address.
1750 This option can be used with the
1751 .Ar random
1752 and
1753 .Ar round-robin
1754 pool options.
1755 Note that by default these associations are destroyed as soon as there are
1756 no longer states which refer to them; in order to make the mappings last
1757 beyond the lifetime of the states, increase the global options with
1758 .Ar set timeout source-track
1759 See
1760 .Sx STATEFUL TRACKING OPTIONS
1761 for more ways to control the source tracking.
1762 .Sh STATEFUL INSPECTION
1763 .Xr pf 4
1764 is a stateful packet filter, which means it can track the state of
1765 a connection.
1766 Instead of passing all traffic to port 25, for instance, it is possible
1767 to pass only the initial packet, and then begin to keep state.
1768 Subsequent traffic will flow because the filter is aware of the connection.
1769 .Pp
1770 You can turn on stateful inspection on all pass rules by default using
1771 the
1772 .Ar set keep-policy
1773 directive.
1774 Any pass rule may specify or override the stateful inspection
1775 default, including turning it off by specifying
1776 .Ar no state .
1777 .Pp
1778 If a packet matches a
1779 .Ar pass ... keep state
1780 rule, the filter creates a state for this connection and automatically
1781 lets pass all subsequent packets of that connection.
1782 .Pp
1783 Before any rules are evaluated, the filter checks whether the packet
1784 matches any state.
1785 If it does, the packet is passed without evaluation of any rules.
1786 .Pp
1787 States are removed after the connection is closed or has timed out.
1788 .Pp
1789 This has several advantages.
1790 Comparing a packet to a state involves checking its sequence numbers.
1791 If the sequence numbers are outside the narrow windows of expected
1792 values, the packet is dropped.
1793 This prevents spoofing attacks, such as when an attacker sends packets with
1794 a fake source address/port but does not know the connection's sequence
1795 numbers.
1796 .Pp
1797 Also, looking up states is usually faster than evaluating rules.
1798 If there are 50 rules, all of them are evaluated sequentially in O(n).
1799 Even with 50000 states, only 16 comparisons are needed to match a
1800 state, since states are stored in a binary search tree that allows
1801 searches in O(log2 n).
1802 .Pp
1803 For instance:
1804 .Bd -literal -offset indent
1805 block all
1806 pass out proto tcp from any to any flags S/SA keep state
1807 pass in  proto tcp from any to any port 25 flags S/SA keep state
1808 .Ed
1809 .Pp
1810 This ruleset blocks everything by default.
1811 Only outgoing connections and incoming connections to port 25 are allowed.
1812 The initial packet of each connection has the SYN
1813 flag set, will be passed and creates state.
1814 All further packets of these connections are passed if they match a state.
1815 .Pp
1816 By default, packets coming in and out of any interface can match a state,
1817 but it is also possible to change that behaviour by assigning states to a
1818 single interface or a group of interfaces.
1819 .Pp
1820 The default policy is specified by the
1821 .Ar state-policy
1822 global option, but this can be adjusted on a per-rule basis by adding one
1823 of the
1824 .Ar if-bound ,
1825 .Ar group-bound
1826 or
1827 .Ar floating
1828 keywords to the
1829 .Ar keep state
1830 option.
1831 For example, if a rule is defined as:
1832 .Bd -literal -offset indent
1833 pass out on ppp from any to 10.12/16 keep state (group-bound)
1834 .Ed
1835 .Pp
1836 A state created on ppp0 would match packets an all PPP interfaces,
1837 but not packets flowing through fxp0 or any other interface.
1838 .Pp
1839 Keeping rules
1840 .Ar floating
1841 is the more flexible option when the firewall is in a dynamic routing
1842 environment.
1843 However, this has some security implications since a state created by one
1844 trusted network could allow potentially hostile packets coming in from other
1845 interfaces.
1846 .Pp
1847 Specifying
1848 .Ar flags S/SA
1849 restricts state creation to the initial SYN
1850 packet of the TCP handshake.
1851 One can also be less restrictive, and allow state creation from
1852 intermediate
1853 .Pq non-SYN
1854 packets.
1855 This will cause
1856 .Xr pf 4
1857 to synchronize to existing connections, for instance
1858 if one flushes the state table.
1859 If you do this you must use the
1860 .Ar pickups
1861 option or
1862 .Ar keep state
1863 will blow up on TCP connections with window scaling turned on.
1864 The
1865 .Ar pickups
1866 option tells keep state to skip sequence space checks on connections
1867 for which no window scaling information is known (meaning it didn't see
1868 the SYN from both directions).
1869 .Pp
1870 For UDP, which is stateless by nature,
1871 .Ar keep state
1872 will create state as well.
1873 UDP packets are matched to states using only host addresses and ports.
1874 .Pp
1875 ICMP messages fall into two categories: ICMP error messages, which always
1876 refer to a TCP or UDP packet, are matched against the referred to connection.
1877 If one keeps state on a TCP connection, and an ICMP source quench message
1878 referring to this TCP connection arrives, it will be matched to the right
1879 state and get passed.
1880 .Pp
1881 For ICMP queries,
1882 .Ar keep state
1883 creates an ICMP state, and
1884 .Xr pf 4
1885 knows how to match ICMP replies to states.
1886 For example,
1887 .Bd -literal -offset indent
1888 pass out inet proto icmp all icmp-type echoreq keep state
1889 .Ed
1890 .Pp
1891 allows echo requests (such as those created by
1892 .Xr ping 8 )
1893 out, creates state, and matches incoming echo replies correctly to states.
1894 .Pp
1895 Note:
1896 .Ar nat , binat No and Ar rdr
1897 rules implicitly create state for connections.
1898 .Sh STATE MODULATION
1899 Much of the security derived from TCP is attributable to how well the
1900 initial sequence numbers (ISNs) are chosen.
1901 Some popular stack implementations choose
1902 .Em very
1903 poor ISNs and thus are normally susceptible to ISN prediction exploits.
1904 By applying a
1905 .Ar modulate state
1906 rule to a TCP connection,
1907 .Xr pf 4
1908 will create a high quality random sequence number for each connection
1909 endpoint.
1910 .Pp
1911 The
1912 .Ar modulate state
1913 directive implicitly keeps state on the rule and is
1914 only applicable to TCP connections.
1915 .Pp
1916 For instance:
1917 .Bd -literal -offset indent
1918 block all
1919 pass out proto tcp from any to any modulate state
1920 pass in  proto tcp from any to any port 25 flags S/SA modulate state
1921 .Ed
1922 .Pp
1923 There are two caveats associated with state modulation:
1924 A
1925 .Ar modulate state
1926 rule can not be applied to a pre-existing but unmodulated connection.
1927 Such an application would desynchronize TCP's strict
1928 sequencing between the two endpoints.
1929 Instead,
1930 .Xr pf 4
1931 will treat the
1932 .Ar modulate state
1933 modifier as a
1934 .Ar keep state
1935 modifier and the pre-existing connection will be inferred without
1936 the protection conferred by modulation.
1937 .Pp
1938 The other caveat affects currently modulated states when the state table
1939 is lost (firewall reboot, flushing the state table, etc...).
1940 .Xr pf 4
1941 will not be able to infer a connection again after the state table flushes
1942 the connection's modulator.
1943 When the state is lost, the connection may be left dangling until the
1944 respective endpoints time out the connection.
1945 It is possible on a fast local network for the endpoints to start an ACK
1946 storm while trying to resynchronize after the loss of the modulator.
1947 Using a
1948 .Ar flags S/SA
1949 modifier on
1950 .Ar modulate state
1951 rules between fast networks is suggested to prevent ACK storms.
1952 .Sh SYN PROXY
1953 By default,
1954 .Xr pf 4
1955 passes packets that are part of a
1956 .Xr tcp 4
1957 handshake between the endpoints.
1958 The
1959 .Ar synproxy state
1960 option can be used to cause
1961 .Xr pf 4
1962 itself to complete the handshake with the active endpoint, perform a handshake
1963 with the passive endpoint, and then forward packets between the endpoints.
1964 .Pp
1965 No packets are sent to the passive endpoint before the active endpoint has
1966 completed the handshake, hence so-called SYN floods with spoofed source
1967 addresses will not reach the passive endpoint, as the sender can't complete the
1968 handshake.
1969 .Pp
1970 The proxy is transparent to both endpoints, they each see a single
1971 connection from/to the other endpoint.
1972 .Xr pf 4
1973 chooses random initial sequence numbers for both handshakes.
1974 Once the handshakes are completed, the sequence number modulators
1975 (see previous section) are used to translate further packets of the
1976 connection.
1977 Hence,
1978 .Ar synproxy state
1979 includes
1980 .Ar modulate state
1981 and
1982 .Ar keep state .
1983 .Pp
1984 Rules with
1985 .Ar synproxy
1986 will not work if
1987 .Xr pf 4
1988 operates on a
1989 .Xr bridge 4 .
1990 .Pp
1991 Example:
1992 .Bd -literal -offset indent
1993 pass in proto tcp from any to any port www flags S/SA synproxy state
1994 .Ed
1995 .Sh STATEFUL TRACKING OPTIONS
1996 All three of
1997 .Ar keep state ,
1998 .Ar modulate state
1999 and
2000 .Ar synproxy state
2001 support the following options:
2002 .Pp
2003 .Bl -tag -width xxxx -compact
2004 .It Ar max <number>
2005 Limits the number of concurrent states the rule may create.
2006 When this limit is reached, further packets matching the rule that would
2007 create state are dropped, until existing states time out.
2008 .It Ar no-sync
2009 Prevent state changes for states created by this rule from appearing on the
2010 .Xr pfsync 4
2011 interface.
2012 .It Ar <timeout> <seconds>
2013 Changes the timeout values used for states created by this rule.
2014 .Pp
2015 When the
2016 .Ar source-track
2017 keyword is specified, the number of states per source IP is tracked.
2018 The following limits can be set:
2019 .Pp
2020 .Bl  -tag -width xxxx -compact
2021 .It Ar max-src-nodes
2022 Limits the maximum number of source addresses which can simultaneously
2023 have state table entries.
2024 .It Ar max-src-states
2025 Limits the maximum number of simultaneous state entries that a single
2026 source address can create with this rule.
2027 .It Ar pickups
2028 Specify that mid-stream pickups are to be allowed.
2029 The default is to NOT allow mid-stream pickups and implies flags
2030 S/SA for TCP connections.
2031 If pickups are enabled, flags S/SA are not implied
2032 for TCP connections and state can be created for any packet.
2033 .Pp
2034 The implied flags parameters need not be specified in either case
2035 unless you explicitly wish to override them, which also allows
2036 you to roll-up several protocols into a single rule.
2037 .Pp
2038 Certain validations are disabled when mid-stream pickups occur.
2039 For example, the window scaling options are not known for
2040 TCP pickups and sequence space comparisons must be disabled.
2041 .Pp
2042 This does not effect state representing fully quantified
2043 connections (for which the SYN/SYN-ACK passed through the routing
2044 engine).
2045 Those connections continue to be fully validated.
2046 .It Ar hash-only
2047 Specify that mid-stream pickups are to be allowed, but unconditionally
2048 disables sequence space checks even if full state is available.
2049 .It Ar no-pickups
2050 Specify that mid-stream pickups are not to be allowed.
2051 This is the
2052 default and this keyword does not normally need to be specified.
2053 However, if you are concerned about rule set portability then
2054 specifying this keyword will at least result in an error from
2055 .Xr pfctl 8
2056 if it doesn't understand the feature.
2057 TCP flags of S/SA are implied
2058 and do not need to explicitly specified.
2059 .El
2060 .Pp
2061 For a list of all valid timeout names, see
2062 .Sx OPTIONS
2063 above.
2064 .Pp
2065 Multiple options can be specified, separated by commas:
2066 .Bd -literal
2067 pass in proto tcp from any to any \e
2068       port www flags S/SA keep state \e
2069       (max 100, source-track rule, max-src-nodes 75, \e
2070       max-src-states 3, tcp.established 60, tcp.closing 5)
2071 .Ed
2072 .El
2073 .Sh OPERATING SYSTEM FINGERPRINTING
2074 Passive OS Fingerprinting is a mechanism to inspect nuances of a TCP
2075 connection's initial SYN packet and guess at the host's operating system.
2076 Unfortunately these nuances are easily spoofed by an attacker so the
2077 fingerprint is not useful in making security decisions.
2078 But the fingerprint is typically accurate enough to make policy decisions
2079 upon.
2080 .Pp
2081 The fingerprints may be specified by operating system class, by
2082 version, or by subtype/patchlevel.
2083 The class of an operating system is typically the vendor or genre
2084 and would be
2085 .Ox
2086 for the
2087 .Xr pf 4
2088 firewall itself.
2089 The version of the oldest available
2090 .Ox
2091 release on the main ftp site
2092 would be 2.6 and the fingerprint would be written
2093 .Pp
2094 .Dl \&"OpenBSD 2.6\&"
2095 .Pp
2096 The subtype of an operating system is typically used to describe the
2097 patchlevel if that patch led to changes in the TCP stack behavior.
2098 In the case of
2099 .Ox ,
2100 the only subtype is for a fingerprint that was
2101 normalized by the
2102 .Ar no-df
2103 scrub option and would be specified as
2104 .Pp
2105 .Dl \&"OpenBSD 3.3 no-df\&"
2106 .Pp
2107 Fingerprints for most popular operating systems are provided by
2108 .Xr pf.os 5 .
2109 Once
2110 .Xr pf 4
2111 is running, a complete list of known operating system fingerprints may
2112 be listed by running:
2113 .Pp
2114 .Dl # pfctl -so
2115 .Pp
2116 Filter rules can enforce policy at any level of operating system specification
2117 assuming a fingerprint is present.
2118 Policy could limit traffic to approved operating systems or even ban traffic
2119 from hosts that aren't at the latest service pack.
2120 .Pp
2121 The
2122 .Ar unknown
2123 class can also be used as the fingerprint which will match packets for
2124 which no operating system fingerprint is known.
2125 .Pp
2126 Examples:
2127 .Bd -literal -offset indent
2128 pass  out proto tcp from any os OpenBSD keep state
2129 block out proto tcp from any os Doors
2130 block out proto tcp from any os "Doors PT"
2131 block out proto tcp from any os "Doors PT SP3"
2132 block out from any os "unknown"
2133 pass on lo0 proto tcp from any os "OpenBSD 3.3 lo0" keep state
2134 .Ed
2135 .Pp
2136 Operating system fingerprinting is limited only to the TCP SYN packet.
2137 This means that it will not work on other protocols and will not match
2138 a currently established connection.
2139 .Pp
2140 Caveat: operating system fingerprints are occasionally wrong.
2141 There are three problems: an attacker can trivially craft his packets to
2142 appear as any operating system he chooses;
2143 an operating system patch could change the stack behavior and no fingerprints
2144 will match it until the database is updated;
2145 and multiple operating systems may have the same fingerprint.
2146 .Sh BLOCKING SPOOFED TRAFFIC
2147 "Spoofing" is the faking of IP addresses, typically for malicious
2148 purposes.
2149 The
2150 .Ar antispoof
2151 directive expands to a set of filter rules which will block all
2152 traffic with a source IP from the network(s) directly connected
2153 to the specified interface(s) from entering the system through
2154 any other interface.
2155 .Pp
2156 For example, the line
2157 .Bd -literal -offset indent
2158 antispoof for lo0
2159 .Ed
2160 .Pp
2161 expands to
2162 .Bd -literal -offset indent
2163 block drop in on ! lo0 inet from 127.0.0.1/8 to any
2164 block drop in on ! lo0 inet6 from ::1 to any
2165 .Ed
2166 .Pp
2167 For non-loopback interfaces, there are additional rules to block incoming
2168 packets with a source IP address identical to the interface's IP(s).
2169 For example, assuming the interface wi0 had an IP address of 10.0.0.1 and a
2170 netmask of 255.255.255.0,
2171 the line
2172 .Bd -literal -offset indent
2173 antispoof for wi0 inet
2174 .Ed
2175 .Pp
2176 expands to
2177 .Bd -literal -offset indent
2178 block drop in on ! wi0 inet from 10.0.0.0/24 to any
2179 block drop in inet from 10.0.0.1 to any
2180 .Ed
2181 .Pp
2182 Caveat: Rules created by the
2183 .Ar antispoof
2184 directive interfere with packets sent over loopback interfaces
2185 to local addresses.
2186 One should pass these explicitly.
2187 .Sh FRAGMENT HANDLING
2188 The size of IP datagrams (packets) can be significantly larger than the
2189 maximum transmission unit (MTU) of the network.
2190 In cases when it is necessary or more efficient to send such large packets,
2191 the large packet will be fragmented into many smaller packets that will each
2192 fit onto the wire.
2193 Unfortunately for a firewalling device, only the first logical fragment will
2194 contain the necessary header information for the subprotocol that allows
2195 .Xr pf 4
2196 to filter on things such as TCP ports or to perform NAT.
2197 .Pp
2198 Besides the use of
2199 .Ar scrub
2200 rules as described in
2201 .Sx TRAFFIC NORMALIZATION
2202 above, there are three options for handling fragments in the packet filter.
2203 .Pp
2204 One alternative is to filter individual fragments with filter rules.
2205 If no
2206 .Ar scrub
2207 rule applies to a fragment, it is passed to the filter.
2208 Filter rules with matching IP header parameters decide whether the
2209 fragment is passed or blocked, in the same way as complete packets
2210 are filtered.
2211 Without reassembly, fragments can only be filtered based on IP header
2212 fields (source/destination address, protocol), since subprotocol header
2213 fields are not available (TCP/UDP port numbers, ICMP code/type).
2214 The
2215 .Ar fragment
2216 option can be used to restrict filter rules to apply only to
2217 fragments, but not complete packets.
2218 Filter rules without the
2219 .Ar fragment
2220 option still apply to fragments, if they only specify IP header fields.
2221 For instance, the rule
2222 .Bd -literal -offset indent
2223 pass in proto tcp from any to any port 80
2224 .Ed
2225 .Pp
2226 never applies to a fragment, even if the fragment is part of a TCP
2227 packet with destination port 80, because without reassembly this information
2228 is not available for each fragment.
2229 This also means that fragments cannot create new or match existing
2230 state table entries, which makes stateful filtering and address
2231 translation (NAT, redirection) for fragments impossible.
2232 .Pp
2233 It's also possible to reassemble only certain fragments by specifying
2234 source or destination addresses or protocols as parameters in
2235 .Ar scrub
2236 rules.
2237 .Pp
2238 In most cases, the benefits of reassembly outweigh the additional
2239 memory cost, and it's recommended to use
2240 .Ar scrub
2241 rules to reassemble
2242 all fragments via the
2243 .Ar fragment reassemble
2244 modifier.
2245 .Pp
2246 The memory allocated for fragment caching can be limited using
2247 .Xr pfctl 8 .
2248 Once this limit is reached, fragments that would have to be cached
2249 are dropped until other entries time out.
2250 The timeout value can also be adjusted.
2251 .Pp
2252 Currently, only IPv4 fragments are supported and IPv6 fragments
2253 are blocked unconditionally.
2254 .Sh ANCHORS AND NAMED RULESETS
2255 Besides the main ruleset,
2256 .Xr pfctl 8
2257 can load named rulesets into
2258 .Ar anchor
2259 attachment points.
2260 An
2261 .Ar anchor
2262 contains a list of named rulesets.
2263 An
2264 .Ar anchor
2265 has a name which specifies where
2266 .Xr pfctl 8
2267 can be used to attach sub-rulesets.
2268 A named ruleset contains filter and translation rules, like the
2269 main ruleset.
2270 The main ruleset can reference
2271 .Ar anchor
2272 attachment points
2273 using the following kinds
2274 of rules:
2275 .Bl -tag -width xxxx
2276 .It Ar nat-anchor <name>
2277 Evaluates the
2278 .Ar nat
2279 rules of all named rulesets in the specified
2280 .Ar anchor .
2281 .It Ar rdr-anchor <name>
2282 Evaluates the
2283 .Ar rdr
2284 rules of all named rulesets in the specified
2285 .Ar anchor .
2286 .It Ar binat-anchor <name>
2287 Evaluates the
2288 .Ar binat
2289 rules of all named rulesets in the specified
2290 .Ar anchor .
2291 .It Ar anchor <name>
2292 Evaluates the filter rules of all named rulesets in the specified
2293 .Ar anchor .
2294 .It Ar load anchor <name>:<ruleset> from <file>
2295 Loads the rules from the specified file into the named
2296 ruleset
2297 .Ar <ruleset>
2298 attached to the anchor
2299 .Ar <name> .
2300 .El
2301 .Pp
2302 When evaluation of the main ruleset reaches an
2303 .Ar anchor
2304 rule,
2305 .Xr pf 4
2306 will proceed to evaluate all rules specified in the
2307 named rulesets attached to that
2308 .Ar anchor .
2309 .Pp
2310 Matching filter rules in named rulesets with the
2311 .Ar quick
2312 option and matching translation rules are final and abort the
2313 evaluation of both the rules in the
2314 .Ar anchor
2315 and the main ruleset.
2316 .Pp
2317 Only the main ruleset can contain
2318 .Ar anchor
2319 rules.
2320 .Pp
2321 When an
2322 .Ar anchor
2323 contains more than one named ruleset, they are evaluated
2324 in the alphabetical order of their names.
2325 .Pp
2326 Rules may contain
2327 .Ar anchor
2328 attachment points which do not contain any rules when the main ruleset
2329 is loaded, and later such named rulesets can be manipulated through
2330 .Xr pfctl 8
2331 without reloading the main ruleset.
2332 For example,
2333 .Bd -literal -offset indent
2334 ext_if = \&"kue0\&"
2335 block on $ext_if all
2336 anchor spam
2337 pass out on $ext_if all keep state
2338 pass in on $ext_if proto tcp from any \e
2339       to $ext_if port smtp keep state
2340 .Ed
2341 .Pp
2342 blocks all packets on the external interface by default, then evaluates
2343 all rulesets in the
2344 .Ar anchor
2345 named "spam", and finally passes all outgoing connections and
2346 incoming connections to port 25.
2347 .Bd -literal -offset indent
2348 # echo \&"block in quick from 1.2.3.4 to any\&" \&| \e
2349       pfctl -a spam:manual -f -
2350 .Ed
2351 .Pp
2352 loads a single ruleset containing a single rule into the
2353 .Ar anchor ,
2354 which blocks all packets from a specific address.
2355 .Pp
2356 The named ruleset can also be populated by adding a
2357 .Ar load anchor
2358 rule after the
2359 .Ar anchor
2360 rule:
2361 .Bd -literal -offset indent
2362 anchor spam
2363 load anchor spam:manual from "/etc/pf-spam.conf"
2364 .Ed
2365 .Pp
2366 When
2367 .Xr pfctl 8
2368 loads
2369 .Nm ,
2370 it will also load all the rules from the file
2371 .Pa /etc/pf-spam.conf
2372 into the named ruleset.
2373 .Pp
2374 Optionally,
2375 .Ar anchor
2376 rules can specify the parameter's
2377 direction, interface, address family, protocol and source/destination
2378 address/port
2379 using the same syntax as filter rules.
2380 When parameters are used, the
2381 .Ar anchor
2382 rule is only evaluated for matching packets.
2383 This allows conditional evaluation of named rulesets, like:
2384 .Bd -literal -offset indent
2385 block on $ext_if all
2386 anchor spam proto tcp from any to any port smtp
2387 pass out on $ext_if all keep state
2388 pass in on $ext_if proto tcp from any to $ext_if port smtp keep state
2389 .Ed
2390 .Pp
2391 The rules inside
2392 .Ar anchor
2393 spam are only evaluated for
2394 .Ar tcp
2395 packets with destination port 25.
2396 Hence,
2397 .Bd -literal -offset indent
2398 # echo \&"block in quick from 1.2.3.4 to any" \&| \e
2399       pfctl -a spam:manual -f -
2400 .Ed
2401 .Pp
2402 will only block connections from 1.2.3.4 to port 25.
2403 .Sh FILES
2404 .Bl -tag -width "/etc/protocols" -compact
2405 .It Pa /etc/hosts
2406 Host name database.
2407 .It Pa /etc/pf.conf
2408 Default location of the ruleset file.
2409 .It Pa /etc/pf.os
2410 Default location of OS fingerprints.
2411 .It Pa /etc/protocols
2412 Protocol name database.
2413 .It Pa /etc/services
2414 Service name database.
2415 .It Pa /usr/share/examples/pf
2416 Example rulesets.
2417 .El
2418 .Sh TRANSLATION EXAMPLES
2419 This example maps incoming requests on port 80 to port 8080, on
2420 which a daemon is running (because, for example, it is not run as root,
2421 and therefore lacks permission to bind to port 80).
2422 .Bd -literal
2423 # use a macro for the interface name, so it can be changed easily
2424 ext_if = \&"ne3\&"
2425
2426 # map daemon on 8080 to appear to be on 80
2427 rdr on $ext_if proto tcp from any to any port 80 -> 127.0.0.1 port 8080
2428 .Ed
2429 .Pp
2430 If the
2431 .Ar pass
2432 modifier is given, packets matching the translation rule are passed without
2433 inspecting the filter rules:
2434 .Bd -literal
2435 rdr pass on $ext_if proto tcp from any to any port 80 -> 127.0.0.1 \e
2436       port 8080
2437 .Ed
2438 .Pp
2439 In the example below, vlan12 is configured as 192.168.168.1;
2440 the machine translates all packets coming from 192.168.168.0/24 to 204.92.77.111
2441 when they are going out any interface except vlan12.
2442 This has the net effect of making traffic from the 192.168.168.0/24
2443 network appear as though it is the Internet routable address
2444 204.92.77.111 to nodes behind any interface on the router except
2445 for the nodes on vlan12.
2446 (Thus, 192.168.168.1 can talk to the 192.168.168.0/24 nodes.)
2447 .Bd -literal
2448 nat on ! vlan12 from 192.168.168.0/24 to any -> 204.92.77.111
2449 .Ed
2450 .Pp
2451 In the example below, the machine sits between a fake internal 144.19.74.*
2452 network, and a routable external IP of 204.92.77.100.
2453 The
2454 .Ar no nat
2455 rule excludes protocol AH from being translated.
2456 .Bd -literal
2457 # NO NAT
2458 no nat on $ext_if proto ah from 144.19.74.0/24 to any
2459 nat on $ext_if from 144.19.74.0/24 to any -> 204.92.77.100
2460 .Ed
2461 .Pp
2462 In the example below, packets bound for one specific server, as well as those
2463 generated by the sysadmins are not proxied; all other connections are.
2464 .Bd -literal
2465 # NO RDR
2466 no rdr on $int_if proto { tcp, udp } from any to $server port 80
2467 no rdr on $int_if proto { tcp, udp } from $sysadmins to any port 80
2468 rdr on $int_if proto { tcp, udp } from any to any port 80 -> 127.0.0.1 \e
2469       port 80
2470 .Ed
2471 .Pp
2472 This longer example uses both a NAT and a redirection.
2473 The external interface has the address 157.161.48.183.
2474 On the internal interface, we are running
2475 .Xr ftp-proxy 8 ,
2476 listening for outbound ftp sessions captured to port 8021.
2477 .Bd -literal
2478 # NAT
2479 # Translate outgoing packets' source addresses (any protocol).
2480 # In this case, any address but the gateway's external address is mapped.
2481 nat on $ext_if inet from ! ($ext_if) to any -> ($ext_if)
2482
2483 # NAT PROXYING
2484 # Map outgoing packets' source port to an assigned proxy port instead of
2485 # an arbitrary port.
2486 # In this case, proxy outgoing isakmp with port 500 on the gateway.
2487 nat on $ext_if inet proto udp from any port = isakmp to any -> ($ext_if) \e
2488       port 500
2489
2490 # BINAT
2491 # Translate outgoing packets' source address (any protocol).
2492 # Translate incoming packets' destination address to an internal machine
2493 # (bidirectional).
2494 binat on $ext_if from 10.1.2.150 to any -> ($ext_if)
2495
2496 # RDR
2497 # Translate incoming packets' destination addresses.
2498 # As an example, redirect a TCP and UDP port to an internal machine.
2499 rdr on $ext_if inet proto tcp from any to ($ext_if) port 8080 \e
2500       -> 10.1.2.151 port 22
2501 rdr on $ext_if inet proto udp from any to ($ext_if) port 8080 \e
2502       -> 10.1.2.151 port 53
2503
2504 # RDR
2505 # Translate outgoing ftp control connections to send them to localhost
2506 # for proxying with ftp-proxy(8) running on port 8021.
2507 rdr on $int_if proto tcp from any to any port 21 -> 127.0.0.1 port 8021
2508 .Ed
2509 .Pp
2510 In this example, a NAT gateway is set up to translate internal addresses
2511 using a pool of public addresses (192.0.2.16/28) and to redirect
2512 incoming web server connections to a group of web servers on the internal
2513 network.
2514 .Bd -literal
2515 # NAT LOAD BALANCE
2516 # Translate outgoing packets' source addresses using an address pool.
2517 # A given source address is always translated to the same pool address by
2518 # using the source-hash keyword.
2519 nat on $ext_if inet from any to any -> 192.0.2.16/28 source-hash
2520
2521 # RDR ROUND ROBIN
2522 # Translate incoming web server connections to a group of web servers on
2523 # the internal network.
2524 rdr on $ext_if proto tcp from any to any port 80 \e
2525       -> { 10.1.2.155, 10.1.2.160, 10.1.2.161 } round-robin
2526 .Ed
2527 .Sh FILTER EXAMPLES
2528 .Bd -literal
2529 # The external interface is kue0
2530 # (157.161.48.183, the only routable address)
2531 # and the private network is 10.0.0.0/8, for which we are doing NAT.
2532
2533 # use a macro for the interface name, so it can be changed easily
2534 ext_if = \&"kue0\&"
2535
2536 # normalize all incoming traffic
2537 scrub in on $ext_if all fragment reassemble
2538
2539 # block and log everything by default
2540 block return log on $ext_if all
2541
2542 # block anything coming from source we have no back routes for
2543 block in from no-route to any
2544
2545 # block and log outgoing packets that do not have our address as source,
2546 # they are either spoofed or something is misconfigured (NAT disabled,
2547 # for instance), we want to be nice and do not send out garbage.
2548 block out log quick on $ext_if from ! 157.161.48.183 to any
2549
2550 # silently drop broadcasts (cable modem noise)
2551 block in quick on $ext_if from any to 255.255.255.255
2552
2553 # block and log incoming packets from reserved address space and invalid
2554 # addresses, they are either spoofed or misconfigured, we cannot reply to
2555 # them anyway (hence, no return-rst).
2556 block in log quick on $ext_if from { 10.0.0.0/8, 172.16.0.0/12, \e
2557       192.168.0.0/16, 255.255.255.255/32 } to any
2558
2559 # ICMP
2560
2561 # pass out/in certain ICMP queries and keep state (ping)
2562 # state matching is done on host addresses and ICMP id (not type/code),
2563 # so replies (like 0/0 for 8/0) will match queries
2564 # ICMP error messages (which always refer to a TCP/UDP packet) are
2565 # handled by the TCP/UDP states
2566 pass on $ext_if inet proto icmp all icmp-type 8 code 0 keep state
2567
2568 # UDP
2569
2570 # pass out all UDP connections and keep state
2571 pass out on $ext_if proto udp all keep state
2572
2573 # pass in certain UDP connections and keep state (DNS)
2574 pass in on $ext_if proto udp from any to any port domain keep state
2575
2576 # TCP
2577
2578 # pass out all TCP connections and modulate state
2579 pass out on $ext_if proto tcp all modulate state
2580
2581 # pass in certain TCP connections and keep state (SSH, SMTP, DNS, IDENT)
2582 pass in on $ext_if proto tcp from any to any port { ssh, smtp, domain, \e
2583       auth } flags S/SA keep state
2584
2585 # pass in data mode connections for ftp-proxy running on this host.
2586 # (see ftp-proxy(8) for details)
2587 pass in on $ext_if proto tcp from any to 157.161.48.183 port >= 49152 \e
2588       flags S/SA keep state
2589
2590 # Do not allow Windows 9x SMTP connections since they are typically
2591 # a viral worm. Alternately we could limit these OSes to 1 connection each.
2592 block in on $ext_if proto tcp from any os {"Windows 95", "Windows 98"} \e
2593       to any port smtp
2594
2595 # Using the pickup options to keep/modulate/synproxy state
2596 #
2597 # no-pickups    (default) Do not allow connections to be picked up in the
2598 #               middle.  Implies flags S/SA (the 'no-pickups' option need
2599 #               not be specified, it is the default).
2600 #
2601 # pickups       Allow connections to be picked up in the middle, even if
2602 #               no window scaling information is known.  Such connections
2603 #               will disable sequence space checks.  Implies no flag
2604 #               restrictions.
2605 #
2606 # hash-only     Do not fail packets on sequence space checks.  Implies no
2607 #               flag restrictions.
2608
2609 pass in on $ext_if proto tcp ... keep state (no-pickups)
2610 pass in on $ext_if proto tcp ... keep state (pickups)
2611 pass in on $ext_if proto tcp ... keep state (hash-only)
2612
2613 # Packet Tagging
2614
2615 # three interfaces: $int_if, $ext_if, and $wifi_if (wireless). NAT is
2616 # being done on $ext_if for all outgoing packets. tag packets in on
2617 # $int_if and pass those tagged packets out on $ext_if.  all other
2618 # outgoing packets (i.e., packets from the wireless network) are only
2619 # permitted to access port 80.
2620
2621 pass in on $int_if from any to any tag INTNET keep state
2622 pass in on $wifi_if from any to any keep state
2623
2624 block out on $ext_if from any to any
2625 pass out quick on $ext_if tagged INTNET keep state
2626 pass out on $ext_if from any to any port 80 keep state
2627
2628 # tag incoming packets as they are redirected to spamd(8). use the tag
2629 # to pass those packets through the packet filter.
2630
2631 rdr on $ext_if inet proto tcp from <spammers> to port smtp \e
2632         tag SPAMD -> 127.0.0.1 port spamd
2633
2634 block in on $ext_if
2635 pass in on $ext_if inet proto tcp tagged SPAMD keep state
2636 .Ed
2637 .Sh GRAMMAR
2638 Syntax for
2639 .Nm
2640 in BNF:
2641 .Bd -literal
2642 line           = option | pf-rule | nat-rule | binat-rule | rdr-rule |
2643                  antispoof-rule | altq-rule | queue-rule | anchor-rule |
2644                  trans-anchors | load-anchors | table-rule
2645
2646 option         = "set" ( [ "timeout" ( timeout | "{" timeout-list "}" ) ] |
2647                  [ "optimization" [ "default" | "normal" |
2648                  "high-latency" | "satellite" |
2649                  "aggressive" | "conservative" ] ]
2650                  [ "limit" ( limit-item | "{" limit-list "}" ) ] |
2651                  [ "loginterface" ( interface-name | "none" ) ] |
2652                  [ "block-policy" ( "drop" | "return" ) ] |
2653                  [ "keep-policy" keep ] |
2654                  [ "state-policy" ( "if-bound" | "group-bound" |
2655                  "floating" ) ]
2656                  [ "require-order" ( "yes" | "no" ) ]
2657                  [ "fingerprints" filename ] |
2658                  [ "debug" ( "none" | "urgent" | "misc" | "loud" ) ] )
2659
2660 pf-rule        = action [ "in" | "out" ]
2661                  [ "log" | "log-all" ] [ "quick" ]
2662                  [ "on" ifspec ] [ route ] [ af ] [ protospec ]
2663                  hosts [ filteropt-list ]
2664
2665 filteropt-list = filteropt-list filteropt | filteropt
2666 filteropt      = user | group | flags | icmp-type | icmp6-type | tos |
2667                  keep | "fragment" | "no-df" | "min-ttl" number |
2668                  "max-mss" number | "random-id" | "reassemble tcp" |
2669                  fragmentation | "allow-opts" |
2670                  "label" string | "tag" string | [ ! ] "tagged" string
2671                  "queue" ( string | "(" string [ [ "," ] string ] ")" ) |
2672                  "probability" number"%"
2673
2674 keep           = "no" "state" |
2675                  ( "keep" | "modulate" | "synproxy" ) "state"
2676                  [ "(" state-opts ")" ]
2677
2678 nat-rule       = [ "no" ] "nat" [ "pass" ] [ "on" ifspec ] [ af ]
2679                  [ protospec ] hosts [ "tag" string ]
2680                  [ "->" ( redirhost | "{" redirhost-list "}" )
2681                  [ portspec ] [ pooltype ] [ "static-port" ] ]
2682
2683 binat-rule     = [ "no" ] "binat" [ "pass" ] [ "on" interface-name ]
2684                  [ af ] [ "proto" ( proto-name | proto-number ) ]
2685                  "from" address [ "/" mask-bits ] "to" ipspec
2686                  [ "tag" string ]
2687                  [ "->" address [ "/" mask-bits ] ]
2688
2689 rdr-rule       = [ "no" ] "rdr" [ "pass" ] [ "on" ifspec ] [ af ]
2690                  [ protospec ] hosts [ "tag" string ]
2691                  [ "->" ( redirhost | "{" redirhost-list "}" )
2692                  [ portspec ] [ pooltype ] ]
2693
2694 antispoof-rule = "antispoof" [ "log" ] [ "quick" ]
2695                  "for" ( interface-name | "{" interface-list "}" )
2696                  [ af ] [ "label" string ]
2697
2698 table-rule     = "table" "<" string ">" [ tableopts-list ]
2699 tableopts-list = tableopts-list tableopts | tableopts
2700 tableopts      = "persist" | "const" | "file" string |
2701                  "{" [ tableaddr-list ] "}"
2702 tableaddr-list = tableaddr-list [ "," ] tableaddr-spec | tableaddr-spec
2703 tableaddr-spec = [ "!" ] tableaddr [ "/" mask-bits ]
2704 tableaddr      = hostname | ipv4-dotted-quad | ipv6-coloned-hex |
2705                  interface-name | "self"
2706
2707 altq-rule      = "altq on" interface-name queueopts-list
2708                  "queue" subqueue
2709 queue-rule     = "queue" string [ "on" interface-name ] queueopts-list
2710                  subqueue
2711
2712 anchor-rule    = "anchor" string [ "in" | "out" ] [ "on" ifspec ]
2713                  [ af ] [ "proto" ] [ protospec ] [ hosts ]
2714
2715 trans-anchors  = ( "nat-anchor" | "rdr-anchor" | "binat-anchor" ) string
2716                  [ "on" ifspec ] [ af ] [ "proto" ] [ protospec ] [ hosts ]
2717
2718 load-anchor    = "load anchor" anchorname:rulesetname "from" filename
2719
2720 queueopts-list = queueopts-list queueopts | queueopts
2721 queueopts      = "bandwidth" bandwidth-spec |
2722                  "qlimit" number | "tbrsize" number |
2723                  "priority" number | schedulers
2724 schedulers     = cbq-def | hfsc-def | priq-def | fairq-def
2725 bandwidth-spec = "number" ( "b" | "Kb" | "Mb" | "Gb" | "%" )
2726
2727 action         = "pass" | "block" [ return ] | "scrub"
2728 return         = "drop" | "return" | "return-rst" [ "( ttl" number ")" ] |
2729                  "return-icmp" [ "(" icmpcode ["," icmp6code ] ")" ] |
2730                  "return-icmp6" [ "(" icmp6code ")" ]
2731 icmpcode       = icmp-code-name | icmp-code-number
2732 icmp6code      = icmp6-code-name | icmp6-code-number
2733
2734 ifspec         = ( [ "!" ] interface-name ) | "{" interface-list "}"
2735 interface-list = [ "!" ] interface-name [ [ "," ] interface-list ]
2736 route          = "fastroute" |
2737                  ( "route-to" | "reply-to" | "dup-to" )
2738                  ( routehost | "{" routehost-list "}" )
2739                  [ pooltype ]
2740 af             = "inet" | "inet6"
2741
2742 protospec      = "proto" ( proto-name | proto-number |
2743                  "{" proto-list "}" )
2744 proto-list     = ( proto-name | proto-number ) [ [ "," ] proto-list ]
2745
2746 hosts          = "all" |
2747                  "from" ( "any" | "no-route" | "self" | host |
2748                  "{" host-list "}" ) [ port ] [ os ]
2749                  "to"   ( "any" | "no-route" | "self" | host |
2750                  "{" host-list "}" ) [ port ]
2751
2752 ipspec         = "any" | host | "{" host-list "}"
2753 host           = [ "!" ] ( address [ "/" mask-bits ] | "<" string ">" )
2754 redirhost      = address [ "/" mask-bits ]
2755 routehost      = interface-name [ address [ "/" mask-bits ] ]
2756 address        = interface-name | "(" interface-name ")" | hostname |
2757                  ipv4-dotted-quad | ipv6-coloned-hex
2758 host-list      = host [ [ "," ] host-list ]
2759 redirhost-list = redirhost [ [ "," ] redirhost-list ]
2760 routehost-list = routehost [ [ "," ] routehost-list ]
2761
2762 port           = "port" ( unary-op | binary-op | "{" op-list "}" )
2763 portspec       = "port" ( number | name ) [ ":" ( "*" | number | name ) ]
2764 os             = "os" ( os-name | "{" os-list "}" )
2765 user           = "user" ( unary-op | binary-op | "{" op-list "}" )
2766 group          = "group" ( unary-op | binary-op | "{" op-list "}" )
2767
2768 unary-op       = [ "=" | "!=" | "<" | "<=" | ">" | ">=" ]
2769                  ( name | number )
2770 binary-op      = number ( "<>" | "><" | ":" ) number
2771 op-list        = ( unary-op | binary-op ) [ [ "," ] op-list ]
2772
2773 os-name        = operating-system-name
2774 os-list        = os-name [ [ "," ] os-list ]
2775
2776 flags          = "flags" [ flag-set ] "/" flag-set
2777 flag-set       = [ "F" ] [ "S" ] [ "R" ] [ "P" ] [ "A" ] [ "U" ] [ "E" ]
2778                  [ "W" ]
2779
2780 icmp-type      = "icmp-type" ( icmp-type-code | "{" icmp-list "}" )
2781 icmp6-type     = "icmp6-type" ( icmp-type-code | "{" icmp-list "}" )
2782 icmp-type-code = ( icmp-type-name | icmp-type-number )
2783                  [ "code" ( icmp-code-name | icmp-code-number ) ]
2784 icmp-list      = icmp-type-code [ [ "," ] icmp-list ]
2785
2786 tos            = "tos" ( "lowdelay" | "throughput" | "reliability" |
2787                  [ "0x" ] number )
2788
2789 state-opts     = state-opt [ [ "," ] state-opts ]
2790 state-opt      = "max" number | "no-sync" | timeout |
2791                  "source-track" [ "rule" | "global" ] |
2792                  "max-src-nodes" number | "max-src-states" number |
2793                  "if-bound" | "group-bound" | "floating" |
2794                  "pickups" | "no-pickups" | "hash-only"
2795
2796 fragmentation  = [ "fragment reassemble" | "fragment crop" |
2797                  "fragment drop-ovl" ]
2798
2799 timeout-list   = timeout [ [ "," ] timeout-list ]
2800 timeout        = ( "tcp.first" | "tcp.opening" | "tcp.established" |
2801                  "tcp.closing" | "tcp.finwait" | "tcp.closed" |
2802                  "udp.first" | "udp.single" | "udp.multiple" |
2803                  "icmp.first" | "icmp.error" |
2804                  "other.first" | "other.single" | "other.multiple" |
2805                  "frag" | "interval" | "src.track" |
2806                  "adaptive.start" | "adaptive.end" ) number
2807
2808 limit-list     = limit-item [ [ "," ] limit-list ]
2809 limit-item     = ( "states" | "frags" | "src-nodes" ) number
2810
2811 pooltype       = ( "bitmask" | "random" |
2812                  "source-hash" [ hex-key | string-key ] |
2813                  "round-robin" ) [ sticky-address ]
2814
2815 subqueue       = string | "{" queue-list "}"
2816 queue-list     = string [ [ "," ] string ]
2817
2818 cbq-def        = "cbq" [ "(" cbq-opts ")" ]
2819 priq-def       = "priq" [ "(" priq-opts ")" ]
2820 hfsc-def       = "hfsc" [ "(" hfsc-opts ")" ]
2821 fairq-def      = "fairq" [ "(" fairq-opts ")" ]
2822
2823 cbq-opts       = cbq-opt [ [ "," ] cbq-opts ]
2824 priq-opts      = priq-opt [ [ "," ] priq-opts ]
2825 hfsc-opts      = hfsc-opt [ [ "," ] hfsc-opts ]
2826 fairq-opts     = fairq-opt [ [ "," ] fairq-opts ]
2827
2828 cbq-opt        = "default" | "borrow" | "red" | "ecn" | "rio"
2829 priq-opt       = "default" | "red" | "ecn" | "rio"
2830 hfsc-opt       = "default" | "red" | "ecn" | "rio" |
2831                  linkshare-sc | realtime-sc | upperlimit-sc
2832 fairq-opt      = "default" | "red" | "ecn" | "rio" |
2833                  "buckets" number | "hogs" number | linkshare-sc
2834
2835 linkshare-sc   = "linkshare" sc-spec
2836 realtime-sc    = "realtime" sc-spec
2837 upperlimit-sc  = "upperlimit" sc-spec
2838 sc-spec        = bandwidth-spec |
2839                  "(" bandwidth-spec number bandwidth-spec ")"
2840 .Ed
2841 .Sh SEE ALSO
2842 .Xr icmp 4 ,
2843 .Xr icmp6 4 ,
2844 .Xr ip 4 ,
2845 .Xr ip6 4 ,
2846 .Xr pf 4 ,
2847 .Xr pfsync 4 ,
2848 .Xr tcp 4 ,
2849 .Xr udp 4 ,
2850 .Xr hosts 5 ,
2851 .Xr pf.os 5 ,
2852 .Xr protocols 5 ,
2853 .Xr services 5 ,
2854 .Xr ftp-proxy 8 ,
2855 .Xr pfctl 8 ,
2856 .Xr pflogd 8
2857 .Sh HISTORY
2858 The
2859 .Nm
2860 file format first appeared in
2861 .Ox 3.0 .