]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/tc/sfq.c
Merge pull request #14293 from keur/systemctl_with_dependencies
[thirdparty/systemd.git] / src / network / tc / sfq.c
1 /* SPDX-License-Identifier: LGPL-2.1+
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_tc_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 return log_syntax(unit, LOG_ERR, filename, line, r,
61 "More than one kind of queueing discipline, ignoring assignment: %m");
62
63 sfq = SFQ(qdisc);
64
65 if (isempty(rvalue)) {
66 sfq->perturb_period = 0;
67
68 qdisc = NULL;
69 return 0;
70 }
71
72 r = parse_sec(rvalue, &sfq->perturb_period);
73 if (r < 0) {
74 log_syntax(unit, LOG_ERR, filename, line, r,
75 "Failed to parse '%s=', ignoring assignment: %s",
76 lvalue, rvalue);
77 return 0;
78 }
79
80 qdisc = NULL;
81
82 return 0;
83 }
84
85 const QDiscVTable sfq_vtable = {
86 .object_size = sizeof(StochasticFairnessQueueing),
87 .tca_kind = "sfq",
88 .fill_message = stochastic_fairness_queueing_fill_message,
89 };