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