e83fb1
diff -up dhcp-4.3.0a1/server/bootp.c.unicast dhcp-4.3.0a1/server/bootp.c
e83fb1
--- dhcp-4.3.0a1/server/bootp.c.unicast	2013-12-11 01:25:12.000000000 +0100
e83fb1
+++ dhcp-4.3.0a1/server/bootp.c	2013-12-19 15:12:12.974671154 +0100
d5d042
@@ -59,6 +59,7 @@ void bootp (packet)
203b45
 	char msgbuf [1024];
203b45
 	int ignorep;
203b45
 	int peer_has_leases = 0;
203b45
+	int norelay = 0;
203b45
 
203b45
 	if (packet -> raw -> op != BOOTREQUEST)
203b45
 		return;
d5d042
@@ -74,7 +75,7 @@ void bootp (packet)
203b45
 		 ? inet_ntoa (packet -> raw -> giaddr)
203b45
 		 : packet -> interface -> name);
203b45
 
203b45
-	if (!locate_network (packet)) {
203b45
+	if ((norelay = locate_network (packet)) == 0) {
203b45
 		log_info ("%s: network unknown", msgbuf);
203b45
 		return;
203b45
 	}
e83fb1
@@ -396,6 +397,15 @@ void bootp (packet)
d5d042
 
203b45
 			goto out;
203b45
 		}
203b45
+	} else if (norelay == 2) {
203b45
+		to.sin_addr = raw.ciaddr;
203b45
+		to.sin_port = remote_port;
203b45
+		if (fallback_interface) {
d5d042
+			result = send_packet (fallback_interface, NULL, &raw,
d5d042
+					      outgoing.packet_length, from,
d5d042
+					      &to, &hto);
203b45
+			goto out;
203b45
+		}
203b45
 
203b45
 	/* If it comes from a client that already knows its address
203b45
 	   and is not requesting a broadcast response, and we can
e83fb1
diff -up dhcp-4.3.0a1/server/dhcp.c.unicast dhcp-4.3.0a1/server/dhcp.c
e83fb1
--- dhcp-4.3.0a1/server/dhcp.c.unicast	2013-12-13 21:50:38.000000000 +0100
e83fb1
+++ dhcp-4.3.0a1/server/dhcp.c	2013-12-19 15:12:12.975671140 +0100
e83fb1
@@ -4627,6 +4627,7 @@ int locate_network (packet)
203b45
 	struct data_string data;
203b45
 	struct subnet *subnet = (struct subnet *)0;
203b45
 	struct option_cache *oc;
203b45
+	int norelay = 0;
203b45
 
ddfb13
 	/* See if there's a Relay Agent Link Selection Option, or a
ddfb13
 	 * Subnet Selection Option.  The Link-Select and Subnet-Select
e83fb1
@@ -4642,12 +4643,24 @@ int locate_network (packet)
203b45
 	   from the interface, if there is one.   If not, fail. */
203b45
 	if (!oc && !packet -> raw -> giaddr.s_addr) {
203b45
 		if (packet -> interface -> shared_network) {
203b45
-			shared_network_reference
203b45
-				(&packet -> shared_network,
203b45
-				 packet -> interface -> shared_network, MDL);
203b45
-			return 1;
203b45
+			struct in_addr any_addr;
203b45
+			any_addr.s_addr = INADDR_ANY;
203b45
+
203b45
+			if (!packet -> packet_type && memcmp(&packet -> raw -> ciaddr, &any_addr, 4)) {
203b45
+				struct iaddr cip;
203b45
+				memcpy(cip.iabuf, &packet -> raw -> ciaddr, 4);
203b45
+				cip.len = 4;
203b45
+				if (!find_grouped_subnet(&subnet, packet->interface->shared_network, cip, MDL))
203b45
+					norelay = 2;
203b45
+			}
203b45
+
203b45
+			if (!norelay) {
203b45
+				shared_network_reference(&packet -> shared_network, packet -> interface -> shared_network, MDL);
203b45
+				return 1;
203b45
+			}
203b45
+		} else {
203b45
+			return 0;
203b45
 		}
203b45
-		return 0;
203b45
 	}
203b45
 
ddfb13
 	/* If there's an option indicating link connection, and it's valid,
e83fb1
@@ -4670,7 +4683,10 @@ int locate_network (packet)
203b45
 		data_string_forget (&data, MDL);
203b45
 	} else {
203b45
 		ia.len = 4;
203b45
-		memcpy (ia.iabuf, &packet -> raw -> giaddr, 4);
203b45
+		if (norelay)
203b45
+			memcpy (ia.iabuf, &packet->raw->ciaddr, 4);
203b45
+		else
203b45
+			memcpy (ia.iabuf, &packet->raw->giaddr, 4);
203b45
 	}
203b45
 
203b45
 	/* If we know the subnet on which the IP address lives, use it. */
e83fb1
@@ -4678,7 +4694,10 @@ int locate_network (packet)
203b45
 		shared_network_reference (&packet -> shared_network,
203b45
 					  subnet -> shared_network, MDL);
203b45
 		subnet_dereference (&subnet, MDL);
203b45
-		return 1;
203b45
+		if (norelay)
203b45
+			return norelay;
203b45
+		else
203b45
+			return 1;
203b45
 	}
203b45
 
203b45
 	/* Otherwise, fail. */