]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - test/test-network/systemd-networkd-tests.py
test-network: add test for AssignToLoopback= setting
[thirdparty/systemd.git] / test / test-network / systemd-networkd-tests.py
index f22fdbe5af754921764db1c1fd560506ad6b386d..fc159271bf670768eb6c205883e57dd53ff1858c 100755 (executable)
@@ -26,7 +26,7 @@ networkd_bin='/usr/lib/systemd/systemd-networkd'
 wait_online_bin='/usr/lib/systemd/systemd-networkd-wait-online'
 networkctl_bin='/usr/bin/networkctl'
 use_valgrind=False
-enable_debug=False
+enable_debug=True
 env = {}
 asan_options=None
 lsan_options=None
@@ -91,6 +91,23 @@ def expectedFailureIfRoutingPolicyIPProtoIsNotAvailable():
 
     return f
 
+def expectedFailureIfLinkFileFieldIsNotSet():
+    def f(func):
+        support = False
+        rc = call('ip link add name dummy99 type dummy')
+        if rc == 0:
+            ret = run('udevadm info -w10s /sys/class/net/dummy99', stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+            if ret.returncode == 0 and 'E: ID_NET_LINK_FILE=' in ret.stdout.rstrip():
+                support = True
+            call('ip link del dummy99')
+
+        if support:
+            return func
+        else:
+            return unittest.expectedFailure(func)
+
+    return f
+
 def expectedFailureIfEthtoolDoesNotSupportDriver():
     def f(func):
         support = False
@@ -184,17 +201,19 @@ def remove_links(links):
 
 def remove_fou_ports(ports):
     for port in ports:
-        call('ip fou del port', port)
+        call('ip fou del port', port, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
 
 def remove_routing_policy_rule_tables(tables):
     for table in tables:
-        call('ip rule del table', table)
+        rc = 0
+        while rc == 0:
+            rc = call('ip rule del table', table, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
 
 def remove_routes(routes):
     for route_type, addr in routes:
-        call('ip route del', route_type, addr)
+        call('ip route del', route_type, addr, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
 
-def l2tp_tunnel_remove(tunnel_ids):
+def remove_l2tp_tunnels(tunnel_ids):
     output = check_output('ip l2tp show tunnel')
     for tid in tunnel_ids:
         words='Tunnel ' + tid + ', encap'
@@ -263,17 +282,28 @@ def remove_log_file():
     if os.path.exists(dnsmasq_log_file):
         os.remove(dnsmasq_log_file)
 
-def start_networkd(sleep_sec=5, remove_state_files=True):
-    if (remove_state_files and
-        os.path.exists(os.path.join(networkd_runtime_directory, 'state'))):
-        check_output('systemctl stop systemd-networkd')
+def remove_networkd_state_files():
+    if os.path.exists(os.path.join(networkd_runtime_directory, 'state')):
         os.remove(os.path.join(networkd_runtime_directory, 'state'))
-        check_output('systemctl start systemd-networkd')
-    else:
-        check_output('systemctl restart systemd-networkd')
+
+def stop_networkd(show_logs=True, remove_state_files=True):
+    if show_logs:
+        invocation_id = check_output('systemctl show systemd-networkd -p InvocationID --value')
+    check_output('systemctl stop systemd-networkd')
+    if show_logs:
+        print(check_output('journalctl _SYSTEMD_INVOCATION_ID=' + invocation_id))
+    if remove_state_files:
+        remove_networkd_state_files()
+
+def start_networkd(sleep_sec=0):
+    check_output('systemctl start systemd-networkd')
     if sleep_sec > 0:
         time.sleep(sleep_sec)
 
+def restart_networkd(sleep_sec=0, show_logs=True, remove_state_files=True):
+    stop_networkd(show_logs, remove_state_files)
+    start_networkd(sleep_sec)
+
 def wait_online(links_with_operstate, timeout='20s', bool_any=False):
     args = wait_online_cmd + [f'--timeout={timeout}'] + [f'--interface={link}' for link in links_with_operstate]
     if bool_any:
@@ -329,14 +359,16 @@ class NetworkctlTests(unittest.TestCase, Utilities):
 
     def setUp(self):
         remove_links(self.links)
+        stop_networkd(show_logs=False)
 
     def tearDown(self):
         remove_links(self.links)
         remove_unit_from_networkd_path(self.units)
+        stop_networkd(show_logs=True)
 
     def test_glob(self):
         copy_unit_to_networkd_unit_path('11-dummy.netdev', '11-dummy.network')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['test1:degraded'])
 
@@ -362,18 +394,47 @@ class NetworkctlTests(unittest.TestCase, Utilities):
 
     def test_mtu(self):
         copy_unit_to_networkd_unit_path('11-dummy-mtu.netdev', '11-dummy.network')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['test1:degraded'])
 
         output = check_output(*networkctl_cmd, 'status', 'test1', env=env)
         self.assertRegex(output, 'MTU: 1600')
 
+    def test_type(self):
+        copy_unit_to_networkd_unit_path('11-dummy.netdev', '11-dummy.network')
+        start_networkd()
+        wait_online(['test1:degraded'])
+
+        output = check_output(*networkctl_cmd, 'status', 'test1')
+        print(output)
+        self.assertRegex(output, 'Type: ether')
+
+        output = check_output(*networkctl_cmd, 'status', 'lo')
+        print(output)
+        self.assertRegex(output, 'Type: loopback')
+
+    @expectedFailureIfLinkFileFieldIsNotSet()
+    def test_udev_link_file(self):
+        copy_unit_to_networkd_unit_path('11-dummy.netdev', '11-dummy.network')
+        start_networkd()
+        wait_online(['test1:degraded'])
+
+        output = check_output(*networkctl_cmd, 'status', 'test1')
+        print(output)
+        self.assertRegex(output, r'Link File: (?:/usr)/lib/systemd/network/99-default.link')
+        self.assertRegex(output, r'Network File: /run/systemd/network/11-dummy.network')
+
+        output = check_output(*networkctl_cmd, 'status', 'lo')
+        print(output)
+        self.assertRegex(output, r'Link File: (?:/usr)/lib/systemd/network/99-default.link')
+        self.assertRegex(output, r'Network File: n/a')
+
     @expectedFailureIfEthtoolDoesNotSupportDriver()
     def test_udev_driver(self):
         copy_unit_to_networkd_unit_path('11-dummy.netdev', '11-dummy.network',
                                         '25-veth.netdev', 'netdev-link-local-addressing-yes.network')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['test1:degraded', 'veth99:degraded', 'veth-peer:degraded'])
 
@@ -389,7 +450,7 @@ class NetworkctlTests(unittest.TestCase, Utilities):
     def test_delete_links(self):
         copy_unit_to_networkd_unit_path('11-dummy.netdev', '11-dummy.network',
                                         '25-veth.netdev', 'netdev-link-local-addressing-yes.network')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['test1:degraded', 'veth99:degraded', 'veth-peer:degraded'])
 
