From: Roy Marples Date: Fri, 25 Oct 2019 12:32:38 +0000 (+0100) Subject: ARP: Add interface to arp_state X-Git-Tag: v8.1.2~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=293af2b091539736203cc490bb0f90a574802d73;p=thirdparty%2Fdhcpcd.git ARP: Add interface to arp_state Simplifies the codes slightly and allows a backreference if we need to pass the ARP state as a context. --- diff --git a/src/arp.c b/src/arp.c index cc080a80..0fdcdd9a 100644 --- a/src/arp.c +++ b/src/arp.c @@ -279,9 +279,9 @@ arp_close(struct interface *ifp) } static void -arp_tryfree(struct interface *ifp) +arp_tryfree(struct iarp_state *state) { - struct iarp_state *state = ARP_STATE(ifp); + struct interface *ifp = state->ifp; /* If there are no more ARP states, close the socket. */ if (TAILQ_FIRST(&state->arp_states) == NULL) { @@ -301,15 +301,14 @@ arp_tryfree(struct interface *ifp) static void arp_read(void *arg) { - struct interface *ifp = arg; - struct iarp_state *state; + struct iarp_state *state = arg; + struct interface *ifp = state->ifp; uint8_t buf[ARP_LEN]; ssize_t bytes; /* Some RAW mechanisms are generic file descriptors, not sockets. * This means we have no kernel call to just get one packet, * 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)) { @@ -328,7 +327,7 @@ arp_read(void *arg) if (state != NULL) { state->bpf_flags &= ~BPF_READING; /* Try and free the state if nothing left to do. */ - arp_tryfree(ifp); + arp_tryfree(state); } } @@ -342,7 +341,7 @@ arp_open(struct interface *ifp) state->bpf_fd = bpf_open(ifp, bpf_arp); if (state->bpf_fd == -1) return -1; - eloop_event_add(ifp->ctx->eloop, state->bpf_fd, arp_read, ifp); + eloop_event_add(ifp->ctx->eloop, state->bpf_fd, arp_read, state); } return state->bpf_fd; } @@ -570,6 +569,7 @@ arp_new(struct interface *ifp, const struct in_addr *addr) logerr(__func__); return NULL; } + state->ifp = ifp; state->bpf_fd = -1; state->bpf_flags = 0; TAILQ_INIT(&state->arp_states); @@ -617,7 +617,7 @@ arp_free(struct arp_state *astate) if (astate->free_cb) astate->free_cb(astate); free(astate); - arp_tryfree(ifp); + arp_tryfree(state); } void diff --git a/src/arp.h b/src/arp.h index 0065e0c9..4842c357 100644 --- a/src/arp.h +++ b/src/arp.h @@ -78,6 +78,7 @@ struct arp_state { TAILQ_HEAD(arp_statehead, arp_state); struct iarp_state { + struct interface *ifp; int bpf_fd; unsigned int bpf_flags; struct arp_statehead arp_states;