]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/tc/gred.c
network: downgrade log level in conf parsers
[thirdparty/systemd.git] / src / network / tc / gred.c
CommitLineData
609e8340
SS
1/* SPDX-License-Identifier: LGPL-2.1+
2 * Copyright © 2020 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"
12
13static int generic_random_early_detection_init(QDisc *qdisc) {
14 GenericRandomEarlyDetection *gred;
15
16 assert(qdisc);
17
18 gred = GRED(qdisc);
19
20 gred->grio = -1;
21
22 return 0;
23}
24
25static int generic_random_early_detection_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) {
26 GenericRandomEarlyDetection *gred;
27 struct tc_gred_sopt opt = {};
28 int r;
29
30 assert(link);
31 assert(qdisc);
32 assert(req);
33
34 gred = GRED(qdisc);
35
36 opt.DPs = gred->virtual_queues;
37 opt.def_DP = gred->default_virtual_queue;
38
39 if (gred->grio >= 0)
40 opt.grio = gred->grio;
41
42 r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "gred");
43 if (r < 0)
44 return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m");
45
46 r = sd_netlink_message_append_data(req, TCA_GRED_DPS, &opt, sizeof(struct tc_gred_sopt));
47 if (r < 0)
48 return log_link_error_errno(link, r, "Could not append TCA_GRED_DPS attribute: %m");
49
50 r = sd_netlink_message_close_container(req);
51 if (r < 0)
52 return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m");
53
54 return 0;
55}
56
57static int generic_random_early_detection_verify(QDisc *qdisc) {
58 GenericRandomEarlyDetection *gred = GRED(qdisc);
59
60 if (gred->default_virtual_queue >= gred->virtual_queues)
61 return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
62 "%s: DefaultVirtualQueue= must be less than VirtualQueues=. "
63 "Ignoring [GenericRandomEarlyDetection] section from line %u.",
64 qdisc->section->filename, qdisc->section->line);
65
66 return 0;
67}
68
69int config_parse_generic_random_early_detection_u32(
70 const char *unit,
71 const char *filename,
72 unsigned line,
73 const char *section,
74 unsigned section_line,
75 const char *lvalue,
76 int ltype,
77 const char *rvalue,
78 void *data,
79 void *userdata) {
80
81 _cleanup_(qdisc_free_or_set_invalidp) QDisc *qdisc = NULL;
82 GenericRandomEarlyDetection *gred;
83 Network *network = data;
84 uint32_t *p;
85 uint32_t v;
86 int r;
87
88 assert(filename);
89 assert(lvalue);
90 assert(rvalue);
91 assert(data);
92
93 r = qdisc_new_static(QDISC_KIND_GRED, network, filename, section_line, &qdisc);
94 if (r == -ENOMEM)
95 return log_oom();
d96edb2c
YW
96 if (r < 0) {
97 log_syntax(unit, LOG_WARNING, filename, line, r,
98 "More than one kind of queueing discipline, ignoring assignment: %m");
99 return 0;
100 }
609e8340
SS
101
102 gred = GRED(qdisc);
103
104 if (streq(lvalue, "VirtualQueues"))
105 p = &gred->virtual_queues;
106 else if (streq(lvalue, "DefaultVirtualQueue"))
107 p = &gred->default_virtual_queue;
108 else
109 assert_not_reached("Invalid lvalue.");
110
111 if (isempty(rvalue)) {
112 *p = 0;
113
114 qdisc = NULL;
115 return 0;
116 }
117
118 r = safe_atou32(rvalue, &v);
119 if (r < 0) {
d96edb2c 120 log_syntax(unit, LOG_WARNING, filename, line, r,
609e8340
SS
121 "Failed to parse '%s=', ignoring assignment: %s",
122 lvalue, rvalue);
123 return 0;
124 }
125
126 if (v > MAX_DPs) {
d96edb2c 127 log_syntax(unit, LOG_WARNING, filename, line, 0,
609e8340
SS
128 "Invalid '%s=', ignoring assignment: %s",
129 lvalue, rvalue);
130 }
131
132 *p = v;
133 qdisc = NULL;
134
135 return 0;
136}
137int config_parse_generic_random_early_detection_bool(
138 const char *unit,
139 const char *filename,
140 unsigned line,
141 const char *section,
142 unsigned section_line,
143 const char *lvalue,
144 int ltype,
145 const char *rvalue,
146 void *data,
147 void *userdata) {
148
149 _cleanup_(qdisc_free_or_set_invalidp) QDisc *qdisc = NULL;
150 GenericRandomEarlyDetection *gred;
151 Network *network = data;
152 int r;
153
154 assert(filename);
155 assert(lvalue);
156 assert(rvalue);
157 assert(data);
158
159 r = qdisc_new_static(QDISC_KIND_GRED, network, filename, section_line, &qdisc);
160 if (r == -ENOMEM)
161 return log_oom();
d96edb2c
YW
162 if (r < 0) {
163 log_syntax(unit, LOG_WARNING, filename, line, r,
164 "More than one kind of queueing discipline, ignoring assignment: %m");
165 return 0;
166 }
609e8340
SS
167
168 gred = GRED(qdisc);
169
170 if (isempty(rvalue)) {
171 gred->grio = -1;
172
173 qdisc = NULL;
174 return 0;
175 }
176
177 r = parse_boolean(rvalue);
178 if (r < 0) {
d96edb2c 179 log_syntax(unit, LOG_WARNING, filename, line, r,
609e8340
SS
180 "Failed to parse '%s=', ignoring assignment: %s",
181 lvalue, rvalue);
182 return 0;
183 }
184
185 gred->grio = r;
186 qdisc = NULL;
187
188 return 0;
189}
190
191const QDiscVTable gred_vtable = {
192 .object_size = sizeof(GenericRandomEarlyDetection),
193 .tca_kind = "gred",
194 .init = generic_random_early_detection_init,
195 .fill_message = generic_random_early_detection_fill_message,
196 .verify = generic_random_early_detection_verify,
197};