Luís Carvalho
2016-03-16 11:33:24 UTC
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)
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
Sorry if this is just nitpicking.
Best Regards,
Luis Carvalho