diff src/privsep-bpf.c @ 5523:357fddea9365 draft

privsep: Close BPF socket on ENXIO. This stops log spam if RTM_IFANNOUNCE is delayed for the departing interface.
author Roy Marples <roy@marples.name>
date Sun, 25 Oct 2020 15:30:13 +0000
parents 5aedb51585b6
children 99bfd2eb77ab
line wrap: on
line diff
--- a/src/privsep-bpf.c	Sun Oct 25 08:52:38 2020 +0000
+++ b/src/privsep-bpf.c	Sun Oct 25 15:30:13 2020 +0000
@@ -70,9 +70,21 @@
 	 * This mechanism allows us to read each packet from the buffer. */
 	while (!(bpf->bpf_flags & BPF_EOF)) {
 		len = bpf_read(bpf, buf, sizeof(buf));
-		if (len == -1)
-			logerr(__func__);
-		if (len == -1 || len == 0)
+		if (len == -1) {
+			int error = errno;
+
+			logerr("%s: %s", psp->psp_ifname, __func__);
+			if (error != ENXIO)
+				break;
+			/* If the interface has departed, close the BPF
+			 * socket. This stops log spam if RTM_IFANNOUNCE is
+			 * delayed in announcing the departing interface. */
+			eloop_event_delete(psp->psp_ctx->eloop, bpf->bpf_fd);
+			bpf_close(bpf);
+			psp->psp_bpf = NULL;
+			break;
+		}
+		if (len == 0)
 			break;
 		psm.ps_flags = bpf->bpf_flags;
 		len = ps_sendpsmdata(psp->psp_ctx, psp->psp_ctx->ps_data_fd,
@@ -107,6 +119,12 @@
 		return -1;
 	}
 
+	/* We might have had an earlier ENXIO error. */
+	if (psp->psp_bpf == NULL) {
+		errno = ENXIO;
+		return -1;
+	}
+
 	return bpf_send(psp->psp_bpf, psp->psp_proto,
 	    iov->iov_base, iov->iov_len);
 }