83597a
diff -up dhcp-4.3.2/client/dhclient.c.improved-xid dhcp-4.3.2/client/dhclient.c
83597a
--- dhcp-4.3.2/client/dhclient.c.improved-xid	2015-06-24 18:55:36.775988325 +0200
83597a
+++ dhcp-4.3.2/client/dhclient.c	2015-06-24 18:56:41.598810344 +0200
83597a
@@ -916,6 +916,26 @@ main(int argc, char **argv) {
bd3a57
 		}
bd3a57
 	}
bd3a57
 
bd3a57
+	/* We create a backup seed before rediscovering interfaces in order to
bd3a57
+	   have a seed built using all of the available interfaces
bd3a57
+	   It's interesting if required interfaces doesn't let us defined
bd3a57
+	   a really unique seed due to a lack of valid HW addr later
bd3a57
+	   (this is the case with DHCP over IB)
bd3a57
+	   We only use the last device as using a sum could broke the
bd3a57
+	   uniqueness of the seed among multiple nodes
bd3a57
+	 */
bd3a57
+	unsigned backup_seed = 0;
bd3a57
+	for (ip = interfaces; ip; ip = ip -> next) {
bd3a57
+		int junk;
bd3a57
+		if ( ip -> hw_address.hlen <= sizeof seed )
bd3a57
+		  continue;
bd3a57
+		memcpy (&junk,
bd3a57
+			&ip -> hw_address.hbuf [ip -> hw_address.hlen -
bd3a57
+						sizeof seed], sizeof seed);
bd3a57
+		backup_seed = junk;
bd3a57
+	}
bd3a57
+
bd3a57
+
bd3a57
 	/* At this point, all the interfaces that the script thinks
bd3a57
 	   are relevant should be running, so now we once again call
bd3a57
 	   discover_interfaces(), and this time ask it to actually set
83597a
@@ -930,14 +950,36 @@ main(int argc, char **argv) {
bd3a57
 	   Not much entropy, but we're booting, so we're not likely to
bd3a57
 	   find anything better. */
bd3a57
 	seed = 0;
bd3a57
+	int seed_flag = 0;
bd3a57
 	for (ip = interfaces; ip; ip = ip->next) {
bd3a57
 		int junk;
bd3a57
+		if ( ip -> hw_address.hlen <= sizeof seed )
bd3a57
+		  continue;
bd3a57
 		memcpy(&junk,
bd3a57
 		       &ip->hw_address.hbuf[ip->hw_address.hlen -
bd3a57
 					    sizeof seed], sizeof seed);
bd3a57
 		seed += junk;
bd3a57
+		seed_flag = 1;
bd3a57
 	}
bd3a57
-	srandom(seed + cur_time + (unsigned)getpid());
bd3a57
+	if ( seed_flag == 0 ) {
bd3a57
+		if ( backup_seed != 0 ) {
bd3a57
+		  seed = backup_seed;
bd3a57
+		  log_info ("xid: rand init seed (0x%x) built using all"
bd3a57
+			    " available interfaces",seed);
bd3a57
+		}
bd3a57
+		else {
bd3a57
+		  seed = cur_time^((unsigned) gethostid()) ;
bd3a57
+		  log_info ("xid: warning: no netdev with useable HWADDR found"
bd3a57
+			    " for seed's uniqueness enforcement");
bd3a57
+		  log_info ("xid: rand init seed (0x%x) built using gethostid",
bd3a57
+			    seed);
bd3a57
+		}
bd3a57
+		/* we only use seed and no current time as a broadcast reply */
bd3a57
+		/* will certainly be used by the hwaddrless interface */
83597a
+		srandom(seed + ((unsigned)(cur_tv.tv_usec * 1000000)) + (unsigned)getpid());
bd3a57
+	}
bd3a57
+	else
83597a
+	        srandom(seed + ((unsigned)(cur_tv.tv_usec * 1000000)) + (unsigned)getpid());
bd3a57
 
bd3a57
 	/* Setup specific Infiniband options */
bd3a57
 	for (ip = interfaces; ip; ip = ip->next) {
83597a
@@ -1491,7 +1533,7 @@ void dhcpack (packet)
bd3a57
 		return;
bd3a57
 	}
