philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

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

26a25c
--- a/server/dhcp.c     2017-07-14 15:32:14.611104590 +0200
26a25c
+++ b/server/dhcp.c	2017-07-14 15:34:17.508858018 +0200
26a25c
@@ -87,6 +87,42 @@
26a25c
 
26a25c
 static TIME leaseTimeCheck(TIME calculated, TIME alternate);
26a25c
 
26a25c
+char *print_client_identifier_from_packet (packet)
26a25c
+	struct packet *packet;
26a25c
+{
26a25c
+	struct option_cache *oc;
26a25c
+	struct data_string client_identifier;
26a25c
+	char *ci;
26a25c
+
26a25c
+	memset (&client_identifier, 0, sizeof client_identifier);
26a25c
+
26a25c
+	oc = lookup_option (&dhcp_universe, packet -> options,
26a25c
+			DHO_DHCP_CLIENT_IDENTIFIER);
26a25c
+	if (oc &&
26a25c
+	    evaluate_option_cache (&client_identifier,
26a25c
+				    packet, (struct lease *)0,
26a25c
+				    (struct client_state *)0,
26a25c
+				    packet -> options,
26a25c
+				    (struct option_state *)0,
26a25c
+				    &global_scope, oc, MDL)) {
26a25c
+		ci = print_hw_addr (HTYPE_INFINIBAND, client_identifier.len, client_identifier.data);
26a25c
+		data_string_forget (&client_identifier, MDL);
26a25c
+		return ci;
26a25c
+	} else
26a25c
+		return "\"no client id\"";
26a25c
+}
26a25c
+
26a25c
+char *print_hw_addr_or_client_id (packet)
26a25c
+	struct packet *packet;
26a25c
+{
26a25c
+	if (packet -> raw -> htype == HTYPE_INFINIBAND)
26a25c
+		return print_client_identifier_from_packet (packet);
26a25c
+	else
26a25c
+		return print_hw_addr (packet -> raw -> htype,
26a25c
+				      packet -> raw -> hlen,
26a25c
+				      packet -> raw -> chaddr);
26a25c
+}
26a25c
+
26a25c
 void
