philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

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

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