]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/tc/drr.c
tree-wide: use ASSERT_PTR more
[thirdparty/systemd.git] / src / network / tc / drr.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later
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 "drr.h"
9 #include "netlink-util.h"
10 #include "parse-util.h"
11 #include "string-util.h"
12
13 const QDiscVTable drr_vtable = {
14 .object_size = sizeof(DeficitRoundRobinScheduler),
15 .tca_kind = "drr",
16 };
17
18 static 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 assert_se(drr = TCLASS_TO_DRR(tclass));
27
28 r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "drr");
29 if (r < 0)
30 return r;
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 r;
36 }
37
38 r = sd_netlink_message_close_container(req);
39 if (r < 0)
40 return r;
41
42 return 0;
43 }
44
45 int 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 = ASSERT_PTR(data);
60 uint64_t u;
61 int r;
62
63 assert(filename);
64 assert(lvalue);
65 assert(rvalue);
66
67 r = tclass_new_static(TCLASS_KIND_DRR, network, filename, section_line, &tclass);
68 if (r == -ENOMEM)
69 return log_oom();
70 if (r < 0) {
71 log_syntax(unit, LOG_WARNING, filename, line, r,
72 "Failed to create traffic control class, ignoring assignment: %m");
73 return 0;
74 }
75
76 drr = TCLASS_TO_DRR(tclass);
77
78 if (isempty(rvalue)) {
79 drr->quantum = 0;
80
81 TAKE_PTR(tclass);
82 return 0;
83 }
84
85 r = parse_size(rvalue, 1024, &u);
86 if (r < 0) {
87 log_syntax(unit, LOG_WARNING, filename, line, r,
88 "Failed to parse '%s=', ignoring assignment: %s",
89 lvalue, rvalue);
90 return 0;
91 }
92 if (u > UINT32_MAX) {
93 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid '%s=', ignoring assignment: %s",
94 lvalue, rvalue);
95 return 0;
96 }
97
98 drr->quantum = (uint32_t) u;
99
100 TAKE_PTR(tclass);
101 return 0;
102 }
103
104 const TClassVTable drr_tclass_vtable = {
105 .object_size = sizeof(DeficitRoundRobinSchedulerClass),
106 .tca_kind = "drr",
107 .fill_message = drr_class_fill_message,
108 };