]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-network: add tests for Blackhole= setting in [NextHop] section 18718/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 14 Feb 2021 19:19:34 +0000 (04:19 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 22 Feb 2021 17:21:35 +0000 (02:21 +0900)
test/test-network/conf/25-nexthop.network
test/test-network/systemd-networkd-tests.py

index a0b220f9184d40cecfdefcf34094ca4b0620a314..8b3e4b65c56cd1e6d0c458417cb3e81a15e7da33 100644 (file)
@@ -28,9 +28,27 @@ Id=5
 Gateway=192.168.10.1
 OnLink=yes
 
+[NextHop]
+Id=6
+Family=ipv4
+Blackhole=yes
+
+[NextHop]
+Id=7
+Family=ipv6
+Blackhole=yes
+
 [NextHop]
 Gateway=192.168.5.2
 
+[NextHop]
+Family=ipv4
+Blackhole=yes
+
+[NextHop]
+Family=ipv6
+Blackhole=yes
+
 [Route]
 NextHop=1
 Destination=10.10.10.10
@@ -46,3 +64,11 @@ Destination=2001:1234:5:8f62::1
 [Route]
 NextHop=5
 Destination=10.10.10.12
+
+[Route]
+NextHop=6
+Destination=10.10.10.13
+
+[Route]
+NextHop=7
+Destination=2001:1234:5:8f62::2
index 2effa42e16dc1744ab789ee3433671ceb2a4306b..6c17b204a1136476ace63a6c17ce4c5c40e783c9 100755 (executable)
@@ -404,6 +404,13 @@ def remove_routes(routes):
     for route_type, addr in routes:
         call('ip route del', route_type, addr, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
 
+def remove_blackhole_nexthops():
+    ret = run('ip nexthop show dev lo', stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
+    if ret.returncode == 0:
+        for line in ret.stdout.rstrip().splitlines():
+            id = line.split()[1]
+            call(f'ip nexthop del id {id}')
+
 def remove_l2tp_tunnels(tunnel_ids):
     output = check_output('ip l2tp show tunnel')
     for tid in tunnel_ids:
@@ -1831,12 +1838,14 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
     routes = [['blackhole', '202.54.1.2'], ['unreachable', '202.54.1.3'], ['prohibit', '202.54.1.4']]
 
     def setUp(self):
+        remove_blackhole_nexthops()
         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_blackhole_nexthops()
         remove_routing_policy_rule_tables(self.routing_policy_rule_tables)
         remove_routes(self.routes)
         remove_links(self.links)
@@ -2829,6 +2838,12 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         self.assertRegex(output, 'id 5 via 192.168.10.1 dev veth99 .*onlink')
         self.assertRegex(output, r'id [0-9]* via 192.168.5.2 dev veth99')
 
+        # kernel manages blackhole nexthops on lo
+        output = check_output('ip nexthop list dev lo')
+        print(output)
+        self.assertIn('id 6 blackhole', output)
+        self.assertIn('id 7 blackhole', output)
+
         output = check_output('ip route show dev veth99 10.10.10.10')
         print(output)
         self.assertEqual('10.10.10.10 nhid 1 via 192.168.5.1 proto static', output)
@@ -2845,6 +2860,14 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         print(output)
         self.assertEqual('2001:1234:5:8f62::1 nhid 2 via 2001:1234:5:8f63::2 proto static metric 1024 pref medium', output)
 
+        output = check_output('ip route show 10.10.10.13')
+        print(output)
+        self.assertEqual('blackhole 10.10.10.13 nhid 6 dev lo proto static', output)
+
+        output = check_output('ip -6 route show 2001:1234:5:8f62::2')
+        print(output)
+        self.assertEqual('blackhole 2001:1234:5:8f62::2 nhid 7 dev lo proto static metric 1024 pref medium', output)
+
     def test_qdisc(self):
         copy_unit_to_networkd_unit_path('25-qdisc-clsact-and-htb.network', '12-dummy.netdev',
                                         '25-qdisc-ingress-netem-compat.network', '11-dummy.netdev')