Skip to content

Commit

Permalink
Fully configure an interface when being activated.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rsmarples committed Dec 14, 2023
1 parent 0a0bbfe commit 411e653
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
35 changes: 12 additions & 23 deletions src/dhcpcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/if-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/if-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *,
Expand Down

0 comments on commit 411e653

Please sign in to comment.