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