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