From: Yu Watanabe Date: Tue, 2 Nov 2021 19:05:02 +0000 (+0900) Subject: network: tc/cake: introduce AutoRateIngress= setting X-Git-Tag: v250-rc1~330^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=025cd94e1c8ba4685acf7a8517edb00caaa8679b;p=thirdparty%2Fsystemd.git network: tc/cake: introduce AutoRateIngress= setting --- diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 39acb2a6a9c..4ace6d60d8d 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -3472,6 +3472,16 @@ Token=prefixstable:2002:da8:1:: + + AutoRateIngress= + + Takes a boolean value. Enables automatic capacity estimation based on traffic arriving + at this qdisc. This is most likely to be useful with cellular links, which tend to change + quality randomly. If this setting is enabled, the Bandwidth= setting is + used as an initial estimate. Defaults to unset, and the kernel's default is used. + + + OverheadBytes= diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 1f0a625183b..c34b3e18122 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -386,6 +386,7 @@ BFIFO.LimitBytes, config_parse_bfifo_size, CAKE.Parent, config_parse_qdisc_parent, QDISC_KIND_CAKE, 0 CAKE.Handle, config_parse_qdisc_handle, QDISC_KIND_CAKE, 0 CAKE.Bandwidth, config_parse_cake_bandwidth, QDISC_KIND_CAKE, 0 +CAKE.AutoRateIngress, config_parse_cake_tristate, QDISC_KIND_CAKE, 0 CAKE.OverheadBytes, config_parse_cake_overhead, QDISC_KIND_CAKE, 0 ControlledDelay.Parent, config_parse_qdisc_parent, QDISC_KIND_CODEL, 0 ControlledDelay.Handle, config_parse_qdisc_handle, QDISC_KIND_CODEL, 0 diff --git a/src/network/tc/cake.c b/src/network/tc/cake.c index 70dd095e932..0f77036fd80 100644 --- a/src/network/tc/cake.c +++ b/src/network/tc/cake.c @@ -11,6 +11,18 @@ #include "qdisc.h" #include "string-util.h" +static int cake_init(QDisc *qdisc) { + CommonApplicationsKeptEnhanced *c; + + assert(qdisc); + + c = CAKE(qdisc); + + c->autorate = -1; + + return 0; +} + static int cake_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { CommonApplicationsKeptEnhanced *c; int r; @@ -31,6 +43,12 @@ static int cake_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) return log_link_error_errno(link, r, "Could not append TCA_CAKE_BASE_RATE64 attribute: %m"); } + if (c->autorate >= 0) { + r = sd_netlink_message_append_u32(req, TCA_CAKE_AUTORATE, c->autorate); + if (r < 0) + return log_link_error_errno(link, r, "Could not append TCA_CAKE_AUTORATE attribute: %m"); + } + r = sd_netlink_message_append_s32(req, TCA_CAKE_OVERHEAD, c->overhead); if (r < 0) return log_link_error_errno(link, r, "Could not append TCA_CAKE_OVERHEAD attribute: %m"); @@ -156,8 +174,66 @@ int config_parse_cake_overhead( return 0; } +int config_parse_cake_tristate( + 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) { + + _cleanup_(qdisc_free_or_set_invalidp) QDisc *qdisc = NULL; + CommonApplicationsKeptEnhanced *c; + Network *network = data; + int *dest, r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + r = qdisc_new_static(QDISC_KIND_CAKE, network, filename, section_line, &qdisc); + if (r == -ENOMEM) + return log_oom(); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "More than one kind of queueing discipline, ignoring assignment: %m"); + return 0; + } + + c = CAKE(qdisc); + + if (streq(lvalue, "AutoRateIngress")) + dest = &c->autorate; + else + assert_not_reached(); + + if (isempty(rvalue)) { + *dest = -1; + TAKE_PTR(qdisc); + return 0; + } + + r = parse_boolean(rvalue); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to parse '%s=', ignoring assignment: %s", + lvalue, rvalue); + return 0; + } + + *dest = r; + TAKE_PTR(qdisc); + return 0; +} + const QDiscVTable cake_vtable = { .object_size = sizeof(CommonApplicationsKeptEnhanced), .tca_kind = "cake", + .init = cake_init, .fill_message = cake_fill_message, }; diff --git a/src/network/tc/cake.h b/src/network/tc/cake.h index 1da28b7d203..ba9dcb9a080 100644 --- a/src/network/tc/cake.h +++ b/src/network/tc/cake.h @@ -8,9 +8,13 @@ typedef struct CommonApplicationsKeptEnhanced { QDisc meta; - int overhead; + /* Shaper parameters */ + int autorate; uint64_t bandwidth; + /* Overhead compensation parameters */ + int overhead; + } CommonApplicationsKeptEnhanced; DEFINE_QDISC_CAST(CAKE, CommonApplicationsKeptEnhanced); @@ -18,3 +22,4 @@ extern const QDiscVTable cake_vtable; CONFIG_PARSER_PROTOTYPE(config_parse_cake_bandwidth); CONFIG_PARSER_PROTOTYPE(config_parse_cake_overhead); +CONFIG_PARSER_PROTOTYPE(config_parse_cake_tristate); diff --git a/test/fuzz/fuzz-network-parser/directives.network b/test/fuzz/fuzz-network-parser/directives.network index 2ff20e0f083..83e9fa9054d 100644 --- a/test/fuzz/fuzz-network-parser/directives.network +++ b/test/fuzz/fuzz-network-parser/directives.network @@ -468,6 +468,7 @@ ECN= Parent= Handle= Bandwidth= +AutoRateIngress= OverheadBytes= [TrafficControlQueueingDiscipline] Parent=