]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/tc/hhf.c
tree-wide: use ASSERT_PTR more
[thirdparty/systemd.git] / src / network / tc / hhf.c
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later
7f224020
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 "hhf.h"
9#include "netlink-util.h"
10#include "parse-util.h"
11#include "string-util.h"
12#include "util.h"
13
14static int heavy_hitter_filter_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) {
15 HeavyHitterFilter *hhf;
16 int r;
17
18 assert(link);
19 assert(qdisc);
20 assert(req);
21
16924f54 22 assert_se(hhf = HHF(qdisc));
7f224020
SS
23
24 r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "hhf");
25 if (r < 0)
16924f54 26 return r;
7f224020
SS
27
28 if (hhf->packet_limit > 0) {
29 r = sd_netlink_message_append_u32(req, TCA_HHF_BACKLOG_LIMIT, hhf->packet_limit);
30 if (r < 0)
16924f54 31 return r;
7f224020
SS
32 }
33
34 r = sd_netlink_message_close_container(req);
35 if (r < 0)
16924f54 36 return r;
7f224020
SS
37
38 return 0;
39}
40
41int config_parse_heavy_hitter_filter_packet_limit(
42 const char *unit,
43 const char *filename,
44 unsigned line,
45 const char *section,
46 unsigned section_line,
47 const char *lvalue,
48 int ltype,
49 const char *rvalue,
50 void *data,
51 void *userdata) {
52
53 _cleanup_(qdisc_free_or_set_invalidp) QDisc *qdisc = NULL;
54 HeavyHitterFilter *hhf;
99534007 55 Network *network = ASSERT_PTR(data);
7f224020
SS
56 int r;
57
58 assert(filename);
59 assert(lvalue);
60 assert(rvalue);
7f224020
SS
61
62 r = qdisc_new_static(QDISC_KIND_HHF, network, filename, section_line, &qdisc);
63 if (r == -ENOMEM)
64 return log_oom();
d96edb2c
YW
65 if (r < 0) {
66 log_syntax(unit, LOG_WARNING, filename, line, r,
67 "More than one kind of queueing discipline, ignoring assignment: %m");
68 return 0;
69 }
7f224020
SS
70
71 hhf = HHF(qdisc);
72
73 if (isempty(rvalue)) {
74 hhf->packet_limit = 0;
75
0132453c 76 TAKE_PTR(qdisc);
7f224020
SS
77 return 0;
78 }
79
80 r = safe_atou32(rvalue, &hhf->packet_limit);
81 if (r < 0) {
d96edb2c 82 log_syntax(unit, LOG_WARNING, filename, line, r,
7f224020
SS
83 "Failed to parse '%s=', ignoring assignment: %s",
84 lvalue, rvalue);
85 return 0;
86 }
87
0132453c 88 TAKE_PTR(qdisc);
7f224020
SS
89
90 return 0;
91}
92
93const QDiscVTable hhf_vtable = {
94 .object_size = sizeof(HeavyHitterFilter),
95 .tca_kind = "hhf",
96 .fill_message = heavy_hitter_filter_fill_message,
97};