3161ff
diff -up dhcp-4.1.0/server/bootp.c.unicast dhcp-4.1.0/server/bootp.c
3161ff
--- dhcp-4.1.0/server/bootp.c.unicast	2008-08-20 13:07:19.000000000 -1000
3161ff
+++ dhcp-4.1.0/server/bootp.c	2009-01-06 10:13:29.000000000 -1000
4f14cb
@@ -58,6 +58,7 @@ void bootp (packet)
985851
 	char msgbuf [1024];
985851
 	int ignorep;
985851
 	int peer_has_leases = 0;
985851
+	int norelay = 0;
985851
 
985851
 	if (packet -> raw -> op != BOOTREQUEST)
985851
 		return;
4f14cb
@@ -73,7 +74,7 @@ void bootp (packet)
985851
 		 ? inet_ntoa (packet -> raw -> giaddr)
985851
 		 : packet -> interface -> name);
985851
 
985851
-	if (!locate_network (packet)) {
985851
+	if ((norelay = locate_network (packet)) == 0) {
985851
 		log_info ("%s: network unknown", msgbuf);
985851
 		return;
985851
 	}
3161ff
@@ -390,6 +391,13 @@ void bootp (packet)
985851
 					      from, &to, &hto);
985851
 			goto out;
985851
 		}
985851
+	} else if (norelay == 2) {
985851
+		to.sin_addr = raw.ciaddr;
985851
+		to.sin_port = remote_port;
985851
+		if (fallback_interface) {
985851
+			result = send_packet (fallback_interface, (struct packet *)0, &raw, outgoing.packet_length, from, &to, &hto);
985851
+			goto out;
985851
+		}
985851
 
985851
 	/* If it comes from a client that already knows its address
985851
 	   and is not requesting a broadcast response, and we can
3161ff
diff -up dhcp-4.1.0/server/dhcp.c.unicast dhcp-4.1.0/server/dhcp.c
3161ff
--- dhcp-4.1.0/server/dhcp.c.unicast	2008-11-03 08:13:58.000000000 -1000
3161ff
+++ dhcp-4.1.0/server/dhcp.c	2009-01-06 10:13:29.000000000 -1000
3161ff
@@ -4111,6 +4111,7 @@ int locate_network (packet)
985851
 	struct data_string data;
985851
 	struct subnet *subnet = (struct subnet *)0;
985851
 	struct option_cache *oc;
985851
+	int norelay = 0;
985851
 
4f14cb
 	/* See if there's a Relay Agent Link Selection Option, or a
4f14cb
 	 * Subnet Selection Option.  The Link-Select and Subnet-Select
3161ff
@@ -4126,12 +4127,24 @@ int locate_network (packet)
985851
 	   from the interface, if there is one.   If not, fail. */
985851
 	if (!oc && !packet -> raw -> giaddr.s_addr) {
985851
 		if (packet -> interface -> shared_network) {
985851
-			shared_network_reference
985851
-				(&packet -> shared_network,
985851
-				 packet -> interface -> shared_network, MDL);
985851
-			return 1;
985851
+			struct in_addr any_addr;
985851
+			any_addr.s_addr = INADDR_ANY;
985851
+
985851
+			if (!packet -> packet_type && memcmp(&packet -> raw -> ciaddr, &any_addr, 4)) {
985851
+				struct iaddr cip;
985851
+				memcpy(cip.iabuf, &packet -> raw -> ciaddr, 4);
985851
+				cip.len = 4;
985851
+				if (!find_grouped_subnet(&subnet, packet->interface->shared_network, cip, MDL))
985851
+					norelay = 2;
985851
+			}
985851
+
985851
+			if (!norelay) {
985851
+				shared_network_reference(&packet -> shared_network, packet -> interface -> shared_network, MDL);
985851
+				return 1;
985851
+			}
985851
+		} else {
985851
+			return 0;
985851
 		}
985851
-		return 0;
985851
 	}
985851
 
4f14cb
 	/* If there's an option indicating link connection, and it's valid,
3161ff
@@ -4154,7 +4167,10 @@ int locate_network (packet)
985851
 		data_string_forget (&data, MDL);
985851
 	} else {
985851
 		ia.len = 4;
985851
-		memcpy (ia.iabuf, &packet -> raw -> giaddr, 4);
985851
+		if (norelay)
985851
+			memcpy (ia.iabuf, &packet->raw->ciaddr, 4);
985851
+		else
985851
+			memcpy (ia.iabuf, &packet->raw->giaddr, 4);
985851
 	}
985851
 
985851
 	/* If we know the subnet on which the IP address lives, use it. */
3161ff
@@ -4162,7 +4178,10 @@ int locate_network (packet)
985851
 		shared_network_reference (&packet -> shared_network,
985851
 					  subnet -> shared_network, MDL);
985851
 		subnet_dereference (&subnet, MDL);
985851
-		return 1;
985851
+		if (norelay)
985851
+			return norelay;
985851
+		else
985851
+			return 1;
985851
 	}
985851
 
985851
 	/* Otherwise, fail. */