From: Yu Watanabe Date: Sun, 14 Feb 2021 19:19:34 +0000 (+0900) Subject: test-network: add tests for Blackhole= setting in [NextHop] section X-Git-Tag: v248-rc1~12^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F18718%2Fhead;p=thirdparty%2Fsystemd.git test-network: add tests for Blackhole= setting in [NextHop] section --- diff --git a/test/test-network/conf/25-nexthop.network b/test/test-network/conf/25-nexthop.network index a0b220f9184..8b3e4b65c56 100644 --- a/test/test-network/conf/25-nexthop.network +++ b/test/test-network/conf/25-nexthop.network @@ -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 diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 2effa42e16d..6c17b204a11 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -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')