1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
/*
* Codel - The Controlled-Delay Active Queue Management algorithm
*
* Copyright (C) 2011-2012 Kathleen Nichols <nichols@pollere.com>
* Copyright (C) 2011-2012 Van Jacobson <van@pollere.com>
* Copyright (C) 2012 Michael D. Taht <dave.taht@bufferbloat.net>
* Copyright (C) 2012,2015 Eric Dumazet <edumazet@google.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* Alternatively, provided that this notice is retained in full, this
* software may be distributed under the terms of the GNU General
* Public License ("GPL") version 2, in which case the provisions of the
* GPL apply INSTEAD OF those given above.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include "utils.h"
#include "tc_util.h"
static void explain(void)
{
fprintf(stderr,
"Usage: ... codel [ limit PACKETS ] [ target TIME ]\n"
" [ interval TIME ] [ ecn | noecn ]\n"
" [ ce_threshold TIME ]\n");
}
static int codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
struct nlmsghdr *n, const char *dev)
{
unsigned int limit = 0;
unsigned int target = 0;
unsigned int interval = 0;
unsigned int ce_threshold = ~0U;
int ecn = -1;
struct rtattr *tail;
while (argc > 0) {
if (strcmp(*argv, "limit") == 0) {
NEXT_ARG();
if (get_unsigned(&limit, *argv, 0)) {
fprintf(stderr, "Illegal \"limit\"\n");
return -1;
}
} else if (strcmp(*argv, "target") == 0) {
NEXT_ARG();
if (get_time(&target, *argv)) {
fprintf(stderr, "Illegal \"target\"\n");
return -1;
}
} else if (strcmp(*argv, "ce_threshold") == 0) {
NEXT_ARG();
if (get_time(&ce_threshold, *argv)) {
fprintf(stderr, "Illegal \"ce_threshold\"\n");
return -1;
}
} else if (strcmp(*argv, "interval") == 0) {
NEXT_ARG();
if (get_time(&interval, *argv)) {
fprintf(stderr, "Illegal \"interval\"\n");
return -1;
}
} else if (strcmp(*argv, "ecn") == 0) {
ecn = 1;
} else if (strcmp(*argv, "noecn") == 0) {
ecn = 0;
} else if (strcmp(*argv, "help") == 0) {
explain();
return -1;
} else {
fprintf(stderr, "What is \"%s\"?\n", *argv);
explain();
return -1;
}
argc--; argv++;
}
tail = addattr_nest(n, 1024, TCA_OPTIONS);
if (limit)
addattr_l(n, 1024, TCA_CODEL_LIMIT, &limit, sizeof(limit));
if (interval)
addattr_l(n, 1024, TCA_CODEL_INTERVAL, &interval, sizeof(interval));
if (target)
addattr_l(n, 1024, TCA_CODEL_TARGET, &target, sizeof(target));
if (ecn != -1)
addattr_l(n, 1024, TCA_CODEL_ECN, &ecn, sizeof(ecn));
if (ce_threshold != ~0U)
addattr_l(n, 1024, TCA_CODEL_CE_THRESHOLD,
&ce_threshold, sizeof(ce_threshold));
addattr_nest_end(n, tail);
return 0;
}
static int codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
struct rtattr *tb[TCA_CODEL_MAX + 1];
unsigned int limit;
unsigned int interval;
unsigned int target;
unsigned int ecn;
unsigned int ce_threshold;
SPRINT_BUF(b1);
if (opt == NULL)
return 0;
parse_rtattr_nested(tb, TCA_CODEL_MAX, opt);
if (tb[TCA_CODEL_LIMIT] &&
RTA_PAYLOAD(tb[TCA_CODEL_LIMIT]) >= sizeof(__u32)) {
limit = rta_getattr_u32(tb[TCA_CODEL_LIMIT]);
print_uint(PRINT_ANY, "limit", "limit %up ", limit);
}
if (tb[TCA_CODEL_TARGET] &&
RTA_PAYLOAD(tb[TCA_CODEL_TARGET]) >= sizeof(__u32)) {
target = rta_getattr_u32(tb[TCA_CODEL_TARGET]);
print_uint(PRINT_JSON, "target", NULL, target);
print_string(PRINT_FP, NULL, "target %s ",
sprint_time(target, b1));
}
if (tb[TCA_CODEL_CE_THRESHOLD] &&
RTA_PAYLOAD(tb[TCA_CODEL_CE_THRESHOLD]) >= sizeof(__u32)) {
ce_threshold = rta_getattr_u32(tb[TCA_CODEL_CE_THRESHOLD]);
print_uint(PRINT_JSON, "ce_threshold", NULL, ce_threshold);
print_string(PRINT_FP, NULL, "ce_threshold %s ",
sprint_time(ce_threshold, b1));
}
if (tb[TCA_CODEL_INTERVAL] &&
RTA_PAYLOAD(tb[TCA_CODEL_INTERVAL]) >= sizeof(__u32)) {
interval = rta_getattr_u32(tb[TCA_CODEL_INTERVAL]);
print_uint(PRINT_JSON, "interval", NULL, interval);
print_string(PRINT_FP, NULL, "interval %s ",
sprint_time(interval, b1));
}
if (tb[TCA_CODEL_ECN] &&
RTA_PAYLOAD(tb[TCA_CODEL_ECN]) >= sizeof(__u32)) {
ecn = rta_getattr_u32(tb[TCA_CODEL_ECN]);
if (ecn)
print_bool(PRINT_ANY, "ecn", "ecn ", true);
}
return 0;
}
static int codel_print_xstats(struct qdisc_util *qu, FILE *f,
struct rtattr *xstats)
{
struct tc_codel_xstats _st = {}, *st;
SPRINT_BUF(b1);
if (xstats == NULL)
return 0;
st = RTA_DATA(xstats);
if (RTA_PAYLOAD(xstats) < sizeof(*st)) {
memcpy(&_st, st, RTA_PAYLOAD(xstats));
st = &_st;
}
print_uint(PRINT_ANY, "count", " count %u", st->count);
print_uint(PRINT_ANY, "lastcount", " lastcount %u", st->lastcount);
print_uint(PRINT_JSON, "ldelay", NULL, st->ldelay);
print_string(PRINT_FP, NULL, " ldelay %s", sprint_time(st->ldelay, b1));
if (st->dropping)
print_bool(PRINT_ANY, "dropping", " dropping", true);
print_int(PRINT_JSON, "drop_next", NULL, st->drop_next);
if (st->drop_next < 0)
print_string(PRINT_FP, NULL, " drop_next -%s",
sprint_time(-st->drop_next, b1));
else
print_string(PRINT_FP, NULL, " drop_next %s",
sprint_time(st->drop_next, b1));
print_nl();
print_uint(PRINT_ANY, "maxpacket", " maxpacket %u", st->maxpacket);
print_uint(PRINT_ANY, "ecn_mark", " ecn_mark %u", st->ecn_mark);
print_uint(PRINT_ANY, "drop_overlimit", " drop_overlimit %u",
st->drop_overlimit);
if (st->ce_mark)
print_uint(PRINT_ANY, "ce_mark", " ce_mark %u", st->ce_mark);
return 0;
}
struct qdisc_util codel_qdisc_util = {
.id = "codel",
.parse_qopt = codel_parse_opt,
.print_qopt = codel_print_opt,
.print_xstats = codel_print_xstats,
};
|