Blame SOURCES/0023-option-97-pxe-client-id.patch

df4638
From 6fd7894ea57791c8eee16c21d19da34b909e016e Mon Sep 17 00:00:00 2001
df4638
From: Pavel Zhukov <pzhukov@redhat.com>
df4638
Date: Thu, 28 Feb 2019 16:40:38 +0100
df4638
Subject: [PATCH 23/26] option 97 - pxe-client-id
df4638
Cc: pzhukov@redhat.com
df4638
df4638
Bug-url: https://bugzilla.redhat.com/1058674
df4638
ISC-Bugs #38110
df4638
---
df4638
 common/options.c        | 27 ++++++++++++++++++++-------
df4638
 common/tables.c         |  3 ++-
df4638
 includes/dhcp.h         |  1 +
df4638
 server/dhcp.c           | 19 +++++++++++++++++++
df4638
 server/dhcpd.conf.5     |  9 ++++++---
df4638
 server/dhcpleasequery.c | 18 +++++++++++++++---
df4638
 server/failover.c       |  3 +++
df4638
 server/mdb.c            |  5 +++--
df4638
 8 files changed, 69 insertions(+), 16 deletions(-)
df4638
df4638
diff --git a/common/options.c b/common/options.c
df4638
index 3034cf0..686dd12 100644
df4638
--- a/common/options.c
df4638
+++ b/common/options.c
df4638
@@ -4465,13 +4465,26 @@ int validate_packet(struct packet *packet)
df4638
 				"a future version of ISC DHCP will reject this");
df4638
 		}
