]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fully configure an interface when being activated.
authorRoy Marples <roy@marples.name>
Sun, 10 Dec 2023 07:34:19 +0000 (07:34 +0000)
committerRoy Marples <roy@marples.name>
Thu, 14 Dec 2023 22:56:00 +0000 (22:56 +0000)
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.

src/dhcpcd.c
src/if-options.c
src/if-options.h

index 5f8fc02b82b6bca68f4ff4d8c8ead5fccb5f40d5..3571aae0c5dd959064db95829019a447f652e90e 100644 (file)
@@ -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);
 }
index 9c930f3817ef90dd299981e796c8131d59268145..b28e4ee2616df58b22de632acd556491bcc240a1 100644 (file)
@@ -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;
index b37a08d3fe7d4415357ebbfc45fc95bb0a0c6017..53914655df50546cb1994153abbad01287af3d7d 100644 (file)
@@ -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 *,