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