xref: /freebsd/sbin/ipfw/ipfw.8 (revision 9aff62dee28239f84b4aa4a3429cf26dbbf770cc)
1.\"
2.Dd May 21, 2026
3.Dt IPFW 8
4.Os
5.Sh NAME
6.Nm ipfw , dnctl
7.Nd User interface for firewall, traffic shaper, packet scheduler,
8in-kernel NAT.\&
9.Sh SYNOPSIS
10.Ss FIREWALL CONFIGURATION
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.Pp
30.Nm
31.Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
32.Nm
33.Cm set move
34.Op Cm rule
35.Ar number Cm to Ar number
36.Nm
37.Cm set swap Ar number number
38.Nm
39.Cm set show
40.Ss SYSCTL SHORTCUTS
41.Nm
42.Cm enable
43.Brq Cm firewall | altq | one_pass | debug | verbose | dyn_keepalive | skipto_cache
44.Nm
45.Cm disable
46.Brq Cm firewall | altq | one_pass | debug | verbose | dyn_keepalive | skipto_cache
47.Ss LOOKUP TABLES
48.Nm
49.Oo Cm set Ar N Oc Cm table Ar name Cm create Ar create-options
50.Nm
51.Oo Cm set Ar N Oc Cm table
52.Brq Ar name | all
53.Cm destroy
54.Nm
55.Oo Cm set Ar N Oc Cm table Ar name Cm modify Ar modify-options
56.Nm
57.Oo Cm set Ar N Oc Cm table Ar name Cm swap Ar name
58.Nm
59.Oo Cm set Ar N Oc Cm table Ar name Cm add Ar table-key Op Ar value
60.Nm
61.Oo Cm set Ar N Oc Cm table Ar name Cm add Op Ar table-key Ar value ...
62.Nm
63.Oo Cm set Ar N Oc Cm table Ar name Cm atomic add Op Ar table-key Ar value ...
64.Nm
65.Oo Cm set Ar N Oc Cm table Ar name Cm delete Op Ar table-key ...
66.Nm
67.Oo Cm set Ar N Oc Cm table Ar name Cm lookup Ar addr
68.Nm
69.Oo Cm set Ar N Oc Cm table Ar name Cm lock
70.Nm
71.Oo Cm set Ar N Oc Cm table Ar name Cm unlock
72.Nm
73.Oo Cm set Ar N Oc Cm table
74.Brq Ar name | all
75.Cm list
76.Nm
77.Oo Cm set Ar N Oc Cm table
78.Brq Ar name | all
79.Cm info
80.Nm
81.Oo Cm set Ar N Oc Cm table
82.Brq Ar name | all
83.Cm detail
84.Nm
85.Oo Cm set Ar N Oc Cm table
86.Brq Ar name | all
87.Cm flush
88.Ss DUMMYNET CONFIGURATION (TRAFFIC SHAPER AND PACKET SCHEDULER)
89.Nm dnctl
90.Brq Cm pipe | queue | sched
91.Ar number
92.Cm config
93.Ar config-options
94.Nm dnctl
95.Op Fl s Op Ar field
96.Brq Cm pipe | queue | sched
97.Brq Cm delete | list | show
98.Op Ar number ...
99.Ss IN-KERNEL NAT
100.Nm
101.Op Fl q
102.Cm nat
103.Ar number
104.Cm config
105.Ar config-options
106.Nm
107.Op Fl q
108.Cm nat
109.Ar number
110.Cm delete
111.Nm
112.Cm nat
113.Ar number
114.Cm show
115.Brq Cm config | log
116.Ss STATEFUL IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
117.Nm
118.Oo Cm set Ar N Oc Cm nat64lsn Ar name Cm create Ar create-options
119.Nm
120.Oo Cm set Ar N Oc Cm nat64lsn Ar name Cm config Ar config-options
121.Nm
122.Oo Cm set Ar N Oc Cm nat64lsn
123.Brq Ar name | all
124.Brq Cm list | show
125.Op Cm states
126.Nm
127.Oo Cm set Ar N Oc Cm nat64lsn
128.Brq Ar name | all
129.Cm destroy
130.Nm
131.Oo Cm set Ar N Oc Cm nat64lsn Ar name Cm stats Op Cm reset
132.Ss STATELESS IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
133.Nm
134.Oo Cm set Ar N Oc Cm nat64stl Ar name Cm create Ar create-options
135.Nm
136.Oo Cm set Ar N Oc Cm nat64stl Ar name Cm config Ar config-options
137.Nm
138.Oo Cm set Ar N Oc Cm nat64stl
139.Brq Ar name | all
140.Brq Cm list | show
141.Nm
142.Oo Cm set Ar N Oc Cm nat64stl
143.Brq Ar name | all
144.Cm destroy
145.Nm
146.Oo Cm set Ar N Oc Cm nat64stl Ar name Cm stats Op Cm reset
147.Ss XLAT464 CLAT IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
148.Nm
149.Oo Cm set Ar N Oc Cm nat64clat Ar name Cm create Ar create-options
150.Nm
151.Oo Cm set Ar N Oc Cm nat64clat Ar name Cm config Ar config-options
152.Nm
153.Oo Cm set Ar N Oc Cm nat64clat
154.Brq Ar name | all
155.Brq Cm list | show
156.Nm
157.Oo Cm set Ar N Oc Cm nat64clat
158.Brq Ar name | all
159.Cm destroy
160.Nm
161.Oo Cm set Ar N Oc Cm nat64clat Ar name Cm stats Op Cm reset
162.Ss IPv6-to-IPv6 NETWORK PREFIX TRANSLATION
163.Nm
164.Oo Cm set Ar N Oc Cm nptv6 Ar name Cm create Ar create-options
165.Nm
166.Oo Cm set Ar N Oc Cm nptv6
167.Brq Ar name | all
168.Brq Cm list | show
169.Nm
170.Oo Cm set Ar N Oc Cm nptv6
171.Brq Ar name | all
172.Cm destroy
173.Nm
174.Oo Cm set Ar N Oc Cm nptv6 Ar name Cm stats Op Cm reset
175.Ss INTERNAL DIAGNOSTICS
176.Nm
177.Cm internal iflist
178.Nm
179.Cm internal monitor Op Ar filter-comment
180.Nm
181.Cm internal talist
182.Nm
183.Cm internal vlist
184.Ss LIST OF RULES AND PREPROCESSING
185.Nm
186.Op Fl cfnNqS
187.Oo
188.Fl p Ar preproc
189.Oo
190.Ar preproc-flags
191.Oc
192.Oc
193.Ar pathname
194.Sh DESCRIPTION
195The
196.Nm
197utility is the user interface for controlling the
198.Xr ipfw 4
199firewall, the
200.Xr dummynet 4
201traffic shaper/packet scheduler, and the
202in-kernel NAT services.
203.Pp
204A firewall configuration, or
205.Em ruleset ,
206is made of a list of
207.Em rules
208numbered from 1 to 65535.
209Packets are passed to the firewall
210from a number of different places in the protocol stack
211(depending on the source and destination of the packet,
212it is possible for the firewall to be
213invoked multiple times on the same packet).
214The packet passed to the firewall is compared
215against each of the rules in the
216.Em ruleset ,
217in rule-number order
218(multiple rules with the same number are permitted, in which case
219they are processed in order of insertion).
220When a match is found, the action corresponding to the
221matching rule is performed.
222.Pp
223Depending on the action and certain system settings, packets
224can be reinjected into the firewall at some rule after the
225matching one for further processing.
226.Pp
227A ruleset always includes a
228.Em default
229rule (numbered 65535) which cannot be modified or deleted,
230and matches all packets.
231The action associated with the
232.Em default
233rule can be either
234.Cm deny
235or
236.Cm allow
237depending on how the kernel is configured.
238.Pp
239If the ruleset includes one or more rules with the
240.Cm keep-state ,
241.Cm record-state ,
242.Cm limit
243or
244.Cm set-limit
245option,
246the firewall will have a
247.Em stateful
248behaviour, i.e., upon a match it will create
249.Em dynamic rules ,
250i.e., rules that match packets with the same 5-tuple
251(protocol, source and destination addresses and ports)
252as the packet which caused their creation.
253Dynamic rules, which have a limited lifetime, are checked
254at the first occurrence of a
255.Cm check-state ,
256.Cm keep-state
257or
258.Cm limit
259rule, and are typically used to open the firewall on-demand to
260legitimate traffic only.
261Please note, that
262.Cm keep-state
263and
264.Cm limit
265imply implicit
266.Cm check-state
267for all packets (not only these matched by the rule) but
268.Cm record-state
269and
270.Cm set-limit
271have no implicit
272.Cm check-state .
273See the
274.Sx STATEFUL FIREWALL
275and
276.Sx EXAMPLES
277Sections below for more information on the stateful behaviour of
278.Nm .
279.Pp
280All rules (including dynamic ones) have a few associated counters:
281a packet count, a byte count, a log count and a timestamp
282indicating the time of the last match.
283Counters can be displayed or reset with
284.Nm
285commands.
286.Pp
287Each rule belongs to one of 32 different
288.Em sets
289, and there are
290.Nm
291commands to atomically manipulate sets, such as enable,
292disable, swap sets, move all rules in a set to another
293one, delete all rules in a set.
294These can be useful to
295install temporary configurations, or to test them.
296See Section
297.Sx SETS OF RULES
298for more information on
299.Em sets .
300.Pp
301Rules can be added with the
302.Cm add
303command; deleted individually or in groups with the
304.Cm delete
305command, and globally (except those in set 31) with the
306.Cm flush
307command; displayed, optionally with the content of the
308counters, using the
309.Cm show
310and
311.Cm list
312commands.
313Finally, counters can be reset with the
314.Cm zero
315and
316.Cm resetlog
317commands.
318.Ss COMMAND OPTIONS
319The following general options are available when invoking
320.Nm :
321.Bl -tag -width indent
322.It Fl a
323Show counter values when listing rules.
324The
325.Cm show
326command implies this option.
327.It Fl b
328Only show the action and the comment, not the body of a rule.
329Implies
330.Fl c .
331.It Fl c
332When entering or showing rules, print them in compact form,
333i.e., omitting the "ip from any to any" string
334when this does not carry any additional information.
335.It Fl d
336When listing, show dynamic rules in addition to static ones.
337.It Fl D
338When listing, show only dynamic states.
339When deleting, delete only dynamic states.
340.It Fl f
341Run without prompting for confirmation for commands that can cause problems
342if misused, i.e.,
343.Cm flush .
344If there is no tty associated with the process, this is implied.
345The
346.Cm delete
347command with this flag ignores possible errors,
348i.e., nonexistent rule number.
349And for batched commands execution continues with the next command.
350.It Fl i
351When listing a table (see the
352.Sx LOOKUP TABLES
353section below for more information on lookup tables), format values
354as IP addresses.
355By default, values are shown as integers.
356.It Fl n
357Only check syntax of the command strings, without actually passing
358them to the kernel.
359.It Fl N
360Try to resolve addresses and service names in output.
361.It Fl q
362Be quiet when executing the
363.Cm add ,
364.Cm nat ,
365.Cm zero ,
366.Cm resetlog
367or
368.Cm flush
369commands;
370(implies
371.Fl f ) .
372This is useful when updating rulesets by executing multiple
373.Nm
374commands in a script
375(e.g.,
376.Ql sh\ /etc/rc.firewall ) ,
377or by processing a file with many
378.Nm
379rules across a remote login session.
380It also stops a table add or delete
381from failing if the entry already exists or is not present.
382.Pp
383The reason why this option may be important is that
384for some of these actions,
385.Nm
386may print a message; if the action results in blocking the
387traffic to the remote client,
388the remote login session will be closed
389and the rest of the ruleset will not be processed.
390Access to the console would then be required to recover.
391.It Fl S
392When listing rules, show the
393.Em set
394each rule belongs to.
395If this flag is not specified, disabled rules will not be
396listed.
397.It Fl s Op Ar field
398When listing pipes, sort according to one of the four
399counters (total or current packets or bytes).
400.It Fl t
401When listing, show last match timestamp converted with
402.Fn ctime .
403.It Fl T
404When listing, show last match timestamp as seconds from the epoch.
405This form can be more convenient for postprocessing by scripts.
406.El
407.Ss LIST OF RULES AND PREPROCESSING
408To ease configuration, rules can be put into a file which is
409processed using
410.Nm
411as shown in the last synopsis line.
412An absolute
413.Ar pathname
414must be used.
415The file will be read line by line and applied as arguments to the
416.Nm
417utility.
418.Pp
419Optionally, a preprocessor can be specified using
420.Fl p Ar preproc
421where
422.Ar pathname
423is to be piped through.
424Useful preprocessors include
425.Xr cpp 1
426and
427.Xr m4 1 .
428If
429.Ar preproc
430does not start with a slash
431.Pq Ql /
432as its first character, the usual
433.Ev PATH
434name search is performed.
435Care should be taken with this in environments where not all
436file systems are mounted (yet) by the time
437.Nm
438is being run (e.g.\& when they are mounted over NFS).
439Once
440.Fl p
441has been specified, any additional arguments are passed on to the preprocessor
442for interpretation.
443This allows for flexible configuration files (like conditionalizing
444them on the local hostname) and the use of macros to centralize
445frequently required arguments like IP addresses.
446.Ss TRAFFIC SHAPER CONFIGURATION
447The
448.Nm dnctl
449.Cm pipe , queue
450and
451.Cm sched
452commands are used to configure the traffic shaper and packet scheduler.
453See the
454.Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
455Section below for details.
456.Pp
457If the world and the kernel get out of sync the
458.Nm
459ABI may break, preventing you from being able to add any rules.
460This can adversely affect the booting process.
461You can use
462.Nm
463.Cm disable
464.Cm firewall
465to temporarily disable the firewall to regain access to the network,
466allowing you to fix the problem.
467.Sh PACKET FLOW
468A packet is checked against the active ruleset in multiple places
469in the protocol stack, under control of several sysctl variables.
470These places and variables are shown below, and it is important to
471have this picture in mind in order to design a correct ruleset.
472.Bd -literal -offset indent
473       ^    to upper layers    V
474       |                       |
475       +----------->-----------+
476       ^                       V
477 [ip(6)_input]           [ip(6)_output]     net.inet(6).ip(6).fw.enable=1
478       |                       |
479       ^                       V
480 [ether_demux]        [ether_output_frame]  net.link.ether.ipfw=1
481       |                       |
482       +-->--[bdg_forward]-->--+            net.link.bridge.ipfw=1
483       ^                       V
484       |      to devices       |
485.Ed
486.Pp
487The number of
488times the same packet goes through the firewall can
489vary between 0 and 4 depending on packet source and
490destination, and system configuration.
491.Pp
492Note that as packets flow through the stack, headers can be
493stripped or added to it, and so they may or may not be available
494for inspection.
495E.g., incoming packets will include the MAC header when
496.Nm
497is invoked from
498.Cm ether_demux() ,
499but the same packets will have the MAC header stripped off when
500.Nm
501is invoked from
502.Cm ip_input()
503or
504.Cm ip6_input() .
505.Pp
506Also note that each packet is always checked against the complete ruleset,
507irrespective of the place where the check occurs, or the source of the packet.
508If a rule contains some match patterns or actions which are not valid
509for the place of invocation (e.g.\& trying to match a MAC header within
510.Cm ip_input
511or
512.Cm ip6_input ),
513the match pattern will not match, but a
514.Cm not
515operator in front of such patterns
516.Em will
517cause the pattern to
518.Em always
519match on those packets.
520It is thus the responsibility of
521the programmer, if necessary, to write a suitable ruleset to
522differentiate among the possible places.
523.Cm skipto
524rules can be useful here, as an example:
525.Bd -literal -offset indent
526# packets from ether_demux or bdg_forward
527ipfw add 10 skipto 1000 all from any to any layer2 in
528# packets from ip_input
529ipfw add 10 skipto 2000 all from any to any not layer2 in
530# packets from ip_output
531ipfw add 10 skipto 3000 all from any to any not layer2 out
532# packets from ether_output_frame
533ipfw add 10 skipto 4000 all from any to any layer2 out
534.Ed
535.Pp
536(yes, at the moment there is no way to differentiate between
537ether_demux and bdg_forward).
538.Pp
539Also note that only actions
540.Cm allow ,
541.Cm deny ,
542.Cm netgraph ,
543.Cm ngtee
544and related to
545.Cm dummynet
546are processed for
547.Cm layer2
548frames and all other actions act as if they were
549.Cm allow
550for such frames.
551Full set of actions is supported for IP packets without
552.Cm layer2
553headers only.
554For example,
555.Cm divert
556action does not divert
557.Cm layer2
558frames.
559.Sh SYNTAX
560In general, each keyword or argument must be provided as
561a separate command line argument, with no leading or trailing
562spaces.
563Keywords are case-sensitive, whereas arguments may
564or may not be case-sensitive depending on their nature
565(e.g.\& uid's are, hostnames are not).
566.Pp
567Some arguments (e.g., port or address lists) are comma-separated
568lists of values.
569In this case, spaces after commas ',' are allowed to make
570the line more readable.
571You can also put the entire
572command (including flags) into a single argument.
573E.g., the following forms are equivalent:
574.Bd -literal -offset indent
575ipfw -q add deny src-ip 10.0.0.0/24,127.0.0.1/8
576ipfw -q add deny src-ip 10.0.0.0/24, 127.0.0.1/8
577ipfw "-q add deny src-ip 10.0.0.0/24, 127.0.0.1/8"
578.Ed
579.Sh RULE FORMAT
580The format of firewall rules is the following:
581.Bd -ragged -offset indent
582.Bk -words
583.Op Ar rule_number
584.Op Cm set Ar set_number
585.Op Cm prob Ar match_probability
586.Ar action
587.Op Cm log Op log_opts
588.Op Cm altq Ar queue
589.Oo
590.Bro Cm tag | untag
591.Brc Ar number
592.Oc
593.Ar body
594.Ek
595.Ed
596.Pp
597where the body of the rule specifies which information is used
598for filtering packets, among the following:
599.Pp
600.Bl -tag -width "Source and dest. addresses and ports" -offset XXX -compact
601.It Layer2 header fields
602When available
603.It IPv4 and IPv6 Protocol
604SCTP, TCP, UDP, ICMP, etc.
605.It Source and dest. addresses and ports
606.It Direction
607See Section
608.Sx PACKET FLOW
609.It Transmit and receive interface
610By name or address
611.It Misc. IP header fields
612Version, type of service, datagram length, identification,
613fragmentation flags,
614Time To Live
615.It IP options
616.It IPv6 Extension headers
617Fragmentation, Hop-by-Hop options,
618Routing Headers, Source routing rthdr0, Mobile IPv6 rthdr2, IPSec options.
619.It IPv6 Flow-ID
620.It Misc. TCP header fields
621TCP flags (SYN, FIN, ACK, RST, etc.),
622sequence number, acknowledgment number,
623window
624.It TCP options
625.It ICMP types
626for ICMP packets
627.It ICMP6 types
628for ICMP6 packets
629.It User/group ID
630When the packet can be associated with a local socket.
631.It Divert status
632Whether a packet came from a divert socket (e.g.,
633.Xr natd 8 ) .
634.It Fib annotation state
635Whether a packet has been tagged for using a specific FIB (routing table)
636in future forwarding decisions.
637.El
638.Pp
639Note that some of the above information, e.g.\& source MAC or IP addresses and
640TCP/UDP ports, can be easily spoofed, so filtering on those fields
641alone might not guarantee the desired results.
642.Bl -tag -width indent
643.It Ar rule_number
644Each rule is associated with a
645.Ar rule_number
646in the range 1..65535, with the latter reserved for the
647.Em default
648rule.
649Rules are checked sequentially by rule number.
650Multiple rules can have the same number, in which case they are
651checked (and listed) according to the order in which they have
652been added.
653If a rule is entered without specifying a number, the kernel will
654assign one in such a way that the rule becomes the last one
655before the
656.Em default
657rule.
658Automatic rule numbers are assigned by incrementing the last
659non-default rule number by the value of the sysctl variable
660.Ar net.inet.ip.fw.autoinc_step
661which defaults to 100.
662If this is not possible (e.g.\& because we would go beyond the
663maximum allowed rule number), the number of the last
664non-default value is used instead.
665.It Cm set Ar set_number
666Each rule is associated with a
667.Ar set_number
668in the range 0..31.
669Sets can be individually disabled and enabled, so this parameter
670is of fundamental importance for atomic ruleset manipulation.
671It can be also used to simplify deletion of groups of rules.
672If a rule is entered without specifying a set number,
673set 0 will be used.
674.br
675Set 31 is special in that it cannot be disabled,
676and rules in set 31 are not deleted by the
677.Nm ipfw flush
678command (but you can delete them with the
679.Nm ipfw delete set 31
680command).
681Set 31 is also used for the
682.Em default
683rule.
684.It Cm prob Ar match_probability
685A match is only declared with the specified probability
686(floating point number between 0 and 1).
687This can be useful for a number of applications such as
688random packet drop or
689(in conjunction with
690.Nm dummynet )
691to simulate the effect of multiple paths leading to out-of-order
692packet delivery.
693.Pp
694Note: this condition is checked before any other condition, including
695ones such as
696.Cm keep-state
697or
698.Cm check-state
699which might have
700side effects.
701.It Cm log Op Cm logamount Ar number
702Packets matching a rule with the
703.Cm log
704keyword will be made available for logging.
705Unless per-rule log destination is specified by
706.Cm logdst Ar logdst_spec
707option (see below), packets are logged in two ways: if the sysctl variable
708.Va net.inet.ip.fw.verbose
709is set to 0 (default), one can use the
710.Xr bpf 4
711tap named
712.Li ipfwXXXXX ,
713where XXXXX is the number of the rule that has the
714.Cm log
715keyword.
716The compatibility
717.Xr bpf 4
718tap named
719.Li ipfw0
720still exists.
721It will catch packets in case if there are no
722.Xr bpf 4
723listener(s) on a per-rule tap.
724There is zero overhead when no
725.Xr bpf 4
726listener is attached to the tap.
727.Pp
728If
729.Va net.inet.ip.fw.verbose
730is set to 1, packets will be logged to
731.Xr syslogd 8
732with a
733.Dv LOG_SECURITY
734facility up to a maximum of
735.Cm logamount
736packets.
737If no
738.Cm logamount
739is specified, the limit is taken from the sysctl variable
740.Va net.inet.ip.fw.verbose_limit .
741In both cases, a value of 0 means unlimited logging.
742.Pp
743Once the limit is reached, logging can be re-enabled by
744clearing the logging counter or the packet counter for that entry, see the
745.Cm resetlog
746command.
747.Pp
748Note: logging is done after all other packet matching conditions
749have been successfully verified, and before performing the final
750action (accept, deny, etc.) on the packet.
751.It Cm log Oo
752.Cm logamount Ar number
753.Oc Cm logdst Ar logdst_spec
754.Ar logdst_spec
755is a comma-separated list of log destinations for logging
756packets matching the rule.
757Destinations supported are:
758.Bl -tag -width indent
759.It Ar syslog
760Logs a packet to
761.Xr syslogd 8
762with a
763.Dv LOG_SECURITY
764facility.
765.It Ar bpf
766Logs a packet to the
767.Xr bpf 4
768tap named
769.Li ipfwXXXXX ,
770where XXXXX is the rule number.
771.It Ar rtsock
772Logs a packet to the
773.Xr route 4
774socket.
775See the comments of
776.Fn ipfw_log_rtsock
777in ipfw source code for more
778information on the message's structure.
779.El
780.Pp
781Note:
782.Cm logamount
783limits a number of logging events rather than packets being logged.
784I.e. A packet matching a rule with
785.Bd -ragged -offset indent
786 ...
787.Cm log logamount
788100
789.Cm logdst
790syslog,bpf ...
791.Ed
792.Pp
793will log upto 50 packets.
794.It Cm tag Ar number
795When a packet matches a rule with the
796.Cm tag
797keyword, the numeric tag for the given
798.Ar number
799in the range 1..65534 will be attached to the packet.
800The tag acts as an internal marker (it is not sent out over
801the wire) that can be used to identify these packets later on.
802This can be used, for example, to provide trust between interfaces
803and to start doing policy-based filtering.
804A packet can have multiple tags at the same time.
805Tags are "sticky", meaning once a tag is applied to a packet by a
806matching rule it exists until explicit removal.
807Tags are kept with the packet everywhere within the kernel, but are
808lost when the packet leaves the kernel, for example, on transmitting
809packet out to the network or sending packet to a
810.Xr divert 4
811socket.
812.Pp
813To check for previously applied tags, use the
814.Cm tagged
815rule option.
816To delete previously applied tag, use the
817.Cm untag
818keyword.
819.Pp
820Note: since tags are kept with the packet everywhere in kernelspace,
821they can be set and unset anywhere in the kernel network subsystem
822(using the
823.Xr mbuf_tags 9
824facility), not only by means of the
825.Xr ipfw 4
826.Cm tag
827and
828.Cm untag
829keywords.
830For example, there can be a specialized
831.Xr netgraph 4
832node doing traffic analyzing and tagging for later inspecting
833in firewall.
834.It Cm untag Ar number
835When a packet matches a rule with the
836.Cm untag
837keyword, the tag with the number
838.Ar number
839is searched among the tags attached to this packet and,
840if found, removed from it.
841Other tags bound to packet, if present, are left untouched.
842.It Cm setmark Ar value | tablearg
843When a packet matches a rule with the
844.Cm setmark
845keyword, a 32-bit numeric mark is assigned to the packet.
846The mark is an extension to the tags.
847The mark is preserved for a packet within a single ipfw ruleset traversal
848and is lost when the packet is checked against the active ruleset
849next time (see
850.Sx PACKET FLOW
851section) or leaves ipfw context (e.g. accepted,
852diverted, bridged or routed).
853Unlike tags, mark can be matched as a lookup table key or compared with bitwise
854mask applied against another value.
855Each packet can have only one mark, so
856.Cm setmark
857always overwrites the previous mark value.
858.Pp
859The initial mark value is 0.
860To check the current mark value, use the
861.Cm mark
862rule option.
863Mark
864.Ar value
865can be entered as decimal or hexadecimal (if prefixed by 0x), and they
866are always printed as hexadecimal.
867.It Cm altq Ar queue
868When a packet matches a rule with the
869.Cm altq
870keyword, the ALTQ identifier for the given
871.Ar queue
872(see
873.Xr altq 4 )
874will be attached.
875Note that this ALTQ tag is only meaningful for packets going "out" of IPFW,
876and not being rejected or going to divert sockets.
877Note that if there is insufficient memory at the time the packet is
878processed, it will not be tagged, so it is wise to make your ALTQ
879"default" queue policy account for this.
880If multiple
881.Cm altq
882rules match a single packet, only the first one adds the ALTQ classification
883tag.
884In doing so, traffic may be shaped by using
885.Cm count Cm altq Ar queue
886rules for classification early in the ruleset, then later applying
887the filtering decision.
888For example,
889.Cm check-state
890and
891.Cm keep-state
892rules may come later and provide the actual filtering decisions in
893addition to the fallback ALTQ tag.
894.Pp
895You must run
896.Xr pfctl 8
897to set up the queues before IPFW will be able to look them up by name,
898and if the ALTQ disciplines are rearranged, the rules in containing the
899queue identifiers in the kernel will likely have gone stale and need
900to be reloaded.
901Stale queue identifiers will probably result in misclassification.
902.Pp
903All system ALTQ processing can be turned on or off via
904.Nm
905.Cm enable Ar altq
906and
907.Nm
908.Cm disable Ar altq .
909The usage of
910.Va net.inet.ip.fw.one_pass
911is irrelevant to ALTQ traffic shaping, as the actual rule action is followed
912always after adding an ALTQ tag.
913.El
914.Ss RULE ACTIONS
915A rule can be associated with one of the following actions, which
916will be executed when the packet matches the body of the rule.
917.Bl -tag -width indent
918.It Cm allow | accept | pass | permit
919Allow packets that match rule.
920The search terminates.
921.It Cm check-state Op Ar :flowname | Cm :any
922Checks the packet against the dynamic ruleset.
923If a match is found, execute the action associated with
924the rule which generated this dynamic rule, otherwise
925move to the next rule.
926.br
927.Cm Check-state
928rules do not have a body.
929If no
930.Cm check-state
931rule is found, the dynamic ruleset is checked at the first
932.Cm keep-state
933or
934.Cm limit
935rule.
936The
937.Ar :flowname
938is symbolic name assigned to dynamic rule by
939.Cm keep-state
940opcode.
941The special flowname
942.Cm :any
943can be used to ignore states flowname when matching.
944The
945.Cm :default
946keyword is special name used for compatibility with old rulesets.
947.It Cm count
948Update counters for all packets that match rule.
949The search continues with the next rule.
950.It Cm deny | drop
951Discard packets that match this rule.
952The search terminates.
953.It Cm divert Ar port
954Divert packets that match this rule to the
955.Xr divert 4
956socket bound to port
957.Ar port .
958The search terminates.
959.It Cm fwd | forward Ar ipaddr | tablearg Ns Op , Ns Ar port
960Change the next-hop on matching packets to
961.Ar ipaddr ,
962which can be an IP address or a host name.
963The next hop can also be supplied by the last table
964looked up for the packet by using the
965.Cm tablearg
966keyword instead of an explicit address.
967The search terminates if this rule matches.
968.Pp
969If
970.Ar ipaddr
971is a local address, then matching packets will be forwarded to
972.Ar port
973(or the port number in the packet if one is not specified in the rule)
974on the local machine.
975.br
976If
977.Ar ipaddr
978is not a local address, then the port number
979(if specified) is ignored, and the packet will be
980forwarded to the remote address, using the route as found in
981the local routing table for that IP.
982.br
983A
984.Ar fwd
985rule will not match layer2 packets (those received
986on ether_input, ether_output, or bridged).
987.br
988The
989.Cm fwd
990action does not change the contents of the packet at all.
991In particular, the destination address remains unmodified, so
992packets forwarded to another system will usually be rejected by that system
993unless there is a matching rule on that system to capture them.
994For packets forwarded locally,
995the local address of the socket will be
996set to the original destination address of the packet.
997This makes the
998.Xr netstat 1
999entry look rather weird but is intended for
1000use with transparent proxy servers.
1001.It Cm nat Ar nat_nr | global | tablearg
1002Pass packet to a
1003nat instance
1004(for network address translation, address redirect, etc.):
1005see the
1006.Sx NETWORK ADDRESS TRANSLATION (NAT)\&
1007Section for further information.
1008.It Cm nat64lsn Ar name
1009Pass packet to a stateful NAT64 instance (for IPv6/IPv4 network address and
1010protocol translation): see the
1011.Sx IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
1012Section for further information.
1013.It Cm nat64stl Ar name
1014Pass packet to a stateless NAT64 instance (for IPv6/IPv4 network address and
1015protocol translation): see the
1016.Sx IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
1017Section for further information.
1018.It Cm nat64clat Ar name
1019Pass packet to a CLAT NAT64 instance (for client-side IPv6/IPv4 network address
1020and protocol translation): see the
1021.Sx IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
1022Section for further information.
1023.It Cm nptv6 Ar name
1024Pass packet to a NPTv6 instance (for IPv6-to-IPv6 network prefix translation):
1025see the
1026.Sx IPv6-to-IPv6 NETWORK PREFIX TRANSLATION (NPTv6)\&
1027Section for further information.
1028.It Cm pipe Ar pipe_nr
1029Pass packet to a
1030.Nm dummynet
1031.Dq pipe
1032(for bandwidth limitation, delay, etc.).
1033See the
1034.Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
1035Section for further information.
1036The search terminates; however, on exit from the pipe and if
1037the
1038.Xr sysctl 8
1039variable
1040.Va net.inet.ip.fw.one_pass
1041is not set, the packet is passed again to the firewall code
1042starting from the next rule.
1043.It Cm queue Ar queue_nr
1044Pass packet to a
1045.Nm dummynet
1046.Dq queue
1047(for bandwidth limitation using WF2Q+).
1048.It Cm reject
1049(Deprecated).
1050Synonym for
1051.Cm unreach host .
1052.It Cm reset
1053Discard packets that match this rule, and if the
1054packet is a TCP packet, try to send a TCP reset (RST) notice.
1055The search terminates.
1056.It Cm reset6
1057Discard packets that match this rule, and if the
1058packet is a TCP packet, try to send a TCP reset (RST) notice.
1059The search terminates.
1060.It Cm skipto Ar number | tablearg
1061Skip all subsequent rules numbered less than
1062.Ar number .
1063The search continues with the first rule numbered
1064.Ar number
1065or higher.
1066It is possible to use the
1067.Cm tablearg
1068keyword with a skipto for a
1069.Em computed
1070skipto.
1071Skipto may work either in O(log(N)) or in O(1) depending
1072on amount of memory and/or sysctl variables.
1073See the
1074.Sx SYSCTL VARIABLES
1075section for more details.
1076.It Cm call Ar number | tablearg
1077The current rule number is saved in the internal stack and
1078ruleset processing continues with the first rule numbered
1079.Ar number
1080or higher.
1081If later a rule with the
1082.Cm return
1083action is encountered, the processing returns to the first rule
1084with number of this
1085.Cm call
1086rule plus one or higher
1087(the same behaviour as with packets returning from
1088.Xr divert 4
1089socket after a
1090.Cm divert
1091action).
1092This could be used to make somewhat like an assembly language
1093.Dq subroutine
1094calls to rules with common checks for different interfaces, etc.
1095.Pp
1096Rule with any number could be called, not just forward jumps as with
1097.Cm skipto .
1098So, to prevent endless loops in case of mistakes, both
1099.Cm call
1100and
1101.Cm return
1102actions don't do any jumps and simply go to the next rule if memory
1103cannot be allocated or stack overflowed/underflowed.
1104.Pp
1105Internally stack for rule numbers is implemented using
1106.Xr mbuf_tags 9
1107facility and currently has size of 16 entries.
1108As mbuf tags are lost when packet leaves the kernel,
1109.Cm divert
1110should not be used in subroutines to avoid endless loops
1111and other undesired effects.
1112.It Cm return
1113Takes rule number saved to internal stack by the last
1114.Cm call
1115action and returns ruleset processing to the first rule
1116with number greater than number of corresponding
1117.Cm call
1118rule.
1119See description of the
1120.Cm call
1121action for more details.
1122.Pp
1123Note that
1124.Cm return
1125rules usually end a
1126.Dq subroutine
1127and thus are unconditional, but
1128.Nm
1129command-line utility currently requires every action except
1130.Cm check-state
1131to have body.
1132While it is sometimes useful to return only on some packets,
1133usually you want to print just
1134.Dq return
1135for readability.
1136A workaround for this is to use new syntax and
1137.Fl c
1138switch:
1139.Bd -literal -offset indent
1140# Add a rule without actual body
1141ipfw add 2999 return via any
1142
1143# List rules without "from any to any" part
1144ipfw -c list
1145.Ed
1146.Pp
1147This cosmetic annoyance may be fixed in future releases.
1148.It Cm tee Ar port
1149Send a copy of packets matching this rule to the
1150.Xr divert 4
1151socket bound to port
1152.Ar port .
1153The search continues with the next rule.
1154.It Cm unreach Ar code Op mtu
1155Discard packets that match this rule, and try to send an ICMP
1156unreachable notice with code
1157.Ar code ,
1158where
1159.Ar code
1160is a number from 0 to 255, or one of these aliases:
1161.Cm net , host , protocol , port ,
1162.Cm needfrag , srcfail , net-unknown , host-unknown ,
1163.Cm isolated , net-prohib , host-prohib , tosnet ,
1164.Cm toshost , filter-prohib , host-precedence
1165or
1166.Cm precedence-cutoff .
1167The
1168.Cm needfrag
1169code may have an optional
1170.Ar mtu
1171parameter.
1172If specified, the MTU value will be put into generated ICMP packet.
1173The search terminates.
1174.It Cm unreach6 Ar code
1175Discard packets that match this rule, and try to send an ICMPv6
1176unreachable notice with code
1177.Ar code ,
1178where
1179.Ar code
1180is a number from 0, 1, 3 or 4, or one of these aliases:
1181.Cm no-route, admin-prohib, address
1182or
1183.Cm port .
1184The search terminates.
1185.It Cm netgraph Ar cookie
1186Divert packet into netgraph with given
1187.Ar cookie .
1188The search terminates.
1189If packet is later returned from netgraph it is either
1190accepted or continues with the next rule, depending on
1191.Va net.inet.ip.fw.one_pass
1192sysctl variable.
1193.It Cm ngtee Ar cookie
1194A copy of packet is diverted into netgraph, original
1195packet continues with the next rule.
1196See
1197.Xr ng_ipfw 4
1198for more information on
1199.Cm netgraph
1200and
1201.Cm ngtee
1202actions.
1203.It Cm setfib Ar fibnum | tablearg
1204The packet is tagged so as to use the FIB (routing table)
1205.Ar fibnum
1206in any subsequent forwarding decisions.
1207In the current implementation, this is limited to the values 0 through 15, see
1208.Xr setfib 2 .
1209Processing continues at the next rule.
1210It is possible to use the
1211.Cm tablearg
1212keyword with setfib.
1213If the tablearg value is not within the compiled range of fibs,
1214the packet's fib is set to 0.
1215.It Cm setdscp Ar DSCP | number | tablearg
1216Set specified DiffServ codepoint for an IPv4/IPv6 packet.
1217Processing continues at the next rule.
1218Supported values are:
1219.Pp
1220.Cm cs0
1221.Pq Dv 000000 ,
1222.Cm cs1
1223.Pq Dv 001000 ,
1224.Cm cs2
1225.Pq Dv 010000 ,
1226.Cm cs3
1227.Pq Dv 011000 ,
1228.Cm cs4
1229.Pq Dv 100000 ,
1230.Cm cs5
1231.Pq Dv 101000 ,
1232.Cm cs6
1233.Pq Dv 110000 ,
1234.Cm cs7
1235.Pq Dv 111000 ,
1236.Cm af11
1237.Pq Dv 001010 ,
1238.Cm af12
1239.Pq Dv 001100 ,
1240.Cm af13
1241.Pq Dv 001110 ,
1242.Cm af21
1243.Pq Dv 010010 ,
1244.Cm af22
1245.Pq Dv 010100 ,
1246.Cm af23
1247.Pq Dv 010110 ,
1248.Cm af31
1249.Pq Dv 011010 ,
1250.Cm af32
1251.Pq Dv 011100 ,
1252.Cm af33
1253.Pq Dv 011110 ,
1254.Cm af41
1255.Pq Dv 100010 ,
1256.Cm af42
1257.Pq Dv 100100 ,
1258.Cm af43
1259.Pq Dv 100110 ,
1260.Cm va
1261.Pq Dv 101100 ,
1262.Cm ef
1263.Pq Dv 101110 ,
1264.Cm be
1265.Pq Dv 000000 .
1266Additionally, DSCP value can be specified by number (0..63).
1267It is also possible to use the
1268.Cm tablearg
1269keyword with setdscp.
1270If the tablearg value is not within the 0..63 range, lower 6 bits of supplied
1271value are used.
1272.It Cm tcp-setmss Ar mss
1273Set the Maximum Segment Size (MSS) in the TCP segment to value
1274.Ar mss .
1275The kernel module
1276.Cm ipfw_pmod
1277should be loaded or kernel should have
1278.Cm options IPFIREWALL_PMOD
1279to be able use this action.
1280This command does not change a packet if original MSS value is lower than
1281specified value.
1282Both TCP over IPv4 and over IPv6 are supported.
1283Regardless of matched a packet or not by the
1284.Cm tcp-setmss
1285rule, the search continues with the next rule.
1286.It Cm reass
1287Queue and reassemble IPv4 fragments.
1288If the packet is not fragmented, counters are updated and
1289processing continues with the next rule.
1290If the packet is the last logical fragment, the packet is reassembled and, if
1291.Va net.inet.ip.fw.one_pass
1292is set to 0, processing continues with the next rule.
1293Otherwise, the packet is allowed to pass and the search terminates.
1294If the packet is a fragment in the middle of a logical group of fragments,
1295it is consumed and
1296processing stops immediately.
1297.Pp
1298Fragment handling can be tuned via
1299.Va net.inet.ip.maxfragpackets
1300and
1301.Va net.inet.ip.maxfragsperpacket
1302which limit, respectively, the maximum number of processable
1303fragments (default: 800) and
1304the maximum number of fragments per packet (default: 16).
1305.Pp
1306NOTA BENE: since fragments do not contain port numbers,
1307they should be avoided with the
1308.Nm reass
1309rule.
1310Alternatively, direction-based (like
1311.Nm in
1312/
1313.Nm out
1314) and source-based (like
1315.Nm via
1316) match patterns can be used to select fragments.
1317.Pp
1318Usually a simple rule like:
1319.Bd -literal -offset indent
1320# reassemble incoming fragments
1321ipfw add reass all from any to any in
1322.Ed
1323.Pp
1324is all you need at the beginning of your ruleset.
1325.It Cm abort
1326Discard packets that match this rule, and if the packet is an SCTP packet,
1327try to send an SCTP packet containing an ABORT chunk.
1328The search terminates.
1329.It Cm abort6
1330Discard packets that match this rule, and if the packet is an SCTP packet,
1331try to send an SCTP packet containing an ABORT chunk.
1332The search terminates.
1333.El
1334.Ss RULE BODY
1335The body of a rule contains zero or more patterns (such as
1336specific source and destination addresses or ports,
1337protocol options, incoming or outgoing interfaces, etc.)
1338that the packet must match in order to be recognised.
1339In general, the patterns are connected by (implicit)
1340.Cm and
1341operators \(em i.e., all must match in order for the
1342rule to match.
1343Individual patterns can be prefixed by the
1344.Cm not
1345operator to reverse the result of the match, as in
1346.Pp
1347.Dl "ipfw add 100 allow ip from not 1.2.3.4 to any"
1348.Pp
1349Additionally, sets of alternative match patterns
1350.Pq Em or-blocks
1351can be constructed by putting the patterns in
1352lists enclosed between parentheses ( ) or braces { }, and
1353using the
1354.Cm or
1355operator as follows:
1356.Pp
1357.Dl "ipfw add 100 allow ip from { x or not y or z } to any"
1358.Pp
1359Only one level of parentheses is allowed.
1360Beware that most shells have special meanings for parentheses
1361or braces, so it is advisable to put a backslash \\ in front of them
1362to prevent such interpretations.
1363.Pp
1364The body of a rule must in general include a source and destination
1365address specifier.
1366The keyword
1367.Ar any
1368can be used in various places to specify that the content of
1369a required field is irrelevant.
1370.Pp
1371The rule body has the following format:
1372.Bd -ragged -offset indent
1373.Op Ar proto Cm from Ar src Cm to Ar dst
1374.Op Ar options
1375.Ed
1376.Pp
1377The first part (proto from src to dst) is for backward
1378compatibility with earlier versions of
1379.Fx .
1380In modern
1381.Fx
1382any match pattern (including MAC headers, IP protocols,
1383addresses and ports) can be specified in the
1384.Ar options
1385section.
1386.Pp
1387Rule fields have the following meaning:
1388.Bl -tag -width indent
1389.It Ar proto : protocol | Cm { Ar protocol Cm or ... }
1390.It Ar protocol : Oo Cm not Oc Ar protocol-name | protocol-number
1391An IP protocol specified by number or name
1392(for a complete list see
1393.Pa /etc/protocols ) ,
1394or one of the following keywords:
1395.Bl -tag -width indent
1396.It Cm ip4 | ipv4
1397Matches IPv4 packets.
1398.It Cm ip6 | ipv6
1399Matches IPv6 packets.
1400.It Cm ip | all
1401Matches any packet.
1402.El
1403.Pp
1404The
1405.Cm ipv6
1406in
1407.Cm proto
1408option will be treated as inner protocol.
1409And, the
1410.Cm ipv4
1411is not available in
1412.Cm proto
1413option.
1414.Pp
1415The
1416.Cm { Ar protocol Cm or ... }
1417format (an
1418.Em or-block )
1419is provided for convenience only but its use is deprecated.
1420.It Ar src No and Ar dst : Bro Cm addr | Cm { Ar addr Cm or ... } Brc Op Oo Cm not Oc Ar ports
1421An address (or a list, see below)
1422optionally followed by
1423.Ar ports
1424specifiers.
1425.Pp
1426The second format
1427.Em ( or-block
1428with multiple addresses) is provided for convenience only and
1429its use is discouraged.
1430.It Ar addr : Oo Cm not Oc Bro
1431.Cm any | me | me6 | Ar table-ref
1432.Ar | addr-list | addr-set
1433.Brc
1434.Bl -tag -width indent
1435.It Cm any
1436Matches any IP address.
1437.It Cm me
1438Matches any IP address configured on an interface in the system.
1439.It Cm me6
1440Matches any IPv6 address configured on an interface in the system.
1441The address list is evaluated at the time the packet is
1442analysed.
1443.El
1444.It Ar table-ref :
1445A table lookup can be specified in one of the following ways:
1446.Bl -tag -width indent
1447.It table Ns Pq Ar name Ns
1448Matches any IPv4 or IPv6 address for which an entry exists in the lookup table
1449.Ar number .
1450.It table Ns Pq Ar name , Ns Ar value
1451Matches any IPv4 or IPv6 address for which an entry exists in the lookup table
1452.Ar number
1453and 32-bit unsigned
1454.Ar value
1455specified matchess entry value.
1456.It table Ns Pq Ar name , Ns Ar value-type Ns = Ns Ar value
1457Matches any IPv4 or IPv6 address for which an entry exists in the lookup table
1458.Ar number
1459and 32-bit unsigned
1460.Ar value
1461specified matches corresponding
1462.Ar value-type
1463field for the record found.
1464.El
1465.Pp
1466See the
1467.Sx LOOKUP TABLES
1468section below for more information on lookup tables.
1469.It Ar addr-list : ip-addr Ns Op , Ns Ar addr-list
1470.It Ar ip-addr :
1471A host or subnet address specified in one of the following ways:
1472.Bl -tag -width indent
1473.It Ar numeric-ip | hostname
1474Matches a single IPv4 address, specified as dotted-quad or a hostname.
1475Hostnames are resolved at the time the rule is added to the firewall list.
1476.It Ar addr Ns / Ns Ar masklen
1477Matches all addresses with base
1478.Ar addr
1479(specified as an IP address, a network number, or a hostname)
1480and mask width of
1481.Cm masklen
1482bits.
1483As an example, 1.2.3.4/25 or 1.2.3.0/25 will match
1484all IP numbers from 1.2.3.0 to 1.2.3.127 .
1485.It Ar addr : Ns Ar mask
1486Matches all addresses with base
1487.Ar addr
1488(specified as an IP address, a network number, or a hostname)
1489and the mask of
1490.Ar mask ,
1491specified as a dotted quad.
1492As an example, 1.2.3.4:255.0.255.0 or 1.0.3.0:255.0.255.0 will match
14931.*.3.*.
1494This form is advised only for non-contiguous
1495masks.
1496It is better to resort to the
1497.Ar addr Ns / Ns Ar masklen
1498format for contiguous masks, which is more compact and less
1499error-prone.
1500.El
1501.It Ar addr-set : addr Ns Oo Ns / Ns Ar masklen Oc Ns Cm { Ns Ar list Ns Cm }
1502.It Ar list : Bro Ar num | num-num Brc Ns Op , Ns Ar list
1503Matches all addresses with base address
1504.Ar addr
1505(specified as an IP address, a network number, or a hostname)
1506and whose last byte is in the list between braces { } .
1507Note that there must be no spaces between braces and
1508numbers (spaces after commas are allowed).
1509Elements of the list can be specified as single entries
1510or ranges.
1511The
1512.Ar masklen
1513field is used to limit the size of the set of addresses,
1514and can have any value between 24 and 32.
1515If not specified,
1516it will be assumed as 24.
1517.br
1518This format is particularly useful to handle sparse address sets
1519within a single rule.
1520Because the matching occurs using a
1521bitmask, it takes constant time and dramatically reduces
1522the complexity of rulesets.
1523.br
1524As an example, an address specified as 1.2.3.4/24{128,35-55,89}
1525or 1.2.3.0/24{128,35-55,89}
1526will match the following IP addresses:
1527.br
15281.2.3.128, 1.2.3.35 to 1.2.3.55, 1.2.3.89 .
1529.It Ar addr6-list : ip6-addr Ns Op , Ns Ar addr6-list
1530.It Ar ip6-addr :
1531A host or subnet specified one of the following ways:
1532.Bl -tag -width indent
1533.It Ar numeric-ip | hostname
1534Matches a single IPv6 address as allowed by
1535.Xr inet_pton 3
1536or a hostname.
1537Hostnames are resolved at the time the rule is added to the firewall
1538list.
1539.It Ar addr Ns / Ns Ar masklen
1540Matches all IPv6 addresses with base
1541.Ar addr
1542(specified as allowed by
1543.Xr inet_pton 3
1544or a hostname)
1545and mask width of
1546.Cm masklen
1547bits.
1548.It Ar addr Ns / Ns Ar mask
1549Matches all IPv6 addresses with base
1550.Ar addr
1551(specified as allowed by
1552.Xr inet_pton 3
1553or a hostname)
1554and the mask of
1555.Ar mask ,
1556specified as allowed by
1557.Xr inet_pton 3 .
1558As an example, fe::640:0:0/ffff::ffff:ffff:0:0 will match
1559fe:*:*:*:0:640:*:*.
1560This form is advised only for non-contiguous
1561masks.
1562It is better to resort to the
1563.Ar addr Ns / Ns Ar masklen
1564format for contiguous masks, which is more compact and less
1565error-prone.
1566.El
1567.Pp
1568No support for sets of IPv6 addresses is provided because IPv6 addresses
1569are typically random past the initial prefix.
1570.It Ar ports : Bro Ar port | port Ns \&- Ns Ar port Ns Brc Ns Op , Ns Ar ports
1571For protocols which support port numbers (such as SCTP, TCP and UDP), optional
1572.Cm ports
1573may be specified as one or more ports or port ranges, separated
1574by commas but no spaces, and an optional
1575.Cm not
1576operator.
1577The
1578.Ql \&-
1579notation specifies a range of ports (including boundaries).
1580.Pp
1581Service names (from
1582.Pa /etc/services )
1583may be used instead of numeric port values.
1584The length of the port list is limited to 30 ports or ranges,
1585though one can specify larger ranges by using an
1586.Em or-block
1587in the
1588.Cm options
1589section of the rule.
1590.Pp
1591A backslash
1592.Pq Ql \e
1593can be used to escape the dash
1594.Pq Ql -
1595character in a service name (from a shell, the backslash must be
1596typed twice to avoid the shell itself interpreting it as an escape
1597character).
1598.Pp
1599.Dl "ipfw add count tcp from any ftp\e\e-data-ftp to any"
1600.Pp
1601Fragmented packets which have a non-zero offset (i.e., not the first
1602fragment) will never match a rule which has one or more port
1603specifications.
1604See the
1605.Cm frag
1606option for details on matching fragmented packets.
1607.El
1608.Ss RULE OPTIONS (MATCH PATTERNS)
1609Additional match patterns can be used within
1610rules.
1611Zero or more of these so-called
1612.Em options
1613can be present in a rule, optionally prefixed by the
1614.Cm not
1615operand, and possibly grouped into
1616.Em or-blocks .
1617.Pp
1618The following match patterns can be used (listed in alphabetical order):
1619.Bl -tag -width indent
1620.It Cm // this is a comment .
1621Inserts the specified text as a comment in the rule.
1622Everything following // is considered as a comment and stored in the rule.
1623You can have comment-only rules, which are listed as having a
1624.Cm count
1625action followed by the comment.
1626.It Cm bridged
1627Alias for
1628.Cm layer2 .
1629.It Cm defer-immediate-action | defer-action
1630A rule with this option will not perform normal action
1631upon a match.
1632This option is intended to be used with
1633.Cm record-state
1634or
1635.Cm keep-state
1636as the dynamic rule, created but ignored on match, will work
1637as intended.
1638Rules with both
1639.Cm record-state
1640and
1641.Cm defer-immediate-action
1642create a dynamic rule and continue with the next rule without actually
1643performing the action part of this rule.
1644When the rule is later activated via the state table, the action is
1645performed as usual.
1646.It Cm diverted
1647Matches only packets generated by a divert socket.
1648.It Cm diverted-loopback
1649Matches only packets coming from a divert socket back into the IP stack
1650input for delivery.
1651.It Cm diverted-output
1652Matches only packets going from a divert socket back outward to the IP
1653stack output for delivery.
1654.It Cm dst-ip Ar ip-address
1655Matches IPv4 packets whose destination IP is one of the address(es)
1656specified as argument.
1657.It Bro Cm dst-ip6 | dst-ipv6 Brc Ar ip6-address
1658Matches IPv6 packets whose destination IP is one of the address(es)
1659specified as argument.
1660.It Cm dst-port Ar ports
1661Matches IP packets whose destination port is one of the port(s)
1662specified as argument.
1663.It Cm established
1664Matches TCP packets that have the RST or ACK bits set.
1665.It Cm ext6hdr Ar header
1666Matches IPv6 packets containing the extended header given by
1667.Ar header .
1668Supported headers are:
1669.Pp
1670Fragment,
1671.Pq Cm frag ,
1672Hop-to-hop options
1673.Pq Cm hopopt ,
1674any type of Routing Header
1675.Pq Cm route ,
1676Source routing Routing Header Type 0
1677.Pq Cm rthdr0 ,
1678Mobile IPv6 Routing Header Type 2
1679.Pq Cm rthdr2 ,
1680Destination options
1681.Pq Cm dstopt ,
1682IPSec authentication headers
1683.Pq Cm ah ,
1684and IPsec encapsulating security payload headers
1685.Pq Cm esp .
1686.It Cm fib Ar fibnum
1687Matches a packet that has been tagged to use
1688the given FIB (routing table) number.
1689.It Cm flow Ar table-ref
1690Search for the flow entry in lookup table specified by
1691.Ar table-ref .
1692If not found, the match fails.
1693Otherwise, the match succeeds and
1694.Cm tablearg
1695is set to the value extracted from the table.
1696.Pp
1697This option can be useful to quickly dispatch traffic based on
1698certain packet fields.
1699See the
1700.Sx LOOKUP TABLES
1701section below for more information on lookup tables.
1702.It Cm flow-id Ar labels
1703Matches IPv6 packets containing any of the flow labels given in
1704.Ar labels .
1705.Ar labels
1706is a comma separated list of numeric flow labels.
1707.It Cm dst-mac Ar table-ref
1708Search for the destination MAC address entry in lookup table specified by
1709.Ar table-ref .
1710If not found, the match fails.
1711Otherwise, the match succeeds and
1712.Cm tablearg
1713is set to the value extracted from the table.
1714.It Cm src-mac Ar table-ref
1715Search for the source MAC address entry in lookup table specified by
1716.Ar table-ref .
1717If not found, the match fails.
1718Otherwise, the match succeeds and
1719.Cm tablearg
1720is set to the value extracted from the table.
1721.It Cm frag Ar spec
1722Matches IPv4 packets whose
1723.Cm ip_off
1724field contains the comma separated list of IPv4 fragmentation
1725options specified in
1726.Ar spec .
1727The recognized options are:
1728.Cm df
1729.Pq Dv don't fragment ,
1730.Cm mf
1731.Pq Dv more fragments ,
1732.Cm rf
1733.Pq Dv reserved fragment bit
1734.Cm offset
1735.Pq Dv non-zero fragment offset .
1736The absence of a particular options may be denoted
1737with a
1738.Ql \&! .
1739.Pp
1740Empty list of options defaults to matching on non-zero fragment offset.
1741Such rule would match all not the first fragment datagrams,
1742both IPv4 and IPv6.
1743This is a backward compatibility with older rulesets.
1744.It Cm gid Ar group
1745Matches all TCP or UDP packets sent by or received for a
1746.Ar group .
1747A
1748.Ar group
1749may be specified by name or number.
1750.It Cm jail Ar jail
1751Matches all TCP or UDP packets sent by or received for the
1752jail whose ID or name is
1753.Ar jail .
1754.It Cm icmptypes Ar types
1755Matches ICMP packets whose ICMP type is in the list
1756.Ar types .
1757The list may be specified as any combination of
1758individual types (numeric) separated by commas.
1759.Em Ranges are not allowed .
1760The supported ICMP types are:
1761.Pp
1762echo reply
1763.Pq Cm 0 ,
1764destination unreachable
1765.Pq Cm 3 ,
1766source quench
1767.Pq Cm 4 ,
1768redirect
1769.Pq Cm 5 ,
1770echo request
1771.Pq Cm 8 ,
1772router advertisement
1773.Pq Cm 9 ,
1774router solicitation
1775.Pq Cm 10 ,
1776time-to-live exceeded
1777.Pq Cm 11 ,
1778IP header bad
1779.Pq Cm 12 ,
1780timestamp request
1781.Pq Cm 13 ,
1782timestamp reply
1783.Pq Cm 14 ,
1784information request
1785.Pq Cm 15 ,
1786information reply
1787.Pq Cm 16 ,
1788address mask request
1789.Pq Cm 17
1790and address mask reply
1791.Pq Cm 18 .
1792.It Cm icmp6types Ar types
1793Matches ICMP6 packets whose ICMP6 type is in the list of
1794.Ar types .
1795The list may be specified as any combination of
1796individual types (numeric) separated by commas.
1797.Em Ranges are not allowed .
1798.It Cm in | out
1799Matches incoming or outgoing packets, respectively.
1800.Cm in
1801and
1802.Cm out
1803are mutually exclusive (in fact,
1804.Cm out
1805is implemented as
1806.Cm not in Ns No ).
1807.It Cm ipid Ar id-list
1808Matches IPv4 packets whose
1809.Cm ip_id
1810field has value included in
1811.Ar id-list ,
1812which is either a single value or a list of values or ranges
1813specified in the same way as
1814.Ar ports .
1815.It Cm iplen Ar len-list
1816Matches IP packets whose total length, including header and data, is
1817in the set
1818.Ar len-list ,
1819which is either a single value or a list of values or ranges
1820specified in the same way as
1821.Ar ports .
1822.It Cm ipoptions Ar spec
1823Matches packets whose IPv4 header contains the comma separated list of
1824options specified in
1825.Ar spec .
1826The supported IP options are:
1827.Pp
1828.Cm ssrr
1829(strict source route),
1830.Cm lsrr
1831(loose source route),
1832.Cm rr
1833(record packet route) and
1834.Cm ts
1835(timestamp).
1836The absence of a particular option may be denoted
1837with a
1838.Ql \&! .
1839.It Cm ipprecedence Ar precedence
1840Matches IPv4 packets whose precedence field is equal to
1841.Ar precedence .
1842.It Cm ipsec
1843Matches packets that have IPSEC history associated with them
1844(i.e., the packet comes encapsulated in IPSEC, the kernel
1845has IPSEC support, and can correctly decapsulate it).
1846.Pp
1847Note that specifying
1848.Cm ipsec
1849is different from specifying
1850.Cm proto Ar ipsec
1851as the latter will only look at the specific IP protocol field,
1852irrespective of IPSEC kernel support and the validity of the IPSEC data.
1853.Pp
1854Further note that this flag is silently ignored in kernels without
1855IPSEC support.
1856It does not affect rule processing when given and the
1857rules are handled as if with no
1858.Cm ipsec
1859flag.
1860.It Cm iptos Ar spec
1861Matches IPv4 packets whose
1862.Cm tos
1863field contains the comma separated list of
1864service types specified in
1865.Ar spec .
1866The supported IP types of service are:
1867.Pp
1868.Cm lowdelay
1869.Pq Dv IPTOS_LOWDELAY ,
1870.Cm throughput
1871.Pq Dv IPTOS_THROUGHPUT ,
1872.Cm reliability
1873.Pq Dv IPTOS_RELIABILITY ,
1874.Cm mincost
1875.Pq Dv IPTOS_MINCOST ,
1876.Cm congestion
1877.Pq Dv IPTOS_ECN_CE .
1878The absence of a particular type may be denoted
1879with a
1880.Ql \&! .
1881.It Cm dscp spec Ns Op , Ns Ar spec
1882Matches IPv4/IPv6 packets whose
1883.Cm DS
1884field value is contained in
1885.Ar spec
1886mask.
1887Multiple values can be specified via
1888the comma separated list.
1889Value can be one of keywords used in
1890.Cm setdscp
1891action or exact number.
1892.It Cm ipttl Ar ttl-list
1893Matches IPv4 packets whose time to live is included in
1894.Ar ttl-list ,
1895which is either a single value or a list of values or ranges
1896specified in the same way as
1897.Ar ports .
1898.It Cm ipversion Ar ver
1899Matches IP packets whose IP version field is
1900.Ar ver .
1901.It Cm keep-state Op Ar :flowname
1902Upon a match, the firewall will create a dynamic rule, whose
1903default behaviour is to match bidirectional traffic between
1904source and destination IP/port using the same protocol.
1905The rule has a limited lifetime (controlled by a set of
1906.Xr sysctl 8
1907variables), and the lifetime is refreshed every time a matching
1908packet is found.
1909The
1910.Ar :flowname
1911is used to assign additional to addresses, ports and protocol parameter
1912to dynamic rule.
1913It can be used for more accurate matching by
1914.Cm check-state
1915rule.
1916The
1917.Cm :default
1918keyword is special name used for compatibility with old rulesets.
1919.It Cm layer2
1920Matches only layer2 packets, i.e., those passed to
1921.Nm
1922from
1923.Fn ether_demux
1924and
1925.Fn ether_output_frame .
1926.It Cm limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N Op Ar :flowname
1927The firewall will only allow
1928.Ar N
1929connections with the same
1930set of parameters as specified in the rule.
1931One or more
1932of source and destination addresses and ports can be
1933specified.
1934.It Cm lookup Bro Cm dst-ip | dst-ip4 | dst-ip6 | dst-port | dst-mac | src-ip |
1935.Cm src-ip4 | src-ip6 | src-port | src-mac | uid | jail | dscp | mark |
1936.Cm rulenum
1937.Brc Ns Oo : Ns Ar bitmask Oc Ar name
1938Search an entry in lookup table
1939.Ar name
1940that matches the field specified as argument.
1941If not found, the match fails.
1942Otherwise, the match succeeds and
1943.Cm tablearg
1944is set to the value extracted from the table.
1945.Pp
1946If an optional
1947.Ar bitmask
1948is specified, value of the field is altered by bitwize AND with
1949.Ar bitmask
1950and resulting value is being searched instead of the original one.
1951The
1952.Ar bitmask
1953is accepted in the following formats:
1954.Bl -enum -width indent
1955.It
1956In a dotted-quad form, e.g. 127.88.34.0.
1957This form can be used for IPv4 lookups as well as for all numeric lookup
1958types.
1959.It
1960As a 32-bit number, e.g. 0xf00baa1 or 255.
1961This form can be used for IPv4 lookups as well as for all numeric lookup
1962types.
1963.It
1964As an IPv6 address when specified alongwith
1965.Cm dst-ip6
1966or
1967.Cm src-ip6
1968field.
1969If used, the rule will match IPv6 packets only.
1970Example: src-ip6:afff:ff00:ffff:ffff:0:0:0:0f0f.
1971.It
1972As a Ethernet mac address when specified alongwith
1973.Cm dst-mac
1974or
1975.Cm src-mac
1976field. E.g. 00:11:22:33:44:55.
1977.El
1978.Pp
1979The
1980.Ar bitmask
1981can not be specified for
1982.Cm dst-ip
1983or
1984.Cm src-ip
1985as these field specifiers lookup both IPv4 and IPv6 addresses.
1986.Pp
1987This option can be useful to quickly dispatch traffic based on
1988certain packet fields.
1989The
1990.Ar bitmask
1991allows to implement wildcard lookups by inserting into table masked prefix and
1992applying
1993.Ar bitmask
1994upon each lookup.
1995.Pp
1996See the
1997.Sx LOOKUP TABLES
1998section below for more information on lookup tables.
1999.It Cm { MAC | mac } Ar dst-mac src-mac
2000Match packets with a given
2001.Ar dst-mac
2002and
2003.Ar src-mac
2004addresses, specified as the
2005.Cm any
2006keyword (matching any MAC address), or six groups of hex digits
2007separated by colons,
2008and optionally followed by a mask indicating the significant bits.
2009The mask may be specified using either of the following methods:
2010.Bl -enum -width indent
2011.It
2012A slash
2013.Pq /
2014followed by the number of significant bits.
2015For example, an address with 33 significant bits could be specified as:
2016.Pp
2017.Dl "MAC 10:20:30:40:50:60/33 any"
2018.It
2019An ampersand
2020.Pq &
2021followed by a bitmask specified as six groups of hex digits separated
2022by colons.
2023For example, an address in which the last 16 bits are significant could
2024be specified as:
2025.Pp
2026.Dl "MAC 10:20:30:40:50:60&00:00:00:00:ff:ff any"
2027.Pp
2028Note that the ampersand character has a special meaning in many shells
2029and should generally be escaped.
2030.El
2031Note that the order of MAC addresses (destination first,
2032source second) is
2033the same as on the wire, but the opposite of the one used for
2034IP addresses.
2035.It Cm mac-type Ar mac-type
2036Matches packets whose Ethernet Type field
2037corresponds to one of those specified as argument.
2038.Ar mac-type
2039is specified in the same way as
2040.Cm port numbers
2041(i.e., one or more comma-separated single values or ranges).
2042You can use symbolic names for known values such as
2043.Em vlan , ipv4, ipv6 .
2044Values can be entered as decimal or hexadecimal (if prefixed by 0x),
2045and they are always printed as hexadecimal (unless the
2046.Cm -N
2047option is used, in which case symbolic resolution will be attempted).
2048.It Cm proto Ar protocol
2049Matches packets with the corresponding IP protocol.
2050.It Cm record-state
2051Upon a match, the firewall will create a dynamic rule as if
2052.Cm keep-state
2053was specified.
2054However, this option doesn't imply an implicit
2055.Cm check-state
2056in contrast to
2057.Cm keep-state .
2058.It Cm recv | xmit | via Brq Ar ifX | Ar ifmask | Ar table-ref | Ar ipno | Ar any
2059Matches packets received, transmitted or going through,
2060respectively, the interface specified by exact name
2061.Po Ar ifX Pc ,
2062by device mask
2063.Po Ar ifmask Pc ,
2064by IP address, or through some interface.
2065.Pp
2066Interface
2067name may be matched against
2068.Ar ifmask
2069with
2070.Xr fnmatch 3
2071according to the rules used by the shell (f.e. tun*).
2072See also the
2073.Sx EXAMPLES
2074section.
2075.Pp
2076A lookup table specified by
2077.Ar table-ref
2078may be used to match interface by its kernel ifindex.
2079See the
2080.Sx LOOKUP TABLES
2081section below for more information on lookup tables.
2082.Pp
2083The
2084.Cm via
2085keyword causes the interface to always be checked.
2086If
2087.Cm recv
2088or
2089.Cm xmit
2090is used instead of
2091.Cm via ,
2092then only the receive or transmit interface (respectively)
2093is checked.
2094By specifying both, it is possible to match packets based on
2095both receive and transmit interface, e.g.:
2096.Pp
2097.Dl "ipfw add deny ip from any to any out recv ed0 xmit ed1"
2098.Pp
2099The
2100.Cm recv
2101interface can be tested on either incoming or outgoing packets,
2102while the
2103.Cm xmit
2104interface can only be tested on outgoing packets.
2105So
2106.Cm out
2107is required (and
2108.Cm in
2109is invalid) whenever
2110.Cm xmit
2111is used.
2112.Pp
2113A packet might not have a receive or transmit interface: packets
2114originating from the local host have no receive interface,
2115while packets destined for the local host have no transmit
2116interface.
2117.It Cm set-limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N
2118Works like
2119.Cm limit
2120but does not have an implicit
2121.Cm check-state
2122attached to it.
2123.It Cm setup
2124Matches TCP packets that have the SYN bit set but no ACK bit.
2125This is the short form of
2126.Dq Li tcpflags\ syn,!ack .
2127.It Cm sockarg
2128Matches packets that are associated to a local socket and
2129for which the SO_USER_COOKIE socket option has been set
2130to a non-zero value.
2131As a side effect, the value of the
2132option is made available as
2133.Cm tablearg
2134value, which in turn can be used as
2135.Cm skipto
2136or
2137.Cm pipe
2138number.
2139.It Cm src-ip Ar ip-address
2140Matches IPv4 packets whose source IP is one of the address(es)
2141specified as an argument.
2142.It Cm src-ip6 Ar ip6-address
2143Matches IPv6 packets whose source IP is one of the address(es)
2144specified as an argument.
2145.It Cm src-port Ar ports
2146Matches IP packets whose source port is one of the port(s)
2147specified as argument.
2148.It Cm tagged Ar tag-list
2149Matches packets whose tags are included in
2150.Ar tag-list ,
2151which is either a single value or a list of values or ranges
2152specified in the same way as
2153.Ar ports .
2154Tags can be applied to the packet using
2155.Cm tag
2156rule action parameter (see it's description for details on tags).
2157.It Cm mark Ar value[:bitmask] | tablearg[:bitmask]
2158Matches packets whose mark is equal to
2159.Ar value
2160with optional
2161.Ar bitmask
2162applied to it.
2163.Cm tablearg
2164can also be used instead of an explicit
2165.Ar value
2166to match a value supplied by the last table lookup.
2167.Pp
2168Both
2169.Ar value
2170and
2171.Ar bitmask
2172can be entered as decimal or hexadecimal (if prefixed by 0x), and they
2173are always printed as hexadecimal.
2174.It Cm tcpack Ar ack
2175TCP packets only.
2176Match if the TCP header acknowledgment number field is set to
2177.Ar ack .
2178.It Cm tcpdatalen Ar tcpdatalen-list
2179Matches TCP packets whose length of TCP data is
2180.Ar tcpdatalen-list ,
2181which is either a single value or a list of values or ranges
2182specified in the same way as
2183.Ar ports .
2184.It Cm tcpflags Ar spec
2185TCP packets only.
2186Match if the TCP header contains the comma separated list of
2187flags specified in
2188.Ar spec .
2189The supported TCP flags are:
2190.Pp
2191.Cm fin ,
2192.Cm syn ,
2193.Cm rst ,
2194.Cm psh ,
2195.Cm ack
2196and
2197.Cm urg .
2198The absence of a particular flag may be denoted
2199with a
2200.Ql \&! .
2201A rule which contains a
2202.Cm tcpflags
2203specification can never match a fragmented packet which has
2204a non-zero offset.
2205See the
2206.Cm frag
2207option for details on matching fragmented packets.
2208.It Cm tcpmss Ar tcpmss-list
2209Matches TCP packets whose MSS (maximum segment size) value is set to
2210.Ar tcpmss-list ,
2211which is either a single value or a list of values or ranges
2212specified in the same way as
2213.Ar ports .
2214.It Cm tcpseq Ar seq
2215TCP packets only.
2216Match if the TCP header sequence number field is set to
2217.Ar seq .
2218.It Cm tcpwin Ar tcpwin-list
2219Matches TCP packets whose  header window field is set to
2220.Ar tcpwin-list ,
2221which is either a single value or a list of values or ranges
2222specified in the same way as
2223.Ar ports .
2224.It Cm tcpoptions Ar spec
2225TCP packets only.
2226Match if the TCP header contains the comma separated list of
2227options specified in
2228.Ar spec .
2229The supported TCP options are:
2230.Pp
2231.Cm mss
2232(maximum segment size),
2233.Cm window
2234(tcp window advertisement),
2235.Cm sack
2236(selective ack),
2237.Cm ts
2238(rfc1323 timestamp) and
2239.Cm cc
2240(rfc1644 t/tcp connection count).
2241The absence of a particular option may be denoted
2242with a
2243.Ql \&! .
2244.It Cm uid Ar user
2245Match all TCP or UDP packets sent by or received for a
2246.Ar user .
2247A
2248.Ar user
2249may be matched by name or identification number.
2250.It Cm verrevpath
2251For incoming packets,
2252a routing table lookup is done on the packet's source address.
2253If the interface on which the packet entered the system matches the
2254outgoing interface for the route,
2255the packet matches.
2256If the interfaces do not match up,
2257the packet does not match.
2258All outgoing packets or packets with no incoming interface match.
2259.Pp
2260The name and functionality of the option is intentionally similar to
2261the Cisco IOS command:
2262.Pp
2263.Dl ip verify unicast reverse-path
2264.Pp
2265This option can be used to make anti-spoofing rules to reject all
2266packets with source addresses not from this interface.
2267See also the option
2268.Cm antispoof .
2269.It Cm versrcreach
2270For incoming packets,
2271a routing table lookup is done on the packet's source address.
2272If a route to the source address exists, but not the default route
2273or a blackhole/reject route, the packet matches.
2274Otherwise, the packet does not match.
2275All outgoing packets match.
2276.Pp
2277The name and functionality of the option is intentionally similar to
2278the Cisco IOS command:
2279.Pp
2280.Dl ip verify unicast source reachable-via any
2281.Pp
2282This option can be used to make anti-spoofing rules to reject all
2283packets whose source address is unreachable.
2284.It Cm antispoof
2285For incoming packets, the packet's source address is checked if it
2286belongs to a directly connected network.
2287If the network is directly connected, then the interface the packet
2288came on in is compared to the interface the network is connected to.
2289When incoming interface and directly connected interface are not the
2290same, the packet does not match.
2291Otherwise, the packet does match.
2292All outgoing packets match.
2293.Pp
2294This option can be used to make anti-spoofing rules to reject all
2295packets that pretend to be from a directly connected network but do
2296not come in through that interface.
2297This option is similar to but more restricted than
2298.Cm verrevpath
2299because it engages only on packets with source addresses of directly
2300connected networks instead of all source addresses.
2301.El
2302.Sh LOOKUP TABLES
2303Lookup tables are useful to handle large sparse sets of
2304addresses or other search keys (e.g., ports, jail IDs, interface names).
2305In the rest of this section we will use the term ``key''.
2306Table name needs to match the following spec:
2307.Ar table-name .
2308Tables with the same name can be created in different
2309.Ar sets .
2310However, rule links to the tables in
2311.Ar set 0
2312by default.
2313This behavior can be controlled by
2314.Va net.inet.ip.fw.tables_sets
2315variable.
2316See the
2317.Sx SETS OF RULES
2318section for more information.
2319There may be up to 65535 different lookup tables.
2320.Pp
2321The following table types are supported:
2322.Bl -tag -width indent
2323.It Ar table-type : Ar addr | iface | number | flow | mac
2324.It Ar table-key : Ar addr Ns Oo / Ns Ar masklen Oc | iface-name | number | flow-spec
2325.It Ar flow-spec : Ar flow-field Ns Op , Ns Ar flow-spec
2326.It Ar flow-field : src-ip | proto | src-port | dst-ip | dst-port
2327.It Cm addr
2328Matches IPv4 or IPv6 address.
2329Each entry is represented by an
2330.Ar addr Ns Op / Ns Ar masklen
2331and will match all addresses with base
2332.Ar addr
2333(specified as an IPv4/IPv6 address, or a hostname) and mask width of
2334.Ar masklen
2335bits.
2336If
2337.Ar masklen
2338is not specified, it defaults to 32 for IPv4 and 128 for IPv6.
2339When looking up an IP address in a table, the most specific
2340entry will match.
2341.It Cm iface
2342Matches interface names.
2343Each entry is represented by string treated as interface name.
2344Wildcards are not supported.
2345.It Cm number
2346Matches protocol ports, uids/gids or jail IDs.
2347Each entry is represented by 32-bit unsigned integer.
2348Ranges are not supported.
2349.It Cm flow
2350Matches packet fields specified by
2351.Ar flow
2352type suboptions with table entries.
2353.It Cm mac
2354Matches MAC address.
2355Each entry is represented by an
2356.Ar addr Ns Op / Ns Ar masklen
2357and will match all addresses with base
2358.Ar addr
2359and mask width of
2360.Ar masklen
2361bits.
2362If
2363.Ar masklen
2364is not specified, it defaults to 48.
2365When looking up an MAC address in a table, the most specific
2366entry will match.
2367.El
2368.Pp
2369Tables require explicit creation via
2370.Cm create
2371before use.
2372.Pp
2373The following creation options are supported:
2374.Bl -tag -width indent
2375.It Ar create-options : Ar create-option | create-options
2376.It Ar create-option : Cm type Ar table-type | Cm valtype Ar value-mask | Cm algo Ar algo-desc |
2377.Cm limit Ar number | Cm locked | Cm missing | Cm or-flush
2378.It Cm type
2379Table key type.
2380.It Cm valtype
2381Table value mask.
2382.It Cm algo
2383Table algorithm to use (see below).
2384.It Cm limit
2385Maximum number of items that may be inserted into table.
2386.It Cm locked
2387Restrict any table modifications.
2388.It Cm missing
2389Do not fail if table already exists and has exactly same options as new one.
2390.It Cm or-flush
2391Flush existing table with same name instead of returning error.
2392Implies
2393.Cm missing
2394so existing table must be compatible with new one.
2395.El
2396.Pp
2397Some of these options may be modified later via
2398.Cm modify
2399keyword.
2400The following options can be changed:
2401.Bl -tag -width indent
2402.It Ar modify-options : Ar modify-option | modify-options
2403.It Ar modify-option : Cm limit Ar number
2404.It Cm limit
2405Alter maximum number of items that may be inserted into table.
2406.El
2407.Pp
2408Additionally, table can be locked or unlocked using
2409.Cm lock
2410or
2411.Cm unlock
2412commands.
2413.Pp
2414Tables of the same
2415.Ar type
2416can be swapped with each other using
2417.Cm swap Ar name
2418command.
2419Swap may fail if tables limits are set and data exchange
2420would result in limits hit.
2421Operation is performed atomically.
2422.Pp
2423One or more entries can be added to a table at once using
2424.Cm add
2425command.
2426Addition of all items are performed atomically.
2427By default, error in addition of one entry does not influence
2428addition of other entries.
2429However, non-zero error code is returned in that case.
2430Special
2431.Cm atomic
2432keyword may be specified before
2433.Cm add
2434to indicate all-or-none add request.
2435.Pp
2436One or more entries can be removed from a table at once using
2437.Cm delete
2438command.
2439By default, error in removal of one entry does not influence
2440removing of other entries.
2441However, non-zero error code is returned in that case.
2442.Pp
2443It may be possible to check what entry will be found on particular
2444.Ar table-key
2445using
2446.Cm lookup
2447.Ar table-key
2448command.
2449This functionality is optional and may be unsupported in some algorithms.
2450.Pp
2451The following operations can be performed on
2452.Ar one
2453or
2454.Cm all
2455tables:
2456.Bl -tag -width indent
2457.It Cm list
2458List all entries.
2459.It Cm flush
2460Removes all entries.
2461.It Cm info
2462Shows generic table information.
2463.It Cm detail
2464Shows generic table information and algo-specific data.
2465.El
2466.Pp
2467The following lookup algorithms are supported:
2468.Bl -tag -width indent
2469.It Ar algo-desc : algo-name | "algo-name algo-data"
2470.It Ar algo-name : Ar addr: radix | addr: hash | iface: array | number: array | flow: hash | mac: radix
2471.It Cm addr: radix
2472Separate Radix trees for IPv4 and IPv6, the same way as the routing table (see
2473.Xr route 4 ) .
2474Default choice for
2475.Ar addr
2476type.
2477.It Cm addr:hash
2478Separate auto-growing hashes for IPv4 and IPv6.
2479Accepts entries with the same mask length specified initially via
2480.Cm "addr:hash masks=/v4,/v6"
2481algorithm creation options.
2482Assume /32 and /128 masks by default.
2483Search removes host bits (according to mask) from supplied address and checks
2484resulting key in appropriate hash.
2485Mostly optimized for /64 and byte-ranged IPv6 masks.
2486.It Cm iface:array
2487Array storing sorted indexes for entries which are presented in the system.
2488Optimized for very fast lookup.
2489.It Cm number:array
2490Array storing sorted u32 numbers.
2491.It Cm flow:hash
2492Auto-growing hash storing flow entries.
2493Search calculates hash on required packet fields and searches for matching
2494entries in selected bucket.
2495.It Cm mac: radix
2496Radix tree for MAC address
2497.El
2498.Pp
2499The
2500.Cm tablearg
2501feature provides the ability to use a value, looked up in the table, as
2502the argument for a rule action, action parameter or rule option.
2503This can significantly reduce number of rules in some configurations.
2504If two tables are used in a rule, the result of the second (destination)
2505is used.
2506.Pp
2507Each record may hold one or more values according to
2508.Ar value-mask .
2509This mask is set on table creation via
2510.Cm valtype
2511option.
2512The following value types are supported:
2513.Bl -tag -width indent
2514.It Ar value-mask : Ar value-type Ns Op , Ns Ar value-mask
2515.It Ar value-type : Ar skipto | pipe | fib | nat | dscp | tag | divert |
2516.Ar netgraph | limit | ipv4 | ipv6 | mark
2517.It Cm skipto
2518rule number to jump to.
2519.It Cm pipe
2520Pipe number to use.
2521.It Cm fib
2522fib number to match/set.
2523.It Cm nat
2524nat number to jump to.
2525.It Cm dscp
2526dscp value to match/set.
2527.It Cm tag
2528tag number to match/set.
2529.It Cm divert
2530port number to divert traffic to.
2531.It Cm netgraph
2532hook number to move packet to.
2533.It Cm limit
2534maximum number of connections.
2535.It Cm ipv4
2536IPv4 nexthop to fwd packets to.
2537.It Cm ipv6
2538IPv6 nexthop to fwd packets to.
2539.It Cm mark
2540mark value to match/set.
2541.El
2542.Pp
2543The
2544.Cm tablearg
2545argument can be used with the following actions:
2546.Cm nat, pipe, queue, divert, tee, netgraph, ngtee, fwd, skipto, setfib ,
2547.Cm setmark ,
2548action parameters:
2549.Cm tag, untag ,
2550rule options:
2551.Cm limit, tagged, mark .
2552.Pp
2553When used with the
2554.Cm skipto
2555action, the user should be aware that the code will walk the ruleset
2556up to a rule equal to, or past, the given number.
2557.Pp
2558See the
2559.Sx EXAMPLES
2560Section for example usage of tables and the tablearg keyword.
2561.Sh SETS OF RULES
2562Each rule or table belongs to one of 32 different
2563.Em sets
2564, numbered 0 to 31.
2565Set 31 is reserved for the default rule.
2566.Pp
2567By default, rules or tables are put in set 0, unless you use the
2568.Cm set N
2569attribute when adding a new rule or table.
2570Sets can be individually and atomically enabled or disabled,
2571so this mechanism permits an easy way to store multiple configurations
2572of the firewall and quickly (and atomically) switch between them.
2573.Pp
2574By default, tables from set 0 are referenced when adding rule with
2575table opcodes regardless of rule set.
2576This behavior can be changed by setting
2577.Va net.inet.ip.fw.tables_sets
2578variable to 1.
2579Rule's set will then be used for table references.
2580.Pp
2581The command to enable/disable sets is
2582.Bd -ragged -offset indent
2583.Nm
2584.Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
2585.Ed
2586.Pp
2587where multiple
2588.Cm enable
2589or
2590.Cm disable
2591sections can be specified.
2592Command execution is atomic on all the sets specified in the command.
2593By default, all sets are enabled.
2594.Pp
2595When you disable a set, its rules behave as if they do not exist
2596in the firewall configuration, with only one exception:
2597.Bd -ragged -offset indent
2598dynamic rules created from a rule before it had been disabled
2599will still be active until they expire.
2600In order to delete
2601dynamic rules you have to explicitly delete the parent rule
2602which generated them.
2603.Ed
2604.Pp
2605The set number of rules can be changed with the command
2606.Bd -ragged -offset indent
2607.Nm
2608.Cm set move
2609.Brq Cm rule Ar rule-number | old-set
2610.Cm to Ar new-set
2611.Ed
2612.Pp
2613Also, you can atomically swap two rulesets with the command
2614.Bd -ragged -offset indent
2615.Nm
2616.Cm set swap Ar first-set second-set
2617.Ed
2618.Pp
2619See the
2620.Sx EXAMPLES
2621Section on some possible uses of sets of rules.
2622.Sh STATEFUL FIREWALL
2623Stateful operation is a way for the firewall to dynamically
2624create rules for specific flows when packets that
2625match a given pattern are detected.
2626Support for stateful
2627operation comes through the
2628.Cm check-state , keep-state , record-state , limit
2629and
2630.Cm set-limit
2631options of
2632.Nm rules .
2633.Pp
2634Dynamic rules are created when a packet matches a
2635.Cm keep-state ,
2636.Cm record-state ,
2637.Cm limit
2638or
2639.Cm set-limit
2640rule, causing the creation of a
2641.Em dynamic
2642rule which will match all and only packets with
2643a given
2644.Em protocol
2645between a
2646.Em src-ip/src-port dst-ip/dst-port
2647pair of addresses
2648.Em ( src
2649and
2650.Em dst
2651are used here only to denote the initial match addresses, but they
2652are completely equivalent afterwards).
2653Rules created by
2654.Cm keep-state
2655option also have a
2656.Ar :flowname
2657taken from it.
2658This name is used in matching together with addresses, ports and protocol.
2659Dynamic rules will be checked at the first
2660.Cm check-state, keep-state
2661or
2662.Cm limit
2663occurrence, and the action performed upon a match will be the same
2664as in the parent rule.
2665.Pp
2666Note that no additional attributes other than protocol and IP addresses
2667and ports and :flowname are checked on dynamic rules.
2668.Pp
2669The typical use of dynamic rules is to keep a closed firewall configuration,
2670but let the first TCP SYN packet from the inside network install a
2671dynamic rule for the flow so that packets belonging to that session
2672will be allowed through the firewall:
2673.Pp
2674.Dl "ipfw add check-state :OUTBOUND"
2675.Dl "ipfw add allow tcp from my-subnet to any setup keep-state :OUTBOUND"
2676.Dl "ipfw add deny tcp from any to any"
2677.Pp
2678A similar approach can be used for UDP, where an UDP packet coming
2679from the inside will install a dynamic rule to let the response through
2680the firewall:
2681.Pp
2682.Dl "ipfw add check-state :OUTBOUND"
2683.Dl "ipfw add allow udp from my-subnet to any keep-state :OUTBOUND"
2684.Dl "ipfw add deny udp from any to any"
2685.Pp
2686Dynamic rules expire after some time, which depends on the status
2687of the flow and the setting of some
2688.Cm sysctl
2689variables.
2690See Section
2691.Sx SYSCTL VARIABLES
2692for more details.
2693For TCP sessions, dynamic rules can be instructed to periodically
2694send keepalive packets to refresh the state of the rule when it is
2695about to expire.
2696.Pp
2697See Section
2698.Sx EXAMPLES
2699for more examples on how to use dynamic rules.
2700.Sh TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
2701.Nm
2702is also the user interface for the
2703.Nm dummynet
2704traffic shaper, packet scheduler and network emulator, a subsystem that
2705can artificially queue, delay or drop packets
2706emulating the behaviour of certain network links
2707or queueing systems.
2708.Pp
2709.Nm dummynet
2710operates by first using the firewall to select packets
2711using any match pattern that can be used in
2712.Nm
2713rules.
2714Matching packets are then passed to either of two
2715different objects, which implement the traffic regulation:
2716.Bl -hang -offset XXXX
2717.It Em pipe
2718A
2719.Em pipe
2720emulates a
2721.Em link
2722with given bandwidth and propagation delay,
2723driven by a FIFO scheduler and a single queue with programmable
2724queue size and packet loss rate.
2725Packets are appended to the queue as they come out from
2726.Nm ipfw ,
2727and then transferred in FIFO order to the link at the desired rate.
2728.It Em queue
2729A
2730.Em queue
2731is an abstraction used to implement packet scheduling
2732using one of several packet scheduling algorithms.
2733Packets sent to a
2734.Em queue
2735are first grouped into flows according to a mask on the 5-tuple.
2736Flows are then passed to the scheduler associated to the
2737.Em queue ,
2738and each flow uses scheduling parameters (weight and others)
2739as configured in the
2740.Em queue
2741itself.
2742A scheduler in turn is connected to an emulated link,
2743and arbitrates the link's bandwidth among backlogged flows according to
2744weights and to the features of the scheduling algorithm in use.
2745.El
2746.Pp
2747In practice,
2748.Em pipes
2749can be used to set hard limits to the bandwidth that a flow can use, whereas
2750.Em queues
2751can be used to determine how different flows share the available bandwidth.
2752.Pp
2753A graphical representation of the binding of queues,
2754flows, schedulers and links is below.
2755.Bd -literal -offset indent
2756                 (flow_mask|sched_mask)  sched_mask
2757         +---------+   weight Wx  +-------------+
2758         |         |->-[flow]-->--|             |-+
2759    -->--| QUEUE x |   ...        |             | |
2760         |         |->-[flow]-->--| SCHEDuler N | |
2761         +---------+              |             | |
2762             ...                  |             +--[LINK N]-->--
2763         +---------+   weight Wy  |             | +--[LINK N]-->--
2764         |         |->-[flow]-->--|             | |
2765    -->--| QUEUE y |   ...        |             | |
2766         |         |->-[flow]-->--|             | |
2767         +---------+              +-------------+ |
2768                                    +-------------+
2769.Ed
2770It is important to understand the role of the SCHED_MASK
2771and FLOW_MASK, which are configured through the commands
2772.Dl "ipfw sched N config mask SCHED_MASK ..."
2773and
2774.Dl "ipfw queue X config mask FLOW_MASK ..." .
2775.Pp
2776The SCHED_MASK is used to assign flows to one or more
2777scheduler instances, one for each
2778value of the packet's 5-tuple after applying SCHED_MASK.
2779As an example, using ``src-ip 0xffffff00'' creates one instance
2780for each /24 destination subnet.
2781.Pp
2782The FLOW_MASK, together with the SCHED_MASK, is used to split
2783packets into flows.
2784As an example, using
2785``src-ip 0x000000ff''
2786together with the previous SCHED_MASK makes a flow for
2787each individual source address.
2788In turn, flows for each /24
2789subnet will be sent to the same scheduler instance.
2790.Pp
2791The above diagram holds even for the
2792.Em pipe
2793case, with the only restriction that a
2794.Em pipe
2795only supports a SCHED_MASK, and forces the use of a FIFO
2796scheduler (these are for backward compatibility reasons;
2797in fact, internally, a
2798.Nm dummynet's
2799pipe is implemented exactly as above).
2800.Pp
2801There are two modes of
2802.Nm dummynet
2803operation:
2804.Dq normal
2805and
2806.Dq fast .
2807The
2808.Dq normal
2809mode tries to emulate a real link: the
2810.Nm dummynet
2811scheduler ensures that the packet will not leave the pipe faster than it
2812would on the real link with a given bandwidth.
2813The
2814.Dq fast
2815mode allows certain packets to bypass the
2816.Nm dummynet
2817scheduler (if packet flow does not exceed pipe's bandwidth).
2818This is the reason why the
2819.Dq fast
2820mode requires less CPU cycles per packet (on average) and packet latency
2821can be significantly lower in comparison to a real link with the same
2822bandwidth.
2823The default mode is
2824.Dq normal .
2825The
2826.Dq fast
2827mode can be enabled by setting the
2828.Va net.inet.ip.dummynet.io_fast
2829.Xr sysctl 8
2830variable to a non-zero value.
2831.Ss PIPE, QUEUE AND SCHEDULER CONFIGURATION
2832The
2833.Em pipe ,
2834.Em queue
2835and
2836.Em scheduler
2837configuration commands are the following:
2838.Bd -ragged -offset indent
2839.Cm pipe Ar number Cm config Ar pipe-configuration
2840.Pp
2841.Cm queue Ar number Cm config Ar queue-configuration
2842.Pp
2843.Cm sched Ar number Cm config Ar sched-configuration
2844.Ed
2845.Pp
2846The following parameters can be configured for a pipe:
2847.Pp
2848.Bl -tag -width indent -compact
2849.It Cm bw Ar bandwidth | device
2850Bandwidth, measured in
2851.Sm off
2852.Op Cm K | M | G
2853.Brq Cm bit/s | Byte/s .
2854.Sm on
2855.Pp
2856A value of 0 (default) means unlimited bandwidth.
2857The unit must immediately follow the number, as in
2858.Pp
2859.Dl "dnctl pipe 1 config bw 300Kbit/s"
2860.Pp
2861If a device name is specified instead of a numeric value, as in
2862.Pp
2863.Dl "dnctl pipe 1 config bw tun0"
2864.Pp
2865then the transmit clock is supplied by the specified device.
2866At the moment only the
2867.Xr tun 4
2868device supports this
2869functionality, for use in conjunction with
2870.Xr ppp 8 .
2871.Pp
2872.It Cm delay Ar ms-delay
2873Propagation delay, measured in milliseconds.
2874The value is rounded to the next multiple of the clock tick
2875(typically 10ms, but it is a good practice to run kernels
2876with
2877.Dq "options HZ=1000"
2878to reduce
2879the granularity to 1ms or less).
2880The default value is 0, meaning no delay.
2881.Pp
2882.It Cm burst Ar size
2883If the data to be sent exceeds the pipe's bandwidth limit
2884(and the pipe was previously idle), up to
2885.Ar size
2886bytes of data are allowed to bypass the
2887.Nm dummynet
2888scheduler, and will be sent as fast as the physical link allows.
2889Any additional data will be transmitted at the rate specified
2890by the
2891.Nm pipe
2892bandwidth.
2893The burst size depends on how long the pipe has been idle;
2894the effective burst size is calculated as follows:
2895MAX(
2896.Ar size
2897,
2898.Nm bw
2899* pipe_idle_time).
2900.Pp
2901.It Cm profile Ar filename
2902A file specifying the additional overhead incurred in the transmission
2903of a packet on the link.
2904.Pp
2905Some link types introduce extra delays in the transmission
2906of a packet, e.g., because of MAC level framing, contention on
2907the use of the channel, MAC level retransmissions and so on.
2908From our point of view, the channel is effectively unavailable
2909for this extra time, which is constant or variable depending
2910on the link type.
2911Additionally, packets may be dropped after this
2912time (e.g., on a wireless link after too many retransmissions).
2913We can model the additional delay with an empirical curve
2914that represents its distribution.
2915.Bd -literal -offset indent
2916      cumulative probability
2917      1.0 ^
2918          |
2919      L   +-- loss-level          x
2920          |                 ******
2921          |                *
2922          |           *****
2923          |          *
2924          |        **
2925          |       *
2926          +-------*------------------->
2927                      delay
2928.Ed
2929The empirical curve may have both vertical and horizontal lines.
2930Vertical lines represent constant delay for a range of
2931probabilities.
2932Horizontal lines correspond to a discontinuity in the delay
2933distribution: the pipe will use the largest delay for a
2934given probability.
2935.Pp
2936The file format is the following, with whitespace acting as
2937a separator and '#' indicating the beginning a comment:
2938.Bl -tag -width indent
2939.It Cm name Ar identifier
2940optional name (listed by "dnctl pipe show")
2941to identify the delay distribution;
2942.It Cm bw Ar value
2943the bandwidth used for the pipe.
2944If not specified here, it must be present
2945explicitly as a configuration parameter for the pipe;
2946.It Cm loss-level Ar L
2947the probability above which packets are lost.
2948(0.0 <= L <= 1.0, default 1.0 i.e., no loss);
2949.It Cm samples Ar N
2950the number of samples used in the internal
2951representation of the curve (2..1024; default 100);
2952.It Cm "delay prob" | "prob delay"
2953One of these two lines is mandatory and defines
2954the format of the following lines with data points.
2955.It Ar XXX Ar YYY
29562 or more lines representing points in the curve,
2957with either delay or probability first, according
2958to the chosen format.
2959The unit for delay is milliseconds.
2960Data points do not need to be sorted.
2961Also, the number of actual lines can be different
2962from the value of the "samples" parameter:
2963.Nm
2964utility will sort and interpolate
2965the curve as needed.
2966.El
2967.Pp
2968Example of a profile file:
2969.Bd -literal -offset indent
2970name    bla_bla_bla
2971samples 100
2972loss-level    0.86
2973prob    delay
29740       200	# minimum overhead is 200ms
29750.5     200
29760.5     300
29770.8     1000
29780.9     1300
29791       1300
2980#configuration file end
2981.Ed
2982.El
2983.Pp
2984The following parameters can be configured for a queue:
2985.Pp
2986.Bl -tag -width indent -compact
2987.It Cm pipe Ar pipe_nr
2988Connects a queue to the specified pipe.
2989Multiple queues (with the same or different weights) can be connected to
2990the same pipe, which specifies the aggregate rate for the set of queues.
2991.Pp
2992.It Cm weight Ar weight
2993Specifies the weight to be used for flows matching this queue.
2994The weight must be in the range 1..100, and defaults to 1.
2995.El
2996.Pp
2997The following case-insensitive parameters can be configured for a
2998scheduler:
2999.Pp
3000.Bl -tag -width indent -compact
3001.It Cm type Ar {fifo | wf2q+ | rr | qfq | fq_codel | fq_pie}
3002specifies the scheduling algorithm to use.
3003.Bl -tag -width indent -compact
3004.It Cm fifo
3005is just a FIFO scheduler (which means that all packets
3006are stored in the same queue as they arrive to the scheduler).
3007FIFO has O(1) per-packet time complexity, with very low
3008constants (estimate 60-80ns on a 2GHz desktop machine)
3009but gives no service guarantees.
3010.It Cm wf2q+
3011implements the WF2Q+ algorithm, which is a Weighted Fair Queueing
3012algorithm which permits flows to share bandwidth according to
3013their weights.
3014Note that weights are not priorities; even a flow
3015with a minuscule weight will never starve.
3016WF2Q+ has O(log N) per-packet processing cost, where N is the number
3017of flows, and is the default algorithm used by previous versions
3018dummynet's queues.
3019.It Cm rr
3020implements the Deficit Round Robin algorithm, which has O(1) processing
3021costs (roughly, 100-150ns per packet)
3022and permits bandwidth allocation according to weights, but
3023with poor service guarantees.
3024.It Cm qfq
3025implements the QFQ algorithm, which is a very fast variant of
3026WF2Q+, with similar service guarantees and O(1) processing
3027costs (roughly, 200-250ns per packet).
3028.It Cm fq_codel
3029implements the FQ-CoDel (FlowQueue-CoDel) scheduler/AQM algorithm, which
3030uses a modified Deficit Round Robin scheduler to manage two lists of sub-queues
3031(old sub-queues and new sub-queues) for providing brief periods of priority to
3032lightweight or short burst flows.
3033By default, the total number of sub-queues is 1024.
3034FQ-CoDel's internal, dynamically
3035created sub-queues are controlled by separate instances of CoDel AQM.
3036.It Cm fq_pie
3037implements the FQ-PIE (FlowQueue-PIE) scheduler/AQM algorithm, which similar to
3038.Cm fq_codel
3039but uses per sub-queue PIE AQM instance to control the queue delay.
3040.El
3041.Pp
3042.Cm fq_codel
3043inherits AQM parameters and options from
3044.Cm codel
3045(see below), and
3046.Cm fq_pie
3047inherits AQM parameters and options from
3048.Cm pie
3049(see below).
3050Additionally, both of
3051.Cm fq_codel
3052and
3053.Cm fq_pie
3054have shared scheduler parameters which are:
3055.Bl -tag -width indent
3056.It Cm quantum
3057.Ar m
3058specifies the quantum (credit) of the scheduler.
3059.Ar m
3060is the number of bytes a queue can serve before being moved to the tail
3061of old queues list.
3062The default is 1514 bytes, and the maximum acceptable value
3063is 9000 bytes.
3064.It Cm limit
3065.Ar m
3066specifies the hard size limit (in unit of packets) of all queues managed by an
3067instance of the scheduler.
3068The default value of
3069.Ar m
3070is 10240 packets, and the maximum acceptable value is 20480 packets.
3071.It Cm flows
3072.Ar m
3073specifies the total number of flow queues (sub-queues) that fq_*
3074creates and manages.
3075By default, 1024 sub-queues are created when an instance
3076of the fq_{codel/pie} scheduler is created.
3077The maximum acceptable value is
307865536.
3079.El
3080.Pp
3081Note that any token after
3082.Cm fq_codel
3083or
3084.Cm fq_pie
3085is considered a parameter for fq_{codel/pie}.
3086So, ensure all scheduler
3087configuration options not related to fq_{codel/pie} are written before
3088.Cm fq_codel/fq_pie
3089tokens.
3090.El
3091.Pp
3092In addition to the type, all parameters allowed for a pipe can also
3093be specified for a scheduler.
3094.Pp
3095Finally, the following parameters can be configured for both
3096pipes and queues:
3097.Pp
3098.Bl -tag -width XXXX -compact
3099.It Cm buckets Ar hash-table-size
3100Specifies the size of the hash table used for storing the
3101various queues.
3102Default value is 64 controlled by the
3103.Xr sysctl 8
3104variable
3105.Va net.inet.ip.dummynet.hash_size ,
3106allowed range is 16 to 65536.
3107.Pp
3108.It Cm mask Ar mask-specifier
3109Packets sent to a given pipe or queue by an
3110.Nm
3111rule can be further classified into multiple flows, each of which is then
3112sent to a different
3113.Em dynamic
3114pipe or queue.
3115A flow identifier is constructed by masking the IP addresses,
3116ports and protocol types as specified with the
3117.Cm mask
3118options in the configuration of the pipe or queue.
3119For each different flow identifier, a new pipe or queue is created
3120with the same parameters as the original object, and matching packets
3121are sent to it.
3122.Pp
3123Thus, when
3124.Em dynamic pipes
3125are used, each flow will get the same bandwidth as defined by the pipe,
3126whereas when
3127.Em dynamic queues
3128are used, each flow will share the parent's pipe bandwidth evenly
3129with other flows generated by the same queue (note that other queues
3130with different weights might be connected to the same pipe).
3131.br
3132Available mask specifiers are a combination of one or more of the following:
3133.Pp
3134.Cm dst-ip Ar mask ,
3135.Cm dst-ip6 Ar mask ,
3136.Cm src-ip Ar mask ,
3137.Cm src-ip6 Ar mask ,
3138.Cm dst-port Ar mask ,
3139.Cm src-port Ar mask ,
3140.Cm flow-id Ar mask ,
3141.Cm proto Ar mask
3142or
3143.Cm all ,
3144.Pp
3145where the latter means all bits in all fields are significant.
3146.Pp
3147.It Cm noerror
3148When a packet is dropped by a
3149.Nm dummynet
3150queue or pipe, the error
3151is normally reported to the caller routine in the kernel, in the
3152same way as it happens when a device queue fills up.
3153Setting this
3154option reports the packet as successfully delivered, which can be
3155needed for some experimental setups where you want to simulate
3156loss or congestion at a remote router.
3157.Pp
3158.It Cm plr Ar packet-loss-rate
3159.It Cm plr Ar K,p,H,r
3160Packet loss rate.
3161Argument
3162.Ar packet-loss-rate
3163is a floating-point number between 0 and 1, with 0 meaning no
3164loss, 1 meaning 100% loss.
3165.Pp
3166When invoked with four arguments, the simple Gilbert-Elliott
3167channel model with two states (Good and Bad) is used.
3168.Bd -literal -offset indent
3169                        r
3170               .----------------.
3171               v                |
3172         .------------.   .------------.
3173         |     G      |   |     B      |
3174         |  drop (K)  |   |  drop (H)  |
3175         '------------'   '------------'
3176               |                ^
3177               '----------------'
3178                        p
3179
3180.Ed
3181This has the associated probabilities
3182.Po Ar K
3183and
3184.Ar H Pc
3185for the loss probability.
3186This is different from the literature, where this model is described with
3187probabilities of successful transmission k and h.
3188However, converting from literature is easy:
3189.Pp
3190K = 1 - k ; H = 1 - h
3191.Pp
3192This is to retain consistency within the interface and allow the
3193quick re-use of loss probability when giving only a single argument.
3194In addition the state change probabilities
3195.Po Ar p
3196and
3197.Ar r Pc
3198are given.
3199All of the above probabilities are internally represented on 31 bits.
3200.Pp
3201.It Cm queue Brq Ar slots | size Ns Cm Kbytes
3202Queue size, in
3203.Ar slots
3204or
3205.Cm KBytes .
3206Default value is 50 slots, which
3207is the typical queue size for Ethernet devices.
3208Note that for slow speed links you should keep the queue
3209size short or your traffic might be affected by a significant
3210queueing delay.
3211E.g., 50 max-sized Ethernet packets (1500 bytes) mean 600Kbit
3212or 20s of queue on a 30Kbit/s pipe.
3213Even worse effects can result if you get packets from an
3214interface with a much larger MTU, e.g.\& the loopback interface
3215with its 16KB packets.
3216The
3217.Xr sysctl 8
3218variables
3219.Em net.inet.ip.dummynet.pipe_byte_limit
3220and
3221.Em net.inet.ip.dummynet.pipe_slot_limit
3222control the maximum lengths that can be specified.
3223.Pp
3224.It Cm red | gred Ar w_q Ns / Ns Ar min_th Ns / Ns Ar max_th Ns / Ns Ar max_p
3225[ecn]
3226Make use of the RED (Random Early Detection) queue management algorithm.
3227.Ar w_q
3228and
3229.Ar max_p
3230are floating
3231point numbers between 0 and 1 (inclusive), while
3232.Ar min_th
3233and
3234.Ar max_th
3235are integer numbers specifying thresholds for queue management
3236(thresholds are computed in bytes if the queue has been defined
3237in bytes, in slots otherwise).
3238The two parameters can also be of the same value if needed.
3239The
3240.Nm dummynet
3241also supports the gentle RED variant (gred) and ECN (Explicit Congestion
3242Notification) as optional.
3243Three
3244.Xr sysctl 8
3245variables can be used to control the RED behaviour:
3246.Bl -tag -width indent
3247.It Va net.inet.ip.dummynet.red_lookup_depth
3248specifies the accuracy in computing the average queue
3249when the link is idle (defaults to 256, must be greater than zero)
3250.It Va net.inet.ip.dummynet.red_avg_pkt_size
3251specifies the expected average packet size (defaults to 512, must be
3252greater than zero)
3253.It Va net.inet.ip.dummynet.red_max_pkt_size
3254specifies the expected maximum packet size, only used when queue
3255thresholds are in bytes (defaults to 1500, must be greater than zero).
3256.El
3257.Pp
3258.It Cm codel Oo Cm target Ar time Oc Oo Cm interval Ar time Oc Oo Cm ecn |
3259.Cm noecn Oc
3260Make use of the CoDel (Controlled-Delay) queue management algorithm.
3261.Ar time
3262is interpreted as milliseconds by default but seconds (s), milliseconds (ms) or
3263microseconds (us) can be specified instead.
3264CoDel drops or marks (ECN) packets
3265depending on packet sojourn time in the queue.
3266.Cm target
3267.Ar time
3268(5ms by default) is the minimum acceptable persistent queue delay that CoDel
3269allows.
3270CoDel does not drop packets directly after packets sojourn time becomes
3271higher than
3272.Cm target
3273.Ar time
3274but waits for
3275.Cm interval
3276.Ar time
3277(100ms default) before dropping.
3278.Cm interval
3279.Ar time
3280should be set to maximum RTT for all expected connections.
3281.Cm ecn
3282enables (disabled by default) packet marking (instead of dropping) for
3283ECN-enabled TCP flows when queue delay becomes high.
3284.Pp
3285Note that any token after
3286.Cm codel
3287is considered a parameter for CoDel.
3288So, ensure all pipe/queue
3289configuration options are written before
3290.Cm codel
3291token.
3292.Pp
3293The
3294.Xr sysctl 8
3295variables
3296.Va net.inet.ip.dummynet.codel.target
3297and
3298.Va net.inet.ip.dummynet.codel.interval
3299can be used to set CoDel default parameters.
3300.Pp
3301.It Cm pie Oo Cm target Ar time Oc Oo Cm tupdate Ar time Oc Oo
3302.Cm alpha Ar n Oc Oo Cm beta Ar n Oc Oo Cm max_burst Ar time Oc Oo
3303.Cm max_ecnth Ar n Oc Oo Cm ecn | Cm noecn Oc Oo Cm capdrop |
3304.Cm nocapdrop Oc Oo Cm drand | Cm nodrand Oc Oo Cm onoff
3305.Oc Oo Cm dre | Cm ts Oc
3306Make use of the PIE (Proportional Integral controller Enhanced) queue management
3307algorithm.
3308PIE drops or marks packets depending on a calculated drop probability during
3309en-queue process, with the aim of achieving high throughput while keeping queue
3310delay low.
3311At regular time intervals of
3312.Cm tupdate
3313.Ar time
3314(15ms by default) a background process (re)calculates the probability based on
3315queue delay deviations from
3316.Cm target
3317.Ar time
3318(15ms by default) and queue delay trends.
3319PIE approximates current queue
3320delay by using a departure rate estimation method, or (optionally) by using a
3321packet timestamp method similar to CoDel.
3322.Ar time
3323is interpreted as milliseconds by default but seconds (s), milliseconds (ms) or
3324microseconds (us) can be specified instead.
3325The other PIE parameters and options are as follows:
3326.Bl -tag -width indent
3327.It Cm alpha Ar n
3328.Ar n
3329is a floating point number between 0 and 7 which specifies the weight of queue
3330delay deviations that is used in drop probability calculation.
33310.125 is the default.
3332.It Cm beta Ar n
3333.Ar n
3334is a floating point number between 0 and 7 which specifies is the weight of
3335queue delay trend that is used in drop probability calculation.
33361.25 is the default.
3337.It Cm max_burst Ar time
3338The maximum period of time that PIE does not drop/mark packets.
3339150ms is the
3340default and 10s is the maximum value.
3341.It Cm max_ecnth Ar n
3342Even when ECN is enabled, PIE drops packets instead of marking them when drop
3343probability becomes higher than ECN probability threshold
3344.Cm max_ecnth Ar n
3345, the default is 0.1 (i.e 10%) and 1 is the maximum value.
3346.It Cm ecn | noecn
3347enable or disable ECN marking for ECN-enabled TCP flows.
3348Disabled by default.
3349.It Cm capdrop | nocapdrop
3350enable or disable cap drop adjustment.
3351Cap drop adjustment is enabled by default.
3352.It Cm drand | nodrand
3353enable or disable drop probability de-randomisation.
3354De-randomisation eliminates
3355the problem of dropping packets too close or too far.
3356De-randomisation is enabled by default.
3357.It Cm onoff
3358enable turning PIE on and off depending on queue load.
3359If this option is enabled,
3360PIE turns on when over 1/3 of queue becomes full.
3361This option is disabled by
3362default.
3363.It Cm dre | ts
3364Calculate queue delay using departure rate estimation
3365.Cm dre
3366or timestamps
3367.Cm ts .
3368.Cm dre
3369is used by default.
3370.El
3371.Pp
3372Note that any token after
3373.Cm pie
3374is considered a parameter for PIE.
3375So ensure all pipe/queue
3376the configuration options are written before
3377.Cm pie
3378token.
3379.Xr sysctl 8
3380variables can be used to control the
3381.Cm pie
3382default parameters.
3383See the
3384.Sx SYSCTL VARIABLES
3385section for more details.
3386.El
3387.Pp
3388When used with IPv6 data,
3389.Nm dummynet
3390currently has several limitations.
3391Information necessary to route link-local packets to an
3392interface is not available after processing by
3393.Nm dummynet
3394so those packets are dropped in the output path.
3395Care should be taken to ensure that link-local packets are not passed to
3396.Nm dummynet .
3397.Sh CHECKLIST
3398Here are some important points to consider when designing your
3399rules:
3400.Bl -bullet
3401.It
3402Remember that you filter both packets going
3403.Cm in
3404and
3405.Cm out .
3406Most connections need packets going in both directions.
3407.It
3408Remember to test very carefully.
3409It is a good idea to be near the console when doing this.
3410If you cannot be near the console,
3411use an auto-recovery script such as the one in
3412.Pa /usr/share/examples/ipfw/change_rules.sh .
3413.It
3414Do not forget the loopback interface.
3415.El
3416.Sh FINE POINTS
3417.Bl -bullet
3418.It
3419There are circumstances where fragmented datagrams are unconditionally
3420dropped.
3421TCP packets are dropped if they do not contain at least 20 bytes of
3422TCP header, UDP packets are dropped if they do not contain a full 8
3423byte UDP header, and ICMP packets are dropped if they do not contain
34244 bytes of ICMP header, enough to specify the ICMP type, code, and
3425checksum.
3426These packets are simply logged as
3427.Dq pullup failed
3428since there may not be enough good data in the packet to produce a
3429meaningful log entry.
3430.It
3431Another type of packet is unconditionally dropped, a TCP packet with a
3432fragment offset of one.
3433This is a valid packet, but it only has one use, to try
3434to circumvent firewalls.
3435When logging is enabled, these packets are
3436reported as being dropped by rule -1.
3437.It
3438If you are logged in over a network, loading the
3439.Xr kld 4
3440version of
3441.Nm
3442is probably not as straightforward as you would think.
3443The following command line is recommended:
3444.Bd -literal -offset indent
3445kldload ipfw && \e
3446ipfw add 32000 allow ip from any to any
3447.Ed
3448.Pp
3449Along the same lines, doing an
3450.Bd -literal -offset indent
3451ipfw flush
3452.Ed
3453.Pp
3454in similar surroundings is also a bad idea.
3455.It
3456The
3457.Nm
3458filter list may not be modified if the system security level
3459is set to 3 or higher
3460(see
3461.Xr init 8
3462for information on system security levels).
3463.El
3464.Sh PACKET DIVERSION
3465A
3466.Xr divert 4
3467socket bound to the specified port will receive all packets
3468diverted to that port.
3469If no socket is bound to the destination port, or if the divert module is
3470not loaded, or if the kernel was not compiled with divert socket support,
3471the packets are dropped.
3472.Sh NETWORK ADDRESS TRANSLATION (NAT)
3473.Nm
3474support in-kernel NAT using the kernel version of
3475.Xr libalias 3 .
3476The kernel module
3477.Cm ipfw_nat
3478should be loaded or kernel should have
3479.Cm options IPFIREWALL_NAT
3480to be able use NAT.
3481.Pp
3482The nat configuration command is the following:
3483.Bd -ragged -offset indent
3484.Bk -words
3485.Cm nat
3486.Ar nat_number
3487.Cm config
3488.Ar nat-configuration
3489.Ek
3490.Ed
3491.Pp
3492The following parameters can be configured:
3493.Bl -tag -width indent
3494.It Cm ip Ar ip_address
3495Define an ip address to use for aliasing.
3496.It Cm if Ar nic
3497Use ip address of NIC for aliasing, dynamically changing
3498it if NIC's ip address changes.
3499.It Cm log
3500Enable logging on this nat instance.
3501.It Cm deny_in
3502Deny any incoming connection from outside world.
3503.It Cm same_ports
3504Try to leave the alias port numbers unchanged from
3505the actual local port numbers.
3506.It Cm unreg_only
3507Traffic on the local network not originating from a RFC 1918
3508unregistered address spaces will be ignored.
3509.It Cm unreg_cgn
3510Like unreg_only, but includes the RFC 6598 (Carrier Grade NAT)
3511address range.
3512.It Cm reset
3513Reset table of the packet aliasing engine on address change.
3514.It Cm reverse
3515Reverse the way libalias handles aliasing.
3516.It Cm proxy_only
3517Obey transparent proxy rules only, packet aliasing is not performed.
3518.It Cm skip_global
3519Skip instance in case of global state lookup (see below).
3520.It Cm port_range Ar lower-upper
3521Set the aliasing ports between the ranges given.
3522Ports must be in the range 1024-65535.
3523Upper port has to be greater than lower.
3524.It Cm udp_eim
3525When enabled, UDP packets use endpoint-independent mapping (EIM) from RFC 4787
3526("full cone" NAT of RFC 3489).
3527All packets from the same internal address:port are mapped to the same NAT
3528address:port, regardless of their destination address:port.
3529If filtering rules allow, and if
3530.Em deny_in
3531is unset, any other external address:port can
3532also send to the internal address:port through its mapped NAT address:port.
3533This is more compatible with applications, and can reduce the need for port
3534forwarding, but less scalable as each NAT address:port can only be
3535concurrently used by at most one internal address:port.
3536.Pp
3537When disabled, UDP packets use endpoint-dependent mapping (EDM) ("symmetric"
3538NAT).
3539Each connection from a particular internal address:port to different
3540external addresses:ports is mapped to a random and unpredictable NAT
3541address:port.
3542Two applications behind EDM NATs can only connect to each other
3543by port forwarding on the NAT, or tunnelling through an in-between server.
3544.El
3545.Pp
3546Some special values can be supplied instead of
3547.Va nat_number
3548in nat rule actions:
3549.Bl -tag -width indent
3550.It Cm global
3551Looks up translation state in all configured nat instances.
3552If an entry is found, packet is aliased according to that entry.
3553If no entry was found in any of the instances, packet is passed unchanged,
3554and no new entry will be created.
3555See section
3556.Sx MULTIPLE INSTANCES
3557in
3558.Xr natd 8
3559for more information.
3560.It Cm tablearg
3561Uses argument supplied in lookup table.
3562See
3563.Sx LOOKUP TABLES
3564section below for more information on lookup tables.
3565.El
3566.Pp
3567To let the packet continue after being (de)aliased, set the sysctl variable
3568.Va net.inet.ip.fw.one_pass
3569to 0.
3570For more information about aliasing modes, refer to
3571.Xr libalias 3 .
3572See Section
3573.Sx EXAMPLES
3574for some examples of nat usage.
3575.Pp
3576To delete specific nat configuration instance, use the following command:
3577.Bd -ragged -offset indent
3578.Bk -words
3579.Cm nat
3580.Ar nat_number
3581.Cm delete
3582.Ek
3583.Ed
3584.Ss REDIRECT AND LSNAT SUPPORT IN IPFW
3585Redirect and LSNAT support follow closely the syntax used in
3586.Xr natd 8 .
3587See Section
3588.Sx EXAMPLES
3589for some examples on how to do redirect and lsnat.
3590.Ss SCTP NAT SUPPORT
3591SCTP nat can be configured in a similar manner to TCP through the
3592.Nm
3593command line tool.
3594The main difference is that
3595.Nm sctp nat
3596does not do port translation.
3597Since the local and global side ports will be the same,
3598there is no need to specify both.
3599Ports are redirected as follows:
3600.Bd -ragged -offset indent
3601.Bk -words
3602.Cm nat
3603.Ar nat_number
3604.Cm config if
3605.Ar nic
3606.Cm redirect_port sctp
3607.Ar ip_address [,addr_list] {[port | port-port] [,ports]}
3608.Ek
3609.Ed
3610.Pp
3611Most
3612.Nm sctp nat
3613configuration can be done in real-time through the
3614.Xr sysctl 8
3615interface.
3616All may be changed dynamically, though the hash_table size will only
3617change for new
3618.Nm nat
3619instances.
3620See
3621.Sx SYSCTL VARIABLES
3622for more info.
3623.Sh IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
3624.Ss Stateful translation
3625.Nm
3626supports in-kernel IPv6/IPv4 network address and protocol translation.
3627Stateful NAT64 translation allows IPv6-only clients to contact IPv4 servers
3628using unicast TCP, UDP or ICMP protocols.
3629One or more IPv4 addresses assigned to a stateful NAT64 translator are shared
3630among several IPv6-only clients.
3631When stateful NAT64 is used in conjunction with DNS64, no changes are usually
3632required in the IPv6 client or the IPv4 server.
3633The kernel module
3634.Cm ipfw_nat64
3635should be loaded or kernel should have
3636.Cm options IPFIREWALL_NAT64
3637to be able use stateful NAT64 translator.
3638.Pp
3639Stateful NAT64 uses a bunch of memory for several types of objects.
3640When IPv6 client initiates connection, NAT64 translator creates a host entry
3641in the states table.
3642Each host entry uses preallocated IPv4 alias entry.
3643Each alias entry has a number of ports group entries allocated on demand.
3644Ports group entries contains connection state entries.
3645There are several options to control limits and lifetime for these objects.
3646.Pp
3647NAT64 translator follows RFC7915 when does ICMPv6/ICMP translation,
3648unsupported message types will be silently dropped.
3649IPv6 needs several ICMPv6 message types to be explicitly allowed for correct
3650operation.
3651Make sure that ND6 neighbor solicitation (ICMPv6 type 135) and neighbor
3652advertisement (ICMPv6 type 136) messages will not be handled by translation
3653rules.
3654.Pp
3655After translation NAT64 translator by default sends packets through
3656corresponding netisr queue.
3657Thus translator host should be configured as IPv4 and IPv6 router.
3658Also this means, that a packet is handled by firewall twice.
3659First time an original packet is handled and consumed by translator,
3660and then it is handled again as translated packet.
3661This behavior can be changed by sysctl variable
3662.Va net.inet.ip.fw.nat64_direct_output .
3663Also translated packet can be tagged using
3664.Cm tag
3665rule action, and then matched by
3666.Cm tagged
3667opcode to avoid loops and extra overhead.
3668.Pp
3669The stateful NAT64 configuration command is the following:
3670.Bd -ragged -offset indent
3671.Bk -words
3672.Cm nat64lsn
3673.Ar name
3674.Cm create
3675.Ar create-options
3676.Ek
3677.Ed
3678.Pp
3679The following parameters can be configured:
3680.Bl -tag -width indent
3681.It Cm prefix4 Ar ipv4_prefix/plen
3682The IPv4 prefix with mask defines the pool of IPv4 addresses used as
3683source address after translation.
3684Stateful NAT64 module translates IPv6 source address of client to one
3685IPv4 address from this pool.
3686Note that incoming IPv4 packets that don't have corresponding state entry
3687in the states table will be dropped by translator.
3688Make sure that translation rules handle packets, destined to configured prefix.
3689.It Cm prefix6 Ar ipv6_prefix/length
3690The IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator
3691to represent IPv4 addresses.
3692This IPv6 prefix should be configured in DNS64.
3693The translator implementation follows RFC6052, that restricts the length of
3694prefixes to one of following: 32, 40, 48, 56, 64, or 96.
3695The Well-Known IPv6 Prefix 64:ff9b:: must be 96 bits long.
3696The special
3697.Ar ::/length
3698prefix can be used to handle several IPv6 prefixes with one NAT64 instance.
3699The NAT64 instance will determine a destination IPv4 address from prefix
3700.Ar length .
3701.It Cm states_chunks Ar number
3702The number of states chunks in single ports group.
3703Each ports group by default can keep 64 state entries in single chunk.
3704The above value affects the maximum number of states that can be associated with
3705a single IPv4 alias address and port.
3706The value must be power of 2, and up to 128.
3707.It Cm host_del_age Ar seconds
3708The number of seconds until the host entry for a IPv6 client will be deleted
3709and all its resources will be released due to inactivity.
3710Default value is
3711.Ar 3600 .
3712.It Cm pg_del_age Ar seconds
3713The number of seconds until a ports group with unused state entries will
3714be released.
3715Default value is
3716.Ar 900 .
3717.It Cm tcp_syn_age Ar seconds
3718The number of seconds while a state entry for TCP connection with only SYN
3719sent will be kept.
3720If TCP connection establishing will not be finished,
3721state entry will be deleted.
3722Default value is
3723.Ar 10 .
3724.It Cm tcp_est_age Ar seconds
3725The number of seconds while a state entry for established TCP connection
3726will be kept.
3727Default value is
3728.Ar 7200 .
3729.It Cm tcp_close_age Ar seconds
3730The number of seconds while a state entry for closed TCP connection
3731will be kept.
3732Keeping state entries for closed connections is needed, because IPv4 servers
3733typically keep closed connections in a TIME_WAIT state for a several minutes.
3734Since translator's IPv4 addresses are shared among all IPv6 clients,
3735new connections from the same addresses and ports may be rejected by server,
3736because these connections are still in a TIME_WAIT state.
3737Keeping them in translator's state table protects from such rejects.
3738Default value is
3739.Ar 180 .
3740.It Cm udp_age Ar seconds
3741The number of seconds while translator keeps state entry in a waiting for
3742reply to the sent UDP datagram.
3743Default value is
3744.Ar 120 .
3745.It Cm icmp_age Ar seconds
3746The number of seconds while translator keeps state entry in a waiting for
3747reply to the sent ICMP message.
3748Default value is
3749.Ar 60 .
3750.It Cm log
3751Turn on logging of all handled packets via BPF tap named
3752.Ar ipfwlog0 .
3753Note that it has different purpose than per-rule
3754.Xr bpf 4
3755taps.
3756Translators sends to BPF an additional information with each packet.
3757With
3758.Cm tcpdump
3759you are able to see each handled packet before and after translation.
3760.It Cm -log
3761Turn off logging of all handled packets via BPF.
3762.It Cm allow_private
3763Turn on processing private IPv4 addresses.
3764By default IPv6 packets with destinations mapped to private address ranges
3765defined by RFC1918 are not processed.
3766.It Cm -allow_private
3767Turn off private address handling in
3768.Nm nat64
3769instance.
3770.El
3771.Pp
3772To inspect a states table of stateful NAT64 the following command can be used:
3773.Bd -ragged -offset indent
3774.Bk -words
3775.Cm nat64lsn
3776.Ar name
3777.Cm show Cm states
3778.Ek
3779.Ed
3780.Pp
3781Stateless NAT64 translator doesn't use a states table for translation
3782and converts IPv4 addresses to IPv6 and vice versa solely based on the
3783mappings taken from configured lookup tables.
3784Since a states table doesn't used by stateless translator,
3785it can be configured to pass IPv4 clients to IPv6-only servers.
3786.Pp
3787The stateless NAT64 configuration command is the following:
3788.Bd -ragged -offset indent
3789.Bk -words
3790.Cm nat64stl
3791.Ar name
3792.Cm create
3793.Ar create-options
3794.Ek
3795.Ed
3796.Pp
3797The following parameters can be configured:
3798.Bl -tag -width indent
3799.It Cm prefix6 Ar ipv6_prefix/length
3800The IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator
3801to represent IPv4 addresses.
3802This IPv6 prefix should be configured in DNS64.
3803.It Cm table4 Ar table46
3804The lookup table
3805.Ar table46
3806contains mapping how IPv4 addresses should be translated to IPv6 addresses.
3807.It Cm table6 Ar table64
3808The lookup table
3809.Ar table64
3810contains mapping how IPv6 addresses should be translated to IPv4 addresses.
3811.It Cm log
3812Turn on logging of all handled packets via BPF through
3813.Ar ipfwlog0
3814tap.
3815.It Cm -log
3816Turn off logging of all handled packets via BPF.
3817.It Cm allow_private
3818Turn on processing private IPv4 addresses.
3819By default IPv6 packets with destinations mapped to private address ranges
3820defined by RFC1918 are not processed.
3821.It Cm -allow_private
3822Turn off private address handling in
3823.Nm nat64
3824instance.
3825.El
3826.Pp
3827Note that the behavior of stateless translator with respect to not matched
3828packets differs from stateful translator.
3829If corresponding addresses was not found in the lookup tables, the packet
3830will not be dropped and the search continues.
3831.Ss XLAT464 CLAT translation
3832XLAT464 CLAT NAT64 translator implements client-side stateless translation as
3833defined in RFC6877 and is very similar to statless NAT64 translator
3834explained above.
3835Instead of lookup tables it uses one-to-one mapping between IPv4 and IPv6
3836addresses using configured prefixes.
3837This mode can be used as a replacement of DNS64 service for applications
3838that are not using it (e.g. VoIP) allowing them to access IPv4-only Internet
3839over IPv6-only networks with help of remote NAT64 translator.
3840.Pp
3841The CLAT NAT64 configuration command is the following:
3842.Bd -ragged -offset indent
3843.Bk -words
3844.Cm nat64clat
3845.Ar name
3846.Cm create
3847.Ar create-options
3848.Ek
3849.Ed
3850.Pp
3851The following parameters can be configured:
3852.Bl -tag -width indent
3853.It Cm clat_prefix Ar ipv6_prefix/length
3854The IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator
3855to represent source IPv4 addresses.
3856.It Cm plat_prefix Ar ipv6_prefix/length
3857The IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator
3858to represent destination IPv4 addresses.
3859This IPv6 prefix should be configured on a remote NAT64 translator.
3860.It Cm log
3861Turn on logging of all handled packets via BPF through
3862.Ar ipfwlog0
3863tap.
3864.It Cm -log
3865Turn off logging of all handled packets via BPF.
3866.It Cm allow_private
3867Turn on processing private IPv4 addresses.
3868By default
3869.Nm nat64clat
3870instance will not process IPv4 packets with destination address from private
3871ranges as defined in RFC1918.
3872.It Cm -allow_private
3873Turn off private address handling in
3874.Nm nat64clat
3875instance.
3876.El
3877.Pp
3878Note that the behavior of CLAT translator with respect to not matched
3879packets differs from stateful translator.
3880If corresponding addresses were not matched against prefixes configured,
3881the packet will not be dropped and the search continues.
3882.Sh IPv6-to-IPv6 NETWORK PREFIX TRANSLATION (NPTv6)
3883.Nm
3884supports in-kernel IPv6-to-IPv6 network prefix translation as described
3885in RFC6296.
3886The kernel module
3887.Cm ipfw_nptv6
3888should be loaded or kernel should has
3889.Cm options IPFIREWALL_NPTV6
3890to be able use NPTv6 translator.
3891.Pp
3892The NPTv6 configuration command is the following:
3893.Bd -ragged -offset indent
3894.Bk -words
3895.Cm nptv6
3896.Ar name
3897.Cm create
3898.Ar create-options
3899.Ek
3900.Ed
3901.Pp
3902The following parameters can be configured:
3903.Bl -tag -width indent
3904.It Cm int_prefix Ar ipv6_prefix
3905IPv6 prefix used in internal network.
3906NPTv6 module translates source address when it matches this prefix.
3907.It Cm ext_prefix Ar ipv6_prefix
3908IPv6 prefix used in external network.
3909NPTv6 module translates destination address when it matches this prefix.
3910.It Cm ext_if Ar nic
3911The NPTv6 module will use first global IPv6 address from interface
3912.Ar nic
3913as external prefix.
3914It can be useful when IPv6 prefix of external network is dynamically obtained.
3915.Cm ext_prefix
3916and
3917.Cm ext_if
3918options are mutually exclusive.
3919.It Cm prefixlen Ar length
3920The length of specified IPv6 prefixes.
3921It must be in range from 8 to 64.
3922.El
3923.Pp
3924Note that the prefix translation rules are silently ignored when IPv6 packet
3925forwarding is disabled.
3926To enable the packet forwarding, set the sysctl variable
3927.Va net.inet6.ip6.forwarding
3928to 1.
3929.Pp
3930To let the packet continue after being translated, set the sysctl variable
3931.Va net.inet.ip.fw.one_pass
3932to 0.
3933.Sh LOADER TUNABLES
3934Tunables can be set in
3935.Xr loader 8
3936prompt,
3937.Xr loader.conf 5
3938or
3939.Xr kenv 1
3940before ipfw module gets loaded.
3941.Bl -tag -width indent
3942.It Va net.inet.ip.fw.enable : No 1
3943Enables the firewall.
3944Setting this variable to 0 lets you run your machine without
3945firewall even if compiled in.
3946.It Va net.inet6.ip6.fw.enable : No 1
3947provides the same functionality as above for the IPv6 case.
3948.It Va net.link.ether.ipfw : No 0
3949Controls whether layer2 packets are passed to
3950.Nm .
3951Default is no.
3952.It Va net.inet.ip.fw.default_to_accept : No 0
3953Defines ipfw last rule behavior.
3954This value overrides
3955.Cd "options IPFW_DEFAULT_TO_(ACCEPT|DENY)"
3956from kernel configuration file.
3957.It Va net.inet.ip.fw.tables_max : No 128
3958Defines number of tables available in ipfw.
3959Number cannot exceed 65534.
3960.El
3961.Sh SYSCTL VARIABLES
3962A set of
3963.Xr sysctl 8
3964variables controls the behaviour of the firewall and
3965associated modules
3966.Pq Nm dummynet , bridge , sctp nat .
3967These are shown below together with their default value
3968(but always check with the
3969.Xr sysctl 8
3970command what value is actually in use) and meaning:
3971.Bl -tag -width indent
3972.It Va net.inet.ip.alias.sctp.accept_global_ootb_addip : No 0
3973Defines how the
3974.Nm nat
3975responds to receipt of global OOTB ASCONF-AddIP:
3976.Bl -tag -width indent
3977.It Cm 0
3978No response (unless a partially matching association exists -
3979ports and vtags match but global address does not)
3980.It Cm 1
3981.Nm nat
3982will accept and process all OOTB global AddIP messages.
3983.El
3984.Pp
3985Option 1 should never be selected as this forms a security risk.
3986An attacker can
3987establish multiple fake associations by sending AddIP messages.
3988.It Va net.inet.ip.alias.sctp.chunk_proc_limit : No 5
3989Defines the maximum number of chunks in an SCTP packet that will be
3990parsed for a
3991packet that matches an existing association.
3992This value is enforced to be greater or equal than
3993.Cm net.inet.ip.alias.sctp.initialising_chunk_proc_limit .
3994A high value is
3995a DoS risk yet setting too low a value may result in
3996important control chunks in
3997the packet not being located and parsed.
3998.It Va net.inet.ip.alias.sctp.error_on_ootb : No 1
3999Defines when the
4000.Nm nat
4001responds to any Out-of-the-Blue (OOTB) packets with ErrorM packets.
4002An OOTB packet is a packet that arrives with no existing association
4003registered in the
4004.Nm nat
4005and is not an INIT or ASCONF-AddIP packet:
4006.Bl -tag -width indent
4007.It Cm 0
4008ErrorM is never sent in response to OOTB packets.
4009.It Cm 1
4010ErrorM is only sent to OOTB packets received on the local side.
4011.It Cm 2
4012ErrorM is sent to the local side and on the global side ONLY if there is a
4013partial match (ports and vtags match but the source global IP does not).
4014This value is only useful if the
4015.Nm nat
4016is tracking global IP addresses.
4017.It Cm 3
4018ErrorM is sent in response to all OOTB packets on both
4019the local and global side
4020(DoS risk).
4021.El
4022.Pp
4023At the moment the default is 0, since the ErrorM packet is not yet
4024supported by most SCTP stacks.
4025When it is supported, and if not tracking
4026global addresses, we recommend setting this value to 1 to allow
4027multi-homed local hosts to function with the
4028.Nm nat .
4029To track global addresses, we recommend setting this value to 2 to
4030allow global hosts to be informed when they need to (re)send an
4031ASCONF-AddIP.
4032Value 3 should never be chosen (except for debugging) as the
4033.Nm nat
4034will respond to all OOTB global packets (a DoS risk).
4035.It Va net.inet.ip.alias.sctp.hashtable_size : No 2003
4036Size of hash tables used for
4037.Nm nat
4038lookups (100 < prime_number > 1000001).
4039This value sets the
4040.Nm hash table
4041size for any future created
4042.Nm nat
4043instance and therefore must be set prior to creating a
4044.Nm nat
4045instance.
4046The table sizes may be changed to suit specific needs.
4047If there will be few
4048concurrent associations, and memory is scarce, you may make these smaller.
4049If there will be many thousands (or millions) of concurrent associations, you
4050should make these larger.
4051A prime number is best for the table size.
4052The sysctl
4053update function will adjust your input value to the next highest prime number.
4054.It Va net.inet.ip.alias.sctp.holddown_time : No 0
4055Hold association in table for this many seconds after receiving a
4056SHUTDOWN-COMPLETE.
4057This allows endpoints to correct shutdown gracefully if a
4058shutdown_complete is lost and retransmissions are required.
4059.It Va net.inet.ip.alias.sctp.init_timer : No 15
4060Timeout value while waiting for (INIT-ACK|AddIP-ACK).
4061This value cannot be 0.
4062.It Va net.inet.ip.alias.sctp.initialising_chunk_proc_limit : No 2
4063Defines the maximum number of chunks in an SCTP packet that will be parsed when
4064no existing association exists that matches that packet.
4065Ideally this packet
4066will only be an INIT or ASCONF-AddIP packet.
4067A higher value may become a DoS
4068risk as malformed packets can consume processing resources.
4069.It Va net.inet.ip.alias.sctp.param_proc_limit : No 25
4070Defines the maximum number of parameters within a chunk that will be
4071parsed in a
4072packet.
4073As for other similar sysctl variables, larger values pose a DoS risk.
4074.It Va net.inet.ip.alias.sctp.log_level : No 0
4075Level of detail in the system log messages (0 \- minimal, 1 \- event,
40762 \- info, 3 \- detail, 4 \- debug, 5 \- max debug).
4077May be a good
4078option in high loss environments.
4079.It Va net.inet.ip.alias.sctp.shutdown_time : No 15
4080Timeout value while waiting for SHUTDOWN-COMPLETE.
4081This value cannot be 0.
4082.It Va net.inet.ip.alias.sctp.track_global_addresses : No 0
4083Enables/disables global IP address tracking within the
4084.Nm nat
4085and places an
4086upper limit on the number of addresses tracked for each association:
4087.Bl -tag -width indent
4088.It Cm 0
4089Global tracking is disabled
4090.It Cm >1
4091Enables tracking, the maximum number of addresses tracked for each
4092association is limited to this value
4093.El
4094.Pp
4095This variable is fully dynamic, the new value will be adopted for all newly
4096arriving associations, existing associations are treated
4097as they were previously.
4098Global tracking will decrease the number of collisions within the
4099.Nm nat
4100at a cost
4101of increased processing load, memory usage, complexity, and possible
4102.Nm nat
4103state
4104problems in complex networks with multiple
4105.Nm nats .
4106We recommend not tracking
4107global IP addresses, this will still result in a fully functional
4108.Nm nat .
4109.It Va net.inet.ip.alias.sctp.up_timer : No 300
4110Timeout value to keep an association up with no traffic.
4111This value cannot be 0.
4112.It Va net.inet.ip.dummynet.codel.interval : No 100000
4113Default
4114.Cm codel
4115AQM interval in microseconds.
4116The value must be in the range 1..5000000.
4117.It Va net.inet.ip.dummynet.codel.target : No 5000
4118Default
4119.Cm codel
4120AQM target delay time in microseconds (the minimum acceptable persistent queue
4121delay).
4122The value must be in the range 1..5000000.
4123.It Va net.inet.ip.dummynet.expire : No 1
4124Lazily delete dynamic pipes/queue once they have no pending traffic.
4125You can disable this by setting the variable to 0, in which case
4126the pipes/queues will only be deleted when the threshold is reached.
4127.It Va net.inet.ip.dummynet.fqcodel.flows : No 1024
4128Defines the default total number of flow queues (sub-queues) that
4129.Cm fq_codel
4130creates and manages.
4131The value must be in the range 1..65536.
4132.It Va net.inet.ip.dummynet.fqcodel.interval : No 100000
4133Default
4134.Cm fq_codel
4135scheduler/AQM interval in microseconds.
4136The value must be in the range 1..5000000.
4137.It Va net.inet.ip.dummynet.fqcodel.limit : No 10240
4138The default hard size limit (in unit of packet) of all queues managed by an
4139instance of the
4140.Cm fq_codel
4141scheduler.
4142The value must be in the range 1..20480.
4143.It Va net.inet.ip.dummynet.fqcodel.quantum : No 1514
4144The default quantum (credit) of the
4145.Cm fq_codel
4146in unit of byte.
4147The value must be in the range 1..9000.
4148.It Va net.inet.ip.dummynet.fqcodel.target : No 5000
4149Default
4150.Cm fq_codel
4151scheduler/AQM target delay time in microseconds (the minimum acceptable
4152persistent queue delay).
4153The value must be in the range 1..5000000.
4154.It Va net.inet.ip.dummynet.fqpie.alpha : No 125
4155The default
4156.Ar alpha
4157parameter (scaled by 1000) for
4158.Cm fq_pie
4159scheduler/AQM.
4160The value must be in the range 1..7000.
4161.It Va net.inet.ip.dummynet.fqpie.beta : No 1250
4162The default
4163.Ar beta
4164parameter (scaled by 1000) for
4165.Cm fq_pie
4166scheduler/AQM.
4167The value must be in the range 1..7000.
4168.It Va net.inet.ip.dummynet.fqpie.flows : No 1024
4169Defines the default total number of flow queues (sub-queues) that
4170.Cm fq_pie
4171creates and manages.
4172The value must be in the range 1..65536.
4173.It Va net.inet.ip.dummynet.fqpie.limit : No 10240
4174The default hard size limit (in unit of packet) of all queues managed by an
4175instance of the
4176.Cm fq_pie
4177scheduler.
4178The value must be in the range 1..20480.
4179.It Va net.inet.ip.dummynet.fqpie.max_burst : No 150000
4180The default maximum period of microseconds that
4181.Cm fq_pie
4182scheduler/AQM does not drop/mark packets.
4183The value must be in the range 1..10000000.
4184.It Va net.inet.ip.dummynet.fqpie.max_ecnth : No 99
4185The default maximum ECN probability threshold (scaled by 1000) for
4186.Cm fq_pie
4187scheduler/AQM.
4188The value must be in the range 1..7000.
4189.It Va net.inet.ip.dummynet.fqpie.quantum : No 1514
4190The default quantum (credit) of the
4191.Cm fq_pie
4192in unit of byte.
4193The value must be in the range 1..9000.
4194.It Va net.inet.ip.dummynet.fqpie.target : No 15000
4195The default
4196.Cm target
4197delay of the
4198.Cm fq_pie
4199in unit of microsecond.
4200The value must be in the range 1..5000000.
4201.It Va net.inet.ip.dummynet.fqpie.tupdate : No 15000
4202The default
4203.Cm tupdate
4204of the
4205.Cm fq_pie
4206in unit of microsecond.
4207The value must be in the range 1..5000000.
4208.It Va net.inet.ip.dummynet.hash_size : No 64
4209Default size of the hash table used for dynamic pipes/queues.
4210This value is used when no
4211.Cm buckets
4212option is specified when configuring a pipe/queue.
4213.It Va net.inet.ip.dummynet.io_fast : No 0
4214If set to a non-zero value,
4215the
4216.Dq fast
4217mode of
4218.Nm dummynet
4219operation (see above) is enabled.
4220.It Va net.inet.ip.dummynet.io_pkt
4221Number of packets passed to
4222.Nm dummynet .
4223.It Va net.inet.ip.dummynet.io_pkt_drop
4224Number of packets dropped by
4225.Nm dummynet .
4226.It Va net.inet.ip.dummynet.io_pkt_fast
4227Number of packets bypassed by the
4228.Nm dummynet
4229scheduler.
4230.It Va net.inet.ip.dummynet.max_chain_len : No 16
4231Target value for the maximum number of pipes/queues in a hash bucket.
4232The product
4233.Cm max_chain_len*hash_size
4234is used to determine the threshold over which empty pipes/queues
4235will be expired even when
4236.Cm net.inet.ip.dummynet.expire=0 .
4237.It Va net.inet.ip.dummynet.red_lookup_depth : No 256
4238.It Va net.inet.ip.dummynet.red_avg_pkt_size : No 512
4239.It Va net.inet.ip.dummynet.red_max_pkt_size : No 1500
4240Parameters used in the computations of the drop probability
4241for the RED algorithm.
4242.It Va net.inet.ip.dummynet.pie.alpha : No 125
4243The default
4244.Ar alpha
4245parameter (scaled by 1000) for
4246.Cm pie
4247AQM.
4248The value must be in the range 1..7000.
4249.It Va net.inet.ip.dummynet.pie.beta : No 1250
4250The default
4251.Ar beta
4252parameter (scaled by 1000) for
4253.Cm pie
4254AQM.
4255The value must be in the range 1..7000.
4256.It Va net.inet.ip.dummynet.pie.max_burst : No 150000
4257The default maximum period of microseconds that
4258.Cm pie
4259AQM does not drop/mark packets.
4260The value must be in the range 1..10000000.
4261.It Va net.inet.ip.dummynet.pie.max_ecnth : No 99
4262The default maximum ECN probability threshold (scaled by 1000) for
4263.Cm pie
4264AQM.
4265The value must be in the range 1..7000.
4266.It Va net.inet.ip.dummynet.pie.target : No 15000
4267The default
4268.Cm target
4269delay of
4270.Cm pie
4271AQM in unit of microsecond.
4272The value must be in the range 1..5000000.
4273.It Va net.inet.ip.dummynet.pie.tupdate : No 15000
4274The default
4275.Cm tupdate
4276of
4277.Cm pie
4278AQM in unit of microsecond.
4279The value must be in the range 1..5000000.
4280.It Va net.inet.ip.dummynet.pipe_byte_limit : No 1048576
4281.It Va net.inet.ip.dummynet.pipe_slot_limit : No 100
4282The maximum queue size that can be specified in bytes or packets.
4283These limits prevent accidental exhaustion of resources such as mbufs.
4284If you raise these limits,
4285you should make sure the system is configured so that sufficient resources
4286are available.
4287.It Va net.inet.ip.fw.autoinc_step : No 100
4288Delta between rule numbers when auto-generating them.
4289The value must be in the range 1..1000.
4290.It Va net.inet.ip.fw.curr_dyn_buckets : Va net.inet.ip.fw.dyn_buckets
4291The current number of buckets in the hash table for dynamic rules
4292(readonly).
4293.It Va net.inet.ip.fw.debug : No 1
4294Controls debugging messages produced by
4295.Nm .
4296.It Va net.inet.ip.fw.default_rule : No 65535
4297The default rule number (read-only).
4298By the design of
4299.Nm , the default rule is the last one, so its number
4300can also serve as the highest number allowed for a rule.
4301.It Va net.inet.ip.fw.dyn_buckets : No 256
4302The number of buckets in the hash table for dynamic rules.
4303Must be a power of 2, up to 65536.
4304It only takes effect when all dynamic rules have expired, so you
4305are advised to use a
4306.Cm flush
4307command to make sure that the hash table is resized.
4308.It Va net.inet.ip.fw.dyn_count : No 3
4309Current number of dynamic rules
4310(read-only).
4311.It Va net.inet.ip.fw.dyn_keepalive : No 1
4312Enables generation of keepalive packets for
4313.Cm keep-state
4314rules on TCP sessions.
4315A keepalive is generated to both
4316sides of the connection every 5 seconds for the last 20
4317seconds of the lifetime of the rule.
4318.It Va net.inet.ip.fw.dyn_max : No 8192
4319Maximum number of dynamic rules.
4320When you hit this limit, no more dynamic rules can be
4321installed until old ones expire.
4322.It Va net.inet.ip.fw.dyn_ack_lifetime : No 300
4323.It Va net.inet.ip.fw.dyn_syn_lifetime : No 20
4324.It Va net.inet.ip.fw.dyn_fin_lifetime : No 1
4325.It Va net.inet.ip.fw.dyn_rst_lifetime : No 1
4326.It Va net.inet.ip.fw.dyn_udp_lifetime : No 5
4327.It Va net.inet.ip.fw.dyn_short_lifetime : No 30
4328These variables control the lifetime, in seconds, of dynamic
4329rules.
4330Upon the initial SYN exchange the lifetime is kept short,
4331then increased after both SYN have been seen, then decreased
4332again during the final FIN exchange or when a RST is received.
4333Both
4334.Em dyn_fin_lifetime
4335and
4336.Em dyn_rst_lifetime
4337must be strictly lower than 5 seconds, the period of
4338repetition of keepalives.
4339The firewall enforces that.
4340.It Va net.inet.ip.fw.dyn_keep_states : No 0
4341Keep dynamic states on rule/set deletion.
4342States are relinked to default rule (65535).
4343This can be handly for ruleset reload.
4344Turned off by default.
4345.It Va net.inet.ip.fw.one_pass : No 1
4346When set, the packet exiting from the
4347.Nm dummynet
4348pipe or from
4349.Xr ng_ipfw 4
4350node is not passed though the firewall again.
4351Otherwise, after an action, the packet is
4352reinjected into the firewall at the next rule.
4353.It Va net.inet.ip.fw.tables_max : No 128
4354Maximum number of tables.
4355.It Va net.inet.ip.fw.verbose : No 1
4356Enables verbose messages.
4357.It Va net.inet.ip.fw.verbose_limit : No 0
4358Limits the number of messages produced by a verbose firewall.
4359.It Va net.inet6.ip6.fw.deny_unknown_exthdrs : No 1
4360If enabled packets with unknown IPv6 Extension Headers will be denied.
4361.It Va net.link.bridge.ipfw : No 0
4362Controls whether bridged packets are passed to
4363.Nm .
4364Default is no.
4365.It Va net.inet.ip.fw.nat64_debug : No 0
4366Controls debugging messages produced by
4367.Nm ipfw_nat64
4368module.
4369.It Va net.inet.ip.fw.nat64_direct_output : No 0
4370Controls the output method used by
4371.Nm ipfw_nat64
4372module:
4373.Bl -tag -width indent
4374.It Cm 0
4375A packet is handled by
4376.Nm ipfw
4377twice.
4378First time an original packet is handled by
4379.Nm ipfw
4380and consumed by
4381.Nm ipfw_nat64
4382translator.
4383Then translated packet is queued via netisr to input processing again.
4384.It Cm 1
4385A packet is handled by
4386.Nm ipfw
4387only once, and after translation it will be pushed directly to outgoing
4388interface.
4389.El
4390.El
4391.Sh INTERNAL DIAGNOSTICS
4392There are some commands that may be useful to understand current state
4393of certain subsystems inside kernel module.
4394These commands provide debugging output which may change without notice.
4395.Pp
4396Currently the following commands are available as
4397.Cm internal
4398sub-options:
4399.Bl -tag -width indent
4400.It Cm iflist
4401Lists all interface which are currently tracked by
4402.Nm
4403with their in-kernel status.
4404.It Cm monitor Op Ar filter-comment
4405Capture messages from
4406.Xr route 4
4407socket, that were logged using rules with
4408.Cm log Cm logdst Ar rtsock
4409opcode.
4410Optional
4411.Ar filter-comment
4412can be specified to show only those messages, that were logged
4413by rules with specific rule comment.
4414.It Cm talist
4415List all table lookup algorithms currently available.
4416.El
4417.Sh EXAMPLES
4418There are far too many possible uses of
4419.Nm
4420so this Section will only give a small set of examples.
4421.Ss BASIC PACKET FILTERING
4422This command adds an entry which denies all tcp packets from
4423.Em cracker.evil.org
4424to the telnet port of
4425.Em wolf.tambov.su
4426from being forwarded by the host:
4427.Pp
4428.Dl "ipfw add deny tcp from cracker.evil.org to wolf.tambov.su telnet"
4429.Pp
4430This one disallows any connection from the entire cracker's
4431network to my host:
4432.Pp
4433.Dl "ipfw add deny ip from 123.45.67.0/24 to my.host.org"
4434.Pp
4435A first and efficient way to limit access (not using dynamic rules)
4436is the use of the following rules:
4437.Pp
4438.Dl "ipfw add allow tcp from any to any established"
4439.Dl "ipfw add allow tcp from net1 portlist1 to net2 portlist2 setup"
4440.Dl "ipfw add allow tcp from net3 portlist3 to net3 portlist3 setup"
4441.Dl "..."
4442.Dl "ipfw add deny tcp from any to any"
4443.Pp
4444The first rule will be a quick match for normal TCP packets,
4445but it will not match the initial SYN packet, which will be
4446matched by the
4447.Cm setup
4448rules only for selected source/destination pairs.
4449All other SYN packets will be rejected by the final
4450.Cm deny
4451rule.
4452.Pp
4453If you administer one or more subnets, you can take advantage
4454of the address sets and or-blocks and write extremely
4455compact rulesets which selectively enable services to blocks
4456of clients, as below:
4457.Pp
4458.Dl "goodguys=\*q{ 10.1.2.0/24{20,35,66,18} or 10.2.3.0/28{6,3,11} }\*q"
4459.Dl "badguys=\*q10.1.2.0/24{8,38,60}\*q"
4460.Dl ""
4461.Dl "ipfw add allow ip from ${goodguys} to any"
4462.Dl "ipfw add deny ip from ${badguys} to any"
4463.Dl "... normal policies ..."
4464.Pp
4465Allow any transit packets coming from single vlan 10 and
4466going out to vlans 100-1000:
4467.Pp
4468.Dl "ipfw add 10 allow out recv vlan10 \e"
4469.Dl "{ xmit vlan1000 or xmit \*qvlan[1-9]??\*q }"
4470.Pp
4471The
4472.Cm verrevpath
4473option could be used to do automated anti-spoofing by adding the
4474following to the top of a ruleset:
4475.Pp
4476.Dl "ipfw add deny ip from any to any not verrevpath in"
4477.Pp
4478This rule drops all incoming packets that appear to be coming to the
4479system on the wrong interface.
4480For example, a packet with a source
4481address belonging to a host on a protected internal network would be
4482dropped if it tried to enter the system from an external interface.
4483.Pp
4484The
4485.Cm antispoof
4486option could be used to do similar but more restricted anti-spoofing
4487by adding the following to the top of a ruleset:
4488.Pp
4489.Dl "ipfw add deny ip from any to any not antispoof in"
4490.Pp
4491This rule drops all incoming packets that appear to be coming from another
4492directly connected system but on the wrong interface.
4493For example, a packet with a source address of
4494.Li 192.168.0.0/24 ,
4495configured on
4496.Li fxp0 ,
4497but coming in on
4498.Li fxp1
4499would be dropped.
4500.Pp
4501The
4502.Cm setdscp
4503option could be used to (re)mark user traffic,
4504by adding the following to the appropriate place in ruleset:
4505.Pp
4506.Dl "ipfw add setdscp be ip from any to any dscp af11,af21"
4507.Ss SELECTIVE MIRRORING
4508If your network has network traffic analyzer
4509connected to your host directly via dedicated interface
4510or remotely via RSPAN vlan, you can selectively mirror
4511some Ethernet layer2 frames to the analyzer.
4512.Pp
4513First, make sure your firewall is already configured and runs.
4514Then, enable layer2 processing if not already enabled:
4515.Pp
4516.Dl "sysctl net.link.ether.ipfw=1"
4517.Pp
4518Next, load needed additional kernel modules:
4519.Pp
4520.Dl "kldload ng_ether ng_ipfw"
4521.Pp
4522Optionally, make system load these modules automatically
4523at startup:
4524.Pp
4525.Dl sysrc kld_list+="ng_ether ng_ipfw"
4526.Pp
4527Next, configure
4528.Xr ng_ipfw 4
4529kernel module to transmit mirrored copies of layer2 frames
4530out via vlan900 interface:
4531.Pp
4532.Dl "ngctl connect ipfw: vlan900: 1 lower"
4533.Pp
4534Think of "1" here as of "mirroring instance index" and vlan900 is its
4535destination.
4536You can have arbitrary number of instances.
4537Refer to
4538.Xr ng_ipfw 4
4539for details.
4540.Pp
4541At last, actually start mirroring of selected frames using "instance 1".
4542For frames incoming from em0 interface:
4543.Pp
4544.Dl "ipfw add ngtee 1 ip from any to 192.168.0.1 layer2 in recv em0"
4545.Pp
4546For frames outgoing to em0 interface:
4547.Pp
4548.Dl "ipfw add ngtee 1 ip from any to 192.168.0.1 layer2 out xmit em0"
4549.Pp
4550For both incoming and outgoing frames while flowing through em0:
4551.Pp
4552.Dl "ipfw add ngtee 1 ip from any to 192.168.0.1 layer2 via em0"
4553.Pp
4554Make sure you do not perform mirroring for already duplicated frames
4555or kernel may hang as there is no safety net.
4556.Ss DYNAMIC RULES
4557In order to protect a site from flood attacks involving fake
4558TCP packets, it is safer to use dynamic rules:
4559.Pp
4560.Dl "ipfw add check-state"
4561.Dl "ipfw add deny tcp from any to any established"
4562.Dl "ipfw add allow tcp from my-net to any setup keep-state"
4563.Pp
4564This will let the firewall install dynamic rules only for
4565those connection which start with a regular SYN packet coming
4566from the inside of our network.
4567Dynamic rules are checked when encountering the first
4568occurrence of a
4569.Cm check-state ,
4570.Cm keep-state
4571or
4572.Cm limit
4573rule.
4574A
4575.Cm check-state
4576rule should usually be placed near the beginning of the
4577ruleset to minimize the amount of work scanning the ruleset.
4578Your mileage may vary.
4579.Pp
4580For more complex scenarios with dynamic rules
4581.Cm record-state
4582and
4583.Cm defer-action
4584can be used to precisely control creation and checking of dynamic rules.
4585Example of usage of these options are provided in
4586.Sx NETWORK ADDRESS TRANSLATION (NAT)\&
4587Section.
4588.Pp
4589To limit the number of connections a user can open
4590you can use the following type of rules:
4591.Pp
4592.Dl "ipfw add allow tcp from my-net/24 to any setup limit src-addr 10"
4593.Dl "ipfw add allow tcp from any to me setup limit src-addr 4"
4594.Pp
4595The former (assuming it runs on a gateway) will allow each host
4596on a /24 network to open at most 10 TCP connections.
4597The latter can be placed on a server to make sure that a single
4598client does not use more than 4 simultaneous connections.
4599.Pp
4600.Em BEWARE :
4601stateful rules can be subject to denial-of-service attacks
4602by a SYN-flood which opens a huge number of dynamic rules.
4603The effects of such attacks can be partially limited by
4604acting on a set of
4605.Xr sysctl 8
4606variables which control the operation of the firewall.
4607.Pp
4608Here is a good usage of the
4609.Cm list
4610command to see accounting records and timestamp information:
4611.Pp
4612.Dl ipfw -at list
4613.Pp
4614or in short form without timestamps:
4615.Pp
4616.Dl ipfw -a list
4617.Pp
4618which is equivalent to:
4619.Pp
4620.Dl ipfw show
4621.Pp
4622Next rule diverts all incoming packets from 192.168.2.0/24
4623to divert port 5000:
4624.Pp
4625.Dl ipfw divert 5000 ip from 192.168.2.0/24 to any in
4626.Ss TRAFFIC SHAPING
4627The following rules show some of the applications of
4628.Nm
4629and
4630.Nm dummynet
4631for simulations and the like.
4632.Pp
4633This rule drops random incoming packets with a probability
4634of 5%:
4635.Pp
4636.Dl "ipfw add prob 0.05 deny ip from any to any in"
4637.Pp
4638A similar effect can be achieved making use of
4639.Nm dummynet
4640pipes:
4641.Pp
4642.Dl "dnctl add pipe 10 ip from any to any"
4643.Dl "dnctl pipe 10 config plr 0.05"
4644.Pp
4645We can use pipes to artificially limit bandwidth, e.g.\& on a
4646machine acting as a router, if we want to limit traffic from
4647local clients on 192.168.2.0/24 we do:
4648.Pp
4649.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
4650.Dl "dnctl pipe 1 config bw 300Kbit/s queue 50KBytes"
4651.Pp
4652note that we use the
4653.Cm out
4654modifier so that the rule is not used twice.
4655Remember in fact that
4656.Nm
4657rules are checked both on incoming and outgoing packets.
4658.Pp
4659Should we want to simulate a bidirectional link with bandwidth
4660limitations, the correct way is the following:
4661.Pp
4662.Dl "ipfw add pipe 1 ip from any to any out"
4663.Dl "ipfw add pipe 2 ip from any to any in"
4664.Dl "dnctl pipe 1 config bw 64Kbit/s queue 10Kbytes"
4665.Dl "dnctl pipe 2 config bw 64Kbit/s queue 10Kbytes"
4666.Pp
4667The above can be very useful, e.g.\& if you want to see how
4668your fancy Web page will look for a residential user who
4669is connected only through a slow link.
4670You should not use only one pipe for both directions, unless
4671you want to simulate a half-duplex medium (e.g.\& AppleTalk,
4672Ethernet, IRDA).
4673It is not necessary that both pipes have the same configuration,
4674so we can also simulate asymmetric links.
4675.Pp
4676Should we want to verify network performance with the RED queue
4677management algorithm:
4678.Pp
4679.Dl "ipfw add pipe 1 ip from any to any"
4680.Dl "dnctl pipe 1 config bw 500Kbit/s queue 100 red 0.002/30/80/0.1"
4681.Pp
4682Another typical application of the traffic shaper is to
4683introduce some delay in the communication.
4684This can significantly affect applications which do a lot of Remote
4685Procedure Calls, and where the round-trip-time of the
4686connection often becomes a limiting factor much more than
4687bandwidth:
4688.Pp
4689.Dl "ipfw add pipe 1 ip from any to any out"
4690.Dl "ipfw add pipe 2 ip from any to any in"
4691.Dl "dnctl pipe 1 config delay 250ms bw 1Mbit/s"
4692.Dl "dnctl pipe 2 config delay 250ms bw 1Mbit/s"
4693.Pp
4694Per-flow queueing can be useful for a variety of purposes.
4695A very simple one is counting traffic:
4696.Pp
4697.Dl "ipfw add pipe 1 tcp from any to any"
4698.Dl "ipfw add pipe 1 udp from any to any"
4699.Dl "ipfw add pipe 1 ip from any to any"
4700.Dl "dnctl pipe 1 config mask all"
4701.Pp
4702The above set of rules will create queues (and collect
4703statistics) for all traffic.
4704Because the pipes have no limitations, the only effect is
4705collecting statistics.
4706Note that we need 3 rules, not just the last one, because
4707when
4708.Nm
4709tries to match IP packets it will not consider ports, so we
4710would not see connections on separate ports as different
4711ones.
4712.Pp
4713A more sophisticated example is limiting the outbound traffic
4714on a net with per-host limits, rather than per-network limits:
4715.Pp
4716.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
4717.Dl "ipfw add pipe 2 ip from any to 192.168.2.0/24 in"
4718.Dl "dnctl pipe 1 config mask src-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
4719.Dl "dnctl pipe 2 config mask dst-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
4720.Ss LOOKUP TABLES
4721In the following example, we need to create several traffic bandwidth
4722classes and we need different hosts/networks to fall into different classes.
4723We create one pipe for each class and configure them accordingly.
4724Then we create a single table and fill it with IP subnets and addresses.
4725For each subnet/host we set the argument equal to the number of the pipe
4726that it should use.
4727Then we classify traffic using a single rule:
4728.Pp
4729.Dl "dnctl pipe 1 config bw 1000Kbyte/s"
4730.Dl "dnctl pipe 4 config bw 4000Kbyte/s"
4731.Dl "..."
4732.Dl "ipfw table T1 create type addr"
4733.Dl "ipfw table T1 add 192.168.2.0/24 1"
4734.Dl "ipfw table T1 add 192.168.0.0/27 4"
4735.Dl "ipfw table T1 add 192.168.0.2 1"
4736.Dl "..."
4737.Dl "ipfw add pipe tablearg ip from 'table(T1)' to any"
4738.Pp
4739Using the
4740.Cm fwd
4741action, the table entries may include hostnames and IP addresses.
4742.Pp
4743.Dl "ipfw table T2 create type addr valtype ipv4"
4744.Dl "ipfw table T2 add 192.168.2.0/24 10.23.2.1"
4745.Dl "ipfw table T2 add 192.168.0.0/27 router1.dmz"
4746.Dl "..."
4747.Dl "ipfw add 100 fwd tablearg ip from any to 'table(T2)'"
4748.Pp
4749In the following example per-interface firewall is created:
4750.Pp
4751.Dl "ipfw table IN create type iface valtype skipto,fib"
4752.Dl "ipfw table IN add vlan20 12000,12"
4753.Dl "ipfw table IN add vlan30 13000,13"
4754.Dl "ipfw table OUT create type iface valtype skipto"
4755.Dl "ipfw table OUT add vlan20 22000"
4756.Dl "ipfw table OUT add vlan30 23000"
4757.Dl ".."
4758.Dl "ipfw add 100 setfib tablearg ip from any to any recv 'table(IN)' in"
4759.Dl "ipfw add 200 skipto tablearg ip from any to any recv 'table(IN)' in"
4760.Dl "ipfw add 300 skipto tablearg ip from any to any xmit 'table(OUT)' out"
4761.Pp
4762The following example illustrate usage of flow tables:
4763.Pp
4764.Dl "ipfw table fl create type flow:src-ip,proto,dst-ip,dst-port"
4765.Dl "ipfw table fl add 2001:db8:77::88,tcp,2001:db8:77::99,80 11"
4766.Dl "ipfw table fl add 10.0.0.1,udp,10.0.0.2,53 12"
4767.Dl ".."
4768.Dl "ipfw add 100 allow ip from any to any flow 'table(fl,11)' recv ix0"
4769.Pp
4770The following example illustrate masked table lookups to aid uniform client
4771distribution among multiple NAT instances:
4772.Bd -literal -offset indent
4773# Configure NAT instances
4774ipfw nat 10 config ip 192.0.2.0
4775ipfw nat 11 config ip 192.0.2.1
4776ipfw nat 12 config ip 192.0.2.2
4777ipfw nat 13 config ip 192.0.2.3
4778
4779ipfw table mynats create type addr valtype nat
4780# Map external NAT address to NAT instance
4781ipfw table mynats add 192.0.2.0 10
4782ipfw table mynats add 192.0.2.1 11
4783ipfw table mynats add 192.0.2.2 12
4784ipfw table mynats add 192.0.2.3 13
4785
4786# Map last 2 bits of client's IP address to NAT instance
4787ipfw table mynats add 0.0.0.0 10
4788ipfw table mynats add 0.0.0.1 11
4789ipfw table mynats add 0.0.0.2 12
4790ipfw table mynats add 0.0.0.3 13
4791
4792# In -> Out NAT, zero out all bits in a client's IP except
4793# 2 least significant prior to table lookup
4794ipfw add nat tablearg ip from 10.0.0.0/24 to any
4795			lookup src-ip4:0.0.0.3 mynats
4796# Out -> In NAT
4797ipfw add nat tablearg ip from any to 192.0.2.0/30
4798			lookup dst-ip mynats
4799.Ed
4800.Ss SETS OF RULES
4801To add a set of rules atomically, e.g.\& set 18:
4802.Pp
4803.Dl "ipfw set disable 18"
4804.Dl "ipfw add NN set 18 ...         # repeat as needed"
4805.Dl "ipfw set enable 18"
4806.Pp
4807To delete a set of rules atomically the command is simply:
4808.Pp
4809.Dl "ipfw delete set 18"
4810.Pp
4811To test a ruleset and disable it and regain control if something goes wrong:
4812.Pp
4813.Dl "ipfw set disable 18"
4814.Dl "ipfw add NN set 18 ...         # repeat as needed"
4815.Dl "ipfw set enable 18; echo done; sleep 30 && ipfw set disable 18"
4816.Pp
4817Here if everything goes well, you press control-C before the "sleep"
4818terminates, and your ruleset will be left active.
4819Otherwise, e.g.\& if
4820you cannot access your box, the ruleset will be disabled after
4821the sleep terminates thus restoring the previous situation.
4822.Pp
4823To show rules of the specific set:
4824.Pp
4825.Dl "ipfw set 18 show"
4826.Pp
4827To show rules of the disabled set:
4828.Pp
4829.Dl "ipfw -S set 18 show"
4830.Pp
4831To clear a specific rule counters of the specific set:
4832.Pp
4833.Dl "ipfw set 18 zero NN"
4834.Pp
4835To delete a specific rule of the specific set:
4836.Pp
4837.Dl "ipfw set 18 delete NN"
4838.Ss NAT, REDIRECT AND LSNAT
4839First redirect all the traffic to nat instance 123:
4840.Pp
4841.Dl "ipfw add nat 123 all from any to any"
4842.Pp
4843Then to configure nat instance 123 to alias all the outgoing traffic with ip
4844192.168.0.123, blocking all incoming connections, trying to keep
4845same ports on both sides, clearing aliasing table on address change
4846and keeping a log of traffic/link statistics:
4847.Pp
4848.Dl "ipfw nat 123 config ip 192.168.0.123 log deny_in reset same_ports"
4849.Pp
4850Or to change address of instance 123, aliasing table will be cleared (see
4851reset option):
4852.Pp
4853.Dl "ipfw nat 123 config ip 10.0.0.1"
4854.Pp
4855To see configuration of nat instance 123:
4856.Pp
4857.Dl "ipfw nat 123 show config"
4858.Pp
4859To show logs of all instances:
4860.Pp
4861.Dl "ipfw nat show log"
4862.Pp
4863To see configurations of all instances:
4864.Pp
4865.Dl "ipfw nat show config"
4866.Pp
4867Or a redirect rule with mixed modes could looks like:
4868.Bd -literal -offset 2n
4869ipfw nat 123 config redirect_addr 10.0.0.1 10.0.0.66
4870			 redirect_port tcp 192.168.0.1:80 500
4871			 redirect_proto udp 192.168.1.43 192.168.1.1
4872			 redirect_addr 192.168.0.10,192.168.0.11
4873			 	    10.0.0.100	# LSNAT
4874			 redirect_port tcp 192.168.0.1:80,192.168.0.10:22
4875			 	    500		# LSNAT
4876.Ed
4877.Pp
4878or it could be split in:
4879.Bd -literal -offset 2n
4880ipfw nat 1 config redirect_addr 10.0.0.1 10.0.0.66
4881ipfw nat 2 config redirect_port tcp 192.168.0.1:80 500
4882ipfw nat 3 config redirect_proto udp 192.168.1.43 192.168.1.1
4883ipfw nat 4 config redirect_addr 192.168.0.10,192.168.0.11,192.168.0.12
4884				         10.0.0.100
4885ipfw nat 5 config redirect_port tcp
4886			192.168.0.1:80,192.168.0.10:22,192.168.0.20:25 500
4887.Ed
4888.Pp
4889Sometimes you may want to mix NAT and dynamic rules.
4890It could be achieved with
4891.Cm record-state
4892and
4893.Cm defer-action
4894options.
4895Problem is, you need to create dynamic rule before NAT and check it
4896after NAT actions (or vice versa) to have consistent addresses and ports.
4897Rule with
4898.Cm keep-state
4899option will trigger activation of existing dynamic state, and action of such
4900rule will be performed as soon as rule is matched.
4901In case of NAT and
4902.Cm allow
4903rule packet need to be passed to NAT, not allowed as soon is possible.
4904.Pp
4905There is example of set of rules to achieve this.
4906Bear in mind that this is example only and it is not very useful by itself.
4907.Pp
4908On way out, after all checks place this rules:
4909.Pp
4910.Dl "ipfw add allow record-state defer-action"
4911.Dl "ipfw add nat 1"
4912.Pp
4913And on way in there should be something like this:
4914.Pp
4915.Dl "ipfw add nat 1"
4916.Dl "ipfw add check-state"
4917.Pp
4918Please note, that first rule on way out doesn't allow packet and doesn't
4919execute existing dynamic rules.
4920All it does, create new dynamic rule with
4921.Cm allow
4922action, if it is not created yet.
4923Later, this dynamic rule is used on way in by
4924.Cm check-state
4925rule.
4926.Ss CONFIGURING CODEL, PIE, FQ-CODEL and FQ-PIE AQM
4927.Cm codel
4928and
4929.Cm pie
4930AQM can be configured for
4931.Nm dummynet
4932.Cm pipe
4933or
4934.Cm queue .
4935.Pp
4936To configure a
4937.Cm pipe
4938with
4939.Cm codel
4940AQM using default configuration for traffic from 192.168.0.0/24 and 1Mbits/s
4941rate limit, we do:
4942.Pp
4943.Dl "dnctl pipe 1 config bw 1mbits/s codel"
4944.Dl "ipfw add 100 pipe 1 ip from 192.168.0.0/24 to any"
4945.Pp
4946To configure a
4947.Cm queue
4948with
4949.Cm codel
4950AQM using different configurations parameters for traffic from
4951192.168.0.0/24 and 1Mbits/s rate limit, we do:
4952.Pp
4953.Dl "dnctl pipe 1 config bw 1mbits/s"
4954.Dl "dnctl queue 1 config pipe 1 codel target 8ms interval 160ms ecn"
4955.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any"
4956.Pp
4957To configure a
4958.Cm pipe
4959with
4960.Cm pie
4961AQM using default configuration for traffic from 192.168.0.0/24 and 1Mbits/s
4962rate limit, we do:
4963.Pp
4964.Dl "dnctl pipe 1 config bw 1mbits/s pie"
4965.Dl "ipfw add 100 pipe 1 ip from 192.168.0.0/24 to any"
4966.Pp
4967To configure a
4968.Cm queue
4969with
4970.Cm pie
4971AQM using different configuration parameters for traffic from
4972192.168.0.0/24 and 1Mbits/s rate limit, we do:
4973.Pp
4974.Dl "dnctl pipe 1 config bw 1mbits/s"
4975.Dl "dnctl queue 1 config pipe 1 pie target 20ms tupdate 30ms ecn"
4976.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any"
4977.Pp
4978.Cm fq_codel
4979and
4980.Cm fq_pie
4981AQM can be configured for
4982.Nm dummynet
4983schedulers.
4984.Pp
4985To configure
4986.Cm fq_codel
4987scheduler using different configurations parameters for traffic from
4988192.168.0.0/24 and 1Mbits/s rate limit, we do:
4989.Pp
4990.Dl "dnctl pipe 1 config bw 1mbits/s"
4991.Dl "dnctl sched 1 config pipe 1 type fq_codel"
4992.Dl "dnctl queue 1 config sched 1"
4993.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any"
4994.Pp
4995To change
4996.Cm fq_codel
4997default configuration for a
4998.Cm sched
4999such as disable ECN and change the
5000.Ar target
5001to 10ms, we do:
5002.Pp
5003.Dl "dnctl sched 1 config pipe 1 type fq_codel target 10ms noecn"
5004.Pp
5005Similar to
5006.Cm fq_codel ,
5007to configure
5008.Cm fq_pie
5009scheduler using different configurations parameters for traffic from
5010192.168.0.0/24 and 1Mbits/s rate limit, we do:
5011.Pp
5012.Dl "dnctl pipe 1 config bw 1mbits/s"
5013.Dl "dnctl sched 1 config pipe 1 type fq_pie"
5014.Dl "dnctl queue 1 config sched 1"
5015.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any"
5016.Pp
5017The configurations of
5018.Cm fq_pie
5019.Cm sched
5020can be changed in a similar way as for
5021.Cm fq_codel
5022.Sh SEE ALSO
5023.Xr cpp 1 ,
5024.Xr m4 1 ,
5025.Xr fnmatch 3 ,
5026.Xr altq 4 ,
5027.Xr divert 4 ,
5028.Xr dummynet 4 ,
5029.Xr if_bridge 4 ,
5030.Xr ip 4 ,
5031.Xr ipfirewall 4 ,
5032.Xr ng_ether 4 ,
5033.Xr ng_ipfw 4 ,
5034.Xr protocols 5 ,
5035.Xr services 5 ,
5036.Xr init 8 ,
5037.Xr kldload 8 ,
5038.Xr reboot 8 ,
5039.Xr sysctl 8 ,
5040.Xr syslogd 8 ,
5041.Xr sysrc 8
5042.Sh HISTORY
5043The
5044.Nm
5045utility first appeared in
5046.Fx 2.0 .
5047.Nm dummynet
5048was introduced in
5049.Fx 2.2.8 .
5050Stateful extensions were introduced in
5051.Fx 4.0 .
5052.Nm ipfw2
5053was introduced in Summer 2002.
5054.Sh AUTHORS
5055.An Ugen J. S. Antsilevich ,
5056.An Poul-Henning Kamp ,
5057.An Alex Nash ,
5058.An Archie Cobbs ,
5059.An Luigi Rizzo ,
5060.An Rasool Al-Saadi .
5061.Pp
5062.An -nosplit
5063API based upon code written by
5064.An Daniel Boulet
5065for BSDI.
5066.Pp
5067Dummynet has been introduced by Luigi Rizzo in 1997-1998.
5068.Pp
5069Some early work (1999-2000) on the
5070.Nm dummynet
5071traffic shaper supported by Akamba Corp.
5072.Pp
5073The ipfw core (ipfw2) has been completely redesigned and
5074reimplemented by Luigi Rizzo in summer 2002.
5075Further
5076actions and
5077options have been added by various developers over the years.
5078.Pp
5079.An -nosplit
5080In-kernel NAT support written by
5081.An Paolo Pisati Aq Mt piso@FreeBSD.org
5082as part of a Summer of Code 2005 project.
5083.Pp
5084SCTP
5085.Nm nat
5086support has been developed by
5087.An The Centre for Advanced Internet Architectures (CAIA) ,
5088.Lk http://www.caia.swin.edu.au .
5089The primary developers and maintainers are David Hayes and Jason But.
5090For further information visit:
5091.Lk http://www.caia.swin.edu.au/urp/SONATA .
5092.Pp
5093Delay profiles have been developed by Alessandro Cerri and
5094Luigi Rizzo, supported by the
5095European Commission within Projects Onelab and Onelab2.
5096.Pp
5097CoDel, PIE, FQ-CoDel and FQ-PIE AQM for Dummynet have been implemented by
5098.An The Centre for Advanced Internet Architectures (CAIA)
5099in 2016, supported by The Comcast Innovation Fund.
5100The primary developer is
5101Rasool Al-Saadi.
5102.Sh BUGS
5103The syntax has grown over the years and sometimes it might be confusing.
5104Unfortunately, backward compatibility prevents cleaning up mistakes
5105made in the definition of the syntax.
5106.Pp
5107.Em !!! WARNING !!!\&
5108.Pp
5109Misconfiguring the firewall can put your computer in an unusable state,
5110possibly shutting down network services and requiring console access to
5111regain control of it.
5112.Pp
5113Incoming packet fragments diverted by
5114.Cm divert
5115are reassembled before delivery to the socket.
5116The action used on those packet is the one from the
5117rule which matches the first fragment of the packet.
5118.Pp
5119Packets diverted to userland, and then reinserted by a userland process
5120may lose various packet attributes.
5121The packet source interface name
5122will be preserved if it is shorter than 8 bytes and the userland process
5123saves and reuses the sockaddr_in
5124(as does
5125.Xr natd 8 ) ;
5126otherwise, it may be lost.
5127If a packet is reinserted in this manner, later rules may be incorrectly
5128applied, making the order of
5129.Cm divert
5130rules in the rule sequence very important.
5131.Pp
5132Dummynet drops all packets with IPv6 link-local addresses.
5133.Pp
5134Rules using
5135.Cm uid
5136or
5137.Cm gid
5138may not behave as expected.
5139In particular, incoming SYN packets may
5140have no uid or gid associated with them since they do not yet belong
5141to a TCP connection, and the uid/gid associated with a packet may not
5142be as expected if the associated process calls
5143.Xr setuid 2
5144or similar system calls.
5145.Pp
5146Rule syntax is subject to the command line environment and some patterns
5147may need to be escaped with the backslash character
5148or quoted appropriately.
5149.Pp
5150Due to the architecture of
5151.Xr libalias 3 ,
5152ipfw nat is not compatible with the TCP segmentation offloading (TSO).
5153Thus, to reliably nat your network traffic, please disable TSO
5154on your NICs using
5155.Xr ifconfig 8 .
5156.Pp
5157ICMP error messages are not implicitly matched by dynamic rules
5158for the respective conversations.
5159To avoid failures of network error detection and path MTU discovery,
5160ICMP error messages may need to be allowed explicitly through static
5161rules.
5162.Pp
5163Rules using
5164.Cm call
5165and
5166.Cm return
5167actions may lead to confusing behaviour if ruleset has mistakes,
5168and/or interaction with other subsystems (netgraph, dummynet, etc.) is used.
5169One possible case for this is packet leaving
5170.Nm
5171in subroutine on the input pass, while later on output encountering unpaired
5172.Cm return
5173first.
5174As the call stack is kept intact after input pass, packet will suddenly
5175return to the rule number used on input pass, not on output one.
5176Order of processing should be checked carefully to avoid such mistakes.
5177