Debian Codegraph @

src/network/tc/sfq.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later
2 * Copyright © 2019 VMware, Inc. */
3
4 #include <linux/pkt_sched.h>
5 #include "sd-netlink.h"
6
7 #include "log.h"
8 #include "qdisc.h"
9 #include "sfq.h"
10 #include "string-util.h"
11
12 static int stochastic_fairness_queueing_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) {
13 StochasticFairnessQueueing *sfq;
14 int r;
15
16 assert(link);
17 assert(qdisc);
18 assert(req);
19
20 assert_se(sfq = SFQ(qdisc));
21
22 const struct tc_sfq_qopt_v1 opt = {
23 .v0.perturb_period = sfq->perturb_period / USEC_PER_SEC,
24 };
25
26 r = sd_netlink_message_append_data(req, TCA_OPTIONS, &opt, sizeof(opt));
27 if (r < 0)
28 return r;
29
30 return 0;
31 }
32
33 int config_parse_sfq_perturb_period(
34 const char *unit,
35 const char *filename,
36 unsigned line,
37 const char *section,
38 unsigned section_line,
39 const char *lvalue,
40 int ltype,
41 const char *rvalue,
42 void *data,
43 void *userdata) {
44
45 _cleanup_(qdisc_unref_or_set_invalidp) QDisc *qdisc = NULL;
46 StochasticFairnessQueueing *sfq;
47 Network *network = ASSERT_PTR(data);
48 int r;
49
50 assert(filename);
51 assert(lvalue);
52 assert(rvalue);
53
54 r = qdisc_new_static(QDISC_KIND_SFQ, network, filename, section_line, &qdisc);
55 if (r == -ENOMEM)
56 return log_oom();
57 if (r < 0) {
58 log_syntax(unit, LOG_WARNING, filename, line, r,
59 "More than one kind of queueing discipline, ignoring assignment: %m");
60 return 0;
61 }
62
63 sfq = SFQ(qdisc);
64
65 if (isempty(rvalue)) {
66 sfq->perturb_period = 0;
67
68 TAKE_PTR(qdisc);
69 return 0;
70 }
71
72 r = parse_sec(rvalue, &sfq->perturb_period);
73 if (r < 0) {
74 log_syntax(unit, LOG_WARNING, filename, line, r,
75 "Failed to parse '%s=', ignoring assignment: %s",
76 lvalue, rvalue);
77 return 0;
78 }
79
80 TAKE_PTR(qdisc);
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 };