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
)
74 os
.makedirs(network_unit_file_path
, exist_ok
=True)
75 os
.makedirs(networkd_ci_path
, exist_ok
=True)
77 shutil
.rmtree(networkd_ci_path
)
78 copytree(os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), 'conf'), networkd_ci_path
)
80 subprocess
.check_call('systemctl stop systemd-networkd.socket', shell
=True)
83 shutil
.rmtree(networkd_ci_path
)
85 subprocess
.check_call('systemctl stop systemd-networkd.service', shell
=True)
86 subprocess
.check_call('systemctl start systemd-networkd.socket', shell
=True)
87 subprocess
.check_call('systemctl start systemd-networkd.service', shell
=True)
90 def read_link_attr(self
, link
, dev
, attribute
):
91 with
open(os
.path
.join(os
.path
.join(os
.path
.join('/sys/class/net/', link
), dev
), attribute
)) as f
:
92 return f
.readline().strip()
94 def read_bridge_port_attr(self
, bridge
, link
, attribute
):
96 path_bridge
= os
.path
.join('/sys/devices/virtual/net', bridge
)
97 path_port
= 'lower_' + link
+ '/brport'
98 path
= os
.path
.join(path_bridge
, path_port
)
100 with
open(os
.path
.join(path
, attribute
)) as f
:
101 return f
.readline().strip()
103 def link_exits(self
, link
):
104 return os
.path
.exists(os
.path
.join('/sys/class/net', link
))
106 def link_remove(self
, links
):
108 if os
.path
.exists(os
.path
.join('/sys/class/net', link
)):
109 subprocess
.call(['ip', 'link', 'del', 'dev', link
])
112 def l2tp_tunnel_remove(self
, tunnel_ids
):
113 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'tunnel']).rstrip().decode('utf-8')
114 for tid
in tunnel_ids
:
115 words
='Tunnel ' + tid
+ ', encap'
117 subprocess
.call(['ip', 'l2tp', 'del', 'tunnel', 'tid', tid
])
120 def read_ipv6_sysctl_attr(self
, link
, attribute
):
121 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, link
), attribute
)) as f
:
122 return f
.readline().strip()
124 def read_ipv4_sysctl_attr(self
, link
, attribute
):
125 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv4_path
, link
), attribute
)) as f
:
126 return f
.readline().strip()
128 def copy_unit_to_networkd_unit_path(self
, *units
):
131 shutil
.copy(os
.path
.join(networkd_ci_path
, unit
), network_unit_file_path
)
132 if (os
.path
.exists(os
.path
.join(networkd_ci_path
, unit
+ '.d'))):
133 copytree(os
.path
.join(networkd_ci_path
, unit
+ '.d'), os
.path
.join(network_unit_file_path
, unit
+ '.d'))
135 def remove_unit_from_networkd_path(self
, units
):
137 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
))):
138 os
.remove(os
.path
.join(network_unit_file_path
, unit
))
139 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
+ '.d'))):
140 shutil
.rmtree(os
.path
.join(network_unit_file_path
, unit
+ '.d'))
142 def start_dnsmasq(self
, additional_options
='', lease_time
='1h'):
143 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
144 subprocess
.check_call(dnsmasq_command
, shell
=True)
148 def stop_dnsmasq(self
, pid_file
):
149 if os
.path
.exists(pid_file
):
150 with
open(pid_file
, 'r') as f
:
151 pid
= f
.read().rstrip(' \t\r\n\0')
152 os
.kill(int(pid
), signal
.SIGTERM
)
156 def search_words_in_dnsmasq_log(self
, words
, show_all
=False):
157 if os
.path
.exists(dnsmasq_log_file
):
158 with
open (dnsmasq_log_file
) as in_file
:
159 contents
= in_file
.read()
162 for line
in contents
.split('\n'):
165 print("%s, %s" % (words
, line
))
169 def remove_lease_file(self
):
170 if os
.path
.exists(os
.path
.join(networkd_ci_path
, 'lease')):
171 os
.remove(os
.path
.join(networkd_ci_path
, 'lease'))
173 def remove_log_file(self
):
174 if os
.path
.exists(dnsmasq_log_file
):
175 os
.remove(dnsmasq_log_file
)
177 def start_networkd(self
, sleep_sec
=5, remove_state_files
=True):
178 if (remove_state_files
and
179 os
.path
.exists(os
.path
.join(networkd_runtime_directory
, 'state'))):
180 subprocess
.check_call('systemctl stop systemd-networkd', shell
=True)
181 os
.remove(os
.path
.join(networkd_runtime_directory
, 'state'))
182 subprocess
.check_call('systemctl start systemd-networkd', shell
=True)
184 subprocess
.check_call('systemctl restart systemd-networkd', shell
=True)
186 time
.sleep(sleep_sec
)
188 def wait_online(self
, links_with_operstate
, timeout
='20s', bool_any
=False):
189 args
= [wait_online_bin
, f
'--timeout={timeout}'] + [f
'--interface={link}' for link
in links_with_operstate
]
192 subprocess
.check_call(args
)
194 class NetworkdNetDevTests(unittest
.TestCase
, Utilities
):
250 '10-dropin-test.netdev',
254 '15-name-conflict-test.netdev',
257 '21-vlan-test1.network',
260 '25-6rd-tunnel.netdev',
262 '25-bond-balanced-tlb.netdev',
265 '25-erspan-tunnel-local-any.netdev',
266 '25-erspan-tunnel.netdev',
267 '25-fou-gretap.netdev',
269 '25-fou-ipip.netdev',
270 '25-fou-ipproto-gre.netdev',
271 '25-fou-ipproto-ipip.netdev',
274 '25-gretap-tunnel-local-any.netdev',
275 '25-gretap-tunnel.netdev',
276 '25-gre-tunnel-local-any.netdev',
277 '25-gre-tunnel-remote-any.netdev',
278 '25-gre-tunnel.netdev',
279 '25-ip6gretap-tunnel-local-any.netdev',
280 '25-ip6gretap-tunnel.netdev',
281 '25-ip6gre-tunnel-local-any.netdev',
282 '25-ip6gre-tunnel-remote-any.netdev',
283 '25-ip6gre-tunnel.netdev',
284 '25-ip6tnl-tunnel-remote-any.netdev',
285 '25-ip6tnl-tunnel-local-any.netdev',
286 '25-ip6tnl-tunnel.netdev',
287 '25-ipip-tunnel-independent.netdev',
288 '25-ipip-tunnel-local-any.netdev',
289 '25-ipip-tunnel-remote-any.netdev',
290 '25-ipip-tunnel.netdev',
292 '25-isatap-tunnel.netdev',
296 '25-sit-tunnel-local-any.netdev',
297 '25-sit-tunnel-remote-any.netdev',
298 '25-sit-tunnel.netdev',
304 '25-vti6-tunnel-local-any.netdev',
305 '25-vti6-tunnel-remote-any.netdev',
306 '25-vti6-tunnel.netdev',
307 '25-vti-tunnel-local-any.netdev',
308 '25-vti-tunnel-remote-any.netdev',
309 '25-vti-tunnel.netdev',
311 '25-wireguard-23-peers.netdev',
312 '25-wireguard-23-peers.network',
313 '25-wireguard-preshared-key.txt',
314 '25-wireguard-private-key.txt',
315 '25-wireguard.netdev',
316 '25-wireguard.network',
334 'vxlan-test1.network',
338 self
.link_remove(self
.links
)
341 self
.link_remove(self
.links
)
342 self
.remove_unit_from_networkd_path(self
.units
)
344 def test_dropin(self
):
345 self
.copy_unit_to_networkd_unit_path('10-dropin-test.netdev', '15-name-conflict-test.netdev')
346 self
.start_networkd()
348 self
.assertTrue(self
.link_exits('dropin-test'))
350 # This also tests NetDev.Name= conflict and basic networkctl functionalities
352 output
= subprocess
.check_output(['ip', 'link', 'show', 'dropin-test']).rstrip().decode('utf-8')
354 self
.assertRegex(output
, '00:50:56:c0:00:28')
356 output
= subprocess
.check_output(['networkctl', 'list']).rstrip().decode('utf-8')
357 self
.assertRegex(output
, '1 lo ')
358 self
.assertRegex(output
, 'dropin-test')
360 output
= subprocess
.check_output(['networkctl', 'list', 'dropin-test']).rstrip().decode('utf-8')
361 self
.assertNotRegex(output
, '1 lo ')
362 self
.assertRegex(output
, 'dropin-test')
364 output
= subprocess
.check_output(['networkctl', 'list', 'dropin-*']).rstrip().decode('utf-8')
365 self
.assertNotRegex(output
, '1 lo ')
366 self
.assertRegex(output
, 'dropin-test')
368 output
= subprocess
.check_output(['networkctl', 'status', 'dropin-*']).rstrip().decode('utf-8')
369 self
.assertNotRegex(output
, '1: lo ')
370 self
.assertRegex(output
, 'dropin-test')
372 ret
= subprocess
.run(['ethtool', '--driver', 'dropin-test'], stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
)
373 print(ret
.stdout
.rstrip().decode('utf-8'))
374 if ret
.returncode
== 0 and re
.search('driver: dummy', ret
.stdout
.rstrip().decode('utf-8')) != None:
375 self
.assertRegex(output
, 'Driver: dummy')
377 print('ethtool does not support driver field at least for dummy interfaces, skipping test for Driver field of networkctl.')
379 def test_wait_online_any(self
):
380 self
.copy_unit_to_networkd_unit_path('25-bridge.netdev', '25-bridge.network', '11-dummy.netdev', '11-dummy.network')
381 self
.start_networkd(0)
383 self
.wait_online(['bridge99', 'test1:degraded'], bool_any
=True)
384 self
.assertTrue(self
.link_exits('bridge99'))
385 self
.assertTrue(self
.link_exits('test1'))
387 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
389 self
.assertRegex(output
, 'State: (?:off|no-carrier) \(configuring\)')
391 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
393 self
.assertRegex(output
, 'State: degraded \(configured\)')
395 def test_bridge(self
):
396 self
.copy_unit_to_networkd_unit_path('25-bridge.netdev')
397 self
.start_networkd()
399 self
.assertTrue(self
.link_exits('bridge99'))
401 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'hello_time'))
402 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge', 'max_age'))
403 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','forward_delay'))
404 self
.assertEqual('900', self
.read_link_attr('bridge99', 'bridge','ageing_time'))
405 self
.assertEqual('9', self
.read_link_attr('bridge99', 'bridge','priority'))
406 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_querier'))
407 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','multicast_snooping'))
408 self
.assertEqual('1', self
.read_link_attr('bridge99', 'bridge','stp_state'))
411 self
.copy_unit_to_networkd_unit_path('25-bond.netdev')
412 self
.start_networkd()
414 self
.assertTrue(self
.link_exits('bond99'))
416 self
.assertEqual('802.3ad 4', self
.read_link_attr('bond99', 'bonding', 'mode'))
417 self
.assertEqual('layer3+4 1', self
.read_link_attr('bond99', 'bonding', 'xmit_hash_policy'))
418 self
.assertEqual('1000', self
.read_link_attr('bond99', 'bonding', 'miimon'))
419 self
.assertEqual('fast 1', self
.read_link_attr('bond99', 'bonding', 'lacp_rate'))
420 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'updelay'))
421 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'downdelay'))
422 self
.assertEqual('4', self
.read_link_attr('bond99', 'bonding', 'resend_igmp'))
423 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'min_links'))
424 self
.assertEqual('1218', self
.read_link_attr('bond99', 'bonding', 'ad_actor_sys_prio'))
425 self
.assertEqual('811', self
.read_link_attr('bond99', 'bonding', 'ad_user_port_key'))
426 self
.assertEqual('00:11:22:33:44:55', self
.read_link_attr('bond99', 'bonding', 'ad_actor_system'))
428 def test_bond_balanced_tlb(self
):
429 self
.copy_unit_to_networkd_unit_path('25-bond-balanced-tlb.netdev')
430 self
.start_networkd()
432 self
.assertTrue(self
.link_exits('bond99'))
434 self
.assertEqual('balance-tlb 5', self
.read_link_attr('bond99', 'bonding', 'mode'))
435 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'tlb_dynamic_lb'))
438 self
.copy_unit_to_networkd_unit_path('21-vlan.netdev', '11-dummy.netdev',
439 '21-vlan.network', '21-vlan-test1.network')
440 self
.start_networkd()
442 self
.assertTrue(self
.link_exits('test1'))
443 self
.assertTrue(self
.link_exits('vlan99'))
445 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
447 self
.assertRegex(output
, ' mtu 2004 ')
449 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vlan99']).rstrip().decode('utf-8')
451 self
.assertRegex(output
, ' mtu 2000 ')
452 self
.assertRegex(output
, 'REORDER_HDR')
453 self
.assertRegex(output
, 'LOOSE_BINDING')
454 self
.assertRegex(output
, 'GVRP')
455 self
.assertRegex(output
, 'MVRP')
456 self
.assertRegex(output
, ' id 99 ')
458 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'test1']).rstrip().decode('utf-8')
460 self
.assertRegex(output
, 'inet 192.168.24.5/24 brd 192.168.24.255 scope global test1')
461 self
.assertRegex(output
, 'inet 192.168.25.5/24 brd 192.168.25.255 scope global test1')
463 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'vlan99']).rstrip().decode('utf-8')
465 self
.assertRegex(output
, 'inet 192.168.23.5/24 brd 192.168.23.255 scope global vlan99')
467 def test_macvtap(self
):
468 self
.copy_unit_to_networkd_unit_path('21-macvtap.netdev', '11-dummy.netdev', 'macvtap.network')
469 self
.start_networkd()
471 self
.assertTrue(self
.link_exits('macvtap99'))
473 def test_macvlan(self
):
474 self
.copy_unit_to_networkd_unit_path('21-macvlan.netdev', '11-dummy.netdev', 'macvlan.network')
475 self
.start_networkd()
477 self
.assertTrue(self
.link_exits('test1'))
478 self
.assertTrue(self
.link_exits('macvlan99'))
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', 'macvlan99']).rstrip().decode('utf-8')
486 self
.assertRegex(output
, ' mtu 2000 ')
488 @expectedFailureIfModuleIsNotAvailable('ipvlan')
489 def test_ipvlan(self
):
490 self
.copy_unit_to_networkd_unit_path('25-ipvlan.netdev', '11-dummy.netdev', 'ipvlan.network')
491 self
.start_networkd()
493 self
.assertTrue(self
.link_exits('ipvlan99'))
496 self
.copy_unit_to_networkd_unit_path('25-veth.netdev')
497 self
.start_networkd()
499 self
.assertTrue(self
.link_exits('veth99'))
501 def test_dummy(self
):
502 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev')
503 self
.start_networkd()
505 self
.assertTrue(self
.link_exits('test1'))
508 self
.copy_unit_to_networkd_unit_path('25-tun.netdev')
509 self
.start_networkd()
511 self
.assertTrue(self
.link_exits('tun99'))
514 self
.copy_unit_to_networkd_unit_path('25-tap.netdev')
515 self
.start_networkd()
517 self
.assertTrue(self
.link_exits('tap99'))
519 @expectedFailureIfModuleIsNotAvailable('vrf')
521 self
.copy_unit_to_networkd_unit_path('25-vrf.netdev')
522 self
.start_networkd()
524 self
.assertTrue(self
.link_exits('vrf99'))
526 @expectedFailureIfModuleIsNotAvailable('vcan')
528 self
.copy_unit_to_networkd_unit_path('25-vcan.netdev')
529 self
.start_networkd()
531 self
.assertTrue(self
.link_exits('vcan99'))
533 @expectedFailureIfModuleIsNotAvailable('wireguard')
534 def test_wireguard(self
):
535 self
.copy_unit_to_networkd_unit_path('25-wireguard.netdev', '25-wireguard.network',
536 '25-wireguard-23-peers.netdev', '25-wireguard-23-peers.network',
537 '25-wireguard-preshared-key.txt', '25-wireguard-private-key.txt')
538 self
.start_networkd(0)
539 self
.wait_online(['wg99:carrier', 'wg98:routable'])
541 self
.assertTrue(self
.link_exits('wg99'))
542 self
.assertTrue(self
.link_exits('wg98'))
544 if shutil
.which('wg'):
545 subprocess
.call('wg')
547 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'listen-port']).rstrip().decode('utf-8')
548 self
.assertRegex(output
, '51820')
549 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'fwmark']).rstrip().decode('utf-8')
550 self
.assertRegex(output
, '0x4d2')
551 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'allowed-ips']).rstrip().decode('utf-8')
552 self
.assertRegex(output
, 'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t192.168.26.0/24 fd31:bf08:57cb::/48')
553 self
.assertRegex(output
, 'lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc=\tfdbc:bae2:7871:e1fe:793:8636::/96 fdbc:bae2:7871:500:e1fe:793:8636:dad1/128')
554 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'persistent-keepalive']).rstrip().decode('utf-8')
555 self
.assertRegex(output
, 'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t20')
556 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'endpoints']).rstrip().decode('utf-8')
557 self
.assertRegex(output
, 'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t192.168.27.3:51820')
558 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'private-key']).rstrip().decode('utf-8')
559 self
.assertRegex(output
, 'EEGlnEPYJV//kbvvIqxKkQwOiS\+UENyPncC4bF46ong=')
560 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'preshared-keys']).rstrip().decode('utf-8')
561 self
.assertRegex(output
, 'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA= IIWIV17wutHv7t4cR6pOT91z6NSz/T8Arh0yaywhw3M=')
562 self
.assertRegex(output
, 'lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc= cPLOy1YUrEI0EMMIycPJmOo0aTu3RZnw8bL5meVD6m0=')
564 output
= subprocess
.check_output(['wg', 'show', 'wg98', 'private-key']).rstrip().decode('utf-8')
565 self
.assertRegex(output
, 'CJQUtcS9emY2fLYqDlpSZiE/QJyHkPWr\+WHtZLZ90FU=')
567 def test_geneve(self
):
568 self
.copy_unit_to_networkd_unit_path('25-geneve.netdev')
569 self
.start_networkd()
571 self
.assertTrue(self
.link_exits('geneve99'))
573 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'geneve99']).rstrip().decode('utf-8')
575 self
.assertRegex(output
, '192.168.22.1')
576 self
.assertRegex(output
, '6082')
577 self
.assertRegex(output
, 'udpcsum')
578 self
.assertRegex(output
, 'udp6zerocsumrx')
580 def test_ipip_tunnel(self
):
581 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ipip-tunnel.netdev', 'ipip.network',
582 '25-ipip-tunnel-local-any.netdev', '25-ipip-tunnel-remote-any.netdev')
583 self
.start_networkd()
585 self
.assertTrue(self
.link_exits('dummy98'))
586 self
.assertTrue(self
.link_exits('ipiptun99'))
587 self
.assertTrue(self
.link_exits('ipiptun98'))
588 self
.assertTrue(self
.link_exits('ipiptun97'))
590 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun99']).rstrip().decode('utf-8')
592 self
.assertRegex(output
, 'ipip (?:ipip |)remote 192.169.224.239 local 192.168.223.238 dev dummy98')
593 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun98']).rstrip().decode('utf-8')
595 self
.assertRegex(output
, 'ipip (?:ipip |)remote 192.169.224.239 local any dev dummy98')
596 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun97']).rstrip().decode('utf-8')
598 self
.assertRegex(output
, 'ipip (?:ipip |)remote any local 192.168.223.238 dev dummy98')
600 def test_gre_tunnel(self
):
601 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gre-tunnel.netdev', 'gretun.network',
602 '25-gre-tunnel-local-any.netdev', '25-gre-tunnel-remote-any.netdev')
603 self
.start_networkd()
605 self
.assertTrue(self
.link_exits('dummy98'))
606 self
.assertTrue(self
.link_exits('gretun99'))
607 self
.assertTrue(self
.link_exits('gretun98'))
608 self
.assertTrue(self
.link_exits('gretun97'))
610 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun99']).rstrip().decode('utf-8')
612 self
.assertRegex(output
, 'gre remote 10.65.223.239 local 10.65.223.238 dev dummy98')
613 self
.assertRegex(output
, 'ikey 1.2.3.103')
614 self
.assertRegex(output
, 'okey 1.2.4.103')
615 self
.assertRegex(output
, 'iseq')
616 self
.assertRegex(output
, 'oseq')
617 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun98']).rstrip().decode('utf-8')
619 self
.assertRegex(output
, 'gre remote 10.65.223.239 local any dev dummy98')
620 self
.assertRegex(output
, 'ikey 0.0.0.104')
621 self
.assertRegex(output
, 'okey 0.0.0.104')
622 self
.assertNotRegex(output
, 'iseq')
623 self
.assertNotRegex(output
, 'oseq')
624 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun97']).rstrip().decode('utf-8')
626 self
.assertRegex(output
, 'gre remote any local 10.65.223.238 dev dummy98')
627 self
.assertRegex(output
, 'ikey 0.0.0.105')
628 self
.assertRegex(output
, 'okey 0.0.0.105')
629 self
.assertNotRegex(output
, 'iseq')
630 self
.assertNotRegex(output
, 'oseq')
632 def test_ip6gre_tunnel(self
):
633 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6gre-tunnel.netdev', 'ip6gretun.network',
634 '25-ip6gre-tunnel-local-any.netdev', '25-ip6gre-tunnel-remote-any.netdev')
635 self
.start_networkd()
637 self
.assertTrue(self
.link_exits('dummy98'))
638 self
.assertTrue(self
.link_exits('ip6gretun99'))
639 self
.assertTrue(self
.link_exits('ip6gretun98'))
640 self
.assertTrue(self
.link_exits('ip6gretun97'))
642 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretun99']).rstrip().decode('utf-8')
644 self
.assertRegex(output
, 'ip6gre remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
645 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretun98']).rstrip().decode('utf-8')
647 self
.assertRegex(output
, 'ip6gre remote 2001:473:fece:cafe::5179 local any dev dummy98')
648 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretun97']).rstrip().decode('utf-8')
650 self
.assertRegex(output
, 'ip6gre remote any local 2a00:ffde:4567:edde::4987 dev dummy98')
652 def test_gretap_tunnel(self
):
653 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-gretap-tunnel.netdev', 'gretap.network',
654 '25-gretap-tunnel-local-any.netdev')
655 self
.start_networkd()
657 self
.assertTrue(self
.link_exits('dummy98'))
658 self
.assertTrue(self
.link_exits('gretap99'))
659 self
.assertTrue(self
.link_exits('gretap98'))
661 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretap99']).rstrip().decode('utf-8')
663 self
.assertRegex(output
, 'gretap remote 10.65.223.239 local 10.65.223.238 dev dummy98')
664 self
.assertRegex(output
, 'ikey 0.0.0.106')
665 self
.assertRegex(output
, 'okey 0.0.0.106')
666 self
.assertRegex(output
, 'iseq')
667 self
.assertRegex(output
, 'oseq')
668 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretap98']).rstrip().decode('utf-8')
670 self
.assertRegex(output
, 'gretap remote 10.65.223.239 local any dev dummy98')
671 self
.assertRegex(output
, 'ikey 0.0.0.107')
672 self
.assertRegex(output
, 'okey 0.0.0.107')
673 self
.assertRegex(output
, 'iseq')
674 self
.assertRegex(output
, 'oseq')
676 def test_ip6gretap_tunnel(self
):
677 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6gretap-tunnel.netdev', 'ip6gretap.network',
678 '25-ip6gretap-tunnel-local-any.netdev')
679 self
.start_networkd()
681 self
.assertTrue(self
.link_exits('dummy98'))
682 self
.assertTrue(self
.link_exits('ip6gretap99'))
683 self
.assertTrue(self
.link_exits('ip6gretap98'))
685 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretap99']).rstrip().decode('utf-8')
687 self
.assertRegex(output
, 'ip6gretap remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
688 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretap98']).rstrip().decode('utf-8')
690 self
.assertRegex(output
, 'ip6gretap remote 2001:473:fece:cafe::5179 local any dev dummy98')
692 def test_vti_tunnel(self
):
693 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti-tunnel.netdev', 'vti.network',
694 '25-vti-tunnel-local-any.netdev', '25-vti-tunnel-remote-any.netdev')
695 self
.start_networkd()
697 self
.assertTrue(self
.link_exits('dummy98'))
698 self
.assertTrue(self
.link_exits('vtitun99'))
699 self
.assertTrue(self
.link_exits('vtitun98'))
700 self
.assertTrue(self
.link_exits('vtitun97'))
702 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vtitun99']).rstrip().decode('utf-8')
704 self
.assertRegex(output
, 'vti remote 10.65.223.239 local 10.65.223.238 dev dummy98')
705 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vtitun98']).rstrip().decode('utf-8')
707 self
.assertRegex(output
, 'vti remote 10.65.223.239 local any dev dummy98')
708 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vtitun97']).rstrip().decode('utf-8')
710 self
.assertRegex(output
, 'vti remote any local 10.65.223.238 dev dummy98')
712 def test_vti6_tunnel(self
):
713 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-vti6-tunnel.netdev', 'vti6.network',
714 '25-vti6-tunnel-local-any.netdev', '25-vti6-tunnel-remote-any.netdev')
715 self
.start_networkd()
717 self
.assertTrue(self
.link_exits('dummy98'))
718 self
.assertTrue(self
.link_exits('vti6tun99'))
719 self
.assertTrue(self
.link_exits('vti6tun98'))
720 self
.assertTrue(self
.link_exits('vti6tun97'))
722 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vti6tun99']).rstrip().decode('utf-8')
724 self
.assertRegex(output
, 'vti6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
725 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vti6tun98']).rstrip().decode('utf-8')
727 self
.assertRegex(output
, 'vti6 remote 2001:473:fece:cafe::5179 local (?:any|::) dev dummy98')
728 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vti6tun97']).rstrip().decode('utf-8')
730 self
.assertRegex(output
, 'vti6 remote (?:any|::) local 2a00:ffde:4567:edde::4987 dev dummy98')
732 def test_ip6tnl_tunnel(self
):
733 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-ip6tnl-tunnel.netdev', 'ip6tnl.network',
734 '25-ip6tnl-tunnel-local-any.netdev', '25-ip6tnl-tunnel-remote-any.netdev')
735 self
.start_networkd()
737 self
.assertTrue(self
.link_exits('dummy98'))
738 self
.assertTrue(self
.link_exits('ip6tnl99'))
739 self
.assertTrue(self
.link_exits('ip6tnl98'))
740 self
.assertTrue(self
.link_exits('ip6tnl97'))
742 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6tnl99']).rstrip().decode('utf-8')
744 self
.assertRegex(output
, 'ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
745 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6tnl98']).rstrip().decode('utf-8')
747 self
.assertRegex(output
, 'ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local (?:any|::) dev dummy98')
748 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6tnl97']).rstrip().decode('utf-8')
750 self
.assertRegex(output
, 'ip6tnl ip6ip6 remote (?:any|::) local 2a00:ffde:4567:edde::4987 dev dummy98')
752 def test_sit_tunnel(self
):
753 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-sit-tunnel.netdev', 'sit.network',
754 '25-sit-tunnel-local-any.netdev',
755 '25-sit-tunnel-remote-any.netdev')
756 self
.start_networkd()
758 self
.assertTrue(self
.link_exits('dummy98'))
759 self
.assertTrue(self
.link_exits('sittun99'))
760 self
.assertTrue(self
.link_exits('sittun98'))
761 self
.assertTrue(self
.link_exits('sittun97'))
763 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun99']).rstrip().decode('utf-8')
765 self
.assertRegex(output
, "sit (?:ip6ip |)remote 10.65.223.239 local 10.65.223.238 dev dummy98")
766 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun98']).rstrip().decode('utf-8')
768 self
.assertRegex(output
, "sit (?:ip6ip |)remote 10.65.223.239 local any dev dummy98")
769 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun97']).rstrip().decode('utf-8')
771 self
.assertRegex(output
, "sit (?:ip6ip |)remote any local 10.65.223.238 dev dummy98")
773 def test_isatap_tunnel(self
):
774 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-isatap-tunnel.netdev', 'isatap.network')
775 self
.start_networkd()
777 self
.assertTrue(self
.link_exits('dummy98'))
778 self
.assertTrue(self
.link_exits('isataptun99'))
780 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'isataptun99']).rstrip().decode('utf-8')
782 self
.assertRegex(output
, "isatap ")
784 def test_6rd_tunnel(self
):
785 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '25-6rd-tunnel.netdev', '6rd.network')
786 self
.start_networkd()
788 self
.assertTrue(self
.link_exits('dummy98'))
789 self
.assertTrue(self
.link_exits('sittun99'))
791 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun99']).rstrip().decode('utf-8')
793 self
.assertRegex(output
, '6rd-prefix 2602::/24')
795 @expectedFailureIfERSPANModuleIsNotAvailable()
796 def test_erspan_tunnel(self
):
797 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'erspan.network',
798 '25-erspan-tunnel.netdev', '25-erspan-tunnel-local-any.netdev')
799 self
.start_networkd()
801 self
.assertTrue(self
.link_exits('dummy98'))
802 self
.assertTrue(self
.link_exits('erspan99'))
803 self
.assertTrue(self
.link_exits('erspan98'))
805 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'erspan99']).rstrip().decode('utf-8')
807 self
.assertRegex(output
, 'erspan remote 172.16.1.100 local 172.16.1.200')
808 self
.assertRegex(output
, 'ikey 0.0.0.101')
809 self
.assertRegex(output
, 'okey 0.0.0.101')
810 self
.assertRegex(output
, 'iseq')
811 self
.assertRegex(output
, 'oseq')
812 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'erspan98']).rstrip().decode('utf-8')
814 self
.assertRegex(output
, 'erspan remote 172.16.1.100 local any')
815 self
.assertRegex(output
, '102')
816 self
.assertRegex(output
, 'ikey 0.0.0.102')
817 self
.assertRegex(output
, 'okey 0.0.0.102')
818 self
.assertRegex(output
, 'iseq')
819 self
.assertRegex(output
, 'oseq')
821 def test_tunnel_independent(self
):
822 self
.copy_unit_to_networkd_unit_path('25-ipip-tunnel-independent.netdev')
823 self
.start_networkd()
825 self
.assertTrue(self
.link_exits('ipiptun99'))
827 @expectedFailureIfModuleIsNotAvailable('fou')
829 # The following redundant check is necessary for CentOS CI.
830 # Maybe, error handling in lookup_id() in sd-netlink/generic-netlink.c needs to be updated.
831 self
.assertTrue(is_module_available('fou'))
833 self
.copy_unit_to_networkd_unit_path('25-fou-ipproto-ipip.netdev', '25-fou-ipproto-gre.netdev',
834 '25-fou-ipip.netdev', '25-fou-sit.netdev',
835 '25-fou-gre.netdev', '25-fou-gretap.netdev')
836 self
.start_networkd()
838 self
.assertTrue(self
.link_exits('ipiptun96'))
839 self
.assertTrue(self
.link_exits('sittun96'))
840 self
.assertTrue(self
.link_exits('gretun96'))
841 self
.assertTrue(self
.link_exits('gretap96'))
843 output
= subprocess
.check_output(['ip', 'fou', 'show']).rstrip().decode('utf-8')
845 self
.assertRegex(output
, 'port 55555 ipproto 4')
846 self
.assertRegex(output
, 'port 55556 ipproto 47')
848 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun96']).rstrip().decode('utf-8')
850 self
.assertRegex(output
, 'encap fou encap-sport auto encap-dport 55555')
851 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun96']).rstrip().decode('utf-8')
853 self
.assertRegex(output
, 'encap fou encap-sport auto encap-dport 55555')
854 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun96']).rstrip().decode('utf-8')
856 self
.assertRegex(output
, 'encap fou encap-sport 1001 encap-dport 55556')
857 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretap96']).rstrip().decode('utf-8')
859 self
.assertRegex(output
, 'encap fou encap-sport auto encap-dport 55556')
861 subprocess
.call(['ip', 'fou', 'del', 'port', '55555'])
862 subprocess
.call(['ip', 'fou', 'del', 'port', '55556'])
864 def test_vxlan(self
):
865 self
.copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network',
866 '11-dummy.netdev', 'vxlan-test1.network')
867 self
.start_networkd(0)
869 self
.wait_online(['test1:degraded', 'vxlan99:degraded'])
871 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vxlan99']).rstrip().decode('utf-8')
873 self
.assertRegex(output
, '999')
874 self
.assertRegex(output
, '5555')
875 self
.assertRegex(output
, 'l2miss')
876 self
.assertRegex(output
, 'l3miss')
877 self
.assertRegex(output
, 'udpcsum')
878 self
.assertRegex(output
, 'udp6zerocsumtx')
879 self
.assertRegex(output
, 'udp6zerocsumrx')
880 self
.assertRegex(output
, 'remcsumtx')
881 self
.assertRegex(output
, 'remcsumrx')
882 self
.assertRegex(output
, 'gbp')
884 output
= subprocess
.check_output(['bridge', 'fdb', 'show', 'dev', 'vxlan99']).rstrip().decode('utf-8')
886 self
.assertRegex(output
, '00:11:22:33:44:55 dst 10.0.0.5 self permanent')
887 self
.assertRegex(output
, '00:11:22:33:44:66 dst 10.0.0.6 self permanent')
888 self
.assertRegex(output
, '00:11:22:33:44:77 dst 10.0.0.7 self permanent')
890 def test_macsec(self
):
891 self
.copy_unit_to_networkd_unit_path('25-macsec.netdev', '25-macsec.network', '25-macsec.key',
892 'macsec.network', '12-dummy.netdev')
893 self
.start_networkd(0)
895 self
.wait_online(['dummy98:degraded', 'macsec99:routable'])
897 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'macsec99']).rstrip().decode('utf-8')
899 self
.assertRegex(output
, 'macsec99@dummy98')
900 self
.assertRegex(output
, 'macsec sci [0-9a-f]*000b')
901 self
.assertRegex(output
, 'encrypt on')
903 output
= subprocess
.check_output(['ip', 'macsec', 'show', 'macsec99']).rstrip().decode('utf-8')
905 self
.assertRegex(output
, 'encrypt on')
906 self
.assertRegex(output
, 'TXSC: [0-9a-f]*000b on SA 1')
907 self
.assertRegex(output
, '0: PN [0-9]*, state on, key 01000000000000000000000000000000')
908 self
.assertRegex(output
, '1: PN [0-9]*, state on, key 02030000000000000000000000000000')
909 self
.assertRegex(output
, 'RXSC: c619528fe6a00100, state on')
910 self
.assertRegex(output
, '0: PN [0-9]*, state on, key 02030405000000000000000000000000')
911 self
.assertRegex(output
, '1: PN [0-9]*, state on, key 02030405060000000000000000000000')
912 self
.assertRegex(output
, '2: PN [0-9]*, state off, key 02030405060700000000000000000000')
913 self
.assertRegex(output
, '3: PN [0-9]*, state off, key 02030405060708000000000000000000')
914 self
.assertNotRegex(output
, 'key 02030405067080900000000000000000')
915 self
.assertRegex(output
, 'RXSC: 8c16456c83a90002, state on')
916 self
.assertRegex(output
, '0: PN [0-9]*, state off, key 02030400000000000000000000000000')
919 class NetworkdL2TPTests(unittest
.TestCase
, Utilities
):
930 '25-l2tp-dummy.network',
932 '25-l2tp-udp.netdev']
934 l2tp_tunnel_ids
= [ '10' ]
937 self
.l2tp_tunnel_remove(self
.l2tp_tunnel_ids
)
938 self
.link_remove(self
.links
)
941 self
.l2tp_tunnel_remove(self
.l2tp_tunnel_ids
)
942 self
.link_remove(self
.links
)
943 self
.remove_unit_from_networkd_path(self
.units
)
945 @expectedFailureIfModuleIsNotAvailable('l2tp_eth')
946 def test_l2tp_udp(self
):
947 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-udp.netdev')
948 self
.start_networkd()
950 self
.assertTrue(self
.link_exits('test1'))
951 self
.assertTrue(self
.link_exits('l2tp-ses1'))
952 self
.assertTrue(self
.link_exits('l2tp-ses2'))
954 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '10']).rstrip().decode('utf-8')
956 self
.assertRegex(output
, "Tunnel 10, encap UDP")
957 self
.assertRegex(output
, "From 192.168.30.100 to 192.168.30.101")
958 self
.assertRegex(output
, "Peer tunnel 11")
959 self
.assertRegex(output
, "UDP source / dest ports: 3000/4000")
960 self
.assertRegex(output
, "UDP checksum: enabled")
962 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '15']).rstrip().decode('utf-8')
964 self
.assertRegex(output
, "Session 15 in tunnel 10")
965 self
.assertRegex(output
, "Peer session 16, tunnel 11")
966 self
.assertRegex(output
, "interface name: l2tp-ses1")
968 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '17']).rstrip().decode('utf-8')
970 self
.assertRegex(output
, "Session 17 in tunnel 10")
971 self
.assertRegex(output
, "Peer session 18, tunnel 11")
972 self
.assertRegex(output
, "interface name: l2tp-ses2")
974 @expectedFailureIfModuleIsNotAvailable('l2tp_ip')
975 def test_l2tp_ip(self
):
976 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-ip.netdev')
977 self
.start_networkd()
979 self
.assertTrue(self
.link_exits('test1'))
980 self
.assertTrue(self
.link_exits('l2tp-ses3'))
981 self
.assertTrue(self
.link_exits('l2tp-ses4'))
983 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '10']).rstrip().decode('utf-8')
985 self
.assertRegex(output
, "Tunnel 10, encap IP")
986 self
.assertRegex(output
, "From 192.168.30.100 to 192.168.30.101")
987 self
.assertRegex(output
, "Peer tunnel 12")
989 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '25']).rstrip().decode('utf-8')
991 self
.assertRegex(output
, "Session 25 in tunnel 10")
992 self
.assertRegex(output
, "Peer session 26, tunnel 12")
993 self
.assertRegex(output
, "interface name: l2tp-ses3")
995 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '27']).rstrip().decode('utf-8')
997 self
.assertRegex(output
, "Session 27 in tunnel 10")
998 self
.assertRegex(output
, "Peer session 28, tunnel 12")
999 self
.assertRegex(output
, "interface name: l2tp-ses4")
1001 class NetworkdNetWorkTests(unittest
.TestCase
, Utilities
):
1011 '23-active-slave.network',
1012 '25-address-link-section.network',
1013 '25-address-preferred-lifetime-zero-ipv6.network',
1014 '25-address-static.network',
1015 '25-bind-carrier.network',
1016 '25-bond-active-backup-slave.netdev',
1017 '25-fibrule-invert.network',
1018 '25-fibrule-port-range.network',
1019 '25-ipv6-address-label-section.network',
1020 '25-neighbor-section.network',
1021 '25-link-local-addressing-no.network',
1022 '25-link-local-addressing-yes.network',
1023 '25-link-section-unmanaged.network',
1024 '25-route-ipv6-src.network',
1025 '25-route-static.network',
1026 '25-sysctl-disable-ipv6.network',
1027 '25-sysctl.network',
1028 'configure-without-carrier.network',
1029 'routing-policy-rule-dummy98.network',
1030 'routing-policy-rule-test1.network']
1033 self
.link_remove(self
.links
)
1036 self
.link_remove(self
.links
)
1037 self
.remove_unit_from_networkd_path(self
.units
)
1039 def test_address_static(self
):
1040 self
.copy_unit_to_networkd_unit_path('25-address-static.network', '12-dummy.netdev')
1041 self
.start_networkd(0)
1043 self
.wait_online(['dummy98:routable'])
1045 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1047 self
.assertRegex(output
, 'inet 10.1.2.3/16 brd 10.1.255.255 scope global dummy98')
1048 self
.assertRegex(output
, 'inet 10.1.2.4/16 brd 10.1.255.255 scope global secondary dummy98')
1049 self
.assertRegex(output
, 'inet 10.2.2.4/16 brd 10.2.255.255 scope global dummy98')
1052 self
.assertNotRegex(output
, '10.10.0.1/16')
1053 self
.assertNotRegex(output
, '10.10.0.2/16')
1055 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '32']).rstrip().decode('utf-8')
1056 self
.assertRegex(output
, 'inet 10.3.2.3/16 brd 10.3.255.255 scope global 32')
1058 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '33']).rstrip().decode('utf-8')
1059 self
.assertRegex(output
, 'inet 10.4.2.3 peer 10.4.2.4/16 scope global 33')
1061 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '34']).rstrip().decode('utf-8')
1062 self
.assertRegex(output
, 'inet 192.168.[0-9]*.1/24 brd 192.168.[0-9]*.255 scope global 34')
1064 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '35']).rstrip().decode('utf-8')
1065 self
.assertRegex(output
, 'inet 172.[0-9]*.0.1/16 brd 172.[0-9]*.255.255 scope global 35')
1067 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1069 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::15/64 scope global')
1070 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::16/64 scope global')
1071 self
.assertRegex(output
, 'inet6 2001:db8:0:f102::15/64 scope global')
1072 self
.assertRegex(output
, 'inet6 2001:db8:0:f102::16/64 scope global')
1073 self
.assertRegex(output
, 'inet6 2001:db8:0:f103::20 peer 2001:db8:0:f103::10/128 scope global')
1074 self
.assertRegex(output
, 'inet6 fd[0-9a-f:]*1/64 scope global')
1076 def test_address_preferred_lifetime_zero_ipv6(self
):
1077 self
.copy_unit_to_networkd_unit_path('25-address-preferred-lifetime-zero-ipv6.network', '12-dummy.netdev')
1078 self
.start_networkd()
1080 self
.assertTrue(self
.link_exits('dummy98'))
1082 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1084 self
.assertRegex(output
, 'State: routable \(configuring\)')
1086 output
= subprocess
.check_output(['ip', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1088 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope link deprecated dummy98')
1089 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::1/64 scope global')
1091 def test_configure_without_carrier(self
):
1092 self
.copy_unit_to_networkd_unit_path('configure-without-carrier.network', '11-dummy.netdev')
1093 self
.start_networkd()
1095 self
.assertTrue(self
.link_exits('test1'))
1097 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1099 self
.assertRegex(output
, '192.168.0.15')
1100 self
.assertRegex(output
, '192.168.0.1')
1101 self
.assertRegex(output
, 'routable')
1103 def test_routing_policy_rule(self
):
1104 self
.copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev')
1106 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1108 self
.start_networkd()
1110 self
.assertTrue(self
.link_exits('test1'))
1112 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
1114 self
.assertRegex(output
, '111')
1115 self
.assertRegex(output
, 'from 192.168.100.18')
1116 self
.assertRegex(output
, r
'tos (?:0x08|throughput)\s')
1117 self
.assertRegex(output
, 'iif test1')
1118 self
.assertRegex(output
, 'oif test1')
1119 self
.assertRegex(output
, 'lookup 7')
1121 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1123 def test_routing_policy_rule_issue_11280(self
):
1124 self
.copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev',
1125 'routing-policy-rule-dummy98.network', '12-dummy.netdev')
1127 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1128 subprocess
.call(['ip', 'rule', 'del', 'table', '8'])
1130 for trial
in range(3):
1131 # Remove state files only first time
1132 self
.start_networkd(remove_state_files
=(trial
== 0))
1134 self
.assertTrue(self
.link_exits('test1'))
1135 self
.assertTrue(self
.link_exits('dummy98'))
1137 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '7']).rstrip().decode('utf-8')
1139 self
.assertRegex(output
, '111: from 192.168.100.18 tos (?:0x08|throughput) iif test1 oif test1 lookup 7')
1141 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '8']).rstrip().decode('utf-8')
1143 self
.assertRegex(output
, '112: from 192.168.101.18 tos (?:0x08|throughput) iif dummy98 oif dummy98 lookup 8')
1145 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1146 subprocess
.call(['ip', 'rule', 'del', 'table', '8'])
1148 @expectedFailureIfRoutingPolicyPortRangeIsNotAvailable()
1149 def test_routing_policy_rule_port_range(self
):
1150 self
.copy_unit_to_networkd_unit_path('25-fibrule-port-range.network', '11-dummy.netdev')
1152 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1154 self
.start_networkd()
1156 self
.assertTrue(self
.link_exits('test1'))
1158 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
1160 self
.assertRegex(output
, '111')
1161 self
.assertRegex(output
, 'from 192.168.100.18')
1162 self
.assertRegex(output
, '1123-1150')
1163 self
.assertRegex(output
, '3224-3290')
1164 self
.assertRegex(output
, 'tcp')
1165 self
.assertRegex(output
, 'lookup 7')
1167 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1169 @expectedFailureIfRoutingPolicyIPProtoIsNotAvailable()
1170 def test_routing_policy_rule_invert(self
):
1171 self
.copy_unit_to_networkd_unit_path('25-fibrule-invert.network', '11-dummy.netdev')
1173 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1175 self
.start_networkd()
1177 self
.assertTrue(self
.link_exits('test1'))
1179 output
= subprocess
.check_output(['ip', 'rule']).rstrip().decode('utf-8')
1181 self
.assertRegex(output
, '111')
1182 self
.assertRegex(output
, 'not.*?from.*?192.168.100.18')
1183 self
.assertRegex(output
, 'tcp')
1184 self
.assertRegex(output
, 'lookup 7')
1186 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1188 def test_route_static(self
):
1189 self
.copy_unit_to_networkd_unit_path('25-route-static.network', '12-dummy.netdev')
1190 self
.start_networkd(0)
1192 self
.wait_online(['dummy98:routable'])
1194 output
= subprocess
.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1196 self
.assertRegex(output
, '2001:1234:5:8fff:ff:ff:ff:ff proto static')
1197 self
.assertRegex(output
, '2001:1234:5:8f63::1 proto kernel')
1199 output
= subprocess
.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
1200 self
.assertRegex(output
, 'default via 2001:1234:5:8fff:ff:ff:ff:ff proto static metric 1024 pref medium')
1202 output
= subprocess
.check_output(['ip', '-4', 'route', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1204 self
.assertRegex(output
, '149.10.124.48/28 proto kernel scope link src 149.10.124.58')
1205 self
.assertRegex(output
, '149.10.124.64 proto static scope link')
1206 self
.assertRegex(output
, '192.168.1.1 proto static initcwnd 20')
1207 self
.assertRegex(output
, '192.168.1.2 proto static initrwnd 30')
1209 output
= subprocess
.check_output(['ip', '-4', 'route', 'show', 'dev', 'dummy98', 'default']).rstrip().decode('utf-8')
1210 self
.assertRegex(output
, 'default via 149.10.125.65 proto static onlink')
1211 self
.assertRegex(output
, 'default via 149.10.124.64 proto static')
1213 output
= subprocess
.check_output(['ip', 'route', 'show', 'type', 'blackhole']).rstrip().decode('utf-8')
1215 self
.assertRegex(output
, 'blackhole 202.54.1.2 proto static')
1217 output
= subprocess
.check_output(['ip', 'route', 'show', 'type', 'unreachable']).rstrip().decode('utf-8')
1219 self
.assertRegex(output
, 'unreachable 202.54.1.3 proto static')
1221 output
= subprocess
.check_output(['ip', 'route', 'show', 'type', 'prohibit']).rstrip().decode('utf-8')
1223 self
.assertRegex(output
, 'prohibit 202.54.1.4 proto static')
1225 subprocess
.call(['ip', 'route', 'del', 'blackhole', '202.54.1.2'])
1226 subprocess
.call(['ip', 'route', 'del', 'unreachable', '202.54.1.3'])
1227 subprocess
.call(['ip', 'route', 'del', 'prohibit', '202.54.1.4'])
1229 def test_ip_route_ipv6_src_route(self
):
1230 # a dummy device does not make the addresses go through tentative state, so we
1231 # reuse a bond from an earlier test, which does make the addresses go through
1232 # tentative state, and do our test on that
1233 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')
1234 self
.start_networkd()
1236 self
.assertTrue(self
.link_exits('dummy98'))
1237 self
.assertTrue(self
.link_exits('bond199'))
1239 output
= subprocess
.check_output(['ip', '-6', 'route', 'list', 'dev', 'bond199']).rstrip().decode('utf-8')
1241 self
.assertRegex(output
, 'abcd::/16')
1242 self
.assertRegex(output
, 'src')
1243 self
.assertRegex(output
, '2001:1234:56:8f63::2')
1245 def test_ip_link_mac_address(self
):
1246 self
.copy_unit_to_networkd_unit_path('25-address-link-section.network', '12-dummy.netdev')
1247 self
.start_networkd()
1249 self
.assertTrue(self
.link_exits('dummy98'))
1251 output
= subprocess
.check_output(['ip', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1253 self
.assertRegex(output
, '00:01:02:aa:bb:cc')
1255 def test_ip_link_unmanaged(self
):
1256 self
.copy_unit_to_networkd_unit_path('25-link-section-unmanaged.network', '12-dummy.netdev')
1257 self
.start_networkd()
1259 self
.assertTrue(self
.link_exits('dummy98'))
1261 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1263 self
.assertRegex(output
, 'unmanaged')
1265 def test_ipv6_address_label(self
):
1266 self
.copy_unit_to_networkd_unit_path('25-ipv6-address-label-section.network', '12-dummy.netdev')
1267 self
.start_networkd()
1269 self
.assertTrue(self
.link_exits('dummy98'))
1271 output
= subprocess
.check_output(['ip', 'addrlabel', 'list']).rstrip().decode('utf-8')
1273 self
.assertRegex(output
, '2004:da8:1::/64')
1275 def test_ipv6_neighbor(self
):
1276 self
.copy_unit_to_networkd_unit_path('25-neighbor-section.network', '12-dummy.netdev')
1277 self
.start_networkd()
1279 self
.assertTrue(self
.link_exits('dummy98'))
1281 output
= subprocess
.check_output(['ip', 'neigh', 'list']).rstrip().decode('utf-8')
1283 self
.assertRegex(output
, '192.168.10.1.*00:00:5e:00:02:65.*PERMANENT')
1284 self
.assertRegex(output
, '2004:da8:1::1.*00:00:5e:00:02:66.*PERMANENT')
1286 def test_link_local_addressing(self
):
1287 self
.copy_unit_to_networkd_unit_path('25-link-local-addressing-yes.network', '11-dummy.netdev',
1288 '25-link-local-addressing-no.network', '12-dummy.netdev')
1289 self
.start_networkd(0)
1290 self
.wait_online(['test1:degraded', 'dummy98:carrier'])
1292 self
.assertTrue(self
.link_exits('test1'))
1293 self
.assertTrue(self
.link_exits('dummy98'))
1295 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'test1']).rstrip().decode('utf-8')
1297 self
.assertRegex(output
, 'inet .* scope link')
1298 self
.assertRegex(output
, 'inet6 .* scope link')
1300 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
1302 self
.assertNotRegex(output
, 'inet6* .* scope link')
1304 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1306 self
.assertRegex(output
, 'State: degraded \(configured\)')
1308 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1310 self
.assertRegex(output
, 'State: carrier \(configured\)')
1313 Documentation/networking/ip-sysctl.txt
1315 addr_gen_mode - INTEGER
1316 Defines how link-local and autoconf addresses are generated.
1318 0: generate address based on EUI64 (default)
1319 1: do no generate a link-local address, use EUI64 for addresses generated
1321 2: generate stable privacy addresses, using the secret from
1322 stable_secret (RFC7217)
1323 3: generate stable privacy addresses, using a random secret if unset
1326 test1_addr_gen_mode
= ''
1327 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'stable_secret')):
1328 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'stable_secret')) as f
:
1332 # if stable_secret is unset, then EIO is returned
1333 test1_addr_gen_mode
= '0'
1335 test1_addr_gen_mode
= '2'
1337 test1_addr_gen_mode
= '0'
1339 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'addr_gen_mode')):
1340 self
.assertEqual(self
.read_ipv6_sysctl_attr('test1', 'addr_gen_mode'), test1_addr_gen_mode
)
1342 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'dummy98'), 'addr_gen_mode')):
1343 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'addr_gen_mode'), '1')
1345 def test_sysctl(self
):
1346 self
.copy_unit_to_networkd_unit_path('25-sysctl.network', '12-dummy.netdev')
1347 self
.start_networkd(0)
1348 self
.wait_online(['dummy98:degraded'])
1350 self
.assertTrue(self
.link_exits('dummy98'))
1352 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'forwarding'), '1')
1353 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'use_tempaddr'), '2')
1354 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'dad_transmits'), '3')
1355 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'hop_limit'), '5')
1356 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'proxy_ndp'), '1')
1357 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'forwarding'),'1')
1358 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'proxy_arp'), '1')
1360 def test_sysctl_disable_ipv6(self
):
1361 self
.copy_unit_to_networkd_unit_path('25-sysctl-disable-ipv6.network', '12-dummy.netdev')
1363 print('## Disable ipv6')
1364 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.all.disable_ipv6=1']), 0)
1365 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.default.disable_ipv6=1']), 0)
1367 self
.start_networkd(0)
1368 self
.wait_online(['dummy98:routable'])
1370 self
.assertTrue(self
.link_exits('dummy98'))
1372 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1374 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98')
1375 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1377 self
.assertEqual(output
, '')
1378 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1379 self
.assertRegex(output
, 'State: routable \(configured\)')
1381 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1383 print('## Enable ipv6')
1384 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.all.disable_ipv6=0']), 0)
1385 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.default.disable_ipv6=0']), 0)
1387 self
.start_networkd(0)
1388 self
.wait_online(['dummy98:routable'])
1390 self
.assertTrue(self
.link_exits('dummy98'))
1392 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1394 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98')
1395 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dummy98']).rstrip().decode('utf-8')
1397 self
.assertRegex(output
, 'inet6 .* scope link')
1398 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1399 self
.assertRegex(output
, 'State: routable \(configured\)')
1401 def test_bind_carrier(self
):
1402 self
.copy_unit_to_networkd_unit_path('25-bind-carrier.network', '11-dummy.netdev')
1403 self
.start_networkd()
1405 self
.assertTrue(self
.link_exits('test1'))
1407 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1408 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1410 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1412 self
.assertRegex(output
, 'UP,LOWER_UP')
1413 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1414 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1415 self
.assertRegex(output
, 'State: routable \(configured\)')
1417 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy99', 'type', 'dummy']), 0)
1418 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy99', 'up']), 0)
1420 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1422 self
.assertRegex(output
, 'UP,LOWER_UP')
1423 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1424 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1425 self
.assertRegex(output
, 'State: routable \(configured\)')
1427 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1429 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1431 self
.assertRegex(output
, 'UP,LOWER_UP')
1432 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1433 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1434 self
.assertRegex(output
, 'State: routable \(configured\)')
1436 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy99']), 0)
1438 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1440 self
.assertNotRegex(output
, 'UP,LOWER_UP')
1441 self
.assertRegex(output
, 'DOWN')
1442 self
.assertNotRegex(output
, '192.168.10')
1443 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1444 self
.assertRegex(output
, 'State: off \(configured\)')
1446 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1447 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1449 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1']).rstrip().decode('utf-8')
1451 self
.assertRegex(output
, 'UP,LOWER_UP')
1452 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1453 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1454 self
.assertRegex(output
, 'State: routable \(configured\)')
1456 class NetworkdNetWorkBondTests(unittest
.TestCase
, Utilities
):
1466 '23-active-slave.network',
1467 '23-bond199.network',
1468 '23-primary-slave.network',
1469 '23-test1-bond199.network',
1470 '25-bond-active-backup-slave.netdev',
1473 'bond-slave.network']
1476 self
.link_remove(self
.links
)
1479 self
.link_remove(self
.links
)
1480 self
.remove_unit_from_networkd_path(self
.units
)
1482 def test_bond_active_slave(self
):
1483 self
.copy_unit_to_networkd_unit_path('23-active-slave.network', '23-bond199.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev')
1484 self
.start_networkd()
1486 self
.assertTrue(self
.link_exits('dummy98'))
1487 self
.assertTrue(self
.link_exits('bond199'))
1489 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
1491 self
.assertRegex(output
, 'active_slave dummy98')
1493 def test_bond_primary_slave(self
):
1494 self
.copy_unit_to_networkd_unit_path('23-primary-slave.network', '23-test1-bond199.network', '25-bond-active-backup-slave.netdev', '11-dummy.netdev')
1495 self
.start_networkd()
1497 self
.assertTrue(self
.link_exits('test1'))
1498 self
.assertTrue(self
.link_exits('bond199'))
1500 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199']).rstrip().decode('utf-8')
1502 self
.assertRegex(output
, 'primary test1')
1504 def test_bond_operstate(self
):
1505 self
.copy_unit_to_networkd_unit_path('25-bond.netdev', '11-dummy.netdev', '12-dummy.netdev',
1506 'bond99.network','bond-slave.network')
1507 self
.start_networkd()
1509 self
.assertTrue(self
.link_exits('bond99'))
1510 self
.assertTrue(self
.link_exits('dummy98'))
1511 self
.assertTrue(self
.link_exits('test1'))
1513 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1515 self
.assertRegex(output
, 'SLAVE,UP,LOWER_UP')
1517 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
1519 self
.assertRegex(output
, 'SLAVE,UP,LOWER_UP')
1521 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond99']).rstrip().decode('utf-8')
1523 self
.assertRegex(output
, 'MASTER,UP,LOWER_UP')
1525 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1527 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1529 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1531 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1533 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1535 self
.assertRegex(output
, 'State: routable \(configured\)')
1537 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'down']), 0)
1540 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1542 self
.assertRegex(output
, 'State: off \(configured\)')
1544 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1546 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1548 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1550 self
.assertRegex(output
, 'State: degraded-carrier \(configured\)')
1552 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1555 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1557 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1559 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1561 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1563 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1565 self
.assertRegex(output
, 'State: routable \(configured\)')
1567 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'down']), 0)
1568 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'test1', 'down']), 0)
1571 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1573 self
.assertRegex(output
, 'State: off \(configured\)')
1575 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1577 self
.assertRegex(output
, 'State: off \(configured\)')
1579 output
= subprocess
.check_output(['networkctl', 'status', 'bond99']).rstrip().decode('utf-8')
1581 self
.assertRegex(output
, 'State: no-carrier \(configured\)')
1583 class NetworkdNetWorkBridgeTests(unittest
.TestCase
, Utilities
):
1593 '26-bridge-slave-interface-1.network',
1594 '26-bridge-slave-interface-2.network',
1595 'bridge99-ignore-carrier-loss.network',
1599 self
.link_remove(self
.links
)
1602 self
.link_remove(self
.links
)
1603 self
.remove_unit_from_networkd_path(self
.units
)
1605 def test_bridge_property(self
):
1606 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
1607 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
1609 self
.start_networkd()
1611 self
.assertTrue(self
.link_exits('dummy98'))
1612 self
.assertTrue(self
.link_exits('test1'))
1613 self
.assertTrue(self
.link_exits('bridge99'))
1615 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
1617 self
.assertRegex(output
, 'master')
1618 self
.assertRegex(output
, 'bridge')
1620 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1622 self
.assertRegex(output
, 'master')
1623 self
.assertRegex(output
, 'bridge')
1625 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99']).rstrip().decode('utf-8')
1627 self
.assertRegex(output
, '192.168.0.15/24')
1629 output
= subprocess
.check_output(['bridge', '-d', 'link', 'show', 'dummy98']).rstrip().decode('utf-8')
1631 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'hairpin_mode'), '1')
1632 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'path_cost'), '400')
1633 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'unicast_flood'), '1')
1634 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_flood'), '0')
1635 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_fast_leave'), '1')
1636 if (os
.path
.exists('/sys/devices/virtual/net/bridge99/lower_dummy98/brport/neigh_suppress')):
1637 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'neigh_suppress'), '1')
1638 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'learning'), '0')
1640 # CONFIG_BRIDGE_IGMP_SNOOPING=y
1641 if (os
.path
.exists('/sys/devices/virtual/net/bridge00/lower_dummy98/brport/multicast_to_unicast')):
1642 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_to_unicast'), '1')
1644 output
= subprocess
.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
1645 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1647 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1648 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1650 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1651 self
.assertRegex(output
, 'State: routable \(configured\)')
1653 self
.assertEqual(subprocess
.call(['ip', 'address', 'add', '192.168.0.16/24', 'dev', 'bridge99']), 0)
1656 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99']).rstrip().decode('utf-8')
1658 self
.assertRegex(output
, '192.168.0.16/24')
1660 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1661 self
.assertRegex(output
, 'State: routable \(configured\)')
1663 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'test1']), 0)
1666 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1667 self
.assertRegex(output
, 'State: degraded-carrier \(configured\)')
1669 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1672 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1673 self
.assertRegex(output
, 'State: no-carrier \(configured\)')
1675 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1677 self
.assertRegex(output
, 'NO-CARRIER')
1678 self
.assertNotRegex(output
, '192.168.0.15/24')
1679 self
.assertNotRegex(output
, '192.168.0.16/24')
1681 def test_bridge_ignore_carrier_loss(self
):
1682 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
1683 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
1684 'bridge99-ignore-carrier-loss.network')
1686 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1688 self
.start_networkd()
1690 self
.assertTrue(self
.link_exits('dummy98'))
1691 self
.assertTrue(self
.link_exits('test1'))
1692 self
.assertTrue(self
.link_exits('bridge99'))
1694 self
.assertEqual(subprocess
.call(['ip', 'address', 'add', '192.168.0.16/24', 'dev', 'bridge99']), 0)
1697 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'test1']), 0)
1698 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1701 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1703 self
.assertRegex(output
, 'NO-CARRIER')
1704 self
.assertRegex(output
, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99')
1705 self
.assertRegex(output
, 'inet 192.168.0.16/24 scope global secondary bridge99')
1707 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1709 def test_bridge_ignore_carrier_loss_frequent_loss_and_gain(self
):
1710 self
.copy_unit_to_networkd_unit_path('26-bridge.netdev', '26-bridge-slave-interface-1.network',
1711 'bridge99-ignore-carrier-loss.network')
1713 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1715 self
.start_networkd()
1717 self
.assertTrue(self
.link_exits('bridge99'))
1719 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1720 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1721 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1723 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1724 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1725 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1727 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1728 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1729 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1731 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1732 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1736 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99']).rstrip().decode('utf-8')
1738 self
.assertRegex(output
, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99')
1740 output
= subprocess
.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
1741 self
.assertRegex(output
, 'State: routable \(configured\)')
1743 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1744 self
.assertRegex(output
, 'State: enslaved \(configured\)')
1746 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '100']).rstrip().decode('utf-8')
1748 self
.assertEqual(output
, '0: from all to 8.8.8.8 lookup 100')
1750 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1752 class NetworkdNetWorkLLDPTests(unittest
.TestCase
, Utilities
):
1756 '23-emit-lldp.network',
1761 self
.link_remove(self
.links
)
1764 self
.link_remove(self
.links
)
1765 self
.remove_unit_from_networkd_path(self
.units
)
1767 def test_lldp(self
):
1768 self
.copy_unit_to_networkd_unit_path('23-emit-lldp.network', '24-lldp.network', '25-veth.netdev')
1769 self
.start_networkd()
1771 self
.assertTrue(self
.link_exits('veth99'))
1773 output
= subprocess
.check_output(['networkctl', 'lldp']).rstrip().decode('utf-8')
1775 self
.assertRegex(output
, 'veth-peer')
1776 self
.assertRegex(output
, 'veth99')
1778 class NetworkdNetworkRATests(unittest
.TestCase
, Utilities
):
1783 'ipv6-prefix.network',
1784 'ipv6-prefix-veth.network']
1787 self
.link_remove(self
.links
)
1790 self
.link_remove(self
.links
)
1791 self
.remove_unit_from_networkd_path(self
.units
)
1793 def test_ipv6_prefix_delegation(self
):
1794 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth.network')
1795 self
.start_networkd()
1797 self
.assertTrue(self
.link_exits('veth99'))
1799 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1801 self
.assertRegex(output
, '2002:da8:1:0')
1803 class NetworkdNetworkDHCPServerTests(unittest
.TestCase
, Utilities
):
1810 '24-search-domain.network',
1812 'dhcp-client.network',
1813 'dhcp-client-timezone-router.network',
1814 'dhcp-server.network',
1815 'dhcp-server-timezone-router.network']
1818 self
.link_remove(self
.links
)
1821 self
.link_remove(self
.links
)
1822 self
.remove_unit_from_networkd_path(self
.units
)
1824 def test_dhcp_server(self
):
1825 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client.network', 'dhcp-server.network')
1826 self
.start_networkd()
1828 self
.assertTrue(self
.link_exits('veth99'))
1830 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1832 self
.assertRegex(output
, '192.168.5.*')
1833 self
.assertRegex(output
, 'Gateway: 192.168.5.1')
1834 self
.assertRegex(output
, 'DNS: 192.168.5.1')
1835 self
.assertRegex(output
, 'NTP: 192.168.5.1')
1837 def test_domain(self
):
1838 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '24-search-domain.network')
1839 self
.start_networkd()
1841 self
.assertTrue(self
.link_exits('dummy98'))
1843 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98']).rstrip().decode('utf-8')
1845 self
.assertRegex(output
, 'Address: 192.168.42.100')
1846 self
.assertRegex(output
, 'DNS: 192.168.42.1')
1847 self
.assertRegex(output
, 'Search Domains: one')
1849 def test_emit_router_timezone(self
):
1850 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client-timezone-router.network', 'dhcp-server-timezone-router.network')
1851 self
.start_networkd()
1853 self
.assertTrue(self
.link_exits('veth99'))
1855 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1857 self
.assertRegex(output
, 'Gateway: 192.168.5.*')
1858 self
.assertRegex(output
, '192.168.5.*')
1859 self
.assertRegex(output
, 'Europe/Berlin')
1861 class NetworkdNetworkDHCPClientTests(unittest
.TestCase
, Utilities
):
1871 'dhcp-client-anonymize.network',
1872 'dhcp-client-critical-connection.network',
1873 'dhcp-client-gateway-onlink-implicit.network',
1874 'dhcp-client-ipv4-dhcp-settings.network',
1875 'dhcp-client-ipv4-only-ipv6-disabled.network',
1876 'dhcp-client-ipv4-only.network',
1877 'dhcp-client-ipv6-only.network',
1878 'dhcp-client-ipv6-rapid-commit.network',
1879 'dhcp-client-listen-port.network',
1880 'dhcp-client-route-metric.network',
1881 'dhcp-client-route-table.network',
1882 'dhcp-client-vrf.network',
1883 'dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network',
1884 'dhcp-client-with-ipv4ll-fallback-without-dhcp-server.network',
1885 'dhcp-client.network',
1886 'dhcp-server-veth-peer.network',
1887 'dhcp-v4-server-veth-peer.network',
1891 self
.link_remove(self
.links
)
1892 self
.stop_dnsmasq(dnsmasq_pid_file
)
1895 self
.link_remove(self
.links
)
1896 self
.remove_unit_from_networkd_path(self
.units
)
1897 self
.stop_dnsmasq(dnsmasq_pid_file
)
1898 self
.remove_lease_file()
1899 self
.remove_log_file()
1901 def test_dhcp_client_ipv6_only(self
):
1902 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
1904 self
.start_networkd(0)
1905 self
.wait_online(['veth-peer:carrier'])
1906 self
.start_dnsmasq()
1907 self
.wait_online(['veth99:routable', 'veth-peer:routable'])
1909 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1911 self
.assertRegex(output
, '2600::')
1912 self
.assertNotRegex(output
, '192.168.5')
1914 # Confirm that ipv6 token is not set in the kernel
1915 output
= subprocess
.check_output(['ip', 'token', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1917 self
.assertRegex(output
, 'token :: dev veth99')
1919 def test_dhcp_client_ipv4_only(self
):
1920 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-only-ipv6-disabled.network')
1921 self
.start_networkd()
1923 self
.assertTrue(self
.link_exits('veth99'))
1925 self
.start_dnsmasq()
1927 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1929 self
.assertNotRegex(output
, '2600::')
1930 self
.assertRegex(output
, '192.168.5')
1932 def test_dhcp_client_ipv4_ipv6(self
):
1933 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network',
1934 'dhcp-client-ipv4-only.network')
1935 self
.start_networkd()
1937 self
.assertTrue(self
.link_exits('veth99'))
1939 self
.start_dnsmasq()
1941 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
1943 self
.assertRegex(output
, '2600::')
1944 self
.assertRegex(output
, '192.168.5')
1946 def test_dhcp_client_settings(self
):
1947 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-dhcp-settings.network')
1948 self
.start_networkd()
1950 self
.assertTrue(self
.link_exits('veth99'))
1952 self
.start_dnsmasq()
1954 print('## ip address show dev veth99')
1955 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1957 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1958 self
.assertRegex(output
, '192.168.5')
1959 self
.assertRegex(output
, '1492')
1962 print('## ip route show table main dev veth99')
1963 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', 'main', 'dev', 'veth99']).rstrip().decode('utf-8')
1965 self
.assertNotRegex(output
, 'proto dhcp')
1967 print('## ip route show table 211 dev veth99')
1968 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '211', 'dev', 'veth99']).rstrip().decode('utf-8')
1970 self
.assertRegex(output
, 'default via 192.168.5.1 proto dhcp')
1971 self
.assertRegex(output
, '192.168.5.0/24 via 192.168.5.5 proto dhcp')
1972 self
.assertRegex(output
, '192.168.5.1 proto dhcp scope link')
1974 print('## dnsmasq log')
1975 self
.assertTrue(self
.search_words_in_dnsmasq_log('vendor class: SusantVendorTest', True))
1976 self
.assertTrue(self
.search_words_in_dnsmasq_log('DHCPDISCOVER(veth-peer) 12:34:56:78:9a:bc'))
1977 self
.assertTrue(self
.search_words_in_dnsmasq_log('client provides name: test-hostname'))
1978 self
.assertTrue(self
.search_words_in_dnsmasq_log('26:mtu'))
1980 def test_dhcp6_client_settings_rapidcommit_true(self
):
1981 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
1982 self
.start_networkd()
1984 self
.assertTrue(self
.link_exits('veth99'))
1986 self
.start_dnsmasq()
1988 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
1990 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1991 self
.assertTrue(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
1993 def test_dhcp6_client_settings_rapidcommit_false(self
):
1994 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-rapid-commit.network')
1995 self
.start_networkd()
1997 self
.assertTrue(self
.link_exits('veth99'))
1999 self
.start_dnsmasq()
2001 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2003 self
.assertRegex(output
, '12:34:56:78:9a:bc')
2004 self
.assertFalse(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
2006 def test_dhcp_client_settings_anonymize(self
):
2007 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-anonymize.network')
2008 self
.start_networkd()
2010 self
.assertTrue(self
.link_exits('veth99'))
2012 self
.start_dnsmasq()
2014 self
.assertFalse(self
.search_words_in_dnsmasq_log('VendorClassIdentifier=SusantVendorTest', True))
2015 self
.assertFalse(self
.search_words_in_dnsmasq_log('test-hostname'))
2016 self
.assertFalse(self
.search_words_in_dnsmasq_log('26:mtu'))
2018 def test_dhcp_client_listen_port(self
):
2019 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-listen-port.network')
2020 self
.start_networkd()
2022 self
.assertTrue(self
.link_exits('veth99'))
2024 self
.start_dnsmasq('--dhcp-alternate-port=67,5555')
2026 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2028 self
.assertRegex(output
, '192.168.5.* dynamic')
2030 def test_dhcp_route_table_id(self
):
2031 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-table.network')
2032 self
.start_networkd()
2034 self
.assertTrue(self
.link_exits('veth99'))
2036 self
.start_dnsmasq()
2038 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '12']).rstrip().decode('utf-8')
2040 self
.assertRegex(output
, 'veth99 proto dhcp')
2041 self
.assertRegex(output
, '192.168.5.1')
2043 def test_dhcp_route_metric(self
):
2044 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-metric.network')
2045 self
.start_networkd()
2047 self
.assertTrue(self
.link_exits('veth99'))
2049 self
.start_dnsmasq()
2051 output
= subprocess
.check_output(['ip', 'route', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2053 self
.assertRegex(output
, 'metric 24')
2055 def test_dhcp_route_criticalconnection_true(self
):
2056 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-critical-connection.network')
2057 self
.start_networkd()
2059 self
.assertTrue(self
.link_exits('veth99'))
2061 self
.start_dnsmasq()
2063 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
2065 self
.assertRegex(output
, '192.168.5.*')
2067 # Stopping dnsmasq as networkd won't be allowed to renew the DHCP lease.
2068 self
.stop_dnsmasq(dnsmasq_pid_file
)
2070 # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
2073 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
2075 self
.assertRegex(output
, '192.168.5.*')
2077 def test_dhcp_client_reuse_address_as_static(self
):
2078 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client.network')
2079 self
.start_networkd()
2081 self
.assertTrue(self
.link_exits('veth99'))
2083 self
.start_dnsmasq()
2085 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
2087 self
.assertRegex(output
, '192.168.5')
2088 self
.assertRegex(output
, '2600::')
2090 ipv4_address
= re
.search('192\.168\.5\.[0-9]*/24', output
)
2091 ipv6_address
= re
.search('2600::[0-9a-f:]*/128', output
)
2092 static_network
= '\n'.join(['[Match]', 'Name=veth99', '[Network]', 'IPv6AcceptRA=no', 'Address=' + ipv4_address
.group(), 'Address=' + ipv6_address
.group()])
2093 print(static_network
)
2095 self
.remove_unit_from_networkd_path(['dhcp-client.network'])
2097 with
open(os
.path
.join(network_unit_file_path
, 'static.network'), mode
='w') as f
:
2098 f
.write(static_network
)
2100 self
.start_networkd()
2102 self
.assertTrue(self
.link_exits('veth99'))
2104 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
2106 self
.assertRegex(output
, '192.168.5')
2107 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
2109 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global']).rstrip().decode('utf-8')
2111 self
.assertRegex(output
, '2600::')
2112 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
2114 @expectedFailureIfModuleIsNotAvailable('vrf')
2115 def test_dhcp_client_vrf(self
):
2116 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-vrf.network',
2117 '25-vrf.netdev', '25-vrf.network')
2118 self
.start_networkd()
2120 self
.assertTrue(self
.link_exits('veth99'))
2121 self
.assertTrue(self
.link_exits('vrf99'))
2123 self
.start_dnsmasq()
2125 print('## ip -d link show dev vrf99')
2126 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dev', 'vrf99']).rstrip().decode('utf-8')
2128 self
.assertRegex(output
, 'vrf table 42')
2130 print('## ip address show vrf vrf99')
2131 output_ip_vrf
= subprocess
.check_output(['ip', 'address', 'show', 'vrf', 'vrf99']).rstrip().decode('utf-8')
2132 print(output_ip_vrf
)
2134 print('## ip address show dev veth99')
2135 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2137 self
.assertEqual(output
, output_ip_vrf
)
2138 self
.assertRegex(output
, 'inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99')
2139 self
.assertRegex(output
, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
2140 self
.assertRegex(output
, 'inet6 2600::[0-9a-f]*/128 scope global dynamic noprefixroute')
2141 self
.assertRegex(output
, 'inet6 .* scope link')
2143 print('## ip route show vrf vrf99')
2144 output
= subprocess
.check_output(['ip', 'route', 'show', 'vrf', 'vrf99']).rstrip().decode('utf-8')
2146 self
.assertRegex(output
, 'default via 192.168.5.1 dev veth99 proto dhcp src 192.168.5.')
2147 self
.assertRegex(output
, 'default dev veth99 proto static scope link')
2148 self
.assertRegex(output
, '169.254.0.0/16 dev veth99 proto kernel scope link src 169.254')
2149 self
.assertRegex(output
, '192.168.5.0/24 dev veth99 proto kernel scope link src 192.168.5')
2150 self
.assertRegex(output
, '192.168.5.0/24 via 192.168.5.5 dev veth99 proto dhcp')
2151 self
.assertRegex(output
, '192.168.5.1 dev veth99 proto dhcp scope link src 192.168.5')
2153 print('## ip route show table main dev veth99')
2154 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', 'main', 'dev', 'veth99']).rstrip().decode('utf-8')
2156 self
.assertEqual(output
, '')
2158 output
= subprocess
.check_output(['networkctl', 'status', 'vrf99']).rstrip().decode('utf-8')
2160 self
.assertRegex(output
, 'State: carrier \(configured\)')
2162 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
2164 self
.assertRegex(output
, 'State: routable \(configured\)')
2166 def test_dhcp_client_gateway_onlink_implicit(self
):
2167 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
2168 'dhcp-client-gateway-onlink-implicit.network')
2169 self
.start_networkd()
2171 self
.assertTrue(self
.link_exits('veth99'))
2173 self
.start_dnsmasq()
2175 output
= subprocess
.check_output(['networkctl', 'status', 'veth99']).rstrip().decode('utf-8')
2177 self
.assertRegex(output
, '192.168.5')
2179 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'veth99', '10.0.0.0/8']).rstrip().decode('utf-8')
2181 self
.assertRegex(output
, 'onlink')
2182 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'veth99', '192.168.100.0/24']).rstrip().decode('utf-8')
2184 self
.assertRegex(output
, 'onlink')
2186 def test_dhcp_client_with_ipv4ll_fallback_with_dhcp_server(self
):
2187 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
2188 'dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network')
2189 self
.start_networkd(0)
2190 self
.wait_online(['veth-peer:carrier'])
2191 self
.start_dnsmasq(lease_time
='2m')
2192 self
.wait_online(['veth99:routable', 'veth-peer:routable'])
2194 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2197 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic']).rstrip().decode('utf-8')
2198 self
.assertNotRegex(output
, 'inet6 2600::[0-9a-f]*/128 scope global dynamic')
2199 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'link']).rstrip().decode('utf-8')
2200 self
.assertRegex(output
, 'inet6 .* scope link')
2201 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic']).rstrip().decode('utf-8')
2202 self
.assertRegex(output
, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
2203 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'link']).rstrip().decode('utf-8')
2204 self
.assertNotRegex(output
, 'inet .* scope link')
2206 print('Wait for the dynamic address to be expired')
2209 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2212 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic']).rstrip().decode('utf-8')
2213 self
.assertNotRegex(output
, 'inet6 2600::[0-9a-f]*/128 scope global dynamic')
2214 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'link']).rstrip().decode('utf-8')
2215 self
.assertRegex(output
, 'inet6 .* scope link')
2216 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic']).rstrip().decode('utf-8')
2217 self
.assertRegex(output
, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
2218 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'link']).rstrip().decode('utf-8')
2219 self
.assertNotRegex(output
, 'inet .* scope link')
2221 self
.search_words_in_dnsmasq_log('DHCPOFFER', show_all
=True)
2223 def test_dhcp_client_with_ipv4ll_fallback_without_dhcp_server(self
):
2224 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
2225 'dhcp-client-with-ipv4ll-fallback-without-dhcp-server.network')
2226 self
.start_networkd(0)
2227 self
.wait_online(['veth99:degraded', 'veth-peer:routable'])
2229 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99']).rstrip().decode('utf-8')
2232 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic']).rstrip().decode('utf-8')
2233 self
.assertNotRegex(output
, 'inet6 2600::[0-9a-f]*/128 scope global dynamic')
2234 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'link']).rstrip().decode('utf-8')
2235 self
.assertRegex(output
, 'inet6 .* scope link')
2236 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic']).rstrip().decode('utf-8')
2237 self
.assertNotRegex(output
, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
2238 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'link']).rstrip().decode('utf-8')
2239 self
.assertRegex(output
, 'inet .* scope link')
2241 if __name__
== '__main__':
2242 unittest
.main(testRunner
=unittest
.TextTestRunner(stream
=sys
.stdout
,