philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

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

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