HALF ECHO LEARN / REFERENCE COLLECTION
v262.2test/test-network/systemd-networkd-tests.py
Git blob: aaf8830b28df24259c9ca79d57929ab5449e46af
Lines 4001–5000 of 11,559
'25-l2tp-udp.netdev',
'25-l2tp.network',
)
start_networkd()
self.wait_online('test1:routable', 'l2tp-ses1:degraded', 'l2tp-ses2:degraded')
self.networkctl_check_unit('test1', '11-dummy', '25-l2tp-dummy')
self.networkctl_check_unit('l2tp-ses1', '25-l2tp-udp', '25-l2tp')
self.networkctl_check_unit('l2tp-ses2', '25-l2tp-udp', '25-l2tp')
output = check_output('ip l2tp show tunnel tunnel_id 10')
print(output)
self.assertRegex(output, 'Tunnel 10, encap UDP')
self.assertRegex(output, 'From 192.168.30.100 to 192.168.30.101')
self.assertRegex(output, 'Peer tunnel 11')
self.assertRegex(output, 'UDP source / dest ports: 3000/4000')
self.assertRegex(output, 'UDP checksum: enabled')
output = check_output('ip l2tp show session tid 10 session_id 15')
print(output)
self.assertRegex(output, 'Session 15 in tunnel 10')
self.assertRegex(output, 'Peer session 16, tunnel 11')
self.assertRegex(output, 'interface name: l2tp-ses1')
output = check_output('ip l2tp show session tid 10 session_id 17')
print(output)
self.assertRegex(output, 'Session 17 in tunnel 10')
self.assertRegex(output, 'Peer session 18, tunnel 11')
self.assertRegex(output, 'interface name: l2tp-ses2')
touch_network_unit(
'11-dummy.netdev',
'25-l2tp-dummy.network',
'25-l2tp-udp.netdev',
'25-l2tp.network',
)
networkctl_reload()
self.wait_online('test1:routable', 'l2tp-ses1:degraded', 'l2tp-ses2:degraded')
@expectedFailureIfModuleIsNotAvailable('l2tp_eth', 'l2tp_ip', 'l2tp_netlink')
def test_l2tp_ip(self):
copy_network_unit(
'11-dummy.netdev',
'25-l2tp-dummy.network',
'25-l2tp-ip.netdev',
'25-l2tp.network',
)
start_networkd()
self.wait_online('test1:routable', 'l2tp-ses3:degraded', 'l2tp-ses4:degraded')
self.networkctl_check_unit('test1', '11-dummy', '25-l2tp-dummy')
self.networkctl_check_unit('l2tp-ses3', '25-l2tp-ip', '25-l2tp')
self.networkctl_check_unit('l2tp-ses4', '25-l2tp-ip', '25-l2tp')
output = check_output('ip l2tp show tunnel tunnel_id 10')
print(output)
self.assertRegex(output, 'Tunnel 10, encap IP')
self.assertRegex(output, 'From 192.168.30.100 to 192.168.30.101')
self.assertRegex(output, 'Peer tunnel 12')
output = check_output('ip l2tp show session tid 10 session_id 25')
print(output)
self.assertRegex(output, 'Session 25 in tunnel 10')
self.assertRegex(output, 'Peer session 26, tunnel 12')
self.assertRegex(output, 'interface name: l2tp-ses3')
output = check_output('ip l2tp show session tid 10 session_id 27')
print(output)
self.assertRegex(output, 'Session 27 in tunnel 10')
self.assertRegex(output, 'Peer session 28, tunnel 12')
self.assertRegex(output, 'interface name: l2tp-ses4')
touch_network_unit(
'11-dummy.netdev',
'25-l2tp-dummy.network',
'25-l2tp-ip.netdev',
'25-l2tp.network',
)
networkctl_reload()
self.wait_online('test1:routable', 'l2tp-ses3:degraded', 'l2tp-ses4:degraded')
class NetworkdNetworkTests(unittest.TestCase, Utilities):
def setUp(self):
setup_common()
def tearDown(self):
tear_down_common()
def test_ID_NET_MANAGED_BY(self):
copy_network_unit('11-dummy.netdev', '11-dummy-unmanaged.link', '11-dummy.network')
start_networkd()
self.wait_online('test1:off', setup_state='unmanaged')
check_output('ip link set dev test1 up')
self.wait_online('test1:degraded', setup_state='unmanaged')
check_output('ip link set dev test1 down')
self.wait_online('test1:off', setup_state='unmanaged')
def verify_address_static(
self,
label1: str,
label2: str,
label3: str,
broadcast1: str,
broadcast2: str,
broadcast3: str,
peer1: str,
peer2: str,
peer3: str,
peer4: str,
peer5: str,
peer6: str,
scope1: str,
scope2: str,
deprecated1: str,
deprecated2: str,
deprecated3: str,
deprecated4: str,
route_metric: int,
flag1: str,
flag2: str,
flag3: str,
flag4: str,
ip4_null_16: str,
ip4_null_24: str,
ip4_null_32: str,
ip6_null_73: str,
ip6_null_74: str,
ip6_null_128: str,
):
output = check_output('ip address show dev dummy98')
print(output)
# simple settings
self.assertIn('inet 10.1.2.3/16 brd 10.1.255.255 scope global dummy98', output)
self.assertIn('inet 10.1.2.4/16 brd 10.1.255.255 scope global secondary dummy98', output)
self.assertIn('inet 10.2.2.4/16 brd 10.2.255.255 scope global dummy98', output)
self.assertIn('inet6 2001:db8:0:f101::15/64 scope global', output)
self.assertIn('inet6 2001:db8:0:f101::16/64 scope global', output)
self.assertIn('inet6 2001:db8:0:f102::15/64 scope global', output)
# label
self.assertIn(f'inet 10.3.1.1/24 brd 10.3.1.255 scope global {label1}', output)
self.assertIn(f'inet 10.3.2.1/24 brd 10.3.2.255 scope global {label2}', output)
self.assertIn(f'inet 10.3.3.1/24 brd 10.3.3.255 scope global {label3}', output)
# broadcast
self.assertIn(f'inet 10.4.1.1/24{broadcast1} scope global dummy98', output)
self.assertIn(f'inet 10.4.2.1/24{broadcast2} scope global dummy98', output)
self.assertIn(f'inet 10.4.3.1/24{broadcast3} scope global dummy98', output)
# peer
self.assertIn(f'inet 10.5.1.1{peer1} scope global dummy98', output)
self.assertIn(f'inet 10.5.2.1{peer2} scope global dummy98', output)
self.assertIn(f'inet 10.5.3.1{peer3} scope global dummy98', output)
self.assertIn(f'inet6 2001:db8:0:f103::1{peer4} scope global', output)
self.assertIn(f'inet6 2001:db8:0:f103::2{peer5} scope global', output)
self.assertIn(f'inet6 2001:db8:0:f103::3{peer6} scope global', output)
# scope
self.assertIn(f'inet 10.6.1.1/24 brd 10.6.1.255 scope {scope1} dummy98', output)
self.assertIn(f'inet 10.6.2.1/24 brd 10.6.2.255 scope {scope2} dummy98', output)
# lifetime
self.assertIn(f'inet 10.7.1.1/24 brd 10.7.1.255 scope global{deprecated1} dummy98', output)
self.assertIn(f'inet 10.7.2.1/24 brd 10.7.2.255 scope global{deprecated2} dummy98', output)
self.assertIn(f'inet6 2001:db8:0:f104::1/64 scope global{deprecated3}', output)
self.assertIn(f'inet6 2001:db8:0:f104::2/64 scope global{deprecated4}', output)
# route metric
self.assertRegex(output, rf'inet 10.8.1.1/24 (metric {route_metric} |)brd 10.8.1.255 scope global dummy98') # fmt: skip
self.assertRegex(output, rf'inet6 2001:db8:0:f105::1/64 (metric {route_metric} |)scope global')
output_route = check_output('ip -4 route show dev dummy98 10.8.1.0/24')
print(output_route)
self.assertIn(f'10.8.1.0/24 proto kernel scope link src 10.8.1.1 metric {route_metric}', output_route) # fmt: skip
output_route = check_output('ip -6 route show dev dummy98 2001:db8:0:f105::/64')
print(output_route)
self.assertIn(f'2001:db8:0:f105::/64 proto kernel metric {route_metric}', output_route)
# flags
self.assertIn(f'inet 10.9.1.1/24 brd 10.9.1.255 scope global{flag1} dummy98', output)
self.assertIn(f'inet 10.9.2.1/24 brd 10.9.2.255 scope global{flag2} dummy98', output)
self.assertIn(f'inet6 2001:db8:0:f106::1/64 scope global{flag3}', output)
self.assertIn(f'inet6 2001:db8:0:f106::2/64 scope global{flag4}', output)
# null address
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'inet {ip4_null_32}/32 scope global host32', output)
self.assertIn(f'inet6 {ip6_null_73}/73 scope global', output)
self.assertIn(f'inet6 {ip6_null_74}/74 scope global', output)
self.assertIn(f'inet6 {ip6_null_128}/128 scope global', output)
# invalid sections
self.assertNotIn('10.4.4.1', output)
self.assertNotIn('10.5.4.1', output)
self.assertNotIn('10.5.5.1', output)
self.assertNotIn('10.8.2.1', output)
self.assertNotIn('10.9.3.1', output)
self.assertNotIn('2001:db8:0:f101::2', output)
self.assertNotIn('2001:db8:0:f103::4', output)
# netlabel
self.check_netlabel('dummy98', r'10\.10\.1\.0/24')
check_json(networkctl_json())
def test_address_static(self):
copy_network_unit('25-address-static.network', '12-dummy.netdev', copy_dropins=False)
self.setup_nftset('addr4', 'ipv4_addr')
self.setup_nftset('network4', 'ipv4_addr', 'flags interval;')
self.setup_nftset('ifindex', 'iface_index')
start_networkd()
self.wait_online('dummy98:routable')
ip4_null_16 = None
ip4_null_24 = None
ip4_null_32 = 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']
elif i['label'] == 'host32':
ip4_null_32 = i['local']
self.assertTrue(ip4_null_16.endswith('.0.1'))
self.assertTrue(ip4_null_24.endswith('.1'))
self.assertIsNotNone(ip4_null_32)
ip6_null_73 = None
ip6_null_74 = None
ip6_null_128 = 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']
elif i['prefixlen'] == 128 and i['local'].startswith('fd'):
ip6_null_128 = i['local']
self.assertTrue(ip6_null_73.endswith(':1'))
self.assertTrue(ip6_null_74.endswith(':1'))
self.assertIsNotNone(ip6_null_128)
self.verify_address_static(
label1='label1',
label2='label2',
label3='dummy98',
broadcast1='',
broadcast2=' brd 10.4.2.255',
broadcast3=' brd 10.4.3.63',
peer1=' peer 10.5.1.101/24',
peer2=' peer 10.5.2.101/24',
peer3='/24 brd 10.5.3.255',
peer4=' peer 2001:db8:0:f103::101/128',
peer5=' peer 2001:db8:0:f103::102/128',
peer6='/128',
scope1='global',
scope2='link',
deprecated1='',
deprecated2=' deprecated',
deprecated3='',
deprecated4=' deprecated',
route_metric=128,
flag1=' noprefixroute',
flag2='',
flag3=' noprefixroute',
flag4=' home mngtmpaddr',
ip4_null_16=ip4_null_16,
ip4_null_24=ip4_null_24,
ip4_null_32=ip4_null_32,
ip6_null_73=ip6_null_73,
ip6_null_74=ip6_null_74,
ip6_null_128=ip6_null_128,
)
# nft set
self.check_nftset('addr4', r'10\.10\.1\.1')
self.check_nftset('network4', r'10\.10\.1\.0/24')
self.check_nftset('ifindex', 'dummy98')
self.teardown_nftset('addr4', 'network4', 'ifindex')
copy_network_unit('25-address-static.network.d/10-override.conf')
networkctl_reload()
self.wait_online('dummy98:routable')
self.verify_address_static(
label1='new-label1',
label2='dummy98',
label3='new-label3',
broadcast1=' brd 10.4.1.255',
broadcast2='',
broadcast3=' brd 10.4.3.31',
peer1=' peer 10.5.1.102/24',
peer2='/24 brd 10.5.2.255',
peer3=' peer 10.5.3.102/24',
peer4=' peer 2001:db8:0:f103::201/128',
peer5='/128',
peer6=' peer 2001:db8:0:f103::203/128',
scope1='link',
scope2='global',
deprecated1=' deprecated',
deprecated2='',
deprecated3=' deprecated',
deprecated4='',
route_metric=256,
flag1='',
flag2=' noprefixroute',
flag3=' home mngtmpaddr',
flag4=' noprefixroute',
ip4_null_16=ip4_null_16,
ip4_null_24=ip4_null_24,
ip4_null_32=ip4_null_32,
ip6_null_73=ip6_null_73,
ip6_null_74=ip6_null_74,
ip6_null_128=ip6_null_128,
)
networkctl_reconfigure('dummy98')
self.wait_online('dummy98:routable')
self.verify_address_static(
label1='new-label1',
label2='dummy98',
label3='new-label3',
broadcast1=' brd 10.4.1.255',
broadcast2='',
broadcast3=' brd 10.4.3.31',
peer1=' peer 10.5.1.102/24',
peer2='/24 brd 10.5.2.255',
peer3=' peer 10.5.3.102/24',
peer4=' peer 2001:db8:0:f103::201/128',
peer5='/128',
peer6=' peer 2001:db8:0:f103::203/128',
scope1='link',
scope2='global',
deprecated1=' deprecated',
deprecated2='',
deprecated3=' deprecated',
deprecated4='',
route_metric=256,
flag1='',
flag2=' noprefixroute',
flag3=' home mngtmpaddr',
flag4=' noprefixroute',
ip4_null_16=ip4_null_16,
ip4_null_24=ip4_null_24,
ip4_null_32=ip4_null_32,
ip6_null_73=ip6_null_73,
ip6_null_74=ip6_null_74,
ip6_null_128=ip6_null_128,
)
# Tests for #20891.
# 1. set preferred lifetime forever to drop the deprecated flag for testing #20891.
check_output('ip address change 10.7.1.1/24 dev dummy98 preferred_lft forever')
check_output('ip address change 2001:db8:0:f104::1/64 dev dummy98 preferred_lft forever')
output = check_output('ip address show dev dummy98')
print(output)
self.assertNotRegex(output, '10.7.1.1/24 .* deprecated')
self.assertNotRegex(output, '2001:db8:0:f104::1/64 .* deprecated')
# 2. reconfigure the interface, and check the deprecated flag is set again
networkctl_reconfigure('dummy98')
self.wait_online('dummy98:routable')
self.verify_address_static(
label1='new-label1',
label2='dummy98',
label3='new-label3',
broadcast1=' brd 10.4.1.255',
broadcast2='',
broadcast3=' brd 10.4.3.31',
peer1=' peer 10.5.1.102/24',
peer2='/24 brd 10.5.2.255',
peer3=' peer 10.5.3.102/24',
peer4=' peer 2001:db8:0:f103::201/128',
peer5='/128',
peer6=' peer 2001:db8:0:f103::203/128',
scope1='link',
scope2='global',
deprecated1=' deprecated',
deprecated2='',
deprecated3=' deprecated',
deprecated4='',
route_metric=256,
flag1='',
flag2=' noprefixroute',
flag3=' home mngtmpaddr',
flag4=' noprefixroute',
ip4_null_16=ip4_null_16,
ip4_null_24=ip4_null_24,
ip4_null_32=ip4_null_32,
ip6_null_73=ip6_null_73,
ip6_null_74=ip6_null_74,
ip6_null_128=ip6_null_128,
)
# test for ENOBUFS issue #17012 (with reload)
copy_network_unit('25-address-static.network.d/10-many-address.conf')
networkctl_reload()
self.wait_online('dummy98:routable')
output = check_output('ip -4 address show dev dummy98')
for i in range(1, 254):
self.assertIn(f'inet 10.3.3.{i}/16 brd 10.3.255.255', output)
# (with reconfigure)
networkctl_reconfigure('dummy98')
self.wait_online('dummy98:routable')
output = check_output('ip -4 address show dev dummy98')
for i in range(1, 254):
self.assertIn(f'inet 10.3.3.{i}/16 brd 10.3.255.255', output)
# test for an empty string assignment for Address= in [Network]
copy_network_unit('25-address-static.network.d/20-clear-addresses.conf')
networkctl_reload()
self.wait_online('dummy98:routable')
output = check_output('ip -4 address show dev dummy98')
for i in range(1, 254):
self.assertNotIn(f'inet 10.3.3.{i}/16 brd 10.3.255.255', output)
self.assertIn('inet 10.4.0.1/16 brd 10.4.255.255', output)
def test_address_ipv4acd(self):
check_output('ip netns add ns99')
check_output('ip link add veth99 type veth peer veth-peer')
check_output('ip link set veth-peer netns ns99')
check_output('ip link set veth99 up')
check_output('ip netns exec ns99 ip link set veth-peer up')
check_output('ip netns exec ns99 ip address add 192.168.100.10/24 dev veth-peer')
copy_network_unit('25-address-ipv4acd-veth99.network', copy_dropins=False)
start_networkd()
self.wait_online('veth99:routable')
output = check_output('ip -4 address show dev veth99')
print(output)
self.assertNotIn('192.168.100.10/24', output)
self.assertIn('192.168.100.11/24', output)
copy_network_unit('25-address-ipv4acd-veth99.network.d/conflict-address.conf')
networkctl_reload()
self.wait_operstate('veth99', operstate='routable', setup_state='configuring', setup_timeout=10)
output = check_output('ip -4 address show dev veth99')
print(output)
self.assertNotIn('192.168.100.10/24', output)
self.assertIn('192.168.100.11/24', output)
def test_address_peer_ipv4(self):
# test for issue #17304
copy_network_unit('25-address-peer-ipv4.network', '12-dummy.netdev')
for trial in range(2):
if trial == 0:
start_networkd()
else:
restart_networkd()
self.wait_online('dummy98:routable')
output = check_output('ip -4 address show dev dummy98')
self.assertIn('inet 100.64.0.1 peer 100.64.0.2/32 scope global', output)
@expectedFailureIfModuleIsNotAvailable('vrf')
def test_prefix_route(self):
copy_network_unit(
'25-prefix-route-with-vrf.network',
'12-dummy.netdev',
'25-prefix-route-without-vrf.network',
'11-dummy.netdev',
'25-vrf.netdev',
'25-vrf.network',
)
for trial in range(2):
if trial == 0:
start_networkd()
else:
restart_networkd()
self.wait_online('dummy98:routable', 'test1:routable', 'vrf99:carrier')
output = check_output('ip route show table 42 dev dummy98')
print('### ip route show table 42 dev dummy98')
print(output)
self.assertRegex(output, 'local 10.20.22.1 proto kernel scope host src 10.20.22.1')
self.assertRegex(output, '10.20.33.0/24 proto kernel scope link src 10.20.33.1')
self.assertRegex(output, 'local 10.20.33.1 proto kernel scope host src 10.20.33.1')
self.assertRegex(output, 'broadcast 10.20.33.255 proto kernel scope link src 10.20.33.1')
self.assertRegex(output, 'local 10.20.44.1 proto kernel scope host src 10.20.44.1')
self.assertRegex(output, 'local 10.20.55.1 proto kernel scope host src 10.20.55.1')
self.assertRegex(output, 'broadcast 10.20.55.255 proto kernel scope link src 10.20.55.1')
output = check_output('ip -6 route show table 42 dev dummy98')
print('### ip -6 route show table 42 dev dummy98')
print(output)
if trial == 0:
# Kernel's bug?
self.assertRegex(output, 'local fdde:11:22::1 proto kernel metric 0 pref medium')
# self.assertRegex(output, 'fdde:11:22::1 proto kernel metric 256 pref medium')
self.assertRegex(output, 'local fdde:11:33::1 proto kernel metric 0 pref medium')
self.assertRegex(output, 'fdde:11:33::/64 proto kernel metric 256 pref medium')
self.assertRegex(output, 'local fdde:11:44::1 proto kernel metric 0 pref medium')
self.assertRegex(output, 'local fdde:11:55::1 proto kernel metric 0 pref medium')
self.assertRegex(output, 'fe80::/64 proto kernel metric 256 pref medium')
self.assertRegex(output, 'ff00::/8 (proto kernel )?metric 256 (linkdown )?pref medium')
print()
output = check_output('ip route show dev test1')
print('### ip route show dev test1')
print(output)
self.assertRegex(output, '10.21.33.0/24 proto kernel scope link src 10.21.33.1')
output = check_output('ip route show table local dev test1')
print('### ip route show table local dev test1')
print(output)
self.assertRegex(output, 'local 10.21.22.1 proto kernel scope host src 10.21.22.1')
self.assertRegex(output, 'local 10.21.33.1 proto kernel scope host src 10.21.33.1')
self.assertRegex(output, 'broadcast 10.21.33.255 proto kernel scope link src 10.21.33.1')
self.assertRegex(output, 'local 10.21.44.1 proto kernel scope host src 10.21.44.1')
self.assertRegex(output, 'local 10.21.55.1 proto kernel scope host src 10.21.55.1')
self.assertRegex(output, 'broadcast 10.21.55.255 proto kernel scope link src 10.21.55.1')
output = check_output('ip -6 route show dev test1')
print('### ip -6 route show dev test1')
print(output)
self.assertRegex(output, 'fdde:12:22::1 proto kernel metric 256 pref medium')
self.assertRegex(output, 'fdde:12:33::/64 proto kernel metric 256 pref medium')
self.assertRegex(output, 'fe80::/64 proto kernel metric 256 pref medium')
output = check_output('ip -6 route show table local dev test1')
print('### ip -6 route show table local dev test1')
print(output)
self.assertRegex(output, 'local fdde:12:22::1 proto kernel metric 0 pref medium')
self.assertRegex(output, 'local fdde:12:33::1 proto kernel metric 0 pref medium')
self.assertRegex(output, 'local fdde:12:44::1 proto kernel metric 0 pref medium')
self.assertRegex(output, 'local fdde:12:55::1 proto kernel metric 0 pref medium')
self.assertRegex(output, 'ff00::/8 (proto kernel )?metric 256 (linkdown )?pref medium')
def test_configure_without_carrier(self):
copy_network_unit('11-dummy.netdev')
start_networkd()
self.wait_operstate('test1', 'off', '')
check_output('ip link set dev test1 up carrier off')
copy_network_unit('25-test1.network.d/configure-without-carrier.conf', copy_dropins=False)
restart_networkd()
self.wait_online('test1:no-carrier')
carrier_map = {'on': '1', 'off': '0'}
routable_map = {'on': 'routable', 'off': 'no-carrier'}
for carrier in ['off', 'on', 'off']:
with self.subTest(carrier=carrier):
if carrier_map[carrier] != read_link_attr('test1', 'carrier'):
check_output(f'ip link set dev test1 carrier {carrier}')
self.wait_online(f'test1:{routable_map[carrier]}:{routable_map[carrier]}')
output = networkctl_status('test1')
print(output)
self.assertRegex(output, '192.168.0.15')
self.assertRegex(output, '192.168.0.1')
self.assertRegex(output, routable_map[carrier])
def test_configure_without_carrier_yes_ignore_carrier_loss_no(self):
copy_network_unit('11-dummy.netdev')
start_networkd()
self.wait_operstate('test1', 'off', '')
check_output('ip link set dev test1 up carrier off')
copy_network_unit('25-test1.network')
restart_networkd()
self.wait_online('test1:no-carrier')
carrier_map = {'on': '1', 'off': '0'}
routable_map = {'on': 'routable', 'off': 'no-carrier'}
for carrier, have_config in [('off', True), ('on', True), ('off', False)]:
with self.subTest(carrier=carrier, have_config=have_config):
if carrier_map[carrier] != read_link_attr('test1', 'carrier'):
check_output(f'ip link set dev test1 carrier {carrier}')
self.wait_online(f'test1:{routable_map[carrier]}:{routable_map[carrier]}')
output = networkctl_status('test1')
print(output)
if have_config:
self.assertRegex(output, '192.168.0.15')
self.assertRegex(output, '192.168.0.1')
else:
self.assertNotRegex(output, '192.168.0.15')
self.assertNotRegex(output, '192.168.0.1')
self.assertRegex(output, routable_map[carrier])
def check_routing_policy_rule_test1(self):
print('### Checking routing policy rules requested by test1')
output = check_output('ip rule list iif test1 priority 111')
print(output)
self.assertRegex(output, r'111: from 192.168.100.18 tos (0x08|throughput) iif test1 oif test1 lookup 7') # fmt: skip
output = check_output('ip -6 rule list iif test1 priority 100')
print(output)
self.assertIn('100: from all iif test1 lookup 8', output)
output = check_output('ip rule list iif test1 priority 101')
print(output)
self.assertIn('101: from all iif test1 lookup 9', output)
output = check_output('ip -6 rule list iif test1 priority 101')
print(output)
self.assertIn('101: from all iif test1 lookup 9', output)
output = check_output('ip rule list iif test1 priority 102')
print(output)
self.assertIn('102: from 0.0.0.0/8 iif test1 lookup 10', output)
output = check_output('ip rule list iif test1 priority 103')
print(output)
self.assertIn('103: from 10.0.0.0/16 iif test1 lookup 11 goto 111', output)
output = check_output('ip rule list iif test1 priority 104')
print(output)
self.assertIn('104: from 10.1.0.0/16 iif test1 lookup 12 nop', output)
output = check_output('ip rule list iif test1 priority 200')
print(output)
self.assertIn('200: from all fwmark 0/0x1 iif test1 lookup 20', output)
output = check_output('ip rule list iif test1 priority 201')
print(output)
self.assertIn('201: from all fwmark 0x7/0xff iif test1 lookup 21', output)
output = check_output('ip rule list iif test1 priority 202')
print(output)
self.assertIn('202: from all fwmark 0x270f iif test1 lookup 22', output)
output = check_output('ip rule list to 192.0.2.0/26')
print(output)
self.assertIn('to 192.0.2.0/26 lookup 1001', output)
output = check_output('ip rule list to 192.0.2.64/26')
print(output)
self.assertIn('to 192.0.2.64/26 lookup 1001', output)
output = check_output('ip rule list to 192.0.2.128/26')
print(output)
self.assertIn('to 192.0.2.128/26 lookup 1001', output)
output = check_output('ip rule list to 192.0.2.192/26')
print(output)
self.assertIn('to 192.0.2.192/26 lookup 1001', output)
def check_routing_policy_rule_dummy98(self):
print('### Checking routing policy rules requested by dummy98')
output = check_output('ip rule list priority 112')
print(output)
self.assertRegex(output, r'112: from 192.168.101.18 tos (0x08|throughput) iif dummy98 oif dummy98 lookup 8') # fmt: skip
def _test_routing_policy_rule(self, manage_foreign_routes):
if not manage_foreign_routes:
copy_networkd_conf_dropin('networkd-manage-foreign-rules-no.conf')
copy_network_unit('25-routing-policy-rule-test1.network', '11-dummy.netdev')
stop_networkd()
check_output('ip -4 rule add priority 20001 table 9999 from 10.10.0.0/16')
check_output('ip -6 rule add priority 20001 table 9999 from 2001:db8:0:1::/64')
start_networkd()
self.wait_online('test1:degraded')
self.check_routing_policy_rule_test1()
check_json(networkctl_json())
output = check_output('ip -4 rule list priority 20001 table 9999 from 10.10.0.0/16')
print(output)
if manage_foreign_routes:
self.assertEqual(output, '')
else:
self.assertIn(output, '20001: from 10.10.0.0/16 lookup 9999')
check_output('ip -4 rule del priority 20001 table 9999 from 10.10.0.0/16')
output = check_output('ip -6 rule list priority 20001 table 9999 from 2001:db8:0:1::/64')
print(output)
if manage_foreign_routes:
self.assertEqual(output, '')
else:
self.assertIn(output, '20001: from 2001:db8:0:1::/64 lookup 9999')
check_output('ip -6 rule del priority 20001 table 9999 from 2001:db8:0:1::/64')
def test_routing_policy_rule(self):
first = True
for manage_foreign_routes in [True, False]:
if first:
first = False
else:
self.tearDown()
print(f'### test_routing_policy_rule(manage_foreign_routes={manage_foreign_routes})')
with self.subTest(manage_foreign_routes=manage_foreign_routes):
self._test_routing_policy_rule(manage_foreign_routes)
def test_routing_policy_rule_restart_and_reconfigure(self):
copy_network_unit(
'25-routing-policy-rule-test1.network',
'11-dummy.netdev',
'25-routing-policy-rule-dummy98.network',
'12-dummy.netdev',
)
# For #11280 and #34068.
for trial in range(3):
restart_networkd(show_logs=(trial > 0))
self.wait_online('test1:degraded', 'dummy98:degraded')
self.check_routing_policy_rule_test1()
self.check_routing_policy_rule_dummy98()
networkctl_reconfigure('test1')
self.wait_online('test1:degraded')
self.check_routing_policy_rule_test1()
self.check_routing_policy_rule_dummy98()
networkctl_reconfigure('dummy98')
self.wait_online('dummy98:degraded')
self.check_routing_policy_rule_test1()
self.check_routing_policy_rule_dummy98()
def test_routing_policy_rule_reconfigure(self):
copy_network_unit('25-routing-policy-rule-reconfigure2.network', '11-dummy.netdev')
start_networkd()
self.wait_online('test1:degraded')
output = check_output('ip rule list table 1011')
print(output)
self.assertIn('10111: from all fwmark 0x3f3 lookup 1011', output)
self.assertIn('10112: from all oif test1 lookup 1011', output)
self.assertIn('10113: from all iif test1 lookup 1011', output)
self.assertIn('10114: from 192.168.8.254 lookup 1011', output)
output = check_output('ip -6 rule list table 1011')
print(output)
self.assertIn('10112: from all oif test1 lookup 1011', output)
copy_network_unit('25-routing-policy-rule-reconfigure1.network', '11-dummy.netdev')
networkctl_reload()
self.wait_online('test1:degraded')
output = check_output('ip rule list table 1011')
print(output)
self.assertIn('10111: from all fwmark 0x3f3 lookup 1011', output)
self.assertIn('10112: from all oif test1 lookup 1011', output)
self.assertIn('10113: from all iif test1 lookup 1011', output)
self.assertIn('10114: from 192.168.8.254 lookup 1011', output)
output = check_output('ip -6 rule list table 1011')
print(output)
self.assertNotIn('10112: from all oif test1 lookup 1011', output)
self.assertIn('10113: from all iif test1 lookup 1011', output)
call('ip rule delete priority 10111')
call('ip rule delete priority 10112')
call('ip rule delete priority 10113')
call('ip rule delete priority 10114')
call('ip -6 rule delete priority 10113')
output = check_output('ip rule list table 1011')
print(output)
self.assertEqual(output, '')
output = check_output('ip -6 rule list table 1011')
print(output)
self.assertEqual(output, '')
networkctl_reconfigure('test1')
self.wait_online('test1:degraded')
output = check_output('ip rule list table 1011')
print(output)
self.assertIn('10111: from all fwmark 0x3f3 lookup 1011', output)
self.assertIn('10112: from all oif test1 lookup 1011', output)
self.assertIn('10113: from all iif test1 lookup 1011', output)
self.assertIn('10114: from 192.168.8.254 lookup 1011', output)
output = check_output('ip -6 rule list table 1011')
print(output)
self.assertIn('10113: from all iif test1 lookup 1011', output)
def test_routing_policy_rule_manual(self):
# For issue #36244.
copy_network_unit(
'11-dummy.netdev',
'25-routing-policy-rule-manual.network',
)
start_networkd()
self.wait_operstate('test1', operstate='off', setup_state='configuring', setup_timeout=20)
check_output('ip link add test2 type dummy')
self.wait_operstate('test2', operstate='off', setup_state='configuring', setup_timeout=20)
networkctl('up', 'test2')
self.wait_online('test2:degraded')
# The request for the routing policy rules are bound to test1. Hence, we need to wait for the rules
# being configured explicitly.
for _ in range(20):
time.sleep(0.5)
output = check_output('ip -4 rule list table 51819')
if output != '10: from all lookup 51819 suppress_prefixlength 0 proto static':
continue
output = check_output('ip -6 rule list table 51819')
if output != '10: from all lookup 51819 suppress_prefixlength 0 proto static':
continue
output = check_output('ip -4 rule list table 51820')
if output != '11: not from all fwmark 0x38f lookup 51820 proto static':
continue
output = check_output('ip -6 rule list table 51820')
if output != '11: not from all fwmark 0x38f lookup 51820 proto static':
continue
break
else:
self.assertFalse(True)
def test_routing_policy_rule_port_range(self):
copy_network_unit('25-fibrule-port-range.network', '11-dummy.netdev')
start_networkd()
self.wait_online('test1:degraded')
output = check_output('ip rule')
print(output)
self.assertIn('111:', output)
self.assertIn('from 192.168.100.18 ', output)
self.assertIn('sport 1123-1150 ', output)
self.assertIn('dport 3224-3290 ', output)
self.assertRegex(output, 'ipproto (tcp|ipproto-6) ')
self.assertIn('lookup 7 ', output)
def test_routing_policy_rule_invert(self):
copy_network_unit('25-fibrule-invert.network', '11-dummy.netdev')
start_networkd()
self.wait_online('test1:degraded')
output = check_output('ip rule')
print(output)
self.assertIn('111:', output)
self.assertIn('not ', output)
self.assertIn('from 192.168.100.18 ', output)
self.assertRegex(output, 'ipproto (tcp|ipproto-6) ')
self.assertIn('lookup 7 ', output)
def test_routing_policy_rule_l3mdev(self):
copy_network_unit('25-fibrule-l3mdev.network', '11-dummy.netdev')
start_networkd()
self.wait_online('test1:degraded')
output = check_output('ip rule')
print(output)
self.assertIn('1500: from all lookup [l3mdev-table]', output)
self.assertIn('2000: from all lookup [l3mdev-table] unreachable', output)
def test_routing_policy_rule_uidrange(self):
copy_network_unit('25-fibrule-uidrange.network', '11-dummy.netdev')
start_networkd()
self.wait_online('test1:degraded')
output = check_output('ip rule')
print(output)
self.assertIn('111:', output)
self.assertIn('from 192.168.100.18 ', output)
self.assertIn('lookup 7 ', output)
self.assertIn('uidrange 100-200 ', output)
def _check_route_static(self, test1_is_managed: bool):
output = networkctl_status('dummy98')
print(output)
output = networkctl_status('test1')
print(output)
print('### ip -6 route show dev dummy98')
output = check_output('ip -6 route show dev dummy98')
print(output)
self.assertIn('2001:1234:5:8fff:ff:ff:ff:ff proto static', output)
self.assertIn('2001:1234:5:8f63::1 proto kernel', output)
self.assertIn('2001:1234:5:afff:ff:ff:ff:ff via fe80:0:222:4dff:ff:ff:ff:ff proto static', output)
print('### ip -6 route show default')
output = check_output('ip -6 route show default')
print(output)
self.assertIn('default', output)
self.assertIn('via 2001:1234:5:8fff:ff:ff:ff:ff', output)
print('### ip -4 route show dev dummy98')
output = check_output('ip -4 route show dev dummy98')
print(output)
self.assertIn('149.10.124.48/28 proto kernel scope link src 149.10.124.58', output)
self.assertIn('149.10.124.64 proto static scope link', output)
self.assertIn('169.254.0.0/16 proto static scope link metric 2048', output)
self.assertIn('192.168.1.1 proto static scope link initcwnd 20', output)
self.assertIn('192.168.1.2 proto static scope link initrwnd 30', output)
self.assertIn('192.168.1.3 proto static scope link advmss 30', output)
self.assertIn('192.168.1.4 proto static scope link hoplimit 122', output)
self.assertIn('multicast 149.10.123.4 proto static', output)
print('### ip -4 route show dev dummy98 default')
output = check_output('ip -4 route show dev dummy98 default')
print(output)
self.assertIn('default via 149.10.125.65 proto static onlink', output)
self.assertIn('default via 149.10.124.64 proto static', output)
self.assertIn('default proto static', output)
self.assertIn('default via 1.1.8.104 proto static', output)
print('### ip -4 route show table local dev dummy98')
output = check_output('ip -4 route show table local dev dummy98')
print(output)
self.assertIn('local 149.10.123.1 proto static scope host', output)
self.assertIn('anycast 149.10.123.2 proto static scope link', output)
self.assertIn('broadcast 149.10.123.3 proto static scope link', output)
print('### ip -4 route show type blackhole')
output = check_output('ip -4 route show type blackhole')
print(output)
self.assertIn('blackhole 202.54.1.2 proto static', output)
print('### ip -4 route show type unreachable')
output = check_output('ip -4 route show type unreachable')
print(output)
self.assertIn('unreachable 202.54.1.3 proto static', output)
print('### ip -4 route show type prohibit')
output = check_output('ip -4 route show type prohibit')
print(output)
self.assertIn('prohibit 202.54.1.4 proto static', output)
print('### ip -6 route show type blackhole')
output = check_output('ip -6 route show type blackhole')
print(output)
self.assertIn('blackhole 2001:1234:5678::2 dev lo proto static', output)
print('### ip -6 route show type unreachable')
output = check_output('ip -6 route show type unreachable')
print(output)
self.assertIn('unreachable 2001:1234:5678::3 dev lo proto static', output)
print('### ip -6 route show type prohibit')
output = check_output('ip -6 route show type prohibit')
print(output)
self.assertIn('prohibit 2001:1234:5678::4 dev lo proto static', output)
print('### ip route show 192.168.10.1')
output = check_output('ip route show 192.168.10.1')
print(output)
self.assertIn('192.168.10.1 proto static', output)
self.assertIn('nexthop via 149.10.123.59 dev test1 weight 20', output)
self.assertIn('nexthop via 149.10.123.60 dev test1 weight 30', output)
self.assertIn('nexthop via 149.10.124.59 dev dummy98 weight 10', output)
self.assertIn('nexthop via 149.10.124.60 dev dummy98 weight 5', output)
print('### ip route show 192.168.10.2')
output = check_output('ip route show 192.168.10.2')
print(output)
self.assertIn('192.168.10.2 proto static', output)
self.assertIn('nexthop via inet6 2001:1234:5:6fff:ff:ff:ff:ff dev test1 weight 20', output)
self.assertIn('nexthop via inet6 2001:1234:5:7fff:ff:ff:ff:ff dev test1 weight 30', output)
self.assertIn('nexthop via inet6 2001:1234:5:8fff:ff:ff:ff:ff dev dummy98 weight 10', output)
self.assertIn('nexthop via inet6 2001:1234:5:9fff:ff:ff:ff:ff dev dummy98 weight 5', output)
print('### ip -6 route show 2001:1234:5:bfff:ff:ff:ff:ff')
output = check_output('ip -6 route show 2001:1234:5:bfff:ff:ff:ff:ff')
print(output)
self.assertIn('2001:1234:5:bfff:ff:ff:ff:ff', output)
if test1_is_managed:
self.assertIn('nexthop via 2001:1234:5:6fff:ff:ff:ff:ff dev test1 weight 20', output)
self.assertIn('nexthop via 2001:1234:5:7fff:ff:ff:ff:ff dev test1 weight 30', output)
self.assertIn('nexthop via 2001:1234:5:8fff:ff:ff:ff:ff dev dummy98 weight 10', output)
self.assertIn('nexthop via 2001:1234:5:9fff:ff:ff:ff:ff dev dummy98 weight 5', output)
print('### ip route show 192.168.20.0/24')
output = check_output('ip route show 192.168.20.0/24')
print(output)
self.assertIn('192.168.20.0/24 proto static', output)
self.assertIn('nexthop dev test1 weight 15', output)
self.assertIn('nexthop dev dummy98 weight 25', output)
check_json(networkctl_json())
def _check_unreachable_routes_removed(self):
print('### ip -4 route show type blackhole')
output = check_output('ip -4 route show type blackhole')
print(output)
self.assertEqual(output, '')