Blob Blame Raw
diff -up dhcp-4.3.1/client/dhclient.c.bind-iface dhcp-4.3.1/client/dhclient.c
--- dhcp-4.3.1/client/dhclient.c.bind-iface	2015-02-03 12:06:57.040989568 +0100
+++ dhcp-4.3.1/client/dhclient.c	2015-02-03 12:08:28.716684946 +0100
@@ -2661,6 +2661,14 @@ void send_request (cpp)
 
 	if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
 	    fallback_interface) {
+#if defined(SO_BINDTODEVICE)
+		if (setsockopt(fallback_interface -> wfdesc, SOL_SOCKET,
+			       SO_BINDTODEVICE, client->interface->name,
+			       strlen(client->interface->name)) < 0) {
+			log_error("%s:%d: Failed to bind fallback interface"
+				  " to %s: %m", MDL, client->interface->name);
+		}
+#endif
 		result = send_packet(fallback_interface, NULL, &client->packet,
 				     client->packet_length, from, &destination,
 				     NULL);
@@ -2670,6 +2678,13 @@ void send_request (cpp)
 				  client->packet_length,
 				  fallback_interface->name);
 		}
+#if defined(SO_BINDTODEVICE)
+		if (setsockopt(fallback_interface -> wfdesc, SOL_SOCKET,
+			       SO_BINDTODEVICE, NULL, 0) < 0) {
+			log_fatal("%s:%d: Failed to unbind fallback interface:"
+				  " %m", MDL);
+		}
+#endif
         }
 	else {
 		/* Send out a packet. */
@@ -2749,6 +2764,14 @@ void send_release (cpp)
 	      ntohs (destination.sin_port), ntohl(client -> xid));
 
 	if (fallback_interface) {
+#if defined(SO_BINDTODEVICE)
+		if (setsockopt(fallback_interface -> wfdesc, SOL_SOCKET,
+			       SO_BINDTODEVICE, client->interface->name,
+			       strlen(client->interface->name)) < 0) {
+			log_error("%s:%d: Failed to bind fallback interface"
+				  " to %s: %m", MDL, client->interface->name);
+		}
+#endif
 		result = send_packet(fallback_interface, NULL, &client->packet,
 				      client->packet_length, from, &destination,
 				      NULL);
@@ -2758,6 +2781,13 @@ void send_release (cpp)
 				  client->packet_length,
 				  fallback_interface->name);
 		}
+#if defined(SO_BINDTODEVICE)
+		if (setsockopt(fallback_interface -> wfdesc, SOL_SOCKET,
+			       SO_BINDTODEVICE, NULL, 0) < 0) {
+			log_fatal("%s:%d: Failed to unbind fallback interface:"
+				  " %m", MDL);
+		}
+#endif
         } else {
 		/* Send out a packet. */
 		result = send_packet(client->interface, NULL, &client->packet,