]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later |
f5fc0441 SS |
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 | |
13 | const QDiscVTable drr_vtable = { | |
14 | .object_size = sizeof(DeficitRoundRobinScheduler), | |
15 | .tca_kind = "drr", | |
16 | }; | |
ad365c5d YW |
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 | ||
16924f54 | 26 | assert_se(drr = TCLASS_TO_DRR(tclass)); |
ad365c5d YW |
27 | |
28 | r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "drr"); | |
29 | if (r < 0) | |
16924f54 | 30 | return r; |
ad365c5d YW |
31 | |
32 | if (drr->quantum > 0) { | |
33 | r = sd_netlink_message_append_u32(req, TCA_DRR_QUANTUM, drr->quantum); | |
34 | if (r < 0) | |
16924f54 | 35 | return r; |
ad365c5d YW |
36 | } |
37 | ||
38 | r = sd_netlink_message_close_container(req); | |
39 | if (r < 0) | |
16924f54 | 40 | return r; |
ad365c5d YW |
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; | |
99534007 | 59 | Network *network = ASSERT_PTR(data); |
ad365c5d YW |
60 | uint64_t u; |
61 | int r; | |
62 | ||
63 | assert(filename); | |
64 | assert(lvalue); | |
65 | assert(rvalue); | |
ad365c5d YW |
66 | |
67 | r = tclass_new_static(TCLASS_KIND_DRR, network, filename, section_line, &tclass); | |
d96edb2c YW |
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 | } | |
ad365c5d YW |
75 | |
76 | drr = TCLASS_TO_DRR(tclass); | |
77 | ||
78 | if (isempty(rvalue)) { | |
79 | drr->quantum = 0; | |
80 | ||
0132453c | 81 | TAKE_PTR(tclass); |
ad365c5d YW |
82 | return 0; |
83 | } | |
84 | ||
c03ef420 | 85 | r = parse_size(rvalue, 1024, &u); |
ad365c5d | 86 | if (r < 0) { |
d96edb2c | 87 | log_syntax(unit, LOG_WARNING, filename, line, r, |
ad365c5d YW |
88 | "Failed to parse '%s=', ignoring assignment: %s", |
89 | lvalue, rvalue); | |
90 | return 0; | |
91 | } | |
92 | if (u > UINT32_MAX) { | |
d96edb2c | 93 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid '%s=', ignoring assignment: %s", |
ad365c5d YW |
94 | lvalue, rvalue); |
95 | return 0; | |
96 | } | |
97 | ||
98 | drr->quantum = (uint32_t) u; | |
99 | ||
0132453c | 100 | TAKE_PTR(tclass); |
ad365c5d YW |
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 | }; |