]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Remove if_oneup and replace with if_afwaited and af_waited.
authorRoy Marples <roy@marples.name>
Tue, 9 Jun 2015 19:47:53 +0000 (19:47 +0000)
committerRoy Marples <roy@marples.name>
Tue, 9 Jun 2015 19:47:53 +0000 (19:47 +0000)
If present, they will show the address family waiting for.

dhcp6.c
dhcp6.h
dhcpcd.c
dhcpcd.h
ipv6.c
ipv6.h
ipv6nd.c
script.c

diff --git a/dhcp6.c b/dhcp6.c
index 363b29ba710eaaed889de8821dab5b2198305670..d551cc79b8501cd3ca9cbe6f1eed73ac81ac8d97 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -1682,24 +1682,16 @@ dhcp6_checkstatusok(const struct interface *ifp,
        return -1;
 }
 
-struct ipv6_addr *
-dhcp6_iffindaddr(struct interface *ifp, const struct in6_addr *addr,
+const struct ipv6_addr *
+dhcp6_iffindaddr(const struct interface *ifp, const struct in6_addr *addr,
     short flags)
 {
-       struct dhcp6_state *state;
-       struct ipv6_addr *ap;
+       const struct dhcp6_state *state;
+       const struct ipv6_addr *ap;
 
-       state = D6_STATE(ifp);
-       if (state) {
+       if ((state = D6_STATE(ifp)) != NULL) {
                TAILQ_FOREACH(ap, &state->addrs, next) {
-                       if (addr == NULL) {
-                               if ((ap->flags &
-                                   (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED)) ==
-                                   (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED))
-                                       return ap;
-                       } else if (ap->prefix_vltime &&
-                           IN6_ARE_ADDR_EQUAL(&ap->addr, addr) &&
-                           (!flags || ap->flags & flags))
+                       if (ipv6_findaddrmatch(ap, addr, flags))
                                return ap;
                }
        }
@@ -1712,11 +1704,15 @@ dhcp6_findaddr(struct dhcpcd_ctx *ctx, const struct in6_addr *addr,
 {
        struct interface *ifp;
        struct ipv6_addr *ap;
+       struct dhcp6_state *state;
 
        TAILQ_FOREACH(ifp, ctx->ifaces, next) {
-               ap = dhcp6_iffindaddr(ifp, addr, flags);
-               if (ap)
-                       return ap;
+               if ((state = D6_STATE(ifp)) != NULL) {
+                       TAILQ_FOREACH(ap, &state->addrs, next) {
+                               if (ipv6_findaddrmatch(ap, addr, flags))
+                                       return ap;
+                       }
+               }
        }
        return NULL;
 }
@@ -1751,7 +1747,10 @@ dhcp6_findna(struct interface *ifp, uint16_t ot, const uint8_t *iaid,
                        continue;
                }
                iap = (const struct dhcp6_ia_addr *)D6_COPTION_DATA(o);
-               a = dhcp6_iffindaddr(ifp, &iap->addr, 0);
+               TAILQ_FOREACH(a, &state->addrs, next) {
+                       if (ipv6_findaddrmatch(a, &iap->addr, 0))
+                               break;
+               }
                if (a == NULL) {
                        a = calloc(1, sizeof(*a));
                        if (a == NULL) {
diff --git a/dhcp6.h b/dhcp6.h
index 90f60fc089c6148e564504552b2bac07dee383b5..7de5fd75f4b48c7806c179141cc32c943585eaef 100644 (file)
--- a/dhcp6.h
+++ b/dhcp6.h
@@ -232,7 +232,7 @@ struct dhcp6_state {
 #ifdef INET6
 void dhcp6_printoptions(const struct dhcpcd_ctx *,
     const struct dhcp_opt *, size_t);
-struct ipv6_addr *dhcp6_iffindaddr(struct interface *ifp,
+const struct ipv6_addr *dhcp6_iffindaddr(const struct interface *ifp,
     const struct in6_addr *addr, short flags);
 struct ipv6_addr *dhcp6_findaddr(struct dhcpcd_ctx *, const struct in6_addr *,
     short);
index a9d929dc9352a4636a88629f24efb34be02cda12..94a424337f663d130edf79b38f1215419c094c7d 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -206,20 +206,6 @@ handle_exit_timeout(void *arg)
        dhcpcd_daemonise(ctx);
 }
 
-int
-dhcpcd_oneup(struct dhcpcd_ctx *ctx)
-{
-       const struct interface *ifp;
-
-       TAILQ_FOREACH(ifp, ctx->ifaces, next) {
-               if (D_STATE_RUNNING(ifp) ||
-                   RS_STATE_RUNNING(ifp) ||
-                   D6_STATE_RUNNING(ifp))
-                       return 1;
-       }
-       return 0;
-}
-
 static const char *
 dhcpcd_af(int af)
 {
@@ -236,10 +222,12 @@ dhcpcd_af(int af)
        }
 }
 
-static int
-dhcpcd_ifafwaiting(struct interface *ifp, unsigned long long opts)
+int
+dhcpcd_ifafwaiting(const struct interface *ifp)
 {
+       unsigned long long opts;
 
+       opts = ifp->options->options;
        if (opts & DHCPCD_WAITIP4 && !ipv4_hasaddr(ifp))
                return AF_INET;
        if (opts & DHCPCD_WAITIP6 && !ipv6_hasaddr(ifp))
@@ -251,27 +239,15 @@ dhcpcd_ifafwaiting(struct interface *ifp, unsigned long long opts)
        return AF_MAX;
 }
 
-static int
-dhcpcd_ipwaited(struct dhcpcd_ctx *ctx)
+int
+dhcpcd_afwaiting(const struct dhcpcd_ctx *ctx)
 {
-       struct interface *ifp;
-       int af;
        unsigned long long opts;
-
-       TAILQ_FOREACH(ifp, ctx->ifaces, next) {
-               if (ifp->options->options & DHCPCD_WAITOPTS) {
-                       af = dhcpcd_ifafwaiting(ifp, ifp->options->options);
-                       if (af != AF_MAX) {
-                               logger(ctx, LOG_DEBUG,
-                                   "%s: waiting for an %s address",
-                                   ifp->name, dhcpcd_af(af));
-                               return 0;
-                       }
-               }
-       }
+       const struct interface *ifp;
+       int af;
 
        if (!(ctx->options & DHCPCD_WAITOPTS))
-               return 1;
+               return AF_MAX;
 
        opts = ctx->options;
        TAILQ_FOREACH(ifp, ctx->ifaces, next) {
@@ -291,10 +267,33 @@ dhcpcd_ipwaited(struct dhcpcd_ctx *ctx)
        else if (opts & DHCPCD_WAITIP6)
                af = AF_INET6;
        else
-               return 1;
+               return AF_MAX;
+       return af;
+}
 
-       logger(ctx, LOG_DEBUG, "waiting for an %s address", dhcpcd_af(af));
-       return 0;
+static int
+dhcpcd_ipwaited(struct dhcpcd_ctx *ctx)
+{
+       struct interface *ifp;
+       int af;
+
+       TAILQ_FOREACH(ifp, ctx->ifaces, next) {
+               if ((af = dhcpcd_ifafwaiting(ifp)) != AF_MAX) {
+                       logger(ctx, LOG_DEBUG,
+                           "%s: waiting for an %s address",
+                           ifp->name, dhcpcd_af(af));
+                       return 0;
+               }
+       }
+
+       if ((af = dhcpcd_afwaiting(ctx)) != AF_MAX) {
+               logger(ctx, LOG_DEBUG,
+                   "waiting for an %s address",
+                   dhcpcd_af(af));
+               return 0;
+       }
+
+       return 1;
 }
 
 /* Returns the pid of the child, otherwise 0. */
index 229a640a1af90c720b8fbb55b0a53c76ce8f5551..c2f9befe7f25c195d7132b8f9464c1ff9366ea1b 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -162,7 +162,8 @@ extern const int dhcpcd_signals[];
 extern const size_t dhcpcd_signals_len;
 #endif
 
-int dhcpcd_oneup(struct dhcpcd_ctx *);
+int dhcpcd_ifafwaiting(const struct interface *);
+int dhcpcd_afwaiting(const struct dhcpcd_ctx *);
 pid_t dhcpcd_daemonise(struct dhcpcd_ctx *);
 
 int dhcpcd_handleargs(struct dhcpcd_ctx *, struct fd_list *, int, char **);
diff --git a/ipv6.c b/ipv6.c
index f9119d4812011215ee4e225580599ac98b628a9e..00d74b46acaf778d3a2d10e91fa03f03d552ede4 100644 (file)
--- a/ipv6.c
+++ b/ipv6.c
@@ -752,6 +752,24 @@ ipv6_publicaddr(const struct ipv6_addr *ia)
            !(ia->addr_flags & IN6_IFF_NOTUSEABLE));
 }
 
+int
+ipv6_findaddrmatch(const struct ipv6_addr *addr, const struct in6_addr *match,
+    short flags)
+{
+
+       if (match == NULL) {
+               if ((addr->flags &
+                   (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED)) ==
+                   (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED))
+                       return 1;
+       } else if (addr->prefix_vltime &&
+           IN6_ARE_ADDR_EQUAL(&addr->addr, match) &&
+           (!flags || addr->flags & flags))
+               return 1;
+
+       return 0;
+}
+
 struct ipv6_addr *
 ipv6_findaddr(struct dhcpcd_ctx *ctx, const struct in6_addr *addr, short flags)
 {
@@ -1030,7 +1048,7 @@ ipv6_handleifa(struct dhcpcd_ctx *ctx,
 }
 
 int
-ipv6_hasaddr(struct interface *ifp)
+ipv6_hasaddr(const struct interface *ifp)
 {
 
        if (ipv6nd_iffindaddr(ifp, NULL, 0) != NULL)
diff --git a/ipv6.h b/ipv6.h
index f7f2e1106dfdaeea856f707cfc0f8620ec0d9204..c7840ff2642934b19fd2359b4f677814020fdef9 100644 (file)
--- a/ipv6.h
+++ b/ipv6.h
@@ -249,7 +249,9 @@ int ipv6_handleifa_addrs(int, struct ipv6_addrhead *,
 int ipv6_publicaddr(const struct ipv6_addr *);
 const struct ipv6_addr *ipv6_iffindaddr(const struct interface *,
     const struct in6_addr *);
-int ipv6_hasaddr(struct interface *);
+int ipv6_hasaddr(const struct interface *);
+int ipv6_findaddrmatch(const struct ipv6_addr *, const struct in6_addr *,
+    short);
 struct ipv6_addr *ipv6_findaddr(struct dhcpcd_ctx *,
     const struct in6_addr *, short);
 #define ipv6_linklocal(ifp) ipv6_iffindaddr((ifp), NULL)
index 74b11cacee4bdf95348aad0dc1f21057757202fb..fe368dbd037e63400ee4ba960d2c1c154d19af63 100644 (file)
--- a/ipv6nd.c
+++ b/ipv6nd.c
@@ -432,19 +432,13 @@ ipv6nd_iffindaddr(const struct interface *ifp, const struct in6_addr *addr,
                if (rap->iface != ifp)
                        continue;
                TAILQ_FOREACH(ap, &rap->addrs, next) {
-                       if (addr == NULL) {
-                               if ((ap->flags &
-                                   (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED)) ==
-                                   (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED))
-                                       return ap;
-                       } else if (ap->prefix_vltime &&
-                           IN6_ARE_ADDR_EQUAL(&ap->addr, addr) &&
-                           (!flags || ap->flags & flags))
+                       if (ipv6_findaddrmatch(ap, addr, flags))
                                return ap;
                }
        }
        return NULL;
 }
+
 struct ipv6_addr *
 ipv6nd_findaddr(struct dhcpcd_ctx *ctx, const struct in6_addr *addr,
     short flags)
@@ -457,14 +451,7 @@ ipv6nd_findaddr(struct dhcpcd_ctx *ctx, const struct in6_addr *addr,
 
        TAILQ_FOREACH(rap, ctx->ipv6->ra_routers, next) {
                TAILQ_FOREACH(ap, &rap->addrs, next) {
-                       if (addr == NULL) {
-                               if ((ap->flags &
-                                   (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED)) ==
-                                   (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED))
-                                       return ap;
-                       } else if (ap->prefix_vltime &&
-                           IN6_ARE_ADDR_EQUAL(&ap->addr, addr) &&
-                           (!flags || ap->flags & flags))
+                       if (ipv6_findaddrmatch(ap, addr, flags))
                                return ap;
                }
        }
index 90278bf1299e1e1aa6f8f6edf582df1ce5240c49..b45bfa32876d860cb25681a2a8e027478ea3ec14 100644 (file)
--- a/script.c
+++ b/script.c
@@ -230,6 +230,7 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
 #endif
        const struct if_options *ifo = ifp->options;
        const struct interface *ifp2;
+       int af;
 #ifdef INET
        int dhcp;
        const struct dhcp_state *state;
@@ -285,11 +286,11 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
        if (ifp->ctx->options & DHCPCD_DUMPLEASE)
                elen = 2;
        else
-               elen = 12;
+               elen = 11;
 
 #define EMALLOC(i, l) if ((env[(i)] = malloc((l))) == NULL) goto eexit;
        /* Make our env + space for profile, wireless and debug */
-       env = calloc(1, sizeof(char *) * (elen + 3 + 1));
+       env = calloc(1, sizeof(char *) * (elen + 4 + 1));
        if (env == NULL)
                goto eexit;
        e = strlen("interface") + strlen(ifp->name) + 2;
@@ -363,12 +364,16 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
        }
        if (env[9] == NULL || env[10] == NULL)
                goto eexit;
-       if (dhcpcd_oneup(ifp->ctx))
-               env[11] = strdup("if_oneup=true");
-       else
-               env[11] = strdup("if_oneup=false");
-       if (env[11] == NULL)
-               goto eexit;
+       if ((af = dhcpcd_ifafwaiting(ifp)) != AF_MAX) {
+               e = 20;
+               EMALLOC(elen, e);
+               snprintf(env[elen++], e, "if_afwaiting=%d", af);
+       }
+       if ((af = dhcpcd_afwaiting(ifp->ctx)) != AF_MAX) {
+               e = 20;
+               EMALLOC(elen, e);
+               snprintf(env[elen++], e, "af_waiting=%d", af);
+       }
        if (ifo->options & DHCPCD_DEBUG) {
                e = strlen("syslog_debug=true") + 1;
                EMALLOC(elen, e);