26a25c
 dhcp (struct packet *packet) {
26a25c
 	int ms_nulltp = 0;
26a25c
@@ -129,9 +165,7 @@
26a25c
 
26a25c
 		log_info("%s from %s via %s: %s", s,
26a25c
 			 (packet->raw->htype
26a25c
-			  ? print_hw_addr(packet->raw->htype,
26a25c
-					  packet->raw->hlen,
26a25c
-					  packet->raw->chaddr)
26a25c
+			  ? print_hw_addr_or_client_id(packet)
26a25c
 			  : "<no identifier>"),
26a25c
 			 packet->raw->giaddr.s_addr
26a25c
 			 ? inet_ntoa(packet->raw->giaddr)
26a25c
@@ -328,9 +362,7 @@
26a25c
 #endif
26a25c
 	snprintf (msgbuf, sizeof msgbuf, "DHCPDISCOVER from %s %s%s%svia %s",
26a25c
 		 (packet -> raw -> htype
26a25c
-		  ? print_hw_addr (packet -> raw -> htype,
26a25c
-				   packet -> raw -> hlen,
26a25c
-				   packet -> raw -> chaddr)
26a25c
+		  ? print_hw_addr_or_client_id (packet)
26a25c
 		  : (lease
26a25c
 		     ? print_hex_1(lease->uid_len, lease->uid, 60)
26a25c
 		     : "<no identifier>")),
26a25c
@@ -542,9 +574,7 @@
26a25c
 		 "DHCPREQUEST for %s%s from %s %s%s%svia %s",
26a25c
 		 piaddr (cip), smbuf,
26a25c
 		 (packet -> raw -> htype
26a25c
-		  ? print_hw_addr (packet -> raw -> htype,
26a25c
-				   packet -> raw -> hlen,
26a25c
-				   packet -> raw -> chaddr)
26a25c
+		  ? print_hw_addr_or_client_id(packet)
26a25c
 		  : (lease
26a25c
 		     ? print_hex_1(lease->uid_len, lease->uid, 60)
26a25c
 		     : "<no identifier>")),
26a25c
@@ -785,9 +815,7 @@
26a25c
 	if ((oc = lookup_option (&dhcp_universe, packet -> options,
26a25c
 				 DHO_DHCP_REQUESTED_ADDRESS))) {
26a25c
 		log_info ("DHCPRELEASE from %s specified requested-address.",
26a25c
-		      print_hw_addr (packet -> raw -> htype,
26a25c
-				     packet -> raw -> hlen,
26a25c
-				     packet -> raw -> chaddr));
26a25c
+		      print_hw_addr_or_client_id(packet));
26a25c
 	}
26a25c
 
26a25c
 	oc = lookup_option (&dhcp_universe, packet -> options,
26a25c
@@ -879,9 +907,7 @@
26a25c
 		 "DHCPRELEASE of %s from %s %s%s%svia %s (%sfound)",
26a25c
 		 cstr,
26a25c
 		 (packet -> raw -> htype
26a25c
-		  ? print_hw_addr (packet -> raw -> htype,
26a25c
-				   packet -> raw -> hlen,
26a25c
-				   packet -> raw -> chaddr)
26a25c
+		  ? print_hw_addr_or_client_id(packet)
26a25c
 		  : (lease
26a25c
 		     ? print_hex_1(lease->uid_len, lease->uid, 60)
26a25c
 		     : "<no identifier>")),
26a25c
@@ -986,9 +1012,7 @@
26a25c
 		 "DHCPDECLINE of %s from %s %s%s%svia %s",
26a25c
 		 piaddr (cip),
26a25c
 		 (packet -> raw -> htype
26a25c
-		  ? print_hw_addr (packet -> raw -> htype,
26a25c
-				   packet -> raw -> hlen,
26a25c
-				   packet -> raw -> chaddr)
26a25c
+		  ? print_hw_addr_or_client_id(packet)
26a25c
 		  : (lease
26a25c
 		     ? print_hex_1(lease->uid_len, lease->uid, 60)
26a25c
 		     : "<no identifier>")),
26a25c
@@ -1707,8 +1731,7 @@
26a25c
 	/* Report what we're sending. */
26a25c
 	snprintf(msgbuf, sizeof msgbuf, "DHCPACK to %s (%s) via", piaddr(cip),
26a25c
 		 (packet->raw->htype && packet->raw->hlen) ?
26a25c
-			print_hw_addr(packet->raw->htype, packet->raw->hlen,
26a25c
-				      packet->raw->chaddr) :
26a25c
+			print_hw_addr_or_client_id(packet) :
26a25c
 			"<no client hardware address>");
26a25c
 	log_info("%s %s", msgbuf, gip.len ? piaddr(gip) :
26a25c
 					    packet->interface->name);
26a25c
@@ -1886,9 +1909,7 @@
26a25c
 #endif
26a25c
 	log_info ("DHCPNAK on %s to %s via %s",
26a25c
 	      piaddr (*cip),
26a25c
-	      print_hw_addr (packet -> raw -> htype,
26a25c
-			     packet -> raw -> hlen,
26a25c
-			     packet -> raw -> chaddr),
26a25c
+	      print_hw_addr_or_client_id(packet),
26a25c
 	      packet -> raw -> giaddr.s_addr
26a25c
 	      ? inet_ntoa (packet -> raw -> giaddr)
26a25c
 	      : packet -> interface -> name);
26a25c
@@ -3897,7 +3918,7 @@
26a25c
 		   ? (state -> offer == DHCPACK ? "DHCPACK" : "DHCPOFFER")
26a25c
 		   : "BOOTREPLY"),
26a25c
 		  piaddr (lease -> ip_addr),
26a25c
-		  (lease -> hardware_addr.hlen
26a25c
+		  (lease -> hardware_addr.hlen > 1
26a25c
 		   ? print_hw_addr (lease -> hardware_addr.hbuf [0],
26a25c
 				    lease -> hardware_addr.hlen - 1,
26a25c
 				    &lease -> hardware_addr.hbuf [1])
26a25c
@@ -4450,10 +4471,7 @@
26a25c
 			if (uid_lease) {
26a25c
 			    if (uid_lease->binding_state == FTS_ACTIVE) {
26a25c
 				log_error ("client %s has duplicate%s on %s",
26a25c
-					   (print_hw_addr
26a25c
-					    (packet -> raw -> htype,
26a25c
-					     packet -> raw -> hlen,
26a25c
-					     packet -> raw -> chaddr)),
26a25c
+					   (print_hw_addr_or_client_id(packet)),
26a25c
 					   " leases",
26a25c
 					   (ip_lease -> subnet ->
26a25c
 					    shared_network -> name));
26a25c
@@ -4620,9 +4638,7 @@
26a25c
 			log_error("uid lease %s for client %s is duplicate "
26a25c
 				  "on %s",
26a25c
 				  piaddr(uid_lease->ip_addr),
26a25c
-				  print_hw_addr(packet->raw->htype,
26a25c
-						packet->raw->hlen,
26a25c
-						packet->raw->chaddr),
26a25c
+				  print_hw_addr_or_client_id(packet),
26a25c
 				  uid_lease->subnet->shared_network->name);
26a25c
 
26a25c
 			if (!packet -> raw -> ciaddr.s_addr &&