philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

Blame SOURCES/dhcp-4.2.4-unicast-bootp.patch

45d60a
diff -up dhcp-4.2.4b1/server/bootp.c.unicast dhcp-4.2.4b1/server/bootp.c
45d60a
--- dhcp-4.2.4b1/server/bootp.c.unicast	2012-04-10 23:27:06.000000000 +0200
45d60a
+++ dhcp-4.2.4b1/server/bootp.c	2012-04-16 17:28:42.095919022 +0200
45d60a
@@ -59,6 +59,7 @@ void bootp (packet)
45d60a
 	char msgbuf [1024];
45d60a
 	int ignorep;
45d60a
 	int peer_has_leases = 0;
45d60a
+	int norelay = 0;
45d60a
 
45d60a
 	if (packet -> raw -> op != BOOTREQUEST)
45d60a
 		return;
45d60a
@@ -74,7 +75,7 @@ void bootp (packet)
45d60a
 		 ? inet_ntoa (packet -> raw -> giaddr)
45d60a
 		 : packet -> interface -> name);
45d60a
 
45d60a
-	if (!locate_network (packet)) {
45d60a
+	if ((norelay = locate_network (packet)) == 0) {
45d60a
 		log_info ("%s: network unknown", msgbuf);
45d60a
 		return;
45d60a
 	}
45d60a
@@ -399,6 +400,15 @@ void bootp (packet)
45d60a
 
45d60a
 			goto out;
45d60a
 		}
45d60a
+	} else if (norelay == 2) {
45d60a
+		to.sin_addr = raw.ciaddr;
45d60a
+		to.sin_port = remote_port;
45d60a
+		if (fallback_interface) {
45d60a
+			result = send_packet (fallback_interface, NULL, &raw,
45d60a
+					      outgoing.packet_length, from,
45d60a
+					      &to, &hto);
45d60a
+			goto out;
45d60a
+		}
45d60a
 
45d60a
 	/* If it comes from a client that already knows its address
45d60a
 	   and is not requesting a broadcast response, and we can
45d60a
diff -up dhcp-4.2.4b1/server/dhcp.c.unicast dhcp-4.2.4b1/server/dhcp.c
45d60a
--- dhcp-4.2.4b1/server/dhcp.c.unicast	2012-03-09 12:28:12.000000000 +0100
45d60a
+++ dhcp-4.2.4b1/server/dhcp.c	2012-04-16 17:26:55.067418285 +0200
45d60a
@@ -4299,6 +4299,7 @@ int locate_network (packet)
45d60a
 	struct data_string data;
45d60a
 	struct subnet *subnet = (struct subnet *)0;
45d60a
 	struct option_cache *oc;
45d60a
+	int norelay = 0;
45d60a
 
45d60a
 	/* See if there's a Relay Agent Link Selection Option, or a
45d60a
 	 * Subnet Selection Option.  The Link-Select and Subnet-Select
45d60a
@@ -4314,12 +4315,24 @@ int locate_network (packet)
45d60a
 	   from the interface, if there is one.   If not, fail. */
45d60a
 	if (!oc && !packet -> raw -> giaddr.s_addr) {
45d60a
 		if (packet -> interface -> shared_network) {
45d60a
-			shared_network_reference
45d60a
-				(&packet -> shared_network,
45d60a
-				 packet -> interface -> shared_network, MDL);
45d60a
-			return 1;
45d60a
+			struct in_addr any_addr;
45d60a
+			any_addr.s_addr = INADDR_ANY;
45d60a
+
45d60a
+			if (!packet -> packet_type && memcmp(&packet -> raw -> ciaddr, &any_addr, 4)) {
45d60a
+				struct iaddr cip;
45d60a
+				memcpy(cip.iabuf, &packet -> raw -> ciaddr, 4);
45d60a
+				cip.len = 4;
45d60a
+				if (!find_grouped_subnet(&subnet, packet->interface->shared_network, cip, MDL))
45d60a
+					norelay = 2;
45d60a
+			}
45d60a
+
45d60a
+			if (!norelay) {
45d60a
+				shared_network_reference(&packet -> shared_network, packet -> interface -> shared_network, MDL);
45d60a
+				return 1;
45d60a
+			}
45d60a
+		} else {
45d60a
+			return 0;
45d60a
 		}
45d60a
-		return 0;
45d60a
 	}
45d60a
 
45d60a
 	/* If there's an option indicating link connection, and it's valid,
45d60a
@@ -4342,7 +4355,10 @@ int locate_network (packet)
45d60a
 		data_string_forget (&data, MDL);
45d60a
 	} else {
45d60a
 		ia.len = 4;
45d60a
-		memcpy (ia.iabuf, &packet -> raw -> giaddr, 4);
45d60a
+		if (norelay)
45d60a
+			memcpy (ia.iabuf, &packet->raw->ciaddr, 4);
45d60a
+		else
45d60a
+			memcpy (ia.iabuf, &packet->raw->giaddr, 4);
45d60a
 	}
45d60a
 
45d60a
 	/* If we know the subnet on which the IP address lives, use it. */
45d60a
@@ -4350,7 +4366,10 @@ int locate_network (packet)
45d60a
 		shared_network_reference (&packet -> shared_network,
45d60a
 					  subnet -> shared_network, MDL);
45d60a
 		subnet_dereference (&subnet, MDL);
45d60a
-		return 1;
45d60a
+		if (norelay)
45d60a
+			return norelay;
45d60a
+		else
45d60a
+			return 1;
45d60a
 	}
45d60a
 
45d60a
 	/* Otherwise, fail. */