philipp / rpms / dhcp

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