philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

Blame SOURCES/dhcp-4.2.4-improved-xid.patch

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