4 * Copyright (C) 2012,2015 Eric Dumazet <edumazet@google.com>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The names of the authors may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * Alternatively, provided that this notice is retained in full, this
19 * software may be distributed under the terms of the GNU General
20 * Public License ("GPL") version 2, in which case the provisions of the
21 * GPL apply INSTEAD OF those given above.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
42 #include <sys/socket.h>
43 #include <netinet/in.h>
44 #include <arpa/inet.h>
50 static void explain(void)
52 fprintf(stderr
, "Usage: ... fq_codel [ limit PACKETS ] [ flows NUMBER ]\n");
53 fprintf(stderr
, " [ target TIME ] [ interval TIME ]\n");
54 fprintf(stderr
, " [ quantum BYTES ] [ [no]ecn ]\n");
55 fprintf(stderr
, " [ ce_threshold TIME ]\n");
58 static int fq_codel_parse_opt(struct qdisc_util
*qu
, int argc
, char **argv
,
59 struct nlmsghdr
*n
, const char *dev
)
61 unsigned int limit
= 0;
62 unsigned int flows
= 0;
63 unsigned int target
= 0;
64 unsigned int interval
= 0;
65 unsigned int quantum
= 0;
66 unsigned int ce_threshold
= ~0U;
67 unsigned int memory
= ~0U;
72 if (strcmp(*argv
, "limit") == 0) {
74 if (get_unsigned(&limit
, *argv
, 0)) {
75 fprintf(stderr
, "Illegal \"limit\"\n");
78 } else if (strcmp(*argv
, "flows") == 0) {
80 if (get_unsigned(&flows
, *argv
, 0)) {
81 fprintf(stderr
, "Illegal \"flows\"\n");
84 } else if (strcmp(*argv
, "quantum") == 0) {
86 if (get_unsigned(&quantum
, *argv
, 0)) {
87 fprintf(stderr
, "Illegal \"quantum\"\n");
90 } else if (strcmp(*argv
, "target") == 0) {
92 if (get_time(&target
, *argv
)) {
93 fprintf(stderr
, "Illegal \"target\"\n");
96 } else if (strcmp(*argv
, "ce_threshold") == 0) {
98 if (get_time(&ce_threshold
, *argv
)) {
99 fprintf(stderr
, "Illegal \"ce_threshold\"\n");
102 } else if (strcmp(*argv
, "memory_limit") == 0) {
104 if (get_size(&memory
, *argv
)) {
105 fprintf(stderr
, "Illegal \"memory_limit\"\n");
108 } else if (strcmp(*argv
, "interval") == 0) {
110 if (get_time(&interval
, *argv
)) {
111 fprintf(stderr
, "Illegal \"interval\"\n");
114 } else if (strcmp(*argv
, "ecn") == 0) {
116 } else if (strcmp(*argv
, "noecn") == 0) {
118 } else if (strcmp(*argv
, "help") == 0) {
122 fprintf(stderr
, "What is \"%s\"?\n", *argv
);
129 tail
= addattr_nest(n
, 1024, TCA_OPTIONS
);
131 addattr_l(n
, 1024, TCA_FQ_CODEL_LIMIT
, &limit
, sizeof(limit
));
133 addattr_l(n
, 1024, TCA_FQ_CODEL_FLOWS
, &flows
, sizeof(flows
));
135 addattr_l(n
, 1024, TCA_FQ_CODEL_QUANTUM
, &quantum
, sizeof(quantum
));
137 addattr_l(n
, 1024, TCA_FQ_CODEL_INTERVAL
, &interval
, sizeof(interval
));
139 addattr_l(n
, 1024, TCA_FQ_CODEL_TARGET
, &target
, sizeof(target
));
141 addattr_l(n
, 1024, TCA_FQ_CODEL_ECN
, &ecn
, sizeof(ecn
));
142 if (ce_threshold
!= ~0U)
143 addattr_l(n
, 1024, TCA_FQ_CODEL_CE_THRESHOLD
,
144 &ce_threshold
, sizeof(ce_threshold
));
146 addattr_l(n
, 1024, TCA_FQ_CODEL_MEMORY_LIMIT
,
147 &memory
, sizeof(memory
));
149 addattr_nest_end(n
, tail
);
153 static int fq_codel_print_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
155 struct rtattr
*tb
[TCA_FQ_CODEL_MAX
+ 1];
158 unsigned int interval
;
161 unsigned int quantum
;
162 unsigned int ce_threshold
;
163 unsigned int memory_limit
;
170 parse_rtattr_nested(tb
, TCA_FQ_CODEL_MAX
, opt
);
172 if (tb
[TCA_FQ_CODEL_LIMIT
] &&
173 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_LIMIT
]) >= sizeof(__u32
)) {
174 limit
= rta_getattr_u32(tb
[TCA_FQ_CODEL_LIMIT
]);
175 print_uint(PRINT_ANY
, "limit", "limit %up ", limit
);
177 if (tb
[TCA_FQ_CODEL_FLOWS
] &&
178 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_FLOWS
]) >= sizeof(__u32
)) {
179 flows
= rta_getattr_u32(tb
[TCA_FQ_CODEL_FLOWS
]);
180 print_uint(PRINT_ANY
, "flows", "flows %u ", flows
);
182 if (tb
[TCA_FQ_CODEL_QUANTUM
] &&
183 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_QUANTUM
]) >= sizeof(__u32
)) {
184 quantum
= rta_getattr_u32(tb
[TCA_FQ_CODEL_QUANTUM
]);
185 print_uint(PRINT_ANY
, "quantum", "quantum %u ", quantum
);
187 if (tb
[TCA_FQ_CODEL_TARGET
] &&
188 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_TARGET
]) >= sizeof(__u32
)) {
189 target
= rta_getattr_u32(tb
[TCA_FQ_CODEL_TARGET
]);
190 print_uint(PRINT_JSON
, "target", NULL
, target
);
191 print_string(PRINT_FP
, NULL
, "target %s ",
192 sprint_time(target
, b1
));
194 if (tb
[TCA_FQ_CODEL_CE_THRESHOLD
] &&
195 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_CE_THRESHOLD
]) >= sizeof(__u32
)) {
196 ce_threshold
= rta_getattr_u32(tb
[TCA_FQ_CODEL_CE_THRESHOLD
]);
197 print_uint(PRINT_JSON
, "ce_threshold", NULL
, ce_threshold
);
198 print_string(PRINT_FP
, NULL
, "ce_threshold %s ",
199 sprint_time(ce_threshold
, b1
));
201 if (tb
[TCA_FQ_CODEL_INTERVAL
] &&
202 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_INTERVAL
]) >= sizeof(__u32
)) {
203 interval
= rta_getattr_u32(tb
[TCA_FQ_CODEL_INTERVAL
]);
204 print_uint(PRINT_JSON
, "interval", NULL
, interval
);
205 print_string(PRINT_FP
, NULL
, "interval %s ",
206 sprint_time(interval
, b1
));
208 if (tb
[TCA_FQ_CODEL_MEMORY_LIMIT
] &&
209 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_MEMORY_LIMIT
]) >= sizeof(__u32
)) {
210 memory_limit
= rta_getattr_u32(tb
[TCA_FQ_CODEL_MEMORY_LIMIT
]);
211 print_uint(PRINT_JSON
, "memory_limit", NULL
, memory_limit
);
212 print_string(PRINT_FP
, NULL
, "memory_limit %s ",
213 sprint_size(memory_limit
, b1
));
215 if (tb
[TCA_FQ_CODEL_ECN
] &&
216 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_ECN
]) >= sizeof(__u32
)) {
217 ecn
= rta_getattr_u32(tb
[TCA_FQ_CODEL_ECN
]);
219 print_bool(PRINT_ANY
, "ecn", "ecn ", true);
225 static int fq_codel_print_xstats(struct qdisc_util
*qu
, FILE *f
,
226 struct rtattr
*xstats
)
228 struct tc_fq_codel_xstats _st
= {}, *st
;
235 st
= RTA_DATA(xstats
);
236 if (RTA_PAYLOAD(xstats
) < sizeof(*st
)) {
237 memcpy(&_st
, st
, RTA_PAYLOAD(xstats
));
240 if (st
->type
== TCA_FQ_CODEL_XSTATS_QDISC
) {
241 fprintf(f
, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u",
242 st
->qdisc_stats
.maxpacket
,
243 st
->qdisc_stats
.drop_overlimit
,
244 st
->qdisc_stats
.new_flow_count
,
245 st
->qdisc_stats
.ecn_mark
);
246 if (st
->qdisc_stats
.ce_mark
)
247 fprintf(f
, " ce_mark %u", st
->qdisc_stats
.ce_mark
);
248 if (st
->qdisc_stats
.memory_usage
)
249 fprintf(f
, " memory_used %u", st
->qdisc_stats
.memory_usage
);
250 if (st
->qdisc_stats
.drop_overmemory
)
251 fprintf(f
, " drop_overmemory %u", st
->qdisc_stats
.drop_overmemory
);
252 fprintf(f
, "\n new_flows_len %u old_flows_len %u",
253 st
->qdisc_stats
.new_flows_len
,
254 st
->qdisc_stats
.old_flows_len
);
256 if (st
->type
== TCA_FQ_CODEL_XSTATS_CLASS
) {
257 fprintf(f
, " deficit %d count %u lastcount %u ldelay %s",
258 st
->class_stats
.deficit
,
259 st
->class_stats
.count
,
260 st
->class_stats
.lastcount
,
261 sprint_time(st
->class_stats
.ldelay
, b1
));
262 if (st
->class_stats
.dropping
) {
263 fprintf(f
, " dropping");
264 if (st
->class_stats
.drop_next
< 0)
265 fprintf(f
, " drop_next -%s",
266 sprint_time(-st
->class_stats
.drop_next
, b1
));
268 fprintf(f
, " drop_next %s",
269 sprint_time(st
->class_stats
.drop_next
, b1
));
276 struct qdisc_util fq_codel_qdisc_util
= {
278 .parse_qopt
= fq_codel_parse_opt
,
279 .print_qopt
= fq_codel_print_opt
,
280 .print_xstats
= fq_codel_print_xstats
,