From: Roy Marples Date: Thu, 4 Feb 2016 10:43:16 +0000 (+0000) Subject: Introduce IF_INACTIVE, IF_ACTIVE and IF_ACTIVE_USER flags. The intent is that IF_ACTI... X-Git-Tag: v6.10.2~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b699cc3d5ccaf0615bb1d1fe7f569e55196f234a;p=thirdparty%2Fdhcpcd.git Introduce IF_INACTIVE, IF_ACTIVE and IF_ACTIVE_USER flags. The intent is that IF_ACTIVE is an interface is active with a system config and IF_ACTIVE_USER with a user config. --- diff --git a/dhcpcd.c b/dhcpcd.c index 51c15fd5..3ae4bac6 100644 --- 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) { diff --git a/dhcpcd.h b/dhcpcd.h index 3ad73664..4e63b26e 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -45,6 +45,10 @@ #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 b3df1681..49c273a6 100644 --- a/if.c +++ b/if.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2015 Roy Marples + * Copyright (c) 2006-2016 Roy Marples * 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 */