package/odhcp6c: fix build with gcc >= 14.x

Detected by Gitlab pipeline when testing the other build fixes in this
series. Autobuilders did not detect the problem due to the build error
with glibc 2.43.

https://gitlab.com/bkuhls/buildroot/-/jobs/14571737512

/builds/bkuhls/buildroot/br-test-pkg/bootlin-powerpc-e500mc-uclibc/build/odhcp6c-f19dd37fb467c9cf10cad57aefa0d048312d7dfd/src/dhcpv6.c:1395:58:
 error: comparison of integer expressions of different signedness:
 ‘uint32_t’ {aka ‘unsigned int’} and ‘int’ [-Werror=sign-compare]
 1395 | if (ia_hdr->iaid != htonl(ifindex) && otype == DHCPV6_OPT_IA_NA)

https://gitlab.com/bkuhls/buildroot/-/jobs/14571737510

/builds/bkuhls/buildroot/br-test-pkg/bootlin-openrisc-uclibc/build/odhcp6c-f19dd37fb467c9cf10cad57aefa0d048312d7dfd/src/dhcpv6.c:1395:58:
 error: comparison of integer expressions of different signedness:
 ‘uint32_t’ {aka ‘unsigned int’} and ‘int’ [-Werror=sign-compare]

https://gitlab.com/bkuhls/buildroot/-/jobs/14571737505

/builds/bkuhls/buildroot/br-test-pkg/bootlin-m68k-68040-uclibc/build/odhcp6c-f19dd37fb467c9cf10cad57aefa0d048312d7dfd/src/dhcpv6.c:1395:58:
 error: comparison of integer expressions of different signedness:
 ‘uint32_t’ {aka ‘unsigned int’} and ‘int’ [-Werror=sign-compare]

Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
Signed-off-by: Arnout Vandecappelle <arnout@rnout.be>
(cherry picked from commit 17b434cf07)
Signed-off-by: Thomas Perale <thomas.perale@mind.be>
This commit is contained in:
Bernd Kuhls
2026-05-27 23:00:17 +02:00
committed by Thomas Perale
parent baf285e1ec
commit c5fbbc198c

View File

@@ -0,0 +1,95 @@
From 9a4d6fe802d21e4fc1b84f7d55b5c3c23e71d6ba Mon Sep 17 00:00:00 2001
From: Paul Donald <newtwen+github@gmail.com>
Date: Thu, 18 Dec 2025 15:10:24 +0100
Subject: [PATCH] dhcpv6: use stable IAID for IA_NA
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
https://www.rfc-editor.org/rfc/rfc8415.html#section-12
........ The IAID is chosen by the client. For any given use of an
IA by the client, the IAID for that IA MUST be consistent across
restarts of the DHCP client. The client may maintain consistency by
either storing the IAID in non-volatile storage or using an algorithm
that will consistently produce the same IAID as long as the
configuration of the client has not changed.
Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/140
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Upstream: https://github.com/openwrt/odhcp6c/commit/9a4d6fe802d21e4fc1b84f7d55b5c3c23e71d6ba
Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
---
src/dhcpv6.c | 15 +++++++++++++--
src/odhcp6c.h | 1 +
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/dhcpv6.c b/src/dhcpv6.c
index d8bb8be..97860b1 100644
--- a/src/dhcpv6.c
+++ b/src/dhcpv6.c
@@ -262,6 +262,9 @@ static struct dhcpv6_stats dhcpv6_stats = {0};
// config
static struct config_dhcp* config_dhcp = NULL;
+// store unique ifname hash to use as IA->IAID
+static uint32_t ifname_hash_iaid = 0;
+
static uint32_t ntohl_unaligned(const uint8_t *data)
{
uint32_t buf;
@@ -542,6 +545,12 @@ void dhcpv6_reset_stats(void)
memset(&dhcpv6_stats, 0, sizeof(dhcpv6_stats));
}
+uint32_t hash_ifname(const char *s) {
+ uint32_t h = 0;
+ while (*s) h = h * 31 + *s++;
+ return h;
+}
+
int init_dhcpv6(const char *ifname)
{
config_dhcp = config_dhcp_get();
@@ -566,6 +575,8 @@ int init_dhcpv6(const char *ifname)
if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0)
goto failure;
+ ifname_hash_iaid = hash_ifname(ifname);
+
ifindex = ifr.ifr_ifindex;
// Set the socket to non-blocking mode
@@ -838,7 +849,7 @@ static void dhcpv6_send(enum dhcpv6_msg req_msg_type, uint8_t trid[3], uint32_t
struct dhcpv6_ia_hdr hdr_ia_na = {
.type = htons(DHCPV6_OPT_IA_NA),
.len = htons(sizeof(hdr_ia_na) - DHCPV6_OPT_HDR_SIZE),
- .iaid = htonl(ifindex),
+ .iaid = htonl(ifname_hash_iaid),
.t1 = 0,
.t2 = 0,
};
@@ -1392,7 +1403,7 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, _o_unused const int rc,
continue;
// Test ID
- if (ia_hdr->iaid != htonl(ifindex) && otype == DHCPV6_OPT_IA_NA)
+ if (ia_hdr->iaid != htonl(ifname_hash_iaid) && otype == DHCPV6_OPT_IA_NA)
continue;
uint16_t code = DHCPV6_Success;
diff --git a/src/odhcp6c.h b/src/odhcp6c.h
index aa73bbc..c57f885 100644
--- a/src/odhcp6c.h
+++ b/src/odhcp6c.h
@@ -540,6 +540,7 @@ struct odhcp6c_opt {
const char *str;
};
+uint32_t hash_ifname(const char *s);
int init_dhcpv6(const char *ifname);
int dhcpv6_get_ia_mode(void);
int dhcpv6_promote_server_cand(void);