[Dnsmasq-discuss] Little detail in DHCP address allocation

Luís Carvalho mail at lmcarvalho.com
Wed Mar 16 11:33:24 GMT 2016


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20160316/8e8fab0f/attachment.html>


More information about the Dnsmasq-discuss mailing list