Improved seed for zcip

Joachim Nilsson joachim.nilsson at vmlinux.org
Wed Oct 29 22:29:18 UTC 2008


Hi!

When I run udhcpc, with zcip as fallback, simultaneously on many
VLAN interfaces I get exactly the same link-local address assigned
for all of them.  It  turns out the random seed basically just uses
the MAC address, which for VLAN interfaces is shared with the base
interface.  To fix this I added the ifindex of the requested iface
to the seed and everything works much better.

Hope someone else finds it useful.

Regards
 /Jocke
 
Signed-off-by: Joachim Nilsson <joachim.nilsson at vmlinux.org>

diff -ru busybox-1.12.1.orig/networking/zcip.c busybox-1.12.1/networking/zcip.c
--- busybox-1.12.1.orig/networking/zcip.c	2008-09-28 20:04:11.000000000 +0200
+++ busybox-1.12.1/networking/zcip.c	2008-10-28 19:16:16.000000000
+0100
@@ -266,9 +266,12 @@
 	// aren't random enough.
 	// NOTE: the sequence of addresses we try changes only
 	// depending on when we detect conflicts.
+        // Also, if more than one interface shares the same MAC address, e.g.
+        // VLAN interfaces, we make sure to add ifindex to the seed, otherwise
+        // we get the same IP for all interfaces...
 	{
 		uint32_t t;
-		memcpy(&t, (char*)&eth_addr + 2, 4);
+		memcpy(&t, (char*)&eth_addr + 2 + if_nametoindex(intf), 4);
 		srand(t);
 	}
 	if (ip.s_addr == 0)



More information about the busybox mailing list