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