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
+11
-3
@@ -51,6 +51,11 @@ class IpRoute(NamedTuple):
|
||||
metric: int
|
||||
route_type: str = "unicast"
|
||||
|
||||
@property
|
||||
def attributes(self) -> dict[str, str]:
|
||||
"""NAPALM's ``protocol_attributes`` for this route: its type, unless unicast."""
|
||||
return {} if self.route_type == "unicast" else {"type": self.route_type}
|
||||
|
||||
|
||||
def parse_ip_route(out: str, family: str) -> Iterator[IpRoute]:
|
||||
"""The routes in *out*, the output of ``IP_ROUTE_COMMANDS[family]``."""
|
||||
@@ -70,9 +75,12 @@ def parse_ip_route(out: str, family: str) -> Iterator[IpRoute]:
|
||||
yield from _routes(route, hops, family)
|
||||
|
||||
|
||||
def route_attributes(route_type: str) -> dict[str, str]:
|
||||
"""NAPALM's ``protocol_attributes`` for a route of *route_type*: its type, unless unicast."""
|
||||
return {} if route_type == "unicast" else {"type": route_type}
|
||||
def with_length(prefix: str) -> str:
|
||||
"""*prefix* with a prefix length: a host route without one is ``/32`` or ``/128``
|
||||
by the address's family (#64)."""
|
||||
if "/" in prefix:
|
||||
return prefix
|
||||
return prefix + _HOST_PREFIX["ipv6" if ":" in prefix else "ipv4"]
|
||||
|
||||
|
||||
def _routes(line: str, hops: list[str], family: str) -> Iterator[IpRoute]:
|
||||
|
||||
@@ -75,7 +75,7 @@ from napalm_linux._dpkg import DPKG_QUERY_COMMAND, parse_dpkg_query
|
||||
from napalm_linux._hostname import HostnameMixin
|
||||
from napalm_linux._local_accounts import LinuxLocalAccountsMixin
|
||||
from napalm_linux._ping import parse_ping, ping_command
|
||||
from napalm_linux._routes import IP_ROUTE_COMMANDS, IpRoute, parse_ip_route, route_attributes
|
||||
from napalm_linux._routes import IP_ROUTE_COMMANDS, IpRoute, parse_ip_route, with_length
|
||||
from napalm_linux._shell import expect_for, prepare_shell, sudo_without_password
|
||||
from napalm_linux._sudo_history import LinuxSudoHistoryMixin
|
||||
|
||||
@@ -955,7 +955,7 @@ class LinuxDriver(
|
||||
if protocol and mapped != protocol.lower():
|
||||
return
|
||||
entry = _make_entry(mapped, route.nexthop, route.iface, route.metric, route.network)
|
||||
entry["protocol_attributes"] = route_attributes(route.route_type)
|
||||
entry["protocol_attributes"] = route.attributes
|
||||
routes.setdefault(route.network, []).append(entry)
|
||||
|
||||
for family, command in IP_ROUTE_COMMANDS.items():
|
||||
@@ -989,12 +989,10 @@ class LinuxDriver(
|
||||
if not vm:
|
||||
continue
|
||||
code = vm.group(1)
|
||||
prefix = vm.group(2)
|
||||
prefix = with_length(vm.group(2))
|
||||
metric = int(vm.group(4))
|
||||
nexthop = vm.group(5) or ""
|
||||
iface = (vm.group(6) or "").rstrip(",")
|
||||
if "/" not in prefix:
|
||||
prefix += "/32"
|
||||
mapped_proto = _frr_code.get(code, code.lower())
|
||||
if prefix in routes:
|
||||
for entry in routes[prefix]:
|
||||
|
||||
Reference in new issue
Block a user