philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone
Blob Blame History Raw
diff -up dhcp-4.2.5/client/dhclient.c.bind-iface dhcp-4.2.5/client/dhclient.c
--- dhcp-4.2.5/client/dhclient.c.bind-iface	2015-02-03 12:24:08.076213363 +0100
+++ dhcp-4.2.5/client/dhclient.c	2015-02-03 12:25:02.399168410 +0100
@@ -2670,6 +2670,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);
@@ -2679,6 +2687,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. */
@@ -2758,6 +2773,14 @@ void send_release (cpp)
 	      ntohs (destination.sin_port), 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);
@@ -2767,6 +2790,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,