]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sbin/ipfw/ipfw.8
Stop building bsdlabel(8) and fdisk(8) on ia64. Both tools are
[FreeBSD/FreeBSD.git] / sbin / ipfw / ipfw.8
1 .\"
2 .\" $FreeBSD$
3 .\"
4 .Dd November 26, 2007
5 .Dt IPFW 8
6 .Os
7 .Sh NAME
8 .Nm ipfw
9 .Nd IP firewall and traffic shaper control program
10 .Sh SYNOPSIS
11 .Nm
12 .Op Fl cq
13 .Cm add
14 .Ar rule
15 .Nm
16 .Op Fl acdefnNStT
17 .Op Cm set Ar N
18 .Brq Cm list | show
19 .Op Ar rule | first-last ...
20 .Nm
21 .Op Fl f | q
22 .Op Cm set Ar N
23 .Cm flush
24 .Nm
25 .Op Fl q
26 .Op Cm set Ar N
27 .Brq Cm delete | zero | resetlog
28 .Op Ar number ...
29 .Nm
30 .Cm enable
31 .Brq Cm firewall | altq | one_pass | debug | verbose | dyn_keepalive
32 .Nm
33 .Cm disable
34 .Brq Cm firewall | altq | one_pass | debug | verbose | dyn_keepalive
35 .Pp
36 .Nm
37 .Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
38 .Nm
39 .Cm set move
40 .Op Cm rule
41 .Ar number Cm to Ar number
42 .Nm
43 .Cm set swap Ar number number
44 .Nm
45 .Cm set show
46 .Pp
47 .Nm
48 .Cm table Ar number Cm add Ar addr Ns Oo / Ns Ar masklen Oc Op Ar value
49 .Nm
50 .Cm table Ar number Cm delete Ar addr Ns Op / Ns Ar masklen
51 .Nm
52 .Cm table Ar number Cm flush
53 .Nm
54 .Cm table Ar number Cm list
55 .Pp
56 .Nm
57 .Brq Cm pipe | queue
58 .Ar number
59 .Cm config
60 .Ar config-options
61 .Nm
62 .Op Fl s Op Ar field
63 .Brq Cm pipe | queue
64 .Brq Cm delete | list | show
65 .Op Ar number ...
66 .Pp
67 .Nm
68 .Cm nat
69 .Ar number
70 .Cm config
71 .Ar config-options
72 .Pp
73 .Nm
74 .Op Fl cfnNqS
75 .Oo
76 .Fl p Ar preproc
77 .Oo
78 .Ar preproc-flags
79 .Oc
80 .Oc
81 .Ar pathname
82 .Sh DESCRIPTION
83 The
84 .Nm
85 utility is the user interface for controlling the
86 .Xr ipfw 4
87 firewall and the
88 .Xr dummynet 4
89 traffic shaper in
90 .Fx .
91 .Pp
92 An
93 .Nm
94 configuration, or
95 .Em ruleset ,
96 is made of a list of
97 .Em rules
98 numbered from 1 to 65535.
99 Packets are passed to
100 .Nm
101 from a number of different places in the protocol stack
102 (depending on the source and destination of the packet,
103 it is possible that
104 .Nm
105 is invoked multiple times on the same packet).
106 The packet passed to the firewall is compared
107 against each of the rules in the firewall
108 .Em ruleset .
109 When a match is found, the action corresponding to the
110 matching rule is performed.
111 .Pp
112 Depending on the action and certain system settings, packets
113 can be reinjected into the firewall at some rule after the
114 matching one for further processing.
115 .Pp
116 An
117 .Nm
118 ruleset always includes a
119 .Em default
120 rule (numbered 65535) which cannot be modified or deleted,
121 and matches all packets.
122 The action associated with the
123 .Em default
124 rule can be either
125 .Cm deny
126 or
127 .Cm allow
128 depending on how the kernel is configured.
129 .Pp
130 If the ruleset includes one or more rules with the
131 .Cm keep-state
132 or
133 .Cm limit
134 option, then
135 .Nm
136 assumes a
137 .Em stateful
138 behaviour, i.e., upon a match it will create dynamic rules matching
139 the exact parameters (addresses and ports) of the matching packet.
140 .Pp
141 These dynamic rules, which have a limited lifetime, are checked
142 at the first occurrence of a
143 .Cm check-state ,
144 .Cm keep-state
145 or
146 .Cm limit
147 rule, and are typically used to open the firewall on-demand to
148 legitimate traffic only.
149 See the
150 .Sx STATEFUL FIREWALL
151 and
152 .Sx EXAMPLES
153 Sections below for more information on the stateful behaviour of
154 .Nm .
155 .Pp
156 All rules (including dynamic ones) have a few associated counters:
157 a packet count, a byte count, a log count and a timestamp
158 indicating the time of the last match.
159 Counters can be displayed or reset with
160 .Nm
161 commands.
162 .Pp
163 Rules can be added with the
164 .Cm add
165 command; deleted individually or in groups with the
166 .Cm delete
167 command, and globally (except those in set 31) with the
168 .Cm flush
169 command; displayed, optionally with the content of the
170 counters, using the
171 .Cm show
172 and
173 .Cm list
174 commands.
175 Finally, counters can be reset with the
176 .Cm zero
177 and
178 .Cm resetlog
179 commands.
180 .Pp
181 Also, each rule belongs to one of 32 different
182 .Em sets
183 , and there are
184 .Nm
185 commands to atomically manipulate sets, such as enable,
186 disable, swap sets, move all rules in a set to another
187 one, delete all rules in a set.
188 These can be useful to
189 install temporary configurations, or to test them.
190 See Section
191 .Sx SETS OF RULES
192 for more information on
193 .Em sets .
194 .Pp
195 The following options are available:
196 .Bl -tag -width indent
197 .It Fl a
198 While listing, show counter values.
199 The
200 .Cm show
201 command just implies this option.
202 .It Fl b
203 Only show the action and the comment, not the body of a rule.
204 Implies
205 .Fl c .
206 .It Fl c
207 When entering or showing rules, print them in compact form,
208 i.e., without the optional "ip from any to any" string
209 when this does not carry any additional information.
210 .It Fl d
211 While listing, show dynamic rules in addition to static ones.
212 .It Fl e
213 While listing, if the
214 .Fl d
215 option was specified, also show expired dynamic rules.
216 .It Fl f
217 Do not ask for confirmation for commands that can cause problems
218 if misused,
219 .No i.e. Cm flush .
220 If there is no tty associated with the process, this is implied.
221 .It Fl i
222 While listing a table (see the
223 .Sx LOOKUP TABLES
224 section below for more information on lookup tables), format values
225 as IP addresses. By default, values are shown as integers.
226 .It Fl n
227 Only check syntax of the command strings, without actually passing
228 them to the kernel.
229 .It Fl N
230 Try to resolve addresses and service names in output.
231 .It Fl q
232 While
233 .Cm add Ns ing ,
234 .Cm zero Ns ing ,
235 .Cm resetlog Ns ging
236 or
237 .Cm flush Ns ing ,
238 be quiet about actions
239 (implies
240 .Fl f ) .
241 This is useful for adjusting rules by executing multiple
242 .Nm
243 commands in a script
244 (e.g.,
245 .Ql sh\ /etc/rc.firewall ) ,
246 or by processing a file of many
247 .Nm
248 rules across a remote login session.
249 It also stops a table add or delete
250 from failing if the entry already exists or is not present.
251 If a
252 .Cm flush
253 is performed in normal (verbose) mode (with the default kernel
254 configuration), it prints a message.
255 Because all rules are flushed, the message might not be delivered
256 to the login session, causing the remote login session to be closed
257 and the remainder of the ruleset to not be processed.
258 Access to the console would then be required to recover.
259 .It Fl S
260 While listing rules, show the
261 .Em set
262 each rule belongs to.
263 If this flag is not specified, disabled rules will not be
264 listed.
265 .It Fl s Op Ar field
266 While listing pipes, sort according to one of the four
267 counters (total or current packets or bytes).
268 .It Fl t
269 While listing, show last match timestamp (converted with ctime()).
270 .It Fl T
271 While listing, show last match timestamp (as seconds from the epoch).
272 This form can be more convenient for postprocessing by scripts.
273 .El
274 .Pp
275 To ease configuration, rules can be put into a file which is
276 processed using
277 .Nm
278 as shown in the last synopsis line.
279 An absolute
280 .Ar pathname
281 must be used.
282 The file will be read line by line and applied as arguments to the
283 .Nm
284 utility.
285 .Pp
286 Optionally, a preprocessor can be specified using
287 .Fl p Ar preproc
288 where
289 .Ar pathname
290 is to be piped through.
291 Useful preprocessors include
292 .Xr cpp 1
293 and
294 .Xr m4 1 .
295 If
296 .Ar preproc
297 does not start with a slash
298 .Pq Ql /
299 as its first character, the usual
300 .Ev PATH
301 name search is performed.
302 Care should be taken with this in environments where not all
303 file systems are mounted (yet) by the time
304 .Nm
305 is being run (e.g.\& when they are mounted over NFS).
306 Once
307 .Fl p
308 has been specified, any additional arguments as passed on to the preprocessor
309 for interpretation.
310 This allows for flexible configuration files (like conditionalizing
311 them on the local hostname) and the use of macros to centralize
312 frequently required arguments like IP addresses.
313 .Pp
314 The
315 .Nm
316 .Cm pipe
317 and
318 .Cm queue
319 commands are used to configure the traffic shaper, as shown in the
320 .Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
321 Section below.
322 .Pp
323 If the world and the kernel get out of sync the
324 .Nm
325 ABI may break, preventing you from being able to add any rules.
326 This can
327 adversely effect the booting process.
328 You can use
329 .Nm
330 .Cm disable
331 .Cm firewall
332 to temporarily disable the firewall to regain access to the network,
333 allowing you to fix the problem.
334 .Sh PACKET FLOW
335 A packet is checked against the active ruleset in multiple places
336 in the protocol stack, under control of several sysctl variables.
337 These places and variables are shown below, and it is important to
338 have this picture in mind in order to design a correct ruleset.
339 .Bd -literal -offset indent
340        ^    to upper layers    V
341        |                       |
342        +----------->-----------+
343        ^                       V
344  [ip(6)_input]           [ip(6)_output]     net.inet(6).ip(6).fw.enable=1
345        |                       |
346        ^                       V
347  [ether_demux]        [ether_output_frame]  net.link.ether.ipfw=1
348        |                       |
349        +-->--[bdg_forward]-->--+            net.link.bridge.ipfw=1
350        ^                       V
351        |      to devices       |
352 .Ed
353 .Pp
354 As can be noted from the above picture, the number of
355 times the same packet goes through the firewall can
356 vary between 0 and 4 depending on packet source and
357 destination, and system configuration.
358 .Pp
359 Note that as packets flow through the stack, headers can be
360 stripped or added to it, and so they may or may not be available
361 for inspection.
362 E.g., incoming packets will include the MAC header when
363 .Nm
364 is invoked from
365 .Cm ether_demux() ,
366 but the same packets will have the MAC header stripped off when
367 .Nm
368 is invoked from
369 .Cm ip_input()
370 or
371 .Cm ip6_input() .
372 .Pp
373 Also note that each packet is always checked against the complete ruleset,
374 irrespective of the place where the check occurs, or the source of the packet.
375 If a rule contains some match patterns or actions which are not valid
376 for the place of invocation (e.g.\& trying to match a MAC header within
377 .Cm ip_input
378 or
379 .Cm ip6_input ),
380 the match pattern will not match, but a
381 .Cm not
382 operator in front of such patterns
383 .Em will
384 cause the pattern to
385 .Em always
386 match on those packets.
387 It is thus the responsibility of
388 the programmer, if necessary, to write a suitable ruleset to
389 differentiate among the possible places.
390 .Cm skipto
391 rules can be useful here, as an example:
392 .Bd -literal -offset indent
393 # packets from ether_demux or bdg_forward
394 ipfw add 10 skipto 1000 all from any to any layer2 in
395 # packets from ip_input
396 ipfw add 10 skipto 2000 all from any to any not layer2 in
397 # packets from ip_output
398 ipfw add 10 skipto 3000 all from any to any not layer2 out
399 # packets from ether_output_frame
400 ipfw add 10 skipto 4000 all from any to any layer2 out
401 .Ed
402 .Pp
403 (yes, at the moment there is no way to differentiate between
404 ether_demux and bdg_forward).
405 .Sh SYNTAX
406 In general, each keyword or argument must be provided as
407 a separate command line argument, with no leading or trailing
408 spaces.
409 Keywords are case-sensitive, whereas arguments may
410 or may not be case-sensitive depending on their nature
411 (e.g.\& uid's are, hostnames are not).
412 .Pp
413 In
414 .Nm ipfw2
415 you can introduce spaces after commas ',' to make
416 the line more readable.
417 You can also put the entire
418 command (including flags) into a single argument.
419 E.g., the following forms are equivalent:
420 .Bd -literal -offset indent
421 ipfw -q add deny src-ip 10.0.0.0/24,127.0.0.1/8
422 ipfw -q add deny src-ip 10.0.0.0/24, 127.0.0.1/8
423 ipfw "-q add deny src-ip 10.0.0.0/24, 127.0.0.1/8"
424 .Ed
425 .Sh RULE FORMAT
426 The format of
427 .Nm
428 rules is the following:
429 .Bd -ragged -offset indent
430 .Bk -words
431 .Op Ar rule_number
432 .Op Cm set Ar set_number
433 .Op Cm prob Ar match_probability
434 .Ar action
435 .Op Cm log Op Cm logamount Ar number
436 .Op Cm altq Ar queue
437 .Oo
438 .Bro Cm tag | untag
439 .Brc Ar number
440 .Oc
441 .Ar body
442 .Ek
443 .Ed
444 .Pp
445 where the body of the rule specifies which information is used
446 for filtering packets, among the following:
447 .Pp
448 .Bl -tag -width "Source and dest. addresses and ports" -offset XXX -compact
449 .It Layer-2 header fields
450 When available
451 .It IPv4 and IPv6 Protocol
452 TCP, UDP, ICMP, etc.
453 .It Source and dest. addresses and ports
454 .It Direction
455 See Section
456 .Sx PACKET FLOW
457 .It Transmit and receive interface
458 By name or address
459 .It Misc. IP header fields
460 Version, type of service, datagram length, identification,
461 fragment flag (non-zero IP offset),
462 Time To Live
463 .It IP options
464 .It IPv6 Extension headers
465 Fragmentation, Hop-by-Hop options,
466 Routing Headers, Source routing rthdr0, Mobile IPv6 rthdr2, IPSec options.
467 .It IPv6 Flow-ID
468 .It Misc. TCP header fields
469 TCP flags (SYN, FIN, ACK, RST, etc.),
470 sequence number, acknowledgment number,
471 window
472 .It TCP options
473 .It ICMP types
474 for ICMP packets
475 .It ICMP6 types
476 for ICMP6 packets
477 .It User/group ID
478 When the packet can be associated with a local socket.
479 .It Divert status
480 Whether a packet came from a divert socket (e.g.,
481 .Xr natd 8 ) .
482 .It Fib annotation state
483 Whether a packet has been tagged for using a specific FIB (routing table)
484 in future forwarding decisions.
485 .El
486 .Pp
487 Note that some of the above information, e.g.\& source MAC or IP addresses and
488 TCP/UDP ports, could easily be spoofed, so filtering on those fields
489 alone might not guarantee the desired results.
490 .Bl -tag -width indent
491 .It Ar rule_number
492 Each rule is associated with a
493 .Ar rule_number
494 in the range 1..65535, with the latter reserved for the
495 .Em default
496 rule.
497 Rules are checked sequentially by rule number.
498 Multiple rules can have the same number, in which case they are
499 checked (and listed) according to the order in which they have
500 been added.
501 If a rule is entered without specifying a number, the kernel will
502 assign one in such a way that the rule becomes the last one
503 before the
504 .Em default
505 rule.
506 Automatic rule numbers are assigned by incrementing the last
507 non-default rule number by the value of the sysctl variable
508 .Ar net.inet.ip.fw.autoinc_step
509 which defaults to 100.
510 If this is not possible (e.g.\& because we would go beyond the
511 maximum allowed rule number), the number of the last
512 non-default value is used instead.
513 .It Cm set Ar set_number
514 Each rule is associated with a
515 .Ar set_number
516 in the range 0..31.
517 Sets can be individually disabled and enabled, so this parameter
518 is of fundamental importance for atomic ruleset manipulation.
519 It can be also used to simplify deletion of groups of rules.
520 If a rule is entered without specifying a set number,
521 set 0 will be used.
522 .br
523 Set 31 is special in that it cannot be disabled,
524 and rules in set 31 are not deleted by the
525 .Nm ipfw flush
526 command (but you can delete them with the
527 .Nm ipfw delete set 31
528 command).
529 Set 31 is also used for the
530 .Em default
531 rule.
532 .It Cm prob Ar match_probability
533 A match is only declared with the specified probability
534 (floating point number between 0 and 1).
535 This can be useful for a number of applications such as
536 random packet drop or
537 (in conjunction with
538 .Nm dummynet )
539 to simulate the effect of multiple paths leading to out-of-order
540 packet delivery.
541 .Pp
542 Note: this condition is checked before any other condition, including
543 ones such as keep-state or check-state which might have side effects.
544 .It Cm log Op Cm logamount Ar number
545 When a packet matches a rule with the
546 .Cm log
547 keyword, a message will be
548 logged to
549 .Xr syslogd 8
550 with a
551 .Dv LOG_SECURITY
552 facility.
553 The logging only occurs if the sysctl variable
554 .Va net.inet.ip.fw.verbose
555 is set to 1
556 (which is the default when the kernel is compiled with
557 .Dv IPFIREWALL_VERBOSE )
558 and the number of packets logged so far for that
559 particular rule does not exceed the
560 .Cm logamount
561 parameter.
562 If no
563 .Cm logamount
564 is specified, the limit is taken from the sysctl variable
565 .Va net.inet.ip.fw.verbose_limit .
566 In both cases, a value of 0 removes the logging limit.
567 .Pp
568 Once the limit is reached, logging can be re-enabled by
569 clearing the logging counter or the packet counter for that entry, see the
570 .Cm resetlog
571 command.
572 .Pp
573 Note: logging is done after all other packet matching conditions
574 have been successfully verified, and before performing the final
575 action (accept, deny, etc.) on the packet.
576 .It Cm tag Ar number
577 When a packet matches a rule with the
578 .Cm tag
579 keyword, the numeric tag for the given
580 .Ar number
581 in the range 1..65534 will be attached to the packet.
582 The tag acts as an internal marker (it is not sent out over
583 the wire) that can be used to identify these packets later on.
584 This can be used, for example, to provide trust between interfaces
585 and to start doing policy-based filtering.
586 A packet can have mutiple tags at the same time.
587 Tags are "sticky", meaning once a tag is applied to a packet by a
588 matching rule it exists until explicit removal.
589 Tags are kept with the packet everywhere within the kernel, but are
590 lost when packet leaves the kernel, for example, on transmitting
591 packet out to the network or sending packet to a
592 .Xr divert 4
593 socket.
594 .Pp
595 To check for previously applied tags, use the
596 .Cm tagged
597 rule option.
598 To delete previously applied tag, use the
599 .Cm untag
600 keyword.
601 .Pp
602 Note: since tags are kept with the packet everywhere in kernelspace,
603 they can be set and unset anywhere in kernel network subsystem
604 (using
605 .Xr mbuf_tags 9
606 facility), not only by means of
607 .Xr ipfw 4
608 .Cm tag
609 and
610 .Cm untag
611 keywords.
612 For example, there can be a specialized
613 .Xr netgraph 4
614 node doing traffic analyzing and tagging for later inspecting
615 in firewall.
616 .It Cm untag Ar number
617 When a packet matches a rule with the
618 .Cm untag
619 keyword, the tag with the number
620 .Ar number
621 is searched among the tags attached to this packet and,
622 if found, removed from it.
623 Other tags bound to packet, if present, are left untouched.
624 .It Cm altq Ar queue
625 When a packet matches a rule with the
626 .Cm altq
627 keyword, the ALTQ identifier for the given
628 .Ar queue
629 (see
630 .Xr altq 4 )
631 will be attached.
632 Note that this ALTQ tag is only meaningful for packets going "out" of IPFW,
633 and not being rejected or going to divert sockets.
634 Note that if there is insufficient memory at the time the packet is
635 processed, it will not be tagged, so it is wise to make your ALTQ
636 "default" queue policy account for this.
637 If multiple
638 .Cm altq
639 rules match a single packet, only the first one adds the ALTQ classification
640 tag.
641 In doing so, traffic may be shaped by using
642 .Cm count Cm altq Ar queue
643 rules for classification early in the ruleset, then later applying
644 the filtering decision.
645 For example,
646 .Cm check-state
647 and
648 .Cm keep-state
649 rules may come later and provide the actual filtering decisions in
650 addition to the fallback ALTQ tag.
651 .Pp
652 You must run
653 .Xr pfctl 8
654 to set up the queues before IPFW will be able to look them up by name,
655 and if the ALTQ disciplines are rearranged, the rules in containing the
656 queue identifiers in the kernel will likely have gone stale and need
657 to be reloaded.
658 Stale queue identifiers will probably result in misclassification.
659 .Pp
660 All system ALTQ processing can be turned on or off via
661 .Nm
662 .Cm enable Ar altq
663 and
664 .Nm
665 .Cm disable Ar altq .
666 The usage of
667 .Va net.inet.ip.fw.one_pass
668 is irrelevant to ALTQ traffic shaping, as the actual rule action is followed
669 always after adding an ALTQ tag.
670 .El
671 .Ss RULE ACTIONS
672 A rule can be associated with one of the following actions, which
673 will be executed when the packet matches the body of the rule.
674 .Bl -tag -width indent
675 .It Cm allow | accept | pass | permit
676 Allow packets that match rule.
677 The search terminates.
678 .It Cm check-state
679 Checks the packet against the dynamic ruleset.
680 If a match is found, execute the action associated with
681 the rule which generated this dynamic rule, otherwise
682 move to the next rule.
683 .br
684 .Cm Check-state
685 rules do not have a body.
686 If no
687 .Cm check-state
688 rule is found, the dynamic ruleset is checked at the first
689 .Cm keep-state
690 or
691 .Cm limit
692 rule.
693 .It Cm count
694 Update counters for all packets that match rule.
695 The search continues with the next rule.
696 .It Cm deny | drop
697 Discard packets that match this rule.
698 The search terminates.
699 .It Cm divert Ar port
700 Divert packets that match this rule to the
701 .Xr divert 4
702 socket bound to port
703 .Ar port .
704 The search terminates.
705 .It Cm fwd | forward Ar ipaddr | tablearg Ns Op , Ns Ar port
706 Change the next-hop on matching packets to
707 .Ar ipaddr ,
708 which can be an IP address or a host name.
709 The next hop can also be supplied by the last table
710 looked up for the packet by using the
711 .Cm tablearg
712 keyword instead of an explicit address.
713 The search terminates if this rule matches.
714 .Pp
715 If
716 .Ar ipaddr
717 is a local address, then matching packets will be forwarded to
718 .Ar port
719 (or the port number in the packet if one is not specified in the rule)
720 on the local machine.
721 .br
722 If
723 .Ar ipaddr
724 is not a local address, then the port number
725 (if specified) is ignored, and the packet will be
726 forwarded to the remote address, using the route as found in
727 the local routing table for that IP.
728 .br
729 A
730 .Ar fwd
731 rule will not match layer-2 packets (those received
732 on ether_input, ether_output, or bridged).
733 .br
734 The
735 .Cm fwd
736 action does not change the contents of the packet at all.
737 In particular, the destination address remains unmodified, so
738 packets forwarded to another system will usually be rejected by that system
739 unless there is a matching rule on that system to capture them.
740 For packets forwarded locally,
741 the local address of the socket will be
742 set to the original destination address of the packet.
743 This makes the
744 .Xr netstat 1
745 entry look rather weird but is intended for
746 use with transparent proxy servers.
747 .Pp
748 To enable
749 .Cm fwd
750 a custom kernel needs to be compiled with the option
751 .Cd "options IPFIREWALL_FORWARD" .
752 .It Cm nat Ar nat_nr
753 Pass packet to a
754 nat instance
755 (for network address translation, address redirect, etc.):
756 see the
757 .Sx NETWORK ADDRESS TRANSLATION (NAT)
758 Section for further information.
759 .It Cm pipe Ar pipe_nr
760 Pass packet to a
761 .Nm dummynet
762 .Dq pipe
763 (for bandwidth limitation, delay, etc.).
764 See the
765 .Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
766 Section for further information.
767 The search terminates; however, on exit from the pipe and if
768 the
769 .Xr sysctl 8
770 variable
771 .Va net.inet.ip.fw.one_pass
772 is not set, the packet is passed again to the firewall code
773 starting from the next rule.
774 .It Cm queue Ar queue_nr
775 Pass packet to a
776 .Nm dummynet
777 .Dq queue
778 (for bandwidth limitation using WF2Q+).
779 .It Cm reject
780 (Deprecated).
781 Synonym for
782 .Cm unreach host .
783 .It Cm reset
784 Discard packets that match this rule, and if the
785 packet is a TCP packet, try to send a TCP reset (RST) notice.
786 The search terminates.
787 .It Cm reset6
788 Discard packets that match this rule, and if the
789 packet is a TCP packet, try to send a TCP reset (RST) notice.
790 The search terminates.
791 .It Cm skipto Ar number
792 Skip all subsequent rules numbered less than
793 .Ar number .
794 The search continues with the first rule numbered
795 .Ar number
796 or higher.
797 .It Cm tee Ar port
798 Send a copy of packets matching this rule to the
799 .Xr divert 4
800 socket bound to port
801 .Ar port .
802 The search continues with the next rule.
803 .It Cm unreach Ar code
804 Discard packets that match this rule, and try to send an ICMP
805 unreachable notice with code
806 .Ar code ,
807 where
808 .Ar code
809 is a number from 0 to 255, or one of these aliases:
810 .Cm net , host , protocol , port ,
811 .Cm needfrag , srcfail , net-unknown , host-unknown ,
812 .Cm isolated , net-prohib , host-prohib , tosnet ,
813 .Cm toshost , filter-prohib , host-precedence
814 or
815 .Cm precedence-cutoff .
816 The search terminates.
817 .It Cm unreach6 Ar code
818 Discard packets that match this rule, and try to send an ICMPv6
819 unreachable notice with code
820 .Ar code ,
821 where
822 .Ar code
823 is a number from 0, 1, 3 or 4, or one of these aliases:
824 .Cm no-route, admin-prohib, address
825 or
826 .Cm port .
827 The search terminates.
828 .It Cm netgraph Ar cookie
829 Divert packet into netgraph with given
830 .Ar cookie .
831 The search terminates.
832 If packet is later returned from netgraph it is either
833 accepted or continues with the next rule, depending on
834 .Va net.inet.ip.fw.one_pass
835 sysctl variable.
836 .It Cm ngtee Ar cookie
837 A copy of packet is diverted into netgraph, original
838 packet is either accepted or continues with the next rule, depending on
839 .Va net.inet.ip.fw.one_pass
840 sysctl variable.
841 See
842 .Xr ng_ipfw 4
843 for more information on
844 .Cm netgraph
845 and
846 .Cm ngtee
847 actions.
848 .It Cm setfib Ar fibnum
849 The packet is tagged so as to use the FIB (routing table)
850 .Ar fibnum
851 in any subsequent forwarding decisions. Initially this is
852 limited to the values  0 through 15. See 
853 .Xr setfib 8
854 .El
855 .Ss RULE BODY
856 The body of a rule contains zero or more patterns (such as
857 specific source and destination addresses or ports,
858 protocol options, incoming or outgoing interfaces, etc.)
859 that the packet must match in order to be recognised.
860 In general, the patterns are connected by (implicit)
861 .Cm and
862 operators -- i.e., all must match in order for the
863 rule to match.
864 Individual patterns can be prefixed by the
865 .Cm not
866 operator to reverse the result of the match, as in
867 .Pp
868 .Dl "ipfw add 100 allow ip from not 1.2.3.4 to any"
869 .Pp
870 Additionally, sets of alternative match patterns
871 .Pq Em or-blocks
872 can be constructed by putting the patterns in
873 lists enclosed between parentheses ( ) or braces { }, and
874 using the
875 .Cm or
876 operator as follows:
877 .Pp
878 .Dl "ipfw add 100 allow ip from { x or not y or z } to any"
879 .Pp
880 Only one level of parentheses is allowed.
881 Beware that most shells have special meanings for parentheses
882 or braces, so it is advisable to put a backslash \\ in front of them
883 to prevent such interpretations.
884 .Pp
885 The body of a rule must in general include a source and destination
886 address specifier.
887 The keyword
888 .Ar any
889 can be used in various places to specify that the content of
890 a required field is irrelevant.
891 .Pp
892 The rule body has the following format:
893 .Bd -ragged -offset indent
894 .Op Ar proto Cm from Ar src Cm to Ar dst
895 .Op Ar options
896 .Ed
897 .Pp
898 The first part (proto from src to dst) is for backward
899 compatibility with earlier versions of
900 .Fx .
901 In modern
902 .Fx
903 any match pattern (including MAC headers, IP protocols,
904 addresses and ports) can be specified in the
905 .Ar options
906 section.
907 .Pp
908 Rule fields have the following meaning:
909 .Bl -tag -width indent
910 .It Ar proto : protocol | Cm { Ar protocol Cm or ... }
911 .It Ar protocol : Oo Cm not Oc Ar protocol-name | protocol-number
912 An IP protocol specified by number or name
913 (for a complete list see
914 .Pa /etc/protocols ) ,
915 or one of the following keywords:
916 .Bl -tag -width indent
917 .It Cm ip4 | ipv4
918 Matches IPv4 packets.
919 .It Cm ip6 | ipv6
920 Matches IPv6 packets.
921 .It Cm ip | all
922 Matches any packet.
923 .El
924 .Pp
925 The
926 .Cm ipv6
927 in
928 .Cm proto
929 option will be treated as inner protocol.
930 And, the
931 .Cm ipv4
932 is not available in
933 .Cm proto
934 option.
935 .Pp
936 The
937 .Cm { Ar protocol Cm or ... }
938 format (an
939 .Em or-block )
940 is provided for convenience only but its use is deprecated.
941 .It Ar src No and Ar dst : Bro Cm addr | Cm { Ar addr Cm or ... } Brc Op Oo Cm not Oc Ar ports
942 An address (or a list, see below)
943 optionally followed by
944 .Ar ports
945 specifiers.
946 .Pp
947 The second format
948 .Em ( or-block
949 with multiple addresses) is provided for convenience only and
950 its use is discouraged.
951 .It Ar addr : Oo Cm not Oc Bro
952 .Cm any | me | me6 |
953 .Cm table Ns Pq Ar number Ns Op , Ns Ar value
954 .Ar | addr-list | addr-set
955 .Brc
956 .It Cm any
957 matches any IP address.
958 .It Cm me
959 matches any IP address configured on an interface in the system.
960 .It Cm me6
961 matches any IPv6 address configured on an interface in the system.
962 The address list is evaluated at the time the packet is
963 analysed.
964 .It Cm table Ns Pq Ar number Ns Op , Ns Ar value
965 Matches any IPv4 address for which an entry exists in the lookup table
966 .Ar number .
967 If an optional 32-bit unsigned
968 .Ar value
969 is also specified, an entry will match only if it has this value.
970 See the
971 .Sx LOOKUP TABLES
972 section below for more information on lookup tables.
973 .It Ar addr-list : ip-addr Ns Op Ns , Ns Ar addr-list
974 .It Ar ip-addr :
975 A host or subnet address specified in one of the following ways:
976 .Bl -tag -width indent
977 .It Ar numeric-ip | hostname
978 Matches a single IPv4 address, specified as dotted-quad or a hostname.
979 Hostnames are resolved at the time the rule is added to the firewall list.
980 .It Ar addr Ns / Ns Ar masklen
981 Matches all addresses with base
982 .Ar addr
983 (specified as an IP address, a network number, or a hostname)
984 and mask width of
985 .Cm masklen
986 bits.
987 As an example, 1.2.3.4/25 or 1.2.3.0/25 will match
988 all IP numbers from 1.2.3.0 to 1.2.3.127 .
989 .It Ar addr Ns : Ns Ar mask
990 Matches all addresses with base
991 .Ar addr
992 (specified as an IP address, a network number, or a hostname)
993 and the mask of
994 .Ar mask ,
995 specified as a dotted quad.
996 As an example, 1.2.3.4:255.0.255.0 or 1.0.3.0:255.0.255.0 will match
997 1.*.3.*.
998 This form is advised only for non-contiguous
999 masks.
1000 It is better to resort to the
1001 .Ar addr Ns / Ns Ar masklen
1002 format for contiguous masks, which is more compact and less
1003 error-prone.
1004 .El
1005 .It Ar addr-set : addr Ns Oo Ns / Ns Ar masklen Oc Ns Cm { Ns Ar list Ns Cm }
1006 .It Ar list : Bro Ar num | num-num Brc Ns Op Ns , Ns Ar list
1007 Matches all addresses with base address
1008 .Ar addr
1009 (specified as an IP address, a network number, or a hostname)
1010 and whose last byte is in the list between braces { } .
1011 Note that there must be no spaces between braces and
1012 numbers (spaces after commas are allowed).
1013 Elements of the list can be specified as single entries
1014 or ranges.
1015 The
1016 .Ar masklen
1017 field is used to limit the size of the set of addresses,
1018 and can have any value between 24 and 32.
1019 If not specified,
1020 it will be assumed as 24.
1021 .br
1022 This format is particularly useful to handle sparse address sets
1023 within a single rule.
1024 Because the matching occurs using a
1025 bitmask, it takes constant time and dramatically reduces
1026 the complexity of rulesets.
1027 .br
1028 As an example, an address specified as 1.2.3.4/24{128,35-55,89}
1029 or 1.2.3.0/24{128,35-55,89}
1030 will match the following IP addresses:
1031 .br
1032 1.2.3.128, 1.2.3.35 to 1.2.3.55, 1.2.3.89 .
1033 .It Ar addr6-list : ip6-addr Ns Op Ns , Ns Ar addr6-list
1034 .It Ar ip6-addr :
1035 A host or subnet specified one of the following ways:
1036 .Pp
1037 .Bl -tag -width indent
1038 .It Ar numeric-ip | hostname
1039 Matches a single IPv6 address as allowed by
1040 .Xr inet_pton 3
1041 or a hostname.
1042 Hostnames are resolved at the time the rule is added to the firewall
1043 list.
1044 .It Ar addr Ns / Ns Ar masklen
1045 Matches all IPv6 addresses with base
1046 .Ar addr
1047 (specified as allowed by
1048 .Xr inet_pton
1049 or a hostname)
1050 and mask width of
1051 .Cm masklen
1052 bits.
1053 .El
1054 .Pp
1055 No support for sets of IPv6 addresses is provided because IPv6 addresses
1056 are typically random past the initial prefix.
1057 .It Ar ports : Bro Ar port | port Ns \&- Ns Ar port Ns Brc Ns Op , Ns Ar ports
1058 For protocols which support port numbers (such as TCP and UDP), optional
1059 .Cm ports
1060 may be specified as one or more ports or port ranges, separated
1061 by commas but no spaces, and an optional
1062 .Cm not
1063 operator.
1064 The
1065 .Ql \&-
1066 notation specifies a range of ports (including boundaries).
1067 .Pp
1068 Service names (from
1069 .Pa /etc/services )
1070 may be used instead of numeric port values.
1071 The length of the port list is limited to 30 ports or ranges,
1072 though one can specify larger ranges by using an
1073 .Em or-block
1074 in the
1075 .Cm options
1076 section of the rule.
1077 .Pp
1078 A backslash
1079 .Pq Ql \e
1080 can be used to escape the dash
1081 .Pq Ql -
1082 character in a service name (from a shell, the backslash must be
1083 typed twice to avoid the shell itself interpreting it as an escape
1084 character).
1085 .Pp
1086 .Dl "ipfw add count tcp from any ftp\e\e-data-ftp to any"
1087 .Pp
1088 Fragmented packets which have a non-zero offset (i.e., not the first
1089 fragment) will never match a rule which has one or more port
1090 specifications.
1091 See the
1092 .Cm frag
1093 option for details on matching fragmented packets.
1094 .El
1095 .Ss RULE OPTIONS (MATCH PATTERNS)
1096 Additional match patterns can be used within
1097 rules.
1098 Zero or more of these so-called
1099 .Em options
1100 can be present in a rule, optionally prefixed by the
1101 .Cm not
1102 operand, and possibly grouped into
1103 .Em or-blocks .
1104 .Pp
1105 The following match patterns can be used (listed in alphabetical order):
1106 .Bl -tag -width indent
1107 .It Cm // this is a comment.
1108 Inserts the specified text as a comment in the rule.
1109 Everything following // is considered as a comment and stored in the rule.
1110 You can have comment-only rules, which are listed as having a
1111 .Cm count
1112 action followed by the comment.
1113 .It Cm bridged
1114 Alias for
1115 .Cm layer2 .
1116 .It Cm diverted
1117 Matches only packets generated by a divert socket.
1118 .It Cm diverted-loopback
1119 Matches only packets coming from a divert socket back into the IP stack
1120 input for delivery.
1121 .It Cm diverted-output
1122 Matches only packets going from a divert socket back outward to the IP
1123 stack output for delivery.
1124 .It Cm dst-ip Ar ip-address
1125 Matches IPv4 packets whose destination IP is one of the address(es)
1126 specified as argument.
1127 .It Bro Cm dst-ip6 | dst-ipv6 Brc Ar ip6-address
1128 Matches IPv6 packets whose destination IP is one of the address(es)
1129 specified as argument.
1130 .It Cm dst-port Ar ports
1131 Matches IP packets whose destination port is one of the port(s)
1132 specified as argument.
1133 .It Cm established
1134 Matches TCP packets that have the RST or ACK bits set.
1135 .It Cm ext6hdr Ar header
1136 Matches IPv6 packets containing the extended header given by
1137 .Ar header .
1138 Supported headers are:
1139 .Pp
1140 Fragment,
1141 .Pq Cm frag ,
1142 Hop-to-hop options
1143 .Pq Cm hopopt ,
1144 any type of Routing Header
1145 .Pq Cm route ,
1146 Source routing Routing Header Type 0
1147 .Pq Cm rthdr0 ,
1148 Mobile IPv6 Routing Header Type 2
1149 .Pq Cm rthdr2 ,
1150 Destination options
1151 .Pq Cm dstopt ,
1152 IPSec authentication headers
1153 .Pq Cm ah ,
1154 and IPSec encapsulated security payload headers
1155 .Pq Cm esp .
1156 .It Cm fib Ar fibnum
1157 Matches a packet that has been tagged to use
1158 the given FIB (routing table) number.
1159 .It Cm flow-id Ar labels
1160 Matches IPv6 packets containing any of the flow labels given in
1161 .Ar labels .
1162 .Ar labels
1163 is a comma seperate list of numeric flow labels.
1164 .It Cm frag
1165 Matches packets that are fragments and not the first
1166 fragment of an IP datagram.
1167 Note that these packets will not have
1168 the next protocol header (e.g.\& TCP, UDP) so options that look into
1169 these headers cannot match.
1170 .It Cm gid Ar group
1171 Matches all TCP or UDP packets sent by or received for a
1172 .Ar group .
1173 A
1174 .Ar group
1175 may be specified by name or number.
1176 .It Cm jail Ar prisonID
1177 Matches all TCP or UDP packets sent by or received for the
1178 jail whos prison ID is
1179 .Ar prisonID .
1180 .It Cm icmptypes Ar types
1181 Matches ICMP packets whose ICMP type is in the list
1182 .Ar types .
1183 The list may be specified as any combination of
1184 individual types (numeric) separated by commas.
1185 .Em Ranges are not allowed .
1186 The supported ICMP types are:
1187 .Pp
1188 echo reply
1189 .Pq Cm 0 ,
1190 destination unreachable
1191 .Pq Cm 3 ,
1192 source quench
1193 .Pq Cm 4 ,
1194 redirect
1195 .Pq Cm 5 ,
1196 echo request
1197 .Pq Cm 8 ,
1198 router advertisement
1199 .Pq Cm 9 ,
1200 router solicitation
1201 .Pq Cm 10 ,
1202 time-to-live exceeded
1203 .Pq Cm 11 ,
1204 IP header bad
1205 .Pq Cm 12 ,
1206 timestamp request
1207 .Pq Cm 13 ,
1208 timestamp reply
1209 .Pq Cm 14 ,
1210 information request
1211 .Pq Cm 15 ,
1212 information reply
1213 .Pq Cm 16 ,
1214 address mask request
1215 .Pq Cm 17
1216 and address mask reply
1217 .Pq Cm 18 .
1218 .It Cm icmp6types Ar types
1219 Matches ICMP6 packets whose ICMP6 type is in the list of
1220 .Ar types .
1221 The list may be specified as any combination of
1222 individual types (numeric) separated by commas.
1223 .Em Ranges are not allowed .
1224 .It Cm in | out
1225 Matches incoming or outgoing packets, respectively.
1226 .Cm in
1227 and
1228 .Cm out
1229 are mutually exclusive (in fact,
1230 .Cm out
1231 is implemented as
1232 .Cm not in Ns No ).
1233 .It Cm ipid Ar id-list
1234 Matches IPv4 packets whose
1235 .Cm ip_id
1236 field has value included in
1237 .Ar id-list ,
1238 which is either a single value or a list of values or ranges
1239 specified in the same way as
1240 .Ar ports .
1241 .It Cm iplen Ar len-list
1242 Matches IP packets whose total length, including header and data, is
1243 in the set
1244 .Ar len-list ,
1245 which is either a single value or a list of values or ranges
1246 specified in the same way as
1247 .Ar ports .
1248 .It Cm ipoptions Ar spec
1249 Matches packets whose IPv4 header contains the comma separated list of
1250 options specified in
1251 .Ar spec .
1252 The supported IP options are:
1253 .Pp
1254 .Cm ssrr
1255 (strict source route),
1256 .Cm lsrr
1257 (loose source route),
1258 .Cm rr
1259 (record packet route) and
1260 .Cm ts
1261 (timestamp).
1262 The absence of a particular option may be denoted
1263 with a
1264 .Ql \&! .
1265 .It Cm ipprecedence Ar precedence
1266 Matches IPv4 packets whose precedence field is equal to
1267 .Ar precedence .
1268 .It Cm ipsec
1269 Matches packets that have IPSEC history associated with them
1270 (i.e., the packet comes encapsulated in IPSEC, the kernel
1271 has IPSEC support and IPSEC_FILTERTUNNEL option, and can correctly
1272 decapsulate it).
1273 .Pp
1274 Note that specifying
1275 .Cm ipsec
1276 is different from specifying
1277 .Cm proto Ar ipsec
1278 as the latter will only look at the specific IP protocol field,
1279 irrespective of IPSEC kernel support and the validity of the IPSEC data.
1280 .Pp
1281 Further note that this flag is silently ignored in kernels without
1282 IPSEC support.
1283 It does not affect rule processing when given and the
1284 rules are handled as if with no
1285 .Cm ipsec
1286 flag.
1287 .It Cm iptos Ar spec
1288 Matches IPv4 packets whose
1289 .Cm tos
1290 field contains the comma separated list of
1291 service types specified in
1292 .Ar spec .
1293 The supported IP types of service are:
1294 .Pp
1295 .Cm lowdelay
1296 .Pq Dv IPTOS_LOWDELAY ,
1297 .Cm throughput
1298 .Pq Dv IPTOS_THROUGHPUT ,
1299 .Cm reliability
1300 .Pq Dv IPTOS_RELIABILITY ,
1301 .Cm mincost
1302 .Pq Dv IPTOS_MINCOST ,
1303 .Cm congestion
1304 .Pq Dv IPTOS_ECN_CE .
1305 The absence of a particular type may be denoted
1306 with a
1307 .Ql \&! .
1308 .It Cm ipttl Ar ttl-list
1309 Matches IPv4 packets whose time to live is included in
1310 .Ar ttl-list ,
1311 which is either a single value or a list of values or ranges
1312 specified in the same way as
1313 .Ar ports .
1314 .It Cm ipversion Ar ver
1315 Matches IP packets whose IP version field is
1316 .Ar ver .
1317 .It Cm keep-state
1318 Upon a match, the firewall will create a dynamic rule, whose
1319 default behaviour is to match bidirectional traffic between
1320 source and destination IP/port using the same protocol.
1321 The rule has a limited lifetime (controlled by a set of
1322 .Xr sysctl 8
1323 variables), and the lifetime is refreshed every time a matching
1324 packet is found.
1325 .It Cm layer2
1326 Matches only layer2 packets, i.e., those passed to
1327 .Nm
1328 from ether_demux() and ether_output_frame().
1329 .It Cm limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N
1330 The firewall will only allow
1331 .Ar N
1332 connections with the same
1333 set of parameters as specified in the rule.
1334 One or more
1335 of source and destination addresses and ports can be
1336 specified.
1337 Currently,
1338 only IPv4 flows are supported.
1339 .It Cm { MAC | mac } Ar dst-mac src-mac
1340 Match packets with a given
1341 .Ar dst-mac
1342 and
1343 .Ar src-mac
1344 addresses, specified as the
1345 .Cm any
1346 keyword (matching any MAC address), or six groups of hex digits
1347 separated by colons,
1348 and optionally followed by a mask indicating the significant bits.
1349 The mask may be specified using either of the following methods:
1350 .Bl -enum -width indent
1351 .It
1352 A slash
1353 .Pq /
1354 followed by the number of significant bits.
1355 For example, an address with 33 significant bits could be specified as:
1356 .Pp
1357 .Dl "MAC 10:20:30:40:50:60/33 any"
1358 .Pp
1359 .It
1360 An ampersand
1361 .Pq &
1362 followed by a bitmask specified as six groups of hex digits separated
1363 by colons.
1364 For example, an address in which the last 16 bits are significant could
1365 be specified as:
1366 .Pp
1367 .Dl "MAC 10:20:30:40:50:60&00:00:00:00:ff:ff any"
1368 .Pp
1369 Note that the ampersand character has a special meaning in many shells
1370 and should generally be escaped.
1371 .Pp
1372 .El
1373 Note that the order of MAC addresses (destination first,
1374 source second) is
1375 the same as on the wire, but the opposite of the one used for
1376 IP addresses.
1377 .It Cm mac-type Ar mac-type
1378 Matches packets whose Ethernet Type field
1379 corresponds to one of those specified as argument.
1380 .Ar mac-type
1381 is specified in the same way as
1382 .Cm port numbers
1383 (i.e., one or more comma-separated single values or ranges).
1384 You can use symbolic names for known values such as
1385 .Em vlan , ipv4, ipv6 .
1386 Values can be entered as decimal or hexadecimal (if prefixed by 0x),
1387 and they are always printed as hexadecimal (unless the
1388 .Cm -N
1389 option is used, in which case symbolic resolution will be attempted).
1390 .It Cm proto Ar protocol
1391 Matches packets with the corresponding IP protocol.
1392 .It Cm recv | xmit | via Brq Ar ifX | Ar if Ns Cm * | Ar ipno | Ar any
1393 Matches packets received, transmitted or going through,
1394 respectively, the interface specified by exact name
1395 .Ns No ( Ar ifX Ns No ),
1396 by device name
1397 .Ns No ( Ar if Ns Ar * Ns No ),
1398 by IP address, or through some interface.
1399 .Pp
1400 The
1401 .Cm via
1402 keyword causes the interface to always be checked.
1403 If
1404 .Cm recv
1405 or
1406 .Cm xmit
1407 is used instead of
1408 .Cm via ,
1409 then only the receive or transmit interface (respectively)
1410 is checked.
1411 By specifying both, it is possible to match packets based on
1412 both receive and transmit interface, e.g.:
1413 .Pp
1414 .Dl "ipfw add deny ip from any to any out recv ed0 xmit ed1"
1415 .Pp
1416 The
1417 .Cm recv
1418 interface can be tested on either incoming or outgoing packets,
1419 while the
1420 .Cm xmit
1421 interface can only be tested on outgoing packets.
1422 So
1423 .Cm out
1424 is required (and
1425 .Cm in
1426 is invalid) whenever
1427 .Cm xmit
1428 is used.
1429 .Pp
1430 A packet may not have a receive or transmit interface: packets
1431 originating from the local host have no receive interface,
1432 while packets destined for the local host have no transmit
1433 interface.
1434 .It Cm setup
1435 Matches TCP packets that have the SYN bit set but no ACK bit.
1436 This is the short form of
1437 .Dq Li tcpflags\ syn,!ack .
1438 .It Cm src-ip Ar ip-address
1439 Matches IPv4 packets whose source IP is one of the address(es)
1440 specified as an argument.
1441 .It Cm src-ip6 Ar ip6-address
1442 Matches IPv6 packets whose source IP is one of the address(es)
1443 specified as an argument.
1444 .It Cm src-port Ar ports
1445 Matches IP packets whose source port is one of the port(s)
1446 specified as argument.
1447 .It Cm tagged Ar tag-list
1448 Matches packets whose tags are included in
1449 .Ar tag-list ,
1450 which is either a single value or a list of values or ranges
1451 specified in the same way as
1452 .Ar ports .
1453 Tags can be applied to the packet using
1454 .Cm tag
1455 rule action parameter (see it's description for details on tags).
1456 .It Cm tcpack Ar ack
1457 TCP packets only.
1458 Match if the TCP header acknowledgment number field is set to
1459 .Ar ack .
1460 .It Cm tcpdatalen Ar tcpdatalen-list
1461 Matches TCP packets whose length of TCP data is
1462 .Ar tcpdatalen-list ,
1463 which is either a single value or a list of values or ranges
1464 specified in the same way as
1465 .Ar ports .
1466 .It Cm tcpflags Ar spec
1467 TCP packets only.
1468 Match if the TCP header contains the comma separated list of
1469 flags specified in
1470 .Ar spec .
1471 The supported TCP flags are:
1472 .Pp
1473 .Cm fin ,
1474 .Cm syn ,
1475 .Cm rst ,
1476 .Cm psh ,
1477 .Cm ack
1478 and
1479 .Cm urg .
1480 The absence of a particular flag may be denoted
1481 with a
1482 .Ql \&! .
1483 A rule which contains a
1484 .Cm tcpflags
1485 specification can never match a fragmented packet which has
1486 a non-zero offset.
1487 See the
1488 .Cm frag
1489 option for details on matching fragmented packets.
1490 .It Cm tcpseq Ar seq
1491 TCP packets only.
1492 Match if the TCP header sequence number field is set to
1493 .Ar seq .
1494 .It Cm tcpwin Ar win
1495 TCP packets only.
1496 Match if the TCP header window field is set to
1497 .Ar win .
1498 .It Cm tcpoptions Ar spec
1499 TCP packets only.
1500 Match if the TCP header contains the comma separated list of
1501 options specified in
1502 .Ar spec .
1503 The supported TCP options are:
1504 .Pp
1505 .Cm mss
1506 (maximum segment size),
1507 .Cm window
1508 (tcp window advertisement),
1509 .Cm sack
1510 (selective ack),
1511 .Cm ts
1512 (rfc1323 timestamp) and
1513 .Cm cc
1514 (rfc1644 t/tcp connection count).
1515 The absence of a particular option may be denoted
1516 with a
1517 .Ql \&! .
1518 .It Cm uid Ar user
1519 Match all TCP or UDP packets sent by or received for a
1520 .Ar user .
1521 A
1522 .Ar user
1523 may be matched by name or identification number.
1524 .It Cm verrevpath
1525 For incoming packets,
1526 a routing table lookup is done on the packet's source address.
1527 If the interface on which the packet entered the system matches the
1528 outgoing interface for the route,
1529 the packet matches.
1530 If the interfaces do not match up,
1531 the packet does not match.
1532 All outgoing packets or packets with no incoming interface match.
1533 .Pp
1534 The name and functionality of the option is intentionally similar to
1535 the Cisco IOS command:
1536 .Pp
1537 .Dl ip verify unicast reverse-path
1538 .Pp
1539 This option can be used to make anti-spoofing rules to reject all
1540 packets with source addresses not from this interface.
1541 See also the option
1542 .Cm antispoof .
1543 .It Cm versrcreach
1544 For incoming packets,
1545 a routing table lookup is done on the packet's source address.
1546 If a route to the source address exists, but not the default route
1547 or a blackhole/reject route, the packet matches.
1548 Otherwise, the packet does not match.
1549 All outgoing packets match.
1550 .Pp
1551 The name and functionality of the option is intentionally similar to
1552 the Cisco IOS command:
1553 .Pp
1554 .Dl ip verify unicast source reachable-via any
1555 .Pp
1556 This option can be used to make anti-spoofing rules to reject all
1557 packets whose source address is unreachable.
1558 .It Cm antispoof
1559 For incoming packets, the packet's source address is checked if it
1560 belongs to a directly connected network.
1561 If the network is directly connected, then the interface the packet
1562 came on in is compared to the interface the network is connected to.
1563 When incoming interface and directly connected interface are not the
1564 same, the packet does not match.
1565 Otherwise, the packet does match.
1566 All outgoing packets match.
1567 .Pp
1568 This option can be used to make anti-spoofing rules to reject all
1569 packets that pretend to be from a directly connected network but do
1570 not come in through that interface.
1571 This option is similar to but more restricted than
1572 .Cm verrevpath
1573 because it engages only on packets with source addresses of directly
1574 connected networks instead of all source addresses.
1575 .El
1576 .Sh LOOKUP TABLES
1577 Lookup tables are useful to handle large sparse address sets,
1578 typically from a hundred to several thousands of entries.
1579 There may be up to 128 different lookup tables, numbered 0 to 127.
1580 .Pp
1581 Each entry is represented by an
1582 .Ar addr Ns Op / Ns Ar masklen
1583 and will match all addresses with base
1584 .Ar addr
1585 (specified as an IP address or a hostname)
1586 and mask width of
1587 .Ar masklen
1588 bits.
1589 If
1590 .Ar masklen
1591 is not specified, it defaults to 32.
1592 When looking up an IP address in a table, the most specific
1593 entry will match.
1594 Associated with each entry is a 32-bit unsigned
1595 .Ar value ,
1596 which can optionally be checked by a rule matching code.
1597 When adding an entry, if
1598 .Ar value
1599 is not specified, it defaults to 0.
1600 .Pp
1601 An entry can be added to a table
1602 .Pq Cm add ,
1603 removed from a table
1604 .Pq Cm delete ,
1605 a table can be examined
1606 .Pq Cm list
1607 or flushed
1608 .Pq Cm flush .
1609 .Pp
1610 Internally, each table is stored in a Radix tree, the same way as
1611 the routing table (see
1612 .Xr route 4 ) .
1613 .Pp
1614 Lookup tables currently support IPv4 addresses only.
1615 .Pp
1616 The
1617 .Cm tablearg
1618 feature provides the ability to use a value, looked up in the table, as
1619 the argument for a rule action, action parameter or rule option.
1620 This can significantly reduce number of rules in some configurations.
1621 The
1622 .Cm tablearg
1623 argument can be used with the following actions:
1624 .Cm nat, pipe , queue, divert, tee, netgraph, ngtee, fwd
1625 action parameters:
1626 .Cm tag, untag,
1627 rule options:
1628 .Cm limit, tagged.
1629 .Pp
1630 When used with
1631 .Cm fwd
1632 it is possible to supply table entries with values
1633 that are in the form of IP addresses or hostnames.
1634 See the
1635 .Sx EXAMPLES
1636 Section for example usage of tables and the tablearg keyword.
1637 .Sh SETS OF RULES
1638 Each rule belongs to one of 32 different
1639 .Em sets
1640 , numbered 0 to 31.
1641 Set 31 is reserved for the default rule.
1642 .Pp
1643 By default, rules are put in set 0, unless you use the
1644 .Cm set N
1645 attribute when entering a new rule.
1646 Sets can be individually and atomically enabled or disabled,
1647 so this mechanism permits an easy way to store multiple configurations
1648 of the firewall and quickly (and atomically) switch between them.
1649 The command to enable/disable sets is
1650 .Bd -ragged -offset indent
1651 .Nm
1652 .Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
1653 .Ed
1654 .Pp
1655 where multiple
1656 .Cm enable
1657 or
1658 .Cm disable
1659 sections can be specified.
1660 Command execution is atomic on all the sets specified in the command.
1661 By default, all sets are enabled.
1662 .Pp
1663 When you disable a set, its rules behave as if they do not exist
1664 in the firewall configuration, with only one exception:
1665 .Bd -ragged -offset indent
1666 dynamic rules created from a rule before it had been disabled
1667 will still be active until they expire.
1668 In order to delete
1669 dynamic rules you have to explicitly delete the parent rule
1670 which generated them.
1671 .Ed
1672 .Pp
1673 The set number of rules can be changed with the command
1674 .Bd -ragged -offset indent
1675 .Nm
1676 .Cm set move
1677 .Brq Cm rule Ar rule-number | old-set
1678 .Cm to Ar new-set
1679 .Ed
1680 .Pp
1681 Also, you can atomically swap two rulesets with the command
1682 .Bd -ragged -offset indent
1683 .Nm
1684 .Cm set swap Ar first-set second-set
1685 .Ed
1686 .Pp
1687 See the
1688 .Sx EXAMPLES
1689 Section on some possible uses of sets of rules.
1690 .Sh STATEFUL FIREWALL
1691 Stateful operation is a way for the firewall to dynamically
1692 create rules for specific flows when packets that
1693 match a given pattern are detected.
1694 Support for stateful
1695 operation comes through the
1696 .Cm check-state , keep-state
1697 and
1698 .Cm limit
1699 options of
1700 .Nm rules .
1701 .Pp
1702 Dynamic rules are created when a packet matches a
1703 .Cm keep-state
1704 or
1705 .Cm limit
1706 rule, causing the creation of a
1707 .Em dynamic
1708 rule which will match all and only packets with
1709 a given
1710 .Em protocol
1711 between a
1712 .Em src-ip/src-port dst-ip/dst-port
1713 pair of addresses
1714 .Em ( src
1715 and
1716 .Em dst
1717 are used here only to denote the initial match addresses, but they
1718 are completely equivalent afterwards).
1719 Dynamic rules will be checked at the first
1720 .Cm check-state, keep-state
1721 or
1722 .Cm limit
1723 occurrence, and the action performed upon a match will be the same
1724 as in the parent rule.
1725 .Pp
1726 Note that no additional attributes other than protocol and IP addresses
1727 and ports are checked on dynamic rules.
1728 .Pp
1729 The typical use of dynamic rules is to keep a closed firewall configuration,
1730 but let the first TCP SYN packet from the inside network install a
1731 dynamic rule for the flow so that packets belonging to that session
1732 will be allowed through the firewall:
1733 .Pp
1734 .Dl "ipfw add check-state"
1735 .Dl "ipfw add allow tcp from my-subnet to any setup keep-state"
1736 .Dl "ipfw add deny tcp from any to any"
1737 .Pp
1738 A similar approach can be used for UDP, where an UDP packet coming
1739 from the inside will install a dynamic rule to let the response through
1740 the firewall:
1741 .Pp
1742 .Dl "ipfw add check-state"
1743 .Dl "ipfw add allow udp from my-subnet to any keep-state"
1744 .Dl "ipfw add deny udp from any to any"
1745 .Pp
1746 Dynamic rules expire after some time, which depends on the status
1747 of the flow and the setting of some
1748 .Cm sysctl
1749 variables.
1750 See Section
1751 .Sx SYSCTL VARIABLES
1752 for more details.
1753 For TCP sessions, dynamic rules can be instructed to periodically
1754 send keepalive packets to refresh the state of the rule when it is
1755 about to expire.
1756 .Pp
1757 See Section
1758 .Sx EXAMPLES
1759 for more examples on how to use dynamic rules.
1760 .Sh TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
1761 .Nm
1762 is also the user interface for the
1763 .Nm dummynet
1764 traffic shaper.
1765 .Pp
1766 .Nm dummynet
1767 operates by first using the firewall to classify packets and divide them into
1768 .Em flows ,
1769 using any match pattern that can be used in
1770 .Nm
1771 rules.
1772 Depending on local policies, a flow can contain packets for a single
1773 TCP connection, or from/to a given host, or entire subnet, or a
1774 protocol type, etc.
1775 .Pp
1776 There are two modes of
1777 .Nm dummynet
1778 operation:
1779 .Dq normal
1780 and
1781 .Dq fast .
1782 The
1783 .Dq normal
1784 mode tries to emulate a real link: the
1785 .Nm dummynet
1786 scheduler ensures that the packet will not leave the pipe faster than it
1787 would on the real link with a given bandwidth.
1788 The
1789 .Dq fast
1790 mode allows certain packets to bypass the
1791 .Nm dummynet
1792 scheduler (if packet flow does not exceed pipe's bandwidth).
1793 This is the reason why the
1794 .Dq fast
1795 mode requires less CPU cycles per packet (on average) and packet latency
1796 can be significantly lower in comparison to a real link with the same
1797 bandwidth.
1798 The default mode is
1799 .Dq normal .
1800 The
1801 .Dq fast
1802 mode can be enabled by setting the
1803 .Va net.inet.ip.dummynet.io_fast
1804 .Xr sysctl 8
1805 variable to a non-zero value.
1806 .Pp
1807 Packets belonging to the same flow are then passed to either of two
1808 different objects, which implement the traffic regulation:
1809 .Bl -hang -offset XXXX
1810 .It Em pipe
1811 A pipe emulates a link with given bandwidth, propagation delay,
1812 queue size and packet loss rate.
1813 Packets are queued in front of the pipe as they come out from the classifier,
1814 and then transferred to the pipe according to the pipe's parameters.
1815 .Pp
1816 .It Em queue
1817 A queue
1818 is an abstraction used to implement the WF2Q+
1819 (Worst-case Fair Weighted Fair Queueing) policy, which is
1820 an efficient variant of the WFQ policy.
1821 .br
1822 The queue associates a
1823 .Em weight
1824 and a reference pipe to each flow, and then all backlogged (i.e.,
1825 with packets queued) flows linked to the same pipe share the pipe's
1826 bandwidth proportionally to their weights.
1827 Note that weights are not priorities; a flow with a lower weight
1828 is still guaranteed to get its fraction of the bandwidth even if a
1829 flow with a higher weight is permanently backlogged.
1830 .Pp
1831 .El
1832 In practice,
1833 .Em pipes
1834 can be used to set hard limits to the bandwidth that a flow can use, whereas
1835 .Em queues
1836 can be used to determine how different flow share the available bandwidth.
1837 .Pp
1838 The
1839 .Em pipe
1840 and
1841 .Em queue
1842 configuration commands are the following:
1843 .Bd -ragged -offset indent
1844 .Cm pipe Ar number Cm config Ar pipe-configuration
1845 .Pp
1846 .Cm queue Ar number Cm config Ar queue-configuration
1847 .Ed
1848 .Pp
1849 The following parameters can be configured for a pipe:
1850 .Pp
1851 .Bl -tag -width indent -compact
1852 .It Cm bw Ar bandwidth | device
1853 Bandwidth, measured in
1854 .Sm off
1855 .Op Cm K | M
1856 .Brq Cm bit/s | Byte/s .
1857 .Sm on
1858 .Pp
1859 A value of 0 (default) means unlimited bandwidth.
1860 The unit must immediately follow the number, as in
1861 .Pp
1862 .Dl "ipfw pipe 1 config bw 300Kbit/s"
1863 .Pp
1864 If a device name is specified instead of a numeric value, as in
1865 .Pp
1866 .Dl "ipfw pipe 1 config bw tun0"
1867 .Pp
1868 then the transmit clock is supplied by the specified device.
1869 At the moment only the
1870 .Xr tun 4
1871 device supports this
1872 functionality, for use in conjunction with
1873 .Xr ppp 8 .
1874 .Pp
1875 .It Cm delay Ar ms-delay
1876 Propagation delay, measured in milliseconds.
1877 The value is rounded to the next multiple of the clock tick
1878 (typically 10ms, but it is a good practice to run kernels
1879 with
1880 .Dq "options HZ=1000"
1881 to reduce
1882 the granularity to 1ms or less).
1883 Default value is 0, meaning no delay.
1884 .El
1885 .Pp
1886 The following parameters can be configured for a queue:
1887 .Pp
1888 .Bl -tag -width indent -compact
1889 .It Cm pipe Ar pipe_nr
1890 Connects a queue to the specified pipe.
1891 Multiple queues (with the same or different weights) can be connected to
1892 the same pipe, which specifies the aggregate rate for the set of queues.
1893 .Pp
1894 .It Cm weight Ar weight
1895 Specifies the weight to be used for flows matching this queue.
1896 The weight must be in the range 1..100, and defaults to 1.
1897 .El
1898 .Pp
1899 Finally, the following parameters can be configured for both
1900 pipes and queues:
1901 .Pp
1902 .Bl -tag -width XXXX -compact
1903 .Pp
1904 .It Cm buckets Ar hash-table-size
1905 Specifies the size of the hash table used for storing the
1906 various queues.
1907 Default value is 64 controlled by the
1908 .Xr sysctl 8
1909 variable
1910 .Va net.inet.ip.dummynet.hash_size ,
1911 allowed range is 16 to 65536.
1912 .Pp
1913 .It Cm mask Ar mask-specifier
1914 Packets sent to a given pipe or queue by an
1915 .Nm
1916 rule can be further classified into multiple flows, each of which is then
1917 sent to a different
1918 .Em dynamic
1919 pipe or queue.
1920 A flow identifier is constructed by masking the IP addresses,
1921 ports and protocol types as specified with the
1922 .Cm mask
1923 options in the configuration of the pipe or queue.
1924 For each different flow identifier, a new pipe or queue is created
1925 with the same parameters as the original object, and matching packets
1926 are sent to it.
1927 .Pp
1928 Thus, when
1929 .Em dynamic pipes
1930 are used, each flow will get the same bandwidth as defined by the pipe,
1931 whereas when
1932 .Em dynamic queues
1933 are used, each flow will share the parent's pipe bandwidth evenly
1934 with other flows generated by the same queue (note that other queues
1935 with different weights might be connected to the same pipe).
1936 .br
1937 Available mask specifiers are a combination of one or more of the following:
1938 .Pp
1939 .Cm dst-ip Ar mask ,
1940 .Cm dst-ip6 Ar mask ,
1941 .Cm src-ip Ar mask ,
1942 .Cm src-ip6 Ar mask ,
1943 .Cm dst-port Ar mask ,
1944 .Cm src-port Ar mask ,
1945 .Cm flow-id Ar mask ,
1946 .Cm proto Ar mask
1947 or
1948 .Cm all ,
1949 .Pp
1950 where the latter means all bits in all fields are significant.
1951 .Pp
1952 .It Cm noerror
1953 When a packet is dropped by a
1954 .Nm dummynet
1955 queue or pipe, the error
1956 is normally reported to the caller routine in the kernel, in the
1957 same way as it happens when a device queue fills up.
1958 Setting this
1959 option reports the packet as successfully delivered, which can be
1960 needed for some experimental setups where you want to simulate
1961 loss or congestion at a remote router.
1962 .Pp
1963 .It Cm plr Ar packet-loss-rate
1964 Packet loss rate.
1965 Argument
1966 .Ar packet-loss-rate
1967 is a floating-point number between 0 and 1, with 0 meaning no
1968 loss, 1 meaning 100% loss.
1969 The loss rate is internally represented on 31 bits.
1970 .Pp
1971 .It Cm queue Brq Ar slots | size Ns Cm Kbytes
1972 Queue size, in
1973 .Ar slots
1974 or
1975 .Cm KBytes .
1976 Default value is 50 slots, which
1977 is the typical queue size for Ethernet devices.
1978 Note that for slow speed links you should keep the queue
1979 size short or your traffic might be affected by a significant
1980 queueing delay.
1981 E.g., 50 max-sized ethernet packets (1500 bytes) mean 600Kbit
1982 or 20s of queue on a 30Kbit/s pipe.
1983 Even worse effects can result if you get packets from an
1984 interface with a much larger MTU, e.g.\& the loopback interface
1985 with its 16KB packets.
1986 The
1987 .Xr sysctl 8
1988 variables
1989 .Em net.inet.ip.dummynet.pipe_byte_limit
1990 and
1991 .Em net.inet.ip.dummynet.pipe_slot_limit
1992 control the maximum lengths that can be specified.
1993 .Pp
1994 .It Cm red | gred Ar w_q Ns / Ns Ar min_th Ns / Ns Ar max_th Ns / Ns Ar max_p
1995 Make use of the RED (Random Early Detection) queue management algorithm.
1996 .Ar w_q
1997 and
1998 .Ar max_p
1999 are floating
2000 point numbers between 0 and 1 (0 not included), while
2001 .Ar min_th
2002 and
2003 .Ar max_th
2004 are integer numbers specifying thresholds for queue management
2005 (thresholds are computed in bytes if the queue has been defined
2006 in bytes, in slots otherwise).
2007 The
2008 .Nm dummynet
2009 also supports the gentle RED variant (gred).
2010 Three
2011 .Xr sysctl 8
2012 variables can be used to control the RED behaviour:
2013 .Bl -tag -width indent
2014 .It Va net.inet.ip.dummynet.red_lookup_depth
2015 specifies the accuracy in computing the average queue
2016 when the link is idle (defaults to 256, must be greater than zero)
2017 .It Va net.inet.ip.dummynet.red_avg_pkt_size
2018 specifies the expected average packet size (defaults to 512, must be
2019 greater than zero)
2020 .It Va net.inet.ip.dummynet.red_max_pkt_size
2021 specifies the expected maximum packet size, only used when queue
2022 thresholds are in bytes (defaults to 1500, must be greater than zero).
2023 .El
2024 .El
2025 .Pp
2026 When used with IPv6 data,
2027 .Nm dummynet
2028 currently has several limitations.
2029 Information necessary to route link-local packets to an
2030 interface is not available after processing by
2031 .Nm dummynet
2032 so those packets are dropped in the output path.
2033 Care should be taken to insure that link-local packets are not passed to
2034 .Nm dummynet .
2035 .Sh CHECKLIST
2036 Here are some important points to consider when designing your
2037 rules:
2038 .Bl -bullet
2039 .It
2040 Remember that you filter both packets going
2041 .Cm in
2042 and
2043 .Cm out .
2044 Most connections need packets going in both directions.
2045 .It
2046 Remember to test very carefully.
2047 It is a good idea to be near the console when doing this.
2048 If you cannot be near the console,
2049 use an auto-recovery script such as the one in
2050 .Pa /usr/share/examples/ipfw/change_rules.sh .
2051 .It
2052 Do not forget the loopback interface.
2053 .El
2054 .Sh FINE POINTS
2055 .Bl -bullet
2056 .It
2057 There are circumstances where fragmented datagrams are unconditionally
2058 dropped.
2059 TCP packets are dropped if they do not contain at least 20 bytes of
2060 TCP header, UDP packets are dropped if they do not contain a full 8
2061 byte UDP header, and ICMP packets are dropped if they do not contain
2062 4 bytes of ICMP header, enough to specify the ICMP type, code, and
2063 checksum.
2064 These packets are simply logged as
2065 .Dq pullup failed
2066 since there may not be enough good data in the packet to produce a
2067 meaningful log entry.
2068 .It
2069 Another type of packet is unconditionally dropped, a TCP packet with a
2070 fragment offset of one.
2071 This is a valid packet, but it only has one use, to try
2072 to circumvent firewalls.
2073 When logging is enabled, these packets are
2074 reported as being dropped by rule -1.
2075 .It
2076 If you are logged in over a network, loading the
2077 .Xr kld 4
2078 version of
2079 .Nm
2080 is probably not as straightforward as you would think.
2081 I recommend the following command line:
2082 .Bd -literal -offset indent
2083 kldload ipfw && \e
2084 ipfw add 32000 allow ip from any to any
2085 .Ed
2086 .Pp
2087 Along the same lines, doing an
2088 .Bd -literal -offset indent
2089 ipfw flush
2090 .Ed
2091 .Pp
2092 in similar surroundings is also a bad idea.
2093 .It
2094 The
2095 .Nm
2096 filter list may not be modified if the system security level
2097 is set to 3 or higher
2098 (see
2099 .Xr init 8
2100 for information on system security levels).
2101 .El
2102 .Sh PACKET DIVERSION
2103 A
2104 .Xr divert 4
2105 socket bound to the specified port will receive all packets
2106 diverted to that port.
2107 If no socket is bound to the destination port, or if the divert module is
2108 not loaded, or if the kernel was not compiled with divert socket support,
2109 the packets are dropped.
2110 .Sh NETWORK ADDRESS TRANSLATION (NAT)
2111 The nat configuration command is the following:
2112 .Bd -ragged -offset indent
2113 .Bk -words
2114 .Cm nat 
2115 .Ar nat_number 
2116 .Cm config 
2117 .Ar nat-configuration
2118 .Ek
2119 .Ed
2120 .Pp
2121 .
2122 The following parameters can be configured:
2123 .Bl -tag -width indent
2124 .It Cm ip Ar ip_address
2125 Define an ip address to use for aliasing.
2126 .It Cm if Ar nic
2127 Use ip addres of NIC for aliasing, dynamically changing
2128 it if NIC's ip address change.
2129 .It Cm log
2130 Enable logging on this nat instance.
2131 .It Cm deny_in
2132 Deny any incoming connection from outside world.
2133 .It Cm same_ports
2134 Try to leave the alias port numbers unchanged from
2135 the actual local port numbers.
2136 .It Cm unreg_only
2137 Traffic on the local network not originating from an
2138 unregistered address spaces will be ignored.
2139 .It Cm reset
2140 Reset table of the packet aliasing engine on address change.
2141 .It Cm reverse
2142 Reverse the way libalias handles aliasing.
2143 .It Cm proxy_only
2144 Obey transparent proxy rules only, packet aliasing is not performed.
2145 .El
2146 .Pp
2147 To let the packet continue after being (de)aliased, set the sysctl variable
2148 .Va net.inet.ip.fw.one_pass 
2149 to 0.
2150 For more information about aliasing modes, refer to
2151 .Xr libalias 3
2152 .
2153 See Section
2154 .Sx EXAMPLES
2155 for some examples about nat usage.
2156 .Sh REDIRECT AND LSNAT SUPPORT IN IPFW
2157 Redirect and LSNAT support follow closely the syntax used in
2158 .Xr natd 8
2159
2160 See Section
2161 .Sx EXAMPLES
2162 for some examples on how to do redirect and lsnat.
2163 .Sh SYSCTL VARIABLES
2164 A set of
2165 .Xr sysctl 8
2166 variables controls the behaviour of the firewall and
2167 associated modules
2168 .Pq Nm dummynet , bridge .
2169 These are shown below together with their default value
2170 (but always check with the
2171 .Xr sysctl 8
2172 command what value is actually in use) and meaning:
2173 .Bl -tag -width indent
2174 .It Va net.inet.ip.dummynet.expire : No 1
2175 Lazily delete dynamic pipes/queue once they have no pending traffic.
2176 You can disable this by setting the variable to 0, in which case
2177 the pipes/queues will only be deleted when the threshold is reached.
2178 .It Va net.inet.ip.dummynet.hash_size : No 64
2179 Default size of the hash table used for dynamic pipes/queues.
2180 This value is used when no
2181 .Cm buckets
2182 option is specified when configuring a pipe/queue.
2183 .It Va net.inet.ip.dummynet.io_fast : No 0
2184 If set to a non-zero value,
2185 the
2186 .Dq fast
2187 mode of
2188 .Nm dummynet
2189 operation (see above) is enabled.
2190 .It Va net.inet.ip.dummynet.io_pkt
2191 Number of packets passed to
2192 .Nm dummynet .
2193 .It Va net.inet.ip.dummynet.io_pkt_drop
2194 Number of packets dropped by
2195 .Nm dummynet .
2196 .It Va net.inet.ip.dummynet.io_pkt_fast
2197 Number of packets bypassed by the
2198 .Nm dummynet
2199 scheduler.
2200 .It Va net.inet.ip.dummynet.max_chain_len : No 16
2201 Target value for the maximum number of pipes/queues in a hash bucket.
2202 The product
2203 .Cm max_chain_len*hash_size
2204 is used to determine the threshold over which empty pipes/queues
2205 will be expired even when
2206 .Cm net.inet.ip.dummynet.expire=0 .
2207 .It Va net.inet.ip.dummynet.red_lookup_depth : No 256
2208 .It Va net.inet.ip.dummynet.red_avg_pkt_size : No 512
2209 .It Va net.inet.ip.dummynet.red_max_pkt_size : No 1500
2210 Parameters used in the computations of the drop probability
2211 for the RED algorithm.
2212 .It Va net.inet.ip.dummynet.pipe_byte_limit : No 1048576
2213 .It Va net.inet.ip.dummynet.pipe_slot_limit : No 100
2214 The maximum queue size that can be specified in bytes or packets.
2215 These limits prevent accidental exhaustion of resources such as mbufs.
2216 If you raise these limits,
2217 you should make sure the system is configured so that sufficient resources
2218 are available.
2219 .It Va net.inet.ip.fw.autoinc_step : No 100
2220 Delta between rule numbers when auto-generating them.
2221 The value must be in the range 1..1000.
2222 .It Va net.inet.ip.fw.curr_dyn_buckets : Va net.inet.ip.fw.dyn_buckets
2223 The current number of buckets in the hash table for dynamic rules
2224 (readonly).
2225 .It Va net.inet.ip.fw.debug : No 1
2226 Controls debugging messages produced by
2227 .Nm .
2228 .It Va net.inet.ip.fw.dyn_buckets : No 256
2229 The number of buckets in the hash table for dynamic rules.
2230 Must be a power of 2, up to 65536.
2231 It only takes effect when all dynamic rules have expired, so you
2232 are advised to use a
2233 .Cm flush
2234 command to make sure that the hash table is resized.
2235 .It Va net.inet.ip.fw.dyn_count : No 3
2236 Current number of dynamic rules
2237 (read-only).
2238 .It Va net.inet.ip.fw.dyn_keepalive : No 1
2239 Enables generation of keepalive packets for
2240 .Cm keep-state
2241 rules on TCP sessions.
2242 A keepalive is generated to both
2243 sides of the connection every 5 seconds for the last 20
2244 seconds of the lifetime of the rule.
2245 .It Va net.inet.ip.fw.dyn_max : No 8192
2246 Maximum number of dynamic rules.
2247 When you hit this limit, no more dynamic rules can be
2248 installed until old ones expire.
2249 .It Va net.inet.ip.fw.dyn_ack_lifetime : No 300
2250 .It Va net.inet.ip.fw.dyn_syn_lifetime : No 20
2251 .It Va net.inet.ip.fw.dyn_fin_lifetime : No 1
2252 .It Va net.inet.ip.fw.dyn_rst_lifetime : No 1
2253 .It Va net.inet.ip.fw.dyn_udp_lifetime : No 5
2254 .It Va net.inet.ip.fw.dyn_short_lifetime : No 30
2255 These variables control the lifetime, in seconds, of dynamic
2256 rules.
2257 Upon the initial SYN exchange the lifetime is kept short,
2258 then increased after both SYN have been seen, then decreased
2259 again during the final FIN exchange or when a RST is received.
2260 Both
2261 .Em dyn_fin_lifetime
2262 and
2263 .Em dyn_rst_lifetime
2264 must be strictly lower than 5 seconds, the period of
2265 repetition of keepalives.
2266 The firewall enforces that.
2267 .It Va net.inet.ip.fw.enable : No 1
2268 Enables the firewall.
2269 Setting this variable to 0 lets you run your machine without
2270 firewall even if compiled in.
2271 .It Va net.inet6.ip6.fw.enable : No 1
2272 provides the same functionality as above for the IPv6 case.
2273 .It Va net.inet.ip.fw.one_pass : No 1
2274 When set, the packet exiting from the
2275 .Nm dummynet
2276 pipe or from
2277 .Xr ng_ipfw 4
2278 node is not passed though the firewall again.
2279 Otherwise, after an action, the packet is
2280 reinjected into the firewall at the next rule.
2281 .It Va net.inet.ip.fw.verbose : No 1
2282 Enables verbose messages.
2283 .It Va net.inet.ip.fw.verbose_limit : No 0
2284 Limits the number of messages produced by a verbose firewall.
2285 .It Va net.inet6.ip6.fw.deny_unknown_exthdrs : No 1
2286 If enabled packets with unknown IPv6 Extension Headers will be denied.
2287 .It Va net.link.ether.ipfw : No 0
2288 Controls whether layer-2 packets are passed to
2289 .Nm .
2290 Default is no.
2291 .It Va net.link.bridge.ipfw : No 0
2292 Controls whether bridged packets are passed to
2293 .Nm .
2294 Default is no.
2295 .El
2296 .Pp
2297 .Sh EXAMPLES
2298 There are far too many possible uses of
2299 .Nm
2300 so this Section will only give a small set of examples.
2301 .Pp
2302 .Ss BASIC PACKET FILTERING
2303 This command adds an entry which denies all tcp packets from
2304 .Em cracker.evil.org
2305 to the telnet port of
2306 .Em wolf.tambov.su
2307 from being forwarded by the host:
2308 .Pp
2309 .Dl "ipfw add deny tcp from cracker.evil.org to wolf.tambov.su telnet"
2310 .Pp
2311 This one disallows any connection from the entire cracker's
2312 network to my host:
2313 .Pp
2314 .Dl "ipfw add deny ip from 123.45.67.0/24 to my.host.org"
2315 .Pp
2316 A first and efficient way to limit access (not using dynamic rules)
2317 is the use of the following rules:
2318 .Pp
2319 .Dl "ipfw add allow tcp from any to any established"
2320 .Dl "ipfw add allow tcp from net1 portlist1 to net2 portlist2 setup"
2321 .Dl "ipfw add allow tcp from net3 portlist3 to net3 portlist3 setup"
2322 .Dl "..."
2323 .Dl "ipfw add deny tcp from any to any"
2324 .Pp
2325 The first rule will be a quick match for normal TCP packets,
2326 but it will not match the initial SYN packet, which will be
2327 matched by the
2328 .Cm setup
2329 rules only for selected source/destination pairs.
2330 All other SYN packets will be rejected by the final
2331 .Cm deny
2332 rule.
2333 .Pp
2334 If you administer one or more subnets, you can take advantage
2335 of the address sets and or-blocks and write extremely
2336 compact rulesets which selectively enable services to blocks
2337 of clients, as below:
2338 .Pp
2339 .Dl "goodguys=\*q{ 10.1.2.0/24{20,35,66,18} or 10.2.3.0/28{6,3,11} }\*q"
2340 .Dl "badguys=\*q10.1.2.0/24{8,38,60}\*q"
2341 .Dl ""
2342 .Dl "ipfw add allow ip from ${goodguys} to any"
2343 .Dl "ipfw add deny ip from ${badguys} to any"
2344 .Dl "... normal policies ..."
2345 .Pp
2346 The
2347 .Cm verrevpath
2348 option could be used to do automated anti-spoofing by adding the
2349 following to the top of a ruleset:
2350 .Pp
2351 .Dl "ipfw add deny ip from any to any not verrevpath in"
2352 .Pp
2353 This rule drops all incoming packets that appear to be coming to the
2354 system on the wrong interface.
2355 For example, a packet with a source
2356 address belonging to a host on a protected internal network would be
2357 dropped if it tried to enter the system from an external interface.
2358 .Pp
2359 The
2360 .Cm antispoof
2361 option could be used to do similar but more restricted anti-spoofing
2362 by adding the following to the top of a ruleset:
2363 .Pp
2364 .Dl "ipfw add deny ip from any to any not antispoof in"
2365 .Pp
2366 This rule drops all incoming packets that appear to be coming from another
2367 directly connected system but on the wrong interface.
2368 For example, a packet with a source address of
2369 .Li 192.168.0.0/24
2370 , configured on
2371 .Li fxp0
2372 , but coming in on
2373 .Li fxp1
2374 would be dropped.
2375 .Ss DYNAMIC RULES
2376 In order to protect a site from flood attacks involving fake
2377 TCP packets, it is safer to use dynamic rules:
2378 .Pp
2379 .Dl "ipfw add check-state"
2380 .Dl "ipfw add deny tcp from any to any established"
2381 .Dl "ipfw add allow tcp from my-net to any setup keep-state"
2382 .Pp
2383 This will let the firewall install dynamic rules only for
2384 those connection which start with a regular SYN packet coming
2385 from the inside of our network.
2386 Dynamic rules are checked when encountering the first
2387 .Cm check-state
2388 or
2389 .Cm keep-state
2390 rule.
2391 A
2392 .Cm check-state
2393 rule should usually be placed near the beginning of the
2394 ruleset to minimize the amount of work scanning the ruleset.
2395 Your mileage may vary.
2396 .Pp
2397 To limit the number of connections a user can open
2398 you can use the following type of rules:
2399 .Pp
2400 .Dl "ipfw add allow tcp from my-net/24 to any setup limit src-addr 10"
2401 .Dl "ipfw add allow tcp from any to me setup limit src-addr 4"
2402 .Pp
2403 The former (assuming it runs on a gateway) will allow each host
2404 on a /24 network to open at most 10 TCP connections.
2405 The latter can be placed on a server to make sure that a single
2406 client does not use more than 4 simultaneous connections.
2407 .Pp
2408 .Em BEWARE :
2409 stateful rules can be subject to denial-of-service attacks
2410 by a SYN-flood which opens a huge number of dynamic rules.
2411 The effects of such attacks can be partially limited by
2412 acting on a set of
2413 .Xr sysctl 8
2414 variables which control the operation of the firewall.
2415 .Pp
2416 Here is a good usage of the
2417 .Cm list
2418 command to see accounting records and timestamp information:
2419 .Pp
2420 .Dl ipfw -at list
2421 .Pp
2422 or in short form without timestamps:
2423 .Pp
2424 .Dl ipfw -a list
2425 .Pp
2426 which is equivalent to:
2427 .Pp
2428 .Dl ipfw show
2429 .Pp
2430 Next rule diverts all incoming packets from 192.168.2.0/24
2431 to divert port 5000:
2432 .Pp
2433 .Dl ipfw divert 5000 ip from 192.168.2.0/24 to any in
2434 .Pp
2435 .Ss TRAFFIC SHAPING
2436 The following rules show some of the applications of
2437 .Nm
2438 and
2439 .Nm dummynet
2440 for simulations and the like.
2441 .Pp
2442 This rule drops random incoming packets with a probability
2443 of 5%:
2444 .Pp
2445 .Dl "ipfw add prob 0.05 deny ip from any to any in"
2446 .Pp
2447 A similar effect can be achieved making use of
2448 .Nm dummynet
2449 pipes:
2450 .Pp
2451 .Dl "ipfw add pipe 10 ip from any to any"
2452 .Dl "ipfw pipe 10 config plr 0.05"
2453 .Pp
2454 We can use pipes to artificially limit bandwidth, e.g.\& on a
2455 machine acting as a router, if we want to limit traffic from
2456 local clients on 192.168.2.0/24 we do:
2457 .Pp
2458 .Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
2459 .Dl "ipfw pipe 1 config bw 300Kbit/s queue 50KBytes"
2460 .Pp
2461 note that we use the
2462 .Cm out
2463 modifier so that the rule is not used twice.
2464 Remember in fact that
2465 .Nm
2466 rules are checked both on incoming and outgoing packets.
2467 .Pp
2468 Should we want to simulate a bidirectional link with bandwidth
2469 limitations, the correct way is the following:
2470 .Pp
2471 .Dl "ipfw add pipe 1 ip from any to any out"
2472 .Dl "ipfw add pipe 2 ip from any to any in"
2473 .Dl "ipfw pipe 1 config bw 64Kbit/s queue 10Kbytes"
2474 .Dl "ipfw pipe 2 config bw 64Kbit/s queue 10Kbytes"
2475 .Pp
2476 The above can be very useful, e.g.\& if you want to see how
2477 your fancy Web page will look for a residential user who
2478 is connected only through a slow link.
2479 You should not use only one pipe for both directions, unless
2480 you want to simulate a half-duplex medium (e.g.\& AppleTalk,
2481 Ethernet, IRDA).
2482 It is not necessary that both pipes have the same configuration,
2483 so we can also simulate asymmetric links.
2484 .Pp
2485 Should we want to verify network performance with the RED queue
2486 management algorithm:
2487 .Pp
2488 .Dl "ipfw add pipe 1 ip from any to any"
2489 .Dl "ipfw pipe 1 config bw 500Kbit/s queue 100 red 0.002/30/80/0.1"
2490 .Pp
2491 Another typical application of the traffic shaper is to
2492 introduce some delay in the communication.
2493 This can significantly affect applications which do a lot of Remote
2494 Procedure Calls, and where the round-trip-time of the
2495 connection often becomes a limiting factor much more than
2496 bandwidth:
2497 .Pp
2498 .Dl "ipfw add pipe 1 ip from any to any out"
2499 .Dl "ipfw add pipe 2 ip from any to any in"
2500 .Dl "ipfw pipe 1 config delay 250ms bw 1Mbit/s"
2501 .Dl "ipfw pipe 2 config delay 250ms bw 1Mbit/s"
2502 .Pp
2503 Per-flow queueing can be useful for a variety of purposes.
2504 A very simple one is counting traffic:
2505 .Pp
2506 .Dl "ipfw add pipe 1 tcp from any to any"
2507 .Dl "ipfw add pipe 1 udp from any to any"
2508 .Dl "ipfw add pipe 1 ip from any to any"
2509 .Dl "ipfw pipe 1 config mask all"
2510 .Pp
2511 The above set of rules will create queues (and collect
2512 statistics) for all traffic.
2513 Because the pipes have no limitations, the only effect is
2514 collecting statistics.
2515 Note that we need 3 rules, not just the last one, because
2516 when
2517 .Nm
2518 tries to match IP packets it will not consider ports, so we
2519 would not see connections on separate ports as different
2520 ones.
2521 .Pp
2522 A more sophisticated example is limiting the outbound traffic
2523 on a net with per-host limits, rather than per-network limits:
2524 .Pp
2525 .Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
2526 .Dl "ipfw add pipe 2 ip from any to 192.168.2.0/24 in"
2527 .Dl "ipfw pipe 1 config mask src-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
2528 .Dl "ipfw pipe 2 config mask dst-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
2529 .Ss LOOKUP TABLES
2530 In the following example, we need to create several traffic bandwidth
2531 classes and we need different hosts/networks to fall into different classes.
2532 We create one pipe for each class and configure them accordingly.
2533 Then we create a single table and fill it with IP subnets and addresses.
2534 For each subnet/host we set the argument equal to the number of the pipe
2535 that it should use.
2536 Then we classify traffic using a single rule:
2537 .Pp
2538 .Dl "ipfw pipe 1 config bw 1000Kbyte/s"
2539 .Dl "ipfw pipe 4 config bw 4000Kbyte/s"
2540 .Dl "..."
2541 .Dl "ipfw table 1 add 192.168.2.0/24 1"
2542 .Dl "ipfw table 1 add 192.168.0.0/27 4"
2543 .Dl "ipfw table 1 add 192.168.0.2 1"
2544 .Dl "..."
2545 .Dl "ipfw add pipe tablearg ip from table(1) to any"
2546 .Pp
2547 Using the
2548 .Cm fwd
2549 action, the table entries may include hostnames and IP addresses.
2550 .Pp
2551 .Dl "ipfw table 1 add 192.168.2.0/24 10.23.2.1"
2552 .Dl "ipfw table 1 add 192.168.0.0/27 router1.dmz"
2553 .Dl "..."
2554 .Dl "ipfw add 100 fwd tablearg ip from any to table(1)"
2555 .Ss SETS OF RULES
2556 To add a set of rules atomically, e.g.\& set 18:
2557 .Pp
2558 .Dl "ipfw set disable 18"
2559 .Dl "ipfw add NN set 18 ...         # repeat as needed"
2560 .Dl "ipfw set enable 18"
2561 .Pp
2562 To delete a set of rules atomically the command is simply:
2563 .Pp
2564 .Dl "ipfw delete set 18"
2565 .Pp
2566 To test a ruleset and disable it and regain control if something goes wrong:
2567 .Pp
2568 .Dl "ipfw set disable 18"
2569 .Dl "ipfw add NN set 18 ...         # repeat as needed"
2570 .Dl "ipfw set enable 18; echo done; sleep 30 && ipfw set disable 18"
2571 .Pp
2572 Here if everything goes well, you press control-C before the "sleep"
2573 terminates, and your ruleset will be left active.
2574 Otherwise, e.g.\& if
2575 you cannot access your box, the ruleset will be disabled after
2576 the sleep terminates thus restoring the previous situation.
2577 .Pp
2578 To show rules of the specific set:
2579 .Pp
2580 .Dl "ipfw set 18 show"
2581 .Pp
2582 To show rules of the disabled set:
2583 .Pp
2584 .Dl "ipfw -S set 18 show"
2585 .Pp
2586 To clear a specific rule counters of the specific set:
2587 .Pp
2588 .Dl "ipfw set 18 zero NN"
2589 .Pp
2590 To delete a specific rule of the specific set:
2591 .Pp
2592 .Dl "ipfw set 18 delete NN"
2593 .Ss NAT, REDIRECT AND LSNAT
2594 First redirect all the traffic to nat instance 123:
2595 .Pp
2596 .Dl "ipfw add nat 123 all from any to any"
2597 .Pp
2598 Then to configure nat instance 123 to alias all the outgoing traffic with ip
2599 192.168.0.123, blocking all incoming connections, trying to keep
2600 same ports on both sides, clearing aliasing table on address change 
2601 and keeping a log of traffic/link statistics:
2602 .Pp
2603 .Dl "ipfw nat 123 config ip 192.168.0.123 log deny_in reset same_ports"
2604 .Pp
2605 Or to change address of instance 123, aliasing table will be cleared (see
2606 reset option):
2607 .Pp
2608 .Dl "ipfw nat 123 config ip 10.0.0.1"
2609 .Pp
2610 To see configuration of nat instance 123:
2611 .Pp
2612 .Dl "ipfw nat 123 show config"
2613 .Pp
2614 To show logs of all the instances in range 111-999:
2615 .Pp
2616 .Dl "ipfw nat 111-999 show"
2617 .Pp
2618 To see configurations of all instances:
2619 .Pp
2620 .Dl "ipfw nat show config"
2621 .Pp
2622 Or a redirect rule with mixed modes could looks like:
2623 .Pp
2624 .Dl "ipfw nat 123 config redirect_addr 10.0.0.1 10.0.0.66"
2625 .Dl "                    redirect_port tcp 192.168.0.1:80 500"
2626 .Dl "                    redirect_proto udp 192.168.1.43 192.168.1.1"
2627 .Dl "                    redirect_addr 192.168.0.10,192.168.0.11"
2628 .Dl "                               10.0.0.100  # LSNAT"
2629 .Dl "                    redirect_port tcp 192.168.0.1:80,192.168.0.10:22" 
2630 .Dl "                               500         # LSNAT"
2631 .Pp
2632 or it could be splitted in:
2633 .Pp
2634 .Dl "ipfw nat 1 config redirect_addr 10.0.0.1 10.0.0.66"
2635 .Dl "ipfw nat 2 config redirect_port tcp 192.168.0.1:80 500"
2636 .Dl "ipfw nat 3 config redirect_proto udp 192.168.1.43 192.168.1.1"
2637 .Dl "ipfw nat 4 config redirect_addr 192.168.0.10,192.168.0.11,192.168.0.12" 
2638 .Dl "                                    10.0.0.100"
2639 .Dl "ipfw nat 5 config redirect_port tcp"
2640 .Dl "                   192.168.0.1:80,192.168.0.10:22,192.168.0.20:25 500"
2641 .Pp
2642 .Sh SEE ALSO
2643 .Xr cpp 1 ,
2644 .Xr m4 1 ,
2645 .Xr altq 4 ,
2646 .Xr divert 4 ,
2647 .Xr dummynet 4 ,
2648 .Xr if_bridge 4 ,
2649 .Xr ip 4 ,
2650 .Xr ipfirewall 4 ,
2651 .Xr ng_ipfw 4 ,
2652 .Xr protocols 5 ,
2653 .Xr services 5 ,
2654 .Xr init 8 ,
2655 .Xr kldload 8 ,
2656 .Xr reboot 8 ,
2657 .Xr sysctl 8 ,
2658 .Xr syslogd 8
2659 .Sh HISTORY
2660 The
2661 .Nm
2662 utility first appeared in
2663 .Fx 2.0 .
2664 .Nm dummynet
2665 was introduced in
2666 .Fx 2.2.8 .
2667 Stateful extensions were introduced in
2668 .Fx 4.0 .
2669 .Nm ipfw2
2670 was introduced in Summer 2002.
2671 .Sh AUTHORS
2672 .An Ugen J. S. Antsilevich ,
2673 .An Poul-Henning Kamp ,
2674 .An Alex Nash ,
2675 .An Archie Cobbs ,
2676 .An Luigi Rizzo .
2677 .Pp
2678 .An -nosplit
2679 API based upon code written by
2680 .An Daniel Boulet
2681 for BSDI.
2682 .Pp
2683 .An -nosplit
2684 In-kernel NAT support written by
2685 .An Paolo Pisati Aq piso@FreeBSD.org
2686 as part of a Summer of Code 2005 project.
2687 .Pp
2688 Work on
2689 .Nm dummynet
2690 traffic shaper supported by Akamba Corp.
2691 .Sh BUGS
2692 The syntax has grown over the years and sometimes it might be confusing.
2693 Unfortunately, backward compatibility prevents cleaning up mistakes
2694 made in the definition of the syntax.
2695 .Pp
2696 .Em !!! WARNING !!!
2697 .Pp
2698 Misconfiguring the firewall can put your computer in an unusable state,
2699 possibly shutting down network services and requiring console access to
2700 regain control of it.
2701 .Pp
2702 Incoming packet fragments diverted by
2703 .Cm divert
2704 are reassembled before delivery to the socket.
2705 The action used on those packet is the one from the
2706 rule which matches the first fragment of the packet.
2707 .Pp
2708 Packets diverted to userland, and then reinserted by a userland process
2709 may lose various packet attributes.
2710 The packet source interface name
2711 will be preserved if it is shorter than 8 bytes and the userland process
2712 saves and reuses the sockaddr_in
2713 (as does
2714 .Xr natd 8 ) ;
2715 otherwise, it may be lost.
2716 If a packet is reinserted in this manner, later rules may be incorrectly
2717 applied, making the order of
2718 .Cm divert
2719 rules in the rule sequence very important.
2720 .Pp
2721 Dummynet drops all packets with IPv6 link-local addresses.
2722 .Pp
2723 Rules using
2724 .Cm uid
2725 or
2726 .Cm gid
2727 may not behave as expected.
2728 In particular, incoming SYN packets may
2729 have no uid or gid associated with them since they do not yet belong
2730 to a TCP connection, and the uid/gid associated with a packet may not
2731 be as expected if the associated process calls
2732 .Xr setuid 2
2733 or similar system calls.
2734 .Pp
2735 Rule syntax is subject to the command line environment and some patterns
2736 may need to be escaped with the backslash character
2737 or quoted appropriately.
2738 .Pp
2739 Due to the architecture of 
2740 .Xr libalias 3 , 
2741 ipfw nat is not compatible with the tcp segmentation offloading
2742 (TSO). Thus, to reliably nat your network traffic, please disable TSO
2743 on your NICs using
2744 .Xr ifconfig 8 .
2745 .Pp
2746 ICMP error messages are not implicitly matched by dynamic rules
2747 for the respective conversations.
2748 To avoid failures of network error detection and path MTU discovery,
2749 ICMP error messages may need to be allowed explicitly through static
2750 rules.