1
0
mirror of https://github.com/openbsd/src.git synced 2026-06-18 07:13:36 +02:00

Sync the nexthop comperators in rde_rib.c and kroute.c

While nexthop_cmp() already looked for the scope_id for link-local IPv6
nexthops, knexthop_compare() did not.

Reported by 7Asecurity
OK tb@
This commit is contained in:
claudio
2026-05-27 12:38:54 +00:00
parent 7d2efe2b68
commit e41d07dbde
2 changed files with 21 additions and 17 deletions
+15 -11
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: kroute.c,v 1.313 2025/02/04 16:07:46 claudio Exp $ */
/* $OpenBSD: kroute.c,v 1.314 2026/05/27 12:38:54 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -1506,30 +1506,34 @@ kroute6_compare(struct kroute6 *a, struct kroute6 *b)
int
knexthop_compare(struct knexthop *a, struct knexthop *b)
{
int i;
int r;
if (a->nexthop.aid != b->nexthop.aid)
return (b->nexthop.aid - a->nexthop.aid);
return (a->nexthop.aid - b->nexthop.aid);
switch (a->nexthop.aid) {
case AID_INET:
if (ntohl(a->nexthop.v4.s_addr) < ntohl(b->nexthop.v4.s_addr))
return (-1);
if (ntohl(a->nexthop.v4.s_addr) > ntohl(b->nexthop.v4.s_addr))
return (1);
if (ntohl(a->nexthop.v4.s_addr) < ntohl(b->nexthop.v4.s_addr))
return (-1);
break;
case AID_INET6:
for (i = 0; i < 16; i++) {
if (a->nexthop.v6.s6_addr[i] < b->nexthop.v6.s6_addr[i])
return (-1);
if (a->nexthop.v6.s6_addr[i] > b->nexthop.v6.s6_addr[i])
r = memcmp(&a->nexthop.v6, &b->nexthop.v6,
sizeof(a->nexthop.v6));
if (r != 0)
return r;
if (IN6_IS_ADDR_LINKLOCAL(&a->nexthop.v6)) {
if (a->nexthop.scope_id > b->nexthop.scope_id)
return (1);
if (a->nexthop.scope_id < b->nexthop.scope_id)
return (-1);
}
break;
default:
fatalx("%s: unknown AF", __func__);
fatalx("%s: %s is unsupported", __func__,
aid2str(a->nexthop.aid));
}
return (0);
}
+6 -6
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: rde_rib.c,v 1.297 2026/05/27 08:28:35 claudio Exp $ */
/* $OpenBSD: rde_rib.c,v 1.298 2026/05/27 12:38:54 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -1495,9 +1495,9 @@ nexthop_cmp(struct nexthop *na, struct nexthop *nb)
return (1);
if (ntohl(a->v4.s_addr) < ntohl(b->v4.s_addr))
return (-1);
return (0);
break;
case AID_INET6:
r = memcmp(&a->v6, &b->v6, sizeof(struct in6_addr));
r = memcmp(&a->v6, &b->v6, sizeof(a->v6));
if (r != 0)
return r;
if (IN6_IS_ADDR_LINKLOCAL(&a->v6)) {
@@ -1506,11 +1506,11 @@ nexthop_cmp(struct nexthop *na, struct nexthop *nb)
if (a->scope_id < b->scope_id)
return (-1);
}
return (0);
break;
default:
fatalx("nexthop_cmp: %s is unsupported", aid2str(a->aid));
fatalx("%s: %s is unsupported", __func__, aid2str(a->aid));
}
return (-1);
return (0);
}
static struct nexthop *