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():
76 rc
= subprocess
.call(['ip', 'link', 'add', 'name', 'test1', 'type', 'dummy'])
79 rc
= subprocess
.call(['ip', 'tunnel', 'add', 'tun99', 'local', '2a00:ffde:4567:edde::4986', 'remote', '2001:473:fece:cafe::5178', 'mode', 'ip6gre', 'dev', 'test1'])
82 # Not sure why, but '0' or '2' do not work.
83 subprocess
.call(['sysctl', '-w', 'net.ipv6.conf.tun99.addr_gen_mode=3'])
85 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'tun99', 'scope', 'link'], universal_newlines
=True).rstrip()
87 success
= 'inet6' in output
89 subprocess
.run(['ip', 'tunnel', 'del', 'tun99'])
91 subprocess
.run(['ip', 'link', 'del', 'test1'])
96 return unittest
.expectedFailure(func
)
101 os
.makedirs(network_unit_file_path
, exist_ok
=True)
102 os
.makedirs(networkd_ci_path
, exist_ok
=True)
104 shutil
.rmtree(networkd_ci_path
)
105 copytree(os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), 'conf'), networkd_ci_path
)
107 subprocess
.check_call('systemctl stop systemd-networkd.socket', shell
=True)
109 def tearDownModule():
110 shutil
.rmtree(networkd_ci_path
)
112 subprocess
.check_call('systemctl stop systemd-networkd.service', shell
=True)
113 subprocess
.check_call('systemctl start systemd-networkd.socket', shell
=True)
114 subprocess
.check_call('systemctl start systemd-networkd.service', shell
=True)
117 def read_link_attr(self
, link
, dev
, attribute
):
118 with
open(os
.path
.join(os
.path
.join(os
.path
.join('/sys/class/net/', link
), dev
), attribute
)) as f
:
119 return f
.readline().strip()
121 def read_bridge_port_attr(self
, bridge
, link
, attribute
):
123 path_bridge
= os
.path
.join('/sys/devices/virtual/net', bridge
)
124 path_port
= 'lower_' + link
+ '/brport'
125 path
= os
.path
.join(path_bridge
, path_port
)
127 with
open(os
.path
.join(path
, attribute
)) as f
:
128 return f
.readline().strip()
130 def link_exists(self
, link
):
131 return os
.path
.exists(os
.path
.join('/sys/class/net', link
))
133 def check_link_exists(self
, link
):
134 self
.assertTrue(self
.link_exists(link
))
136 def link_remove(self
, links
):
138 if self
.link_exists(link
):
139 subprocess
.call(['ip', 'link', 'del', 'dev', link
])
142 def l2tp_tunnel_remove(self
, tunnel_ids
):
143 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'tunnel'], universal_newlines
=True).rstrip()
144 for tid
in tunnel_ids
:
145 words
='Tunnel ' + tid
+ ', encap'
147 subprocess
.call(['ip', 'l2tp', 'del', 'tunnel', 'tid', tid
])
150 def read_ipv6_sysctl_attr(self
, link
, attribute
):
151 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, link
), attribute
)) as f
:
152 return f
.readline().strip()
154 def read_ipv4_sysctl_attr(self
, link
, attribute
):
155 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv4_path
, link
), attribute
)) as f
:
156 return f
.readline().strip()
158 def copy_unit_to_networkd_unit_path(self
, *units
):
161 shutil
.copy(os
.path
.join(networkd_ci_path
, unit
), network_unit_file_path
)
162 if (os
.path
.exists(os
.path
.join(networkd_ci_path
, unit
+ '.d'))):
163 copytree(os
.path
.join(networkd_ci_path
, unit
+ '.d'), os
.path
.join(network_unit_file_path
, unit
+ '.d'))
165 def remove_unit_from_networkd_path(self
, units
):
167 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
))):
168 os
.remove(os
.path
.join(network_unit_file_path
, unit
))
169 if (os
.path
.exists(os
.path
.join(network_unit_file_path
, unit
+ '.d'))):
170 shutil
.rmtree(os
.path
.join(network_unit_file_path
, unit
+ '.d'))
172 def start_dnsmasq(self
, additional_options
='', lease_time
='1h'):
173 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
174 subprocess
.check_call(dnsmasq_command
, shell
=True)
178 def stop_dnsmasq(self
, pid_file
):
179 if os
.path
.exists(pid_file
):
180 with
open(pid_file
, 'r') as f
:
181 pid
= f
.read().rstrip(' \t\r\n\0')
182 os
.kill(int(pid
), signal
.SIGTERM
)
186 def search_words_in_dnsmasq_log(self
, words
, show_all
=False):
187 if os
.path
.exists(dnsmasq_log_file
):
188 with
open (dnsmasq_log_file
) as in_file
:
189 contents
= in_file
.read()
192 for line
in contents
.splitlines():
195 print("%s, %s" % (words
, line
))
199 def remove_lease_file(self
):
200 if os
.path
.exists(os
.path
.join(networkd_ci_path
, 'lease')):
201 os
.remove(os
.path
.join(networkd_ci_path
, 'lease'))
203 def remove_log_file(self
):
204 if os
.path
.exists(dnsmasq_log_file
):
205 os
.remove(dnsmasq_log_file
)
207 def start_networkd(self
, sleep_sec
=5, remove_state_files
=True):
208 if (remove_state_files
and
209 os
.path
.exists(os
.path
.join(networkd_runtime_directory
, 'state'))):
210 subprocess
.check_call('systemctl stop systemd-networkd', shell
=True)
211 os
.remove(os
.path
.join(networkd_runtime_directory
, 'state'))
212 subprocess
.check_call('systemctl start systemd-networkd', shell
=True)
214 subprocess
.check_call('systemctl restart systemd-networkd', shell
=True)
216 time
.sleep(sleep_sec
)
218 def wait_online(self
, links_with_operstate
, timeout
='20s', bool_any
=False):
219 args
= [wait_online_bin
, f
'--timeout={timeout}'] + [f
'--interface={link}' for link
in links_with_operstate
]
223 subprocess
.check_call(args
)
224 except subprocess
.CalledProcessError
:
225 for link
in links_with_operstate
:
226 output
= subprocess
.check_output(['networkctl', 'status', link
.split(':')[0]], universal_newlines
=True).rstrip()
230 def get_operstate(self
, link
, show_status
=True, setup_state
='configured'):
231 output
= subprocess
.check_output(['networkctl', 'status', link
], universal_newlines
=True).rstrip()
234 for line
in output
.splitlines():
235 if 'State:' in line
and (not setup_state
or setup_state
in line
):
236 return line
.split()[1]
239 def check_operstate(self
, link
, expected
, show_status
=True, setup_state
='configured'):
240 self
.assertRegex(self
.get_operstate(link
, show_status
, setup_state
), expected
)
243 class NetworkdNetDevTests(unittest
.TestCase
, Utilities
):
300 '10-dropin-test.netdev',
304 '15-name-conflict-test.netdev',
307 '21-vlan-test1.network',
310 '25-6rd-tunnel.netdev',
312 '25-bond-balanced-tlb.netdev',
315 '25-erspan-tunnel-local-any.netdev',
316 '25-erspan-tunnel.netdev',
317 '25-fou-gretap.netdev',
319 '25-fou-ipip.netdev',
320 '25-fou-ipproto-gre.netdev',
321 '25-fou-ipproto-ipip.netdev',
324 '25-gretap-tunnel-local-any.netdev',
325 '25-gretap-tunnel.netdev',
326 '25-gre-tunnel-local-any.netdev',
327 '25-gre-tunnel-remote-any.netdev',
328 '25-gre-tunnel.netdev',
329 '25-ip6gretap-tunnel-local-any.netdev',
330 '25-ip6gretap-tunnel.netdev',
331 '25-ip6gre-tunnel-local-any.netdev',
332 '25-ip6gre-tunnel-remote-any.netdev',
333 '25-ip6gre-tunnel.netdev',
334 '25-ip6tnl-tunnel-remote-any.netdev',
335 '25-ip6tnl-tunnel-local-any.netdev',
336 '25-ip6tnl-tunnel.netdev',
337 '25-ipip-tunnel-independent.netdev',
338 '25-ipip-tunnel-local-any.netdev',
339 '25-ipip-tunnel-remote-any.netdev',
340 '25-ipip-tunnel.netdev',
343 '25-isatap-tunnel.netdev',
347 '25-sit-tunnel-local-any.netdev',
348 '25-sit-tunnel-remote-any.netdev',
349 '25-sit-tunnel.netdev',
352 '25-tunnel-local-any.network',
353 '25-tunnel-remote-any.network',
358 '25-vti6-tunnel-local-any.netdev',
359 '25-vti6-tunnel-remote-any.netdev',
360 '25-vti6-tunnel.netdev',
361 '25-vti-tunnel-local-any.netdev',
362 '25-vti-tunnel-remote-any.netdev',
363 '25-vti-tunnel.netdev',
365 '25-wireguard-23-peers.netdev',
366 '25-wireguard-23-peers.network',
367 '25-wireguard-preshared-key.txt',
368 '25-wireguard-private-key.txt',
369 '25-wireguard.netdev',
370 '25-wireguard.network',
386 'netdev-link-local-addressing-yes.network',
390 'vxlan-test1.network',
394 self
.link_remove(self
.links
)
397 self
.link_remove(self
.links
)
398 self
.remove_unit_from_networkd_path(self
.units
)
400 def test_dropin_and_networkctl_glob(self
):
401 self
.copy_unit_to_networkd_unit_path('10-dropin-test.netdev', '15-name-conflict-test.netdev')
402 self
.start_networkd(0)
404 self
.wait_online(['dropin-test:off'])
406 # This also tests NetDev.Name= conflict and basic networkctl functionalities
408 output
= subprocess
.check_output(['ip', 'link', 'show', 'dropin-test'], universal_newlines
=True).rstrip()
410 self
.assertRegex(output
, '00:50:56:c0:00:28')
412 output
= subprocess
.check_output(['networkctl', 'list'], universal_newlines
=True).rstrip()
413 self
.assertRegex(output
, '1 lo ')
414 self
.assertRegex(output
, 'dropin-test')
416 output
= subprocess
.check_output(['networkctl', 'list', 'dropin-test'], universal_newlines
=True).rstrip()
417 self
.assertNotRegex(output
, '1 lo ')
418 self
.assertRegex(output
, 'dropin-test')
420 output
= subprocess
.check_output(['networkctl', 'list', 'dropin-*'], universal_newlines
=True).rstrip()
421 self
.assertNotRegex(output
, '1 lo ')
422 self
.assertRegex(output
, 'dropin-test')
424 output
= subprocess
.check_output(['networkctl', 'status', 'dropin-*'], universal_newlines
=True).rstrip()
425 self
.assertNotRegex(output
, '1: lo ')
426 self
.assertRegex(output
, 'dropin-test')
428 ret
= subprocess
.run(['ethtool', '--driver', 'dropin-test'], stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
, universal_newlines
=True)
429 print(ret
.stdout
.rstrip())
430 if ret
.returncode
== 0 and re
.search('driver: dummy', ret
.stdout
.rstrip()) != None:
431 self
.assertRegex(output
, 'Driver: dummy')
433 print('ethtool does not support driver field at least for dummy interfaces, skipping test for Driver field of networkctl.')
435 def test_wait_online_any(self
):
436 self
.copy_unit_to_networkd_unit_path('25-bridge.netdev', '25-bridge.network', '11-dummy.netdev', '11-dummy.network')
437 self
.start_networkd(0)
439 self
.wait_online(['bridge99', 'test1:degraded'], bool_any
=True)
440 self
.check_link_exists('bridge99')
441 self
.check_link_exists('test1')
443 self
.check_operstate('bridge99', '(?:off|no-carrier)', setup_state
='configuring')
444 self
.check_operstate('test1', 'degraded')
446 def test_bridge(self
):
447 self
.copy_unit_to_networkd_unit_path('25-bridge.netdev')
448 self
.start_networkd(0)
450 self
.wait_online(['bridge99:off'])
452 tick
= os
.sysconf('SC_CLK_TCK')
453 self
.assertEqual(9, round(float(self
.read_link_attr('bridge99', 'bridge', 'hello_time')) / tick
))
454 self
.assertEqual(9, round(float(self
.read_link_attr('bridge99', 'bridge', 'max_age')) / tick
))
455 self
.assertEqual(9, round(float(self
.read_link_attr('bridge99', 'bridge','forward_delay')) / tick
))
456 self
.assertEqual(9, round(float(self
.read_link_attr('bridge99', 'bridge','ageing_time')) / tick
))
457 self
.assertEqual(9, int(self
.read_link_attr('bridge99', 'bridge','priority')))
458 self
.assertEqual(1, int(self
.read_link_attr('bridge99', 'bridge','multicast_querier')))
459 self
.assertEqual(1, int(self
.read_link_attr('bridge99', 'bridge','multicast_snooping')))
460 self
.assertEqual(1, int(self
.read_link_attr('bridge99', 'bridge','stp_state')))
463 self
.copy_unit_to_networkd_unit_path('25-bond.netdev', '25-bond-balanced-tlb.netdev')
464 self
.start_networkd(0)
466 self
.wait_online(['bond99:off', 'bond98:off'])
468 self
.assertEqual('802.3ad 4', self
.read_link_attr('bond99', 'bonding', 'mode'))
469 self
.assertEqual('layer3+4 1', self
.read_link_attr('bond99', 'bonding', 'xmit_hash_policy'))
470 self
.assertEqual('1000', self
.read_link_attr('bond99', 'bonding', 'miimon'))
471 self
.assertEqual('fast 1', self
.read_link_attr('bond99', 'bonding', 'lacp_rate'))
472 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'updelay'))
473 self
.assertEqual('2000', self
.read_link_attr('bond99', 'bonding', 'downdelay'))
474 self
.assertEqual('4', self
.read_link_attr('bond99', 'bonding', 'resend_igmp'))
475 self
.assertEqual('1', self
.read_link_attr('bond99', 'bonding', 'min_links'))
476 self
.assertEqual('1218', self
.read_link_attr('bond99', 'bonding', 'ad_actor_sys_prio'))
477 self
.assertEqual('811', self
.read_link_attr('bond99', 'bonding', 'ad_user_port_key'))
478 self
.assertEqual('00:11:22:33:44:55', self
.read_link_attr('bond99', 'bonding', 'ad_actor_system'))
480 self
.assertEqual('balance-tlb 5', self
.read_link_attr('bond98', 'bonding', 'mode'))
481 self
.assertEqual('1', self
.read_link_attr('bond98', 'bonding', 'tlb_dynamic_lb'))
484 self
.copy_unit_to_networkd_unit_path('21-vlan.netdev', '11-dummy.netdev',
485 '21-vlan.network', '21-vlan-test1.network')
486 self
.start_networkd(0)
488 self
.wait_online(['test1', 'vlan99'])
490 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1'], universal_newlines
=True).rstrip()
492 self
.assertRegex(output
, ' mtu 2000 ')
494 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vlan99'], universal_newlines
=True).rstrip()
496 self
.assertRegex(output
, ' mtu 2000 ')
497 self
.assertRegex(output
, 'REORDER_HDR')
498 self
.assertRegex(output
, 'LOOSE_BINDING')
499 self
.assertRegex(output
, 'GVRP')
500 self
.assertRegex(output
, 'MVRP')
501 self
.assertRegex(output
, ' id 99 ')
503 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'test1'], universal_newlines
=True).rstrip()
505 self
.assertRegex(output
, 'inet 192.168.24.5/24 brd 192.168.24.255 scope global test1')
506 self
.assertRegex(output
, 'inet 192.168.25.5/24 brd 192.168.25.255 scope global test1')
508 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'vlan99'], universal_newlines
=True).rstrip()
510 self
.assertRegex(output
, 'inet 192.168.23.5/24 brd 192.168.23.255 scope global vlan99')
512 def test_macvtap(self
):
513 for mode
in ['private', 'vepa', 'bridge', 'passthru']:
514 with self
.subTest(mode
=mode
):
515 if mode
!= 'private':
517 self
.copy_unit_to_networkd_unit_path('21-macvtap.netdev', 'netdev-link-local-addressing-yes.network',
518 '11-dummy.netdev', 'macvtap.network')
519 with
open(os
.path
.join(network_unit_file_path
, '21-macvtap.netdev'), mode
='a') as f
:
520 f
.write('[MACVTAP]\nMode=' + mode
)
521 self
.start_networkd(0)
523 self
.wait_online(['macvtap99:degraded', 'test1:degraded'])
525 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'macvtap99'], universal_newlines
=True).rstrip()
527 self
.assertRegex(output
, 'macvtap mode ' + mode
+ ' ')
529 def test_macvlan(self
):
530 for mode
in ['private', 'vepa', 'bridge', 'passthru']:
531 with self
.subTest(mode
=mode
):
532 if mode
!= 'private':
534 self
.copy_unit_to_networkd_unit_path('21-macvlan.netdev', 'netdev-link-local-addressing-yes.network',
535 '11-dummy.netdev', 'macvlan.network')
536 with
open(os
.path
.join(network_unit_file_path
, '21-macvlan.netdev'), mode
='a') as f
:
537 f
.write('[MACVLAN]\nMode=' + mode
)
538 self
.start_networkd(0)
540 self
.wait_online(['macvlan99:degraded', 'test1:degraded'])
542 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1'], universal_newlines
=True).rstrip()
544 self
.assertRegex(output
, ' mtu 2000 ')
546 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'macvlan99'], universal_newlines
=True).rstrip()
548 self
.assertRegex(output
, ' mtu 2000 ')
549 self
.assertRegex(output
, 'macvlan mode ' + mode
+ ' ')
551 @expectedFailureIfModuleIsNotAvailable('ipvlan')
552 def test_ipvlan(self
):
553 for mode
, flag
in [['L2', 'private'], ['L3', 'vepa'], ['L3S', 'bridge']]:
554 with self
.subTest(mode
=mode
, flag
=flag
):
557 self
.copy_unit_to_networkd_unit_path('25-ipvlan.netdev', 'netdev-link-local-addressing-yes.network',
558 '11-dummy.netdev', 'ipvlan.network')
559 with
open(os
.path
.join(network_unit_file_path
, '25-ipvlan.netdev'), mode
='a') as f
:
560 f
.write('[IPVLAN]\nMode=' + mode
+ '\nFlags=' + flag
)
562 self
.start_networkd(0)
563 self
.wait_online(['ipvlan99:degraded', 'test1:degraded'])
565 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipvlan99'], universal_newlines
=True).rstrip()
567 self
.assertRegex(output
, 'ipvlan *mode ' + mode
.lower() + ' ' + flag
)
569 @expectedFailureIfModuleIsNotAvailable('ipvtap')
570 def test_ipvtap(self
):
571 for mode
, flag
in [['L2', 'private'], ['L3', 'vepa'], ['L3S', 'bridge']]:
572 with self
.subTest(mode
=mode
, flag
=flag
):
575 self
.copy_unit_to_networkd_unit_path('25-ipvtap.netdev', 'netdev-link-local-addressing-yes.network',
576 '11-dummy.netdev', 'ipvtap.network')
577 with
open(os
.path
.join(network_unit_file_path
, '25-ipvtap.netdev'), mode
='a') as f
:
578 f
.write('[IPVTAP]\nMode=' + mode
+ '\nFlags=' + flag
)
580 self
.start_networkd(0)
581 self
.wait_online(['ipvtap99:degraded', 'test1:degraded'])
583 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipvtap99'], universal_newlines
=True).rstrip()
585 self
.assertRegex(output
, 'ipvtap *mode ' + mode
.lower() + ' ' + flag
)
588 self
.copy_unit_to_networkd_unit_path('25-veth.netdev')
589 self
.start_networkd(0)
591 self
.wait_online(['veth99:off', 'veth-peer:off'])
593 def test_dummy(self
):
594 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev')
595 self
.start_networkd(0)
597 self
.wait_online(['test1:off'])
600 self
.copy_unit_to_networkd_unit_path('25-tun.netdev')
601 self
.start_networkd(0)
603 self
.wait_online(['tun99:off'])
605 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'tun99'], universal_newlines
=True).rstrip()
607 # Old ip command does not support IFF_ flags
608 self
.assertRegex(output
, 'tun (?:type tun pi on vnet_hdr on multi_queue|addrgenmode) ')
611 self
.copy_unit_to_networkd_unit_path('25-tap.netdev')
612 self
.start_networkd(0)
614 self
.wait_online(['tap99:off'])
616 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'tap99'], universal_newlines
=True).rstrip()
618 # Old ip command does not support IFF_ flags
619 self
.assertRegex(output
, 'tun (?:type tap pi on vnet_hdr on multi_queue|addrgenmode) ')
621 @expectedFailureIfModuleIsNotAvailable('vrf')
623 self
.copy_unit_to_networkd_unit_path('25-vrf.netdev')
624 self
.start_networkd(0)
626 self
.wait_online(['vrf99:off'])
628 @expectedFailureIfModuleIsNotAvailable('vcan')
630 self
.copy_unit_to_networkd_unit_path('25-vcan.netdev')
631 self
.start_networkd(0)
633 self
.wait_online(['vcan99:off'])
635 @expectedFailureIfModuleIsNotAvailable('wireguard')
636 def test_wireguard(self
):
637 self
.copy_unit_to_networkd_unit_path('25-wireguard.netdev', '25-wireguard.network',
638 '25-wireguard-23-peers.netdev', '25-wireguard-23-peers.network',
639 '25-wireguard-preshared-key.txt', '25-wireguard-private-key.txt')
640 self
.start_networkd(0)
641 self
.wait_online(['wg99:carrier', 'wg98:routable'])
643 if shutil
.which('wg'):
644 subprocess
.call('wg')
646 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'listen-port'], universal_newlines
=True).rstrip()
647 self
.assertRegex(output
, '51820')
648 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'fwmark'], universal_newlines
=True).rstrip()
649 self
.assertRegex(output
, '0x4d2')
650 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'allowed-ips'], universal_newlines
=True).rstrip()
651 self
.assertRegex(output
, 'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t192.168.26.0/24 fd31:bf08:57cb::/48')
652 self
.assertRegex(output
, 'lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc=\tfdbc:bae2:7871:e1fe:793:8636::/96 fdbc:bae2:7871:500:e1fe:793:8636:dad1/128')
653 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'persistent-keepalive'], universal_newlines
=True).rstrip()
654 self
.assertRegex(output
, 'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t20')
655 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'endpoints'], universal_newlines
=True).rstrip()
656 self
.assertRegex(output
, 'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA=\t192.168.27.3:51820')
657 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'private-key'], universal_newlines
=True).rstrip()
658 self
.assertRegex(output
, 'EEGlnEPYJV//kbvvIqxKkQwOiS\+UENyPncC4bF46ong=')
659 output
= subprocess
.check_output(['wg', 'show', 'wg99', 'preshared-keys'], universal_newlines
=True).rstrip()
660 self
.assertRegex(output
, 'RDf\+LSpeEre7YEIKaxg\+wbpsNV7du\+ktR99uBEtIiCA= IIWIV17wutHv7t4cR6pOT91z6NSz/T8Arh0yaywhw3M=')
661 self
.assertRegex(output
, 'lsDtM3AbjxNlauRKzHEPfgS1Zp7cp/VX5Use/P4PQSc= cPLOy1YUrEI0EMMIycPJmOo0aTu3RZnw8bL5meVD6m0=')
663 output
= subprocess
.check_output(['wg', 'show', 'wg98', 'private-key'], universal_newlines
=True).rstrip()
664 self
.assertRegex(output
, 'CJQUtcS9emY2fLYqDlpSZiE/QJyHkPWr\+WHtZLZ90FU=')
666 def test_geneve(self
):
667 self
.copy_unit_to_networkd_unit_path('25-geneve.netdev')
668 self
.start_networkd(0)
670 self
.wait_online(['geneve99:off'])
672 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'geneve99'], universal_newlines
=True).rstrip()
674 self
.assertRegex(output
, '192.168.22.1')
675 self
.assertRegex(output
, '6082')
676 self
.assertRegex(output
, 'udpcsum')
677 self
.assertRegex(output
, 'udp6zerocsumrx')
679 def test_ipip_tunnel(self
):
680 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ipip.network',
681 '25-ipip-tunnel.netdev', '25-tunnel.network',
682 '25-ipip-tunnel-local-any.netdev', '25-tunnel-local-any.network',
683 '25-ipip-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
684 self
.start_networkd(0)
685 self
.wait_online(['ipiptun99:routable', 'ipiptun98:routable', 'ipiptun97:routable', 'dummy98:degraded'])
687 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun99'], universal_newlines
=True).rstrip()
689 self
.assertRegex(output
, 'ipip (?:ipip |)remote 192.169.224.239 local 192.168.223.238 dev dummy98')
690 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun98'], universal_newlines
=True).rstrip()
692 self
.assertRegex(output
, 'ipip (?:ipip |)remote 192.169.224.239 local any dev dummy98')
693 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun97'], universal_newlines
=True).rstrip()
695 self
.assertRegex(output
, 'ipip (?:ipip |)remote any local 192.168.223.238 dev dummy98')
697 def test_gre_tunnel(self
):
698 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'gretun.network',
699 '25-gre-tunnel.netdev', '25-tunnel.network',
700 '25-gre-tunnel-local-any.netdev', '25-tunnel-local-any.network',
701 '25-gre-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
702 self
.start_networkd(0)
703 self
.wait_online(['gretun99:routable', 'gretun98:routable', 'gretun97:routable', 'dummy98:degraded'])
705 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun99'], universal_newlines
=True).rstrip()
707 self
.assertRegex(output
, 'gre remote 10.65.223.239 local 10.65.223.238 dev dummy98')
708 self
.assertRegex(output
, 'ikey 1.2.3.103')
709 self
.assertRegex(output
, 'okey 1.2.4.103')
710 self
.assertRegex(output
, 'iseq')
711 self
.assertRegex(output
, 'oseq')
712 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun98'], universal_newlines
=True).rstrip()
714 self
.assertRegex(output
, 'gre remote 10.65.223.239 local any dev dummy98')
715 self
.assertRegex(output
, 'ikey 0.0.0.104')
716 self
.assertRegex(output
, 'okey 0.0.0.104')
717 self
.assertNotRegex(output
, 'iseq')
718 self
.assertNotRegex(output
, 'oseq')
719 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun97'], universal_newlines
=True).rstrip()
721 self
.assertRegex(output
, 'gre remote any local 10.65.223.238 dev dummy98')
722 self
.assertRegex(output
, 'ikey 0.0.0.105')
723 self
.assertRegex(output
, 'okey 0.0.0.105')
724 self
.assertNotRegex(output
, 'iseq')
725 self
.assertNotRegex(output
, 'oseq')
727 @expectedFailureIf_ip6gre_do_not_support_ipv6ll()
728 def test_ip6gre_tunnel(self
):
729 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ip6gretun.network',
730 '25-ip6gre-tunnel.netdev', '25-tunnel.network',
731 '25-ip6gre-tunnel-local-any.netdev', '25-tunnel-local-any.network',
732 '25-ip6gre-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
733 self
.start_networkd()
735 self
.check_link_exists('dummy98')
736 self
.check_link_exists('ip6gretun99')
737 self
.check_link_exists('ip6gretun98')
738 self
.check_link_exists('ip6gretun97')
740 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretun99'], universal_newlines
=True).rstrip()
742 self
.assertRegex(output
, 'ip6gre remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
743 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretun98'], universal_newlines
=True).rstrip()
745 self
.assertRegex(output
, 'ip6gre remote 2001:473:fece:cafe::5179 local any dev dummy98')
746 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretun97'], universal_newlines
=True).rstrip()
748 self
.assertRegex(output
, 'ip6gre remote any local 2a00:ffde:4567:edde::4987 dev dummy98')
750 # Old kernels may not support IPv6LL address on ip6gre tunnel, and the following test may fails.
751 self
.wait_online(['ip6gretun99:routable', 'ip6gretun98:routable', 'ip6gretun97:routable', 'dummy98:degraded'])
753 def test_gretap_tunnel(self
):
754 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'gretap.network',
755 '25-gretap-tunnel.netdev', '25-tunnel.network',
756 '25-gretap-tunnel-local-any.netdev', '25-tunnel-local-any.network')
757 self
.start_networkd(0)
758 self
.wait_online(['gretap99:routable', 'gretap98:routable', 'dummy98:degraded'])
760 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretap99'], universal_newlines
=True).rstrip()
762 self
.assertRegex(output
, 'gretap remote 10.65.223.239 local 10.65.223.238 dev dummy98')
763 self
.assertRegex(output
, 'ikey 0.0.0.106')
764 self
.assertRegex(output
, 'okey 0.0.0.106')
765 self
.assertRegex(output
, 'iseq')
766 self
.assertRegex(output
, 'oseq')
767 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretap98'], universal_newlines
=True).rstrip()
769 self
.assertRegex(output
, 'gretap remote 10.65.223.239 local any dev dummy98')
770 self
.assertRegex(output
, 'ikey 0.0.0.107')
771 self
.assertRegex(output
, 'okey 0.0.0.107')
772 self
.assertRegex(output
, 'iseq')
773 self
.assertRegex(output
, 'oseq')
775 def test_ip6gretap_tunnel(self
):
776 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ip6gretap.network',
777 '25-ip6gretap-tunnel.netdev', '25-tunnel.network',
778 '25-ip6gretap-tunnel-local-any.netdev', '25-tunnel-local-any.network')
779 self
.start_networkd(0)
780 self
.wait_online(['ip6gretap99:routable', 'ip6gretap98:routable', 'dummy98:degraded'])
782 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretap99'], universal_newlines
=True).rstrip()
784 self
.assertRegex(output
, 'ip6gretap remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
785 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6gretap98'], universal_newlines
=True).rstrip()
787 self
.assertRegex(output
, 'ip6gretap remote 2001:473:fece:cafe::5179 local any dev dummy98')
789 def test_vti_tunnel(self
):
790 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'vti.network',
791 '25-vti-tunnel.netdev', '25-tunnel.network',
792 '25-vti-tunnel-local-any.netdev', '25-tunnel-local-any.network',
793 '25-vti-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
794 self
.start_networkd(0)
795 self
.wait_online(['vtitun99:routable', 'vtitun98:routable', 'vtitun97:routable', 'dummy98:degraded'])
797 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vtitun99'], universal_newlines
=True).rstrip()
799 self
.assertRegex(output
, 'vti remote 10.65.223.239 local 10.65.223.238 dev dummy98')
800 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vtitun98'], universal_newlines
=True).rstrip()
802 self
.assertRegex(output
, 'vti remote 10.65.223.239 local any dev dummy98')
803 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vtitun97'], universal_newlines
=True).rstrip()
805 self
.assertRegex(output
, 'vti remote any local 10.65.223.238 dev dummy98')
807 def test_vti6_tunnel(self
):
808 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'vti6.network',
809 '25-vti6-tunnel.netdev', '25-tunnel.network',
810 '25-vti6-tunnel-local-any.netdev', '25-tunnel-local-any.network',
811 '25-vti6-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
812 self
.start_networkd(0)
813 self
.wait_online(['vti6tun99:routable', 'vti6tun98:routable', 'vti6tun97:routable', 'dummy98:degraded'])
815 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vti6tun99'], universal_newlines
=True).rstrip()
817 self
.assertRegex(output
, 'vti6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
818 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vti6tun98'], universal_newlines
=True).rstrip()
820 self
.assertRegex(output
, 'vti6 remote 2001:473:fece:cafe::5179 local (?:any|::) dev dummy98')
821 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vti6tun97'], universal_newlines
=True).rstrip()
823 self
.assertRegex(output
, 'vti6 remote (?:any|::) local 2a00:ffde:4567:edde::4987 dev dummy98')
825 def test_ip6tnl_tunnel(self
):
826 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ip6tnl.network',
827 '25-ip6tnl-tunnel.netdev', '25-tunnel.network',
828 '25-ip6tnl-tunnel-local-any.netdev', '25-tunnel-local-any.network',
829 '25-ip6tnl-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
830 self
.start_networkd(0)
831 self
.wait_online(['ip6tnl99:routable', 'ip6tnl98:routable', 'ip6tnl97:routable', 'dummy98:degraded'])
833 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6tnl99'], universal_newlines
=True).rstrip()
835 self
.assertRegex(output
, 'ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
836 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6tnl98'], universal_newlines
=True).rstrip()
838 self
.assertRegex(output
, 'ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local (?:any|::) dev dummy98')
839 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ip6tnl97'], universal_newlines
=True).rstrip()
841 self
.assertRegex(output
, 'ip6tnl ip6ip6 remote (?:any|::) local 2a00:ffde:4567:edde::4987 dev dummy98')
843 def test_sit_tunnel(self
):
844 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'sit.network',
845 '25-sit-tunnel.netdev', '25-tunnel.network',
846 '25-sit-tunnel-local-any.netdev', '25-tunnel-local-any.network',
847 '25-sit-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
848 self
.start_networkd(0)
849 self
.wait_online(['sittun99:routable', 'sittun98:routable', 'sittun97:routable', 'dummy98:degraded'])
851 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun99'], universal_newlines
=True).rstrip()
853 self
.assertRegex(output
, "sit (?:ip6ip |)remote 10.65.223.239 local 10.65.223.238 dev dummy98")
854 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun98'], universal_newlines
=True).rstrip()
856 self
.assertRegex(output
, "sit (?:ip6ip |)remote 10.65.223.239 local any dev dummy98")
857 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun97'], universal_newlines
=True).rstrip()
859 self
.assertRegex(output
, "sit (?:ip6ip |)remote any local 10.65.223.238 dev dummy98")
861 def test_isatap_tunnel(self
):
862 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'isatap.network',
863 '25-isatap-tunnel.netdev', '25-tunnel.network')
864 self
.start_networkd(0)
865 self
.wait_online(['isataptun99:routable', 'dummy98:degraded'])
867 self
.check_link_exists('dummy98')
868 self
.check_link_exists('isataptun99')
870 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'isataptun99'], universal_newlines
=True).rstrip()
872 self
.assertRegex(output
, "isatap ")
874 def test_6rd_tunnel(self
):
875 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '6rd.network',
876 '25-6rd-tunnel.netdev', '25-tunnel.network')
877 self
.start_networkd(0)
878 self
.wait_online(['sittun99:routable', 'dummy98:degraded'])
880 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun99'], universal_newlines
=True).rstrip()
882 self
.assertRegex(output
, '6rd-prefix 2602::/24')
884 @expectedFailureIfERSPANModuleIsNotAvailable()
885 def test_erspan_tunnel(self
):
886 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', 'erspan.network',
887 '25-erspan-tunnel.netdev', '25-tunnel.network',
888 '25-erspan-tunnel-local-any.netdev', '25-tunnel-local-any.network')
889 self
.start_networkd(0)
890 self
.wait_online(['erspan99:routable', 'erspan98:routable', 'dummy98:degraded'])
892 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'erspan99'], universal_newlines
=True).rstrip()
894 self
.assertRegex(output
, 'erspan remote 172.16.1.100 local 172.16.1.200')
895 self
.assertRegex(output
, 'ikey 0.0.0.101')
896 self
.assertRegex(output
, 'okey 0.0.0.101')
897 self
.assertRegex(output
, 'iseq')
898 self
.assertRegex(output
, 'oseq')
899 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'erspan98'], universal_newlines
=True).rstrip()
901 self
.assertRegex(output
, 'erspan remote 172.16.1.100 local any')
902 self
.assertRegex(output
, '102')
903 self
.assertRegex(output
, 'ikey 0.0.0.102')
904 self
.assertRegex(output
, 'okey 0.0.0.102')
905 self
.assertRegex(output
, 'iseq')
906 self
.assertRegex(output
, 'oseq')
908 def test_tunnel_independent(self
):
909 self
.copy_unit_to_networkd_unit_path('25-ipip-tunnel-independent.netdev')
910 self
.start_networkd(0)
912 self
.wait_online(['ipiptun99:off'])
914 @expectedFailureIfModuleIsNotAvailable('fou')
916 # The following redundant check is necessary for CentOS CI.
917 # Maybe, error handling in lookup_id() in sd-netlink/generic-netlink.c needs to be updated.
918 self
.assertTrue(is_module_available('fou'))
920 self
.copy_unit_to_networkd_unit_path('25-fou-ipproto-ipip.netdev', '25-fou-ipproto-gre.netdev',
921 '25-fou-ipip.netdev', '25-fou-sit.netdev',
922 '25-fou-gre.netdev', '25-fou-gretap.netdev')
923 self
.start_networkd(0)
925 self
.wait_online(['ipiptun96:off', 'sittun96:off', 'gretun96:off', 'gretap96:off'])
927 output
= subprocess
.check_output(['ip', 'fou', 'show'], universal_newlines
=True).rstrip()
929 self
.assertRegex(output
, 'port 55555 ipproto 4')
930 self
.assertRegex(output
, 'port 55556 ipproto 47')
932 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'ipiptun96'], universal_newlines
=True).rstrip()
934 self
.assertRegex(output
, 'encap fou encap-sport auto encap-dport 55555')
935 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'sittun96'], universal_newlines
=True).rstrip()
937 self
.assertRegex(output
, 'encap fou encap-sport auto encap-dport 55555')
938 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretun96'], universal_newlines
=True).rstrip()
940 self
.assertRegex(output
, 'encap fou encap-sport 1001 encap-dport 55556')
941 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'gretap96'], universal_newlines
=True).rstrip()
943 self
.assertRegex(output
, 'encap fou encap-sport auto encap-dport 55556')
945 subprocess
.call(['ip', 'fou', 'del', 'port', '55555'])
946 subprocess
.call(['ip', 'fou', 'del', 'port', '55556'])
948 def test_vxlan(self
):
949 self
.copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network',
950 '11-dummy.netdev', 'vxlan-test1.network')
951 self
.start_networkd(0)
953 self
.wait_online(['test1:degraded', 'vxlan99:degraded'])
955 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'vxlan99'], universal_newlines
=True).rstrip()
957 self
.assertRegex(output
, '999')
958 self
.assertRegex(output
, '5555')
959 self
.assertRegex(output
, 'l2miss')
960 self
.assertRegex(output
, 'l3miss')
961 self
.assertRegex(output
, 'udpcsum')
962 self
.assertRegex(output
, 'udp6zerocsumtx')
963 self
.assertRegex(output
, 'udp6zerocsumrx')
964 self
.assertRegex(output
, 'remcsumtx')
965 self
.assertRegex(output
, 'remcsumrx')
966 self
.assertRegex(output
, 'gbp')
968 output
= subprocess
.check_output(['bridge', 'fdb', 'show', 'dev', 'vxlan99'], universal_newlines
=True).rstrip()
970 self
.assertRegex(output
, '00:11:22:33:44:55 dst 10.0.0.5 self permanent')
971 self
.assertRegex(output
, '00:11:22:33:44:66 dst 10.0.0.6 self permanent')
972 self
.assertRegex(output
, '00:11:22:33:44:77 dst 10.0.0.7 self permanent')
974 def test_macsec(self
):
975 self
.copy_unit_to_networkd_unit_path('25-macsec.netdev', '25-macsec.network', '25-macsec.key',
976 'macsec.network', '12-dummy.netdev')
977 self
.start_networkd(0)
979 self
.wait_online(['dummy98:degraded', 'macsec99:routable'])
981 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'macsec99'], universal_newlines
=True).rstrip()
983 self
.assertRegex(output
, 'macsec99@dummy98')
984 self
.assertRegex(output
, 'macsec sci [0-9a-f]*000b')
985 self
.assertRegex(output
, 'encrypt on')
987 output
= subprocess
.check_output(['ip', 'macsec', 'show', 'macsec99'], universal_newlines
=True).rstrip()
989 self
.assertRegex(output
, 'encrypt on')
990 self
.assertRegex(output
, 'TXSC: [0-9a-f]*000b on SA 1')
991 self
.assertRegex(output
, '0: PN [0-9]*, state on, key 01000000000000000000000000000000')
992 self
.assertRegex(output
, '1: PN [0-9]*, state on, key 02030000000000000000000000000000')
993 self
.assertRegex(output
, 'RXSC: c619528fe6a00100, state on')
994 self
.assertRegex(output
, '0: PN [0-9]*, state on, key 02030405000000000000000000000000')
995 self
.assertRegex(output
, '1: PN [0-9]*, state on, key 02030405060000000000000000000000')
996 self
.assertRegex(output
, '2: PN [0-9]*, state off, key 02030405060700000000000000000000')
997 self
.assertRegex(output
, '3: PN [0-9]*, state off, key 02030405060708000000000000000000')
998 self
.assertNotRegex(output
, 'key 02030405067080900000000000000000')
999 self
.assertRegex(output
, 'RXSC: 8c16456c83a90002, state on')
1000 self
.assertRegex(output
, '0: PN [0-9]*, state off, key 02030400000000000000000000000000')
1003 class NetworkdL2TPTests(unittest
.TestCase
, Utilities
):
1014 '25-l2tp-dummy.network',
1015 '25-l2tp-ip.netdev',
1016 '25-l2tp-udp.netdev']
1018 l2tp_tunnel_ids
= [ '10' ]
1021 self
.l2tp_tunnel_remove(self
.l2tp_tunnel_ids
)
1022 self
.link_remove(self
.links
)
1025 self
.l2tp_tunnel_remove(self
.l2tp_tunnel_ids
)
1026 self
.link_remove(self
.links
)
1027 self
.remove_unit_from_networkd_path(self
.units
)
1029 @expectedFailureIfModuleIsNotAvailable('l2tp_eth')
1030 def test_l2tp_udp(self
):
1031 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-udp.netdev')
1032 self
.start_networkd(0)
1034 self
.wait_online(['test1:routable', 'l2tp-ses1:off', 'l2tp-ses2:off'])
1036 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '10'], universal_newlines
=True).rstrip()
1038 self
.assertRegex(output
, "Tunnel 10, encap UDP")
1039 self
.assertRegex(output
, "From 192.168.30.100 to 192.168.30.101")
1040 self
.assertRegex(output
, "Peer tunnel 11")
1041 self
.assertRegex(output
, "UDP source / dest ports: 3000/4000")
1042 self
.assertRegex(output
, "UDP checksum: enabled")
1044 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '15'], universal_newlines
=True).rstrip()
1046 self
.assertRegex(output
, "Session 15 in tunnel 10")
1047 self
.assertRegex(output
, "Peer session 16, tunnel 11")
1048 self
.assertRegex(output
, "interface name: l2tp-ses1")
1050 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '17'], universal_newlines
=True).rstrip()
1052 self
.assertRegex(output
, "Session 17 in tunnel 10")
1053 self
.assertRegex(output
, "Peer session 18, tunnel 11")
1054 self
.assertRegex(output
, "interface name: l2tp-ses2")
1056 @expectedFailureIfModuleIsNotAvailable('l2tp_ip')
1057 def test_l2tp_ip(self
):
1058 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-ip.netdev')
1059 self
.start_networkd(0)
1061 self
.wait_online(['test1:routable', 'l2tp-ses3:off', 'l2tp-ses4:off'])
1063 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '10'], universal_newlines
=True).rstrip()
1065 self
.assertRegex(output
, "Tunnel 10, encap IP")
1066 self
.assertRegex(output
, "From 192.168.30.100 to 192.168.30.101")
1067 self
.assertRegex(output
, "Peer tunnel 12")
1069 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '25'], universal_newlines
=True).rstrip()
1071 self
.assertRegex(output
, "Session 25 in tunnel 10")
1072 self
.assertRegex(output
, "Peer session 26, tunnel 12")
1073 self
.assertRegex(output
, "interface name: l2tp-ses3")
1075 output
= subprocess
.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '27'], universal_newlines
=True).rstrip()
1077 self
.assertRegex(output
, "Session 27 in tunnel 10")
1078 self
.assertRegex(output
, "Peer session 28, tunnel 12")
1079 self
.assertRegex(output
, "interface name: l2tp-ses4")
1081 class NetworkdNetWorkTests(unittest
.TestCase
, Utilities
):
1091 '23-active-slave.network',
1092 '25-address-link-section.network',
1093 '25-address-preferred-lifetime-zero-ipv6.network',
1094 '25-address-static.network',
1095 '25-bind-carrier.network',
1096 '25-bond-active-backup-slave.netdev',
1097 '25-fibrule-invert.network',
1098 '25-fibrule-port-range.network',
1099 '25-ipv6-address-label-section.network',
1100 '25-neighbor-section.network',
1101 '25-link-local-addressing-no.network',
1102 '25-link-local-addressing-yes.network',
1103 '25-link-section-unmanaged.network',
1104 '25-route-ipv6-src.network',
1105 '25-route-static.network',
1106 '25-sysctl-disable-ipv6.network',
1107 '25-sysctl.network',
1108 'configure-without-carrier.network',
1109 'routing-policy-rule-dummy98.network',
1110 'routing-policy-rule-test1.network']
1113 self
.link_remove(self
.links
)
1116 self
.link_remove(self
.links
)
1117 self
.remove_unit_from_networkd_path(self
.units
)
1119 def test_address_static(self
):
1120 self
.copy_unit_to_networkd_unit_path('25-address-static.network', '12-dummy.netdev')
1121 self
.start_networkd(0)
1123 self
.wait_online(['dummy98:routable'])
1125 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98'], universal_newlines
=True).rstrip()
1127 self
.assertRegex(output
, 'inet 10.1.2.3/16 brd 10.1.255.255 scope global dummy98')
1128 self
.assertRegex(output
, 'inet 10.1.2.4/16 brd 10.1.255.255 scope global secondary dummy98')
1129 self
.assertRegex(output
, 'inet 10.2.2.4/16 brd 10.2.255.255 scope global dummy98')
1132 self
.assertNotRegex(output
, '10.10.0.1/16')
1133 self
.assertNotRegex(output
, '10.10.0.2/16')
1135 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '32'], universal_newlines
=True).rstrip()
1136 self
.assertRegex(output
, 'inet 10.3.2.3/16 brd 10.3.255.255 scope global 32')
1138 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '33'], universal_newlines
=True).rstrip()
1139 self
.assertRegex(output
, 'inet 10.4.2.3 peer 10.4.2.4/16 scope global 33')
1141 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '34'], universal_newlines
=True).rstrip()
1142 self
.assertRegex(output
, 'inet 192.168.[0-9]*.1/24 brd 192.168.[0-9]*.255 scope global 34')
1144 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'dummy98', 'label', '35'], universal_newlines
=True).rstrip()
1145 self
.assertRegex(output
, 'inet 172.[0-9]*.0.1/16 brd 172.[0-9]*.255.255 scope global 35')
1147 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'dummy98'], universal_newlines
=True).rstrip()
1149 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::15/64 scope global')
1150 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::16/64 scope global')
1151 self
.assertRegex(output
, 'inet6 2001:db8:0:f102::15/64 scope global')
1152 self
.assertRegex(output
, 'inet6 2001:db8:0:f102::16/64 scope global')
1153 self
.assertRegex(output
, 'inet6 2001:db8:0:f103::20 peer 2001:db8:0:f103::10/128 scope global')
1154 self
.assertRegex(output
, 'inet6 fd[0-9a-f:]*1/64 scope global')
1156 def test_address_preferred_lifetime_zero_ipv6(self
):
1157 self
.copy_unit_to_networkd_unit_path('25-address-preferred-lifetime-zero-ipv6.network', '12-dummy.netdev')
1158 self
.start_networkd()
1160 self
.check_link_exists('dummy98')
1162 self
.check_operstate('dummy98', 'routable', setup_state
='configuring')
1164 output
= subprocess
.check_output(['ip', 'address', 'show', 'dummy98'], universal_newlines
=True).rstrip()
1166 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope link deprecated dummy98')
1167 self
.assertRegex(output
, 'inet6 2001:db8:0:f101::1/64 scope global')
1169 def test_configure_without_carrier(self
):
1170 self
.copy_unit_to_networkd_unit_path('configure-without-carrier.network', '11-dummy.netdev')
1171 self
.start_networkd()
1173 self
.check_link_exists('test1')
1175 output
= subprocess
.check_output(['networkctl', 'status', 'test1'], universal_newlines
=True).rstrip()
1177 self
.assertRegex(output
, '192.168.0.15')
1178 self
.assertRegex(output
, '192.168.0.1')
1179 self
.assertRegex(output
, 'routable')
1181 def test_routing_policy_rule(self
):
1182 self
.copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev')
1184 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1186 self
.start_networkd()
1188 self
.check_link_exists('test1')
1190 output
= subprocess
.check_output(['ip', 'rule'], universal_newlines
=True).rstrip()
1192 self
.assertRegex(output
, '111')
1193 self
.assertRegex(output
, 'from 192.168.100.18')
1194 self
.assertRegex(output
, r
'tos (?:0x08|throughput)\s')
1195 self
.assertRegex(output
, 'iif test1')
1196 self
.assertRegex(output
, 'oif test1')
1197 self
.assertRegex(output
, 'lookup 7')
1199 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1201 def test_routing_policy_rule_issue_11280(self
):
1202 self
.copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev',
1203 'routing-policy-rule-dummy98.network', '12-dummy.netdev')
1205 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1206 subprocess
.call(['ip', 'rule', 'del', 'table', '8'])
1208 for trial
in range(3):
1209 # Remove state files only first time
1210 self
.start_networkd(remove_state_files
=(trial
== 0))
1212 self
.check_link_exists('test1')
1213 self
.check_link_exists('dummy98')
1215 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '7'], universal_newlines
=True).rstrip()
1217 self
.assertRegex(output
, '111: from 192.168.100.18 tos (?:0x08|throughput) iif test1 oif test1 lookup 7')
1219 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '8'], universal_newlines
=True).rstrip()
1221 self
.assertRegex(output
, '112: from 192.168.101.18 tos (?:0x08|throughput) iif dummy98 oif dummy98 lookup 8')
1223 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1224 subprocess
.call(['ip', 'rule', 'del', 'table', '8'])
1226 @expectedFailureIfRoutingPolicyPortRangeIsNotAvailable()
1227 def test_routing_policy_rule_port_range(self
):
1228 self
.copy_unit_to_networkd_unit_path('25-fibrule-port-range.network', '11-dummy.netdev')
1230 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1232 self
.start_networkd()
1234 self
.check_link_exists('test1')
1236 output
= subprocess
.check_output(['ip', 'rule'], universal_newlines
=True).rstrip()
1238 self
.assertRegex(output
, '111')
1239 self
.assertRegex(output
, 'from 192.168.100.18')
1240 self
.assertRegex(output
, '1123-1150')
1241 self
.assertRegex(output
, '3224-3290')
1242 self
.assertRegex(output
, 'tcp')
1243 self
.assertRegex(output
, 'lookup 7')
1245 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1247 @expectedFailureIfRoutingPolicyIPProtoIsNotAvailable()
1248 def test_routing_policy_rule_invert(self
):
1249 self
.copy_unit_to_networkd_unit_path('25-fibrule-invert.network', '11-dummy.netdev')
1251 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1253 self
.start_networkd()
1255 self
.check_link_exists('test1')
1257 output
= subprocess
.check_output(['ip', 'rule'], universal_newlines
=True).rstrip()
1259 self
.assertRegex(output
, '111')
1260 self
.assertRegex(output
, 'not.*?from.*?192.168.100.18')
1261 self
.assertRegex(output
, 'tcp')
1262 self
.assertRegex(output
, 'lookup 7')
1264 subprocess
.call(['ip', 'rule', 'del', 'table', '7'])
1266 def test_route_static(self
):
1267 self
.copy_unit_to_networkd_unit_path('25-route-static.network', '12-dummy.netdev')
1268 self
.start_networkd(0)
1270 self
.wait_online(['dummy98:routable'])
1272 output
= subprocess
.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98'], universal_newlines
=True).rstrip()
1274 self
.assertRegex(output
, '2001:1234:5:8fff:ff:ff:ff:ff proto static')
1275 self
.assertRegex(output
, '2001:1234:5:8f63::1 proto kernel')
1277 output
= subprocess
.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98', 'default'], universal_newlines
=True).rstrip()
1278 self
.assertRegex(output
, 'default via 2001:1234:5:8fff:ff:ff:ff:ff proto static metric 1024 pref medium')
1280 output
= subprocess
.check_output(['ip', '-4', 'route', 'show', 'dev', 'dummy98'], universal_newlines
=True).rstrip()
1282 self
.assertRegex(output
, '149.10.124.48/28 proto kernel scope link src 149.10.124.58')
1283 self
.assertRegex(output
, '149.10.124.64 proto static scope link')
1284 self
.assertRegex(output
, '169.254.0.0/16 proto static scope link metric 2048')
1285 self
.assertRegex(output
, '192.168.1.1 proto static initcwnd 20')
1286 self
.assertRegex(output
, '192.168.1.2 proto static initrwnd 30')
1288 output
= subprocess
.check_output(['ip', '-4', 'route', 'show', 'dev', 'dummy98', 'default'], universal_newlines
=True).rstrip()
1289 self
.assertRegex(output
, 'default via 149.10.125.65 proto static onlink')
1290 self
.assertRegex(output
, 'default via 149.10.124.64 proto static')
1291 self
.assertRegex(output
, 'default proto static')
1293 output
= subprocess
.check_output(['ip', 'route', 'show', 'type', 'blackhole'], universal_newlines
=True).rstrip()
1295 self
.assertRegex(output
, 'blackhole 202.54.1.2 proto static')
1297 output
= subprocess
.check_output(['ip', 'route', 'show', 'type', 'unreachable'], universal_newlines
=True).rstrip()
1299 self
.assertRegex(output
, 'unreachable 202.54.1.3 proto static')
1301 output
= subprocess
.check_output(['ip', 'route', 'show', 'type', 'prohibit'], universal_newlines
=True).rstrip()
1303 self
.assertRegex(output
, 'prohibit 202.54.1.4 proto static')
1305 subprocess
.call(['ip', 'route', 'del', 'blackhole', '202.54.1.2'])
1306 subprocess
.call(['ip', 'route', 'del', 'unreachable', '202.54.1.3'])
1307 subprocess
.call(['ip', 'route', 'del', 'prohibit', '202.54.1.4'])
1309 def test_ip_route_ipv6_src_route(self
):
1310 # a dummy device does not make the addresses go through tentative state, so we
1311 # reuse a bond from an earlier test, which does make the addresses go through
1312 # tentative state, and do our test on that
1313 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')
1314 self
.start_networkd()
1316 self
.check_link_exists('dummy98')
1317 self
.check_link_exists('bond199')
1319 output
= subprocess
.check_output(['ip', '-6', 'route', 'list', 'dev', 'bond199'], universal_newlines
=True).rstrip()
1321 self
.assertRegex(output
, 'abcd::/16')
1322 self
.assertRegex(output
, 'src')
1323 self
.assertRegex(output
, '2001:1234:56:8f63::2')
1325 def test_ip_link_mac_address(self
):
1326 self
.copy_unit_to_networkd_unit_path('25-address-link-section.network', '12-dummy.netdev')
1327 self
.start_networkd()
1329 self
.check_link_exists('dummy98')
1331 output
= subprocess
.check_output(['ip', 'link', 'show', 'dummy98'], universal_newlines
=True).rstrip()
1333 self
.assertRegex(output
, '00:01:02:aa:bb:cc')
1335 def test_ip_link_unmanaged(self
):
1336 self
.copy_unit_to_networkd_unit_path('25-link-section-unmanaged.network', '12-dummy.netdev')
1337 self
.start_networkd()
1339 self
.check_link_exists('dummy98')
1341 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98'], universal_newlines
=True).rstrip()
1343 self
.assertRegex(output
, 'unmanaged')
1345 def test_ipv6_address_label(self
):
1346 self
.copy_unit_to_networkd_unit_path('25-ipv6-address-label-section.network', '12-dummy.netdev')
1347 self
.start_networkd()
1349 self
.check_link_exists('dummy98')
1351 output
= subprocess
.check_output(['ip', 'addrlabel', 'list'], universal_newlines
=True).rstrip()
1353 self
.assertRegex(output
, '2004:da8:1::/64')
1355 def test_ipv6_neighbor(self
):
1356 self
.copy_unit_to_networkd_unit_path('25-neighbor-section.network', '12-dummy.netdev')
1357 self
.start_networkd()
1359 self
.check_link_exists('dummy98')
1361 output
= subprocess
.check_output(['ip', 'neigh', 'list'], universal_newlines
=True).rstrip()
1363 self
.assertRegex(output
, '192.168.10.1.*00:00:5e:00:02:65.*PERMANENT')
1364 self
.assertRegex(output
, '2004:da8:1::1.*00:00:5e:00:02:66.*PERMANENT')
1366 def test_link_local_addressing(self
):
1367 self
.copy_unit_to_networkd_unit_path('25-link-local-addressing-yes.network', '11-dummy.netdev',
1368 '25-link-local-addressing-no.network', '12-dummy.netdev')
1369 self
.start_networkd(0)
1370 self
.wait_online(['test1:degraded', 'dummy98:carrier'])
1372 self
.check_link_exists('test1')
1373 self
.check_link_exists('dummy98')
1375 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'test1'], universal_newlines
=True).rstrip()
1377 self
.assertRegex(output
, 'inet .* scope link')
1378 self
.assertRegex(output
, 'inet6 .* scope link')
1380 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'dummy98'], universal_newlines
=True).rstrip()
1382 self
.assertNotRegex(output
, 'inet6* .* scope link')
1384 self
.check_operstate('test1', 'degraded')
1385 self
.check_operstate('dummy98', 'carrier')
1388 Documentation/networking/ip-sysctl.txt
1390 addr_gen_mode - INTEGER
1391 Defines how link-local and autoconf addresses are generated.
1393 0: generate address based on EUI64 (default)
1394 1: do no generate a link-local address, use EUI64 for addresses generated
1396 2: generate stable privacy addresses, using the secret from
1397 stable_secret (RFC7217)
1398 3: generate stable privacy addresses, using a random secret if unset
1401 test1_addr_gen_mode
= ''
1402 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'stable_secret')):
1403 with
open(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'stable_secret')) as f
:
1407 # if stable_secret is unset, then EIO is returned
1408 test1_addr_gen_mode
= '0'
1410 test1_addr_gen_mode
= '2'
1412 test1_addr_gen_mode
= '0'
1414 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'test1'), 'addr_gen_mode')):
1415 self
.assertEqual(self
.read_ipv6_sysctl_attr('test1', 'addr_gen_mode'), test1_addr_gen_mode
)
1417 if os
.path
.exists(os
.path
.join(os
.path
.join(network_sysctl_ipv6_path
, 'dummy98'), 'addr_gen_mode')):
1418 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'addr_gen_mode'), '1')
1420 def test_sysctl(self
):
1421 self
.copy_unit_to_networkd_unit_path('25-sysctl.network', '12-dummy.netdev')
1422 self
.start_networkd(0)
1423 self
.wait_online(['dummy98:degraded'])
1425 self
.check_link_exists('dummy98')
1427 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'forwarding'), '1')
1428 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'use_tempaddr'), '2')
1429 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'dad_transmits'), '3')
1430 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'hop_limit'), '5')
1431 self
.assertEqual(self
.read_ipv6_sysctl_attr('dummy98', 'proxy_ndp'), '1')
1432 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'forwarding'),'1')
1433 self
.assertEqual(self
.read_ipv4_sysctl_attr('dummy98', 'proxy_arp'), '1')
1435 def test_sysctl_disable_ipv6(self
):
1436 self
.copy_unit_to_networkd_unit_path('25-sysctl-disable-ipv6.network', '12-dummy.netdev')
1438 print('## Disable ipv6')
1439 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.all.disable_ipv6=1']), 0)
1440 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.default.disable_ipv6=1']), 0)
1442 self
.start_networkd(0)
1443 self
.wait_online(['dummy98:routable'])
1445 self
.check_link_exists('dummy98')
1447 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dummy98'], universal_newlines
=True).rstrip()
1449 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98')
1450 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dummy98'], universal_newlines
=True).rstrip()
1452 self
.assertEqual(output
, '')
1453 self
.check_operstate('dummy98', 'routable')
1455 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1457 print('## Enable ipv6')
1458 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.all.disable_ipv6=0']), 0)
1459 self
.assertEqual(subprocess
.call(['sysctl', 'net.ipv6.conf.default.disable_ipv6=0']), 0)
1461 self
.start_networkd(0)
1462 self
.wait_online(['dummy98:routable'])
1464 self
.check_link_exists('dummy98')
1466 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dummy98'], universal_newlines
=True).rstrip()
1468 self
.assertRegex(output
, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98')
1469 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dummy98'], universal_newlines
=True).rstrip()
1471 self
.assertRegex(output
, 'inet6 .* scope link')
1472 self
.check_operstate('dummy98', 'routable')
1474 def test_bind_carrier(self
):
1475 self
.copy_unit_to_networkd_unit_path('25-bind-carrier.network', '11-dummy.netdev')
1476 self
.start_networkd()
1478 self
.check_link_exists('test1')
1480 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1481 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1483 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1'], universal_newlines
=True).rstrip()
1485 self
.assertRegex(output
, 'UP,LOWER_UP')
1486 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1487 self
.check_operstate('test1', 'routable')
1489 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy99', 'type', 'dummy']), 0)
1490 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy99', 'up']), 0)
1492 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1'], universal_newlines
=True).rstrip()
1494 self
.assertRegex(output
, 'UP,LOWER_UP')
1495 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1496 self
.check_operstate('test1', 'routable')
1498 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1500 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1'], universal_newlines
=True).rstrip()
1502 self
.assertRegex(output
, 'UP,LOWER_UP')
1503 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1504 self
.check_operstate('test1', 'routable')
1506 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy99']), 0)
1508 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1'], universal_newlines
=True).rstrip()
1510 self
.assertNotRegex(output
, 'UP,LOWER_UP')
1511 self
.assertRegex(output
, 'DOWN')
1512 self
.assertNotRegex(output
, '192.168.10')
1513 self
.check_operstate('test1', 'off')
1515 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1516 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1518 output
= subprocess
.check_output(['ip', 'address', 'show', 'test1'], universal_newlines
=True).rstrip()
1520 self
.assertRegex(output
, 'UP,LOWER_UP')
1521 self
.assertRegex(output
, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
1522 self
.check_operstate('test1', 'routable')
1524 class NetworkdNetWorkBondTests(unittest
.TestCase
, Utilities
):
1534 '23-active-slave.network',
1535 '23-bond199.network',
1536 '23-primary-slave.network',
1537 '23-test1-bond199.network',
1538 '25-bond-active-backup-slave.netdev',
1541 'bond-slave.network']
1544 self
.link_remove(self
.links
)
1547 self
.link_remove(self
.links
)
1548 self
.remove_unit_from_networkd_path(self
.units
)
1550 def test_bond_active_slave(self
):
1551 self
.copy_unit_to_networkd_unit_path('23-active-slave.network', '23-bond199.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev')
1552 self
.start_networkd()
1554 self
.check_link_exists('dummy98')
1555 self
.check_link_exists('bond199')
1557 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199'], universal_newlines
=True).rstrip()
1559 self
.assertRegex(output
, 'active_slave dummy98')
1561 def test_bond_primary_slave(self
):
1562 self
.copy_unit_to_networkd_unit_path('23-primary-slave.network', '23-test1-bond199.network', '25-bond-active-backup-slave.netdev', '11-dummy.netdev')
1563 self
.start_networkd()
1565 self
.check_link_exists('test1')
1566 self
.check_link_exists('bond199')
1568 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond199'], universal_newlines
=True).rstrip()
1570 self
.assertRegex(output
, 'primary test1')
1572 def test_bond_operstate(self
):
1573 self
.copy_unit_to_networkd_unit_path('25-bond.netdev', '11-dummy.netdev', '12-dummy.netdev',
1574 'bond99.network','bond-slave.network')
1575 self
.start_networkd()
1577 self
.check_link_exists('bond99')
1578 self
.check_link_exists('dummy98')
1579 self
.check_link_exists('test1')
1581 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98'], universal_newlines
=True).rstrip()
1583 self
.assertRegex(output
, 'SLAVE,UP,LOWER_UP')
1585 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1'], universal_newlines
=True).rstrip()
1587 self
.assertRegex(output
, 'SLAVE,UP,LOWER_UP')
1589 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'bond99'], universal_newlines
=True).rstrip()
1591 self
.assertRegex(output
, 'MASTER,UP,LOWER_UP')
1593 self
.check_operstate('dummy98', 'enslaved')
1594 self
.check_operstate('test1', 'enslaved')
1595 self
.check_operstate('bond99', 'routable')
1597 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'down']), 0)
1600 self
.check_operstate('dummy98', 'off')
1601 self
.check_operstate('test1', 'enslaved')
1602 self
.check_operstate('bond99', 'degraded-carrier')
1604 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1607 self
.check_operstate('dummy98', 'enslaved')
1608 self
.check_operstate('test1', 'enslaved')
1609 self
.check_operstate('bond99', 'routable')
1611 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'down']), 0)
1612 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'test1', 'down']), 0)
1615 self
.check_operstate('dummy98', 'off')
1616 self
.check_operstate('test1', 'off')
1618 bond_has_no_carrier
=False
1619 for trial
in range(30):
1622 output
= subprocess
.check_output(['ip', 'address', 'show', 'bond99'], universal_newlines
=True).rstrip()
1624 if self
.get_operstate('bond99') == 'no-carrier':
1627 # Huh? Kernel does not recognize that all slave interfaces are down?
1628 # Let's confirm that networkd's operstate is consistent with ip's result.
1629 self
.assertNotRegex(output
, 'NO-CARRIER')
1631 class NetworkdNetWorkBridgeTests(unittest
.TestCase
, Utilities
):
1641 '26-bridge-slave-interface-1.network',
1642 '26-bridge-slave-interface-2.network',
1643 'bridge99-ignore-carrier-loss.network',
1647 self
.link_remove(self
.links
)
1650 self
.link_remove(self
.links
)
1651 self
.remove_unit_from_networkd_path(self
.units
)
1653 def test_bridge_property(self
):
1654 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
1655 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
1657 self
.start_networkd()
1659 self
.check_link_exists('dummy98')
1660 self
.check_link_exists('test1')
1661 self
.check_link_exists('bridge99')
1663 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'test1'], universal_newlines
=True).rstrip()
1665 self
.assertRegex(output
, 'master')
1666 self
.assertRegex(output
, 'bridge')
1668 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dummy98'], universal_newlines
=True).rstrip()
1670 self
.assertRegex(output
, 'master')
1671 self
.assertRegex(output
, 'bridge')
1673 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99'], universal_newlines
=True).rstrip()
1675 self
.assertRegex(output
, '192.168.0.15/24')
1677 output
= subprocess
.check_output(['bridge', '-d', 'link', 'show', 'dummy98'], universal_newlines
=True).rstrip()
1679 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'hairpin_mode'), '1')
1680 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'path_cost'), '400')
1681 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'unicast_flood'), '1')
1682 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_flood'), '0')
1683 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_fast_leave'), '1')
1684 if (os
.path
.exists('/sys/devices/virtual/net/bridge99/lower_dummy98/brport/neigh_suppress')):
1685 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'neigh_suppress'), '1')
1686 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'learning'), '0')
1688 # CONFIG_BRIDGE_IGMP_SNOOPING=y
1689 if (os
.path
.exists('/sys/devices/virtual/net/bridge00/lower_dummy98/brport/multicast_to_unicast')):
1690 self
.assertEqual(self
.read_bridge_port_attr('bridge99', 'dummy98', 'multicast_to_unicast'), '1')
1692 self
.check_operstate('test1', 'enslaved')
1693 self
.check_operstate('dummy98', 'enslaved')
1694 self
.check_operstate('bridge99', 'routable')
1696 self
.assertEqual(subprocess
.call(['ip', 'address', 'add', '192.168.0.16/24', 'dev', 'bridge99']), 0)
1699 output
= subprocess
.check_output(['ip', 'addr', 'show', 'bridge99'], universal_newlines
=True).rstrip()
1701 self
.assertRegex(output
, '192.168.0.16/24')
1703 self
.check_operstate('bridge99', 'routable')
1705 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'test1']), 0)
1708 self
.check_operstate('bridge99', 'degraded-carrier')
1710 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1713 self
.check_operstate('bridge99', 'no-carrier')
1715 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99'], universal_newlines
=True).rstrip()
1717 self
.assertRegex(output
, 'NO-CARRIER')
1718 self
.assertNotRegex(output
, '192.168.0.15/24')
1719 self
.assertNotRegex(output
, '192.168.0.16/24')
1721 def test_bridge_ignore_carrier_loss(self
):
1722 self
.copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
1723 '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
1724 'bridge99-ignore-carrier-loss.network')
1726 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1728 self
.start_networkd()
1730 self
.check_link_exists('dummy98')
1731 self
.check_link_exists('test1')
1732 self
.check_link_exists('bridge99')
1734 self
.assertEqual(subprocess
.call(['ip', 'address', 'add', '192.168.0.16/24', 'dev', 'bridge99']), 0)
1737 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'test1']), 0)
1738 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1741 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99'], universal_newlines
=True).rstrip()
1743 self
.assertRegex(output
, 'NO-CARRIER')
1744 self
.assertRegex(output
, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99')
1745 self
.assertRegex(output
, 'inet 192.168.0.16/24 scope global secondary bridge99')
1747 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1749 def test_bridge_ignore_carrier_loss_frequent_loss_and_gain(self
):
1750 self
.copy_unit_to_networkd_unit_path('26-bridge.netdev', '26-bridge-slave-interface-1.network',
1751 'bridge99-ignore-carrier-loss.network')
1753 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1755 self
.start_networkd()
1757 self
.check_link_exists('bridge99')
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)
1765 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1767 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1768 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1769 self
.assertEqual(subprocess
.call(['ip', 'link', 'del', 'dummy98']), 0)
1771 self
.assertEqual(subprocess
.call(['ip', 'link', 'add', 'dummy98', 'type', 'dummy']), 0)
1772 self
.assertEqual(subprocess
.call(['ip', 'link', 'set', 'dummy98', 'up']), 0)
1776 output
= subprocess
.check_output(['ip', 'address', 'show', 'bridge99'], universal_newlines
=True).rstrip()
1778 self
.assertRegex(output
, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99')
1780 self
.check_operstate('bridge99', 'routable')
1781 self
.check_operstate('dummy98', 'enslaved')
1783 output
= subprocess
.check_output(['ip', 'rule', 'list', 'table', '100'], universal_newlines
=True).rstrip()
1785 self
.assertEqual(output
, '0: from all to 8.8.8.8 lookup 100')
1787 subprocess
.call(['ip', 'rule', 'del', 'table', '100'])
1789 class NetworkdNetWorkLLDPTests(unittest
.TestCase
, Utilities
):
1793 '23-emit-lldp.network',
1798 self
.link_remove(self
.links
)
1801 self
.link_remove(self
.links
)
1802 self
.remove_unit_from_networkd_path(self
.units
)
1804 def test_lldp(self
):
1805 self
.copy_unit_to_networkd_unit_path('23-emit-lldp.network', '24-lldp.network', '25-veth.netdev')
1806 self
.start_networkd()
1808 self
.check_link_exists('veth99')
1810 output
= subprocess
.check_output(['networkctl', 'lldp'], universal_newlines
=True).rstrip()
1812 self
.assertRegex(output
, 'veth-peer')
1813 self
.assertRegex(output
, 'veth99')
1815 class NetworkdNetworkRATests(unittest
.TestCase
, Utilities
):
1820 'ipv6-prefix.network',
1821 'ipv6-prefix-veth.network']
1824 self
.link_remove(self
.links
)
1827 self
.link_remove(self
.links
)
1828 self
.remove_unit_from_networkd_path(self
.units
)
1830 def test_ipv6_prefix_delegation(self
):
1831 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth.network')
1832 self
.start_networkd()
1834 self
.check_link_exists('veth99')
1836 output
= subprocess
.check_output(['networkctl', 'status', 'veth99'], universal_newlines
=True).rstrip()
1838 self
.assertRegex(output
, '2002:da8:1:0')
1840 class NetworkdNetworkDHCPServerTests(unittest
.TestCase
, Utilities
):
1847 '24-search-domain.network',
1849 'dhcp-client.network',
1850 'dhcp-client-timezone-router.network',
1851 'dhcp-server.network',
1852 'dhcp-server-timezone-router.network']
1855 self
.link_remove(self
.links
)
1858 self
.link_remove(self
.links
)
1859 self
.remove_unit_from_networkd_path(self
.units
)
1861 def test_dhcp_server(self
):
1862 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client.network', 'dhcp-server.network')
1863 self
.start_networkd()
1865 self
.check_link_exists('veth99')
1867 output
= subprocess
.check_output(['networkctl', 'status', 'veth99'], universal_newlines
=True).rstrip()
1869 self
.assertRegex(output
, '192.168.5.*')
1870 self
.assertRegex(output
, 'Gateway: 192.168.5.1')
1871 self
.assertRegex(output
, 'DNS: 192.168.5.1')
1872 self
.assertRegex(output
, 'NTP: 192.168.5.1')
1874 def test_domain(self
):
1875 self
.copy_unit_to_networkd_unit_path('12-dummy.netdev', '24-search-domain.network')
1876 self
.start_networkd()
1878 self
.check_link_exists('dummy98')
1880 output
= subprocess
.check_output(['networkctl', 'status', 'dummy98'], universal_newlines
=True).rstrip()
1882 self
.assertRegex(output
, 'Address: 192.168.42.100')
1883 self
.assertRegex(output
, 'DNS: 192.168.42.1')
1884 self
.assertRegex(output
, 'Search Domains: one')
1886 def test_emit_router_timezone(self
):
1887 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client-timezone-router.network', 'dhcp-server-timezone-router.network')
1888 self
.start_networkd()
1890 self
.check_link_exists('veth99')
1892 output
= subprocess
.check_output(['networkctl', 'status', 'veth99'], universal_newlines
=True).rstrip()
1894 self
.assertRegex(output
, 'Gateway: 192.168.5.*')
1895 self
.assertRegex(output
, '192.168.5.*')
1896 self
.assertRegex(output
, 'Europe/Berlin')
1898 class NetworkdNetworkDHCPClientTests(unittest
.TestCase
, Utilities
):
1908 'dhcp-client-anonymize.network',
1909 'dhcp-client-critical-connection.network',
1910 'dhcp-client-gateway-onlink-implicit.network',
1911 'dhcp-client-ipv4-dhcp-settings.network',
1912 'dhcp-client-ipv4-only-ipv6-disabled.network',
1913 'dhcp-client-ipv4-only.network',
1914 'dhcp-client-ipv6-only.network',
1915 'dhcp-client-ipv6-rapid-commit.network',
1916 'dhcp-client-listen-port.network',
1917 'dhcp-client-route-metric.network',
1918 'dhcp-client-route-table.network',
1919 'dhcp-client-vrf.network',
1920 'dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network',
1921 'dhcp-client-with-ipv4ll-fallback-without-dhcp-server.network',
1922 'dhcp-client.network',
1923 'dhcp-server-veth-peer.network',
1924 'dhcp-v4-server-veth-peer.network',
1928 self
.link_remove(self
.links
)
1929 self
.stop_dnsmasq(dnsmasq_pid_file
)
1932 self
.link_remove(self
.links
)
1933 self
.remove_unit_from_networkd_path(self
.units
)
1934 self
.stop_dnsmasq(dnsmasq_pid_file
)
1935 self
.remove_lease_file()
1936 self
.remove_log_file()
1938 def test_dhcp_client_ipv6_only(self
):
1939 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
1941 self
.start_networkd(0)
1942 self
.wait_online(['veth-peer:carrier'])
1943 self
.start_dnsmasq()
1944 self
.wait_online(['veth99:routable', 'veth-peer:routable'])
1946 output
= subprocess
.check_output(['networkctl', 'status', 'veth99'], universal_newlines
=True).rstrip()
1948 self
.assertRegex(output
, '2600::')
1949 self
.assertNotRegex(output
, '192.168.5')
1951 # Confirm that ipv6 token is not set in the kernel
1952 output
= subprocess
.check_output(['ip', 'token', 'show', 'dev', 'veth99'], universal_newlines
=True).rstrip()
1954 self
.assertRegex(output
, 'token :: dev veth99')
1956 def test_dhcp_client_ipv4_only(self
):
1957 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-only-ipv6-disabled.network')
1958 self
.start_networkd()
1960 self
.check_link_exists('veth99')
1962 self
.start_dnsmasq()
1964 output
= subprocess
.check_output(['networkctl', 'status', 'veth99'], universal_newlines
=True).rstrip()
1966 self
.assertNotRegex(output
, '2600::')
1967 self
.assertRegex(output
, '192.168.5')
1969 def test_dhcp_client_ipv4_ipv6(self
):
1970 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network',
1971 'dhcp-client-ipv4-only.network')
1972 self
.start_networkd()
1974 self
.check_link_exists('veth99')
1976 self
.start_dnsmasq()
1978 output
= subprocess
.check_output(['networkctl', 'status', 'veth99'], universal_newlines
=True).rstrip()
1980 self
.assertRegex(output
, '2600::')
1981 self
.assertRegex(output
, '192.168.5')
1983 def test_dhcp_client_settings(self
):
1984 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-dhcp-settings.network')
1985 self
.start_networkd()
1987 self
.check_link_exists('veth99')
1989 self
.start_dnsmasq()
1991 print('## ip address show dev veth99')
1992 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99'], universal_newlines
=True).rstrip()
1994 self
.assertRegex(output
, '12:34:56:78:9a:bc')
1995 self
.assertRegex(output
, '192.168.5')
1996 self
.assertRegex(output
, '1492')
1999 print('## ip route show table main dev veth99')
2000 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', 'main', 'dev', 'veth99'], universal_newlines
=True).rstrip()
2002 self
.assertNotRegex(output
, 'proto dhcp')
2004 print('## ip route show table 211 dev veth99')
2005 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '211', 'dev', 'veth99'], universal_newlines
=True).rstrip()
2007 self
.assertRegex(output
, 'default via 192.168.5.1 proto dhcp')
2008 self
.assertRegex(output
, '192.168.5.0/24 via 192.168.5.5 proto dhcp')
2009 self
.assertRegex(output
, '192.168.5.1 proto dhcp scope link')
2011 print('## dnsmasq log')
2012 self
.assertTrue(self
.search_words_in_dnsmasq_log('vendor class: SusantVendorTest', True))
2013 self
.assertTrue(self
.search_words_in_dnsmasq_log('DHCPDISCOVER(veth-peer) 12:34:56:78:9a:bc'))
2014 self
.assertTrue(self
.search_words_in_dnsmasq_log('client provides name: test-hostname'))
2015 self
.assertTrue(self
.search_words_in_dnsmasq_log('26:mtu'))
2017 def test_dhcp6_client_settings_rapidcommit_true(self
):
2018 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
2019 self
.start_networkd()
2021 self
.check_link_exists('veth99')
2023 self
.start_dnsmasq()
2025 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99'], universal_newlines
=True).rstrip()
2027 self
.assertRegex(output
, '12:34:56:78:9a:bc')
2028 self
.assertTrue(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
2030 def test_dhcp6_client_settings_rapidcommit_false(self
):
2031 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-rapid-commit.network')
2032 self
.start_networkd()
2034 self
.check_link_exists('veth99')
2036 self
.start_dnsmasq()
2038 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99'], universal_newlines
=True).rstrip()
2040 self
.assertRegex(output
, '12:34:56:78:9a:bc')
2041 self
.assertFalse(self
.search_words_in_dnsmasq_log('14:rapid-commit', True))
2043 def test_dhcp_client_settings_anonymize(self
):
2044 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-anonymize.network')
2045 self
.start_networkd()
2047 self
.check_link_exists('veth99')
2049 self
.start_dnsmasq()
2051 self
.assertFalse(self
.search_words_in_dnsmasq_log('VendorClassIdentifier=SusantVendorTest', True))
2052 self
.assertFalse(self
.search_words_in_dnsmasq_log('test-hostname'))
2053 self
.assertFalse(self
.search_words_in_dnsmasq_log('26:mtu'))
2055 def test_dhcp_client_listen_port(self
):
2056 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-listen-port.network')
2057 self
.start_networkd()
2059 self
.check_link_exists('veth99')
2061 self
.start_dnsmasq('--dhcp-alternate-port=67,5555')
2063 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99'], universal_newlines
=True).rstrip()
2065 self
.assertRegex(output
, '192.168.5.* dynamic')
2067 def test_dhcp_route_table_id(self
):
2068 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-table.network')
2069 self
.start_networkd()
2071 self
.check_link_exists('veth99')
2073 self
.start_dnsmasq()
2075 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', '12'], universal_newlines
=True).rstrip()
2077 self
.assertRegex(output
, 'veth99 proto dhcp')
2078 self
.assertRegex(output
, '192.168.5.1')
2080 def test_dhcp_route_metric(self
):
2081 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-metric.network')
2082 self
.start_networkd()
2084 self
.check_link_exists('veth99')
2086 self
.start_dnsmasq()
2088 output
= subprocess
.check_output(['ip', 'route', 'show', 'dev', 'veth99'], universal_newlines
=True).rstrip()
2090 self
.assertRegex(output
, 'metric 24')
2092 def test_dhcp_route_criticalconnection_true(self
):
2093 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-critical-connection.network')
2094 self
.start_networkd()
2096 self
.check_link_exists('veth99')
2098 self
.start_dnsmasq()
2100 output
= subprocess
.check_output(['networkctl', 'status', 'veth99'], universal_newlines
=True).rstrip()
2102 self
.assertRegex(output
, '192.168.5.*')
2104 # Stopping dnsmasq as networkd won't be allowed to renew the DHCP lease.
2105 self
.stop_dnsmasq(dnsmasq_pid_file
)
2107 # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
2110 output
= subprocess
.check_output(['networkctl', 'status', 'veth99'], universal_newlines
=True).rstrip()
2112 self
.assertRegex(output
, '192.168.5.*')
2114 def test_dhcp_client_reuse_address_as_static(self
):
2115 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client.network')
2116 self
.start_networkd()
2118 self
.check_link_exists('veth99')
2120 self
.start_dnsmasq()
2122 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99', 'scope', 'global'], universal_newlines
=True).rstrip()
2124 self
.assertRegex(output
, '192.168.5')
2125 self
.assertRegex(output
, '2600::')
2127 ipv4_address
= re
.search('192\.168\.5\.[0-9]*/24', output
)
2128 ipv6_address
= re
.search('2600::[0-9a-f:]*/128', output
)
2129 static_network
= '\n'.join(['[Match]', 'Name=veth99', '[Network]', 'IPv6AcceptRA=no', 'Address=' + ipv4_address
.group(), 'Address=' + ipv6_address
.group()])
2130 print(static_network
)
2132 self
.remove_unit_from_networkd_path(['dhcp-client.network'])
2134 with
open(os
.path
.join(network_unit_file_path
, 'static.network'), mode
='w') as f
:
2135 f
.write(static_network
)
2137 self
.start_networkd()
2139 self
.check_link_exists('veth99')
2141 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global'], universal_newlines
=True).rstrip()
2143 self
.assertRegex(output
, '192.168.5')
2144 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
2146 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global'], universal_newlines
=True).rstrip()
2148 self
.assertRegex(output
, '2600::')
2149 self
.assertRegex(output
, 'valid_lft forever preferred_lft forever')
2151 @expectedFailureIfModuleIsNotAvailable('vrf')
2152 def test_dhcp_client_vrf(self
):
2153 self
.copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-vrf.network',
2154 '25-vrf.netdev', '25-vrf.network')
2155 self
.start_networkd()
2157 self
.check_link_exists('veth99')
2158 self
.check_link_exists('vrf99')
2160 self
.start_dnsmasq()
2162 print('## ip -d link show dev vrf99')
2163 output
= subprocess
.check_output(['ip', '-d', 'link', 'show', 'dev', 'vrf99'], universal_newlines
=True).rstrip()
2165 self
.assertRegex(output
, 'vrf table 42')
2167 print('## ip address show vrf vrf99')
2168 output_ip_vrf
= subprocess
.check_output(['ip', 'address', 'show', 'vrf', 'vrf99'], universal_newlines
=True).rstrip()
2169 print(output_ip_vrf
)
2171 print('## ip address show dev veth99')
2172 output
= subprocess
.check_output(['ip', 'address', 'show', 'dev', 'veth99'], universal_newlines
=True).rstrip()
2174 self
.assertEqual(output
, output_ip_vrf
)
2175 self
.assertRegex(output
, 'inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99')
2176 self
.assertRegex(output
, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
2177 self
.assertRegex(output
, 'inet6 2600::[0-9a-f]*/128 scope global dynamic noprefixroute')
2178 self
.assertRegex(output
, 'inet6 .* scope link')
2180 print('## ip route show vrf vrf99')
2181 output
= subprocess
.check_output(['ip', 'route', 'show', 'vrf', 'vrf99'], universal_newlines
=True).rstrip()
2183 self
.assertRegex(output
, 'default via 192.168.5.1 dev veth99 proto dhcp src 192.168.5.')
2184 self
.assertRegex(output
, 'default dev veth99 proto static scope link')
2185 self
.assertRegex(output
, '169.254.0.0/16 dev veth99 proto kernel scope link src 169.254')
2186 self
.assertRegex(output
, '192.168.5.0/24 dev veth99 proto kernel scope link src 192.168.5')
2187 self
.assertRegex(output
, '192.168.5.0/24 via 192.168.5.5 dev veth99 proto dhcp')
2188 self
.assertRegex(output
, '192.168.5.1 dev veth99 proto dhcp scope link src 192.168.5')
2190 print('## ip route show table main dev veth99')
2191 output
= subprocess
.check_output(['ip', 'route', 'show', 'table', 'main', 'dev', 'veth99'], universal_newlines
=True).rstrip()
2193 self
.assertEqual(output
, '')
2195 self
.check_operstate('vrf99', 'carrier')
2196 self
.check_operstate('veth99', 'routable')
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
.check_link_exists('veth99')
2205 self
.start_dnsmasq()
2207 output
= subprocess
.check_output(['networkctl', 'status', 'veth99'], universal_newlines
=True).rstrip()
2209 self
.assertRegex(output
, '192.168.5')
2211 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'veth99', '10.0.0.0/8'], universal_newlines
=True).rstrip()
2213 self
.assertRegex(output
, 'onlink')
2214 output
= subprocess
.check_output(['ip', 'route', 'list', 'dev', 'veth99', '192.168.100.0/24'], universal_newlines
=True).rstrip()
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'], universal_newlines
=True).rstrip()
2229 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic'], universal_newlines
=True).rstrip()
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'], universal_newlines
=True).rstrip()
2232 self
.assertRegex(output
, 'inet6 .* scope link')
2233 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic'], universal_newlines
=True).rstrip()
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'], universal_newlines
=True).rstrip()
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'], universal_newlines
=True).rstrip()
2244 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic'], universal_newlines
=True).rstrip()
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'], universal_newlines
=True).rstrip()
2247 self
.assertRegex(output
, 'inet6 .* scope link')
2248 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic'], universal_newlines
=True).rstrip()
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'], universal_newlines
=True).rstrip()
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'], universal_newlines
=True).rstrip()
2264 output
= subprocess
.check_output(['ip', '-6', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic'], universal_newlines
=True).rstrip()
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'], universal_newlines
=True).rstrip()
2267 self
.assertRegex(output
, 'inet6 .* scope link')
2268 output
= subprocess
.check_output(['ip', '-4', 'address', 'show', 'dev', 'veth99', 'scope', 'global', 'dynamic'], universal_newlines
=True).rstrip()
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'], universal_newlines
=True).rstrip()
2271 self
.assertRegex(output
, 'inet .* scope link')
2273 if __name__
== '__main__':
2274 unittest
.main(testRunner
=unittest
.TextTestRunner(stream
=sys
.stdout
,