summaryrefslogtreecommitdiff
path: root/src/tests/test_frrender.py
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-11-01 18:53:09 +0000
committerChristian Breunig <christian@breunig.cc>2026-11-01 19:58:49 +0100
commitf819e149290ea56583b3a4b1cef3c5f86a01ab37 (patch)
tree99ef8275694751423c9b38c7a1b9f40846cdf8fd /src/tests/test_frrender.py
parent39f31b58157d89edc077392d436c12a42ab1d726 (diff)
downloadvyos-1x-f819e149290ea56583b3a4b1cef3c5f86a01ab37.tar.gz
vyos-1x-f819e149290ea56583b3a4b1cef3c5f86a01ab37.zip
frrender: T9482: drop a blackhole route FRR would refuse
The default route of a DHCP or PPPoE interface changes with an interface-only commit or a lease event, without a commit of the static routes. If it gets the same prefix and distance as a blackhole or reject route, FRR refuses the reload and every static route added with it is lost. The rendered FRR configuration is now checked for a blackhole or reject route next to any other route of the same prefix and distance, per VRF and table. Such a blackhole or reject route is not rendered, and an error naming it is logged to the journal. Prefixes are compared in their normalized form, as FRR stores them.
Diffstat (limited to 'src/tests/test_frrender.py')
-rw-r--r--src/tests/test_frrender.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/tests/test_frrender.py b/src/tests/test_frrender.py
index d6dfc37eb..e8a28215e 100644
--- a/src/tests/test_frrender.py
+++ b/src/tests/test_frrender.py
@@ -20,6 +20,7 @@ from unittest.mock import patch
from vyos import ConfigError
from vyos import frrender
from vyos.frrender import FRRender
+from vyos.frrender import drop_conflicting_discard_routes
# generate() only renders known protocols, so this renders an empty file but
# still differs from the empty cache of a new instance
@@ -134,3 +135,79 @@ class TestFRRenderCache(TestCase):
self.frr.apply()
self.assertEqual(len(tries), 5)
self.assertFalse(self.frr.generate(config))
+
+
+class TestDropConflictingDiscardRoutes(TestCase):
+ def drop(self, lines):
+ output, messages = drop_conflicting_discard_routes('\n'.join(lines))
+ return output.splitlines(), messages
+
+ def test_no_conflict(self):
+ lines = ['!',
+ 'ip route 0.0.0.0/0 blackhole 200',
+ 'ip route 0.0.0.0/0 pppoe0 tag 210 ',
+ 'ip route 10.0.0.0/8 blackhole',
+ 'ip route 10.0.0.0/8 192.0.2.1 tag 5 10',
+ 'ip mroute 224.1.0.0/24 eth0 1',
+ '!']
+ self.assertEqual(self.drop(lines), (lines, []))
+
+ def test_pppoe_default_route(self):
+ # rendered without a distance, so both use distance 1
+ output, messages = self.drop(['ip route 0.0.0.0/0 blackhole',
+ 'ip route 0.0.0.0/0 pppoe0 tag 210 '])
+ self.assertEqual(output, ['ip route 0.0.0.0/0 pppoe0 tag 210 '])
+ self.assertEqual(len(messages), 1)
+ self.assertIn('"ip route 0.0.0.0/0 blackhole"', messages[0])
+
+ def test_dhcp_default_route_distance(self):
+ output, _ = self.drop(['ip route 0.0.0.0/0 reject tag 5 210',
+ 'ip route 0.0.0.0/0 192.0.2.1 eth0 tag 210 210'])
+ self.assertEqual(output, ['ip route 0.0.0.0/0 192.0.2.1 eth0 tag 210 210'])
+
+ def test_explicit_default_distance(self):
+ output, _ = self.drop(['ipv6 route ::/0 blackhole 1',
+ 'ipv6 route ::/0 pppoe0 tag 210 '])
+ self.assertEqual(output, ['ipv6 route ::/0 pppoe0 tag 210 '])
+
+ def test_vrf(self):
+ # the default route of an interface in a VRF is rendered into it, with
+ # a double space after "ip"
+ lines = ['vrf red',
+ ' ip route 0.0.0.0/0 blackhole 210',
+ ' ip route 0.0.0.0/0 192.0.2.1 eth1 tag 210 210',
+ 'exit-vrf',
+ '!',
+ 'ip route 0.0.0.0/0 blackhole 210']
+ output, messages = self.drop(lines)
+ self.assertEqual(output, [lines[0], lines[2], lines[3], lines[4], lines[5]])
+ self.assertIn('in VRF "red"', messages[0])
+
+ def test_table(self):
+ lines = ['ip route 0.0.0.0/0 blackhole table 100',
+ 'ip route 0.0.0.0/0 192.0.2.1 eth0 table 100',
+ 'ip route 0.0.0.0/0 blackhole table 200',
+ 'ip route 0.0.0.0/0 pppoe0 tag 210 ']
+ output, messages = self.drop(lines)
+ self.assertEqual(output, lines[1:])
+ self.assertIn('in table 100', messages[0])
+
+ def test_options(self):
+ # option values must not be taken for the distance
+ lines = ['ip route 10.0.0.0/8 blackhole tag 20',
+ 'ip route 10.0.0.0/8 192.0.2.1 bfd multi-hop source 192.0.2.10 '
+ 'profile 20 nexthop-vrf blue',
+ 'ip route 10.1.0.0/16 blackhole 20',
+ 'ip route 10.1.0.0/16 eth0 tag 20 30']
+ output, _ = self.drop(lines)
+ self.assertEqual(output, lines[1:])
+
+ def test_spelling(self):
+ # FRR stores both as the same route
+ output, _ = self.drop(['ipv6 route 2001:db8::/32 blackhole',
+ 'ipv6 route 2001:0db8::1/32 2001:db8::1'])
+ self.assertEqual(output, ['ipv6 route 2001:0db8::1/32 2001:db8::1'])
+
+ def test_only_discard_routes(self):
+ lines = ['ip route 10.0.0.0/8 blackhole', 'ip route 10.0.0.0/8 reject 5']
+ self.assertEqual(self.drop(lines), (lines, []))