From d354ebb66cdcccc3373156468eec1c660fb2922c Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Thu, 4 Dec 2025 15:38:20 +0100 Subject: [PATCH] router: optimize duplicated PIO comparison MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Compare prefix and length with a single memcmp instead of performing separate comparisons. Suggested-by: Paul Donald Link: https://github.com/openwrt/odhcpd/pull/336 Signed-off-by: Álvaro Fernández Rojas --- src/odhcpd.h | 7 +++++-- src/router.c | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/odhcpd.h b/src/odhcpd.h index 1ce2452..0b308b2 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -346,10 +346,13 @@ struct dnr_options { // RA PIO - RFC9096 struct ra_pio { - struct in6_addr prefix; - uint8_t length; + struct { + struct in6_addr prefix; + uint8_t length; + }; time_t lifetime; }; +#define ra_pio_cmp_len offsetof(struct ra_pio, lifetime) struct interface { diff --git a/src/router.c b/src/router.c index ef47d0f..0e7a110 100644 --- a/src/router.c +++ b/src/router.c @@ -538,8 +538,7 @@ static void router_clear_duplicated_ra_pio(struct interface *iface) while (j < iface->pio_cnt) { struct ra_pio *pio_b = &iface->pios[j]; - if (pio_a->length == pio_b->length && - !memcmp(&pio_a->prefix, &pio_b->prefix, sizeof(struct in6_addr))) { + if (!memcmp(pio_a, pio_b, ra_pio_cmp_len)) { warn("rfc9096: %s: clear duplicated %s/%u", iface->ifname, inet_ntop(AF_INET6, &pio_a->prefix, ipv6_str, sizeof(ipv6_str)), -- 2.30.2