fix(routes): give an FRR host route without a length /128 for IPv6
The FRR enrichment in get_route_to completed every prefix without a length with /32. An IPv6 host route became a different, much larger /32 prefix, so it missed the kernel's /128 entry for the same host (stored that way since #6) and added a bogus one instead. with_length() in _routes.py completes a prefix by its family, /32 or /128. The protocol attributes move onto IpRoute, which keeps the import in linux.py on one line; get_route_to shrinks and the baseline records it. Closes #64
This commit is contained in:
1 parent
a1e8ec78c3
commit
9089429c2d
5 files changed
+62
-12
No files matched your search
@@ -2487,3 +2487,45 @@ class TestParseIpRoute:
|
||||
assert list(parse_ip_route(out, "ipv4")) == [
|
||||
IpRoute("0.0.0.0/0", "dhcp", "192.0.2.1", "eth0", 100)
|
||||
]
|
||||
|
||||
|
||||
class TestFrrHostRoutes:
|
||||
"""The FRR enrichment completes a prefix without a length by its family (#64)."""
|
||||
|
||||
# FRR installs its routes as "proto zebra"; vtysh names the real source.
|
||||
_IP6 = "2001:db8:2::7 via fe80::1 dev eth0 proto zebra metric 20 pref medium\n"
|
||||
_VTYSH = (
|
||||
"O>* 2001:db8:2::7 [110/20] via fe80::1, eth0, weight 1, 00:01:02\n"
|
||||
"O>* 2001:db8:3::9 [110/30] via fe80::1, eth0, weight 1, 00:01:02\n"
|
||||
"O>* 10.10.0.7 [110/20] via 10.255.255.2, wg0, weight 1, 00:01:02\n"
|
||||
"O>* 10.10.1.0/24 [110/20] via 10.255.255.2, wg0, weight 1, 00:01:02\n"
|
||||
)
|
||||
|
||||
@pytest.fixture()
|
||||
def routes(self, driver):
|
||||
def send(command, **_kw):
|
||||
if command.startswith("command -v vtysh"):
|
||||
return "/usr/bin/vtysh"
|
||||
if command.startswith("vtysh"):
|
||||
return self._VTYSH
|
||||
if "ip -6 route" in command:
|
||||
return self._IP6
|
||||
return ""
|
||||
|
||||
with patch.object(driver, "_send", side_effect=send):
|
||||
return driver.get_route_to()
|
||||
|
||||
def test_an_ipv6_host_route_is_a_128(self, routes):
|
||||
assert "2001:db8:3::9/128" in routes
|
||||
assert not any(
|
||||
network.endswith("::7/32") or network.endswith("::9/32") for network in routes
|
||||
)
|
||||
|
||||
def test_it_meets_the_kernel_route_of_the_same_host(self, routes):
|
||||
assert [e["protocol"] for e in routes["2001:db8:2::7/128"]] == ["ospf"]
|
||||
|
||||
def test_an_ipv4_host_route_stays_a_32(self, routes):
|
||||
assert "10.10.0.7/32" in routes
|
||||
|
||||
def test_a_prefix_with_a_length_keeps_it(self, routes):
|
||||
assert "10.10.1.0/24" in routes
|
||||
Reference in new issue
Block a user