]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/tc/sfq.c
license: LGPL-2.1+ -> LGPL-2.1-or-later
[thirdparty/systemd.git] / src / network / tc / sfq.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later
2 * Copyright © 2019 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 "sfq.h"
12 #include "string-util.h"
13
14 static int stochastic_fairness_queueing_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) {
15 StochasticFairnessQueueing *sfq;
16 struct tc_sfq_qopt_v1 opt = {};
17 int r;
18
19 assert(link);
20 assert(qdisc);
21 assert(req);
22
23 sfq = SFQ(qdisc);
24
25 opt.v0.perturb_period = sfq->perturb_period / USEC_PER_SEC;
26
27 r = sd_netlink_message_append_data(req, TCA_OPTIONS, &opt, sizeof(struct tc_sfq_qopt_v1));
28 if (r < 0)
29 return log_link_error_errno(link, r, "Could not append TCA_OPTIONS attribute: %m");
30
31 return 0;
32 }
33
34 int config_parse_stochastic_fairness_queueing_perturb_period(
35 const char *unit,
36 const char *filename,
37 unsigned line,
38 const char *section,
39 unsigned section_line,
40 const char *lvalue,
41 int ltype,
42 const char *rvalue,
43 void *data,
44 void *userdata) {
45
46 _cleanup_(qdisc_free_or_set_invalidp) QDisc *qdisc = NULL;
47 StochasticFairnessQueueing *sfq;
48 Network *network = data;
49 int r;
50
51 assert(filename);
52 assert(lvalue);
53 assert(rvalue);
54 assert(data);
55
56 r = qdisc_new_static(QDISC_KIND_SFQ, network, filename, section_line, &qdisc);
57 if (r == -ENOMEM)
58 return log_oom();
59 if (r < 0) {
60 log_syntax(unit, LOG_WARNING, filename, line, r,
61 "More than one kind of queueing discipline, ignoring assignment: %m");
62 return 0;
63 }
64
65 sfq = SFQ(qdisc);
66
67 if (isempty(rvalue)) {
68 sfq->perturb_period = 0;
69
70 qdisc = NULL;
71 return 0;
72 }
73
74 r = parse_sec(rvalue, &sfq->perturb_period);
75 if (r < 0) {
76 log_syntax(unit, LOG_WARNING, filename, line, r,
77 "Failed to parse '%s=', ignoring assignment: %s",
78 lvalue, rvalue);
79 return 0;
80 }
81
82 qdisc = NULL;
83
84 return 0;
85 }
86
87 const QDiscVTable sfq_vtable = {
88 .object_size = sizeof(StochasticFairnessQueueing),
89 .tca_kind = "sfq",
90 .fill_message = stochastic_fairness_queueing_fill_message,
91 };