4 * Copyright (C) 2012 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
43 #include <sys/socket.h>
44 #include <netinet/in.h>
45 #include <arpa/inet.h>
51 static void explain(void)
53 fprintf(stderr
, "Usage: ... fq_codel [ limit PACKETS ] [ flows NUMBER ]\n");
54 fprintf(stderr
, " [ target TIME] [ interval TIME ]\n");
55 fprintf(stderr
, " [ quantum BYTES ] [ [no]ecn ]\n");
58 static int fq_codel_parse_opt(struct qdisc_util
*qu
, int argc
, char **argv
,
64 unsigned interval
= 0;
70 if (strcmp(*argv
, "limit") == 0) {
72 if (get_unsigned(&limit
, *argv
, 0)) {
73 fprintf(stderr
, "Illegal \"limit\"\n");
76 } else if (strcmp(*argv
, "flows") == 0) {
78 if (get_unsigned(&flows
, *argv
, 0)) {
79 fprintf(stderr
, "Illegal \"flows\"\n");
82 } else if (strcmp(*argv
, "quantum") == 0) {
84 if (get_unsigned(&quantum
, *argv
, 0)) {
85 fprintf(stderr
, "Illegal \"quantum\"\n");
88 } else if (strcmp(*argv
, "target") == 0) {
90 if (get_time(&target
, *argv
)) {
91 fprintf(stderr
, "Illegal \"target\"\n");
94 } else if (strcmp(*argv
, "interval") == 0) {
96 if (get_time(&interval
, *argv
)) {
97 fprintf(stderr
, "Illegal \"interval\"\n");
100 } else if (strcmp(*argv
, "ecn") == 0) {
102 } else if (strcmp(*argv
, "noecn") == 0) {
104 } else if (strcmp(*argv
, "help") == 0) {
108 fprintf(stderr
, "What is \"%s\"?\n", *argv
);
115 tail
= NLMSG_TAIL(n
);
116 addattr_l(n
, 1024, TCA_OPTIONS
, NULL
, 0);
118 addattr_l(n
, 1024, TCA_FQ_CODEL_LIMIT
, &limit
, sizeof(limit
));
120 addattr_l(n
, 1024, TCA_FQ_CODEL_FLOWS
, &flows
, sizeof(flows
));
122 addattr_l(n
, 1024, TCA_FQ_CODEL_QUANTUM
, &quantum
, sizeof(quantum
));
124 addattr_l(n
, 1024, TCA_FQ_CODEL_INTERVAL
, &interval
, sizeof(interval
));
126 addattr_l(n
, 1024, TCA_FQ_CODEL_TARGET
, &target
, sizeof(target
));
128 addattr_l(n
, 1024, TCA_FQ_CODEL_ECN
, &ecn
, sizeof(ecn
));
129 tail
->rta_len
= (void *) NLMSG_TAIL(n
) - (void *) tail
;
133 static int fq_codel_print_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
135 struct rtattr
*tb
[TCA_FQ_CODEL_MAX
+ 1];
147 parse_rtattr_nested(tb
, TCA_FQ_CODEL_MAX
, opt
);
149 if (tb
[TCA_FQ_CODEL_LIMIT
] &&
150 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_LIMIT
]) >= sizeof(__u32
)) {
151 limit
= rta_getattr_u32(tb
[TCA_FQ_CODEL_LIMIT
]);
152 fprintf(f
, "limit %up ", limit
);
154 if (tb
[TCA_FQ_CODEL_FLOWS
] &&
155 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_FLOWS
]) >= sizeof(__u32
)) {
156 flows
= rta_getattr_u32(tb
[TCA_FQ_CODEL_FLOWS
]);
157 fprintf(f
, "flows %u ", flows
);
159 if (tb
[TCA_FQ_CODEL_QUANTUM
] &&
160 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_QUANTUM
]) >= sizeof(__u32
)) {
161 quantum
= rta_getattr_u32(tb
[TCA_FQ_CODEL_QUANTUM
]);
162 fprintf(f
, "quantum %u ", quantum
);
164 if (tb
[TCA_FQ_CODEL_TARGET
] &&
165 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_TARGET
]) >= sizeof(__u32
)) {
166 target
= rta_getattr_u32(tb
[TCA_FQ_CODEL_TARGET
]);
167 fprintf(f
, "target %s ", sprint_time(target
, b1
));
169 if (tb
[TCA_FQ_CODEL_INTERVAL
] &&
170 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_INTERVAL
]) >= sizeof(__u32
)) {
171 interval
= rta_getattr_u32(tb
[TCA_FQ_CODEL_INTERVAL
]);
172 fprintf(f
, "interval %s ", sprint_time(interval
, b1
));
174 if (tb
[TCA_FQ_CODEL_ECN
] &&
175 RTA_PAYLOAD(tb
[TCA_FQ_CODEL_ECN
]) >= sizeof(__u32
)) {
176 ecn
= rta_getattr_u32(tb
[TCA_FQ_CODEL_ECN
]);
184 static int fq_codel_print_xstats(struct qdisc_util
*qu
, FILE *f
,
185 struct rtattr
*xstats
)
187 struct tc_fq_codel_xstats
*st
;
193 if (RTA_PAYLOAD(xstats
) < sizeof(*st
))
196 st
= RTA_DATA(xstats
);
197 if (st
->type
== TCA_FQ_CODEL_XSTATS_QDISC
) {
198 fprintf(f
, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u",
199 st
->qdisc_stats
.maxpacket
,
200 st
->qdisc_stats
.drop_overlimit
,
201 st
->qdisc_stats
.new_flow_count
,
202 st
->qdisc_stats
.ecn_mark
);
203 fprintf(f
, "\n new_flows_len %u old_flows_len %u",
204 st
->qdisc_stats
.new_flows_len
,
205 st
->qdisc_stats
.old_flows_len
);
207 if (st
->type
== TCA_FQ_CODEL_XSTATS_CLASS
) {
208 fprintf(f
, " deficit %d count %u lastcount %u ldelay %s",
209 st
->class_stats
.deficit
,
210 st
->class_stats
.count
,
211 st
->class_stats
.lastcount
,
212 sprint_time(st
->class_stats
.ldelay
, b1
));
213 if (st
->class_stats
.dropping
) {
214 fprintf(f
, " dropping");
215 if (st
->class_stats
.drop_next
< 0)
216 fprintf(f
, " drop_next -%s",
217 sprint_time(-st
->class_stats
.drop_next
, b1
));
219 fprintf(f
, " drop_next %s",
220 sprint_time(st
->class_stats
.drop_next
, b1
));
227 struct qdisc_util fq_codel_qdisc_util
= {
229 .parse_qopt
= fq_codel_parse_opt
,
230 .print_qopt
= fq_codel_print_opt
,
231 .print_xstats
= fq_codel_print_xstats
,