@@ -461,6 +522,8 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
         '11-dummy.netdev',
         '11-dummy.network',
         '12-dummy.netdev',
+        '13-not-match-udev-property.network',
+        '14-match-udev-property.network',
         '15-name-conflict-test.netdev',
         '21-macvlan.netdev',
         '21-macvtap.netdev',
@@ -471,6 +534,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
         '25-bond.netdev',
         '25-bond-balanced-tlb.netdev',
         '25-bridge.netdev',
+        '25-bridge-configure-without-carrier.network',
         '25-bridge.network',
         '25-erspan-tunnel-local-any.netdev',
         '25-erspan-tunnel.netdev',
@@ -495,6 +559,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
         '25-ip6tnl-tunnel-local-any.netdev',
         '25-ip6tnl-tunnel.netdev',
         '25-ipip-tunnel-independent.netdev',
+        '25-ipip-tunnel-independent-loopback.netdev',
         '25-ipip-tunnel-local-any.netdev',
         '25-ipip-tunnel-remote-any.netdev',
         '25-ipip-tunnel.netdev',
@@ -559,15 +624,17 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
     def setUp(self):
         remove_fou_ports(self.fou_ports)
         remove_links(self.links)
+        stop_networkd(show_logs=False)
 
     def tearDown(self):
         remove_fou_ports(self.fou_ports)
         remove_links(self.links)
         remove_unit_from_networkd_path(self.units)
+        stop_networkd(show_logs=True)
 
     def test_dropin_and_name_conflict(self):
         copy_unit_to_networkd_unit_path('10-dropin-test.netdev', '15-name-conflict-test.netdev')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['dropin-test:off'])
 
@@ -575,9 +642,18 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
         print(output)
         self.assertRegex(output, '00:50:56:c0:00:28')
 
+    def test_match_udev_property(self):
+        copy_unit_to_networkd_unit_path('12-dummy.netdev', '13-not-match-udev-property.network', '14-match-udev-property.network')
+        start_networkd()
+        wait_online(['dummy98:routable'])
+
+        output = check_output('networkctl status dummy98')
+        print(output)
+        self.assertRegex(output, 'Network File: /run/systemd/network/14-match-udev-property')
+
     def test_wait_online_any(self):
         copy_unit_to_networkd_unit_path('25-bridge.netdev', '25-bridge.network', '11-dummy.netdev', '11-dummy.network')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['bridge99', 'test1:degraded'], bool_any=True)
 
@@ -585,10 +661,10 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
         self.check_operstate('test1', 'degraded')
 
     def test_bridge(self):
-        copy_unit_to_networkd_unit_path('25-bridge.netdev')
-        start_networkd(0)
+        copy_unit_to_networkd_unit_path('25-bridge.netdev', '25-bridge-configure-without-carrier.network')
+        start_networkd()
 
-        wait_online(['bridge99:off'])
+        wait_online(['bridge99:no-carrier'])
 
         tick = os.sysconf('SC_CLK_TCK')
         self.assertEqual(9, round(float(read_link_attr('bridge99', 'bridge', 'hello_time')) / tick))
@@ -602,7 +678,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
 
     def test_bond(self):
         copy_unit_to_networkd_unit_path('25-bond.netdev', '25-bond-balanced-tlb.netdev')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['bond99:off', 'bond98:off'])
 
@@ -624,7 +700,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
     def test_vlan(self):
         copy_unit_to_networkd_unit_path('21-vlan.netdev', '11-dummy.netdev',
                                         '21-vlan.network', '21-vlan-test1.network')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['test1:degraded', 'vlan99:routable'])
 
@@ -659,7 +735,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
                                                 '11-dummy.netdev', 'macvtap.network')
                 with open(os.path.join(network_unit_file_path, '21-macvtap.netdev'), mode='a') as f:
                     f.write('[MACVTAP]\nMode=' + mode)
-                start_networkd(0)
+                start_networkd()
 
                 wait_online(['macvtap99:degraded', 'test1:degraded'])
 
@@ -676,7 +752,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
                                                 '11-dummy.netdev', 'macvlan.network')
                 with open(os.path.join(network_unit_file_path, '21-macvlan.netdev'), mode='a') as f:
                     f.write('[MACVLAN]\nMode=' + mode)
-                start_networkd(0)
+                start_networkd()
 
                 wait_online(['macvlan99:degraded', 'test1:degraded'])
 
@@ -700,7 +776,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
                 with open(os.path.join(network_unit_file_path, '25-ipvlan.netdev'), mode='a') as f:
                     f.write('[IPVLAN]\nMode=' + mode + '\nFlags=' + flag)
 
-                start_networkd(0)
+                start_networkd()
                 wait_online(['ipvlan99:degraded', 'test1:degraded'])
 
                 output = check_output('ip -d link show ipvlan99')
@@ -718,7 +794,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
                 with open(os.path.join(network_unit_file_path, '25-ipvtap.netdev'), mode='a') as f:
                     f.write('[IPVTAP]\nMode=' + mode + '\nFlags=' + flag)
 
-                start_networkd(0)
+                start_networkd()
                 wait_online(['ipvtap99:degraded', 'test1:degraded'])
 
                 output = check_output('ip -d link show ipvtap99')
@@ -727,7 +803,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
 
     def test_veth(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'netdev-link-local-addressing-yes.network')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['veth99:degraded', 'veth-peer:degraded'])
 
