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