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.
This commit is contained in:
Roy Marples 2016-02-04 21:42:14 +00:00
parent b699cc3d5c
commit 598e6cc727
5 changed files with 57 additions and 20 deletions

View File

@ -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);
}
}
}

View File

@ -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);
}

View File

@ -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

View File

@ -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);

View File

@ -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 *,