]> git.saurik.com Git - apple/network_cmds.git/blame - dnctl/dnctl.8
network_cmds-511.50.3.tar.gz
[apple/network_cmds.git] / dnctl / dnctl.8
CommitLineData
7af5ce03
A
1.Dd August 13, 2002
2.Dt DNCTL 8
3.Os Darwin
4.Sh NAME
5.Nm dnctl
6.Nd Traffic shaper control program
7.Sh SYNOPSIS
8.Nm
9.Op Fl anqs
10.Brq Cm list | show
11.Nm
12.Op Fl f | q
13.Cm flush
14.Nm
15.Op Fl q
16.Brq Cm delete
17.Op Ar number ...
18.Nm
19.Brq Cm pipe | queue
20.Ar number
21.Cm config
22.Ar config-options
23.Nm
24.Op Fl s Op Ar field
25.Brq Cm pipe | queue
26.Brq Cm delete | list | show
27.Op Ar number ...
28.Nm
29.Op Fl nq
30.Oo
31.Fl p Ar preproc
32.Oo
33.Ar preproc-flags
34.Oc
35.Oc
36.Ar pathname
37.Sh DESCRIPTION
38.Pp
39The
40.Nm
41utility is the user interface for controlling the
42.Xr dummynet 4
43traffic shaper.
44.Pp
45.Nm dummynet
46operates by first using a packet filter to classify packets and divide them into
47.Em flows ,
48using any match pattern that can be used in
49.Nm
50rules.
51Depending on local policies, a flow can contain packets for a single
52TCP connection, or from/to a given host, or entire subnet, or a
53protocol type, etc.
54.Pp
55Packets belonging to the same flow are then passed to either of two
56different objects, which implement the traffic regulation:
57.Bl -hang -offset XXXX
58.It Em pipe
59A pipe emulates a link with given bandwidth, propagation delay,
60queue size and packet loss rate.
61Packets are queued in front of the pipe as they come out from the classifier,
62and then transferred to the pipe according to the pipe's parameters.
63.Pp
64.It Em queue
65A queue
66is an abstraction used to implement the WF2Q+
67(Worst-case Fair Weighted Fair Queueing) policy, which is
68an efficient variant of the WFQ policy.
69.br
70The queue associates a
71.Em weight
72and a reference pipe to each flow, and then all backlogged (i.e.,
73with packets queued) flows linked to the same pipe share the pipe's
74bandwidth proportionally to their weights.
75Note that weights are not priorities; a flow with a lower weight
76is still guaranteed to get its fraction of the bandwidth even if a
77flow with a higher weight is permanently backlogged.
78.Pp
79.El
80In practice,
81.Em pipes
82can be used to set hard limits to the bandwidth that a flow can use, whereas
83.Em queues
84can be used to determine how different flow share the available bandwidth.
85.Pp
86The
87.Em pipe
88and
89.Em queue
90configuration commands are the following:
91.Bd -ragged -offset indent
92.Cm pipe Ar number Cm config Ar pipe-configuration
93.Pp
94.Cm queue Ar number Cm config Ar queue-configuration
95.Ed
96.Pp
97The following parameters can be configured for a pipe:
98.Pp
99.Bl -tag -width indent -compact
100.It Cm bw Ar bandwidth | device
101Bandwidth, measured in
102.Sm off
103.Op Cm K | M
104.Brq Cm bit/s | Byte/s .
105.Sm on
106.Pp
107A value of 0 (default) means unlimited bandwidth.
108The unit must immediately follow the number, as in
109.Pp
110.Dl "dnctl pipe 1 config bw 300Kbit/s"
111.Pp
112If a device name is specified instead of a numeric value, as in
113.Pp
114.Dl "dnctl pipe 1 config bw tun0"
115.Pp
116then the transmit clock is supplied by the specified device.
117At the moment no
118device supports this
119functionality.
120.Pp
121.It Cm delay Ar ms-delay
122Propagation delay, measured in milliseconds.
123The value is rounded to the next multiple of the clock tick
124(typically 10ms, but it is a good practice to run kernels
125with
126.Dq "options HZ=1000"
127to reduce
128the granularity to 1ms or less).
129Default value is 0, meaning no delay.
130.El
131.Pp
132The following parameters can be configured for a queue:
133.Pp
134.Bl -tag -width indent -compact
135.It Cm pipe Ar pipe_nr
136Connects a queue to the specified pipe.
137Multiple queues (with the same or different weights) can be connected to
138the same pipe, which specifies the aggregate rate for the set of queues.
139.Pp
140.It Cm weight Ar weight
141Specifies the weight to be used for flows matching this queue.
142The weight must be in the range 1..100, and defaults to 1.
143.El
144.Pp
145Finally, the following parameters can be configured for both
146pipes and queues:
147.Pp
148.Bl -tag -width XXXX -compact
149.It Cm buckets Ar hash-table-size
150Specifies the size of the hash table used for storing the
151various queues.
152Default value is 64 controlled by the
153.Xr sysctl 8
154variable
155.Em net.inet.ip.dummynet.hash_size ,
156allowed range is 16 to 65536.
157.Pp
158.It Cm mask Ar mask-specifier
159Packets sent to a given pipe or queue by an
160.Nm
161rule can be further classified into multiple flows, each of which is then
162sent to a different
163.Em dynamic
164pipe or queue.
165A flow identifier is constructed by masking the IP addresses,
166ports and protocol types as specified with the
167.Cm mask
168options in the configuration of the pipe or queue.
169For each different flow identifier, a new pipe or queue is created
170with the same parameters as the original object, and matching packets
171are sent to it.
172.Pp
173Thus, when
174.Em dynamic pipes
175are used, each flow will get the same bandwidth as defined by the pipe,
176whereas when
177.Em dynamic queues
178are used, each flow will share the parent's pipe bandwidth evenly
179with other flows generated by the same queue (note that other queues
180with different weights might be connected to the same pipe).
181.br
182Available mask specifiers are a combination of one or more of the following:
183.Pp
184.Cm dst-ip Ar mask ,
185.Cm dst-ip6 Ar mask ,
186.Cm src-ip Ar mask ,
187.Cm src-ip6 Ar mask ,
188.Cm dst-port Ar mask ,
189.Cm src-port Ar mask ,
190.Cm proto Ar mask
191or
192.Cm all ,
193.Pp
194where the latter means all bits in all fields are significant.
195.Pp
196.It Cm noerror
197When a packet is dropped by a dummynet queue or pipe, the error
198is normally reported to the caller routine in the kernel, in the
199same way as it happens when a device queue fills up. Setting this
200option reports the packet as successfully delivered, which can be
201needed for some experimental setups where you want to simulate
202loss or congestion at a remote router.
203.Pp
204.It Cm plr Ar packet-loss-rate
205Packet loss rate.
206Argument
207.Ar packet-loss-rate
208is a floating-point number between 0 and 1, with 0 meaning no
209loss, 1 meaning 100% loss.
210The loss rate is internally represented on 31 bits.
211.Pp
212.It Cm queue Brq Ar slots | size Ns Cm Kbytes
213Queue size, in
214.Ar slots
215or
216.Cm KBytes .
217Default value is 50 slots, which
218is the typical queue size for Ethernet devices.
219Note that for slow speed links you should keep the queue
220size short or your traffic might be affected by a significant
221queueing delay.
222E.g., 50 max-sized ethernet packets (1500 bytes) mean 600Kbit
223or 20s of queue on a 30Kbit/s pipe.
224Even worse effect can result if you get packets from an
225interface with a much larger MTU, e.g. the loopback interface
226with its 16KB packets.
227.Pp
228.It Cm red | gred Ar w_q Ns / Ns Ar min_th Ns / Ns Ar max_th Ns / Ns Ar max_p
229Make use of the RED (Random Early Detection) queue management algorithm.
230.Ar w_q
231and
232.Ar max_p
233are floating
234point numbers between 0 and 1 (0 not included), while
235.Ar min_th
236and
237.Ar max_th
238are integer numbers specifying thresholds for queue management
239(thresholds are computed in bytes if the queue has been defined
240in bytes, in slots otherwise).
241The
242.Xr dummynet 4
243also supports the gentle RED variant (gred).
244.Pp
245Three
246.Xr sysctl 8
247variables can be used to control the RED behaviour:
248.Bl -tag -width indent
249.It Em net.inet.ip.dummynet.red_lookup_depth
250specifies the accuracy in computing the average queue
251when the link is idle (defaults to 256, must be greater than zero)
252.It Em net.inet.ip.dummynet.red_avg_pkt_size
253specifies the expected average packet size (defaults to 512, must be
254greater than zero)
255.It Em net.inet.ip.dummynet.red_max_pkt_size
256specifies the expected maximum packet size, only used when queue
257thresholds are in bytes (defaults to 1500, must be greater than zero).
258.El
259.El
260.Pp
261The following options are available:
262.Bl -tag -width indent
263.It Fl a
264While listing, show counter values.
265The
266.Cm show
267command just implies this option.
268.It Fl f
269Don't ask for confirmation for commands that can cause problems
270if misused,
271.No i.e. Cm flush .
272If there is no tty associated with the process, this is implied.
273.It Fl h
274Displays a short help.
275.It Fl n
276Only check syntax of the command strings, without actually passing
277them to the kernel.
278.It Fl q
279While
280.Cm add Ns ing ,
281.Cm zero Ns ing ,
282.Cm resetlog Ns ging
283or
284.Cm flush Ns ing ,
285be quiet about actions
286(implies
287.Fl f ) .
288This is useful for adjusting rules by executing multiple
289.Nm
290commands in a script
291or by processing a file of many
292.Nm
293rules across a remote login session.
294If a
295.Cm flush
296is performed in normal (verbose) mode (with the default kernel
297configuration), it prints a message.
298Because all rules are flushed, the message might not be delivered
299to the login session, causing the remote login session to be closed
300and the remainder of the ruleset to not be processed.
301Access to the console would then be required to recover.
302.It Fl s Op Ar field
303While listing pipes, sort according to one of the four
304counters (total or current packets or bytes).
305.It Fl v
306Be verbose.
307.El
308.Pp
309To ease configuration, rules can be put into a file which is
310processed using
311.Nm
312as shown in the last synopsis line.
313An absolute
314.Ar pathname
315must be used.
316The file will be read line by line and applied as arguments to the
317.Nm
318utility.
319.Pp
320Optionally, a preprocessor can be specified using
321.Fl p Ar preproc
322where
323.Ar pathname
324is to be piped through.
325Useful preprocessors include
326.Xr cpp 1
327and
328.Xr m4 1 .
329If
330.Ar preproc
331doesn't start with a slash
332.Pq Ql /
333as its first character, the usual
334.Ev PATH
335name search is performed.
336Care should be taken with this in environments where not all
337file systems are mounted (yet) by the time
338.Nm
339is being run (e.g. when they are mounted over NFS).
340Once
341.Fl p
342has been specified, any additional arguments as passed on to the preprocessor
343for interpretation.
344This allows for flexible configuration files (like conditionalizing
345them on the local hostname) and the use of macros to centralize
346frequently required arguments like IP addresses.
347.El
348.Sh CHECKLIST
349Here are some important points to consider when designing your
350rules:
351.Bl -bullet
352.It
353Remember that you filter both packets going
354.Cm in
355and
356.Cm out .
357Most connections need packets going in both directions.
358.It
359Remember to test very carefully.
360It is a good idea to be near the console when doing this.
7af5ce03
A
361.It
362Don't forget the loopback interface.
363.El
364.Sh SYSCTL VARIABLES
365A set of
366.Xr sysctl 8
367variables controls the behaviour of the
368.Nm dummynet
369module.
370These are shown below together with their default value
371(but always check with the
372.Xr sysctl 8
373command what value is actually in use) and meaning:
374.Bl -tag -width indent
375.It Em net.inet.ip.dummynet.expire : No 1
376Lazily delete dynamic pipes/queue once they have no pending traffic.
377You can disable this by setting the variable to 0, in which case
378the pipes/queues will only be deleted when the threshold is reached.
379.It Em net.inet.ip.dummynet.hash_size : No 64
380Default size of the hash table used for dynamic pipes/queues.
381This value is used when no
382.Cm buckets
383option is specified when configuring a pipe/queue.
384.It Em net.inet.ip.dummynet.max_chain_len : No 16
385Target value for the maximum number of pipes/queues in a hash bucket.
386The product
387.Cm max_chain_len*hash_size
388is used to determine the threshold over which empty pipes/queues
389will be expired even when
390.Cm net.inet.ip.dummynet.expire=0 .
391.It Em net.inet.ip.dummynet.red_lookup_depth : No 256
392.It Em net.inet.ip.dummynet.red_avg_pkt_size : No 512
393.It Em net.inet.ip.dummynet.red_max_pkt_size : No 1500
394Parameters used in the computations of the drop probability
395for the RED algorithm.
396.El
397.Sh EXAMPLES
398The following rules show some of the applications of
342c141e
A
399for simulations and the like by using
400.Em dummynet
401rules in
402.Xr pf.conf 8
403configuration files.
404.Pp
405To drop random incoming IPv4 and IPv6 ICMP packets with a probability of 5%,
406create a pipe:
7af5ce03
A
407.Dl "dnctl pipe 10 config plr 0.05"
408.Pp
342c141e
A
409and add these rules in your pf.conf file:
410.Dl "dummynet in inet proto icmp all pipe 10"
411.Dl "dummynet in inet6 proto ipv6-icmp all pipe 10"
7af5ce03
A
412.Pp
413Should we want to simulate a bidirectional link with bandwidth
342c141e
A
414limitations, the correct way is to create a pipe for each direction:
415.Dl "dnctl pipe 1 config bw 14Kbit/s queue 10Kbytes"
416.Dl "dnctl pipe 2 config bw 1Kbit/s queue 10Kbytes"
7af5ce03 417.Pp
342c141e
A
418and add these rules in your pf.conf file:
419.Dl "dummynet in all pipe 1"
420.Dl "dummynet out all pipe 2"
7af5ce03
A
421.Pp
422The above can be very useful, e.g. if you want to see how
423your fancy Web page will look for a residential user who
424is connected only through a slow link.
425You should not use only one pipe for both directions, unless
426you want to simulate a half-duplex medium (e.g. AppleTalk,
427Ethernet, IRDA).
7af5ce03 428.Pp
342c141e
A
429Note that with the above rules the pipes receive traffic for both the
430IPv4 and IPv6 protocols.
7af5ce03 431.Pp
342c141e
A
432Should we want to verify network performance with the RED queue
433management algorithm, create this pipe:
7af5ce03
A
434.Dl "dnctl pipe 1 config bw 500Kbit/s queue 100 red 0.002/30/80/0.1"
435.Pp
342c141e
A
436and then add these rules to you pf.conf file:
437.Dl "dummynet all pipe 1"
438.Pp
7af5ce03
A
439Another typical application of the traffic shaper is to
440introduce some delay in the communication.
441This can significantly affect applications which do a lot of Remote
442Procedure Calls, and where the round-trip-time of the
443connection often becomes a limiting factor much more than
444bandwidth:
7af5ce03
A
445.Dl "dnctl pipe 1 config delay 250ms bw 1Mbit/s"
446.Dl "dnctl pipe 2 config delay 250ms bw 1Mbit/s"
447.Pp
342c141e
A
448and add these rules in your pf.conf file:
449.Dl "dummynet in all pipe 1"
450.Dl "dummynet out all pipe 2"
451.Pp
7af5ce03
A
452Per-flow queueing can be useful for a variety of purposes.
453A very simple one is counting traffic:
7af5ce03
A
454.Dl "dnctl pipe 1 config mask all"
455.Pp
342c141e
A
456and add these statements in your pf.conf file:
457.Dl "dummynet in quick proto tcp all pipe 1"
458.Dl "dummynet out quick proto tcp all pipe 1"
459.Dl "dummynet in quick proto udp all pipe 1"
460.Dl "dummynet out quick proto udp all pipe 1"
461.Dl "dummynet in quick all pipe 1"
462.Dl "dummynet out quick all pipe 1"
463.Pp
7af5ce03
A
464The above set of rules will create queues (and collect
465statistics) for all traffic.
466Because the pipes have no limitations, the only effect is
467collecting statistics.
342c141e 468Note that we need six rules, not just the last two one, because
7af5ce03
A
469when
470.Nm
471tries to match IP packets it will not consider ports, so we
472would not see connections on separate ports as different
473ones.
7af5ce03
A
474.Sh SEE ALSO
475.Xr cpp 1 ,
7af5ce03 476.Xr dummynet 4 ,
342c141e 477.Xr m4 1 ,
7af5ce03 478.Xr ip 4 ,
342c141e
A
479.Xr pfctl 8 ,
480.Xr pf.conf 5 ,
7af5ce03
A
481.Xr protocols 5 ,
482.Xr services 5 ,
483.Xr sysctl 8
484.Sh AUTHORS
485.An Ugen J. S. Antsilevich ,
486.An Poul-Henning Kamp ,
487.An Alex Nash ,
488.An Archie Cobbs ,
489.An Luigi Rizzo .
490.Pp
491.An -nosplit
492API based upon code written by
493.An Daniel Boulet
494for BSDI.
495.Pp
496Work on
497.Xr dummynet 4
498traffic shaper supported by Akamba Corp.
499.Sh HISTORY
500The
501.Nm
502utility first appeared in
503.Fx 2.0 .
504.Xr dummynet 4
505was introduced in
506.Fx 2.2.8 .
507Stateful extensions were introduced in
508.Fx 4.0 .