From: Roy Marples Date: Sun, 10 Dec 2023 07:34:19 +0000 (+0000) Subject: Fully configure an interface when being activated. X-Git-Tag: v10.0.6~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=411e6539fd242224b320782eac4b4769f13a81fe;p=thirdparty%2Fdhcpcd.git Fully configure an interface when being activated. We need the full configuration - for example dhcpcd.conf might have environment options for the hooks for the interface being activated. Because we now guard against starting protocols with IF_ACTIVE_USER this is safe. Fixes #257. --- diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 5f8fc02b..3571aae0 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -657,20 +657,17 @@ configure_interface(struct interface *ifp, int argc, char **argv, } static void -dhcpcd_initstate2(struct interface *ifp, unsigned long long options) +dhcpcd_initstate1(struct interface *ifp, int argc, char **argv, + unsigned long long options) { struct if_options *ifo; - if (options) { - if ((ifo = default_config(ifp->ctx)) == NULL) { - logerr(__func__); - return; - } - ifo->options |= options; - free(ifp->options); - ifp->options = ifo; - } else - ifo = ifp->options; + configure_interface(ifp, argc, argv, options); + if (!ifp->active) + return; + + ifo = ifp->options; + ifo->options |= options; #ifdef INET6 if (ifo->options & DHCPCD_IPV6 && ipv6_init(ifp->ctx) == -1) { @@ -680,16 +677,6 @@ dhcpcd_initstate2(struct interface *ifp, unsigned long long options) #endif } -static void -dhcpcd_initstate1(struct interface *ifp, int argc, char **argv, - unsigned long long options) -{ - - configure_interface(ifp, argc, argv, options); - if (ifp->active) - dhcpcd_initstate2(ifp, 0); -} - static void dhcpcd_initstate(struct interface *ifp, unsigned long long options) { @@ -1033,15 +1020,17 @@ dhcpcd_activateinterface(struct interface *ifp, unsigned long long options) if (ifp->active) return; + /* IF_ACTIVE_USER will start protocols when the interface is started. + * IF_ACTIVE will ask the protocols for setup, + * such as any delegated prefixes. */ ifp->active = IF_ACTIVE; - dhcpcd_initstate2(ifp, options); + dhcpcd_initstate(ifp, options); /* It's possible we might not have been able to load * a config. */ if (!ifp->active) return; - configure_interface1(ifp); run_preinit(ifp); dhcpcd_prestartinterface(ifp); } diff --git a/src/if-options.c b/src/if-options.c index 9c930f38..b28e4ee2 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -2407,7 +2407,7 @@ finish_config(struct if_options *ifo) ~(DHCPCD_IPV6RA_AUTOCONF | DHCPCD_IPV6RA_REQRDNSS); } -struct if_options * +static struct if_options * default_config(struct dhcpcd_ctx *ctx) { struct if_options *ifo; diff --git a/src/if-options.h b/src/if-options.h index b37a08d3..53914655 100644 --- a/src/if-options.h +++ b/src/if-options.h @@ -285,7 +285,6 @@ struct if_options { struct auth auth; }; -struct if_options *default_config(struct dhcpcd_ctx *); struct if_options *read_config(struct dhcpcd_ctx *, const char *, const char *, const char *); int add_options(struct dhcpcd_ctx *, const char *,