Skip to content

Commit abf6677

Browse files
committed
dhcpv6: replace hash_ifname() with MD5 implementation
Replace hash_ifname() with new implementation based on MD5 hash. This implementation generates the same output as: openwrt/openwrt@e1f2b66 (cherry picked from commit 591ce40) Link: #150 Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
1 parent 699cc61 commit abf6677

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/dhcpv6.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,21 @@ void dhcpv6_reset_stats(void)
544544
memset(&dhcpv6_stats, 0, sizeof(dhcpv6_stats));
545545
}
546546

547-
uint32_t hash_ifname(const char *s) {
548-
uint32_t h = 0;
549-
while (*s) h = h * 31 + *s++;
550-
return h;
547+
static uint32_t dhcpv6_generate_iface_iaid(const char *ifname) {
548+
uint8_t hash[16] = {0};
549+
uint32_t iaid;
550+
md5_ctx_t md5;
551+
552+
md5_begin(&md5);
553+
md5_hash(ifname, strlen(ifname), &md5);
554+
md5_end(hash, &md5);
555+
556+
iaid = hash[0] << 24;
557+
iaid |= hash[1] << 16;
558+
iaid |= hash[2] << 8;
559+
iaid |= hash[3];
560+
561+
return iaid;
551562
}
552563

553564
int init_dhcpv6(const char *ifname)
@@ -574,7 +585,7 @@ int init_dhcpv6(const char *ifname)
574585
if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0)
575586
goto failure;
576587

577-
ifname_hash_iaid = hash_ifname(ifname);
588+
ifname_hash_iaid = dhcpv6_generate_iface_iaid(ifname);
578589

579590
ifindex = ifr.ifr_ifindex;
580591

0 commit comments

Comments
 (0)