Blame SOURCES/dhcp-improved-xid.patch

324fcf
diff -up dhcp-4.3.4/client/dhclient.c.improved-xid dhcp-4.3.4/client/dhclient.c
324fcf
--- dhcp-4.3.4/client/dhclient.c.improved-xid	2016-04-29 12:54:55.997102182 +0200
324fcf
+++ dhcp-4.3.4/client/dhclient.c	2016-04-29 12:57:25.123139587 +0200
324fcf
@@ -1045,6 +1045,26 @@ main(int argc, char **argv) {
324fcf
 		}
324fcf
 	}
324fcf
 
324fcf
+	/* We create a backup seed before rediscovering interfaces in order to
324fcf
+	   have a seed built using all of the available interfaces
324fcf
+	   It's interesting if required interfaces doesn't let us defined
324fcf
+	   a really unique seed due to a lack of valid HW addr later
324fcf
+	   (this is the case with DHCP over IB)
324fcf
+	   We only use the last device as using a sum could broke the
324fcf
+	   uniqueness of the seed among multiple nodes
324fcf
+	 */
324fcf
+	unsigned backup_seed = 0;
324fcf
+	for (ip = interfaces; ip; ip = ip -> next) {
324fcf
+		int junk;
324fcf
+		if ( ip -> hw_address.hlen <= sizeof seed )
324fcf
+		  continue;
324fcf
+		memcpy (&junk,
324fcf
+			&ip -> hw_address.hbuf [ip -> hw_address.hlen -
324fcf
+						sizeof seed], sizeof seed);
324fcf
+		backup_seed = junk;
324fcf
+	}
324fcf
+
324fcf
+
324fcf
 	/* At this point, all the interfaces that the script thinks
324fcf
 	   are relevant should be running, so now we once again call
324fcf
 	   discover_interfaces(), and this time ask it to actually set
324fcf
@@ -1059,14 +1079,36 @@ main(int argc, char **argv) {
324fcf
 	   Not much entropy, but we're booting, so we're not likely to
324fcf
 	   find anything better. */
324fcf
 	seed = 0;
324fcf
+	int seed_flag = 0;
324fcf
 	for (ip = interfaces; ip; ip = ip->next) {
324fcf
 		int junk;
324fcf
+		if ( ip -> hw_address.hlen <= sizeof seed )
324fcf
+		  continue;
324fcf
 		memcpy(&junk,
324fcf
 		       &ip->hw_address.hbuf[ip->hw_address.hlen -
324fcf
 					    sizeof seed], sizeof seed);
324fcf
 		seed += junk;
324fcf
+		seed_flag = 1;
324fcf
 	}
324fcf
-	srandom(seed + cur_time + (unsigned)getpid());
324fcf
+	if ( seed_flag == 0 ) {
324fcf
+		if ( backup_seed != 0 ) {
324fcf
+		  seed = backup_seed;
324fcf
+		  log_info ("xid: rand init seed (0x%x) built using all"
324fcf
+			    " available interfaces",seed);
324fcf
+		}
324fcf
+		else {
324fcf
+		  seed = cur_time^((unsigned) gethostid()) ;
324fcf
+		  log_info ("xid: warning: no netdev with useable HWADDR found"
324fcf
+			    " for seed's uniqueness enforcement");
324fcf
+		  log_info ("xid: rand init seed (0x%x) built using gethostid",
324fcf
+			    seed);
324fcf
+		}
324fcf
+		/* we only use seed and no current time as a broadcast reply */
324fcf
+		/* will certainly be used by the hwaddrless interface */
324fcf
+		srandom(seed + ((unsigned)(cur_tv.tv_usec * 1000000)) + (unsigned)getpid());
324fcf
+	}
324fcf
+	else
324fcf
+	        srandom(seed + ((unsigned)(cur_tv.tv_usec * 1000000)) + (unsigned)getpid());
324fcf
 
324fcf
 	/* Setup specific Infiniband options */
324fcf
 	for (ip = interfaces; ip; ip = ip->next) {
324fcf
@@ -1633,7 +1675,7 @@ void dhcpack (packet)
324fcf
 		return;
324fcf
 	}
324fcf
 
