philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

Blame SOURCES/dhcp-option97-pxe-client-id.patch

45d60a
diff -up dhcp-4.2.5/common/options.c.option97 dhcp-4.2.5/common/options.c
45d60a
--- dhcp-4.2.5/common/options.c.option97	2015-05-20 16:44:34.958765179 +0200
45d60a
+++ dhcp-4.2.5/common/options.c	2015-05-20 16:44:35.078763436 +0200
45d60a
@@ -4222,13 +4222,26 @@ int validate_packet(struct packet *packe
45d60a
 				"a future version of ISC DHCP will reject this");
45d60a
 		}
45d60a
 	} else {
45d60a
-		/* 
45d60a
-		 * If hlen is 0 we don't have any identifier, we warn the user
45d60a
-		 * but continue processing the packet as we can.
45d60a
-		 */
45d60a
-		if (packet->raw->hlen == 0) {
45d60a
-			log_debug("Received DHCPv4 packet without client-id"
45d60a
-				  " option and empty hlen field.");
45d60a
+		oc = lookup_option (&dhcp_universe, packet->options,
45d60a
+				    DHO_PXE_CLIENT_ID);
45d60a
+		if (oc) {
45d60a
+			/* Let's check if pxe-client-id is sane */
45d60a
+			if ((oc->data.len < 2) ||
45d60a
+			    (oc->data.data[0] == '\0' &&
45d60a
+			     oc->data.len != 17)) {
45d60a
+				log_debug("Dropped DHCPv4 packet with wrong "
45d60a
+				    "(len == %d) pxe-client-id", oc->data.len);
45d60a
+				return (0);
45d60a
+			}
45d60a
+		} else {
45d60a
+			/*
45d60a
+			 * If hlen is 0 we don't have any identifier, we warn the user
45d60a
+			 * but continue processing the packet as we can.
45d60a
+			 */
45d60a
+			if (packet->raw->hlen == 0) {
45d60a
+				log_debug("Received DHCPv4 packet without client-id"
45d60a
+						" option and empty hlen field.");
45d60a
+			}
45d60a
 		}
45d60a
 	}
45d60a
 
45d60a
diff -up dhcp-4.2.5/common/tables.c.option97 dhcp-4.2.5/common/tables.c
45d60a
--- dhcp-4.2.5/common/tables.c.option97	2015-05-20 16:44:35.079763422 +0200
45d60a
+++ dhcp-4.2.5/common/tables.c	2015-05-20 16:47:50.172931400 +0200
45d60a
@@ -203,8 +203,9 @@ static struct option dhcp_options[] = {
45d60a
 	/* Defined by RFC 4578 */
45d60a
 	{ "pxe-system-type", "S",		&dhcp_universe,  93, 1 },
45d60a
 	{ "pxe-interface-id", "BBB",		&dhcp_universe,  94, 1 },
45d60a
-	{ "pxe-client-id", "BX",		&dhcp_universe,  97, 1 },
45d60a
 #endif
45d60a
+	{ "pxe-client-id", "BX",		&dhcp_universe,  97, 1 },
45d60a
+
45d60a
 	{ "uap-servers", "t",			&dhcp_universe,  98, 1 },
45d60a
 	{ "netinfo-server-address", "Ia",	&dhcp_universe, 112, 1 },
45d60a
 	{ "netinfo-server-tag", "t",		&dhcp_universe, 113, 1 },
45d60a
diff -up dhcp-4.2.5/includes/dhcp.h.option97 dhcp-4.2.5/includes/dhcp.h
45d60a
--- dhcp-4.2.5/includes/dhcp.h.option97	2015-05-20 16:44:34.975764932 +0200
45d60a
+++ dhcp-4.2.5/includes/dhcp.h	2015-05-20 16:44:35.079763422 +0200
45d60a
@@ -163,6 +163,7 @@ struct dhcp_packet {
45d60a
 #define DHO_AUTHENTICATE			90  /* RFC3118, was 210 */
45d60a
 #define DHO_CLIENT_LAST_TRANSACTION_TIME	91
45d60a
 #define DHO_ASSOCIATED_IP			92
45d60a
+#define DHO_PXE_CLIENT_ID			97  /* RFC4578 */
45d60a
 #define DHO_SUBNET_SELECTION			118 /* RFC3011! */
45d60a
 #define DHO_DOMAIN_SEARCH			119 /* RFC3397 */
45d60a
 #define DHO_CLASSLESS_STATIC_ROUTES		121 /* RFC3442 */
45d60a
diff -up dhcp-4.2.5/server/dhcp.c.option97 dhcp-4.2.5/server/dhcp.c
45d60a
--- dhcp-4.2.5/server/dhcp.c.option97	2015-05-20 16:44:35.060763698 +0200
45d60a
+++ dhcp-4.2.5/server/dhcp.c	2015-05-20 16:51:26.718798033 +0200
45d60a
@@ -202,6 +205,10 @@ dhcp (struct packet *packet) {
45d60a
 			oc = lookup_option (&dhcp_universe, packet -> options,
45d60a
 					    DHO_DHCP_CLIENT_IDENTIFIER);
45d60a
 			if (!oc)
45d60a
+				oc = lookup_option (&dhcp_universe,
45d60a
+						    packet -> options,
45d60a
+						    DHO_PXE_CLIENT_ID);
45d60a
+			if (!oc)
45d60a
 				goto nolease;
45d60a
 
45d60a
 			memset (&data, 0, sizeof data);
45d60a
@@ -770,6 +777,9 @@ void dhcprelease (packet, ms_nulltp)
45d60a
 
45d60a
 	oc = lookup_option (&dhcp_universe, packet -> options,
45d60a
 			    DHO_DHCP_CLIENT_IDENTIFIER);
45d60a
+	if (!oc)
45d60a
+		oc = lookup_option (&dhcp_universe, packet -> options,
45d60a
+				    DHO_PXE_CLIENT_ID);
45d60a
 	memset (&data, 0, sizeof data);
45d60a
 	if (oc &&
45d60a
 	    evaluate_option_cache (&data, packet, (struct lease *)0,
45d60a
@@ -1841,6 +1851,9 @@ void ack_lease (packet, lease, offer, wh
45d60a
 		   can be used. */
45d60a
 		oc = lookup_option (&dhcp_universe, packet -> options,
45d60a
 				    DHO_DHCP_CLIENT_IDENTIFIER);
45d60a
+		if (!oc)
45d60a
+			oc = lookup_option (&dhcp_universe, packet -> options,
45d60a
+					    DHO_PXE_CLIENT_ID);
45d60a
 		if (oc &&
45d60a
 		    evaluate_option_cache (&d1, packet, lease,
45d60a
 					   (struct client_state *)0,
45d60a
@@ -2386,6 +2399,9 @@ void ack_lease (packet, lease, offer, wh
45d60a
 	/* Record the uid, if given... */
45d60a
 	oc = lookup_option (&dhcp_universe, packet -> options,
45d60a
 			    DHO_DHCP_CLIENT_IDENTIFIER);
45d60a
+	if (!oc)
45d60a
+		oc = lookup_option (&dhcp_universe, packet -> options,
45d60a
+				    DHO_PXE_CLIENT_ID);
45d60a
 	if (oc &&
45d60a
 	    evaluate_option_cache (&d1, packet, lease,
45d60a
 				   (struct client_state *)0,
45d60a
@@ -3429,6 +3445,9 @@ int find_lease (struct lease **lp,
45d60a
 	   specified unique client identifier. */
45d60a
 	oc = lookup_option (&dhcp_universe, packet -> options,
45d60a
 			    DHO_DHCP_CLIENT_IDENTIFIER);
45d60a
+	if (!oc)
45d60a
+		oc = lookup_option (&dhcp_universe, packet -> options,
45d60a
+				    DHO_PXE_CLIENT_ID);
45d60a
 	memset (&client_identifier, 0, sizeof client_identifier);
45d60a
 	if (oc &&
45d60a
 	    evaluate_option_cache (&client_identifier,
45d60a
diff -up dhcp-4.2.5/server/dhcpd.conf.5.option97 dhcp-4.2.5/server/dhcpd.conf.5
45d60a
--- dhcp-4.2.5/server/dhcpd.conf.5.option97	2015-05-20 16:44:34.908765906 +0200
45d60a
+++ dhcp-4.2.5/server/dhcpd.conf.5	2015-05-20 16:44:35.081763393 +0200
45d60a
@@ -1657,10 +1657,12 @@ should be a name identifying the host.
45d60a
 not specified for the host, \fIhostname\fR is used.
45d60a
 .PP
45d60a
 \fIHost\fR declarations are matched to actual DHCP or BOOTP clients
45d60a
-by matching the \fRdhcp-client-identifier\fR option specified in the
45d60a
+by matching the \fIdhcp-client-identifier\fR or \fIpxe-client-id\fR
45d60a
+options specified in the
45d60a
 \fIhost\fR declaration to the one supplied by the client, or, if the
45d60a
 \fIhost\fR declaration or the client does not provide a
45d60a
-\fRdhcp-client-identifier\fR option, by matching the \fIhardware\fR
45d60a
+\fIdhcp-client-identifier\fR or \fIpxe-client-id\fR options,
45d60a
+by matching the \fIhardware\fR
45d60a
 parameter in the \fIhost\fR declaration to the network hardware
45d60a
 address supplied by the client.  BOOTP clients do not normally
45d60a
 provide a \fIdhcp-client-identifier\fR, so the hardware address must
45d60a
@@ -1672,7 +1674,8 @@ to identify hosts.
45d60a
 .PP
45d60a
 Please be aware that
45d60a
 .B only
45d60a
-the \fIdhcp-client-identifier\fR option and the hardware address can be
45d60a
+the \fIdhcp-client-identifier\fR and \fIpxe-client-id\fR
45d60a
+options and the hardware address can be
45d60a
 used to match a host declaration, or the \fIhost-identifier option\fR
45d60a
 parameter for DHCPv6 servers.  For example, it is not possible to
45d60a
 match a host declaration to a \fIhost-name\fR option.  This is
45d60a
diff -up dhcp-4.2.5/server/dhcpleasequery.c.option97 dhcp-4.2.5/server/dhcpleasequery.c
45d60a
--- dhcp-4.2.5/server/dhcpleasequery.c.option97	2013-01-03 01:02:25.000000000 +0100
45d60a
+++ dhcp-4.2.5/server/dhcpleasequery.c	2015-05-20 16:44:35.082763378 +0200
45d60a
@@ -279,7 +279,7 @@ dhcpleasequery(struct packet *packet, in
45d60a
 		 */
45d60a
 
45d60a
 		memset(&uid, 0, sizeof(uid));
45d60a
-		if (get_option(&uid, 
45d60a
+		i = get_option(&uid,
45d60a
 			       &dhcp_universe,
45d60a
 			       packet,
45d60a
 			       NULL,
45d60a
@@ -289,8 +289,20 @@ dhcpleasequery(struct packet *packet, in
45d60a
 			       packet->options, 
45d60a
 			       &global_scope,
45d60a
 			       DHO_DHCP_CLIENT_IDENTIFIER,
45d60a
-			       MDL)) {
45d60a
-
45d60a
+			       MDL);
45d60a
+		if (!i)
45d60a
+			i = get_option(&uid,
45d60a
+				       &dhcp_universe,
45d60a
+				       packet,
45d60a
+				       NULL,
45d60a
+				       NULL,
45d60a
+				       packet->options,
45d60a
+				       NULL,
45d60a
+				       packet->options,
45d60a
+				       &global_scope,
45d60a
+				       DHO_PXE_CLIENT_ID,
45d60a
+				       MDL);
45d60a
+		if (i) {
45d60a
 			snprintf(dbg_info, 
45d60a
 				 sizeof(dbg_info), 
45d60a
 				 "client-id %s",
45d60a
diff -up dhcp-4.2.5/server/failover.c.option97 dhcp-4.2.5/server/failover.c
45d60a
--- dhcp-4.2.5/server/failover.c.option97	2015-05-20 16:44:35.001764555 +0200
45d60a
+++ dhcp-4.2.5/server/failover.c	2015-05-20 16:44:35.083763364 +0200
45d60a
@@ -5875,6 +5875,9 @@ int load_balance_mine (struct packet *pa
45d60a
 
45d60a
 	oc = lookup_option(&dhcp_universe, packet->options,
45d60a
 			   DHO_DHCP_CLIENT_IDENTIFIER);
45d60a
+	if (!oc)
45d60a
+		oc = lookup_option(&dhcp_universe, packet -> options,
45d60a
+				    DHO_PXE_CLIENT_ID);
45d60a
 	memset(&ds, 0, sizeof ds);
45d60a
 	if (oc &&
45d60a
 	    evaluate_option_cache(&ds, packet, NULL, NULL,
45d60a
diff -up dhcp-4.2.5/server/mdb.c.option97 dhcp-4.2.5/server/mdb.c
45d60a
--- dhcp-4.2.5/server/mdb.c.option97	2013-01-03 01:02:25.000000000 +0100
45d60a
+++ dhcp-4.2.5/server/mdb.c	2015-05-20 16:44:35.084763349 +0200
45d60a
@@ -127,8 +127,9 @@ static int find_uid_statement (struct ex
45d60a
 	    esp -> data.option &&
45d60a
 	    (esp -> data.option -> option -> universe ==
45d60a
 	     &dhcp_universe) &&
45d60a
-	    (esp -> data.option -> option -> code ==
45d60a
-	     DHO_DHCP_CLIENT_IDENTIFIER)) {
45d60a
+	    ((esp -> data.option -> option -> code ==
45d60a
+						DHO_DHCP_CLIENT_IDENTIFIER) ||
45d60a
+	     (esp -> data.option -> option -> code == DHO_PXE_CLIENT_ID))) {
45d60a
 		if (condp) {
45d60a
 			log_error ("dhcp client identifier may not be %s",
45d60a
 				   "specified conditionally.");