3b727c
--- dhcp-3.0.5/server/bootp.c.unicast	2005-05-18 15:54:17.000000000 -0400
3b727c
+++ dhcp-3.0.5/server/bootp.c	2007-03-30 16:16:00.000000000 -0400
3b727c
@@ -62,6 +62,7 @@
3b727c
 	char msgbuf [1024];
3b727c
 	int ignorep;
3b727c
 	int peer_has_leases = 0;
3b727c
+	int norelay = 0;
3b727c
 
3b727c
 	if (packet -> raw -> op != BOOTREQUEST)
3b727c
 		return;
3b727c
@@ -77,7 +78,7 @@
3b727c
 		 ? inet_ntoa (packet -> raw -> giaddr)
3b727c
 		 : packet -> interface -> name);
3b727c
 
3b727c
-	if (!locate_network (packet)) {
3b727c
+	if ((norelay = locate_network (packet)) == 0) {
3b727c
 		log_info ("%s: network unknown", msgbuf);
3b727c
 		return;
3b727c
 	}
3b727c
@@ -357,6 +358,13 @@
3b727c
 					      from, &to, &hto);
3b727c
 			goto out;
3b727c
 		}
3b727c
+	} else if (norelay == 2) {
3b727c
+		to.sin_addr = raw.ciaddr;
3b727c
+		to.sin_port = remote_port;
3b727c
+		if (fallback_interface) {
3b727c
+			result = send_packet (fallback_interface, (struct packet *)0, &raw, outgoing.packet_length, from, &to, &hto);
3b727c
+			goto out;
3b727c
+		}
3b727c
 
3b727c
 	/* If it comes from a client that already knows its address
3b727c
 	   and is not requesting a broadcast response, and we can
3b727c
--- dhcp-3.0.5/server/dhcp.c.unicast	2007-03-30 16:13:36.000000000 -0400
3b727c
+++ dhcp-3.0.5/server/dhcp.c	2007-03-30 16:19:35.000000000 -0400
3b727c
@@ -3817,6 +3817,7 @@
3b727c
 	struct data_string data;
3b727c
 	struct subnet *subnet = (struct subnet *)0;
3b727c
 	struct option_cache *oc;
3b727c
+	int norelay = 0;
3b727c
 
3b727c
 	/* See if there's a subnet selection option. */
3b727c
 	oc = lookup_option (&dhcp_universe, packet -> options,
3b727c
@@ -3826,12 +3827,24 @@
3b727c
 	   from the interface, if there is one.   If not, fail. */
3b727c
 	if (!oc && !packet -> raw -> giaddr.s_addr) {
3b727c
 		if (packet -> interface -> shared_network) {
3b727c
-			shared_network_reference
3b727c
-				(&packet -> shared_network,
3b727c
-				 packet -> interface -> shared_network, MDL);
3b727c
-			return 1;
3b727c
+			struct in_addr any_addr;
3b727c
+			any_addr.s_addr = INADDR_ANY;
3b727c
+
3b727c
+			if (!packet -> packet_type && memcmp(&packet -> raw -> ciaddr, &any_addr, 4)) {
3b727c
+				struct iaddr cip;
3b727c
+				memcpy(cip.iabuf, &packet -> raw -> ciaddr, 4);
3b727c
+				cip.len = 4;
3b727c
+				if (!find_grouped_subnet(&subnet, packet->interface->shared_network, cip, MDL))
3b727c
+					norelay = 2;
3b727c
+			}
3b727c
+
3b727c
+			if (!norelay) {
3b727c
+				shared_network_reference(&packet -> shared_network, packet -> interface -> shared_network, MDL);
3b727c
+				return 1;
3b727c
+			}
3b727c
+		} else {
3b727c
+			return 0;
3b727c
 		}
3b727c
-		return 0;
3b727c
 	}
3b727c
 
3b727c
 	/* If there's an SSO, and it's valid, use it to figure out the
3b727c
@@ -3853,7 +3866,10 @@
3b727c
 		data_string_forget (&data, MDL);
3b727c
 	} else {
3b727c
 		ia.len = 4;
3b727c
-		memcpy (ia.iabuf, &packet -> raw -> giaddr, 4);
3b727c
+		if (norelay)
3b727c
+			memcpy (ia.iabuf, &packet->raw->ciaddr, 4);
3b727c
+		else
3b727c
+			memcpy (ia.iabuf, &packet->raw->giaddr, 4);
3b727c
 	}
3b727c
 
3b727c
 	/* If we know the subnet on which the IP address lives, use it. */
3b727c
@@ -3861,7 +3877,10 @@
3b727c
 		shared_network_reference (&packet -> shared_network,
3b727c
 					  subnet -> shared_network, MDL);
3b727c
 		subnet_dereference (&subnet, MDL);
3b727c
-		return 1;
3b727c
+		if (norelay)
3b727c
+			return norelay;
3b727c
+		else
3b727c
+			return 1;
3b727c
 	}
3b727c
 
3b727c
 	/* Otherwise, fail. */