Blame SOURCES/dhcp-IPoIB-log-id.patch

54343e
diff -up dhcp-4.2.5/server/dhcp.c.IPoIB-log-id dhcp-4.2.5/server/dhcp.c
54343e
--- dhcp-4.2.5/server/dhcp.c.IPoIB-log-id	2014-09-08 14:50:39.000000000 +0200
54343e
+++ dhcp-4.2.5/server/dhcp.c	2014-09-08 15:06:28.367697349 +0200
54343e
@@ -80,6 +80,42 @@ const int dhcp_type_name_max = ((sizeof
54343e
 # define send_packet trace_packet_send
54343e
 #endif
54343e
 
54343e
+char *print_client_identifier_from_packet (packet)
54343e
+	struct packet *packet;
54343e
+{
54343e
+	struct option_cache *oc;
54343e
+	struct data_string client_identifier;
54343e
+	char *ci;
54343e
+
54343e
+	memset (&client_identifier, 0, sizeof client_identifier);
54343e
+
54343e
+	oc = lookup_option (&dhcp_universe, packet -> options,
54343e
+			DHO_DHCP_CLIENT_IDENTIFIER);
54343e
+	if (oc &&
54343e
+	    evaluate_option_cache (&client_identifier,
54343e
+				    packet, (struct lease *)0,
54343e
+				    (struct client_state *)0,
54343e
+				    packet -> options,
54343e
+				    (struct option_state *)0,
54343e
+				    &global_scope, oc, MDL)) {
54343e
+		ci = print_hw_addr (HTYPE_INFINIBAND, client_identifier.len, client_identifier.data);
54343e
+		data_string_forget (&client_identifier, MDL);
54343e
+		return ci;
54343e
+	} else
54343e
+		return "\"no client id\"";
54343e
+}
54343e
+
54343e
+char *print_hw_addr_or_client_id (packet)
54343e
+	struct packet *packet;
54343e
+{
54343e
+	if (packet -> raw -> htype == HTYPE_INFINIBAND)
54343e
+		return print_client_identifier_from_packet (packet);
54343e
+	else
54343e
+		return print_hw_addr (packet -> raw -> htype,
54343e
+				      packet -> raw -> hlen,
54343e
+				      packet -> raw -> chaddr);
54343e
+}
54343e
+
54343e
 void
54343e
 dhcp (struct packet *packet) {
54343e
 	int ms_nulltp = 0;
54343e
@@ -108,9 +144,7 @@ dhcp (struct packet *packet) {
54343e
 		
54343e
 		log_info("%s from %s via %s: %s", s,
54343e
 			 (packet->raw->htype
54343e
-			  ? print_hw_addr(packet->raw->htype,
54343e
-					  packet->raw->hlen,
54343e
-					  packet->raw->chaddr)
54343e
+			  ? print_hw_addr_or_client_id (packet)
54343e
 			  : "<no identifier>"),
54343e
 			 packet->raw->giaddr.s_addr
54343e
 			 ? inet_ntoa(packet->raw->giaddr)
54343e
@@ -294,9 +328,7 @@ void dhcpdiscover (packet, ms_nulltp)
54343e
 	 */
54343e
 	snprintf (msgbuf, sizeof msgbuf, "DHCPDISCOVER from %s %s%s%svia %s",
54343e
 		 (packet -> raw -> htype
54343e
-		  ? print_hw_addr (packet -> raw -> htype,
54343e
-				   packet -> raw -> hlen,
54343e
-				   packet -> raw -> chaddr)
54343e
+		  ? print_hw_addr_or_client_id (packet)
54343e
 		  : (lease
54343e
 		     ? print_hex_1(lease->uid_len, lease->uid, 60)
54343e
 		     : "<no identifier>")),
54343e
@@ -490,9 +522,7 @@ void dhcprequest (packet, ms_nulltp, ip_
54343e
 		 "DHCPREQUEST for %s%s from %s %s%s%svia %s",
54343e
 		 piaddr (cip), smbuf,
54343e
 		 (packet -> raw -> htype
54343e
-		  ? print_hw_addr (packet -> raw -> htype,
54343e
-				   packet -> raw -> hlen,
54343e
-				   packet -> raw -> chaddr)
54343e
+		  ? print_hw_addr_or_client_id (packet)
54343e
 		  : (lease
54343e
 		     ? print_hex_1(lease->uid_len, lease->uid, 60)
54343e
 		     : "<no identifier>")),
54343e
@@ -735,9 +765,7 @@ void dhcprelease (packet, ms_nulltp)
54343e
 	if ((oc = lookup_option (&dhcp_universe, packet -> options,
54343e
 				 DHO_DHCP_REQUESTED_ADDRESS))) {
54343e
 		log_info ("DHCPRELEASE from %s specified requested-address.",
54343e
-		      print_hw_addr (packet -> raw -> htype,
54343e
-				     packet -> raw -> hlen,
54343e
-				     packet -> raw -> chaddr));
54343e
+		      print_hw_addr_or_client_id (packet));
54343e
 	}
54343e
 
54343e
 	oc = lookup_option (&dhcp_universe, packet -> options,
54343e
@@ -811,9 +839,7 @@ void dhcprelease (packet, ms_nulltp)
54343e
 		 "DHCPRELEASE of %s from %s %s%s%svia %s (%sfound)",
54343e
 		 cstr,
54343e
 		 (packet -> raw -> htype
54343e
-		  ? print_hw_addr (packet -> raw -> htype,
54343e
-				   packet -> raw -> hlen,
54343e
-				   packet -> raw -> chaddr)
54343e
+		  ? print_hw_addr_or_client_id (packet)
54343e
 		  : (lease
54343e
 		     ? print_hex_1(lease->uid_len, lease->uid, 60)
54343e
 		     : "<no identifier>")),
54343e
@@ -906,9 +932,7 @@ void dhcpdecline (packet, ms_nulltp)
54343e
 		 "DHCPDECLINE of %s from %s %s%s%svia %s",
54343e
 		 piaddr (cip),
54343e
 		 (packet -> raw -> htype
54343e
-		  ? print_hw_addr (packet -> raw -> htype,
54343e
-				   packet -> raw -> hlen,
54343e
-				   packet -> raw -> chaddr)
54343e
+		  ? print_hw_addr_or_client_id(packet)
54343e
 		  : (lease
54343e
 		     ? print_hex_1(lease->uid_len, lease->uid, 60)
54343e
 		     : "<no identifier>")),
54343e
@@ -1348,8 +1372,7 @@ void dhcpinform (packet, ms_nulltp)
54343e
 	/* Report what we're sending. */
54343e
 	snprintf(msgbuf, sizeof msgbuf, "DHCPACK to %s (%s) via", piaddr(cip),
54343e
 		 (packet->raw->htype && packet->raw->hlen) ?
54343e
-			print_hw_addr(packet->raw->htype, packet->raw->hlen,
54343e
-				      packet->raw->chaddr) :
54343e
+			print_hw_addr_or_client_id(packet) :
54343e
 			"<no client hardware address>");
54343e
 	log_info("%s %s", msgbuf, gip.len ? piaddr(gip) :
54343e
 					    packet->interface->name);
54343e
@@ -1493,9 +1516,7 @@ void nak_lease (packet, cip)
54343e
 	/* Report what we're sending... */
54343e
 	log_info ("DHCPNAK on %s to %s via %s",
54343e
 	      piaddr (*cip),
54343e
-	      print_hw_addr (packet -> raw -> htype,
54343e
-			     packet -> raw -> hlen,
54343e
-			     packet -> raw -> chaddr),
54343e
+	      print_hw_addr_or_client_id (packet),
54343e
 	      packet -> raw -> giaddr.s_addr
54343e
 	      ? inet_ntoa (packet -> raw -> giaddr)
54343e
 	      : packet -> interface -> name);
54343e
@@ -3214,7 +3235,7 @@ void dhcp_reply (lease)
54343e
 		   ? (state -> offer == DHCPACK ? "DHCPACK" : "DHCPOFFER")
54343e
 		   : "BOOTREPLY"),
54343e
 		  piaddr (lease -> ip_addr),
54343e
-		  (lease -> hardware_addr.hlen
54343e
+		  (lease -> hardware_addr.hlen > 1
54343e
 		   ? print_hw_addr (lease -> hardware_addr.hbuf [0],
54343e
 				    lease -> hardware_addr.hlen - 1,
54343e
 				    &lease -> hardware_addr.hbuf [1])
54343e
@@ -3772,10 +3793,7 @@ int find_lease (struct lease **lp,
54343e
 			if (uid_lease) {
54343e
 			    if (uid_lease->binding_state == FTS_ACTIVE) {
54343e
 				log_error ("client %s has duplicate%s on %s",
54343e
-					   (print_hw_addr
54343e
-					    (packet -> raw -> htype,
54343e
-					     packet -> raw -> hlen,
54343e
-					     packet -> raw -> chaddr)),
54343e
+					   (print_hw_addr_or_client_id(packet)),
54343e
 					   " leases",
54343e
 					   (ip_lease -> subnet ->
54343e
 					    shared_network -> name));
54343e
@@ -3942,9 +3960,7 @@ int find_lease (struct lease **lp,
54343e
 			log_error("uid lease %s for client %s is duplicate "
54343e
 				  "on %s",
54343e
 				  piaddr(uid_lease->ip_addr),
54343e
-				  print_hw_addr(packet->raw->htype,
54343e
-						packet->raw->hlen,
54343e
-						packet->raw->chaddr),
54343e
+				  print_hw_addr_or_client_id(packet),
54343e
 				  uid_lease->subnet->shared_network->name);
54343e
 
54343e
 			if (!packet -> raw -> ciaddr.s_addr &&