1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

test-network: add test for multiple IPv6 null addresses

This also merges test_address_null() into test_address_static().
This commit is contained in:
Yu Watanabe 2023-09-08 10:17:32 +09:00
parent 6174dc7d96
commit d5adff70c0
3 changed files with 54 additions and 45 deletions

View File

@ -1,14 +0,0 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Match]
Name=dummy98
[Network]
IPv6AcceptRA=no
Address=0.0.0.0/16
Address=0.0.0.0/30
Address=::/64
[Address]
Address=0.0.0.0/24
# The broadcast address will be ignored.
Broadcast=192.168.0.255

View File

@ -173,6 +173,9 @@ Label=subnet24
[Address]
Address=::/73
[Address]
Address=::/74
[Address]
Address=10.10.1.1/24
# just a random label which should exist

View File

@ -2383,6 +2383,10 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
flag2: str,
flag3: str,
flag4: str,
ip4_null_16: str,
ip4_null_24: str,
ip6_null_73: str,
ip6_null_74: str,
):
output = check_output('ip address show dev dummy98')
print(output)
@ -2442,9 +2446,14 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
self.assertIn(f'inet6 2001:db8:0:f106::2/64 scope global{flag4}', output)
# null address
self.assertRegex(output, r'inet [0-9]*.[0-9]*.0.1/16 brd [0-9]*.[0-9]*.255.255 scope global subnet16')
self.assertRegex(output, r'inet [0-9]*.[0-9]*.[0-9]*.1/24 brd [0-9]*.[0-9]*.[0-9]*.255 scope global subnet24')
self.assertRegex(output, r'inet6 [0-9a-f:]*:1/73 scope global')
self.assertTrue(ip4_null_16.endswith('.0.1'))
prefix16 = ip4_null_16[:-len('.0.1')]
self.assertTrue(ip4_null_24.endswith('.1'))
prefix24 = ip4_null_24[:-len('.1')]
self.assertIn(f'inet {ip4_null_16}/16 brd {prefix16}.255.255 scope global subnet16', output)
self.assertIn(f'inet {ip4_null_24}/24 brd {prefix24}.255 scope global subnet24', output)
self.assertIn(f'inet6 {ip6_null_73}/73 scope global', output)
self.assertIn(f'inet6 {ip6_null_74}/74 scope global', output)
# invalid sections
self.assertNotIn('10.4.4.1', output)
@ -2469,6 +2478,29 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
self.setup_nftset('ifindex', 'iface_index')
self.wait_online(['dummy98:routable'])
ip4_null_16 = None
ip4_null_24 = None
output = check_output('ip -4 --json address show dev dummy98')
for i in json.loads(output)[0]['addr_info']:
if i['label'] == 'subnet16':
ip4_null_16 = i['local']
elif i['label'] == 'subnet24':
ip4_null_24 = i['local']
self.assertTrue(ip4_null_16.endswith('.0.1'))
self.assertTrue(ip4_null_24.endswith('.1'))
ip6_null_73 = None
ip6_null_74 = None
output = check_output('ip -6 --json address show dev dummy98')
for i in json.loads(output)[0]['addr_info']:
if i['prefixlen'] == 73:
ip6_null_73 = i['local']
elif i['prefixlen'] == 74:
ip6_null_74 = i['local']
self.assertTrue(ip6_null_73.endswith(':1'))
self.assertTrue(ip6_null_74.endswith(':1'))
self.verify_address_static(
label1='label1',
label2='label2',
@ -2493,6 +2525,10 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
flag2='',
flag3=' noprefixroute',
flag4=' home mngtmpaddr',
ip4_null_16=ip4_null_16,
ip4_null_24=ip4_null_24,
ip6_null_73=ip6_null_73,
ip6_null_74=ip6_null_74,
)
# nft set
self.check_nftset('addr4', r'10\.10\.1\.1')
@ -2528,6 +2564,10 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
flag2=' noprefixroute',
flag3=' home mngtmpaddr',
flag4=' noprefixroute',
ip4_null_16=ip4_null_16,
ip4_null_24=ip4_null_24,
ip6_null_73=ip6_null_73,
ip6_null_74=ip6_null_74,
)
networkctl_reconfigure('dummy98')
@ -2556,6 +2596,10 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
flag2=' noprefixroute',
flag3=' home mngtmpaddr',
flag4=' noprefixroute',
ip4_null_16=ip4_null_16,
ip4_null_24=ip4_null_24,
ip6_null_73=ip6_null_73,
ip6_null_74=ip6_null_74,
)
# Tests for #20891.
@ -2594,6 +2638,10 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
flag2=' noprefixroute',
flag3=' home mngtmpaddr',
flag4=' noprefixroute',
ip4_null_16=ip4_null_16,
ip4_null_24=ip4_null_24,
ip6_null_73=ip6_null_73,
ip6_null_74=ip6_null_74,
)
# test for ENOBUFS issue #17012 (with reload)
@ -2611,34 +2659,6 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
for i in range(1, 254):
self.assertIn(f'inet 10.3.3.{i}/16 brd 10.3.255.255', output)
def test_address_null(self):
copy_network_unit('25-address-null.network', '12-dummy.netdev')
start_networkd()
self.wait_online(['dummy98:routable'])
output = check_output('ip address show dev dummy98 scope global')
print(output)
ipv4_address_16 = re.findall(r'inet 172.[0-9]*.0.1/16 brd 172.[0-9]*.255.255', output)
self.assertEqual(len(ipv4_address_16), 1)
ipv4_address_24 = re.findall(r'inet 192.168.[0-9]*.1/24 brd 192.168.[0-9]*.255', output)
self.assertEqual(len(ipv4_address_24), 1)
ipv4_address_30 = re.findall(r'inet 192.168.[0-9]*.[0-9]*/30 brd 192.168.[0-9]*.[0-9]*', output)
self.assertEqual(len(ipv4_address_30), 1)
ipv6_address = re.findall(r'inet6 fd[0-9a-f:]*/64', output)
self.assertEqual(len(ipv6_address), 1)
networkctl_reconfigure('dummy98')
self.wait_online(['dummy98:routable'])
output = check_output('ip address show dev dummy98 scope global')
print(output)
self.assertIn(ipv4_address_16[0], output)
self.assertIn(ipv4_address_24[0], output)
self.assertIn(ipv4_address_30[0], output)
self.assertIn(ipv6_address[0], output)
def test_address_ipv4acd(self):
check_output('ip netns add ns99')
check_output('ip link add veth99 type veth peer veth-peer')