]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: Avoid duplicate read of packet
authorRoy Marples <roy@marples.name>
Sun, 28 Jul 2019 13:27:24 +0000 (14:27 +0100)
committerRoy Marples <roy@marples.name>
Sun, 28 Jul 2019 13:27:24 +0000 (14:27 +0100)
If the BPF socket is open, discard any read from UDP as it
would be duplicated.

src/dhcp.c

index 01f73c0ec1c1017d639da0f1982cdb967586849e..36b8c7273dc8451a155d3e3707dd3677ba9602c7 100644 (file)
@@ -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