]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/tc/drr.c
network: downgrade log level in conf parsers
[thirdparty/systemd.git] / src / network / tc / drr.c
CommitLineData
f5fc0441
SS
1/* SPDX-License-Identifier: LGPL-2.1+
2 * Copyright © 2020 VMware, Inc. */
3
ad365c5d
YW
4#include <linux/pkt_sched.h>
5
6#include "alloc-util.h"
7#include "conf-parser.h"
f5fc0441 8#include "drr.h"
ad365c5d
YW
9#include "netlink-util.h"
10#include "parse-util.h"
11#include "string-util.h"
f5fc0441
SS
12
13const QDiscVTable drr_vtable = {
14 .object_size = sizeof(DeficitRoundRobinScheduler),
15 .tca_kind = "drr",
16};
ad365c5d
YW
17
18static int drr_class_fill_message(Link *link, TClass *tclass, sd_netlink_message *req) {
19 DeficitRoundRobinSchedulerClass *drr;
20 int r;
21
22 assert(link);
23 assert(tclass);
24 assert(req);
25
26 drr = TCLASS_TO_DRR(tclass);
27
28 r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "drr");
29 if (r < 0)
30 return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m");
31
32 if (drr->quantum > 0) {
33 r = sd_netlink_message_append_u32(req, TCA_DRR_QUANTUM, drr->quantum);
34 if (r < 0)
35 return log_link_error_errno(link, r, "Could not append TCA_DRR_QUANTUM, attribute: %m");
36 }
37
38 r = sd_netlink_message_close_container(req);
39 if (r < 0)
40 return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m");
41
42 return 0;
43}
44
45int config_parse_drr_size(
46 const char *unit,
47 const char *filename,
48 unsigned line,
49 const char *section,
50 unsigned section_line,
51 const char *lvalue,
52 int ltype,
53 const char *rvalue,
54 void *data,
55 void *userdata) {
56
57 _cleanup_(tclass_free_or_set_invalidp) TClass *tclass = NULL;
58 DeficitRoundRobinSchedulerClass *drr;
59 Network *network = data;
60 uint64_t u;
61 int r;
62
63 assert(filename);
64 assert(lvalue);
65 assert(rvalue);
66 assert(data);
67
68 r = tclass_new_static(TCLASS_KIND_DRR, network, filename, section_line, &tclass);
d96edb2c
YW
69 if (r == -ENOMEM)
70 return log_oom();
71 if (r < 0) {
72 log_syntax(unit, LOG_WARNING, filename, line, r,
73 "Failed to create traffic control class, ignoring assignment: %m");
74 return 0;
75 }
ad365c5d
YW
76
77 drr = TCLASS_TO_DRR(tclass);
78
79 if (isempty(rvalue)) {
80 drr->quantum = 0;
81
82 tclass = NULL;
83 return 0;
84 }
85
c03ef420 86 r = parse_size(rvalue, 1024, &u);
ad365c5d 87 if (r < 0) {
d96edb2c 88 log_syntax(unit, LOG_WARNING, filename, line, r,
ad365c5d
YW
89 "Failed to parse '%s=', ignoring assignment: %s",
90 lvalue, rvalue);
91 return 0;
92 }
93 if (u > UINT32_MAX) {
d96edb2c 94 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid '%s=', ignoring assignment: %s",
ad365c5d
YW
95 lvalue, rvalue);
96 return 0;
97 }
98
99 drr->quantum = (uint32_t) u;
100
101 tclass = NULL;
102 return 0;
103}
104
105const TClassVTable drr_tclass_vtable = {
106 .object_size = sizeof(DeficitRoundRobinSchedulerClass),
107 .tca_kind = "drr",
108 .fill_message = drr_class_fill_message,
109};