]> git.saurik.com Git - apple/network_cmds.git/blob - ipfw.tproj/ipfw.8
4136a3fe994bae78d0f63d38ac8b3ce07c0ca73a
[apple/network_cmds.git] / ipfw.tproj / ipfw.8
1 .\"
2 .\" $FreeBSD: /repoman/r/ncvs/src/sbin/ipfw/ipfw.8,v 1.63.2.38 2003/07/28 07:15:13 luigi Exp $
3 .\"
4 .Dd August 13, 2002
5 .Dt IPFW 8
6 .Os Darwin
7 .Sh NAME
8 .Nm ipfw
9 .Nd IP firewall and traffic shaper control program
10 (DEPRECATED)
11 .Sh SYNOPSIS
12 .Nm
13 .Op Fl cq
14 .Cm add
15 .Ar rule
16 .Nm
17 .Op Fl acdefnNStT
18 .Brq Cm list | show
19 .Op Ar rule | first-last ...
20 .Nm
21 .Op Fl f | q
22 .Cm flush
23 .Nm
24 .Op Fl q
25 .Brq Cm delete | zero | resetlog
26 .Op Cm set
27 .Op Ar number ...
28 .Nm
29 .Cm enable
30 .Brq Cm firewall | one_pass | debug | verbose | dyn_keepalive
31 .Nm
32 .Cm disable
33 .Brq Cm firewall | one_pass | debug | verbose | dyn_keepalive
34 .Pp
35 .Nm
36 .Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
37 .Nm
38 .Cm set move
39 .Op Cm rule
40 .Ar number Cm to Ar number
41 .Nm
42 .Cm set swap Ar number number
43 .Nm
44 .Cm set show
45 .Pp
46 .Nm
47 .Brq Cm pipe | queue
48 .Ar number
49 .Cm config
50 .Ar config-options
51 .Nm
52 .Op Fl s Op Ar field
53 .Brq Cm pipe | queue
54 .Brq Cm delete | list | show
55 .Op Ar number ...
56 .Pp
57 .Nm
58 .Op Fl cnNqS
59 .Oo
60 .Fl p Ar preproc
61 .Oo
62 .Ar preproc-flags
63 .Oc
64 .Oc
65 .Ar pathname
66 .Sh DESCRIPTION
67 Note that use of this utility is
68 .Cm DEPRECATED.
69 Please use
70 .Xr pfctl 8
71 instead.
72 .Pp
73 The
74 .Nm
75 utility is the user interface for controlling the
76 .Xr ipfw 4
77 firewall and the
78 .Xr dummynet 4
79 traffic shaper.
80 .Pp
81 An
82 .Nm
83 configuration, or
84 .Em ruleset ,
85 is made of a list of
86 .Em rules
87 numbered from 1 to 65535.
88 Packets are passed to
89 .Nm
90 from a number of different places in the protocol stack
91 (depending on the source and destination of the packet,
92 it is possible that
93 .Nm
94 is invoked multiple times on the same packet).
95 The packet passed to the firewall is compared
96 against each of the rules in the firewall
97 .Em ruleset .
98 When a match is found, the action corresponding to the
99 matching rule is performed.
100 .Pp
101 Depending on the action and certain system settings, packets
102 can be reinjected into the firewall at some rule after the
103 matching one for further processing.
104 .Pp
105 An
106 .Nm
107 ruleset always includes a
108 .Em default
109 rule (numbered 65535) which cannot be modified or deleted,
110 and matches all packets.
111 The action associated with the
112 .Em default
113 rule can be either
114 .Cm deny
115 or
116 .Cm allow
117 depending on how the kernel is configured.
118 .Pp
119 If the ruleset includes one or more rules with the
120 .Cm keep-state
121 or
122 .Cm limit
123 option, then
124 .Nm
125 assumes a
126 .Em stateful
127 behaviour, i.e. upon a match it will create dynamic rules matching
128 the exact parameters (addresses and ports) of the matching packet.
129 .Pp
130 These dynamic rules, which have a limited lifetime, are checked
131 at the first occurrence of a
132 .Cm check-state ,
133 .Cm keep-state
134 or
135 .Cm limit
136 rule, and are typically used to open the firewall on-demand to
137 legitimate traffic only.
138 See the
139 .Sx STATEFUL FIREWALL
140 and
141 .Sx EXAMPLES
142 Sections below for more information on the stateful behaviour of
143 .Nm .
144 .Pp
145 All rules (including dynamic ones) have a few associated counters:
146 a packet count, a byte count, a log count and a timestamp
147 indicating the time of the last match.
148 Counters can be displayed or reset with
149 .Nm
150 commands.
151 .Pp
152 Rules can be added with the
153 .Cm add
154 command; deleted individually or in groups with the
155 .Cm delete
156 command, and globally (except those in set 31) with the
157 .Cm flush
158 command; displayed, optionally with the content of the
159 counters, using the
160 .Cm show
161 and
162 .Cm list
163 commands.
164 Finally, counters can be reset with the
165 .Cm zero
166 and
167 .Cm resetlog
168 commands.
169 .Pp
170 Also, each rule belongs to one of 32 different
171 .Em sets
172 , and there are
173 .Nm
174 commands to atomically manipulate sets, such as enable,
175 disable, swap sets, move all rules in a set to another
176 one, delete all rules in a set. These can be useful to
177 install temporary configurations, or to test them.
178 See Section
179 .Sx SETS OF RULES
180 for more information on
181 .Em sets .
182 .Pp
183 The following options are available:
184 .Bl -tag -width indent
185 .It Fl a
186 While listing, show counter values.
187 The
188 .Cm show
189 command just implies this option.
190 .It Fl c
191 When entering or showing rules, print them in compact form,
192 i.e. without the optional "ip from any to any" string
193 when this does not carry any additional information.
194 .It Fl d
195 While listing, show dynamic rules in addition to static ones.
196 .It Fl e
197 While listing, if the
198 .Fl d
199 option was specified, also show expired dynamic rules.
200 .It Fl f
201 Don't ask for confirmation for commands that can cause problems
202 if misused,
203 .No i.e. Cm flush .
204 If there is no tty associated with the process, this is implied.
205 .It Fl n
206 Only check syntax of the command strings, without actually passing
207 them to the kernel.
208 .It Fl N
209 Try to resolve addresses and service names in output.
210 .It Fl q
211 While
212 .Cm add Ns ing ,
213 .Cm zero Ns ing ,
214 .Cm resetlog Ns ging
215 or
216 .Cm flush Ns ing ,
217 be quiet about actions
218 (implies
219 .Fl f ) .
220 This is useful for adjusting rules by executing multiple
221 .Nm
222 commands in a script
223 (e.g.,
224 .Ql sh\ /etc/rc.firewall ) ,
225 or by processing a file of many
226 .Nm
227 rules across a remote login session.
228 If a
229 .Cm flush
230 is performed in normal (verbose) mode (with the default kernel
231 configuration), it prints a message.
232 Because all rules are flushed, the message might not be delivered
233 to the login session, causing the remote login session to be closed
234 and the remainder of the ruleset to not be processed.
235 Access to the console would then be required to recover.
236 .It Fl S
237 While listing rules, show the
238 .Em set
239 each rule belongs to.
240 If this flag is not specified, disabled rules will not be
241 listed.
242 .It Fl s Op Ar field
243 While listing pipes, sort according to one of the four
244 counters (total or current packets or bytes).
245 .It Fl t
246 While listing, show last match timestamp (converted with ctime()).
247 .It Fl T
248 While listing, show last match timestamp (as seconds from the epoch).
249 This form can be more convenient for postprocessing by scripts.
250 .El
251 .Pp
252 To ease configuration, rules can be put into a file which is
253 processed using
254 .Nm
255 as shown in the last synopsis line.
256 An absolute
257 .Ar pathname
258 must be used.
259 The file will be read line by line and applied as arguments to the
260 .Nm
261 utility.
262 .Pp
263 Optionally, a preprocessor can be specified using
264 .Fl p Ar preproc
265 where
266 .Ar pathname
267 is to be piped through.
268 Useful preprocessors include
269 .Xr cpp 1
270 and
271 .Xr m4 1 .
272 If
273 .Ar preproc
274 doesn't start with a slash
275 .Pq Ql /
276 as its first character, the usual
277 .Ev PATH
278 name search is performed.
279 Care should be taken with this in environments where not all
280 file systems are mounted (yet) by the time
281 .Nm
282 is being run (e.g. when they are mounted over NFS).
283 Once
284 .Fl p
285 has been specified, any additional arguments as passed on to the preprocessor
286 for interpretation.
287 This allows for flexible configuration files (like conditionalizing
288 them on the local hostname) and the use of macros to centralize
289 frequently required arguments like IP addresses.
290 .Pp
291 The
292 .Nm
293 .Cm pipe
294 and
295 .Cm queue
296 commands are used to configure the traffic shaper, as shown in the
297 .Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
298 Section below.
299 .Pp
300 If the world and the kernel get out of sync the
301 .Nm
302 ABI may break, preventing you from being able to add any rules. This can
303 adversely effect the booting process. You can use
304 .Nm
305 .Cm disable
306 .Cm firewall
307 to temporarily disable the firewall to regain access to the network,
308 allowing you to fix the problem.
309 .Sh PACKET FLOW
310 A packet is checked against the active ruleset in multiple places
311 in the protocol stack, under control of several sysctl variables.
312 These places and variables are shown below, and it is important to
313 have this picture in mind in order to design a correct ruleset.
314 .Bd -literal -offset indent
315 ^ to upper layers V
316 | |
317 +----------->-----------+
318 ^ V
319 [ip_input] [ip_output] net.inet.ip.fw.enable=1
320 | |
321 ^ V
322 [ether_demux] [ether_output_frame] net.link.ether.ipfw=1
323 | |
324 +-->--[bdg_forward]-->--+ net.link.ether.bridge_ipfw=1
325 ^ V
326 | to devices |
327 .Ed
328 .Pp
329 As can be noted from the above picture, the number of
330 times the same packet goes through the firewall can
331 vary between 0 and 4 depending on packet source and
332 destination, and system configuration.
333 .Pp
334 Note that as packets flow through the stack, headers can be
335 stripped or added to it, and so they may or may not be available
336 for inspection.
337 E.g., incoming packets will include the MAC header when
338 .Nm
339 is invoked from
340 .Cm ether_demux() ,
341 but the same packets will have the MAC header stripped off when
342 .Nm
343 is invoked from
344 .Cm ip_input() .
345 .Pp
346 Also note that each packet is always checked against the complete ruleset,
347 irrespective of the place where the check occurs, or the source of the packet.
348 If a rule contains some match patterns or actions which are not valid
349 for the place of invocation (e.g. trying to match a MAC header within
350 .Cm ip_input()
351 ), the match pattern will not match, but a
352 .Cm not
353 operator in front of such patterns
354 .Em will
355 cause the pattern to
356 .Em always
357 match on those packets.
358 It is thus the responsibility of
359 the programmer, if necessary, to write a suitable ruleset to
360 differentiate among the possible places.
361 .Cm skipto
362 rules can be useful here, as an example:
363 .Bd -literal -offset indent
364 # packets from ether_demux or bdg_forward
365 ipfw add 10 skipto 1000 all from any to any layer2 in
366 # packets from ip_input
367 ipfw add 10 skipto 2000 all from any to any not layer2 in
368 # packets from ip_output
369 ipfw add 10 skipto 3000 all from any to any not layer2 out
370 # packets from ether_output_frame
371 ipfw add 10 skipto 4000 all from any to any layer2 out
372 .Ed
373 .Pp
374 (yes, at the moment there is no way to differentiate between
375 ether_demux and bdg_forward).
376 .Sh SYNTAX
377 In general, each keyword or argument must be provided as
378 a separate command line argument, with no leading or trailing
379 spaces. Keywords are case-sensitive, whereas arguments may
380 or may not be case-sensitive depending on their nature
381 (e.g. uid's are, hostnames are not).
382 .Pp
383 In
384 .Nm ipfw2
385 you can introduce spaces after commas ',' to make
386 the line more readable. You can also put the entire
387 command (including flags) into a single argument.
388 E.g. the following forms are equivalent:
389 .Bd -literal -offset indent
390 ipfw -q add deny src-ip 10.0.0.0/24,127.0.0.1/8
391 ipfw -q add deny src-ip 10.0.0.0/24, 127.0.0.1/8
392 ipfw "-q add deny src-ip 10.0.0.0/24, 127.0.0.1/8"
393 .Ed
394 .Sh RULE FORMAT
395 The format of
396 .Nm
397 rules is the following:
398 .Bd -ragged -offset indent
399 .Op Ar rule_number
400 .Op Cm set Ar set_number
401 .Op Cm prob Ar match_probability
402 .br
403 .Ar " " action
404 .Op Cm log Op Cm logamount Ar number
405 .Ar body
406 .Ed
407 .Pp
408 where the body of the rule specifies which information is used
409 for filtering packets, among the following:
410 .Pp
411 .Bl -tag -width "Source and dest. addresses and ports" -offset XXX -compact
412 .It Layer-2 header fields
413 When available
414 .It IPv4 Protocol
415 TCP, UDP, ICMP, etc.
416 .It Source and dest. addresses and ports
417 .It Direction
418 See Section
419 .Sx PACKET FLOW
420 .It Transmit and receive interface
421 By name or address
422 .It Misc. IP header fields
423 Version, type of service, datagram length, identification,
424 fragment flag (non-zero IP offset),
425 Time To Live
426 .It IP options
427 .It Misc. TCP header fields
428 TCP flags (SYN, FIN, ACK, RST, etc.),
429 sequence number, acknowledgment number,
430 window
431 .It TCP options
432 .It ICMP types
433 for ICMP packets
434 .It User/group ID
435 When the packet can be associated with a local socket.
436 .El
437 .Pp
438 Note that some of the above information, e.g. source MAC or IP addresses and
439 TCP/UDP ports, could easily be spoofed, so filtering on those fields
440 alone might not guarantee the desired results.
441 .Bl -tag -width indent
442 .It Ar rule_number
443 Each rule is associated with a
444 .Ar rule_number
445 in the range 1..65535, with the latter reserved for the
446 .Em default
447 rule.
448 Rules are checked sequentially by rule number.
449 Multiple rules can have the same number, in which case they are
450 checked (and listed) according to the order in which they have
451 been added.
452 If a rule is entered without specifying a number, the kernel will
453 assign one in such a way that the rule becomes the last one
454 before the
455 .Em default
456 rule.
457 Automatic rule numbers are assigned by incrementing the last
458 non-default rule number by the value of the sysctl variable
459 .Ar net.inet.ip.fw.autoinc_step
460 which defaults to 100.
461 If this is not possible (e.g. because we would go beyond the
462 maximum allowed rule number), the number of the last
463 non-default value is used instead.
464 .It Cm set Ar set_number
465 Each rule is associated with a
466 .Ar set_number
467 in the range 0..31.
468 Sets can be individually disabled and enabled, so this parameter
469 is of fundamental importance for atomic ruleset manipulation.
470 It can be also used to simplify deletion of groups of rules.
471 If a rule is entered without specifying a set number,
472 set 0 will be used.
473 .br
474 Set 31 is special in that it cannot be disabled,
475 and rules in set 31 are not deleted by the
476 .Nm ipfw flush
477 command (but you can delete them with the
478 .Nm ipfw delete set 31
479 command).
480 Set 31 is also used for the
481 .Em default
482 rule.
483 .It Cm prob Ar match_probability
484 A match is only declared with the specified probability
485 (floating point number between 0 and 1).
486 This can be useful for a number of applications such as
487 random packet drop or
488 (in conjunction with
489 .Xr dummynet 4 )
490 to simulate the effect of multiple paths leading to out-of-order
491 packet delivery.
492 .Pp
493 Note: this condition is checked before any other condition, including
494 ones such as keep-state or check-state which might have side effects.
495 .It Cm log Op Cm logamount Ar number
496 When a packet matches a rule with the
497 .Cm log
498 keyword, a message will be
499 logged to
500 .Xr syslogd 8
501 with a
502 .Dv LOG_SECURITY
503 facility.
504 The logging only occurs if the sysctl variable
505 .Em net.inet.ip.fw.verbose
506 is set to 1
507 (which is the default when the kernel is compiled with
508 .Dv IPFIREWALL_VERBOSE
509 ) and the number of packets logged so far for that
510 particular rule does not exceed the
511 .Cm logamount
512 parameter.
513 If no
514 .Cm logamount
515 is specified, the limit is taken from the sysctl variable
516 .Em net.inet.ip.fw.verbose_limit .
517 In both cases, a value of 0 removes the logging limit.
518 .Pp
519 Once the limit is reached, logging can be re-enabled by
520 clearing the logging counter or the packet counter for that entry, see the
521 .Cm resetlog
522 command.
523 .Pp
524 Note: logging is done after all other packet matching conditions
525 have been successfully verified, and before performing the final
526 action (accept, deny, etc.) on the packet.
527 .El
528 .Ss RULE ACTIONS
529 A rule can be associated with one of the following actions, which
530 will be executed when the packet matches the body of the rule.
531 .Bl -tag -width indent
532 .It Cm allow | accept | pass | permit
533 Allow packets that match rule.
534 The search terminates.
535 .It Cm check-state
536 Checks the packet against the dynamic ruleset.
537 If a match is found, execute the action associated with
538 the rule which generated this dynamic rule, otherwise
539 move to the next rule.
540 .br
541 .Cm Check-state
542 rules do not have a body.
543 If no
544 .Cm check-state
545 rule is found, the dynamic ruleset is checked at the first
546 .Cm keep-state
547 or
548 .Cm limit
549 rule.
550 .It Cm count
551 Update counters for all packets that match rule.
552 The search continues with the next rule.
553 .It Cm deny | drop
554 Discard packets that match this rule.
555 The search terminates.
556 .It Cm divert Ar port
557 Divert packets that match this rule to the
558 .Xr divert 4
559 socket bound to port
560 .Ar port .
561 The search terminates.
562 .It Cm fwd | forward Ar ipaddr Ns Op , Ns Ar port
563 Change the next-hop on matching packets to
564 .Ar ipaddr ,
565 which can be an IP address in dotted quad format or a host name.
566 The search terminates if this rule matches.
567 .Pp
568 If
569 .Ar ipaddr
570 is a local address, then matching packets will be forwarded to
571 .Ar port
572 (or the port number in the packet if one is not specified in the rule)
573 on the local machine.
574 .br
575 If
576 .Ar ipaddr
577 is not a local address, then the port number
578 (if specified) is ignored, and the packet will be
579 forwarded to the remote address, using the route as found in
580 the local routing table for that IP.
581 .br
582 A
583 .Ar fwd
584 rule will not match layer-2 packets (those received
585 on ether_input, ether_output, or bridged).
586 .br
587 The
588 .Cm fwd
589 action does not change the contents of the packet at all.
590 In particular, the destination address remains unmodified, so
591 packets forwarded to another system will usually be rejected by that system
592 unless there is a matching rule on that system to capture them.
593 For packets forwarded locally,
594 the local address of the socket will be
595 set to the original destination address of the packet.
596 This makes the
597 .Xr netstat 1
598 entry look rather weird but is intended for
599 use with transparent proxy servers.
600 .It Cm pipe Ar pipe_nr
601 Pass packet to a
602 .Xr dummynet 4
603 .Dq pipe
604 (for bandwidth limitation, delay, etc.).
605 See the
606 .Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
607 Section for further information.
608 The search terminates; however, on exit from the pipe and if
609 the
610 .Xr sysctl 8
611 variable
612 .Em net.inet.ip.fw.one_pass
613 is not set, the packet is passed again to the firewall code
614 starting from the next rule.
615 .It Cm queue Ar queue_nr
616 Pass packet to a
617 .Xr dummynet 4
618 .Dq queue
619 (for bandwidth limitation using WF2Q+).
620 .It Cm reject
621 (Deprecated).
622 Synonym for
623 .Cm unreach host .
624 .It Cm reset
625 Discard packets that match this rule, and if the
626 packet is a TCP packet, try to send a TCP reset (RST) notice.
627 The search terminates.
628 .It Cm skipto Ar number
629 Skip all subsequent rules numbered less than
630 .Ar number .
631 The search continues with the first rule numbered
632 .Ar number
633 or higher.
634 .It Cm tee Ar port
635 Send a copy of packets matching this rule to the
636 .Xr divert 4
637 socket bound to port
638 .Ar port .
639 The search terminates and the original packet is accepted
640 (but see Section
641 .Sx BUGS
642 below).
643 .It Cm unreach Ar code
644 Discard packets that match this rule, and try to send an ICMP
645 unreachable notice with code
646 .Ar code ,
647 where
648 .Ar code
649 is a number from 0 to 255, or one of these aliases:
650 .Cm net , host , protocol , port ,
651 .Cm needfrag , srcfail , net-unknown , host-unknown ,
652 .Cm isolated , net-prohib , host-prohib , tosnet ,
653 .Cm toshost , filter-prohib , host-precedence
654 or
655 .Cm precedence-cutoff .
656 The search terminates.
657 .El
658 .Ss RULE BODY
659 The body of a rule contains zero or more patterns (such as
660 specific source and destination addresses or ports,
661 protocol options, incoming or outgoing interfaces, etc.)
662 that the packet must match in order to be recognised.
663 In general, the patterns are connected by (implicit)
664 .Cm and
665 operators -- i.e. all must match in order for the
666 rule to match.
667 Individual patterns can be prefixed by the
668 .Cm not
669 operator to reverse the result of the match, as in
670 .Pp
671 .Dl "ipfw add 100 allow ip from not 1.2.3.4 to any"
672 .Pp
673 Additionally, sets of alternative match patterns (
674 .Em or-blocks
675 ) can be constructed by putting the patterns in
676 lists enclosed between parentheses ( ) or braces { }, and
677 using the
678 .Cm or
679 operator as follows:
680 .Pp
681 .Dl "ipfw add 100 allow ip from { x or not y or z } to any"
682 .Pp
683 Only one level of parentheses is allowed.
684 Beware that most shells have special meanings for parentheses
685 or braces, so it is advisable to put a backslash \\ in front of them
686 to prevent such interpretations.
687 .Pp
688 The body of a rule must in general include a source and destination
689 address specifier.
690 The keyword
691 .Ar any
692 can be used in various places to specify that the content of
693 a required field is irrelevant.
694 .Pp
695 The rule body has the following format:
696 .Bd -ragged -offset indent
697 .Op Ar proto Cm from Ar src Cm to Ar dst
698 .Op Ar options
699 .Ed
700 .Pp
701 The first part (proto from src to dst) is for backward
702 compatibility with
703 .Nm ipfw1 .
704 In
705 .Nm ipfw2
706 any match pattern (including MAC headers, IPv4 protocols,
707 addresses and ports) can be specified in the
708 .Ar options
709 section.
710 .Pp
711 Rule fields have the following meaning:
712 .Bl -tag -width indent
713 .It Ar proto : protocol | Cm { Ar protocol Cm or ... }
714 .It Ar protocol : Oo Cm not Oc Ar protocol-name | protocol-number
715 An IPv4 protocol specified by number or name
716 (for a complete list see
717 .Pa /etc/protocols ) .
718 The
719 .Cm ip
720 or
721 .Cm all
722 keywords mean any protocol will match.
723 .Pp
724 The
725 .Cm { Ar protocol Cm or ... }
726 format (an
727 .Em or-block )
728 is provided for convenience only but its use is deprecated.
729 .It Ar src No and Ar dst : Bro Cm addr | Cm { Ar addr Cm or ... } Brc Op Oo Cm not Oc Ar ports
730 An address (or a list, see below)
731 optionally followed by
732 .Ar ports
733 specifiers.
734 .Pp
735 The second format (
736 .Em or-block
737 with multiple addresses) is provided for convenience only and
738 its use is discouraged.
739 .It Ar addr : Oo Cm not Oc Brq Cm any | me | Ar addr-list | Ar addr-set
740 .It Cm any
741 matches any IP address.
742 .It Cm me
743 matches any IP address configured on an interface in the system.
744 The address list is evaluated at the time the packet is
745 analysed.
746 .It Ar addr-list : ip-addr Ns Op Ns , Ns Ar addr-list
747 .It Ar ip-addr :
748 A host or subnet address specified in one of the following ways:
749 .Bl -tag -width indent
750 .It Ar numeric-ip | hostname
751 Matches a single IPv4 address, specified as dotted-quad or a hostname.
752 Hostnames are resolved at the time the rule is added to the firewall list.
753 .It Ar addr Ns / Ns Ar masklen
754 Matches all addresses with base
755 .Ar addr
756 (specified as a dotted quad or a hostname)
757 and mask width of
758 .Cm masklen
759 bits.
760 As an example, 1.2.3.4/25 will match
761 all IP numbers from 1.2.3.0 to 1.2.3.127 .
762 .It Ar addr Ns : Ns Ar mask
763 Matches all addresses with base
764 .Ar addr
765 (specified as a dotted quad or a hostname)
766 and the mask of
767 .Ar mask ,
768 specified as a dotted quad.
769 As an example, 1.2.3.4/255.0.255.0 will match
770 1.*.3.*.
771 We suggest to use this form only for non-contiguous
772 masks, and resort to the
773 .Ar addr Ns / Ns Ar masklen
774 format for contiguous masks, which is more compact and less
775 error-prone.
776 .El
777 .It Ar addr-set : addr Ns Oo Ns / Ns Ar masklen Oc Ns Cm { Ns Ar list Ns Cm }
778 .It Ar list : Bro Ar num | num-num Brc Ns Op Ns , Ns Ar list
779 Matches all addresses with base address
780 .Ar addr
781 (specified as a dotted quad or a hostname)
782 and whose last byte is in the list between braces { } .
783 Note that there must be no spaces between braces and
784 numbers (spaces after commas are allowed).
785 Elements of the list can be specified as single entries
786 or ranges.
787 The
788 .Ar masklen
789 field is used to limit the size of the set of addresses,
790 and can have any value between 24 and 32. If not specified,
791 it will be assumed as 24.
792 .br
793 This format is particularly useful to handle sparse address sets
794 within a single rule. Because the matching occurs using a
795 bitmask, it takes constant time and dramatically reduces
796 the complexity of rulesets.
797 .br
798 As an example, an address specified as 1.2.3.4/24{128,35-55,89}
799 will match the following IP addresses:
800 .br
801 1.2.3.128, 1.2.3.35 to 1.2.3.55, 1.2.3.89 .
802 .It Ar ports : Bro Ar port | port Ns \&- Ns Ar port Ns Brc Ns Op , Ns Ar ports
803 For protocols which support port numbers (such as TCP and UDP), optional
804 .Cm ports
805 may be specified as one or more ports or port ranges, separated
806 by commas but no spaces, and an optional
807 .Cm not
808 operator.
809 The
810 .Ql \&-
811 notation specifies a range of ports (including boundaries).
812 .Pp
813 Service names (from
814 .Pa /etc/services )
815 may be used instead of numeric port values.
816 The length of the port list is limited to 30 ports or ranges,
817 though one can specify larger ranges by using an
818 .Em or-block
819 in the
820 .Cm options
821 section of the rule.
822 .Pp
823 A backslash
824 .Pq Ql \e
825 can be used to escape the dash
826 .Pq Ql -
827 character in a service name (from a shell, the backslash must be
828 typed twice to avoid the shell itself interpreting it as an escape
829 character).
830 .Pp
831 .Dl "ipfw add count tcp from any ftp\e\e-data-ftp to any"
832 .Pp
833 Fragmented packets which have a non-zero offset (i.e. not the first
834 fragment) will never match a rule which has one or more port
835 specifications.
836 See the
837 .Cm frag
838 option for details on matching fragmented packets.
839 .El
840 .Ss RULE OPTIONS (MATCH PATTERNS)
841 Additional match patterns can be used within
842 rules. Zero or more of these so-called
843 .Em options
844 can be present in a rule, optionally prefixed by the
845 .Cm not
846 operand, and possibly grouped into
847 .Em or-blocks .
848 .Pp
849 The following match patterns can be used (listed in alphabetical order):
850 .Bl -tag -width indent
851 .It Cm // this is a comment.
852 Inserts the specified text as a comment in the rule.
853 Everything following // is considered as a comment and stored in the rule.
854 You can have comment-only rules, which are listed as having a
855 .Cm count
856 action followed by the comment.
857 .It Cm bridged
858 Matches only bridged packets.
859 .It Cm dst-ip Ar ip-address
860 Matches IP packets whose destination IP is one of the address(es)
861 specified as argument.
862 .It Cm dst-port Ar ports
863 Matches IP packets whose destination port is one of the port(s)
864 specified as argument.
865 .It Cm established
866 Matches TCP packets that have the RST or ACK bits set.
867 .It Cm frag
868 Matches packets that are fragments and not the first
869 fragment of an IP datagram. Note that these packets will not have
870 the next protocol header (e.g. TCP, UDP) so options that look into
871 these headers cannot match.
872 .It Cm gid Ar group
873 Matches all TCP or UDP packets sent by or received for a
874 .Ar group .
875 A
876 .Ar group
877 may be specified by name or number.
878 .It Cm icmptypes Ar types
879 Matches ICMP packets whose ICMP type is in the list
880 .Ar types .
881 The list may be specified as any combination of
882 individual types (numeric) separated by commas.
883 .Em Ranges are not allowed.
884 The supported ICMP types are:
885 .Pp
886 echo reply
887 .Pq Cm 0 ,
888 destination unreachable
889 .Pq Cm 3 ,
890 source quench
891 .Pq Cm 4 ,
892 redirect
893 .Pq Cm 5 ,
894 echo request
895 .Pq Cm 8 ,
896 router advertisement
897 .Pq Cm 9 ,
898 router solicitation
899 .Pq Cm 10 ,
900 time-to-live exceeded
901 .Pq Cm 11 ,
902 IP header bad
903 .Pq Cm 12 ,
904 timestamp request
905 .Pq Cm 13 ,
906 timestamp reply
907 .Pq Cm 14 ,
908 information request
909 .Pq Cm 15 ,
910 information reply
911 .Pq Cm 16 ,
912 address mask request
913 .Pq Cm 17
914 and address mask reply
915 .Pq Cm 18 .
916 .It Cm in | out
917 Matches incoming or outgoing packets, respectively.
918 .Cm in
919 and
920 .Cm out
921 are mutually exclusive (in fact,
922 .Cm out
923 is implemented as
924 .Cm not in Ns No ).
925 .It Cm ipid Ar id-list
926 Matches IP packets whose
927 .Cm ip_id
928 field has value included in
929 .Ar id-list ,
930 which is either a single value or a list of values or ranges
931 specified in the same way as
932 .Ar ports .
933 .It Cm iplen Ar len-list
934 Matches IP packets whose total length, including header and data, is
935 in the set
936 .Ar len-list ,
937 which is either a single value or a list of values or ranges
938 specified in the same way as
939 .Ar ports .
940 .It Cm ipoptions Ar spec
941 Matches packets whose IP header contains the comma separated list of
942 options specified in
943 .Ar spec .
944 The supported IP options are:
945 .Pp
946 .Cm ssrr
947 (strict source route),
948 .Cm lsrr
949 (loose source route),
950 .Cm rr
951 (record packet route) and
952 .Cm ts
953 (timestamp).
954 The absence of a particular option may be denoted
955 with a
956 .Ql \&! .
957 .It Cm ipprecedence Ar precedence
958 Matches IP packets whose precedence field is equal to
959 .Ar precedence .
960 .It Cm ipsec
961 Matches packets that have IPSEC history associated with them
962 (i.e. the packet comes encapsulated in IPSEC, the kernel
963 has IPSEC support and IPSEC_FILTERGIF option, and can correctly
964 decapsulate it).
965 .Pp
966 Note that specifying
967 .Cm ipsec
968 is different from specifying
969 .Cm proto Ar ipsec
970 as the latter will only look at the specific IP protocol field,
971 irrespective of IPSEC kernel support and the validity of the IPSEC data.
972 .It Cm iptos Ar spec
973 Matches IP packets whose
974 .Cm tos
975 field contains the comma separated list of
976 service types specified in
977 .Ar spec .
978 The supported IP types of service are:
979 .Pp
980 .Cm lowdelay
981 .Pq Dv IPTOS_LOWDELAY ,
982 .Cm throughput
983 .Pq Dv IPTOS_THROUGHPUT ,
984 .Cm reliability
985 .Pq Dv IPTOS_RELIABILITY ,
986 .Cm mincost
987 .Pq Dv IPTOS_MINCOST ,
988 .Cm congestion
989 .Pq Dv IPTOS_CE .
990 The absence of a particular type may be denoted
991 with a
992 .Ql \&! .
993 .It Cm ipttl Ar ttl-list
994 Matches IP packets whose time to live is included in
995 .Ar ttl-list ,
996 which is either a single value or a list of values or ranges
997 specified in the same way as
998 .Ar ports .
999 .It Cm ipversion Ar ver
1000 Matches IP packets whose IP version field is
1001 .Ar ver .
1002 .It Cm keep-state
1003 Upon a match, the firewall will create a dynamic rule, whose
1004 default behaviour is to match bidirectional traffic between
1005 source and destination IP/port using the same protocol.
1006 The rule has a limited lifetime (controlled by a set of
1007 .Xr sysctl 8
1008 variables), and the lifetime is refreshed every time a matching
1009 packet is found.
1010 .It Cm layer2
1011 Matches only layer2 packets, i.e. those passed to
1012 .Nm
1013 from ether_demux() and ether_output_frame().
1014 .It Cm limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N
1015 The firewall will only allow
1016 .Ar N
1017 connections with the same
1018 set of parameters as specified in the rule.
1019 One or more
1020 of source and destination addresses and ports can be
1021 specified.
1022 .It Cm { MAC | mac } Ar dst-mac src-mac
1023 Match packets with a given
1024 .Ar dst-mac
1025 and
1026 .Ar src-mac
1027 addresses, specified as the
1028 .Cm any
1029 keyword (matching any MAC address), or six groups of hex digits
1030 separated by colons,
1031 and optionally followed by a mask indicating how many bits are
1032 significant, as in
1033 .Pp
1034 .Dl "MAC 10:20:30:40:50:60/33 any"
1035 .Pp
1036 Note that the order of MAC addresses (destination first,
1037 source second) is
1038 the same as on the wire, but the opposite of the one used for
1039 IP addresses.
1040 .It Cm mac-type Ar mac-type
1041 Matches packets whose Ethernet Type field
1042 corresponds to one of those specified as argument.
1043 .Ar mac-type
1044 is specified in the same way as
1045 .Cm port numbers
1046 (i.e. one or more comma-separated single values or ranges).
1047 You can use symbolic names for known values such as
1048 .Em vlan , ipv4, ipv6 .
1049 Values can be entered as decimal or hexadecimal (if prefixed by 0x),
1050 and they are always printed as hexadecimal (unless the
1051 .Cm -N
1052 option is used, in which case symbolic resolution will be attempted).
1053 .It Cm proto Ar protocol
1054 Matches packets with the corresponding IPv4 protocol.
1055 .It Cm recv | xmit | via Brq Ar ifX | Ar if Ns Cm * | Ar ipno | Ar any
1056 Matches packets received, transmitted or going through,
1057 respectively, the interface specified by exact name
1058 .Ns No ( Ar ifX Ns No ),
1059 by device name
1060 .Ns No ( Ar if Ns Ar * Ns No ),
1061 by IP address, or through some interface.
1062 .Pp
1063 The
1064 .Cm via
1065 keyword causes the interface to always be checked.
1066 If
1067 .Cm recv
1068 or
1069 .Cm xmit
1070 is used instead of
1071 .Cm via ,
1072 then only the receive or transmit interface (respectively)
1073 is checked.
1074 By specifying both, it is possible to match packets based on
1075 both receive and transmit interface, e.g.:
1076 .Pp
1077 .Dl "ipfw add deny ip from any to any out recv ed0 xmit ed1"
1078 .Pp
1079 The
1080 .Cm recv
1081 interface can be tested on either incoming or outgoing packets,
1082 while the
1083 .Cm xmit
1084 interface can only be tested on outgoing packets.
1085 So
1086 .Cm out
1087 is required (and
1088 .Cm in
1089 is invalid) whenever
1090 .Cm xmit
1091 is used.
1092 .Pp
1093 A packet may not have a receive or transmit interface: packets
1094 originating from the local host have no receive interface,
1095 while packets destined for the local host have no transmit
1096 interface.
1097 .It Cm setup
1098 Matches TCP packets that have the SYN bit set but no ACK bit.
1099 This is the short form of
1100 .Dq Li tcpflags\ syn,!ack .
1101 .It Cm src-ip Ar ip-address
1102 Matches IP packets whose source IP is one of the address(es)
1103 specified as argument.
1104 .It Cm src-port Ar ports
1105 Matches IP packets whose source port is one of the port(s)
1106 specified as argument.
1107 .It Cm tcpack Ar ack
1108 TCP packets only.
1109 Match if the TCP header acknowledgment number field is set to
1110 .Ar ack .
1111 .It Cm tcpflags Ar spec
1112 TCP packets only.
1113 Match if the TCP header contains the comma separated list of
1114 flags specified in
1115 .Ar spec .
1116 The supported TCP flags are:
1117 .Pp
1118 .Cm fin ,
1119 .Cm syn ,
1120 .Cm rst ,
1121 .Cm psh ,
1122 .Cm ack
1123 and
1124 .Cm urg .
1125 The absence of a particular flag may be denoted
1126 with a
1127 .Ql \&! .
1128 A rule which contains a
1129 .Cm tcpflags
1130 specification can never match a fragmented packet which has
1131 a non-zero offset.
1132 See the
1133 .Cm frag
1134 option for details on matching fragmented packets.
1135 .It Cm tcpseq Ar seq
1136 TCP packets only.
1137 Match if the TCP header sequence number field is set to
1138 .Ar seq .
1139 .It Cm tcpwin Ar win
1140 TCP packets only.
1141 Match if the TCP header window field is set to
1142 .Ar win .
1143 .It Cm tcpoptions Ar spec
1144 TCP packets only.
1145 Match if the TCP header contains the comma separated list of
1146 options specified in
1147 .Ar spec .
1148 The supported TCP options are:
1149 .Pp
1150 .Cm mss
1151 (maximum segment size),
1152 .Cm window
1153 (tcp window advertisement),
1154 .Cm sack
1155 (selective ack),
1156 .Cm ts
1157 (rfc1323 timestamp) and
1158 .Cm cc
1159 (rfc1644 t/tcp connection count).
1160 The absence of a particular option may be denoted
1161 with a
1162 .Ql \&! .
1163 .It Cm uid Ar user
1164 Match all TCP or UDP packets sent by or received for a
1165 .Ar user .
1166 A
1167 .Ar user
1168 may be matched by name or identification number.
1169 .It Cm verrevpath
1170 For incoming packets,
1171 a routing table lookup is done on the packet's source address.
1172 If the interface on which the packet entered the system matches the
1173 outgoing interface for the route,
1174 the packet matches.
1175 If the interfaces do not match up,
1176 the packet does not match.
1177 All outgoing packets or packets with no incoming interface match.
1178 .Pp
1179 The name and functionality of the option is intentionally similar to
1180 the Cisco IOS command:
1181 .Pp
1182 .Dl ip verify unicast reverse-path
1183 .Pp
1184 This option can be used to make anti-spoofing rules.
1185 .El
1186 .Sh SETS OF RULES
1187 Each rule belongs to one of 32 different
1188 .Em sets
1189 , numbered 0 to 31.
1190 Set 31 is reserved for the default rule.
1191 .Pp
1192 By default, rules are put in set 0, unless you use the
1193 .Cm set N
1194 attribute when entering a new rule.
1195 Sets can be individually and atomically enabled or disabled,
1196 so this mechanism permits an easy way to store multiple configurations
1197 of the firewall and quickly (and atomically) switch between them.
1198 The command to enable/disable sets is
1199 .Bd -ragged -offset indent
1200 .Nm
1201 .Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
1202 .Ed
1203 .Pp
1204 where multiple
1205 .Cm enable
1206 or
1207 .Cm disable
1208 sections can be specified.
1209 Command execution is atomic on all the sets specified in the command.
1210 By default, all sets are enabled.
1211 .Pp
1212 When you disable a set, its rules behave as if they do not exist
1213 in the firewall configuration, with only one exception:
1214 .Bd -ragged -offset indent
1215 dynamic rules created from a rule before it had been disabled
1216 will still be active until they expire. In order to delete
1217 dynamic rules you have to explicitly delete the parent rule
1218 which generated them.
1219 .Ed
1220 .Pp
1221 The set number of rules can be changed with the command
1222 .Bd -ragged -offset indent
1223 .Nm
1224 .Cm set move
1225 .Brq Cm rule Ar rule-number | old-set
1226 .Cm to Ar new-set
1227 .Ed
1228 .Pp
1229 Also, you can atomically swap two rulesets with the command
1230 .Bd -ragged -offset indent
1231 .Nm
1232 .Cm set swap Ar first-set second-set
1233 .Ed
1234 .Pp
1235 See the
1236 .Sx EXAMPLES
1237 Section on some possible uses of sets of rules.
1238 .Sh STATEFUL FIREWALL
1239 Stateful operation is a way for the firewall to dynamically
1240 create rules for specific flows when packets that
1241 match a given pattern are detected. Support for stateful
1242 operation comes through the
1243 .Cm check-state , keep-state
1244 and
1245 .Cm limit
1246 options of
1247 .Nm rules.
1248 .Pp
1249 Dynamic rules are created when a packet matches a
1250 .Cm keep-state
1251 or
1252 .Cm limit
1253 rule, causing the creation of a
1254 .Em dynamic
1255 rule which will match all and only packets with
1256 a given
1257 .Em protocol
1258 between a
1259 .Em src-ip/src-port dst-ip/dst-port
1260 pair of addresses (
1261 .Em src
1262 and
1263 .Em dst
1264 are used here only to denote the initial match addresses, but they
1265 are completely equivalent afterwards).
1266 Dynamic rules will be checked at the first
1267 .Cm check-state, keep-state
1268 or
1269 .Cm limit
1270 occurrence, and the action performed upon a match will be the same
1271 as in the parent rule.
1272 .Pp
1273 Note that no additional attributes other than protocol and IP addresses
1274 and ports are checked on dynamic rules.
1275 .Pp
1276 The typical use of dynamic rules is to keep a closed firewall configuration,
1277 but let the first TCP SYN packet from the inside network install a
1278 dynamic rule for the flow so that packets belonging to that session
1279 will be allowed through the firewall:
1280 .Pp
1281 .Dl "ipfw add check-state"
1282 .Dl "ipfw add allow tcp from my-subnet to any setup keep-state"
1283 .Dl "ipfw add deny tcp from any to any"
1284 .Pp
1285 A similar approach can be used for UDP, where an UDP packet coming
1286 from the inside will install a dynamic rule to let the response through
1287 the firewall:
1288 .Pp
1289 .Dl "ipfw add check-state"
1290 .Dl "ipfw add allow udp from my-subnet to any keep-state"
1291 .Dl "ipfw add deny udp from any to any"
1292 .Pp
1293 Dynamic rules expire after some time, which depends on the status
1294 of the flow and the setting of some
1295 .Cm sysctl
1296 variables.
1297 See Section
1298 .Sx SYSCTL VARIABLES
1299 for more details.
1300 For TCP sessions, dynamic rules can be instructed to periodically
1301 send keepalive packets to refresh the state of the rule when it is
1302 about to expire.
1303 .Pp
1304 See Section
1305 .Sx EXAMPLES
1306 for more examples on how to use dynamic rules.
1307 .Sh TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
1308 .Nm
1309 is also the user interface for the
1310 .Xr dummynet 4
1311 traffic shaper.
1312 .Pp
1313 .Nm dummynet
1314 operates by first using the firewall to classify packets and divide them into
1315 .Em flows ,
1316 using any match pattern that can be used in
1317 .Nm
1318 rules.
1319 Depending on local policies, a flow can contain packets for a single
1320 TCP connection, or from/to a given host, or entire subnet, or a
1321 protocol type, etc.
1322 .Pp
1323 Packets belonging to the same flow are then passed to either of two
1324 different objects, which implement the traffic regulation:
1325 .Bl -hang -offset XXXX
1326 .It Em pipe
1327 A pipe emulates a link with given bandwidth, propagation delay,
1328 queue size and packet loss rate.
1329 Packets are queued in front of the pipe as they come out from the classifier,
1330 and then transferred to the pipe according to the pipe's parameters.
1331 .Pp
1332 .It Em queue
1333 A queue
1334 is an abstraction used to implement the WF2Q+
1335 (Worst-case Fair Weighted Fair Queueing) policy, which is
1336 an efficient variant of the WFQ policy.
1337 .br
1338 The queue associates a
1339 .Em weight
1340 and a reference pipe to each flow, and then all backlogged (i.e.,
1341 with packets queued) flows linked to the same pipe share the pipe's
1342 bandwidth proportionally to their weights.
1343 Note that weights are not priorities; a flow with a lower weight
1344 is still guaranteed to get its fraction of the bandwidth even if a
1345 flow with a higher weight is permanently backlogged.
1346 .Pp
1347 .El
1348 In practice,
1349 .Em pipes
1350 can be used to set hard limits to the bandwidth that a flow can use, whereas
1351 .Em queues
1352 can be used to determine how different flow share the available bandwidth.
1353 .Pp
1354 The
1355 .Em pipe
1356 and
1357 .Em queue
1358 configuration commands are the following:
1359 .Bd -ragged -offset indent
1360 .Cm pipe Ar number Cm config Ar pipe-configuration
1361 .Pp
1362 .Cm queue Ar number Cm config Ar queue-configuration
1363 .Ed
1364 .Pp
1365 The following parameters can be configured for a pipe:
1366 .Pp
1367 .Bl -tag -width indent -compact
1368 .It Cm bw Ar bandwidth | device
1369 Bandwidth, measured in
1370 .Sm off
1371 .Op Cm K | M
1372 .Brq Cm bit/s | Byte/s .
1373 .Sm on
1374 .Pp
1375 A value of 0 (default) means unlimited bandwidth.
1376 The unit must immediately follow the number, as in
1377 .Pp
1378 .Dl "ipfw pipe 1 config bw 300Kbit/s"
1379 .Pp
1380 If a device name is specified instead of a numeric value, as in
1381 .Pp
1382 .Dl "ipfw pipe 1 config bw tun0"
1383 .Pp
1384 then the transmit clock is supplied by the specified device.
1385 At the moment only the
1386 .Xr tun 4
1387 device supports this
1388 functionality, for use in conjunction with
1389 .Xr ppp 8 .
1390 .Pp
1391 .It Cm delay Ar ms-delay
1392 Propagation delay, measured in milliseconds.
1393 The value is rounded to the next multiple of the clock tick
1394 (typically 10ms, but it is a good practice to run kernels
1395 with
1396 .Dq "options HZ=1000"
1397 to reduce
1398 the granularity to 1ms or less).
1399 Default value is 0, meaning no delay.
1400 .El
1401 .Pp
1402 The following parameters can be configured for a queue:
1403 .Pp
1404 .Bl -tag -width indent -compact
1405 .It Cm pipe Ar pipe_nr
1406 Connects a queue to the specified pipe.
1407 Multiple queues (with the same or different weights) can be connected to
1408 the same pipe, which specifies the aggregate rate for the set of queues.
1409 .Pp
1410 .It Cm weight Ar weight
1411 Specifies the weight to be used for flows matching this queue.
1412 The weight must be in the range 1..100, and defaults to 1.
1413 .El
1414 .Pp
1415 Finally, the following parameters can be configured for both
1416 pipes and queues:
1417 .Pp
1418 .Bl -tag -width XXXX -compact
1419 .Pp
1420 .It Cm buckets Ar hash-table-size
1421 Specifies the size of the hash table used for storing the
1422 various queues.
1423 Default value is 64 controlled by the
1424 .Xr sysctl 8
1425 variable
1426 .Em net.inet.ip.dummynet.hash_size ,
1427 allowed range is 16 to 65536.
1428 .Pp
1429 .It Cm mask Ar mask-specifier
1430 Packets sent to a given pipe or queue by an
1431 .Nm
1432 rule can be further classified into multiple flows, each of which is then
1433 sent to a different
1434 .Em dynamic
1435 pipe or queue.
1436 A flow identifier is constructed by masking the IP addresses,
1437 ports and protocol types as specified with the
1438 .Cm mask
1439 options in the configuration of the pipe or queue.
1440 For each different flow identifier, a new pipe or queue is created
1441 with the same parameters as the original object, and matching packets
1442 are sent to it.
1443 .Pp
1444 Thus, when
1445 .Em dynamic pipes
1446 are used, each flow will get the same bandwidth as defined by the pipe,
1447 whereas when
1448 .Em dynamic queues
1449 are used, each flow will share the parent's pipe bandwidth evenly
1450 with other flows generated by the same queue (note that other queues
1451 with different weights might be connected to the same pipe).
1452 .br
1453 Available mask specifiers are a combination of one or more of the following:
1454 .Pp
1455 .Cm dst-ip Ar mask ,
1456 .Cm src-ip Ar mask ,
1457 .Cm dst-port Ar mask ,
1458 .Cm src-port Ar mask ,
1459 .Cm proto Ar mask
1460 or
1461 .Cm all ,
1462 .Pp
1463 where the latter means all bits in all fields are significant.
1464 .Pp
1465 .It Cm noerror
1466 When a packet is dropped by a dummynet queue or pipe, the error
1467 is normally reported to the caller routine in the kernel, in the
1468 same way as it happens when a device queue fills up. Setting this
1469 option reports the packet as successfully delivered, which can be
1470 needed for some experimental setups where you want to simulate
1471 loss or congestion at a remote router.
1472 .Pp
1473 .It Cm plr Ar packet-loss-rate
1474 Packet loss rate.
1475 Argument
1476 .Ar packet-loss-rate
1477 is a floating-point number between 0 and 1, with 0 meaning no
1478 loss, 1 meaning 100% loss.
1479 The loss rate is internally represented on 31 bits.
1480 .Pp
1481 .It Cm queue Brq Ar slots | size Ns Cm Kbytes
1482 Queue size, in
1483 .Ar slots
1484 or
1485 .Cm KBytes .
1486 Default value is 50 slots, which
1487 is the typical queue size for Ethernet devices.
1488 Note that for slow speed links you should keep the queue
1489 size short or your traffic might be affected by a significant
1490 queueing delay.
1491 E.g., 50 max-sized ethernet packets (1500 bytes) mean 600Kbit
1492 or 20s of queue on a 30Kbit/s pipe.
1493 Even worse effect can result if you get packets from an
1494 interface with a much larger MTU, e.g. the loopback interface
1495 with its 16KB packets.
1496 .Pp
1497 .It Cm red | gred Ar w_q Ns / Ns Ar min_th Ns / Ns Ar max_th Ns / Ns Ar max_p
1498 Make use of the RED (Random Early Detection) queue management algorithm.
1499 .Ar w_q
1500 and
1501 .Ar max_p
1502 are floating
1503 point numbers between 0 and 1 (0 not included), while
1504 .Ar min_th
1505 and
1506 .Ar max_th
1507 are integer numbers specifying thresholds for queue management
1508 (thresholds are computed in bytes if the queue has been defined
1509 in bytes, in slots otherwise).
1510 The
1511 .Xr dummynet 4
1512 also supports the gentle RED variant (gred).
1513 Three
1514 .Xr sysctl 8
1515 variables can be used to control the RED behaviour:
1516 .Bl -tag -width indent
1517 .It Em net.inet.ip.dummynet.red_lookup_depth
1518 specifies the accuracy in computing the average queue
1519 when the link is idle (defaults to 256, must be greater than zero)
1520 .It Em net.inet.ip.dummynet.red_avg_pkt_size
1521 specifies the expected average packet size (defaults to 512, must be
1522 greater than zero)
1523 .It Em net.inet.ip.dummynet.red_max_pkt_size
1524 specifies the expected maximum packet size, only used when queue
1525 thresholds are in bytes (defaults to 1500, must be greater than zero).
1526 .El
1527 .El
1528 .Sh CHECKLIST
1529 Here are some important points to consider when designing your
1530 rules:
1531 .Bl -bullet
1532 .It
1533 Remember that you filter both packets going
1534 .Cm in
1535 and
1536 .Cm out .
1537 Most connections need packets going in both directions.
1538 .It
1539 Remember to test very carefully.
1540 It is a good idea to be near the console when doing this.
1541 If you cannot be near the console,
1542 use an auto-recovery script such as the one in
1543 .Pa /usr/share/examples/ipfw/change_rules.sh .
1544 .It
1545 Don't forget the loopback interface.
1546 .El
1547 .Sh FINE POINTS
1548 .Bl -bullet
1549 .It
1550 There are circumstances where fragmented datagrams are unconditionally
1551 dropped.
1552 TCP packets are dropped if they do not contain at least 20 bytes of
1553 TCP header, UDP packets are dropped if they do not contain a full 8
1554 byte UDP header, and ICMP packets are dropped if they do not contain
1555 4 bytes of ICMP header, enough to specify the ICMP type, code, and
1556 checksum.
1557 These packets are simply logged as
1558 .Dq pullup failed
1559 since there may not be enough good data in the packet to produce a
1560 meaningful log entry.
1561 .It
1562 Another type of packet is unconditionally dropped, a TCP packet with a
1563 fragment offset of one.
1564 This is a valid packet, but it only has one use, to try
1565 to circumvent firewalls.
1566 When logging is enabled, these packets are
1567 reported as being dropped by rule -1.
1568 .It
1569 The
1570 .Nm
1571 filter list may not be modified if the system security level
1572 is set to 3 or higher.
1573 .El
1574 .Sh PACKET DIVERSION
1575 A
1576 .Xr divert 4
1577 socket bound to the specified port will receive all packets
1578 diverted to that port.
1579 If no socket is bound to the destination port, or if the kernel
1580 wasn't compiled with divert socket support, the packets are
1581 dropped.
1582 .Sh SYSCTL VARIABLES
1583 A set of
1584 .Xr sysctl 8
1585 variables controls the behaviour of the firewall and
1586 associated modules (
1587 .Nm dummynet, bridge
1588 ).
1589 These are shown below together with their default value
1590 (but always check with the
1591 .Xr sysctl 8
1592 command what value is actually in use) and meaning:
1593 .Bl -tag -width indent
1594 .It Em net.inet.ip.dummynet.expire : No 1
1595 Lazily delete dynamic pipes/queue once they have no pending traffic.
1596 You can disable this by setting the variable to 0, in which case
1597 the pipes/queues will only be deleted when the threshold is reached.
1598 .It Em net.inet.ip.dummynet.hash_size : No 64
1599 Default size of the hash table used for dynamic pipes/queues.
1600 This value is used when no
1601 .Cm buckets
1602 option is specified when configuring a pipe/queue.
1603 .It Em net.inet.ip.dummynet.max_chain_len : No 16
1604 Target value for the maximum number of pipes/queues in a hash bucket.
1605 The product
1606 .Cm max_chain_len*hash_size
1607 is used to determine the threshold over which empty pipes/queues
1608 will be expired even when
1609 .Cm net.inet.ip.dummynet.expire=0 .
1610 .It Em net.inet.ip.dummynet.red_lookup_depth : No 256
1611 .It Em net.inet.ip.dummynet.red_avg_pkt_size : No 512
1612 .It Em net.inet.ip.dummynet.red_max_pkt_size : No 1500
1613 Parameters used in the computations of the drop probability
1614 for the RED algorithm.
1615 .It Em net.inet.ip.fw.autoinc_step : No 100
1616 Delta between rule numbers when auto-generating them.
1617 The value must be in the range 1..1000.
1618 This variable is only present in
1619 .Nm ipfw2 ,
1620 the delta is hardwired to 100 in
1621 .Nm ipfw1 .
1622 .It Em net.inet.ip.fw.curr_dyn_buckets : Em net.inet.ip.fw.dyn_buckets
1623 The current number of buckets in the hash table for dynamic rules
1624 (readonly).
1625 .It Em net.inet.ip.fw.debug : No 1
1626 Controls debugging messages produced by
1627 .Nm .
1628 .It Em net.inet.ip.fw.dyn_buckets : No 256
1629 The number of buckets in the hash table for dynamic rules.
1630 Must be a power of 2, up to 65536.
1631 It only takes effect when all dynamic rules have expired, so you
1632 are advised to use a
1633 .Cm flush
1634 command to make sure that the hash table is resized.
1635 .It Em net.inet.ip.fw.dyn_count : No 3
1636 Current number of dynamic rules
1637 (read-only).
1638 .It Em net.inet.ip.fw.dyn_keepalive : No 1
1639 Enables generation of keepalive packets for
1640 .Cm keep-state
1641 rules on TCP sessions. A keepalive is generated to both
1642 sides of the connection every 5 seconds for the last 20
1643 seconds of the lifetime of the rule.
1644 .It Em net.inet.ip.fw.dyn_max : No 8192
1645 Maximum number of dynamic rules.
1646 When you hit this limit, no more dynamic rules can be
1647 installed until old ones expire.
1648 .It Em net.inet.ip.fw.dyn_ack_lifetime : No 300
1649 .It Em net.inet.ip.fw.dyn_syn_lifetime : No 20
1650 .It Em net.inet.ip.fw.dyn_fin_lifetime : No 1
1651 .It Em net.inet.ip.fw.dyn_rst_lifetime : No 1
1652 .It Em net.inet.ip.fw.dyn_udp_lifetime : No 5
1653 .It Em net.inet.ip.fw.dyn_short_lifetime : No 30
1654 These variables control the lifetime, in seconds, of dynamic
1655 rules.
1656 Upon the initial SYN exchange the lifetime is kept short,
1657 then increased after both SYN have been seen, then decreased
1658 again during the final FIN exchange or when a RST is received.
1659 Both
1660 .Em dyn_fin_lifetime
1661 and
1662 .Em dyn_rst_lifetime
1663 must be strictly lower than 5 seconds, the period of
1664 repetition of keepalives. The firewall enforces that.
1665 .It Em net.inet.ip.fw.enable : No 1
1666 Enables the firewall.
1667 Setting this variable to 0 lets you run your machine without
1668 firewall even if compiled in.
1669 .It Em net.inet.ip.fw.one_pass : No 1
1670 When set, the packet exiting from the
1671 .Xr dummynet 4
1672 pipe is not passed though the firewall again.
1673 Otherwise, after a pipe action, the packet is
1674 reinjected into the firewall at the next rule.
1675 .It Em net.inet.ip.fw.verbose : No 1
1676 Enables verbose messages.
1677 .It Em net.inet.ip.fw.verbose_limit : No 0
1678 Limits the number of messages produced by a verbose firewall.
1679 .It Em net.link.ether.ipfw : No 0
1680 Controls whether layer-2 packets are passed to
1681 .Nm .
1682 Default is no.
1683 .It Em net.link.ether.bridge_ipfw : No 0
1684 Controls whether bridged packets are passed to
1685 .Nm .
1686 Default is no.
1687 .El
1688 .Pp
1689 .Sh IPFW2 ENHANCEMENTS
1690 This Section lists the features that have been introduced in
1691 .Nm ipfw2
1692 which were not present in
1693 .Nm ipfw1 .
1694 We list them in order of the potential impact that they can
1695 have in writing your rulesets.
1696 You might want to consider using these features in order to
1697 write your rulesets in a more efficient way.
1698 .Bl -tag -width indent
1699 .It Syntax and flags
1700 .Nm ipfw1
1701 does not support the -n flag (only test syntax),
1702 nor it allows spaces after commas or supports all
1703 rule fields in a single argument.
1704 .It Handling of non-IPv4 packets
1705 .Nm ipfw1
1706 will silently accept all non-IPv4 packets (which
1707 .Nm ipfw1
1708 will only see when
1709 .Em net.link.ether.bridge_ipfw=1 Ns
1710 ).
1711 .Nm ipfw2
1712 will filter all packets (including non-IPv4 ones) according to the ruleset.
1713 To achieve the same behaviour as
1714 .Nm ipfw1
1715 you can use the following as the very first rule in your ruleset:
1716 .Pp
1717 .Dl "ipfw add 1 allow layer2 not mac-type ip"
1718 .Pp
1719 The
1720 .Cm layer2
1721 option might seem redundant, but it is necessary -- packets
1722 passed to the firewall from layer3 will not have a MAC header,
1723 so the
1724 .Cm mac-type ip
1725 pattern will always fail on them, and the
1726 .Cm not
1727 operator will make this rule into a pass-all.
1728 .It Addresses
1729 .Nm ipfw1
1730 does not supports address sets or lists of addresses.
1731 .Pp
1732 .It Port specifications
1733 .Nm ipfw1
1734 only allows one port range when specifying TCP and UDP ports, and
1735 is limited to 10 entries instead of the 15 allowed by
1736 .Nm ipfw2 .
1737 Also, in
1738 .Nm ipfw1
1739 you can only specify ports when the rule is requesting
1740 .Cm tcp
1741 or
1742 .Cm udp
1743 packets. With
1744 .Nm ipfw2
1745 you can put port specifications in rules matching all packets,
1746 and the match will be attempted only on those packets carrying
1747 protocols which include port identifiers.
1748 .Pp
1749 Finally,
1750 .Nm ipfw1
1751 allowed the first port entry to be specified as
1752 .Ar port:mask
1753 where
1754 .Ar mask
1755 can be an arbitrary 16-bit mask.
1756 This syntax is of questionable usefulness and it is not
1757 supported anymore in
1758 .Nm ipfw2 .
1759 .It Or-blocks
1760 .Nm ipfw1
1761 does not support Or-blocks.
1762 .It keepalives
1763 .Nm ipfw1
1764 does not generate keepalives for stateful sessions.
1765 As a consequence, it might cause idle sessions to drop because
1766 the lifetime of the dynamic rules expires.
1767 .It Sets of rules
1768 .Nm ipfw1
1769 does not implement sets of rules.
1770 .It MAC header filtering and Layer-2 firewalling.
1771 .Nm ipfw1
1772 does not implement filtering on MAC header fields, nor is it
1773 invoked on packets from
1774 .Cm ether_demux()
1775 and
1776 .Cm ether_output_frame().
1777 The sysctl variable
1778 .Em net.link.ether.ipfw
1779 has no effect there.
1780 .It Options
1781 In
1782 .Nm ipfw1 ,
1783 the following options only accept a single value as an argument:
1784 .Pp
1785 .Cm ipid, iplen, ipttl
1786 .Pp
1787 The following options are not implemented by
1788 .Nm ipfw1 :
1789 .Pp
1790 .Cm dst-ip, dst-port, layer2, mac, mac-type, src-ip, src-port.
1791 .Pp
1792 Additionally, the RELENG_4 version of
1793 .Nm ipfw1
1794 does not implement the following options:
1795 .Pp
1796 .Cm ipid, iplen, ipprecedence, iptos, ipttl,
1797 .Cm ipversion, tcpack, tcpseq, tcpwin .
1798 .It Dummynet options
1799 The following option for
1800 .Nm dummynet
1801 pipes/queues is not supported:
1802 .Cm noerror .
1803 .El
1804 .Sh EXAMPLES
1805 There are far too many possible uses of
1806 .Nm
1807 so this Section will only give a small set of examples.
1808 .Pp
1809 .Ss BASIC PACKET FILTERING
1810 This command adds an entry which denies all tcp packets from
1811 .Em cracker.evil.org
1812 to the telnet port of
1813 .Em wolf.tambov.su
1814 from being forwarded by the host:
1815 .Pp
1816 .Dl "ipfw add deny tcp from cracker.evil.org to wolf.tambov.su telnet"
1817 .Pp
1818 This one disallows any connection from the entire cracker's
1819 network to my host:
1820 .Pp
1821 .Dl "ipfw add deny ip from 123.45.67.0/24 to my.host.org"
1822 .Pp
1823 A first and efficient way to limit access (not using dynamic rules)
1824 is the use of the following rules:
1825 .Pp
1826 .Dl "ipfw add allow tcp from any to any established"
1827 .Dl "ipfw add allow tcp from net1 portlist1 to net2 portlist2 setup"
1828 .Dl "ipfw add allow tcp from net3 portlist3 to net3 portlist3 setup"
1829 .Dl "..."
1830 .Dl "ipfw add deny tcp from any to any"
1831 .Pp
1832 The first rule will be a quick match for normal TCP packets,
1833 but it will not match the initial SYN packet, which will be
1834 matched by the
1835 .Cm setup
1836 rules only for selected source/destination pairs.
1837 All other SYN packets will be rejected by the final
1838 .Cm deny
1839 rule.
1840 .Pp
1841 If you administer one or more subnets, you can take advantage of the
1842 .Nm ipfw2
1843 syntax to specify address sets and or-blocks and write extremely
1844 compact rulesets which selectively enable services to blocks
1845 of clients, as below:
1846 .Pp
1847 .Dl "goodguys=\*q{ 10.1.2.0/24{20,35,66,18} or 10.2.3.0/28{6,3,11} }\*q"
1848 .Dl "badguys=\*q10.1.2.0/24{8,38,60}\*q"
1849 .Dl ""
1850 .Dl "ipfw add allow ip from ${goodguys} to any"
1851 .Dl "ipfw add deny ip from ${badguys} to any"
1852 .Dl "... normal policies ..."
1853 .Pp
1854 The
1855 .Nm ipfw1
1856 syntax would require a separate rule for each IP in the above
1857 example.
1858 .Pp
1859 The
1860 .Cm verrevpath
1861 option could be used to do automated anti-spoofing by adding the
1862 following to the top of a ruleset:
1863 .Pp
1864 .Dl "ipfw add deny ip from any to any not verrevpath in"
1865 .Pp
1866 This rule drops all incoming packets that appear to be coming to the
1867 sytem on the wrong interface. For example, a packet with a source
1868 address belonging to a host on a protected internal network would be
1869 dropped if it tried to enter the system from an external interface.
1870 .Ss DYNAMIC RULES
1871 In order to protect a site from flood attacks involving fake
1872 TCP packets, it is safer to use dynamic rules:
1873 .Pp
1874 .Dl "ipfw add check-state"
1875 .Dl "ipfw add deny tcp from any to any established"
1876 .Dl "ipfw add allow tcp from my-net to any setup keep-state"
1877 .Pp
1878 This will let the firewall install dynamic rules only for
1879 those connection which start with a regular SYN packet coming
1880 from the inside of our network.
1881 Dynamic rules are checked when encountering the first
1882 .Cm check-state
1883 or
1884 .Cm keep-state
1885 rule.
1886 A
1887 .Cm check-state
1888 rule should usually be placed near the beginning of the
1889 ruleset to minimize the amount of work scanning the ruleset.
1890 Your mileage may vary.
1891 .Pp
1892 To limit the number of connections a user can open
1893 you can use the following type of rules:
1894 .Pp
1895 .Dl "ipfw add allow tcp from my-net/24 to any setup limit src-addr 10"
1896 .Dl "ipfw add allow tcp from any to me setup limit src-addr 4"
1897 .Pp
1898 The former (assuming it runs on a gateway) will allow each host
1899 on a /24 network to open at most 10 TCP connections.
1900 The latter can be placed on a server to make sure that a single
1901 client does not use more than 4 simultaneous connections.
1902 .Pp
1903 .Em BEWARE :
1904 stateful rules can be subject to denial-of-service attacks
1905 by a SYN-flood which opens a huge number of dynamic rules.
1906 The effects of such attacks can be partially limited by
1907 acting on a set of
1908 .Xr sysctl 8
1909 variables which control the operation of the firewall.
1910 .Pp
1911 Here is a good usage of the
1912 .Cm list
1913 command to see accounting records and timestamp information:
1914 .Pp
1915 .Dl ipfw -at list
1916 .Pp
1917 or in short form without timestamps:
1918 .Pp
1919 .Dl ipfw -a list
1920 .Pp
1921 which is equivalent to:
1922 .Pp
1923 .Dl ipfw show
1924 .Pp
1925 Next rule diverts all incoming packets from 192.168.2.0/24
1926 to divert port 5000:
1927 .Pp
1928 .Dl ipfw divert 5000 ip from 192.168.2.0/24 to any in
1929 .Pp
1930 .Ss TRAFFIC SHAPING
1931 The following rules show some of the applications of
1932 .Nm
1933 and
1934 .Xr dummynet 4
1935 for simulations and the like.
1936 .Pp
1937 This rule drops random incoming packets with a probability
1938 of 5%:
1939 .Pp
1940 .Dl "ipfw add prob 0.05 deny ip from any to any in"
1941 .Pp
1942 A similar effect can be achieved making use of dummynet pipes:
1943 .Pp
1944 .Dl "ipfw add pipe 10 ip from any to any"
1945 .Dl "ipfw pipe 10 config plr 0.05"
1946 .Pp
1947 We can use pipes to artificially limit bandwidth, e.g. on a
1948 machine acting as a router, if we want to limit traffic from
1949 local clients on 192.168.2.0/24 we do:
1950 .Pp
1951 .Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
1952 .Dl "ipfw pipe 1 config bw 300Kbit/s queue 50KBytes"
1953 .Pp
1954 note that we use the
1955 .Cm out
1956 modifier so that the rule is not used twice.
1957 Remember in fact that
1958 .Nm
1959 rules are checked both on incoming and outgoing packets.
1960 .Pp
1961 Should we want to simulate a bidirectional link with bandwidth
1962 limitations, the correct way is the following:
1963 .Pp
1964 .Dl "ipfw add pipe 1 ip from any to any out"
1965 .Dl "ipfw add pipe 2 ip from any to any in"
1966 .Dl "ipfw pipe 1 config bw 64Kbit/s queue 10Kbytes"
1967 .Dl "ipfw pipe 2 config bw 64Kbit/s queue 10Kbytes"
1968 .Pp
1969 The above can be very useful, e.g. if you want to see how
1970 your fancy Web page will look for a residential user who
1971 is connected only through a slow link.
1972 You should not use only one pipe for both directions, unless
1973 you want to simulate a half-duplex medium (e.g. AppleTalk,
1974 Ethernet, IRDA).
1975 It is not necessary that both pipes have the same configuration,
1976 so we can also simulate asymmetric links.
1977 .Pp
1978 Should we want to verify network performance with the RED queue
1979 management algorithm:
1980 .Pp
1981 .Dl "ipfw add pipe 1 ip from any to any"
1982 .Dl "ipfw pipe 1 config bw 500Kbit/s queue 100 red 0.002/30/80/0.1"
1983 .Pp
1984 Another typical application of the traffic shaper is to
1985 introduce some delay in the communication.
1986 This can significantly affect applications which do a lot of Remote
1987 Procedure Calls, and where the round-trip-time of the
1988 connection often becomes a limiting factor much more than
1989 bandwidth:
1990 .Pp
1991 .Dl "ipfw add pipe 1 ip from any to any out"
1992 .Dl "ipfw add pipe 2 ip from any to any in"
1993 .Dl "ipfw pipe 1 config delay 250ms bw 1Mbit/s"
1994 .Dl "ipfw pipe 2 config delay 250ms bw 1Mbit/s"
1995 .Pp
1996 Per-flow queueing can be useful for a variety of purposes.
1997 A very simple one is counting traffic:
1998 .Pp
1999 .Dl "ipfw add pipe 1 tcp from any to any"
2000 .Dl "ipfw add pipe 1 udp from any to any"
2001 .Dl "ipfw add pipe 1 ip from any to any"
2002 .Dl "ipfw pipe 1 config mask all"
2003 .Pp
2004 The above set of rules will create queues (and collect
2005 statistics) for all traffic.
2006 Because the pipes have no limitations, the only effect is
2007 collecting statistics.
2008 Note that we need 3 rules, not just the last one, because
2009 when
2010 .Nm
2011 tries to match IP packets it will not consider ports, so we
2012 would not see connections on separate ports as different
2013 ones.
2014 .Pp
2015 A more sophisticated example is limiting the outbound traffic
2016 on a net with per-host limits, rather than per-network limits:
2017 .Pp
2018 .Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
2019 .Dl "ipfw add pipe 2 ip from any to 192.168.2.0/24 in"
2020 .Dl "ipfw pipe 1 config mask src-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
2021 .Dl "ipfw pipe 2 config mask dst-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
2022 .Ss SETS OF RULES
2023 To add a set of rules atomically, e.g. set 18:
2024 .Pp
2025 .Dl "ipfw set disable 18"
2026 .Dl "ipfw add NN set 18 ... # repeat as needed"
2027 .Dl "ipfw set enable 18"
2028 .Pp
2029 To delete a set of rules atomically the command is simply:
2030 .Pp
2031 .Dl "ipfw delete set 18"
2032 .Pp
2033 To test a ruleset and disable it and regain control if something goes wrong:
2034 .Pp
2035 .Dl "ipfw set disable 18"
2036 .Dl "ipfw add NN set 18 ... # repeat as needed"
2037 .Dl "ipfw set enable 18; echo done; sleep 30 && ipfw set disable 18"
2038 .Pp
2039 Here if everything goes well, you press control-C before the "sleep"
2040 terminates, and your ruleset will be left active. Otherwise, e.g. if
2041 you cannot access your box, the ruleset will be disabled after
2042 the sleep terminates thus restoring the previous situation.
2043 .Sh SEE ALSO
2044 .Xr cpp 1 ,
2045 .Xr m4 1 ,
2046 .Xr divert 4 ,
2047 .Xr dummynet 4 ,
2048 .Xr ip 4 ,
2049 .Xr ipfirewall 4 ,
2050 .Xr protocols 5 ,
2051 .Xr services 5 ,
2052 .Xr reboot 8 ,
2053 .Xr sysctl 8 ,
2054 .Xr syslogd 8
2055 .Sh BUGS
2056 The syntax has grown over the years and sometimes it might be confusing.
2057 Unfortunately, backward compatibility prevents cleaning up mistakes
2058 made in the definition of the syntax.
2059 .Pp
2060 .Em !!! WARNING !!!
2061 .Pp
2062 Misconfiguring the firewall can put your computer in an unusable state,
2063 possibly shutting down network services and requiring console access to
2064 regain control of it.
2065 .Pp
2066 Incoming packet fragments diverted by
2067 .Cm divert
2068 or
2069 .Cm tee
2070 are reassembled before delivery to the socket.
2071 The action used on those packet is the one from the
2072 rule which matches the first fragment of the packet.
2073 .Pp
2074 Packets that match a
2075 .Cm tee
2076 rule should not be immediately accepted, but should continue
2077 going through the rule list.
2078 This may be fixed in a later version.
2079 .Pp
2080 Packets diverted to userland, and then reinserted by a userland process
2081 may lose various packet attributes.
2082 The packet source interface name
2083 will be preserved if it is shorter than 8 bytes and the userland process
2084 saves and reuses the sockaddr_in
2085 (as does
2086 .Xr natd 8 ) ;
2087 otherwise, it may be lost.
2088 If a packet is reinserted in this manner, later rules may be incorrectly
2089 applied, making the order of
2090 .Cm divert
2091 rules in the rule sequence very important.
2092 .Sh AUTHORS
2093 .An Ugen J. S. Antsilevich ,
2094 .An Poul-Henning Kamp ,
2095 .An Alex Nash ,
2096 .An Archie Cobbs ,
2097 .An Luigi Rizzo .
2098 .Pp
2099 .An -nosplit
2100 API based upon code written by
2101 .An Daniel Boulet
2102 for BSDI.
2103 .Pp
2104 Work on
2105 .Xr dummynet 4
2106 traffic shaper supported by Akamba Corp.
2107 .Sh HISTORY
2108 The
2109 .Nm
2110 utility first appeared in
2111 .Fx 2.0 .
2112 .Xr dummynet 4
2113 was introduced in
2114 .Fx 2.2.8 .
2115 Stateful extensions were introduced in
2116 .Fx 4.0 .
2117 .Nm ipfw2
2118 was introduced in Summer 2002.