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