]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Introduce IF_INACTIVE, IF_ACTIVE and IF_ACTIVE_USER flags. The intent is that IF_ACTI...
authorRoy Marples <roy@marples.name>
Thu, 4 Feb 2016 10:43:16 +0000 (10:43 +0000)
committerRoy Marples <roy@marples.name>
Thu, 4 Feb 2016 10:43:16 +0000 (10:43 +0000)
dhcpcd.c
dhcpcd.h
if.c

index 51c15fd59c57fdb5a0c5455911f26619f9703934..3ae4bac6c58bc4d4ba503562ea164c38f2f18edd 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -226,7 +226,7 @@ dhcpcd_ifafwaiting(const struct interface *ifp)
 {
        unsigned long long opts;
 
-       if (!ifp->active)
+       if (ifp->active != IF_ACTIVE_USER)
                return AF_MAX;
 
        opts = ifp->options->options;
@@ -424,7 +424,7 @@ stop_interface(struct interface *ifp)
        eloop_q_timeout_delete(ctx->eloop, 0, NULL, ifp);
 
        /* De-activate the interface */
-       ifp->active = 0;
+       ifp->active = IF_INACTIVE;
 
 stop:
        if (!(ctx->options & (DHCPCD_MASTER | DHCPCD_TEST)))
@@ -1003,7 +1003,7 @@ dhcpcd_activateinterface(struct interface *ifp)
 {
 
        if (!ifp->active) {
-               ifp->active = 1;
+               ifp->active = IF_ACTIVE;
                dhcpcd_initstate(ifp, 0);
                run_preinit(ifp);
                dhcpcd_prestartinterface(ifp);
@@ -1067,7 +1067,7 @@ dhcpcd_handleinterface(void *arg, int action, const char *ifname)
                                if (strcmp(ctx->ifv[i], ifname) == 0)
                                        break;
                        if (i >= ctx->ifc)
-                               ifp->active = 0;
+                               ifp->active = IF_INACTIVE;
                }
 
                i = 0;
@@ -1184,7 +1184,7 @@ reconf_reboot(struct dhcpcd_ctx *ctx, int action, int argc, char **argv, int oi)
                        else
                                ipv4_applyaddr(ifp);
                } else if (i != argc) {
-                       ifp->active = 1;
+                       ifp->active = IF_ACTIVE_USER;
                        dhcpcd_initstate1(ifp, argc, argv, 0);
                        run_preinit(ifp);
                        dhcpcd_prestartinterface(ifp);
@@ -1908,7 +1908,7 @@ printpidfile:
                            ctx.ifv[i]);
        }
        TAILQ_FOREACH(ifp, ctx.ifaces, next) {
-               if (ifp->active)
+               if (ifp->active == IF_ACTIVE_USER)
                        break;
        }
        if (ifp == NULL) {
index 3ad736648ff0268f86919ee2d70642982bf68e5e..4e63b26e94fd97973cbc11b7c26c784e91b5fe80 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
 #define PROFILE_LEN    64
 #define SECRET_LEN     64
 
+#define IF_INACTIVE    0
+#define IF_ACTIVE      1
+#define IF_ACTIVE_USER 2
+
 #define LINK_UP                1
 #define LINK_UNKNOWN   0
 #define LINK_DOWN      -1
diff --git a/if.c b/if.c
index b3df1681ef889013d64c9c0a5947b8798c3e4438..49c273a6feae9c83d91c21fb46a4f6e4c2c5b212 100644 (file)
--- a/if.c
+++ b/if.c
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2016 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -289,7 +289,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                if (ifp)
                        continue;
 
-               active = 1;
+               active = IF_ACTIVE_USER;
                if (argc > 0) {
                        for (i = 0; i < argc; i++) {
 #ifdef __linux__
@@ -306,7 +306,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
 #endif
                        }
                        if (i == argc) {
-                               active = 0;
+                               active = IF_INACTIVE;
                                p =  ifa->ifa_name;
 #ifdef __linux__
                                strlcpy(ifn, ifa->ifa_name, sizeof(ifn));
@@ -329,12 +329,12 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                        if (!fnmatch(ctx->ifdv[i], p, 0))
                                break;
                if (i < ctx->ifdc)
-                       active = 0;
+                       active = IF_INACTIVE;
                for (i = 0; i < ctx->ifac; i++)
                        if (!fnmatch(ctx->ifav[i], p, 0))
                                break;
                if (ctx->ifac && i == ctx->ifac)
-                       active = 0;
+                       active = IF_INACTIVE;
 
 #ifdef PLUGIN_DEV
                /* Ensure that the interface name has settled */
@@ -346,7 +346,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                if (ifa->ifa_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) {
                        if ((argc == 0 || argc == -1) &&
                            ctx->ifac == 0 && !if_hasconf(ctx, p))
-                               active = 0;
+                               active = IF_INACTIVE;
                }
 
                if (if_vimaster(ctx, p) == 1) {
@@ -412,7 +412,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                                            " interface type and"
                                            " no config",
                                            ifp->name);
-                                       active = 0;
+                                       active = IF_INACTIVE;
                                }
                                /* FALLTHROUGH */
 #endif
@@ -440,7 +440,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                                if ((argc == 0 || argc == -1) &&
                                    ctx->ifac == 0 &&
                                    !if_hasconf(ctx, ifp->name))
-                                       active = 0;
+                                       active = IF_INACTIVE;
                                if (active)
                                        logger(ifp->ctx, LOG_WARNING,
                                            "%s: unsupported"
@@ -474,7 +474,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                if (ifp->family != ARPHRD_ETHER) {
                        if ((argc == 0 || argc == -1) &&
                            ctx->ifac == 0 && !if_hasconf(ctx, ifp->name))
-                               active = 0;
+                               active = IF_INACTIVE;
                        switch (ifp->family) {
                        case ARPHRD_IEEE1394:
                        case ARPHRD_INFINIBAND:
@@ -604,9 +604,9 @@ if_cmp(const struct interface *si, const struct interface *ti)
 #endif
 
        /* Check active first */
-       if (si->active && !ti->active)
+       if (si->active ti->active)
                return -1;
-       if (!si->active && ti->active)
+       if (si->active < ti->active)
                return 1;
 
        /* Check carrier status next */