ssahani / rpms / dhcp

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