diff options
| author | Álvaro Fernández Rojas | 2025-12-14 08:04:33 +0000 |
|---|---|---|
| committer | Álvaro Fernández Rojas | 2025-12-14 08:29:24 +0000 |
| commit | 7ebd96083971ad2b241b527fe02bbc4a974cd841 (patch) | |
| tree | fbe25bd51bc64f32c8f6d66dd30285b402a82838 | |
| parent | 90ae6fc6e478ee6b18ab201275d93817fb5259a5 (diff) | |
| download | odhcpd-7ebd96083971ad2b241b527fe02bbc4a974cd841.tar.gz | |
Revert "router: optimize duplicated PIO comparison"
This reverts commit d354ebb66cdcccc3373156468eec1c660fb2922c.
As stated by David Härdeman at [1]:
Note that time_t will have an alignment of 4 (unlikely) or 8, meaning
that struct ra_pio will have padding. A straight memcmp() could
therefore generate the wrong result unless both struct ra_pios that are
compared are guaranteed to have been memset to zero.
Avoid the risk of something going wrong here by doing a straight
comparison of the two members of the struct that we want to compare.
[1]: https://github.com/openwrt/odhcpd/pull/348/changes/d02fce006abd4f0761bf3100c9ddd4ce70847edb
(cherry picked from commit 03c1468355c0ffb8fa965cdf57f0d3fc8f01f006)
Link: https://github.com/openwrt/odhcpd/pull/354
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, 4 insertions, 6 deletions
diff --git a/src/odhcpd.h b/src/odhcpd.h index 86375ab..f005909 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -346,13 +346,10 @@ struct dnr_options { // RA PIO - RFC9096 struct ra_pio { - struct { - struct in6_addr prefix; - uint8_t length; - }; + 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 608a558..b322a41 100644 --- a/src/router.c +++ b/src/router.c @@ -539,7 +539,8 @@ static void router_clear_duplicated_ra_pio(struct interface *iface) while (j < iface->pio_cnt) { struct ra_pio *pio_b = &iface->pios[j]; - if (!memcmp(pio_a, pio_b, ra_pio_cmp_len)) { + if (pio_a->length == pio_b->length && + !memcmp(&pio_a->prefix, &pio_b->prefix, sizeof(struct in6_addr))) { warn("rfc9096: %s: clear duplicated %s/%u", iface->ifname, inet_ntop(AF_INET6, &pio_a->prefix, ipv6_str, sizeof(ipv6_str)), |