2 # SPDX-License-Identifier: LGPL-2.1+
3 # systemd-networkd tests
14 from shutil
import copytree
16 network_unit_file_path
='/run/systemd/network'
17 networkd_runtime_directory
='/run/systemd/netif'
18 networkd_ci_path
='/run/networkd-ci'
19 network_sysctl_ipv6_path
='/proc/sys/net/ipv6/conf'
20 network_sysctl_ipv4_path
='/proc/sys/net/ipv4/conf'
22 dnsmasq_pid_file
='/run/networkd-ci/test-test-dnsmasq.pid'
23 dnsmasq_log_file
='/run/networkd-ci/test-dnsmasq-log-file'
25 wait_online_bin
='/usr/lib/systemd/systemd-networkd-wait-online'
27 def is_module_available(module_name
):
28 lsmod_output
= subprocess
.check_output('lsmod', universal_newlines
=True)
29 module_re
= re
.compile(r
'^{0}\b'.format(re
.escape(module_name
)), re
.MULTILINE
)
30 return module_re
.search(lsmod_output
) or not subprocess
.call(["modprobe", module_name
])
32 def expectedFailureIfModuleIsNotAvailable(module_name
):
34 if not is_module_available(module_name
):
35 return unittest
.expectedFailure(func
)
40 def expectedFailureIfERSPANModuleIsNotAvailable():
42 rc
= subprocess
.call(['ip', 'link', 'add', 'dev', 'erspan99', 'type', 'erspan', 'seq', 'key', '30', 'local', '192.168.1.4', 'remote', '192.168.1.1', 'erspan_ver', '1', 'erspan', '123'])
44 subprocess
.call(['ip', 'link', 'del', 'erspan99'])
47 return unittest
.expectedFailure(func
)
51 def expectedFailureIfRoutingPolicyPortRangeIsNotAvailable():
53 rc
= subprocess
.call(['ip', 'rule', 'add', 'from', '192.168.100.19', 'sport', '1123-1150', 'dport', '3224-3290', 'table', '7'])
55 subprocess
.call(['ip', 'rule', 'del', 'from', '192.168.100.19', 'sport', '1123-1150', 'dport', '3224-3290', 'table', '7'])
58 return unittest
.expectedFailure(func
)
62 def expectedFailureIfRoutingPolicyIPProtoIsNotAvailable():
64 rc
= subprocess
.call(['ip', 'rule', 'add', 'not', 'from', '192.168.100.19', 'ipproto', 'tcp', 'table', '7'])
66 subprocess
.call(['ip', 'rule', 'del', 'not', 'from', '192.168.100.19', 'ipproto', 'tcp', 'table', '7'])
69 return unittest
.expectedFailure(func
)
73 def expectedFailureIf_ip6gre_do_not_support_ipv6ll():
75 rc
= subprocess
.call(['ip', 'link', 'add', 'name', 'test1', 'type', 'dummy'])
77 return unittest
.expectedFailure(func
)
80 rc
= subprocess
.call(['ip', 'tunnel', 'add', 'tun99', 'local', '2a00:ffde:4567:edde::4986', 'remote', '2001:473:fece:cafe::5178', 'mode', 'ip6gre', 'dev', 'dummy99'])
82 return unittest
.expectedFailure(func
)
85 # Not sure why, but '0' or '2' do not work.
86 rc
= subprocess
.call(['sysctl', '-w', 'net.ipv6.conf.tun99.addr_gen_mode=3'])
88 return unittest
.expectedFailure(func
)
91 rc
= subprocess
.run(['ip', '-6', 'address', 'show', 'dev', 'tun99', 'scope', 'link'], stdout
=subprocess
.PIPE
)
92 if rc
.returncode
!= 0:
93 return unittest
.expectedFailure(func
)
95 if 'inet6' not in rc
.stdout
.rstrip().decode('utf-8'):
96 return unittest
.expectedFailure(func
)
103 os
.makedirs(network_unit_file_path
, exist_ok
=True)
104 os
.makedirs(networkd_ci_path
, exist_ok
=True)
106 shutil
.rmtree(networkd_ci_path
)
107 copytree(os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), 'conf'), networkd_ci_path
)
109 subprocess
.check_call('systemctl stop systemd-networkd.socket', shell
=True)
111 def tearDownModule():
112 shutil
.rmtree(networkd_ci_path
)
114 subprocess
.check_call('systemctl stop systemd-networkd.service', shell
=True)
115 subprocess
.check_call('systemctl start systemd-networkd.socket', shell
=True)
116 subprocess
.check_call('systemctl start systemd-networkd.service', shell
=True)
119 def read_link_attr(self
, link
, dev
, attribute
):
120 with
open(os
.path
.join(os
.path
.join(os
.path
.join('/sys/class/net/', link
), dev
), attribute
)) as f
:
121 return f
.readline().strip()
123 def read_bridge_port_attr(self
, bridge
, link
, attribute
):
125 path_bridge
= os
.path
.join('/sys/devices/virtual/net', bridge
)
126 path_port
= 'lower_' + link
+ '/brport'
127 path
= os
.path
.join(path_bridge
, path_port
)
129 with
open(os
.path
.join(path
, attribute
)) as f
:
130 return f
.readline().strip()
132 def link_exits(self
, link
):
133 return os
.path
.exists(os
.path
.join('/sys/class/net', link
))
135 def link_remove(self
, links
):
137 if os
.path
.exists(os
.path
.join('/sys/class/net', link
)):
138 subprocess
.call(['ip', 'link', 'del', 'dev', link
])
141 def l2tp_tunnel_remove(self
, tunnel_ids
):
142 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'tunnel']).rstrip().decode('utf-8')
143 for tid
in tunnel_ids
:
144 words
='Tunnel ' + tid
+ ', encap'
146 subprocess
.call(['ip', 'l2tp', 'del', 'tunnel', 'tid', tid
])
149 def read_ipv6_sysctl_attr(self
, link
, attribute
):
150 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, link
), attribute
)) as f
:
151 return f
.readline().strip()
153 def read_ipv4_sysctl_attr(self
, link
, attribute
):
154 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv4_path
, link
), attribute
)) as f
:
155 return f
.readline().strip()
157 def copy_unit_to_networkd_unit_path(self
, *units
):
160 shutil
.copy(os
.path
.join(networkd_ci_path
, unit
), network_unit_file_path
)
161 if (os
.path
.exists(os
.path
.join(networkd_ci_path
, unit
+ '.d'))):
162 copytree(os
.path
.join(networkd_ci_path
, unit
+ '.d'), os
.path
.join(network_unit_file_path
, unit
+ '.d'))
164 def remove_unit_from_networkd_path(self
, units
):
166 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
))):
167 os
.remove(os
.path
.join(network_unit_file_path
, unit
))
168 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
+ '.d'))):
169 shutil
.rmtree(os
.path
.join(network_unit_file_path
, unit
+ '.d'))
171 def start_dnsmasq(self
, additional_options
='', lease_time
='1h'):
172 dnsmasq_command
= f
'dnsmasq -8 /var/run/networkd-ci/test-dnsmasq-log-file --log-queries=extra --log-dhcp --pid-file=/var/run/networkd-ci/test-test-dnsmasq.pid --conf-file=/dev/null --interface=veth-peer --enable-ra --dhcp-range=2600::10,2600::20,{lease_time} --dhcp-range=192.168.5.10,192.168.5.200,{lease_time} -R --dhcp-leasefile=/var/run/networkd-ci/lease --dhcp-option=26,1492 --dhcp-option=option:router,192.168.5.1 --dhcp-option=33,192.168.5.4,192.168.5.5 --port=0 ' + additional_options
173 subprocess
.check_call(dnsmasq_command
, shell
=True)
177 def stop_dnsmasq(self
, pid_file
):
178 if os
.path
.exists(pid_file
):
179 with
open(pid_file
, 'r') as f
:
180 pid
= f
.read().rstrip(' \t\r\n\0')
181 os
.kill(int(pid
), signal
.SIGTERM
)
185 def search_words_in_dnsmasq_log(self
, words
, show_all
=False):
186 if os
.path
.exists(dnsmasq_log_file
):
187 with
open (dnsmasq_log_file
) as in_file
:
188 contents
= in_file
.read()
191 for line
in contents
.split('\n'):
194 print("%s, %s" % (words
, line
))
198 def remove_lease_file(self
):
199 if os
.path
.exists(os
.path
.join(networkd_ci_path
, 'lease')):
200 os
.remove(os
.path
.join(networkd_ci_path
, 'lease'))
202 def remove_log_file(self
):
203 if os
.path
.exists(dnsmasq_log_file
):
204 os
.remove(dnsmasq_log_file
)
206 def start_networkd(self
, sleep_sec
=5, remove_state_files
=True):
207 if (remove_state_files
and
208 os
.path
.exists(os
.path
.join(networkd_runtime_directory
, 'state'))):
209 subprocess
.check_call('systemctl stop systemd-networkd', shell
=True)
210 os
.remove(os
.path
.join(networkd_runtime_directory
, 'state'))
211 subprocess
.check_call('systemctl start systemd-networkd', shell
=True)
213 subprocess
.check_call('systemctl restart systemd-networkd', shell
=True)
215 time
.sleep(sleep_sec
)
217 def wait_online(self
, links_with_operstate
, timeout
='20s', bool_any
=False):
218 args
= [wait_online_bin
, f
'--timeout={timeout}'] + [f
'--interface={link}' for link
in links_with_operstate
]
221 subprocess
.check_call(args
)
223 class NetworkdNetDevTests(unittest
.TestCase
, Utilities
):
280 '10-dropin-test.netdev',
284 '15-name-conflict-test.netdev',
287 '21-vlan-test1.network',
290 '25-6rd-tunnel.netdev',
292 '25-bond-balanced-tlb.netdev',
295 '25-erspan-tunnel-local-any.netdev',
296 '25-erspan-tunnel.netdev',
297 '25-fou-gretap.netdev',
299 '25-fou-ipip.netdev',
300 '25-fou-ipproto-gre.netdev',
301 '25-fou-ipproto-ipip.netdev',
304 '25-gretap-tunnel-local-any.netdev',
305 '25-gretap-tunnel.netdev',
306 '25-gre-tunnel-local-any.netdev',
307 '25-gre-tunnel-remote-any.netdev',
308 '25-gre-tunnel.netdev',
309 '25-ip6gretap-tunnel-local-any.netdev',
310 '25-ip6gretap-tunnel.netdev',
311 '25-ip6gre-tunnel-local-any.netdev',
312 '25-ip6gre-tunnel-remote-any.netdev',
313 '25-ip6gre-tunnel.netdev',
314 '25-ip6tnl-tunnel-remote-any.netdev',
315 '25-ip6tnl-tunnel-local-any.netdev',
316 '25-ip6tnl-tunnel.netdev',
317 '25-ipip-tunnel-independent.netdev',
318 '25-ipip-tunnel-local-any.netdev',
319 '25-ipip-tunnel-remote-any.netdev',
320 '25-ipip-tunnel.netdev',
323 '25-isatap-tunnel.netdev',
327 '25-sit-tunnel-local-any.netdev',
328 '25-sit-tunnel-remote-any.netdev',
329 '25-sit-tunnel.netdev',
332 '25-tunnel-local-any.network',
333 '25-tunnel-remote-any.network',
338 '25-vti6-tunnel-local-any.netdev',
339 '25-vti6-tunnel-remote-any.netdev',
340 '25-vti6-tunnel.netdev',
341 '25-vti-tunnel-local-any.netdev',
342 '25-vti-tunnel-remote-any.netdev',
343 '25-vti-tunnel.netdev',
345 '25-wireguard-23-peers.netdev',
346 '25-wireguard-23-peers.network',
347 '25-wireguard-preshared-key.txt',
348 '25-wireguard-private-key.txt',
349 '25-wireguard.netdev',
350 '25-wireguard.network',
369 'vxlan-test1.network',
373 self
.link_remove(self
.links
)
376 self
.link_remove(self
.links
)
377 self
.remove_unit_from_networkd_path(self
.units
)
379 def test_dropin(self
):
380 self
.copy_unit_to_networkd_unit_path('10-dropin-test.netdev', '15-name-conflict-test.netdev')
381 self
.start_networkd()
383 self
.assertTrue(self
.link_exits('dropin-test'))
385 # This also tests NetDev.Name= conflict and basic networkctl functionalities
387 output
= subprocess
.check_output(['ip', 'link', 'show', 'dropin-test']).rstrip().decode('utf-8')
389 self
.assertRegex(output
, '00:50:56:c0:00:28')
391 output
= subprocess
.check_output(['networkctl', 'list']).rstrip().decode('utf-8')
392 self
.assertRegex(output
, '1 lo ')
393 self
.assertRegex(output
, 'dropin-test')
395 output
= subprocess
.check_output(['networkctl', 'list', 'dropin-test']).rstrip().decode('utf-8')
396 self
.assertNotRegex(output
, '1 lo ')
397 self
.assertRegex(output
, 'dropin-test')
399 output
= subprocess
.check_output(['networkctl', 'list', 'dropin-*']).rstrip().decode('utf-8')
400 self
.assertNotRegex(output
, '1 lo ')
401 self
.assertRegex(output
, 'dropin-test')
403 output
= subprocess
.check_output(['networkctl', 'status', 'dropin-*']).rstrip().decode('utf-8')
404 self
.assertNotRegex(output
, '1: lo ')
405 self
.assertRegex(output
, 'dropin-test')
407 ret
= subprocess
.run(['ethtool', '--driver', 'dropin-test'], stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
)
408 print(ret
.stdout
.rstrip().decode('utf-8'))
409 if ret
.returncode
== 0 and re
.search('driver: dummy', ret
.stdout
.rstrip().decode('utf-8')) != None:
410 self
.assertRegex(output
, 'Driver: dummy')
412 print('ethtool does not support driver field at least for dummy interfaces, skipping test for Driver field of networkctl.')
414 def test_wait_online_any(self
):
415 self
.copy_unit_to_networkd_unit_path('25-bridge.netdev', '25-bridge.network', '11-dummy.netdev', '11-dummy.network')
416 self
.start_networkd(0)
418 self
.wait_online(['bridge99', 'test1:degraded'], bool_any
=True)
419 self
.assertTrue(self
.link_exits('bridge99'))
420 self
.assertTrue(self
.link_exits('test1'))
422 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
424 self
.assertRegex(output
, 'State: (?:off|no-carrier) \(configuring\)')
426 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
428 self
.assertRegex(output
, 'State: degraded \(configured\)')
430 def test_bridge(self
):
431 self
.copy_unit_to_networkd_unit_path('25-bridge.netdev')
432 self
.start_networkd()
434 self
.assertTrue(self
.link_exits('bridge99'))
436 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'hello_time'))
437 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'max_age'))
438 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','forward_delay'))
439 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','ageing_time'))
440 self
.assertEqual('9', self
.read_link_attr('bridge99', 'bridge','priority'))
441 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_querier'))
442 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_snooping'))
443 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','stp_state'))
446 self
.copy_unit_to_networkd_unit_path('25-bond.netdev')
447 self
.start_networkd()
449 self
.assertTrue(self
.link_exits('bond99'))
451 self
.assertEqual('802.3ad 4', self
.read_link_attr('bond99', 'bonding', 'mode'))
452 self
.assertEqual('layer3+4 1', self
.read_link_attr('bond99', 'bonding', 'xmit_hash_policy'))
453 self
.assertEqual('1000', self
.read_link_attr('bond99', 'bonding', 'miimon'))
454 self
.assertEqual('fast 1', self
.read_link_attr('bond99', 'bonding', 'lacp_rate'))
455 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'updelay'))
456 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'downdelay'))
457 self
.assertEqual('4', self
.read_link_attr('bond99', 'bonding', 'resend_igmp'))
458 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'min_links'))
459 self
.assertEqual('1218', self
.read_link_attr('bond99', 'bonding', 'ad_actor_sys_prio'))
460 self
.assertEqual('811', self
.read_link_attr('bond99', 'bonding', 'ad_user_port_key'))
461 self
.assertEqual('00:11:22:33:44:55', self
.read_link_attr('bond99', 'bonding', 'ad_actor_system'))
463 def test_bond_balanced_tlb(self
):
464 self
.copy_unit_to_networkd_unit_path('25-bond-balanced-tlb.netdev')
465 self
.start_networkd()
467 self
.assertTrue(self
.link_exits('bond99'))
469 self
.assertEqual('balance-tlb 5', self
.read_link_attr('bond99', 'bonding', 'mode'))
470 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'tlb_dynamic_lb'))
473 self
.copy_unit_to_networkd_unit_path('21-vlan.netdev', '11-dummy.netdev',
474 '21-vlan.network', '21-vlan-test1.network')
475 self
.start_networkd()
477 self
.assertTrue(self
.link_exits('test1'))
478 self
.assertTrue(self
.link_exits('vlan99'))
480 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
482 self
.assertRegex(output
, ' mtu 2000 ')
484 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vlan99']).rstrip().decode('utf-8')
486 self
.assertRegex(output
, ' mtu 2000 ')
487 self
.assertRegex(output
, 'REORDER_HDR')
488 self
.assertRegex(output
, 'LOOSE_BINDING')
489 self
.assertRegex(output
, 'GVRP')
490 self
.assertRegex(output
, 'MVRP')
491 self
.assertRegex(output
, ' id 99 ')
493 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'test1']).rstrip().decode('utf-8')
495 self
.assertRegex(output
, 'inet 192.168.24.5/24 brd 192.168.24.255 scope global test1')
496 self
.assertRegex(output
, 'inet 192.168.25.5/24 brd 192.168.25.255 scope global test1')
498 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'vlan99']).rstrip().decode('utf-8')
500 self
.assertRegex(output
, 'inet 192.168.23.5/24 brd 192.168.23.255 scope global vlan99')
502 def test_macvtap(self
):
503 self
.copy_unit_to_networkd_unit_path('21-macvtap.netdev', '11-dummy.netdev', 'macvtap.network')
504 self
.start_networkd()
506 self
.assertTrue(self
.link_exits('macvtap99'))
508 def test_macvlan(self
):
509 self
.copy_unit_to_networkd_unit_path('21-macvlan.netdev', '11-dummy.netdev', 'macvlan.network')
510 self
.start_networkd()
512 self
.assertTrue(self
.link_exits('test1'))
513 self
.assertTrue(self
.link_exits('macvlan99'))
515 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
517 self
.assertRegex(output
, ' mtu 2000 ')
519 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'macvlan99']).rstrip().decode('utf-8')
521 self
.assertRegex(output
, ' mtu 2000 ')
523 @expectedFailureIfModuleIsNotAvailable('ipvlan')
524 def test_ipvlan(self
):
525 self
.copy_unit_to_networkd_unit_path('25-ipvlan.netdev', '11-dummy.netdev', 'ipvlan.network')
526 self
.start_networkd()
528 self
.assertTrue(self
.link_exits('ipvlan99'))
530 @expectedFailureIfModuleIsNotAvailable('ipvtap')
531 def test_ipvtap(self
):
532 self
.copy_unit_to_networkd_unit_path('25-ipvtap.netdev', '11-dummy.netdev', 'ipvtap.network')
533 self
.start_networkd()
535 self
.assertTrue(self
.link_exits('ipvtap99'))
538 self
.copy_unit_to_networkd_unit_path('25-veth.netdev')
539 self
.start_networkd()
541 self
.assertTrue(self
.link_exits('veth99'))
543 def test_dummy(self
):
544 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev')
545 self
.start_networkd()
547 self
.assertTrue(self
.link_exits('test1'))
550 self
.copy_unit_to_networkd_unit_path('25-tun.netdev')
551 self
.start_networkd()
553 self
.assertTrue(self
.link_exits('tun99'))
556 self
.copy_unit_to_networkd_unit_path('25-tap.netdev')
557 self
.start_networkd()
559 self
.assertTrue(self
.link_exits('tap99'))
561 @expectedFailureIfModuleIsNotAvailable('vrf')
563 self
.copy_unit_to_networkd_unit_path('25-vrf.netdev')
564 self
.start_networkd()
566 self
.assertTrue(self
.link_exits('vrf99'))
568 @expectedFailureIfModuleIsNotAvailable('vcan')
570 self
.copy_unit_to_networkd_unit_path('25-vcan.netdev')
571 self
.start_networkd()
573 self
.assertTrue(self
.link_exits('vcan99'))
575 @expectedFailureIfModuleIsNotAvailable('wireguard')
576 def test_wireguard(self
):
577 self
.copy_unit_to_networkd_unit_path('25-wireguard.netdev', '25-wireguard.network',
578 '25-wireguard-23-peers.netdev', '25-wireguard-23-peers.network',
579 '25-wireguard-preshared-key.txt', '25-wireguard-private-key.txt')
580 self
.start_networkd(0)
581 self
.wait_online(['wg99:carrier', 'wg98:routable'])
583 self
.assertTrue(self
.link_exits('wg99'))
584 self
.assertTrue(self
.link_exits('wg98'))
586 if shutil
.which('wg'):
587 subprocess
.call('wg')
589 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'listen-port']).rstrip().decode('utf-8')
590 self
.assertRegex(output
, '51820')
591 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'fwmark']).rstrip().decode('utf-8')
592 self
.assertRegex(output
, '0x4d2')
593 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'allowed-ips']).rstrip().decode('utf-8')
594 self
.assertRegex(output
, 'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t192.168.26.0/24 fd31:bf08:57cb::/48')
595 self
.assertRegex(output
, 'lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc=\tfdbc:bae2:7871:e1fe:793:8636::/96 fdbc:bae2:7871:500:e1fe:793:8636:dad1/128')
596 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'persistent-keepalive']).rstrip().decode('utf-8')
597 self
.assertRegex(output
, 'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t20')
598 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'endpoints']).rstrip().decode('utf-8')
599 self
.assertRegex(output
, 'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t192.168.27.3:51820')
600 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'private-key']).rstrip().decode('utf-8')
601 self
.assertRegex(output
, 'EEGlnEPYJV//kbvvIqxKkQwOiS\+UENyPncC4bF46ong=')
602 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'preshared-keys']).rstrip().decode('utf-8')
603 self
.assertRegex(output
, 'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA= IIWIV17wutHv7t4cR6pOT91z6NSz/T8Arh0yaywhw3M=')
604 self
.assertRegex(output
, 'lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc= cPLOy1YUrEI0EMMIycPJmOo0aTu3RZnw8bL5meVD6m0=')
606 output
= subprocess
.check_output(['wg', 'show', 'wg98', 'private-key']).rstrip().decode('utf-8')
607 self
.assertRegex(output
, 'CJQUtcS9emY2fLYqDlpSZiE/QJyHkPWr\+WHtZLZ90FU=')
609 def test_geneve(self
):
610 self
.copy_unit_to_networkd_unit_path('25-geneve.netdev')
611 self
.start_networkd()
613 self
.assertTrue(self
.link_exits('geneve99'))
615 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'geneve99']).rstrip().decode('utf-8')
617 self
.assertRegex(output
, '192.168.22.1')
618 self
.assertRegex(output
, '6082')
619 self
.assertRegex(output
, 'udpcsum')
620 self
.assertRegex(output
, 'udp6zerocsumrx')
622 def test_ipip_tunnel(self
):
623 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ipip.network',
624 '25-ipip-tunnel.netdev', '25-tunnel.network',
625 '25-ipip-tunnel-local-any.netdev', '25-tunnel-local-any.network',
626 '25-ipip-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
627 self
.start_networkd(0)
628 self
.wait_online(['ipiptun99:routable', 'ipiptun98:routable', 'ipiptun97:routable', 'dummy98:degraded'])
630 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun99']).rstrip().decode('utf-8')
632 self
.assertRegex(output
, 'ipip (?:ipip |)remote 192.169.224.239 local 192.168.223.238 dev dummy98')
633 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun98']).rstrip().decode('utf-8')
635 self
.assertRegex(output
, 'ipip (?:ipip |)remote 192.169.224.239 local any dev dummy98')
636 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun97']).rstrip().decode('utf-8')
638 self
.assertRegex(output
, 'ipip (?:ipip |)remote any local 192.168.223.238 dev dummy98')
640 def test_gre_tunnel(self
):
641 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'gretun.network',
642 '25-gre-tunnel.netdev', '25-tunnel.network',
643 '25-gre-tunnel-local-any.netdev', '25-tunnel-local-any.network',
644 '25-gre-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
645 self
.start_networkd(0)
646 self
.wait_online(['gretun99:routable', 'gretun98:routable', 'gretun97:routable', 'dummy98:degraded'])
648 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun99']).rstrip().decode('utf-8')
650 self
.assertRegex(output
, 'gre remote 10.65.223.239 local 10.65.223.238 dev dummy98')
651 self
.assertRegex(output
, 'ikey 1.2.3.103')
652 self
.assertRegex(output
, 'okey 1.2.4.103')
653 self
.assertRegex(output
, 'iseq')
654 self
.assertRegex(output
, 'oseq')
655 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun98']).rstrip().decode('utf-8')
657 self
.assertRegex(output
, 'gre remote 10.65.223.239 local any dev dummy98')
658 self
.assertRegex(output
, 'ikey 0.0.0.104')
659 self
.assertRegex(output
, 'okey 0.0.0.104')
660 self
.assertNotRegex(output
, 'iseq')
661 self
.assertNotRegex(output
, 'oseq')
662 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun97']).rstrip().decode('utf-8')
664 self
.assertRegex(output
, 'gre remote any local 10.65.223.238 dev dummy98')
665 self
.assertRegex(output
, 'ikey 0.0.0.105')
666 self
.assertRegex(output
, 'okey 0.0.0.105')
667 self
.assertNotRegex(output
, 'iseq')
668 self
.assertNotRegex(output
, 'oseq')
670 @expectedFailureIf_ip6gre_do_not_support_ipv6ll()
671 def test_ip6gre_tunnel(self
):
672 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ip6gretun.network',
673 '25-ip6gre-tunnel.netdev', '25-tunnel.network',
674 '25-ip6gre-tunnel-local-any.netdev', '25-tunnel-local-any.network',
675 '25-ip6gre-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
676 self
.start_networkd()
678 self
.assertTrue(self
.link_exits('dummy98'))
679 self
.assertTrue(self
.link_exits('ip6gretun99'))
680 self
.assertTrue(self
.link_exits('ip6gretun98'))
681 self
.assertTrue(self
.link_exits('ip6gretun97'))
683 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretun99']).rstrip().decode('utf-8')
685 self
.assertRegex(output
, 'ip6gre remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
686 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretun98']).rstrip().decode('utf-8')
688 self
.assertRegex(output
, 'ip6gre remote 2001:473:fece:cafe::5179 local any dev dummy98')
689 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretun97']).rstrip().decode('utf-8')
691 self
.assertRegex(output
, 'ip6gre remote any local 2a00:ffde:4567:edde::4987 dev dummy98')
693 # Old kernels may not support IPv6LL address on ip6gre tunnel, and the following test may fails.
694 self
.wait_online(['ip6gretun99:routable', 'ip6gretun98:routable', 'ip6gretun97:routable', 'dummy98:degraded'])
696 def test_gretap_tunnel(self
):
697 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'gretap.network',
698 '25-gretap-tunnel.netdev', '25-tunnel.network',
699 '25-gretap-tunnel-local-any.netdev', '25-tunnel-local-any.network')
700 self
.start_networkd(0)
701 self
.wait_online(['gretap99:routable', 'gretap98:routable', 'dummy98:degraded'])
703 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretap99']).rstrip().decode('utf-8')
705 self
.assertRegex(output
, 'gretap remote 10.65.223.239 local 10.65.223.238 dev dummy98')
706 self
.assertRegex(output
, 'ikey 0.0.0.106')
707 self
.assertRegex(output
, 'okey 0.0.0.106')
708 self
.assertRegex(output
, 'iseq')
709 self
.assertRegex(output
, 'oseq')
710 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretap98']).rstrip().decode('utf-8')
712 self
.assertRegex(output
, 'gretap remote 10.65.223.239 local any dev dummy98')
713 self
.assertRegex(output
, 'ikey 0.0.0.107')
714 self
.assertRegex(output
, 'okey 0.0.0.107')
715 self
.assertRegex(output
, 'iseq')
716 self
.assertRegex(output
, 'oseq')
718 def test_ip6gretap_tunnel(self
):
719 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ip6gretap.network',
720 '25-ip6gretap-tunnel.netdev', '25-tunnel.network',
721 '25-ip6gretap-tunnel-local-any.netdev', '25-tunnel-local-any.network')
722 self
.start_networkd(0)
723 self
.wait_online(['ip6gretap99:routable', 'ip6gretap98:routable', 'dummy98:degraded'])
725 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretap99']).rstrip().decode('utf-8')
727 self
.assertRegex(output
, 'ip6gretap remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
728 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretap98']).rstrip().decode('utf-8')
730 self
.assertRegex(output
, 'ip6gretap remote 2001:473:fece:cafe::5179 local any dev dummy98')
732 def test_vti_tunnel(self
):
733 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'vti.network',
734 '25-vti-tunnel.netdev', '25-tunnel.network',
735 '25-vti-tunnel-local-any.netdev', '25-tunnel-local-any.network',
736 '25-vti-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
737 self
.start_networkd(0)
738 self
.wait_online(['vtitun99:routable', 'vtitun98:routable', 'vtitun97:routable', 'dummy98:degraded'])
740 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vtitun99']).rstrip().decode('utf-8')
742 self
.assertRegex(output
, 'vti remote 10.65.223.239 local 10.65.223.238 dev dummy98')
743 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vtitun98']).rstrip().decode('utf-8')
745 self
.assertRegex(output
, 'vti remote 10.65.223.239 local any dev dummy98')
746 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vtitun97']).rstrip().decode('utf-8')
748 self
.assertRegex(output
, 'vti remote any local 10.65.223.238 dev dummy98')
750 def test_vti6_tunnel(self
):
751 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'vti6.network',
752 '25-vti6-tunnel.netdev', '25-tunnel.network',
753 '25-vti6-tunnel-local-any.netdev', '25-tunnel-local-any.network',
754 '25-vti6-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
755 self
.start_networkd(0)
756 self
.wait_online(['vti6tun99:routable', 'vti6tun98:routable', 'vti6tun97:routable', 'dummy98:degraded'])
758 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vti6tun99']).rstrip().decode('utf-8')
760 self
.assertRegex(output
, 'vti6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
761 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vti6tun98']).rstrip().decode('utf-8')
763 self
.assertRegex(output
, 'vti6 remote 2001:473:fece:cafe::5179 local (?:any|::) dev dummy98')
764 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vti6tun97']).rstrip().decode('utf-8')
766 self
.assertRegex(output
, 'vti6 remote (?:any|::) local 2a00:ffde:4567:edde::4987 dev dummy98')
768 def test_ip6tnl_tunnel(self
):
769 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ip6tnl.network',
770 '25-ip6tnl-tunnel.netdev', '25-tunnel.network',
771 '25-ip6tnl-tunnel-local-any.netdev', '25-tunnel-local-any.network',
772 '25-ip6tnl-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
773 self
.start_networkd(0)
774 self
.wait_online(['ip6tnl99:routable', 'ip6tnl98:routable', 'ip6tnl97:routable', 'dummy98:degraded'])
776 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6tnl99']).rstrip().decode('utf-8')
778 self
.assertRegex(output
, 'ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
779 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6tnl98']).rstrip().decode('utf-8')
781 self
.assertRegex(output
, 'ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local (?:any|::) dev dummy98')
782 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6tnl97']).rstrip().decode('utf-8')
784 self
.assertRegex(output
, 'ip6tnl ip6ip6 remote (?:any|::) local 2a00:ffde:4567:edde::4987 dev dummy98')
786 def test_sit_tunnel(self
):
787 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'sit.network',
788 '25-sit-tunnel.netdev', '25-tunnel.network',
789 '25-sit-tunnel-local-any.netdev', '25-tunnel-local-any.network',
790 '25-sit-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
791 self
.start_networkd(0)
792 self
.wait_online(['sittun99:routable', 'sittun98:routable', 'sittun97:routable', 'dummy98:degraded'])
794 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun99']).rstrip().decode('utf-8')
796 self
.assertRegex(output
, "sit (?:ip6ip |)remote 10.65.223.239 local 10.65.223.238 dev dummy98")
797 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun98']).rstrip().decode('utf-8')
799 self
.assertRegex(output
, "sit (?:ip6ip |)remote 10.65.223.239 local any dev dummy98")
800 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun97']).rstrip().decode('utf-8')
802 self
.assertRegex(output
, "sit (?:ip6ip |)remote any local 10.65.223.238 dev dummy98")
804 def test_isatap_tunnel(self
):
805 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'isatap.network',
806 '25-isatap-tunnel.netdev', '25-tunnel.network')
807 self
.start_networkd(0)
808 self
.wait_online(['isataptun99:routable', 'dummy98:degraded'])
810 self
.assertTrue(self
.link_exits('dummy98'))
811 self
.assertTrue(self
.link_exits('isataptun99'))
813 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'isataptun99']).rstrip().decode('utf-8')
815 self
.assertRegex(output
, "isatap ")
817 def test_6rd_tunnel(self
):
818 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '6rd.network',
819 '25-6rd-tunnel.netdev', '25-tunnel.network')
820 self
.start_networkd(0)
821 self
.wait_online(['sittun99:routable', 'dummy98:degraded'])
823 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun99']).rstrip().decode('utf-8')
825 self
.assertRegex(output
, '6rd-prefix 2602::/24')
827 @expectedFailureIfERSPANModuleIsNotAvailable()
828 def test_erspan_tunnel(self
):
829 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'erspan.network',
830 '25-erspan-tunnel.netdev', '25-tunnel.network',
831 '25-erspan-tunnel-local-any.netdev', '25-tunnel-local-any.network')
832 self
.start_networkd(0)
833 self
.wait_online(['erspan99:routable', 'erspan98:routable', 'dummy98:degraded'])
835 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'erspan99']).rstrip().decode('utf-8')
837 self
.assertRegex(output
, 'erspan remote 172.16.1.100 local 172.16.1.200')
838 self
.assertRegex(output
, 'ikey 0.0.0.101')
839 self
.assertRegex(output
, 'okey 0.0.0.101')
840 self
.assertRegex(output
, 'iseq')
841 self
.assertRegex(output
, 'oseq')
842 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'erspan98']).rstrip().decode('utf-8')
844 self
.assertRegex(output
, 'erspan remote 172.16.1.100 local any')
845 self
.assertRegex(output
, '102')
846 self
.assertRegex(output
, 'ikey 0.0.0.102')
847 self
.assertRegex(output
, 'okey 0.0.0.102')
848 self
.assertRegex(output
, 'iseq')
849 self
.assertRegex(output
, 'oseq')
851 def test_tunnel_independent(self
):
852 self
.copy_unit_to_networkd_unit_path('25-ipip-tunnel-independent.netdev')
853 self
.start_networkd()
855 self
.assertTrue(self
.link_exits('ipiptun99'))
857 @expectedFailureIfModuleIsNotAvailable('fou')
859 # The following redundant check is necessary for CentOS CI.
860 # Maybe, error handling in lookup_id() in sd-netlink/generic-netlink.c needs to be updated.
861 self
.assertTrue(is_module_available('fou'))
863 self
.copy_unit_to_networkd_unit_path('25-fou-ipproto-ipip.netdev', '25-fou-ipproto-gre.netdev',
864 '25-fou-ipip.netdev', '25-fou-sit.netdev',
865 '25-fou-gre.netdev', '25-fou-gretap.netdev')
866 self
.start_networkd()
868 self
.assertTrue(self
.link_exits('ipiptun96'))
869 self
.assertTrue(self
.link_exits('sittun96'))
870 self
.assertTrue(self
.link_exits('gretun96'))
871 self
.assertTrue(self
.link_exits('gretap96'))
873 output
= subprocess
.check_output(['ip', 'fou', 'show']).rstrip().decode('utf-8')
875 self
.assertRegex(output
, 'port 55555 ipproto 4')
876 self
.assertRegex(output
, 'port 55556 ipproto 47')
878 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun96']).rstrip().decode('utf-8')
880 self
.assertRegex(output
, 'encap fou encap-sport auto encap-dport 55555')
881 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun96']).rstrip().decode('utf-8')
883 self
.assertRegex(output
, 'encap fou encap-sport auto encap-dport 55555')
884 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun96']).rstrip().decode('utf-8')
886 self
.assertRegex(output
, 'encap fou encap-sport 1001 encap-dport 55556')
887 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretap96']).rstrip().decode('utf-8')
889 self
.assertRegex(output
, 'encap fou encap-sport auto encap-dport 55556')
891 subprocess
.call(['ip', 'fou', 'del', 'port', '55555'])
892 subprocess
.call(['ip', 'fou', 'del', 'port', '55556'])
894 def test_vxlan(self
):
895 self
.copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network',
896 '11-dummy.netdev', 'vxlan-test1.network')
897 self
.start_networkd(0)
899 self
.wait_online(['test1:degraded', 'vxlan99:degraded'])
901 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vxlan99']).rstrip().decode('utf-8')
903 self
.assertRegex(output
, '999')
904 self
.assertRegex(output
, '5555')
905 self
.assertRegex(output
, 'l2miss')
906 self
.assertRegex(output
, 'l3miss')
907 self
.assertRegex(output
, 'udpcsum')
908 self
.assertRegex(output
, 'udp6zerocsumtx')
909 self
.assertRegex(output
, 'udp6zerocsumrx')
910 self
.assertRegex(output
, 'remcsumtx')
911 self
.assertRegex(output
, 'remcsumrx')
912 self
.assertRegex(output
, 'gbp')
914 output
= subprocess
.check_output(['bridge', 'fdb', 'show', 'dev', 'vxlan99']).rstrip().decode('utf-8')
916 self
.assertRegex(output
, '00:11:22:33:44:55 dst 10.0.0.5 self permanent')
917 self
.assertRegex(output
, '00:11:22:33:44:66 dst 10.0.0.6 self permanent')
918 self
.assertRegex(output
, '00:11:22:33:44:77 dst 10.0.0.7 self permanent')
920 def test_macsec(self
):
921 self
.copy_unit_to_networkd_unit_path('25-macsec.netdev', '25-macsec.network', '25-macsec.key',
922 'macsec.network', '12-dummy.netdev')
923 self
.start_networkd(0)
925 self
.wait_online(['dummy98:degraded', 'macsec99:routable'])
927 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'macsec99']).rstrip().decode('utf-8')
929 self
.assertRegex(output
, 'macsec99@dummy98')
930 self
.assertRegex(output
, 'macsec sci [0-9a-f]*000b')
931 self
.assertRegex(output
, 'encrypt on')
933 output
= subprocess
.check_output(['ip', 'macsec', 'show', 'macsec99']).rstrip().decode('utf-8')
935 self
.assertRegex(output
, 'encrypt on')
936 self
.assertRegex(output
, 'TXSC: [0-9a-f]*000b on SA 1')
937 self
.assertRegex(output
, '0: PN [0-9]*, state on, key 01000000000000000000000000000000')
938 self
.assertRegex(output
, '1: PN [0-9]*, state on, key 02030000000000000000000000000000')
939 self
.assertRegex(output
, 'RXSC: c619528fe6a00100, state on')
940 self
.assertRegex(output
, '0: PN [0-9]*, state on, key 02030405000000000000000000000000')
941 self
.assertRegex(output
, '1: PN [0-9]*, state on, key 02030405060000000000000000000000')
942 self
.assertRegex(output
, '2: PN [0-9]*, state off, key 02030405060700000000000000000000')
943 self
.assertRegex(output
, '3: PN [0-9]*, state off, key 02030405060708000000000000000000')
944 self
.assertNotRegex(output
, 'key 02030405067080900000000000000000')
945 self
.assertRegex(output
, 'RXSC: 8c16456c83a90002, state on')
946 self
.assertRegex(output
, '0: PN [0-9]*, state off, key 02030400000000000000000000000000')
949 class NetworkdL2TPTests(unittest
.TestCase
, Utilities
):
960 '25-l2tp-dummy.network',
962 '25-l2tp-udp.netdev']
964 l2tp_tunnel_ids
= [ '10' ]
967 self
.l2tp_tunnel_remove(self
.l2tp_tunnel_ids
)
968 self
.link_remove(self
.links
)
971 self
.l2tp_tunnel_remove(self
.l2tp_tunnel_ids
)
972 self
.link_remove(self
.links
)
973 self
.remove_unit_from_networkd_path(self
.units
)
975 @expectedFailureIfModuleIsNotAvailable('l2tp_eth')
976 def test_l2tp_udp(self
):
977 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-udp.netdev')
978 self
.start_networkd()
980 self
.assertTrue(self
.link_exits('test1'))
981 self
.assertTrue(self
.link_exits('l2tp-ses1'))
982 self
.assertTrue(self
.link_exits('l2tp-ses2'))
984 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '10']).rstrip().decode('utf-8')
986 self
.assertRegex(output
, "Tunnel 10, encap UDP")
987 self
.assertRegex(output
, "From 192.168.30.100 to 192.168.30.101")
988 self
.assertRegex(output
, "Peer tunnel 11")
989 self
.assertRegex(output
, "UDP source / dest ports: 3000/4000")
990 self
.assertRegex(output
, "UDP checksum: enabled")
992 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '15']).rstrip().decode('utf-8')
994 self
.assertRegex(output
, "Session 15 in tunnel 10")
995 self
.assertRegex(output
, "Peer session 16, tunnel 11")
996 self
.assertRegex(output
, "interface name: l2tp-ses1")
998 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '17']).rstrip().decode('utf-8')
1000 self
.assertRegex(output
, "Session 17 in tunnel 10")
1001 self
.assertRegex(output
, "Peer session 18, tunnel 11")
1002 self
.assertRegex(output
, "interface name: l2tp-ses2")
1004 @expectedFailureIfModuleIsNotAvailable('l2tp_ip')
1005 def test_l2tp_ip(self
):
1006 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-ip.netdev')
1007 self
.start_networkd()
1009 self
.assertTrue(self
.link_exits('test1'))
1010 self
.assertTrue(self
.link_exits('l2tp-ses3'))
1011 self
.assertTrue(self
.link_exits('l2tp-ses4'))
1013 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '10']).rstrip().decode('utf-8')
1015 self
.assertRegex(output
, "Tunnel 10, encap IP")
1016 self
.assertRegex(output
, "From 192.168.30.100 to 192.168.30.101")
1017 self
.assertRegex(output
, "Peer tunnel 12")
1019 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '25']).rstrip().decode('utf-8')
1021 self
.assertRegex(output
, "Session 25 in tunnel 10")
1022 self
.assertRegex(output
, "Peer session 26, tunnel 12")
1023 self
.assertRegex(output
, "interface name: l2tp-ses3")
1025 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '27']).rstrip().decode('utf-8')
1027 self
.assertRegex(output
, "Session 27 in tunnel 10")
1028 self
.assertRegex(output
, "Peer session 28, tunnel 12")
1029 self
.assertRegex(output
, "interface name: l2tp-ses4")
1031 class NetworkdNetWorkTests(unittest
.TestCase
, Utilities
):
1041 '23-active-slave.network',
1042 '25-address-link-section.network',
1043 '25-address-preferred-lifetime-zero-ipv6.network',
1044 '25-address-static.network',
1045 '25-bind-carrier.network',
1046 '25-bond-active-backup-slave.netdev',
1047 '25-fibrule-invert.network',
1048 '25-fibrule-port-range.network',
1049 '25-ipv6-address-label-section.network',
1050 '25-neighbor-section.network',
1051 '25-link-local-addressing-no.network',
1052 '25-link-local-addressing-yes.network',
1053 '25-link-section-unmanaged.network',
1054 '25-route-ipv6-src.network',
1055 '25-route-static.network',
1056 '25-sysctl-disable-ipv6.network',
1057 '25-sysctl.network',
1058 'configure-without-carrier.network',
1059 'routing-policy-rule-dummy98.network',
1060 'routing-policy-rule-test1.network']
1063 self
.link_remove(self
.links
)
1066 self
.link_remove(self
.links
)
1067 self
.remove_unit_from_networkd_path(self
.units
)
1069 def test_address_static(self
):
1070 self
.copy_unit_to_networkd_unit_path('25-address-static.network', '12-dummy.netdev')
1071 self
.start_networkd(0)
1073 self
.wait_online(['dummy98:routable'])
1075 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1077 self
.assertRegex(output
, 'inet 10.1.2.3/16 brd 10.1.255.255 scope global dummy98')
1078 self
.assertRegex(output
, 'inet 10.1.2.4/16 brd 10.1.255.255 scope global secondary dummy98')
1079 self
.assertRegex(output
, 'inet 10.2.2.4/16 brd 10.2.255.255 scope global dummy98')
1082 self
.assertNotRegex(output
, '10.10.0.1/16')
1083 self
.assertNotRegex(output
, '10.10.0.2/16')
1085 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '32']).rstrip().decode('utf-8')
1086 self
.assertRegex(output
, 'inet 10.3.2.3/16 brd 10.3.255.255 scope global 32')
1088 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '33']).rstrip().decode('utf-8')
1089 self
.assertRegex(output
, 'inet 10.4.2.3 peer 10.4.2.4/16 scope global 33')
1091 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '34']).rstrip().decode('utf-8')
1092 self
.assertRegex(output
, 'inet 192.168.[0-9]*.1/24 brd 192.168.[0-9]*.255 scope global 34')
1094 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '35']).rstrip().decode('utf-8')
1095 self
.assertRegex(output
, 'inet 172.[0-9]*.0.1/16 brd 172.[0-9]*.255.255 scope global 35')
1097 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1099 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::15/64 scope global')
1100 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::16/64 scope global')
1101 self
.assertRegex(output
, 'inet6 2001:db8:0:f102::15/64 scope global')
1102 self
.assertRegex(output
, 'inet6 2001:db8:0:f102::16/64 scope global')
1103 self
.assertRegex(output
, 'inet6 2001:db8:0:f103::20 peer 2001:db8:0:f103::10/128 scope global')
1104 self
.assertRegex(output
, 'inet6 fd[0-9a-f:]*1/64 scope global')
1106 def test_address_preferred_lifetime_zero_ipv6(self
):
1107 self
.copy_unit_to_networkd_unit_path('25-address-preferred-lifetime-zero-ipv6.network', '12-dummy.netdev')
1108 self
.start_networkd()
1110 self
.assertTrue(self
.link_exits('dummy98'))
1112 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1114 self
.assertRegex(output
, 'State: routable \(configuring\)')
1116 output
= subprocess
.check_output(['ip', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1118 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope link deprecated dummy98')
1119 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::1/64 scope global')
1121 def test_configure_without_carrier(self
):
1122 self
.copy_unit_to_networkd_unit_path('configure-without-carrier.network', '11-dummy.netdev')
1123 self
.start_networkd()
1125 self
.assertTrue(self
.link_exits('test1'))
1127 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1129 self
.assertRegex(output
, '192.168.0.15')
1130 self
.assertRegex(output
, '192.168.0.1')
1131 self
.assertRegex(output
, 'routable')
1133 def test_routing_policy_rule(self
):
1134 self
.copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev')
1136 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1138 self
.start_networkd()
1140 self
.assertTrue(self
.link_exits('test1'))
1142 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
1144 self
.assertRegex(output
, '111')
1145 self
.assertRegex(output
, 'from 192.168.100.18')
1146 self
.assertRegex(output
, r
'tos (?:0x08|throughput)\s')
1147 self
.assertRegex(output
, 'iif test1')
1148 self
.assertRegex(output
, 'oif test1')
1149 self
.assertRegex(output
, 'lookup 7')
1151 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1153 def test_routing_policy_rule_issue_11280(self
):
1154 self
.copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev',
1155 'routing-policy-rule-dummy98.network', '12-dummy.netdev')
1157 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1158 subprocess
.call(['ip', 'rule', 'del', 'table', '8'])
1160 for trial
in range(3):
1161 # Remove state files only first time
1162 self
.start_networkd(remove_state_files
=(trial
== 0))
1164 self
.assertTrue(self
.link_exits('test1'))
1165 self
.assertTrue(self
.link_exits('dummy98'))
1167 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '7']).rstrip().decode('utf-8')
1169 self
.assertRegex(output
, '111: from 192.168.100.18 tos (?:0x08|throughput) iif test1 oif test1 lookup 7')
1171 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '8']).rstrip().decode('utf-8')
1173 self
.assertRegex(output
, '112: from 192.168.101.18 tos (?:0x08|throughput) iif dummy98 oif dummy98 lookup 8')
1175 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1176 subprocess
.call(['ip', 'rule', 'del', 'table', '8'])
1178 @expectedFailureIfRoutingPolicyPortRangeIsNotAvailable()
1179 def test_routing_policy_rule_port_range(self
):
1180 self
.copy_unit_to_networkd_unit_path('25-fibrule-port-range.network', '11-dummy.netdev')
1182 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1184 self
.start_networkd()
1186 self
.assertTrue(self
.link_exits('test1'))
1188 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
1190 self
.assertRegex(output
, '111')
1191 self
.assertRegex(output
, 'from 192.168.100.18')
1192 self
.assertRegex(output
, '1123-1150')
1193 self
.assertRegex(output
, '3224-3290')
1194 self
.assertRegex(output
, 'tcp')
1195 self
.assertRegex(output
, 'lookup 7')
1197 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1199 @expectedFailureIfRoutingPolicyIPProtoIsNotAvailable()
1200 def test_routing_policy_rule_invert(self
):
1201 self
.copy_unit_to_networkd_unit_path('25-fibrule-invert.network', '11-dummy.netdev')
1203 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1205 self
.start_networkd()
1207 self
.assertTrue(self
.link_exits('test1'))
1209 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
1211 self
.assertRegex(output
, '111')
1212 self
.assertRegex(output
, 'not.*?from.*?192.168.100.18')
1213 self
.assertRegex(output
, 'tcp')
1214 self
.assertRegex(output
, 'lookup 7')
1216 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1218 def test_route_static(self
):
1219 self
.copy_unit_to_networkd_unit_path('25-route-static.network', '12-dummy.netdev')
1220 self
.start_networkd(0)
1222 self
.wait_online(['dummy98:routable'])
1224 output
= subprocess
.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1226 self
.assertRegex(output
, '2001:1234:5:8fff:ff:ff:ff:ff proto static')
1227 self
.assertRegex(output
, '2001:1234:5:8f63::1 proto kernel')
1229 output
= subprocess
.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
1230 self
.assertRegex(output
, 'default via 2001:1234:5:8fff:ff:ff:ff:ff proto static metric 1024 pref medium')
1232 output
= subprocess
.check_output(['ip', '-4', 'route', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1234 self
.assertRegex(output
, '149.10.124.48/28 proto kernel scope link src 149.10.124.58')
1235 self
.assertRegex(output
, '149.10.124.64 proto static scope link')
1236 self
.assertRegex(output
, '169.254.0.0/16 proto static scope link metric 2048')
1237 self
.assertRegex(output
, '192.168.1.1 proto static initcwnd 20')
1238 self
.assertRegex(output
, '192.168.1.2 proto static initrwnd 30')
1240 output
= subprocess
.check_output(['ip', '-4', 'route', 'show', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
1241 self
.assertRegex(output
, 'default via 149.10.125.65 proto static onlink')
1242 self
.assertRegex(output
, 'default via 149.10.124.64 proto static')
1243 self
.assertRegex(output
, 'default proto static')
1245 output
= subprocess
.check_output(['ip', 'route', 'show', 'type', 'blackhole']).rstrip().decode('utf-8')
1247 self
.assertRegex(output
, 'blackhole 202.54.1.2 proto static')
1249 output
= subprocess
.check_output(['ip', 'route', 'show', 'type', 'unreachable']).rstrip().decode('utf-8')
1251 self
.assertRegex(output
, 'unreachable 202.54.1.3 proto static')
1253 output
= subprocess
.check_output(['ip', 'route', 'show', 'type', 'prohibit']).rstrip().decode('utf-8')
1255 self
.assertRegex(output
, 'prohibit 202.54.1.4 proto static')
1257 subprocess
.call(['ip', 'route', 'del', 'blackhole', '202.54.1.2'])
1258 subprocess
.call(['ip', 'route', 'del', 'unreachable', '202.54.1.3'])
1259 subprocess
.call(['ip', 'route', 'del', 'prohibit', '202.54.1.4'])
1261 def test_ip_route_ipv6_src_route(self
):
1262 # a dummy device does not make the addresses go through tentative state, so we
1263 # reuse a bond from an earlier test, which does make the addresses go through
1264 # tentative state, and do our test on that
1265 self
.copy_unit_to_networkd_unit_path('23-active-slave.network', '25-route-ipv6-src.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev')
1266 self
.start_networkd()
1268 self
.assertTrue(self
.link_exits('dummy98'))
1269 self
.assertTrue(self
.link_exits('bond199'))
1271 output
= subprocess
.check_output(['ip', '-6', 'route', 'list', 'dev', 'bond199']).rstrip().decode('utf-8')
1273 self
.assertRegex(output
, 'abcd::/16')
1274 self
.assertRegex(output
, 'src')
1275 self
.assertRegex(output
, '2001:1234:56:8f63::2')
1277 def test_ip_link_mac_address(self
):
1278 self
.copy_unit_to_networkd_unit_path('25-address-link-section.network', '12-dummy.netdev')
1279 self
.start_networkd()
1281 self
.assertTrue(self
.link_exits('dummy98'))
1283 output
= subprocess
.check_output(['ip', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1285 self
.assertRegex(output
, '00:01:02:aa:bb:cc')
1287 def test_ip_link_unmanaged(self
):
1288 self
.copy_unit_to_networkd_unit_path('25-link-section-unmanaged.network', '12-dummy.netdev')
1289 self
.start_networkd()
1291 self
.assertTrue(self
.link_exits('dummy98'))
1293 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1295 self
.assertRegex(output
, 'unmanaged')
1297 def test_ipv6_address_label(self
):
1298 self
.copy_unit_to_networkd_unit_path('25-ipv6-address-label-section.network', '12-dummy.netdev')
1299 self
.start_networkd()
1301 self
.assertTrue(self
.link_exits('dummy98'))
1303 output
= subprocess
.check_output(['ip', 'addrlabel', 'list']).rstrip().decode('utf-8')
1305 self
.assertRegex(output
, '2004:da8:1::/64')
1307 def test_ipv6_neighbor(self
):
1308 self
.copy_unit_to_networkd_unit_path('25-neighbor-section.network', '12-dummy.netdev')
1309 self
.start_networkd()
1311 self
.assertTrue(self
.link_exits('dummy98'))
1313 output
= subprocess
.check_output(['ip', 'neigh', 'list']).rstrip().decode('utf-8')
1315 self
.assertRegex(output
, '192.168.10.1.*00:00:5e:00:02:65.*PERMANENT')
1316 self
.assertRegex(output
, '2004:da8:1::1.*00:00:5e:00:02:66.*PERMANENT')
1318 def test_link_local_addressing(self
):
1319 self
.copy_unit_to_networkd_unit_path('25-link-local-addressing-yes.network', '11-dummy.netdev',
1320 '25-link-local-addressing-no.network', '12-dummy.netdev')
1321 self
.start_networkd(0)
1322 self
.wait_online(['test1:degraded', 'dummy98:carrier'])
1324 self
.assertTrue(self
.link_exits('test1'))
1325 self
.assertTrue(self
.link_exits('dummy98'))
1327 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'test1']).rstrip().decode('utf-8')
1329 self
.assertRegex(output
, 'inet .* scope link')
1330 self
.assertRegex(output
, 'inet6 .* scope link')
1332 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1334 self
.assertNotRegex(output
, 'inet6* .* scope link')
1336 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1338 self
.assertRegex(output
, 'State: degraded \(configured\)')
1340 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1342 self
.assertRegex(output
, 'State: carrier \(configured\)')
1345 Documentation/networking/ip-sysctl.txt
1347 addr_gen_mode - INTEGER
1348 Defines how link-local and autoconf addresses are generated.
1350 0: generate address based on EUI64 (default)
1351 1: do no generate a link-local address, use EUI64 for addresses generated
1353 2: generate stable privacy addresses, using the secret from
1354 stable_secret (RFC7217)
1355 3: generate stable privacy addresses, using a random secret if unset
1358 test1_addr_gen_mode
= ''
1359 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'stable_secret')):
1360 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'stable_secret')) as f
:
1364 # if stable_secret is unset, then EIO is returned
1365 test1_addr_gen_mode
= '0'
1367 test1_addr_gen_mode
= '2'
1369 test1_addr_gen_mode
= '0'
1371 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'addr_gen_mode')):
1372 self
.assertEqual(self
.read_ipv6_sysctl_attr('test1', 'addr_gen_mode'), test1_addr_gen_mode
)
1374 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'dummy98'), 'addr_gen_mode')):
1375 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'addr_gen_mode'), '1')
1377 def test_sysctl(self
):
1378 self
.copy_unit_to_networkd_unit_path('25-sysctl.network', '12-dummy.netdev')
1379 self
.start_networkd(0)
1380 self
.wait_online(['dummy98:degraded'])
1382 self
.assertTrue(self
.link_exits('dummy98'))
1384 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'forwarding'), '1')
1385 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'use_tempaddr'), '2')
1386 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'dad_transmits'), '3')
1387 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'hop_limit'), '5')
1388 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'proxy_ndp'), '1')
1389 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'forwarding'),'1')
1390 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'proxy_arp'), '1')
1392 def test_sysctl_disable_ipv6(self
):
1393 self
.copy_unit_to_networkd_unit_path('25-sysctl-disable-ipv6.network', '12-dummy.netdev')
1395 print('## Disable ipv6')
1396 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.all.disable_ipv6=1']), 0)
1397 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.default.disable_ipv6=1']), 0)
1399 self
.start_networkd(0)
1400 self
.wait_online(['dummy98:routable'])
1402 self
.assertTrue(self
.link_exits('dummy98'))
1404 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1406 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98')
1407 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1409 self
.assertEqual(output
, '')
1410 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1411 self
.assertRegex(output
, 'State: routable \(configured\)')
1413 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1415 print('## Enable ipv6')
1416 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.all.disable_ipv6=0']), 0)
1417 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.default.disable_ipv6=0']), 0)
1419 self
.start_networkd(0)
1420 self
.wait_online(['dummy98:routable'])
1422 self
.assertTrue(self
.link_exits('dummy98'))
1424 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1426 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98')
1427 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1429 self
.assertRegex(output
, 'inet6 .* scope link')
1430 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1431 self
.assertRegex(output
, 'State: routable \(configured\)')
1433 def test_bind_carrier(self
):
1434 self
.copy_unit_to_networkd_unit_path('25-bind-carrier.network', '11-dummy.netdev')
1435 self
.start_networkd()
1437 self
.assertTrue(self
.link_exits('test1'))
1439 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1440 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1442 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1444 self
.assertRegex(output
, 'UP,LOWER_UP')
1445 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1446 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1447 self
.assertRegex(output
, 'State: routable \(configured\)')
1449 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy99', 'type', 'dummy']), 0)
1450 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy99', 'up']), 0)
1452 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1454 self
.assertRegex(output
, 'UP,LOWER_UP')
1455 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1456 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1457 self
.assertRegex(output
, 'State: routable \(configured\)')
1459 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1461 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1463 self
.assertRegex(output
, 'UP,LOWER_UP')
1464 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1465 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1466 self
.assertRegex(output
, 'State: routable \(configured\)')
1468 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy99']), 0)
1470 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1472 self
.assertNotRegex(output
, 'UP,LOWER_UP')
1473 self
.assertRegex(output
, 'DOWN')
1474 self
.assertNotRegex(output
, '192.168.10')
1475 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1476 self
.assertRegex(output
, 'State: off \(configured\)')
1478 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1479 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1481 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1483 self
.assertRegex(output
, 'UP,LOWER_UP')
1484 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1485 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1486 self
.assertRegex(output
, 'State: routable \(configured\)')
1488 class NetworkdNetWorkBondTests(unittest
.TestCase
, Utilities
):
1498 '23-active-slave.network',
1499 '23-bond199.network',
1500 '23-primary-slave.network',
1501 '23-test1-bond199.network',
1502 '25-bond-active-backup-slave.netdev',
1505 'bond-slave.network']
1508 self
.link_remove(self
.links
)
1511 self
.link_remove(self
.links
)
1512 self
.remove_unit_from_networkd_path(self
.units
)
1514 def test_bond_active_slave(self
):
1515 self
.copy_unit_to_networkd_unit_path('23-active-slave.network', '23-bond199.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev')
1516 self
.start_networkd()
1518 self
.assertTrue(self
.link_exits('dummy98'))
1519 self
.assertTrue(self
.link_exits('bond199'))
1521 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
1523 self
.assertRegex(output
, 'active_slave dummy98')
1525 def test_bond_primary_slave(self
):
1526 self
.copy_unit_to_networkd_unit_path('23-primary-slave.network', '23-test1-bond199.network', '25-bond-active-backup-slave.netdev', '11-dummy.netdev')
1527 self
.start_networkd()
1529 self
.assertTrue(self
.link_exits('test1'))
1530 self
.assertTrue(self
.link_exits('bond199'))
1532 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
1534 self
.assertRegex(output
, 'primary test1')
1536 def test_bond_operstate(self
):
1537 self
.copy_unit_to_networkd_unit_path('25-bond.netdev', '11-dummy.netdev', '12-dummy.netdev',
1538 'bond99.network','bond-slave.network')
1539 self
.start_networkd()
1541 self
.assertTrue(self
.link_exits('bond99'))
1542 self
.assertTrue(self
.link_exits('dummy98'))
1543 self
.assertTrue(self
.link_exits('test1'))
1545 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1547 self
.assertRegex(output
, 'SLAVE,UP,LOWER_UP')
1549 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
1551 self
.assertRegex(output
, 'SLAVE,UP,LOWER_UP')
1553 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond99']).rstrip().decode('utf-8')
1555 self
.assertRegex(output
, 'MASTER,UP,LOWER_UP')
1557 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1559 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1561 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1563 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1565 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1567 self
.assertRegex(output
, 'State: routable \(configured\)')
1569 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'down']), 0)
1572 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1574 self
.assertRegex(output
, 'State: off \(configured\)')
1576 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1578 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1580 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1582 self
.assertRegex(output
, 'State: degraded-carrier \(configured\)')
1584 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1587 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1589 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1591 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1593 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1595 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1597 self
.assertRegex(output
, 'State: routable \(configured\)')
1599 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'down']), 0)
1600 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'test1', 'down']), 0)
1603 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1605 self
.assertRegex(output
, 'State: off \(configured\)')
1607 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1609 self
.assertRegex(output
, 'State: off \(configured\)')
1611 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1613 self
.assertRegex(output
, 'State: no-carrier \(configured\)')
1615 class NetworkdNetWorkBridgeTests(unittest
.TestCase
, Utilities
):
1625 '26-bridge-slave-interface-1.network',
1626 '26-bridge-slave-interface-2.network',
1627 'bridge99-ignore-carrier-loss.network',
1631 self
.link_remove(self
.links
)
1634 self
.link_remove(self
.links
)
1635 self
.remove_unit_from_networkd_path(self
.units
)
1637 def test_bridge_property(self
):
1638 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
1639 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
1641 self
.start_networkd()
1643 self
.assertTrue(self
.link_exits('dummy98'))
1644 self
.assertTrue(self
.link_exits('test1'))
1645 self
.assertTrue(self
.link_exits('bridge99'))
1647 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
1649 self
.assertRegex(output
, 'master')
1650 self
.assertRegex(output
, 'bridge')
1652 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1654 self
.assertRegex(output
, 'master')
1655 self
.assertRegex(output
, 'bridge')
1657 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99']).rstrip().decode('utf-8')
1659 self
.assertRegex(output
, '192.168.0.15/24')
1661 output
= subprocess
.check_output(['bridge', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1663 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'hairpin_mode'), '1')
1664 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'path_cost'), '400')
1665 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'unicast_flood'), '1')
1666 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_flood'), '0')
1667 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_fast_leave'), '1')
1668 if (os
.path
.exists('/sys/devices/virtual/net/bridge99/lower_dummy98/brport/neigh_suppress')):
1669 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'neigh_suppress'), '1')
1670 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'learning'), '0')
1672 # CONFIG_BRIDGE_IGMP_SNOOPING=y
1673 if (os
.path
.exists('/sys/devices/virtual/net/bridge00/lower_dummy98/brport/multicast_to_unicast')):
1674 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_to_unicast'), '1')
1676 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1677 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1679 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1680 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1682 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1683 self
.assertRegex(output
, 'State: routable \(configured\)')
1685 self
.assertEqual(subprocess
.call(['ip', 'address', 'add', '192.168.0.16/24', 'dev', 'bridge99']), 0)
1688 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99']).rstrip().decode('utf-8')
1690 self
.assertRegex(output
, '192.168.0.16/24')
1692 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1693 self
.assertRegex(output
, 'State: routable \(configured\)')
1695 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'test1']), 0)
1698 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1699 self
.assertRegex(output
, 'State: degraded-carrier \(configured\)')
1701 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1704 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1705 self
.assertRegex(output
, 'State: no-carrier \(configured\)')
1707 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1709 self
.assertRegex(output
, 'NO-CARRIER')
1710 self
.assertNotRegex(output
, '192.168.0.15/24')
1711 self
.assertNotRegex(output
, '192.168.0.16/24')
1713 def test_bridge_ignore_carrier_loss(self
):
1714 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
1715 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
1716 'bridge99-ignore-carrier-loss.network')
1718 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1720 self
.start_networkd()
1722 self
.assertTrue(self
.link_exits('dummy98'))
1723 self
.assertTrue(self
.link_exits('test1'))
1724 self
.assertTrue(self
.link_exits('bridge99'))
1726 self
.assertEqual(subprocess
.call(['ip', 'address', 'add', '192.168.0.16/24', 'dev', 'bridge99']), 0)
1729 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'test1']), 0)
1730 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1733 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1735 self
.assertRegex(output
, 'NO-CARRIER')
1736 self
.assertRegex(output
, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99')
1737 self
.assertRegex(output
, 'inet 192.168.0.16/24 scope global secondary bridge99')
1739 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1741 def test_bridge_ignore_carrier_loss_frequent_loss_and_gain(self
):
1742 self
.copy_unit_to_networkd_unit_path('26-bridge.netdev', '26-bridge-slave-interface-1.network',
1743 'bridge99-ignore-carrier-loss.network')
1745 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1747 self
.start_networkd()
1749 self
.assertTrue(self
.link_exits('bridge99'))
1751 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1752 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1753 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1755 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1756 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1757 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1759 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1760 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1761 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1763 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1764 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1768 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1770 self
.assertRegex(output
, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99')
1772 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1773 self
.assertRegex(output
, 'State: routable \(configured\)')
1775 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1776 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1778 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '100']).rstrip().decode('utf-8')
1780 self
.assertEqual(output
, '0: from all to 8.8.8.8 lookup 100')
1782 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1784 class NetworkdNetWorkLLDPTests(unittest
.TestCase
, Utilities
):
1788 '23-emit-lldp.network',
1793 self
.link_remove(self
.links
)
1796 self
.link_remove(self
.links
)
1797 self
.remove_unit_from_networkd_path(self
.units
)
1799 def test_lldp(self
):
1800 self
.copy_unit_to_networkd_unit_path('23-emit-lldp.network', '24-lldp.network', '25-veth.netdev')
1801 self
.start_networkd()
1803 self
.assertTrue(self
.link_exits('veth99'))
1805 output
= subprocess
.check_output(['networkctl', 'lldp']).rstrip().decode('utf-8')
1807 self
.assertRegex(output
, 'veth-peer')
1808 self
.assertRegex(output
, 'veth99')
1810 class NetworkdNetworkRATests(unittest
.TestCase
, Utilities
):
1815 'ipv6-prefix.network',
1816 'ipv6-prefix-veth.network']
1819 self
.link_remove(self
.links
)
1822 self
.link_remove(self
.links
)
1823 self
.remove_unit_from_networkd_path(self
.units
)
1825 def test_ipv6_prefix_delegation(self
):
1826 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth.network')
1827 self
.start_networkd()
1829 self
.assertTrue(self
.link_exits('veth99'))
1831 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1833 self
.assertRegex(output
, '2002:da8:1:0')
1835 class NetworkdNetworkDHCPServerTests(unittest
.TestCase
, Utilities
):
1842 '24-search-domain.network',
1844 'dhcp-client.network',
1845 'dhcp-client-timezone-router.network',
1846 'dhcp-server.network',
1847 'dhcp-server-timezone-router.network']
1850 self
.link_remove(self
.links
)
1853 self
.link_remove(self
.links
)
1854 self
.remove_unit_from_networkd_path(self
.units
)
1856 def test_dhcp_server(self
):
1857 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client.network', 'dhcp-server.network')
1858 self
.start_networkd()
1860 self
.assertTrue(self
.link_exits('veth99'))
1862 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1864 self
.assertRegex(output
, '192.168.5.*')
1865 self
.assertRegex(output
, 'Gateway: 192.168.5.1')
1866 self
.assertRegex(output
, 'DNS: 192.168.5.1')
1867 self
.assertRegex(output
, 'NTP: 192.168.5.1')
1869 def test_domain(self
):
1870 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '24-search-domain.network')
1871 self
.start_networkd()
1873 self
.assertTrue(self
.link_exits('dummy98'))
1875 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1877 self
.assertRegex(output
, 'Address: 192.168.42.100')
1878 self
.assertRegex(output
, 'DNS: 192.168.42.1')
1879 self
.assertRegex(output
, 'Search Domains: one')
1881 def test_emit_router_timezone(self
):
1882 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client-timezone-router.network', 'dhcp-server-timezone-router.network')
1883 self
.start_networkd()
1885 self
.assertTrue(self
.link_exits('veth99'))
1887 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1889 self
.assertRegex(output
, 'Gateway: 192.168.5.*')
1890 self
.assertRegex(output
, '192.168.5.*')
1891 self
.assertRegex(output
, 'Europe/Berlin')
1893 class NetworkdNetworkDHCPClientTests(unittest
.TestCase
, Utilities
):
1903 'dhcp-client-anonymize.network',
1904 'dhcp-client-critical-connection.network',
1905 'dhcp-client-gateway-onlink-implicit.network',
1906 'dhcp-client-ipv4-dhcp-settings.network',
1907 'dhcp-client-ipv4-only-ipv6-disabled.network',
1908 'dhcp-client-ipv4-only.network',
1909 'dhcp-client-ipv6-only.network',
1910 'dhcp-client-ipv6-rapid-commit.network',
1911 'dhcp-client-listen-port.network',
1912 'dhcp-client-route-metric.network',
1913 'dhcp-client-route-table.network',
1914 'dhcp-client-vrf.network',
1915 'dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network',
1916 'dhcp-client-with-ipv4ll-fallback-without-dhcp-server.network',
1917 'dhcp-client.network',
1918 'dhcp-server-veth-peer.network',
1919 'dhcp-v4-server-veth-peer.network',
1923 self
.link_remove(self
.links
)
1924 self
.stop_dnsmasq(dnsmasq_pid_file
)
1927 self
.link_remove(self
.links
)
1928 self
.remove_unit_from_networkd_path(self
.units
)
1929 self
.stop_dnsmasq(dnsmasq_pid_file
)
1930 self
.remove_lease_file()
1931 self
.remove_log_file()
1933 def test_dhcp_client_ipv6_only(self
):
1934 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
1936 self
.start_networkd(0)
1937 self
.wait_online(['veth-peer:carrier'])
1938 self
.start_dnsmasq()
1939 self
.wait_online(['veth99:routable', 'veth-peer:routable'])
1941 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1943 self
.assertRegex(output
, '2600::')
1944 self
.assertNotRegex(output
, '192.168.5')
1946 # Confirm that ipv6 token is not set in the kernel
1947 output
= subprocess
.check_output(['ip', 'token', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1949 self
.assertRegex(output
, 'token :: dev veth99')
1951 def test_dhcp_client_ipv4_only(self
):
1952 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-only-ipv6-disabled.network')
1953 self
.start_networkd()
1955 self
.assertTrue(self
.link_exits('veth99'))
1957 self
.start_dnsmasq()
1959 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1961 self
.assertNotRegex(output
, '2600::')
1962 self
.assertRegex(output
, '192.168.5')
1964 def test_dhcp_client_ipv4_ipv6(self
):
1965 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network',
1966 'dhcp-client-ipv4-only.network')
1967 self
.start_networkd()
1969 self
.assertTrue(self
.link_exits('veth99'))
1971 self
.start_dnsmasq()
1973 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1975 self
.assertRegex(output
, '2600::')
1976 self
.assertRegex(output
, '192.168.5')
1978 def test_dhcp_client_settings(self
):
1979 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-dhcp-settings.network')
1980 self
.start_networkd()
1982 self
.assertTrue(self
.link_exits('veth99'))
1984 self
.start_dnsmasq()
1986 print('## ip address show dev veth99')
1987 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1989 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1990 self
.assertRegex(output
, '192.168.5')
1991 self
.assertRegex(output
, '1492')
1994 print('## ip route show table main dev veth99')
1995 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', 'main', 'dev', 'veth99']).rstrip().decode('utf-8')
1997 self
.assertNotRegex(output
, 'proto dhcp')
1999 print('## ip route show table 211 dev veth99')
2000 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '211', 'dev', 'veth99']).rstrip().decode('utf-8')
2002 self
.assertRegex(output
, 'default via 192.168.5.1 proto dhcp')
2003 self
.assertRegex(output
, '192.168.5.0/24 via 192.168.5.5 proto dhcp')
2004 self
.assertRegex(output
, '192.168.5.1 proto dhcp scope link')
2006 print('## dnsmasq log')
2007 self
.assertTrue(self
.search_words_in_dnsmasq_log('vendor class: SusantVendorTest', True))
2008 self
.assertTrue(self
.search_words_in_dnsmasq_log('DHCPDISCOVER(veth-peer) 12:34:56:78:9a:bc'))
2009 self
.assertTrue(self
.search_words_in_dnsmasq_log('client provides name: test-hostname'))
2010 self
.assertTrue(self
.search_words_in_dnsmasq_log('26:mtu'))
2012 def test_dhcp6_client_settings_rapidcommit_true(self
):
2013 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
2014 self
.start_networkd()
2016 self
.assertTrue(self
.link_exits('veth99'))
2018 self
.start_dnsmasq()
2020 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2022 self
.assertRegex(output
, '12:34:56:78:9a:bc')
2023 self
.assertTrue(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
2025 def test_dhcp6_client_settings_rapidcommit_false(self
):
2026 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-rapid-commit.network')
2027 self
.start_networkd()
2029 self
.assertTrue(self
.link_exits('veth99'))
2031 self
.start_dnsmasq()
2033 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2035 self
.assertRegex(output
, '12:34:56:78:9a:bc')
2036 self
.assertFalse(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
2038 def test_dhcp_client_settings_anonymize(self
):
2039 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-anonymize.network')
2040 self
.start_networkd()
2042 self
.assertTrue(self
.link_exits('veth99'))
2044 self
.start_dnsmasq()
2046 self
.assertFalse(self
.search_words_in_dnsmasq_log('VendorClassIdentifier=SusantVendorTest', True))
2047 self
.assertFalse(self
.search_words_in_dnsmasq_log('test-hostname'))
2048 self
.assertFalse(self
.search_words_in_dnsmasq_log('26:mtu'))
2050 def test_dhcp_client_listen_port(self
):
2051 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-listen-port.network')
2052 self
.start_networkd()
2054 self
.assertTrue(self
.link_exits('veth99'))
2056 self
.start_dnsmasq('--dhcp-alternate-port=67,5555')
2058 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2060 self
.assertRegex(output
, '192.168.5.* dynamic')
2062 def test_dhcp_route_table_id(self
):
2063 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-table.network')
2064 self
.start_networkd()
2066 self
.assertTrue(self
.link_exits('veth99'))
2068 self
.start_dnsmasq()
2070 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '12']).rstrip().decode('utf-8')
2072 self
.assertRegex(output
, 'veth99 proto dhcp')
2073 self
.assertRegex(output
, '192.168.5.1')
2075 def test_dhcp_route_metric(self
):
2076 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-metric.network')
2077 self
.start_networkd()
2079 self
.assertTrue(self
.link_exits('veth99'))
2081 self
.start_dnsmasq()
2083 output
= subprocess
.check_output(['ip', 'route', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2085 self
.assertRegex(output
, 'metric 24')
2087 def test_dhcp_route_criticalconnection_true(self
):
2088 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-critical-connection.network')
2089 self
.start_networkd()
2091 self
.assertTrue(self
.link_exits('veth99'))
2093 self
.start_dnsmasq()
2095 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
2097 self
.assertRegex(output
, '192.168.5.*')
2099 # Stopping dnsmasq as networkd won't be allowed to renew the DHCP lease.
2100 self
.stop_dnsmasq(dnsmasq_pid_file
)
2102 # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
2105 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
2107 self
.assertRegex(output
, '192.168.5.*')
2109 def test_dhcp_client_reuse_address_as_static(self
):
2110 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client.network')
2111 self
.start_networkd()
2113 self
.assertTrue(self
.link_exits('veth99'))
2115 self
.start_dnsmasq()
2117 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
2119 self
.assertRegex(output
, '192.168.5')
2120 self
.assertRegex(output
, '2600::')
2122 ipv4_address
= re
.search('192\.168\.5\.[0-9]*/24', output
)
2123 ipv6_address
= re
.search('2600::[0-9a-f:]*/128', output
)
2124 static_network
= '\n'.join(['[Match]', 'Name=veth99', '[Network]', 'IPv6AcceptRA=no', 'Address=' + ipv4_address
.group(), 'Address=' + ipv6_address
.group()])
2125 print(static_network
)
2127 self
.remove_unit_from_networkd_path(['dhcp-client.network'])
2129 with
open(os
.path
.join(network_unit_file_path
, 'static.network'), mode
='w') as f
:
2130 f
.write(static_network
)
2132 self
.start_networkd()
2134 self
.assertTrue(self
.link_exits('veth99'))
2136 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
2138 self
.assertRegex(output
, '192.168.5')
2139 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
2141 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
2143 self
.assertRegex(output
, '2600::')
2144 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
2146 @expectedFailureIfModuleIsNotAvailable('vrf')
2147 def test_dhcp_client_vrf(self
):
2148 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-vrf.network',
2149 '25-vrf.netdev', '25-vrf.network')
2150 self
.start_networkd()
2152 self
.assertTrue(self
.link_exits('veth99'))
2153 self
.assertTrue(self
.link_exits('vrf99'))
2155 self
.start_dnsmasq()
2157 print('## ip -d link show dev vrf99')
2158 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dev', 'vrf99']).rstrip().decode('utf-8')
2160 self
.assertRegex(output
, 'vrf table 42')
2162 print('## ip address show vrf vrf99')
2163 output_ip_vrf
= subprocess
.check_output(['ip', 'address', 'show', 'vrf', 'vrf99']).rstrip().decode('utf-8')
2164 print(output_ip_vrf
)
2166 print('## ip address show dev veth99')
2167 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2169 self
.assertEqual(output
, output_ip_vrf
)
2170 self
.assertRegex(output
, 'inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99')
2171 self
.assertRegex(output
, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
2172 self
.assertRegex(output
, 'inet6 2600::[0-9a-f]*/128 scope global dynamic noprefixroute')
2173 self
.assertRegex(output
, 'inet6 .* scope link')
2175 print('## ip route show vrf vrf99')
2176 output
= subprocess
.check_output(['ip', 'route', 'show', 'vrf', 'vrf99']).rstrip().decode('utf-8')
2178 self
.assertRegex(output
, 'default via 192.168.5.1 dev veth99 proto dhcp src 192.168.5.')
2179 self
.assertRegex(output
, 'default dev veth99 proto static scope link')
2180 self
.assertRegex(output
, '169.254.0.0/16 dev veth99 proto kernel scope link src 169.254')
2181 self
.assertRegex(output
, '192.168.5.0/24 dev veth99 proto kernel scope link src 192.168.5')
2182 self
.assertRegex(output
, '192.168.5.0/24 via 192.168.5.5 dev veth99 proto dhcp')
2183 self
.assertRegex(output
, '192.168.5.1 dev veth99 proto dhcp scope link src 192.168.5')
2185 print('## ip route show table main dev veth99')
2186 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', 'main', 'dev', 'veth99']).rstrip().decode('utf-8')
2188 self
.assertEqual(output
, '')
2190 output
= subprocess
.check_output(['networkctl', 'status', 'vrf99']).rstrip().decode('utf-8')
2192 self
.assertRegex(output
, 'State: carrier \(configured\)')
2194 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
2196 self
.assertRegex(output
, 'State: routable \(configured\)')
2198 def test_dhcp_client_gateway_onlink_implicit(self
):
2199 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
2200 'dhcp-client-gateway-onlink-implicit.network')
2201 self
.start_networkd()
2203 self
.assertTrue(self
.link_exits('veth99'))
2205 self
.start_dnsmasq()
2207 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
2209 self
.assertRegex(output
, '192.168.5')
2211 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'veth99', '10.0.0.0/8']).rstrip().decode('utf-8')
2213 self
.assertRegex(output
, 'onlink')
2214 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'veth99', '192.168.100.0/24']).rstrip().decode('utf-8')
2216 self
.assertRegex(output
, 'onlink')
2218 def test_dhcp_client_with_ipv4ll_fallback_with_dhcp_server(self
):
2219 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
2220 'dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network')
2221 self
.start_networkd(0)
2222 self
.wait_online(['veth-peer:carrier'])
2223 self
.start_dnsmasq(lease_time
='2m')
2224 self
.wait_online(['veth99:routable', 'veth-peer:routable'])
2226 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2229 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic']).rstrip().decode('utf-8')
2230 self
.assertNotRegex(output
, 'inet6 2600::[0-9a-f]*/128 scope global dynamic')
2231 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'link']).rstrip().decode('utf-8')
2232 self
.assertRegex(output
, 'inet6 .* scope link')
2233 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic']).rstrip().decode('utf-8')
2234 self
.assertRegex(output
, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
2235 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'link']).rstrip().decode('utf-8')
2236 self
.assertNotRegex(output
, 'inet .* scope link')
2238 print('Wait for the dynamic address to be expired')
2241 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2244 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic']).rstrip().decode('utf-8')
2245 self
.assertNotRegex(output
, 'inet6 2600::[0-9a-f]*/128 scope global dynamic')
2246 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'link']).rstrip().decode('utf-8')
2247 self
.assertRegex(output
, 'inet6 .* scope link')
2248 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic']).rstrip().decode('utf-8')
2249 self
.assertRegex(output
, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
2250 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'link']).rstrip().decode('utf-8')
2251 self
.assertNotRegex(output
, 'inet .* scope link')
2253 self
.search_words_in_dnsmasq_log('DHCPOFFER', show_all
=True)
2255 def test_dhcp_client_with_ipv4ll_fallback_without_dhcp_server(self
):
2256 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
2257 'dhcp-client-with-ipv4ll-fallback-without-dhcp-server.network')
2258 self
.start_networkd(0)
2259 self
.wait_online(['veth99:degraded', 'veth-peer:routable'])
2261 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2264 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic']).rstrip().decode('utf-8')
2265 self
.assertNotRegex(output
, 'inet6 2600::[0-9a-f]*/128 scope global dynamic')
2266 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'link']).rstrip().decode('utf-8')
2267 self
.assertRegex(output
, 'inet6 .* scope link')
2268 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic']).rstrip().decode('utf-8')
2269 self
.assertNotRegex(output
, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
2270 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'link']).rstrip().decode('utf-8')
2271 self
.assertRegex(output
, 'inet .* scope link')
2273 if __name__
== '__main__':
2274 unittest
.main(testRunner
=unittest
.TextTestRunner(stream
=sys
.stdout
,