Mercurial > hg > dhcpcd
comparison src/dhcp.c @ 5528:274d31419935 draft
privsep: don't leave a BOOTP process hanging around on SIGUSR1
When not in master mode.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Fri, 30 Oct 2020 16:11:44 +0000 |
| parents | 8c0e5dc34824 |
| children | 16610f4104a4 |
comparison
equal
deleted
inserted
replaced
| 5527:071a9ea18363 | 5528:274d31419935 |
|---|---|
| 1518 logerr(__func__); /* try to continue */ | 1518 logerr(__func__); /* try to continue */ |
| 1519 } | 1519 } |
| 1520 #endif | 1520 #endif |
| 1521 } | 1521 } |
| 1522 | 1522 |
| 1523 void | 1523 static void |
| 1524 dhcp_close(struct interface *ifp) | 1524 dhcp_closebpf(struct interface *ifp) |
| 1525 { | 1525 { |
| 1526 struct dhcpcd_ctx *ctx = ifp->ctx; | 1526 struct dhcpcd_ctx *ctx = ifp->ctx; |
| 1527 struct dhcp_state *state = D_STATE(ifp); | 1527 struct dhcp_state *state = D_STATE(ifp); |
| 1528 | 1528 |
| 1529 if (state == NULL) | |
| 1530 return; | |
| 1531 | |
| 1532 #ifdef PRIVSEP | 1529 #ifdef PRIVSEP |
| 1533 if (IN_PRIVSEP_SE(ctx)) { | 1530 if (IN_PRIVSEP_SE(ctx)) |
| 1534 ps_bpf_closebootp(ifp); | 1531 ps_bpf_closebootp(ifp); |
| 1535 if (state->addr != NULL) | |
| 1536 ps_inet_closebootp(state->addr); | |
| 1537 } | |
| 1538 #endif | 1532 #endif |
| 1539 | 1533 |
| 1540 if (state->bpf != NULL) { | 1534 if (state->bpf != NULL) { |
| 1541 eloop_event_delete(ctx->eloop, state->bpf->bpf_fd); | 1535 eloop_event_delete(ctx->eloop, state->bpf->bpf_fd); |
| 1542 bpf_close(state->bpf); | 1536 bpf_close(state->bpf); |
| 1543 state->bpf = NULL; | 1537 state->bpf = NULL; |
| 1544 } | 1538 } |
| 1539 } | |
| 1540 | |
| 1541 static void | |
| 1542 dhcp_closeinet(struct interface *ifp) | |
| 1543 { | |
| 1544 struct dhcpcd_ctx *ctx = ifp->ctx; | |
| 1545 struct dhcp_state *state = D_STATE(ifp); | |
| 1546 | |
| 1547 #ifdef PRIVSEP | |
| 1548 if (IN_PRIVSEP_SE(ctx)) { | |
| 1549 if (state->addr != NULL) | |
| 1550 ps_inet_closebootp(state->addr); | |
| 1551 } | |
| 1552 #endif | |
| 1553 | |
| 1545 if (state->udp_rfd != -1) { | 1554 if (state->udp_rfd != -1) { |
| 1546 eloop_event_delete(ctx->eloop, state->udp_rfd); | 1555 eloop_event_delete(ctx->eloop, state->udp_rfd); |
| 1547 close(state->udp_rfd); | 1556 close(state->udp_rfd); |
| 1548 state->udp_rfd = -1; | 1557 state->udp_rfd = -1; |
| 1549 } | 1558 } |
| 1559 } | |
| 1560 | |
| 1561 void | |
| 1562 dhcp_close(struct interface *ifp) | |
| 1563 { | |
| 1564 struct dhcp_state *state = D_STATE(ifp); | |
| 1565 | |
| 1566 if (state == NULL) | |
| 1567 return; | |
| 1568 | |
| 1569 dhcp_closebpf(ifp); | |
| 1570 dhcp_closeinet(ifp); | |
| 1550 | 1571 |
| 1551 state->interval = 0; | 1572 state->interval = 0; |
| 1552 } | 1573 } |
| 1553 | 1574 |
| 1554 int | 1575 int |
| 1754 if (from.s_addr != INADDR_ANY && | 1775 if (from.s_addr != INADDR_ANY && |
| 1755 state->lease.server.s_addr != INADDR_ANY) | 1776 state->lease.server.s_addr != INADDR_ANY) |
| 1756 to.s_addr = state->lease.server.s_addr; | 1777 to.s_addr = state->lease.server.s_addr; |
| 1757 else | 1778 else |
| 1758 to.s_addr = INADDR_BROADCAST; | 1779 to.s_addr = INADDR_BROADCAST; |
| 1780 | |
| 1781 logdebugx("from %s", inet_ntoa(from)); | |
| 1782 logdebugx("to %s", inet_ntoa(to)); | |
| 1759 | 1783 |
| 1760 /* | 1784 /* |
| 1761 * If not listening on the unspecified address we can | 1785 * If not listening on the unspecified address we can |
| 1762 * only receive broadcast messages via BPF. | 1786 * only receive broadcast messages via BPF. |
| 1763 * Sockets bound to an address cannot receive broadcast messages | 1787 * Sockets bound to an address cannot receive broadcast messages |
| 2319 if (dhcp_writefile(ifp->ctx, state->leasefile, 0640, | 2343 if (dhcp_writefile(ifp->ctx, state->leasefile, 0640, |
| 2320 state->new, state->new_len) == -1) | 2344 state->new, state->new_len) == -1) |
| 2321 logerr("dhcp_writefile: %s", state->leasefile); | 2345 logerr("dhcp_writefile: %s", state->leasefile); |
| 2322 } | 2346 } |
| 2323 | 2347 |
| 2348 old_state = state->added; | |
| 2349 | |
| 2324 /* Close the BPF filter as we can now receive DHCP messages | 2350 /* Close the BPF filter as we can now receive DHCP messages |
| 2325 * on a UDP socket. */ | 2351 * on a UDP socket. */ |
| 2326 old_state = state->added; | 2352 dhcp_closebpf(ifp); |
| 2327 if (ctx->options & DHCPCD_MASTER || | 2353 |
| 2328 state->old == NULL || | 2354 /* Add the address */ |
| 2329 state->old->yiaddr != state->new->yiaddr || old_state & STATE_FAKE) | |
| 2330 dhcp_close(ifp); | |
| 2331 | |
| 2332 ipv4_applyaddr(ifp); | 2355 ipv4_applyaddr(ifp); |
| 2333 | 2356 |
| 2334 /* If not in master mode, open an address specific socket. */ | 2357 /* If not in master mode, open an address specific socket. */ |
| 2335 if (ctx->options & DHCPCD_MASTER || | 2358 if (ctx->options & DHCPCD_MASTER || |
| 2336 (state->old != NULL && | 2359 (state->old != NULL && |
| 2337 state->old->yiaddr == state->new->yiaddr && | 2360 state->old->yiaddr == state->new->yiaddr && |
| 2338 old_state & STATE_ADDED && !(old_state & STATE_FAKE))) | 2361 old_state & STATE_ADDED && !(old_state & STATE_FAKE))) |
| 2339 return; | 2362 return; |
| 2363 | |
| 2364 dhcp_closeinet(ifp); | |
| 2340 | 2365 |
| 2341 #ifdef PRIVSEP | 2366 #ifdef PRIVSEP |
| 2342 if (IN_PRIVSEP_SE(ctx)) { | 2367 if (IN_PRIVSEP_SE(ctx)) { |
| 2343 if (ps_inet_openbootp(state->addr) == -1) | 2368 if (ps_inet_openbootp(state->addr) == -1) |
| 2344 logerr(__func__); | 2369 logerr(__func__); |
