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