@@ -740,7 +816,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
 
     def test_tun(self):
         copy_unit_to_networkd_unit_path('25-tun.netdev')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['tun99:off'])
 
@@ -751,7 +827,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
 
     def test_tap(self):
         copy_unit_to_networkd_unit_path('25-tap.netdev')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['tap99:off'])
 
@@ -763,21 +839,21 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
     @expectedFailureIfModuleIsNotAvailable('vrf')
     def test_vrf(self):
         copy_unit_to_networkd_unit_path('25-vrf.netdev', 'netdev-link-local-addressing-yes.network')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['vrf99:carrier'])
 
     @expectedFailureIfModuleIsNotAvailable('vcan')
     def test_vcan(self):
         copy_unit_to_networkd_unit_path('25-vcan.netdev', 'netdev-link-local-addressing-yes.network')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['vcan99:carrier'])
 
     @expectedFailureIfModuleIsNotAvailable('vxcan')
     def test_vxcan(self):
         copy_unit_to_networkd_unit_path('25-vxcan.netdev', 'netdev-link-local-addressing-yes.network')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['vxcan99:carrier', 'vxcan-peer:carrier'])
 
@@ -786,7 +862,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
         copy_unit_to_networkd_unit_path('25-wireguard.netdev', '25-wireguard.network',
                                         '25-wireguard-23-peers.netdev', '25-wireguard-23-peers.network',
                                         '25-wireguard-preshared-key.txt', '25-wireguard-private-key.txt')
-        start_networkd(0)
+        start_networkd()
         wait_online(['wg99:carrier', 'wg98:routable'])
 
         if shutil.which('wg'):
@@ -814,7 +890,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
 
     def test_geneve(self):
         copy_unit_to_networkd_unit_path('25-geneve.netdev', 'netdev-link-local-addressing-yes.network')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['geneve99:degraded'])
 
@@ -830,7 +906,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
                                         '25-ipip-tunnel.netdev', '25-tunnel.network',
                                         '25-ipip-tunnel-local-any.netdev', '25-tunnel-local-any.network',
                                         '25-ipip-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['ipiptun99:routable', 'ipiptun98:routable', 'ipiptun97:routable', 'dummy98:degraded'])
 
         output = check_output('ip -d link show ipiptun99')
@@ -848,7 +924,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
                                         '25-gre-tunnel.netdev', '25-tunnel.network',
                                         '25-gre-tunnel-local-any.netdev', '25-tunnel-local-any.network',
                                         '25-gre-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['gretun99:routable', 'gretun98:routable', 'gretun97:routable', 'dummy98:degraded'])
 
         output = check_output('ip -d link show gretun99')
@@ -878,7 +954,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
                                         '25-ip6gre-tunnel.netdev', '25-tunnel.network',
                                         '25-ip6gre-tunnel-local-any.netdev', '25-tunnel-local-any.network',
                                         '25-ip6gre-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
-        start_networkd()
+        start_networkd(5)
 
         # Old kernels seem not to support IPv6LL address on ip6gre tunnel, So please do not use wait_online() here.
 
@@ -901,7 +977,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
         copy_unit_to_networkd_unit_path('12-dummy.netdev', 'gretap.network',
                                         '25-gretap-tunnel.netdev', '25-tunnel.network',
                                         '25-gretap-tunnel-local-any.netdev', '25-tunnel-local-any.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['gretap99:routable', 'gretap98:routable', 'dummy98:degraded'])
 
         output = check_output('ip -d link show gretap99')
@@ -923,7 +999,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
         copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ip6gretap.network',
                                         '25-ip6gretap-tunnel.netdev', '25-tunnel.network',
                                         '25-ip6gretap-tunnel-local-any.netdev', '25-tunnel-local-any.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['ip6gretap99:routable', 'ip6gretap98:routable', 'dummy98:degraded'])
 
         output = check_output('ip -d link show ip6gretap99')
@@ -938,7 +1014,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
                                         '25-vti-tunnel.netdev', '25-tunnel.network',
                                         '25-vti-tunnel-local-any.netdev', '25-tunnel-local-any.network',
                                         '25-vti-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['vtitun99:routable', 'vtitun98:routable', 'vtitun97:routable', 'dummy98:degraded'])
 
         output = check_output('ip -d link show vtitun99')
@@ -956,7 +1032,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
                                         '25-vti6-tunnel.netdev', '25-tunnel.network',
                                         '25-vti6-tunnel-local-any.netdev', '25-tunnel-local-any.network',
                                         '25-vti6-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['vti6tun99:routable', 'vti6tun98:routable', 'vti6tun97:routable', 'dummy98:degraded'])
 
         output = check_output('ip -d link show vti6tun99')
@@ -974,7 +1050,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
                                         '25-ip6tnl-tunnel.netdev', '25-tunnel.network',
                                         '25-ip6tnl-tunnel-local-any.netdev', '25-tunnel-local-any.network',
                                         '25-ip6tnl-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['ip6tnl99:routable', 'ip6tnl98:routable', 'ip6tnl97:routable', 'dummy98:degraded'])
 
         output = check_output('ip -d link show ip6tnl99')
@@ -992,7 +1068,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
                                         '25-sit-tunnel.netdev', '25-tunnel.network',
                                         '25-sit-tunnel-local-any.netdev', '25-tunnel-local-any.network',
                                         '25-sit-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['sittun99:routable', 'sittun98:routable', 'sittun97:routable', 'dummy98:degraded'])
 
         output = check_output('ip -d link show sittun99')
@@ -1008,7 +1084,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
     def test_isatap_tunnel(self):
         copy_unit_to_networkd_unit_path('12-dummy.netdev', 'isatap.network',
                                         '25-isatap-tunnel.netdev', '25-tunnel.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['isataptun99:routable', 'dummy98:degraded'])
 
         output = check_output('ip -d link show isataptun99')
@@ -1018,7 +1094,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
     def test_6rd_tunnel(self):
         copy_unit_to_networkd_unit_path('12-dummy.netdev', '6rd.network',
                                         '25-6rd-tunnel.netdev', '25-tunnel.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['sittun99:routable', 'dummy98:degraded'])
 
         output = check_output('ip -d link show sittun99')
@@ -1030,7 +1106,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
         copy_unit_to_networkd_unit_path('12-dummy.netdev', 'erspan.network',
                                         '25-erspan-tunnel.netdev', '25-tunnel.network',
                                         '25-erspan-tunnel-local-any.netdev', '25-tunnel-local-any.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['erspan99:routable', 'erspan98:routable', 'dummy98:degraded'])
 
         output = check_output('ip -d link show erspan99')
@@ -1051,7 +1127,13 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
 
     def test_tunnel_independent(self):
         copy_unit_to_networkd_unit_path('25-ipip-tunnel-independent.netdev', 'netdev-link-local-addressing-yes.network')
-        start_networkd(0)
+        start_networkd()
+
+        wait_online(['ipiptun99:carrier'])
+
+    def test_tunnel_independent_loopback(self):
+        copy_unit_to_networkd_unit_path('25-ipip-tunnel-independent-loopback.netdev', 'netdev-link-local-addressing-yes.network')
+        start_networkd()
 
         wait_online(['ipiptun99:carrier'])
 
@@ -1064,7 +1146,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
         copy_unit_to_networkd_unit_path('25-fou-ipproto-ipip.netdev', '25-fou-ipproto-gre.netdev',
                                         '25-fou-ipip.netdev', '25-fou-sit.netdev',
                                         '25-fou-gre.netdev', '25-fou-gretap.netdev')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['ipiptun96:off', 'sittun96:off', 'gretun96:off', 'gretap96:off'])
 
@@ -1089,7 +1171,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
     def test_vxlan(self):
         copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network',
                                         '11-dummy.netdev', 'vxlan-test1.network')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['test1:degraded', 'vxlan99:degraded'])
 
@@ -1115,7 +1197,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
     def test_macsec(self):
         copy_unit_to_networkd_unit_path('25-macsec.netdev', '25-macsec.network', '25-macsec.key',
                                         'macsec.network', '12-dummy.netdev')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['dummy98:degraded', 'macsec99:routable'])
 
