]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/tc/sfq.c
Merge pull request #17549 from yuwata/tiny-fixes
[thirdparty/systemd.git] / src / network / tc / sfq.c
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later
9942b710
SS
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
e8c17dc0
YW
14static int stochastic_fairness_queueing_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) {
15 StochasticFairnessQueueing *sfq;
9942b710
SS
16 struct tc_sfq_qopt_v1 opt = {};
17 int r;
18
19 assert(link);
e8c17dc0 20 assert(qdisc);
9942b710
SS
21 assert(req);
22
e8c17dc0
YW
23 sfq = SFQ(qdisc);
24
9942b710
SS
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
18de0969 34int config_parse_stochastic_fairness_queueing_perturb_period(
9942b710
SS
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;
e8c17dc0 47 StochasticFairnessQueueing *sfq;
9942b710
SS
48 Network *network = data;
49 int r;
50
51 assert(filename);
52 assert(lvalue);
53 assert(rvalue);
54 assert(data);
55
e8c17dc0
YW
56 r = qdisc_new_static(QDISC_KIND_SFQ, network, filename, section_line, &qdisc);
57 if (r == -ENOMEM)
58 return log_oom();
d96edb2c
YW
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 }
e8c17dc0
YW
64
65 sfq = SFQ(qdisc);
9942b710
SS
66
67 if (isempty(rvalue)) {
e8c17dc0 68 sfq->perturb_period = 0;
9942b710
SS
69
70 qdisc = NULL;
71 return 0;
72 }
73
e8c17dc0 74 r = parse_sec(rvalue, &sfq->perturb_period);
9942b710 75 if (r < 0) {
d96edb2c 76 log_syntax(unit, LOG_WARNING, filename, line, r,
9942b710
SS
77 "Failed to parse '%s=', ignoring assignment: %s",
78 lvalue, rvalue);
79 return 0;
80 }
81
9942b710
SS
82 qdisc = NULL;
83
84 return 0;
85}
e8c17dc0
YW
86
87const QDiscVTable sfq_vtable = {
88 .object_size = sizeof(StochasticFairnessQueueing),
89 .tca_kind = "sfq",
90 .fill_message = stochastic_fairness_queueing_fill_message,
91};