]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
When activating an interface, bring up a basic config that does nothing.
authorRoy Marples <roy@marples.name>
Thu, 4 Feb 2016 21:42:14 +0000 (21:42 +0000)
committerRoy Marples <roy@marples.name>
Thu, 4 Feb 2016 21:42:14 +0000 (21:42 +0000)
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.

dhcp6.c
dhcpcd.c
dhcpcd.h
if-options.c
if-options.h

diff --git a/dhcp6.c b/dhcp6.c
index 0615cc323384dacf5ef0a773bd8bac7d5d585bfd..7dd5a1924b6ac9f0ff3274d97363e295a3ba31d9 100644 (file)
--- 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);
                        }
                }
        }
index 3ae4bac6c58bc4d4ba503562ea164c38f2f18edd..28e4d0a0314a0d46ff2a54121e3c6b2264a248bb 100644 (file)
--- 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);
        }
index 4e63b26e94fd97973cbc11b7c26c784e91b5fe80..b74dbacb3a0b7d7a6205ca7b10bfcc74a7e9b819 100644 (file)
--- 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
index f9264ff1866dccfde4f38d7c448bdd5ec4f3451d..ff28aa39a40f65f9fa54b5d82be448adf4013352 100644 (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);
index 6c7ab153b26d93884419b733b888173840c4e21b..7d7e7c11cb68e34d2f0cfd62ba2d3ef8bc74e15e 100644 (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 *,