From: Roy Marples Date: Thu, 4 Feb 2016 21:42:14 +0000 (+0000) Subject: When activating an interface, bring up a basic config that does nothing. X-Git-Tag: v6.10.2~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=598e6cc727c427221a5041f5dcaa7e196b3ac4ce;p=thirdparty%2Fdhcpcd.git When activating an interface, bring up a basic config that does nothing. Then apply enough of the config for the base protocol, passed via an argument, to work. This means that when a prefix is delegated to an inactive interface, it won't magically start configuring IPv4 on it. --- diff --git a/dhcp6.c b/dhcp6.c index 0615cc32..7dd5a192 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -3047,7 +3047,6 @@ recv: ipv6nd_runignoredra(ifp); ipv6_addaddrs(&state->addrs); - dhcp6_delegate_prefix(ifp); if (state->state == DH6S_INFORMED) logger(ifp->ctx, has_new ? LOG_INFO : LOG_DEBUG, @@ -3064,6 +3063,7 @@ recv: if_initrt6(ifp); ipv6_buildroutes(ifp->ctx); dhcp6_writelease(ifp); + dhcp6_delegate_prefix(ifp); dhcp6_script_try_run(ifp, 0); } @@ -3188,7 +3188,8 @@ dhcp6_start1(void *arg) logger(ifp->ctx, LOG_INFO, "%s: activating for delegation", sla->ifname); - dhcpcd_activateinterface(ifd); + dhcpcd_activateinterface(ifd, + DHCPCD_IPV6 | DHCPCD_DHCP6); } } } diff --git a/dhcpcd.c b/dhcpcd.c index 3ae4bac6..28e4d0a0 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -671,13 +671,21 @@ dhcpcd_pollup(void *arg) } static void -dhcpcd_initstate1(struct interface *ifp, int argc, char **argv, - unsigned long long options) +dhcpcd_initstate2(struct interface *ifp, unsigned long long options) { struct if_options *ifo; - configure_interface(ifp, argc, argv, options); - ifo = ifp->options; + if (options) { + if ((ifo = default_config(ifp->ctx)) == NULL) { + logger(ifp->ctx, LOG_ERR, "%s: %s: %m", + ifp->name, __func__); + return; + } + ifo->options |= options; + free(ifp->options); + ifp->options = ifo; + } else + ifo = ifp->options; if (ifo->options & DHCPCD_IPV4 && ipv4_init(ifp->ctx) == -1) { logger(ifp->ctx, LOG_ERR, "ipv4_init: %m"); @@ -698,6 +706,15 @@ dhcpcd_initstate1(struct interface *ifp, int argc, char **argv, } } +static void +dhcpcd_initstate1(struct interface *ifp, int argc, char **argv, + unsigned long long options) +{ + + configure_interface(ifp, argc, argv, options); + dhcpcd_initstate2(ifp, 0); +} + static void dhcpcd_initstate(struct interface *ifp, unsigned long long options) { @@ -999,12 +1016,13 @@ run_preinit(struct interface *ifp) } void -dhcpcd_activateinterface(struct interface *ifp) +dhcpcd_activateinterface(struct interface *ifp, unsigned long long options) { if (!ifp->active) { ifp->active = IF_ACTIVE; - dhcpcd_initstate(ifp, 0); + dhcpcd_initstate2(ifp, options); + configure_interface1(ifp); run_preinit(ifp); dhcpcd_prestartinterface(ifp); } diff --git a/dhcpcd.h b/dhcpcd.h index 4e63b26e..b74dbacb 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -206,6 +206,6 @@ void dhcpcd_dropinterface(struct interface *, const char *); int dhcpcd_selectprofile(struct interface *, const char *); void dhcpcd_startinterface(void *); -void dhcpcd_activateinterface(struct interface *); +void dhcpcd_activateinterface(struct interface *, unsigned long long); #endif diff --git a/if-options.c b/if-options.c index f9264ff1..ff28aa39 100644 --- a/if-options.c +++ b/if-options.c @@ -2140,6 +2140,32 @@ get_line(char ** __restrict buf, size_t * __restrict buflen, return p; } +struct if_options * +default_config(struct dhcpcd_ctx *ctx) +{ + struct if_options *ifo; + + /* Seed our default options */ + if ((ifo = calloc(1, sizeof(*ifo))) == NULL) { + logger(ctx, LOG_ERR, "%s: %m", __func__); + return NULL; + } + ifo->options |= DHCPCD_IF_UP | DHCPCD_LINK | DHCPCD_INITIAL_DELAY; + ifo->timeout = DEFAULT_TIMEOUT; + ifo->reboot = DEFAULT_REBOOT; + ifo->metric = -1; + ifo->auth.options |= DHCPCD_AUTH_REQUIRE; + TAILQ_INIT(&ifo->auth.tokens); + + /* Inherit some global defaults */ + if (ctx->options & DHCPCD_PERSISTENT) + ifo->options |= DHCPCD_PERSISTENT; + if (ctx->options & DHCPCD_SLAACPRIVATE) + ifo->options |= DHCPCD_SLAACPRIVATE; + + return ifo; +} + struct if_options * read_config(struct dhcpcd_ctx *ctx, const char *ifname, const char *ssid, const char *profile) @@ -2162,13 +2188,9 @@ read_config(struct dhcpcd_ctx *ctx, struct dhcp_opt *ldop, *edop; /* Seed our default options */ - ifo = calloc(1, sizeof(*ifo)); - if (ifo == NULL) { - logger(ctx, LOG_ERR, "%s: %m", __func__); + if ((ifo = default_config(ctx)) == NULL) return NULL; - } - ifo->options |= DHCPCD_DAEMONISE | DHCPCD_LINK | DHCPCD_INITIAL_DELAY; - ifo->options |= DHCPCD_IF_UP; + ifo->options |= DHCPCD_DAEMONISE; #ifdef PLUGIN_DEV ifo->options |= DHCPCD_DEV; #endif @@ -2181,11 +2203,6 @@ read_config(struct dhcpcd_ctx *ctx, ifo->options |= DHCPCD_IPV6RA_AUTOCONF | DHCPCD_IPV6RA_REQRDNSS; ifo->options |= DHCPCD_DHCP6; #endif - ifo->timeout = DEFAULT_TIMEOUT; - ifo->reboot = DEFAULT_REBOOT; - ifo->metric = -1; - ifo->auth.options |= DHCPCD_AUTH_REQUIRE; - TAILQ_INIT(&ifo->auth.tokens); vlen = dhcp_vendor((char *)ifo->vendorclassid + 1, sizeof(ifo->vendorclassid) - 1); diff --git a/if-options.h b/if-options.h index 6c7ab153..7d7e7c11 100644 --- a/if-options.h +++ b/if-options.h @@ -215,6 +215,7 @@ 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 *,