9c49c9e
From 7e8cc8388ac31c5c2b1a423c6b2da0491b19f6f9 Mon Sep 17 00:00:00 2001
7c09728
From: Pavel Zhukov <pzhukov@redhat.com>
7c09728
Date: Thu, 21 Feb 2019 10:22:41 +0100
9c49c9e
Subject: [PATCH 04/26] Support unicast BOOTP for IBM pSeries systems (and
7c09728
 maybe others)
7c09728
Cc: pzhukov@redhat.com
7c09728
7c09728
---
7c09728
 server/bootp.c | 12 +++++++++++-
7c09728
 server/dhcp.c  | 33 ++++++++++++++++++++++++++-------
7c09728
 2 files changed, 37 insertions(+), 8 deletions(-)
7c09728
7c09728
diff --git a/server/bootp.c b/server/bootp.c
7c09728
index 26a7607..2212f31 100644
7c09728
--- a/server/bootp.c
7c09728
+++ b/server/bootp.c
8173a68
@@ -52,6 +52,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;
8173a68
@@ -67,7 +68,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
 	}
8173a68
@@ -428,6 +429,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
7c09728
diff --git a/server/dhcp.c b/server/dhcp.c
7c09728
index 6f3a91f..20f2a62 100644
7c09728
--- a/server/dhcp.c
7c09728
+++ b/server/dhcp.c
7c09728
@@ -5224,6 +5224,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
 
8173a68
 #if defined(DHCPv6) && defined(DHCP4o6)
8173a68
 	if (dhcpv4_over_dhcpv6 && (packet->dhcp4o6_response != NULL)) {
7c09728
@@ -5245,12 +5246,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,
7c09728
@@ -5277,7 +5290,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. */
7c09728
@@ -5285,7 +5301,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. */
7c09728
-- 
7c09728
2.14.5
7c09728