From: Roy Marples Date: Tue, 24 Oct 2017 23:04:44 +0000 (+0100) Subject: Fix prior patches by using correct bitmasks for flags. X-Git-Tag: v7.0.0-rc4~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2597f458607b25ea478f3f59b38c2975d032195a;p=thirdparty%2Fdhcpcd.git Fix prior patches by using correct bitmasks for flags. Add BPF_READING and BPF_FREE so that arp can free the state after finishing the read loop. --- diff --git a/src/arp.c b/src/arp.c index 77a1dc3d..61a8c771 100644 --- a/src/arp.c +++ b/src/arp.c @@ -198,19 +198,27 @@ arp_read(void *arg) * so we have to process the entire buffer. */ state = ARP_STATE(ifp); state->bpf_flags &= ~BPF_EOF; + state->bpf_flags |= BPF_READING; while (!(state->bpf_flags & BPF_EOF)) { bytes = bpf_read(ifp, state->bpf_fd, buf, sizeof(buf), &state->bpf_flags); if (bytes == -1) { logerr("%s: %s", __func__, ifp->name); arp_close(ifp); - return; + break; } arp_packet(ifp, buf, (size_t)bytes); /* Check we still have a state after processing. */ if ((state = ARP_STATE(ifp)) == NULL) break; } + if (state != NULL) { + state->bpf_flags &= ~BPF_READING; + if (state->bpf_flags & BPF_FREE) { + free(state); + ifp->if_data[IF_DATA_ARP] = NULL; + } + } } int @@ -503,8 +511,12 @@ arp_free(struct arp_state *astate) /* If there are no more ARP states, close the socket. */ if (TAILQ_FIRST(&state->arp_states) == NULL) { arp_close(ifp); - free(state); - ifp->if_data[IF_DATA_ARP] = NULL; + if (state->bpf_flags & BPF_READING) + state->bpf_flags |= BPF_EOF | BPF_FREE; + else { + free(state); + ifp->if_data[IF_DATA_ARP] = NULL; + } } else if (bpf_arp(ifp, state->bpf_fd) == -1) logerr(__func__); diff --git a/src/bpf.h b/src/bpf.h index 89e69bca..d41efdce 100644 --- a/src/bpf.h +++ b/src/bpf.h @@ -28,8 +28,10 @@ #ifndef BPF_HEADER #define BPF_HEADER -#define BPF_EOF (1U << 0) -#define BPF_PARTIALCSUM (2U << 0) +#define BPF_EOF (1U << 0) +#define BPF_PARTIALCSUM (1U << 1) +#define BPF_READING (1U << 2) +#define BPF_FREE (1U << 3) #include "dhcpcd.h" diff --git a/src/dhcp.c b/src/dhcp.c index 1e93078d..55a6d69d 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -3300,6 +3300,7 @@ dhcp_readpacket(void *arg) * This means we have no kernel call to just get one packet, * so we have to process the entire buffer. */ state->bpf_flags &= ~BPF_EOF; + state->bpf_flags |= BPF_READING; while (!(state->bpf_flags & BPF_EOF)) { bytes = bpf_read(ifp, state->bpf_fd, buf, sizeof(buf), &state->bpf_flags); @@ -3308,13 +3309,15 @@ dhcp_readpacket(void *arg) logerr("%s: %s", __func__, ifp->name); dhcp_close(ifp); } - return; + break; } dhcp_handlepacket(ifp, buf, (size_t)bytes); /* Check we still have a state after processing. */ if ((state = D_STATE(ifp)) == NULL) break; } + if (state != NULL) + state->bpf_flags &= ~BPF_READING; } static void