comparison src/dhcp.c @ 5535:a0d828e25482 draft

Add --noconfigure option With this set dhcpcd will not configure anything on the host. The expectation is that a 3rd party script will instead.
author Roy Marples <roy@marples.name>
date Wed, 04 Nov 2020 14:18:48 +0000
parents 226b850d158d
children bcca2ff28a64
comparison
equal deleted inserted replaced
5534:605f7f9a20c0 5535:a0d828e25482
2344 logerr("dhcp_writefile: %s", state->leasefile); 2344 logerr("dhcp_writefile: %s", state->leasefile);
2345 } 2345 }
2346 2346
2347 old_state = state->added; 2347 old_state = state->added;
2348 2348
2349 if (!(ifo->options & DHCPCD_CONFIGURE)) {
2350 struct ipv4_addr *ia;
2351
2352 script_runreason(ifp, state->reason);
2353 dhcpcd_daemonise(ifp->ctx);
2354
2355 /* We we are not configuring the address, we need to keep
2356 * the BPF socket open if the address does not exist. */
2357 ia = ipv4_iffindaddr(ifp, &state->lease.addr, NULL);
2358 if (ia != NULL) {
2359 state->addr = ia;
2360 state->added = STATE_ADDED;
2361 dhcp_closebpf(ifp);
2362 goto openudp;
2363 }
2364 return;
2365 }
2366
2349 /* Close the BPF filter as we can now receive DHCP messages 2367 /* Close the BPF filter as we can now receive DHCP messages
2350 * on a UDP socket. */ 2368 * on a UDP socket. */
2351 dhcp_closebpf(ifp); 2369 dhcp_closebpf(ifp);
2352 2370
2353 /* Add the address */ 2371 /* Add the address */
2354 ipv4_applyaddr(ifp); 2372 ipv4_applyaddr(ifp);
2355 2373
2374 openudp:
2356 /* If not in master mode, open an address specific socket. */ 2375 /* If not in master mode, open an address specific socket. */
2357 if (ctx->options & DHCPCD_MASTER || 2376 if (ctx->options & DHCPCD_MASTER ||
2358 (state->old != NULL && 2377 (state->old != NULL &&
2359 state->old->yiaddr == state->new->yiaddr && 2378 state->old->yiaddr == state->new->yiaddr &&
2360 old_state & STATE_ADDED && !(old_state & STATE_FAKE))) 2379 old_state & STATE_ADDED && !(old_state & STATE_FAKE)))
2361 return; 2380 return;
2362 2381
2363 dhcp_closeinet(ifp); 2382 dhcp_closeinet(ifp);
2364
2365 #ifdef PRIVSEP 2383 #ifdef PRIVSEP
2366 if (IN_PRIVSEP_SE(ctx)) { 2384 if (IN_PRIVSEP_SE(ctx)) {
2367 if (ps_inet_openbootp(state->addr) == -1) 2385 if (ps_inet_openbootp(state->addr) == -1)
2368 logerr(__func__); 2386 logerr(__func__);
2369 return; 2387 return;
2803 state->old = state->new; 2821 state->old = state->new;
2804 state->old_len = state->new_len; 2822 state->old_len = state->new_len;
2805 state->new = NULL; 2823 state->new = NULL;
2806 state->new_len = 0; 2824 state->new_len = 0;
2807 state->reason = reason; 2825 state->reason = reason;
2808 ipv4_applyaddr(ifp); 2826 if (ifp->options->options & DHCPCD_CONFIGURE)
2827 ipv4_applyaddr(ifp);
2828 else {
2829 state->addr = NULL;
2830 state->added = 0;
2831 script_runreason(ifp, state->reason);
2832 }
2809 free(state->old); 2833 free(state->old);
2810 state->old = NULL; 2834 state->old = NULL;
2811 state->old_len = 0; 2835 state->old_len = 0;
2812 state->lease.addr.s_addr = 0; 2836 state->lease.addr.s_addr = 0;
2813 ifp->options->options &= ~(DHCPCD_CSR_WARNED | 2837 ifp->options->options &= ~(DHCPCD_CSR_WARNED |
4217 else if (ia->addr_flags & IN_IFF_DUPLICATED) 4241 else if (ia->addr_flags & IN_IFF_DUPLICATED)
4218 return dhcp_addr_duplicated(ifp, &ia->addr) ? NULL : ia; 4242 return dhcp_addr_duplicated(ifp, &ia->addr) ? NULL : ia;
4219 #endif 4243 #endif
4220 4244
4221 ifo = ifp->options; 4245 ifo = ifp->options;
4246
4247 #ifdef PRIVSEP
4248 if (IN_PRIVSEP_SE(ifp->ctx) &&
4249 !(ifp->ctx->options & (DHCPCD_MASTER | DHCPCD_CONFIGURE)) &&
4250 IN_ARE_ADDR_EQUAL(&state->lease.addr, &ia->addr))
4251 {
4252 state->addr = ia;
4253 state->added = STATE_ADDED;
4254 dhcp_closebpf(ifp);
4255 if (ps_inet_openbootp(ia) == -1)
4256 logerr(__func__);
4257 }
4258 #endif
4259
4222 if (ifo->options & DHCPCD_INFORM) { 4260 if (ifo->options & DHCPCD_INFORM) {
4223 if (state->state != DHS_INFORM) 4261 if (state->state != DHS_INFORM)
4224 dhcp_inform(ifp); 4262 dhcp_inform(ifp);
4225 return ia; 4263 return ia;
4226 } 4264 }