xref: /f-stack/tools/ipfw/ipfw.8 (revision 22ce4aff)
1127dd473Swhl739.\"
2127dd473Swhl739.\" $FreeBSD$
3127dd473Swhl739.\"
4*22ce4affSfengbojiang.Dd August 21, 2020
5127dd473Swhl739.Dt IPFW 8
6127dd473Swhl739.Os
7127dd473Swhl739.Sh NAME
8127dd473Swhl739.Nm ipfw
9127dd473Swhl739.Nd User interface for firewall, traffic shaper, packet scheduler,
10127dd473Swhl739in-kernel NAT.
11127dd473Swhl739.Sh SYNOPSIS
12127dd473Swhl739.Ss FIREWALL CONFIGURATION
13127dd473Swhl739.Nm
14127dd473Swhl739.Op Fl cq
15127dd473Swhl739.Cm add
16127dd473Swhl739.Ar rule
17127dd473Swhl739.Nm
18127dd473Swhl739.Op Fl acdefnNStT
19127dd473Swhl739.Op Cm set Ar N
20127dd473Swhl739.Brq Cm list | show
21127dd473Swhl739.Op Ar rule | first-last ...
22127dd473Swhl739.Nm
23127dd473Swhl739.Op Fl f | q
24127dd473Swhl739.Op Cm set Ar N
25127dd473Swhl739.Cm flush
26127dd473Swhl739.Nm
27127dd473Swhl739.Op Fl q
28127dd473Swhl739.Op Cm set Ar N
29127dd473Swhl739.Brq Cm delete | zero | resetlog
30127dd473Swhl739.Op Ar number ...
31127dd473Swhl739.Pp
32127dd473Swhl739.Nm
33127dd473Swhl739.Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
34127dd473Swhl739.Nm
35127dd473Swhl739.Cm set move
36127dd473Swhl739.Op Cm rule
37127dd473Swhl739.Ar number Cm to Ar number
38127dd473Swhl739.Nm
39127dd473Swhl739.Cm set swap Ar number number
40127dd473Swhl739.Nm
41127dd473Swhl739.Cm set show
42127dd473Swhl739.Ss SYSCTL SHORTCUTS
43127dd473Swhl739.Nm
44127dd473Swhl739.Cm enable
45127dd473Swhl739.Brq Cm firewall | altq | one_pass | debug | verbose | dyn_keepalive
46127dd473Swhl739.Nm
47127dd473Swhl739.Cm disable
48127dd473Swhl739.Brq Cm firewall | altq | one_pass | debug | verbose | dyn_keepalive
49127dd473Swhl739.Ss LOOKUP TABLES
50127dd473Swhl739.Nm
51127dd473Swhl739.Oo Cm set Ar N Oc Cm table Ar name Cm create Ar create-options
52127dd473Swhl739.Nm
53*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm table
54*22ce4affSfengbojiang.Brq Ar name | all
55*22ce4affSfengbojiang.Cm destroy
56127dd473Swhl739.Nm
57127dd473Swhl739.Oo Cm set Ar N Oc Cm table Ar name Cm modify Ar modify-options
58127dd473Swhl739.Nm
59127dd473Swhl739.Oo Cm set Ar N Oc Cm table Ar name Cm swap Ar name
60127dd473Swhl739.Nm
61127dd473Swhl739.Oo Cm set Ar N Oc Cm table Ar name Cm add Ar table-key Op Ar value
62127dd473Swhl739.Nm
63127dd473Swhl739.Oo Cm set Ar N Oc Cm table Ar name Cm add Op Ar table-key Ar value ...
64127dd473Swhl739.Nm
65127dd473Swhl739.Oo Cm set Ar N Oc Cm table Ar name Cm atomic add Op Ar table-key Ar value ...
66127dd473Swhl739.Nm
67127dd473Swhl739.Oo Cm set Ar N Oc Cm table Ar name Cm delete Op Ar table-key ...
68127dd473Swhl739.Nm
69127dd473Swhl739.Oo Cm set Ar N Oc Cm table Ar name Cm lookup Ar addr
70127dd473Swhl739.Nm
71127dd473Swhl739.Oo Cm set Ar N Oc Cm table Ar name Cm lock
72127dd473Swhl739.Nm
73127dd473Swhl739.Oo Cm set Ar N Oc Cm table Ar name Cm unlock
74127dd473Swhl739.Nm
75127dd473Swhl739.Oo Cm set Ar N Oc Cm table
76127dd473Swhl739.Brq Ar name | all
77127dd473Swhl739.Cm list
78127dd473Swhl739.Nm
79127dd473Swhl739.Oo Cm set Ar N Oc Cm table
80127dd473Swhl739.Brq Ar name | all
81127dd473Swhl739.Cm info
82127dd473Swhl739.Nm
83127dd473Swhl739.Oo Cm set Ar N Oc Cm table
84127dd473Swhl739.Brq Ar name | all
85127dd473Swhl739.Cm detail
86127dd473Swhl739.Nm
87127dd473Swhl739.Oo Cm set Ar N Oc Cm table
88127dd473Swhl739.Brq Ar name | all
89127dd473Swhl739.Cm flush
90127dd473Swhl739.Ss DUMMYNET CONFIGURATION (TRAFFIC SHAPER AND PACKET SCHEDULER)
91127dd473Swhl739.Nm
92127dd473Swhl739.Brq Cm pipe | queue | sched
93127dd473Swhl739.Ar number
94127dd473Swhl739.Cm config
95127dd473Swhl739.Ar config-options
96127dd473Swhl739.Nm
97127dd473Swhl739.Op Fl s Op Ar field
98127dd473Swhl739.Brq Cm pipe | queue | sched
99127dd473Swhl739.Brq Cm delete | list | show
100127dd473Swhl739.Op Ar number ...
101127dd473Swhl739.Ss IN-KERNEL NAT
102127dd473Swhl739.Nm
103127dd473Swhl739.Op Fl q
104127dd473Swhl739.Cm nat
105127dd473Swhl739.Ar number
106127dd473Swhl739.Cm config
107127dd473Swhl739.Ar config-options
108*22ce4affSfengbojiang.Ss STATEFUL IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
109*22ce4affSfengbojiang.Nm
110*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64lsn Ar name Cm create Ar create-options
111*22ce4affSfengbojiang.Nm
112*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64lsn Ar name Cm config Ar config-options
113*22ce4affSfengbojiang.Nm
114*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64lsn
115*22ce4affSfengbojiang.Brq Ar name | all
116*22ce4affSfengbojiang.Brq Cm list | show
117*22ce4affSfengbojiang.Op Cm states
118*22ce4affSfengbojiang.Nm
119*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64lsn
120*22ce4affSfengbojiang.Brq Ar name | all
121*22ce4affSfengbojiang.Cm destroy
122*22ce4affSfengbojiang.Nm
123*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64lsn Ar name Cm stats Op Cm reset
124*22ce4affSfengbojiang.Ss STATELESS IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
125*22ce4affSfengbojiang.Nm
126*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64stl Ar name Cm create Ar create-options
127*22ce4affSfengbojiang.Nm
128*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64stl Ar name Cm config Ar config-options
129*22ce4affSfengbojiang.Nm
130*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64stl
131*22ce4affSfengbojiang.Brq Ar name | all
132*22ce4affSfengbojiang.Brq Cm list | show
133*22ce4affSfengbojiang.Nm
134*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64stl
135*22ce4affSfengbojiang.Brq Ar name | all
136*22ce4affSfengbojiang.Cm destroy
137*22ce4affSfengbojiang.Nm
138*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64stl Ar name Cm stats Op Cm reset
139*22ce4affSfengbojiang.Ss XLAT464 CLAT IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
140*22ce4affSfengbojiang.Nm
141*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64clat Ar name Cm create Ar create-options
142*22ce4affSfengbojiang.Nm
143*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64clat Ar name Cm config Ar config-options
144*22ce4affSfengbojiang.Nm
145*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64clat
146*22ce4affSfengbojiang.Brq Ar name | all
147*22ce4affSfengbojiang.Brq Cm list | show
148*22ce4affSfengbojiang.Nm
149*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64clat
150*22ce4affSfengbojiang.Brq Ar name | all
151*22ce4affSfengbojiang.Cm destroy
152*22ce4affSfengbojiang.Nm
153*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nat64clat Ar name Cm stats Op Cm reset
154*22ce4affSfengbojiang.Ss IPv6-to-IPv6 NETWORK PREFIX TRANSLATION
155*22ce4affSfengbojiang.Nm
156*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nptv6 Ar name Cm create Ar create-options
157*22ce4affSfengbojiang.Nm
158*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nptv6
159*22ce4affSfengbojiang.Brq Ar name | all
160*22ce4affSfengbojiang.Brq Cm list | show
161*22ce4affSfengbojiang.Nm
162*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nptv6
163*22ce4affSfengbojiang.Brq Ar name | all
164*22ce4affSfengbojiang.Cm destroy
165*22ce4affSfengbojiang.Nm
166*22ce4affSfengbojiang.Oo Cm set Ar N Oc Cm nptv6 Ar name Cm stats Op Cm reset
167*22ce4affSfengbojiang.Ss INTERNAL DIAGNOSTICS
168*22ce4affSfengbojiang.Nm
169*22ce4affSfengbojiang.Cm internal iflist
170*22ce4affSfengbojiang.Nm
171*22ce4affSfengbojiang.Cm internal talist
172*22ce4affSfengbojiang.Nm
173*22ce4affSfengbojiang.Cm internal vlist
174*22ce4affSfengbojiang.Ss LIST OF RULES AND PREPROCESSING
175127dd473Swhl739.Nm
176127dd473Swhl739.Op Fl cfnNqS
177127dd473Swhl739.Oo
178127dd473Swhl739.Fl p Ar preproc
179127dd473Swhl739.Oo
180127dd473Swhl739.Ar preproc-flags
181127dd473Swhl739.Oc
182127dd473Swhl739.Oc
183127dd473Swhl739.Ar pathname
184127dd473Swhl739.Sh DESCRIPTION
185127dd473Swhl739The
186127dd473Swhl739.Nm
187127dd473Swhl739utility is the user interface for controlling the
188127dd473Swhl739.Xr ipfw 4
189127dd473Swhl739firewall, the
190127dd473Swhl739.Xr dummynet 4
191127dd473Swhl739traffic shaper/packet scheduler, and the
192127dd473Swhl739in-kernel NAT services.
193127dd473Swhl739.Pp
194127dd473Swhl739A firewall configuration, or
195127dd473Swhl739.Em ruleset ,
196127dd473Swhl739is made of a list of
197127dd473Swhl739.Em rules
198127dd473Swhl739numbered from 1 to 65535.
199127dd473Swhl739Packets are passed to the firewall
200127dd473Swhl739from a number of different places in the protocol stack
201127dd473Swhl739(depending on the source and destination of the packet,
202127dd473Swhl739it is possible for the firewall to be
203127dd473Swhl739invoked multiple times on the same packet).
204127dd473Swhl739The packet passed to the firewall is compared
205127dd473Swhl739against each of the rules in the
206127dd473Swhl739.Em ruleset ,
207127dd473Swhl739in rule-number order
208127dd473Swhl739(multiple rules with the same number are permitted, in which case
209127dd473Swhl739they are processed in order of insertion).
210127dd473Swhl739When a match is found, the action corresponding to the
211127dd473Swhl739matching rule is performed.
212127dd473Swhl739.Pp
213127dd473Swhl739Depending on the action and certain system settings, packets
214127dd473Swhl739can be reinjected into the firewall at some rule after the
215127dd473Swhl739matching one for further processing.
216127dd473Swhl739.Pp
217127dd473Swhl739A ruleset always includes a
218127dd473Swhl739.Em default
219127dd473Swhl739rule (numbered 65535) which cannot be modified or deleted,
220127dd473Swhl739and matches all packets.
221127dd473Swhl739The action associated with the
222127dd473Swhl739.Em default
223127dd473Swhl739rule can be either
224127dd473Swhl739.Cm deny
225127dd473Swhl739or
226127dd473Swhl739.Cm allow
227127dd473Swhl739depending on how the kernel is configured.
228127dd473Swhl739.Pp
229127dd473Swhl739If the ruleset includes one or more rules with the
230*22ce4affSfengbojiang.Cm keep-state ,
231*22ce4affSfengbojiang.Cm record-state ,
232127dd473Swhl739.Cm limit
233*22ce4affSfengbojiangor
234*22ce4affSfengbojiang.Cm set-limit
235127dd473Swhl739option,
236127dd473Swhl739the firewall will have a
237127dd473Swhl739.Em stateful
238127dd473Swhl739behaviour, i.e., upon a match it will create
239127dd473Swhl739.Em dynamic rules ,
240127dd473Swhl739i.e., rules that match packets with the same 5-tuple
241127dd473Swhl739(protocol, source and destination addresses and ports)
242127dd473Swhl739as the packet which caused their creation.
243127dd473Swhl739Dynamic rules, which have a limited lifetime, are checked
244127dd473Swhl739at the first occurrence of a
245127dd473Swhl739.Cm check-state ,
246127dd473Swhl739.Cm keep-state
247127dd473Swhl739or
248127dd473Swhl739.Cm limit
249127dd473Swhl739rule, and are typically used to open the firewall on-demand to
250127dd473Swhl739legitimate traffic only.
251*22ce4affSfengbojiangPlease note, that
252*22ce4affSfengbojiang.Cm keep-state
253*22ce4affSfengbojiangand
254*22ce4affSfengbojiang.Cm limit
255*22ce4affSfengbojiangimply implicit
256*22ce4affSfengbojiang.Cm check-state
257*22ce4affSfengbojiangfor all packets (not only these matched by the rule) but
258*22ce4affSfengbojiang.Cm record-state
259*22ce4affSfengbojiangand
260*22ce4affSfengbojiang.Cm set-limit
261*22ce4affSfengbojianghave no implicit
262*22ce4affSfengbojiang.Cm check-state .
263127dd473Swhl739See the
264127dd473Swhl739.Sx STATEFUL FIREWALL
265127dd473Swhl739and
266127dd473Swhl739.Sx EXAMPLES
267127dd473Swhl739Sections below for more information on the stateful behaviour of
268127dd473Swhl739.Nm .
269127dd473Swhl739.Pp
270127dd473Swhl739All rules (including dynamic ones) have a few associated counters:
271127dd473Swhl739a packet count, a byte count, a log count and a timestamp
272127dd473Swhl739indicating the time of the last match.
273127dd473Swhl739Counters can be displayed or reset with
274127dd473Swhl739.Nm
275127dd473Swhl739commands.
276127dd473Swhl739.Pp
277127dd473Swhl739Each rule belongs to one of 32 different
278127dd473Swhl739.Em sets
279127dd473Swhl739, and there are
280127dd473Swhl739.Nm
281127dd473Swhl739commands to atomically manipulate sets, such as enable,
282127dd473Swhl739disable, swap sets, move all rules in a set to another
283127dd473Swhl739one, delete all rules in a set.
284127dd473Swhl739These can be useful to
285127dd473Swhl739install temporary configurations, or to test them.
286127dd473Swhl739See Section
287127dd473Swhl739.Sx SETS OF RULES
288127dd473Swhl739for more information on
289127dd473Swhl739.Em sets .
290127dd473Swhl739.Pp
291127dd473Swhl739Rules can be added with the
292127dd473Swhl739.Cm add
293127dd473Swhl739command; deleted individually or in groups with the
294127dd473Swhl739.Cm delete
295127dd473Swhl739command, and globally (except those in set 31) with the
296127dd473Swhl739.Cm flush
297127dd473Swhl739command; displayed, optionally with the content of the
298127dd473Swhl739counters, using the
299127dd473Swhl739.Cm show
300127dd473Swhl739and
301127dd473Swhl739.Cm list
302127dd473Swhl739commands.
303127dd473Swhl739Finally, counters can be reset with the
304127dd473Swhl739.Cm zero
305127dd473Swhl739and
306127dd473Swhl739.Cm resetlog
307127dd473Swhl739commands.
308127dd473Swhl739.Ss COMMAND OPTIONS
309127dd473Swhl739The following general options are available when invoking
310127dd473Swhl739.Nm :
311127dd473Swhl739.Bl -tag -width indent
312127dd473Swhl739.It Fl a
313127dd473Swhl739Show counter values when listing rules.
314127dd473Swhl739The
315127dd473Swhl739.Cm show
316127dd473Swhl739command implies this option.
317127dd473Swhl739.It Fl b
318127dd473Swhl739Only show the action and the comment, not the body of a rule.
319127dd473Swhl739Implies
320127dd473Swhl739.Fl c .
321127dd473Swhl739.It Fl c
322127dd473Swhl739When entering or showing rules, print them in compact form,
323127dd473Swhl739i.e., omitting the "ip from any to any" string
324127dd473Swhl739when this does not carry any additional information.
325127dd473Swhl739.It Fl d
326127dd473Swhl739When listing, show dynamic rules in addition to static ones.
327*22ce4affSfengbojiang.It Fl D
328*22ce4affSfengbojiangWhen listing, show only dynamic states.
329*22ce4affSfengbojiangWhen deleting, delete only dynamic states.
330127dd473Swhl739.It Fl f
331*22ce4affSfengbojiangRun without prompting for confirmation for commands that can cause problems if misused,
332*22ce4affSfengbojiangi.e.,
333127dd473Swhl739.Cm flush .
334127dd473Swhl739If there is no tty associated with the process, this is implied.
335*22ce4affSfengbojiangThe
336*22ce4affSfengbojiang.Cm delete
337*22ce4affSfengbojiangcommand with this flag ignores possible errors,
338*22ce4affSfengbojiangi.e., nonexistent rule number.
339*22ce4affSfengbojiangAnd for batched commands execution continues with the next command.
340127dd473Swhl739.It Fl i
341127dd473Swhl739When listing a table (see the
342127dd473Swhl739.Sx LOOKUP TABLES
343127dd473Swhl739section below for more information on lookup tables), format values
344127dd473Swhl739as IP addresses.
345127dd473Swhl739By default, values are shown as integers.
346127dd473Swhl739.It Fl n
347127dd473Swhl739Only check syntax of the command strings, without actually passing
348127dd473Swhl739them to the kernel.
349127dd473Swhl739.It Fl N
350127dd473Swhl739Try to resolve addresses and service names in output.
351127dd473Swhl739.It Fl q
352127dd473Swhl739Be quiet when executing the
353127dd473Swhl739.Cm add ,
354127dd473Swhl739.Cm nat ,
355127dd473Swhl739.Cm zero ,
356127dd473Swhl739.Cm resetlog
357127dd473Swhl739or
358127dd473Swhl739.Cm flush
359127dd473Swhl739commands;
360127dd473Swhl739(implies
361127dd473Swhl739.Fl f ) .
362127dd473Swhl739This is useful when updating rulesets by executing multiple
363127dd473Swhl739.Nm
364127dd473Swhl739commands in a script
365127dd473Swhl739(e.g.,
366127dd473Swhl739.Ql sh\ /etc/rc.firewall ) ,
367127dd473Swhl739or by processing a file with many
368127dd473Swhl739.Nm
369127dd473Swhl739rules across a remote login session.
370127dd473Swhl739It also stops a table add or delete
371127dd473Swhl739from failing if the entry already exists or is not present.
372127dd473Swhl739.Pp
373127dd473Swhl739The reason why this option may be important is that
374127dd473Swhl739for some of these actions,
375127dd473Swhl739.Nm
376127dd473Swhl739may print a message; if the action results in blocking the
377127dd473Swhl739traffic to the remote client,
378127dd473Swhl739the remote login session will be closed
379127dd473Swhl739and the rest of the ruleset will not be processed.
380127dd473Swhl739Access to the console would then be required to recover.
381127dd473Swhl739.It Fl S
382127dd473Swhl739When listing rules, show the
383127dd473Swhl739.Em set
384127dd473Swhl739each rule belongs to.
385127dd473Swhl739If this flag is not specified, disabled rules will not be
386127dd473Swhl739listed.
387127dd473Swhl739.It Fl s Op Ar field
388127dd473Swhl739When listing pipes, sort according to one of the four
389127dd473Swhl739counters (total or current packets or bytes).
390127dd473Swhl739.It Fl t
391*22ce4affSfengbojiangWhen listing, show last match timestamp converted with
392*22ce4affSfengbojiang.Fn ctime .
393127dd473Swhl739.It Fl T
394127dd473Swhl739When listing, show last match timestamp as seconds from the epoch.
395127dd473Swhl739This form can be more convenient for postprocessing by scripts.
396127dd473Swhl739.El
397127dd473Swhl739.Ss LIST OF RULES AND PREPROCESSING
398127dd473Swhl739To ease configuration, rules can be put into a file which is
399127dd473Swhl739processed using
400127dd473Swhl739.Nm
401127dd473Swhl739as shown in the last synopsis line.
402127dd473Swhl739An absolute
403127dd473Swhl739.Ar pathname
404127dd473Swhl739must be used.
405127dd473Swhl739The file will be read line by line and applied as arguments to the
406127dd473Swhl739.Nm
407127dd473Swhl739utility.
408127dd473Swhl739.Pp
409127dd473Swhl739Optionally, a preprocessor can be specified using
410127dd473Swhl739.Fl p Ar preproc
411127dd473Swhl739where
412127dd473Swhl739.Ar pathname
413127dd473Swhl739is to be piped through.
414127dd473Swhl739Useful preprocessors include
415127dd473Swhl739.Xr cpp 1
416127dd473Swhl739and
417127dd473Swhl739.Xr m4 1 .
418127dd473Swhl739If
419127dd473Swhl739.Ar preproc
420127dd473Swhl739does not start with a slash
421127dd473Swhl739.Pq Ql /
422127dd473Swhl739as its first character, the usual
423127dd473Swhl739.Ev PATH
424127dd473Swhl739name search is performed.
425127dd473Swhl739Care should be taken with this in environments where not all
426127dd473Swhl739file systems are mounted (yet) by the time
427127dd473Swhl739.Nm
428127dd473Swhl739is being run (e.g.\& when they are mounted over NFS).
429127dd473Swhl739Once
430127dd473Swhl739.Fl p
431127dd473Swhl739has been specified, any additional arguments are passed on to the preprocessor
432127dd473Swhl739for interpretation.
433127dd473Swhl739This allows for flexible configuration files (like conditionalizing
434127dd473Swhl739them on the local hostname) and the use of macros to centralize
435127dd473Swhl739frequently required arguments like IP addresses.
436127dd473Swhl739.Ss TRAFFIC SHAPER CONFIGURATION
437127dd473Swhl739The
438127dd473Swhl739.Nm
439127dd473Swhl739.Cm pipe , queue
440127dd473Swhl739and
441127dd473Swhl739.Cm sched
442127dd473Swhl739commands are used to configure the traffic shaper and packet scheduler.
443127dd473Swhl739See the
444127dd473Swhl739.Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
445127dd473Swhl739Section below for details.
446127dd473Swhl739.Pp
447127dd473Swhl739If the world and the kernel get out of sync the
448127dd473Swhl739.Nm
449127dd473Swhl739ABI may break, preventing you from being able to add any rules.
450127dd473Swhl739This can adversely affect the booting process.
451127dd473Swhl739You can use
452127dd473Swhl739.Nm
453127dd473Swhl739.Cm disable
454127dd473Swhl739.Cm firewall
455127dd473Swhl739to temporarily disable the firewall to regain access to the network,
456127dd473Swhl739allowing you to fix the problem.
457127dd473Swhl739.Sh PACKET FLOW
458127dd473Swhl739A packet is checked against the active ruleset in multiple places
459127dd473Swhl739in the protocol stack, under control of several sysctl variables.
460127dd473Swhl739These places and variables are shown below, and it is important to
461127dd473Swhl739have this picture in mind in order to design a correct ruleset.
462127dd473Swhl739.Bd -literal -offset indent
463127dd473Swhl739       ^    to upper layers    V
464127dd473Swhl739       |                       |
465127dd473Swhl739       +----------->-----------+
466127dd473Swhl739       ^                       V
467127dd473Swhl739 [ip(6)_input]           [ip(6)_output]     net.inet(6).ip(6).fw.enable=1
468127dd473Swhl739       |                       |
469127dd473Swhl739       ^                       V
470127dd473Swhl739 [ether_demux]        [ether_output_frame]  net.link.ether.ipfw=1
471127dd473Swhl739       |                       |
472127dd473Swhl739       +-->--[bdg_forward]-->--+            net.link.bridge.ipfw=1
473127dd473Swhl739       ^                       V
474127dd473Swhl739       |      to devices       |
475127dd473Swhl739.Ed
476127dd473Swhl739.Pp
477127dd473Swhl739The number of
478127dd473Swhl739times the same packet goes through the firewall can
479127dd473Swhl739vary between 0 and 4 depending on packet source and
480127dd473Swhl739destination, and system configuration.
481127dd473Swhl739.Pp
482127dd473Swhl739Note that as packets flow through the stack, headers can be
483127dd473Swhl739stripped or added to it, and so they may or may not be available
484127dd473Swhl739for inspection.
485127dd473Swhl739E.g., incoming packets will include the MAC header when
486127dd473Swhl739.Nm
487127dd473Swhl739is invoked from
488127dd473Swhl739.Cm ether_demux() ,
489127dd473Swhl739but the same packets will have the MAC header stripped off when
490127dd473Swhl739.Nm
491127dd473Swhl739is invoked from
492127dd473Swhl739.Cm ip_input()
493127dd473Swhl739or
494127dd473Swhl739.Cm ip6_input() .
495127dd473Swhl739.Pp
496127dd473Swhl739Also note that each packet is always checked against the complete ruleset,
497127dd473Swhl739irrespective of the place where the check occurs, or the source of the packet.
498127dd473Swhl739If a rule contains some match patterns or actions which are not valid
499127dd473Swhl739for the place of invocation (e.g.\& trying to match a MAC header within
500127dd473Swhl739.Cm ip_input
501127dd473Swhl739or
502127dd473Swhl739.Cm ip6_input ),
503127dd473Swhl739the match pattern will not match, but a
504127dd473Swhl739.Cm not
505127dd473Swhl739operator in front of such patterns
506127dd473Swhl739.Em will
507127dd473Swhl739cause the pattern to
508127dd473Swhl739.Em always
509127dd473Swhl739match on those packets.
510127dd473Swhl739It is thus the responsibility of
511127dd473Swhl739the programmer, if necessary, to write a suitable ruleset to
512127dd473Swhl739differentiate among the possible places.
513127dd473Swhl739.Cm skipto
514127dd473Swhl739rules can be useful here, as an example:
515127dd473Swhl739.Bd -literal -offset indent
516127dd473Swhl739# packets from ether_demux or bdg_forward
517127dd473Swhl739ipfw add 10 skipto 1000 all from any to any layer2 in
518127dd473Swhl739# packets from ip_input
519127dd473Swhl739ipfw add 10 skipto 2000 all from any to any not layer2 in
520127dd473Swhl739# packets from ip_output
521127dd473Swhl739ipfw add 10 skipto 3000 all from any to any not layer2 out
522127dd473Swhl739# packets from ether_output_frame
523127dd473Swhl739ipfw add 10 skipto 4000 all from any to any layer2 out
524127dd473Swhl739.Ed
525127dd473Swhl739.Pp
526127dd473Swhl739(yes, at the moment there is no way to differentiate between
527127dd473Swhl739ether_demux and bdg_forward).
528*22ce4affSfengbojiang.Pp
529*22ce4affSfengbojiangAlso note that only actions
530*22ce4affSfengbojiang.Cm allow ,
531*22ce4affSfengbojiang.Cm deny ,
532*22ce4affSfengbojiang.Cm netgraph ,
533*22ce4affSfengbojiang.Cm ngtee
534*22ce4affSfengbojiangand related to
535*22ce4affSfengbojiang.Cm dummynet
536*22ce4affSfengbojiangare processed for
537*22ce4affSfengbojiang.Cm layer2
538*22ce4affSfengbojiangframes and all other actions act as if they were
539*22ce4affSfengbojiang.Cm allow
540*22ce4affSfengbojiangfor such frames.
541*22ce4affSfengbojiangFull set of actions is supported for IP packets without
542*22ce4affSfengbojiang.Cm layer2
543*22ce4affSfengbojiangheaders only.
544*22ce4affSfengbojiangFor example,
545*22ce4affSfengbojiang.Cm divert
546*22ce4affSfengbojiangaction does not divert
547*22ce4affSfengbojiang.Cm layer2
548*22ce4affSfengbojiangframes.
549127dd473Swhl739.Sh SYNTAX
550127dd473Swhl739In general, each keyword or argument must be provided as
551127dd473Swhl739a separate command line argument, with no leading or trailing
552127dd473Swhl739spaces.
553127dd473Swhl739Keywords are case-sensitive, whereas arguments may
554127dd473Swhl739or may not be case-sensitive depending on their nature
555127dd473Swhl739(e.g.\& uid's are, hostnames are not).
556127dd473Swhl739.Pp
557127dd473Swhl739Some arguments (e.g., port or address lists) are comma-separated
558127dd473Swhl739lists of values.
559127dd473Swhl739In this case, spaces after commas ',' are allowed to make
560127dd473Swhl739the line more readable.
561127dd473Swhl739You can also put the entire
562127dd473Swhl739command (including flags) into a single argument.
563127dd473Swhl739E.g., the following forms are equivalent:
564127dd473Swhl739.Bd -literal -offset indent
565127dd473Swhl739ipfw -q add deny src-ip 10.0.0.0/24,127.0.0.1/8
566127dd473Swhl739ipfw -q add deny src-ip 10.0.0.0/24, 127.0.0.1/8
567127dd473Swhl739ipfw "-q add deny src-ip 10.0.0.0/24, 127.0.0.1/8"
568127dd473Swhl739.Ed
569127dd473Swhl739.Sh RULE FORMAT
570127dd473Swhl739The format of firewall rules is the following:
571127dd473Swhl739.Bd -ragged -offset indent
572127dd473Swhl739.Bk -words
573127dd473Swhl739.Op Ar rule_number
574127dd473Swhl739.Op Cm set Ar set_number
575127dd473Swhl739.Op Cm prob Ar match_probability
576127dd473Swhl739.Ar action
577127dd473Swhl739.Op Cm log Op Cm logamount Ar number
578127dd473Swhl739.Op Cm altq Ar queue
579127dd473Swhl739.Oo
580127dd473Swhl739.Bro Cm tag | untag
581127dd473Swhl739.Brc Ar number
582127dd473Swhl739.Oc
583127dd473Swhl739.Ar body
584127dd473Swhl739.Ek
585127dd473Swhl739.Ed
586127dd473Swhl739.Pp
587127dd473Swhl739where the body of the rule specifies which information is used
588127dd473Swhl739for filtering packets, among the following:
589127dd473Swhl739.Pp
590127dd473Swhl739.Bl -tag -width "Source and dest. addresses and ports" -offset XXX -compact
591127dd473Swhl739.It Layer-2 header fields
592127dd473Swhl739When available
593127dd473Swhl739.It IPv4 and IPv6 Protocol
594*22ce4affSfengbojiangSCTP, TCP, UDP, ICMP, etc.
595127dd473Swhl739.It Source and dest. addresses and ports
596127dd473Swhl739.It Direction
597127dd473Swhl739See Section
598127dd473Swhl739.Sx PACKET FLOW
599127dd473Swhl739.It Transmit and receive interface
600127dd473Swhl739By name or address
601127dd473Swhl739.It Misc. IP header fields
602127dd473Swhl739Version, type of service, datagram length, identification,
603*22ce4affSfengbojiangfragmentation flags,
604127dd473Swhl739Time To Live
605127dd473Swhl739.It IP options
606127dd473Swhl739.It IPv6 Extension headers
607127dd473Swhl739Fragmentation, Hop-by-Hop options,
608127dd473Swhl739Routing Headers, Source routing rthdr0, Mobile IPv6 rthdr2, IPSec options.
609127dd473Swhl739.It IPv6 Flow-ID
610127dd473Swhl739.It Misc. TCP header fields
611127dd473Swhl739TCP flags (SYN, FIN, ACK, RST, etc.),
612127dd473Swhl739sequence number, acknowledgment number,
613127dd473Swhl739window
614127dd473Swhl739.It TCP options
615127dd473Swhl739.It ICMP types
616127dd473Swhl739for ICMP packets
617127dd473Swhl739.It ICMP6 types
618127dd473Swhl739for ICMP6 packets
619127dd473Swhl739.It User/group ID
620127dd473Swhl739When the packet can be associated with a local socket.
621127dd473Swhl739.It Divert status
622127dd473Swhl739Whether a packet came from a divert socket (e.g.,
623127dd473Swhl739.Xr natd 8 ) .
624127dd473Swhl739.It Fib annotation state
625127dd473Swhl739Whether a packet has been tagged for using a specific FIB (routing table)
626127dd473Swhl739in future forwarding decisions.
627127dd473Swhl739.El
628127dd473Swhl739.Pp
629127dd473Swhl739Note that some of the above information, e.g.\& source MAC or IP addresses and
630127dd473Swhl739TCP/UDP ports, can be easily spoofed, so filtering on those fields
631127dd473Swhl739alone might not guarantee the desired results.
632127dd473Swhl739.Bl -tag -width indent
633127dd473Swhl739.It Ar rule_number
634127dd473Swhl739Each rule is associated with a
635127dd473Swhl739.Ar rule_number
636127dd473Swhl739in the range 1..65535, with the latter reserved for the
637127dd473Swhl739.Em default
638127dd473Swhl739rule.
639127dd473Swhl739Rules are checked sequentially by rule number.
640127dd473Swhl739Multiple rules can have the same number, in which case they are
641127dd473Swhl739checked (and listed) according to the order in which they have
642127dd473Swhl739been added.
643127dd473Swhl739If a rule is entered without specifying a number, the kernel will
644127dd473Swhl739assign one in such a way that the rule becomes the last one
645127dd473Swhl739before the
646127dd473Swhl739.Em default
647127dd473Swhl739rule.
648127dd473Swhl739Automatic rule numbers are assigned by incrementing the last
649127dd473Swhl739non-default rule number by the value of the sysctl variable
650127dd473Swhl739.Ar net.inet.ip.fw.autoinc_step
651127dd473Swhl739which defaults to 100.
652127dd473Swhl739If this is not possible (e.g.\& because we would go beyond the
653127dd473Swhl739maximum allowed rule number), the number of the last
654127dd473Swhl739non-default value is used instead.
655127dd473Swhl739.It Cm set Ar set_number
656127dd473Swhl739Each rule is associated with a
657127dd473Swhl739.Ar set_number
658127dd473Swhl739in the range 0..31.
659127dd473Swhl739Sets can be individually disabled and enabled, so this parameter
660127dd473Swhl739is of fundamental importance for atomic ruleset manipulation.
661127dd473Swhl739It can be also used to simplify deletion of groups of rules.
662127dd473Swhl739If a rule is entered without specifying a set number,
663127dd473Swhl739set 0 will be used.
664127dd473Swhl739.br
665127dd473Swhl739Set 31 is special in that it cannot be disabled,
666127dd473Swhl739and rules in set 31 are not deleted by the
667127dd473Swhl739.Nm ipfw flush
668127dd473Swhl739command (but you can delete them with the
669127dd473Swhl739.Nm ipfw delete set 31
670127dd473Swhl739command).
671127dd473Swhl739Set 31 is also used for the
672127dd473Swhl739.Em default
673127dd473Swhl739rule.
674127dd473Swhl739.It Cm prob Ar match_probability
675127dd473Swhl739A match is only declared with the specified probability
676127dd473Swhl739(floating point number between 0 and 1).
677127dd473Swhl739This can be useful for a number of applications such as
678127dd473Swhl739random packet drop or
679127dd473Swhl739(in conjunction with
680127dd473Swhl739.Nm dummynet )
681127dd473Swhl739to simulate the effect of multiple paths leading to out-of-order
682127dd473Swhl739packet delivery.
683127dd473Swhl739.Pp
684127dd473Swhl739Note: this condition is checked before any other condition, including
685*22ce4affSfengbojiangones such as
686*22ce4affSfengbojiang.Cm keep-state
687*22ce4affSfengbojiangor
688*22ce4affSfengbojiang.Cm check-state
689*22ce4affSfengbojiangwhich might have
690*22ce4affSfengbojiangside effects.
691127dd473Swhl739.It Cm log Op Cm logamount Ar number
692127dd473Swhl739Packets matching a rule with the
693127dd473Swhl739.Cm log
694127dd473Swhl739keyword will be made available for logging in two ways:
695127dd473Swhl739if the sysctl variable
696127dd473Swhl739.Va net.inet.ip.fw.verbose
697127dd473Swhl739is set to 0 (default), one can use
698127dd473Swhl739.Xr bpf 4
699127dd473Swhl739attached to the
700127dd473Swhl739.Li ipfw0
701127dd473Swhl739pseudo interface.
702*22ce4affSfengbojiangThis pseudo interface can be created manually after a system
703*22ce4affSfengbojiangboot by using the following command:
704127dd473Swhl739.Bd -literal -offset indent
705127dd473Swhl739# ifconfig ipfw0 create
706127dd473Swhl739.Ed
707127dd473Swhl739.Pp
708127dd473Swhl739Or, automatically at boot time by adding the following
709127dd473Swhl739line to the
710127dd473Swhl739.Xr rc.conf 5
711127dd473Swhl739file:
712127dd473Swhl739.Bd -literal -offset indent
713127dd473Swhl739firewall_logif="YES"
714127dd473Swhl739.Ed
715127dd473Swhl739.Pp
716*22ce4affSfengbojiangThere is zero overhead when no
717127dd473Swhl739.Xr bpf 4
718127dd473Swhl739is attached to the pseudo interface.
719127dd473Swhl739.Pp
720127dd473Swhl739If
721127dd473Swhl739.Va net.inet.ip.fw.verbose
722127dd473Swhl739is set to 1, packets will be logged to
723127dd473Swhl739.Xr syslogd 8
724127dd473Swhl739with a
725127dd473Swhl739.Dv LOG_SECURITY
726127dd473Swhl739facility up to a maximum of
727127dd473Swhl739.Cm logamount
728127dd473Swhl739packets.
729127dd473Swhl739If no
730127dd473Swhl739.Cm logamount
731127dd473Swhl739is specified, the limit is taken from the sysctl variable
732127dd473Swhl739.Va net.inet.ip.fw.verbose_limit .
733127dd473Swhl739In both cases, a value of 0 means unlimited logging.
734127dd473Swhl739.Pp
735127dd473Swhl739Once the limit is reached, logging can be re-enabled by
736127dd473Swhl739clearing the logging counter or the packet counter for that entry, see the
737127dd473Swhl739.Cm resetlog
738127dd473Swhl739command.
739127dd473Swhl739.Pp
740127dd473Swhl739Note: logging is done after all other packet matching conditions
741127dd473Swhl739have been successfully verified, and before performing the final
742127dd473Swhl739action (accept, deny, etc.) on the packet.
743127dd473Swhl739.It Cm tag Ar number
744127dd473Swhl739When a packet matches a rule with the
745127dd473Swhl739.Cm tag
746127dd473Swhl739keyword, the numeric tag for the given
747127dd473Swhl739.Ar number
748127dd473Swhl739in the range 1..65534 will be attached to the packet.
749127dd473Swhl739The tag acts as an internal marker (it is not sent out over
750127dd473Swhl739the wire) that can be used to identify these packets later on.
751127dd473Swhl739This can be used, for example, to provide trust between interfaces
752127dd473Swhl739and to start doing policy-based filtering.
753127dd473Swhl739A packet can have multiple tags at the same time.
754127dd473Swhl739Tags are "sticky", meaning once a tag is applied to a packet by a
755127dd473Swhl739matching rule it exists until explicit removal.
756127dd473Swhl739Tags are kept with the packet everywhere within the kernel, but are
757127dd473Swhl739lost when packet leaves the kernel, for example, on transmitting
758127dd473Swhl739packet out to the network or sending packet to a
759127dd473Swhl739.Xr divert 4
760127dd473Swhl739socket.
761127dd473Swhl739.Pp
762127dd473Swhl739To check for previously applied tags, use the
763127dd473Swhl739.Cm tagged
764127dd473Swhl739rule option.
765127dd473Swhl739To delete previously applied tag, use the
766127dd473Swhl739.Cm untag
767127dd473Swhl739keyword.
768127dd473Swhl739.Pp
769127dd473Swhl739Note: since tags are kept with the packet everywhere in kernelspace,
770127dd473Swhl739they can be set and unset anywhere in the kernel network subsystem
771127dd473Swhl739(using the
772127dd473Swhl739.Xr mbuf_tags 9
773127dd473Swhl739facility), not only by means of the
774127dd473Swhl739.Xr ipfw 4
775127dd473Swhl739.Cm tag
776127dd473Swhl739and
777127dd473Swhl739.Cm untag
778127dd473Swhl739keywords.
779127dd473Swhl739For example, there can be a specialized
780127dd473Swhl739.Xr netgraph 4
781127dd473Swhl739node doing traffic analyzing and tagging for later inspecting
782127dd473Swhl739in firewall.
783127dd473Swhl739.It Cm untag Ar number
784127dd473Swhl739When a packet matches a rule with the
785127dd473Swhl739.Cm untag
786127dd473Swhl739keyword, the tag with the number
787127dd473Swhl739.Ar number
788127dd473Swhl739is searched among the tags attached to this packet and,
789127dd473Swhl739if found, removed from it.
790127dd473Swhl739Other tags bound to packet, if present, are left untouched.
791127dd473Swhl739.It Cm altq Ar queue
792127dd473Swhl739When a packet matches a rule with the
793127dd473Swhl739.Cm altq
794127dd473Swhl739keyword, the ALTQ identifier for the given
795127dd473Swhl739.Ar queue
796127dd473Swhl739(see
797127dd473Swhl739.Xr altq 4 )
798127dd473Swhl739will be attached.
799127dd473Swhl739Note that this ALTQ tag is only meaningful for packets going "out" of IPFW,
800127dd473Swhl739and not being rejected or going to divert sockets.
801127dd473Swhl739Note that if there is insufficient memory at the time the packet is
802127dd473Swhl739processed, it will not be tagged, so it is wise to make your ALTQ
803127dd473Swhl739"default" queue policy account for this.
804127dd473Swhl739If multiple
805127dd473Swhl739.Cm altq
806127dd473Swhl739rules match a single packet, only the first one adds the ALTQ classification
807127dd473Swhl739tag.
808127dd473Swhl739In doing so, traffic may be shaped by using
809127dd473Swhl739.Cm count Cm altq Ar queue
810127dd473Swhl739rules for classification early in the ruleset, then later applying
811127dd473Swhl739the filtering decision.
812127dd473Swhl739For example,
813127dd473Swhl739.Cm check-state
814127dd473Swhl739and
815127dd473Swhl739.Cm keep-state
816127dd473Swhl739rules may come later and provide the actual filtering decisions in
817127dd473Swhl739addition to the fallback ALTQ tag.
818127dd473Swhl739.Pp
819127dd473Swhl739You must run
820127dd473Swhl739.Xr pfctl 8
821127dd473Swhl739to set up the queues before IPFW will be able to look them up by name,
822127dd473Swhl739and if the ALTQ disciplines are rearranged, the rules in containing the
823127dd473Swhl739queue identifiers in the kernel will likely have gone stale and need
824127dd473Swhl739to be reloaded.
825127dd473Swhl739Stale queue identifiers will probably result in misclassification.
826127dd473Swhl739.Pp
827127dd473Swhl739All system ALTQ processing can be turned on or off via
828127dd473Swhl739.Nm
829127dd473Swhl739.Cm enable Ar altq
830127dd473Swhl739and
831127dd473Swhl739.Nm
832127dd473Swhl739.Cm disable Ar altq .
833127dd473Swhl739The usage of
834127dd473Swhl739.Va net.inet.ip.fw.one_pass
835127dd473Swhl739is irrelevant to ALTQ traffic shaping, as the actual rule action is followed
836127dd473Swhl739always after adding an ALTQ tag.
837127dd473Swhl739.El
838127dd473Swhl739.Ss RULE ACTIONS
839127dd473Swhl739A rule can be associated with one of the following actions, which
840127dd473Swhl739will be executed when the packet matches the body of the rule.
841127dd473Swhl739.Bl -tag -width indent
842127dd473Swhl739.It Cm allow | accept | pass | permit
843127dd473Swhl739Allow packets that match rule.
844127dd473Swhl739The search terminates.
845*22ce4affSfengbojiang.It Cm check-state Op Ar :flowname | Cm :any
846127dd473Swhl739Checks the packet against the dynamic ruleset.
847127dd473Swhl739If a match is found, execute the action associated with
848127dd473Swhl739the rule which generated this dynamic rule, otherwise
849127dd473Swhl739move to the next rule.
850127dd473Swhl739.br
851127dd473Swhl739.Cm Check-state
852127dd473Swhl739rules do not have a body.
853127dd473Swhl739If no
854127dd473Swhl739.Cm check-state
855127dd473Swhl739rule is found, the dynamic ruleset is checked at the first
856127dd473Swhl739.Cm keep-state
857127dd473Swhl739or
858127dd473Swhl739.Cm limit
859127dd473Swhl739rule.
860*22ce4affSfengbojiangThe
861*22ce4affSfengbojiang.Ar :flowname
862*22ce4affSfengbojiangis symbolic name assigned to dynamic rule by
863*22ce4affSfengbojiang.Cm keep-state
864*22ce4affSfengbojiangopcode.
865*22ce4affSfengbojiangThe special flowname
866*22ce4affSfengbojiang.Cm :any
867*22ce4affSfengbojiangcan be used to ignore states flowname when matching.
868*22ce4affSfengbojiangThe
869*22ce4affSfengbojiang.Cm :default
870*22ce4affSfengbojiangkeyword is special name used for compatibility with old rulesets.
871127dd473Swhl739.It Cm count
872127dd473Swhl739Update counters for all packets that match rule.
873127dd473Swhl739The search continues with the next rule.
874127dd473Swhl739.It Cm deny | drop
875127dd473Swhl739Discard packets that match this rule.
876127dd473Swhl739The search terminates.
877127dd473Swhl739.It Cm divert Ar port
878127dd473Swhl739Divert packets that match this rule to the
879127dd473Swhl739.Xr divert 4
880127dd473Swhl739socket bound to port
881127dd473Swhl739.Ar port .
882127dd473Swhl739The search terminates.
883127dd473Swhl739.It Cm fwd | forward Ar ipaddr | tablearg Ns Op , Ns Ar port
884127dd473Swhl739Change the next-hop on matching packets to
885127dd473Swhl739.Ar ipaddr ,
886127dd473Swhl739which can be an IP address or a host name.
887*22ce4affSfengbojiangThe next hop can also be supplied by the last table
888127dd473Swhl739looked up for the packet by using the
889127dd473Swhl739.Cm tablearg
890127dd473Swhl739keyword instead of an explicit address.
891127dd473Swhl739The search terminates if this rule matches.
892127dd473Swhl739.Pp
893127dd473Swhl739If
894127dd473Swhl739.Ar ipaddr
895127dd473Swhl739is a local address, then matching packets will be forwarded to
896127dd473Swhl739.Ar port
897127dd473Swhl739(or the port number in the packet if one is not specified in the rule)
898127dd473Swhl739on the local machine.
899127dd473Swhl739.br
900127dd473Swhl739If
901127dd473Swhl739.Ar ipaddr
902127dd473Swhl739is not a local address, then the port number
903127dd473Swhl739(if specified) is ignored, and the packet will be
904127dd473Swhl739forwarded to the remote address, using the route as found in
905127dd473Swhl739the local routing table for that IP.
906127dd473Swhl739.br
907127dd473Swhl739A
908127dd473Swhl739.Ar fwd
909127dd473Swhl739rule will not match layer-2 packets (those received
910127dd473Swhl739on ether_input, ether_output, or bridged).
911127dd473Swhl739.br
912127dd473Swhl739The
913127dd473Swhl739.Cm fwd
914127dd473Swhl739action does not change the contents of the packet at all.
915127dd473Swhl739In particular, the destination address remains unmodified, so
916127dd473Swhl739packets forwarded to another system will usually be rejected by that system
917127dd473Swhl739unless there is a matching rule on that system to capture them.
918127dd473Swhl739For packets forwarded locally,
919127dd473Swhl739the local address of the socket will be
920127dd473Swhl739set to the original destination address of the packet.
921127dd473Swhl739This makes the
922127dd473Swhl739.Xr netstat 1
923127dd473Swhl739entry look rather weird but is intended for
924127dd473Swhl739use with transparent proxy servers.
925127dd473Swhl739.It Cm nat Ar nat_nr | tablearg
926127dd473Swhl739Pass packet to a
927127dd473Swhl739nat instance
928127dd473Swhl739(for network address translation, address redirect, etc.):
929127dd473Swhl739see the
930127dd473Swhl739.Sx NETWORK ADDRESS TRANSLATION (NAT)
931127dd473Swhl739Section for further information.
932*22ce4affSfengbojiang.It Cm nat64lsn Ar name
933*22ce4affSfengbojiangPass packet to a stateful NAT64 instance (for IPv6/IPv4 network address and
934*22ce4affSfengbojiangprotocol translation): see the
935*22ce4affSfengbojiang.Sx IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
936*22ce4affSfengbojiangSection for further information.
937*22ce4affSfengbojiang.It Cm nat64stl Ar name
938*22ce4affSfengbojiangPass packet to a stateless NAT64 instance (for IPv6/IPv4 network address and
939*22ce4affSfengbojiangprotocol translation): see the
940*22ce4affSfengbojiang.Sx IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
941*22ce4affSfengbojiangSection for further information.
942*22ce4affSfengbojiang.It Cm nat64clat Ar name
943*22ce4affSfengbojiangPass packet to a CLAT NAT64 instance (for client-side IPv6/IPv4 network address and
944*22ce4affSfengbojiangprotocol translation): see the
945*22ce4affSfengbojiang.Sx IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
946*22ce4affSfengbojiangSection for further information.
947*22ce4affSfengbojiang.It Cm nptv6 Ar name
948*22ce4affSfengbojiangPass packet to a NPTv6 instance (for IPv6-to-IPv6 network prefix translation):
949*22ce4affSfengbojiangsee the
950*22ce4affSfengbojiang.Sx IPv6-to-IPv6 NETWORK PREFIX TRANSLATION (NPTv6)
951*22ce4affSfengbojiangSection for further information.
952127dd473Swhl739.It Cm pipe Ar pipe_nr
953127dd473Swhl739Pass packet to a
954127dd473Swhl739.Nm dummynet
955127dd473Swhl739.Dq pipe
956127dd473Swhl739(for bandwidth limitation, delay, etc.).
957127dd473Swhl739See the
958127dd473Swhl739.Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
959127dd473Swhl739Section for further information.
960127dd473Swhl739The search terminates; however, on exit from the pipe and if
961127dd473Swhl739the
962127dd473Swhl739.Xr sysctl 8
963127dd473Swhl739variable
964127dd473Swhl739.Va net.inet.ip.fw.one_pass
965127dd473Swhl739is not set, the packet is passed again to the firewall code
966127dd473Swhl739starting from the next rule.
967127dd473Swhl739.It Cm queue Ar queue_nr
968127dd473Swhl739Pass packet to a
969127dd473Swhl739.Nm dummynet
970127dd473Swhl739.Dq queue
971127dd473Swhl739(for bandwidth limitation using WF2Q+).
972127dd473Swhl739.It Cm reject
973127dd473Swhl739(Deprecated).
974127dd473Swhl739Synonym for
975127dd473Swhl739.Cm unreach host .
976127dd473Swhl739.It Cm reset
977127dd473Swhl739Discard packets that match this rule, and if the
978127dd473Swhl739packet is a TCP packet, try to send a TCP reset (RST) notice.
979127dd473Swhl739The search terminates.
980127dd473Swhl739.It Cm reset6
981127dd473Swhl739Discard packets that match this rule, and if the
982127dd473Swhl739packet is a TCP packet, try to send a TCP reset (RST) notice.
983127dd473Swhl739The search terminates.
984127dd473Swhl739.It Cm skipto Ar number | tablearg
985127dd473Swhl739Skip all subsequent rules numbered less than
986127dd473Swhl739.Ar number .
987127dd473Swhl739The search continues with the first rule numbered
988127dd473Swhl739.Ar number
989127dd473Swhl739or higher.
990127dd473Swhl739It is possible to use the
991127dd473Swhl739.Cm tablearg
992127dd473Swhl739keyword with a skipto for a
993127dd473Swhl739.Em computed
994*22ce4affSfengbojiangskipto.
995*22ce4affSfengbojiangSkipto may work either in O(log(N)) or in O(1) depending
996127dd473Swhl739on amount of memory and/or sysctl variables.
997127dd473Swhl739See the
998127dd473Swhl739.Sx SYSCTL VARIABLES
999127dd473Swhl739section for more details.
1000127dd473Swhl739.It Cm call Ar number | tablearg
1001127dd473Swhl739The current rule number is saved in the internal stack and
1002127dd473Swhl739ruleset processing continues with the first rule numbered
1003127dd473Swhl739.Ar number
1004127dd473Swhl739or higher.
1005127dd473Swhl739If later a rule with the
1006127dd473Swhl739.Cm return
1007127dd473Swhl739action is encountered, the processing returns to the first rule
1008127dd473Swhl739with number of this
1009127dd473Swhl739.Cm call
1010127dd473Swhl739rule plus one or higher
1011127dd473Swhl739(the same behaviour as with packets returning from
1012127dd473Swhl739.Xr divert 4
1013127dd473Swhl739socket after a
1014127dd473Swhl739.Cm divert
1015127dd473Swhl739action).
1016127dd473Swhl739This could be used to make somewhat like an assembly language
1017127dd473Swhl739.Dq subroutine
1018127dd473Swhl739calls to rules with common checks for different interfaces, etc.
1019127dd473Swhl739.Pp
1020127dd473Swhl739Rule with any number could be called, not just forward jumps as with
1021127dd473Swhl739.Cm skipto .
1022127dd473Swhl739So, to prevent endless loops in case of mistakes, both
1023127dd473Swhl739.Cm call
1024127dd473Swhl739and
1025127dd473Swhl739.Cm return
1026127dd473Swhl739actions don't do any jumps and simply go to the next rule if memory
1027127dd473Swhl739cannot be allocated or stack overflowed/underflowed.
1028127dd473Swhl739.Pp
1029127dd473Swhl739Internally stack for rule numbers is implemented using
1030127dd473Swhl739.Xr mbuf_tags 9
1031127dd473Swhl739facility and currently has size of 16 entries.
1032127dd473Swhl739As mbuf tags are lost when packet leaves the kernel,
1033127dd473Swhl739.Cm divert
1034127dd473Swhl739should not be used in subroutines to avoid endless loops
1035127dd473Swhl739and other undesired effects.
1036127dd473Swhl739.It Cm return
1037127dd473Swhl739Takes rule number saved to internal stack by the last
1038127dd473Swhl739.Cm call
1039127dd473Swhl739action and returns ruleset processing to the first rule
1040127dd473Swhl739with number greater than number of corresponding
1041127dd473Swhl739.Cm call
1042127dd473Swhl739rule.
1043127dd473Swhl739See description of the
1044127dd473Swhl739.Cm call
1045127dd473Swhl739action for more details.
1046127dd473Swhl739.Pp
1047127dd473Swhl739Note that
1048127dd473Swhl739.Cm return
1049127dd473Swhl739rules usually end a
1050127dd473Swhl739.Dq subroutine
1051127dd473Swhl739and thus are unconditional, but
1052127dd473Swhl739.Nm
1053127dd473Swhl739command-line utility currently requires every action except
1054127dd473Swhl739.Cm check-state
1055127dd473Swhl739to have body.
1056127dd473Swhl739While it is sometimes useful to return only on some packets,
1057127dd473Swhl739usually you want to print just
1058127dd473Swhl739.Dq return
1059127dd473Swhl739for readability.
1060127dd473Swhl739A workaround for this is to use new syntax and
1061127dd473Swhl739.Fl c
1062127dd473Swhl739switch:
1063127dd473Swhl739.Bd -literal -offset indent
1064127dd473Swhl739# Add a rule without actual body
1065127dd473Swhl739ipfw add 2999 return via any
1066127dd473Swhl739
1067127dd473Swhl739# List rules without "from any to any" part
1068127dd473Swhl739ipfw -c list
1069127dd473Swhl739.Ed
1070127dd473Swhl739.Pp
1071127dd473Swhl739This cosmetic annoyance may be fixed in future releases.
1072127dd473Swhl739.It Cm tee Ar port
1073127dd473Swhl739Send a copy of packets matching this rule to the
1074127dd473Swhl739.Xr divert 4
1075127dd473Swhl739socket bound to port
1076127dd473Swhl739.Ar port .
1077127dd473Swhl739The search continues with the next rule.
1078127dd473Swhl739.It Cm unreach Ar code
1079127dd473Swhl739Discard packets that match this rule, and try to send an ICMP
1080127dd473Swhl739unreachable notice with code
1081127dd473Swhl739.Ar code ,
1082127dd473Swhl739where
1083127dd473Swhl739.Ar code
1084127dd473Swhl739is a number from 0 to 255, or one of these aliases:
1085127dd473Swhl739.Cm net , host , protocol , port ,
1086127dd473Swhl739.Cm needfrag , srcfail , net-unknown , host-unknown ,
1087127dd473Swhl739.Cm isolated , net-prohib , host-prohib , tosnet ,
1088127dd473Swhl739.Cm toshost , filter-prohib , host-precedence
1089127dd473Swhl739or
1090127dd473Swhl739.Cm precedence-cutoff .
1091127dd473Swhl739The search terminates.
1092127dd473Swhl739.It Cm unreach6 Ar code
1093127dd473Swhl739Discard packets that match this rule, and try to send an ICMPv6
1094127dd473Swhl739unreachable notice with code
1095127dd473Swhl739.Ar code ,
1096127dd473Swhl739where
1097127dd473Swhl739.Ar code
1098127dd473Swhl739is a number from 0, 1, 3 or 4, or one of these aliases:
1099127dd473Swhl739.Cm no-route, admin-prohib, address
1100127dd473Swhl739or
1101127dd473Swhl739.Cm port .
1102127dd473Swhl739The search terminates.
1103127dd473Swhl739.It Cm netgraph Ar cookie
1104127dd473Swhl739Divert packet into netgraph with given
1105127dd473Swhl739.Ar cookie .
1106127dd473Swhl739The search terminates.
1107127dd473Swhl739If packet is later returned from netgraph it is either
1108127dd473Swhl739accepted or continues with the next rule, depending on
1109127dd473Swhl739.Va net.inet.ip.fw.one_pass
1110127dd473Swhl739sysctl variable.
1111127dd473Swhl739.It Cm ngtee Ar cookie
1112127dd473Swhl739A copy of packet is diverted into netgraph, original
1113127dd473Swhl739packet continues with the next rule.
1114127dd473Swhl739See
1115127dd473Swhl739.Xr ng_ipfw 4
1116127dd473Swhl739for more information on
1117127dd473Swhl739.Cm netgraph
1118127dd473Swhl739and
1119127dd473Swhl739.Cm ngtee
1120127dd473Swhl739actions.
1121127dd473Swhl739.It Cm setfib Ar fibnum | tablearg
1122127dd473Swhl739The packet is tagged so as to use the FIB (routing table)
1123127dd473Swhl739.Ar fibnum
1124127dd473Swhl739in any subsequent forwarding decisions.
1125127dd473Swhl739In the current implementation, this is limited to the values 0 through 15, see
1126127dd473Swhl739.Xr setfib 2 .
1127127dd473Swhl739Processing continues at the next rule.
1128127dd473Swhl739It is possible to use the
1129127dd473Swhl739.Cm tablearg
1130127dd473Swhl739keyword with setfib.
1131127dd473Swhl739If the tablearg value is not within the compiled range of fibs,
1132127dd473Swhl739the packet's fib is set to 0.
1133127dd473Swhl739.It Cm setdscp Ar DSCP | number | tablearg
1134127dd473Swhl739Set specified DiffServ codepoint for an IPv4/IPv6 packet.
1135127dd473Swhl739Processing continues at the next rule.
1136127dd473Swhl739Supported values are:
1137127dd473Swhl739.Pp
1138*22ce4affSfengbojiang.Cm cs0
1139127dd473Swhl739.Pq Dv 000000 ,
1140*22ce4affSfengbojiang.Cm cs1
1141127dd473Swhl739.Pq Dv 001000 ,
1142*22ce4affSfengbojiang.Cm cs2
1143127dd473Swhl739.Pq Dv 010000 ,
1144*22ce4affSfengbojiang.Cm cs3
1145127dd473Swhl739.Pq Dv 011000 ,
1146*22ce4affSfengbojiang.Cm cs4
1147127dd473Swhl739.Pq Dv 100000 ,
1148*22ce4affSfengbojiang.Cm cs5
1149127dd473Swhl739.Pq Dv 101000 ,
1150*22ce4affSfengbojiang.Cm cs6
1151127dd473Swhl739.Pq Dv 110000 ,
1152*22ce4affSfengbojiang.Cm cs7
1153127dd473Swhl739.Pq Dv 111000 ,
1154*22ce4affSfengbojiang.Cm af11
1155127dd473Swhl739.Pq Dv 001010 ,
1156*22ce4affSfengbojiang.Cm af12
1157127dd473Swhl739.Pq Dv 001100 ,
1158*22ce4affSfengbojiang.Cm af13
1159127dd473Swhl739.Pq Dv 001110 ,
1160*22ce4affSfengbojiang.Cm af21
1161127dd473Swhl739.Pq Dv 010010 ,
1162*22ce4affSfengbojiang.Cm af22
1163127dd473Swhl739.Pq Dv 010100 ,
1164*22ce4affSfengbojiang.Cm af23
1165127dd473Swhl739.Pq Dv 010110 ,
1166*22ce4affSfengbojiang.Cm af31
1167127dd473Swhl739.Pq Dv 011010 ,
1168*22ce4affSfengbojiang.Cm af32
1169127dd473Swhl739.Pq Dv 011100 ,
1170*22ce4affSfengbojiang.Cm af33
1171127dd473Swhl739.Pq Dv 011110 ,
1172*22ce4affSfengbojiang.Cm af41
1173127dd473Swhl739.Pq Dv 100010 ,
1174*22ce4affSfengbojiang.Cm af42
1175127dd473Swhl739.Pq Dv 100100 ,
1176*22ce4affSfengbojiang.Cm af43
1177127dd473Swhl739.Pq Dv 100110 ,
1178*22ce4affSfengbojiang.Cm ef
1179127dd473Swhl739.Pq Dv 101110 ,
1180*22ce4affSfengbojiang.Cm be
1181127dd473Swhl739.Pq Dv 000000 .
1182*22ce4affSfengbojiangAdditionally, DSCP value can be specified by number (0..63).
1183127dd473Swhl739It is also possible to use the
1184127dd473Swhl739.Cm tablearg
1185127dd473Swhl739keyword with setdscp.
1186*22ce4affSfengbojiangIf the tablearg value is not within the 0..63 range, lower 6 bits of supplied
1187127dd473Swhl739value are used.
1188*22ce4affSfengbojiang.It Cm tcp-setmss Ar mss
1189*22ce4affSfengbojiangSet the Maximum Segment Size (MSS) in the TCP segment to value
1190*22ce4affSfengbojiang.Ar mss .
1191*22ce4affSfengbojiangThe kernel module
1192*22ce4affSfengbojiang.Cm ipfw_pmod
1193*22ce4affSfengbojiangshould be loaded or kernel should have
1194*22ce4affSfengbojiang.Cm options IPFIREWALL_PMOD
1195*22ce4affSfengbojiangto be able use this action.
1196*22ce4affSfengbojiangThis command does not change a packet if original MSS value is lower than
1197*22ce4affSfengbojiangspecified value.
1198*22ce4affSfengbojiangBoth TCP over IPv4 and over IPv6 are supported.
1199*22ce4affSfengbojiangRegardless of matched a packet or not by the
1200*22ce4affSfengbojiang.Cm tcp-setmss
1201*22ce4affSfengbojiangrule, the search continues with the next rule.
1202127dd473Swhl739.It Cm reass
1203*22ce4affSfengbojiangQueue and reassemble IPv4 fragments.
1204127dd473Swhl739If the packet is not fragmented, counters are updated and
1205127dd473Swhl739processing continues with the next rule.
1206127dd473Swhl739If the packet is the last logical fragment, the packet is reassembled and, if
1207127dd473Swhl739.Va net.inet.ip.fw.one_pass
1208127dd473Swhl739is set to 0, processing continues with the next rule.
1209127dd473Swhl739Otherwise, the packet is allowed to pass and the search terminates.
1210127dd473Swhl739If the packet is a fragment in the middle of a logical group of fragments,
1211127dd473Swhl739it is consumed and
1212127dd473Swhl739processing stops immediately.
1213127dd473Swhl739.Pp
1214127dd473Swhl739Fragment handling can be tuned via
1215127dd473Swhl739.Va net.inet.ip.maxfragpackets
1216127dd473Swhl739and
1217127dd473Swhl739.Va net.inet.ip.maxfragsperpacket
1218127dd473Swhl739which limit, respectively, the maximum number of processable
1219127dd473Swhl739fragments (default: 800) and
1220127dd473Swhl739the maximum number of fragments per packet (default: 16).
1221127dd473Swhl739.Pp
1222127dd473Swhl739NOTA BENE: since fragments do not contain port numbers,
1223127dd473Swhl739they should be avoided with the
1224127dd473Swhl739.Nm reass
1225127dd473Swhl739rule.
1226127dd473Swhl739Alternatively, direction-based (like
1227127dd473Swhl739.Nm in
1228127dd473Swhl739/
1229127dd473Swhl739.Nm out
1230127dd473Swhl739) and source-based (like
1231127dd473Swhl739.Nm via
1232127dd473Swhl739) match patterns can be used to select fragments.
1233127dd473Swhl739.Pp
1234127dd473Swhl739Usually a simple rule like:
1235127dd473Swhl739.Bd -literal -offset indent
1236127dd473Swhl739# reassemble incoming fragments
1237127dd473Swhl739ipfw add reass all from any to any in
1238127dd473Swhl739.Ed
1239127dd473Swhl739.Pp
1240127dd473Swhl739is all you need at the beginning of your ruleset.
1241*22ce4affSfengbojiang.It Cm abort
1242*22ce4affSfengbojiangDiscard packets that match this rule, and if the packet is an SCTP packet,
1243*22ce4affSfengbojiangtry to send an SCTP packet containing an ABORT chunk.
1244*22ce4affSfengbojiangThe search terminates.
1245*22ce4affSfengbojiang.It Cm abort6
1246*22ce4affSfengbojiangDiscard packets that match this rule, and if the packet is an SCTP packet,
1247*22ce4affSfengbojiangtry to send an SCTP packet containing an ABORT chunk.
1248*22ce4affSfengbojiangThe search terminates.
1249127dd473Swhl739.El
1250127dd473Swhl739.Ss RULE BODY
1251127dd473Swhl739The body of a rule contains zero or more patterns (such as
1252127dd473Swhl739specific source and destination addresses or ports,
1253127dd473Swhl739protocol options, incoming or outgoing interfaces, etc.)
1254127dd473Swhl739that the packet must match in order to be recognised.
1255127dd473Swhl739In general, the patterns are connected by (implicit)
1256127dd473Swhl739.Cm and
1257127dd473Swhl739operators -- i.e., all must match in order for the
1258127dd473Swhl739rule to match.
1259127dd473Swhl739Individual patterns can be prefixed by the
1260127dd473Swhl739.Cm not
1261127dd473Swhl739operator to reverse the result of the match, as in
1262127dd473Swhl739.Pp
1263127dd473Swhl739.Dl "ipfw add 100 allow ip from not 1.2.3.4 to any"
1264127dd473Swhl739.Pp
1265127dd473Swhl739Additionally, sets of alternative match patterns
1266127dd473Swhl739.Pq Em or-blocks
1267127dd473Swhl739can be constructed by putting the patterns in
1268127dd473Swhl739lists enclosed between parentheses ( ) or braces { }, and
1269127dd473Swhl739using the
1270127dd473Swhl739.Cm or
1271127dd473Swhl739operator as follows:
1272127dd473Swhl739.Pp
1273127dd473Swhl739.Dl "ipfw add 100 allow ip from { x or not y or z } to any"
1274127dd473Swhl739.Pp
1275127dd473Swhl739Only one level of parentheses is allowed.
1276127dd473Swhl739Beware that most shells have special meanings for parentheses
1277127dd473Swhl739or braces, so it is advisable to put a backslash \\ in front of them
1278127dd473Swhl739to prevent such interpretations.
1279127dd473Swhl739.Pp
1280127dd473Swhl739The body of a rule must in general include a source and destination
1281127dd473Swhl739address specifier.
1282127dd473Swhl739The keyword
1283127dd473Swhl739.Ar any
1284127dd473Swhl739can be used in various places to specify that the content of
1285127dd473Swhl739a required field is irrelevant.
1286127dd473Swhl739.Pp
1287127dd473Swhl739The rule body has the following format:
1288127dd473Swhl739.Bd -ragged -offset indent
1289127dd473Swhl739.Op Ar proto Cm from Ar src Cm to Ar dst
1290127dd473Swhl739.Op Ar options
1291127dd473Swhl739.Ed
1292127dd473Swhl739.Pp
1293127dd473Swhl739The first part (proto from src to dst) is for backward
1294127dd473Swhl739compatibility with earlier versions of
1295127dd473Swhl739.Fx .
1296127dd473Swhl739In modern
1297127dd473Swhl739.Fx
1298127dd473Swhl739any match pattern (including MAC headers, IP protocols,
1299127dd473Swhl739addresses and ports) can be specified in the
1300127dd473Swhl739.Ar options
1301127dd473Swhl739section.
1302127dd473Swhl739.Pp
1303127dd473Swhl739Rule fields have the following meaning:
1304127dd473Swhl739.Bl -tag -width indent
1305127dd473Swhl739.It Ar proto : protocol | Cm { Ar protocol Cm or ... }
1306127dd473Swhl739.It Ar protocol : Oo Cm not Oc Ar protocol-name | protocol-number
1307127dd473Swhl739An IP protocol specified by number or name
1308127dd473Swhl739(for a complete list see
1309127dd473Swhl739.Pa /etc/protocols ) ,
1310127dd473Swhl739or one of the following keywords:
1311127dd473Swhl739.Bl -tag -width indent
1312127dd473Swhl739.It Cm ip4 | ipv4
1313127dd473Swhl739Matches IPv4 packets.
1314127dd473Swhl739.It Cm ip6 | ipv6
1315127dd473Swhl739Matches IPv6 packets.
1316127dd473Swhl739.It Cm ip | all
1317127dd473Swhl739Matches any packet.
1318127dd473Swhl739.El
1319127dd473Swhl739.Pp
1320127dd473Swhl739The
1321127dd473Swhl739.Cm ipv6
1322127dd473Swhl739in
1323127dd473Swhl739.Cm proto
1324127dd473Swhl739option will be treated as inner protocol.
1325127dd473Swhl739And, the
1326127dd473Swhl739.Cm ipv4
1327127dd473Swhl739is not available in
1328127dd473Swhl739.Cm proto
1329127dd473Swhl739option.
1330127dd473Swhl739.Pp
1331127dd473Swhl739The
1332127dd473Swhl739.Cm { Ar protocol Cm or ... }
1333127dd473Swhl739format (an
1334127dd473Swhl739.Em or-block )
1335127dd473Swhl739is provided for convenience only but its use is deprecated.
1336127dd473Swhl739.It Ar src No and Ar dst : Bro Cm addr | Cm { Ar addr Cm or ... } Brc Op Oo Cm not Oc Ar ports
1337127dd473Swhl739An address (or a list, see below)
1338127dd473Swhl739optionally followed by
1339127dd473Swhl739.Ar ports
1340127dd473Swhl739specifiers.
1341127dd473Swhl739.Pp
1342127dd473Swhl739The second format
1343127dd473Swhl739.Em ( or-block
1344127dd473Swhl739with multiple addresses) is provided for convenience only and
1345127dd473Swhl739its use is discouraged.
1346127dd473Swhl739.It Ar addr : Oo Cm not Oc Bro
1347127dd473Swhl739.Cm any | me | me6 |
1348127dd473Swhl739.Cm table Ns Pq Ar name Ns Op , Ns Ar value
1349127dd473Swhl739.Ar | addr-list | addr-set
1350127dd473Swhl739.Brc
1351127dd473Swhl739.Bl -tag -width indent
1352127dd473Swhl739.It Cm any
1353*22ce4affSfengbojiangMatches any IP address.
1354127dd473Swhl739.It Cm me
1355*22ce4affSfengbojiangMatches any IP address configured on an interface in the system.
1356127dd473Swhl739.It Cm me6
1357*22ce4affSfengbojiangMatches any IPv6 address configured on an interface in the system.
1358127dd473Swhl739The address list is evaluated at the time the packet is
1359127dd473Swhl739analysed.
1360127dd473Swhl739.It Cm table Ns Pq Ar name Ns Op , Ns Ar value
1361127dd473Swhl739Matches any IPv4 or IPv6 address for which an entry exists in the lookup table
1362127dd473Swhl739.Ar number .
1363127dd473Swhl739If an optional 32-bit unsigned
1364127dd473Swhl739.Ar value
1365127dd473Swhl739is also specified, an entry will match only if it has this value.
1366127dd473Swhl739See the
1367127dd473Swhl739.Sx LOOKUP TABLES
1368127dd473Swhl739section below for more information on lookup tables.
1369127dd473Swhl739.El
1370127dd473Swhl739.It Ar addr-list : ip-addr Ns Op Ns , Ns Ar addr-list
1371127dd473Swhl739.It Ar ip-addr :
1372127dd473Swhl739A host or subnet address specified in one of the following ways:
1373127dd473Swhl739.Bl -tag -width indent
1374127dd473Swhl739.It Ar numeric-ip | hostname
1375127dd473Swhl739Matches a single IPv4 address, specified as dotted-quad or a hostname.
1376127dd473Swhl739Hostnames are resolved at the time the rule is added to the firewall list.
1377127dd473Swhl739.It Ar addr Ns / Ns Ar masklen
1378127dd473Swhl739Matches all addresses with base
1379127dd473Swhl739.Ar addr
1380127dd473Swhl739(specified as an IP address, a network number, or a hostname)
1381127dd473Swhl739and mask width of
1382127dd473Swhl739.Cm masklen
1383127dd473Swhl739bits.
1384127dd473Swhl739As an example, 1.2.3.4/25 or 1.2.3.0/25 will match
1385127dd473Swhl739all IP numbers from 1.2.3.0 to 1.2.3.127 .
1386127dd473Swhl739.It Ar addr Ns : Ns Ar mask
1387127dd473Swhl739Matches all addresses with base
1388127dd473Swhl739.Ar addr
1389127dd473Swhl739(specified as an IP address, a network number, or a hostname)
1390127dd473Swhl739and the mask of
1391127dd473Swhl739.Ar mask ,
1392127dd473Swhl739specified as a dotted quad.
1393127dd473Swhl739As an example, 1.2.3.4:255.0.255.0 or 1.0.3.0:255.0.255.0 will match
1394127dd473Swhl7391.*.3.*.
1395127dd473Swhl739This form is advised only for non-contiguous
1396127dd473Swhl739masks.
1397127dd473Swhl739It is better to resort to the
1398127dd473Swhl739.Ar addr Ns / Ns Ar masklen
1399127dd473Swhl739format for contiguous masks, which is more compact and less
1400127dd473Swhl739error-prone.
1401127dd473Swhl739.El
1402127dd473Swhl739.It Ar addr-set : addr Ns Oo Ns / Ns Ar masklen Oc Ns Cm { Ns Ar list Ns Cm }
1403127dd473Swhl739.It Ar list : Bro Ar num | num-num Brc Ns Op Ns , Ns Ar list
1404127dd473Swhl739Matches all addresses with base address
1405127dd473Swhl739.Ar addr
1406127dd473Swhl739(specified as an IP address, a network number, or a hostname)
1407127dd473Swhl739and whose last byte is in the list between braces { } .
1408127dd473Swhl739Note that there must be no spaces between braces and
1409127dd473Swhl739numbers (spaces after commas are allowed).
1410127dd473Swhl739Elements of the list can be specified as single entries
1411127dd473Swhl739or ranges.
1412127dd473Swhl739The
1413127dd473Swhl739.Ar masklen
1414127dd473Swhl739field is used to limit the size of the set of addresses,
1415127dd473Swhl739and can have any value between 24 and 32.
1416127dd473Swhl739If not specified,
1417127dd473Swhl739it will be assumed as 24.
1418127dd473Swhl739.br
1419127dd473Swhl739This format is particularly useful to handle sparse address sets
1420127dd473Swhl739within a single rule.
1421127dd473Swhl739Because the matching occurs using a
1422127dd473Swhl739bitmask, it takes constant time and dramatically reduces
1423127dd473Swhl739the complexity of rulesets.
1424127dd473Swhl739.br
1425127dd473Swhl739As an example, an address specified as 1.2.3.4/24{128,35-55,89}
1426127dd473Swhl739or 1.2.3.0/24{128,35-55,89}
1427127dd473Swhl739will match the following IP addresses:
1428127dd473Swhl739.br
1429127dd473Swhl7391.2.3.128, 1.2.3.35 to 1.2.3.55, 1.2.3.89 .
1430127dd473Swhl739.It Ar addr6-list : ip6-addr Ns Op Ns , Ns Ar addr6-list
1431127dd473Swhl739.It Ar ip6-addr :
1432127dd473Swhl739A host or subnet specified one of the following ways:
1433127dd473Swhl739.Bl -tag -width indent
1434127dd473Swhl739.It Ar numeric-ip | hostname
1435127dd473Swhl739Matches a single IPv6 address as allowed by
1436127dd473Swhl739.Xr inet_pton 3
1437127dd473Swhl739or a hostname.
1438127dd473Swhl739Hostnames are resolved at the time the rule is added to the firewall
1439127dd473Swhl739list.
1440127dd473Swhl739.It Ar addr Ns / Ns Ar masklen
1441127dd473Swhl739Matches all IPv6 addresses with base
1442127dd473Swhl739.Ar addr
1443127dd473Swhl739(specified as allowed by
1444*22ce4affSfengbojiang.Xr inet_pton 3
1445127dd473Swhl739or a hostname)
1446127dd473Swhl739and mask width of
1447127dd473Swhl739.Cm masklen
1448127dd473Swhl739bits.
1449*22ce4affSfengbojiang.It Ar addr Ns / Ns Ar mask
1450*22ce4affSfengbojiangMatches all IPv6 addresses with base
1451*22ce4affSfengbojiang.Ar addr
1452*22ce4affSfengbojiang(specified as allowed by
1453*22ce4affSfengbojiang.Xr inet_pton 3
1454*22ce4affSfengbojiangor a hostname)
1455*22ce4affSfengbojiangand the mask of
1456*22ce4affSfengbojiang.Ar mask ,
1457*22ce4affSfengbojiangspecified as allowed by
1458*22ce4affSfengbojiang.Xr inet_pton 3 .
1459*22ce4affSfengbojiangAs an example, fe::640:0:0/ffff::ffff:ffff:0:0 will match
1460*22ce4affSfengbojiangfe:*:*:*:0:640:*:*.
1461*22ce4affSfengbojiangThis form is advised only for non-contiguous
1462*22ce4affSfengbojiangmasks.
1463*22ce4affSfengbojiangIt is better to resort to the
1464*22ce4affSfengbojiang.Ar addr Ns / Ns Ar masklen
1465*22ce4affSfengbojiangformat for contiguous masks, which is more compact and less
1466*22ce4affSfengbojiangerror-prone.
1467127dd473Swhl739.El
1468127dd473Swhl739.Pp
1469127dd473Swhl739No support for sets of IPv6 addresses is provided because IPv6 addresses
1470127dd473Swhl739are typically random past the initial prefix.
1471127dd473Swhl739.It Ar ports : Bro Ar port | port Ns \&- Ns Ar port Ns Brc Ns Op , Ns Ar ports
1472*22ce4affSfengbojiangFor protocols which support port numbers (such as SCTP, TCP and UDP), optional
1473127dd473Swhl739.Cm ports
1474127dd473Swhl739may be specified as one or more ports or port ranges, separated
1475127dd473Swhl739by commas but no spaces, and an optional
1476127dd473Swhl739.Cm not
1477127dd473Swhl739operator.
1478127dd473Swhl739The
1479127dd473Swhl739.Ql \&-
1480127dd473Swhl739notation specifies a range of ports (including boundaries).
1481127dd473Swhl739.Pp
1482127dd473Swhl739Service names (from
1483127dd473Swhl739.Pa /etc/services )
1484127dd473Swhl739may be used instead of numeric port values.
1485127dd473Swhl739The length of the port list is limited to 30 ports or ranges,
1486127dd473Swhl739though one can specify larger ranges by using an
1487127dd473Swhl739.Em or-block
1488127dd473Swhl739in the
1489127dd473Swhl739.Cm options
1490127dd473Swhl739section of the rule.
1491127dd473Swhl739.Pp
1492127dd473Swhl739A backslash
1493127dd473Swhl739.Pq Ql \e
1494127dd473Swhl739can be used to escape the dash
1495127dd473Swhl739.Pq Ql -
1496127dd473Swhl739character in a service name (from a shell, the backslash must be
1497127dd473Swhl739typed twice to avoid the shell itself interpreting it as an escape
1498127dd473Swhl739character).
1499127dd473Swhl739.Pp
1500127dd473Swhl739.Dl "ipfw add count tcp from any ftp\e\e-data-ftp to any"
1501127dd473Swhl739.Pp
1502127dd473Swhl739Fragmented packets which have a non-zero offset (i.e., not the first
1503127dd473Swhl739fragment) will never match a rule which has one or more port
1504127dd473Swhl739specifications.
1505127dd473Swhl739See the
1506127dd473Swhl739.Cm frag
1507127dd473Swhl739option for details on matching fragmented packets.
1508127dd473Swhl739.El
1509127dd473Swhl739.Ss RULE OPTIONS (MATCH PATTERNS)
1510127dd473Swhl739Additional match patterns can be used within
1511127dd473Swhl739rules.
1512127dd473Swhl739Zero or more of these so-called
1513127dd473Swhl739.Em options
1514127dd473Swhl739can be present in a rule, optionally prefixed by the
1515127dd473Swhl739.Cm not
1516127dd473Swhl739operand, and possibly grouped into
1517127dd473Swhl739.Em or-blocks .
1518127dd473Swhl739.Pp
1519127dd473Swhl739The following match patterns can be used (listed in alphabetical order):
1520127dd473Swhl739.Bl -tag -width indent
1521127dd473Swhl739.It Cm // this is a comment .
1522127dd473Swhl739Inserts the specified text as a comment in the rule.
1523127dd473Swhl739Everything following // is considered as a comment and stored in the rule.
1524127dd473Swhl739You can have comment-only rules, which are listed as having a
1525127dd473Swhl739.Cm count
1526127dd473Swhl739action followed by the comment.
1527127dd473Swhl739.It Cm bridged
1528127dd473Swhl739Alias for
1529127dd473Swhl739.Cm layer2 .
1530*22ce4affSfengbojiang.It Cm defer-immediate-action | defer-action
1531*22ce4affSfengbojiangA rule with this option will not perform normal action
1532*22ce4affSfengbojiangupon a match.
1533*22ce4affSfengbojiangThis option is intended to be used with
1534*22ce4affSfengbojiang.Cm record-state
1535*22ce4affSfengbojiangor
1536*22ce4affSfengbojiang.Cm keep-state
1537*22ce4affSfengbojiangas the dynamic rule, created but ignored on match, will work
1538*22ce4affSfengbojiangas intended.
1539*22ce4affSfengbojiangRules with both
1540*22ce4affSfengbojiang.Cm record-state
1541*22ce4affSfengbojiangand
1542*22ce4affSfengbojiang.Cm defer-immediate-action
1543*22ce4affSfengbojiangcreate a dynamic rule and continue with the next rule without actually
1544*22ce4affSfengbojiangperforming the action part of this rule.
1545*22ce4affSfengbojiangWhen the rule is later activated via the state table, the action is
1546*22ce4affSfengbojiangperformed as usual.
1547127dd473Swhl739.It Cm diverted
1548127dd473Swhl739Matches only packets generated by a divert socket.
1549127dd473Swhl739.It Cm diverted-loopback
1550127dd473Swhl739Matches only packets coming from a divert socket back into the IP stack
1551127dd473Swhl739input for delivery.
1552127dd473Swhl739.It Cm diverted-output
1553127dd473Swhl739Matches only packets going from a divert socket back outward to the IP
1554127dd473Swhl739stack output for delivery.
1555127dd473Swhl739.It Cm dst-ip Ar ip-address
1556127dd473Swhl739Matches IPv4 packets whose destination IP is one of the address(es)
1557127dd473Swhl739specified as argument.
1558127dd473Swhl739.It Bro Cm dst-ip6 | dst-ipv6 Brc Ar ip6-address
1559127dd473Swhl739Matches IPv6 packets whose destination IP is one of the address(es)
1560127dd473Swhl739specified as argument.
1561127dd473Swhl739.It Cm dst-port Ar ports
1562127dd473Swhl739Matches IP packets whose destination port is one of the port(s)
1563127dd473Swhl739specified as argument.
1564127dd473Swhl739.It Cm established
1565127dd473Swhl739Matches TCP packets that have the RST or ACK bits set.
1566127dd473Swhl739.It Cm ext6hdr Ar header
1567127dd473Swhl739Matches IPv6 packets containing the extended header given by
1568127dd473Swhl739.Ar header .
1569127dd473Swhl739Supported headers are:
1570127dd473Swhl739.Pp
1571127dd473Swhl739Fragment,
1572127dd473Swhl739.Pq Cm frag ,
1573127dd473Swhl739Hop-to-hop options
1574127dd473Swhl739.Pq Cm hopopt ,
1575127dd473Swhl739any type of Routing Header
1576127dd473Swhl739.Pq Cm route ,
1577127dd473Swhl739Source routing Routing Header Type 0
1578127dd473Swhl739.Pq Cm rthdr0 ,
1579127dd473Swhl739Mobile IPv6 Routing Header Type 2
1580127dd473Swhl739.Pq Cm rthdr2 ,
1581127dd473Swhl739Destination options
1582127dd473Swhl739.Pq Cm dstopt ,
1583127dd473Swhl739IPSec authentication headers
1584127dd473Swhl739.Pq Cm ah ,
1585127dd473Swhl739and IPsec encapsulated security payload headers
1586127dd473Swhl739.Pq Cm esp .
1587127dd473Swhl739.It Cm fib Ar fibnum
1588127dd473Swhl739Matches a packet that has been tagged to use
1589127dd473Swhl739the given FIB (routing table) number.
1590127dd473Swhl739.It Cm flow Ar table Ns Pq Ar name Ns Op , Ns Ar value
1591127dd473Swhl739Search for the flow entry in lookup table
1592127dd473Swhl739.Ar name .
1593127dd473Swhl739If not found, the match fails.
1594127dd473Swhl739Otherwise, the match succeeds and
1595127dd473Swhl739.Cm tablearg
1596127dd473Swhl739is set to the value extracted from the table.
1597127dd473Swhl739.Pp
1598127dd473Swhl739This option can be useful to quickly dispatch traffic based on
1599127dd473Swhl739certain packet fields.
1600127dd473Swhl739See the
1601127dd473Swhl739.Sx LOOKUP TABLES
1602127dd473Swhl739section below for more information on lookup tables.
1603127dd473Swhl739.It Cm flow-id Ar labels
1604127dd473Swhl739Matches IPv6 packets containing any of the flow labels given in
1605127dd473Swhl739.Ar labels .
1606127dd473Swhl739.Ar labels
1607127dd473Swhl739is a comma separated list of numeric flow labels.
1608*22ce4affSfengbojiang.It Cm frag Ar spec
1609*22ce4affSfengbojiangMatches IPv4 packets whose
1610*22ce4affSfengbojiang.Cm ip_off
1611*22ce4affSfengbojiangfield contains the comma separated list of IPv4 fragmentation
1612*22ce4affSfengbojiangoptions specified in
1613*22ce4affSfengbojiang.Ar spec .
1614*22ce4affSfengbojiangThe recognized options are:
1615*22ce4affSfengbojiang.Cm df
1616*22ce4affSfengbojiang.Pq Dv don't fragment ,
1617*22ce4affSfengbojiang.Cm mf
1618*22ce4affSfengbojiang.Pq Dv more fragments ,
1619*22ce4affSfengbojiang.Cm rf
1620*22ce4affSfengbojiang.Pq Dv reserved fragment bit
1621*22ce4affSfengbojiang.Cm offset
1622*22ce4affSfengbojiang.Pq Dv non-zero fragment offset .
1623*22ce4affSfengbojiangThe absence of a particular options may be denoted
1624*22ce4affSfengbojiangwith a
1625*22ce4affSfengbojiang.Ql \&! .
1626*22ce4affSfengbojiang.Pp
1627*22ce4affSfengbojiangEmpty list of options defaults to matching on non-zero fragment offset.
1628*22ce4affSfengbojiangSuch rule would match all not the first fragment datagrams,
1629*22ce4affSfengbojiangboth IPv4 and IPv6.
1630*22ce4affSfengbojiangThis is a backward compatibility with older rulesets.
1631127dd473Swhl739.It Cm gid Ar group
1632127dd473Swhl739Matches all TCP or UDP packets sent by or received for a
1633127dd473Swhl739.Ar group .
1634127dd473Swhl739A
1635127dd473Swhl739.Ar group
1636127dd473Swhl739may be specified by name or number.
1637*22ce4affSfengbojiang.It Cm jail Ar jail
1638127dd473Swhl739Matches all TCP or UDP packets sent by or received for the
1639*22ce4affSfengbojiangjail whose ID or name is
1640*22ce4affSfengbojiang.Ar jail .
1641127dd473Swhl739.It Cm icmptypes Ar types
1642127dd473Swhl739Matches ICMP packets whose ICMP type is in the list
1643127dd473Swhl739.Ar types .
1644127dd473Swhl739The list may be specified as any combination of
1645127dd473Swhl739individual types (numeric) separated by commas.
1646127dd473Swhl739.Em Ranges are not allowed .
1647127dd473Swhl739The supported ICMP types are:
1648127dd473Swhl739.Pp
1649127dd473Swhl739echo reply
1650127dd473Swhl739.Pq Cm 0 ,
1651127dd473Swhl739destination unreachable
1652127dd473Swhl739.Pq Cm 3 ,
1653127dd473Swhl739source quench
1654127dd473Swhl739.Pq Cm 4 ,
1655127dd473Swhl739redirect
1656127dd473Swhl739.Pq Cm 5 ,
1657127dd473Swhl739echo request
1658127dd473Swhl739.Pq Cm 8 ,
1659127dd473Swhl739router advertisement
1660127dd473Swhl739.Pq Cm 9 ,
1661127dd473Swhl739router solicitation
1662127dd473Swhl739.Pq Cm 10 ,
1663127dd473Swhl739time-to-live exceeded
1664127dd473Swhl739.Pq Cm 11 ,
1665127dd473Swhl739IP header bad
1666127dd473Swhl739.Pq Cm 12 ,
1667127dd473Swhl739timestamp request
1668127dd473Swhl739.Pq Cm 13 ,
1669127dd473Swhl739timestamp reply
1670127dd473Swhl739.Pq Cm 14 ,
1671127dd473Swhl739information request
1672127dd473Swhl739.Pq Cm 15 ,
1673127dd473Swhl739information reply
1674127dd473Swhl739.Pq Cm 16 ,
1675127dd473Swhl739address mask request
1676127dd473Swhl739.Pq Cm 17
1677127dd473Swhl739and address mask reply
1678127dd473Swhl739.Pq Cm 18 .
1679127dd473Swhl739.It Cm icmp6types Ar types
1680127dd473Swhl739Matches ICMP6 packets whose ICMP6 type is in the list of
1681127dd473Swhl739.Ar types .
1682127dd473Swhl739The list may be specified as any combination of
1683127dd473Swhl739individual types (numeric) separated by commas.
1684127dd473Swhl739.Em Ranges are not allowed .
1685127dd473Swhl739.It Cm in | out
1686127dd473Swhl739Matches incoming or outgoing packets, respectively.
1687127dd473Swhl739.Cm in
1688127dd473Swhl739and
1689127dd473Swhl739.Cm out
1690127dd473Swhl739are mutually exclusive (in fact,
1691127dd473Swhl739.Cm out
1692127dd473Swhl739is implemented as
1693127dd473Swhl739.Cm not in Ns No ).
1694127dd473Swhl739.It Cm ipid Ar id-list
1695127dd473Swhl739Matches IPv4 packets whose
1696127dd473Swhl739.Cm ip_id
1697127dd473Swhl739field has value included in
1698127dd473Swhl739.Ar id-list ,
1699127dd473Swhl739which is either a single value or a list of values or ranges
1700127dd473Swhl739specified in the same way as
1701127dd473Swhl739.Ar ports .
1702127dd473Swhl739.It Cm iplen Ar len-list
1703127dd473Swhl739Matches IP packets whose total length, including header and data, is
1704127dd473Swhl739in the set
1705127dd473Swhl739.Ar len-list ,
1706127dd473Swhl739which is either a single value or a list of values or ranges
1707127dd473Swhl739specified in the same way as
1708127dd473Swhl739.Ar ports .
1709127dd473Swhl739.It Cm ipoptions Ar spec
1710127dd473Swhl739Matches packets whose IPv4 header contains the comma separated list of
1711127dd473Swhl739options specified in
1712127dd473Swhl739.Ar spec .
1713127dd473Swhl739The supported IP options are:
1714127dd473Swhl739.Pp
1715127dd473Swhl739.Cm ssrr
1716127dd473Swhl739(strict source route),
1717127dd473Swhl739.Cm lsrr
1718127dd473Swhl739(loose source route),
1719127dd473Swhl739.Cm rr
1720127dd473Swhl739(record packet route) and
1721127dd473Swhl739.Cm ts
1722127dd473Swhl739(timestamp).
1723127dd473Swhl739The absence of a particular option may be denoted
1724127dd473Swhl739with a
1725127dd473Swhl739.Ql \&! .
1726127dd473Swhl739.It Cm ipprecedence Ar precedence
1727127dd473Swhl739Matches IPv4 packets whose precedence field is equal to
1728127dd473Swhl739.Ar precedence .
1729127dd473Swhl739.It Cm ipsec
1730127dd473Swhl739Matches packets that have IPSEC history associated with them
1731127dd473Swhl739(i.e., the packet comes encapsulated in IPSEC, the kernel
1732*22ce4affSfengbojianghas IPSEC support, and can correctly decapsulate it).
1733127dd473Swhl739.Pp
1734127dd473Swhl739Note that specifying
1735127dd473Swhl739.Cm ipsec
1736127dd473Swhl739is different from specifying
1737127dd473Swhl739.Cm proto Ar ipsec
1738127dd473Swhl739as the latter will only look at the specific IP protocol field,
1739127dd473Swhl739irrespective of IPSEC kernel support and the validity of the IPSEC data.
1740127dd473Swhl739.Pp
1741127dd473Swhl739Further note that this flag is silently ignored in kernels without
1742127dd473Swhl739IPSEC support.
1743127dd473Swhl739It does not affect rule processing when given and the
1744127dd473Swhl739rules are handled as if with no
1745127dd473Swhl739.Cm ipsec
1746127dd473Swhl739flag.
1747127dd473Swhl739.It Cm iptos Ar spec
1748127dd473Swhl739Matches IPv4 packets whose
1749127dd473Swhl739.Cm tos
1750127dd473Swhl739field contains the comma separated list of
1751127dd473Swhl739service types specified in
1752127dd473Swhl739.Ar spec .
1753127dd473Swhl739The supported IP types of service are:
1754127dd473Swhl739.Pp
1755127dd473Swhl739.Cm lowdelay
1756127dd473Swhl739.Pq Dv IPTOS_LOWDELAY ,
1757127dd473Swhl739.Cm throughput
1758127dd473Swhl739.Pq Dv IPTOS_THROUGHPUT ,
1759127dd473Swhl739.Cm reliability
1760127dd473Swhl739.Pq Dv IPTOS_RELIABILITY ,
1761127dd473Swhl739.Cm mincost
1762127dd473Swhl739.Pq Dv IPTOS_MINCOST ,
1763127dd473Swhl739.Cm congestion
1764127dd473Swhl739.Pq Dv IPTOS_ECN_CE .
1765127dd473Swhl739The absence of a particular type may be denoted
1766127dd473Swhl739with a
1767127dd473Swhl739.Ql \&! .
1768127dd473Swhl739.It Cm dscp spec Ns Op , Ns Ar spec
1769127dd473Swhl739Matches IPv4/IPv6 packets whose
1770127dd473Swhl739.Cm DS
1771127dd473Swhl739field value is contained in
1772127dd473Swhl739.Ar spec
1773127dd473Swhl739mask.
1774127dd473Swhl739Multiple values can be specified via
1775127dd473Swhl739the comma separated list.
1776127dd473Swhl739Value can be one of keywords used in
1777127dd473Swhl739.Cm setdscp
1778127dd473Swhl739action or exact number.
1779127dd473Swhl739.It Cm ipttl Ar ttl-list
1780127dd473Swhl739Matches IPv4 packets whose time to live is included in
1781127dd473Swhl739.Ar ttl-list ,
1782127dd473Swhl739which is either a single value or a list of values or ranges
1783127dd473Swhl739specified in the same way as
1784127dd473Swhl739.Ar ports .
1785127dd473Swhl739.It Cm ipversion Ar ver
1786127dd473Swhl739Matches IP packets whose IP version field is
1787127dd473Swhl739.Ar ver .
1788*22ce4affSfengbojiang.It Cm keep-state Op Ar :flowname
1789127dd473Swhl739Upon a match, the firewall will create a dynamic rule, whose
1790127dd473Swhl739default behaviour is to match bidirectional traffic between
1791127dd473Swhl739source and destination IP/port using the same protocol.
1792127dd473Swhl739The rule has a limited lifetime (controlled by a set of
1793127dd473Swhl739.Xr sysctl 8
1794127dd473Swhl739variables), and the lifetime is refreshed every time a matching
1795127dd473Swhl739packet is found.
1796*22ce4affSfengbojiangThe
1797*22ce4affSfengbojiang.Ar :flowname
1798*22ce4affSfengbojiangis used to assign additional to addresses, ports and protocol parameter
1799*22ce4affSfengbojiangto dynamic rule.
1800*22ce4affSfengbojiangIt can be used for more accurate matching by
1801*22ce4affSfengbojiang.Cm check-state
1802*22ce4affSfengbojiangrule.
1803*22ce4affSfengbojiangThe
1804*22ce4affSfengbojiang.Cm :default
1805*22ce4affSfengbojiangkeyword is special name used for compatibility with old rulesets.
1806127dd473Swhl739.It Cm layer2
1807127dd473Swhl739Matches only layer2 packets, i.e., those passed to
1808127dd473Swhl739.Nm
1809*22ce4affSfengbojiangfrom
1810*22ce4affSfengbojiang.Fn ether_demux
1811*22ce4affSfengbojiangand
1812*22ce4affSfengbojiang.Fn ether_output_frame .
1813*22ce4affSfengbojiang.It Cm limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N Op Ar :flowname
1814127dd473Swhl739The firewall will only allow
1815127dd473Swhl739.Ar N
1816127dd473Swhl739connections with the same
1817127dd473Swhl739set of parameters as specified in the rule.
1818127dd473Swhl739One or more
1819127dd473Swhl739of source and destination addresses and ports can be
1820127dd473Swhl739specified.
1821127dd473Swhl739.It Cm lookup Bro Cm dst-ip | dst-port | src-ip | src-port | uid | jail Brc Ar name
1822127dd473Swhl739Search an entry in lookup table
1823127dd473Swhl739.Ar name
1824127dd473Swhl739that matches the field specified as argument.
1825127dd473Swhl739If not found, the match fails.
1826127dd473Swhl739Otherwise, the match succeeds and
1827127dd473Swhl739.Cm tablearg
1828127dd473Swhl739is set to the value extracted from the table.
1829127dd473Swhl739.Pp
1830127dd473Swhl739This option can be useful to quickly dispatch traffic based on
1831127dd473Swhl739certain packet fields.
1832127dd473Swhl739See the
1833127dd473Swhl739.Sx LOOKUP TABLES
1834127dd473Swhl739section below for more information on lookup tables.
1835127dd473Swhl739.It Cm { MAC | mac } Ar dst-mac src-mac
1836127dd473Swhl739Match packets with a given
1837127dd473Swhl739.Ar dst-mac
1838127dd473Swhl739and
1839127dd473Swhl739.Ar src-mac
1840127dd473Swhl739addresses, specified as the
1841127dd473Swhl739.Cm any
1842127dd473Swhl739keyword (matching any MAC address), or six groups of hex digits
1843127dd473Swhl739separated by colons,
1844127dd473Swhl739and optionally followed by a mask indicating the significant bits.
1845127dd473Swhl739The mask may be specified using either of the following methods:
1846127dd473Swhl739.Bl -enum -width indent
1847127dd473Swhl739.It
1848127dd473Swhl739A slash
1849127dd473Swhl739.Pq /
1850127dd473Swhl739followed by the number of significant bits.
1851127dd473Swhl739For example, an address with 33 significant bits could be specified as:
1852127dd473Swhl739.Pp
1853127dd473Swhl739.Dl "MAC 10:20:30:40:50:60/33 any"
1854127dd473Swhl739.It
1855127dd473Swhl739An ampersand
1856127dd473Swhl739.Pq &
1857127dd473Swhl739followed by a bitmask specified as six groups of hex digits separated
1858127dd473Swhl739by colons.
1859127dd473Swhl739For example, an address in which the last 16 bits are significant could
1860127dd473Swhl739be specified as:
1861127dd473Swhl739.Pp
1862127dd473Swhl739.Dl "MAC 10:20:30:40:50:60&00:00:00:00:ff:ff any"
1863127dd473Swhl739.Pp
1864127dd473Swhl739Note that the ampersand character has a special meaning in many shells
1865127dd473Swhl739and should generally be escaped.
1866127dd473Swhl739.El
1867127dd473Swhl739Note that the order of MAC addresses (destination first,
1868127dd473Swhl739source second) is
1869127dd473Swhl739the same as on the wire, but the opposite of the one used for
1870127dd473Swhl739IP addresses.
1871127dd473Swhl739.It Cm mac-type Ar mac-type
1872127dd473Swhl739Matches packets whose Ethernet Type field
1873127dd473Swhl739corresponds to one of those specified as argument.
1874127dd473Swhl739.Ar mac-type
1875127dd473Swhl739is specified in the same way as
1876127dd473Swhl739.Cm port numbers
1877127dd473Swhl739(i.e., one or more comma-separated single values or ranges).
1878127dd473Swhl739You can use symbolic names for known values such as
1879127dd473Swhl739.Em vlan , ipv4, ipv6 .
1880127dd473Swhl739Values can be entered as decimal or hexadecimal (if prefixed by 0x),
1881127dd473Swhl739and they are always printed as hexadecimal (unless the
1882127dd473Swhl739.Cm -N
1883127dd473Swhl739option is used, in which case symbolic resolution will be attempted).
1884127dd473Swhl739.It Cm proto Ar protocol
1885127dd473Swhl739Matches packets with the corresponding IP protocol.
1886*22ce4affSfengbojiang.It Cm record-state
1887*22ce4affSfengbojiangUpon a match, the firewall will create a dynamic rule as if
1888*22ce4affSfengbojiang.Cm keep-state
1889*22ce4affSfengbojiangwas specified.
1890*22ce4affSfengbojiangHowever, this option doesn't imply an implicit
1891*22ce4affSfengbojiang.Cm check-state
1892*22ce4affSfengbojiangin contrast to
1893*22ce4affSfengbojiang.Cm keep-state .
1894127dd473Swhl739.It Cm recv | xmit | via Brq Ar ifX | Ar if Ns Cm * | Ar table Ns Po Ar name Ns Oo , Ns Ar value Oc Pc | Ar ipno | Ar any
1895127dd473Swhl739Matches packets received, transmitted or going through,
1896127dd473Swhl739respectively, the interface specified by exact name
1897127dd473Swhl739.Po Ar ifX Pc ,
1898127dd473Swhl739by device name
1899127dd473Swhl739.Po Ar if* Pc ,
1900127dd473Swhl739by IP address, or through some interface.
1901127dd473Swhl739Table
1902127dd473Swhl739.Ar name
1903127dd473Swhl739may be used to match interface by its kernel ifindex.
1904127dd473Swhl739See the
1905127dd473Swhl739.Sx LOOKUP TABLES
1906127dd473Swhl739section below for more information on lookup tables.
1907127dd473Swhl739.Pp
1908127dd473Swhl739The
1909127dd473Swhl739.Cm via
1910127dd473Swhl739keyword causes the interface to always be checked.
1911127dd473Swhl739If
1912127dd473Swhl739.Cm recv
1913127dd473Swhl739or
1914127dd473Swhl739.Cm xmit
1915127dd473Swhl739is used instead of
1916127dd473Swhl739.Cm via ,
1917127dd473Swhl739then only the receive or transmit interface (respectively)
1918127dd473Swhl739is checked.
1919127dd473Swhl739By specifying both, it is possible to match packets based on
1920127dd473Swhl739both receive and transmit interface, e.g.:
1921127dd473Swhl739.Pp
1922127dd473Swhl739.Dl "ipfw add deny ip from any to any out recv ed0 xmit ed1"
1923127dd473Swhl739.Pp
1924127dd473Swhl739The
1925127dd473Swhl739.Cm recv
1926127dd473Swhl739interface can be tested on either incoming or outgoing packets,
1927127dd473Swhl739while the
1928127dd473Swhl739.Cm xmit
1929127dd473Swhl739interface can only be tested on outgoing packets.
1930127dd473Swhl739So
1931127dd473Swhl739.Cm out
1932127dd473Swhl739is required (and
1933127dd473Swhl739.Cm in
1934127dd473Swhl739is invalid) whenever
1935127dd473Swhl739.Cm xmit
1936127dd473Swhl739is used.
1937127dd473Swhl739.Pp
1938127dd473Swhl739A packet might not have a receive or transmit interface: packets
1939127dd473Swhl739originating from the local host have no receive interface,
1940127dd473Swhl739while packets destined for the local host have no transmit
1941127dd473Swhl739interface.
1942*22ce4affSfengbojiang.It Cm set-limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N
1943*22ce4affSfengbojiangWorks like
1944*22ce4affSfengbojiang.Cm limit
1945*22ce4affSfengbojiangbut does not have an implicit
1946*22ce4affSfengbojiang.Cm check-state
1947*22ce4affSfengbojiangattached to it.
1948127dd473Swhl739.It Cm setup
1949127dd473Swhl739Matches TCP packets that have the SYN bit set but no ACK bit.
1950127dd473Swhl739This is the short form of
1951127dd473Swhl739.Dq Li tcpflags\ syn,!ack .
1952127dd473Swhl739.It Cm sockarg
1953127dd473Swhl739Matches packets that are associated to a local socket and
1954127dd473Swhl739for which the SO_USER_COOKIE socket option has been set
1955127dd473Swhl739to a non-zero value.
1956127dd473Swhl739As a side effect, the value of the
1957127dd473Swhl739option is made available as
1958127dd473Swhl739.Cm tablearg
1959127dd473Swhl739value, which in turn can be used as
1960127dd473Swhl739.Cm skipto
1961127dd473Swhl739or
1962127dd473Swhl739.Cm pipe
1963127dd473Swhl739number.
1964127dd473Swhl739.It Cm src-ip Ar ip-address
1965127dd473Swhl739Matches IPv4 packets whose source IP is one of the address(es)
1966127dd473Swhl739specified as an argument.
1967127dd473Swhl739.It Cm src-ip6 Ar ip6-address
1968127dd473Swhl739Matches IPv6 packets whose source IP is one of the address(es)
1969127dd473Swhl739specified as an argument.
1970127dd473Swhl739.It Cm src-port Ar ports
1971127dd473Swhl739Matches IP packets whose source port is one of the port(s)
1972127dd473Swhl739specified as argument.
1973127dd473Swhl739.It Cm tagged Ar tag-list
1974127dd473Swhl739Matches packets whose tags are included in
1975127dd473Swhl739.Ar tag-list ,
1976127dd473Swhl739which is either a single value or a list of values or ranges
1977127dd473Swhl739specified in the same way as
1978127dd473Swhl739.Ar ports .
1979127dd473Swhl739Tags can be applied to the packet using
1980127dd473Swhl739.Cm tag
1981127dd473Swhl739rule action parameter (see it's description for details on tags).
1982127dd473Swhl739.It Cm tcpack Ar ack
1983127dd473Swhl739TCP packets only.
1984127dd473Swhl739Match if the TCP header acknowledgment number field is set to
1985127dd473Swhl739.Ar ack .
1986127dd473Swhl739.It Cm tcpdatalen Ar tcpdatalen-list
1987127dd473Swhl739Matches TCP packets whose length of TCP data is
1988127dd473Swhl739.Ar tcpdatalen-list ,
1989127dd473Swhl739which is either a single value or a list of values or ranges
1990127dd473Swhl739specified in the same way as
1991127dd473Swhl739.Ar ports .
1992127dd473Swhl739.It Cm tcpflags Ar spec
1993127dd473Swhl739TCP packets only.
1994127dd473Swhl739Match if the TCP header contains the comma separated list of
1995127dd473Swhl739flags specified in
1996127dd473Swhl739.Ar spec .
1997127dd473Swhl739The supported TCP flags are:
1998127dd473Swhl739.Pp
1999127dd473Swhl739.Cm fin ,
2000127dd473Swhl739.Cm syn ,
2001127dd473Swhl739.Cm rst ,
2002127dd473Swhl739.Cm psh ,
2003127dd473Swhl739.Cm ack
2004127dd473Swhl739and
2005127dd473Swhl739.Cm urg .
2006127dd473Swhl739The absence of a particular flag may be denoted
2007127dd473Swhl739with a
2008127dd473Swhl739.Ql \&! .
2009127dd473Swhl739A rule which contains a
2010127dd473Swhl739.Cm tcpflags
2011127dd473Swhl739specification can never match a fragmented packet which has
2012127dd473Swhl739a non-zero offset.
2013127dd473Swhl739See the
2014127dd473Swhl739.Cm frag
2015127dd473Swhl739option for details on matching fragmented packets.
2016*22ce4affSfengbojiang.It Cm tcpmss Ar tcpmss-list
2017*22ce4affSfengbojiangMatches TCP packets whose MSS (maximum segment size) value is set to
2018*22ce4affSfengbojiang.Ar tcpmss-list ,
2019*22ce4affSfengbojiangwhich is either a single value or a list of values or ranges
2020*22ce4affSfengbojiangspecified in the same way as
2021*22ce4affSfengbojiang.Ar ports .
2022127dd473Swhl739.It Cm tcpseq Ar seq
2023127dd473Swhl739TCP packets only.
2024127dd473Swhl739Match if the TCP header sequence number field is set to
2025127dd473Swhl739.Ar seq .
2026127dd473Swhl739.It Cm tcpwin Ar tcpwin-list
2027127dd473Swhl739Matches TCP packets whose  header window field is set to
2028127dd473Swhl739.Ar tcpwin-list ,
2029127dd473Swhl739which is either a single value or a list of values or ranges
2030127dd473Swhl739specified in the same way as
2031127dd473Swhl739.Ar ports .
2032127dd473Swhl739.It Cm tcpoptions Ar spec
2033127dd473Swhl739TCP packets only.
2034127dd473Swhl739Match if the TCP header contains the comma separated list of
2035127dd473Swhl739options specified in
2036127dd473Swhl739.Ar spec .
2037127dd473Swhl739The supported TCP options are:
2038127dd473Swhl739.Pp
2039127dd473Swhl739.Cm mss
2040127dd473Swhl739(maximum segment size),
2041127dd473Swhl739.Cm window
2042127dd473Swhl739(tcp window advertisement),
2043127dd473Swhl739.Cm sack
2044127dd473Swhl739(selective ack),
2045127dd473Swhl739.Cm ts
2046127dd473Swhl739(rfc1323 timestamp) and
2047127dd473Swhl739.Cm cc
2048127dd473Swhl739(rfc1644 t/tcp connection count).
2049127dd473Swhl739The absence of a particular option may be denoted
2050127dd473Swhl739with a
2051127dd473Swhl739.Ql \&! .
2052127dd473Swhl739.It Cm uid Ar user
2053127dd473Swhl739Match all TCP or UDP packets sent by or received for a
2054127dd473Swhl739.Ar user .
2055127dd473Swhl739A
2056127dd473Swhl739.Ar user
2057127dd473Swhl739may be matched by name or identification number.
2058127dd473Swhl739.It Cm verrevpath
2059127dd473Swhl739For incoming packets,
2060127dd473Swhl739a routing table lookup is done on the packet's source address.
2061127dd473Swhl739If the interface on which the packet entered the system matches the
2062127dd473Swhl739outgoing interface for the route,
2063127dd473Swhl739the packet matches.
2064127dd473Swhl739If the interfaces do not match up,
2065127dd473Swhl739the packet does not match.
2066127dd473Swhl739All outgoing packets or packets with no incoming interface match.
2067127dd473Swhl739.Pp
2068127dd473Swhl739The name and functionality of the option is intentionally similar to
2069127dd473Swhl739the Cisco IOS command:
2070127dd473Swhl739.Pp
2071127dd473Swhl739.Dl ip verify unicast reverse-path
2072127dd473Swhl739.Pp
2073127dd473Swhl739This option can be used to make anti-spoofing rules to reject all
2074127dd473Swhl739packets with source addresses not from this interface.
2075127dd473Swhl739See also the option
2076127dd473Swhl739.Cm antispoof .
2077127dd473Swhl739.It Cm versrcreach
2078127dd473Swhl739For incoming packets,
2079127dd473Swhl739a routing table lookup is done on the packet's source address.
2080127dd473Swhl739If a route to the source address exists, but not the default route
2081127dd473Swhl739or a blackhole/reject route, the packet matches.
2082127dd473Swhl739Otherwise, the packet does not match.
2083127dd473Swhl739All outgoing packets match.
2084127dd473Swhl739.Pp
2085127dd473Swhl739The name and functionality of the option is intentionally similar to
2086127dd473Swhl739the Cisco IOS command:
2087127dd473Swhl739.Pp
2088127dd473Swhl739.Dl ip verify unicast source reachable-via any
2089127dd473Swhl739.Pp
2090127dd473Swhl739This option can be used to make anti-spoofing rules to reject all
2091127dd473Swhl739packets whose source address is unreachable.
2092127dd473Swhl739.It Cm antispoof
2093127dd473Swhl739For incoming packets, the packet's source address is checked if it
2094127dd473Swhl739belongs to a directly connected network.
2095127dd473Swhl739If the network is directly connected, then the interface the packet
2096127dd473Swhl739came on in is compared to the interface the network is connected to.
2097127dd473Swhl739When incoming interface and directly connected interface are not the
2098127dd473Swhl739same, the packet does not match.
2099127dd473Swhl739Otherwise, the packet does match.
2100127dd473Swhl739All outgoing packets match.
2101127dd473Swhl739.Pp
2102127dd473Swhl739This option can be used to make anti-spoofing rules to reject all
2103127dd473Swhl739packets that pretend to be from a directly connected network but do
2104127dd473Swhl739not come in through that interface.
2105127dd473Swhl739This option is similar to but more restricted than
2106127dd473Swhl739.Cm verrevpath
2107127dd473Swhl739because it engages only on packets with source addresses of directly
2108127dd473Swhl739connected networks instead of all source addresses.
2109127dd473Swhl739.El
2110127dd473Swhl739.Sh LOOKUP TABLES
2111127dd473Swhl739Lookup tables are useful to handle large sparse sets of
2112127dd473Swhl739addresses or other search keys (e.g., ports, jail IDs, interface names).
2113127dd473Swhl739In the rest of this section we will use the term ``key''.
2114127dd473Swhl739Table name needs to match the following spec:
2115127dd473Swhl739.Ar table-name .
2116127dd473Swhl739Tables with the same name can be created in different
2117127dd473Swhl739.Ar sets .
2118127dd473Swhl739However, rule links to the tables in
2119127dd473Swhl739.Ar set 0
2120127dd473Swhl739by default.
2121127dd473Swhl739This behavior can be controlled by
2122127dd473Swhl739.Va net.inet.ip.fw.tables_sets
2123127dd473Swhl739variable.
2124127dd473Swhl739See the
2125127dd473Swhl739.Sx SETS OF RULES
2126127dd473Swhl739section for more information.
2127127dd473Swhl739There may be up to 65535 different lookup tables.
2128127dd473Swhl739.Pp
2129127dd473Swhl739The following table types are supported:
2130127dd473Swhl739.Bl -tag -width indent
2131127dd473Swhl739.It Ar table-type : Ar addr | iface | number | flow
2132127dd473Swhl739.It Ar table-key : Ar addr Ns Oo / Ns Ar masklen Oc | iface-name | number | flow-spec
2133127dd473Swhl739.It Ar flow-spec : Ar flow-field Ns Op , Ns Ar flow-spec
2134127dd473Swhl739.It Ar flow-field : src-ip | proto | src-port | dst-ip | dst-port
2135127dd473Swhl739.It Cm addr
2136*22ce4affSfengbojiangMatches IPv4 or IPv6 address.
2137127dd473Swhl739Each entry is represented by an
2138127dd473Swhl739.Ar addr Ns Op / Ns Ar masklen
2139127dd473Swhl739and will match all addresses with base
2140127dd473Swhl739.Ar addr
2141127dd473Swhl739(specified as an IPv4/IPv6 address, or a hostname) and mask width of
2142127dd473Swhl739.Ar masklen
2143127dd473Swhl739bits.
2144127dd473Swhl739If
2145127dd473Swhl739.Ar masklen
2146127dd473Swhl739is not specified, it defaults to 32 for IPv4 and 128 for IPv6.
2147127dd473Swhl739When looking up an IP address in a table, the most specific
2148127dd473Swhl739entry will match.
2149127dd473Swhl739.It Cm iface
2150*22ce4affSfengbojiangMatches interface names.
2151127dd473Swhl739Each entry is represented by string treated as interface name.
2152127dd473Swhl739Wildcards are not supported.
2153127dd473Swhl739.It Cm number
2154*22ce4affSfengbojiangMatches protocol ports, uids/gids or jail IDs.
2155127dd473Swhl739Each entry is represented by 32-bit unsigned integer.
2156127dd473Swhl739Ranges are not supported.
2157127dd473Swhl739.It Cm flow
2158127dd473Swhl739Matches packet fields specified by
2159127dd473Swhl739.Ar flow
2160127dd473Swhl739type suboptions with table entries.
2161127dd473Swhl739.El
2162127dd473Swhl739.Pp
2163127dd473Swhl739Tables require explicit creation via
2164127dd473Swhl739.Cm create
2165127dd473Swhl739before use.
2166127dd473Swhl739.Pp
2167127dd473Swhl739The following creation options are supported:
2168127dd473Swhl739.Bl -tag -width indent
2169127dd473Swhl739.It Ar create-options : Ar create-option | create-options
2170127dd473Swhl739.It Ar create-option : Cm type Ar table-type | Cm valtype Ar value-mask | Cm algo Ar algo-desc |
2171*22ce4affSfengbojiang.Cm limit Ar number | Cm locked | Cm missing | Cm or-flush
2172127dd473Swhl739.It Cm type
2173127dd473Swhl739Table key type.
2174127dd473Swhl739.It Cm valtype
2175127dd473Swhl739Table value mask.
2176127dd473Swhl739.It Cm algo
2177127dd473Swhl739Table algorithm to use (see below).
2178127dd473Swhl739.It Cm limit
2179127dd473Swhl739Maximum number of items that may be inserted into table.
2180127dd473Swhl739.It Cm locked
2181127dd473Swhl739Restrict any table modifications.
2182*22ce4affSfengbojiang.It Cm missing
2183*22ce4affSfengbojiangDo not fail if table already exists and has exactly same options as new one.
2184*22ce4affSfengbojiang.It Cm or-flush
2185*22ce4affSfengbojiangFlush existing table with same name instead of returning error.
2186*22ce4affSfengbojiangImplies
2187*22ce4affSfengbojiang.Cm missing
2188*22ce4affSfengbojiangso existing table must be compatible with new one.
2189127dd473Swhl739.El
2190127dd473Swhl739.Pp
2191127dd473Swhl739Some of these options may be modified later via
2192127dd473Swhl739.Cm modify
2193127dd473Swhl739keyword.
2194127dd473Swhl739The following options can be changed:
2195127dd473Swhl739.Bl -tag -width indent
2196127dd473Swhl739.It Ar modify-options : Ar modify-option | modify-options
2197127dd473Swhl739.It Ar modify-option : Cm limit Ar number
2198127dd473Swhl739.It Cm limit
2199127dd473Swhl739Alter maximum number of items that may be inserted into table.
2200127dd473Swhl739.El
2201127dd473Swhl739.Pp
2202127dd473Swhl739Additionally, table can be locked or unlocked using
2203127dd473Swhl739.Cm lock
2204127dd473Swhl739or
2205127dd473Swhl739.Cm unlock
2206127dd473Swhl739commands.
2207127dd473Swhl739.Pp
2208127dd473Swhl739Tables of the same
2209127dd473Swhl739.Ar type
2210127dd473Swhl739can be swapped with each other using
2211127dd473Swhl739.Cm swap Ar name
2212127dd473Swhl739command.
2213127dd473Swhl739Swap may fail if tables limits are set and data exchange
2214127dd473Swhl739would result in limits hit.
2215127dd473Swhl739Operation is performed atomically.
2216127dd473Swhl739.Pp
2217127dd473Swhl739One or more entries can be added to a table at once using
2218127dd473Swhl739.Cm add
2219127dd473Swhl739command.
2220127dd473Swhl739Addition of all items are performed atomically.
2221127dd473Swhl739By default, error in addition of one entry does not influence
2222*22ce4affSfengbojiangaddition of other entries.
2223*22ce4affSfengbojiangHowever, non-zero error code is returned in that case.
2224127dd473Swhl739Special
2225127dd473Swhl739.Cm atomic
2226127dd473Swhl739keyword may be specified before
2227127dd473Swhl739.Cm add
2228127dd473Swhl739to indicate all-or-none add request.
2229127dd473Swhl739.Pp
2230127dd473Swhl739One or more entries can be removed from a table at once using
2231127dd473Swhl739.Cm delete
2232127dd473Swhl739command.
2233127dd473Swhl739By default, error in removal of one entry does not influence
2234*22ce4affSfengbojiangremoving of other entries.
2235*22ce4affSfengbojiangHowever, non-zero error code is returned in that case.
2236127dd473Swhl739.Pp
2237127dd473Swhl739It may be possible to check what entry will be found on particular
2238127dd473Swhl739.Ar table-key
2239127dd473Swhl739using
2240127dd473Swhl739.Cm lookup
2241127dd473Swhl739.Ar table-key
2242127dd473Swhl739command.
2243127dd473Swhl739This functionality is optional and may be unsupported in some algorithms.
2244127dd473Swhl739.Pp
2245127dd473Swhl739The following operations can be performed on
2246127dd473Swhl739.Ar one
2247127dd473Swhl739or
2248127dd473Swhl739.Cm all
2249127dd473Swhl739tables:
2250127dd473Swhl739.Bl -tag -width indent
2251127dd473Swhl739.It Cm list
2252127dd473Swhl739List all entries.
2253127dd473Swhl739.It Cm flush
2254127dd473Swhl739Removes all entries.
2255127dd473Swhl739.It Cm info
2256127dd473Swhl739Shows generic table information.
2257127dd473Swhl739.It Cm detail
2258127dd473Swhl739Shows generic table information and algo-specific data.
2259127dd473Swhl739.El
2260127dd473Swhl739.Pp
2261127dd473Swhl739The following lookup algorithms are supported:
2262127dd473Swhl739.Bl -tag -width indent
2263127dd473Swhl739.It Ar algo-desc : algo-name | "algo-name algo-data"
2264127dd473Swhl739.It Ar algo-name : Ar addr: radix | addr: hash | iface: array | number: array | flow: hash
2265127dd473Swhl739.It Cm addr: radix
2266127dd473Swhl739Separate Radix trees for IPv4 and IPv6, the same way as the routing table (see
2267127dd473Swhl739.Xr route 4 ) .
2268127dd473Swhl739Default choice for
2269127dd473Swhl739.Ar addr
2270127dd473Swhl739type.
2271127dd473Swhl739.It Cm addr:hash
2272127dd473Swhl739Separate auto-growing hashes for IPv4 and IPv6.
2273127dd473Swhl739Accepts entries with the same mask length specified initially via
2274127dd473Swhl739.Cm "addr:hash masks=/v4,/v6"
2275127dd473Swhl739algorithm creation options.
2276127dd473Swhl739Assume /32 and /128 masks by default.
2277127dd473Swhl739Search removes host bits (according to mask) from supplied address and checks
2278127dd473Swhl739resulting key in appropriate hash.
2279127dd473Swhl739Mostly optimized for /64 and byte-ranged IPv6 masks.
2280127dd473Swhl739.It Cm iface:array
2281127dd473Swhl739Array storing sorted indexes for entries which are presented in the system.
2282127dd473Swhl739Optimized for very fast lookup.
2283127dd473Swhl739.It Cm number:array
2284127dd473Swhl739Array storing sorted u32 numbers.
2285127dd473Swhl739.It Cm flow:hash
2286127dd473Swhl739Auto-growing hash storing flow entries.
2287127dd473Swhl739Search calculates hash on required packet fields and searches for matching
2288127dd473Swhl739entries in selected bucket.
2289127dd473Swhl739.El
2290127dd473Swhl739.Pp
2291127dd473Swhl739The
2292127dd473Swhl739.Cm tablearg
2293127dd473Swhl739feature provides the ability to use a value, looked up in the table, as
2294127dd473Swhl739the argument for a rule action, action parameter or rule option.
2295127dd473Swhl739This can significantly reduce number of rules in some configurations.
2296127dd473Swhl739If two tables are used in a rule, the result of the second (destination)
2297127dd473Swhl739is used.
2298127dd473Swhl739.Pp
2299127dd473Swhl739Each record may hold one or more values according to
2300127dd473Swhl739.Ar value-mask .
2301127dd473Swhl739This mask is set on table creation via
2302127dd473Swhl739.Cm valtype
2303127dd473Swhl739option.
2304127dd473Swhl739The following value types are supported:
2305127dd473Swhl739.Bl -tag -width indent
2306127dd473Swhl739.It Ar value-mask : Ar value-type Ns Op , Ns Ar value-mask
2307127dd473Swhl739.It Ar value-type : Ar skipto | pipe | fib | nat | dscp | tag | divert |
2308127dd473Swhl739.Ar netgraph | limit | ipv4
2309127dd473Swhl739.It Cm skipto
2310127dd473Swhl739rule number to jump to.
2311127dd473Swhl739.It Cm pipe
2312127dd473Swhl739Pipe number to use.
2313127dd473Swhl739.It Cm fib
2314127dd473Swhl739fib number to match/set.
2315127dd473Swhl739.It Cm nat
2316127dd473Swhl739nat number to jump to.
2317127dd473Swhl739.It Cm dscp
2318127dd473Swhl739dscp value to match/set.
2319127dd473Swhl739.It Cm tag
2320127dd473Swhl739tag number to match/set.
2321127dd473Swhl739.It Cm divert
2322127dd473Swhl739port number to divert traffic to.
2323127dd473Swhl739.It Cm netgraph
2324127dd473Swhl739hook number to move packet to.
2325127dd473Swhl739.It Cm limit
2326127dd473Swhl739maximum number of connections.
2327127dd473Swhl739.It Cm ipv4
2328127dd473Swhl739IPv4 nexthop to fwd packets to.
2329127dd473Swhl739.It Cm ipv6
2330127dd473Swhl739IPv6 nexthop to fwd packets to.
2331127dd473Swhl739.El
2332127dd473Swhl739.Pp
2333127dd473Swhl739The
2334127dd473Swhl739.Cm tablearg
2335127dd473Swhl739argument can be used with the following actions:
2336127dd473Swhl739.Cm nat, pipe, queue, divert, tee, netgraph, ngtee, fwd, skipto, setfib ,
2337127dd473Swhl739action parameters:
2338127dd473Swhl739.Cm tag, untag ,
2339127dd473Swhl739rule options:
2340127dd473Swhl739.Cm limit, tagged .
2341127dd473Swhl739.Pp
2342127dd473Swhl739When used with the
2343127dd473Swhl739.Cm skipto
2344127dd473Swhl739action, the user should be aware that the code will walk the ruleset
2345127dd473Swhl739up to a rule equal to, or past, the given number.
2346127dd473Swhl739.Pp
2347127dd473Swhl739See the
2348127dd473Swhl739.Sx EXAMPLES
2349127dd473Swhl739Section for example usage of tables and the tablearg keyword.
2350127dd473Swhl739.Sh SETS OF RULES
2351127dd473Swhl739Each rule or table belongs to one of 32 different
2352127dd473Swhl739.Em sets
2353127dd473Swhl739, numbered 0 to 31.
2354127dd473Swhl739Set 31 is reserved for the default rule.
2355127dd473Swhl739.Pp
2356127dd473Swhl739By default, rules or tables are put in set 0, unless you use the
2357127dd473Swhl739.Cm set N
2358127dd473Swhl739attribute when adding a new rule or table.
2359127dd473Swhl739Sets can be individually and atomically enabled or disabled,
2360127dd473Swhl739so this mechanism permits an easy way to store multiple configurations
2361127dd473Swhl739of the firewall and quickly (and atomically) switch between them.
2362127dd473Swhl739.Pp
2363127dd473Swhl739By default, tables from set 0 are referenced when adding rule with
2364127dd473Swhl739table opcodes regardless of rule set.
2365127dd473Swhl739This behavior can be changed by setting
2366*22ce4affSfengbojiang.Va net.inet.ip.fw.tables_sets
2367127dd473Swhl739variable to 1.
2368127dd473Swhl739Rule's set will then be used for table references.
2369127dd473Swhl739.Pp
2370127dd473Swhl739The command to enable/disable sets is
2371127dd473Swhl739.Bd -ragged -offset indent
2372127dd473Swhl739.Nm
2373127dd473Swhl739.Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
2374127dd473Swhl739.Ed
2375127dd473Swhl739.Pp
2376127dd473Swhl739where multiple
2377127dd473Swhl739.Cm enable
2378127dd473Swhl739or
2379127dd473Swhl739.Cm disable
2380127dd473Swhl739sections can be specified.
2381127dd473Swhl739Command execution is atomic on all the sets specified in the command.
2382127dd473Swhl739By default, all sets are enabled.
2383127dd473Swhl739.Pp
2384127dd473Swhl739When you disable a set, its rules behave as if they do not exist
2385127dd473Swhl739in the firewall configuration, with only one exception:
2386127dd473Swhl739.Bd -ragged -offset indent
2387127dd473Swhl739dynamic rules created from a rule before it had been disabled
2388127dd473Swhl739will still be active until they expire.
2389127dd473Swhl739In order to delete
2390127dd473Swhl739dynamic rules you have to explicitly delete the parent rule
2391127dd473Swhl739which generated them.
2392127dd473Swhl739.Ed
2393127dd473Swhl739.Pp
2394127dd473Swhl739The set number of rules can be changed with the command
2395127dd473Swhl739.Bd -ragged -offset indent
2396127dd473Swhl739.Nm
2397127dd473Swhl739.Cm set move
2398127dd473Swhl739.Brq Cm rule Ar rule-number | old-set
2399127dd473Swhl739.Cm to Ar new-set
2400127dd473Swhl739.Ed
2401127dd473Swhl739.Pp
2402127dd473Swhl739Also, you can atomically swap two rulesets with the command
2403127dd473Swhl739.Bd -ragged -offset indent
2404127dd473Swhl739.Nm
2405127dd473Swhl739.Cm set swap Ar first-set second-set
2406127dd473Swhl739.Ed
2407127dd473Swhl739.Pp
2408127dd473Swhl739See the
2409127dd473Swhl739.Sx EXAMPLES
2410127dd473Swhl739Section on some possible uses of sets of rules.
2411127dd473Swhl739.Sh STATEFUL FIREWALL
2412127dd473Swhl739Stateful operation is a way for the firewall to dynamically
2413127dd473Swhl739create rules for specific flows when packets that
2414127dd473Swhl739match a given pattern are detected.
2415127dd473Swhl739Support for stateful
2416127dd473Swhl739operation comes through the
2417*22ce4affSfengbojiang.Cm check-state , keep-state , record-state , limit
2418127dd473Swhl739and
2419*22ce4affSfengbojiang.Cm set-limit
2420127dd473Swhl739options of
2421127dd473Swhl739.Nm rules .
2422127dd473Swhl739.Pp
2423127dd473Swhl739Dynamic rules are created when a packet matches a
2424*22ce4affSfengbojiang.Cm keep-state ,
2425*22ce4affSfengbojiang.Cm record-state ,
2426127dd473Swhl739.Cm limit
2427*22ce4affSfengbojiangor
2428*22ce4affSfengbojiang.Cm set-limit
2429127dd473Swhl739rule, causing the creation of a
2430127dd473Swhl739.Em dynamic
2431127dd473Swhl739rule which will match all and only packets with
2432127dd473Swhl739a given
2433127dd473Swhl739.Em protocol
2434127dd473Swhl739between a
2435127dd473Swhl739.Em src-ip/src-port dst-ip/dst-port
2436127dd473Swhl739pair of addresses
2437127dd473Swhl739.Em ( src
2438127dd473Swhl739and
2439127dd473Swhl739.Em dst
2440127dd473Swhl739are used here only to denote the initial match addresses, but they
2441127dd473Swhl739are completely equivalent afterwards).
2442*22ce4affSfengbojiangRules created by
2443*22ce4affSfengbojiang.Cm keep-state
2444*22ce4affSfengbojiangoption also have a
2445*22ce4affSfengbojiang.Ar :flowname
2446*22ce4affSfengbojiangtaken from it.
2447*22ce4affSfengbojiangThis name is used in matching together with addresses, ports and protocol.
2448127dd473Swhl739Dynamic rules will be checked at the first
2449127dd473Swhl739.Cm check-state, keep-state
2450127dd473Swhl739or
2451127dd473Swhl739.Cm limit
2452127dd473Swhl739occurrence, and the action performed upon a match will be the same
2453127dd473Swhl739as in the parent rule.
2454127dd473Swhl739.Pp
2455127dd473Swhl739Note that no additional attributes other than protocol and IP addresses
2456*22ce4affSfengbojiangand ports and :flowname are checked on dynamic rules.
2457127dd473Swhl739.Pp
2458127dd473Swhl739The typical use of dynamic rules is to keep a closed firewall configuration,
2459127dd473Swhl739but let the first TCP SYN packet from the inside network install a
2460127dd473Swhl739dynamic rule for the flow so that packets belonging to that session
2461127dd473Swhl739will be allowed through the firewall:
2462127dd473Swhl739.Pp
2463*22ce4affSfengbojiang.Dl "ipfw add check-state :OUTBOUND"
2464*22ce4affSfengbojiang.Dl "ipfw add allow tcp from my-subnet to any setup keep-state :OUTBOUND"
2465127dd473Swhl739.Dl "ipfw add deny tcp from any to any"
2466127dd473Swhl739.Pp
2467127dd473Swhl739A similar approach can be used for UDP, where an UDP packet coming
2468127dd473Swhl739from the inside will install a dynamic rule to let the response through
2469127dd473Swhl739the firewall:
2470127dd473Swhl739.Pp
2471*22ce4affSfengbojiang.Dl "ipfw add check-state :OUTBOUND"
2472*22ce4affSfengbojiang.Dl "ipfw add allow udp from my-subnet to any keep-state :OUTBOUND"
2473127dd473Swhl739.Dl "ipfw add deny udp from any to any"
2474127dd473Swhl739.Pp
2475127dd473Swhl739Dynamic rules expire after some time, which depends on the status
2476127dd473Swhl739of the flow and the setting of some
2477127dd473Swhl739.Cm sysctl
2478127dd473Swhl739variables.
2479127dd473Swhl739See Section
2480127dd473Swhl739.Sx SYSCTL VARIABLES
2481127dd473Swhl739for more details.
2482127dd473Swhl739For TCP sessions, dynamic rules can be instructed to periodically
2483127dd473Swhl739send keepalive packets to refresh the state of the rule when it is
2484127dd473Swhl739about to expire.
2485127dd473Swhl739.Pp
2486127dd473Swhl739See Section
2487127dd473Swhl739.Sx EXAMPLES
2488127dd473Swhl739for more examples on how to use dynamic rules.
2489127dd473Swhl739.Sh TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
2490127dd473Swhl739.Nm
2491127dd473Swhl739is also the user interface for the
2492127dd473Swhl739.Nm dummynet
2493127dd473Swhl739traffic shaper, packet scheduler and network emulator, a subsystem that
2494127dd473Swhl739can artificially queue, delay or drop packets
2495127dd473Swhl739emulating the behaviour of certain network links
2496127dd473Swhl739or queueing systems.
2497127dd473Swhl739.Pp
2498127dd473Swhl739.Nm dummynet
2499127dd473Swhl739operates by first using the firewall to select packets
2500127dd473Swhl739using any match pattern that can be used in
2501127dd473Swhl739.Nm
2502127dd473Swhl739rules.
2503127dd473Swhl739Matching packets are then passed to either of two
2504127dd473Swhl739different objects, which implement the traffic regulation:
2505127dd473Swhl739.Bl -hang -offset XXXX
2506127dd473Swhl739.It Em pipe
2507127dd473Swhl739A
2508127dd473Swhl739.Em pipe
2509127dd473Swhl739emulates a
2510127dd473Swhl739.Em link
2511127dd473Swhl739with given bandwidth and propagation delay,
2512127dd473Swhl739driven by a FIFO scheduler and a single queue with programmable
2513127dd473Swhl739queue size and packet loss rate.
2514127dd473Swhl739Packets are appended to the queue as they come out from
2515127dd473Swhl739.Nm ipfw ,
2516127dd473Swhl739and then transferred in FIFO order to the link at the desired rate.
2517127dd473Swhl739.It Em queue
2518127dd473Swhl739A
2519127dd473Swhl739.Em queue
2520127dd473Swhl739is an abstraction used to implement packet scheduling
2521127dd473Swhl739using one of several packet scheduling algorithms.
2522127dd473Swhl739Packets sent to a
2523127dd473Swhl739.Em queue
2524127dd473Swhl739are first grouped into flows according to a mask on the 5-tuple.
2525127dd473Swhl739Flows are then passed to the scheduler associated to the
2526127dd473Swhl739.Em queue ,
2527127dd473Swhl739and each flow uses scheduling parameters (weight and others)
2528127dd473Swhl739as configured in the
2529127dd473Swhl739.Em queue
2530127dd473Swhl739itself.
2531127dd473Swhl739A scheduler in turn is connected to an emulated link,
2532127dd473Swhl739and arbitrates the link's bandwidth among backlogged flows according to
2533127dd473Swhl739weights and to the features of the scheduling algorithm in use.
2534127dd473Swhl739.El
2535127dd473Swhl739.Pp
2536127dd473Swhl739In practice,
2537127dd473Swhl739.Em pipes
2538127dd473Swhl739can be used to set hard limits to the bandwidth that a flow can use, whereas
2539127dd473Swhl739.Em queues
2540127dd473Swhl739can be used to determine how different flows share the available bandwidth.
2541127dd473Swhl739.Pp
2542127dd473Swhl739A graphical representation of the binding of queues,
2543127dd473Swhl739flows, schedulers and links is below.
2544127dd473Swhl739.Bd -literal -offset indent
2545127dd473Swhl739                 (flow_mask|sched_mask)  sched_mask
2546127dd473Swhl739         +---------+   weight Wx  +-------------+
2547127dd473Swhl739         |         |->-[flow]-->--|             |-+
2548127dd473Swhl739    -->--| QUEUE x |   ...        |             | |
2549127dd473Swhl739         |         |->-[flow]-->--| SCHEDuler N | |
2550127dd473Swhl739         +---------+              |             | |
2551127dd473Swhl739             ...                  |             +--[LINK N]-->--
2552127dd473Swhl739         +---------+   weight Wy  |             | +--[LINK N]-->--
2553127dd473Swhl739         |         |->-[flow]-->--|             | |
2554127dd473Swhl739    -->--| QUEUE y |   ...        |             | |
2555127dd473Swhl739         |         |->-[flow]-->--|             | |
2556127dd473Swhl739         +---------+              +-------------+ |
2557127dd473Swhl739                                    +-------------+
2558127dd473Swhl739.Ed
2559127dd473Swhl739It is important to understand the role of the SCHED_MASK
2560127dd473Swhl739and FLOW_MASK, which are configured through the commands
2561127dd473Swhl739.Dl "ipfw sched N config mask SCHED_MASK ..."
2562127dd473Swhl739and
2563127dd473Swhl739.Dl "ipfw queue X config mask FLOW_MASK ..." .
2564127dd473Swhl739.Pp
2565127dd473Swhl739The SCHED_MASK is used to assign flows to one or more
2566127dd473Swhl739scheduler instances, one for each
2567127dd473Swhl739value of the packet's 5-tuple after applying SCHED_MASK.
2568127dd473Swhl739As an example, using ``src-ip 0xffffff00'' creates one instance
2569127dd473Swhl739for each /24 destination subnet.
2570127dd473Swhl739.Pp
2571127dd473Swhl739The FLOW_MASK, together with the SCHED_MASK, is used to split
2572127dd473Swhl739packets into flows.
2573127dd473Swhl739As an example, using
2574127dd473Swhl739``src-ip 0x000000ff''
2575127dd473Swhl739together with the previous SCHED_MASK makes a flow for
2576127dd473Swhl739each individual source address.
2577127dd473Swhl739In turn, flows for each /24
2578127dd473Swhl739subnet will be sent to the same scheduler instance.
2579127dd473Swhl739.Pp
2580127dd473Swhl739The above diagram holds even for the
2581127dd473Swhl739.Em pipe
2582127dd473Swhl739case, with the only restriction that a
2583127dd473Swhl739.Em pipe
2584127dd473Swhl739only supports a SCHED_MASK, and forces the use of a FIFO
2585127dd473Swhl739scheduler (these are for backward compatibility reasons;
2586127dd473Swhl739in fact, internally, a
2587127dd473Swhl739.Nm dummynet's
2588127dd473Swhl739pipe is implemented exactly as above).
2589127dd473Swhl739.Pp
2590127dd473Swhl739There are two modes of
2591127dd473Swhl739.Nm dummynet
2592127dd473Swhl739operation:
2593127dd473Swhl739.Dq normal
2594127dd473Swhl739and
2595127dd473Swhl739.Dq fast .
2596127dd473Swhl739The
2597127dd473Swhl739.Dq normal
2598127dd473Swhl739mode tries to emulate a real link: the
2599127dd473Swhl739.Nm dummynet
2600127dd473Swhl739scheduler ensures that the packet will not leave the pipe faster than it
2601127dd473Swhl739would on the real link with a given bandwidth.
2602127dd473Swhl739The
2603127dd473Swhl739.Dq fast
2604127dd473Swhl739mode allows certain packets to bypass the
2605127dd473Swhl739.Nm dummynet
2606127dd473Swhl739scheduler (if packet flow does not exceed pipe's bandwidth).
2607127dd473Swhl739This is the reason why the
2608127dd473Swhl739.Dq fast
2609127dd473Swhl739mode requires less CPU cycles per packet (on average) and packet latency
2610127dd473Swhl739can be significantly lower in comparison to a real link with the same
2611127dd473Swhl739bandwidth.
2612127dd473Swhl739The default mode is
2613127dd473Swhl739.Dq normal .
2614127dd473Swhl739The
2615127dd473Swhl739.Dq fast
2616127dd473Swhl739mode can be enabled by setting the
2617127dd473Swhl739.Va net.inet.ip.dummynet.io_fast
2618127dd473Swhl739.Xr sysctl 8
2619127dd473Swhl739variable to a non-zero value.
2620127dd473Swhl739.Ss PIPE, QUEUE AND SCHEDULER CONFIGURATION
2621127dd473Swhl739The
2622127dd473Swhl739.Em pipe ,
2623127dd473Swhl739.Em queue
2624127dd473Swhl739and
2625127dd473Swhl739.Em scheduler
2626127dd473Swhl739configuration commands are the following:
2627127dd473Swhl739.Bd -ragged -offset indent
2628127dd473Swhl739.Cm pipe Ar number Cm config Ar pipe-configuration
2629127dd473Swhl739.Pp
2630127dd473Swhl739.Cm queue Ar number Cm config Ar queue-configuration
2631127dd473Swhl739.Pp
2632127dd473Swhl739.Cm sched Ar number Cm config Ar sched-configuration
2633127dd473Swhl739.Ed
2634127dd473Swhl739.Pp
2635127dd473Swhl739The following parameters can be configured for a pipe:
2636127dd473Swhl739.Pp
2637127dd473Swhl739.Bl -tag -width indent -compact
2638127dd473Swhl739.It Cm bw Ar bandwidth | device
2639127dd473Swhl739Bandwidth, measured in
2640127dd473Swhl739.Sm off
2641*22ce4affSfengbojiang.Op Cm K | M | G
2642127dd473Swhl739.Brq Cm bit/s | Byte/s .
2643127dd473Swhl739.Sm on
2644127dd473Swhl739.Pp
2645127dd473Swhl739A value of 0 (default) means unlimited bandwidth.
2646127dd473Swhl739The unit must immediately follow the number, as in
2647127dd473Swhl739.Pp
2648127dd473Swhl739.Dl "ipfw pipe 1 config bw 300Kbit/s"
2649127dd473Swhl739.Pp
2650127dd473Swhl739If a device name is specified instead of a numeric value, as in
2651127dd473Swhl739.Pp
2652127dd473Swhl739.Dl "ipfw pipe 1 config bw tun0"
2653127dd473Swhl739.Pp
2654127dd473Swhl739then the transmit clock is supplied by the specified device.
2655127dd473Swhl739At the moment only the
2656127dd473Swhl739.Xr tun 4
2657127dd473Swhl739device supports this
2658127dd473Swhl739functionality, for use in conjunction with
2659127dd473Swhl739.Xr ppp 8 .
2660127dd473Swhl739.Pp
2661127dd473Swhl739.It Cm delay Ar ms-delay
2662127dd473Swhl739Propagation delay, measured in milliseconds.
2663127dd473Swhl739The value is rounded to the next multiple of the clock tick
2664127dd473Swhl739(typically 10ms, but it is a good practice to run kernels
2665127dd473Swhl739with
2666127dd473Swhl739.Dq "options HZ=1000"
2667127dd473Swhl739to reduce
2668127dd473Swhl739the granularity to 1ms or less).
2669127dd473Swhl739The default value is 0, meaning no delay.
2670127dd473Swhl739.Pp
2671127dd473Swhl739.It Cm burst Ar size
2672127dd473Swhl739If the data to be sent exceeds the pipe's bandwidth limit
2673127dd473Swhl739(and the pipe was previously idle), up to
2674127dd473Swhl739.Ar size
2675127dd473Swhl739bytes of data are allowed to bypass the
2676127dd473Swhl739.Nm dummynet
2677127dd473Swhl739scheduler, and will be sent as fast as the physical link allows.
2678127dd473Swhl739Any additional data will be transmitted at the rate specified
2679127dd473Swhl739by the
2680127dd473Swhl739.Nm pipe
2681127dd473Swhl739bandwidth.
2682127dd473Swhl739The burst size depends on how long the pipe has been idle;
2683127dd473Swhl739the effective burst size is calculated as follows:
2684127dd473Swhl739MAX(
2685127dd473Swhl739.Ar size
2686127dd473Swhl739,
2687127dd473Swhl739.Nm bw
2688127dd473Swhl739* pipe_idle_time).
2689127dd473Swhl739.Pp
2690127dd473Swhl739.It Cm profile Ar filename
2691127dd473Swhl739A file specifying the additional overhead incurred in the transmission
2692127dd473Swhl739of a packet on the link.
2693127dd473Swhl739.Pp
2694127dd473Swhl739Some link types introduce extra delays in the transmission
2695127dd473Swhl739of a packet, e.g., because of MAC level framing, contention on
2696127dd473Swhl739the use of the channel, MAC level retransmissions and so on.
2697127dd473Swhl739From our point of view, the channel is effectively unavailable
2698127dd473Swhl739for this extra time, which is constant or variable depending
2699127dd473Swhl739on the link type.
2700127dd473Swhl739Additionally, packets may be dropped after this
2701127dd473Swhl739time (e.g., on a wireless link after too many retransmissions).
2702127dd473Swhl739We can model the additional delay with an empirical curve
2703127dd473Swhl739that represents its distribution.
2704127dd473Swhl739.Bd -literal -offset indent
2705127dd473Swhl739      cumulative probability
2706127dd473Swhl739      1.0 ^
2707127dd473Swhl739          |
2708127dd473Swhl739      L   +-- loss-level          x
2709127dd473Swhl739          |                 ******
2710127dd473Swhl739          |                *
2711127dd473Swhl739          |           *****
2712127dd473Swhl739          |          *
2713127dd473Swhl739          |        **
2714127dd473Swhl739          |       *
2715127dd473Swhl739          +-------*------------------->
2716127dd473Swhl739                      delay
2717127dd473Swhl739.Ed
2718127dd473Swhl739The empirical curve may have both vertical and horizontal lines.
2719127dd473Swhl739Vertical lines represent constant delay for a range of
2720127dd473Swhl739probabilities.
2721127dd473Swhl739Horizontal lines correspond to a discontinuity in the delay
2722127dd473Swhl739distribution: the pipe will use the largest delay for a
2723127dd473Swhl739given probability.
2724127dd473Swhl739.Pp
2725127dd473Swhl739The file format is the following, with whitespace acting as
2726127dd473Swhl739a separator and '#' indicating the beginning a comment:
2727127dd473Swhl739.Bl -tag -width indent
2728127dd473Swhl739.It Cm name Ar identifier
2729127dd473Swhl739optional name (listed by "ipfw pipe show")
2730127dd473Swhl739to identify the delay distribution;
2731127dd473Swhl739.It Cm bw Ar value
2732127dd473Swhl739the bandwidth used for the pipe.
2733127dd473Swhl739If not specified here, it must be present
2734127dd473Swhl739explicitly as a configuration parameter for the pipe;
2735127dd473Swhl739.It Cm loss-level Ar L
2736127dd473Swhl739the probability above which packets are lost.
2737127dd473Swhl739(0.0 <= L <= 1.0, default 1.0 i.e., no loss);
2738127dd473Swhl739.It Cm samples Ar N
2739127dd473Swhl739the number of samples used in the internal
2740127dd473Swhl739representation of the curve (2..1024; default 100);
2741127dd473Swhl739.It Cm "delay prob" | "prob delay"
2742127dd473Swhl739One of these two lines is mandatory and defines
2743127dd473Swhl739the format of the following lines with data points.
2744127dd473Swhl739.It Ar XXX Ar YYY
2745127dd473Swhl7392 or more lines representing points in the curve,
2746127dd473Swhl739with either delay or probability first, according
2747127dd473Swhl739to the chosen format.
2748127dd473Swhl739The unit for delay is milliseconds.
2749127dd473Swhl739Data points do not need to be sorted.
2750127dd473Swhl739Also, the number of actual lines can be different
2751127dd473Swhl739from the value of the "samples" parameter:
2752127dd473Swhl739.Nm
2753127dd473Swhl739utility will sort and interpolate
2754127dd473Swhl739the curve as needed.
2755127dd473Swhl739.El
2756127dd473Swhl739.Pp
2757127dd473Swhl739Example of a profile file:
2758127dd473Swhl739.Bd -literal -offset indent
2759127dd473Swhl739name    bla_bla_bla
2760127dd473Swhl739samples 100
2761127dd473Swhl739loss-level    0.86
2762127dd473Swhl739prob    delay
2763127dd473Swhl7390       200	# minimum overhead is 200ms
2764127dd473Swhl7390.5     200
2765127dd473Swhl7390.5     300
2766127dd473Swhl7390.8     1000
2767127dd473Swhl7390.9     1300
2768127dd473Swhl7391       1300
2769127dd473Swhl739#configuration file end
2770127dd473Swhl739.Ed
2771127dd473Swhl739.El
2772127dd473Swhl739.Pp
2773127dd473Swhl739The following parameters can be configured for a queue:
2774127dd473Swhl739.Pp
2775127dd473Swhl739.Bl -tag -width indent -compact
2776127dd473Swhl739.It Cm pipe Ar pipe_nr
2777127dd473Swhl739Connects a queue to the specified pipe.
2778127dd473Swhl739Multiple queues (with the same or different weights) can be connected to
2779127dd473Swhl739the same pipe, which specifies the aggregate rate for the set of queues.
2780127dd473Swhl739.Pp
2781127dd473Swhl739.It Cm weight Ar weight
2782127dd473Swhl739Specifies the weight to be used for flows matching this queue.
2783127dd473Swhl739The weight must be in the range 1..100, and defaults to 1.
2784127dd473Swhl739.El
2785127dd473Swhl739.Pp
2786127dd473Swhl739The following case-insensitive parameters can be configured for a
2787127dd473Swhl739scheduler:
2788127dd473Swhl739.Pp
2789127dd473Swhl739.Bl -tag -width indent -compact
2790*22ce4affSfengbojiang.It Cm type Ar {fifo | wf2q+ | rr | qfq | fq_codel | fq_pie}
2791127dd473Swhl739specifies the scheduling algorithm to use.
2792127dd473Swhl739.Bl -tag -width indent -compact
2793127dd473Swhl739.It Cm fifo
2794127dd473Swhl739is just a FIFO scheduler (which means that all packets
2795127dd473Swhl739are stored in the same queue as they arrive to the scheduler).
2796127dd473Swhl739FIFO has O(1) per-packet time complexity, with very low
2797127dd473Swhl739constants (estimate 60-80ns on a 2GHz desktop machine)
2798127dd473Swhl739but gives no service guarantees.
2799127dd473Swhl739.It Cm wf2q+
2800127dd473Swhl739implements the WF2Q+ algorithm, which is a Weighted Fair Queueing
2801127dd473Swhl739algorithm which permits flows to share bandwidth according to
2802127dd473Swhl739their weights.
2803127dd473Swhl739Note that weights are not priorities; even a flow
2804127dd473Swhl739with a minuscule weight will never starve.
2805127dd473Swhl739WF2Q+ has O(log N) per-packet processing cost, where N is the number
2806127dd473Swhl739of flows, and is the default algorithm used by previous versions
2807127dd473Swhl739dummynet's queues.
2808127dd473Swhl739.It Cm rr
2809127dd473Swhl739implements the Deficit Round Robin algorithm, which has O(1) processing
2810127dd473Swhl739costs (roughly, 100-150ns per packet)
2811127dd473Swhl739and permits bandwidth allocation according to weights, but
2812127dd473Swhl739with poor service guarantees.
2813127dd473Swhl739.It Cm qfq
2814127dd473Swhl739implements the QFQ algorithm, which is a very fast variant of
2815127dd473Swhl739WF2Q+, with similar service guarantees and O(1) processing
2816127dd473Swhl739costs (roughly, 200-250ns per packet).
2817*22ce4affSfengbojiang.It Cm fq_codel
2818*22ce4affSfengbojiangimplements the FQ-CoDel (FlowQueue-CoDel) scheduler/AQM algorithm, which
2819*22ce4affSfengbojianguses a modified Deficit Round Robin scheduler to manage two lists of sub-queues
2820*22ce4affSfengbojiang(old sub-queues and new sub-queues) for providing brief periods of priority to
2821*22ce4affSfengbojianglightweight or short burst flows.
2822*22ce4affSfengbojiangBy default, the total number of sub-queues is 1024.
2823*22ce4affSfengbojiangFQ-CoDel's internal, dynamically
2824*22ce4affSfengbojiangcreated sub-queues are controlled by separate instances of CoDel AQM.
2825*22ce4affSfengbojiang.It Cm fq_pie
2826*22ce4affSfengbojiangimplements the FQ-PIE (FlowQueue-PIE) scheduler/AQM algorithm, which similar to
2827*22ce4affSfengbojiang.Cm fq_codel
2828*22ce4affSfengbojiangbut uses per sub-queue PIE AQM instance to control the queue delay.
2829127dd473Swhl739.El
2830*22ce4affSfengbojiang.Pp
2831*22ce4affSfengbojiang.Cm fq_codel
2832*22ce4affSfengbojianginherits AQM parameters and options from
2833*22ce4affSfengbojiang.Cm codel
2834*22ce4affSfengbojiang(see below), and
2835*22ce4affSfengbojiang.Cm fq_pie
2836*22ce4affSfengbojianginherits AQM parameters and options from
2837*22ce4affSfengbojiang.Cm pie
2838*22ce4affSfengbojiang(see below).
2839*22ce4affSfengbojiangAdditionally, both of
2840*22ce4affSfengbojiang.Cm fq_codel
2841*22ce4affSfengbojiangand
2842*22ce4affSfengbojiang.Cm fq_pie
2843*22ce4affSfengbojianghave shared scheduler parameters which are:
2844*22ce4affSfengbojiang.Bl -tag -width indent
2845*22ce4affSfengbojiang.It Cm quantum
2846*22ce4affSfengbojiang.Ar m
2847*22ce4affSfengbojiangspecifies the quantum (credit) of the scheduler.
2848*22ce4affSfengbojiang.Ar m
2849*22ce4affSfengbojiangis the number of bytes a queue can serve before being moved to the tail
2850*22ce4affSfengbojiangof old queues list.
2851*22ce4affSfengbojiangThe default is 1514 bytes, and the maximum acceptable value
2852*22ce4affSfengbojiangis 9000 bytes.
2853*22ce4affSfengbojiang.It Cm limit
2854*22ce4affSfengbojiang.Ar m
2855*22ce4affSfengbojiangspecifies the hard size limit (in unit of packets) of all queues managed by an
2856*22ce4affSfengbojianginstance of the scheduler.
2857*22ce4affSfengbojiangThe default value of
2858*22ce4affSfengbojiang.Ar m
2859*22ce4affSfengbojiangis 10240 packets, and the maximum acceptable value is 20480 packets.
2860*22ce4affSfengbojiang.It Cm flows
2861*22ce4affSfengbojiang.Ar m
2862*22ce4affSfengbojiangspecifies the total number of flow queues (sub-queues) that fq_*
2863*22ce4affSfengbojiangcreates and manages.
2864*22ce4affSfengbojiangBy default, 1024 sub-queues are created when an instance
2865*22ce4affSfengbojiangof the fq_{codel/pie} scheduler is created.
2866*22ce4affSfengbojiangThe maximum acceptable value is
2867*22ce4affSfengbojiang65536.
2868*22ce4affSfengbojiang.El
2869*22ce4affSfengbojiang.Pp
2870*22ce4affSfengbojiangNote that any token after
2871*22ce4affSfengbojiang.Cm fq_codel
2872*22ce4affSfengbojiangor
2873*22ce4affSfengbojiang.Cm fq_pie
2874*22ce4affSfengbojiangis considered a parameter for fq_{codel/pie}.
2875*22ce4affSfengbojiangSo, ensure all scheduler
2876*22ce4affSfengbojiangconfiguration options not related to fq_{codel/pie} are written before
2877*22ce4affSfengbojiang.Cm fq_codel/fq_pie
2878*22ce4affSfengbojiangtokens.
2879127dd473Swhl739.El
2880127dd473Swhl739.Pp
2881127dd473Swhl739In addition to the type, all parameters allowed for a pipe can also
2882127dd473Swhl739be specified for a scheduler.
2883127dd473Swhl739.Pp
2884127dd473Swhl739Finally, the following parameters can be configured for both
2885127dd473Swhl739pipes and queues:
2886127dd473Swhl739.Pp
2887127dd473Swhl739.Bl -tag -width XXXX -compact
2888127dd473Swhl739.It Cm buckets Ar hash-table-size
2889127dd473Swhl739Specifies the size of the hash table used for storing the
2890127dd473Swhl739various queues.
2891127dd473Swhl739Default value is 64 controlled by the
2892127dd473Swhl739.Xr sysctl 8
2893127dd473Swhl739variable
2894127dd473Swhl739.Va net.inet.ip.dummynet.hash_size ,
2895127dd473Swhl739allowed range is 16 to 65536.
2896127dd473Swhl739.Pp
2897127dd473Swhl739.It Cm mask Ar mask-specifier
2898127dd473Swhl739Packets sent to a given pipe or queue by an
2899127dd473Swhl739.Nm
2900127dd473Swhl739rule can be further classified into multiple flows, each of which is then
2901127dd473Swhl739sent to a different
2902127dd473Swhl739.Em dynamic
2903127dd473Swhl739pipe or queue.
2904127dd473Swhl739A flow identifier is constructed by masking the IP addresses,
2905127dd473Swhl739ports and protocol types as specified with the
2906127dd473Swhl739.Cm mask
2907127dd473Swhl739options in the configuration of the pipe or queue.
2908127dd473Swhl739For each different flow identifier, a new pipe or queue is created
2909127dd473Swhl739with the same parameters as the original object, and matching packets
2910127dd473Swhl739are sent to it.
2911127dd473Swhl739.Pp
2912127dd473Swhl739Thus, when
2913127dd473Swhl739.Em dynamic pipes
2914127dd473Swhl739are used, each flow will get the same bandwidth as defined by the pipe,
2915127dd473Swhl739whereas when
2916127dd473Swhl739.Em dynamic queues
2917127dd473Swhl739are used, each flow will share the parent's pipe bandwidth evenly
2918127dd473Swhl739with other flows generated by the same queue (note that other queues
2919127dd473Swhl739with different weights might be connected to the same pipe).
2920127dd473Swhl739.br
2921127dd473Swhl739Available mask specifiers are a combination of one or more of the following:
2922127dd473Swhl739.Pp
2923127dd473Swhl739.Cm dst-ip Ar mask ,
2924127dd473Swhl739.Cm dst-ip6 Ar mask ,
2925127dd473Swhl739.Cm src-ip Ar mask ,
2926127dd473Swhl739.Cm src-ip6 Ar mask ,
2927127dd473Swhl739.Cm dst-port Ar mask ,
2928127dd473Swhl739.Cm src-port Ar mask ,
2929127dd473Swhl739.Cm flow-id Ar mask ,
2930127dd473Swhl739.Cm proto Ar mask
2931127dd473Swhl739or
2932127dd473Swhl739.Cm all ,
2933127dd473Swhl739.Pp
2934127dd473Swhl739where the latter means all bits in all fields are significant.
2935127dd473Swhl739.Pp
2936127dd473Swhl739.It Cm noerror
2937127dd473Swhl739When a packet is dropped by a
2938127dd473Swhl739.Nm dummynet
2939127dd473Swhl739queue or pipe, the error
2940127dd473Swhl739is normally reported to the caller routine in the kernel, in the
2941127dd473Swhl739same way as it happens when a device queue fills up.
2942127dd473Swhl739Setting this
2943127dd473Swhl739option reports the packet as successfully delivered, which can be
2944127dd473Swhl739needed for some experimental setups where you want to simulate
2945127dd473Swhl739loss or congestion at a remote router.
2946127dd473Swhl739.Pp
2947127dd473Swhl739.It Cm plr Ar packet-loss-rate
2948127dd473Swhl739Packet loss rate.
2949127dd473Swhl739Argument
2950127dd473Swhl739.Ar packet-loss-rate
2951127dd473Swhl739is a floating-point number between 0 and 1, with 0 meaning no
2952127dd473Swhl739loss, 1 meaning 100% loss.
2953127dd473Swhl739The loss rate is internally represented on 31 bits.
2954127dd473Swhl739.Pp
2955127dd473Swhl739.It Cm queue Brq Ar slots | size Ns Cm Kbytes
2956127dd473Swhl739Queue size, in
2957127dd473Swhl739.Ar slots
2958127dd473Swhl739or
2959127dd473Swhl739.Cm KBytes .
2960127dd473Swhl739Default value is 50 slots, which
2961127dd473Swhl739is the typical queue size for Ethernet devices.
2962127dd473Swhl739Note that for slow speed links you should keep the queue
2963127dd473Swhl739size short or your traffic might be affected by a significant
2964127dd473Swhl739queueing delay.
2965*22ce4affSfengbojiangE.g., 50 max-sized Ethernet packets (1500 bytes) mean 600Kbit
2966127dd473Swhl739or 20s of queue on a 30Kbit/s pipe.
2967127dd473Swhl739Even worse effects can result if you get packets from an
2968127dd473Swhl739interface with a much larger MTU, e.g.\& the loopback interface
2969127dd473Swhl739with its 16KB packets.
2970127dd473Swhl739The
2971127dd473Swhl739.Xr sysctl 8
2972127dd473Swhl739variables
2973127dd473Swhl739.Em net.inet.ip.dummynet.pipe_byte_limit
2974127dd473Swhl739and
2975127dd473Swhl739.Em net.inet.ip.dummynet.pipe_slot_limit
2976127dd473Swhl739control the maximum lengths that can be specified.
2977127dd473Swhl739.Pp
2978127dd473Swhl739.It Cm red | gred Ar w_q Ns / Ns Ar min_th Ns / Ns Ar max_th Ns / Ns Ar max_p
2979127dd473Swhl739[ecn]
2980127dd473Swhl739Make use of the RED (Random Early Detection) queue management algorithm.
2981127dd473Swhl739.Ar w_q
2982127dd473Swhl739and
2983127dd473Swhl739.Ar max_p
2984127dd473Swhl739are floating
2985127dd473Swhl739point numbers between 0 and 1 (inclusive), while
2986127dd473Swhl739.Ar min_th
2987127dd473Swhl739and
2988127dd473Swhl739.Ar max_th
2989127dd473Swhl739are integer numbers specifying thresholds for queue management
2990127dd473Swhl739(thresholds are computed in bytes if the queue has been defined
2991127dd473Swhl739in bytes, in slots otherwise).
2992*22ce4affSfengbojiangThe two parameters can also be of the same value if needed.
2993*22ce4affSfengbojiangThe
2994127dd473Swhl739.Nm dummynet
2995127dd473Swhl739also supports the gentle RED variant (gred) and ECN (Explicit Congestion
2996*22ce4affSfengbojiangNotification) as optional.
2997*22ce4affSfengbojiangThree
2998127dd473Swhl739.Xr sysctl 8
2999127dd473Swhl739variables can be used to control the RED behaviour:
3000127dd473Swhl739.Bl -tag -width indent
3001127dd473Swhl739.It Va net.inet.ip.dummynet.red_lookup_depth
3002127dd473Swhl739specifies the accuracy in computing the average queue
3003127dd473Swhl739when the link is idle (defaults to 256, must be greater than zero)
3004127dd473Swhl739.It Va net.inet.ip.dummynet.red_avg_pkt_size
3005127dd473Swhl739specifies the expected average packet size (defaults to 512, must be
3006127dd473Swhl739greater than zero)
3007127dd473Swhl739.It Va net.inet.ip.dummynet.red_max_pkt_size
3008127dd473Swhl739specifies the expected maximum packet size, only used when queue
3009127dd473Swhl739thresholds are in bytes (defaults to 1500, must be greater than zero).
3010127dd473Swhl739.El
3011*22ce4affSfengbojiang.Pp
3012*22ce4affSfengbojiang.It Cm codel Oo Cm target Ar time Oc Oo Cm interval Ar time Oc Oo Cm ecn |
3013*22ce4affSfengbojiang.Cm noecn Oc
3014*22ce4affSfengbojiangMake use of the CoDel (Controlled-Delay) queue management algorithm.
3015*22ce4affSfengbojiang.Ar time
3016*22ce4affSfengbojiangis interpreted as milliseconds by default but seconds (s), milliseconds (ms) or
3017*22ce4affSfengbojiangmicroseconds (us) can be specified instead.
3018*22ce4affSfengbojiangCoDel drops or marks (ECN) packets
3019*22ce4affSfengbojiangdepending on packet sojourn time in the queue.
3020*22ce4affSfengbojiang.Cm target
3021*22ce4affSfengbojiang.Ar time
3022*22ce4affSfengbojiang(5ms by default) is the minimum acceptable persistent queue delay that CoDel
3023*22ce4affSfengbojiangallows.
3024*22ce4affSfengbojiangCoDel does not drop packets directly after packets sojourn time becomes
3025*22ce4affSfengbojianghigher than
3026*22ce4affSfengbojiang.Cm target
3027*22ce4affSfengbojiang.Ar time
3028*22ce4affSfengbojiangbut waits for
3029*22ce4affSfengbojiang.Cm interval
3030*22ce4affSfengbojiang.Ar time
3031*22ce4affSfengbojiang(100ms default) before dropping.
3032*22ce4affSfengbojiang.Cm interval
3033*22ce4affSfengbojiang.Ar time
3034*22ce4affSfengbojiangshould be set to maximum RTT for all expected connections.
3035*22ce4affSfengbojiang.Cm ecn
3036*22ce4affSfengbojiangenables (disabled by default) packet marking (instead of dropping) for
3037*22ce4affSfengbojiangECN-enabled TCP flows when queue delay becomes high.
3038*22ce4affSfengbojiang.Pp
3039*22ce4affSfengbojiangNote that any token after
3040*22ce4affSfengbojiang.Cm codel
3041*22ce4affSfengbojiangis considered a parameter for CoDel.
3042*22ce4affSfengbojiangSo, ensure all pipe/queue
3043*22ce4affSfengbojiangconfiguration options are written before
3044*22ce4affSfengbojiang.Cm codel
3045*22ce4affSfengbojiangtoken.
3046*22ce4affSfengbojiang.Pp
3047*22ce4affSfengbojiangThe
3048*22ce4affSfengbojiang.Xr sysctl 8
3049*22ce4affSfengbojiangvariables
3050*22ce4affSfengbojiang.Va net.inet.ip.dummynet.codel.target
3051*22ce4affSfengbojiangand
3052*22ce4affSfengbojiang.Va net.inet.ip.dummynet.codel.interval
3053*22ce4affSfengbojiangcan be used to set CoDel default parameters.
3054*22ce4affSfengbojiang.Pp
3055*22ce4affSfengbojiang.It Cm pie Oo Cm target Ar time Oc Oo Cm tupdate Ar time Oc Oo
3056*22ce4affSfengbojiang.Cm alpha Ar n Oc Oo Cm beta Ar n Oc Oo Cm max_burst Ar time Oc Oo
3057*22ce4affSfengbojiang.Cm max_ecnth Ar n Oc Oo Cm ecn | Cm noecn Oc Oo Cm capdrop |
3058*22ce4affSfengbojiang.Cm nocapdrop Oc Oo Cm drand | Cm nodrand Oc Oo Cm onoff
3059*22ce4affSfengbojiang.Oc Oo Cm dre | Cm ts Oc
3060*22ce4affSfengbojiangMake use of the PIE (Proportional Integral controller Enhanced) queue management
3061*22ce4affSfengbojiangalgorithm.
3062*22ce4affSfengbojiangPIE drops or marks packets depending on a calculated drop probability during
3063*22ce4affSfengbojiangen-queue process, with the aim of achieving high throughput while keeping queue
3064*22ce4affSfengbojiangdelay low.
3065*22ce4affSfengbojiangAt regular time intervals of
3066*22ce4affSfengbojiang.Cm tupdate
3067*22ce4affSfengbojiang.Ar time
3068*22ce4affSfengbojiang(15ms by default) a background process (re)calculates the probability based on queue delay
3069*22ce4affSfengbojiangdeviations from
3070*22ce4affSfengbojiang.Cm target
3071*22ce4affSfengbojiang.Ar time
3072*22ce4affSfengbojiang(15ms by default) and queue delay trends.
3073*22ce4affSfengbojiangPIE approximates current queue
3074*22ce4affSfengbojiangdelay by using a departure rate estimation method, or (optionally) by using a
3075*22ce4affSfengbojiangpacket timestamp method similar to CoDel.
3076*22ce4affSfengbojiang.Ar time
3077*22ce4affSfengbojiangis interpreted as milliseconds by default but seconds (s), milliseconds (ms) or
3078*22ce4affSfengbojiangmicroseconds (us) can be specified instead.
3079*22ce4affSfengbojiangThe other PIE parameters and options are as follows:
3080*22ce4affSfengbojiang.Bl -tag -width indent
3081*22ce4affSfengbojiang.It Cm alpha Ar n
3082*22ce4affSfengbojiang.Ar n
3083*22ce4affSfengbojiangis a floating point number between 0 and 7 which specifies the weight of queue
3084*22ce4affSfengbojiangdelay deviations that is used in drop probability calculation.
3085*22ce4affSfengbojiang0.125 is the default.
3086*22ce4affSfengbojiang.It Cm beta Ar n
3087*22ce4affSfengbojiang.Ar n
3088*22ce4affSfengbojiangis a floating point number between 0 and 7 which specifies is the weight of queue
3089*22ce4affSfengbojiangdelay trend that is used in drop probability calculation.
3090*22ce4affSfengbojiang1.25 is the default.
3091*22ce4affSfengbojiang.It Cm max_burst Ar time
3092*22ce4affSfengbojiangThe maximum period of time that PIE does not drop/mark packets.
3093*22ce4affSfengbojiang150ms is the
3094*22ce4affSfengbojiangdefault and 10s is the maximum value.
3095*22ce4affSfengbojiang.It Cm max_ecnth Ar n
3096*22ce4affSfengbojiangEven when ECN is enabled, PIE drops packets instead of marking them when drop
3097*22ce4affSfengbojiangprobability becomes higher than ECN probability threshold
3098*22ce4affSfengbojiang.Cm max_ecnth Ar n
3099*22ce4affSfengbojiang, the default is 0.1 (i.e 10%) and 1 is the maximum value.
3100*22ce4affSfengbojiang.It Cm ecn | noecn
3101*22ce4affSfengbojiangenable or disable ECN marking for ECN-enabled TCP flows.
3102*22ce4affSfengbojiangDisabled by default.
3103*22ce4affSfengbojiang.It Cm capdrop | nocapdrop
3104*22ce4affSfengbojiangenable or disable cap drop adjustment.
3105*22ce4affSfengbojiangCap drop adjustment is enabled by default.
3106*22ce4affSfengbojiang.It Cm drand | nodrand
3107*22ce4affSfengbojiangenable or disable drop probability de-randomisation.
3108*22ce4affSfengbojiangDe-randomisation eliminates
3109*22ce4affSfengbojiangthe problem of dropping packets too close or too far.
3110*22ce4affSfengbojiangDe-randomisation is enabled by default.
3111*22ce4affSfengbojiang.It Cm onoff
3112*22ce4affSfengbojiangenable turning PIE on and off depending on queue load.
3113*22ce4affSfengbojiangIf this option is enabled,
3114*22ce4affSfengbojiangPIE turns on when over 1/3 of queue becomes full.
3115*22ce4affSfengbojiangThis option is disabled by
3116*22ce4affSfengbojiangdefault.
3117*22ce4affSfengbojiang.It Cm dre | ts
3118*22ce4affSfengbojiangCalculate queue delay using departure rate estimation
3119*22ce4affSfengbojiang.Cm dre
3120*22ce4affSfengbojiangor timestamps
3121*22ce4affSfengbojiang.Cm ts .
3122*22ce4affSfengbojiang.Cm dre
3123*22ce4affSfengbojiangis used by default.
3124*22ce4affSfengbojiang.El
3125*22ce4affSfengbojiang.Pp
3126*22ce4affSfengbojiangNote that any token after
3127*22ce4affSfengbojiang.Cm pie
3128*22ce4affSfengbojiangis considered a parameter for PIE.
3129*22ce4affSfengbojiangSo ensure all pipe/queue
3130*22ce4affSfengbojiangthe configuration options are written before
3131*22ce4affSfengbojiang.Cm pie
3132*22ce4affSfengbojiangtoken.
3133*22ce4affSfengbojiang.Xr sysctl 8
3134*22ce4affSfengbojiangvariables can be used to control the
3135*22ce4affSfengbojiang.Cm pie
3136*22ce4affSfengbojiangdefault parameters.
3137*22ce4affSfengbojiangSee the
3138*22ce4affSfengbojiang.Sx SYSCTL VARIABLES
3139*22ce4affSfengbojiangsection for more details.
3140127dd473Swhl739.El
3141127dd473Swhl739.Pp
3142127dd473Swhl739When used with IPv6 data,
3143127dd473Swhl739.Nm dummynet
3144127dd473Swhl739currently has several limitations.
3145127dd473Swhl739Information necessary to route link-local packets to an
3146127dd473Swhl739interface is not available after processing by
3147127dd473Swhl739.Nm dummynet
3148127dd473Swhl739so those packets are dropped in the output path.
3149127dd473Swhl739Care should be taken to ensure that link-local packets are not passed to
3150127dd473Swhl739.Nm dummynet .
3151127dd473Swhl739.Sh CHECKLIST
3152127dd473Swhl739Here are some important points to consider when designing your
3153127dd473Swhl739rules:
3154127dd473Swhl739.Bl -bullet
3155127dd473Swhl739.It
3156127dd473Swhl739Remember that you filter both packets going
3157127dd473Swhl739.Cm in
3158127dd473Swhl739and
3159127dd473Swhl739.Cm out .
3160127dd473Swhl739Most connections need packets going in both directions.
3161127dd473Swhl739.It
3162127dd473Swhl739Remember to test very carefully.
3163127dd473Swhl739It is a good idea to be near the console when doing this.
3164127dd473Swhl739If you cannot be near the console,
3165127dd473Swhl739use an auto-recovery script such as the one in
3166127dd473Swhl739.Pa /usr/share/examples/ipfw/change_rules.sh .
3167127dd473Swhl739.It
3168127dd473Swhl739Do not forget the loopback interface.
3169127dd473Swhl739.El
3170127dd473Swhl739.Sh FINE POINTS
3171127dd473Swhl739.Bl -bullet
3172127dd473Swhl739.It
3173127dd473Swhl739There are circumstances where fragmented datagrams are unconditionally
3174127dd473Swhl739dropped.
3175127dd473Swhl739TCP packets are dropped if they do not contain at least 20 bytes of
3176127dd473Swhl739TCP header, UDP packets are dropped if they do not contain a full 8
3177127dd473Swhl739byte UDP header, and ICMP packets are dropped if they do not contain
3178127dd473Swhl7394 bytes of ICMP header, enough to specify the ICMP type, code, and
3179127dd473Swhl739checksum.
3180127dd473Swhl739These packets are simply logged as
3181127dd473Swhl739.Dq pullup failed
3182127dd473Swhl739since there may not be enough good data in the packet to produce a
3183127dd473Swhl739meaningful log entry.
3184127dd473Swhl739.It
3185127dd473Swhl739Another type of packet is unconditionally dropped, a TCP packet with a
3186127dd473Swhl739fragment offset of one.
3187127dd473Swhl739This is a valid packet, but it only has one use, to try
3188127dd473Swhl739to circumvent firewalls.
3189127dd473Swhl739When logging is enabled, these packets are
3190127dd473Swhl739reported as being dropped by rule -1.
3191127dd473Swhl739.It
3192127dd473Swhl739If you are logged in over a network, loading the
3193127dd473Swhl739.Xr kld 4
3194127dd473Swhl739version of
3195127dd473Swhl739.Nm
3196127dd473Swhl739is probably not as straightforward as you would think.
3197127dd473Swhl739The following command line is recommended:
3198127dd473Swhl739.Bd -literal -offset indent
3199127dd473Swhl739kldload ipfw && \e
3200127dd473Swhl739ipfw add 32000 allow ip from any to any
3201127dd473Swhl739.Ed
3202127dd473Swhl739.Pp
3203127dd473Swhl739Along the same lines, doing an
3204127dd473Swhl739.Bd -literal -offset indent
3205127dd473Swhl739ipfw flush
3206127dd473Swhl739.Ed
3207127dd473Swhl739.Pp
3208127dd473Swhl739in similar surroundings is also a bad idea.
3209127dd473Swhl739.It
3210127dd473Swhl739The
3211127dd473Swhl739.Nm
3212127dd473Swhl739filter list may not be modified if the system security level
3213127dd473Swhl739is set to 3 or higher
3214127dd473Swhl739(see
3215127dd473Swhl739.Xr init 8
3216127dd473Swhl739for information on system security levels).
3217127dd473Swhl739.El
3218127dd473Swhl739.Sh PACKET DIVERSION
3219127dd473Swhl739A
3220127dd473Swhl739.Xr divert 4
3221127dd473Swhl739socket bound to the specified port will receive all packets
3222127dd473Swhl739diverted to that port.
3223127dd473Swhl739If no socket is bound to the destination port, or if the divert module is
3224127dd473Swhl739not loaded, or if the kernel was not compiled with divert socket support,
3225127dd473Swhl739the packets are dropped.
3226127dd473Swhl739.Sh NETWORK ADDRESS TRANSLATION (NAT)
3227127dd473Swhl739.Nm
3228127dd473Swhl739support in-kernel NAT using the kernel version of
3229127dd473Swhl739.Xr libalias 3 .
3230*22ce4affSfengbojiangThe kernel module
3231*22ce4affSfengbojiang.Cm ipfw_nat
3232*22ce4affSfengbojiangshould be loaded or kernel should have
3233*22ce4affSfengbojiang.Cm options IPFIREWALL_NAT
3234*22ce4affSfengbojiangto be able use NAT.
3235127dd473Swhl739.Pp
3236127dd473Swhl739The nat configuration command is the following:
3237127dd473Swhl739.Bd -ragged -offset indent
3238127dd473Swhl739.Bk -words
3239127dd473Swhl739.Cm nat
3240127dd473Swhl739.Ar nat_number
3241127dd473Swhl739.Cm config
3242127dd473Swhl739.Ar nat-configuration
3243127dd473Swhl739.Ek
3244127dd473Swhl739.Ed
3245127dd473Swhl739.Pp
3246127dd473Swhl739The following parameters can be configured:
3247127dd473Swhl739.Bl -tag -width indent
3248127dd473Swhl739.It Cm ip Ar ip_address
3249127dd473Swhl739Define an ip address to use for aliasing.
3250127dd473Swhl739.It Cm if Ar nic
3251127dd473Swhl739Use ip address of NIC for aliasing, dynamically changing
3252127dd473Swhl739it if NIC's ip address changes.
3253127dd473Swhl739.It Cm log
3254127dd473Swhl739Enable logging on this nat instance.
3255127dd473Swhl739.It Cm deny_in
3256127dd473Swhl739Deny any incoming connection from outside world.
3257127dd473Swhl739.It Cm same_ports
3258127dd473Swhl739Try to leave the alias port numbers unchanged from
3259127dd473Swhl739the actual local port numbers.
3260127dd473Swhl739.It Cm unreg_only
3261*22ce4affSfengbojiangTraffic on the local network not originating from a RFC 1918
3262127dd473Swhl739unregistered address spaces will be ignored.
3263*22ce4affSfengbojiang.It Cm unreg_cgn
3264*22ce4affSfengbojiangLike unreg_only, but includes the RFC 6598 (Carrier Grade NAT)
3265*22ce4affSfengbojiangaddress range.
3266127dd473Swhl739.It Cm reset
3267127dd473Swhl739Reset table of the packet aliasing engine on address change.
3268127dd473Swhl739.It Cm reverse
3269127dd473Swhl739Reverse the way libalias handles aliasing.
3270127dd473Swhl739.It Cm proxy_only
3271127dd473Swhl739Obey transparent proxy rules only, packet aliasing is not performed.
3272127dd473Swhl739.It Cm skip_global
3273127dd473Swhl739Skip instance in case of global state lookup (see below).
3274127dd473Swhl739.El
3275127dd473Swhl739.Pp
3276127dd473Swhl739Some specials value can be supplied instead of
3277127dd473Swhl739.Va nat_number :
3278127dd473Swhl739.Bl -tag -width indent
3279127dd473Swhl739.It Cm global
3280127dd473Swhl739Looks up translation state in all configured nat instances.
3281127dd473Swhl739If an entry is found, packet is aliased according to that entry.
3282127dd473Swhl739If no entry was found in any of the instances, packet is passed unchanged,
3283127dd473Swhl739and no new entry will be created.
3284127dd473Swhl739See section
3285127dd473Swhl739.Sx MULTIPLE INSTANCES
3286127dd473Swhl739in
3287127dd473Swhl739.Xr natd 8
3288127dd473Swhl739for more information.
3289127dd473Swhl739.It Cm tablearg
3290127dd473Swhl739Uses argument supplied in lookup table.
3291127dd473Swhl739See
3292127dd473Swhl739.Sx LOOKUP TABLES
3293127dd473Swhl739section below for more information on lookup tables.
3294127dd473Swhl739.El
3295127dd473Swhl739.Pp
3296127dd473Swhl739To let the packet continue after being (de)aliased, set the sysctl variable
3297127dd473Swhl739.Va net.inet.ip.fw.one_pass
3298127dd473Swhl739to 0.
3299127dd473Swhl739For more information about aliasing modes, refer to
3300127dd473Swhl739.Xr libalias 3 .
3301127dd473Swhl739See Section
3302127dd473Swhl739.Sx EXAMPLES
3303127dd473Swhl739for some examples about nat usage.
3304127dd473Swhl739.Ss REDIRECT AND LSNAT SUPPORT IN IPFW
3305127dd473Swhl739Redirect and LSNAT support follow closely the syntax used in
3306127dd473Swhl739.Xr natd 8 .
3307127dd473Swhl739See Section
3308127dd473Swhl739.Sx EXAMPLES
3309127dd473Swhl739for some examples on how to do redirect and lsnat.
3310127dd473Swhl739.Ss SCTP NAT SUPPORT
3311127dd473Swhl739SCTP nat can be configured in a similar manner to TCP through the
3312127dd473Swhl739.Nm
3313127dd473Swhl739command line tool.
3314127dd473Swhl739The main difference is that
3315127dd473Swhl739.Nm sctp nat
3316127dd473Swhl739does not do port translation.
3317127dd473Swhl739Since the local and global side ports will be the same,
3318127dd473Swhl739there is no need to specify both.
3319127dd473Swhl739Ports are redirected as follows:
3320127dd473Swhl739.Bd -ragged -offset indent
3321127dd473Swhl739.Bk -words
3322127dd473Swhl739.Cm nat
3323127dd473Swhl739.Ar nat_number
3324127dd473Swhl739.Cm config if
3325127dd473Swhl739.Ar nic
3326127dd473Swhl739.Cm redirect_port sctp
3327127dd473Swhl739.Ar ip_address [,addr_list] {[port | port-port] [,ports]}
3328127dd473Swhl739.Ek
3329127dd473Swhl739.Ed
3330127dd473Swhl739.Pp
3331127dd473Swhl739Most
3332127dd473Swhl739.Nm sctp nat
3333127dd473Swhl739configuration can be done in real-time through the
3334127dd473Swhl739.Xr sysctl 8
3335127dd473Swhl739interface.
3336127dd473Swhl739All may be changed dynamically, though the hash_table size will only
3337127dd473Swhl739change for new
3338127dd473Swhl739.Nm nat
3339127dd473Swhl739instances.
3340127dd473Swhl739See
3341127dd473Swhl739.Sx SYSCTL VARIABLES
3342127dd473Swhl739for more info.
3343*22ce4affSfengbojiang.Sh IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION
3344*22ce4affSfengbojiang.Ss Stateful translation
3345*22ce4affSfengbojiang.Nm
3346*22ce4affSfengbojiangsupports in-kernel IPv6/IPv4 network address and protocol translation.
3347*22ce4affSfengbojiangStateful NAT64 translation allows IPv6-only clients to contact IPv4 servers
3348*22ce4affSfengbojiangusing unicast TCP, UDP or ICMP protocols.
3349*22ce4affSfengbojiangOne or more IPv4 addresses assigned to a stateful NAT64 translator are shared
3350*22ce4affSfengbojiangamong several IPv6-only clients.
3351*22ce4affSfengbojiangWhen stateful NAT64 is used in conjunction with DNS64, no changes are usually
3352*22ce4affSfengbojiangrequired in the IPv6 client or the IPv4 server.
3353*22ce4affSfengbojiangThe kernel module
3354*22ce4affSfengbojiang.Cm ipfw_nat64
3355*22ce4affSfengbojiangshould be loaded or kernel should have
3356*22ce4affSfengbojiang.Cm options IPFIREWALL_NAT64
3357*22ce4affSfengbojiangto be able use stateful NAT64 translator.
3358*22ce4affSfengbojiang.Pp
3359*22ce4affSfengbojiangStateful NAT64 uses a bunch of memory for several types of objects.
3360*22ce4affSfengbojiangWhen IPv6 client initiates connection, NAT64 translator creates a host entry
3361*22ce4affSfengbojiangin the states table.
3362*22ce4affSfengbojiangEach host entry uses preallocated IPv4 alias entry.
3363*22ce4affSfengbojiangEach alias entry has a number of ports group entries allocated on demand.
3364*22ce4affSfengbojiangPorts group entries contains connection state entries.
3365*22ce4affSfengbojiangThere are several options to control limits and lifetime for these objects.
3366*22ce4affSfengbojiang.Pp
3367*22ce4affSfengbojiangNAT64 translator follows RFC7915 when does ICMPv6/ICMP translation,
3368*22ce4affSfengbojiangunsupported message types will be silently dropped.
3369*22ce4affSfengbojiangIPv6 needs several ICMPv6 message types to be explicitly allowed for correct
3370*22ce4affSfengbojiangoperation.
3371*22ce4affSfengbojiangMake sure that ND6 neighbor solicitation (ICMPv6 type 135) and neighbor
3372*22ce4affSfengbojiangadvertisement (ICMPv6 type 136) messages will not be handled by translation
3373*22ce4affSfengbojiangrules.
3374*22ce4affSfengbojiang.Pp
3375*22ce4affSfengbojiangAfter translation NAT64 translator by default sends packets through
3376*22ce4affSfengbojiangcorresponding netisr queue.
3377*22ce4affSfengbojiangThus translator host should be configured as IPv4 and IPv6 router.
3378*22ce4affSfengbojiangAlso this means, that a packet is handled by firewall twice.
3379*22ce4affSfengbojiangFirst time an original packet is handled and consumed by translator,
3380*22ce4affSfengbojiangand then it is handled again as translated packet.
3381*22ce4affSfengbojiangThis behavior can be changed by sysctl variable
3382*22ce4affSfengbojiang.Va net.inet.ip.fw.nat64_direct_output .
3383*22ce4affSfengbojiangAlso translated packet can be tagged using
3384*22ce4affSfengbojiang.Cm tag
3385*22ce4affSfengbojiangrule action, and then matched by
3386*22ce4affSfengbojiang.Cm tagged
3387*22ce4affSfengbojiangopcode to avoid loops and extra overhead.
3388*22ce4affSfengbojiang.Pp
3389*22ce4affSfengbojiangThe stateful NAT64 configuration command is the following:
3390*22ce4affSfengbojiang.Bd -ragged -offset indent
3391*22ce4affSfengbojiang.Bk -words
3392*22ce4affSfengbojiang.Cm nat64lsn
3393*22ce4affSfengbojiang.Ar name
3394*22ce4affSfengbojiang.Cm create
3395*22ce4affSfengbojiang.Ar create-options
3396*22ce4affSfengbojiang.Ek
3397*22ce4affSfengbojiang.Ed
3398*22ce4affSfengbojiang.Pp
3399*22ce4affSfengbojiangThe following parameters can be configured:
3400*22ce4affSfengbojiang.Bl -tag -width indent
3401*22ce4affSfengbojiang.It Cm prefix4 Ar ipv4_prefix/plen
3402*22ce4affSfengbojiangThe IPv4 prefix with mask defines the pool of IPv4 addresses used as
3403*22ce4affSfengbojiangsource address after translation.
3404*22ce4affSfengbojiangStateful NAT64 module translates IPv6 source address of client to one
3405*22ce4affSfengbojiangIPv4 address from this pool.
3406*22ce4affSfengbojiangNote that incoming IPv4 packets that don't have corresponding state entry
3407*22ce4affSfengbojiangin the states table will be dropped by translator.
3408*22ce4affSfengbojiangMake sure that translation rules handle packets, destined to configured prefix.
3409*22ce4affSfengbojiang.It Cm prefix6 Ar ipv6_prefix/length
3410*22ce4affSfengbojiangThe IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator
3411*22ce4affSfengbojiangto represent IPv4 addresses.
3412*22ce4affSfengbojiangThis IPv6 prefix should be configured in DNS64.
3413*22ce4affSfengbojiangThe translator implementation follows RFC6052, that restricts the length of
3414*22ce4affSfengbojiangprefixes to one of following: 32, 40, 48, 56, 64, or 96.
3415*22ce4affSfengbojiangThe Well-Known IPv6 Prefix 64:ff9b:: must be 96 bits long.
3416*22ce4affSfengbojiangThe special
3417*22ce4affSfengbojiang.Ar ::/length
3418*22ce4affSfengbojiangprefix can be used to handle several IPv6 prefixes with one NAT64 instance.
3419*22ce4affSfengbojiangThe NAT64 instance will determine a destination IPv4 address from prefix
3420*22ce4affSfengbojiang.Ar length .
3421*22ce4affSfengbojiang.It Cm states_chunks Ar number
3422*22ce4affSfengbojiangThe number of states chunks in single ports group.
3423*22ce4affSfengbojiangEach ports group by default can keep 64 state entries in single chunk.
3424*22ce4affSfengbojiangThe above value affects the maximum number of states that can be associated with single IPv4 alias address and port.
3425*22ce4affSfengbojiangThe value must be power of 2, and up to 128.
3426*22ce4affSfengbojiang.It Cm host_del_age Ar seconds
3427*22ce4affSfengbojiangThe number of seconds until the host entry for a IPv6 client will be deleted
3428*22ce4affSfengbojiangand all its resources will be released due to inactivity.
3429*22ce4affSfengbojiangDefault value is
3430*22ce4affSfengbojiang.Ar 3600 .
3431*22ce4affSfengbojiang.It Cm pg_del_age Ar seconds
3432*22ce4affSfengbojiangThe number of seconds until a ports group with unused state entries will
3433*22ce4affSfengbojiangbe released.
3434*22ce4affSfengbojiangDefault value is
3435*22ce4affSfengbojiang.Ar 900 .
3436*22ce4affSfengbojiang.It Cm tcp_syn_age Ar seconds
3437*22ce4affSfengbojiangThe number of seconds while a state entry for TCP connection with only SYN
3438*22ce4affSfengbojiangsent will be kept.
3439*22ce4affSfengbojiangIf TCP connection establishing will not be finished,
3440*22ce4affSfengbojiangstate entry will be deleted.
3441*22ce4affSfengbojiangDefault value is
3442*22ce4affSfengbojiang.Ar 10 .
3443*22ce4affSfengbojiang.It Cm tcp_est_age Ar seconds
3444*22ce4affSfengbojiangThe number of seconds while a state entry for established TCP connection
3445*22ce4affSfengbojiangwill be kept.
3446*22ce4affSfengbojiangDefault value is
3447*22ce4affSfengbojiang.Ar 7200 .
3448*22ce4affSfengbojiang.It Cm tcp_close_age Ar seconds
3449*22ce4affSfengbojiangThe number of seconds while a state entry for closed TCP connection
3450*22ce4affSfengbojiangwill be kept.
3451*22ce4affSfengbojiangKeeping state entries for closed connections is needed, because IPv4 servers
3452*22ce4affSfengbojiangtypically keep closed connections in a TIME_WAIT state for a several minutes.
3453*22ce4affSfengbojiangSince translator's IPv4 addresses are shared among all IPv6 clients,
3454*22ce4affSfengbojiangnew connections from the same addresses and ports may be rejected by server,
3455*22ce4affSfengbojiangbecause these connections are still in a TIME_WAIT state.
3456*22ce4affSfengbojiangKeeping them in translator's state table protects from such rejects.
3457*22ce4affSfengbojiangDefault value is
3458*22ce4affSfengbojiang.Ar 180 .
3459*22ce4affSfengbojiang.It Cm udp_age Ar seconds
3460*22ce4affSfengbojiangThe number of seconds while translator keeps state entry in a waiting for
3461*22ce4affSfengbojiangreply to the sent UDP datagram.
3462*22ce4affSfengbojiangDefault value is
3463*22ce4affSfengbojiang.Ar 120 .
3464*22ce4affSfengbojiang.It Cm icmp_age Ar seconds
3465*22ce4affSfengbojiangThe number of seconds while translator keeps state entry in a waiting for
3466*22ce4affSfengbojiangreply to the sent ICMP message.
3467*22ce4affSfengbojiangDefault value is
3468*22ce4affSfengbojiang.Ar 60 .
3469*22ce4affSfengbojiang.It Cm log
3470*22ce4affSfengbojiangTurn on logging of all handled packets via BPF through
3471*22ce4affSfengbojiang.Ar ipfwlog0
3472*22ce4affSfengbojianginterface.
3473*22ce4affSfengbojiang.Ar ipfwlog0
3474*22ce4affSfengbojiangis a pseudo interface and can be created after a boot manually with
3475*22ce4affSfengbojiang.Cm ifconfig
3476*22ce4affSfengbojiangcommand.
3477*22ce4affSfengbojiangNote that it has different purpose than
3478*22ce4affSfengbojiang.Ar ipfw0
3479*22ce4affSfengbojianginterface.
3480*22ce4affSfengbojiangTranslators sends to BPF an additional information with each packet.
3481*22ce4affSfengbojiangWith
3482*22ce4affSfengbojiang.Cm tcpdump
3483*22ce4affSfengbojiangyou are able to see each handled packet before and after translation.
3484*22ce4affSfengbojiang.It Cm -log
3485*22ce4affSfengbojiangTurn off logging of all handled packets via BPF.
3486*22ce4affSfengbojiang.It Cm allow_private
3487*22ce4affSfengbojiangTurn on processing private IPv4 addresses.
3488*22ce4affSfengbojiangBy default IPv6 packets with destinations mapped to private address ranges
3489*22ce4affSfengbojiangdefined by RFC1918 are not processed.
3490*22ce4affSfengbojiang.It Cm -allow_private
3491*22ce4affSfengbojiangTurn off private address handling in
3492*22ce4affSfengbojiang.Nm nat64
3493*22ce4affSfengbojianginstance.
3494*22ce4affSfengbojiang.El
3495*22ce4affSfengbojiang.Pp
3496*22ce4affSfengbojiangTo inspect a states table of stateful NAT64 the following command can be used:
3497*22ce4affSfengbojiang.Bd -ragged -offset indent
3498*22ce4affSfengbojiang.Bk -words
3499*22ce4affSfengbojiang.Cm nat64lsn
3500*22ce4affSfengbojiang.Ar name
3501*22ce4affSfengbojiang.Cm show Cm states
3502*22ce4affSfengbojiang.Ek
3503*22ce4affSfengbojiang.Ed
3504*22ce4affSfengbojiang.Pp
3505*22ce4affSfengbojiangStateless NAT64 translator doesn't use a states table for translation
3506*22ce4affSfengbojiangand converts IPv4 addresses to IPv6 and vice versa solely based on the
3507*22ce4affSfengbojiangmappings taken from configured lookup tables.
3508*22ce4affSfengbojiangSince a states table doesn't used by stateless translator,
3509*22ce4affSfengbojiangit can be configured to pass IPv4 clients to IPv6-only servers.
3510*22ce4affSfengbojiang.Pp
3511*22ce4affSfengbojiangThe stateless NAT64 configuration command is the following:
3512*22ce4affSfengbojiang.Bd -ragged -offset indent
3513*22ce4affSfengbojiang.Bk -words
3514*22ce4affSfengbojiang.Cm nat64stl
3515*22ce4affSfengbojiang.Ar name
3516*22ce4affSfengbojiang.Cm create
3517*22ce4affSfengbojiang.Ar create-options
3518*22ce4affSfengbojiang.Ek
3519*22ce4affSfengbojiang.Ed
3520*22ce4affSfengbojiang.Pp
3521*22ce4affSfengbojiangThe following parameters can be configured:
3522*22ce4affSfengbojiang.Bl -tag -width indent
3523*22ce4affSfengbojiang.It Cm prefix6 Ar ipv6_prefix/length
3524*22ce4affSfengbojiangThe IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator
3525*22ce4affSfengbojiangto represent IPv4 addresses.
3526*22ce4affSfengbojiangThis IPv6 prefix should be configured in DNS64.
3527*22ce4affSfengbojiang.It Cm table4 Ar table46
3528*22ce4affSfengbojiangThe lookup table
3529*22ce4affSfengbojiang.Ar table46
3530*22ce4affSfengbojiangcontains mapping how IPv4 addresses should be translated to IPv6 addresses.
3531*22ce4affSfengbojiang.It Cm table6 Ar table64
3532*22ce4affSfengbojiangThe lookup table
3533*22ce4affSfengbojiang.Ar table64
3534*22ce4affSfengbojiangcontains mapping how IPv6 addresses should be translated to IPv4 addresses.
3535*22ce4affSfengbojiang.It Cm log
3536*22ce4affSfengbojiangTurn on logging of all handled packets via BPF through
3537*22ce4affSfengbojiang.Ar ipfwlog0
3538*22ce4affSfengbojianginterface.
3539*22ce4affSfengbojiang.It Cm -log
3540*22ce4affSfengbojiangTurn off logging of all handled packets via BPF.
3541*22ce4affSfengbojiang.It Cm allow_private
3542*22ce4affSfengbojiangTurn on processing private IPv4 addresses.
3543*22ce4affSfengbojiangBy default IPv6 packets with destinations mapped to private address ranges
3544*22ce4affSfengbojiangdefined by RFC1918 are not processed.
3545*22ce4affSfengbojiang.It Cm -allow_private
3546*22ce4affSfengbojiangTurn off private address handling in
3547*22ce4affSfengbojiang.Nm nat64
3548*22ce4affSfengbojianginstance.
3549*22ce4affSfengbojiang.El
3550*22ce4affSfengbojiang.Pp
3551*22ce4affSfengbojiangNote that the behavior of stateless translator with respect to not matched
3552*22ce4affSfengbojiangpackets differs from stateful translator.
3553*22ce4affSfengbojiangIf corresponding addresses was not found in the lookup tables, the packet
3554*22ce4affSfengbojiangwill not be dropped and the search continues.
3555*22ce4affSfengbojiang.Ss XLAT464 CLAT translation
3556*22ce4affSfengbojiangXLAT464 CLAT NAT64 translator implements client-side stateless translation as
3557*22ce4affSfengbojiangdefined in RFC6877 and is very similar to statless NAT64 translator
3558*22ce4affSfengbojiangexplained above.
3559*22ce4affSfengbojiangInstead of lookup tables it uses one-to-one mapping between IPv4 and IPv6
3560*22ce4affSfengbojiangaddresses using configured prefixes.
3561*22ce4affSfengbojiangThis mode can be used as a replacement of DNS64 service for applications
3562*22ce4affSfengbojiangthat are not using it (e.g. VoIP) allowing them to access IPv4-only Internet
3563*22ce4affSfengbojiangover IPv6-only networks with help of remote NAT64 translator.
3564*22ce4affSfengbojiang.Pp
3565*22ce4affSfengbojiangThe CLAT NAT64 configuration command is the following:
3566*22ce4affSfengbojiang.Bd -ragged -offset indent
3567*22ce4affSfengbojiang.Bk -words
3568*22ce4affSfengbojiang.Cm nat64clat
3569*22ce4affSfengbojiang.Ar name
3570*22ce4affSfengbojiang.Cm create
3571*22ce4affSfengbojiang.Ar create-options
3572*22ce4affSfengbojiang.Ek
3573*22ce4affSfengbojiang.Ed
3574*22ce4affSfengbojiang.Pp
3575*22ce4affSfengbojiangThe following parameters can be configured:
3576*22ce4affSfengbojiang.Bl -tag -width indent
3577*22ce4affSfengbojiang.It Cm clat_prefix Ar ipv6_prefix/length
3578*22ce4affSfengbojiangThe IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator
3579*22ce4affSfengbojiangto represent source IPv4 addresses.
3580*22ce4affSfengbojiang.It Cm plat_prefix Ar ipv6_prefix/length
3581*22ce4affSfengbojiangThe IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator
3582*22ce4affSfengbojiangto represent destination IPv4 addresses.
3583*22ce4affSfengbojiangThis IPv6 prefix should be configured on a remote NAT64 translator.
3584*22ce4affSfengbojiang.It Cm log
3585*22ce4affSfengbojiangTurn on logging of all handled packets via BPF through
3586*22ce4affSfengbojiang.Ar ipfwlog0
3587*22ce4affSfengbojianginterface.
3588*22ce4affSfengbojiang.It Cm -log
3589*22ce4affSfengbojiangTurn off logging of all handled packets via BPF.
3590*22ce4affSfengbojiang.It Cm allow_private
3591*22ce4affSfengbojiangTurn on processing private IPv4 addresses.
3592*22ce4affSfengbojiangBy default
3593*22ce4affSfengbojiang.Nm nat64clat
3594*22ce4affSfengbojianginstance will not process IPv4 packets with destination address from private
3595*22ce4affSfengbojiangranges as defined in RFC1918.
3596*22ce4affSfengbojiang.It Cm -allow_private
3597*22ce4affSfengbojiangTurn off private address handling in
3598*22ce4affSfengbojiang.Nm nat64clat
3599*22ce4affSfengbojianginstance.
3600*22ce4affSfengbojiang.El
3601*22ce4affSfengbojiang.Pp
3602*22ce4affSfengbojiangNote that the behavior of CLAT translator with respect to not matched
3603*22ce4affSfengbojiangpackets differs from stateful translator.
3604*22ce4affSfengbojiangIf corresponding addresses were not matched against prefixes configured,
3605*22ce4affSfengbojiangthe packet will not be dropped and the search continues.
3606*22ce4affSfengbojiang.Sh IPv6-to-IPv6 NETWORK PREFIX TRANSLATION (NPTv6)
3607*22ce4affSfengbojiang.Nm
3608*22ce4affSfengbojiangsupports in-kernel IPv6-to-IPv6 network prefix translation as described
3609*22ce4affSfengbojiangin RFC6296.
3610*22ce4affSfengbojiangThe kernel module
3611*22ce4affSfengbojiang.Cm ipfw_nptv6
3612*22ce4affSfengbojiangshould be loaded or kernel should has
3613*22ce4affSfengbojiang.Cm options IPFIREWALL_NPTV6
3614*22ce4affSfengbojiangto be able use NPTv6 translator.
3615*22ce4affSfengbojiang.Pp
3616*22ce4affSfengbojiangThe NPTv6 configuration command is the following:
3617*22ce4affSfengbojiang.Bd -ragged -offset indent
3618*22ce4affSfengbojiang.Bk -words
3619*22ce4affSfengbojiang.Cm nptv6
3620*22ce4affSfengbojiang.Ar name
3621*22ce4affSfengbojiang.Cm create
3622*22ce4affSfengbojiang.Ar create-options
3623*22ce4affSfengbojiang.Ek
3624*22ce4affSfengbojiang.Ed
3625*22ce4affSfengbojiang.Pp
3626*22ce4affSfengbojiangThe following parameters can be configured:
3627*22ce4affSfengbojiang.Bl -tag -width indent
3628*22ce4affSfengbojiang.It Cm int_prefix Ar ipv6_prefix
3629*22ce4affSfengbojiangIPv6 prefix used in internal network.
3630*22ce4affSfengbojiangNPTv6 module translates source address when it matches this prefix.
3631*22ce4affSfengbojiang.It Cm ext_prefix Ar ipv6_prefix
3632*22ce4affSfengbojiangIPv6 prefix used in external network.
3633*22ce4affSfengbojiangNPTv6 module translates destination address when it matches this prefix.
3634*22ce4affSfengbojiang.It Cm ext_if Ar nic
3635*22ce4affSfengbojiangThe NPTv6 module will use first global IPv6 address from interface
3636*22ce4affSfengbojiang.Ar nic
3637*22ce4affSfengbojiangas external prefix.
3638*22ce4affSfengbojiangIt can be useful when IPv6 prefix of external network is dynamically obtained.
3639*22ce4affSfengbojiang.Cm ext_prefix
3640*22ce4affSfengbojiangand
3641*22ce4affSfengbojiang.Cm ext_if
3642*22ce4affSfengbojiangoptions are mutually exclusive.
3643*22ce4affSfengbojiang.It Cm prefixlen Ar length
3644*22ce4affSfengbojiangThe length of specified IPv6 prefixes.
3645*22ce4affSfengbojiangIt must be in range from 8 to 64.
3646*22ce4affSfengbojiang.El
3647*22ce4affSfengbojiang.Pp
3648*22ce4affSfengbojiangNote that the prefix translation rules are silently ignored when IPv6 packet
3649*22ce4affSfengbojiangforwarding is disabled.
3650*22ce4affSfengbojiangTo enable the packet forwarding, set the sysctl variable
3651*22ce4affSfengbojiang.Va net.inet6.ip6.forwarding
3652*22ce4affSfengbojiangto 1.
3653*22ce4affSfengbojiang.Pp
3654*22ce4affSfengbojiangTo let the packet continue after being translated, set the sysctl variable
3655*22ce4affSfengbojiang.Va net.inet.ip.fw.one_pass
3656*22ce4affSfengbojiangto 0.
3657127dd473Swhl739.Sh LOADER TUNABLES
3658127dd473Swhl739Tunables can be set in
3659127dd473Swhl739.Xr loader 8
3660127dd473Swhl739prompt,
3661127dd473Swhl739.Xr loader.conf 5
3662127dd473Swhl739or
3663127dd473Swhl739.Xr kenv 1
3664127dd473Swhl739before ipfw module gets loaded.
3665127dd473Swhl739.Bl -tag -width indent
3666127dd473Swhl739.It Va net.inet.ip.fw.default_to_accept : No 0
3667127dd473Swhl739Defines ipfw last rule behavior.
3668127dd473Swhl739This value overrides
3669127dd473Swhl739.Cd "options IPFW_DEFAULT_TO_(ACCEPT|DENY)"
3670127dd473Swhl739from kernel configuration file.
3671127dd473Swhl739.It Va net.inet.ip.fw.tables_max : No 128
3672127dd473Swhl739Defines number of tables available in ipfw.
3673127dd473Swhl739Number cannot exceed 65534.
3674127dd473Swhl739.El
3675127dd473Swhl739.Sh SYSCTL VARIABLES
3676127dd473Swhl739A set of
3677127dd473Swhl739.Xr sysctl 8
3678127dd473Swhl739variables controls the behaviour of the firewall and
3679127dd473Swhl739associated modules
3680127dd473Swhl739.Pq Nm dummynet , bridge , sctp nat .
3681127dd473Swhl739These are shown below together with their default value
3682127dd473Swhl739(but always check with the
3683127dd473Swhl739.Xr sysctl 8
3684127dd473Swhl739command what value is actually in use) and meaning:
3685127dd473Swhl739.Bl -tag -width indent
3686127dd473Swhl739.It Va net.inet.ip.alias.sctp.accept_global_ootb_addip : No 0
3687127dd473Swhl739Defines how the
3688127dd473Swhl739.Nm nat
3689127dd473Swhl739responds to receipt of global OOTB ASCONF-AddIP:
3690127dd473Swhl739.Bl -tag -width indent
3691127dd473Swhl739.It Cm 0
3692127dd473Swhl739No response (unless a partially matching association exists -
3693127dd473Swhl739ports and vtags match but global address does not)
3694127dd473Swhl739.It Cm 1
3695127dd473Swhl739.Nm nat
3696127dd473Swhl739will accept and process all OOTB global AddIP messages.
3697127dd473Swhl739.El
3698127dd473Swhl739.Pp
3699127dd473Swhl739Option 1 should never be selected as this forms a security risk.
3700127dd473Swhl739An attacker can
3701127dd473Swhl739establish multiple fake associations by sending AddIP messages.
3702127dd473Swhl739.It Va net.inet.ip.alias.sctp.chunk_proc_limit : No 5
3703127dd473Swhl739Defines the maximum number of chunks in an SCTP packet that will be
3704127dd473Swhl739parsed for a
3705127dd473Swhl739packet that matches an existing association.
3706127dd473Swhl739This value is enforced to be greater or equal than
3707127dd473Swhl739.Cm net.inet.ip.alias.sctp.initialising_chunk_proc_limit .
3708127dd473Swhl739A high value is
3709127dd473Swhl739a DoS risk yet setting too low a value may result in
3710127dd473Swhl739important control chunks in
3711127dd473Swhl739the packet not being located and parsed.
3712127dd473Swhl739.It Va net.inet.ip.alias.sctp.error_on_ootb : No 1
3713127dd473Swhl739Defines when the
3714127dd473Swhl739.Nm nat
3715127dd473Swhl739responds to any Out-of-the-Blue (OOTB) packets with ErrorM packets.
3716127dd473Swhl739An OOTB packet is a packet that arrives with no existing association
3717127dd473Swhl739registered in the
3718127dd473Swhl739.Nm nat
3719127dd473Swhl739and is not an INIT or ASCONF-AddIP packet:
3720127dd473Swhl739.Bl -tag -width indent
3721127dd473Swhl739.It Cm 0
3722127dd473Swhl739ErrorM is never sent in response to OOTB packets.
3723127dd473Swhl739.It Cm 1
3724127dd473Swhl739ErrorM is only sent to OOTB packets received on the local side.
3725127dd473Swhl739.It Cm 2
3726127dd473Swhl739ErrorM is sent to the local side and on the global side ONLY if there is a
3727127dd473Swhl739partial match (ports and vtags match but the source global IP does not).
3728127dd473Swhl739This value is only useful if the
3729127dd473Swhl739.Nm nat
3730127dd473Swhl739is tracking global IP addresses.
3731127dd473Swhl739.It Cm 3
3732127dd473Swhl739ErrorM is sent in response to all OOTB packets on both
3733127dd473Swhl739the local and global side
3734127dd473Swhl739(DoS risk).
3735127dd473Swhl739.El
3736127dd473Swhl739.Pp
3737127dd473Swhl739At the moment the default is 0, since the ErrorM packet is not yet
3738127dd473Swhl739supported by most SCTP stacks.
3739127dd473Swhl739When it is supported, and if not tracking
3740127dd473Swhl739global addresses, we recommend setting this value to 1 to allow
3741127dd473Swhl739multi-homed local hosts to function with the
3742127dd473Swhl739.Nm nat .
3743127dd473Swhl739To track global addresses, we recommend setting this value to 2 to
3744127dd473Swhl739allow global hosts to be informed when they need to (re)send an
3745127dd473Swhl739ASCONF-AddIP.
3746127dd473Swhl739Value 3 should never be chosen (except for debugging) as the
3747127dd473Swhl739.Nm nat
3748127dd473Swhl739will respond to all OOTB global packets (a DoS risk).
3749127dd473Swhl739.It Va net.inet.ip.alias.sctp.hashtable_size : No 2003
3750127dd473Swhl739Size of hash tables used for
3751127dd473Swhl739.Nm nat
3752127dd473Swhl739lookups (100 < prime_number > 1000001).
3753127dd473Swhl739This value sets the
3754127dd473Swhl739.Nm hash table
3755127dd473Swhl739size for any future created
3756127dd473Swhl739.Nm nat
3757127dd473Swhl739instance and therefore must be set prior to creating a
3758127dd473Swhl739.Nm nat
3759127dd473Swhl739instance.
3760127dd473Swhl739The table sizes may be changed to suit specific needs.
3761127dd473Swhl739If there will be few
3762127dd473Swhl739concurrent associations, and memory is scarce, you may make these smaller.
3763127dd473Swhl739If there will be many thousands (or millions) of concurrent associations, you
3764127dd473Swhl739should make these larger.
3765127dd473Swhl739A prime number is best for the table size.
3766127dd473Swhl739The sysctl
3767127dd473Swhl739update function will adjust your input value to the next highest prime number.
3768127dd473Swhl739.It Va net.inet.ip.alias.sctp.holddown_time : No 0
3769127dd473Swhl739Hold association in table for this many seconds after receiving a
3770127dd473Swhl739SHUTDOWN-COMPLETE.
3771127dd473Swhl739This allows endpoints to correct shutdown gracefully if a
3772127dd473Swhl739shutdown_complete is lost and retransmissions are required.
3773127dd473Swhl739.It Va net.inet.ip.alias.sctp.init_timer : No 15
3774127dd473Swhl739Timeout value while waiting for (INIT-ACK|AddIP-ACK).
3775127dd473Swhl739This value cannot be 0.
3776127dd473Swhl739.It Va net.inet.ip.alias.sctp.initialising_chunk_proc_limit : No 2
3777127dd473Swhl739Defines the maximum number of chunks in an SCTP packet that will be parsed when
3778127dd473Swhl739no existing association exists that matches that packet.
3779127dd473Swhl739Ideally this packet
3780127dd473Swhl739will only be an INIT or ASCONF-AddIP packet.
3781127dd473Swhl739A higher value may become a DoS
3782127dd473Swhl739risk as malformed packets can consume processing resources.
3783127dd473Swhl739.It Va net.inet.ip.alias.sctp.param_proc_limit : No 25
3784127dd473Swhl739Defines the maximum number of parameters within a chunk that will be
3785127dd473Swhl739parsed in a
3786127dd473Swhl739packet.
3787127dd473Swhl739As for other similar sysctl variables, larger values pose a DoS risk.
3788127dd473Swhl739.It Va net.inet.ip.alias.sctp.log_level : No 0
3789127dd473Swhl739Level of detail in the system log messages (0 \- minimal, 1 \- event,
3790127dd473Swhl7392 \- info, 3 \- detail, 4 \- debug, 5 \- max debug).
3791127dd473Swhl739May be a good
3792127dd473Swhl739option in high loss environments.
3793127dd473Swhl739.It Va net.inet.ip.alias.sctp.shutdown_time : No 15
3794127dd473Swhl739Timeout value while waiting for SHUTDOWN-COMPLETE.
3795127dd473Swhl739This value cannot be 0.
3796127dd473Swhl739.It Va net.inet.ip.alias.sctp.track_global_addresses : No 0
3797127dd473Swhl739Enables/disables global IP address tracking within the
3798127dd473Swhl739.Nm nat
3799127dd473Swhl739and places an
3800127dd473Swhl739upper limit on the number of addresses tracked for each association:
3801127dd473Swhl739.Bl -tag -width indent
3802127dd473Swhl739.It Cm 0
3803127dd473Swhl739Global tracking is disabled
3804127dd473Swhl739.It Cm >1
3805127dd473Swhl739Enables tracking, the maximum number of addresses tracked for each
3806127dd473Swhl739association is limited to this value
3807127dd473Swhl739.El
3808127dd473Swhl739.Pp
3809127dd473Swhl739This variable is fully dynamic, the new value will be adopted for all newly
3810127dd473Swhl739arriving associations, existing associations are treated
3811127dd473Swhl739as they were previously.
3812127dd473Swhl739Global tracking will decrease the number of collisions within the
3813127dd473Swhl739.Nm nat
3814127dd473Swhl739at a cost
3815127dd473Swhl739of increased processing load, memory usage, complexity, and possible
3816127dd473Swhl739.Nm nat
3817127dd473Swhl739state
3818127dd473Swhl739problems in complex networks with multiple
3819127dd473Swhl739.Nm nats .
3820127dd473Swhl739We recommend not tracking
3821127dd473Swhl739global IP addresses, this will still result in a fully functional
3822127dd473Swhl739.Nm nat .
3823127dd473Swhl739.It Va net.inet.ip.alias.sctp.up_timer : No 300
3824127dd473Swhl739Timeout value to keep an association up with no traffic.
3825127dd473Swhl739This value cannot be 0.
3826*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.codel.interval : No 100000
3827*22ce4affSfengbojiangDefault
3828*22ce4affSfengbojiang.Cm codel
3829*22ce4affSfengbojiangAQM interval in microseconds.
3830*22ce4affSfengbojiangThe value must be in the range 1..5000000.
3831*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.codel.target : No 5000
3832*22ce4affSfengbojiangDefault
3833*22ce4affSfengbojiang.Cm codel
3834*22ce4affSfengbojiangAQM target delay time in microseconds (the minimum acceptable persistent queue
3835*22ce4affSfengbojiangdelay).
3836*22ce4affSfengbojiangThe value must be in the range 1..5000000.
3837127dd473Swhl739.It Va net.inet.ip.dummynet.expire : No 1
3838127dd473Swhl739Lazily delete dynamic pipes/queue once they have no pending traffic.
3839127dd473Swhl739You can disable this by setting the variable to 0, in which case
3840127dd473Swhl739the pipes/queues will only be deleted when the threshold is reached.
3841*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqcodel.flows : No 1024
3842*22ce4affSfengbojiangDefines the default total number of flow queues (sub-queues) that
3843*22ce4affSfengbojiang.Cm fq_codel
3844*22ce4affSfengbojiangcreates and manages.
3845*22ce4affSfengbojiangThe value must be in the range 1..65536.
3846*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqcodel.interval : No 100000
3847*22ce4affSfengbojiangDefault
3848*22ce4affSfengbojiang.Cm fq_codel
3849*22ce4affSfengbojiangscheduler/AQM interval in microseconds.
3850*22ce4affSfengbojiangThe value must be in the range 1..5000000.
3851*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqcodel.limit : No 10240
3852*22ce4affSfengbojiangThe default hard size limit (in unit of packet) of all queues managed by an
3853*22ce4affSfengbojianginstance of the
3854*22ce4affSfengbojiang.Cm fq_codel
3855*22ce4affSfengbojiangscheduler.
3856*22ce4affSfengbojiangThe value must be in the range 1..20480.
3857*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqcodel.quantum : No 1514
3858*22ce4affSfengbojiangThe default quantum (credit) of the
3859*22ce4affSfengbojiang.Cm fq_codel
3860*22ce4affSfengbojiangin unit of byte.
3861*22ce4affSfengbojiangThe value must be in the range 1..9000.
3862*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqcodel.target : No 5000
3863*22ce4affSfengbojiangDefault
3864*22ce4affSfengbojiang.Cm fq_codel
3865*22ce4affSfengbojiangscheduler/AQM target delay time in microseconds (the minimum acceptable
3866*22ce4affSfengbojiangpersistent queue delay).
3867*22ce4affSfengbojiangThe value must be in the range 1..5000000.
3868*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqpie.alpha : No 125
3869*22ce4affSfengbojiangThe default
3870*22ce4affSfengbojiang.Ar alpha
3871*22ce4affSfengbojiangparameter (scaled by 1000) for
3872*22ce4affSfengbojiang.Cm fq_pie
3873*22ce4affSfengbojiangscheduler/AQM.
3874*22ce4affSfengbojiangThe value must be in the range 1..7000.
3875*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqpie.beta : No 1250
3876*22ce4affSfengbojiangThe default
3877*22ce4affSfengbojiang.Ar beta
3878*22ce4affSfengbojiangparameter (scaled by 1000) for
3879*22ce4affSfengbojiang.Cm fq_pie
3880*22ce4affSfengbojiangscheduler/AQM.
3881*22ce4affSfengbojiangThe value must be in the range 1..7000.
3882*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqpie.flows : No 1024
3883*22ce4affSfengbojiangDefines the default total number of flow queues (sub-queues) that
3884*22ce4affSfengbojiang.Cm fq_pie
3885*22ce4affSfengbojiangcreates and manages.
3886*22ce4affSfengbojiangThe value must be in the range 1..65536.
3887*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqpie.limit : No 10240
3888*22ce4affSfengbojiangThe default hard size limit (in unit of packet) of all queues managed by an
3889*22ce4affSfengbojianginstance of the
3890*22ce4affSfengbojiang.Cm fq_pie
3891*22ce4affSfengbojiangscheduler.
3892*22ce4affSfengbojiangThe value must be in the range 1..20480.
3893*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqpie.max_burst : No 150000
3894*22ce4affSfengbojiangThe default maximum period of microseconds that
3895*22ce4affSfengbojiang.Cm fq_pie
3896*22ce4affSfengbojiangscheduler/AQM does not drop/mark packets.
3897*22ce4affSfengbojiangThe value must be in the range 1..10000000.
3898*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqpie.max_ecnth : No 99
3899*22ce4affSfengbojiangThe default maximum ECN probability threshold (scaled by 1000) for
3900*22ce4affSfengbojiang.Cm fq_pie
3901*22ce4affSfengbojiangscheduler/AQM.
3902*22ce4affSfengbojiangThe value must be in the range 1..7000.
3903*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqpie.quantum : No 1514
3904*22ce4affSfengbojiangThe default quantum (credit) of the
3905*22ce4affSfengbojiang.Cm fq_pie
3906*22ce4affSfengbojiangin unit of byte.
3907*22ce4affSfengbojiangThe value must be in the range 1..9000.
3908*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqpie.target : No 15000
3909*22ce4affSfengbojiangThe default
3910*22ce4affSfengbojiang.Cm target
3911*22ce4affSfengbojiangdelay of the
3912*22ce4affSfengbojiang.Cm fq_pie
3913*22ce4affSfengbojiangin unit of microsecond.
3914*22ce4affSfengbojiangThe value must be in the range 1..5000000.
3915*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.fqpie.tupdate : No 15000
3916*22ce4affSfengbojiangThe default
3917*22ce4affSfengbojiang.Cm tupdate
3918*22ce4affSfengbojiangof the
3919*22ce4affSfengbojiang.Cm fq_pie
3920*22ce4affSfengbojiangin unit of microsecond.
3921*22ce4affSfengbojiangThe value must be in the range 1..5000000.
3922127dd473Swhl739.It Va net.inet.ip.dummynet.hash_size : No 64
3923127dd473Swhl739Default size of the hash table used for dynamic pipes/queues.
3924127dd473Swhl739This value is used when no
3925127dd473Swhl739.Cm buckets
3926127dd473Swhl739option is specified when configuring a pipe/queue.
3927127dd473Swhl739.It Va net.inet.ip.dummynet.io_fast : No 0
3928127dd473Swhl739If set to a non-zero value,
3929127dd473Swhl739the
3930127dd473Swhl739.Dq fast
3931127dd473Swhl739mode of
3932127dd473Swhl739.Nm dummynet
3933127dd473Swhl739operation (see above) is enabled.
3934127dd473Swhl739.It Va net.inet.ip.dummynet.io_pkt
3935127dd473Swhl739Number of packets passed to
3936127dd473Swhl739.Nm dummynet .
3937127dd473Swhl739.It Va net.inet.ip.dummynet.io_pkt_drop
3938127dd473Swhl739Number of packets dropped by
3939127dd473Swhl739.Nm dummynet .
3940127dd473Swhl739.It Va net.inet.ip.dummynet.io_pkt_fast
3941127dd473Swhl739Number of packets bypassed by the
3942127dd473Swhl739.Nm dummynet
3943127dd473Swhl739scheduler.
3944127dd473Swhl739.It Va net.inet.ip.dummynet.max_chain_len : No 16
3945127dd473Swhl739Target value for the maximum number of pipes/queues in a hash bucket.
3946127dd473Swhl739The product
3947127dd473Swhl739.Cm max_chain_len*hash_size
3948127dd473Swhl739is used to determine the threshold over which empty pipes/queues
3949127dd473Swhl739will be expired even when
3950127dd473Swhl739.Cm net.inet.ip.dummynet.expire=0 .
3951127dd473Swhl739.It Va net.inet.ip.dummynet.red_lookup_depth : No 256
3952127dd473Swhl739.It Va net.inet.ip.dummynet.red_avg_pkt_size : No 512
3953127dd473Swhl739.It Va net.inet.ip.dummynet.red_max_pkt_size : No 1500
3954127dd473Swhl739Parameters used in the computations of the drop probability
3955127dd473Swhl739for the RED algorithm.
3956*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.pie.alpha : No 125
3957*22ce4affSfengbojiangThe default
3958*22ce4affSfengbojiang.Ar alpha
3959*22ce4affSfengbojiangparameter (scaled by 1000) for
3960*22ce4affSfengbojiang.Cm pie
3961*22ce4affSfengbojiangAQM.
3962*22ce4affSfengbojiangThe value must be in the range 1..7000.
3963*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.pie.beta : No 1250
3964*22ce4affSfengbojiangThe default
3965*22ce4affSfengbojiang.Ar beta
3966*22ce4affSfengbojiangparameter (scaled by 1000) for
3967*22ce4affSfengbojiang.Cm pie
3968*22ce4affSfengbojiangAQM.
3969*22ce4affSfengbojiangThe value must be in the range 1..7000.
3970*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.pie.max_burst : No 150000
3971*22ce4affSfengbojiangThe default maximum period of microseconds that
3972*22ce4affSfengbojiang.Cm pie
3973*22ce4affSfengbojiangAQM does not drop/mark packets.
3974*22ce4affSfengbojiangThe value must be in the range 1..10000000.
3975*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.pie.max_ecnth : No 99
3976*22ce4affSfengbojiangThe default maximum ECN probability threshold (scaled by 1000) for
3977*22ce4affSfengbojiang.Cm pie
3978*22ce4affSfengbojiangAQM.
3979*22ce4affSfengbojiangThe value must be in the range 1..7000.
3980*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.pie.target : No 15000
3981*22ce4affSfengbojiangThe default
3982*22ce4affSfengbojiang.Cm target
3983*22ce4affSfengbojiangdelay of
3984*22ce4affSfengbojiang.Cm pie
3985*22ce4affSfengbojiangAQM in unit of microsecond.
3986*22ce4affSfengbojiangThe value must be in the range 1..5000000.
3987*22ce4affSfengbojiang.It Va net.inet.ip.dummynet.pie.tupdate : No 15000
3988*22ce4affSfengbojiangThe default
3989*22ce4affSfengbojiang.Cm tupdate
3990*22ce4affSfengbojiangof
3991*22ce4affSfengbojiang.Cm pie
3992*22ce4affSfengbojiangAQM in unit of microsecond.
3993*22ce4affSfengbojiangThe value must be in the range 1..5000000.
3994127dd473Swhl739.It Va net.inet.ip.dummynet.pipe_byte_limit : No 1048576
3995127dd473Swhl739.It Va net.inet.ip.dummynet.pipe_slot_limit : No 100
3996127dd473Swhl739The maximum queue size that can be specified in bytes or packets.
3997127dd473Swhl739These limits prevent accidental exhaustion of resources such as mbufs.
3998127dd473Swhl739If you raise these limits,
3999127dd473Swhl739you should make sure the system is configured so that sufficient resources
4000127dd473Swhl739are available.
4001127dd473Swhl739.It Va net.inet.ip.fw.autoinc_step : No 100
4002127dd473Swhl739Delta between rule numbers when auto-generating them.
4003127dd473Swhl739The value must be in the range 1..1000.
4004127dd473Swhl739.It Va net.inet.ip.fw.curr_dyn_buckets : Va net.inet.ip.fw.dyn_buckets
4005127dd473Swhl739The current number of buckets in the hash table for dynamic rules
4006127dd473Swhl739(readonly).
4007127dd473Swhl739.It Va net.inet.ip.fw.debug : No 1
4008127dd473Swhl739Controls debugging messages produced by
4009127dd473Swhl739.Nm .
4010127dd473Swhl739.It Va net.inet.ip.fw.default_rule : No 65535
4011127dd473Swhl739The default rule number (read-only).
4012127dd473Swhl739By the design of
4013127dd473Swhl739.Nm , the default rule is the last one, so its number
4014127dd473Swhl739can also serve as the highest number allowed for a rule.
4015127dd473Swhl739.It Va net.inet.ip.fw.dyn_buckets : No 256
4016127dd473Swhl739The number of buckets in the hash table for dynamic rules.
4017127dd473Swhl739Must be a power of 2, up to 65536.
4018127dd473Swhl739It only takes effect when all dynamic rules have expired, so you
4019127dd473Swhl739are advised to use a
4020127dd473Swhl739.Cm flush
4021127dd473Swhl739command to make sure that the hash table is resized.
4022127dd473Swhl739.It Va net.inet.ip.fw.dyn_count : No 3
4023127dd473Swhl739Current number of dynamic rules
4024127dd473Swhl739(read-only).
4025127dd473Swhl739.It Va net.inet.ip.fw.dyn_keepalive : No 1
4026127dd473Swhl739Enables generation of keepalive packets for
4027127dd473Swhl739.Cm keep-state
4028127dd473Swhl739rules on TCP sessions.
4029127dd473Swhl739A keepalive is generated to both
4030127dd473Swhl739sides of the connection every 5 seconds for the last 20
4031127dd473Swhl739seconds of the lifetime of the rule.
4032127dd473Swhl739.It Va net.inet.ip.fw.dyn_max : No 8192
4033127dd473Swhl739Maximum number of dynamic rules.
4034127dd473Swhl739When you hit this limit, no more dynamic rules can be
4035127dd473Swhl739installed until old ones expire.
4036127dd473Swhl739.It Va net.inet.ip.fw.dyn_ack_lifetime : No 300
4037127dd473Swhl739.It Va net.inet.ip.fw.dyn_syn_lifetime : No 20
4038127dd473Swhl739.It Va net.inet.ip.fw.dyn_fin_lifetime : No 1
4039127dd473Swhl739.It Va net.inet.ip.fw.dyn_rst_lifetime : No 1
4040127dd473Swhl739.It Va net.inet.ip.fw.dyn_udp_lifetime : No 5
4041127dd473Swhl739.It Va net.inet.ip.fw.dyn_short_lifetime : No 30
4042127dd473Swhl739These variables control the lifetime, in seconds, of dynamic
4043127dd473Swhl739rules.
4044127dd473Swhl739Upon the initial SYN exchange the lifetime is kept short,
4045127dd473Swhl739then increased after both SYN have been seen, then decreased
4046127dd473Swhl739again during the final FIN exchange or when a RST is received.
4047127dd473Swhl739Both
4048127dd473Swhl739.Em dyn_fin_lifetime
4049127dd473Swhl739and
4050127dd473Swhl739.Em dyn_rst_lifetime
4051127dd473Swhl739must be strictly lower than 5 seconds, the period of
4052127dd473Swhl739repetition of keepalives.
4053127dd473Swhl739The firewall enforces that.
4054127dd473Swhl739.It Va net.inet.ip.fw.dyn_keep_states : No 0
4055127dd473Swhl739Keep dynamic states on rule/set deletion.
4056127dd473Swhl739States are relinked to default rule (65535).
4057127dd473Swhl739This can be handly for ruleset reload.
4058127dd473Swhl739Turned off by default.
4059127dd473Swhl739.It Va net.inet.ip.fw.enable : No 1
4060127dd473Swhl739Enables the firewall.
4061127dd473Swhl739Setting this variable to 0 lets you run your machine without
4062127dd473Swhl739firewall even if compiled in.
4063127dd473Swhl739.It Va net.inet6.ip6.fw.enable : No 1
4064127dd473Swhl739provides the same functionality as above for the IPv6 case.
4065127dd473Swhl739.It Va net.inet.ip.fw.one_pass : No 1
4066127dd473Swhl739When set, the packet exiting from the
4067127dd473Swhl739.Nm dummynet
4068127dd473Swhl739pipe or from
4069127dd473Swhl739.Xr ng_ipfw 4
4070127dd473Swhl739node is not passed though the firewall again.
4071127dd473Swhl739Otherwise, after an action, the packet is
4072127dd473Swhl739reinjected into the firewall at the next rule.
4073127dd473Swhl739.It Va net.inet.ip.fw.tables_max : No 128
4074127dd473Swhl739Maximum number of tables.
4075127dd473Swhl739.It Va net.inet.ip.fw.verbose : No 1
4076127dd473Swhl739Enables verbose messages.
4077127dd473Swhl739.It Va net.inet.ip.fw.verbose_limit : No 0
4078127dd473Swhl739Limits the number of messages produced by a verbose firewall.
4079127dd473Swhl739.It Va net.inet6.ip6.fw.deny_unknown_exthdrs : No 1
4080127dd473Swhl739If enabled packets with unknown IPv6 Extension Headers will be denied.
4081127dd473Swhl739.It Va net.link.ether.ipfw : No 0
4082127dd473Swhl739Controls whether layer-2 packets are passed to
4083127dd473Swhl739.Nm .
4084127dd473Swhl739Default is no.
4085127dd473Swhl739.It Va net.link.bridge.ipfw : No 0
4086127dd473Swhl739Controls whether bridged packets are passed to
4087127dd473Swhl739.Nm .
4088127dd473Swhl739Default is no.
4089*22ce4affSfengbojiang.It Va net.inet.ip.fw.nat64_debug : No 0
4090*22ce4affSfengbojiangControls debugging messages produced by
4091*22ce4affSfengbojiang.Nm ipfw_nat64
4092*22ce4affSfengbojiangmodule.
4093*22ce4affSfengbojiang.It Va net.inet.ip.fw.nat64_direct_output : No 0
4094*22ce4affSfengbojiangControls the output method used by
4095*22ce4affSfengbojiang.Nm ipfw_nat64
4096*22ce4affSfengbojiangmodule:
4097*22ce4affSfengbojiang.Bl -tag -width indent
4098*22ce4affSfengbojiang.It Cm 0
4099*22ce4affSfengbojiangA packet is handled by
4100*22ce4affSfengbojiang.Nm ipfw
4101*22ce4affSfengbojiangtwice.
4102*22ce4affSfengbojiangFirst time an original packet is handled by
4103*22ce4affSfengbojiang.Nm ipfw
4104*22ce4affSfengbojiangand consumed by
4105*22ce4affSfengbojiang.Nm ipfw_nat64
4106*22ce4affSfengbojiangtranslator.
4107*22ce4affSfengbojiangThen translated packet is queued via netisr to input processing again.
4108*22ce4affSfengbojiang.It Cm 1
4109*22ce4affSfengbojiangA packet is handled by
4110*22ce4affSfengbojiang.Nm ipfw
4111*22ce4affSfengbojiangonly once, and after translation it will be pushed directly to outgoing
4112*22ce4affSfengbojianginterface.
4113*22ce4affSfengbojiang.El
4114127dd473Swhl739.El
4115127dd473Swhl739.Sh INTERNAL DIAGNOSTICS
4116127dd473Swhl739There are some commands that may be useful to understand current state
4117127dd473Swhl739of certain subsystems inside kernel module.
4118127dd473Swhl739These commands provide debugging output which may change without notice.
4119127dd473Swhl739.Pp
4120127dd473Swhl739Currently the following commands are available as
4121127dd473Swhl739.Cm internal
4122127dd473Swhl739sub-options:
4123127dd473Swhl739.Bl -tag -width indent
4124127dd473Swhl739.It Cm iflist
4125127dd473Swhl739Lists all interface which are currently tracked by
4126127dd473Swhl739.Nm
4127127dd473Swhl739with their in-kernel status.
4128127dd473Swhl739.It Cm talist
4129127dd473Swhl739List all table lookup algorithms currently available.
4130127dd473Swhl739.El
4131127dd473Swhl739.Sh EXAMPLES
4132127dd473Swhl739There are far too many possible uses of
4133127dd473Swhl739.Nm
4134127dd473Swhl739so this Section will only give a small set of examples.
4135127dd473Swhl739.Ss BASIC PACKET FILTERING
4136127dd473Swhl739This command adds an entry which denies all tcp packets from
4137127dd473Swhl739.Em cracker.evil.org
4138127dd473Swhl739to the telnet port of
4139127dd473Swhl739.Em wolf.tambov.su
4140127dd473Swhl739from being forwarded by the host:
4141127dd473Swhl739.Pp
4142127dd473Swhl739.Dl "ipfw add deny tcp from cracker.evil.org to wolf.tambov.su telnet"
4143127dd473Swhl739.Pp
4144127dd473Swhl739This one disallows any connection from the entire cracker's
4145127dd473Swhl739network to my host:
4146127dd473Swhl739.Pp
4147127dd473Swhl739.Dl "ipfw add deny ip from 123.45.67.0/24 to my.host.org"
4148127dd473Swhl739.Pp
4149127dd473Swhl739A first and efficient way to limit access (not using dynamic rules)
4150127dd473Swhl739is the use of the following rules:
4151127dd473Swhl739.Pp
4152127dd473Swhl739.Dl "ipfw add allow tcp from any to any established"
4153127dd473Swhl739.Dl "ipfw add allow tcp from net1 portlist1 to net2 portlist2 setup"
4154127dd473Swhl739.Dl "ipfw add allow tcp from net3 portlist3 to net3 portlist3 setup"
4155127dd473Swhl739.Dl "..."
4156127dd473Swhl739.Dl "ipfw add deny tcp from any to any"
4157127dd473Swhl739.Pp
4158127dd473Swhl739The first rule will be a quick match for normal TCP packets,
4159127dd473Swhl739but it will not match the initial SYN packet, which will be
4160127dd473Swhl739matched by the
4161127dd473Swhl739.Cm setup
4162127dd473Swhl739rules only for selected source/destination pairs.
4163127dd473Swhl739All other SYN packets will be rejected by the final
4164127dd473Swhl739.Cm deny
4165127dd473Swhl739rule.
4166127dd473Swhl739.Pp
4167127dd473Swhl739If you administer one or more subnets, you can take advantage
4168127dd473Swhl739of the address sets and or-blocks and write extremely
4169127dd473Swhl739compact rulesets which selectively enable services to blocks
4170127dd473Swhl739of clients, as below:
4171127dd473Swhl739.Pp
4172127dd473Swhl739.Dl "goodguys=\*q{ 10.1.2.0/24{20,35,66,18} or 10.2.3.0/28{6,3,11} }\*q"
4173127dd473Swhl739.Dl "badguys=\*q10.1.2.0/24{8,38,60}\*q"
4174127dd473Swhl739.Dl ""
4175127dd473Swhl739.Dl "ipfw add allow ip from ${goodguys} to any"
4176127dd473Swhl739.Dl "ipfw add deny ip from ${badguys} to any"
4177127dd473Swhl739.Dl "... normal policies ..."
4178127dd473Swhl739.Pp
4179127dd473Swhl739The
4180127dd473Swhl739.Cm verrevpath
4181127dd473Swhl739option could be used to do automated anti-spoofing by adding the
4182127dd473Swhl739following to the top of a ruleset:
4183127dd473Swhl739.Pp
4184127dd473Swhl739.Dl "ipfw add deny ip from any to any not verrevpath in"
4185127dd473Swhl739.Pp
4186127dd473Swhl739This rule drops all incoming packets that appear to be coming to the
4187127dd473Swhl739system on the wrong interface.
4188127dd473Swhl739For example, a packet with a source
4189127dd473Swhl739address belonging to a host on a protected internal network would be
4190127dd473Swhl739dropped if it tried to enter the system from an external interface.
4191127dd473Swhl739.Pp
4192127dd473Swhl739The
4193127dd473Swhl739.Cm antispoof
4194127dd473Swhl739option could be used to do similar but more restricted anti-spoofing
4195127dd473Swhl739by adding the following to the top of a ruleset:
4196127dd473Swhl739.Pp
4197127dd473Swhl739.Dl "ipfw add deny ip from any to any not antispoof in"
4198127dd473Swhl739.Pp
4199127dd473Swhl739This rule drops all incoming packets that appear to be coming from another
4200127dd473Swhl739directly connected system but on the wrong interface.
4201127dd473Swhl739For example, a packet with a source address of
4202127dd473Swhl739.Li 192.168.0.0/24 ,
4203127dd473Swhl739configured on
4204127dd473Swhl739.Li fxp0 ,
4205127dd473Swhl739but coming in on
4206127dd473Swhl739.Li fxp1
4207127dd473Swhl739would be dropped.
4208127dd473Swhl739.Pp
4209127dd473Swhl739The
4210127dd473Swhl739.Cm setdscp
4211127dd473Swhl739option could be used to (re)mark user traffic,
4212127dd473Swhl739by adding the following to the appropriate place in ruleset:
4213127dd473Swhl739.Pp
4214127dd473Swhl739.Dl "ipfw add setdscp be ip from any to any dscp af11,af21"
4215*22ce4affSfengbojiang.Ss SELECTIVE MIRRORING
4216*22ce4affSfengbojiangIf your network has network traffic analyzer
4217*22ce4affSfengbojiangconnected to your host directly via dedicated interface
4218*22ce4affSfengbojiangor remotely via RSPAN vlan, you can selectively mirror
4219*22ce4affSfengbojiangsome Ethernet layer2 frames to the analyzer.
4220*22ce4affSfengbojiang.Pp
4221*22ce4affSfengbojiangFirst, make sure your firewall is already configured and runs.
4222*22ce4affSfengbojiangThen, enable layer2 processing if not already enabled:
4223*22ce4affSfengbojiang.Pp
4224*22ce4affSfengbojiang.Dl "sysctl net.link.ether.ipfw=1"
4225*22ce4affSfengbojiang.Pp
4226*22ce4affSfengbojiangNext, load needed additional kernel modules:
4227*22ce4affSfengbojiang.Pp
4228*22ce4affSfengbojiang.Dl "kldload ng_ether ng_ipfw"
4229*22ce4affSfengbojiang.Pp
4230*22ce4affSfengbojiangOptionally, make system load these modules automatically
4231*22ce4affSfengbojiangat startup:
4232*22ce4affSfengbojiang.Pp
4233*22ce4affSfengbojiang.Dl sysrc kld_list+="ng_ether ng_ipfw"
4234*22ce4affSfengbojiang.Pp
4235*22ce4affSfengbojiangNext, configure
4236*22ce4affSfengbojiang.Xr ng_ipfw 4
4237*22ce4affSfengbojiangkernel module to transmit mirrored copies of layer2 frames
4238*22ce4affSfengbojiangout via vlan900 interface:
4239*22ce4affSfengbojiang.Pp
4240*22ce4affSfengbojiang.Dl "ngctl connect ipfw: vlan900: 1 lower"
4241*22ce4affSfengbojiang.Pp
4242*22ce4affSfengbojiangThink of "1" here as of "mirroring instance index" and vlan900 is its
4243*22ce4affSfengbojiangdestination.
4244*22ce4affSfengbojiangYou can have arbitrary number of instances.
4245*22ce4affSfengbojiangRefer to
4246*22ce4affSfengbojiang.Xr ng_ipfw 4
4247*22ce4affSfengbojiangfor details.
4248*22ce4affSfengbojiang.Pp
4249*22ce4affSfengbojiangAt last, actually start mirroring of selected frames using "instance 1".
4250*22ce4affSfengbojiangFor frames incoming from em0 interface:
4251*22ce4affSfengbojiang.Pp
4252*22ce4affSfengbojiang.Dl "ipfw add ngtee 1 ip from any to 192.168.0.1 layer2 in recv em0"
4253*22ce4affSfengbojiang.Pp
4254*22ce4affSfengbojiangFor frames outgoing to em0 interface:
4255*22ce4affSfengbojiang.Pp
4256*22ce4affSfengbojiang.Dl "ipfw add ngtee 1 ip from any to 192.168.0.1 layer2 out xmit em0"
4257*22ce4affSfengbojiang.Pp
4258*22ce4affSfengbojiangFor both incoming and outgoing frames while flowing through em0:
4259*22ce4affSfengbojiang.Pp
4260*22ce4affSfengbojiang.Dl "ipfw add ngtee 1 ip from any to 192.168.0.1 layer2 via em0"
4261*22ce4affSfengbojiang.Pp
4262*22ce4affSfengbojiangMake sure you do not perform mirroring for already duplicated frames
4263*22ce4affSfengbojiangor kernel may hang as there is no safety net.
4264127dd473Swhl739.Ss DYNAMIC RULES
4265127dd473Swhl739In order to protect a site from flood attacks involving fake
4266127dd473Swhl739TCP packets, it is safer to use dynamic rules:
4267127dd473Swhl739.Pp
4268127dd473Swhl739.Dl "ipfw add check-state"
4269127dd473Swhl739.Dl "ipfw add deny tcp from any to any established"
4270127dd473Swhl739.Dl "ipfw add allow tcp from my-net to any setup keep-state"
4271127dd473Swhl739.Pp
4272127dd473Swhl739This will let the firewall install dynamic rules only for
4273127dd473Swhl739those connection which start with a regular SYN packet coming
4274127dd473Swhl739from the inside of our network.
4275127dd473Swhl739Dynamic rules are checked when encountering the first
4276127dd473Swhl739occurrence of a
4277127dd473Swhl739.Cm check-state ,
4278127dd473Swhl739.Cm keep-state
4279127dd473Swhl739or
4280127dd473Swhl739.Cm limit
4281127dd473Swhl739rule.
4282127dd473Swhl739A
4283127dd473Swhl739.Cm check-state
4284127dd473Swhl739rule should usually be placed near the beginning of the
4285127dd473Swhl739ruleset to minimize the amount of work scanning the ruleset.
4286127dd473Swhl739Your mileage may vary.
4287127dd473Swhl739.Pp
4288*22ce4affSfengbojiangFor more complex scenarios with dynamic rules
4289*22ce4affSfengbojiang.Cm record-state
4290*22ce4affSfengbojiangand
4291*22ce4affSfengbojiang.Cm defer-action
4292*22ce4affSfengbojiangcan be used to precisely control creation and checking of dynamic rules.
4293*22ce4affSfengbojiangExample of usage of these options are provided in
4294*22ce4affSfengbojiang.Sx NETWORK ADDRESS TRANSLATION (NAT)
4295*22ce4affSfengbojiangSection.
4296*22ce4affSfengbojiang.Pp
4297127dd473Swhl739To limit the number of connections a user can open
4298127dd473Swhl739you can use the following type of rules:
4299127dd473Swhl739.Pp
4300127dd473Swhl739.Dl "ipfw add allow tcp from my-net/24 to any setup limit src-addr 10"
4301127dd473Swhl739.Dl "ipfw add allow tcp from any to me setup limit src-addr 4"
4302127dd473Swhl739.Pp
4303127dd473Swhl739The former (assuming it runs on a gateway) will allow each host
4304127dd473Swhl739on a /24 network to open at most 10 TCP connections.
4305127dd473Swhl739The latter can be placed on a server to make sure that a single
4306127dd473Swhl739client does not use more than 4 simultaneous connections.
4307127dd473Swhl739.Pp
4308127dd473Swhl739.Em BEWARE :
4309127dd473Swhl739stateful rules can be subject to denial-of-service attacks
4310127dd473Swhl739by a SYN-flood which opens a huge number of dynamic rules.
4311127dd473Swhl739The effects of such attacks can be partially limited by
4312127dd473Swhl739acting on a set of
4313127dd473Swhl739.Xr sysctl 8
4314127dd473Swhl739variables which control the operation of the firewall.
4315127dd473Swhl739.Pp
4316127dd473Swhl739Here is a good usage of the
4317127dd473Swhl739.Cm list
4318127dd473Swhl739command to see accounting records and timestamp information:
4319127dd473Swhl739.Pp
4320127dd473Swhl739.Dl ipfw -at list
4321127dd473Swhl739.Pp
4322127dd473Swhl739or in short form without timestamps:
4323127dd473Swhl739.Pp
4324127dd473Swhl739.Dl ipfw -a list
4325127dd473Swhl739.Pp
4326127dd473Swhl739which is equivalent to:
4327127dd473Swhl739.Pp
4328127dd473Swhl739.Dl ipfw show
4329127dd473Swhl739.Pp
4330127dd473Swhl739Next rule diverts all incoming packets from 192.168.2.0/24
4331127dd473Swhl739to divert port 5000:
4332127dd473Swhl739.Pp
4333127dd473Swhl739.Dl ipfw divert 5000 ip from 192.168.2.0/24 to any in
4334127dd473Swhl739.Ss TRAFFIC SHAPING
4335127dd473Swhl739The following rules show some of the applications of
4336127dd473Swhl739.Nm
4337127dd473Swhl739and
4338127dd473Swhl739.Nm dummynet
4339127dd473Swhl739for simulations and the like.
4340127dd473Swhl739.Pp
4341127dd473Swhl739This rule drops random incoming packets with a probability
4342127dd473Swhl739of 5%:
4343127dd473Swhl739.Pp
4344127dd473Swhl739.Dl "ipfw add prob 0.05 deny ip from any to any in"
4345127dd473Swhl739.Pp
4346127dd473Swhl739A similar effect can be achieved making use of
4347127dd473Swhl739.Nm dummynet
4348127dd473Swhl739pipes:
4349127dd473Swhl739.Pp
4350127dd473Swhl739.Dl "ipfw add pipe 10 ip from any to any"
4351127dd473Swhl739.Dl "ipfw pipe 10 config plr 0.05"
4352127dd473Swhl739.Pp
4353127dd473Swhl739We can use pipes to artificially limit bandwidth, e.g.\& on a
4354127dd473Swhl739machine acting as a router, if we want to limit traffic from
4355127dd473Swhl739local clients on 192.168.2.0/24 we do:
4356127dd473Swhl739.Pp
4357127dd473Swhl739.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
4358127dd473Swhl739.Dl "ipfw pipe 1 config bw 300Kbit/s queue 50KBytes"
4359127dd473Swhl739.Pp
4360127dd473Swhl739note that we use the
4361127dd473Swhl739.Cm out
4362127dd473Swhl739modifier so that the rule is not used twice.
4363127dd473Swhl739Remember in fact that
4364127dd473Swhl739.Nm
4365127dd473Swhl739rules are checked both on incoming and outgoing packets.
4366127dd473Swhl739.Pp
4367127dd473Swhl739Should we want to simulate a bidirectional link with bandwidth
4368127dd473Swhl739limitations, the correct way is the following:
4369127dd473Swhl739.Pp
4370127dd473Swhl739.Dl "ipfw add pipe 1 ip from any to any out"
4371127dd473Swhl739.Dl "ipfw add pipe 2 ip from any to any in"
4372127dd473Swhl739.Dl "ipfw pipe 1 config bw 64Kbit/s queue 10Kbytes"
4373127dd473Swhl739.Dl "ipfw pipe 2 config bw 64Kbit/s queue 10Kbytes"
4374127dd473Swhl739.Pp
4375127dd473Swhl739The above can be very useful, e.g.\& if you want to see how
4376127dd473Swhl739your fancy Web page will look for a residential user who
4377127dd473Swhl739is connected only through a slow link.
4378127dd473Swhl739You should not use only one pipe for both directions, unless
4379127dd473Swhl739you want to simulate a half-duplex medium (e.g.\& AppleTalk,
4380127dd473Swhl739Ethernet, IRDA).
4381127dd473Swhl739It is not necessary that both pipes have the same configuration,
4382127dd473Swhl739so we can also simulate asymmetric links.
4383127dd473Swhl739.Pp
4384127dd473Swhl739Should we want to verify network performance with the RED queue
4385127dd473Swhl739management algorithm:
4386127dd473Swhl739.Pp
4387127dd473Swhl739.Dl "ipfw add pipe 1 ip from any to any"
4388127dd473Swhl739.Dl "ipfw pipe 1 config bw 500Kbit/s queue 100 red 0.002/30/80/0.1"
4389127dd473Swhl739.Pp
4390127dd473Swhl739Another typical application of the traffic shaper is to
4391127dd473Swhl739introduce some delay in the communication.
4392127dd473Swhl739This can significantly affect applications which do a lot of Remote
4393127dd473Swhl739Procedure Calls, and where the round-trip-time of the
4394127dd473Swhl739connection often becomes a limiting factor much more than
4395127dd473Swhl739bandwidth:
4396127dd473Swhl739.Pp
4397127dd473Swhl739.Dl "ipfw add pipe 1 ip from any to any out"
4398127dd473Swhl739.Dl "ipfw add pipe 2 ip from any to any in"
4399127dd473Swhl739.Dl "ipfw pipe 1 config delay 250ms bw 1Mbit/s"
4400127dd473Swhl739.Dl "ipfw pipe 2 config delay 250ms bw 1Mbit/s"
4401127dd473Swhl739.Pp
4402127dd473Swhl739Per-flow queueing can be useful for a variety of purposes.
4403127dd473Swhl739A very simple one is counting traffic:
4404127dd473Swhl739.Pp
4405127dd473Swhl739.Dl "ipfw add pipe 1 tcp from any to any"
4406127dd473Swhl739.Dl "ipfw add pipe 1 udp from any to any"
4407127dd473Swhl739.Dl "ipfw add pipe 1 ip from any to any"
4408127dd473Swhl739.Dl "ipfw pipe 1 config mask all"
4409127dd473Swhl739.Pp
4410127dd473Swhl739The above set of rules will create queues (and collect
4411127dd473Swhl739statistics) for all traffic.
4412127dd473Swhl739Because the pipes have no limitations, the only effect is
4413127dd473Swhl739collecting statistics.
4414127dd473Swhl739Note that we need 3 rules, not just the last one, because
4415127dd473Swhl739when
4416127dd473Swhl739.Nm
4417127dd473Swhl739tries to match IP packets it will not consider ports, so we
4418127dd473Swhl739would not see connections on separate ports as different
4419127dd473Swhl739ones.
4420127dd473Swhl739.Pp
4421127dd473Swhl739A more sophisticated example is limiting the outbound traffic
4422127dd473Swhl739on a net with per-host limits, rather than per-network limits:
4423127dd473Swhl739.Pp
4424127dd473Swhl739.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
4425127dd473Swhl739.Dl "ipfw add pipe 2 ip from any to 192.168.2.0/24 in"
4426127dd473Swhl739.Dl "ipfw pipe 1 config mask src-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
4427127dd473Swhl739.Dl "ipfw pipe 2 config mask dst-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
4428127dd473Swhl739.Ss LOOKUP TABLES
4429127dd473Swhl739In the following example, we need to create several traffic bandwidth
4430127dd473Swhl739classes and we need different hosts/networks to fall into different classes.
4431127dd473Swhl739We create one pipe for each class and configure them accordingly.
4432127dd473Swhl739Then we create a single table and fill it with IP subnets and addresses.
4433127dd473Swhl739For each subnet/host we set the argument equal to the number of the pipe
4434127dd473Swhl739that it should use.
4435127dd473Swhl739Then we classify traffic using a single rule:
4436127dd473Swhl739.Pp
4437127dd473Swhl739.Dl "ipfw pipe 1 config bw 1000Kbyte/s"
4438127dd473Swhl739.Dl "ipfw pipe 4 config bw 4000Kbyte/s"
4439127dd473Swhl739.Dl "..."
4440127dd473Swhl739.Dl "ipfw table T1 create type addr"
4441127dd473Swhl739.Dl "ipfw table T1 add 192.168.2.0/24 1"
4442127dd473Swhl739.Dl "ipfw table T1 add 192.168.0.0/27 4"
4443127dd473Swhl739.Dl "ipfw table T1 add 192.168.0.2 1"
4444127dd473Swhl739.Dl "..."
4445127dd473Swhl739.Dl "ipfw add pipe tablearg ip from 'table(T1)' to any"
4446127dd473Swhl739.Pp
4447127dd473Swhl739Using the
4448127dd473Swhl739.Cm fwd
4449127dd473Swhl739action, the table entries may include hostnames and IP addresses.
4450127dd473Swhl739.Pp
4451127dd473Swhl739.Dl "ipfw table T2 create type addr ftype ip"
4452127dd473Swhl739.Dl "ipfw table T2 add 192.168.2.0/24 10.23.2.1"
4453127dd473Swhl739.Dl "ipfw table T21 add 192.168.0.0/27 router1.dmz"
4454127dd473Swhl739.Dl "..."
4455127dd473Swhl739.Dl "ipfw add 100 fwd tablearg ip from any to table(1)"
4456127dd473Swhl739.Pp
4457127dd473Swhl739In the following example per-interface firewall is created:
4458127dd473Swhl739.Pp
4459127dd473Swhl739.Dl "ipfw table IN create type iface valtype skipto,fib"
4460127dd473Swhl739.Dl "ipfw table IN add vlan20 12000,12"
4461127dd473Swhl739.Dl "ipfw table IN add vlan30 13000,13"
4462127dd473Swhl739.Dl "ipfw table OUT create type iface valtype skipto"
4463127dd473Swhl739.Dl "ipfw table OUT add vlan20 22000"
4464127dd473Swhl739.Dl "ipfw table OUT add vlan30 23000"
4465127dd473Swhl739.Dl ".."
4466*22ce4affSfengbojiang.Dl "ipfw add 100 setfib tablearg ip from any to any recv 'table(IN)' in"
4467*22ce4affSfengbojiang.Dl "ipfw add 200 skipto tablearg ip from any to any recv 'table(IN)' in"
4468*22ce4affSfengbojiang.Dl "ipfw add 300 skipto tablearg ip from any to any xmit 'table(OUT)' out"
4469127dd473Swhl739.Pp
4470127dd473Swhl739The following example illustrate usage of flow tables:
4471127dd473Swhl739.Pp
4472*22ce4affSfengbojiang.Dl "ipfw table fl create type flow:src-ip,proto,dst-ip,dst-port"
4473127dd473Swhl739.Dl "ipfw table fl add 2a02:6b8:77::88,tcp,2a02:6b8:77::99,80 11"
4474127dd473Swhl739.Dl "ipfw table fl add 10.0.0.1,udp,10.0.0.2,53 12"
4475127dd473Swhl739.Dl ".."
4476127dd473Swhl739.Dl "ipfw add 100 allow ip from any to any flow 'table(fl,11)' recv ix0"
4477127dd473Swhl739.Ss SETS OF RULES
4478127dd473Swhl739To add a set of rules atomically, e.g.\& set 18:
4479127dd473Swhl739.Pp
4480127dd473Swhl739.Dl "ipfw set disable 18"
4481127dd473Swhl739.Dl "ipfw add NN set 18 ...         # repeat as needed"
4482127dd473Swhl739.Dl "ipfw set enable 18"
4483127dd473Swhl739.Pp
4484127dd473Swhl739To delete a set of rules atomically the command is simply:
4485127dd473Swhl739.Pp
4486127dd473Swhl739.Dl "ipfw delete set 18"
4487127dd473Swhl739.Pp
4488127dd473Swhl739To test a ruleset and disable it and regain control if something goes wrong:
4489127dd473Swhl739.Pp
4490127dd473Swhl739.Dl "ipfw set disable 18"
4491127dd473Swhl739.Dl "ipfw add NN set 18 ...         # repeat as needed"
4492127dd473Swhl739.Dl "ipfw set enable 18; echo done; sleep 30 && ipfw set disable 18"
4493127dd473Swhl739.Pp
4494127dd473Swhl739Here if everything goes well, you press control-C before the "sleep"
4495127dd473Swhl739terminates, and your ruleset will be left active.
4496127dd473Swhl739Otherwise, e.g.\& if
4497127dd473Swhl739you cannot access your box, the ruleset will be disabled after
4498127dd473Swhl739the sleep terminates thus restoring the previous situation.
4499127dd473Swhl739.Pp
4500127dd473Swhl739To show rules of the specific set:
4501127dd473Swhl739.Pp
4502127dd473Swhl739.Dl "ipfw set 18 show"
4503127dd473Swhl739.Pp
4504127dd473Swhl739To show rules of the disabled set:
4505127dd473Swhl739.Pp
4506127dd473Swhl739.Dl "ipfw -S set 18 show"
4507127dd473Swhl739.Pp
4508127dd473Swhl739To clear a specific rule counters of the specific set:
4509127dd473Swhl739.Pp
4510127dd473Swhl739.Dl "ipfw set 18 zero NN"
4511127dd473Swhl739.Pp
4512127dd473Swhl739To delete a specific rule of the specific set:
4513127dd473Swhl739.Pp
4514127dd473Swhl739.Dl "ipfw set 18 delete NN"
4515127dd473Swhl739.Ss NAT, REDIRECT AND LSNAT
4516127dd473Swhl739First redirect all the traffic to nat instance 123:
4517127dd473Swhl739.Pp
4518127dd473Swhl739.Dl "ipfw add nat 123 all from any to any"
4519127dd473Swhl739.Pp
4520127dd473Swhl739Then to configure nat instance 123 to alias all the outgoing traffic with ip
4521127dd473Swhl739192.168.0.123, blocking all incoming connections, trying to keep
4522127dd473Swhl739same ports on both sides, clearing aliasing table on address change
4523127dd473Swhl739and keeping a log of traffic/link statistics:
4524127dd473Swhl739.Pp
4525127dd473Swhl739.Dl "ipfw nat 123 config ip 192.168.0.123 log deny_in reset same_ports"
4526127dd473Swhl739.Pp
4527127dd473Swhl739Or to change address of instance 123, aliasing table will be cleared (see
4528127dd473Swhl739reset option):
4529127dd473Swhl739.Pp
4530127dd473Swhl739.Dl "ipfw nat 123 config ip 10.0.0.1"
4531127dd473Swhl739.Pp
4532127dd473Swhl739To see configuration of nat instance 123:
4533127dd473Swhl739.Pp
4534127dd473Swhl739.Dl "ipfw nat 123 show config"
4535127dd473Swhl739.Pp
4536127dd473Swhl739To show logs of all the instances in range 111-999:
4537127dd473Swhl739.Pp
4538127dd473Swhl739.Dl "ipfw nat 111-999 show"
4539127dd473Swhl739.Pp
4540127dd473Swhl739To see configurations of all instances:
4541127dd473Swhl739.Pp
4542127dd473Swhl739.Dl "ipfw nat show config"
4543127dd473Swhl739.Pp
4544127dd473Swhl739Or a redirect rule with mixed modes could looks like:
4545*22ce4affSfengbojiang.Bd -literal -offset 2n
4546*22ce4affSfengbojiangipfw nat 123 config redirect_addr 10.0.0.1 10.0.0.66
4547*22ce4affSfengbojiang			 redirect_port tcp 192.168.0.1:80 500
4548*22ce4affSfengbojiang			 redirect_proto udp 192.168.1.43 192.168.1.1
4549*22ce4affSfengbojiang			 redirect_addr 192.168.0.10,192.168.0.11
4550*22ce4affSfengbojiang			 	    10.0.0.100	# LSNAT
4551*22ce4affSfengbojiang			 redirect_port tcp 192.168.0.1:80,192.168.0.10:22
4552*22ce4affSfengbojiang			 	    500		# LSNAT
4553*22ce4affSfengbojiang.Ed
4554127dd473Swhl739.Pp
4555127dd473Swhl739or it could be split in:
4556*22ce4affSfengbojiang.Bd -literal -offset 2n
4557*22ce4affSfengbojiangipfw nat 1 config redirect_addr 10.0.0.1 10.0.0.66
4558*22ce4affSfengbojiangipfw nat 2 config redirect_port tcp 192.168.0.1:80 500
4559*22ce4affSfengbojiangipfw nat 3 config redirect_proto udp 192.168.1.43 192.168.1.1
4560*22ce4affSfengbojiangipfw nat 4 config redirect_addr 192.168.0.10,192.168.0.11,192.168.0.12
4561*22ce4affSfengbojiang				         10.0.0.100
4562*22ce4affSfengbojiangipfw nat 5 config redirect_port tcp
4563*22ce4affSfengbojiang			192.168.0.1:80,192.168.0.10:22,192.168.0.20:25 500
4564*22ce4affSfengbojiang.Ed
4565127dd473Swhl739.Pp
4566*22ce4affSfengbojiangSometimes you may want to mix NAT and dynamic rules.
4567*22ce4affSfengbojiangIt could be achieved with
4568*22ce4affSfengbojiang.Cm record-state
4569*22ce4affSfengbojiangand
4570*22ce4affSfengbojiang.Cm defer-action
4571*22ce4affSfengbojiangoptions.
4572*22ce4affSfengbojiangProblem is, you need to create dynamic rule before NAT and check it
4573*22ce4affSfengbojiangafter NAT actions (or vice versa) to have consistent addresses and ports.
4574*22ce4affSfengbojiangRule with
4575*22ce4affSfengbojiang.Cm keep-state
4576*22ce4affSfengbojiangoption will trigger activation of existing dynamic state, and action of such
4577*22ce4affSfengbojiangrule will be performed as soon as rule is matched.
4578*22ce4affSfengbojiangIn case of NAT and
4579*22ce4affSfengbojiang.Cm allow
4580*22ce4affSfengbojiangrule packet need to be passed to NAT, not allowed as soon is possible.
4581*22ce4affSfengbojiang.Pp
4582*22ce4affSfengbojiangThere is example of set of rules to achieve this.
4583*22ce4affSfengbojiangBear in mind that this is example only and it is not very useful by itself.
4584*22ce4affSfengbojiang.Pp
4585*22ce4affSfengbojiangOn way out, after all checks place this rules:
4586*22ce4affSfengbojiang.Pp
4587*22ce4affSfengbojiang.Dl "ipfw add allow record-state skip-action"
4588*22ce4affSfengbojiang.Dl "ipfw add nat 1"
4589*22ce4affSfengbojiang.Pp
4590*22ce4affSfengbojiangAnd on way in there should be something like this:
4591*22ce4affSfengbojiang.Pp
4592*22ce4affSfengbojiang.Dl "ipfw add nat 1"
4593*22ce4affSfengbojiang.Dl "ipfw add check-state"
4594*22ce4affSfengbojiang.Pp
4595*22ce4affSfengbojiangPlease note, that first rule on way out doesn't allow packet and doesn't
4596*22ce4affSfengbojiangexecute existing dynamic rules.
4597*22ce4affSfengbojiangAll it does, create new dynamic rule with
4598*22ce4affSfengbojiang.Cm allow
4599*22ce4affSfengbojiangaction, if it is not created yet.
4600*22ce4affSfengbojiangLater, this dynamic rule is used on way in by
4601*22ce4affSfengbojiang.Cm check-state
4602*22ce4affSfengbojiangrule.
4603*22ce4affSfengbojiang.Ss CONFIGURING CODEL, PIE, FQ-CODEL and FQ-PIE AQM
4604*22ce4affSfengbojiang.Cm codel
4605*22ce4affSfengbojiangand
4606*22ce4affSfengbojiang.Cm pie
4607*22ce4affSfengbojiangAQM can be configured for
4608*22ce4affSfengbojiang.Nm dummynet
4609*22ce4affSfengbojiang.Cm pipe
4610*22ce4affSfengbojiangor
4611*22ce4affSfengbojiang.Cm queue .
4612*22ce4affSfengbojiang.Pp
4613*22ce4affSfengbojiangTo configure a
4614*22ce4affSfengbojiang.Cm pipe
4615*22ce4affSfengbojiangwith
4616*22ce4affSfengbojiang.Cm codel
4617*22ce4affSfengbojiangAQM using default configuration for traffic from 192.168.0.0/24 and 1Mbits/s
4618*22ce4affSfengbojiangrate limit, we do:
4619*22ce4affSfengbojiang.Pp
4620*22ce4affSfengbojiang.Dl "ipfw pipe 1 config bw 1mbits/s codel"
4621*22ce4affSfengbojiang.Dl "ipfw add 100 pipe 1 ip from 192.168.0.0/24 to any"
4622*22ce4affSfengbojiang.Pp
4623*22ce4affSfengbojiangTo configure a
4624*22ce4affSfengbojiang.Cm queue
4625*22ce4affSfengbojiangwith
4626*22ce4affSfengbojiang.Cm codel
4627*22ce4affSfengbojiangAQM using different configurations parameters for traffic from
4628*22ce4affSfengbojiang192.168.0.0/24 and 1Mbits/s rate limit, we do:
4629*22ce4affSfengbojiang.Pp
4630*22ce4affSfengbojiang.Dl "ipfw pipe 1 config bw 1mbits/s"
4631*22ce4affSfengbojiang.Dl "ipfw queue 1 config pipe 1 codel target 8ms interval 160ms ecn"
4632*22ce4affSfengbojiang.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any"
4633*22ce4affSfengbojiang.Pp
4634*22ce4affSfengbojiangTo configure a
4635*22ce4affSfengbojiang.Cm pipe
4636*22ce4affSfengbojiangwith
4637*22ce4affSfengbojiang.Cm pie
4638*22ce4affSfengbojiangAQM using default configuration for traffic from 192.168.0.0/24 and 1Mbits/s
4639*22ce4affSfengbojiangrate limit, we do:
4640*22ce4affSfengbojiang.Pp
4641*22ce4affSfengbojiang.Dl "ipfw pipe 1 config bw 1mbits/s pie"
4642*22ce4affSfengbojiang.Dl "ipfw add 100 pipe 1 ip from 192.168.0.0/24 to any"
4643*22ce4affSfengbojiang.Pp
4644*22ce4affSfengbojiangTo configure a
4645*22ce4affSfengbojiang.Cm queue
4646*22ce4affSfengbojiangwith
4647*22ce4affSfengbojiang.Cm pie
4648*22ce4affSfengbojiangAQM using different configuration parameters for traffic from
4649*22ce4affSfengbojiang192.168.0.0/24 and 1Mbits/s rate limit, we do:
4650*22ce4affSfengbojiang.Pp
4651*22ce4affSfengbojiang.Dl "ipfw pipe 1 config bw 1mbits/s"
4652*22ce4affSfengbojiang.Dl "ipfw queue 1 config pipe 1 pie target 20ms tupdate 30ms ecn"
4653*22ce4affSfengbojiang.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any"
4654*22ce4affSfengbojiang.Pp
4655*22ce4affSfengbojiang.Cm fq_codel
4656*22ce4affSfengbojiangand
4657*22ce4affSfengbojiang.Cm fq_pie
4658*22ce4affSfengbojiangAQM can be configured for
4659*22ce4affSfengbojiang.Nm dummynet
4660*22ce4affSfengbojiangschedulers.
4661*22ce4affSfengbojiang.Pp
4662*22ce4affSfengbojiangTo configure
4663*22ce4affSfengbojiang.Cm fq_codel
4664*22ce4affSfengbojiangscheduler using different configurations parameters for traffic from
4665*22ce4affSfengbojiang192.168.0.0/24 and 1Mbits/s rate limit, we do:
4666*22ce4affSfengbojiang.Pp
4667*22ce4affSfengbojiang.Dl "ipfw pipe 1 config bw 1mbits/s"
4668*22ce4affSfengbojiang.Dl "ipfw sched 1 config pipe 1 type fq_codel"
4669*22ce4affSfengbojiang.Dl "ipfw queue 1 config sched 1"
4670*22ce4affSfengbojiang.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any"
4671*22ce4affSfengbojiang.Pp
4672*22ce4affSfengbojiangTo change
4673*22ce4affSfengbojiang.Cm fq_codel
4674*22ce4affSfengbojiangdefault configuration for a
4675*22ce4affSfengbojiang.Cm sched
4676*22ce4affSfengbojiangsuch as disable ECN and change the
4677*22ce4affSfengbojiang.Ar target
4678*22ce4affSfengbojiangto 10ms, we do:
4679*22ce4affSfengbojiang.Pp
4680*22ce4affSfengbojiang.Dl "ipfw sched 1 config pipe 1 type fq_codel target 10ms noecn"
4681*22ce4affSfengbojiang.Pp
4682*22ce4affSfengbojiangSimilar to
4683*22ce4affSfengbojiang.Cm fq_codel ,
4684*22ce4affSfengbojiangto configure
4685*22ce4affSfengbojiang.Cm fq_pie
4686*22ce4affSfengbojiangscheduler using different configurations parameters for traffic from
4687*22ce4affSfengbojiang192.168.0.0/24 and 1Mbits/s rate limit, we do:
4688*22ce4affSfengbojiang.Pp
4689*22ce4affSfengbojiang.Dl "ipfw pipe 1 config bw 1mbits/s"
4690*22ce4affSfengbojiang.Dl "ipfw sched 1 config pipe 1 type fq_pie"
4691*22ce4affSfengbojiang.Dl "ipfw queue 1 config sched 1"
4692*22ce4affSfengbojiang.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any"
4693*22ce4affSfengbojiang.Pp
4694*22ce4affSfengbojiangThe configurations of
4695*22ce4affSfengbojiang.Cm fq_pie
4696*22ce4affSfengbojiang.Cm sched
4697*22ce4affSfengbojiangcan be changed in a similar way as for
4698*22ce4affSfengbojiang.Cm fq_codel
4699127dd473Swhl739.Sh SEE ALSO
4700127dd473Swhl739.Xr cpp 1 ,
4701127dd473Swhl739.Xr m4 1 ,
4702127dd473Swhl739.Xr altq 4 ,
4703127dd473Swhl739.Xr divert 4 ,
4704127dd473Swhl739.Xr dummynet 4 ,
4705127dd473Swhl739.Xr if_bridge 4 ,
4706127dd473Swhl739.Xr ip 4 ,
4707127dd473Swhl739.Xr ipfirewall 4 ,
4708*22ce4affSfengbojiang.Xr ng_ether 4 ,
4709127dd473Swhl739.Xr ng_ipfw 4 ,
4710127dd473Swhl739.Xr protocols 5 ,
4711127dd473Swhl739.Xr services 5 ,
4712127dd473Swhl739.Xr init 8 ,
4713127dd473Swhl739.Xr kldload 8 ,
4714127dd473Swhl739.Xr reboot 8 ,
4715127dd473Swhl739.Xr sysctl 8 ,
4716*22ce4affSfengbojiang.Xr syslogd 8 ,
4717*22ce4affSfengbojiang.Xr sysrc 8
4718127dd473Swhl739.Sh HISTORY
4719127dd473Swhl739The
4720127dd473Swhl739.Nm
4721127dd473Swhl739utility first appeared in
4722127dd473Swhl739.Fx 2.0 .
4723127dd473Swhl739.Nm dummynet
4724127dd473Swhl739was introduced in
4725127dd473Swhl739.Fx 2.2.8 .
4726127dd473Swhl739Stateful extensions were introduced in
4727127dd473Swhl739.Fx 4.0 .
4728127dd473Swhl739.Nm ipfw2
4729127dd473Swhl739was introduced in Summer 2002.
4730127dd473Swhl739.Sh AUTHORS
4731127dd473Swhl739.An Ugen J. S. Antsilevich ,
4732127dd473Swhl739.An Poul-Henning Kamp ,
4733127dd473Swhl739.An Alex Nash ,
4734127dd473Swhl739.An Archie Cobbs ,
4735*22ce4affSfengbojiang.An Luigi Rizzo ,
4736*22ce4affSfengbojiang.An Rasool Al-Saadi .
4737127dd473Swhl739.Pp
4738127dd473Swhl739.An -nosplit
4739127dd473Swhl739API based upon code written by
4740127dd473Swhl739.An Daniel Boulet
4741127dd473Swhl739for BSDI.
4742127dd473Swhl739.Pp
4743127dd473Swhl739Dummynet has been introduced by Luigi Rizzo in 1997-1998.
4744127dd473Swhl739.Pp
4745127dd473Swhl739Some early work (1999-2000) on the
4746127dd473Swhl739.Nm dummynet
4747127dd473Swhl739traffic shaper supported by Akamba Corp.
4748127dd473Swhl739.Pp
4749127dd473Swhl739The ipfw core (ipfw2) has been completely redesigned and
4750127dd473Swhl739reimplemented by Luigi Rizzo in summer 2002.
4751127dd473Swhl739Further
4752127dd473Swhl739actions and
4753*22ce4affSfengbojiangoptions have been added by various developers over the years.
4754127dd473Swhl739.Pp
4755127dd473Swhl739.An -nosplit
4756127dd473Swhl739In-kernel NAT support written by
4757127dd473Swhl739.An Paolo Pisati Aq Mt [email protected]
4758127dd473Swhl739as part of a Summer of Code 2005 project.
4759127dd473Swhl739.Pp
4760127dd473Swhl739SCTP
4761127dd473Swhl739.Nm nat
4762127dd473Swhl739support has been developed by
4763127dd473Swhl739.An The Centre for Advanced Internet Architectures (CAIA) Aq http://www.caia.swin.edu.au .
4764127dd473Swhl739The primary developers and maintainers are David Hayes and Jason But.
4765127dd473Swhl739For further information visit:
4766127dd473Swhl739.Aq http://www.caia.swin.edu.au/urp/SONATA
4767127dd473Swhl739.Pp
4768127dd473Swhl739Delay profiles have been developed by Alessandro Cerri and
4769127dd473Swhl739Luigi Rizzo, supported by the
4770127dd473Swhl739European Commission within Projects Onelab and Onelab2.
4771*22ce4affSfengbojiang.Pp
4772*22ce4affSfengbojiangCoDel, PIE, FQ-CoDel and FQ-PIE AQM for Dummynet have been implemented by
4773*22ce4affSfengbojiang.An The Centre for Advanced Internet Architectures (CAIA)
4774*22ce4affSfengbojiangin 2016, supported by The Comcast Innovation Fund.
4775*22ce4affSfengbojiangThe primary developer is
4776*22ce4affSfengbojiangRasool Al-Saadi.
4777127dd473Swhl739.Sh BUGS
4778127dd473Swhl739The syntax has grown over the years and sometimes it might be confusing.
4779127dd473Swhl739Unfortunately, backward compatibility prevents cleaning up mistakes
4780127dd473Swhl739made in the definition of the syntax.
4781127dd473Swhl739.Pp
4782127dd473Swhl739.Em !!! WARNING !!!
4783127dd473Swhl739.Pp
4784127dd473Swhl739Misconfiguring the firewall can put your computer in an unusable state,
4785127dd473Swhl739possibly shutting down network services and requiring console access to
4786127dd473Swhl739regain control of it.
4787127dd473Swhl739.Pp
4788127dd473Swhl739Incoming packet fragments diverted by
4789127dd473Swhl739.Cm divert
4790127dd473Swhl739are reassembled before delivery to the socket.
4791127dd473Swhl739The action used on those packet is the one from the
4792127dd473Swhl739rule which matches the first fragment of the packet.
4793127dd473Swhl739.Pp
4794127dd473Swhl739Packets diverted to userland, and then reinserted by a userland process
4795127dd473Swhl739may lose various packet attributes.
4796127dd473Swhl739The packet source interface name
4797127dd473Swhl739will be preserved if it is shorter than 8 bytes and the userland process
4798127dd473Swhl739saves and reuses the sockaddr_in
4799127dd473Swhl739(as does
4800127dd473Swhl739.Xr natd 8 ) ;
4801127dd473Swhl739otherwise, it may be lost.
4802127dd473Swhl739If a packet is reinserted in this manner, later rules may be incorrectly
4803127dd473Swhl739applied, making the order of
4804127dd473Swhl739.Cm divert
4805127dd473Swhl739rules in the rule sequence very important.
4806127dd473Swhl739.Pp
4807127dd473Swhl739Dummynet drops all packets with IPv6 link-local addresses.
4808127dd473Swhl739.Pp
4809127dd473Swhl739Rules using
4810127dd473Swhl739.Cm uid
4811127dd473Swhl739or
4812127dd473Swhl739.Cm gid
4813127dd473Swhl739may not behave as expected.
4814127dd473Swhl739In particular, incoming SYN packets may
4815127dd473Swhl739have no uid or gid associated with them since they do not yet belong
4816127dd473Swhl739to a TCP connection, and the uid/gid associated with a packet may not
4817127dd473Swhl739be as expected if the associated process calls
4818127dd473Swhl739.Xr setuid 2
4819127dd473Swhl739or similar system calls.
4820127dd473Swhl739.Pp
4821127dd473Swhl739Rule syntax is subject to the command line environment and some patterns
4822127dd473Swhl739may need to be escaped with the backslash character
4823127dd473Swhl739or quoted appropriately.
4824127dd473Swhl739.Pp
4825127dd473Swhl739Due to the architecture of
4826127dd473Swhl739.Xr libalias 3 ,
4827127dd473Swhl739ipfw nat is not compatible with the TCP segmentation offloading (TSO).
4828127dd473Swhl739Thus, to reliably nat your network traffic, please disable TSO
4829127dd473Swhl739on your NICs using
4830127dd473Swhl739.Xr ifconfig 8 .
4831127dd473Swhl739.Pp
4832127dd473Swhl739ICMP error messages are not implicitly matched by dynamic rules
4833127dd473Swhl739for the respective conversations.
4834127dd473Swhl739To avoid failures of network error detection and path MTU discovery,
4835127dd473Swhl739ICMP error messages may need to be allowed explicitly through static
4836127dd473Swhl739rules.
4837127dd473Swhl739.Pp
4838127dd473Swhl739Rules using
4839127dd473Swhl739.Cm call
4840127dd473Swhl739and
4841127dd473Swhl739.Cm return
4842127dd473Swhl739actions may lead to confusing behaviour if ruleset has mistakes,
4843127dd473Swhl739and/or interaction with other subsystems (netgraph, dummynet, etc.) is used.
4844127dd473Swhl739One possible case for this is packet leaving
4845127dd473Swhl739.Nm
4846127dd473Swhl739in subroutine on the input pass, while later on output encountering unpaired
4847127dd473Swhl739.Cm return
4848127dd473Swhl739first.
4849127dd473Swhl739As the call stack is kept intact after input pass, packet will suddenly
4850127dd473Swhl739return to the rule number used on input pass, not on output one.
4851127dd473Swhl739Order of processing should be checked carefully to avoid such mistakes.
4852