Skip to content

Commit 7dfeb36

Browse files
committed
BPF: Start with the EOF marker set
This will allow us to abort any BPF read loop if it's reset. While here, delay restarting DHCP slightly to allow privsep builds to recover the same error. Fixes #481.
1 parent 733a473 commit 7dfeb36

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/bpf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ bpf_open(const struct interface *ifp,
170170
if (bpf == NULL)
171171
return NULL;
172172
bpf->bpf_ifp = ifp;
173+
bpf->bpf_flags = BPF_EOF;
173174

174175
/* /dev/bpf is a cloner on modern kernels */
175176
bpf->bpf_fd = open("/dev/bpf", BPF_OPEN_FLAGS);
@@ -218,10 +219,12 @@ bpf_open(const struct interface *ifp,
218219
/* Get the required BPF buffer length from the kernel. */
219220
if (ioctl(bpf->bpf_fd, BIOCGBLEN, &ibuf_len) == -1)
220221
goto eexit;
222+
221223
bpf->bpf_size = (size_t)ibuf_len;
222224
bpf->bpf_buffer = malloc(bpf->bpf_size);
223225
if (bpf->bpf_buffer == NULL)
224226
goto eexit;
227+
225228
return bpf;
226229

227230
eexit:

src/dhcp.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2236,12 +2236,18 @@ dhcp_arp_defend_failed(struct arp_state *astate)
22362236
{
22372237
struct interface *ifp = astate->iface;
22382238
struct dhcp_state *state = D_STATE(ifp);
2239+
unsigned int delay;
22392240

22402241
if (!(ifp->options->options & (DHCPCD_INFORM | DHCPCD_STATIC)))
22412242
dhcp_decline(ifp);
22422243
dhcp_drop(ifp, "EXPIRED");
22432244
dhcp_unlink(ifp->ctx, state->leasefile);
2244-
dhcp_start1(ifp);
2245+
2246+
// Delay restarting to give time for the BPF ARP process to exit
2247+
// as we may spawn a new one with a different filter fairly quickly
2248+
delay = MSEC_PER_SEC +
2249+
(arc4random_uniform(MSEC_PER_SEC * 2) - MSEC_PER_SEC);
2250+
eloop_timeout_add_msec(ifp->ctx->eloop, delay, dhcp_start1, ifp);
22452251
}
22462252
#endif
22472253

src/if-linux.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,7 @@ bpf_open(const struct interface *ifp,
18501850
if (bpf == NULL)
18511851
return NULL;
18521852
bpf->bpf_ifp = ifp;
1853+
bpf->bpf_flags = BPF_EOF;
18531854

18541855
/* Allocate a suitably large buffer for a single packet. */
18551856
bpf->bpf_size = ETH_FRAME_LEN;

0 commit comments

Comments
 (0)