iproute2: cake: make gso/gro splitting configurable
[openwrt/openwrt.git] / package / network / utils / iproute2 / patches / 190-add-cake-to-tc.patch
1 --- a/include/uapi/linux/pkt_sched.h
2 +++ b/include/uapi/linux/pkt_sched.h
3 @@ -934,4 +934,118 @@ enum {
4
5 #define TCA_CBS_MAX (__TCA_CBS_MAX - 1)
6
7 +/* CAKE */
8 +enum {
9 + TCA_CAKE_UNSPEC,
10 + TCA_CAKE_PAD,
11 + TCA_CAKE_BASE_RATE64,
12 + TCA_CAKE_DIFFSERV_MODE,
13 + TCA_CAKE_ATM,
14 + TCA_CAKE_FLOW_MODE,
15 + TCA_CAKE_OVERHEAD,
16 + TCA_CAKE_RTT,
17 + TCA_CAKE_TARGET,
18 + TCA_CAKE_AUTORATE,
19 + TCA_CAKE_MEMORY,
20 + TCA_CAKE_NAT,
21 + TCA_CAKE_RAW, // was _ETHERNET
22 + TCA_CAKE_WASH,
23 + TCA_CAKE_MPU,
24 + TCA_CAKE_INGRESS,
25 + TCA_CAKE_ACK_FILTER,
26 + TCA_CAKE_SPLIT_GSO,
27 + __TCA_CAKE_MAX
28 +};
29 +#define TCA_CAKE_MAX (__TCA_CAKE_MAX - 1)
30 +
31 +enum {
32 + __TCA_CAKE_STATS_INVALID,
33 + TCA_CAKE_STATS_PAD,
34 + TCA_CAKE_STATS_CAPACITY_ESTIMATE64,
35 + TCA_CAKE_STATS_MEMORY_LIMIT,
36 + TCA_CAKE_STATS_MEMORY_USED,
37 + TCA_CAKE_STATS_AVG_NETOFF,
38 + TCA_CAKE_STATS_MIN_NETLEN,
39 + TCA_CAKE_STATS_MAX_NETLEN,
40 + TCA_CAKE_STATS_MIN_ADJLEN,
41 + TCA_CAKE_STATS_MAX_ADJLEN,
42 + TCA_CAKE_STATS_TIN_STATS,
43 + TCA_CAKE_STATS_DEFICIT,
44 + TCA_CAKE_STATS_COBALT_COUNT,
45 + TCA_CAKE_STATS_DROPPING,
46 + TCA_CAKE_STATS_DROP_NEXT_US,
47 + TCA_CAKE_STATS_P_DROP,
48 + TCA_CAKE_STATS_BLUE_TIMER_US,
49 + __TCA_CAKE_STATS_MAX
50 +};
51 +#define TCA_CAKE_STATS_MAX (__TCA_CAKE_STATS_MAX - 1)
52 +
53 +enum {
54 + __TCA_CAKE_TIN_STATS_INVALID,
55 + TCA_CAKE_TIN_STATS_PAD,
56 + TCA_CAKE_TIN_STATS_SENT_PACKETS,
57 + TCA_CAKE_TIN_STATS_SENT_BYTES64,
58 + TCA_CAKE_TIN_STATS_DROPPED_PACKETS,
59 + TCA_CAKE_TIN_STATS_DROPPED_BYTES64,
60 + TCA_CAKE_TIN_STATS_ACKS_DROPPED_PACKETS,
61 + TCA_CAKE_TIN_STATS_ACKS_DROPPED_BYTES64,
62 + TCA_CAKE_TIN_STATS_ECN_MARKED_PACKETS,
63 + TCA_CAKE_TIN_STATS_ECN_MARKED_BYTES64,
64 + TCA_CAKE_TIN_STATS_BACKLOG_PACKETS,
65 + TCA_CAKE_TIN_STATS_BACKLOG_BYTES,
66 + TCA_CAKE_TIN_STATS_THRESHOLD_RATE64,
67 + TCA_CAKE_TIN_STATS_TARGET_US,
68 + TCA_CAKE_TIN_STATS_INTERVAL_US,
69 + TCA_CAKE_TIN_STATS_WAY_INDIRECT_HITS,
70 + TCA_CAKE_TIN_STATS_WAY_MISSES,
71 + TCA_CAKE_TIN_STATS_WAY_COLLISIONS,
72 + TCA_CAKE_TIN_STATS_PEAK_DELAY_US,
73 + TCA_CAKE_TIN_STATS_AVG_DELAY_US,
74 + TCA_CAKE_TIN_STATS_BASE_DELAY_US,
75 + TCA_CAKE_TIN_STATS_SPARSE_FLOWS,
76 + TCA_CAKE_TIN_STATS_BULK_FLOWS,
77 + TCA_CAKE_TIN_STATS_UNRESPONSIVE_FLOWS,
78 + TCA_CAKE_TIN_STATS_MAX_SKBLEN,
79 + TCA_CAKE_TIN_STATS_FLOW_QUANTUM,
80 + __TCA_CAKE_TIN_STATS_MAX
81 +};
82 +#define TCA_CAKE_TIN_STATS_MAX (__TCA_CAKE_TIN_STATS_MAX - 1)
83 +#define TC_CAKE_MAX_TINS (8)
84 +
85 +enum {
86 + CAKE_FLOW_NONE = 0,
87 + CAKE_FLOW_SRC_IP,
88 + CAKE_FLOW_DST_IP,
89 + CAKE_FLOW_HOSTS, /* = CAKE_FLOW_SRC_IP | CAKE_FLOW_DST_IP */
90 + CAKE_FLOW_FLOWS,
91 + CAKE_FLOW_DUAL_SRC, /* = CAKE_FLOW_SRC_IP | CAKE_FLOW_FLOWS */
92 + CAKE_FLOW_DUAL_DST, /* = CAKE_FLOW_DST_IP | CAKE_FLOW_FLOWS */
93 + CAKE_FLOW_TRIPLE, /* = CAKE_FLOW_HOSTS | CAKE_FLOW_FLOWS */
94 + CAKE_FLOW_MAX,
95 +};
96 +
97 +enum {
98 + CAKE_DIFFSERV_DIFFSERV3 = 0,
99 + CAKE_DIFFSERV_DIFFSERV4,
100 + CAKE_DIFFSERV_DIFFSERV8,
101 + CAKE_DIFFSERV_BESTEFFORT,
102 + CAKE_DIFFSERV_PRECEDENCE,
103 + CAKE_DIFFSERV_MAX
104 +};
105 +
106 +enum {
107 + CAKE_ACK_NONE = 0,
108 + CAKE_ACK_FILTER,
109 + CAKE_ACK_AGGRESSIVE,
110 + CAKE_ACK_MAX
111 +};
112 +
113 +enum {
114 + CAKE_ATM_NONE = 0,
115 + CAKE_ATM_ATM,
116 + CAKE_ATM_PTM,
117 + CAKE_ATM_MAX
118 +};
119 +
120 +
121 #endif
122 --- /dev/null
123 +++ b/man/man8/tc-cake.8
124 @@ -0,0 +1,632 @@
125 +.TH CAKE 8 "19 July 2018" "iproute2" "Linux"
126 +.SH NAME
127 +CAKE \- Common Applications Kept Enhanced (CAKE)
128 +.SH SYNOPSIS
129 +.B tc qdisc ... cake
130 +.br
131 +[
132 +.BR bandwidth
133 +RATE |
134 +.BR unlimited*
135 +|
136 +.BR autorate-ingress
137 +]
138 +.br
139 +[
140 +.BR rtt
141 +TIME |
142 +.BR datacentre
143 +|
144 +.BR lan
145 +|
146 +.BR metro
147 +|
148 +.BR regional
149 +|
150 +.BR internet*
151 +|
152 +.BR oceanic
153 +|
154 +.BR satellite
155 +|
156 +.BR interplanetary
157 +]
158 +.br
159 +[
160 +.BR besteffort
161 +|
162 +.BR diffserv8
163 +|
164 +.BR diffserv4
165 +|
166 +.BR diffserv3*
167 +]
168 +.br
169 +[
170 +.BR flowblind
171 +|
172 +.BR srchost
173 +|
174 +.BR dsthost
175 +|
176 +.BR hosts
177 +|
178 +.BR flows
179 +|
180 +.BR dual-srchost
181 +|
182 +.BR dual-dsthost
183 +|
184 +.BR triple-isolate*
185 +]
186 +.br
187 +[
188 +.BR nat
189 +|
190 +.BR nonat*
191 +]
192 +.br
193 +[
194 +.BR wash
195 +|
196 +.BR nowash*
197 +]
198 +.br
199 +[
200 +.BR ack-filter
201 +|
202 +.BR ack-filter-aggressive
203 +|
204 +.BR no-ack-filter*
205 +]
206 +.br
207 +[
208 +.BR memlimit
209 +LIMIT ]
210 +.br
211 +[
212 +.BR ptm
213 +|
214 +.BR atm
215 +|
216 +.BR noatm*
217 +]
218 +.br
219 +[
220 +.BR overhead
221 +N |
222 +.BR conservative
223 +|
224 +.BR raw*
225 +]
226 +.br
227 +[
228 +.BR mpu
229 +N ]
230 +.br
231 +[
232 +.BR ingress
233 +|
234 +.BR egress*
235 +]
236 +.br
237 +(* marks defaults)
238 +
239 +
240 +.SH DESCRIPTION
241 +CAKE (Common Applications Kept Enhanced) is a shaping-capable queue discipline
242 +which uses both AQM and FQ. It combines COBALT, which is an AQM algorithm
243 +combining Codel and BLUE, a shaper which operates in deficit mode, and a variant
244 +of DRR++ for flow isolation. 8-way set-associative hashing is used to virtually
245 +eliminate hash collisions. Priority queuing is available through a simplified
246 +diffserv implementation. Overhead compensation for various encapsulation
247 +schemes is tightly integrated.
248 +
249 +All settings are optional; the default settings are chosen to be sensible in
250 +most common deployments. Most people will only need to set the
251 +.B bandwidth
252 +parameter to get useful results, but reading the
253 +.B Overhead Compensation
254 +and
255 +.B Round Trip Time
256 +sections is strongly encouraged.
257 +
258 +.SH SHAPER PARAMETERS
259 +CAKE uses a deficit-mode shaper, which does not exhibit the initial burst
260 +typical of token-bucket shapers. It will automatically burst precisely as much
261 +as required to maintain the configured throughput. As such, it is very
262 +straightforward to configure.
263 +.PP
264 +.B unlimited
265 +(default)
266 +.br
267 + No limit on the bandwidth.
268 +.PP
269 +.B bandwidth
270 +RATE
271 +.br
272 + Set the shaper bandwidth. See
273 +.BR tc(8)
274 +or examples below for details of the RATE value.
275 +.PP
276 +.B autorate-ingress
277 +.br
278 + Automatic capacity estimation based on traffic arriving at this qdisc.
279 +This is most likely to be useful with cellular links, which tend to change
280 +quality randomly. A
281 +.B bandwidth
282 +parameter can be used in conjunction to specify an initial estimate. The shaper
283 +will periodically be set to a bandwidth slightly below the estimated rate. This
284 +estimator cannot estimate the bandwidth of links downstream of itself.
285 +
286 +.SH OVERHEAD COMPENSATION PARAMETERS
287 +The size of each packet on the wire may differ from that seen by Linux. The
288 +following parameters allow CAKE to compensate for this difference by internally
289 +considering each packet to be bigger than Linux informs it. To assist users who
290 +are not expert network engineers, keywords have been provided to represent a
291 +number of common link technologies.
292 +
293 +.SS Manual Overhead Specification
294 +.B overhead
295 +BYTES
296 +.br
297 + Adds BYTES to the size of each packet. BYTES may be negative; values
298 +between -64 and 256 (inclusive) are accepted.
299 +.PP
300 +.B mpu
301 +BYTES
302 +.br
303 + Rounds each packet (including overhead) up to a minimum length
304 +BYTES. BYTES may not be negative; values between 0 and 256 (inclusive)
305 +are accepted.
306 +.PP
307 +.B atm
308 +.br
309 + Compensates for ATM cell framing, which is normally found on ADSL links.
310 +This is performed after the
311 +.B overhead
312 +parameter above. ATM uses fixed 53-byte cells, each of which can carry 48 bytes
313 +payload.
314 +.PP
315 +.B ptm
316 +.br
317 + Compensates for PTM encoding, which is normally found on VDSL2 links and
318 +uses a 64b/65b encoding scheme. It is even more efficient to simply
319 +derate the specified shaper bandwidth by a factor of 64/65 or 0.984. See
320 +ITU G.992.3 Annex N and IEEE 802.3 Section 61.3 for details.
321 +.PP
322 +.B noatm
323 +.br
324 + Disables ATM and PTM compensation.
325 +
326 +.SS Failsafe Overhead Keywords
327 +These two keywords are provided for quick-and-dirty setup. Use them if you
328 +can't be bothered to read the rest of this section.
329 +.PP
330 +.B raw
331 +(default)
332 +.br
333 + Turns off all overhead compensation in CAKE. The packet size reported
334 +by Linux will be used directly.
335 +.PP
336 + Other overhead keywords may be added after "raw". The effect of this is
337 +to make the overhead compensation operate relative to the reported packet size,
338 +not the underlying IP packet size.
339 +.PP
340 +.B conservative
341 +.br
342 + Compensates for more overhead than is likely to occur on any
343 +widely-deployed link technology.
344 +.br
345 + Equivalent to
346 +.B overhead 48 atm.
347 +
348 +.SS ADSL Overhead Keywords
349 +Most ADSL modems have a way to check which framing scheme is in use. Often this
350 +is also specified in the settings document provided by the ISP. The keywords in
351 +this section are intended to correspond with these sources of information. All
352 +of them implicitly set the
353 +.B atm
354 +flag.
355 +.PP
356 +.B pppoa-vcmux
357 +.br
358 + Equivalent to
359 +.B overhead 10 atm
360 +.PP
361 +.B pppoa-llc
362 +.br
363 + Equivalent to
364 +.B overhead 14 atm
365 +.PP
366 +.B pppoe-vcmux
367 +.br
368 + Equivalent to
369 +.B overhead 32 atm
370 +.PP
371 +.B pppoe-llcsnap
372 +.br
373 + Equivalent to
374 +.B overhead 40 atm
375 +.PP
376 +.B bridged-vcmux
377 +.br
378 + Equivalent to
379 +.B overhead 24 atm
380 +.PP
381 +.B bridged-llcsnap
382 +.br
383 + Equivalent to
384 +.B overhead 32 atm
385 +.PP
386 +.B ipoa-vcmux
387 +.br
388 + Equivalent to
389 +.B overhead 8 atm
390 +.PP
391 +.B ipoa-llcsnap
392 +.br
393 + Equivalent to
394 +.B overhead 16 atm
395 +.PP
396 +See also the Ethernet Correction Factors section below.
397 +
398 +.SS VDSL2 Overhead Keywords
399 +ATM was dropped from VDSL2 in favour of PTM, which is a much more
400 +straightforward framing scheme. Some ISPs retained PPPoE for compatibility with
401 +their existing back-end systems.
402 +.PP
403 +.B pppoe-ptm
404 +.br
405 + Equivalent to
406 +.B overhead 30 ptm
407 +
408 +.br
409 + PPPoE: 2B PPP + 6B PPPoE +
410 +.br
411 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
412 +.br
413 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
414 +.br
415 +.PP
416 +.B bridged-ptm
417 +.br
418 + Equivalent to
419 +.B overhead 22 ptm
420 +.br
421 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
422 +.br
423 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
424 +.br
425 +.PP
426 +See also the Ethernet Correction Factors section below.
427 +
428 +.SS DOCSIS Cable Overhead Keyword
429 +DOCSIS is the universal standard for providing Internet service over cable-TV
430 +infrastructure.
431 +
432 +In this case, the actual on-wire overhead is less important than the packet size
433 +the head-end equipment uses for shaping and metering. This is specified to be
434 +an Ethernet frame including the CRC (aka FCS).
435 +.PP
436 +.B docsis
437 +.br
438 + Equivalent to
439 +.B overhead 18 mpu 64 noatm
440 +
441 +.SS Ethernet Overhead Keywords
442 +.PP
443 +.B ethernet
444 +.br
445 + Accounts for Ethernet's preamble, inter-frame gap, and Frame Check
446 +Sequence. Use this keyword when the bottleneck being shaped for is an
447 +actual Ethernet cable.
448 +.br
449 + Equivalent to
450 +.B overhead 38 mpu 84 noatm
451 +.PP
452 +.B ether-vlan
453 +.br
454 + Adds 4 bytes to the overhead compensation, accounting for an IEEE 802.1Q
455 +VLAN header appended to the Ethernet frame header. NB: Some ISPs use one or
456 +even two of these within PPPoE; this keyword may be repeated as necessary to
457 +express this.
458 +
459 +.SH ROUND TRIP TIME PARAMETERS
460 +Active Queue Management (AQM) consists of embedding congestion signals in the
461 +packet flow, which receivers use to instruct senders to slow down when the queue
462 +is persistently occupied. CAKE uses ECN signalling when available, and packet
463 +drops otherwise, according to a combination of the Codel and BLUE AQM algorithms
464 +called COBALT.
465 +
466 +Very short latencies require a very rapid AQM response to adequately control
467 +latency. However, such a rapid response tends to impair throughput when the
468 +actual RTT is relatively long. CAKE allows specifying the RTT it assumes for
469 +tuning various parameters. Actual RTTs within an order of magnitude of this
470 +will generally work well for both throughput and latency management.
471 +
472 +At the 'lan' setting and below, the time constants are similar in magnitude to
473 +the jitter in the Linux kernel itself, so congestion might be signalled
474 +prematurely. The flows will then become sparse and total throughput reduced,
475 +leaving little or no back-pressure for the fairness logic to work against. Use
476 +the "metro" setting for local lans unless you have a custom kernel.
477 +.PP
478 +.B rtt
479 +TIME
480 +.br
481 + Manually specify an RTT.
482 +.PP
483 +.B datacentre
484 +.br
485 + For extremely high-performance 10GigE+ networks only. Equivalent to
486 +.B rtt 100us.
487 +.PP
488 +.B lan
489 +.br
490 + For pure Ethernet (not Wi-Fi) networks, at home or in the office. Don't
491 +use this when shaping for an Internet access link. Equivalent to
492 +.B rtt 1ms.
493 +.PP
494 +.B metro
495 +.br
496 + For traffic mostly within a single city. Equivalent to
497 +.B rtt 10ms.
498 +.PP
499 +.B regional
500 +.br
501 + For traffic mostly within a European-sized country. Equivalent to
502 +.B rtt 30ms.
503 +.PP
504 +.B internet
505 +(default)
506 +.br
507 + This is suitable for most Internet traffic. Equivalent to
508 +.B rtt 100ms.
509 +.PP
510 +.B oceanic
511 +.br
512 + For Internet traffic with generally above-average latency, such as that
513 +suffered by Australasian residents. Equivalent to
514 +.B rtt 300ms.
515 +.PP
516 +.B satellite
517 +.br
518 + For traffic via geostationary satellites. Equivalent to
519 +.B rtt 1000ms.
520 +.PP
521 +.B interplanetary
522 +.br
523 + So named because Jupiter is about 1 light-hour from Earth. Use this to
524 +(almost) completely disable AQM actions. Equivalent to
525 +.B rtt 3600s.
526 +
527 +.SH FLOW ISOLATION PARAMETERS
528 +With flow isolation enabled, CAKE places packets from different flows into
529 +different queues, each of which carries its own AQM state. Packets from each
530 +queue are then delivered fairly, according to a DRR++ algorithm which minimises
531 +latency for "sparse" flows. CAKE uses a set-associative hashing algorithm to
532 +minimise flow collisions.
533 +
534 +These keywords specify whether fairness based on source address, destination
535 +address, individual flows, or any combination of those is desired.
536 +.PP
537 +.B flowblind
538 +.br
539 + Disables flow isolation; all traffic passes through a single queue for
540 +each tin.
541 +.PP
542 +.B srchost
543 +.br
544 + Flows are defined only by source address. Could be useful on the egress
545 +path of an ISP backhaul.
546 +.PP
547 +.B dsthost
548 +.br
549 + Flows are defined only by destination address. Could be useful on the
550 +ingress path of an ISP backhaul.
551 +.PP
552 +.B hosts
553 +.br
554 + Flows are defined by source-destination host pairs. This is host
555 +isolation, rather than flow isolation.
556 +.PP
557 +.B flows
558 +.br
559 + Flows are defined by the entire 5-tuple of source address, destination
560 +address, transport protocol, source port and destination port. This is the type
561 +of flow isolation performed by SFQ and fq_codel.
562 +.PP
563 +.B dual-srchost
564 +.br
565 + Flows are defined by the 5-tuple, and fairness is applied first over
566 +source addresses, then over individual flows. Good for use on egress traffic
567 +from a LAN to the internet, where it'll prevent any one LAN host from
568 +monopolising the uplink, regardless of the number of flows they use.
569 +.PP
570 +.B dual-dsthost
571 +.br
572 + Flows are defined by the 5-tuple, and fairness is applied first over
573 +destination addresses, then over individual flows. Good for use on ingress
574 +traffic to a LAN from the internet, where it'll prevent any one LAN host from
575 +monopolising the downlink, regardless of the number of flows they use.
576 +.PP
577 +.B triple-isolate
578 +(default)
579 +.br
580 + Flows are defined by the 5-tuple, and fairness is applied over source
581 +*and* destination addresses intelligently (ie. not merely by host-pairs), and
582 +also over individual flows. Use this if you're not certain whether to use
583 +dual-srchost or dual-dsthost; it'll do both jobs at once, preventing any one
584 +host on *either* side of the link from monopolising it with a large number of
585 +flows.
586 +.PP
587 +.B nat
588 +.br
589 + Instructs Cake to perform a NAT lookup before applying flow-isolation
590 +rules, to determine the true addresses and port numbers of the packet, to
591 +improve fairness between hosts "inside" the NAT. This has no practical effect
592 +in "flowblind" or "flows" modes, or if NAT is performed on a different host.
593 +.PP
594 +.B nonat
595 +(default)
596 +.br
597 + Cake will not perform a NAT lookup. Flow isolation will be performed
598 +using the addresses and port numbers directly visible to the interface Cake is
599 +attached to.
600 +
601 +.SH PRIORITY QUEUE PARAMETERS
602 +CAKE can divide traffic into "tins" based on the Diffserv field. Each tin has
603 +its own independent set of flow-isolation queues, and is serviced based on a WRR
604 +algorithm. To avoid perverse Diffserv marking incentives, tin weights have a
605 +"priority sharing" value when bandwidth used by that tin is below a threshold,
606 +and a lower "bandwidth sharing" value when above. Bandwidth is compared against
607 +the threshold using the same algorithm as the deficit-mode shaper.
608 +
609 +Detailed customisation of tin parameters is not provided. The following presets
610 +perform all necessary tuning, relative to the current shaper bandwidth and RTT
611 +settings.
612 +.PP
613 +.B besteffort
614 +.br
615 + Disables priority queuing by placing all traffic in one tin.
616 +.PP
617 +.B precedence
618 +.br
619 + Enables legacy interpretation of TOS "Precedence" field. Use of this
620 +preset on the modern Internet is firmly discouraged.
621 +.PP
622 +.B diffserv4
623 +.br
624 + Provides a general-purpose Diffserv implementation with four tins:
625 +.br
626 + Bulk (CS1), 6.25% threshold, generally low priority.
627 +.br
628 + Best Effort (general), 100% threshold.
629 +.br
630 + Video (AF4x, AF3x, CS3, AF2x, CS2, TOS4, TOS1), 50% threshold.
631 +.br
632 + Voice (CS7, CS6, EF, VA, CS5, CS4), 25% threshold.
633 +.PP
634 +.B diffserv3
635 +(default)
636 +.br
637 + Provides a simple, general-purpose Diffserv implementation with three tins:
638 +.br
639 + Bulk (CS1), 6.25% threshold, generally low priority.
640 +.br
641 + Best Effort (general), 100% threshold.
642 +.br
643 + Voice (CS7, CS6, EF, VA, TOS4), 25% threshold, reduced Codel interval.
644 +
645 +.SH OTHER PARAMETERS
646 +.B memlimit
647 +LIMIT
648 +.br
649 + Limit the memory consumed by Cake to LIMIT bytes. Note that this does
650 +not translate directly to queue size (so do not size this based on bandwidth
651 +delay product considerations, but rather on worst case acceptable memory
652 +consumption), as there is some overhead in the data structures containing the
653 +packets, especially for small packets.
654 +
655 + By default, the limit is calculated based on the bandwidth and RTT
656 +settings.
657 +
658 +.PP
659 +.B wash
660 +
661 +.br
662 + Traffic entering your diffserv domain is frequently mis-marked in
663 +transit from the perspective of your network, and traffic exiting yours may be
664 +mis-marked from the perspective of the transiting provider.
665 +
666 +Apply the wash option to clear all extra diffserv (but not ECN bits), after
667 +priority queuing has taken place.
668 +
669 +If you are shaping inbound, and cannot trust the diffserv markings (as is the
670 +case for Comcast Cable, among others), it is best to use a single queue
671 +"besteffort" mode with wash.
672 +
673 +.SH EXAMPLES
674 +# tc qdisc delete root dev eth0
675 +.br
676 +# tc qdisc add root dev eth0 cake bandwidth 100Mbit ethernet
677 +.br
678 +# tc -s qdisc show dev eth0
679 +.br
680 +qdisc cake 1: root refcnt 2 bandwidth 100Mbit diffserv3 triple-isolate rtt 100.0ms noatm overhead 38 mpu 84
681 + Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
682 + backlog 0b 0p requeues 0
683 + memory used: 0b of 5000000b
684 + capacity estimate: 100Mbit
685 + min/max network layer size: 65535 / 0
686 + min/max overhead-adjusted size: 65535 / 0
687 + average network hdr offset: 0
688 +
689 + Bulk Best Effort Voice
690 + thresh 6250Kbit 100Mbit 25Mbit
691 + target 5.0ms 5.0ms 5.0ms
692 + interval 100.0ms 100.0ms 100.0ms
693 + pk_delay 0us 0us 0us
694 + av_delay 0us 0us 0us
695 + sp_delay 0us 0us 0us
696 + pkts 0 0 0
697 + bytes 0 0 0
698 + way_inds 0 0 0
699 + way_miss 0 0 0
700 + way_cols 0 0 0
701 + drops 0 0 0
702 + marks 0 0 0
703 + ack_drop 0 0 0
704 + sp_flows 0 0 0
705 + bk_flows 0 0 0
706 + un_flows 0 0 0
707 + max_len 0 0 0
708 + quantum 300 1514 762
709 +
710 +After some use:
711 +.br
712 +# tc -s qdisc show dev eth0
713 +
714 +qdisc cake 1: root refcnt 2 bandwidth 100Mbit diffserv3 triple-isolate rtt 100.0ms noatm overhead 38 mpu 84
715 + Sent 44709231 bytes 31931 pkt (dropped 45, overlimits 93782 requeues 0)
716 + backlog 33308b 22p requeues 0
717 + memory used: 292352b of 5000000b
718 + capacity estimate: 100Mbit
719 + min/max network layer size: 28 / 1500
720 + min/max overhead-adjusted size: 84 / 1538
721 + average network hdr offset: 14
722 +
723 + Bulk Best Effort Voice
724 + thresh 6250Kbit 100Mbit 25Mbit
725 + target 5.0ms 5.0ms 5.0ms
726 + interval 100.0ms 100.0ms 100.0ms
727 + pk_delay 8.7ms 6.9ms 5.0ms
728 + av_delay 4.9ms 5.3ms 3.8ms
729 + sp_delay 727us 1.4ms 511us
730 + pkts 2590 21271 8137
731 + bytes 3081804 30302659 11426206
732 + way_inds 0 46 0
733 + way_miss 3 17 4
734 + way_cols 0 0 0
735 + drops 20 15 10
736 + marks 0 0 0
737 + ack_drop 0 0 0
738 + sp_flows 2 4 1
739 + bk_flows 1 2 1
740 + un_flows 0 0 0
741 + max_len 1514 1514 1514
742 + quantum 300 1514 762
743 +
744 +.SH SEE ALSO
745 +.BR tc (8),
746 +.BR tc-codel (8),
747 +.BR tc-fq_codel (8),
748 +.BR tc-htb (8)
749 +
750 +.SH AUTHORS
751 +Cake's principal author is Jonathan Morton, with contributions from
752 +Tony Ambardar, Kevin Darbyshire-Bryant, Toke Høiland-Jørgensen,
753 +Sebastian Moeller, Ryan Mounce, Dean Scarff, Nils Andreas Svee, and Dave Täht.
754 +
755 +This manual page was written by Loganaden Velvindron. Please report corrections
756 +to the Linux Networking mailing list <netdev@vger.kernel.org>.
757 --- a/man/man8/tc.8
758 +++ b/man/man8/tc.8
759 @@ -795,6 +795,7 @@ was written by Alexey N. Kuznetsov and a
760 .BR tc-basic (8),
761 .BR tc-bfifo (8),
762 .BR tc-bpf (8),
763 +.BR tc-cake (8),
764 .BR tc-cbq (8),
765 .BR tc-cgroup (8),
766 .BR tc-choke (8),
767 --- a/tc/Makefile
768 +++ b/tc/Makefile
769 @@ -66,6 +66,7 @@ TCMODULES += q_codel.o
770 TCMODULES += q_fq_codel.o
771 TCMODULES += q_fq.o
772 TCMODULES += q_pie.o
773 +TCMODULES += q_cake.o
774 TCMODULES += q_hhf.o
775 TCMODULES += q_clsact.o
776 TCMODULES += e_bpf.o
777 --- /dev/null
778 +++ b/tc/q_cake.c
779 @@ -0,0 +1,799 @@
780 +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
781 +
782 +/*
783 + * Common Applications Kept Enhanced -- CAKE
784 + *
785 + * Copyright (C) 2014-2018 Jonathan Morton <chromatix99@gmail.com>
786 + * Copyright (C) 2017-2018 Toke Høiland-Jørgensen <toke@toke.dk>
787 + */
788 +
789 +#include <stddef.h>
790 +#include <stdio.h>
791 +#include <stdlib.h>
792 +#include <unistd.h>
793 +#include <syslog.h>
794 +#include <fcntl.h>
795 +#include <sys/socket.h>
796 +#include <netinet/in.h>
797 +#include <arpa/inet.h>
798 +#include <string.h>
799 +#include <inttypes.h>
800 +
801 +#include "utils.h"
802 +#include "tc_util.h"
803 +
804 +struct cake_preset {
805 + char *name;
806 + unsigned int target;
807 + unsigned int interval;
808 +};
809 +
810 +static struct cake_preset presets[] = {
811 + {"datacentre", 5, 100},
812 + {"lan", 50, 1000},
813 + {"metro", 500, 10000},
814 + {"regional", 1500, 30000},
815 + {"internet", 5000, 100000},
816 + {"oceanic", 15000, 300000},
817 + {"satellite", 50000, 1000000},
818 + {"interplanetary", 50000000, 1000000000},
819 +};
820 +
821 +static const char * diffserv_names[CAKE_DIFFSERV_MAX] = {
822 + [CAKE_DIFFSERV_DIFFSERV3] = "diffserv3",
823 + [CAKE_DIFFSERV_DIFFSERV4] = "diffserv4",
824 + [CAKE_DIFFSERV_DIFFSERV8] = "diffserv8",
825 + [CAKE_DIFFSERV_BESTEFFORT] = "besteffort",
826 + [CAKE_DIFFSERV_PRECEDENCE] = "precedence",
827 +};
828 +
829 +static const char * flowmode_names[CAKE_FLOW_MAX] = {
830 + [CAKE_FLOW_NONE] = "flowblind",
831 + [CAKE_FLOW_SRC_IP] = "srchost",
832 + [CAKE_FLOW_DST_IP] = "dsthost",
833 + [CAKE_FLOW_HOSTS] = "hosts",
834 + [CAKE_FLOW_FLOWS] = "flows",
835 + [CAKE_FLOW_DUAL_SRC] = "dual-srchost",
836 + [CAKE_FLOW_DUAL_DST] = "dual-dsthost",
837 + [CAKE_FLOW_TRIPLE] = "triple-isolate",
838 +};
839 +
840 +static struct cake_preset *find_preset(char *argv)
841 +{
842 + int i;
843 +
844 + for (i = 0; i < ARRAY_SIZE(presets); i++)
845 + if (!strcmp(argv, presets[i].name))
846 + return &presets[i];
847 + return NULL;
848 +}
849 +
850 +static void explain(void)
851 +{
852 + fprintf(stderr,
853 +"Usage: ... cake [ bandwidth RATE | unlimited* | autorate-ingress ]\n"
854 +" [ rtt TIME | datacentre | lan | metro | regional |\n"
855 +" internet* | oceanic | satellite | interplanetary ]\n"
856 +" [ besteffort | diffserv8 | diffserv4 | diffserv3* ]\n"
857 +" [ flowblind | srchost | dsthost | hosts | flows |\n"
858 +" dual-srchost | dual-dsthost | triple-isolate* ]\n"
859 +" [ nat | nonat* ]\n"
860 +" [ wash | nowash* ]\n"
861 +" [ split-gso* | no-split-gso ]\n"
862 +" [ ack-filter | ack-filter-aggressive | no-ack-filter* ]\n"
863 +" [ memlimit LIMIT ]\n"
864 +" [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
865 +" [ mpu N ] [ ingress | egress* ]\n"
866 +" (* marks defaults)\n");
867 +}
868 +
869 +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
870 + struct nlmsghdr *n, const char *dev)
871 +{
872 + struct cake_preset *preset, *preset_set = NULL;
873 + bool overhead_override = false;
874 + bool overhead_set = false;
875 + unsigned int interval = 0;
876 + unsigned int diffserv = 0;
877 + unsigned int memlimit = 0;
878 + unsigned int target = 0;
879 + __u64 bandwidth = 0;
880 + int ack_filter = -1;
881 + struct rtattr *tail;
882 + int unlimited = 0;
883 + int flowmode = -1;
884 + int autorate = -1;
885 + int ingress = -1;
886 + int overhead = 0;
887 + int wash = -1;
888 + int nat = -1;
889 + int atm = -1;
890 + int mpu = 0;
891 + int split_gso = -1;
892 +
893 + while (argc > 0) {
894 + if (strcmp(*argv, "bandwidth") == 0) {
895 + NEXT_ARG();
896 + if (get_rate64(&bandwidth, *argv)) {
897 + fprintf(stderr, "Illegal \"bandwidth\"\n");
898 + return -1;
899 + }
900 + unlimited = 0;
901 + autorate = 0;
902 + } else if (strcmp(*argv, "unlimited") == 0) {
903 + bandwidth = 0;
904 + unlimited = 1;
905 + autorate = 0;
906 + } else if (strcmp(*argv, "autorate-ingress") == 0) {
907 + autorate = 1;
908 + } else if (strcmp(*argv, "rtt") == 0) {
909 + NEXT_ARG();
910 + if (get_time(&interval, *argv)) {
911 + fprintf(stderr, "Illegal \"rtt\"\n");
912 + return -1;
913 + }
914 + target = interval / 20;
915 + if (!target)
916 + target = 1;
917 + } else if ((preset = find_preset(*argv))) {
918 + if (preset_set)
919 + duparg(*argv, preset_set->name);
920 + preset_set = preset;
921 + target = preset->target;
922 + interval = preset->interval;
923 + } else if (strcmp(*argv, "besteffort") == 0) {
924 + diffserv = CAKE_DIFFSERV_BESTEFFORT;
925 + } else if (strcmp(*argv, "precedence") == 0) {
926 + diffserv = CAKE_DIFFSERV_PRECEDENCE;
927 + } else if (strcmp(*argv, "diffserv8") == 0) {
928 + diffserv = CAKE_DIFFSERV_DIFFSERV8;
929 + } else if (strcmp(*argv, "diffserv4") == 0) {
930 + diffserv = CAKE_DIFFSERV_DIFFSERV4;
931 + } else if (strcmp(*argv, "diffserv") == 0) {
932 + diffserv = CAKE_DIFFSERV_DIFFSERV4;
933 + } else if (strcmp(*argv, "diffserv3") == 0) {
934 + diffserv = CAKE_DIFFSERV_DIFFSERV3;
935 + } else if (strcmp(*argv, "nowash") == 0) {
936 + wash = 0;
937 + } else if (strcmp(*argv, "wash") == 0) {
938 + wash = 1;
939 + } else if (strcmp(*argv, "split-gso") == 0) {
940 + split_gso = 1;
941 + } else if (strcmp(*argv, "no-split-gso") == 0) {
942 + split_gso = 0;
943 + } else if (strcmp(*argv, "flowblind") == 0) {
944 + flowmode = CAKE_FLOW_NONE;
945 + } else if (strcmp(*argv, "srchost") == 0) {
946 + flowmode = CAKE_FLOW_SRC_IP;
947 + } else if (strcmp(*argv, "dsthost") == 0) {
948 + flowmode = CAKE_FLOW_DST_IP;
949 + } else if (strcmp(*argv, "hosts") == 0) {
950 + flowmode = CAKE_FLOW_HOSTS;
951 + } else if (strcmp(*argv, "flows") == 0) {
952 + flowmode = CAKE_FLOW_FLOWS;
953 + } else if (strcmp(*argv, "dual-srchost") == 0) {
954 + flowmode = CAKE_FLOW_DUAL_SRC;
955 + } else if (strcmp(*argv, "dual-dsthost") == 0) {
956 + flowmode = CAKE_FLOW_DUAL_DST;
957 + } else if (strcmp(*argv, "triple-isolate") == 0) {
958 + flowmode = CAKE_FLOW_TRIPLE;
959 + } else if (strcmp(*argv, "nat") == 0) {
960 + nat = 1;
961 + } else if (strcmp(*argv, "nonat") == 0) {
962 + nat = 0;
963 + } else if (strcmp(*argv, "ptm") == 0) {
964 + atm = CAKE_ATM_PTM;
965 + } else if (strcmp(*argv, "atm") == 0) {
966 + atm = CAKE_ATM_ATM;
967 + } else if (strcmp(*argv, "noatm") == 0) {
968 + atm = CAKE_ATM_NONE;
969 + } else if (strcmp(*argv, "raw") == 0) {
970 + atm = CAKE_ATM_NONE;
971 + overhead = 0;
972 + overhead_set = true;
973 + overhead_override = true;
974 + } else if (strcmp(*argv, "conservative") == 0) {
975 + /*
976 + * Deliberately over-estimate overhead:
977 + * one whole ATM cell plus ATM framing.
978 + * A safe choice if the actual overhead is unknown.
979 + */
980 + atm = CAKE_ATM_ATM;
981 + overhead = 48;
982 + overhead_set = true;
983 +
984 + /* Various ADSL framing schemes, all over ATM cells */
985 + } else if (strcmp(*argv, "ipoa-vcmux") == 0) {
986 + atm = CAKE_ATM_ATM;
987 + overhead += 8;
988 + overhead_set = true;
989 + } else if (strcmp(*argv, "ipoa-llcsnap") == 0) {
990 + atm = CAKE_ATM_ATM;
991 + overhead += 16;
992 + overhead_set = true;
993 + } else if (strcmp(*argv, "bridged-vcmux") == 0) {
994 + atm = CAKE_ATM_ATM;
995 + overhead += 24;
996 + overhead_set = true;
997 + } else if (strcmp(*argv, "bridged-llcsnap") == 0) {
998 + atm = CAKE_ATM_ATM;
999 + overhead += 32;
1000 + overhead_set = true;
1001 + } else if (strcmp(*argv, "pppoa-vcmux") == 0) {
1002 + atm = CAKE_ATM_ATM;
1003 + overhead += 10;
1004 + overhead_set = true;
1005 + } else if (strcmp(*argv, "pppoa-llc") == 0) {
1006 + atm = CAKE_ATM_ATM;
1007 + overhead += 14;
1008 + overhead_set = true;
1009 + } else if (strcmp(*argv, "pppoe-vcmux") == 0) {
1010 + atm = CAKE_ATM_ATM;
1011 + overhead += 32;
1012 + overhead_set = true;
1013 + } else if (strcmp(*argv, "pppoe-llcsnap") == 0) {
1014 + atm = CAKE_ATM_ATM;
1015 + overhead += 40;
1016 + overhead_set = true;
1017 +
1018 + /* Typical VDSL2 framing schemes, both over PTM */
1019 + /* PTM has 64b/65b coding which absorbs some bandwidth */
1020 + } else if (strcmp(*argv, "pppoe-ptm") == 0) {
1021 + /* 2B PPP + 6B PPPoE + 6B dest MAC + 6B src MAC
1022 + * + 2B ethertype + 4B Frame Check Sequence
1023 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
1024 + * + 2B TC-CRC (PTM-FCS) = 30B
1025 + */
1026 + atm = CAKE_ATM_PTM;
1027 + overhead += 30;
1028 + overhead_set = true;
1029 + } else if (strcmp(*argv, "bridged-ptm") == 0) {
1030 + /* 6B dest MAC + 6B src MAC + 2B ethertype
1031 + * + 4B Frame Check Sequence
1032 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
1033 + * + 2B TC-CRC (PTM-FCS) = 22B
1034 + */
1035 + atm = CAKE_ATM_PTM;
1036 + overhead += 22;
1037 + overhead_set = true;
1038 + } else if (strcmp(*argv, "via-ethernet") == 0) {
1039 + /*
1040 + * We used to use this flag to manually compensate for
1041 + * Linux including the Ethernet header on Ethernet-type
1042 + * interfaces, but not on IP-type interfaces.
1043 + *
1044 + * It is no longer needed, because Cake now adjusts for
1045 + * that automatically, and is thus ignored.
1046 + *
1047 + * It would be deleted entirely, but it appears in the
1048 + * stats output when the automatic compensation is
1049 + * active.
1050 + */
1051 + } else if (strcmp(*argv, "ethernet") == 0) {
1052 + /* ethernet pre-amble & interframe gap & FCS
1053 + * you may need to add vlan tag
1054 + */
1055 + overhead += 38;
1056 + overhead_set = true;
1057 + mpu = 84;
1058 +
1059 + /* Additional Ethernet-related overhead used by some ISPs */
1060 + } else if (strcmp(*argv, "ether-vlan") == 0) {
1061 + /* 802.1q VLAN tag - may be repeated */
1062 + overhead += 4;
1063 + overhead_set = true;
1064 +
1065 + /*
1066 + * DOCSIS cable shapers account for Ethernet frame with FCS,
1067 + * but not interframe gap or preamble.
1068 + */
1069 + } else if (strcmp(*argv, "docsis") == 0) {
1070 + atm = CAKE_ATM_NONE;
1071 + overhead += 18;
1072 + overhead_set = true;
1073 + mpu = 64;
1074 + } else if (strcmp(*argv, "overhead") == 0) {
1075 + char *p = NULL;
1076 +
1077 + NEXT_ARG();
1078 + overhead = strtol(*argv, &p, 10);
1079 + if (!p || *p || !*argv ||
1080 + overhead < -64 || overhead > 256) {
1081 + fprintf(stderr,
1082 + "Illegal \"overhead\", valid range is -64 to 256\\n");
1083 + return -1;
1084 + }
1085 + overhead_set = true;
1086 +
1087 + } else if (strcmp(*argv, "mpu") == 0) {
1088 + char *p = NULL;
1089 +
1090 + NEXT_ARG();
1091 + mpu = strtol(*argv, &p, 10);
1092 + if (!p || *p || !*argv || mpu < 0 || mpu > 256) {
1093 + fprintf(stderr,
1094 + "Illegal \"mpu\", valid range is 0 to 256\\n");
1095 + return -1;
1096 + }
1097 + } else if (strcmp(*argv, "ingress") == 0) {
1098 + ingress = 1;
1099 + } else if (strcmp(*argv, "egress") == 0) {
1100 + ingress = 0;
1101 + } else if (strcmp(*argv, "no-ack-filter") == 0) {
1102 + ack_filter = CAKE_ACK_NONE;
1103 + } else if (strcmp(*argv, "ack-filter") == 0) {
1104 + ack_filter = CAKE_ACK_FILTER;
1105 + } else if (strcmp(*argv, "ack-filter-aggressive") == 0) {
1106 + ack_filter = CAKE_ACK_AGGRESSIVE;
1107 + } else if (strcmp(*argv, "memlimit") == 0) {
1108 + NEXT_ARG();
1109 + if (get_size(&memlimit, *argv)) {
1110 + fprintf(stderr,
1111 + "Illegal value for \"memlimit\": \"%s\"\n", *argv);
1112 + return -1;
1113 + }
1114 + } else if (strcmp(*argv, "help") == 0) {
1115 + explain();
1116 + return -1;
1117 + } else {
1118 + fprintf(stderr, "What is \"%s\"?\n", *argv);
1119 + explain();
1120 + return -1;
1121 + }
1122 + argc--; argv++;
1123 + }
1124 +
1125 + tail = NLMSG_TAIL(n);
1126 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
1127 + if (bandwidth || unlimited)
1128 + addattr_l(n, 1024, TCA_CAKE_BASE_RATE64, &bandwidth,
1129 + sizeof(bandwidth));
1130 + if (diffserv)
1131 + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv,
1132 + sizeof(diffserv));
1133 + if (atm != -1)
1134 + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm));
1135 + if (flowmode != -1)
1136 + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode,
1137 + sizeof(flowmode));
1138 + if (overhead_set)
1139 + addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead,
1140 + sizeof(overhead));
1141 + if (overhead_override) {
1142 + unsigned int zero = 0;
1143 +
1144 + addattr_l(n, 1024, TCA_CAKE_RAW, &zero, sizeof(zero));
1145 + }
1146 + if (mpu > 0)
1147 + addattr_l(n, 1024, TCA_CAKE_MPU, &mpu, sizeof(mpu));
1148 + if (interval)
1149 + addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
1150 + if (target)
1151 + addattr_l(n, 1024, TCA_CAKE_TARGET, &target, sizeof(target));
1152 + if (autorate != -1)
1153 + addattr_l(n, 1024, TCA_CAKE_AUTORATE, &autorate,
1154 + sizeof(autorate));
1155 + if (memlimit)
1156 + addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit,
1157 + sizeof(memlimit));
1158 + if (nat != -1)
1159 + addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat));
1160 + if (wash != -1)
1161 + addattr_l(n, 1024, TCA_CAKE_WASH, &wash, sizeof(wash));
1162 + if (split_gso != -1)
1163 + addattr_l(n, 1024, TCA_CAKE_SPLIT_GSO, &split_gso,
1164 + sizeof(split_gso));
1165 + if (ingress != -1)
1166 + addattr_l(n, 1024, TCA_CAKE_INGRESS, &ingress, sizeof(ingress));
1167 + if (ack_filter != -1)
1168 + addattr_l(n, 1024, TCA_CAKE_ACK_FILTER, &ack_filter,
1169 + sizeof(ack_filter));
1170 +
1171 + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
1172 + return 0;
1173 +}
1174 +
1175 +static void cake_print_mode(unsigned int value, unsigned int max,
1176 + const char *key, const char **table)
1177 +{
1178 + if (value < max && table[value]) {
1179 + print_string(PRINT_ANY, key, "%s ", table[value]);
1180 + } else {
1181 + print_string(PRINT_JSON, key, NULL, "unknown");
1182 + print_string(PRINT_FP, NULL, "(?%s?)", key);
1183 + }
1184 +}
1185 +
1186 +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
1187 +{
1188 + struct rtattr *tb[TCA_CAKE_MAX + 1];
1189 + unsigned int interval = 0;
1190 + unsigned int memlimit = 0;
1191 + __u64 bandwidth = 0;
1192 + int ack_filter = 0;
1193 + int split_gso = 0;
1194 + int overhead = 0;
1195 + int autorate = 0;
1196 + int ingress = 0;
1197 + int wash = 0;
1198 + int raw = 0;
1199 + int mpu = 0;
1200 + int atm = 0;
1201 + int nat = 0;
1202 +
1203 + SPRINT_BUF(b1);
1204 + SPRINT_BUF(b2);
1205 +
1206 + if (opt == NULL)
1207 + return 0;
1208 +
1209 + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt);
1210 +
1211 + if (tb[TCA_CAKE_BASE_RATE64] &&
1212 + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE64]) >= sizeof(bandwidth)) {
1213 + bandwidth = rta_getattr_u64(tb[TCA_CAKE_BASE_RATE64]);
1214 + if (bandwidth) {
1215 + print_uint(PRINT_JSON, "bandwidth", NULL, bandwidth);
1216 + print_string(PRINT_FP, NULL, "bandwidth %s ",
1217 + sprint_rate(bandwidth, b1));
1218 + } else
1219 + print_string(PRINT_ANY, "bandwidth", "bandwidth %s ",
1220 + "unlimited");
1221 + }
1222 + if (tb[TCA_CAKE_AUTORATE] &&
1223 + RTA_PAYLOAD(tb[TCA_CAKE_AUTORATE]) >= sizeof(__u32)) {
1224 + autorate = rta_getattr_u32(tb[TCA_CAKE_AUTORATE]);
1225 + if (autorate == 1)
1226 + print_string(PRINT_ANY, "autorate", "%s ",
1227 + "autorate-ingress");
1228 + else if (autorate)
1229 + print_string(PRINT_ANY, "autorate", "(?autorate?) ",
1230 + "unknown");
1231 + }
1232 + if (tb[TCA_CAKE_DIFFSERV_MODE] &&
1233 + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) {
1234 + cake_print_mode(rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]),
1235 + CAKE_DIFFSERV_MAX, "diffserv", diffserv_names);
1236 + }
1237 + if (tb[TCA_CAKE_FLOW_MODE] &&
1238 + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) {
1239 + cake_print_mode(rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]),
1240 + CAKE_FLOW_MAX, "flowmode", flowmode_names);
1241 + }
1242 +
1243 + if (tb[TCA_CAKE_NAT] &&
1244 + RTA_PAYLOAD(tb[TCA_CAKE_NAT]) >= sizeof(__u32)) {
1245 + nat = rta_getattr_u32(tb[TCA_CAKE_NAT]);
1246 + }
1247 +
1248 + if (nat)
1249 + print_string(PRINT_FP, NULL, "nat ", NULL);
1250 + print_bool(PRINT_JSON, "nat", NULL, nat);
1251 +
1252 + if (tb[TCA_CAKE_WASH] &&
1253 + RTA_PAYLOAD(tb[TCA_CAKE_WASH]) >= sizeof(__u32)) {
1254 + wash = rta_getattr_u32(tb[TCA_CAKE_WASH]);
1255 + }
1256 + if (tb[TCA_CAKE_ATM] &&
1257 + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
1258 + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
1259 + }
1260 + if (tb[TCA_CAKE_OVERHEAD] &&
1261 + RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__s32)) {
1262 + overhead = *(__s32 *) RTA_DATA(tb[TCA_CAKE_OVERHEAD]);
1263 + }
1264 + if (tb[TCA_CAKE_MPU] &&
1265 + RTA_PAYLOAD(tb[TCA_CAKE_MPU]) >= sizeof(__u32)) {
1266 + mpu = rta_getattr_u32(tb[TCA_CAKE_MPU]);
1267 + }
1268 + if (tb[TCA_CAKE_INGRESS] &&
1269 + RTA_PAYLOAD(tb[TCA_CAKE_INGRESS]) >= sizeof(__u32)) {
1270 + ingress = rta_getattr_u32(tb[TCA_CAKE_INGRESS]);
1271 + }
1272 + if (tb[TCA_CAKE_ACK_FILTER] &&
1273 + RTA_PAYLOAD(tb[TCA_CAKE_ACK_FILTER]) >= sizeof(__u32)) {
1274 + ack_filter = rta_getattr_u32(tb[TCA_CAKE_ACK_FILTER]);
1275 + }
1276 + if (tb[TCA_CAKE_SPLIT_GSO] &&
1277 + RTA_PAYLOAD(tb[TCA_CAKE_SPLIT_GSO]) >= sizeof(__u32)) {
1278 + split_gso = rta_getattr_u32(tb[TCA_CAKE_SPLIT_GSO]);
1279 + }
1280 + if (tb[TCA_CAKE_RAW]) {
1281 + raw = 1;
1282 + }
1283 + if (tb[TCA_CAKE_RTT] &&
1284 + RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
1285 + interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
1286 + }
1287 +
1288 + if (wash)
1289 + print_string(PRINT_FP, NULL, "wash ", NULL);
1290 + print_bool(PRINT_JSON, "wash", NULL, wash);
1291 +
1292 + if (ingress)
1293 + print_string(PRINT_FP, NULL, "ingress ", NULL);
1294 + print_bool(PRINT_JSON, "ingress", NULL, ingress);
1295 +
1296 + if (ack_filter == CAKE_ACK_AGGRESSIVE)
1297 + print_string(PRINT_ANY, "ack-filter", "ack-filter-%s ",
1298 + "aggressive");
1299 + else if (ack_filter == CAKE_ACK_FILTER)
1300 + print_string(PRINT_ANY, "ack-filter", "ack-filter ", "enabled");
1301 + else
1302 + print_string(PRINT_JSON, "ack-filter", NULL, "disabled");
1303 +
1304 + if (split_gso)
1305 + print_string(PRINT_FP, NULL, "split-gso ", NULL);
1306 + print_bool(PRINT_JSON, "split_gso", NULL, split_gso);
1307 +
1308 + if (interval)
1309 + print_string(PRINT_FP, NULL, "rtt %s ",
1310 + sprint_time(interval, b2));
1311 + print_uint(PRINT_JSON, "rtt", NULL, interval);
1312 +
1313 + if (raw)
1314 + print_string(PRINT_FP, NULL, "raw ", NULL);
1315 + print_bool(PRINT_JSON, "raw", NULL, raw);
1316 +
1317 + if (atm == CAKE_ATM_ATM)
1318 + print_string(PRINT_ANY, "atm", "%s ", "atm");
1319 + else if (atm == CAKE_ATM_PTM)
1320 + print_string(PRINT_ANY, "atm", "%s ", "ptm");
1321 + else if (!raw)
1322 + print_string(PRINT_ANY, "atm", "%s ", "noatm");
1323 +
1324 + print_int(PRINT_ANY, "overhead", "overhead %d ", overhead);
1325 +
1326 + if (mpu)
1327 + print_uint(PRINT_ANY, "mpu", "mpu %u ", mpu);
1328 +
1329 + if (memlimit) {
1330 + print_uint(PRINT_JSON, "memlimit", NULL, memlimit);
1331 + print_string(PRINT_FP, NULL, "memlimit %s",
1332 + sprint_size(memlimit, b1));
1333 + }
1334 +
1335 + return 0;
1336 +}
1337 +
1338 +static void cake_print_json_tin(struct rtattr **tstat)
1339 +{
1340 +#define PRINT_TSTAT_JSON(type, name, attr) if (tstat[TCA_CAKE_TIN_STATS_ ## attr]) \
1341 + print_u64(PRINT_JSON, name, NULL, \
1342 + rta_getattr_ ## type((struct rtattr *) \
1343 + tstat[TCA_CAKE_TIN_STATS_ ## attr]))
1344 +
1345 + open_json_object(NULL);
1346 + PRINT_TSTAT_JSON(u64, "threshold_rate", THRESHOLD_RATE64);
1347 + PRINT_TSTAT_JSON(u64, "sent_bytes", SENT_BYTES64);
1348 + PRINT_TSTAT_JSON(u32, "backlog_bytes", BACKLOG_BYTES);
1349 + PRINT_TSTAT_JSON(u32, "target_us", TARGET_US);
1350 + PRINT_TSTAT_JSON(u32, "interval_us", INTERVAL_US);
1351 + PRINT_TSTAT_JSON(u32, "peak_delay_us", PEAK_DELAY_US);
1352 + PRINT_TSTAT_JSON(u32, "avg_delay_us", AVG_DELAY_US);
1353 + PRINT_TSTAT_JSON(u32, "base_delay_us", BASE_DELAY_US);
1354 + PRINT_TSTAT_JSON(u32, "sent_packets", SENT_PACKETS);
1355 + PRINT_TSTAT_JSON(u32, "way_indirect_hits", WAY_INDIRECT_HITS);
1356 + PRINT_TSTAT_JSON(u32, "way_misses", WAY_MISSES);
1357 + PRINT_TSTAT_JSON(u32, "way_collisions", WAY_COLLISIONS);
1358 + PRINT_TSTAT_JSON(u32, "drops", DROPPED_PACKETS);
1359 + PRINT_TSTAT_JSON(u32, "ecn_mark", ECN_MARKED_PACKETS);
1360 + PRINT_TSTAT_JSON(u32, "ack_drops", ACKS_DROPPED_PACKETS);
1361 + PRINT_TSTAT_JSON(u32, "sparse_flows", SPARSE_FLOWS);
1362 + PRINT_TSTAT_JSON(u32, "bulk_flows", BULK_FLOWS);
1363 + PRINT_TSTAT_JSON(u32, "unresponsive_flows", UNRESPONSIVE_FLOWS);
1364 + PRINT_TSTAT_JSON(u32, "max_pkt_len", MAX_SKBLEN);
1365 + PRINT_TSTAT_JSON(u32, "flow_quantum", FLOW_QUANTUM);
1366 + close_json_object();
1367 +
1368 +#undef PRINT_TSTAT_JSON
1369 +}
1370 +
1371 +static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
1372 + struct rtattr *xstats)
1373 +{
1374 + struct rtattr *st[TCA_CAKE_STATS_MAX + 1];
1375 + SPRINT_BUF(b1);
1376 + int i;
1377 +
1378 + if (xstats == NULL)
1379 + return 0;
1380 +
1381 +#define GET_STAT_U32(attr) rta_getattr_u32(st[TCA_CAKE_STATS_ ## attr])
1382 +#define GET_STAT_S32(attr) (*(__s32 *)RTA_DATA(st[TCA_CAKE_STATS_ ## attr]))
1383 +#define GET_STAT_U64(attr) rta_getattr_u64(st[TCA_CAKE_STATS_ ## attr])
1384 +
1385 + parse_rtattr_nested(st, TCA_CAKE_STATS_MAX, xstats);
1386 +
1387 + if (st[TCA_CAKE_STATS_MEMORY_USED] &&
1388 + st[TCA_CAKE_STATS_MEMORY_LIMIT]) {
1389 + print_string(PRINT_FP, NULL, " memory used: %s",
1390 + sprint_size(GET_STAT_U32(MEMORY_USED), b1));
1391 +
1392 + print_string(PRINT_FP, NULL, " of %s\n",
1393 + sprint_size(GET_STAT_U32(MEMORY_LIMIT), b1));
1394 +
1395 + print_uint(PRINT_JSON, "memory_used", NULL,
1396 + GET_STAT_U32(MEMORY_USED));
1397 + print_uint(PRINT_JSON, "memory_limit", NULL,
1398 + GET_STAT_U32(MEMORY_LIMIT));
1399 + }
1400 +
1401 + if (st[TCA_CAKE_STATS_CAPACITY_ESTIMATE64]) {
1402 + print_string(PRINT_FP, NULL, " capacity estimate: %s\n",
1403 + sprint_rate(GET_STAT_U64(CAPACITY_ESTIMATE64), b1));
1404 + print_uint(PRINT_JSON, "capacity_estimate", NULL,
1405 + GET_STAT_U64(CAPACITY_ESTIMATE64));
1406 + }
1407 +
1408 + if (st[TCA_CAKE_STATS_MIN_NETLEN] &&
1409 + st[TCA_CAKE_STATS_MAX_NETLEN]) {
1410 + print_uint(PRINT_ANY, "min_network_size",
1411 + " min/max network layer size: %12u",
1412 + GET_STAT_U32(MIN_NETLEN));
1413 + print_uint(PRINT_ANY, "max_network_size",
1414 + " /%8u\n", GET_STAT_U32(MAX_NETLEN));
1415 + }
1416 +
1417 + if (st[TCA_CAKE_STATS_MIN_ADJLEN] &&
1418 + st[TCA_CAKE_STATS_MAX_ADJLEN]) {
1419 + print_uint(PRINT_ANY, "min_adj_size",
1420 + " min/max overhead-adjusted size: %8u",
1421 + GET_STAT_U32(MIN_ADJLEN));
1422 + print_uint(PRINT_ANY, "max_adj_size",
1423 + " /%8u\n", GET_STAT_U32(MAX_ADJLEN));
1424 + }
1425 +
1426 + if (st[TCA_CAKE_STATS_AVG_NETOFF])
1427 + print_uint(PRINT_ANY, "avg_hdr_offset",
1428 + " average network hdr offset: %12u\n\n",
1429 + GET_STAT_U32(AVG_NETOFF));
1430 +
1431 + /* class stats */
1432 + if (st[TCA_CAKE_STATS_DEFICIT])
1433 + print_int(PRINT_ANY, "deficit", " deficit %u",
1434 + GET_STAT_S32(DEFICIT));
1435 + if (st[TCA_CAKE_STATS_COBALT_COUNT])
1436 + print_uint(PRINT_ANY, "count", " count %u",
1437 + GET_STAT_U32(COBALT_COUNT));
1438 +
1439 + if (st[TCA_CAKE_STATS_DROPPING] && GET_STAT_U32(DROPPING)) {
1440 + print_bool(PRINT_ANY, "dropping", " dropping", true);
1441 + if (st[TCA_CAKE_STATS_DROP_NEXT_US]) {
1442 + int drop_next = GET_STAT_S32(DROP_NEXT_US);
1443 +
1444 + if (drop_next < 0) {
1445 + print_string(PRINT_FP, NULL, " drop_next -%s",
1446 + sprint_time(drop_next, b1));
1447 + } else {
1448 + print_uint(PRINT_JSON, "drop_next", NULL,
1449 + drop_next);
1450 + print_string(PRINT_FP, NULL, " drop_next %s",
1451 + sprint_time(drop_next, b1));
1452 + }
1453 + }
1454 + }
1455 +
1456 + if (st[TCA_CAKE_STATS_P_DROP]) {
1457 + print_uint(PRINT_ANY, "blue_prob", " blue_prob %u",
1458 + GET_STAT_U32(P_DROP));
1459 + if (st[TCA_CAKE_STATS_BLUE_TIMER_US]) {
1460 + int blue_timer = GET_STAT_S32(BLUE_TIMER_US);
1461 +
1462 + if (blue_timer < 0) {
1463 + print_string(PRINT_FP, NULL, " blue_timer -%s",
1464 + sprint_time(blue_timer, b1));
1465 + } else {
1466 + print_uint(PRINT_JSON, "blue_timer", NULL,
1467 + blue_timer);
1468 + print_string(PRINT_FP, NULL, " blue_timer %s",
1469 + sprint_time(blue_timer, b1));
1470 + }
1471 + }
1472 + }
1473 +
1474 +#undef GET_STAT_U32
1475 +#undef GET_STAT_S32
1476 +#undef GET_STAT_U64
1477 +
1478 + if (st[TCA_CAKE_STATS_TIN_STATS]) {
1479 + struct rtattr *tstat[TC_CAKE_MAX_TINS][TCA_CAKE_TIN_STATS_MAX + 1];
1480 + struct rtattr *tins[TC_CAKE_MAX_TINS + 1];
1481 + int num_tins = 0;
1482 +
1483 + parse_rtattr_nested(tins, TC_CAKE_MAX_TINS,
1484 + st[TCA_CAKE_STATS_TIN_STATS]);
1485 +
1486 + for (i = 1; i <= TC_CAKE_MAX_TINS && tins[i]; i++) {
1487 + parse_rtattr_nested(tstat[i-1], TCA_CAKE_TIN_STATS_MAX,
1488 + tins[i]);
1489 + num_tins++;
1490 + }
1491 +
1492 + if (!num_tins)
1493 + return 0;
1494 +
1495 + if (is_json_context()) {
1496 + open_json_array(PRINT_JSON, "tins");
1497 + for (i = 0; i < num_tins; i++)
1498 + cake_print_json_tin(tstat[i]);
1499 + close_json_array(PRINT_JSON, NULL);
1500 +
1501 + return 0;
1502 + }
1503 +
1504 +
1505 + switch (num_tins) {
1506 + case 3:
1507 + fprintf(f, " Bulk Best Effort Voice\n");
1508 + break;
1509 +
1510 + case 4:
1511 + fprintf(f, " Bulk Best Effort Video Voice\n");
1512 + break;
1513 +
1514 + default:
1515 + fprintf(f, " ");
1516 + for (i = 0; i < num_tins; i++)
1517 + fprintf(f, " Tin %u", i);
1518 + fprintf(f, "\n");
1519 + };
1520 +
1521 +#define GET_TSTAT(i, attr) (tstat[i][TCA_CAKE_TIN_STATS_ ## attr])
1522 +#define PRINT_TSTAT(name, attr, fmts, val) do { \
1523 + if (GET_TSTAT(0, attr)) { \
1524 + fprintf(f, name); \
1525 + for (i = 0; i < num_tins; i++) \
1526 + fprintf(f, " %12" fmts, val); \
1527 + fprintf(f, "\n"); \
1528 + } \
1529 + } while (0)
1530 +
1531 +#define SPRINT_TSTAT(pfunc, type, name, attr) PRINT_TSTAT( \
1532 + name, attr, "s", sprint_ ## pfunc( \
1533 + rta_getattr_ ## type(GET_TSTAT(i, attr)), b1))
1534 +
1535 +#define PRINT_TSTAT_U32(name, attr) PRINT_TSTAT( \
1536 + name, attr, "u", rta_getattr_u32(GET_TSTAT(i, attr)))
1537 +
1538 +#define PRINT_TSTAT_U64(name, attr) PRINT_TSTAT( \
1539 + name, attr, "llu", rta_getattr_u64(GET_TSTAT(i, attr)))
1540 +
1541 + SPRINT_TSTAT(rate, u64, " thresh ", THRESHOLD_RATE64);
1542 + SPRINT_TSTAT(time, u32, " target ", TARGET_US);
1543 + SPRINT_TSTAT(time, u32, " interval", INTERVAL_US);
1544 + SPRINT_TSTAT(time, u32, " pk_delay", PEAK_DELAY_US);
1545 + SPRINT_TSTAT(time, u32, " av_delay", AVG_DELAY_US);
1546 + SPRINT_TSTAT(time, u32, " sp_delay", BASE_DELAY_US);
1547 + SPRINT_TSTAT(size, u32, " backlog ", BACKLOG_BYTES);
1548 +
1549 + PRINT_TSTAT_U32(" pkts ", SENT_PACKETS);
1550 + PRINT_TSTAT_U64(" bytes ", SENT_BYTES64);
1551 +
1552 + PRINT_TSTAT_U32(" way_inds", WAY_INDIRECT_HITS);
1553 + PRINT_TSTAT_U32(" way_miss", WAY_MISSES);
1554 + PRINT_TSTAT_U32(" way_cols", WAY_COLLISIONS);
1555 + PRINT_TSTAT_U32(" drops ", DROPPED_PACKETS);
1556 + PRINT_TSTAT_U32(" marks ", ECN_MARKED_PACKETS);
1557 + PRINT_TSTAT_U32(" ack_drop", ACKS_DROPPED_PACKETS);
1558 + PRINT_TSTAT_U32(" sp_flows", SPARSE_FLOWS);
1559 + PRINT_TSTAT_U32(" bk_flows", BULK_FLOWS);
1560 + PRINT_TSTAT_U32(" un_flows", UNRESPONSIVE_FLOWS);
1561 + PRINT_TSTAT_U32(" max_len ", MAX_SKBLEN);
1562 + PRINT_TSTAT_U32(" quantum ", FLOW_QUANTUM);
1563 +
1564 +#undef GET_STAT
1565 +#undef PRINT_TSTAT
1566 +#undef SPRINT_TSTAT
1567 +#undef PRINT_TSTAT_U32
1568 +#undef PRINT_TSTAT_U64
1569 + }
1570 + return 0;
1571 +}
1572 +
1573 +struct qdisc_util cake_qdisc_util = {
1574 + .id = "cake",
1575 + .parse_qopt = cake_parse_opt,
1576 + .print_qopt = cake_print_opt,
1577 + .print_xstats = cake_print_xstats,
1578 +};