2 .\" $OpenBSD: pf.conf.5,v 1.406 2009/01/31 19:37:12 sobrado Exp $
4 .\" Copyright (c) 2002, Daniel Hartmeier
5 .\" All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
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.
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.
36 .Nd packet filter configuration file
40 packet filter modifies, drops or passes packets according to rules or
41 definitions specified in
44 There are seven types of statements in
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
53 Tables provide a mechanism for increasing the performance and flexibility of
54 rules with large numbers of source or destination addresses.
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.
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
65 .It Cm Packet Filtering
66 Packet filtering provides rule-based blocking or passing of packets.
73 the types of statements should be grouped and appear in
75 in the order shown above, as this matches the operation of the underlying
76 packet filtering engine.
79 enforces this order (see
83 Comments can be put anywhere in the file using a hash mark
85 and extend to the end of the current line.
87 Additional configuration files can be included with the
90 .Bd -literal -offset indent
91 include "/etc/pf/sub.filter.conf"
94 Macros can be defined that will later be expanded in context.
95 Macro names must start with a letter, and may contain letters, digits
97 Macro names may not be reserved words (for example
101 Macros are not expanded inside quotes.
104 .Bd -literal -offset indent
106 all_ifs = \&"{\&" $ext_if lo0 \&"}\&"
107 pass out on $ext_if from any to any
108 pass in on $ext_if proto tcp from any to any port 25
111 Tables are named structures which can hold a collection of addresses and
113 Lookups against tables in
115 are relatively fast, making a single rule with tables much more efficient,
117 processor usage and memory consumption, than a large number of rules which
118 differ only in IP address (either created explicitly or automatically by rule
121 Tables can be used as the source or destination of filter rules,
125 translation rules such as
129 (see below for details on the various rule types).
130 Tables can also be used for the redirect address of
134 rules and in the routing options of filter rules, but only for
138 Tables can be defined with any of the following
141 As with macros, reserved words may not be used as table names.
142 .Bl -tag -width "manually"
144 Persistent tables can be manually created with the
150 before or after the ruleset has been loaded.
152 Table definitions can be placed directly in this file, and loaded at the
153 same time as other rules are loaded, atomically.
154 Table definitions inside
158 statement, and are especially useful to define non-persistent tables.
159 The contents of a pre-existing table defined without a list of addresses
160 to initialize it is not altered when
163 A table initialized with the empty list,
165 will be cleared on load.
168 Tables may be defined with the following attributes:
169 .Bl -tag -width persist
173 flag forces the kernel to keep the table even when no rules refer to it.
174 If the flag is not set, the kernel will automatically remove the table
175 when the last rule referring to it is flushed.
179 flag prevents the user from altering the contents of the table once it
183 can be used to add or remove addresses from the table at any time, even
190 flag enables per-address packet and byte counters which can be displayed with
195 .Bd -literal -offset indent
196 table \*(Ltprivate\*(Gt const { 10/8, 172.16/12, 192.168/16 }
197 table \*(Ltbadhosts\*(Gt persist
198 block on fxp0 from { \*(Ltprivate\*(Gt, \*(Ltbadhosts\*(Gt } to any
201 creates a table called private, to hold RFC 1918 private network
202 blocks, and a table called badhosts, which is initially empty.
203 A filter rule is set up to block all traffic coming from addresses listed in
205 The private table cannot have its contents changed and the badhosts table
206 will exist even when no active filter rules reference it.
207 Addresses may later be added to the badhosts table, so that traffic from
208 these hosts can be blocked by using
209 .Bd -literal -offset indent
210 # pfctl -t badhosts -Tadd 204.92.77.111
213 A table can also be initialized with an address list specified in one or more
214 external files, using the following syntax:
215 .Bd -literal -offset indent
216 table \*(Ltspam\*(Gt persist file \&"/etc/spammers\&" file \&"/etc/openrelays\&"
217 block on fxp0 from \*(Ltspam\*(Gt to any
224 list IP addresses, one per line.
225 Any lines beginning with a # are treated as comments and ignored.
226 In addition to being specified by IP address, hosts may also be
227 specified by their hostname.
228 When the resolver is called to add a hostname to a table,
230 resulting IPv4 and IPv6 addresses are placed into the table.
231 IP addresses can also be entered in a table by specifying a valid interface
232 name, a valid interface group or the
234 keyword, in which case all addresses assigned to the interface(s) will be
238 may be tuned for various situations using the
244 .Bl -tag -width "src.track" -compact
246 Interval between purging expired states and fragments.
248 Seconds before an unassembled fragment is expired.
250 Length of time to retain a source tracking entry after the last state
254 When a packet matches a stateful connection, the seconds to live for the
255 connection will be updated to that of the
257 which corresponds to the connection state.
258 Each packet which matches this state will reset the TTL.
259 Tuning these values may improve the performance of the
260 firewall at the risk of dropping valid idle connections.
262 .Bl -tag -width xxxx -compact
264 The state after the first packet.
266 The state before the destination host ever sends a packet.
267 .It Ar tcp.established
268 The fully established state.
270 The state after the first FIN has been sent.
272 The state after both FINs have been exchanged and the connection is closed.
273 Some hosts (notably web servers on Solaris) send TCP packets even after closing
279 can prevent blocking of such packets.
281 The state after one endpoint sends an RST.
284 ICMP and UDP are handled in a fashion similar to TCP, but with a much more
285 limited set of states:
287 .Bl -tag -width xxxx -compact
289 The state after the first packet.
291 The state if the source host sends more than one packet but the destination
292 host has never sent one back.
294 The state if both hosts have sent packets.
296 The state after the first packet.
298 The state after an ICMP error came back in response to an ICMP packet.
301 Other protocols are handled similarly to UDP:
303 .Bl -tag -width xxxx -compact
306 .It Ar other.multiple
309 Timeout values can be reduced adaptively as the number of state table
312 .Bl -tag -width xxxx -compact
313 .It Ar adaptive.start
314 When the number of state entries exceeds this value, adaptive scaling
316 All timeout values are scaled linearly with factor
317 (adaptive.end - number of states) / (adaptive.end - adaptive.start).
319 When reaching this number of state entries, all timeout values become
320 zero, effectively purging all state entries immediately.
321 This value is used to define the scale factor, it should not actually
322 be reached (set a lower state limit, see below).
325 Adaptive timeouts are enabled by default, with an adaptive.start value
326 equal to 60% of the state limit, and an adaptive.end value equal to
327 120% of the state limit.
328 They can be disabled by setting both adaptive.start and adaptive.end to 0.
330 The adaptive timeout values can be defined both globally and for each rule.
331 When used on a per-rule basis, the values relate to the number of
332 states created by the rule, otherwise to the total number of
336 .Bd -literal -offset indent
337 set timeout tcp.first 120
338 set timeout tcp.established 86400
339 set timeout { adaptive.start 6000, adaptive.end 12000 }
340 set limit states 10000
343 With 9000 state table entries, the timeout values are scaled to 50%
344 (tcp.first 60, tcp.established 43200).
345 .It Ar set loginterface
346 Enable collection of packet and byte count statistics for the given
347 interface or interface group.
348 These statistics can be viewed using
349 .Bd -literal -offset indent
355 collects statistics on the interface named dc0:
356 .Bd -literal -offset indent
360 One can disable the loginterface using:
361 .Bd -literal -offset indent
362 set loginterface none
365 Sets hard limits on the memory pools used by the packet filter.
368 for an explanation of memory pools.
371 .Bd -literal -offset indent
372 set limit states 20000
375 sets the maximum number of entries in the memory pool used by state table
376 entries (generated by
378 rules which do not specify
382 .Bd -literal -offset indent
383 set limit frags 20000
386 sets the maximum number of entries in the memory pool used for fragment
387 reassembly (generated by
391 .Bd -literal -offset indent
392 set limit src-nodes 2000
395 sets the maximum number of entries in the memory pool used for tracking
396 source IP addresses (generated by the
402 .Bd -literal -offset indent
403 set limit tables 1000
404 set limit table-entries 100000
407 sets limits on the memory pools used by tables.
408 The first limits the number of tables that can exist to 1000.
409 The second limits the overall number of addresses that can be stored
412 Various limits can be combined on a single line:
413 .Bd -literal -offset indent
414 set limit { states 20000, frags 20000, src-nodes 2000 }
416 .It Ar set ruleset-optimization
417 .Bl -tag -width xxxxxxxx -compact
419 Disable the ruleset optimizer.
421 Enable basic ruleset optimization.
422 This is the default behaviour.
423 Basic ruleset optimization does four things to improve the
424 performance of ruleset evaluations:
428 remove duplicate rules
430 remove rules that are a subset of another rule
432 combine multiple rules into a table when advantageous
434 re-order the rules to improve evaluation performance
438 Uses the currently loaded ruleset as a feedback profile to tailor the
439 ordering of quick rules to actual network traffic.
442 It is important to note that the ruleset optimizer will modify the ruleset
443 to improve performance.
444 A side effect of the ruleset modification is that per-rule accounting
445 statistics will have different meanings than before.
446 If per-rule accounting is important for billing purposes or whatnot,
447 either the ruleset optimizer should not be used or a label field should
448 be added to all of the accounting rules to act as optimization barriers.
450 Optimization can also be set as a command-line argument to
452 overriding the settings in
454 .It Ar set optimization
455 Optimize state timeouts for one of the following network environments:
457 .Bl -tag -width xxxx -compact
459 A normal network environment.
460 Suitable for almost all networks.
462 A high-latency environment (such as a satellite connection).
467 Aggressively expire connections.
468 This can greatly reduce the memory usage of the firewall at the cost of
469 dropping idle connections early.
471 Extremely conservative settings.
472 Avoid dropping legitimate connections at the
473 expense of greater memory utilization (possibly much greater on a busy
474 network) and slightly increased processor utilization.
478 .Bd -literal -offset indent
479 set optimization aggressive
481 .It Ar set block-policy
484 option sets the default behaviour for the packet
488 .Bl -tag -width xxxxxxxx -compact
490 Packet is silently dropped.
492 A TCP RST is returned for blocked TCP packets,
493 an ICMP UNREACHABLE is returned for blocked UDP packets,
494 and all other packets are silently dropped.
498 .Bd -literal -offset indent
499 set block-policy return
501 .It Ar set state-policy
504 option sets the default behaviour for states:
506 .Bl -tag -width group-bound -compact
508 States are bound to interface.
510 States can match packets on any interfaces (the default).
514 .Bd -literal -offset indent
515 set state-policy if-bound
517 .It Ar set state-defaults
520 option sets the state options for states created from rules
524 .Bd -literal -offset indent
525 set state-defaults pflow, no-sync
530 identifies this firewall's state table entries to other firewalls
534 By default the hostid is set to a pseudo-random value, however it may be
535 desirable to manually configure it, for example to more easily identify the
536 source of state table entries.
537 .Bd -literal -offset indent
541 The hostid may be specified in either decimal or hexadecimal.
542 .It Ar set require-order
545 enforces an ordering of the statement types in the ruleset to:
551 Setting this option to
553 disables this enforcement.
554 There may be non-trivial and non-obvious implications to an out of
556 Consider carefully before disabling the order enforcement.
557 .It Ar set fingerprints
558 Load fingerprints of known operating systems from the given filename.
559 By default fingerprints of known operating systems are automatically
564 but can be overridden via this option.
565 Setting this option may leave a small period of time where the fingerprints
566 referenced by the currently active ruleset are inconsistent until the new
567 ruleset finishes loading.
571 .Dl set fingerprints \&"/etc/pf.os.devel\&"
572 .It Ar set skip on Aq Ar ifspec
573 List interfaces for which packets should not be filtered.
574 Packets passing in or out on such interfaces are passed as if pf was
575 disabled, i.e. pf does not process them in any way.
576 This can be useful on loopback and other virtual interfaces, when
577 packet filtering is not desired and can have unexpected effects.
584 to one of the following:
586 .Bl -tag -width xxxxxxxxxxxx -compact
588 Don't generate debug messages.
590 Generate debug messages only for serious errors.
592 Generate debug messages for various errors.
594 Generate debug messages for common conditions.
597 .Sh TRAFFIC NORMALIZATION
598 Traffic normalization is used to sanitize packet content in such
599 a way that there are no ambiguities in packet interpretation on
601 The normalizer does IP fragment reassembly to prevent attacks
602 that confuse intrusion detection systems by sending overlapping
604 Packet normalization is invoked with the
609 has the following options:
614 bit from a matching IP packet.
615 Some operating systems are known to generate fragmented packets with the
618 This is particularly true with NFS.
620 will drop such fragmented
626 Unfortunately some operating systems also generate their
628 packets with a zero IP identification field.
631 bit on packets with a zero IP ID may cause deleterious results if an
632 upstream router later fragments the packet.
635 modifier (see below) is recommended in combination with the
637 modifier to ensure unique IP identifiers.
638 .It Ar min-ttl Aq Ar number
639 Enforces a minimum TTL for matching IP packets.
640 .It Ar max-mss Aq Ar number
641 Enforces a maximum MSS for matching TCP packets.
642 .It Xo Ar set-tos Aq Ar string
643 .No \*(Ba Aq Ar number
647 for matching IP packets.
657 or one of the DiffServ Code Points:
659 .Ar af11 No ... Ar af43 ,
660 .Ar cs0 No ... Ar cs7 ;
661 or as either hex or decimal.
663 Replaces the IP identification field with random values to compensate
664 for predictable values generated by many hosts.
665 This option only applies to packets that are not fragmented
666 after the optional fragment reassembly.
667 .It Ar fragment reassemble
670 rules, fragments can be reassembled by normalization.
671 In this case, fragments are buffered until they form a complete
672 packet, and only the completed packet is passed on to the filter.
673 The advantage is that filter rules have to deal only with complete
674 packets, and can ignore fragments.
675 The drawback of caching fragments is the additional memory cost.
676 .It Ar reassemble tcp
677 Statefully normalizes TCP connections.
678 .Ar scrub reassemble tcp
679 rules may not have the direction (in/out) specified.
681 performs the following normalizations:
683 .Bl -tag -width timeout -compact
685 Neither side of the connection is allowed to reduce their IP TTL.
686 An attacker may send a packet such that it reaches the firewall, affects
687 the firewall state, and expires before reaching the destination host.
689 will raise the TTL of all packets back up to the highest value seen on
691 .It timestamp modulation
692 Modern TCP stacks will send a timestamp on every TCP packet and echo
693 the other endpoint's timestamp back to them.
694 Many operating systems will merely start the timestamp at zero when
695 first booted, and increment it several times a second.
696 The uptime of the host can be deduced by reading the timestamp and multiplying
698 Also observing several different timestamps can be used to count hosts
700 And spoofing TCP packets into a connection requires knowing or guessing
702 Timestamps merely need to be monotonically increasing and not derived off a
707 to modulate the TCP timestamps with a random number.
708 .It extended PAWS checks
709 There is a problem with TCP on long fat pipes, in that a packet might get
710 delayed for longer than it takes the connection to wrap its 32-bit sequence
712 In such an occurrence, the old packet would be indistinguishable from a
713 new packet and would be accepted as such.
714 The solution to this is called PAWS: Protection Against Wrapped Sequence
716 It protects against it by making sure the timestamp on each packet does
719 also makes sure the timestamp on the packet does not go forward more
723 artificially extends the security of TCP sequence numbers by 10 to 18
724 bits when the host uses appropriately randomized timestamps, since a
725 blind attacker would have to guess the timestamp as well.
730 .Bd -literal -offset indent
731 scrub in on $ext_if all fragment reassemble
736 option prefixed to a scrub rule causes matching packets to remain unscrubbed,
737 much in the same way as
739 works in the packet filter (see below).
740 This mechanism should be used when it is necessary to exclude specific packets
741 from broader scrub rules.
743 The ALTQ system is currently not available in the GENERIC kernel nor as
745 In order to use the herein after called queueing options one has to use a
749 to learn about the related kernel options.
751 Packets can be assigned to queues for the purpose of bandwidth
753 At least two declarations are required to configure queues, and later
754 any packet filtering rule can reference the defined queues by name.
755 During the filtering component of
759 name is where any packets from
761 rules will be queued, while for
763 rules it specifies where any resulting ICMP or TCP RST
764 packets should be queued.
767 defines the algorithm used to decide which packets get delayed, dropped, or
768 sent out immediately.
774 Class Based Queueing.
776 attached to an interface build a tree, thus each
778 can have further child
780 Each queue can have a
786 mainly controls the time packets take to get sent out, while
788 has primarily effects on throughput.
790 achieves both partitioning and sharing of link bandwidth
791 by hierarchically structured classes.
792 Each class has its own
794 and is assigned its share of
796 A child class can borrow bandwidth from its parent class
797 as long as excess bandwidth is available
804 are flat attached to the interface, thus,
806 cannot have further child
812 assigned, ranging from 0 to 15.
819 Hierarchical Fair Service Curve.
821 attached to an interface build a tree, thus each
823 can have further child
825 Each queue can have a
831 mainly controls the time packets take to get sent out, while
833 primarily affects throughput.
835 supports both link-sharing and guaranteed real-time services.
836 It employs a service curve based QoS model,
837 and its unique feature is an ability to decouple
844 The interfaces on which queueing should be activated are declared using
849 has the following keywords:
852 Queueing is enabled on the named interface.
854 Specifies which queueing scheduler to use.
855 Currently supported values
858 for Class Based Queueing,
860 for Priority Queueing and
862 for the Hierarchical Fair Service Curve scheduler.
863 .It Ar bandwidth Aq Ar bw
864 The maximum bitrate for all queues on an
865 interface may be specified using the
868 The value can be specified as an absolute value or as a
869 percentage of the interface bandwidth.
870 When using an absolute value, the suffixes
876 are used to represent bits, kilobits, megabits, and
877 gigabits per second, respectively.
878 The value must not exceed the interface bandwidth.
881 is not specified, the interface bandwidth is used
882 (but take note that some interfaces do not know their bandwidth,
883 or can adapt their bandwidth rates).
884 .It Ar qlimit Aq Ar limit
885 The maximum number of packets held in the queue.
887 .It Ar tbrsize Aq Ar size
888 Adjusts the size, in bytes, of the token bucket regulator.
889 If not specified, heuristics based on the
890 interface bandwidth are used to determine the size.
891 .It Ar queue Aq Ar list
892 Defines a list of subqueues to create on an interface.
895 In the following example, the interface dc0
896 should queue up to 5Mbps in four second-level queues using
897 Class Based Queueing.
898 Those four queues will be shown in a later example.
899 .Bd -literal -offset indent
900 altq on dc0 cbq bandwidth 5Mb queue { std, http, mail, ssh }
903 Once interfaces are activated for queueing using the
905 directive, a sequence of
907 directives may be defined.
908 The name associated with a
910 must match a queue defined in the
912 directive (e.g. mail), or, except for the
918 The following keywords can be used:
920 .It Ar on Aq Ar interface
921 Specifies the interface the queue operates on.
922 If not given, it operates on all matching interfaces.
923 .It Ar bandwidth Aq Ar bw
924 Specifies the maximum bitrate to be processed by the queue.
925 This value must not exceed the value of the parent
927 and can be specified as an absolute value or a percentage of the parent
929 If not specified, defaults to 100% of the parent queue's bandwidth.
932 scheduler does not support bandwidth specification.
933 .It Ar priority Aq Ar level
934 Between queues a priority level can be set.
939 the range is 0 to 7 and for
941 the range is 0 to 15.
942 The default for all is 1.
944 queues with a higher priority are always served first.
948 queues with a higher priority are preferred in the case of overload.
949 .It Ar qlimit Aq Ar limit
950 The maximum number of packets held in the queue.
956 can get additional parameters with
958 .Pf ( Aq Ar parameters ) .
960 Parameters are as follows:
963 Packets not matched by another queue are assigned to this one.
964 Exactly one default queue is required.
966 Enable RED (Random Early Detection) on this queue.
967 RED drops packets with a probability proportional to the average
970 Enables RIO on this queue.
971 RIO is RED with IN/OUT, thus running
972 RED two times more than RIO would achieve the same effect.
973 RIO is currently not supported in the GENERIC kernel.
975 Enables ECN (Explicit Congestion Notification) on this queue.
982 supports an additional option:
985 The queue can borrow bandwidth from the parent.
991 supports some additional options:
993 .It Ar realtime Aq Ar sc
994 The minimum required bandwidth for the queue.
995 .It Ar upperlimit Aq Ar sc
996 The maximum allowed bandwidth for the queue.
997 .It Ar linkshare Aq Ar sc
998 The bandwidth share of a backlogged queue.
1005 The format for service curve specifications is
1006 .Ar ( m1 , d , m2 ) .
1008 controls the bandwidth assigned to the queue.
1012 are optional and can be used to control the initial bandwidth assignment.
1015 milliseconds the queue gets the bandwidth given as
1017 afterwards the value given in
1024 child queues can be specified as in an
1026 declaration, thus building a tree of queues using a part of
1027 their parent's bandwidth.
1029 Packets can be assigned to queues based on filter rules by using the
1034 is specified; when a second one is specified it will instead be used for
1035 packets which have a
1039 and for TCP ACKs with no data payload.
1041 To continue the previous example, the examples below would specify the
1043 queues, plus a few child queues.
1046 sessions get priority over bulk transfers like
1050 The queues may then be referenced by filtering rules (see
1051 .Sx PACKET FILTERING
1054 queue std bandwidth 10% cbq(default)
1055 queue http bandwidth 60% priority 2 cbq(borrow red) \e
1056 { employees, developers }
1057 queue developers bandwidth 75% cbq(borrow)
1058 queue employees bandwidth 15%
1059 queue mail bandwidth 10% priority 0 cbq(borrow ecn)
1060 queue ssh bandwidth 20% cbq(borrow) { ssh_interactive, ssh_bulk }
1061 queue ssh_interactive bandwidth 50% priority 7 cbq(borrow)
1062 queue ssh_bulk bandwidth 50% priority 0 cbq(borrow)
1064 block return out on dc0 inet all queue std
1065 pass out on dc0 inet proto tcp from $developerhosts to any port 80 \e
1067 pass out on dc0 inet proto tcp from $employeehosts to any port 80 \e
1069 pass out on dc0 inet proto tcp from any to any port 22 \e
1070 queue(ssh_bulk, ssh_interactive)
1071 pass out on dc0 inet proto tcp from any to any port 25 \e
1075 Translation rules modify either the source or destination address of the
1076 packets associated with a stateful connection.
1077 A stateful connection is automatically created to track packets matching
1078 such a rule as long as they are not blocked by the filtering section of
1080 The translation engine modifies the specified address and/or port in the
1081 packet, recalculates IP, TCP and UDP checksums as necessary, and passes it to
1082 the packet filter for evaluation.
1084 Since translation occurs before filtering the filter
1085 engine will see packets as they look after any
1086 addresses and ports have been translated.
1087 Filter rules will therefore have to filter based on the translated
1088 address and port number.
1089 Packets that match a translation rule are only automatically passed if
1092 modifier is given, otherwise they are
1099 The state entry created permits
1101 to keep track of the original address for traffic associated with that state
1102 and correctly direct return traffic for that connection.
1104 Various types of translation are possible with pf:
1105 .Bl -tag -width xxxx
1109 rule specifies a bidirectional mapping between an external IP netblock
1110 and an internal IP netblock.
1114 rule specifies that IP addresses are to be changed as the packet
1115 traverses the given interface.
1116 This technique allows one or more IP addresses
1117 on the translating host to support network traffic for a larger range of
1118 machines on an "inside" network.
1119 Although in theory any IP address can be used on the inside, it is strongly
1120 recommended that one of the address ranges defined by RFC 1918 be used.
1121 These netblocks are:
1123 10.0.0.0 - 10.255.255.255 (all of net 10, i.e., 10/8)
1124 172.16.0.0 - 172.31.255.255 (i.e., 172.16/12)
1125 192.168.0.0 - 192.168.255.255 (i.e., 192.168/16)
1128 The packet is redirected to another destination and possibly a
1131 rules can optionally specify port ranges instead of single ports.
1132 rdr ... port 2000:2999 -\*(Gt ... port 4000
1133 redirects ports 2000 to 2999 (inclusive) to port 4000.
1134 rdr ... port 2000:2999 -\*(Gt ... port 4000:*
1135 redirects port 2000 to 4000, 2001 to 4001, ..., 2999 to 4999.
1138 In addition to modifying the address, some translation rules may modify
1139 source or destination ports for
1143 connections; implicitly in the case of
1145 rules and explicitly in the case of
1148 Port numbers are never translated with a
1152 Evaluation order of the translation rules is dependent on the type
1153 of the translation rules and of the direction of a packet.
1155 rules are always evaluated first.
1158 rules are evaluated on an inbound packet or the
1160 rules on an outbound packet.
1161 Rules of the same type are evaluated in the same order in which they
1162 appear in the ruleset.
1163 The first matching rule decides what action is taken.
1167 option prefixed to a translation rule causes packets to remain untranslated,
1168 much in the same way as
1170 works in the packet filter (see below).
1171 If no rule matches the packet it is passed to the filter engine unmodified.
1173 Translation rules apply only to packets that pass through
1174 the specified interface, and if no interface is specified,
1175 translation is applied to packets on all interfaces.
1176 For instance, redirecting port 80 on an external interface to an internal
1177 web server will only work for connections originating from the outside.
1178 Connections to the address of the external interface from local hosts will
1179 not be redirected, since such packets do not actually pass through the
1181 Redirections cannot reflect packets back through the interface they arrive
1182 on, they can only be redirected to hosts connected to different interfaces
1183 or to the firewall itself.
1185 Note that redirecting external incoming connections to the loopback
1187 .Bd -literal -offset indent
1188 rdr on ne3 inet proto tcp to port smtp -\*(Gt 127.0.0.1 port spamd
1191 will effectively allow an external host to connect to daemons
1192 bound solely to the loopback address, circumventing the traditional
1193 blocking of such connections on a real interface.
1194 Unless this effect is desired, any of the local non-loopback addresses
1195 should be used as redirection target instead, which allows external
1196 connections only to daemons bound to this address or not bound to
1200 .Sx TRANSLATION EXAMPLES
1202 .Sh PACKET FILTERING
1208 packets based on attributes of their layer 3 (see
1218 In addition, packets may also be
1219 assigned to queues for the purpose of bandwidth control.
1221 For each packet processed by the packet filter, the filter rules are
1222 evaluated in sequential order, from first to last.
1223 The last matching rule decides what action is taken.
1224 If no rule matches the packet, the default action is to pass
1227 The following actions can be used in the filter:
1228 .Bl -tag -width xxxx
1230 The packet is blocked.
1231 There are a number of ways in which a
1233 rule can behave when blocking a packet.
1234 The default behaviour is to
1236 packets silently, however this can be overridden or made
1237 explicit either globally, by setting the
1239 option, or on a per-rule basis with one of the following options:
1241 .Bl -tag -width xxxx -compact
1243 The packet is silently dropped.
1245 This applies only to
1247 packets, and issues a TCP RST which closes the
1251 This causes ICMP messages to be returned for packets which match the rule.
1252 By default this is an ICMP UNREACHABLE message, however this
1253 can be overridden by specifying a message as a code or number.
1255 This causes a TCP RST to be returned for
1257 packets and an ICMP UNREACHABLE for UDP and other packets.
1260 Options returning ICMP packets currently have no effect if
1264 as the code to support this feature has not yet been implemented.
1266 The simplest mechanism to block everything by default and only pass
1267 packets that match explicit rules is specify a first filter rule of:
1268 .Bd -literal -offset indent
1272 The packet is passed;
1273 state is created unless the
1275 option is specified.
1280 filters packets statefully; the first time a packet matches a
1282 rule, a state entry is created; for subsequent packets the filter checks
1283 whether the packet matches any state.
1284 If it does, the packet is passed without evaluation of any rules.
1285 After the connection is closed or times out, the state entry is automatically
1288 This has several advantages.
1289 For TCP connections, comparing a packet to a state involves checking
1290 its sequence numbers, as well as TCP timestamps if a
1291 .Ar scrub reassemble tcp
1292 rule applies to the connection.
1293 If these values are outside the narrow windows of expected
1294 values, the packet is dropped.
1295 This prevents spoofing attacks, such as when an attacker sends packets with
1296 a fake source address/port but does not know the connection's sequence
1300 knows how to match ICMP replies to states.
1302 .Bd -literal -offset indent
1303 pass out inet proto icmp all icmp-type echoreq
1306 allows echo requests (such as those created by
1308 out statefully, and matches incoming echo replies correctly to states.
1310 Also, looking up states is usually faster than evaluating rules.
1311 If there are 50 rules, all of them are evaluated sequentially in O(n).
1312 Even with 50000 states, only 16 comparisons are needed to match a
1313 state, since states are stored in a binary search tree that allows
1314 searches in O(log2 n).
1316 Furthermore, correct handling of ICMP error messages is critical to
1317 many protocols, particularly TCP.
1319 matches ICMP error messages to the correct connection, checks them against
1320 connection parameters, and passes them if appropriate.
1321 For example if an ICMP source quench message referring to a stateful TCP
1322 connection arrives, it will be matched to the state and get passed.
1324 Finally, state tracking is required for
1325 .Ar nat , binat No and Ar rdr
1326 rules, in order to track address and port translations and reverse the
1327 translation on returning packets.
1330 will also create state for other protocols which are effectively stateless by
1332 UDP packets are matched to states using only host addresses and ports,
1333 and other protocols are matched to states using only the host addresses.
1335 If stateless filtering of individual packets is desired,
1338 keyword can be used to specify that state will not be created
1339 if this is the last matching rule.
1340 A number of parameters can also be set to affect how
1342 handles state tracking.
1344 .Sx STATEFUL TRACKING OPTIONS
1345 below for further details.
1347 The rule parameters specify the packets to which a rule applies.
1348 A packet always comes in on, or goes out through, one interface.
1349 Most parameters are optional.
1350 If a parameter is specified, the rule only applies to packets with
1351 matching attributes.
1352 Certain parameters can be expressed as lists, in which case
1354 generates all needed rule combinations.
1355 .Bl -tag -width xxxx
1356 .It Ar in No or Ar out
1357 This rule applies to incoming or outgoing packets.
1362 are specified, the rule will match packets in both directions.
1364 In addition to the action specified, a log message is generated.
1365 Only the packet that establishes the state is logged,
1368 option is specified.
1369 The logged packets are sent to a
1371 interface, by default
1373 This interface is monitored by the
1375 logging daemon, which dumps the logged packets to the file
1381 Used to force logging of all packets for a connection.
1382 This is not necessary when
1384 is explicitly specified.
1387 packets are logged to
1392 user ID of the user that owns the socket and the PID of the process that
1393 has the socket open where the packet is sourced from or destined to
1394 (depending on which socket is local).
1395 This is in addition to the normal information logged.
1397 Only the first packet
1400 will have the user credentials logged when using stateful matching.
1401 .It Ar log (to Aq Ar interface )
1402 Send logs to the specified
1404 interface instead of
1407 If a packet matches a rule which has the
1409 option set, this rule
1410 is considered the last matching rule, and evaluation of subsequent rules
1412 .It Ar on Aq Ar interface
1413 This rule applies only to packets coming in on, or going out through, this
1414 particular interface or interface group.
1415 For more information on interface groups,
1421 This rule applies only to packets of this address family.
1422 Supported values are
1426 .It Ar proto Aq Ar protocol
1427 This rule applies only to packets of this protocol.
1428 Common protocols are
1434 For a list of all the protocol name to number mappings used by
1437 .Pa /etc/protocols .
1439 .Ar from Aq Ar source
1440 .Ar port Aq Ar source
1445 This rule applies only to packets with the specified source and destination
1446 addresses and ports.
1448 Addresses can be specified in CIDR notation (matching netblocks), as
1449 symbolic host names, interface names or interface group names, or as any
1450 of the following keywords:
1452 .Bl -tag -width xxxxxxxxxxxxxx -compact
1456 Any address which is not currently routable.
1458 Any source address that fails a unicast reverse path forwarding (URPF)
1459 check, i.e. packets coming in on an interface other than that which holds
1460 the route back to the packet's source address.
1462 Any address that matches the given table.
1465 Ranges of addresses are specified by using the
1469 .Dq 10.1.1.10 - 10.1.1.12
1470 means all addresses from 10.1.1.10 to 10.1.1.12,
1471 hence addresses 10.1.1.10, 10.1.1.11, and 10.1.1.12.
1473 Interface names and interface group names can have modifiers appended:
1475 .Bl -tag -width xxxxxxxxxxxx -compact
1477 Translates to the network(s) attached to the interface.
1479 Translates to the interface's broadcast address(es).
1481 Translates to the point-to-point interface's peer address(es).
1483 Do not include interface aliases.
1486 Host names may also have the
1488 option appended to restrict the name resolution to the first of each
1489 v4 and v6 address found.
1491 Host name resolution and interface to address translation are done at
1493 When the address of an interface (or host name) changes (under DHCP or PPP,
1494 for instance), the ruleset must be reloaded for the change to be reflected
1496 Surrounding the interface name (and optional modifiers) in parentheses
1497 changes this behaviour.
1498 When the interface name is surrounded by parentheses, the rule is
1499 automatically updated whenever the interface changes its address.
1500 The ruleset does not need to be reloaded.
1501 This is especially useful with
1504 Ports can be specified either by number or by name.
1505 For example, port 80 can be specified as
1507 For a list of all port name to number mappings used by
1512 Ports and ranges of ports are specified by using these operators:
1513 .Bd -literal -offset indent
1517 \*(Le (less than or equal)
1518 \*(Gt (greater than)
1519 \*(Ge (greater than or equal)
1520 : (range including boundaries)
1521 \*(Gt\*(Lt (range excluding boundaries)
1522 \*(Lt\*(Gt (except range)
1529 are binary operators (they take two arguments).
1532 .It Ar port 2000:2004
1534 .Sq all ports \*(Ge 2000 and \*(Le 2004 ,
1535 hence ports 2000, 2001, 2002, 2003 and 2004.
1536 .It Ar port 2000 \*(Gt\*(Lt 2004
1538 .Sq all ports \*(Gt 2000 and \*(Lt 2004 ,
1539 hence ports 2001, 2002 and 2003.
1540 .It Ar port 2000 \*(Lt\*(Gt 2004
1542 .Sq all ports \*(Lt 2000 or \*(Gt 2004 ,
1543 hence ports 1-1999 and 2005-65535.
1546 The operating system of the source host can be specified in the case of TCP
1551 .Sx OPERATING SYSTEM FINGERPRINTING
1552 section for more information.
1554 The host, port and OS specifications are optional, as in the following examples:
1555 .Bd -literal -offset indent
1557 pass in from any to any
1558 pass in proto tcp from any port \*(Le 1024 to any
1559 pass in proto tcp from any to any port 25
1560 pass in proto tcp from 10.0.0.0/8 port \*(Gt 1024 \e
1561 to ! 10.1.2.3 port != ssh
1562 pass in proto tcp from any os "OpenBSD"
1565 This is equivalent to "from any to any".
1566 .It Ar group Aq Ar group
1569 this rule only applies to packets of sockets owned by the specified group.
1570 .It Ar user Aq Ar user
1571 This rule only applies to packets of sockets owned by the specified user.
1572 For outgoing connections initiated from the firewall, this is the user
1573 that opened the connection.
1574 For incoming connections to the firewall itself, this is the user that
1575 listens on the destination port.
1576 For forwarded connections, where the firewall is not a connection endpoint,
1577 the user and group are
1580 All packets, both outgoing and incoming, of one connection are associated
1581 with the same user and group.
1582 Only TCP and UDP packets can be associated with users; for other protocols
1583 these parameters are ignored.
1585 User and group refer to the effective (as opposed to the real) IDs, in
1586 case the socket is created by a setuid/setgid process.
1587 User and group IDs are stored when a socket is created;
1588 when a process creates a listening socket as root (for instance, by
1589 binding to a privileged port) and subsequently changes to another
1590 user ID (to drop privileges), the credentials will remain root.
1592 User and group IDs can be specified as either numbers or names.
1593 The syntax is similar to the one for ports.
1596 matches packets of forwarded connections.
1598 can only be used with the operators
1602 Other constructs like
1603 .Cm user \*(Ge unknown
1605 Forwarded packets with unknown user and group ID match only rules
1606 that explicitly compare against
1614 does not match forwarded packets.
1615 The following example allows only selected users to open outgoing
1617 .Bd -literal -offset indent
1618 block out proto { tcp, udp } all
1619 pass out proto { tcp, udp } all user { \*(Lt 1000, dhartmei }
1621 .It Xo Ar flags Aq Ar a
1623 .No \*(Ba / Ns Aq Ar b
1626 This rule only applies to TCP packets that have the flags
1630 Flags not specified in
1633 For stateful connections, the default is
1635 To indicate that flags should not be checked at all, specify
1637 The flags are: (F)IN, (S)YN, (R)ST, (P)USH, (A)CK, (U)RG, (E)CE, and C(W)R.
1641 The other flags are ignored.
1643 This is the default setting for stateful connections.
1644 Out of SYN and ACK, exactly SYN may be set.
1645 SYN, SYN+PSH and SYN+RST match, but SYN+ACK, ACK and ACK+RST do not.
1646 This is more restrictive than the previous example.
1648 If the first set is not specified, it defaults to none.
1649 All of SYN, FIN, RST and ACK must be unset.
1654 is applied by default (unless
1656 is specified), only the initial SYN packet of a TCP handshake will create
1657 a state for a TCP connection.
1658 It is possible to be less restrictive, and allow state creation from
1661 packets, by specifying
1665 to synchronize to existing connections, for instance
1666 if one flushes the state table.
1667 However, states created from such intermediate packets may be missing
1668 connection details such as the TCP window scaling factor.
1669 States which modify the packet flow, such as those affected by
1670 .Ar nat , binat No or Ar rdr
1672 .Ar modulate No or Ar synproxy state
1673 options, or scrubbed with
1675 will also not be recoverable from intermediate packets.
1676 Such connections will stall and time out.
1677 .It Xo Ar icmp-type Aq Ar type
1680 .It Xo Ar icmp6-type Aq Ar type
1683 This rule only applies to ICMP or ICMPv6 packets with the specified type
1685 Text names for ICMP types and codes are listed in
1689 This parameter is only valid for rules that cover protocols ICMP or
1691 The protocol and the ICMP type indicator
1698 .It Xo Ar tos Aq Ar string
1699 .No \*(Ba Aq Ar number
1701 This rule applies to packets with the specified
1713 or one of the DiffServ Code Points:
1715 .Ar af11 No ... Ar af43 ,
1716 .Ar cs0 No ... Ar cs7 ;
1717 or as either hex or decimal.
1719 For example, the following rules are identical:
1720 .Bd -literal -offset indent
1721 pass all tos lowdelay
1726 By default, IPv4 packets with IP options or IPv6 packets with routing
1727 extension headers are blocked.
1732 rule, packets that pass the filter based on that rule (last matching)
1733 do so even if they contain IP options or routing extension headers.
1734 For packets that match state, the rule that initially created the
1738 rule that is used when a packet does not match any rules does not
1740 .It Ar label Aq Ar string
1741 Adds a label (name) to the rule, which can be used to identify the rule.
1744 shows per-rule statistics for rules that have labels.
1746 The following macros can be used in labels:
1748 .Bl -tag -width $srcaddr -compact -offset indent
1752 The source IP address.
1754 The destination IP address.
1756 The source port specification.
1758 The destination port specification.
1766 .Bd -literal -offset indent
1767 ips = \&"{ 1.2.3.4, 1.2.3.5 }\&"
1768 pass in proto tcp from any to $ips \e
1769 port \*(Gt 1023 label \&"$dstaddr:$dstport\&"
1773 .Bd -literal -offset indent
1774 pass in inet proto tcp from any to 1.2.3.4 \e
1775 port \*(Gt 1023 label \&"1.2.3.4:\*(Gt1023\&"
1776 pass in inet proto tcp from any to 1.2.3.5 \e
1777 port \*(Gt 1023 label \&"1.2.3.5:\*(Gt1023\&"
1780 The macro expansion for the
1782 directive occurs only at configuration file parse time, not during runtime.
1783 .It Xo Ar queue Aq Ar queue
1784 .No \*(Ba ( Aq Ar queue ,
1787 Packets matching this rule will be assigned to the specified queue.
1788 If two queues are given, packets which have a
1792 and TCP ACKs with no data payload will be assigned to the second one.
1798 .Bd -literal -offset indent
1799 pass in proto tcp to port 25 queue mail
1800 pass in proto tcp to port 22 queue(ssh_bulk, ssh_prio)
1803 .It Cm set prio Ar priority | Pq Ar priority , priority
1804 Packets matching this rule will be assigned a specific queueing priority.
1805 Priorities are assigned as integers 0 through 7.
1806 If the packet is transmitted on a
1808 interface, the queueing priority will be written as the priority
1809 code point in the 802.1Q VLAN header.
1810 If two priorities are given, packets which have a TOS of
1812 and TCP ACKs with no data payload will be assigned to the second one.
1815 .Bd -literal -offset indent
1816 pass in proto tcp to port 25 set prio 2
1817 pass in proto tcp to port 22 set prio (2, 5)
1820 .It Ar tag Aq Ar string
1821 Packets matching this rule will be tagged with the
1823 The tag acts as an internal marker that can be used to
1824 identify these packets later on.
1825 This can be used, for example, to provide trust between
1826 interfaces and to determine if packets have been
1827 processed by translation rules.
1830 meaning that the packet will be tagged even if the rule
1831 is not the last matching rule.
1832 Further matching rules can replace the tag with a
1833 new one but will not remove a previously applied tag.
1834 A packet is only ever assigned one tag at a time.
1835 Packet tagging can be done during
1840 rules in addition to filter rules.
1841 Tags take the same macros as labels (see above).
1842 .It Ar tagged Aq Ar string
1843 Used with filter, translation or scrub rules
1844 to specify that packets must already
1845 be tagged with the given tag in order to match the rule.
1846 Inverse tag matching can also be done
1852 .It Ar rtable Aq Ar number
1853 Used to select an alternate routing table for the routing lookup.
1854 Only effective before the route lookup happened, i.e. when filtering inbound.
1855 .It Xo Ar divert-to Aq Ar host
1858 Used to redirect packets to a local socket bound to
1862 The packets will not be modified, so
1864 on the socket will return the original destination address of the packet.
1866 Used to receive replies for sockets that are bound to addresses
1867 which are not local to the machine.
1870 for information on how to bind these sockets.
1871 .It Ar probability Aq Ar number
1872 A probability attribute can be attached to a rule, with a value set between
1873 0 and 1, bounds not included.
1874 In that case, the rule will be honoured using the given probability value
1876 For example, the following rule will drop 20% of incoming ICMP packets:
1877 .Bd -literal -offset indent
1878 block in proto icmp probability 20%
1880 .It Ar prio Aq Ar number
1881 Only match packets which have the given queueing priority assigned.
1885 If a packet matches a rule with a route option set, the packet filter will
1886 route the packet according to the type of route option.
1887 When such a rule creates state, the route option is also applied to all
1888 packets matching the same connection.
1889 .Bl -tag -width xxxx
1893 option routes the packet to the specified interface with an optional address
1897 rule creates state, only packets that pass in the same direction as the
1898 filter rule specifies will be routed in this way.
1899 Packets passing in the opposite direction (replies) are not affected
1900 and are routed normally.
1904 option is similar to
1906 but routes packets that pass in the opposite direction (replies) to the
1907 specified interface.
1908 Opposite direction is only defined in the context of a state entry, and
1910 is useful only in rules that create state.
1911 It can be used on systems with multiple external connections to
1912 route all outgoing packets of a connection through the interface
1913 the incoming connection arrived through (symmetric routing enforcement).
1917 option creates a duplicate of the packet and routes it like
1919 The original packet gets routed as it normally would.
1926 rules, (as well as for the
1931 rule options) for which there is a single redirection address which has a
1932 subnet mask smaller than 32 for IPv4 or 128 for IPv6 (more than one IP
1933 address), a variety of different methods for assigning this address can be
1935 .Bl -tag -width xxxx
1939 option applies the network portion of the redirection address to the address
1940 to be modified (source with
1947 option selects an address at random within the defined block of addresses.
1951 option uses a hash of the source address to determine the redirection address,
1952 ensuring that the redirection address is always the same for a given source.
1953 An optional key can be specified after this keyword either in hex or as a
1956 randomly generates a key for source-hash every time the
1957 ruleset is reloaded.
1961 option loops through the redirection address(es).
1963 When more than one redirection address is specified,
1965 is the only permitted pool type.
1973 from modifying the source port on TCP and UDP packets.
1978 option can be specified to help ensure that multiple connections from the
1979 same source are mapped to the same redirection address.
1980 This option can be used with the
1985 Note that by default these associations are destroyed as soon as there are
1986 no longer states which refer to them; in order to make the mappings last
1987 beyond the lifetime of the states, increase the global options with
1988 .Ar set timeout src.track .
1990 .Sx STATEFUL TRACKING OPTIONS
1991 for more ways to control the source tracking.
1992 .Sh STATE MODULATION
1993 Much of the security derived from TCP is attributable to how well the
1994 initial sequence numbers (ISNs) are chosen.
1995 Some popular stack implementations choose
1997 poor ISNs and thus are normally susceptible to ISN prediction exploits.
2000 rule to a TCP connection,
2002 will create a high quality random sequence number for each connection
2007 directive implicitly keeps state on the rule and is
2008 only applicable to TCP connections.
2011 .Bd -literal -offset indent
2013 pass out proto tcp from any to any modulate state
2014 pass in proto tcp from any to any port 25 flags S/SFRA modulate state
2017 Note that modulated connections will not recover when the state table
2018 is lost (firewall reboot, flushing the state table, etc...).
2020 will not be able to infer a connection again after the state table flushes
2021 the connection's modulator.
2022 When the state is lost, the connection may be left dangling until the
2023 respective endpoints time out the connection.
2024 It is possible on a fast local network for the endpoints to start an ACK
2025 storm while trying to resynchronize after the loss of the modulator.
2028 settings (or a more strict equivalent) should be used on
2030 rules to prevent ACK storms.
2032 Note that alternative methods are available
2033 to prevent loss of the state table
2034 and allow for firewall failover.
2039 for further information.
2043 passes packets that are part of a
2045 handshake between the endpoints.
2048 option can be used to cause
2050 itself to complete the handshake with the active endpoint, perform a handshake
2051 with the passive endpoint, and then forward packets between the endpoints.
2053 No packets are sent to the passive endpoint before the active endpoint has
2054 completed the handshake, hence so-called SYN floods with spoofed source
2055 addresses will not reach the passive endpoint, as the sender can't complete the
2058 The proxy is transparent to both endpoints, they each see a single
2059 connection from/to the other endpoint.
2061 chooses random initial sequence numbers for both handshakes.
2062 Once the handshakes are completed, the sequence number modulators
2063 (see previous section) are used to translate further packets of the
2067 .Ar modulate state .
2077 .Bd -literal -offset indent
2078 pass in proto tcp from any to any port www synproxy state
2080 .Sh STATEFUL TRACKING OPTIONS
2081 A number of options related to stateful tracking can be applied on a
2087 support these options, and
2089 must be specified explicitly to apply options to a rule.
2091 .Bl -tag -width xxxx -compact
2092 .It Ar max Aq Ar number
2093 Limits the number of concurrent states the rule may create.
2094 When this limit is reached, further packets that would create
2095 state will not match this rule until existing states time out.
2097 Prevent state changes for states created by this rule from appearing on the
2100 .It Xo Aq Ar timeout
2103 Changes the timeout values used for states created by this rule.
2104 For a list of all valid timeout names, see
2108 Uses a sloppy TCP connection tracker that does not check sequence
2109 numbers at all, which makes insertion and ICMP teardown attacks way
2111 This is intended to be used in situations where one does not see all
2112 packets of a connection, e.g. in asymmetric routing situations.
2113 Cannot be used with modulate or synproxy state.
2115 States created by this rule are exported on the
2120 Multiple options can be specified, separated by commas:
2121 .Bd -literal -offset indent
2122 pass in proto tcp from any to any \e
2123 port www keep state \e
2124 (max 100, source-track rule, max-src-nodes 75, \e
2125 max-src-states 3, tcp.established 60, tcp.closing 5)
2130 keyword is specified, the number of states per source IP is tracked.
2132 .Bl -tag -width xxxx -compact
2133 .It Ar source-track rule
2134 The maximum number of states created by this rule is limited by the rule's
2139 Only state entries created by this particular rule count toward the rule's
2141 .It Ar source-track global
2142 The number of states created by all rules that use this option is limited.
2143 Each rule can specify different
2147 options, however state entries created by any participating rule count towards
2148 each individual rule's limits.
2151 The following limits can be set:
2153 .Bl -tag -width xxxx -compact
2154 .It Ar max-src-nodes Aq Ar number
2155 Limits the maximum number of source addresses which can simultaneously
2156 have state table entries.
2157 .It Ar max-src-states Aq Ar number
2158 Limits the maximum number of simultaneous state entries that a single
2159 source address can create with this rule.
2162 For stateful TCP connections, limits on established connections (connections
2163 which have completed the TCP 3-way handshake) can also be enforced
2166 .Bl -tag -width xxxx -compact
2167 .It Ar max-src-conn Aq Ar number
2168 Limits the maximum number of simultaneous TCP connections which have
2169 completed the 3-way handshake that a single host can make.
2170 .It Xo Ar max-src-conn-rate Aq Ar number
2173 Limit the rate of new connections over a time interval.
2174 The connection rate is an approximation calculated as a moving average.
2177 Because the 3-way handshake ensures that the source address is not being
2178 spoofed, more aggressive action can be taken based on these limits.
2180 .Ar overload Aq Ar table
2181 state option, source IP addresses which hit either of the limits on
2182 established connections will be added to the named table.
2183 This table can be used in the ruleset to block further activity from
2184 the offending host, redirect it to a tarpit process, or restrict its
2189 keyword kills all states created by the matching rule which originate
2190 from the host which exceeds these limits.
2193 modifier to the flush command kills all states originating from the
2194 offending host, regardless of which rule created the state.
2196 For example, the following rules will protect the webserver against
2197 hosts making more than 100 connections in 10 seconds.
2198 Any host which connects faster than this rate will have its address added
2201 table and have all states originating from it flushed.
2202 Any new packets arriving from this host will be dropped unconditionally
2204 .Bd -literal -offset indent
2205 block quick from \*(Ltbad_hosts\*(Gt
2206 pass in on $ext_if proto tcp to $webserver port www keep state \e
2207 (max-src-conn-rate 100/10, overload \*(Ltbad_hosts\*(Gt flush global)
2209 .Sh OPERATING SYSTEM FINGERPRINTING
2210 Passive OS Fingerprinting is a mechanism to inspect nuances of a TCP
2211 connection's initial SYN packet and guess at the host's operating system.
2212 Unfortunately these nuances are easily spoofed by an attacker so the
2213 fingerprint is not useful in making security decisions.
2214 But the fingerprint is typically accurate enough to make policy decisions
2217 The fingerprints may be specified by operating system class, by
2218 version, or by subtype/patchlevel.
2219 The class of an operating system is typically the vendor or genre
2225 The version of the oldest available
2227 release on the main FTP site
2228 would be 2.6 and the fingerprint would be written
2230 .Dl \&"OpenBSD 2.6\&"
2232 The subtype of an operating system is typically used to describe the
2233 patchlevel if that patch led to changes in the TCP stack behavior.
2236 the only subtype is for a fingerprint that was
2239 scrub option and would be specified as
2241 .Dl \&"OpenBSD 3.3 no-df\&"
2243 Fingerprints for most popular operating systems are provided by
2247 is running, a complete list of known operating system fingerprints may
2248 be listed by running:
2252 Filter rules can enforce policy at any level of operating system specification
2253 assuming a fingerprint is present.
2254 Policy could limit traffic to approved operating systems or even ban traffic
2255 from hosts that aren't at the latest service pack.
2259 class can also be used as the fingerprint which will match packets for
2260 which no operating system fingerprint is known.
2263 .Bd -literal -offset indent
2264 pass out proto tcp from any os OpenBSD
2265 block out proto tcp from any os Doors
2266 block out proto tcp from any os "Doors PT"
2267 block out proto tcp from any os "Doors PT SP3"
2268 block out from any os "unknown"
2269 pass on lo0 proto tcp from any os "OpenBSD 3.3 lo0"
2272 Operating system fingerprinting is limited only to the TCP SYN packet.
2273 This means that it will not work on other protocols and will not match
2274 a currently established connection.
2276 Caveat: operating system fingerprints are occasionally wrong.
2277 There are three problems: an attacker can trivially craft his packets to
2278 appear as any operating system he chooses;
2279 an operating system patch could change the stack behavior and no fingerprints
2280 will match it until the database is updated;
2281 and multiple operating systems may have the same fingerprint.
2282 .Sh BLOCKING SPOOFED TRAFFIC
2283 "Spoofing" is the faking of IP addresses, typically for malicious
2287 directive expands to a set of filter rules which will block all
2288 traffic with a source IP from the network(s) directly connected
2289 to the specified interface(s) from entering the system through
2290 any other interface.
2292 For example, the line
2293 .Bd -literal -offset indent
2298 .Bd -literal -offset indent
2299 block drop in on ! lo0 inet from 127.0.0.1/8 to any
2300 block drop in on ! lo0 inet6 from ::1 to any
2303 For non-loopback interfaces, there are additional rules to block incoming
2304 packets with a source IP address identical to the interface's IP(s).
2305 For example, assuming the interface wi0 had an IP address of 10.0.0.1 and a
2306 netmask of 255.255.255.0,
2308 .Bd -literal -offset indent
2309 antispoof for wi0 inet
2313 .Bd -literal -offset indent
2314 block drop in on ! wi0 inet from 10.0.0.0/24 to any
2315 block drop in inet from 10.0.0.1 to any
2318 Caveat: Rules created by the
2320 directive interfere with packets sent over loopback interfaces
2322 One should pass these explicitly.
2323 .Sh FRAGMENT HANDLING
2324 The size of IP datagrams (packets) can be significantly larger than the
2325 maximum transmission unit (MTU) of the network.
2326 In cases when it is necessary or more efficient to send such large packets,
2327 the large packet will be fragmented into many smaller packets that will each
2329 Unfortunately for a firewalling device, only the first logical fragment will
2330 contain the necessary header information for the subprotocol that allows
2332 to filter on things such as TCP ports or to perform NAT.
2336 rules as described in
2337 .Sx TRAFFIC NORMALIZATION
2338 above, there are three options for handling fragments in the packet filter.
2340 One alternative is to filter individual fragments with filter rules.
2343 rule applies to a fragment, it is passed to the filter.
2344 Filter rules with matching IP header parameters decide whether the
2345 fragment is passed or blocked, in the same way as complete packets
2347 Without reassembly, fragments can only be filtered based on IP header
2348 fields (source/destination address, protocol), since subprotocol header
2349 fields are not available (TCP/UDP port numbers, ICMP code/type).
2352 option can be used to restrict filter rules to apply only to
2353 fragments, but not complete packets.
2354 Filter rules without the
2356 option still apply to fragments, if they only specify IP header fields.
2357 For instance, the rule
2358 .Bd -literal -offset indent
2359 pass in proto tcp from any to any port 80
2362 never applies to a fragment, even if the fragment is part of a TCP
2363 packet with destination port 80, because without reassembly this information
2364 is not available for each fragment.
2365 This also means that fragments cannot create new or match existing
2366 state table entries, which makes stateful filtering and address
2367 translation (NAT, redirection) for fragments impossible.
2369 It's also possible to reassemble only certain fragments by specifying
2370 source or destination addresses or protocols as parameters in
2374 In most cases, the benefits of reassembly outweigh the additional
2375 memory cost, and it's recommended to use
2378 all fragments via the
2379 .Ar fragment reassemble
2382 The memory allocated for fragment caching can be limited using
2384 Once this limit is reached, fragments that would have to be cached
2385 are dropped until other entries time out.
2386 The timeout value can also be adjusted.
2388 When forwarding reassembled IPv6 packets, pf refragments them with
2389 the original maximum fragment size.
2390 This allows the sender to determine the optimal fragment size by
2393 Besides the main ruleset,
2395 can load rulesets into
2400 is a container that can hold rules, address tables, and other anchors.
2404 has a name which specifies the path where
2406 can be used to access the anchor to perform operations on it, such as
2407 attaching child anchors to it or loading rules into it.
2408 Anchors may be nested, with components separated by
2410 characters, similar to how file system hierarchies are laid out.
2411 The main ruleset is actually the default anchor, so filter and
2412 translation rules, for example, may also be contained in any anchor.
2414 An anchor can reference another
2417 using the following kinds
2419 .Bl -tag -width xxxx
2420 .It Ar nat-anchor Aq Ar name
2423 rules in the specified
2425 .It Ar rdr-anchor Aq Ar name
2428 rules in the specified
2430 .It Ar binat-anchor Aq Ar name
2433 rules in the specified
2435 .It Ar anchor Aq Ar name
2436 Evaluates the filter rules in the specified
2438 .It Xo Ar load anchor
2442 Loads the rules from the specified file into the
2447 When evaluation of the main ruleset reaches an
2451 will proceed to evaluate all rules specified in that anchor.
2453 Matching filter and translation rules marked with the
2455 option are final and abort the evaluation of the rules in other
2456 anchors and the main ruleset.
2459 itself is marked with the
2462 ruleset evaluation will terminate when the anchor is exited if the packet is
2463 matched by any rule within the anchor.
2466 rules are evaluated relative to the anchor in which they are contained.
2469 rules specified in the main ruleset will reference anchor
2470 attachment points underneath the main ruleset, and
2472 rules specified in a file loaded from a
2474 rule will be attached under that anchor point.
2476 Rules may be contained in
2478 attachment points which do not contain any rules when the main ruleset
2479 is loaded, and later such anchors can be manipulated through
2481 without reloading the main ruleset or other anchors.
2483 .Bd -literal -offset indent
2485 block on $ext_if all
2487 pass out on $ext_if all
2488 pass in on $ext_if proto tcp from any \e
2489 to $ext_if port smtp
2492 blocks all packets on the external interface by default, then evaluates
2495 named "spam", and finally passes all outgoing connections and
2496 incoming connections to port 25.
2497 .Bd -literal -offset indent
2498 # echo \&"block in quick from 1.2.3.4 to any\&" \&| \e
2502 This loads a single rule into the
2504 which blocks all packets from a specific address.
2506 The anchor can also be populated by adding a
2511 .Bd -literal -offset indent
2513 load anchor spam from "/etc/pf-spam.conf"
2520 it will also load all the rules from the file
2521 .Pa /etc/pf-spam.conf
2526 rules can specify packet filtering parameters using the same syntax as
2528 When parameters are used, the
2530 rule is only evaluated for matching packets.
2531 This allows conditional evaluation of anchors, like:
2532 .Bd -literal -offset indent
2533 block on $ext_if all
2534 anchor spam proto tcp from any to any port smtp
2535 pass out on $ext_if all
2536 pass in on $ext_if proto tcp from any to $ext_if port smtp
2541 spam are only evaluated for
2543 packets with destination port 25.
2545 .Bd -literal -offset indent
2546 # echo \&"block in quick from 1.2.3.4 to any" \&| \e
2550 will only block connections from 1.2.3.4 to port 25.
2552 Anchors may end with the asterisk
2554 character, which signifies that all anchors attached at that point
2555 should be evaluated in the alphabetical ordering of their anchor name.
2557 .Bd -literal -offset indent
2561 will evaluate each rule in each anchor attached to the
2564 Note that it will only evaluate anchors that are directly attached to the
2566 anchor, and will not descend to evaluate anchors recursively.
2568 Since anchors are evaluated relative to the anchor in which they are
2569 contained, there is a mechanism for accessing the parent and ancestor
2570 anchors of a given anchor.
2571 Similar to file system path name resolution, if the sequence
2573 appears as an anchor path component, the parent anchor of the current
2574 anchor in the path evaluation at that point will become the new current
2576 As an example, consider the following:
2577 .Bd -literal -offset indent
2578 # echo ' anchor "spam/allowed" ' | pfctl -f -
2579 # echo -e ' anchor "../banned" \en pass' | \e
2580 pfctl -a spam/allowed -f -
2583 Evaluation of the main ruleset will lead into the
2585 anchor, which will evaluate the rules in the
2587 anchor, if any, before finally evaluating the
2593 can also be loaded inline in the ruleset within a brace ('{' '}') delimited
2595 Brace delimited blocks may contain rules or other brace-delimited blocks.
2596 When anchors are loaded this way the anchor name becomes optional.
2597 .Bd -literal -offset indent
2598 anchor "external" on egress {
2601 pass proto tcp from any to port { 25, 80, 443 }
2603 pass in proto tcp to any port 22
2607 Since the parser specification for anchor names is a string, any
2608 reference to an anchor name containing
2610 characters will require double quote
2612 characters around the anchor name.
2613 .Sh TRANSLATION EXAMPLES
2614 This example maps incoming requests on port 80 to port 8080, on
2615 which a daemon is running (because, for example, it is not run as root,
2616 and therefore lacks permission to bind to port 80).
2618 # use a macro for the interface name, so it can be changed easily
2621 # map daemon on 8080 to appear to be on 80
2622 rdr on $ext_if proto tcp from any to any port 80 -\*(Gt 127.0.0.1 port 8080
2627 modifier is given, packets matching the translation rule are passed without
2628 inspecting the filter rules:
2630 rdr pass on $ext_if proto tcp from any to any port 80 -\*(Gt 127.0.0.1 \e
2634 In the example below, vlan12 is configured as 192.168.168.1;
2635 the machine translates all packets coming from 192.168.168.0/24 to 204.92.77.111
2636 when they are going out any interface except vlan12.
2637 This has the net effect of making traffic from the 192.168.168.0/24
2638 network appear as though it is the Internet routable address
2639 204.92.77.111 to nodes behind any interface on the router except
2640 for the nodes on vlan12.
2641 (Thus, 192.168.168.1 can talk to the 192.168.168.0/24 nodes.)
2643 nat on ! vlan12 from 192.168.168.0/24 to any -\*(Gt 204.92.77.111
2646 In the example below, the machine sits between a fake internal 144.19.74.*
2647 network, and a routable external IP of 204.92.77.100.
2650 rule excludes protocol AH from being translated.
2653 no nat on $ext_if proto ah from 144.19.74.0/24 to any
2654 nat on $ext_if from 144.19.74.0/24 to any -\*(Gt 204.92.77.100
2657 In the example below, packets bound for one specific server, as well as those
2658 generated by the sysadmins are not proxied; all other connections are.
2661 no rdr on $int_if proto { tcp, udp } from any to $server port 80
2662 no rdr on $int_if proto { tcp, udp } from $sysadmins to any port 80
2663 rdr on $int_if proto { tcp, udp } from any to any port 80 -\*(Gt 127.0.0.1 \e
2667 This longer example uses both a NAT and a redirection.
2668 The external interface has the address 157.161.48.183.
2669 On localhost, we are running
2671 waiting for FTP sessions to be redirected to it.
2672 The three mandatory anchors for
2674 are omitted from this example; see the
2679 # Translate outgoing packets' source addresses (any protocol).
2680 # In this case, any address but the gateway's external address is mapped.
2681 nat on $ext_if inet from ! ($ext_if) to any -\*(Gt ($ext_if)
2684 # Map outgoing packets' source port to an assigned proxy port instead of
2685 # an arbitrary port.
2686 # In this case, proxy outgoing isakmp with port 500 on the gateway.
2687 nat on $ext_if inet proto udp from any port = isakmp to any -\*(Gt ($ext_if) \e
2691 # Translate outgoing packets' source address (any protocol).
2692 # Translate incoming packets' destination address to an internal machine
2694 binat on $ext_if from 10.1.2.150 to any -\*(Gt $ext_if
2697 # Translate incoming packets' destination addresses.
2698 # As an example, redirect a TCP and UDP port to an internal machine.
2699 rdr on $ext_if inet proto tcp from any to ($ext_if) port 8080 \e
2700 -\*(Gt 10.1.2.151 port 22
2701 rdr on $ext_if inet proto udp from any to ($ext_if) port 8080 \e
2702 -\*(Gt 10.1.2.151 port 53
2705 # Translate outgoing ftp control connections to send them to localhost
2706 # for proxying with ftp-proxy(8) running on port 8021.
2707 rdr on $int_if proto tcp from any to any port 21 -\*(Gt 127.0.0.1 port 8021
2710 In this example, a NAT gateway is set up to translate internal addresses
2711 using a pool of public addresses (192.0.2.16/28) and to redirect
2712 incoming web server connections to a group of web servers on the internal
2716 # Translate outgoing packets' source addresses using an address pool.
2717 # A given source address is always translated to the same pool address by
2718 # using the source-hash keyword.
2719 nat on $ext_if inet from any to any -\*(Gt 192.0.2.16/28 source-hash
2722 # Translate incoming web server connections to a group of web servers on
2723 # the internal network.
2724 rdr on $ext_if proto tcp from any to any port 80 \e
2725 -\*(Gt { 10.1.2.155, 10.1.2.160, 10.1.2.161 } round-robin
2729 # The external interface is kue0
2730 # (157.161.48.183, the only routable address)
2731 # and the private network is 10.0.0.0/8, for which we are doing NAT.
2733 # use a macro for the interface name, so it can be changed easily
2736 # normalize all incoming traffic
2737 scrub in on $ext_if all fragment reassemble
2739 # block and log everything by default
2740 block return log on $ext_if all
2742 # block anything coming from source we have no back routes for
2743 block in from no-route to any
2745 # block packets whose ingress interface does not match the one in
2746 # the route back to their source address
2747 block in from urpf-failed to any
2749 # block and log outgoing packets that do not have our address as source,
2750 # they are either spoofed or something is misconfigured (NAT disabled,
2751 # for instance), we want to be nice and do not send out garbage.
2752 block out log quick on $ext_if from ! 157.161.48.183 to any
2754 # silently drop broadcasts (cable modem noise)
2755 block in quick on $ext_if from any to 255.255.255.255
2757 # block and log incoming packets from reserved address space and invalid
2758 # addresses, they are either spoofed or misconfigured, we cannot reply to
2759 # them anyway (hence, no return-rst).
2760 block in log quick on $ext_if from { 10.0.0.0/8, 172.16.0.0/12, \e
2761 192.168.0.0/16, 255.255.255.255/32 } to any
2765 # pass out/in certain ICMP queries and keep state (ping)
2766 # state matching is done on host addresses and ICMP id (not type/code),
2767 # so replies (like 0/0 for 8/0) will match queries
2768 # ICMP error messages (which always refer to a TCP/UDP packet) are
2769 # handled by the TCP/UDP states
2770 pass on $ext_if inet proto icmp all icmp-type 8 code 0
2774 # pass out all UDP connections and keep state
2775 pass out on $ext_if proto udp all
2777 # pass in certain UDP connections and keep state (DNS)
2778 pass in on $ext_if proto udp from any to any port domain
2782 # pass out all TCP connections and modulate state
2783 pass out on $ext_if proto tcp all modulate state
2785 # pass in certain TCP connections and keep state (SSH, SMTP, DNS, IDENT)
2786 pass in on $ext_if proto tcp from any to any port { ssh, smtp, domain, \e
2789 # Do not allow Windows 9x SMTP connections since they are typically
2790 # a viral worm. Alternately we could limit these OSes to 1 connection each.
2791 block in on $ext_if proto tcp from any os {"Windows 95", "Windows 98"} \e
2795 # pass in/out all IPv6 traffic: note that we have to enable this in two
2796 # different ways, on both our physical interface and our tunnel
2797 pass quick on gif0 inet6
2798 pass quick on $ext_if proto ipv6
2802 # three interfaces: $int_if, $ext_if, and $wifi_if (wireless). NAT is
2803 # being done on $ext_if for all outgoing packets. tag packets in on
2804 # $int_if and pass those tagged packets out on $ext_if. all other
2805 # outgoing packets (i.e., packets from the wireless network) are only
2806 # permitted to access port 80.
2808 pass in on $int_if from any to any tag INTNET
2809 pass in on $wifi_if from any to any
2811 block out on $ext_if from any to any
2812 pass out quick on $ext_if tagged INTNET
2813 pass out on $ext_if proto tcp from any to any port 80
2815 # tag incoming packets as they are redirected to spamd(8). use the tag
2816 # to pass those packets through the packet filter.
2818 rdr on $ext_if inet proto tcp from \*(Ltspammers\*(Gt to port smtp \e
2819 tag SPAMD -\*(Gt 127.0.0.1 port spamd
2822 pass in on $ext_if inet proto tcp tagged SPAMD
2829 line = ( option | pf-rule | nat-rule | binat-rule | rdr-rule |
2830 antispoof-rule | altq-rule | queue-rule | trans-anchors |
2831 anchor-rule | anchor-close | load-anchor | table-rule |
2834 option = "set" ( [ "timeout" ( timeout | "{" timeout-list "}" ) ] |
2835 [ "ruleset-optimization" [ "none" | "basic" | "profile" ]] |
2836 [ "optimization" [ "default" | "normal" |
2837 "high-latency" | "satellite" |
2838 "aggressive" | "conservative" ] ]
2839 [ "limit" ( limit-item | "{" limit-list "}" ) ] |
2840 [ "loginterface" ( interface-name | "none" ) ] |
2841 [ "block-policy" ( "drop" | "return" ) ] |
2842 [ "state-policy" ( "if-bound" | "floating" ) ]
2843 [ "state-defaults" state-opts ]
2844 [ "require-order" ( "yes" | "no" ) ]
2845 [ "fingerprints" filename ] |
2846 [ "skip on" ifspec ] |
2847 [ "debug" ( "none" | "urgent" | "misc" | "loud" ) ] )
2849 pf-rule = action [ ( "in" | "out" ) ]
2850 [ "log" [ "(" logopts ")"] ] [ "quick" ]
2851 [ "on" ifspec ] [ route ] [ af ] [ protospec ]
2852 hosts [ filteropt-list ]
2854 logopts = logopt [ "," logopts ]
2855 logopt = "all" | "user" | "to" interface-name
2857 filteropt-list = filteropt-list filteropt | filteropt
2858 filteropt = user | group | flags | icmp-type | icmp6-type | "tos" tos |
2859 ( "no" | "keep" | "modulate" | "synproxy" ) "state"
2860 [ "(" state-opts ")" ] |
2861 "fragment" | "no-df" | "min-ttl" number | "set-tos" tos |
2862 "max-mss" number | "random-id" | "reassemble tcp" |
2863 fragmentation | "allow-opts" |
2864 "label" string | "tag" string | [ ! ] "tagged" string |
2865 "set prio" ( number | "(" number [ [ "," ] number ] ")" ) |
2866 "queue" ( string | "(" string [ [ "," ] string ] ")" ) |
2867 "rtable" number | "probability" number"%" | "prio" number
2869 nat-rule = [ "no" ] "nat" [ "pass" [ "log" [ "(" logopts ")" ] ] ]
2870 [ "on" ifspec ] [ af ]
2871 [ protospec ] hosts [ "tag" string ] [ "tagged" string ]
2872 [ "-\*(Gt" ( redirhost | "{" redirhost-list "}" )
2873 [ portspec ] [ pooltype ] [ "static-port" ] ]
2875 binat-rule = [ "no" ] "binat" [ "pass" [ "log" [ "(" logopts ")" ] ] ]
2876 [ "on" interface-name ] [ af ]
2877 [ "proto" ( proto-name | proto-number ) ]
2878 "from" address [ "/" mask-bits ] "to" ipspec
2879 [ "tag" string ] [ "tagged" string ]
2880 [ "-\*(Gt" address [ "/" mask-bits ] ]
2882 rdr-rule = [ "no" ] "rdr" [ "pass" [ "log" [ "(" logopts ")" ] ] ]
2883 [ "on" ifspec ] [ af ]
2884 [ protospec ] hosts [ "tag" string ] [ "tagged" string ]
2885 [ "-\*(Gt" ( redirhost | "{" redirhost-list "}" )
2886 [ portspec ] [ pooltype ] ]
2888 antispoof-rule = "antispoof" [ "log" ] [ "quick" ]
2889 "for" ifspec [ af ] [ "label" string ]
2891 table-rule = "table" "\*(Lt" string "\*(Gt" [ tableopts-list ]
2892 tableopts-list = tableopts-list tableopts | tableopts
2893 tableopts = "persist" | "const" | "counters" | "file" string |
2894 "{" [ tableaddr-list ] "}"
2895 tableaddr-list = tableaddr-list [ "," ] tableaddr-spec | tableaddr-spec
2896 tableaddr-spec = [ "!" ] tableaddr [ "/" mask-bits ]
2897 tableaddr = hostname | ifspec | "self" |
2898 ipv4-dotted-quad | ipv6-coloned-hex
2900 altq-rule = "altq on" interface-name queueopts-list
2902 queue-rule = "queue" string [ "on" interface-name ] queueopts-list
2905 anchor-rule = "anchor" [ string ] [ ( "in" | "out" ) ] [ "on" ifspec ]
2906 [ af ] [ protospec ] [ hosts ] [ filteropt-list ] [ "{" ]
2910 trans-anchors = ( "nat-anchor" | "rdr-anchor" | "binat-anchor" ) string
2911 [ "on" ifspec ] [ af ] [ "proto" ] [ protospec ] [ hosts ]
2913 load-anchor = "load anchor" string "from" filename
2915 queueopts-list = queueopts-list queueopts | queueopts
2916 queueopts = [ "bandwidth" bandwidth-spec ] |
2917 [ "qlimit" number ] | [ "tbrsize" number ] |
2918 [ "priority" number ] | [ schedulers ]
2919 schedulers = ( cbq-def | priq-def | hfsc-def )
2920 bandwidth-spec = "number" ( "b" | "Kb" | "Mb" | "Gb" | "%" )
2922 action = "pass" | "block" [ return ] | [ "no" ] "scrub"
2923 return = "drop" | "return" | "return-rst" [ "( ttl" number ")" ] |
2924 "return-icmp" [ "(" icmpcode [ [ "," ] icmp6code ] ")" ] |
2925 "return-icmp6" [ "(" icmp6code ")" ]
2926 icmpcode = ( icmp-code-name | icmp-code-number )
2927 icmp6code = ( icmp6-code-name | icmp6-code-number )
2929 ifspec = ( [ "!" ] ( interface-name | interface-group ) ) |
2930 "{" interface-list "}"
2931 interface-list = [ "!" ] ( interface-name | interface-group )
2932 [ [ "," ] interface-list ]
2933 route = ( "route-to" | "reply-to" | "dup-to" )
2934 ( routehost | "{" routehost-list "}" )
2936 af = "inet" | "inet6"
2938 protospec = "proto" ( proto-name | proto-number |
2939 "{" proto-list "}" )
2940 proto-list = ( proto-name | proto-number ) [ [ "," ] proto-list ]
2943 "from" ( "any" | "no-route" | "urpf-failed" | "self" | host |
2944 "{" host-list "}" ) [ port ] [ os ]
2945 "to" ( "any" | "no-route" | "self" | host |
2946 "{" host-list "}" ) [ port ]
2948 ipspec = "any" | host | "{" host-list "}"
2949 host = [ "!" ] ( address [ "/" mask-bits ] | "\*(Lt" string "\*(Gt" )
2950 redirhost = address [ "/" mask-bits ]
2951 routehost = "(" interface-name [ address [ "/" mask-bits ] ] ")"
2952 address = ( interface-name | interface-group |
2953 "(" ( interface-name | interface-group ) ")" |
2954 hostname | ipv4-dotted-quad | ipv6-coloned-hex )
2955 host-list = host [ [ "," ] host-list ]
2956 redirhost-list = redirhost [ [ "," ] redirhost-list ]
2957 routehost-list = routehost [ [ "," ] routehost-list ]
2959 port = "port" ( unary-op | binary-op | "{" op-list "}" )
2960 portspec = "port" ( number | name ) [ ":" ( "*" | number | name ) ]
2961 os = "os" ( os-name | "{" os-list "}" )
2962 user = "user" ( unary-op | binary-op | "{" op-list "}" )
2963 group = "group" ( unary-op | binary-op | "{" op-list "}" )
2965 unary-op = [ "=" | "!=" | "\*(Lt" | "\*(Le" | "\*(Gt" | "\*(Ge" ]
2967 binary-op = number ( "\*(Lt\*(Gt" | "\*(Gt\*(Lt" | ":" ) number
2968 op-list = ( unary-op | binary-op ) [ [ "," ] op-list ]
2970 os-name = operating-system-name
2971 os-list = os-name [ [ "," ] os-list ]
2973 flags = "flags" ( [ flag-set ] "/" flag-set | "any" )
2974 flag-set = [ "F" ] [ "S" ] [ "R" ] [ "P" ] [ "A" ] [ "U" ] [ "E" ]
2977 icmp-type = "icmp-type" ( icmp-type-code | "{" icmp-list "}" )
2978 icmp6-type = "icmp6-type" ( icmp-type-code | "{" icmp-list "}" )
2979 icmp-type-code = ( icmp-type-name | icmp-type-number )
2980 [ "code" ( icmp-code-name | icmp-code-number ) ]
2981 icmp-list = icmp-type-code [ [ "," ] icmp-list ]
2983 tos = ( "lowdelay" | "throughput" | "reliability" |
2986 state-opts = state-opt [ [ "," ] state-opts ]
2987 state-opt = ( "max" number | "no-sync" | timeout | "sloppy" | "pflow" |
2988 "source-track" [ ( "rule" | "global" ) ] |
2989 "max-src-nodes" number | "max-src-states" number |
2990 "max-src-conn" number |
2991 "max-src-conn-rate" number "/" number |
2992 "overload" "\*(Lt" string "\*(Gt" [ "flush" ] |
2993 "if-bound" | "floating" )
2995 fragmentation = [ "fragment reassemble" ]
2997 timeout-list = timeout [ [ "," ] timeout-list ]
2998 timeout = ( "tcp.first" | "tcp.opening" | "tcp.established" |
2999 "tcp.closing" | "tcp.finwait" | "tcp.closed" |
3000 "udp.first" | "udp.single" | "udp.multiple" |
3001 "icmp.first" | "icmp.error" |
3002 "other.first" | "other.single" | "other.multiple" |
3003 "frag" | "interval" | "src.track" |
3004 "adaptive.start" | "adaptive.end" ) number
3006 limit-list = limit-item [ [ "," ] limit-list ]
3007 limit-item = ( "states" | "frags" | "src-nodes" ) number
3009 pooltype = ( "bitmask" | "random" |
3010 "source-hash" [ ( hex-key | string-key ) ] |
3011 "round-robin" ) [ sticky-address ]
3013 subqueue = string | "{" queue-list "}"
3014 queue-list = string [ [ "," ] string ]
3015 cbq-def = "cbq" [ "(" cbq-opt [ [ "," ] cbq-opt ] ")" ]
3016 priq-def = "priq" [ "(" priq-opt [ [ "," ] priq-opt ] ")" ]
3017 hfsc-def = "hfsc" [ "(" hfsc-opt [ [ "," ] hfsc-opt ] ")" ]
3018 cbq-opt = ( "default" | "borrow" | "red" | "ecn" | "rio" )
3019 priq-opt = ( "default" | "red" | "ecn" | "rio" )
3020 hfsc-opt = ( "default" | "red" | "ecn" | "rio" |
3021 linkshare-sc | realtime-sc | upperlimit-sc )
3022 linkshare-sc = "linkshare" sc-spec
3023 realtime-sc = "realtime" sc-spec
3024 upperlimit-sc = "upperlimit" sc-spec
3025 sc-spec = ( bandwidth-spec |
3026 "(" bandwidth-spec number bandwidth-spec ")" )
3027 include = "include" filename
3030 .Bl -tag -width "/etc/protocols" -compact
3034 Default location of the ruleset file.
3036 Default location of OS fingerprints.
3037 .It Pa /etc/protocols
3038 Protocol name database.
3039 .It Pa /etc/services
3040 Service name database.
3064 file format first appeared in