xref: /freebsd/sbin/ipfw/ipfw.8 (revision 39beb93c3f8bdbf72a61fda42300b5ebed7390c8)
1.\"
2.\" $FreeBSD$
3.\"
4.Dd September 27, 2008
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 kernel network subsystem
610(using
611.Xr mbuf_tags 9
612facility), not only by means of
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. Initially this is
866limited to the values  0 through 15. See
867.Xr setfib 8 .
868Processing continues at the next rule.
869.El
870.Ss RULE BODY
871The body of a rule contains zero or more patterns (such as
872specific source and destination addresses or ports,
873protocol options, incoming or outgoing interfaces, etc.)
874that the packet must match in order to be recognised.
875In general, the patterns are connected by (implicit)
876.Cm and
877operators -- i.e., all must match in order for the
878rule to match.
879Individual patterns can be prefixed by the
880.Cm not
881operator to reverse the result of the match, as in
882.Pp
883.Dl "ipfw add 100 allow ip from not 1.2.3.4 to any"
884.Pp
885Additionally, sets of alternative match patterns
886.Pq Em or-blocks
887can be constructed by putting the patterns in
888lists enclosed between parentheses ( ) or braces { }, and
889using the
890.Cm or
891operator as follows:
892.Pp
893.Dl "ipfw add 100 allow ip from { x or not y or z } to any"
894.Pp
895Only one level of parentheses is allowed.
896Beware that most shells have special meanings for parentheses
897or braces, so it is advisable to put a backslash \\ in front of them
898to prevent such interpretations.
899.Pp
900The body of a rule must in general include a source and destination
901address specifier.
902The keyword
903.Ar any
904can be used in various places to specify that the content of
905a required field is irrelevant.
906.Pp
907The rule body has the following format:
908.Bd -ragged -offset indent
909.Op Ar proto Cm from Ar src Cm to Ar dst
910.Op Ar options
911.Ed
912.Pp
913The first part (proto from src to dst) is for backward
914compatibility with earlier versions of
915.Fx .
916In modern
917.Fx
918any match pattern (including MAC headers, IP protocols,
919addresses and ports) can be specified in the
920.Ar options
921section.
922.Pp
923Rule fields have the following meaning:
924.Bl -tag -width indent
925.It Ar proto : protocol | Cm { Ar protocol Cm or ... }
926.It Ar protocol : Oo Cm not Oc Ar protocol-name | protocol-number
927An IP protocol specified by number or name
928(for a complete list see
929.Pa /etc/protocols ) ,
930or one of the following keywords:
931.Bl -tag -width indent
932.It Cm ip4 | ipv4
933Matches IPv4 packets.
934.It Cm ip6 | ipv6
935Matches IPv6 packets.
936.It Cm ip | all
937Matches any packet.
938.El
939.Pp
940The
941.Cm ipv6
942in
943.Cm proto
944option will be treated as inner protocol.
945And, the
946.Cm ipv4
947is not available in
948.Cm proto
949option.
950.Pp
951The
952.Cm { Ar protocol Cm or ... }
953format (an
954.Em or-block )
955is provided for convenience only but its use is deprecated.
956.It Ar src No and Ar dst : Bro Cm addr | Cm { Ar addr Cm or ... } Brc Op Oo Cm not Oc Ar ports
957An address (or a list, see below)
958optionally followed by
959.Ar ports
960specifiers.
961.Pp
962The second format
963.Em ( or-block
964with multiple addresses) is provided for convenience only and
965its use is discouraged.
966.It Ar addr : Oo Cm not Oc Bro
967.Cm any | me | me6 |
968.Cm table Ns Pq Ar number Ns Op , Ns Ar value
969.Ar | addr-list | addr-set
970.Brc
971.It Cm any
972matches any IP address.
973.It Cm me
974matches any IP address configured on an interface in the system.
975.It Cm me6
976matches any IPv6 address configured on an interface in the system.
977The address list is evaluated at the time the packet is
978analysed.
979.It Cm table Ns Pq Ar number Ns Op , Ns Ar value
980Matches any IPv4 address for which an entry exists in the lookup table
981.Ar number .
982If an optional 32-bit unsigned
983.Ar value
984is also specified, an entry will match only if it has this value.
985See the
986.Sx LOOKUP TABLES
987section below for more information on lookup tables.
988.It Ar addr-list : ip-addr Ns Op Ns , Ns Ar addr-list
989.It Ar ip-addr :
990A host or subnet address specified in one of the following ways:
991.Bl -tag -width indent
992.It Ar numeric-ip | hostname
993Matches a single IPv4 address, specified as dotted-quad or a hostname.
994Hostnames are resolved at the time the rule is added to the firewall list.
995.It Ar addr Ns / Ns Ar masklen
996Matches all addresses with base
997.Ar addr
998(specified as an IP address, a network number, or a hostname)
999and mask width of
1000.Cm masklen
1001bits.
1002As an example, 1.2.3.4/25 or 1.2.3.0/25 will match
1003all IP numbers from 1.2.3.0 to 1.2.3.127 .
1004.It Ar addr Ns : Ns Ar mask
1005Matches all addresses with base
1006.Ar addr
1007(specified as an IP address, a network number, or a hostname)
1008and the mask of
1009.Ar mask ,
1010specified as a dotted quad.
1011As an example, 1.2.3.4:255.0.255.0 or 1.0.3.0:255.0.255.0 will match
10121.*.3.*.
1013This form is advised only for non-contiguous
1014masks.
1015It is better to resort to the
1016.Ar addr Ns / Ns Ar masklen
1017format for contiguous masks, which is more compact and less
1018error-prone.
1019.El
1020.It Ar addr-set : addr Ns Oo Ns / Ns Ar masklen Oc Ns Cm { Ns Ar list Ns Cm }
1021.It Ar list : Bro Ar num | num-num Brc Ns Op Ns , Ns Ar list
1022Matches all addresses with base address
1023.Ar addr
1024(specified as an IP address, a network number, or a hostname)
1025and whose last byte is in the list between braces { } .
1026Note that there must be no spaces between braces and
1027numbers (spaces after commas are allowed).
1028Elements of the list can be specified as single entries
1029or ranges.
1030The
1031.Ar masklen
1032field is used to limit the size of the set of addresses,
1033and can have any value between 24 and 32.
1034If not specified,
1035it will be assumed as 24.
1036.br
1037This format is particularly useful to handle sparse address sets
1038within a single rule.
1039Because the matching occurs using a
1040bitmask, it takes constant time and dramatically reduces
1041the complexity of rulesets.
1042.br
1043As an example, an address specified as 1.2.3.4/24{128,35-55,89}
1044or 1.2.3.0/24{128,35-55,89}
1045will match the following IP addresses:
1046.br
10471.2.3.128, 1.2.3.35 to 1.2.3.55, 1.2.3.89 .
1048.It Ar addr6-list : ip6-addr Ns Op Ns , Ns Ar addr6-list
1049.It Ar ip6-addr :
1050A host or subnet specified one of the following ways:
1051.Pp
1052.Bl -tag -width indent
1053.It Ar numeric-ip | hostname
1054Matches a single IPv6 address as allowed by
1055.Xr inet_pton 3
1056or a hostname.
1057Hostnames are resolved at the time the rule is added to the firewall
1058list.
1059.It Ar addr Ns / Ns Ar masklen
1060Matches all IPv6 addresses with base
1061.Ar addr
1062(specified as allowed by
1063.Xr inet_pton
1064or a hostname)
1065and mask width of
1066.Cm masklen
1067bits.
1068.El
1069.Pp
1070No support for sets of IPv6 addresses is provided because IPv6 addresses
1071are typically random past the initial prefix.
1072.It Ar ports : Bro Ar port | port Ns \&- Ns Ar port Ns Brc Ns Op , Ns Ar ports
1073For protocols which support port numbers (such as TCP and UDP), optional
1074.Cm ports
1075may be specified as one or more ports or port ranges, separated
1076by commas but no spaces, and an optional
1077.Cm not
1078operator.
1079The
1080.Ql \&-
1081notation specifies a range of ports (including boundaries).
1082.Pp
1083Service names (from
1084.Pa /etc/services )
1085may be used instead of numeric port values.
1086The length of the port list is limited to 30 ports or ranges,
1087though one can specify larger ranges by using an
1088.Em or-block
1089in the
1090.Cm options
1091section of the rule.
1092.Pp
1093A backslash
1094.Pq Ql \e
1095can be used to escape the dash
1096.Pq Ql -
1097character in a service name (from a shell, the backslash must be
1098typed twice to avoid the shell itself interpreting it as an escape
1099character).
1100.Pp
1101.Dl "ipfw add count tcp from any ftp\e\e-data-ftp to any"
1102.Pp
1103Fragmented packets which have a non-zero offset (i.e., not the first
1104fragment) will never match a rule which has one or more port
1105specifications.
1106See the
1107.Cm frag
1108option for details on matching fragmented packets.
1109.El
1110.Ss RULE OPTIONS (MATCH PATTERNS)
1111Additional match patterns can be used within
1112rules.
1113Zero or more of these so-called
1114.Em options
1115can be present in a rule, optionally prefixed by the
1116.Cm not
1117operand, and possibly grouped into
1118.Em or-blocks .
1119.Pp
1120The following match patterns can be used (listed in alphabetical order):
1121.Bl -tag -width indent
1122.It Cm // this is a comment.
1123Inserts the specified text as a comment in the rule.
1124Everything following // is considered as a comment and stored in the rule.
1125You can have comment-only rules, which are listed as having a
1126.Cm count
1127action followed by the comment.
1128.It Cm bridged
1129Alias for
1130.Cm layer2 .
1131.It Cm diverted
1132Matches only packets generated by a divert socket.
1133.It Cm diverted-loopback
1134Matches only packets coming from a divert socket back into the IP stack
1135input for delivery.
1136.It Cm diverted-output
1137Matches only packets going from a divert socket back outward to the IP
1138stack output for delivery.
1139.It Cm dst-ip Ar ip-address
1140Matches IPv4 packets whose destination IP is one of the address(es)
1141specified as argument.
1142.It Bro Cm dst-ip6 | dst-ipv6 Brc Ar ip6-address
1143Matches IPv6 packets whose destination IP is one of the address(es)
1144specified as argument.
1145.It Cm dst-port Ar ports
1146Matches IP packets whose destination port is one of the port(s)
1147specified as argument.
1148.It Cm established
1149Matches TCP packets that have the RST or ACK bits set.
1150.It Cm ext6hdr Ar header
1151Matches IPv6 packets containing the extended header given by
1152.Ar header .
1153Supported headers are:
1154.Pp
1155Fragment,
1156.Pq Cm frag ,
1157Hop-to-hop options
1158.Pq Cm hopopt ,
1159any type of Routing Header
1160.Pq Cm route ,
1161Source routing Routing Header Type 0
1162.Pq Cm rthdr0 ,
1163Mobile IPv6 Routing Header Type 2
1164.Pq Cm rthdr2 ,
1165Destination options
1166.Pq Cm dstopt ,
1167IPSec authentication headers
1168.Pq Cm ah ,
1169and IPSec encapsulated security payload headers
1170.Pq Cm esp .
1171.It Cm fib Ar fibnum
1172Matches a packet that has been tagged to use
1173the given FIB (routing table) number.
1174.It Cm flow-id Ar labels
1175Matches IPv6 packets containing any of the flow labels given in
1176.Ar labels .
1177.Ar labels
1178is a comma seperate list of numeric flow labels.
1179.It Cm frag
1180Matches packets that are fragments and not the first
1181fragment of an IP datagram.
1182Note that these packets will not have
1183the next protocol header (e.g.\& TCP, UDP) so options that look into
1184these headers cannot match.
1185.It Cm gid Ar group
1186Matches all TCP or UDP packets sent by or received for a
1187.Ar group .
1188A
1189.Ar group
1190may be specified by name or number.
1191.It Cm jail Ar prisonID
1192Matches all TCP or UDP packets sent by or received for the
1193jail whos prison ID is
1194.Ar prisonID .
1195.It Cm icmptypes Ar types
1196Matches ICMP packets whose ICMP type is in the list
1197.Ar types .
1198The list may be specified as any combination of
1199individual types (numeric) separated by commas.
1200.Em Ranges are not allowed .
1201The supported ICMP types are:
1202.Pp
1203echo reply
1204.Pq Cm 0 ,
1205destination unreachable
1206.Pq Cm 3 ,
1207source quench
1208.Pq Cm 4 ,
1209redirect
1210.Pq Cm 5 ,
1211echo request
1212.Pq Cm 8 ,
1213router advertisement
1214.Pq Cm 9 ,
1215router solicitation
1216.Pq Cm 10 ,
1217time-to-live exceeded
1218.Pq Cm 11 ,
1219IP header bad
1220.Pq Cm 12 ,
1221timestamp request
1222.Pq Cm 13 ,
1223timestamp reply
1224.Pq Cm 14 ,
1225information request
1226.Pq Cm 15 ,
1227information reply
1228.Pq Cm 16 ,
1229address mask request
1230.Pq Cm 17
1231and address mask reply
1232.Pq Cm 18 .
1233.It Cm icmp6types Ar types
1234Matches ICMP6 packets whose ICMP6 type is in the list of
1235.Ar types .
1236The list may be specified as any combination of
1237individual types (numeric) separated by commas.
1238.Em Ranges are not allowed .
1239.It Cm in | out
1240Matches incoming or outgoing packets, respectively.
1241.Cm in
1242and
1243.Cm out
1244are mutually exclusive (in fact,
1245.Cm out
1246is implemented as
1247.Cm not in Ns No ).
1248.It Cm ipid Ar id-list
1249Matches IPv4 packets whose
1250.Cm ip_id
1251field has value included in
1252.Ar id-list ,
1253which is either a single value or a list of values or ranges
1254specified in the same way as
1255.Ar ports .
1256.It Cm iplen Ar len-list
1257Matches IP packets whose total length, including header and data, is
1258in the set
1259.Ar len-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 ipoptions Ar spec
1264Matches packets whose IPv4 header contains the comma separated list of
1265options specified in
1266.Ar spec .
1267The supported IP options are:
1268.Pp
1269.Cm ssrr
1270(strict source route),
1271.Cm lsrr
1272(loose source route),
1273.Cm rr
1274(record packet route) and
1275.Cm ts
1276(timestamp).
1277The absence of a particular option may be denoted
1278with a
1279.Ql \&! .
1280.It Cm ipprecedence Ar precedence
1281Matches IPv4 packets whose precedence field is equal to
1282.Ar precedence .
1283.It Cm ipsec
1284Matches packets that have IPSEC history associated with them
1285(i.e., the packet comes encapsulated in IPSEC, the kernel
1286has IPSEC support and IPSEC_FILTERTUNNEL option, and can correctly
1287decapsulate it).
1288.Pp
1289Note that specifying
1290.Cm ipsec
1291is different from specifying
1292.Cm proto Ar ipsec
1293as the latter will only look at the specific IP protocol field,
1294irrespective of IPSEC kernel support and the validity of the IPSEC data.
1295.Pp
1296Further note that this flag is silently ignored in kernels without
1297IPSEC support.
1298It does not affect rule processing when given and the
1299rules are handled as if with no
1300.Cm ipsec
1301flag.
1302.It Cm iptos Ar spec
1303Matches IPv4 packets whose
1304.Cm tos
1305field contains the comma separated list of
1306service types specified in
1307.Ar spec .
1308The supported IP types of service are:
1309.Pp
1310.Cm lowdelay
1311.Pq Dv IPTOS_LOWDELAY ,
1312.Cm throughput
1313.Pq Dv IPTOS_THROUGHPUT ,
1314.Cm reliability
1315.Pq Dv IPTOS_RELIABILITY ,
1316.Cm mincost
1317.Pq Dv IPTOS_MINCOST ,
1318.Cm congestion
1319.Pq Dv IPTOS_ECN_CE .
1320The absence of a particular type may be denoted
1321with a
1322.Ql \&! .
1323.It Cm ipttl Ar ttl-list
1324Matches IPv4 packets whose time to live is included in
1325.Ar ttl-list ,
1326which is either a single value or a list of values or ranges
1327specified in the same way as
1328.Ar ports .
1329.It Cm ipversion Ar ver
1330Matches IP packets whose IP version field is
1331.Ar ver .
1332.It Cm keep-state
1333Upon a match, the firewall will create a dynamic rule, whose
1334default behaviour is to match bidirectional traffic between
1335source and destination IP/port using the same protocol.
1336The rule has a limited lifetime (controlled by a set of
1337.Xr sysctl 8
1338variables), and the lifetime is refreshed every time a matching
1339packet is found.
1340.It Cm layer2
1341Matches only layer2 packets, i.e., those passed to
1342.Nm
1343from ether_demux() and ether_output_frame().
1344.It Cm limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N
1345The firewall will only allow
1346.Ar N
1347connections with the same
1348set of parameters as specified in the rule.
1349One or more
1350of source and destination addresses and ports can be
1351specified.
1352Currently,
1353only IPv4 flows are supported.
1354.It Cm { MAC | mac } Ar dst-mac src-mac
1355Match packets with a given
1356.Ar dst-mac
1357and
1358.Ar src-mac
1359addresses, specified as the
1360.Cm any
1361keyword (matching any MAC address), or six groups of hex digits
1362separated by colons,
1363and optionally followed by a mask indicating the significant bits.
1364The mask may be specified using either of the following methods:
1365.Bl -enum -width indent
1366.It
1367A slash
1368.Pq /
1369followed by the number of significant bits.
1370For example, an address with 33 significant bits could be specified as:
1371.Pp
1372.Dl "MAC 10:20:30:40:50:60/33 any"
1373.Pp
1374.It
1375An ampersand
1376.Pq &
1377followed by a bitmask specified as six groups of hex digits separated
1378by colons.
1379For example, an address in which the last 16 bits are significant could
1380be specified as:
1381.Pp
1382.Dl "MAC 10:20:30:40:50:60&00:00:00:00:ff:ff any"
1383.Pp
1384Note that the ampersand character has a special meaning in many shells
1385and should generally be escaped.
1386.Pp
1387.El
1388Note that the order of MAC addresses (destination first,
1389source second) is
1390the same as on the wire, but the opposite of the one used for
1391IP addresses.
1392.It Cm mac-type Ar mac-type
1393Matches packets whose Ethernet Type field
1394corresponds to one of those specified as argument.
1395.Ar mac-type
1396is specified in the same way as
1397.Cm port numbers
1398(i.e., one or more comma-separated single values or ranges).
1399You can use symbolic names for known values such as
1400.Em vlan , ipv4, ipv6 .
1401Values can be entered as decimal or hexadecimal (if prefixed by 0x),
1402and they are always printed as hexadecimal (unless the
1403.Cm -N
1404option is used, in which case symbolic resolution will be attempted).
1405.It Cm proto Ar protocol
1406Matches packets with the corresponding IP protocol.
1407.It Cm recv | xmit | via Brq Ar ifX | Ar if Ns Cm * | Ar ipno | Ar any
1408Matches packets received, transmitted or going through,
1409respectively, the interface specified by exact name
1410.Ns No ( Ar ifX Ns No ),
1411by device name
1412.Ns No ( Ar if Ns Ar * Ns No ),
1413by IP address, or through some interface.
1414.Pp
1415The
1416.Cm via
1417keyword causes the interface to always be checked.
1418If
1419.Cm recv
1420or
1421.Cm xmit
1422is used instead of
1423.Cm via ,
1424then only the receive or transmit interface (respectively)
1425is checked.
1426By specifying both, it is possible to match packets based on
1427both receive and transmit interface, e.g.:
1428.Pp
1429.Dl "ipfw add deny ip from any to any out recv ed0 xmit ed1"
1430.Pp
1431The
1432.Cm recv
1433interface can be tested on either incoming or outgoing packets,
1434while the
1435.Cm xmit
1436interface can only be tested on outgoing packets.
1437So
1438.Cm out
1439is required (and
1440.Cm in
1441is invalid) whenever
1442.Cm xmit
1443is used.
1444.Pp
1445A packet may not have a receive or transmit interface: packets
1446originating from the local host have no receive interface,
1447while packets destined for the local host have no transmit
1448interface.
1449.It Cm setup
1450Matches TCP packets that have the SYN bit set but no ACK bit.
1451This is the short form of
1452.Dq Li tcpflags\ syn,!ack .
1453.It Cm src-ip Ar ip-address
1454Matches IPv4 packets whose source IP is one of the address(es)
1455specified as an argument.
1456.It Cm src-ip6 Ar ip6-address
1457Matches IPv6 packets whose source IP is one of the address(es)
1458specified as an argument.
1459.It Cm src-port Ar ports
1460Matches IP packets whose source port is one of the port(s)
1461specified as argument.
1462.It Cm tagged Ar tag-list
1463Matches packets whose tags are included in
1464.Ar tag-list ,
1465which is either a single value or a list of values or ranges
1466specified in the same way as
1467.Ar ports .
1468Tags can be applied to the packet using
1469.Cm tag
1470rule action parameter (see it's description for details on tags).
1471.It Cm tcpack Ar ack
1472TCP packets only.
1473Match if the TCP header acknowledgment number field is set to
1474.Ar ack .
1475.It Cm tcpdatalen Ar tcpdatalen-list
1476Matches TCP packets whose length of TCP data is
1477.Ar tcpdatalen-list ,
1478which is either a single value or a list of values or ranges
1479specified in the same way as
1480.Ar ports .
1481.It Cm tcpflags Ar spec
1482TCP packets only.
1483Match if the TCP header contains the comma separated list of
1484flags specified in
1485.Ar spec .
1486The supported TCP flags are:
1487.Pp
1488.Cm fin ,
1489.Cm syn ,
1490.Cm rst ,
1491.Cm psh ,
1492.Cm ack
1493and
1494.Cm urg .
1495The absence of a particular flag may be denoted
1496with a
1497.Ql \&! .
1498A rule which contains a
1499.Cm tcpflags
1500specification can never match a fragmented packet which has
1501a non-zero offset.
1502See the
1503.Cm frag
1504option for details on matching fragmented packets.
1505.It Cm tcpseq Ar seq
1506TCP packets only.
1507Match if the TCP header sequence number field is set to
1508.Ar seq .
1509.It Cm tcpwin Ar win
1510TCP packets only.
1511Match if the TCP header window field is set to
1512.Ar win .
1513.It Cm tcpoptions Ar spec
1514TCP packets only.
1515Match if the TCP header contains the comma separated list of
1516options specified in
1517.Ar spec .
1518The supported TCP options are:
1519.Pp
1520.Cm mss
1521(maximum segment size),
1522.Cm window
1523(tcp window advertisement),
1524.Cm sack
1525(selective ack),
1526.Cm ts
1527(rfc1323 timestamp) and
1528.Cm cc
1529(rfc1644 t/tcp connection count).
1530The absence of a particular option may be denoted
1531with a
1532.Ql \&! .
1533.It Cm uid Ar user
1534Match all TCP or UDP packets sent by or received for a
1535.Ar user .
1536A
1537.Ar user
1538may be matched by name or identification number.
1539.It Cm verrevpath
1540For incoming packets,
1541a routing table lookup is done on the packet's source address.
1542If the interface on which the packet entered the system matches the
1543outgoing interface for the route,
1544the packet matches.
1545If the interfaces do not match up,
1546the packet does not match.
1547All outgoing packets or packets with no incoming interface match.
1548.Pp
1549The name and functionality of the option is intentionally similar to
1550the Cisco IOS command:
1551.Pp
1552.Dl ip verify unicast reverse-path
1553.Pp
1554This option can be used to make anti-spoofing rules to reject all
1555packets with source addresses not from this interface.
1556See also the option
1557.Cm antispoof .
1558.It Cm versrcreach
1559For incoming packets,
1560a routing table lookup is done on the packet's source address.
1561If a route to the source address exists, but not the default route
1562or a blackhole/reject route, the packet matches.
1563Otherwise, the packet does not match.
1564All outgoing packets match.
1565.Pp
1566The name and functionality of the option is intentionally similar to
1567the Cisco IOS command:
1568.Pp
1569.Dl ip verify unicast source reachable-via any
1570.Pp
1571This option can be used to make anti-spoofing rules to reject all
1572packets whose source address is unreachable.
1573.It Cm antispoof
1574For incoming packets, the packet's source address is checked if it
1575belongs to a directly connected network.
1576If the network is directly connected, then the interface the packet
1577came on in is compared to the interface the network is connected to.
1578When incoming interface and directly connected interface are not the
1579same, the packet does not match.
1580Otherwise, the packet does match.
1581All outgoing packets match.
1582.Pp
1583This option can be used to make anti-spoofing rules to reject all
1584packets that pretend to be from a directly connected network but do
1585not come in through that interface.
1586This option is similar to but more restricted than
1587.Cm verrevpath
1588because it engages only on packets with source addresses of directly
1589connected networks instead of all source addresses.
1590.El
1591.Sh LOOKUP TABLES
1592Lookup tables are useful to handle large sparse address sets,
1593typically from a hundred to several thousands of entries.
1594There may be up to 128 different lookup tables, numbered 0 to 127.
1595.Pp
1596Each entry is represented by an
1597.Ar addr Ns Op / Ns Ar masklen
1598and will match all addresses with base
1599.Ar addr
1600(specified as an IP address or a hostname)
1601and mask width of
1602.Ar masklen
1603bits.
1604If
1605.Ar masklen
1606is not specified, it defaults to 32.
1607When looking up an IP address in a table, the most specific
1608entry will match.
1609Associated with each entry is a 32-bit unsigned
1610.Ar value ,
1611which can optionally be checked by a rule matching code.
1612When adding an entry, if
1613.Ar value
1614is not specified, it defaults to 0.
1615.Pp
1616An entry can be added to a table
1617.Pq Cm add ,
1618removed from a table
1619.Pq Cm delete ,
1620a table can be examined
1621.Pq Cm list
1622or flushed
1623.Pq Cm flush .
1624.Pp
1625Internally, each table is stored in a Radix tree, the same way as
1626the routing table (see
1627.Xr route 4 ) .
1628.Pp
1629Lookup tables currently support IPv4 addresses only.
1630.Pp
1631The
1632.Cm tablearg
1633feature provides the ability to use a value, looked up in the table, as
1634the argument for a rule action, action parameter or rule option.
1635This can significantly reduce number of rules in some configurations.
1636If two tables are used in a rule, the result of the second (destination)
1637is used.
1638The
1639.Cm tablearg
1640argument can be used with the following actions:
1641.Cm nat, pipe , queue, divert, tee, netgraph, ngtee, fwd, skipto
1642action parameters:
1643.Cm tag, untag,
1644rule options:
1645.Cm limit, tagged.
1646.Pp
1647When used with
1648.Cm fwd
1649it is possible to supply table entries with values
1650that are in the form of IP addresses or hostnames.
1651See the
1652.Sx EXAMPLES
1653Section for example usage of tables and the tablearg keyword.
1654.Pp
1655When used with the
1656.Cm skipto
1657action, the user should be aware that the code will walk the ruleset
1658up to a rule equal to, or past, the given number, and should therefore try keep the
1659ruleset compact between the skipto and the target rules.
1660.Sh SETS OF RULES
1661Each rule belongs to one of 32 different
1662.Em sets
1663, numbered 0 to 31.
1664Set 31 is reserved for the default rule.
1665.Pp
1666By default, rules are put in set 0, unless you use the
1667.Cm set N
1668attribute when entering a new rule.
1669Sets can be individually and atomically enabled or disabled,
1670so this mechanism permits an easy way to store multiple configurations
1671of the firewall and quickly (and atomically) switch between them.
1672The command to enable/disable sets is
1673.Bd -ragged -offset indent
1674.Nm
1675.Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
1676.Ed
1677.Pp
1678where multiple
1679.Cm enable
1680or
1681.Cm disable
1682sections can be specified.
1683Command execution is atomic on all the sets specified in the command.
1684By default, all sets are enabled.
1685.Pp
1686When you disable a set, its rules behave as if they do not exist
1687in the firewall configuration, with only one exception:
1688.Bd -ragged -offset indent
1689dynamic rules created from a rule before it had been disabled
1690will still be active until they expire.
1691In order to delete
1692dynamic rules you have to explicitly delete the parent rule
1693which generated them.
1694.Ed
1695.Pp
1696The set number of rules can be changed with the command
1697.Bd -ragged -offset indent
1698.Nm
1699.Cm set move
1700.Brq Cm rule Ar rule-number | old-set
1701.Cm to Ar new-set
1702.Ed
1703.Pp
1704Also, you can atomically swap two rulesets with the command
1705.Bd -ragged -offset indent
1706.Nm
1707.Cm set swap Ar first-set second-set
1708.Ed
1709.Pp
1710See the
1711.Sx EXAMPLES
1712Section on some possible uses of sets of rules.
1713.Sh STATEFUL FIREWALL
1714Stateful operation is a way for the firewall to dynamically
1715create rules for specific flows when packets that
1716match a given pattern are detected.
1717Support for stateful
1718operation comes through the
1719.Cm check-state , keep-state
1720and
1721.Cm limit
1722options of
1723.Nm rules .
1724.Pp
1725Dynamic rules are created when a packet matches a
1726.Cm keep-state
1727or
1728.Cm limit
1729rule, causing the creation of a
1730.Em dynamic
1731rule which will match all and only packets with
1732a given
1733.Em protocol
1734between a
1735.Em src-ip/src-port dst-ip/dst-port
1736pair of addresses
1737.Em ( src
1738and
1739.Em dst
1740are used here only to denote the initial match addresses, but they
1741are completely equivalent afterwards).
1742Dynamic rules will be checked at the first
1743.Cm check-state, keep-state
1744or
1745.Cm limit
1746occurrence, and the action performed upon a match will be the same
1747as in the parent rule.
1748.Pp
1749Note that no additional attributes other than protocol and IP addresses
1750and ports are checked on dynamic rules.
1751.Pp
1752The typical use of dynamic rules is to keep a closed firewall configuration,
1753but let the first TCP SYN packet from the inside network install a
1754dynamic rule for the flow so that packets belonging to that session
1755will be allowed through the firewall:
1756.Pp
1757.Dl "ipfw add check-state"
1758.Dl "ipfw add allow tcp from my-subnet to any setup keep-state"
1759.Dl "ipfw add deny tcp from any to any"
1760.Pp
1761A similar approach can be used for UDP, where an UDP packet coming
1762from the inside will install a dynamic rule to let the response through
1763the firewall:
1764.Pp
1765.Dl "ipfw add check-state"
1766.Dl "ipfw add allow udp from my-subnet to any keep-state"
1767.Dl "ipfw add deny udp from any to any"
1768.Pp
1769Dynamic rules expire after some time, which depends on the status
1770of the flow and the setting of some
1771.Cm sysctl
1772variables.
1773See Section
1774.Sx SYSCTL VARIABLES
1775for more details.
1776For TCP sessions, dynamic rules can be instructed to periodically
1777send keepalive packets to refresh the state of the rule when it is
1778about to expire.
1779.Pp
1780See Section
1781.Sx EXAMPLES
1782for more examples on how to use dynamic rules.
1783.Sh TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
1784.Nm
1785is also the user interface for the
1786.Nm dummynet
1787traffic shaper.
1788.Pp
1789.Nm dummynet
1790operates by first using the firewall to classify packets and divide them into
1791.Em flows ,
1792using any match pattern that can be used in
1793.Nm
1794rules.
1795Depending on local policies, a flow can contain packets for a single
1796TCP connection, or from/to a given host, or entire subnet, or a
1797protocol type, etc.
1798.Pp
1799There are two modes of
1800.Nm dummynet
1801operation:
1802.Dq normal
1803and
1804.Dq fast .
1805The
1806.Dq normal
1807mode tries to emulate a real link: the
1808.Nm dummynet
1809scheduler ensures that the packet will not leave the pipe faster than it
1810would on the real link with a given bandwidth.
1811The
1812.Dq fast
1813mode allows certain packets to bypass the
1814.Nm dummynet
1815scheduler (if packet flow does not exceed pipe's bandwidth).
1816This is the reason why the
1817.Dq fast
1818mode requires less CPU cycles per packet (on average) and packet latency
1819can be significantly lower in comparison to a real link with the same
1820bandwidth.
1821The default mode is
1822.Dq normal .
1823The
1824.Dq fast
1825mode can be enabled by setting the
1826.Va net.inet.ip.dummynet.io_fast
1827.Xr sysctl 8
1828variable to a non-zero value.
1829.Pp
1830Packets belonging to the same flow are then passed to either of two
1831different objects, which implement the traffic regulation:
1832.Bl -hang -offset XXXX
1833.It Em pipe
1834A pipe emulates a link with given bandwidth, propagation delay,
1835queue size and packet loss rate.
1836Packets are queued in front of the pipe as they come out from the classifier,
1837and then transferred to the pipe according to the pipe's parameters.
1838.Pp
1839.It Em queue
1840A queue
1841is an abstraction used to implement the WF2Q+
1842(Worst-case Fair Weighted Fair Queueing) policy, which is
1843an efficient variant of the WFQ policy.
1844.br
1845The queue associates a
1846.Em weight
1847and a reference pipe to each flow, and then all backlogged (i.e.,
1848with packets queued) flows linked to the same pipe share the pipe's
1849bandwidth proportionally to their weights.
1850Note that weights are not priorities; a flow with a lower weight
1851is still guaranteed to get its fraction of the bandwidth even if a
1852flow with a higher weight is permanently backlogged.
1853.Pp
1854.El
1855In practice,
1856.Em pipes
1857can be used to set hard limits to the bandwidth that a flow can use, whereas
1858.Em queues
1859can be used to determine how different flows share the available bandwidth.
1860.Pp
1861The
1862.Em pipe
1863and
1864.Em queue
1865configuration commands are the following:
1866.Bd -ragged -offset indent
1867.Cm pipe Ar number Cm config Ar pipe-configuration
1868.Pp
1869.Cm queue Ar number Cm config Ar queue-configuration
1870.Ed
1871.Pp
1872The following parameters can be configured for a pipe:
1873.Pp
1874.Bl -tag -width indent -compact
1875.It Cm bw Ar bandwidth | device
1876Bandwidth, measured in
1877.Sm off
1878.Op Cm K | M
1879.Brq Cm bit/s | Byte/s .
1880.Sm on
1881.Pp
1882A value of 0 (default) means unlimited bandwidth.
1883The unit must immediately follow the number, as in
1884.Pp
1885.Dl "ipfw pipe 1 config bw 300Kbit/s"
1886.Pp
1887If a device name is specified instead of a numeric value, as in
1888.Pp
1889.Dl "ipfw pipe 1 config bw tun0"
1890.Pp
1891then the transmit clock is supplied by the specified device.
1892At the moment only the
1893.Xr tun 4
1894device supports this
1895functionality, for use in conjunction with
1896.Xr ppp 8 .
1897.Pp
1898.It Cm delay Ar ms-delay
1899Propagation delay, measured in milliseconds.
1900The value is rounded to the next multiple of the clock tick
1901(typically 10ms, but it is a good practice to run kernels
1902with
1903.Dq "options HZ=1000"
1904to reduce
1905the granularity to 1ms or less).
1906Default value is 0, meaning no delay.
1907.El
1908.Pp
1909The following parameters can be configured for a queue:
1910.Pp
1911.Bl -tag -width indent -compact
1912.It Cm pipe Ar pipe_nr
1913Connects a queue to the specified pipe.
1914Multiple queues (with the same or different weights) can be connected to
1915the same pipe, which specifies the aggregate rate for the set of queues.
1916.Pp
1917.It Cm weight Ar weight
1918Specifies the weight to be used for flows matching this queue.
1919The weight must be in the range 1..100, and defaults to 1.
1920.El
1921.Pp
1922Finally, the following parameters can be configured for both
1923pipes and queues:
1924.Pp
1925.Bl -tag -width XXXX -compact
1926.Pp
1927.It Cm buckets Ar hash-table-size
1928Specifies the size of the hash table used for storing the
1929various queues.
1930Default value is 64 controlled by the
1931.Xr sysctl 8
1932variable
1933.Va net.inet.ip.dummynet.hash_size ,
1934allowed range is 16 to 65536.
1935.Pp
1936.It Cm mask Ar mask-specifier
1937Packets sent to a given pipe or queue by an
1938.Nm
1939rule can be further classified into multiple flows, each of which is then
1940sent to a different
1941.Em dynamic
1942pipe or queue.
1943A flow identifier is constructed by masking the IP addresses,
1944ports and protocol types as specified with the
1945.Cm mask
1946options in the configuration of the pipe or queue.
1947For each different flow identifier, a new pipe or queue is created
1948with the same parameters as the original object, and matching packets
1949are sent to it.
1950.Pp
1951Thus, when
1952.Em dynamic pipes
1953are used, each flow will get the same bandwidth as defined by the pipe,
1954whereas when
1955.Em dynamic queues
1956are used, each flow will share the parent's pipe bandwidth evenly
1957with other flows generated by the same queue (note that other queues
1958with different weights might be connected to the same pipe).
1959.br
1960Available mask specifiers are a combination of one or more of the following:
1961.Pp
1962.Cm dst-ip Ar mask ,
1963.Cm dst-ip6 Ar mask ,
1964.Cm src-ip Ar mask ,
1965.Cm src-ip6 Ar mask ,
1966.Cm dst-port Ar mask ,
1967.Cm src-port Ar mask ,
1968.Cm flow-id Ar mask ,
1969.Cm proto Ar mask
1970or
1971.Cm all ,
1972.Pp
1973where the latter means all bits in all fields are significant.
1974.Pp
1975.It Cm noerror
1976When a packet is dropped by a
1977.Nm dummynet
1978queue or pipe, the error
1979is normally reported to the caller routine in the kernel, in the
1980same way as it happens when a device queue fills up.
1981Setting this
1982option reports the packet as successfully delivered, which can be
1983needed for some experimental setups where you want to simulate
1984loss or congestion at a remote router.
1985.Pp
1986.It Cm plr Ar packet-loss-rate
1987Packet loss rate.
1988Argument
1989.Ar packet-loss-rate
1990is a floating-point number between 0 and 1, with 0 meaning no
1991loss, 1 meaning 100% loss.
1992The loss rate is internally represented on 31 bits.
1993.Pp
1994.It Cm queue Brq Ar slots | size Ns Cm Kbytes
1995Queue size, in
1996.Ar slots
1997or
1998.Cm KBytes .
1999Default value is 50 slots, which
2000is the typical queue size for Ethernet devices.
2001Note that for slow speed links you should keep the queue
2002size short or your traffic might be affected by a significant
2003queueing delay.
2004E.g., 50 max-sized ethernet packets (1500 bytes) mean 600Kbit
2005or 20s of queue on a 30Kbit/s pipe.
2006Even worse effects can result if you get packets from an
2007interface with a much larger MTU, e.g.\& the loopback interface
2008with its 16KB packets.
2009The
2010.Xr sysctl 8
2011variables
2012.Em net.inet.ip.dummynet.pipe_byte_limit
2013and
2014.Em net.inet.ip.dummynet.pipe_slot_limit
2015control the maximum lengths that can be specified.
2016.Pp
2017.It Cm red | gred Ar w_q Ns / Ns Ar min_th Ns / Ns Ar max_th Ns / Ns Ar max_p
2018Make use of the RED (Random Early Detection) queue management algorithm.
2019.Ar w_q
2020and
2021.Ar max_p
2022are floating
2023point numbers between 0 and 1 (0 not included), while
2024.Ar min_th
2025and
2026.Ar max_th
2027are integer numbers specifying thresholds for queue management
2028(thresholds are computed in bytes if the queue has been defined
2029in bytes, in slots otherwise).
2030The
2031.Nm dummynet
2032also supports the gentle RED variant (gred).
2033Three
2034.Xr sysctl 8
2035variables can be used to control the RED behaviour:
2036.Bl -tag -width indent
2037.It Va net.inet.ip.dummynet.red_lookup_depth
2038specifies the accuracy in computing the average queue
2039when the link is idle (defaults to 256, must be greater than zero)
2040.It Va net.inet.ip.dummynet.red_avg_pkt_size
2041specifies the expected average packet size (defaults to 512, must be
2042greater than zero)
2043.It Va net.inet.ip.dummynet.red_max_pkt_size
2044specifies the expected maximum packet size, only used when queue
2045thresholds are in bytes (defaults to 1500, must be greater than zero).
2046.El
2047.El
2048.Pp
2049When used with IPv6 data,
2050.Nm dummynet
2051currently has several limitations.
2052Information necessary to route link-local packets to an
2053interface is not available after processing by
2054.Nm dummynet
2055so those packets are dropped in the output path.
2056Care should be taken to insure that link-local packets are not passed to
2057.Nm dummynet .
2058.Sh CHECKLIST
2059Here are some important points to consider when designing your
2060rules:
2061.Bl -bullet
2062.It
2063Remember that you filter both packets going
2064.Cm in
2065and
2066.Cm out .
2067Most connections need packets going in both directions.
2068.It
2069Remember to test very carefully.
2070It is a good idea to be near the console when doing this.
2071If you cannot be near the console,
2072use an auto-recovery script such as the one in
2073.Pa /usr/share/examples/ipfw/change_rules.sh .
2074.It
2075Do not forget the loopback interface.
2076.El
2077.Sh FINE POINTS
2078.Bl -bullet
2079.It
2080There are circumstances where fragmented datagrams are unconditionally
2081dropped.
2082TCP packets are dropped if they do not contain at least 20 bytes of
2083TCP header, UDP packets are dropped if they do not contain a full 8
2084byte UDP header, and ICMP packets are dropped if they do not contain
20854 bytes of ICMP header, enough to specify the ICMP type, code, and
2086checksum.
2087These packets are simply logged as
2088.Dq pullup failed
2089since there may not be enough good data in the packet to produce a
2090meaningful log entry.
2091.It
2092Another type of packet is unconditionally dropped, a TCP packet with a
2093fragment offset of one.
2094This is a valid packet, but it only has one use, to try
2095to circumvent firewalls.
2096When logging is enabled, these packets are
2097reported as being dropped by rule -1.
2098.It
2099If you are logged in over a network, loading the
2100.Xr kld 4
2101version of
2102.Nm
2103is probably not as straightforward as you would think.
2104I recommend the following command line:
2105.Bd -literal -offset indent
2106kldload ipfw && \e
2107ipfw add 32000 allow ip from any to any
2108.Ed
2109.Pp
2110Along the same lines, doing an
2111.Bd -literal -offset indent
2112ipfw flush
2113.Ed
2114.Pp
2115in similar surroundings is also a bad idea.
2116.It
2117The
2118.Nm
2119filter list may not be modified if the system security level
2120is set to 3 or higher
2121(see
2122.Xr init 8
2123for information on system security levels).
2124.El
2125.Sh PACKET DIVERSION
2126A
2127.Xr divert 4
2128socket bound to the specified port will receive all packets
2129diverted to that port.
2130If no socket is bound to the destination port, or if the divert module is
2131not loaded, or if the kernel was not compiled with divert socket support,
2132the packets are dropped.
2133.Sh NETWORK ADDRESS TRANSLATION (NAT)
2134The nat configuration command is the following:
2135.Bd -ragged -offset indent
2136.Bk -words
2137.Cm nat
2138.Ar nat_number
2139.Cm config
2140.Ar nat-configuration
2141.Ek
2142.Ed
2143.Pp
2144.
2145The following parameters can be configured:
2146.Bl -tag -width indent
2147.It Cm ip Ar ip_address
2148Define an ip address to use for aliasing.
2149.It Cm if Ar nic
2150Use ip addres of NIC for aliasing, dynamically changing
2151it if NIC's ip address change.
2152.It Cm log
2153Enable logging on this nat instance.
2154.It Cm deny_in
2155Deny any incoming connection from outside world.
2156.It Cm same_ports
2157Try to leave the alias port numbers unchanged from
2158the actual local port numbers.
2159.It Cm unreg_only
2160Traffic on the local network not originating from an
2161unregistered address spaces will be ignored.
2162.It Cm reset
2163Reset table of the packet aliasing engine on address change.
2164.It Cm reverse
2165Reverse the way libalias handles aliasing.
2166.It Cm proxy_only
2167Obey transparent proxy rules only, packet aliasing is not performed.
2168.El
2169.Pp
2170To let the packet continue after being (de)aliased, set the sysctl variable
2171.Va net.inet.ip.fw.one_pass
2172to 0.
2173For more information about aliasing modes, refer to
2174.Xr libalias 3
2175.
2176See Section
2177.Sx EXAMPLES
2178for some examples about nat usage.
2179.Sh REDIRECT AND LSNAT SUPPORT IN IPFW
2180Redirect and LSNAT support follow closely the syntax used in
2181.Xr natd 8
2182.
2183See Section
2184.Sx EXAMPLES
2185for some examples on how to do redirect and lsnat.
2186.Sh SCTP NAT SUPPORT
2187Sctp nat can be configured in a simillar manner to TCP through the
2188ipfw command line tool
2189.Xr ipfw 8
2190, the main difference is that
2191.Nm sctp nat
2192does not do port
2193translation. Since the local and global side ports will be the same,
2194there is no need to specify both. Ports are redirected as follows:
2195.Bd -ragged -offset indent
2196.Bk -words
2197.Cm nat
2198.Ar nat_number
2199.Cm config if
2200.Ar nic
2201.Cm redirect_port sctp
2202.Ar ip_address [,addr_list] {[port | port-port] [,ports]}
2203.Ek
2204.Ed
2205.Pp
2206.
2207Most
2208.B sctp nat
2209configuration can be done in real-time through the
2210.B sysctl(8)
2211interface. All may be changed dynamically, though the hash_table size will only
2212change for new
2213.Nm nat
2214instances. See
2215.Sx SYSCTL VARIABLES
2216for more info.
2217.Sh SYSCTL VARIABLES
2218A set of
2219.Xr sysctl 8
2220variables controls the behaviour of the firewall and
2221associated modules
2222.Pq Nm dummynet , bridge , sctp nat .
2223These are shown below together with their default value
2224(but always check with the
2225.Xr sysctl 8
2226command what value is actually in use) and meaning:
2227.Bl -tag -width indent
2228.It Va net.inet.ip.alias.sctp.accept_global_ootb_addip: No 0
2229Defines how the
2230.Nm nat
2231responds to receipt of global OOTB ASCONF-AddIP:
2232.Bl -tag -width indent
2233.It Cm 0
2234No response (unless a partially matching association exists -
2235ports and vtags match but global address does not)
2236.It Cm 1
2237.Nm nat
2238will accept and process all OOTB global AddIP messages.
2239.El
2240.Pp
2241Option 1 should never be selected as this forms a security risk. An attacker can
2242establish multiple fake associations by sending AddIP messages.
2243.It Va net.inet.ip.alias.sctp.chunk_proc_limit: No 5
2244Defines the maximum number of chunks in an SCTP packet that will be parsed for a
2245packet that matches an existing association. This value is enforced to be greater or equal
2246than
2247.Cm net.inet.ip.alias.sctp.initialising_chunk_proc_limit .
2248A high value is
2249a DoS risk yet setting too low a value may result in important control chunks in
2250the packet not being located and parsed.
2251.It Va net.inet.ip.alias.sctp.error_on_ootb: No 1
2252Defines when the
2253.Nm nat
2254responds to any Out-of-the-Blue (OOTB) packets with ErrorM
2255packets. An OOTB packet is a packet that arrives with no existing association
2256registered in the
2257.Nm nat
2258and is not an INIT or ASCONF-AddIP packet:
2259.Bl -tag -width indent
2260.It Cm 0
2261ErrorM is never sent in response to OOTB packets.
2262.It Cm 1
2263ErrorM is only sent to OOTB packets received on the local side.
2264.It Cm 2
2265ErrorM is sent to the local side and on the global side ONLY if there is a
2266partial match (ports and vtags match but the source global IP does not). This
2267value is only useful if the
2268.Nm nat
2269is tracking global IP addresses.
2270.It Cm 3
2271ErrorM is sent in response to all OOTB packets on both the local and global side
2272(DoS risk).
2273.El
2274.Pp
2275At the moment the default is 0, since the ErrorM packet is not yet
2276supported by most SCTP stacks. When it is supported, and if not tracking
2277global addresses, we recommend setting this value to 1 to allow
2278multi-homed local hosts to function with the
2279.Nm nat .
2280To track global addresses, we recommend setting this value to 2 to
2281allow global hosts to be informed when they need to (re)send an
2282ASCONF-AddIP. Value 3 should never be chosen (except for debugging) as
2283the
2284.Nm nat
2285will respond to all OOTB global packets (a DoS risk).
2286.It Va net.inet.ip.alias.sctp.hashtable_size: No 2003
2287Size of hash tables used for
2288.Nm nat
2289lookups (100 < prime_number > 1000001)
2290This value sets the
2291.Nm hash table
2292size for any future created
2293.Nm nat
2294instance and therefore must be set prior to creating a
2295.Nm nat
2296instance.
2297The table sizes my be changed to suit specific needs. If there will be few
2298concurrent associations, and memory is scarce, you may make these smaller.  If
2299there will be many thousands (or millions) of concurrent associations, you
2300should make these larger. A prime number is best for the table size. The sysctl
2301update function will adjust your input value to the next highest prime number.
2302.It Va net.inet.ip.alias.sctp.holddown_time:  No 0
2303Hold association in table for this many seconds after receiving a
2304SHUTDOWN-COMPLETE.  This allows endpoints to correct shutdown gracefully if a
2305shutdown_complete is lost and retransmissions are required.
2306.It Va net.inet.ip.alias.sctp.init_timer: No 15
2307Timeout value while waiting for (INIT-ACK|AddIP-ACK).
2308This value cannot be 0.
2309.It Va net.inet.ip.alias.sctp.initialising_chunk_proc_limit: No 2
2310Defines the maximum number of chunks in an SCTP packet that will be parsed when
2311no existing association exists that matches that packet. Ideally this packet
2312will only be an INIT or ASCONF-AddIP packet. A higher value may become a DoS
2313risk as malformed packets can consume processing resources.
2314.It Va net.inet.ip.alias.sctp.param_proc_limit: No 25
2315Defines the maximum number of parameters within a chunk that will be parsed in a
2316packet. As for other similar sysctl variables, larger values pose a DoS risk.
2317.It Va net.inet.ip.alias.sctp.log_level: No 0
2318Level of detail in the system log messages (0 \- minimal, 1 \- event,
23192 \- info, 3 \- detail, 4 \- debug, 5 \- max debug). May be a good
2320option in high loss environments.
2321.It Va net.inet.ip.alias.sctp.shutdown_time: No 15
2322Timeout value while waiting for SHUTDOWN-COMPLETE.
2323This value cannot be 0.
2324.It Va net.inet.ip.alias.sctp.track_global_addresses: No 0
2325Enables/disables global IP address tracking within the
2326.Nm nat
2327and places an
2328upper limit on the number of addresses tracked for each association:
2329.Bl -tag -width indent
2330.It Cm 0
2331Global tracking is disabled
2332.It Cm >1
2333Enables tracking, the maximum number of addresses tracked for each
2334association is limited to this value
2335.El
2336.Pp
2337This variable is fully dynamic, the new value will be adopted for all newly
2338arriving associations, existing association are treated as they were previously.
2339Global tracking will decrease the number of collisions within the
2340.Nm nat
2341at a cost
2342of increased processing load, memory usage, complexity, and possible
2343.Nm nat
2344state
2345problems in complex networks with multiple
2346.Nm nats .
2347We recommend not tracking
2348global IP addresses, this will still result in a fully functional
2349.Nm nat .
2350.It Va net.inet.ip.alias.sctp.up_timer: No 300
2351Timeout value to keep an association up with no traffic.
2352This value cannot be 0.
2353.It Va net.inet.ip.dummynet.expire : No 1
2354Lazily delete dynamic pipes/queue once they have no pending traffic.
2355You can disable this by setting the variable to 0, in which case
2356the pipes/queues will only be deleted when the threshold is reached.
2357.It Va net.inet.ip.dummynet.hash_size : No 64
2358Default size of the hash table used for dynamic pipes/queues.
2359This value is used when no
2360.Cm buckets
2361option is specified when configuring a pipe/queue.
2362.It Va net.inet.ip.dummynet.io_fast : No 0
2363If set to a non-zero value,
2364the
2365.Dq fast
2366mode of
2367.Nm dummynet
2368operation (see above) is enabled.
2369.It Va net.inet.ip.dummynet.io_pkt
2370Number of packets passed to
2371.Nm dummynet .
2372.It Va net.inet.ip.dummynet.io_pkt_drop
2373Number of packets dropped by
2374.Nm dummynet .
2375.It Va net.inet.ip.dummynet.io_pkt_fast
2376Number of packets bypassed by the
2377.Nm dummynet
2378scheduler.
2379.It Va net.inet.ip.dummynet.max_chain_len : No 16
2380Target value for the maximum number of pipes/queues in a hash bucket.
2381The product
2382.Cm max_chain_len*hash_size
2383is used to determine the threshold over which empty pipes/queues
2384will be expired even when
2385.Cm net.inet.ip.dummynet.expire=0 .
2386.It Va net.inet.ip.dummynet.red_lookup_depth : No 256
2387.It Va net.inet.ip.dummynet.red_avg_pkt_size : No 512
2388.It Va net.inet.ip.dummynet.red_max_pkt_size : No 1500
2389Parameters used in the computations of the drop probability
2390for the RED algorithm.
2391.It Va net.inet.ip.dummynet.pipe_byte_limit : No 1048576
2392.It Va net.inet.ip.dummynet.pipe_slot_limit : No 100
2393The maximum queue size that can be specified in bytes or packets.
2394These limits prevent accidental exhaustion of resources such as mbufs.
2395If you raise these limits,
2396you should make sure the system is configured so that sufficient resources
2397are available.
2398.It Va net.inet.ip.fw.autoinc_step : No 100
2399Delta between rule numbers when auto-generating them.
2400The value must be in the range 1..1000.
2401.It Va net.inet.ip.fw.curr_dyn_buckets : Va net.inet.ip.fw.dyn_buckets
2402The current number of buckets in the hash table for dynamic rules
2403(readonly).
2404.It Va net.inet.ip.fw.debug : No 1
2405Controls debugging messages produced by
2406.Nm .
2407.It Va net.inet.ip.fw.default_rule : No 65535
2408The default rule number (read-only).
2409By the design of
2410.Nm , the default rule is the last one, so its number
2411can also serve as the highest number allowed for a rule.
2412.It Va net.inet.ip.fw.dyn_buckets : No 256
2413The number of buckets in the hash table for dynamic rules.
2414Must be a power of 2, up to 65536.
2415It only takes effect when all dynamic rules have expired, so you
2416are advised to use a
2417.Cm flush
2418command to make sure that the hash table is resized.
2419.It Va net.inet.ip.fw.dyn_count : No 3
2420Current number of dynamic rules
2421(read-only).
2422.It Va net.inet.ip.fw.dyn_keepalive : No 1
2423Enables generation of keepalive packets for
2424.Cm keep-state
2425rules on TCP sessions.
2426A keepalive is generated to both
2427sides of the connection every 5 seconds for the last 20
2428seconds of the lifetime of the rule.
2429.It Va net.inet.ip.fw.dyn_max : No 8192
2430Maximum number of dynamic rules.
2431When you hit this limit, no more dynamic rules can be
2432installed until old ones expire.
2433.It Va net.inet.ip.fw.dyn_ack_lifetime : No 300
2434.It Va net.inet.ip.fw.dyn_syn_lifetime : No 20
2435.It Va net.inet.ip.fw.dyn_fin_lifetime : No 1
2436.It Va net.inet.ip.fw.dyn_rst_lifetime : No 1
2437.It Va net.inet.ip.fw.dyn_udp_lifetime : No 5
2438.It Va net.inet.ip.fw.dyn_short_lifetime : No 30
2439These variables control the lifetime, in seconds, of dynamic
2440rules.
2441Upon the initial SYN exchange the lifetime is kept short,
2442then increased after both SYN have been seen, then decreased
2443again during the final FIN exchange or when a RST is received.
2444Both
2445.Em dyn_fin_lifetime
2446and
2447.Em dyn_rst_lifetime
2448must be strictly lower than 5 seconds, the period of
2449repetition of keepalives.
2450The firewall enforces that.
2451.It Va net.inet.ip.fw.enable : No 1
2452Enables the firewall.
2453Setting this variable to 0 lets you run your machine without
2454firewall even if compiled in.
2455.It Va net.inet6.ip6.fw.enable : No 1
2456provides the same functionality as above for the IPv6 case.
2457.It Va net.inet.ip.fw.one_pass : No 1
2458When set, the packet exiting from the
2459.Nm dummynet
2460pipe or from
2461.Xr ng_ipfw 4
2462node is not passed though the firewall again.
2463Otherwise, after an action, the packet is
2464reinjected into the firewall at the next rule.
2465.It Va net.inet.ip.fw.tables_max : No 128
2466Maximum number of tables (read-only).
2467.It Va net.inet.ip.fw.verbose : No 1
2468Enables verbose messages.
2469.It Va net.inet.ip.fw.verbose_limit : No 0
2470Limits the number of messages produced by a verbose firewall.
2471.It Va net.inet6.ip6.fw.deny_unknown_exthdrs : No 1
2472If enabled packets with unknown IPv6 Extension Headers will be denied.
2473.It Va net.link.ether.ipfw : No 0
2474Controls whether layer-2 packets are passed to
2475.Nm .
2476Default is no.
2477.It Va net.link.bridge.ipfw : No 0
2478Controls whether bridged packets are passed to
2479.Nm .
2480Default is no.
2481.El
2482.Pp
2483.Sh EXAMPLES
2484There are far too many possible uses of
2485.Nm
2486so this Section will only give a small set of examples.
2487.Pp
2488.Ss BASIC PACKET FILTERING
2489This command adds an entry which denies all tcp packets from
2490.Em cracker.evil.org
2491to the telnet port of
2492.Em wolf.tambov.su
2493from being forwarded by the host:
2494.Pp
2495.Dl "ipfw add deny tcp from cracker.evil.org to wolf.tambov.su telnet"
2496.Pp
2497This one disallows any connection from the entire cracker's
2498network to my host:
2499.Pp
2500.Dl "ipfw add deny ip from 123.45.67.0/24 to my.host.org"
2501.Pp
2502A first and efficient way to limit access (not using dynamic rules)
2503is the use of the following rules:
2504.Pp
2505.Dl "ipfw add allow tcp from any to any established"
2506.Dl "ipfw add allow tcp from net1 portlist1 to net2 portlist2 setup"
2507.Dl "ipfw add allow tcp from net3 portlist3 to net3 portlist3 setup"
2508.Dl "..."
2509.Dl "ipfw add deny tcp from any to any"
2510.Pp
2511The first rule will be a quick match for normal TCP packets,
2512but it will not match the initial SYN packet, which will be
2513matched by the
2514.Cm setup
2515rules only for selected source/destination pairs.
2516All other SYN packets will be rejected by the final
2517.Cm deny
2518rule.
2519.Pp
2520If you administer one or more subnets, you can take advantage
2521of the address sets and or-blocks and write extremely
2522compact rulesets which selectively enable services to blocks
2523of clients, as below:
2524.Pp
2525.Dl "goodguys=\*q{ 10.1.2.0/24{20,35,66,18} or 10.2.3.0/28{6,3,11} }\*q"
2526.Dl "badguys=\*q10.1.2.0/24{8,38,60}\*q"
2527.Dl ""
2528.Dl "ipfw add allow ip from ${goodguys} to any"
2529.Dl "ipfw add deny ip from ${badguys} to any"
2530.Dl "... normal policies ..."
2531.Pp
2532The
2533.Cm verrevpath
2534option could be used to do automated anti-spoofing by adding the
2535following to the top of a ruleset:
2536.Pp
2537.Dl "ipfw add deny ip from any to any not verrevpath in"
2538.Pp
2539This rule drops all incoming packets that appear to be coming to the
2540system on the wrong interface.
2541For example, a packet with a source
2542address belonging to a host on a protected internal network would be
2543dropped if it tried to enter the system from an external interface.
2544.Pp
2545The
2546.Cm antispoof
2547option could be used to do similar but more restricted anti-spoofing
2548by adding the following to the top of a ruleset:
2549.Pp
2550.Dl "ipfw add deny ip from any to any not antispoof in"
2551.Pp
2552This rule drops all incoming packets that appear to be coming from another
2553directly connected system but on the wrong interface.
2554For example, a packet with a source address of
2555.Li 192.168.0.0/24
2556, configured on
2557.Li fxp0
2558, but coming in on
2559.Li fxp1
2560would be dropped.
2561.Ss DYNAMIC RULES
2562In order to protect a site from flood attacks involving fake
2563TCP packets, it is safer to use dynamic rules:
2564.Pp
2565.Dl "ipfw add check-state"
2566.Dl "ipfw add deny tcp from any to any established"
2567.Dl "ipfw add allow tcp from my-net to any setup keep-state"
2568.Pp
2569This will let the firewall install dynamic rules only for
2570those connection which start with a regular SYN packet coming
2571from the inside of our network.
2572Dynamic rules are checked when encountering the first
2573.Cm check-state
2574or
2575.Cm keep-state
2576rule.
2577A
2578.Cm check-state
2579rule should usually be placed near the beginning of the
2580ruleset to minimize the amount of work scanning the ruleset.
2581Your mileage may vary.
2582.Pp
2583To limit the number of connections a user can open
2584you can use the following type of rules:
2585.Pp
2586.Dl "ipfw add allow tcp from my-net/24 to any setup limit src-addr 10"
2587.Dl "ipfw add allow tcp from any to me setup limit src-addr 4"
2588.Pp
2589The former (assuming it runs on a gateway) will allow each host
2590on a /24 network to open at most 10 TCP connections.
2591The latter can be placed on a server to make sure that a single
2592client does not use more than 4 simultaneous connections.
2593.Pp
2594.Em BEWARE :
2595stateful rules can be subject to denial-of-service attacks
2596by a SYN-flood which opens a huge number of dynamic rules.
2597The effects of such attacks can be partially limited by
2598acting on a set of
2599.Xr sysctl 8
2600variables which control the operation of the firewall.
2601.Pp
2602Here is a good usage of the
2603.Cm list
2604command to see accounting records and timestamp information:
2605.Pp
2606.Dl ipfw -at list
2607.Pp
2608or in short form without timestamps:
2609.Pp
2610.Dl ipfw -a list
2611.Pp
2612which is equivalent to:
2613.Pp
2614.Dl ipfw show
2615.Pp
2616Next rule diverts all incoming packets from 192.168.2.0/24
2617to divert port 5000:
2618.Pp
2619.Dl ipfw divert 5000 ip from 192.168.2.0/24 to any in
2620.Pp
2621.Ss TRAFFIC SHAPING
2622The following rules show some of the applications of
2623.Nm
2624and
2625.Nm dummynet
2626for simulations and the like.
2627.Pp
2628This rule drops random incoming packets with a probability
2629of 5%:
2630.Pp
2631.Dl "ipfw add prob 0.05 deny ip from any to any in"
2632.Pp
2633A similar effect can be achieved making use of
2634.Nm dummynet
2635pipes:
2636.Pp
2637.Dl "ipfw add pipe 10 ip from any to any"
2638.Dl "ipfw pipe 10 config plr 0.05"
2639.Pp
2640We can use pipes to artificially limit bandwidth, e.g.\& on a
2641machine acting as a router, if we want to limit traffic from
2642local clients on 192.168.2.0/24 we do:
2643.Pp
2644.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
2645.Dl "ipfw pipe 1 config bw 300Kbit/s queue 50KBytes"
2646.Pp
2647note that we use the
2648.Cm out
2649modifier so that the rule is not used twice.
2650Remember in fact that
2651.Nm
2652rules are checked both on incoming and outgoing packets.
2653.Pp
2654Should we want to simulate a bidirectional link with bandwidth
2655limitations, the correct way is the following:
2656.Pp
2657.Dl "ipfw add pipe 1 ip from any to any out"
2658.Dl "ipfw add pipe 2 ip from any to any in"
2659.Dl "ipfw pipe 1 config bw 64Kbit/s queue 10Kbytes"
2660.Dl "ipfw pipe 2 config bw 64Kbit/s queue 10Kbytes"
2661.Pp
2662The above can be very useful, e.g.\& if you want to see how
2663your fancy Web page will look for a residential user who
2664is connected only through a slow link.
2665You should not use only one pipe for both directions, unless
2666you want to simulate a half-duplex medium (e.g.\& AppleTalk,
2667Ethernet, IRDA).
2668It is not necessary that both pipes have the same configuration,
2669so we can also simulate asymmetric links.
2670.Pp
2671Should we want to verify network performance with the RED queue
2672management algorithm:
2673.Pp
2674.Dl "ipfw add pipe 1 ip from any to any"
2675.Dl "ipfw pipe 1 config bw 500Kbit/s queue 100 red 0.002/30/80/0.1"
2676.Pp
2677Another typical application of the traffic shaper is to
2678introduce some delay in the communication.
2679This can significantly affect applications which do a lot of Remote
2680Procedure Calls, and where the round-trip-time of the
2681connection often becomes a limiting factor much more than
2682bandwidth:
2683.Pp
2684.Dl "ipfw add pipe 1 ip from any to any out"
2685.Dl "ipfw add pipe 2 ip from any to any in"
2686.Dl "ipfw pipe 1 config delay 250ms bw 1Mbit/s"
2687.Dl "ipfw pipe 2 config delay 250ms bw 1Mbit/s"
2688.Pp
2689Per-flow queueing can be useful for a variety of purposes.
2690A very simple one is counting traffic:
2691.Pp
2692.Dl "ipfw add pipe 1 tcp from any to any"
2693.Dl "ipfw add pipe 1 udp from any to any"
2694.Dl "ipfw add pipe 1 ip from any to any"
2695.Dl "ipfw pipe 1 config mask all"
2696.Pp
2697The above set of rules will create queues (and collect
2698statistics) for all traffic.
2699Because the pipes have no limitations, the only effect is
2700collecting statistics.
2701Note that we need 3 rules, not just the last one, because
2702when
2703.Nm
2704tries to match IP packets it will not consider ports, so we
2705would not see connections on separate ports as different
2706ones.
2707.Pp
2708A more sophisticated example is limiting the outbound traffic
2709on a net with per-host limits, rather than per-network limits:
2710.Pp
2711.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
2712.Dl "ipfw add pipe 2 ip from any to 192.168.2.0/24 in"
2713.Dl "ipfw pipe 1 config mask src-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
2714.Dl "ipfw pipe 2 config mask dst-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
2715.Ss LOOKUP TABLES
2716In the following example, we need to create several traffic bandwidth
2717classes and we need different hosts/networks to fall into different classes.
2718We create one pipe for each class and configure them accordingly.
2719Then we create a single table and fill it with IP subnets and addresses.
2720For each subnet/host we set the argument equal to the number of the pipe
2721that it should use.
2722Then we classify traffic using a single rule:
2723.Pp
2724.Dl "ipfw pipe 1 config bw 1000Kbyte/s"
2725.Dl "ipfw pipe 4 config bw 4000Kbyte/s"
2726.Dl "..."
2727.Dl "ipfw table 1 add 192.168.2.0/24 1"
2728.Dl "ipfw table 1 add 192.168.0.0/27 4"
2729.Dl "ipfw table 1 add 192.168.0.2 1"
2730.Dl "..."
2731.Dl "ipfw add pipe tablearg ip from table(1) to any"
2732.Pp
2733Using the
2734.Cm fwd
2735action, the table entries may include hostnames and IP addresses.
2736.Pp
2737.Dl "ipfw table 1 add 192.168.2.0/24 10.23.2.1"
2738.Dl "ipfw table 1 add 192.168.0.0/27 router1.dmz"
2739.Dl "..."
2740.Dl "ipfw add 100 fwd tablearg ip from any to table(1)"
2741.Ss SETS OF RULES
2742To add a set of rules atomically, e.g.\& set 18:
2743.Pp
2744.Dl "ipfw set disable 18"
2745.Dl "ipfw add NN set 18 ...         # repeat as needed"
2746.Dl "ipfw set enable 18"
2747.Pp
2748To delete a set of rules atomically the command is simply:
2749.Pp
2750.Dl "ipfw delete set 18"
2751.Pp
2752To test a ruleset and disable it and regain control if something goes wrong:
2753.Pp
2754.Dl "ipfw set disable 18"
2755.Dl "ipfw add NN set 18 ...         # repeat as needed"
2756.Dl "ipfw set enable 18; echo done; sleep 30 && ipfw set disable 18"
2757.Pp
2758Here if everything goes well, you press control-C before the "sleep"
2759terminates, and your ruleset will be left active.
2760Otherwise, e.g.\& if
2761you cannot access your box, the ruleset will be disabled after
2762the sleep terminates thus restoring the previous situation.
2763.Pp
2764To show rules of the specific set:
2765.Pp
2766.Dl "ipfw set 18 show"
2767.Pp
2768To show rules of the disabled set:
2769.Pp
2770.Dl "ipfw -S set 18 show"
2771.Pp
2772To clear a specific rule counters of the specific set:
2773.Pp
2774.Dl "ipfw set 18 zero NN"
2775.Pp
2776To delete a specific rule of the specific set:
2777.Pp
2778.Dl "ipfw set 18 delete NN"
2779.Ss NAT, REDIRECT AND LSNAT
2780First redirect all the traffic to nat instance 123:
2781.Pp
2782.Dl "ipfw add nat 123 all from any to any"
2783.Pp
2784Then to configure nat instance 123 to alias all the outgoing traffic with ip
2785192.168.0.123, blocking all incoming connections, trying to keep
2786same ports on both sides, clearing aliasing table on address change
2787and keeping a log of traffic/link statistics:
2788.Pp
2789.Dl "ipfw nat 123 config ip 192.168.0.123 log deny_in reset same_ports"
2790.Pp
2791Or to change address of instance 123, aliasing table will be cleared (see
2792reset option):
2793.Pp
2794.Dl "ipfw nat 123 config ip 10.0.0.1"
2795.Pp
2796To see configuration of nat instance 123:
2797.Pp
2798.Dl "ipfw nat 123 show config"
2799.Pp
2800To show logs of all the instances in range 111-999:
2801.Pp
2802.Dl "ipfw nat 111-999 show"
2803.Pp
2804To see configurations of all instances:
2805.Pp
2806.Dl "ipfw nat show config"
2807.Pp
2808Or a redirect rule with mixed modes could looks like:
2809.Pp
2810.Dl "ipfw nat 123 config redirect_addr 10.0.0.1 10.0.0.66"
2811.Dl "			 redirect_port tcp 192.168.0.1:80 500"
2812.Dl "			 redirect_proto udp 192.168.1.43 192.168.1.1"
2813.Dl "			 redirect_addr 192.168.0.10,192.168.0.11"
2814.Dl "			 	    10.0.0.100	# LSNAT"
2815.Dl "			 redirect_port tcp 192.168.0.1:80,192.168.0.10:22"
2816.Dl "			 	    500		# LSNAT"
2817.Pp
2818or it could be splitted in:
2819.Pp
2820.Dl "ipfw nat 1 config redirect_addr 10.0.0.1 10.0.0.66"
2821.Dl "ipfw nat 2 config redirect_port tcp 192.168.0.1:80 500"
2822.Dl "ipfw nat 3 config redirect_proto udp 192.168.1.43 192.168.1.1"
2823.Dl "ipfw nat 4 config redirect_addr 192.168.0.10,192.168.0.11,192.168.0.12"
2824.Dl "				         10.0.0.100"
2825.Dl "ipfw nat 5 config redirect_port tcp"
2826.Dl "			192.168.0.1:80,192.168.0.10:22,192.168.0.20:25 500"
2827.Pp
2828.Sh SEE ALSO
2829.Xr cpp 1 ,
2830.Xr m4 1 ,
2831.Xr altq 4 ,
2832.Xr divert 4 ,
2833.Xr dummynet 4 ,
2834.Xr if_bridge 4 ,
2835.Xr ip 4 ,
2836.Xr ipfirewall 4 ,
2837.Xr ng_ipfw 4 ,
2838.Xr protocols 5 ,
2839.Xr services 5 ,
2840.Xr init 8 ,
2841.Xr kldload 8 ,
2842.Xr reboot 8 ,
2843.Xr sysctl 8 ,
2844.Xr syslogd 8
2845.Sh HISTORY
2846The
2847.Nm
2848utility first appeared in
2849.Fx 2.0 .
2850.Nm dummynet
2851was introduced in
2852.Fx 2.2.8 .
2853Stateful extensions were introduced in
2854.Fx 4.0 .
2855.Nm ipfw2
2856was introduced in Summer 2002.
2857.Sh AUTHORS
2858.An Ugen J. S. Antsilevich ,
2859.An Poul-Henning Kamp ,
2860.An Alex Nash ,
2861.An Archie Cobbs ,
2862.An Luigi Rizzo .
2863.Pp
2864.An -nosplit
2865API based upon code written by
2866.An Daniel Boulet
2867for BSDI.
2868.Pp
2869.An -nosplit
2870In-kernel NAT support written by
2871.An Paolo Pisati Aq piso@FreeBSD.org
2872as part of a Summer of Code 2005 project.
2873.Pp
2874Work on
2875.Nm dummynet
2876traffic shaper supported by Akamba Corp.
2877.Pp
2878Sctp
2879.Nm nat
2880support has been developed by
2881.An The Centre for Advanced Internet Architectures (CAIA) Aq http://www.caia.swin.edu.au .
2882The primary developers and maintainers are David Hayes and Jason But.
2883For further information visit:
2884.Aq http://www.caia.swin.edu.au/urp/SONATA
2885.
2886.Sh BUGS
2887The syntax has grown over the years and sometimes it might be confusing.
2888Unfortunately, backward compatibility prevents cleaning up mistakes
2889made in the definition of the syntax.
2890.Pp
2891.Em !!! WARNING !!!
2892.Pp
2893Misconfiguring the firewall can put your computer in an unusable state,
2894possibly shutting down network services and requiring console access to
2895regain control of it.
2896.Pp
2897Incoming packet fragments diverted by
2898.Cm divert
2899are reassembled before delivery to the socket.
2900The action used on those packet is the one from the
2901rule which matches the first fragment of the packet.
2902.Pp
2903Packets diverted to userland, and then reinserted by a userland process
2904may lose various packet attributes.
2905The packet source interface name
2906will be preserved if it is shorter than 8 bytes and the userland process
2907saves and reuses the sockaddr_in
2908(as does
2909.Xr natd 8 ) ;
2910otherwise, it may be lost.
2911If a packet is reinserted in this manner, later rules may be incorrectly
2912applied, making the order of
2913.Cm divert
2914rules in the rule sequence very important.
2915.Pp
2916Dummynet drops all packets with IPv6 link-local addresses.
2917.Pp
2918Rules using
2919.Cm uid
2920or
2921.Cm gid
2922may not behave as expected.
2923In particular, incoming SYN packets may
2924have no uid or gid associated with them since they do not yet belong
2925to a TCP connection, and the uid/gid associated with a packet may not
2926be as expected if the associated process calls
2927.Xr setuid 2
2928or similar system calls.
2929.Pp
2930Rule syntax is subject to the command line environment and some patterns
2931may need to be escaped with the backslash character
2932or quoted appropriately.
2933.Pp
2934Due to the architecture of
2935.Xr libalias 3 ,
2936ipfw nat is not compatible with the tcp segmentation offloading
2937(TSO). Thus, to reliably nat your network traffic, please disable TSO
2938on your NICs using
2939.Xr ifconfig 8 .
2940.Pp
2941ICMP error messages are not implicitly matched by dynamic rules
2942for the respective conversations.
2943To avoid failures of network error detection and path MTU discovery,
2944ICMP error messages may need to be allowed explicitly through static
2945rules.
2946