Merge pull request #14278 from ssahani/tc
network tc: qdisc parent add support to set ingress
This commit is contained in:
commit
d8e897d345
|
@ -2327,8 +2327,8 @@
|
|||
<varlistentry>
|
||||
<term><varname>Parent=</varname></term>
|
||||
<listitem>
|
||||
<para>Specifies the parent Queueing Discipline (qdisc). Takes one of <literal>root</literal>
|
||||
or <literal>clsact</literal>. Defaults to <literal>root</literal>.</para>
|
||||
<para>Specifies the parent Queueing Discipline (qdisc). Takes one of <literal>root</literal>,
|
||||
<literal>clsact</literal> or <literal>ingress</literal>. Defaults to <literal>root</literal>.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
@ -2442,6 +2442,14 @@
|
|||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>FairQueuingControlledDelayPacketLimit=</varname></term>
|
||||
<listitem>
|
||||
<para>Specifies the hard limit on the real queue size. When this limit is reached, incoming packets are
|
||||
dropped. Defaults to unset and kernel's default is used.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
|
|
|
@ -107,6 +107,8 @@ sources = files('''
|
|||
networkd-util.h
|
||||
networkd-wifi.c
|
||||
networkd-wifi.h
|
||||
tc/fq-codel.c
|
||||
tc/fq-codel.h
|
||||
tc/netem.c
|
||||
tc/netem.h
|
||||
tc/qdisc.c
|
||||
|
|
|
@ -258,6 +258,7 @@ TrafficControlQueueingDiscipline.TokenBufferFilterMPUBytes, con
|
|||
TrafficControlQueueingDiscipline.TokenBufferFilterPeakRate, config_parse_tc_token_buffer_filter_size, 0, 0
|
||||
TrafficControlQueueingDiscipline.TokenBufferFilterLatencySec, config_parse_tc_token_buffer_filter_latency, 0, 0
|
||||
TrafficControlQueueingDiscipline.StochasticFairnessQueueingPerturbPeriodSec, config_parse_tc_stochastic_fairness_queueing_perturb_period, 0, 0
|
||||
TrafficControlQueueingDiscipline.FairQueuingControlledDelayPacketLimit, config_parse_tc_fair_queuing_controlled_delay_limit, 0, 0
|
||||
/* backwards compatibility: do not add new entries to this section */
|
||||
Network.IPv4LL, config_parse_ipv4ll, 0, offsetof(Network, link_local)
|
||||
DHCP.ClientIdentifier, config_parse_dhcp_client_identifier, 0, offsetof(Network, dhcp_client_identifier)
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+
|
||||
* Copyright © 2019 VMware, Inc. */
|
||||
|
||||
#include <linux/pkt_sched.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "conf-parser.h"
|
||||
#include "netlink-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "qdisc.h"
|
||||
#include "string-util.h"
|
||||
|
||||
int fair_queuing_controlled_delay_new(FairQueuingControlledDelay **ret) {
|
||||
FairQueuingControlledDelay *fqcd = NULL;
|
||||
|
||||
fqcd = new0(FairQueuingControlledDelay, 1);
|
||||
if (!fqcd)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = TAKE_PTR(fqcd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fair_queuing_controlled_delay_fill_message(Link *link, const FairQueuingControlledDelay *fqcd, sd_netlink_message *req) {
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
assert(fqcd);
|
||||
assert(req);
|
||||
|
||||
r = sd_netlink_message_open_array(req, TCA_OPTIONS);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m");
|
||||
|
||||
r = sd_netlink_message_append_data(req, TCA_FQ_CODEL_LIMIT, &fqcd->limit, sizeof(fqcd->limit));
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_LIMIT attribute: %m");
|
||||
|
||||
r = sd_netlink_message_close_container(req);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_tc_fair_queuing_controlled_delay_limit(
|
||||
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;
|
||||
Network *network = data;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
r = qdisc_new_static(network, filename, section_line, &qdisc);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
qdisc->fq_codel.limit = 0;
|
||||
|
||||
qdisc = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = safe_atou32(rvalue, &qdisc->fq_codel.limit);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, r,
|
||||
"Failed to parse '%s=', ignoring assignment: %s",
|
||||
lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
qdisc->has_fair_queuing_controlled_delay = true;
|
||||
qdisc = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+
|
||||
* Copyright © 2019 VMware, Inc. */
|
||||
#pragma once
|
||||
|
||||
#include "sd-netlink.h"
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "networkd-link.h"
|
||||
|
||||
typedef struct FairQueuingControlledDelay {
|
||||
uint32_t limit;
|
||||
} FairQueuingControlledDelay;
|
||||
|
||||
int fair_queuing_controlled_delay_new(FairQueuingControlledDelay **ret);
|
||||
int fair_queuing_controlled_delay_fill_message(Link *link, const FairQueuingControlledDelay *sfq, sd_netlink_message *req);
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_tc_fair_queuing_controlled_delay_limit);
|
|
@ -84,6 +84,7 @@ void qdisc_free(QDisc *qdisc) {
|
|||
|
||||
network_config_section_free(qdisc->section);
|
||||
|
||||
free(qdisc->tca_kind);
|
||||
free(qdisc);
|
||||
}
|
||||
|
||||
|
@ -116,6 +117,7 @@ static int qdisc_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
|||
int qdisc_configure(Link *link, QDisc *qdisc) {
|
||||
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
|
||||
_cleanup_free_ char *tca_kind = NULL;
|
||||
char *p;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
|
@ -131,12 +133,8 @@ int qdisc_configure(Link *link, QDisc *qdisc) {
|
|||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not create tcm_parent message: %m");
|
||||
|
||||
if (qdisc->parent == TC_H_CLSACT) {
|
||||
tca_kind = strdup("clsact");
|
||||
if (!tca_kind)
|
||||
return log_oom();
|
||||
|
||||
r = sd_rtnl_message_set_qdisc_handle(req, TC_H_MAKE(TC_H_CLSACT, 0));
|
||||
if (qdisc->handle != TC_H_UNSPEC) {
|
||||
r = sd_rtnl_message_set_qdisc_handle(req, qdisc->handle);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not set tcm_handle message: %m");
|
||||
}
|
||||
|
@ -171,8 +169,19 @@ int qdisc_configure(Link *link, QDisc *qdisc) {
|
|||
return r;
|
||||
}
|
||||
|
||||
if (tca_kind) {
|
||||
r = sd_netlink_message_append_string(req, TCA_KIND, tca_kind);
|
||||
if (qdisc->has_fair_queuing_controlled_delay) {
|
||||
r = free_and_strdup(&tca_kind, "fq_codel");
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
r = fair_queuing_controlled_delay_fill_message(link, &qdisc->fq_codel, req);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
p = tca_kind ?:qdisc->tca_kind;
|
||||
if (p) {
|
||||
r = sd_netlink_message_append_string(req, TCA_KIND, p);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append TCA_KIND attribute: %m");
|
||||
}
|
||||
|
@ -218,10 +227,10 @@ int qdisc_section_verify(QDisc *qdisc, bool *has_root, bool *has_clsact) {
|
|||
"Ignoring [TrafficControlQueueingDiscipline] section from line %u.",
|
||||
qdisc->section->filename, qdisc->section->line);
|
||||
*has_root = true;
|
||||
} else if (qdisc->parent == TC_H_CLSACT) {
|
||||
} else if (qdisc->parent == TC_H_CLSACT) { /* TC_H_CLSACT == TC_H_INGRESS */
|
||||
if (*has_clsact)
|
||||
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: More than one clsact TrafficControlQueueingDiscipline sections are defined. "
|
||||
"%s: More than one clsact or ingress TrafficControlQueueingDiscipline sections are defined. "
|
||||
"Ignoring [TrafficControlQueueingDiscipline] section from line %u.",
|
||||
qdisc->section->filename, qdisc->section->line);
|
||||
*has_clsact = true;
|
||||
|
@ -255,17 +264,30 @@ int config_parse_tc_qdiscs_parent(
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (streq(rvalue, "root"))
|
||||
if (streq(rvalue, "root")) {
|
||||
qdisc->parent = TC_H_ROOT;
|
||||
else if (streq(rvalue, "clsact"))
|
||||
qdisc->handle = TC_H_UNSPEC;
|
||||
} else if (streq(rvalue, "clsact")) {
|
||||
qdisc->parent = TC_H_CLSACT;
|
||||
else {
|
||||
qdisc->handle = TC_H_MAKE(TC_H_CLSACT, 0);
|
||||
} else if (streq(rvalue, "ingress")) {
|
||||
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 [QueueDiscs] 'Parent=', ignoring assignment: %s",
|
||||
"Failed to parse 'Parent=', ignoring assignment: %s",
|
||||
rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (streq(rvalue, "root"))
|
||||
qdisc->tca_kind = mfree(qdisc->tca_kind);
|
||||
else {
|
||||
r = free_and_strdup(&qdisc->tca_kind, rvalue);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
qdisc = NULL;
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "fq-codel.h"
|
||||
#include "netem.h"
|
||||
#include "networkd-link.h"
|
||||
#include "networkd-network.h"
|
||||
|
@ -21,13 +22,16 @@ typedef struct QDisc {
|
|||
uint32_t handle;
|
||||
uint32_t parent;
|
||||
|
||||
char *tca_kind;
|
||||
bool has_network_emulator:1;
|
||||
bool has_token_buffer_filter:1;
|
||||
bool has_stochastic_fairness_queueing:1;
|
||||
bool has_fair_queuing_controlled_delay:1;
|
||||
|
||||
NetworkEmulator ne;
|
||||
TokenBufferFilter tbf;
|
||||
StochasticFairnessQueueing sfq;
|
||||
FairQueuingControlledDelay fq_codel;
|
||||
} QDisc;
|
||||
|
||||
void qdisc_free(QDisc *qdisc);
|
||||
|
|
|
@ -278,3 +278,4 @@ TokenBufferFilterMPUBytes=
|
|||
TokenBufferFilterPeakRate=
|
||||
TokenBufferFilterLatencySec=
|
||||
StochasticFairnessQueueingPerturbPeriodSec=
|
||||
FairQueuingControlledDelayPacketLimit=
|
||||
|
|
|
@ -13,8 +13,5 @@ NetworkEmulatorLossRate=20%
|
|||
NetworkEmulatorPacketLimit=100
|
||||
|
||||
[TrafficControlQueueingDiscipline]
|
||||
Parent=clsact
|
||||
NetworkEmulatorDelaySec=100ms
|
||||
NetworkEmulatorDelayJitterSec=13ms
|
||||
NetworkEmulatorLossRate=20.5%
|
||||
NetworkEmulatorPacketLimit=200
|
||||
Parent=ingress
|
||||
FairQueuingControlledDelayPacketLimit=20480
|
|
@ -1509,7 +1509,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
|
|||
'25-neighbor-ip-dummy.network',
|
||||
'25-neighbor-ip.network',
|
||||
'25-nexthop.network',
|
||||
'25-qdisc-netem.network',
|
||||
'25-qdisc-netem-and-fqcodel.network',
|
||||
'25-qdisc-tbf-and-sfq.network',
|
||||
'25-route-ipv6-src.network',
|
||||
'25-route-static.network',
|
||||
|
@ -2083,7 +2083,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
|
|||
self.assertRegex(output, '192.168.5.1')
|
||||
|
||||
def test_qdisc(self):
|
||||
copy_unit_to_networkd_unit_path('25-qdisc-netem.network', '12-dummy.netdev',
|
||||
copy_unit_to_networkd_unit_path('25-qdisc-netem-and-fqcodel.network', '12-dummy.netdev',
|
||||
'25-qdisc-tbf-and-sfq.network', '11-dummy.netdev')
|
||||
start_networkd()
|
||||
|
||||
|
@ -2093,7 +2093,8 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
|
|||
print(output)
|
||||
self.assertRegex(output, 'qdisc netem')
|
||||
self.assertRegex(output, 'limit 100 delay 50.0ms 10.0ms loss 20%')
|
||||
self.assertRegex(output, 'limit 200 delay 100.0ms 13.0ms loss 20.5%')
|
||||
self.assertRegex(output, 'qdisc fq_codel')
|
||||
self.assertRegex(output, 'limit 20480p')
|
||||
output = check_output('tc qdisc show dev test1')
|
||||
print(output)
|
||||
self.assertRegex(output, 'qdisc tbf')
|
||||
|
|
Loading…
Reference in New Issue