philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone
26a25c
diff -up dhcp-4.3.4/server/bootp.c.unicast dhcp-4.3.4/server/bootp.c
26a25c
--- dhcp-4.3.4/server/bootp.c.unicast	2016-03-22 14:16:51.000000000 +0100
26a25c
+++ dhcp-4.3.4/server/bootp.c	2016-05-02 15:09:40.023243008 +0200
26a25c
@@ -52,6 +52,7 @@ void bootp (packet)
26a25c
 	char msgbuf [1024];
26a25c
 	int ignorep;
26a25c
 	int peer_has_leases = 0;
26a25c
+	int norelay = 0;
26a25c
 
26a25c
 	if (packet -> raw -> op != BOOTREQUEST)
26a25c
 		return;
26a25c
@@ -67,7 +68,7 @@ void bootp (packet)
26a25c
 		 ? inet_ntoa (packet -> raw -> giaddr)
26a25c
 		 : packet -> interface -> name);
26a25c
 
26a25c
-	if (!locate_network (packet)) {
26a25c
+	if ((norelay = locate_network (packet)) == 0) {
26a25c
 		log_info ("%s: network unknown", msgbuf);
26a25c
 		return;
26a25c
 	}
26a25c
@@ -428,6 +429,15 @@ void bootp (packet)
26a25c
 
26a25c
 			goto out;
26a25c
 		}
26a25c
+	} else if (norelay == 2) {
26a25c
+		to.sin_addr = raw.ciaddr;
26a25c
+		to.sin_port = remote_port;
26a25c
+		if (fallback_interface) {
26a25c
+			result = send_packet (fallback_interface, NULL, &raw,
26a25c
+					      outgoing.packet_length, from,
26a25c
+					      &to, &hto);
26a25c
+			goto out;
26a25c
+		}
26a25c
 
26a25c
 	/* If it comes from a client that already knows its address
26a25c
 	   and is not requesting a broadcast response, and we can
26a25c
diff -up dhcp-4.3.4/server/dhcp.c.unicast dhcp-4.3.4/server/dhcp.c
26a25c
--- dhcp-4.3.4/server/dhcp.c.unicast	2016-03-22 14:16:51.000000000 +0100
26a25c
+++ dhcp-4.3.4/server/dhcp.c	2016-05-02 15:10:13.255267511 +0200
26a25c
@@ -5132,6 +5132,7 @@ int locate_network (packet)
26a25c
 	struct data_string data;
26a25c
 	struct subnet *subnet = (struct subnet *)0;
26a25c
 	struct option_cache *oc;
26a25c
+	int norelay = 0;
26a25c
 
26a25c
 #if defined(DHCPv6) && defined(DHCP4o6)
26a25c
 	if (dhcpv4_over_dhcpv6 && (packet->dhcp4o6_response != NULL)) {
26a25c
@@ -5153,12 +5154,24 @@ int locate_network (packet)
26a25c
 	   from the interface, if there is one.   If not, fail. */
26a25c
 	if (!oc && !packet -> raw -> giaddr.s_addr) {
26a25c
 		if (packet -> interface -> shared_network) {
26a25c
-			shared_network_reference
26a25c
-				(&packet -> shared_network,
26a25c
-				 packet -> interface -> shared_network, MDL);
26a25c
-			return 1;
26a25c
+			struct in_addr any_addr;
26a25c
+			any_addr.s_addr = INADDR_ANY;
26a25c
+
26a25c
+			if (!packet -> packet_type && memcmp(&packet -> raw -> ciaddr, &any_addr, 4)) {
26a25c
+				struct iaddr cip;
26a25c
+				memcpy(cip.iabuf, &packet -> raw -> ciaddr, 4);
26a25c
+				cip.len = 4;
26a25c
+				if (!find_grouped_subnet(&subnet, packet->interface->shared_network, cip, MDL))
26a25c
+					norelay = 2;
26a25c
+			}
26a25c
+
26a25c
+			if (!norelay) {
26a25c
+				shared_network_reference(&packet -> shared_network, packet -> interface -> shared_network, MDL);
26a25c
+				return 1;
26a25c
+			}
26a25c
+		} else {
26a25c
+			return 0;
26a25c
 		}
26a25c
-		return 0;
26a25c
 	}
26a25c
 
26a25c
 	/* If there's an option indicating link connection, and it's valid,
26a25c
@@ -5185,7 +5198,10 @@ int locate_network (packet)
26a25c
 		data_string_forget (&data, MDL);
26a25c
 	} else {
26a25c
 		ia.len = 4;
26a25c
-		memcpy (ia.iabuf, &packet -> raw -> giaddr, 4);
26a25c
+		if (norelay)
26a25c
+			memcpy (ia.iabuf, &packet->raw->ciaddr, 4);
26a25c
+		else
26a25c
+			memcpy (ia.iabuf, &packet->raw->giaddr, 4);
26a25c
 	}
26a25c
 
26a25c
 	/* If we know the subnet on which the IP address lives, use it. */
26a25c
@@ -5193,7 +5209,10 @@ int locate_network (packet)
26a25c
 		shared_network_reference (&packet -> shared_network,
26a25c
 					  subnet -> shared_network, MDL);
26a25c
 		subnet_dereference (&subnet, MDL);
26a25c
-		return 1;
26a25c
+		if (norelay)
26a25c
+			return norelay;
26a25c
+		else
26a25c
+			return 1;
26a25c
 	}
26a25c
 
26a25c
 	/* Otherwise, fail. */