From 2a0963311795677a43fdb2b9ae9c3dfbfee83ac6 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 10 Feb 2020 17:45:24 +0900 Subject: [PATCH] network: tc: make Parent= take class id --- man/systemd.network.xml | 28 +++++++++++++++++++++------- src/network/tc/qdisc.c | 20 ++++++++++++-------- src/network/tc/tc-util.c | 30 ++++++++++++++++++++++++++++++ src/network/tc/tc-util.h | 1 + 4 files changed, 64 insertions(+), 15 deletions(-) diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 209787bf1b..c3608394c8 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -2322,7 +2322,9 @@ Parent= Specifies the parent Queueing Discipline (qdisc). Takes one of root, - clsact or ingress. Defaults to root. + clsact, ingress or a class id. The class id takes the + major and minor number in hexadecimal ranges 1 to ffff separated with a colon + (major:minor). Defaults to root. @@ -2386,7 +2388,9 @@ Parent= Specifies the parent Queueing Discipline (qdisc). Takes one of root, - clsact or ingress. Defaults to root. + clsact, ingress or a class id. The class id takes the + major and minor number in hexadecimal ranges 1 to ffff separated with a colon + (major:minor). Defaults to root. @@ -2473,7 +2477,9 @@ Parent= Specifies the parent Queueing Discipline (qdisc). Takes one of root, - clsact or ingress. Defaults to root. + clsact, ingress or a class id. The class id takes the + major and minor number in hexadecimal ranges 1 to ffff separated with a colon + (major:minor). Defaults to root. @@ -2504,7 +2510,9 @@ Parent= Specifies the parent Queueing Discipline (qdisc). Takes one of root, - clsact or ingress. Defaults to root. + clsact, ingress or a class id. The class id takes the + major and minor number in hexadecimal ranges 1 to ffff separated with a colon + (major:minor). Defaults to root. @@ -2568,7 +2576,9 @@ Parent= Specifies the parent Queueing Discipline (qdisc). Takes one of root, - clsact or ingress. Defaults to root. + clsact, ingress or a class id. The class id takes the + major and minor number in hexadecimal ranges 1 to ffff separated with a colon + (major:minor). Defaults to root. @@ -2658,7 +2668,9 @@ Parent= Specifies the parent Queueing Discipline (qdisc). Takes one of root, - clsact or ingress. Defaults to root. + clsact, ingress or a class id. The class id takes the + major and minor number in hexadecimal ranges 1 to ffff separated with a colon + (major:minor). Defaults to root. @@ -2760,7 +2772,9 @@ Parent= Specifies the parent Queueing Discipline (qdisc). Takes one of root, - clsact or ingress. Defaults to root. + clsact, ingress or a class id. The class id takes the + major and minor number in hexadecimal ranges 1 to ffff separated with a colon + (major:minor). Defaults to root. diff --git a/src/network/tc/qdisc.c b/src/network/tc/qdisc.c index 0619e894cc..988167f8b4 100644 --- a/src/network/tc/qdisc.c +++ b/src/network/tc/qdisc.c @@ -12,6 +12,8 @@ #include "qdisc.h" #include "set.h" #include "string-util.h" +#include "strv.h" +#include "tc-util.h" const QDiscVTable * const qdisc_vtable[_QDISC_KIND_MAX] = { [QDISC_KIND_CODEL] = &codel_vtable, @@ -279,19 +281,21 @@ int config_parse_qdisc_parent( qdisc->parent = TC_H_INGRESS; qdisc->handle = TC_H_MAKE(TC_H_INGRESS, 0); } else { - log_syntax(unit, LOG_ERR, filename, line, r, - "Failed to parse 'Parent=', ignoring assignment: %s", - rvalue); - return 0; + r = parse_handle(rvalue, &qdisc->parent); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to parse 'Parent=', ignoring assignment: %s", + rvalue); + return 0; + } } - if (streq(rvalue, "root")) - qdisc->tca_kind = mfree(qdisc->tca_kind); - else { + if (STR_IN_SET(rvalue, "clsact", "ingress")) { r = free_and_strdup(&qdisc->tca_kind, rvalue); if (r < 0) return log_oom(); - } + } else + qdisc->tca_kind = mfree(qdisc->tca_kind); qdisc = NULL; diff --git a/src/network/tc/tc-util.c b/src/network/tc/tc-util.c index c46550f955..47371a841b 100644 --- a/src/network/tc/tc-util.c +++ b/src/network/tc/tc-util.c @@ -2,6 +2,7 @@ * Copyright © 2019 VMware, Inc. */ #include "alloc-util.h" +#include "extract-word.h" #include "fileio.h" #include "parse-util.h" #include "tc-util.h" @@ -92,3 +93,32 @@ int tc_fill_ratespec_and_table(struct tc_ratespec *rate, uint32_t *rtab, uint32_ rate->linklayer = TC_LINKLAYER_ETHERNET; return 0; } + +int parse_handle(const char *t, uint32_t *ret) { + _cleanup_free_ char *word = NULL; + uint16_t major, minor; + int r; + + assert(t); + assert(ret); + + /* Extract the major number. */ + r = extract_first_word(&t, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS); + if (r < 0) + return r; + if (r == 0) + return -EINVAL; + if (!t) + return -EINVAL; + + r = safe_atou16_full(word, 16, &major); + if (r < 0) + return r; + + r = safe_atou16_full(t, 16, &minor); + if (r < 0) + return r; + + *ret = ((uint32_t) major << 16) | minor; + return 0; +} diff --git a/src/network/tc/tc-util.h b/src/network/tc/tc-util.h index c901f50691..38b9d0786d 100644 --- a/src/network/tc/tc-util.h +++ b/src/network/tc/tc-util.h @@ -10,3 +10,4 @@ int tc_time_to_tick(usec_t t, uint32_t *ret); int parse_tc_percent(const char *s, uint32_t *percent); int tc_transmit_time(uint64_t rate, uint32_t size, uint32_t *ret); int tc_fill_ratespec_and_table(struct tc_ratespec *rate, uint32_t *rtab, uint32_t mtu); +int parse_handle(const char *t, uint32_t *ret);