[Dnsmasq-discuss] Why is dnsmasq handing out the same IP to different MACs?

Paul Smith psmith at gnu.org
Tue Apr 13 07:17:16 BST 2010


On Mon, 2010-04-12 at 19:13 -0400, Paul Smith wrote:
> But, on my test of 192 MACs, the sdbm hash function worked perfectly: I
> got 192 unique IP address offsets.  Funnily enough of all the hash
> functions this one is closest in concept to your current one... but it
> uses shifts of 6 bits and 16 bits (plus a subtract) instead of 8 and 16.
> 
> I'll send a patch later tonight so you can see it. 

Patch is below (not sure if you prefer an attachment or not; let me know
if so).  You can find this algorithm by searching for SDBM hash.

I was looking into fixing up the collision handling algorithm as well.

--- dnsmasq-2.52/src/dhcp.c	2010-01-15 05:13:49.000000000 -0500
+++ dnsmasq/src/dhcp.c	2010-04-13 02:08:13.002012929 -0400
@@ -559,9 +559,10 @@
   int i, pass;
   unsigned int j; 
 
-  /* hash hwaddr */
+  /* 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] + (hwaddr[i] << 8) + (hwaddr[i] << 16);
+    j += hwaddr[i] + (j << 6) + (j << 16) - j;
   
   for (pass = 0; pass <= 1; pass++)
     for (c = context; c; c = c->current)

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <psmith at gnu.org>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.net
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




More information about the Dnsmasq-discuss mailing list