]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/tc/fq-codel.c
network: downgrade log level in conf parsers
[thirdparty/systemd.git] / src / network / tc / fq-codel.c
CommitLineData
4e5ef149
SS
1/* SPDX-License-Identifier: LGPL-2.1+
2 * Copyright © 2019 VMware, Inc. */
3
4#include <linux/pkt_sched.h>
5
6#include "alloc-util.h"
7#include "conf-parser.h"
8#include "netlink-util.h"
9#include "parse-util.h"
10#include "qdisc.h"
11#include "string-util.h"
c03ef420 12#include "strv.h"
4e5ef149 13
18de0969
YW
14static int fair_queueing_controlled_delay_init(QDisc *qdisc) {
15 FairQueueingControlledDelay *fqcd;
ac810b75
YW
16
17 assert(qdisc);
18
19 fqcd = FQ_CODEL(qdisc);
20
21 fqcd->memory_limit = UINT32_MAX;
22 fqcd->ce_threshold_usec = USEC_INFINITY;
23 fqcd->ecn = -1;
24
25 return 0;
26}
27
18de0969
YW
28static int fair_queueing_controlled_delay_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) {
29 FairQueueingControlledDelay *fqcd;
4e5ef149
SS
30 int r;
31
32 assert(link);
e8c17dc0 33 assert(qdisc);
4e5ef149
SS
34 assert(req);
35
e8c17dc0
YW
36 fqcd = FQ_CODEL(qdisc);
37
92c7593f 38 r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "fq_codel");
4e5ef149
SS
39 if (r < 0)
40 return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m");
41
ac810b75
YW
42 if (fqcd->packet_limit > 0) {
43 r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_LIMIT, fqcd->packet_limit);
44 if (r < 0)
45 return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_LIMIT attribute: %m");
46 }
47
48 if (fqcd->flows > 0) {
49 r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_FLOWS, fqcd->flows);
50 if (r < 0)
51 return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_FLOWS attribute: %m");
52 }
53
54 if (fqcd->quantum > 0) {
55 r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_QUANTUM, fqcd->quantum);
56 if (r < 0)
57 return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_QUANTUM attribute: %m");
58 }
59
60 if (fqcd->interval_usec > 0) {
61 r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_INTERVAL, fqcd->interval_usec);
62 if (r < 0)
63 return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_INTERVAL attribute: %m");
64 }
65
66 if (fqcd->target_usec > 0) {
67 r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_TARGET, fqcd->target_usec);
68 if (r < 0)
69 return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_TARGET attribute: %m");
70 }
71
72 if (fqcd->ecn >= 0) {
73 r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_ECN, fqcd->ecn);
74 if (r < 0)
75 return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_ECN attribute: %m");
76 }
77
78 if (fqcd->ce_threshold_usec != USEC_INFINITY) {
79 r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_CE_THRESHOLD, fqcd->ce_threshold_usec);
80 if (r < 0)
81 return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_CE_THRESHOLD attribute: %m");
82 }
83
84 if (fqcd->memory_limit != UINT32_MAX) {
85 r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_MEMORY_LIMIT, fqcd->memory_limit);
86 if (r < 0)
87 return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_MEMORY_LIMIT attribute: %m");
88 }
4e5ef149
SS
89
90 r = sd_netlink_message_close_container(req);
91 if (r < 0)
92 return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m");
93
94 return 0;
95}
96
18de0969 97int config_parse_fair_queueing_controlled_delay_u32(
4e5ef149
SS
98 const char *unit,
99 const char *filename,
100 unsigned line,
101 const char *section,
102 unsigned section_line,
103 const char *lvalue,
104 int ltype,
105 const char *rvalue,
106 void *data,
107 void *userdata) {
108
109 _cleanup_(qdisc_free_or_set_invalidp) QDisc *qdisc = NULL;
18de0969 110 FairQueueingControlledDelay *fqcd;
4e5ef149 111 Network *network = data;
ac810b75 112 uint32_t *p;
4e5ef149
SS
113 int r;
114
115 assert(filename);
116 assert(lvalue);
117 assert(rvalue);
118 assert(data);
119
e8c17dc0
YW
120 r = qdisc_new_static(QDISC_KIND_FQ_CODEL, network, filename, section_line, &qdisc);
121 if (r == -ENOMEM)
122 return log_oom();
d96edb2c
YW
123 if (r < 0) {
124 log_syntax(unit, LOG_WARNING, filename, line, r,
125 "More than one kind of queueing discipline, ignoring assignment: %m");
126 return 0;
127 }
e8c17dc0
YW
128
129 fqcd = FQ_CODEL(qdisc);
4e5ef149 130
18de0969 131 if (streq(lvalue, "PacketLimit"))
ac810b75 132 p = &fqcd->packet_limit;
18de0969 133 else if (streq(lvalue, "Flows"))
ac810b75
YW
134 p = &fqcd->flows;
135 else
136 assert_not_reached("Invalid lvalue.");
137
4e5ef149 138 if (isempty(rvalue)) {
ac810b75 139 *p = 0;
4e5ef149
SS
140
141 qdisc = NULL;
142 return 0;
143 }
144
ac810b75 145 r = safe_atou32(rvalue, p);
4e5ef149 146 if (r < 0) {
d96edb2c 147 log_syntax(unit, LOG_WARNING, filename, line, r,
4e5ef149
SS
148 "Failed to parse '%s=', ignoring assignment: %s",
149 lvalue, rvalue);
150 return 0;
151 }
152
4e5ef149
SS
153 qdisc = NULL;
154
155 return 0;
156}
e8c17dc0 157
18de0969 158int config_parse_fair_queueing_controlled_delay_usec(
ac810b75
YW
159 const char *unit,
160 const char *filename,
161 unsigned line,
162 const char *section,
163 unsigned section_line,
164 const char *lvalue,
165 int ltype,
166 const char *rvalue,
167 void *data,
168 void *userdata) {
169
170 _cleanup_(qdisc_free_or_set_invalidp) QDisc *qdisc = NULL;
18de0969 171 FairQueueingControlledDelay *fqcd;
ac810b75
YW
172 Network *network = data;
173 usec_t *p;
174 int r;
175
176 assert(filename);
177 assert(lvalue);
178 assert(rvalue);
179 assert(data);
180
181 r = qdisc_new_static(QDISC_KIND_FQ_CODEL, network, filename, section_line, &qdisc);
182 if (r == -ENOMEM)
183 return log_oom();
d96edb2c
YW
184 if (r < 0) {
185 log_syntax(unit, LOG_WARNING, filename, line, r,
186 "More than one kind of queueing discipline, ignoring assignment: %m");
187 return 0;
188 }
ac810b75
YW
189
190 fqcd = FQ_CODEL(qdisc);
191
18de0969 192 if (streq(lvalue, "TargetSec"))
ac810b75 193 p = &fqcd->target_usec;
18de0969 194 else if (streq(lvalue, "IntervalSec"))
ac810b75 195 p = &fqcd->interval_usec;
18de0969 196 else if (streq(lvalue, "CEThresholdSec"))
ac810b75
YW
197 p = &fqcd->ce_threshold_usec;
198 else
199 assert_not_reached("Invalid lvalue.");
200
201 if (isempty(rvalue)) {
18de0969 202 if (streq(lvalue, "CEThresholdSec"))
ac810b75
YW
203 *p = USEC_INFINITY;
204 else
205 *p = 0;
206
207 qdisc = NULL;
208 return 0;
209 }
210
211 r = parse_sec(rvalue, p);
212 if (r < 0) {
d96edb2c 213 log_syntax(unit, LOG_WARNING, filename, line, r,
ac810b75
YW
214 "Failed to parse '%s=', ignoring assignment: %s",
215 lvalue, rvalue);
216 return 0;
217 }
218
219 qdisc = NULL;
220
221 return 0;
222}
223
18de0969 224int config_parse_fair_queueing_controlled_delay_bool(
ac810b75
YW
225 const char *unit,
226 const char *filename,
227 unsigned line,
228 const char *section,
229 unsigned section_line,
230 const char *lvalue,
231 int ltype,
232 const char *rvalue,
233 void *data,
234 void *userdata) {
235
236 _cleanup_(qdisc_free_or_set_invalidp) QDisc *qdisc = NULL;
18de0969 237 FairQueueingControlledDelay *fqcd;
ac810b75
YW
238 Network *network = data;
239 int r;
240
241 assert(filename);
242 assert(lvalue);
243 assert(rvalue);
244 assert(data);
245
246 r = qdisc_new_static(QDISC_KIND_FQ_CODEL, network, filename, section_line, &qdisc);
247 if (r == -ENOMEM)
248 return log_oom();
d96edb2c
YW
249 if (r < 0) {
250 log_syntax(unit, LOG_WARNING, filename, line, r,
251 "More than one kind of queueing discipline, ignoring assignment: %m");
252 return 0;
253 }
ac810b75
YW
254
255 fqcd = FQ_CODEL(qdisc);
256
257 if (isempty(rvalue)) {
258 fqcd->ecn = -1;
259
260 qdisc = NULL;
261 return 0;
262 }
263
264 r = parse_boolean(rvalue);
265 if (r < 0) {
d96edb2c 266 log_syntax(unit, LOG_WARNING, filename, line, r,
ac810b75
YW
267 "Failed to parse '%s=', ignoring assignment: %s",
268 lvalue, rvalue);
269 return 0;
270 }
271
272 fqcd->ecn = r;
273 qdisc = NULL;
274
275 return 0;
276}
277
18de0969 278int config_parse_fair_queueing_controlled_delay_size(
ac810b75
YW
279 const char *unit,
280 const char *filename,
281 unsigned line,
282 const char *section,
283 unsigned section_line,
284 const char *lvalue,
285 int ltype,
286 const char *rvalue,
287 void *data,
288 void *userdata) {
289
290 _cleanup_(qdisc_free_or_set_invalidp) QDisc *qdisc = NULL;
18de0969 291 FairQueueingControlledDelay *fqcd;
ac810b75
YW
292 Network *network = data;
293 uint64_t sz;
294 uint32_t *p;
295 int r;
296
297 assert(filename);
298 assert(lvalue);
299 assert(rvalue);
300 assert(data);
301
302 r = qdisc_new_static(QDISC_KIND_FQ_CODEL, network, filename, section_line, &qdisc);
303 if (r == -ENOMEM)
304 return log_oom();
d96edb2c
YW
305 if (r < 0) {
306 log_syntax(unit, LOG_WARNING, filename, line, r,
307 "More than one kind of queueing discipline, ignoring assignment: %m");
308 return 0;
309 }
ac810b75
YW
310
311 fqcd = FQ_CODEL(qdisc);
312
c03ef420 313 if (STR_IN_SET(lvalue, "MemoryLimitBytes", "MemoryLimit"))
ac810b75 314 p = &fqcd->memory_limit;
c03ef420 315 else if (STR_IN_SET(lvalue, "QuantumBytes", "Quantum"))
ac810b75
YW
316 p = &fqcd->quantum;
317 else
318 assert_not_reached("Invalid lvalue.");
319
320 if (isempty(rvalue)) {
c03ef420 321 if (STR_IN_SET(lvalue, "MemoryLimitBytes", "MemoryLimit"))
ac810b75
YW
322 *p = UINT32_MAX;
323 else
324 *p = 0;
325
326 qdisc = NULL;
327 return 0;
328 }
329
330 r = parse_size(rvalue, 1024, &sz);
331 if (r < 0) {
d96edb2c 332 log_syntax(unit, LOG_WARNING, filename, line, r,
ac810b75
YW
333 "Failed to parse '%s=', ignoring assignment: %s",
334 lvalue, rvalue);
335 return 0;
336 }
337 if (sz >= UINT32_MAX) {
d96edb2c 338 log_syntax(unit, LOG_WARNING, filename, line, 0,
ac810b75
YW
339 "Specified '%s=' is too large, ignoring assignment: %s",
340 lvalue, rvalue);
341 return 0;
342 }
343
344 *p = sz;
345 qdisc = NULL;
346
347 return 0;
348}
349
e8c17dc0 350const QDiscVTable fq_codel_vtable = {
18de0969 351 .object_size = sizeof(FairQueueingControlledDelay),
e8c17dc0 352 .tca_kind = "fq_codel",
18de0969
YW
353 .init = fair_queueing_controlled_delay_init,
354 .fill_message = fair_queueing_controlled_delay_fill_message,
e8c17dc0 355};