@@ -1164,18 +1246,20 @@ class NetworkdL2TPTests(unittest.TestCase, Utilities):
     l2tp_tunnel_ids = [ '10' ]
 
     def setUp(self):
-        l2tp_tunnel_remove(self.l2tp_tunnel_ids)
+        remove_l2tp_tunnels(self.l2tp_tunnel_ids)
         remove_links(self.links)
+        stop_networkd(show_logs=False)
 
     def tearDown(self):
-        l2tp_tunnel_remove(self.l2tp_tunnel_ids)
+        remove_l2tp_tunnels(self.l2tp_tunnel_ids)
         remove_links(self.links)
         remove_unit_from_networkd_path(self.units)
+        stop_networkd(show_logs=True)
 
     @expectedFailureIfModuleIsNotAvailable('l2tp_eth')
     def test_l2tp_udp(self):
         copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-udp.netdev')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['test1:routable', 'l2tp-ses1:off', 'l2tp-ses2:off'])
 
@@ -1202,7 +1286,7 @@ class NetworkdL2TPTests(unittest.TestCase, Utilities):
     @expectedFailureIfModuleIsNotAvailable('l2tp_ip')
     def test_l2tp_ip(self):
         copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-ip.netdev')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['test1:routable', 'l2tp-ses3:off', 'l2tp-ses4:off'])
 
@@ -1264,16 +1348,18 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         remove_routing_policy_rule_tables(self.routing_policy_rule_tables)
         remove_routes(self.routes)
         remove_links(self.links)
+        stop_networkd(show_logs=False)
 
     def tearDown(self):
         remove_routing_policy_rule_tables(self.routing_policy_rule_tables)
         remove_routes(self.routes)
         remove_links(self.links)
         remove_unit_from_networkd_path(self.units)
+        stop_networkd(show_logs=True)
 
     def test_address_static(self):
         copy_unit_to_networkd_unit_path('25-address-static.network', '12-dummy.netdev')
-        start_networkd(0)
+        start_networkd()
 
         wait_online(['dummy98:routable'])
 
@@ -1310,10 +1396,9 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
 
     def test_address_preferred_lifetime_zero_ipv6(self):
         copy_unit_to_networkd_unit_path('25-address-preferred-lifetime-zero-ipv6.network', '12-dummy.netdev')
-        start_networkd()
+        start_networkd(5)
 
         self.check_link_exists('dummy98')
-
         self.check_operstate('dummy98', 'routable', setup_state='configuring')
 
         output = check_output('ip address show dummy98')
@@ -1324,8 +1409,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
     def test_configure_without_carrier(self):
         copy_unit_to_networkd_unit_path('configure-without-carrier.network', '11-dummy.netdev')
         start_networkd()
-
-        self.check_link_exists('test1')
+        wait_online(['test1:routable'])
 
         output = check_output(*networkctl_cmd, 'status', 'test1')
         print(output)
@@ -1335,10 +1419,8 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
 
     def test_routing_policy_rule(self):
         copy_unit_to_networkd_unit_path('routing-policy-rule-test1.network', '11-dummy.netdev')
-
         start_networkd()
-
-        self.check_link_exists('test1')
+        wait_online(['test1:degraded'])
 
         output = check_output('ip rule')
         print(output)
@@ -1355,10 +1437,9 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
 
         for trial in range(3):
             # Remove state files only first time
-            start_networkd(remove_state_files=(trial == 0))
-
-            self.check_link_exists('test1')
-            self.check_link_exists('dummy98')
+            start_networkd()
+            wait_online(['test1:degraded', 'dummy98:degraded'])
+            time.sleep(1)
 
             output = check_output('ip rule list table 7')
             print(output)
@@ -1368,13 +1449,13 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
             print(output)
             self.assertRegex(output, '112:     from 192.168.101.18 tos (?:0x08|throughput) iif dummy98 oif dummy98 lookup 8')
 
+            stop_networkd(remove_state_files=False)
+
     @expectedFailureIfRoutingPolicyPortRangeIsNotAvailable()
     def test_routing_policy_rule_port_range(self):
         copy_unit_to_networkd_unit_path('25-fibrule-port-range.network', '11-dummy.netdev')
