diff options
Diffstat (limited to 'test/test-network')
-rw-r--r-- | test/test-network/conf/25-veth-router-high2.network | 18 | ||||
-rw-r--r-- | test/test-network/conf/25-veth-router-low2.network | 18 | ||||
-rwxr-xr-x | test/test-network/systemd-networkd-tests.py | 104 |
3 files changed, 50 insertions, 90 deletions
diff --git a/test/test-network/conf/25-veth-router-high2.network b/test/test-network/conf/25-veth-router-high2.network deleted file mode 100644 index 47e8cd715c..0000000000 --- a/test/test-network/conf/25-veth-router-high2.network +++ /dev/null @@ -1,18 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Match] -Name=router-low - -[Network] -IPv6AcceptRA=no -IPv6SendRA=yes - -[IPv6SendRA] -# changed from low to high -RouterPreference=high -EmitDNS=no -EmitDomains=no - -[IPv6Prefix] -Prefix=2002:da8:1:98::/64 -PreferredLifetimeSec=1000s -ValidLifetimeSec=2100s diff --git a/test/test-network/conf/25-veth-router-low2.network b/test/test-network/conf/25-veth-router-low2.network deleted file mode 100644 index f318938ca7..0000000000 --- a/test/test-network/conf/25-veth-router-low2.network +++ /dev/null @@ -1,18 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Match] -Name=router-high - -[Network] -IPv6AcceptRA=no -IPv6SendRA=yes - -[IPv6SendRA] -# changed from high to low -RouterPreference=low -EmitDNS=no -EmitDomains=no - -[IPv6Prefix] -Prefix=2002:da8:1:99::/64 -PreferredLifetimeSec=1000s -ValidLifetimeSec=2100s diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 65561a0138..462d40d839 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -6391,6 +6391,27 @@ class NetworkdRATests(unittest.TestCase, Utilities): self.check_ipv6_sysctl_attr('client', 'hop_limit', '43') + def check_router_preference(self, suffix, metric_1, preference_1, metric_2, preference_2): + self.wait_online('client:routable') + self.wait_address('client', f'2002:da8:1:99:1034:56ff:fe78:9a{suffix}/64', ipv='-6', timeout_sec=10) + self.wait_address('client', f'2002:da8:1:98:1034:56ff:fe78:9a{suffix}/64', ipv='-6', timeout_sec=10) + self.wait_route('client', rf'default nhid [0-9]* via fe80::1034:56ff:fe78:9a99 proto ra metric {metric_1}', ipv='-6', timeout_sec=10) + self.wait_route('client', rf'default nhid [0-9]* via fe80::1034:56ff:fe78:9a98 proto ra metric {metric_2}', ipv='-6', timeout_sec=10) + + print('### ip -6 route show dev client default') + output = check_output('ip -6 route show dev client default') + print(output) + self.assertRegex(output, rf'default nhid [0-9]* via fe80::1034:56ff:fe78:9a99 proto ra metric {metric_1} expires [0-9]*sec pref {preference_1}') + self.assertRegex(output, rf'default nhid [0-9]* via fe80::1034:56ff:fe78:9a98 proto ra metric {metric_2} expires [0-9]*sec pref {preference_2}') + + for i in [100, 200, 300, 512, 1024, 2048]: + if i not in [metric_1, metric_2]: + self.assertNotIn(f'{i}', output) + + for i in ['low', 'medium', 'high']: + if i not in [preference_1, preference_2]: + self.assertNotIn(f'{i}', output) + def test_router_preference(self): copy_network_unit('25-veth-client.netdev', '25-veth-router-high.netdev', @@ -6409,72 +6430,47 @@ class NetworkdRATests(unittest.TestCase, Utilities): networkctl_reconfigure('client') self.wait_online('client:routable') + self.check_router_preference('00', 512, 'high', 2048, 'low') - self.wait_address('client', '2002:da8:1:99:1034:56ff:fe78:9a00/64', ipv='-6', timeout_sec=10) - self.wait_address('client', '2002:da8:1:98:1034:56ff:fe78:9a00/64', ipv='-6', timeout_sec=10) - self.wait_route('client', r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a99 proto ra metric 512', ipv='-6', timeout_sec=10) - self.wait_route('client', r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a98 proto ra metric 2048', ipv='-6', timeout_sec=10) - - print('### ip -6 route show dev client default') - output = check_output('ip -6 route show dev client default') - print(output) - self.assertRegex(output, r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a99 proto ra metric 512 expires [0-9]*sec pref high') - self.assertRegex(output, r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a98 proto ra metric 2048 expires [0-9]*sec pref low') - + # change the map from preference to metric. with open(os.path.join(network_unit_dir, '25-veth-client.network'), mode='a', encoding='utf-8') as f: f.write('\n[Link]\nMACAddress=12:34:56:78:9a:01\n[IPv6AcceptRA]\nRouteMetric=100:200:300\n') - networkctl_reload() - self.wait_online('client:routable') - - self.wait_address('client', '2002:da8:1:99:1034:56ff:fe78:9a01/64', ipv='-6', timeout_sec=10) - self.wait_address('client', '2002:da8:1:98:1034:56ff:fe78:9a01/64', ipv='-6', timeout_sec=10) - self.wait_route('client', r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a99 proto ra metric 100', ipv='-6', timeout_sec=10) - self.wait_route('client', r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a98 proto ra metric 300', ipv='-6', timeout_sec=10) - - print('### ip -6 route show dev client default') - output = check_output('ip -6 route show dev client default') - print(output) - self.assertRegex(output, r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a99 proto ra metric 100 expires [0-9]*sec pref high') - self.assertRegex(output, r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a98 proto ra metric 300 expires [0-9]*sec pref low') - self.assertNotIn('metric 512', output) - self.assertNotIn('metric 2048', output) + self.check_router_preference('01', 100, 'high', 300, 'low') # swap the preference (for issue #28439) - remove_network_unit('25-veth-router-high.network', '25-veth-router-low.network') - copy_network_unit('25-veth-router-high2.network', '25-veth-router-low2.network') + with open(os.path.join(network_unit_dir, '25-veth-router-high.network'), mode='a', encoding='utf-8') as f: + f.write('\n[IPv6SendRA]\nRouterPreference=low\n') + with open(os.path.join(network_unit_dir, '25-veth-router-low.network'), mode='a', encoding='utf-8') as f: + f.write('\n[IPv6SendRA]\nRouterPreference=high\n') networkctl_reload() - self.wait_route('client', r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a99 proto ra metric 300', ipv='-6', timeout_sec=10) - self.wait_route('client', r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a98 proto ra metric 100', ipv='-6', timeout_sec=10) - - print('### ip -6 route show dev client default') - output = check_output('ip -6 route show dev client default') - print(output) - self.assertRegex(output, r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a99 proto ra metric 300 expires [0-9]*sec pref low') - self.assertRegex(output, r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a98 proto ra metric 100 expires [0-9]*sec pref high') - self.assertNotRegex(output, r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a99 proto ra metric 100') - self.assertNotRegex(output, r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a98 proto ra metric 300') - self.assertNotIn('metric 512', output) - self.assertNotIn('metric 2048', output) + self.check_router_preference('01', 300, 'low', 100, 'high') # Use the same preference, and check if the two routes are not coalesced. See issue #33470. - with open(os.path.join(network_unit_dir, '25-veth-router-high2.network'), mode='a', encoding='utf-8') as f: + with open(os.path.join(network_unit_dir, '25-veth-router-high.network'), mode='a', encoding='utf-8') as f: f.write('\n[IPv6SendRA]\nRouterPreference=medium\n') - with open(os.path.join(network_unit_dir, '25-veth-router-low2.network'), mode='a', encoding='utf-8') as f: + with open(os.path.join(network_unit_dir, '25-veth-router-low.network'), mode='a', encoding='utf-8') as f: f.write('\n[IPv6SendRA]\nRouterPreference=medium\n') networkctl_reload() - self.wait_route('client', r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a99 proto ra metric 200', ipv='-6', timeout_sec=10) - self.wait_route('client', r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a98 proto ra metric 200', ipv='-6', timeout_sec=10) - - print('### ip -6 route show dev client default') - output = check_output('ip -6 route show dev client default') - print(output) - self.assertRegex(output, r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a99 proto ra metric 200 expires [0-9]*sec pref medium') - self.assertRegex(output, r'default nhid [0-9]* via fe80::1034:56ff:fe78:9a98 proto ra metric 200 expires [0-9]*sec pref medium') - self.assertNotIn('pref high', output) - self.assertNotIn('pref low', output) - self.assertNotIn('metric 512', output) - self.assertNotIn('metric 2048', output) + self.check_router_preference('01', 200, 'medium', 200, 'medium') + + # Use route options to configure default routes. + # The preference specified in the RA header should be ignored. See issue #33468. + with open(os.path.join(network_unit_dir, '25-veth-router-high.network'), mode='a', encoding='utf-8') as f: + f.write('\n[IPv6SendRA]\nRouterPreference=high\n[IPv6RoutePrefix]\nRoute=::/0\nLifetimeSec=1200\n') + with open(os.path.join(network_unit_dir, '25-veth-router-low.network'), mode='a', encoding='utf-8') as f: + f.write('\n[IPv6SendRA]\nRouterPreference=low\n[IPv6RoutePrefix]\nRoute=::/0\nLifetimeSec=1200\n') + networkctl_reload() + self.check_router_preference('01', 200, 'medium', 200, 'medium') + + # Set zero lifetime to the route options. + # The preference specified in the RA header should be used. + with open(os.path.join(network_unit_dir, '25-veth-router-high.network'), mode='a', encoding='utf-8') as f: + f.write('LifetimeSec=0\n') + with open(os.path.join(network_unit_dir, '25-veth-router-low.network'), mode='a', encoding='utf-8') as f: + f.write('LifetimeSec=0\n') + networkctl_reload() + self.check_router_preference('01', 100, 'high', 300, 'low') def _test_ndisc_vs_static_route(self, manage_foreign_nexthops): if not manage_foreign_nexthops: |