324fcf
-	log_info ("DHCPACK from %s", piaddr (packet -> client_addr));
324fcf
+	log_info ("DHCPACK from %s (xid=0x%x)", piaddr (packet -> client_addr), ntohl(client -> xid));
324fcf
 
324fcf
 	lease = packet_to_lease (packet, client);
324fcf
 	if (!lease) {
324fcf
@@ -2541,7 +2583,7 @@ void dhcpnak (packet)
324fcf
 		return;
324fcf
 	}
324fcf
 
324fcf
-	log_info ("DHCPNAK from %s", piaddr (packet -> client_addr));
324fcf
+	log_info ("DHCPNAK from %s (xid=0x%x)", piaddr (packet -> client_addr), ntohl(client -> xid));
324fcf
 
324fcf
 	if (!client -> active) {
324fcf
 #if defined (DEBUG)
324fcf
@@ -2674,10 +2716,10 @@ void send_discover (cpp)
324fcf
 			  (long)(client -> interval));
324fcf
 	} else
324fcf
 #endif
324fcf
-	log_info ("DHCPDISCOVER on %s to %s port %d interval %ld",
324fcf
+	log_info ("DHCPDISCOVER on %s to %s port %d interval %ld (xid=0x%x)",
324fcf
 	      client -> name ? client -> name : client -> interface -> name,
324fcf
 	      inet_ntoa (sockaddr_broadcast.sin_addr),
324fcf
-	      ntohs (sockaddr_broadcast.sin_port), (long)(client -> interval));
324fcf
+	      ntohs (sockaddr_broadcast.sin_port), (long)(client -> interval), ntohl(client -> xid));
324fcf
 
324fcf
 	/* Send out a packet. */
324fcf
 #if defined(DHCPv6) && defined(DHCP4o6)
324fcf
@@ -2962,10 +3004,10 @@ void send_request (cpp)
324fcf
 		log_info ("DHCPREQUEST");
324fcf
 	} else
324fcf
 #endif
324fcf
-	log_info ("DHCPREQUEST on %s to %s port %d",
324fcf
+	log_info ("DHCPREQUEST on %s to %s port %d (xid=0x%x)",
324fcf
 	      client -> name ? client -> name : client -> interface -> name,
324fcf
 	      inet_ntoa (destination.sin_addr),
324fcf
-	      ntohs (destination.sin_port));
324fcf
+	      ntohs (destination.sin_port), ntohl(client -> xid));
324fcf
 
324fcf
 #if defined(DHCPv6) && defined(DHCP4o6)
324fcf
 	if (dhcpv4_over_dhcpv6) {
324fcf
@@ -3022,10 +3064,10 @@ void send_decline (cpp)
324fcf
 		log_info ("DHCPDECLINE");
324fcf
 	} else
324fcf
 #endif
324fcf
-	log_info ("DHCPDECLINE on %s to %s port %d",
324fcf
+	log_info ("DHCPDECLINE on %s to %s port %d (xid=0x%x)",
324fcf
 	      client->name ? client->name : client->interface->name,
324fcf
 	      inet_ntoa(sockaddr_broadcast.sin_addr),
324fcf
-	      ntohs(sockaddr_broadcast.sin_port));
324fcf
+	      ntohs(sockaddr_broadcast.sin_port), ntohl(client -> xid));
324fcf
 
324fcf
 	/* Send out a packet. */
324fcf
 #if defined(DHCPv6) && defined(DHCP4o6)
324fcf
@@ -3084,10 +3126,10 @@ void send_release (cpp)
324fcf
 		log_info ("DHCPRELEASE");
324fcf
 	} else
324fcf
 #endif
324fcf
-	log_info ("DHCPRELEASE on %s to %s port %d",
324fcf
+	log_info ("DHCPRELEASE on %s to %s port %d (xid=0x%x)",
324fcf
 	      client -> name ? client -> name : client -> interface -> name,
324fcf
 	      inet_ntoa (destination.sin_addr),
324fcf
-	      ntohs (destination.sin_port));
324fcf
+	      ntohs (destination.sin_port), ntohl(client -> xid));
324fcf
 
324fcf
 #if defined(DHCPv6) && defined(DHCP4o6)
324fcf
 	if (dhcpv4_over_dhcpv6) {