bd3a57
 
bd3a57
-	log_info ("DHCPACK from %s", piaddr (packet -> client_addr));
96d5a6
+	log_info ("DHCPACK from %s (xid=0x%x)", piaddr (packet -> client_addr), ntohl(client -> xid));
bd3a57
 
bd3a57
 	lease = packet_to_lease (packet, client);
bd3a57
 	if (!lease) {
83597a
@@ -2211,7 +2253,7 @@ void dhcpnak (packet)
bd3a57
 		return;
bd3a57
 	}
bd3a57
 
bd3a57
-	log_info ("DHCPNAK from %s", piaddr (packet -> client_addr));
96d5a6
+	log_info ("DHCPNAK from %s (xid=0x%x)", piaddr (packet -> client_addr), ntohl(client -> xid));
bd3a57
 
bd3a57
 	if (!client -> active) {
bd3a57
 #if defined (DEBUG)
83597a
@@ -2338,10 +2380,10 @@ void send_discover (cpp)
bd3a57
 		client -> packet.secs = htons (65535);
bd3a57
 	client -> secs = client -> packet.secs;
bd3a57
 
bd3a57
-	log_info ("DHCPDISCOVER on %s to %s port %d interval %ld",
bd3a57
+	log_info ("DHCPDISCOVER on %s to %s port %d interval %ld (xid=0x%x)",
bd3a57
 	      client -> name ? client -> name : client -> interface -> name,
bd3a57
 	      inet_ntoa (sockaddr_broadcast.sin_addr),
bd3a57
-	      ntohs (sockaddr_broadcast.sin_port), (long)(client -> interval));
96d5a6
+	      ntohs (sockaddr_broadcast.sin_port), (long)(client -> interval), ntohl(client -> xid));
bd3a57
 
bd3a57
 	/* Send out a packet. */
d5d042
 	result = send_packet(client->interface, NULL, &client->packet,
83597a
@@ -2610,10 +2652,10 @@ void send_request (cpp)
bd3a57
 			client -> packet.secs = htons (65535);
bd3a57
 	}
bd3a57
 
bd3a57
-	log_info ("DHCPREQUEST on %s to %s port %d",
bd3a57
+	log_info ("DHCPREQUEST on %s to %s port %d (xid=0x%x)",
bd3a57
 	      client -> name ? client -> name : client -> interface -> name,
bd3a57
 	      inet_ntoa (destination.sin_addr),
bd3a57
-	      ntohs (destination.sin_port));
96d5a6
+	      ntohs (destination.sin_port), ntohl(client -> xid));
bd3a57
 
bd3a57
 	if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
d5d042
 	    fallback_interface) {
83597a
@@ -2653,10 +2695,10 @@ void send_decline (cpp)
bd3a57
 
bd3a57
 	int result;
bd3a57
 
bd3a57
-	log_info ("DHCPDECLINE on %s to %s port %d",
bd3a57
+	log_info ("DHCPDECLINE on %s to %s port %d (xid=0x%x)",
d5d042
 	      client->name ? client->name : client->interface->name,
d5d042
 	      inet_ntoa(sockaddr_broadcast.sin_addr),
d5d042
-	      ntohs(sockaddr_broadcast.sin_port));
96d5a6
+	      ntohs(sockaddr_broadcast.sin_port), ntohl(client -> xid));
bd3a57
 
bd3a57
 	/* Send out a packet. */
d5d042
 	result = send_packet(client->interface, NULL, &client->packet,
83597a
@@ -2699,10 +2741,10 @@ void send_release (cpp)
bd3a57
 		return;
bd3a57
 	}
bd3a57
 
bd3a57
-	log_info ("DHCPRELEASE on %s to %s port %d",
bd3a57
+	log_info ("DHCPRELEASE on %s to %s port %d (xid=0x%x)",
bd3a57
 	      client -> name ? client -> name : client -> interface -> name,
bd3a57
 	      inet_ntoa (destination.sin_addr),
bd3a57
-	      ntohs (destination.sin_port));
96d5a6
+	      ntohs (destination.sin_port), ntohl(client -> xid));
bd3a57
 
d5d042
 	if (fallback_interface) {
d5d042
 		result = send_packet(fallback_interface, NULL, &client->packet,