Index | Thread | Search

From:
Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:
bgpd: compare scopeid for nexthops -- aka I hate IPv6
To:
tech@openbsd.org
Date:
Wed, 13 May 2026 15:59:11 +0200

Download raw body.

Thread
I hate IPv6 and especially scope ids.

Add missing scope_id checks in nexthop_cmp() since we now do allow
link-local nexthops in some cases.

There is probably more missing but this is one step.
-- 
:wq Claudio

Index: rde_rib.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_rib.c,v
diff -u -p -r1.292 rde_rib.c
--- rde_rib.c	7 May 2026 11:21:24 -0000	1.292
+++ rde_rib.c	13 May 2026 13:55:32 -0000
@@ -1469,6 +1469,7 @@ static inline int
 nexthop_cmp(struct nexthop *na, struct nexthop *nb)
 {
 	struct bgpd_addr	*a, *b;
+	int r;
 
 	if (na == nb)
 		return (0);
@@ -1491,7 +1492,16 @@ nexthop_cmp(struct nexthop *na, struct n
 			return (-1);
 		return (0);
 	case AID_INET6:
-		return (memcmp(&a->v6, &b->v6, sizeof(struct in6_addr)));
+		r = memcmp(&a->v6, &b->v6, sizeof(struct in6_addr));
+		if (r != 0)
+			return r;
+		if (IN6_IS_ADDR_LINKLOCAL(&a->v6)) {
+			if (a->scope_id > b->scope_id)
+				return (1);
+			if (a->scope_id < b->scope_id)
+				return (1);
+		}
+		return (0);
 	default:
 		fatalx("nexthop_cmp: %s is unsupported", aid2str(a->aid));
 	}