]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later |
bde4ae88 SS |
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 "pie.h" | |
9 | #include "netlink-util.h" | |
10 | #include "parse-util.h" | |
11 | #include "string-util.h" | |
12 | ||
13 | static int pie_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { | |
ff60129b | 14 | ProportionalIntegralControllerEnhanced *pie; |
bde4ae88 SS |
15 | int r; |
16 | ||
17 | assert(link); | |
18 | assert(qdisc); | |
19 | assert(req); | |
20 | ||
16924f54 | 21 | assert_se(pie = PIE(qdisc)); |
bde4ae88 SS |
22 | |
23 | r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "pie"); | |
24 | if (r < 0) | |
16924f54 | 25 | return r; |
bde4ae88 SS |
26 | |
27 | if (pie->packet_limit > 0) { | |
28 | r = sd_netlink_message_append_u32(req, TCA_PIE_LIMIT, pie->packet_limit); | |
29 | if (r < 0) | |
16924f54 | 30 | return r; |
bde4ae88 SS |
31 | } |
32 | ||
33 | r = sd_netlink_message_close_container(req); | |
34 | if (r < 0) | |
16924f54 | 35 | return r; |
bde4ae88 SS |
36 | |
37 | return 0; | |
38 | } | |
39 | ||
40 | int config_parse_pie_packet_limit( | |
41 | const char *unit, | |
42 | const char *filename, | |
43 | unsigned line, | |
44 | const char *section, | |
45 | unsigned section_line, | |
46 | const char *lvalue, | |
47 | int ltype, | |
48 | const char *rvalue, | |
49 | void *data, | |
50 | void *userdata) { | |
51 | ||
52 | _cleanup_(qdisc_free_or_set_invalidp) QDisc *qdisc = NULL; | |
ff60129b | 53 | ProportionalIntegralControllerEnhanced *pie; |
99534007 | 54 | Network *network = ASSERT_PTR(data); |
bde4ae88 SS |
55 | int r; |
56 | ||
57 | assert(filename); | |
58 | assert(lvalue); | |
59 | assert(rvalue); | |
bde4ae88 SS |
60 | |
61 | r = qdisc_new_static(QDISC_KIND_PIE, network, filename, section_line, &qdisc); | |
62 | if (r == -ENOMEM) | |
63 | return log_oom(); | |
d96edb2c YW |
64 | if (r < 0) { |
65 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
66 | "More than one kind of queueing discipline, ignoring assignment: %m"); | |
67 | return 0; | |
68 | } | |
bde4ae88 SS |
69 | |
70 | pie = PIE(qdisc); | |
71 | ||
72 | if (isempty(rvalue)) { | |
73 | pie->packet_limit = 0; | |
74 | ||
0132453c | 75 | TAKE_PTR(qdisc); |
bde4ae88 SS |
76 | return 0; |
77 | } | |
78 | ||
79 | r = safe_atou32(rvalue, &pie->packet_limit); | |
80 | if (r < 0) { | |
d96edb2c | 81 | log_syntax(unit, LOG_WARNING, filename, line, r, |
bde4ae88 SS |
82 | "Failed to parse '%s=', ignoring assignment: %s", |
83 | lvalue, rvalue); | |
84 | return 0; | |
85 | } | |
86 | ||
0132453c | 87 | TAKE_PTR(qdisc); |
bde4ae88 SS |
88 | |
89 | return 0; | |
90 | } | |
91 | ||
92 | const QDiscVTable pie_vtable = { | |
ff60129b | 93 | .object_size = sizeof(ProportionalIntegralControllerEnhanced), |
bde4ae88 SS |
94 | .tca_kind = "pie", |
95 | .fill_message = pie_fill_message, | |
96 | }; |