Discussion:
[Dnsmasq-discuss] Little detail in DHCP address allocation
Luís Carvalho
2016-03-16 11:33:24 UTC
Permalink
Hi,

I was trying to understand how dnsmasq computes the IP it gives out to a
specific computer, which brought me to this e-mail chain:
http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2010q2/003893.html

This mentions the SDBM hash described here:
http://www.cse.yorku.ca/~oz/hash.html

However, there is a typo in the implementation, which is increasing the
number of collisions in this hash.

This might be irrelevant as the number of possible hashes is already high,
but still I thought to warn you, as the fix is simple.

A potential patch to fix it would be:

diff --git a/src/dhcp.c b/src/dhcp.c
index c11675d..00145bc 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -651,7 +651,7 @@ int address_allocate(struct dhcp_context *context,
/* hash hwaddr: use the SDBM hashing algorithm. Seems to give good
dispersal even with similarly-valued "strings". */
for (j = 0, i = 0; i < hw_len; i++)
- j += hwaddr[i] + (j << 6) + (j << 16) - j;
+ j = hwaddr[i] + (j << 6) + (j << 16) - j;

for (pass = 0; pass <= 1; pass++)
for (c = context; c; c = c->current)
--
Sorry if this is just nitpicking.

Best Regards,
Luis Carvalho
Simon Kelley
2016-04-25 16:07:31 UTC
Permalink
Thanks for that. I pushed that fix, and the equivalent one in the DHCPv6
code, which got the same error by cut 'n paste....




Cheers,

Simon.
Post by Luís Carvalho
Hi,
I was trying to understand how dnsmasq computes the IP it gives out to a
http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2010q2/003893.html
http://www.cse.yorku.ca/~oz/hash.html
However, there is a typo in the implementation, which is increasing the
number of collisions in this hash.
This might be irrelevant as the number of possible hashes is already high,
but still I thought to warn you, as the fix is simple.
diff --git a/src/dhcp.c b/src/dhcp.c
index c11675d..00145bc 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -651,7 +651,7 @@ int address_allocate(struct dhcp_context *context,
/* hash hwaddr: use the SDBM hashing algorithm. Seems to give good
dispersal even with similarly-valued "strings". */
for (j = 0, i = 0; i < hw_len; i++)
- j += hwaddr[i] + (j << 6) + (j << 16) - j;
+ j = hwaddr[i] + (j << 6) + (j << 16) - j;
for (pass = 0; pass <= 1; pass++)
for (c = context; c; c = c->current)
_______________________________________________
Dnsmasq-discuss mailing list
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
Loading...