get_route_to: unreachable/blackhole/prohibit routes and multipath nexthop lines become destinations #57

Closed
opened 2026-11-01 21:44:45 +00:00 by christianmanivong · 0 comments
Owner

What happens

get_route_to (napalm_linux/linux.py:958) reads ip -4 route show && ip -6 route show and takes the first word of every line as the destination (line 963):

dest_m = re.match(r"^(\S+)", line)

That is wrong for lines whose first word is the route type or a continuation:

  • unreachable 10.0.0.0/8 metric 1024, blackhole 192.0.2.0/24, prohibit …, throw … → destination unreachable/32, blackhole/32 (lines 972-973 append /32 to anything without a slash).
  • A multipath route prints its next hops on continuation lines (\tnexthop via 10.0.0.1 dev eth0 weight 1); after strip() each becomes a destination nexthop/32, and the parent line (default proto static metric 100) has no via, so it gets an empty next hop.
  • An IPv6 host route without a prefix length also gets /32 instead of /128.

(The IPv6 default route stored as 0.0.0.0/0 is #6.)

Expected

Route-type keywords are read as the type (skipped, or reported with the type), the destination is the next word; nexthop lines attach their gateways to the preceding route; host routes get /32 or /128 by family. Test-first with a captured ip route output containing unreachable, blackhole and a multipath default.

Priority: P4 — bogus prefixes in the routing table on hosts with such routes.

Found during the bug sweep of 2026-11-01.

## What happens `get_route_to` (`napalm_linux/linux.py:958`) reads `ip -4 route show && ip -6 route show` and takes the first word of every line as the destination (line 963): ```python dest_m = re.match(r"^(\S+)", line) ``` That is wrong for lines whose first word is the route type or a continuation: - `unreachable 10.0.0.0/8 metric 1024`, `blackhole 192.0.2.0/24`, `prohibit …`, `throw …` → destination `unreachable/32`, `blackhole/32` (lines 972-973 append `/32` to anything without a slash). - A multipath route prints its next hops on continuation lines (`\tnexthop via 10.0.0.1 dev eth0 weight 1`); after `strip()` each becomes a destination `nexthop/32`, and the parent line (`default proto static metric 100`) has no `via`, so it gets an empty next hop. - An IPv6 host route without a prefix length also gets `/32` instead of `/128`. (The IPv6 default route stored as `0.0.0.0/0` is #6.) ## Expected Route-type keywords are read as the type (skipped, or reported with the type), the destination is the next word; `nexthop` lines attach their gateways to the preceding route; host routes get `/32` or `/128` by family. Test-first with a captured `ip route` output containing `unreachable`, `blackhole` and a multipath default. Priority: P4 — bogus prefixes in the routing table on hosts with such routes. Found during the bug sweep of 2026-11-01.
christianmanivong added the
prio
P4
bug
labels 2026-11-01 21:44:45 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-linux#57