-
         start_networkd()
-
-        self.check_link_exists('test1')
+        wait_online(['test1:degraded'])
 
         output = check_output('ip rule')
         print(output)
@@ -1388,10 +1469,8 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
     @expectedFailureIfRoutingPolicyIPProtoIsNotAvailable()
     def test_routing_policy_rule_invert(self):
         copy_unit_to_networkd_unit_path('25-fibrule-invert.network', '11-dummy.netdev')
-
         start_networkd()
-
-        self.check_link_exists('test1')
+        wait_online(['test1:degraded'])
 
         output = check_output('ip rule')
         print(output)
@@ -1402,8 +1481,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
 
     def test_route_static(self):
         copy_unit_to_networkd_unit_path('25-route-static.network', '12-dummy.netdev')
-        start_networkd(0)
-
+        start_networkd()
         wait_online(['dummy98:routable'])
 
         output = check_output('ip -6 route show dev dummy98')
@@ -1445,9 +1523,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         # tentative state, and do our test on that
         copy_unit_to_networkd_unit_path('23-active-slave.network', '25-route-ipv6-src.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev')
         start_networkd()
-
-        self.check_link_exists('dummy98')
-        self.check_link_exists('bond199')
+        wait_online(['dummy98:enslaved', 'bond199:routable'])
 
         output = check_output('ip -6 route list dev bond199')
         print(output)
@@ -1458,8 +1534,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
     def test_ip_link_mac_address(self):
         copy_unit_to_networkd_unit_path('25-address-link-section.network', '12-dummy.netdev')
         start_networkd()
-
-        self.check_link_exists('dummy98')
+        wait_online(['dummy98:degraded'])
 
         output = check_output('ip link show dummy98')
         print(output)
@@ -1467,19 +1542,16 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
 
     def test_ip_link_unmanaged(self):
         copy_unit_to_networkd_unit_path('25-link-section-unmanaged.network', '12-dummy.netdev')
-        start_networkd()
+        start_networkd(5)
 
         self.check_link_exists('dummy98')
 
-        output = check_output(*networkctl_cmd, 'status', 'dummy98')
-        print(output)
-        self.assertRegex(output, 'unmanaged')
+        self.check_operstate('dummy98', 'off', setup_state='unmanaged')
 
     def test_ipv6_address_label(self):
         copy_unit_to_networkd_unit_path('25-ipv6-address-label-section.network', '12-dummy.netdev')
         start_networkd()
-
-        self.check_link_exists('dummy98')
+        wait_online(['dummy98:degraded'])
 
         output = check_output('ip addrlabel list')
         print(output)
@@ -1488,10 +1560,9 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
     def test_ipv6_neighbor(self):
         copy_unit_to_networkd_unit_path('25-neighbor-section.network', '12-dummy.netdev')
         start_networkd()
+        wait_online(['dummy98:degraded'], timeout='40s')
 
-        self.check_link_exists('dummy98')
-
-        output = check_output('ip neigh list')
+        output = check_output('ip neigh list dev dummy98')
         print(output)
         self.assertRegex(output, '192.168.10.1.*00:00:5e:00:02:65.*PERMANENT')
         self.assertRegex(output, '2004:da8:1::1.*00:00:5e:00:02:66.*PERMANENT')
@@ -1499,12 +1570,9 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
     def test_link_local_addressing(self):
         copy_unit_to_networkd_unit_path('25-link-local-addressing-yes.network', '11-dummy.netdev',
                                         '25-link-local-addressing-no.network', '12-dummy.netdev')
-        start_networkd(0)
+        start_networkd()
         wait_online(['test1:degraded', 'dummy98:carrier'])
 
-        self.check_link_exists('test1')
-        self.check_link_exists('dummy98')
-
         output = check_output('ip address show dev test1')
         print(output)
         self.assertRegex(output, 'inet .* scope link')
@@ -1514,9 +1582,6 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         print(output)
         self.assertNotRegex(output, 'inet6* .* scope link')
 
