diff options
| author | Álvaro Fernández Rojas | 2025-12-04 14:38:20 +0000 |
|---|---|---|
| committer | Álvaro Fernández Rojas | 2025-12-04 14:54:59 +0000 |
| commit | d354ebb66cdcccc3373156468eec1c660fb2922c (patch) | |
| tree | 88cbd42213ceeaee32d09d9b613d06f580e5dbf2 | |
| parent | 8b26b0124aeddd11c92328e5a968c0f903ee1f0a (diff) | |
router: optimize duplicated PIO comparison
Compare prefix and length with a single memcmp instead of performing
separate comparisons.
Suggested-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcpd/pull/336
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
| -rw-r--r-- | src/odhcpd.h | 7 | ||||
| -rw-r--r-- | 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)), |