Mercurial > hg > dhcpcd
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 5522:75fdbbc9e1a5 | 5523:357fddea9365 |
|---|---|
| 68 bpf->bpf_flags &= ~BPF_EOF; | 68 bpf->bpf_flags &= ~BPF_EOF; |
| 69 /* A BPF read can read more than one filtered packet at time. | 69 /* A BPF read can read more than one filtered packet at time. |
| 70 * This mechanism allows us to read each packet from the buffer. */ | 70 * This mechanism allows us to read each packet from the buffer. */ |
| 71 while (!(bpf->bpf_flags & BPF_EOF)) { | 71 while (!(bpf->bpf_flags & BPF_EOF)) { |
| 72 len = bpf_read(bpf, buf, sizeof(buf)); | 72 len = bpf_read(bpf, buf, sizeof(buf)); |
| 73 if (len == -1) | 73 if (len == -1) { |
| 74 logerr(__func__); | 74 int error = errno; |
| 75 if (len == -1 || len == 0) | 75 |
| 76 logerr("%s: %s", psp->psp_ifname, __func__); | |
| 77 if (error != ENXIO) | |
| 78 break; | |
| 79 /* If the interface has departed, close the BPF | |
| 80 * socket. This stops log spam if RTM_IFANNOUNCE is | |
| 81 * delayed in announcing the departing interface. */ | |
| 82 eloop_event_delete(psp->psp_ctx->eloop, bpf->bpf_fd); | |
| 83 bpf_close(bpf); | |
| 84 psp->psp_bpf = NULL; | |
| 85 break; | |
| 86 } | |
| 87 if (len == 0) | |
| 76 break; | 88 break; |
| 77 psm.ps_flags = bpf->bpf_flags; | 89 psm.ps_flags = bpf->bpf_flags; |
| 78 len = ps_sendpsmdata(psp->psp_ctx, psp->psp_ctx->ps_data_fd, | 90 len = ps_sendpsmdata(psp->psp_ctx, psp->psp_ctx->ps_data_fd, |
| 79 &psm, buf, (size_t)len); | 91 &psm, buf, (size_t)len); |
| 80 if (len == -1) | 92 if (len == -1) |
| 105 * at this point!/ */ | 117 * at this point!/ */ |
| 106 errno = EINVAL; | 118 errno = EINVAL; |
| 107 return -1; | 119 return -1; |
| 108 } | 120 } |
| 109 | 121 |
| 122 /* We might have had an earlier ENXIO error. */ | |
| 123 if (psp->psp_bpf == NULL) { | |
| 124 errno = ENXIO; | |
| 125 return -1; | |
| 126 } | |
| 127 | |
| 110 return bpf_send(psp->psp_bpf, psp->psp_proto, | 128 return bpf_send(psp->psp_bpf, psp->psp_proto, |
| 111 iov->iov_base, iov->iov_len); | 129 iov->iov_base, iov->iov_len); |
| 112 } | 130 } |
| 113 | 131 |
| 114 static void | 132 static void |
