// 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;
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();
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
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,
};
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;
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);