]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later |
982998b0 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 "netlink-util.h" | |
9 | #include "parse-util.h" | |
10 | #include "qdisc.h" | |
11 | #include "sfb.h" | |
12 | #include "string-util.h" | |
13 | ||
14 | static int stochastic_fair_blue_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { | |
15 | StochasticFairBlue *sfb; | |
16924f54 ZJS |
16 | int r; |
17 | ||
18 | assert(link); | |
19 | assert(qdisc); | |
20 | assert(req); | |
21 | ||
22 | assert_se(sfb = SFB(qdisc)); | |
23 | ||
24 | const struct tc_sfb_qopt opt = { | |
982998b0 SS |
25 | .rehash_interval = 600*1000, |
26 | .warmup_time = 60*1000, | |
27 | .penalty_rate = 10, | |
28 | .penalty_burst = 20, | |
29 | .increment = (SFB_MAX_PROB + 1000) / 2000, | |
30 | .decrement = (SFB_MAX_PROB + 10000) / 20000, | |
31 | .max = 25, | |
32 | .bin_size = 20, | |
16924f54 | 33 | .limit = sfb->packet_limit, |
982998b0 | 34 | }; |
982998b0 SS |
35 | |
36 | r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "sfb"); | |
37 | if (r < 0) | |
16924f54 | 38 | return r; |
982998b0 | 39 | |
16924f54 | 40 | r = sd_netlink_message_append_data(req, TCA_SFB_PARMS, &opt, sizeof(opt)); |
982998b0 | 41 | if (r < 0) |
16924f54 | 42 | return r; |
982998b0 SS |
43 | |
44 | r = sd_netlink_message_close_container(req); | |
45 | if (r < 0) | |
16924f54 | 46 | return r; |
982998b0 SS |
47 | |
48 | return 0; | |
49 | } | |
50 | ||
51 | int config_parse_stochastic_fair_blue_u32( | |
52 | const char *unit, | |
53 | const char *filename, | |
54 | unsigned line, | |
55 | const char *section, | |
56 | unsigned section_line, | |
57 | const char *lvalue, | |
58 | int ltype, | |
59 | const char *rvalue, | |
60 | void *data, | |
61 | void *userdata) { | |
62 | ||
63 | _cleanup_(qdisc_free_or_set_invalidp) QDisc *qdisc = NULL; | |
64 | StochasticFairBlue *sfb; | |
99534007 | 65 | Network *network = ASSERT_PTR(data); |
982998b0 SS |
66 | int r; |
67 | ||
68 | assert(filename); | |
69 | assert(lvalue); | |
70 | assert(rvalue); | |
982998b0 SS |
71 | |
72 | r = qdisc_new_static(QDISC_KIND_SFB, network, filename, section_line, &qdisc); | |
73 | if (r == -ENOMEM) | |
74 | return log_oom(); | |
d96edb2c YW |
75 | if (r < 0) { |
76 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
77 | "More than one kind of queueing discipline, ignoring assignment: %m"); | |
78 | return 0; | |
79 | } | |
982998b0 SS |
80 | |
81 | sfb = SFB(qdisc); | |
82 | ||
83 | if (isempty(rvalue)) { | |
84 | sfb->packet_limit = 0; | |
85 | ||
5a3e1cb9 | 86 | TAKE_PTR(qdisc); |
982998b0 SS |
87 | return 0; |
88 | } | |
89 | ||
90 | r = safe_atou32(rvalue, &sfb->packet_limit); | |
91 | if (r < 0) { | |
d96edb2c | 92 | log_syntax(unit, LOG_WARNING, filename, line, r, |
982998b0 SS |
93 | "Failed to parse '%s=', ignoring assignment: %s", |
94 | lvalue, rvalue); | |
95 | return 0; | |
96 | } | |
97 | ||
5a3e1cb9 | 98 | TAKE_PTR(qdisc); |
982998b0 SS |
99 | |
100 | return 0; | |
101 | } | |
102 | ||
103 | const QDiscVTable sfb_vtable = { | |
104 | .object_size = sizeof(StochasticFairBlue), | |
105 | .tca_kind = "sfb", | |
106 | .fill_message = stochastic_fair_blue_fill_message, | |
107 | }; |