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
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:
1 parent
9089429c2d
commit
ca65f007c1
4 files changed
+52
-2
No files matched your search
@@ -54,6 +54,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
each with its gateway and interface. A host route that FRR reports without a prefix
|
each with its gateway and interface. A host route that FRR reports without a prefix
|
||||||
length is a `/128` for IPv6 instead of a `/32` (#64), so it meets the kernel's route
|
length is a `/128` for IPv6 instead of a `/32` (#64), so it meets the kernel's route
|
||||||
for the same host and gets FRR's protocol.
|
for the same host and gets FRR's protocol.
|
||||||
|
- `get_route_to()` reads the next hop of an IPv4 route through an IPv6 gateway (RFC
|
||||||
|
8950, as BGP unnumbered sets up), which `ip route` prints as `via inet6 fe80::1`
|
||||||
|
(#65). The next hop came back as `inet6`; it is now the address, for multipath
|
||||||
|
routes too. Such a route stays `family: ipv4`: the family is the destination's,
|
||||||
|
never the next hop's.
|
||||||
- `get_available_updates()` works on dnf and yum hosts whose login user has
|
- `get_available_updates()` works on dnf and yum hosts whose login user has
|
||||||
passwordless sudo (NOPASSWD), as netOrk's own account does, and marks the security
|
passwordless sudo (NOPASSWD), as netOrk's own account does, and marks the security
|
||||||
fixes there (#56). The security-advisory query did not parse under `sudo -n`, so no
|
fixes there (#56). The security-advisory query did not parse under `sudo -n`, so no
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ _NO_FORWARDING = frozenset({"blackhole", "unreachable", "prohibit", "throw"})
|
|||||||
#: The line a multipath route's next hops start with, one each, after the route.
|
#: The line a multipath route's next hops start with, one each, after the route.
|
||||||
_NEXTHOP = "nexthop"
|
_NEXTHOP = "nexthop"
|
||||||
|
|
||||||
_VIA = re.compile(r"via\s+(\S+)")
|
#: ``via 192.0.2.1``, or with the gateway's family in front: ``via inet6 fe80::1`` for an
|
||||||
|
#: IPv4 route with an IPv6 next hop (RFC 8950, #65).
|
||||||
|
_VIA = re.compile(r"via\s+(?:inet6?\s+)?(\S+)")
|
||||||
_DEV = re.compile(r"dev\s+(\S+)")
|
_DEV = re.compile(r"dev\s+(\S+)")
|
||||||
_PROTO = re.compile(r"proto\s+(\S+)")
|
_PROTO = re.compile(r"proto\s+(\S+)")
|
||||||
_METRIC = re.compile(r"metric\s+(\d+)")
|
_METRIC = re.compile(r"metric\s+(\d+)")
|
||||||
|
|||||||
@@ -933,7 +933,7 @@ class LinuxDriver(
|
|||||||
def _make_entry(
|
def _make_entry(
|
||||||
proto: str, nexthop: str, iface: str, metric: int, network: str
|
proto: str, nexthop: str, iface: str, metric: int, network: str
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
family = "ipv6" if (":" in network or (nexthop and ":" in nexthop)) else "ipv4"
|
family = "ipv6" if ":" in network else "ipv4" # not the next hop's (#65)
|
||||||
return {
|
return {
|
||||||
"protocol": proto,
|
"protocol": proto,
|
||||||
"family": family,
|
"family": family,
|
||||||
|
|||||||
@@ -2529,3 +2529,46 @@ class TestFrrHostRoutes:
|
|||||||
|
|
||||||
def test_a_prefix_with_a_length_keeps_it(self, routes):
|
def test_a_prefix_with_a_length_keeps_it(self, routes):
|
||||||
assert "10.10.1.0/24" in 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"]
|
||||||
Reference in new issue
Block a user