From ff325644c7afae2588583f935f4ea9b9694eb52e Mon Sep 17 00:00:00 2001 From: Neil Jerram Date: Tue, 3 May 2016 22:45:14 +0100 Subject: [PATCH] Fix for DHCP in transmission interface when --bridge-interface in use. From f3d832b41f44c856003517c583fbd7af4dca722c Mon Sep 17 00:00:00 2001 From: Neil Jerram Date: Fri, 8 Apr 2016 19:23:47 +0100 Subject: [PATCH] Fix DHCPv4 reply via --bridge-interface alias interface Sending a DHCPv4 reply through a --bridge-interface alias interface was inadvertently broken by commit 65c721200023ef0023114459a8d12f8b0a24cfd8 Author: Lung-Pin Chang Date: Thu Mar 19 23:22:21 2015 +0000 dhcp: set outbound interface via cmsg in unicast reply If multiple routes to the same network exist, Linux blindly picks the first interface (route) based on destination address, which might not be the one we're actually offering leases. Rather than relying on this, always set the interface for outgoing unicast DHCP packets. because in the aliasing case, iface_index is changed from the index of the interface on which the packet was received, to be the interface index of the 'bridge' interface (where the DHCP context is expected to be defined, and so needs to be looked up). For the cmsg code that the cited commit added, we need the original iface_index; so this commit saves that off before the aliasing code can change it, as rcvd_iface_index, and then uses rcvd_iface_index instead of iface_index for the cmsg code. --- src/dhcp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dhcp.c b/src/dhcp.c index 00145bc..10f1fb9 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -146,6 +146,7 @@ void dhcp_packet(time_t now, int pxe_fd) struct iovec iov; ssize_t sz; int iface_index = 0, unicast_dest = 0, is_inform = 0; + int rcvd_iface_index; struct in_addr iface_addr; struct iface_param parm; #ifdef HAVE_LINUX_NETWORK @@ -230,6 +231,7 @@ void dhcp_packet(time_t now, int pxe_fd) --bridge-interface option), change ifr.ifr_name so that we look for DHCP contexts associated with the aliased interface instead of with the aliasing one. */ + rcvd_iface_index = iface_index; for (bridge = daemon->bridges; bridge; bridge = bridge->next) { for (alias = bridge->alias; alias; alias = alias->next) @@ -387,7 +389,7 @@ void dhcp_packet(time_t now, int pxe_fd) msg.msg_controllen = sizeof(control_u); cmptr = CMSG_FIRSTHDR(&msg); pkt = (struct in_pktinfo *)CMSG_DATA(cmptr); - pkt->ipi_ifindex = iface_index; + pkt->ipi_ifindex = rcvd_iface_index; pkt->ipi_spec_dst.s_addr = 0; msg.msg_controllen = cmptr->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo)); cmptr->cmsg_level = IPPROTO_IP;