From: Roy Marples Date: Mon, 3 Feb 2014 17:30:03 +0000 (+0000) Subject: Drain the correct UDP socket. X-Git-Tag: v6.3.0~53 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=47ecfbd00258566085f39965bfa2d0d0ef37ac99;p=thirdparty%2Fdhcpcd.git Drain the correct UDP socket. --- diff --git a/dhcp.c b/dhcp.c index ef00d97e..99707d6c 100644 --- a/dhcp.c +++ b/dhcp.c @@ -2590,15 +2590,21 @@ dhcp_handlepacket(void *arg) static void dhcp_handleudp(void *arg) { + int fd; const struct interface *ifp; const struct dhcp_state *state; uint8_t buffer[sizeof(struct dhcp_message)]; - ifp = arg; - state = D_CSTATE(ifp); + if (arg) { + ifp = arg; + state = D_CSTATE(ifp); + fd = state->udp_fd; + } else + fd = udp_fd; + /* Just read what's in the UDP fd and discard it as we always read * from the raw fd */ - read(state->udp_fd, buffer, sizeof(buffer)); + read(fd, buffer, sizeof(buffer)); } static int @@ -2708,11 +2714,6 @@ dhcp_init(struct interface *ifp) const struct if_options *ifo; size_t len; - /* Listen on *.*.*.*:bootpc so that the kernel never sends an - * ICMP port unreachable message back to the DHCP server */ - if (udp_fd == -1 && dhcp_openudp(NULL) != -1) - eloop_event_add(udp_fd, dhcp_handleudp, NULL); - state = D_STATE(ifp); if (state == NULL) { ifp->if_data[IF_DATA_DHCP] = calloc(1, sizeof(*state)); @@ -2795,6 +2796,11 @@ dhcp_start(struct interface *ifp) if (!(ifo->options & DHCPCD_IPV4)) return; + /* Listen on *.*.*.*:bootpc so that the kernel never sends an + * ICMP port unreachable message back to the DHCP server */ + if (udp_fd == -1 && dhcp_openudp(NULL) != -1) + eloop_event_add(udp_fd, dhcp_handleudp, NULL); + if (dhcp_init(ifp) == -1) { syslog(LOG_ERR, "%s: dhcp_init: %m", ifp->name); return;