From 4d13d175f8454df63843a880c78badd4f6d720ca Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 24 May 2023 11:02:36 +0900 Subject: [PATCH 1/3] network/vlan: drop unnecessary restriction for QoS mapping Fixes #27460. --- src/network/netdev/vlan.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/network/netdev/vlan.c b/src/network/netdev/vlan.c index a3d961dac3..d61e9486ab 100644 --- a/src/network/netdev/vlan.c +++ b/src/network/netdev/vlan.c @@ -165,11 +165,6 @@ int config_parse_vlan_qos_maps( continue; } - if (m->to > m->from || m->to == 0 || m->from == 0) { - log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid %s, ignoring: %s", lvalue, w); - continue; - } - r = set_ensure_consume(s, &vlan_qos_maps_hash_ops, TAKE_PTR(m)); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to store %s, ignoring: %s", lvalue, w); From 4194478af861f80a73905d1f9e570a09862f91a7 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 24 May 2023 11:06:35 +0900 Subject: [PATCH 2/3] network/vlan: paranoia about type safety No functional change, as the struct is defined as the following: ``` struct ifla_vlan_qos_mapping { __u32 from; __u32 to; }; ``` --- src/network/netdev/vlan.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/network/netdev/vlan.c b/src/network/netdev/vlan.c index d61e9486ab..5eb36ef680 100644 --- a/src/network/netdev/vlan.c +++ b/src/network/netdev/vlan.c @@ -144,6 +144,7 @@ int config_parse_vlan_qos_maps( for (const char *p = rvalue;;) { _cleanup_free_ struct ifla_vlan_qos_mapping *m = NULL; _cleanup_free_ char *w = NULL; + unsigned from, to; r = extract_first_word(&p, &w, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE); if (r == -ENOMEM) @@ -155,16 +156,21 @@ int config_parse_vlan_qos_maps( if (r == 0) return 0; - m = new0(struct ifla_vlan_qos_mapping, 1); - if (!m) - return log_oom(); - - r = parse_range(w, &m->from, &m->to); + r = parse_range(w, &from, &to); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, w); continue; } + m = new(struct ifla_vlan_qos_mapping, 1); + if (!m) + return log_oom(); + + *m = (struct ifla_vlan_qos_mapping) { + .from = from, + .to = to, + }; + r = set_ensure_consume(s, &vlan_qos_maps_hash_ops, TAKE_PTR(m)); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to store %s, ignoring: %s", lvalue, w); From 73d24e45f8ac18eaaebf1df2b1f055c14179c6ff Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 24 May 2023 11:15:44 +0900 Subject: [PATCH 3/3] test-network: add tests for vlan QoS mapping --- .../conf/21-vlan.netdev.d/override.conf | 10 ++++++---- test/test-network/systemd-networkd-tests.py | 14 ++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/test/test-network/conf/21-vlan.netdev.d/override.conf b/test/test-network/conf/21-vlan.netdev.d/override.conf index 3b8d47d9b1..c71077d274 100644 --- a/test/test-network/conf/21-vlan.netdev.d/override.conf +++ b/test/test-network/conf/21-vlan.netdev.d/override.conf @@ -3,7 +3,9 @@ MTUBytes=2000 [VLAN] Id=99 -GVRP=true -MVRP=true -LooseBinding=true -ReorderHeader=true +GVRP=yes +MVRP=yes +LooseBinding=yes +ReorderHeader=yes +EgressQOSMaps=0-1 1-3 10-3 6-6 7-7 +IngressQOSMaps=15-13 20-100 diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index fe72f37ce4..8b01718d55 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -1285,12 +1285,14 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities): output = check_output('ip -d link show vlan99') print(output) - self.assertRegex(output, ' mtu 2000 ') - self.assertRegex(output, 'REORDER_HDR') - self.assertRegex(output, 'LOOSE_BINDING') - self.assertRegex(output, 'GVRP') - self.assertRegex(output, 'MVRP') - self.assertRegex(output, ' id 99 ') + self.assertIn(' mtu 2000 ', output) + self.assertIn('REORDER_HDR', output) + self.assertIn('LOOSE_BINDING', output) + self.assertIn('GVRP', output) + self.assertIn('MVRP', output) + self.assertIn(' id 99 ', output) + self.assertIn('ingress-qos-map { 4:100 7:13 }', output) + self.assertIn('egress-qos-map { 0:1 1:3 6:6 7:7 10:3 }', output) output = check_output('ip -4 address show dev test1') print(output)