fix(routes): read the address of a "via inet6" next hop
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 16s
driver / types (pull_request) Successful in 1m17s
driver / test (3.13) (pull_request) Successful in 1m12s
driver / test (3.12) (pull_request) Successful in 1m18s
driver / lowest (pull_request) Successful in 37s
driver / build (pull_request) Successful in 40s
driver / security (pull_request) Successful in 1m25s
CI / driver (pull_request) Successful in 3m10s
driver / publish (pull_request) Skipped

iproute2 prints an IPv4 route with an IPv6 next hop (RFC 8950, BGP
unnumbered) as "via inet6 fe80::1", and the next hop was read as the
literal "inet6". The family word after "via" is now skipped, for
multipath next hops as well.

With the address in place, get_route_to would have reported such a
route as ipv6, because it took the family from the next hop too. The
family is now the destination's alone. The test fixture is ip's output
(iproute2 6.1.0) recorded in a network namespace set up with these
routes.

Closes #65
This commit is contained in:
Christian Manivong committed 2026-11-02 08:49:53 +01:00
1 parent 9089429c2d
commit ca65f007c1
4 files changed
+52 -2

No files matched your search

+43
View File
@@ -2529,3 +2529,46 @@ class TestFrrHostRoutes:
def test_a_prefix_with_a_length_keeps_it(self, routes):
assert "10.10.1.0/24" in routes
#: ``ip -4 route show``, iproute2 6.1.0 on Linux 7.0 (Linux Mint 22.3), recorded in a
#: network namespace set up for it: IPv4 routes with IPv6 next hops (RFC 8950), single
#: and multipath, as BGP unnumbered installs them (#65). Documentation addresses only.
_IP4_VIA_INET6 = (
"default via inet6 2001:db8:1::1 dev eth0 \n"
"10.20.0.0/16 proto bgp metric 20 \n"
"\tnexthop via inet6 2001:db8:1::1 dev eth0 weight 1 \n"
"\tnexthop via inet6 2001:db8:2::1 dev eth1 weight 1 \n"
"10.40.0.0/16 via inet6 2001:db8:1::1 dev eth0 proto bgp metric 20 \n"
"192.0.2.0/24 dev eth0 proto kernel scope link src 192.0.2.10 \n"
)
class TestIpv6NextHops:
"""``via inet6 <address>``: the next hop is the address (#65)."""
@pytest.fixture()
def routes(self, driver):
def send(command, **_kw):
return _IP4_VIA_INET6 if "ip -4 route" in command else ""
with patch.object(driver, "_send", side_effect=send):
return driver.get_route_to()
@pytest.mark.parametrize("network", ["0.0.0.0/0", "10.40.0.0/16"])
def test_the_next_hop_is_the_address(self, routes, network):
assert [e["next_hop"] for e in routes[network]] == ["2001:db8:1::1"]
def test_a_multipath_route_has_each_address(self, routes):
hops = [(e["next_hop"], e["outgoing_interface"]) for e in routes["10.20.0.0/16"]]
assert hops == [("2001:db8:1::1", "eth0"), ("2001:db8:2::1", "eth1")]
def test_the_route_stays_ipv4(self, routes):
"""The family is the destination's; an IPv6 next hop does not change it."""
assert {e["family"] for entries in routes.values() for e in entries} == {"ipv4"}
def test_a_family_word_for_ipv4_is_skipped_too(self):
out = "10.50.0.0/16 via inet 192.0.2.1 dev eth0\n"
assert [r.nexthop for r in parse_ip_route(out, "ipv4")] == ["192.0.2.1"]