BPF reads the whole BPF buffer in for processing.
We might close the BPF socket during processing and because the
buffer is shared between ARP and DHCP we need to re-wind it
when closing.
if ((state = ARP_STATE(ifp)) != NULL && state->fd != -1) {
eloop_event_delete(ifp->ctx->eloop, state->fd);
- bpf_close(state->fd);
+ bpf_close(ifp, state->fd);
state->fd = -1;
}
}
goto eexit;
state->buffer = nb;
state->buffer_size = buf_len;
- state->buffer_len = state->buffer_pos = 0;
}
#ifdef BIOCIMMEDIATE
}
#endif
+int
+bpf_close(struct interface *ifp, int fd)
+{
+ struct ipv4_state *state = IPV4_STATE(ifp);
+
+ /* Rewind the buffer on closing. */
+ state->buffer_len = state->buffer_pos = 0;
+ return close(fd);
+}
+
static unsigned int
bpf_cmp_hwaddr(struct bpf_insn *bpf, size_t bpf_len, size_t off,
bool equal, uint8_t *hwaddr, size_t hwaddr_len)
extern const char *bpf_name;
size_t bpf_frame_header_len(const struct interface *);
int bpf_open(struct interface *, int (*)(struct interface *, int));
+int bpf_close(struct interface *, int);
int bpf_attach(int, void *, unsigned int);
-#define bpf_close close
ssize_t bpf_send(const struct interface *, int, uint16_t, const void *, size_t);
ssize_t bpf_read(struct interface *, int, void *, size_t, int *);
int bpf_arp(struct interface *, int);
if (state->bpf_fd != -1) {
eloop_event_delete(ifp->ctx->eloop, state->bpf_fd);
- bpf_close(state->bpf_fd);
+ bpf_close(ifp, state->bpf_fd);
state->bpf_fd = -1;
}