df4638
 	} else {
df4638
-		/*
df4638
-		 * If hlen is 0 we don't have any identifier, we warn the user
df4638
-		 * but continue processing the packet as we can.
df4638
-		 */
df4638
-		if (packet->raw->hlen == 0) {
df4638
-			log_debug("Received DHCPv4 packet without client-id"
df4638
-				  " option and empty hlen field.");
df4638
+		oc = lookup_option (&dhcp_universe, packet->options,
df4638
+				    DHO_PXE_CLIENT_ID);
df4638
+		if (oc) {
df4638
+			/* Let's check if pxe-client-id is sane */
df4638
+			if ((oc->data.len < 2) ||
df4638
+			    (oc->data.data[0] == '\0' &&
df4638
+			     oc->data.len != 17)) {
df4638
+				log_debug("Dropped DHCPv4 packet with wrong "
df4638
+				    "(len == %d) pxe-client-id", oc->data.len);
df4638
+				return (0);
df4638
+			}
df4638
+		} else {
df4638
+			/*
df4638
+			 * If hlen is 0 we don't have any identifier, we warn the user
df4638
+			 * but continue processing the packet as we can.
df4638
+			 */
df4638
+			if (packet->raw->hlen == 0) {
df4638
+				log_debug("Received DHCPv4 packet without client-id"
df4638
+						" option and empty hlen field.");
df4638
+			}
df4638
 		}
df4638
 	}
df4638
 
df4638
diff --git a/common/tables.c b/common/tables.c
df4638
index f1be07d..4419220 100644
df4638
--- a/common/tables.c
df4638
+++ b/common/tables.c
df4638
@@ -196,8 +196,9 @@ static struct option dhcp_options[] = {
df4638
 	/* Defined by RFC 4578 */
df4638
 	{ "pxe-system-type", "Sa",		&dhcp_universe,  93, 1 },
df4638
 	{ "pxe-interface-id", "BBB",		&dhcp_universe,  94, 1 },
df4638
-	{ "pxe-client-id", "BX",		&dhcp_universe,  97, 1 },
df4638
 #endif
df4638
+	{ "pxe-client-id", "BX",		&dhcp_universe,  97, 1 },
df4638
+
df4638
 	{ "uap-servers", "t",			&dhcp_universe,  98, 1 },
df4638
 #if defined(RFC4776_OPTIONS)
df4638
         { "geoconf-civic", "X",                 &dhcp_universe, 99, 1 },
df4638
diff --git a/includes/dhcp.h b/includes/dhcp.h
df4638
index 4cc547a..4eb9791 100644
df4638
--- a/includes/dhcp.h
df4638
+++ b/includes/dhcp.h
df4638
@@ -158,6 +158,7 @@ struct dhcp_packet {
df4638
 #define DHO_AUTHENTICATE			90  /* RFC3118, was 210 */
df4638
 #define DHO_CLIENT_LAST_TRANSACTION_TIME	91
df4638
 #define DHO_ASSOCIATED_IP			92
df4638
+#define DHO_PXE_CLIENT_ID			97  /* RFC4578 */
df4638
 #define DHO_SUBNET_SELECTION			118 /* RFC3011! */
df4638
 #define DHO_DOMAIN_SEARCH			119 /* RFC3397 */
df4638
 #define DHO_CLASSLESS_STATIC_ROUTES		121 /* RFC3442 */
df4638
diff --git a/server/dhcp.c b/server/dhcp.c
df4638
index 0582c4c..4e86262 100644
df4638
--- a/server/dhcp.c
df4638
+++ b/server/dhcp.c
df4638
@@ -222,6 +222,10 @@ dhcp (struct packet *packet) {
df4638
 		if (lease -> uid_len) {
df4638
 			oc = lookup_option (&dhcp_universe, packet -> options,
df4638
 					    DHO_DHCP_CLIENT_IDENTIFIER);
df4638
+			if (!oc)
df4638
+				oc = lookup_option (&dhcp_universe,
df4638
+						    packet -> options,
df4638
+						    DHO_PXE_CLIENT_ID);
df4638
 			if (!oc)
df4638
 				goto nolease;
df4638
 
df4638
@@ -820,6 +824,9 @@ void dhcprelease (packet, ms_nulltp)
df4638
 
df4638
 	oc = lookup_option (&dhcp_universe, packet -> options,
df4638
 			    DHO_DHCP_CLIENT_IDENTIFIER);
df4638
+	if (!oc)
df4638
+		oc = lookup_option (&dhcp_universe, packet -> options,
df4638
+				    DHO_PXE_CLIENT_ID);
df4638
 	memset (&data, 0, sizeof data);
df4638
 	if (oc &&
df4638
 	    evaluate_option_cache (&data, packet, (struct lease *)0,
df4638
@@ -1331,6 +1338,9 @@ void dhcpinform (packet, ms_nulltp)
df4638
          */
df4638
 	oc = lookup_option(&dhcp_universe, packet->options,
df4638
 			   DHO_DHCP_CLIENT_IDENTIFIER);
df4638
+	if (!oc)
df4638
+		oc = lookup_option (&dhcp_universe, packet -> options,
df4638
+				    DHO_PXE_CLIENT_ID);
df4638
 	memset(&d1, 0, sizeof(d1));
df4638
 	if (oc &&
df4638
 	    evaluate_option_cache(&d1, packet, NULL, NULL,
df4638
@@ -2441,6 +2451,9 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp, hp)
df4638
 		   can be used. */
df4638
 		oc = lookup_option (&dhcp_universe, packet -> options,
df4638
 				    DHO_DHCP_CLIENT_IDENTIFIER);
df4638
+		if (!oc)
df4638
+			oc = lookup_option (&dhcp_universe, packet -> options,
df4638
+					    DHO_PXE_CLIENT_ID);
df4638
 		if (oc &&
df4638
 		    evaluate_option_cache (&d1, packet, lease,
df4638
 					   (struct client_state *)0,
df4638
@@ -3033,6 +3046,9 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp, hp)
df4638
 		/* Record the uid, if given... */
df4638
 		oc = lookup_option (&dhcp_universe, packet -> options,
df4638
 				    DHO_DHCP_CLIENT_IDENTIFIER);
df4638
+		if (!oc)
df4638
+			oc = lookup_option (&dhcp_universe, packet -> options,
df4638
+					    DHO_PXE_CLIENT_ID);
df4638
 		if (oc &&
df4638
 		    evaluate_option_cache(&d1, packet, lease, NULL,
df4638
 					  packet->options, state->options,
df4638
@@ -4150,6 +4166,9 @@ int find_lease (struct lease **lp,
df4638
 	   specified unique client identifier. */
df4638
 	oc = lookup_option (&dhcp_universe, packet -> options,
df4638
 			    DHO_DHCP_CLIENT_IDENTIFIER);
df4638
+	if (!oc)
df4638
+		oc = lookup_option (&dhcp_universe, packet -> options,
df4638
+				    DHO_PXE_CLIENT_ID);
df4638
 	memset (&client_identifier, 0, sizeof client_identifier);
df4638
 	if (oc &&
df4638
 	    evaluate_option_cache (&client_identifier,
df4638
diff --git a/server/dhcpd.conf.5 b/server/dhcpd.conf.5
df4638
index 89b5540..4751a8b 100644
df4638
--- a/server/dhcpd.conf.5
df4638
+++ b/server/dhcpd.conf.5
df4638
@@ -1664,10 +1664,12 @@ should be a name identifying the host.  If a \fIhostname\fR option is
df4638
 not specified for the host, \fIhostname\fR is used.
df4638
 .PP
df4638
 \fIHost\fR declarations are matched to actual DHCP or BOOTP clients
df4638
-by matching the \fRdhcp-client-identifier\fR option specified in the
df4638
+by matching the \fIdhcp-client-identifier\fR or \fIpxe-client-id\fR
df4638
+options specified in the
df4638
 \fIhost\fR declaration to the one supplied by the client, or, if the
df4638
 \fIhost\fR declaration or the client does not provide a
df4638
-\fRdhcp-client-identifier\fR option, by matching the \fIhardware\fR
df4638
+\fIdhcp-client-identifier\fR or \fIpxe-client-id\fR options,
df4638
+by matching the \fIhardware\fR
df4638
 parameter in the \fIhost\fR declaration to the network hardware
df4638
 address supplied by the client.  BOOTP clients do not normally
df4638
 provide a \fIdhcp-client-identifier\fR, so the hardware address must
df4638
@@ -1679,7 +1681,8 @@ to identify hosts.
df4638
 .PP
df4638
 Please be aware that
df4638
 .B only
df4638
-the \fIdhcp-client-identifier\fR option and the hardware address can be
df4638
+the \fIdhcp-client-identifier\fR and \fIpxe-client-id\fR
df4638
+options and the hardware address can be
df4638
 used to match a host declaration, or the \fIhost-identifier option\fR
df4638
 parameter for DHCPv6 servers.  For example, it is not possible to
df4638
 match a host declaration to a \fIhost-name\fR option.  This is
df4638
diff --git a/server/dhcpleasequery.c b/server/dhcpleasequery.c
df4638
index 7be0788..2fee698 100644
df4638
--- a/server/dhcpleasequery.c
df4638
+++ b/server/dhcpleasequery.c
df4638
@@ -276,7 +276,7 @@ dhcpleasequery(struct packet *packet, int ms_nulltp) {
df4638
 		 */
df4638
 
df4638
 		memset(&uid, 0, sizeof(uid));
df4638
-		if (get_option(&uid, 
df4638
+		i = get_option(&uid,
df4638
 			       &dhcp_universe,
df4638
 			       packet,
df4638
 			       NULL,
df4638
@@ -286,8 +286,20 @@ dhcpleasequery(struct packet *packet, int ms_nulltp) {
df4638
 			       packet->options, 
df4638
 			       &global_scope,
df4638
 			       DHO_DHCP_CLIENT_IDENTIFIER,
df4638
-			       MDL)) {
df4638
-
df4638
+			       MDL);
df4638
+		if (!i)
df4638
+			i = get_option(&uid,
df4638
+				       &dhcp_universe,
df4638
+				       packet,
df4638
+				       NULL,
df4638
+				       NULL,
df4638
+				       packet->options,
df4638
+				       NULL,
df4638
+				       packet->options,
df4638
+				       &global_scope,
df4638
+				       DHO_PXE_CLIENT_ID,
df4638
+				       MDL);
df4638
+		if (i) {
df4638
 			snprintf(dbg_info, 
df4638
 				 sizeof(dbg_info), 
df4638
 				 "client-id %s",
df4638
diff --git a/server/failover.c b/server/failover.c
df4638
index 72f7b00..40fa691 100644
df4638
--- a/server/failover.c
df4638
+++ b/server/failover.c
df4638
@@ -5988,6 +5988,9 @@ int load_balance_mine (struct packet *packet, dhcp_failover_state_t *state)
df4638
 
df4638
 	oc = lookup_option(&dhcp_universe, packet->options,
df4638
 			   DHO_DHCP_CLIENT_IDENTIFIER);
df4638
+	if (!oc)
df4638
+		oc = lookup_option(&dhcp_universe, packet -> options,
df4638
+				    DHO_PXE_CLIENT_ID);
df4638
 	memset(&ds, 0, sizeof ds);
df4638
 	if (oc &&
df4638
 	    evaluate_option_cache(&ds, packet, NULL, NULL,
df4638
diff --git a/server/mdb.c b/server/mdb.c
df4638
index 052df67..8851366 100644
df4638
--- a/server/mdb.c
df4638
+++ b/server/mdb.c
df4638
@@ -129,8 +129,9 @@ static int find_uid_statement (struct executable_statement *esp,
df4638
 	    esp -> data.option &&
df4638
 	    (esp -> data.option -> option -> universe ==
df4638
 	     &dhcp_universe) &&
df4638
-	    (esp -> data.option -> option -> code ==
df4638
-	     DHO_DHCP_CLIENT_IDENTIFIER)) {
df4638
+	    ((esp -> data.option -> option -> code ==
df4638
+						DHO_DHCP_CLIENT_IDENTIFIER) ||
df4638
+	     (esp -> data.option -> option -> code == DHO_PXE_CLIENT_ID))) {
df4638
 		if (condp) {
df4638
 			log_error ("dhcp client identifier may not be %s",
df4638
 				   "specified conditionally.");
df4638
-- 
df4638
2.14.5
df4638