-        self.check_operstate('test1', 'degraded')
-        self.check_operstate('dummy98', 'carrier')
-
         '''
         Documentation/networking/ip-sysctl.txt
 
@@ -1552,7 +1617,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
 
     def test_sysctl(self):
         copy_unit_to_networkd_unit_path('25-sysctl.network', '12-dummy.netdev')
-        start_networkd(0)
+        start_networkd()
         wait_online(['dummy98:degraded'])
 
         self.assertEqual(read_ipv6_sysctl_attr('dummy98', 'forwarding'), '1')
@@ -1570,7 +1635,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         check_output('sysctl net.ipv6.conf.all.disable_ipv6=1')
         check_output('sysctl net.ipv6.conf.default.disable_ipv6=1')
 
-        start_networkd(0)
+        start_networkd()
         wait_online(['dummy98:routable'])
 
         output = check_output('ip -4 address show dummy98')
@@ -1592,7 +1657,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         check_output('sysctl net.ipv6.conf.all.disable_ipv6=0')
         check_output('sysctl net.ipv6.conf.default.disable_ipv6=0')
 
-        start_networkd(0)
+        restart_networkd()
         wait_online(['dummy98:routable'])
 
         output = check_output('ip -4 address show dummy98')
@@ -1612,8 +1677,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
     def test_bind_carrier(self):
         copy_unit_to_networkd_unit_path('25-bind-carrier.network', '11-dummy.netdev')
         start_networkd()
-
-        self.check_link_exists('test1')
+        wait_online(['test1:routable'])
 
         check_output('ip link add dummy98 type dummy')
         check_output('ip link set dummy98 up')
@@ -1661,7 +1725,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
 
     def test_domain(self):
         copy_unit_to_networkd_unit_path('12-dummy.netdev', '24-search-domain.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['dummy98:routable'])
 
         output = check_output(*networkctl_cmd, 'status', 'dummy98', env=env)
@@ -1684,7 +1748,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         print(output)
 
         copy_unit_to_networkd_unit_path('24-keep-configuration-static.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['dummy98:routable'])
 
         output = check_output('ip address show dummy98')
@@ -1705,7 +1769,6 @@ class NetworkdBondTests(unittest.TestCase, Utilities):
         '23-active-slave.network',
         '23-bond199.network',
         '23-primary-slave.network',
-        '23-test1-bond199.network',
         '25-bond-active-backup-slave.netdev',
         '25-bond.netdev',
         'bond99.network',
@@ -1713,41 +1776,36 @@ class NetworkdBondTests(unittest.TestCase, Utilities):
 
     def setUp(self):
         remove_links(self.links)
+        stop_networkd(show_logs=False)
 
     def tearDown(self):
         remove_links(self.links)
         remove_unit_from_networkd_path(self.units)
+        stop_networkd(show_logs=True)
 
     def test_bond_active_slave(self):
         copy_unit_to_networkd_unit_path('23-active-slave.network', '23-bond199.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev')
         start_networkd()
-
-        self.check_link_exists('dummy98')
-        self.check_link_exists('bond199')
+        wait_online(['dummy98:enslaved', 'bond199:degraded'])
 
         output = check_output('ip -d link show bond199')
         print(output)
         self.assertRegex(output, 'active_slave dummy98')
 
     def test_bond_primary_slave(self):
-        copy_unit_to_networkd_unit_path('23-primary-slave.network', '23-test1-bond199.network', '25-bond-active-backup-slave.netdev', '11-dummy.netdev')
+        copy_unit_to_networkd_unit_path('23-primary-slave.network', '23-bond199.network', '25-bond-active-backup-slave.netdev', '12-dummy.netdev')
         start_networkd()
-
-        self.check_link_exists('test1')
-        self.check_link_exists('bond199')
+        wait_online(['dummy98:enslaved', 'bond199:degraded'])
 
         output = check_output('ip -d link show bond199')
         print(output)
-        self.assertRegex(output, 'primary test1')
+        self.assertRegex(output, 'primary dummy98')
 
     def test_bond_operstate(self):
         copy_unit_to_networkd_unit_path('25-bond.netdev', '11-dummy.netdev', '12-dummy.netdev',
                                         'bond99.network','bond-slave.network')
         start_networkd()
-
-        self.check_link_exists('bond99')
-        self.check_link_exists('dummy98')
-        self.check_link_exists('test1')
+        wait_online(['dummy98:enslaved', 'test1:enslaved', 'bond99:routable'])
 
         output = check_output('ip -d link show dummy98')
         print(output)
@@ -1810,25 +1868,50 @@ class NetworkdBridgeTests(unittest.TestCase, Utilities):
         '26-bridge.netdev',
         '26-bridge-slave-interface-1.network',
         '26-bridge-slave-interface-2.network',
+        '26-bridge-vlan-master.network',
+        '26-bridge-vlan-slave.network',
         'bridge99-ignore-carrier-loss.network',
         'bridge99.network']
 
+    routing_policy_rule_tables = ['100']
+
     def setUp(self):
+        remove_routing_policy_rule_tables(self.routing_policy_rule_tables)
         remove_links(self.links)
+        stop_networkd(show_logs=False)
 
     def tearDown(self):
+        remove_routing_policy_rule_tables(self.routing_policy_rule_tables)
         remove_links(self.links)
         remove_unit_from_networkd_path(self.units)
+        stop_networkd(show_logs=True)
+
+    def test_bridge_vlan(self):
+        copy_unit_to_networkd_unit_path('11-dummy.netdev', '26-bridge-vlan-slave.network',
+                                        '26-bridge.netdev', '26-bridge-vlan-master.network')
+        start_networkd()
+        wait_online(['test1:enslaved', 'bridge99:degraded'])
+
+        output = check_output('bridge vlan show dev test1')
+        print(output)
+        self.assertNotRegex(output, '4063')
+        for i in range(4064, 4095):
+            self.assertRegex(output, f'{i}')
+        self.assertNotRegex(output, '4095')
+
+        output = check_output('bridge vlan show dev bridge99')
+        print(output)
+        self.assertNotRegex(output, '4059')
+        for i in range(4060, 4095):
+            self.assertRegex(output, f'{i}')
+        self.assertNotRegex(output, '4095')
 
     def test_bridge_property(self):
         copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
                                         '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
                                         'bridge99.network')
         start_networkd()
-
-        self.check_link_exists('dummy98')
-        self.check_link_exists('test1')
-        self.check_link_exists('bridge99')
+        wait_online(['dummy98:enslaved', 'test1:enslaved', 'bridge99:routable'])
 
         output = check_output('ip -d link show test1')
         print(output)
@@ -1859,10 +1942,6 @@ class NetworkdBridgeTests(unittest.TestCase, Utilities):
         if (os.path.exists('/sys/devices/virtual/net/bridge00/lower_dummy98/brport/multicast_to_unicast')):
             self.assertEqual(read_bridge_port_attr('bridge99', 'dummy98', 'multicast_to_unicast'), '1')
 
-        self.check_operstate('test1', 'enslaved')
-        self.check_operstate('dummy98', 'enslaved')
-        self.check_operstate('bridge99', 'routable')
-
         check_output('ip address add 192.168.0.16/24 dev bridge99')
         time.sleep(1)
 
@@ -1870,8 +1949,6 @@ class NetworkdBridgeTests(unittest.TestCase, Utilities):
         print(output)
         self.assertRegex(output, '192.168.0.16/24')
 
-        self.check_operstate('bridge99', 'routable')
-
         self.assertEqual(call('ip link del test1'), 0)
         time.sleep(3)
 
@@ -1892,13 +1969,8 @@ class NetworkdBridgeTests(unittest.TestCase, Utilities):
         copy_unit_to_networkd_unit_path('11-dummy.netdev', '12-dummy.netdev', '26-bridge.netdev',
                                         '26-bridge-slave-interface-1.network', '26-bridge-slave-interface-2.network',
                                         'bridge99-ignore-carrier-loss.network')
-        call('ip rule del table 100')
-
         start_networkd()
-
-        self.check_link_exists('dummy98')
-        self.check_link_exists('test1')
-        self.check_link_exists('bridge99')
+        wait_online(['dummy98:enslaved', 'test1:enslaved', 'bridge99:routable'])
 
         check_output('ip address add 192.168.0.16/24 dev bridge99')
         time.sleep(1)
@@ -1913,40 +1985,19 @@ class NetworkdBridgeTests(unittest.TestCase, Utilities):
         self.assertRegex(output, 'inet 192.168.0.15/24 brd 192.168.0.255 scope global bridge99')
         self.assertRegex(output, 'inet 192.168.0.16/24 scope global secondary bridge99')
 
-        call('ip rule del table 100')
-
     def test_bridge_ignore_carrier_loss_frequent_loss_and_gain(self):
         copy_unit_to_networkd_unit_path('26-bridge.netdev', '26-bridge-slave-interface-1.network',
                                         'bridge99-ignore-carrier-loss.network')
-
-        call('ip rule del table 100')
-
         start_networkd()
+        wait_online(['bridge99:no-carrier'])
 
-        self.check_link_exists('bridge99')
-
-        check_output('ip link add dummy98 type dummy')
-        check_output('ip link set dummy98 up')
-        check_output('ip link del dummy98')
-
-        check_output('ip link add dummy98 type dummy')
-        check_output('ip link set dummy98 up')
-        check_output('ip link del dummy98')
-
-        check_output('ip link add dummy98 type dummy')
-        check_output('ip link set dummy98 up')
-        check_output('ip link del dummy98')
+        for trial in range(4):
+            check_output('ip link add dummy98 type dummy')
+            check_output('ip link set dummy98 up')
+            if trial < 3:
+                check_output('ip link del dummy98')
 
-        check_output('ip link add dummy98 type dummy')
-        check_output('ip link set dummy98 up')
-
-        for trial in range(30):
-            if trial > 0:
-                time.sleep(1)
-            if get_operstate('bridge99') == 'routable' and get_operstate('dummy98') == 'enslaved':
-                break
-        else:
-            self.assertTrue(False)
+        wait_online(['bridge99:routable', 'dummy98:enslaved'])
 
         output = check_output('ip address show bridge99')
         print(output)
@@ -1956,8 +2007,6 @@ class NetworkdBridgeTests(unittest.TestCase, Utilities):
         print(output)
         self.assertEqual(output, '0:   from all to 8.8.8.8 lookup 100')
 
-        call('ip rule del table 100')
-
 class NetworkdLLDPTests(unittest.TestCase, Utilities):
     links = ['veth99']
 
@@ -1968,14 +2017,16 @@ class NetworkdLLDPTests(unittest.TestCase, Utilities):
 
     def setUp(self):
         remove_links(self.links)
+        stop_networkd(show_logs=False)
 
     def tearDown(self):
         remove_links(self.links)
         remove_unit_from_networkd_path(self.units)
+        stop_networkd(show_logs=True)
 
     def test_lldp(self):
         copy_unit_to_networkd_unit_path('23-emit-lldp.network', '24-lldp.network', '25-veth.netdev')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth99:degraded', 'veth-peer:degraded'])
 
         output = check_output(*networkctl_cmd, 'lldp', env=env)
@@ -1993,15 +2044,17 @@ class NetworkdRATests(unittest.TestCase, Utilities):
 
     def setUp(self):
         remove_links(self.links)
+        stop_networkd(show_logs=False)
 
     def tearDown(self):
         remove_links(self.links)
         remove_unit_from_networkd_path(self.units)
+        stop_networkd(show_logs=True)
 
     def test_ipv6_prefix_delegation(self):
         warn_about_firewalld()
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6-prefix.network', 'ipv6-prefix-veth.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth99:routable', 'veth-peer:degraded'])
 
         output = check_output(*networkctl_cmd, 'status', 'veth99', env=env)
@@ -2020,15 +2073,17 @@ class NetworkdDHCPServerTests(unittest.TestCase, Utilities):
 
     def setUp(self):
         remove_links(self.links)
+        stop_networkd(show_logs=False)
 
     def tearDown(self):
         remove_links(self.links)
         remove_unit_from_networkd_path(self.units)
+        stop_networkd(show_logs=True)
 
     def test_dhcp_server(self):
         warn_about_firewalld()
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client.network', 'dhcp-server.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth99:routable', 'veth-peer:routable'])
 
         output = check_output(*networkctl_cmd, 'status', 'veth99', env=env)
@@ -2041,7 +2096,7 @@ class NetworkdDHCPServerTests(unittest.TestCase, Utilities):
     def test_emit_router_timezone(self):
         warn_about_firewalld()
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-client-timezone-router.network', 'dhcp-server-timezone-router.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth99:routable', 'veth-peer:routable'])
 
         output = check_output(*networkctl_cmd, 'status', 'veth99', env=env)
@@ -2071,9 +2126,11 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
         'dhcp-client-listen-port.network',
         'dhcp-client-route-metric.network',
         'dhcp-client-route-table.network',
+        'dhcp-client-use-routes-no.network',
         'dhcp-client-vrf.network',
         'dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network',
         'dhcp-client-with-ipv4ll-fallback-without-dhcp-server.network',
+        'dhcp-client-with-static-address.network',
         'dhcp-client.network',
         'dhcp-server-veth-peer.network',
         'dhcp-v4-server-veth-peer.network',
@@ -2082,6 +2139,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
     def setUp(self):
         stop_dnsmasq(dnsmasq_pid_file)
         remove_links(self.links)
+        stop_networkd(show_logs=False)
 
     def tearDown(self):
         stop_dnsmasq(dnsmasq_pid_file)
@@ -2089,11 +2147,12 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
         remove_log_file()
         remove_links(self.links)
         remove_unit_from_networkd_path(self.units)
+        stop_networkd(show_logs=True)
 
     def test_dhcp_client_ipv6_only(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
 
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq()
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2111,7 +2170,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
     def test_dhcp_client_ipv4_only(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-only-ipv6-disabled.network')
 
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq()
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2124,7 +2183,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
     def test_dhcp_client_ipv4_ipv6(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network',
                                         'dhcp-client-ipv4-only.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq()
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2141,7 +2200,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
     def test_dhcp_client_settings(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-dhcp-settings.network')
 
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq()
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2174,7 +2233,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
 
     def test_dhcp6_client_settings_rapidcommit_true(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq()
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2186,7 +2245,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
 
     def test_dhcp6_client_settings_rapidcommit_false(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-rapid-commit.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq()
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2198,7 +2257,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
 
     def test_dhcp_client_settings_anonymize(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-anonymize.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq()
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2209,7 +2268,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
 
     def test_dhcp_client_listen_port(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-listen-port.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq('--dhcp-alternate-port=67,5555')
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2222,9 +2281,29 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
         print(output)
         self.assertRegex(output, '192.168.5.* dynamic')
 
+    def test_dhcp_client_with_static_address(self):
+        copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network',
+                                        'dhcp-client-with-static-address.network')
+        start_networkd()
+        wait_online(['veth-peer:carrier'])
+        start_dnsmasq()
+        wait_online(['veth99:routable', 'veth-peer:routable'])
+
+        output = check_output('ip address show dev veth99 scope global')
+        print(output)
+        self.assertRegex(output, r'inet 192.168.5.250/24 brd 192.168.5.255 scope global veth99')
+        self.assertRegex(output, r'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global secondary dynamic veth99')
+
+        output = check_output('ip route show dev veth99')
+        print(output)
+        self.assertRegex(output, r'default via 192.168.5.1 proto dhcp src 192.168.5.[0-9]* metric 1024')
+        self.assertRegex(output, r'192.168.5.0/24 proto kernel scope link src 192.168.5.250')
+        self.assertRegex(output, r'192.168.5.0/24 via 192.168.5.5 proto dhcp src 192.168.5.[0-9]* metric 1024')
+        self.assertRegex(output, r'192.168.5.1 proto dhcp scope link src 192.168.5.[0-9]* metric 1024')
+
     def test_dhcp_route_table_id(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-table.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq()
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2236,7 +2315,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
 
     def test_dhcp_route_metric(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-route-metric.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq()
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2245,9 +2324,41 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
         print(output)
         self.assertRegex(output, 'metric 24')
 
+    def test_dhcp_client_use_routes_no(self):
+        copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
+                                        'dhcp-client-use-routes-no.network')
+        start_networkd()
+        wait_online(['veth-peer:carrier'])
+        start_dnsmasq(lease_time='2m')
+        wait_online(['veth99:routable', 'veth-peer:routable'])
+
+        output = check_output('ip address show dev veth99 scope global')
+        print(output)
+        self.assertRegex(output, r'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
+
+        output = check_output('ip route show dev veth99')
+        print(output)
+        self.assertRegex(output, r'192.168.5.0/24 proto kernel scope link src 192.168.5.[0-9]*')
+        self.assertRegex(output, r'192.168.5.0/24 proto static')
+        self.assertRegex(output, r'192.168.6.0/24 proto static')
+        self.assertRegex(output, r'192.168.7.0/24 proto static')
+
+        # Sleep for 120 sec as the dnsmasq minimum lease time can only be set to 120
+        print('Wait for the dynamic address to be renewed')
+        time.sleep(125)
+
+        wait_online(['veth99:routable'])
+
+        output = check_output('ip route show dev veth99')
+        print(output)
+        self.assertRegex(output, r'192.168.5.0/24 proto kernel scope link src 192.168.5.[0-9]*')
+        self.assertRegex(output, r'192.168.5.0/24 proto static')
+        self.assertRegex(output, r'192.168.6.0/24 proto static')
+        self.assertRegex(output, r'192.168.7.0/24 proto static')
+
     def test_dhcp_keep_configuration_dhcp(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-keep-configuration-dhcp.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq(lease_time='2m')
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2301,7 +2412,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
 
     def test_dhcp_keep_configuration_dhcp_on_stop(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-v4-server-veth-peer.network', 'dhcp-client-keep-configuration-dhcp-on-stop.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq(lease_time='2m')
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2317,7 +2428,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
         print(output)
         self.assertRegex(output, r'192.168.5.*')
 
-        start_networkd(0)
+        restart_networkd()
         wait_online(['veth-peer:routable'])
 
         output = check_output('ip address show dev veth99 scope global')
@@ -2326,7 +2437,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
 
     def test_dhcp_client_reuse_address_as_static(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq()
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2352,7 +2463,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
 
         # When networkd started, the links are already configured, so let's wait for 5 seconds
         # the links to be re-configured.
-        start_networkd(5)
+        restart_networkd(5)
         wait_online(['veth99:routable', 'veth-peer:routable'])
 
         output = check_output('ip -4 address show dev veth99 scope global')
@@ -2369,7 +2480,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
     def test_dhcp_client_vrf(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-vrf.network',
                                         '25-vrf.netdev', '25-vrf.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq()
         wait_online(['veth99:routable', 'veth-peer:routable', 'vrf99:carrier'])
@@ -2414,13 +2525,10 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
         print(output)
         self.assertEqual(output, '')
 
-        self.check_operstate('vrf99', 'carrier')
-        self.check_operstate('veth99', 'routable')
-
     def test_dhcp_client_gateway_onlink_implicit(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
                                         'dhcp-client-gateway-onlink-implicit.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq()
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2439,7 +2547,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
     def test_dhcp_client_with_ipv4ll_fallback_with_dhcp_server(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
                                         'dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq(lease_time='2m')
         wait_online(['veth99:routable', 'veth-peer:routable'])
@@ -2476,7 +2584,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
     def test_dhcp_client_with_ipv4ll_fallback_without_dhcp_server(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
                                         'dhcp-client-with-ipv4ll-fallback-without-dhcp-server.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth99:degraded', 'veth-peer:routable'])
 
         output = check_output('ip address show dev veth99')
@@ -2494,7 +2602,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
     def test_dhcp_client_route_remove_on_renew(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network',
                                         'dhcp-client-ipv4-only-ipv6-disabled.network')
-        start_networkd(0)
+        start_networkd()
         wait_online(['veth-peer:carrier'])
         start_dnsmasq(ipv4_range='192.168.5.100,192.168.5.199', lease_time='2m')
         wait_online(['veth99:routable', 'veth-peer:routable'])