]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later |
8f6b6d70 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 "fq-pie.h" | |
9 | #include "netlink-util.h" | |
10 | #include "parse-util.h" | |
11 | #include "string-util.h" | |
12 | ||
13 | static int fq_pie_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { | |
14 | FlowQueuePIE *fq_pie; | |
15 | int r; | |
16 | ||
17 | assert(link); | |
18 | assert(qdisc); | |
19 | assert(req); | |
20 | ||
16924f54 | 21 | assert_se(fq_pie = FQ_PIE(qdisc)); |
8f6b6d70 SS |
22 | |
23 | r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "fq_pie"); | |
24 | if (r < 0) | |
16924f54 | 25 | return r; |
8f6b6d70 SS |
26 | |
27 | if (fq_pie->packet_limit > 0) { | |
28 | r = sd_netlink_message_append_u32(req, TCA_FQ_PIE_LIMIT, fq_pie->packet_limit); | |
29 | if (r < 0) | |
16924f54 | 30 | return r; |
8f6b6d70 SS |
31 | } |
32 | ||
33 | r = sd_netlink_message_close_container(req); | |
34 | if (r < 0) | |
16924f54 | 35 | return r; |
8f6b6d70 SS |
36 | |
37 | return 0; | |
38 | } | |
39 | ||
40 | int config_parse_fq_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; | |
53 | FlowQueuePIE *fq_pie; | |
99534007 | 54 | Network *network = ASSERT_PTR(data); |
fdeecf7b | 55 | uint32_t val; |
8f6b6d70 SS |
56 | int r; |
57 | ||
58 | assert(filename); | |
59 | assert(lvalue); | |
60 | assert(rvalue); | |
8f6b6d70 SS |
61 | |
62 | r = qdisc_new_static(QDISC_KIND_FQ_PIE, network, filename, section_line, &qdisc); | |
63 | if (r == -ENOMEM) | |
64 | return log_oom(); | |
65 | if (r < 0) | |
66 | return log_syntax(unit, LOG_WARNING, filename, line, r, | |
67 | "More than one kind of queueing discipline, ignoring assignment: %m"); | |
68 | ||
69 | fq_pie = FQ_PIE(qdisc); | |
70 | ||
71 | if (isempty(rvalue)) { | |
72 | fq_pie->packet_limit = 0; | |
73 | ||
74 | qdisc = NULL; | |
75 | return 0; | |
76 | } | |
77 | ||
fdeecf7b | 78 | r = safe_atou32(rvalue, &val); |
8f6b6d70 SS |
79 | if (r < 0) { |
80 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
81 | "Failed to parse '%s=', ignoring assignment: %s", | |
82 | lvalue, rvalue); | |
83 | return 0; | |
84 | } | |
fdeecf7b YW |
85 | if (val == 0) { |
86 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
87 | "Invalid '%s=', ignoring assignment: %s", | |
88 | lvalue, rvalue); | |
89 | return 0; | |
90 | } | |
8f6b6d70 | 91 | |
fdeecf7b | 92 | fq_pie->packet_limit = val; |
8f6b6d70 SS |
93 | qdisc = NULL; |
94 | ||
95 | return 0; | |
96 | } | |
97 | ||
98 | const QDiscVTable fq_pie_vtable = { | |
99 | .object_size = sizeof(FlowQueuePIE), | |
100 | .tca_kind = "fq_pie", | |
101 | .fill_message = fq_pie_fill_message, | |
102 | }; |