Hi,

Reporting 2 bugs that I had with ospf6d over the last years.
>From my side it wasn't easy to replicate, so I used Claude for this today.

We managed to find a way to replicate the issues. 
Claude also produced two patches which I've tested and at least didn't 
reproduce the problem.

Tell me if you need more information.

regards,

G

Here is the report by claude:

TL;DR
-----

ospf6d can install a p2p next hop with the link-local address of a
*different* neighbor (right interface, wrong address), which silently
blackholes all routes via that neighbor until ospf6d is restarted.

Cause: calc_nexthop_lladdr() looks up the neighbor's Link-LSA with our
own interface ID instead of the neighbor's (nbr_iface_id), so the
lookup always misses on p2p links and falls back to the address of
whichever neighbor delivered the Router-LSA. 

A second, related issue:
rt_nexthop_add() merges equal-cost next hops by address only, ignoring
the interface. Both date back to 2007/2009, affect ospf6d only, and are
reproducible on 8.0. Two small diffs below, tested on 8.0.

>Synopsis: ospf6d: p2p next hop gets the link-local address of a different 
>neighbor
>Release: 8.0
>System: OpenBSD 8.0 (GENERIC.MP) #12: Tue Nov 17 01:55:14 CST 2026
    
[email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.MP

Setup
-----

Two OpenBSD 8.0 routers, r1 (CARP master) and r2 (CARP backup), running ospf6d 
in one area.
Both peer over point-to-point links ("type p2p") with the same two routers,
A (172.16.0.111, upstream) and B (172.16.176.3,internal). 

All links use "depend on carp", so r2's interfaces advertise
metric 65535 while it is backup.

r2:

  vlan914 -> A 172.16.0.111, fe80::208:e3ff:feff:ff24
  vlan121 -> B 172.16.176.3, fe80::215:2cff:fe16:7d00

  # ospf6ctl show neighbor
  ID              Pri State        DeadTime  Iface       Uptime
  172.16.0.111    255 FULL/P2P     00:00:15  vlan914     00:40:14
  172.16.176.3    1   FULL/P2P     00:00:17  vlan121     00:44:52

Since A and B are also connected through r1, every Router-LSA reaches r2
over both of its adjacencies.

Bug 1: p2p next hop uses another neighbor's address
---------------------------------------------------

On a p2p link, the next hop should be the neighbor's link-local address
from the Link-LSA it advertises on that link. ospf6d looks that Link-LSA
up with its own interface ID instead of the neighbor's, so the lookup
never succeeds. It then falls back to the address of the neighbor that
the remote Router-LSA was received from.

Usually that is the same neighbor. If the current instance of A's
Router-LSA reached r2 first through B, r2 installs B's address on A's
interface. It cannot be resolved there, so everything routed via A is
dropped until a newer instance of A's LSA arrives directly or ospf6d is
restarted.

Interface IDs on the r2-A link (ours 17, A's 199):

  # ospf6ctl show database router      (excerpt)
  Advertising Router: 172.16.176.2
      Link (Interface ID 0.0.0.17) connected to: Point-to-Point
      Router ID: 172.16.0.111
      Interface ID: 0.0.0.199
      Metric: 65535

  Advertising Router: 172.16.0.111
      Link (Interface ID 0.0.0.199) connected to: Point-to-Point
      Router ID: 172.16.176.2
      Interface ID: 0.0.0.17
      Metric: 4096

A's Link-LSA on vlan914 is present and correct while the bug is active:

  # ospf6ctl show database link        (excerpt, vlan914)
  Link State ID: 0.0.0.199 (Interface ID of Advertising Router)
  Advertising Router: 172.16.0.111
  Link Local Address: fe80::208:e3ff:feff:ff24
      Prefix: 2001:db8:2c00:391::4/126

RIB and neighbor cache while broken:

  # ospf6ctl show rib      (excerpt)
  ::172.16.0.111   fe80::215:2cff:fe16:7d00%vlan914  Inter-Area  Router   65535
  ::/0             fe80::215:2cff:fe16:7d00%vlan914  Type 2 ext  Network  65535

  # ndp -an      (excerpt)
  fe80::208:e3ff:feff:ff24%vlan914   00:08:e3:ff:ff:24  vlan914  5s  D R
  fe80::215:2cff:fe16:7d00%vlan914   (incomplete)       vlan914  1s  I 3

ospf6d -vvv log (A is reached over the direct link, cost 65535, but with
B's address):

  16:29:20 r2 ospf6d: (172.16.0.111, 0x2001, 0.0.0.0) cost 65535 has nexthops 
[fe80::208:e3ff:feff:ff24%vlan914]
  16:29:40 r2 ospf6d: (172.16.0.111, 0x2001, 0.0.0.0) cost 65535 has nexthops 
[fe80::215:2cff:fe16:7d00%vlan914]
  16:30:43 r2 ospf6d: startup                          (ospf6d restarted)
  16:30:48 r2 ospf6d: (172.16.0.111, 0x2001, 0.0.0.0) cost 65535 has nexthops 
[fe80::208:e3ff:feff:ff24%vlan914]

Bug 2: equal-cost next hops compared by address only
----------------------------------------------------

When merging equal-cost next hops into a route, ospf6d compares them by
address only, not by interface. Two next hops with the same link-local
address on different interfaces are treated as one, and the second is
dropped. Link-local addresses are only unique per link, and many routers
use the same one on all interfaces, so this can drop a valid path.

In this case bug 1 gave both paths to r1 (172.16.176.1) the same address:

  16:29:40 r2 ospf6d: (172.16.176.1, 0x2001, 0.0.0.0) cost 65536 has nexthops 
[fe80::215:2cff:fe16:7d00%vlan914, fe80::215:2cff:fe16:7d00%vlan121]

and the prefix behind r1 kept only one entry:

  2001:db8:2c00:6c08::/64  fe80::215:2cff:fe16:7d00%vlan121  Intra-Area  
Network  65537

The kernel side (kroute.c) already compares next hop and scope, so only
the RIB merge is affected.

How to reproduce
----------------

Reproduced twice without the diffs, the second time with both routers
on 8.0:

1. On r1, take down its link to A (ifconfig down). A drops r1 and
   re-originates its Router-LSA; r2 receives it directly.
2. On r2, block OSPF from A on vlan914 with pf, shorter than the dead
   interval (kill the existing state first, then 10s blocked / 10s open,
   repeated).
3. On r1, bring the link back up. A re-originates its Router-LSA with
   the r1 link; r2 receives this instance via r1 and B first.
4. r2's routes via A now use B's link-local address on vlan914.

The same state also appeared occasionally after a reboot or a restart of
ospf6d, depending on which adjacency delivered A's LSA first.

Testing
-------

Tested on r2 (8.0) with both diffs applied, using the same procedure.
A's new Router-LSA arrived only via B (r2 was blocking A at that moment),
the adjacency with A stayed up, and r2 kept the correct next hop:

  17:10:12 r2 ospf6d: (172.16.0.111, 0x2001, 0.0.0.0) cost 65535 has nexthops 
[fe80::208:e3ff:feff:ff24%vlan914]
  17:10:27 r2 ospf6d: (172.16.0.111, 0x2001, 0.0.0.0) cost 65535 has nexthops 
[fe80::208:e3ff:feff:ff24%vlan914]

r1 now gets two distinct next hops, and the prefix behind it two RIB
entries:

  17:08:02 r2 ospf6d: (172.16.176.1, 0x2001, 0.0.0.0) cost 65536 has nexthops 
[fe80::208:e3ff:feff:ff24%vlan914, fe80::215:2cff:fe16:7d00%vlan121]

  2001:db8:2c00:6c08::/64  fe80::215:2cff:fe16:7d00%vlan121  Intra-Area  
Network  65537
  2001:db8:2c00:6c08::/64  fe80::208:e3ff:feff:ff24%vlan914  Intra-Area  
Network  65537

History
-------

Both are old and only affect ospf6d; ospfd takes the next hop directly
from the neighbor's interface address in the Router-LSA and compares
IPv4 addresses, which is correct there.

Bug 1: the fallback to dst->peerid dates from 2009-03-29 ("As a first
step towards SPF tree calculation, prepare for proper next-hop
calculation"). The Link-LSA lookup in calc_nexthop_lladdr() using
rtr_link->iface_id came on 2009-12-22 ("Give calc_nexthop_lladdr() a
chance to find the correct link local address"). A follow-up the same
day ("Use correct interface id. iface_id is our ifindex, nbr_iface_id is
the interface id of the remote side.") fixed the ifindex argument in the
p2p case of calc_nexthop(), but not the Link-LSA lookup. That lookup is
right for transit networks, where rtr_link comes from the neighbor's
own Router-LSA, but wrong for p2p, where it comes from ours. It mostly
goes unnoticed because the fallback usually returns the right neighbor.

Bug 2: rt_nexthop_add() has compared by address only since 2007-10-16
("First step at making kroute IPv6 aware"), carried over from ospfd.

Diff 1: look up the neighbor's Link-LSA with the neighbor's interface ID
------------------------------------------------------------------------

calc_nexthop_lladdr() now takes the Link State ID to look up. The transit
case keeps passing the neighbor's own iface_id, the p2p case passes
nbr_iface_id.

Index: rde_spf.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/rde_spf.c,v
diff -u -p -r1.29 rde_spf.c
--- rde_spf.c   8 Mar 2023 04:43:14 -0000       1.29
+++ rde_spf.c   19 Nov 2026 14:00:00 -0000
@@ -36,7 +36,7 @@ RB_PROTOTYPE(rt_tree, rt_node, entry, rt
 RB_GENERATE(rt_tree, rt_node, entry, rt_compare)
 struct vertex                  *spf_root = NULL;
 
-struct in6_addr        *calc_nexthop_lladdr(struct vertex *, struct 
lsa_rtr_link *,
+struct in6_addr        *calc_nexthop_lladdr(struct vertex *, u_int32_t,
                     unsigned int);
 void            calc_nexthop_transit_nbr(struct vertex *, struct vertex *,
                     unsigned int);
@@ -457,7 +457,7 @@ spf_tree_clr(struct area *area)
 }
 
 struct in6_addr *
-calc_nexthop_lladdr(struct vertex *dst, struct lsa_rtr_link *rtr_link,
+calc_nexthop_lladdr(struct vertex *dst, u_int32_t nbr_iface_id,
     unsigned int ifindex)
 {
        struct iface            *iface;
@@ -471,14 +471,14 @@ calc_nexthop_lladdr(struct vertex *dst,
        }
        if (!iface) {
                log_warnx("calc_nexthop_lladdr: no interface found for "
-                   "ifindex %d", ntohl(rtr_link->iface_id));
+                   "ifindex %u", ifindex);
                return (NULL);
        }
 
        /* Determine neighbor's link-local address.
         * Try to get it from link LSA first. */
        link = lsa_find_tree(&iface->lsa_tree,
-               htons(LSA_TYPE_LINK), rtr_link->iface_id,
+               htons(LSA_TYPE_LINK), nbr_iface_id,
                htonl(dst->adv_rtr));
        if (link)
                return &link->lsa->data.link.lladdr;
@@ -510,7 +510,8 @@ calc_nexthop_transit_nbr(struct vertex *
                if (rtr_link->type == LINK_TYPE_TRANSIT_NET &&
                    rtr_link->nbr_rtr_id == parent->lsa->hdr.adv_rtr &&
                    rtr_link->nbr_iface_id == parent->lsa->hdr.ls_id) {
-                       lladdr = calc_nexthop_lladdr(dst, rtr_link, ifindex);
+                       lladdr = calc_nexthop_lladdr(dst, rtr_link->iface_id,
+                           ifindex);
                        vertex_nexthop_add(dst, parent, lladdr, ifindex);
                }
        }
@@ -529,8 +530,8 @@ calc_nexthop(struct vertex *dst, struct
                case LSA_TYPE_ROUTER:
                        if (rtr_link->type != LINK_TYPE_POINTTOPOINT)
                                fatalx("inconsistent SPF tree");
-                       nexthop = calc_nexthop_lladdr(dst, rtr_link,
-                           ntohl(rtr_link->iface_id));
+                       nexthop = calc_nexthop_lladdr(dst,
+                           rtr_link->nbr_iface_id, ntohl(rtr_link->iface_id));
                        break;
                case LSA_TYPE_NETWORK:
                        if (rtr_link->type != LINK_TYPE_TRANSIT_NET)

With this diff the fallback in calc_nexthop_lladdr() is only used when
the Link-LSA is not (yet) known. It can still pick a neighbor on a
different interface in that case; it may be worth restricting it to a
neighbor on ifindex, but I left that out to keep the diff minimal.

Diff 2: compare ifindex as well as the address when merging next hops
---------------------------------------------------------------------

Index: rde_spf.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/rde_spf.c,v
diff -u -p -r1.29 rde_spf.c
--- rde_spf.c   8 Mar 2023 04:43:14 -0000       1.29
+++ rde_spf.c   19 Nov 2026 14:00:00 -0000
@@ -873,7 +873,8 @@ rt_nexthop_add(struct rt_node *r, struct
 
        TAILQ_FOREACH(vn, vnh, entry) {
                TAILQ_FOREACH(rn, &r->nexthop, entry) {
-                       if (!IN6_ARE_ADDR_EQUAL(&rn->nexthop, &vn->nexthop))
+                       if (!IN6_ARE_ADDR_EQUAL(&rn->nexthop, &vn->nexthop) ||
+                           rn->ifindex != vn->ifindex)
                                continue;
 
                        rn->adv_rtr.s_addr = adv_rtr.s_addr;

Both diffs apply independently against rde_spf.c 1.29.


Reply via email to