From b751c3e747a90915964b332b1bf64a471a6a9659 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 10 Feb 2020 00:40:13 +0900 Subject: [PATCH 1/3] network fix parser for IPv6Token= extract_first_word() drops multiple ':'. So, it is not suitable for parsing 'static' case. --- src/network/networkd-ndisc.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c index 4bdc26a38fc..12f8c1a1dcc 100644 --- a/src/network/networkd-ndisc.c +++ b/src/network/networkd-ndisc.c @@ -962,7 +962,6 @@ int config_parse_address_generation_type( void *userdata) { _cleanup_free_ IPv6Token *token = NULL; - _cleanup_free_ char *word = NULL; union in_addr_union buffer; Network *network = data; const char *p; @@ -978,35 +977,19 @@ int config_parse_address_generation_type( return 0; } - p = rvalue; - r = extract_first_word(&p, &word, ":", 0); - if (r == -ENOMEM) - return log_oom(); - if (r <= 0) { - log_syntax(unit, LOG_ERR, filename, line, r, - "Invalid IPv6Token= , ignoring assignment: %s", rvalue); - return 0; - } - r = ipv6token_new(&token); if (r < 0) return log_oom(); - if (streq(word, "static")) + if ((p = startswith(rvalue, "static:"))) token->address_generation_type = IPV6_TOKEN_ADDRESS_GENERATION_STATIC; - else if (streq(word, "prefixstable")) + else if ((p = startswith(rvalue, "prefixstable:"))) token->address_generation_type = IPV6_TOKEN_ADDRESS_GENERATION_PREFIXSTABLE; else { token->address_generation_type = IPV6_TOKEN_ADDRESS_GENERATION_STATIC; p = rvalue; } - if (isempty(p)) { - log_syntax(unit, LOG_ERR, filename, line, 0, - "Invalid IPv6Token= , ignoring assignment: %s", rvalue); - return 0; - } - r = in_addr_from_string(AF_INET6, p, &buffer); if (r < 0) { log_syntax(unit, LOG_ERR, filename, line, r, From b241fa00e92ea086a9d99840f9f5cbb98485680e Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Sat, 8 Feb 2020 20:27:06 -0500 Subject: [PATCH 2/3] network: Add test for explicit 'static' IPv6Token Add a test case for an explicitly-specified 'static' IPv6Token. Signed-off-by: Kevin P. Fleming --- .../ipv6-prefix-veth-token-static-explicit.network | 6 ++++++ test/test-network/systemd-networkd-tests.py | 10 ++++++++++ 2 files changed, 16 insertions(+) create mode 100644 test/test-network/conf/ipv6-prefix-veth-token-static-explicit.network diff --git a/test/test-network/conf/ipv6-prefix-veth-token-static-explicit.network b/test/test-network/conf/ipv6-prefix-veth-token-static-explicit.network new file mode 100644 index 00000000000..237f9aa6623 --- /dev/null +++ b/test/test-network/conf/ipv6-prefix-veth-token-static-explicit.network @@ -0,0 +1,6 @@ +[Match] +Name=veth99 + +[Network] +IPv6AcceptRA=true +IPv6Token=static:::1a:2b:3c:4d diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 027570027de..0210c7bfaea 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -2681,6 +2681,7 @@ class NetworkdRATests(unittest.TestCase, Utilities): 'ipv6-prefix.network', 'ipv6-prefix-veth.network', 'ipv6-prefix-veth-token-static.network', + 'ipv6-prefix-veth-token-static-explicit.network', 'ipv6-prefix-veth-token-prefixstable.network'] def setUp(self): @@ -2715,6 +2716,15 @@ class NetworkdRATests(unittest.TestCase, Utilities): print(output) self.assertRegex(output, '2002:da8:1:0:1a:2b:3c:4d') + def test_ipv6_token_static_explicit(self): + copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth-token-static-explicit.network') + start_networkd() + self.wait_online(['veth99:routable', 'veth-peer:degraded']) + + output = check_output(*networkctl_cmd, '-n', '0', 'status', 'veth99', env=env) + print(output) + self.assertRegex(output, '2002:da8:1:0:1a:2b:3c:4d') + def test_ipv6_token_prefixstable(self): copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth-token-prefixstable.network') start_networkd() From f7ada4b8ec12d09748f95de6c9753e1a0657d51c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 10 Feb 2020 00:43:58 +0900 Subject: [PATCH 3/3] test-network: tentatively stops .socket units for udevd To suppress the following warning: --- Warning: Stopping systemd-udevd.service, but it can still be activated by: systemd-udevd-control.socket systemd-udevd-kernel.socket --- test/test-network/systemd-networkd-tests.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 0210c7bfaea..c1a84ca9ec0 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -165,7 +165,9 @@ def setUpModule(): shutil.rmtree(networkd_ci_path) copytree(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'conf'), networkd_ci_path) - for u in ['systemd-networkd.socket', 'systemd-networkd.service', 'systemd-resolved.service', 'systemd-udevd.service', 'firewalld.service']: + for u in ['systemd-networkd.socket', 'systemd-networkd.service', 'systemd-resolved.service', + 'systemd-udevd-kernel.socket', 'systemd-udevd-control.socket', 'systemd-udevd.service', + 'firewalld.service']: if call(f'systemctl is-active --quiet {u}') == 0: check_output(f'systemctl stop {u}') running_units.append(u) @@ -249,13 +251,14 @@ def tearDownModule(): shutil.rmtree(networkd_ci_path) - for u in ['systemd-networkd.service', 'systemd-resolved.service', 'systemd-udevd.service']: + for u in ['systemd-networkd.service', 'systemd-resolved.service']: check_output(f'systemctl stop {u}') shutil.rmtree('/run/systemd/system/systemd-networkd.service.d') shutil.rmtree('/run/systemd/system/systemd-resolved.service.d') shutil.rmtree('/run/systemd/system/systemd-udevd.service.d') check_output('systemctl daemon-reload') + check_output('systemctl restart systemd-udevd.service') for u in running_units: check_output(f'systemctl start {u}')