]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
ARP: Add interface to arp_state
authorRoy Marples <roy@marples.name>
Fri, 25 Oct 2019 12:32:38 +0000 (13:32 +0100)
committerRoy Marples <roy@marples.name>
Fri, 25 Oct 2019 12:32:38 +0000 (13:32 +0100)
Simplifies the codes slightly and allows a backreference if
we need to pass the ARP state as a context.

src/arp.c
src/arp.h

index cc080a801f365d02514a2534a609d90e9752c28f..0fdcdd9aa3ba6310b61c63fefceb39e50bbaf9ad 100644 (file)
--- 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
index 0065e0c91786a7eb542f89765739316e17504956..4842c3579ae0cd8e8a1c6ef674a17b7dd9818637 100644 (file)
--- 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;