fix(routes): give the IPv6 default route ::/0
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 1m10s
driver / test (3.12) (pull_request) Successful in 1m8s
driver / lowest (pull_request) Successful in 37s
driver / test (3.13) (pull_request) Successful in 1m14s
driver / build (pull_request) Successful in 38s
driver / security (pull_request) Successful in 1m20s
CI / driver (pull_request) Successful in 2m59s
driver / publish (pull_request) Skipped

get_route_to read "ip -4 route show && ip -6 route show" as one output
and mapped "default" to 0.0.0.0/0; the "default6" branch meant for IPv6
never matches, because ip -6 also prints "default". A dual-stack host
showed two 0.0.0.0/0 routes, one of them family ipv6. Each family is now
read with its own command, so "default" becomes ::/0 for IPv6 and a host
route without a prefix length a /128 there instead of a /32.

The line parse moves to napalm_linux/_routes.py.

Closes #6
This commit is contained in:
Christian Manivong committed 2026-11-01 21:50:33 +01:00
1 parent 69f1701ea6
commit 897892b923
5 files changed
+108 -41

No files matched your search

+45
View File
@@ -2240,3 +2240,48 @@ class TestGetProcesses:
_mock_send(driver, " 1 0 root 0.0 0.1 23456 12345 ? Ss Tue Oct 6\n")
assert driver.get_processes() == []
class TestRouteFamilies:
"""``ip -6 route show`` calls its default route ``default`` too (#6)."""
_V4 = (
"default via 192.0.2.1 dev eth0 proto dhcp src 192.0.2.10 metric 100\n"
"192.0.2.0/24 dev eth0 proto kernel scope link src 192.0.2.10 metric 100\n"
)
_V6 = (
"2001:db8:1::/64 dev eth0 proto ra metric 100 expires 86391sec pref medium\n"
"fe80::/64 dev eth0 proto kernel metric 256 pref medium\n"
"default via fe80::1 dev eth0 proto ra metric 100 expires 1791sec pref medium\n"
)
def _routes(self, driver, v6=_V6):
def send(command, **_kw):
out = ""
if "ip -4 route" in command:
out += self._V4
if "ip -6 route" in command:
out += v6
return out
with patch.object(driver, "_send", side_effect=send):
return driver.get_route_to()
def test_the_ipv6_default_route_is_its_own(self, driver):
routes = self._routes(driver)
assert [r["family"] for r in routes["::/0"]] == ["ipv6"]
assert routes["::/0"][0]["next_hop"] == "fe80::1"
def test_the_ipv4_default_route_stays_ipv4(self, driver):
routes = self._routes(driver)
assert [r["family"] for r in routes["0.0.0.0/0"]] == ["ipv4"]
assert routes["0.0.0.0/0"][0]["next_hop"] == "192.0.2.1"
def test_an_ipv6_host_route_is_a_128(self, driver):
routes = self._routes(
driver, v6="2001:db8:2::7 via fe80::1 dev eth0 proto static metric 1024\n"
)
assert "2001:db8:2::7/128" in routes