Skip to content

Commit a2648b7

Browse files
committed
Revert "router: optimize duplicated PIO comparison"
This reverts commit d354ebb. 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]: openwrt@d02fce0 Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
1 parent 6b88c31 commit a2648b7

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/odhcpd.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,10 @@ struct dnr_options {
346346

347347
// RA PIO - RFC9096
348348
struct ra_pio {
349-
struct {
350-
struct in6_addr prefix;
351-
uint8_t length;
352-
};
349+
struct in6_addr prefix;
350+
uint8_t length;
353351
time_t lifetime;
354352
};
355-
#define ra_pio_cmp_len offsetof(struct ra_pio, lifetime)
356353

357354

358355
struct interface {

src/router.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,8 @@ static void router_clear_duplicated_ra_pio(struct interface *iface)
539539
while (j < iface->pio_cnt) {
540540
struct ra_pio *pio_b = &iface->pios[j];
541541

542-
if (!memcmp(pio_a, pio_b, ra_pio_cmp_len)) {
542+
if (pio_a->length == pio_b->length &&
543+
!memcmp(&pio_a->prefix, &pio_b->prefix, sizeof(struct in6_addr))) {
543544
warn("rfc9096: %s: clear duplicated %s/%u",
544545
iface->ifname,
545546
inet_ntop(AF_INET6, &pio_a->prefix, ipv6_str, sizeof(ipv6_str)),

0 commit comments

Comments
 (0)