1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "macro.h"
4 #include "parse-util.h"
5 #include "string-util.h"
6 #include "teql.h"
7
trivial_link_equalizer_verify(QDisc * qdisc)8 static int trivial_link_equalizer_verify(QDisc *qdisc) {
9 _cleanup_free_ char *tca_kind = NULL;
10 TrivialLinkEqualizer *teql;
11
12 teql = TEQL(ASSERT_PTR(qdisc));
13
14 if (asprintf(&tca_kind, "teql%u", teql->id) < 0)
15 return log_oom();
16
17 return free_and_replace(qdisc->tca_kind, tca_kind);
18 }
19
20 const QDiscVTable teql_vtable = {
21 .object_size = sizeof(TrivialLinkEqualizer),
22 .verify = trivial_link_equalizer_verify,
23 };
24
config_parse_trivial_link_equalizer_id(const char * unit,const char * filename,unsigned line,const char * section,unsigned section_line,const char * lvalue,int ltype,const char * rvalue,void * data,void * userdata)25 int config_parse_trivial_link_equalizer_id(
26 const char *unit,
27 const char *filename,
28 unsigned line,
29 const char *section,
30 unsigned section_line,
31 const char *lvalue,
32 int ltype,
33 const char *rvalue,
34 void *data,
35 void *userdata) {
36
37 _cleanup_(qdisc_free_or_set_invalidp) QDisc *qdisc = NULL;
38 TrivialLinkEqualizer *teql;
39 Network *network = data;
40 unsigned id;
41 int r;
42
43 assert(filename);
44 assert(lvalue);
45 assert(rvalue);
46 assert(data);
47
48 r = qdisc_new_static(QDISC_KIND_TEQL, network, filename, section_line, &qdisc);
49 if (r == -ENOMEM)
50 return log_oom();
51 if (r < 0) {
52 log_syntax(unit, LOG_WARNING, filename, line, r,
53 "More than one kind of queueing discipline, ignoring assignment: %m");
54 return 0;
55 }
56
57 teql = TEQL(qdisc);
58
59 if (isempty(rvalue)) {
60 teql->id = 0;
61
62 TAKE_PTR(qdisc);
63 return 0;
64 }
65
66 r = safe_atou(rvalue, &id);
67 if (r < 0) {
68 log_syntax(unit, LOG_WARNING, filename, line, r,
69 "Failed to parse '%s=', ignoring assignment: %s",
70 lvalue, rvalue);
71 return 0;
72 }
73 if (id > INT_MAX)
74 log_syntax(unit, LOG_WARNING, filename, line, 0,
75 "'%s=' is too large, ignoring assignment: %s",
76 lvalue, rvalue);
77
78 teql->id = id;
79
80 TAKE_PTR(qdisc);
81 return 0;
82 }
83