9c49c9e
From 193c4d7631fd623efa601f52fdab6018bf8be771 Mon Sep 17 00:00:00 2001
7c09728
From: Pavel Zhukov <pzhukov@redhat.com>
7c09728
Date: Thu, 21 Feb 2019 10:39:36 +0100
9c49c9e
Subject: [PATCH 17/26] Send unicast request/release via correct interface
7c09728
Cc: pzhukov@redhat.com
7c09728
7c09728
(#800561, #1177351)
7c09728
(Submitted to dhcp-bugs@isc.org - [ISC-Bugs #30544])
7c09728
---
7c09728
 client/dhclient.c | 30 ++++++++++++++++++++++++++++++
7c09728
 1 file changed, 30 insertions(+)
7c09728
7c09728
diff --git a/client/dhclient.c b/client/dhclient.c
7c09728
index ccc98e4..27fde69 100644
7c09728
--- a/client/dhclient.c
7c09728
+++ b/client/dhclient.c
7c09728
@@ -3171,6 +3171,14 @@ void send_request (cpp)
8173a68
 #endif
8e68883
 	if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
8e68883
 	    fallback_interface) {
8e68883
+#if defined(SO_BINDTODEVICE)
8e68883
+		if (setsockopt(fallback_interface -> wfdesc, SOL_SOCKET,
8e68883
+			       SO_BINDTODEVICE, client->interface->name,
8e68883
+			       strlen(client->interface->name)) < 0) {
8e68883
+			log_error("%s:%d: Failed to bind fallback interface"
8e68883
+				  " to %s: %m", MDL, client->interface->name);
8e68883
+		}
8e68883
+#endif
8e68883
 		result = send_packet(fallback_interface, NULL, &client->packet,
8e68883
 				     client->packet_length, from, &destination,
8e68883
 				     NULL);
7c09728
@@ -3180,6 +3188,13 @@ void send_request (cpp)
8e68883
 				  client->packet_length,
8e68883
 				  fallback_interface->name);
8e68883
 		}
8e68883
+#if defined(SO_BINDTODEVICE)
8e68883
+		if (setsockopt(fallback_interface -> wfdesc, SOL_SOCKET,
8e68883
+			       SO_BINDTODEVICE, NULL, 0) < 0) {
8e68883
+			log_fatal("%s:%d: Failed to unbind fallback interface:"
8e68883
+				  " %m", MDL);
8e68883
+		}
8e68883
+#endif
8e68883
         }
8e68883
 	else {
8e68883
 		/* Send out a packet. */
7c09728
@@ -3297,6 +3312,14 @@ void send_release (cpp)
8173a68
 	} else
8173a68
 #endif
8e68883
 	if (fallback_interface) {
8e68883
+#if defined(SO_BINDTODEVICE)
8e68883
+		if (setsockopt(fallback_interface -> wfdesc, SOL_SOCKET,
8e68883
+			       SO_BINDTODEVICE, client->interface->name,
8e68883
+			       strlen(client->interface->name)) < 0) {
8e68883
+			log_error("%s:%d: Failed to bind fallback interface"
8e68883
+				  " to %s: %m", MDL, client->interface->name);
8e68883
+		}
8e68883
+#endif
8e68883
 		result = send_packet(fallback_interface, NULL, &client->packet,
8e68883
 				      client->packet_length, from, &destination,
8e68883
 				      NULL);
7c09728
@@ -3306,6 +3329,13 @@ void send_release (cpp)
8e68883
 				  client->packet_length,
8e68883
 				  fallback_interface->name);
8e68883
 		}
8e68883
+#if defined(SO_BINDTODEVICE)
8e68883
+		if (setsockopt(fallback_interface -> wfdesc, SOL_SOCKET,
8e68883
+			       SO_BINDTODEVICE, NULL, 0) < 0) {
8e68883
+			log_fatal("%s:%d: Failed to unbind fallback interface:"
8e68883
+				  " %m", MDL);
8e68883
+		}
8e68883
+#endif
8e68883
         } else {
8e68883
 		/* Send out a packet. */
8e68883
 		result = send_packet(client->interface, NULL, &client->packet,
7c09728
-- 
7c09728
2.14.5
7c09728