From: Roy Marples Date: Sun, 28 Jul 2019 13:27:24 +0000 (+0100) Subject: DHCP: Avoid duplicate read of packet X-Git-Tag: v8.0.2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c23075688a8d4dd3209f4f7be09194723c803fe;p=thirdparty%2Fdhcpcd.git DHCP: Avoid duplicate read of packet If the BPF socket is open, discard any read from UDP as it would be duplicated. --- diff --git a/src/dhcp.c b/src/dhcp.c index 01f73c0e..36b8c727 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -3393,6 +3393,7 @@ dhcp_readudp(struct dhcpcd_ctx *ctx, struct interface *ifp) #ifdef IP_PKTINFO unsigned char ctl[CMSG_SPACE(sizeof(struct in_pktinfo))] = { 0 }; char sfrom[INET_ADDRSTRLEN]; + const struct dhcp_state *state; #endif struct msghdr msg = { .msg_name = &from, .msg_namelen = sizeof(from), @@ -3405,8 +3406,7 @@ dhcp_readudp(struct dhcpcd_ctx *ctx, struct interface *ifp) ssize_t bytes; if (ifp != NULL) { - const struct dhcp_state *state = D_CSTATE(ifp); - + state = D_CSTATE(ifp); s = state->udp_fd; } else s = ctx->udp_fd; @@ -3426,13 +3426,19 @@ dhcp_readudp(struct dhcpcd_ctx *ctx, struct interface *ifp) logerr(__func__); return; } - if (D_CSTATE(ifp) == NULL) { + state = D_CSTATE(ifp); + if (state == NULL) { logdebugx("%s: received BOOTP for inactive interface", ifp->name); return; } } + if (state->bpf_fd != -1) { + /* Avoid a duplicate read if BPF is open for the interface. */ + return; + } + dhcp_handlebootp(ifp, (struct bootp *)(void *)buf, (size_t)bytes, &from.sin_addr); #endif