1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-11 09:18:07 +03:00

network: tc/teql: set tca_kind in verify()

Then, qdisc_configure() can be simplified.
This commit is contained in:
Yu Watanabe 2022-01-26 12:18:47 +09:00
parent 828a81a937
commit b3208e0fad
3 changed files with 12 additions and 34 deletions

View File

@ -269,24 +269,12 @@ int qdisc_configure(Link *link, QDisc *qdisc) {
if (r < 0)
return log_link_debug_errno(link, r, "Could not create RTM_NEWQDISC message: %m");
if (QDISC_VTABLE(qdisc)) {
if (QDISC_VTABLE(qdisc)->fill_tca_kind) {
r = QDISC_VTABLE(qdisc)->fill_tca_kind(link, qdisc, req);
if (r < 0)
return r;
} else {
r = sd_netlink_message_append_string(req, TCA_KIND, QDISC_VTABLE(qdisc)->tca_kind);
if (r < 0)
return r;
}
r = sd_netlink_message_append_string(req, TCA_KIND, qdisc_get_tca_kind(qdisc));
if (r < 0)
return r;
if (QDISC_VTABLE(qdisc)->fill_message) {
r = QDISC_VTABLE(qdisc)->fill_message(link, qdisc, req);
if (r < 0)
return r;
}
} else {
r = sd_netlink_message_append_string(req, TCA_KIND, qdisc->tca_kind);
if (QDISC_VTABLE(qdisc) && QDISC_VTABLE(qdisc)->fill_message) {
r = QDISC_VTABLE(qdisc)->fill_message(link, qdisc, req);
if (r < 0)
return r;
}

View File

@ -55,7 +55,6 @@ typedef struct QDiscVTable {
const char *tca_kind;
/* called in qdisc_new() */
int (*init)(QDisc *qdisc);
int (*fill_tca_kind)(Link *link, QDisc *qdisc, sd_netlink_message *m);
int (*fill_message)(Link *link, QDisc *qdisc, sd_netlink_message *m);
int (*verify)(QDisc *qdisc);
} QDiscVTable;

View File

@ -1,34 +1,25 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "macro.h"
#include "netlink-util.h"
#include "parse-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "teql.h"
static int trivial_link_equalizer_fill_tca_kind(Link *link, QDisc *qdisc, sd_netlink_message *req) {
char kind[STRLEN("teql") + DECIMAL_STR_MAX(unsigned)];
static int trivial_link_equalizer_verify(QDisc *qdisc) {
_cleanup_free_ char *tca_kind = NULL;
TrivialLinkEqualizer *teql;
int r;
assert(link);
assert(qdisc);
assert(req);
teql = TEQL(ASSERT_PTR(qdisc));
teql = TEQL(qdisc);
if (asprintf(&tca_kind, "teql%u", teql->id) < 0)
return log_oom();
xsprintf(kind, "teql%u", teql->id);
r = sd_netlink_message_append_string(req, TCA_KIND, kind);
if (r < 0)
return log_link_error_errno(link, r, "Could not append TCA_KIND attribute: %m");
return 0;
return free_and_replace(qdisc->tca_kind, tca_kind);
}
const QDiscVTable teql_vtable = {
.object_size = sizeof(TrivialLinkEqualizer),
.fill_tca_kind = trivial_link_equalizer_fill_tca_kind,
.verify = trivial_link_equalizer_verify,
};
int config_parse_trivial_link_equalizer_id(