}
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) {
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)) {
if (state != NULL) {
state->bpf_flags &= ~BPF_READING;
/* Try and free the state if nothing left to do. */
- arp_tryfree(ifp);
+ arp_tryfree(state);
}
}
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;
}
logerr(__func__);
return NULL;
}
+ state->ifp = ifp;
state->bpf_fd = -1;
state->bpf_flags = 0;
TAILQ_INIT(&state->arp_states);
if (astate->free_cb)
astate->free_cb(astate);
free(astate);
- arp_tryfree(ifp);
+ arp_tryfree(state);
}
void