]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
privsep: Don't close BPF listeners when forked
authorRoy Marples <roy@marples.name>
Fri, 29 Nov 2019 00:32:42 +0000 (00:32 +0000)
committerRoy Marples <roy@marples.name>
Fri, 29 Nov 2019 00:32:42 +0000 (00:32 +0000)
The normal flow is just to release resources for sanitisers.

src/arp.c
src/dhcp.c

index a07ca09dac775edb528b6888af3d223e4437af6c..3c395035798e29f3c037911cc8dc64d304a32a63 100644 (file)
--- a/src/arp.c
+++ b/src/arp.c
@@ -272,13 +272,14 @@ arp_packet(struct interface *ifp, uint8_t *data, size_t len)
 static void
 arp_close(struct interface *ifp)
 {
+       struct dhcpcd_ctx *ctx = ifp->ctx;
        struct iarp_state *state;
 
        if ((state = ARP_STATE(ifp)) == NULL)
                return;
 
 #ifdef PRIVSEP
-       if (ifp->ctx->options & DHCPCD_PRIVSEP) {
+       if ((ctx->options & (DHCPCD_PRIVSEP|DHCPCD_FORKED)) == DHCPCD_PRIVSEP) {
                if (ps_bpf_closearp(ifp) == -1)
                        logerr(__func__);
        }
@@ -286,7 +287,7 @@ arp_close(struct interface *ifp)
 
        if (state->bpf_fd == -1)
                return;
-       eloop_event_delete(ifp->ctx->eloop, state->bpf_fd);
+       eloop_event_delete(ctx->eloop, state->bpf_fd);
        bpf_close(ifp, state->bpf_fd);
        state->bpf_fd = -1;
        state->bpf_flags |= BPF_EOF;
index f3f8592c83afc8116586b03debde612dfd2128f3..d16c649f867437f7a4ebf5c62cb667ff5983c7d7 100644 (file)
@@ -1520,13 +1520,14 @@ again:
 void
 dhcp_close(struct interface *ifp)
 {
+       struct dhcpcd_ctx *ctx = ifp->ctx;
        struct dhcp_state *state = D_STATE(ifp);
 
        if (state == NULL)
                return;
 
 #ifdef PRIVSEP
-       if (ifp->ctx->options & DHCPCD_PRIVSEP) {
+       if ((ctx->options & (DHCPCD_PRIVSEP|DHCPCD_FORKED)) == DHCPCD_PRIVSEP) {
                ps_bpf_closebootp(ifp);
                if (state->addr != NULL)
                        ps_inet_closebootp(state->addr);
@@ -1534,13 +1535,13 @@ dhcp_close(struct interface *ifp)
 #endif
 
        if (state->bpf_fd != -1) {
-               eloop_event_delete(ifp->ctx->eloop, state->bpf_fd);
+               eloop_event_delete(ctx->eloop, state->bpf_fd);
                bpf_close(ifp, state->bpf_fd);
                state->bpf_fd = -1;
                state->bpf_flags |= BPF_EOF;
        }
        if (state->udp_fd != -1) {
-               eloop_event_delete(ifp->ctx->eloop, state->udp_fd);
+               eloop_event_delete(ctx->eloop, state->udp_fd);
                close(state->udp_fd);
                state->udp_fd = -1;
        }