Blame SOURCES/0004-Support-unicast-BOOTP-for-IBM-pSeries-systems-and-ma.patch

df4638
From 7e8cc8388ac31c5c2b1a423c6b2da0491b19f6f9 Mon Sep 17 00:00:00 2001
df4638
From: Pavel Zhukov <pzhukov@redhat.com>
df4638
Date: Thu, 21 Feb 2019 10:22:41 +0100
df4638
Subject: [PATCH 04/26] Support unicast BOOTP for IBM pSeries systems (and
df4638
 maybe others)
df4638
Cc: pzhukov@redhat.com
df4638
df4638
---
df4638
 server/bootp.c | 12 +++++++++++-
df4638
 server/dhcp.c  | 33 ++++++++++++++++++++++++++-------
df4638
 2 files changed, 37 insertions(+), 8 deletions(-)
df4638
df4638
diff --git a/server/bootp.c b/server/bootp.c
df4638
index 26a7607..2212f31 100644
df4638
--- a/server/bootp.c
df4638
+++ b/server/bootp.c
df4638
@@ -52,6 +52,7 @@ void bootp (packet)
df4638
 	char msgbuf [1024];
df4638
 	int ignorep;
df4638
 	int peer_has_leases = 0;
df4638
+	int norelay = 0;
df4638
 
df4638
 	if (packet -> raw -> op != BOOTREQUEST)
df4638
 		return;
df4638
@@ -67,7 +68,7 @@ void bootp (packet)
df4638
 		 ? inet_ntoa (packet -> raw -> giaddr)
df4638
 		 : packet -> interface -> name);
df4638
 
df4638
-	if (!locate_network (packet)) {
df4638
+	if ((norelay = locate_network (packet)) == 0) {
df4638
 		log_info ("%s: network unknown", msgbuf);
df4638
 		return;
df4638
 	}
df4638
@@ -428,6 +429,15 @@ void bootp (packet)
df4638
 
df4638
 			goto out;
df4638
 		}
df4638
+	} else if (norelay == 2) {
df4638
+		to.sin_addr = raw.ciaddr;
df4638
+		to.sin_port = remote_port;
df4638
+		if (fallback_interface) {
df4638
+			result = send_packet (fallback_interface, NULL, &raw,
df4638
+					      outgoing.packet_length, from,
df4638
+					      &to, &hto);
df4638
+			goto out;
df4638
+		}
df4638
 
df4638
 	/* If it comes from a client that already knows its address
df4638
 	   and is not requesting a broadcast response, and we can
df4638
diff --git a/server/dhcp.c b/server/dhcp.c
df4638
index 6f3a91f..20f2a62 100644
df4638
--- a/server/dhcp.c
df4638
+++ b/server/dhcp.c
df4638
@@ -5224,6 +5224,7 @@ int locate_network (packet)
df4638
 	struct data_string data;
df4638
 	struct subnet *subnet = (struct subnet *)0;
df4638
 	struct option_cache *oc;
df4638
+	int norelay = 0;
df4638
 
df4638
 #if defined(DHCPv6) && defined(DHCP4o6)
df4638
 	if (dhcpv4_over_dhcpv6 && (packet->dhcp4o6_response != NULL)) {
df4638
@@ -5245,12 +5246,24 @@ int locate_network (packet)
df4638
 	   from the interface, if there is one.   If not, fail. */
df4638
 	if (!oc && !packet -> raw -> giaddr.s_addr) {
df4638
 		if (packet -> interface -> shared_network) {
df4638
-			shared_network_reference
df4638
-				(&packet -> shared_network,
df4638
-				 packet -> interface -> shared_network, MDL);
df4638
-			return 1;
df4638
+			struct in_addr any_addr;
df4638
+			any_addr.s_addr = INADDR_ANY;
df4638
+
df4638
+			if (!packet -> packet_type && memcmp(&packet -> raw -> ciaddr, &any_addr, 4)) {
df4638
+				struct iaddr cip;
df4638
+				memcpy(cip.iabuf, &packet -> raw -> ciaddr, 4);
df4638
+				cip.len = 4;
df4638
+				if (!find_grouped_subnet(&subnet, packet->interface->shared_network, cip, MDL))
df4638
+					norelay = 2;
df4638
+			}
df4638
+
df4638
+			if (!norelay) {
df4638
+				shared_network_reference(&packet -> shared_network, packet -> interface -> shared_network, MDL);
df4638
+				return 1;
df4638
+			}
df4638
+		} else {
df4638
+			return 0;
df4638
 		}
df4638
-		return 0;
df4638
 	}
df4638
 
df4638
 	/* If there's an option indicating link connection, and it's valid,
df4638
@@ -5277,7 +5290,10 @@ int locate_network (packet)
df4638
 		data_string_forget (&data, MDL);
df4638
 	} else {
df4638
 		ia.len = 4;
df4638
-		memcpy (ia.iabuf, &packet -> raw -> giaddr, 4);
df4638
+		if (norelay)
df4638
+			memcpy (ia.iabuf, &packet->raw->ciaddr, 4);
df4638
+		else
df4638
+			memcpy (ia.iabuf, &packet->raw->giaddr, 4);
df4638
 	}
df4638
 
df4638
 	/* If we know the subnet on which the IP address lives, use it. */
df4638
@@ -5285,7 +5301,10 @@ int locate_network (packet)
df4638
 		shared_network_reference (&packet -> shared_network,
df4638
 					  subnet -> shared_network, MDL);
df4638
 		subnet_dereference (&subnet, MDL);
df4638
-		return 1;
df4638
+		if (norelay)
df4638
+			return norelay;
df4638
+		else
df4638
+			return 1;
df4638
 	}
df4638
 
df4638
 	/* Otherwise, fail. */
df4638
-- 
df4638
2.14.5
df4638