]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/tc/teql.c
network: tc: support teql
[thirdparty/systemd.git] / src / network / tc / teql.c
CommitLineData
9b749c11
YW
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include "macro.h"
4#include "netlink-util.h"
5#include "parse-util.h"
6#include "stdio-util.h"
7#include "string-util.h"
8#include "teql.h"
9
10static int trivial_link_equalizer_fill_tca_kind(Link *link, QDisc *qdisc, sd_netlink_message *req) {
11 char kind[STRLEN("teql") + DECIMAL_STR_MAX(unsigned)];
12 TrivialLinkEqualizer *teql;
13 int r;
14
15 assert(link);
16 assert(qdisc);
17 assert(req);
18
19 teql = TEQL(qdisc);
20
21 xsprintf(kind, "teql%u", teql->id);
22 r = sd_netlink_message_append_string(req, TCA_KIND, kind);
23 if (r < 0)
24 return log_link_error_errno(link, r, "Could not append TCA_KIND attribute: %m");
25
26 return 0;
27}
28
29const QDiscVTable teql_vtable = {
30 .object_size = sizeof(TrivialLinkEqualizer),
31 .fill_tca_kind = trivial_link_equalizer_fill_tca_kind,
32};
33
34int config_parse_trivial_link_equalizer_id(
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 TrivialLinkEqualizer *teql;
48 Network *network = data;
49 unsigned id;
50 int r;
51
52 assert(filename);
53 assert(lvalue);
54 assert(rvalue);
55 assert(data);
56
57 r = qdisc_new_static(QDISC_KIND_TEQL, network, filename, section_line, &qdisc);
58 if (r == -ENOMEM)
59 return log_oom();
60 if (r < 0)
61 return log_syntax(unit, LOG_ERR, filename, line, r,
62 "More than one kind of queueing discipline, ignoring assignment: %m");
63
64 teql = TEQL(qdisc);
65
66 if (isempty(rvalue)) {
67 teql->id = 0;
68
69 qdisc = NULL;
70 return 0;
71 }
72
73 r = safe_atou(rvalue, &id);
74 if (r < 0) {
75 log_syntax(unit, LOG_ERR, filename, line, r,
76 "Failed to parse '%s=', ignoring assignment: %s",
77 lvalue, rvalue);
78 return 0;
79 }
80 if (id > INT_MAX) {
81 log_syntax(unit, LOG_ERR, filename, line, 0,
82 "'%s=' is too large, ignoring assignment: %s",
83 lvalue, rvalue);
84 }
85
86 teql->id = id;
87
88 qdisc = NULL;
89 return 0;
90}