]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
For each ND, output the time of acquisition and the current time in seconds.
authorRoy Marples <roy@marples.name>
Fri, 15 May 2015 13:47:35 +0000 (13:47 +0000)
committerRoy Marples <roy@marples.name>
Fri, 15 May 2015 13:47:35 +0000 (13:47 +0000)
common.c
common.h
ipv6nd.c
ipv6nd.h

index 5317dcc80d55403661fc34037152de9fdc2fb68b..f81663f60bb3d45bdd933e0158f6e9582f546c80 100644 (file)
--- a/common.c
+++ b/common.c
@@ -221,6 +221,17 @@ setvar(struct dhcpcd_ctx *ctx,
        return (ssize_t)len;
 }
 
+ssize_t
+setvard(struct dhcpcd_ctx *ctx,
+    char **e, const char *prefix, const char *var, size_t value)
+{
+
+       char buffer[32];
+
+       snprintf(buffer, sizeof(buffer), "%zu", value);
+       return setvar(ctx, e, prefix, var, buffer);
+}
+
 ssize_t
 addvar(struct dhcpcd_ctx *ctx,
     char ***e, const char *prefix, const char *var, const char *value)
index 619277a4f025fad8347579e05c9d40b3dbe77776..dfbc2e94218698d595d09090537ac06f2e0485a9 100644 (file)
--- a/common.h
+++ b/common.h
@@ -185,6 +185,8 @@ void logger_close(struct dhcpcd_ctx *);
 
 ssize_t setvar(struct dhcpcd_ctx *,
     char **, const char *, const char *, const char *);
+ssize_t setvard(struct dhcpcd_ctx *,
+    char **, const char *, const char *, size_t);
 ssize_t addvar(struct dhcpcd_ctx *,
     char ***, const char *, const char *, const char *);
 ssize_t addvard(struct dhcpcd_ctx *,
index 907ef80c922e13162a1173a8ee8097322b4c6f2e..4f389dbaa20306b71879fb8825c4251d49093193 100644 (file)
--- a/ipv6nd.c
+++ b/ipv6nd.c
@@ -354,7 +354,7 @@ ipv6nd_expire(struct interface *ifp, uint32_t seconds)
 
        TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) {
                if (rap->iface == ifp) {
-                       rap->received = now;
+                       rap->acquired = now;
                        rap->expired = seconds ? 0 : 1;
                        if (seconds) {
                                struct ipv6_addr *ap;
@@ -846,7 +846,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *dctx, struct interface *ifp,
                rap->data_len = len;
        }
 
-       clock_gettime(CLOCK_MONOTONIC, &rap->received);
+       clock_gettime(CLOCK_MONOTONIC, &rap->acquired);
        rap->flags = nd_ra->nd_ra_flags_reserved;
        if (new_rap == 0 && rap->lifetime == 0)
                logger(ifp->ctx, LOG_WARNING, "%s: %s router available",
@@ -993,7 +993,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *dctx, struct interface *ifp,
                                        ap->saddr[0] = '\0';
                                }
                                ap->dadcallback = ipv6nd_dadcallback;
-                               ap->created = ap->acquired = rap->received;
+                               ap->created = ap->acquired = rap->acquired;
                                TAILQ_INSERT_TAIL(&rap->addrs, ap, next);
 
 #ifdef IPV6_MANAGETEMPADDR
@@ -1013,7 +1013,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *dctx, struct interface *ifp,
                                new_ap = 0;
 #endif
                                ap->flags &= ~IPV6_AF_STALE;
-                               ap->acquired = rap->received;
+                               ap->acquired = rap->acquired;
                        }
                        if (pi->nd_opt_pi_flags_reserved &
                            ND_OPT_PI_FLAG_ONLINK)
@@ -1106,7 +1106,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *dctx, struct interface *ifp,
        }
        ipv6_addaddrs(&rap->addrs);
 #ifdef IPV6_MANAGETEMPADDR
-       ipv6_addtempaddrs(ifp, &rap->received);
+       ipv6_addtempaddrs(ifp, &rap->acquired);
 #endif
 
        /* Find any freshly added routes, such as the subnet route.
@@ -1252,7 +1252,9 @@ ipv6nd_env(char **env, const char *prefix, const struct interface *ifp)
        struct dhcp_opt *opt;
        const struct nd_opt_hdr *o;
        struct ipv6_addr *ia;
+       struct timespec now;
 
+       clock_gettime(CLOCK_MONOTONIC, &now);
        i = n = 0;
        TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) {
                if (rap->iface != ifp)
@@ -1268,6 +1270,14 @@ ipv6nd_env(char **env, const char *prefix, const struct interface *ifp)
                        setvar(rap->iface->ctx, &env[n], ndprefix,
                            "from", rap->sfrom);
                n++;
+               if (env)
+                       setvard(rap->iface->ctx, &env[n], ndprefix,
+                           "acquired", (size_t)rap->acquired.tv_sec);
+               n++;
+               if (env)
+                       setvard(rap->iface->ctx, &env[n], ndprefix,
+                           "now", (size_t)now.tv_sec);
+               n++;
 
                /* Zero our indexes */
                if (env) {
@@ -1328,8 +1338,11 @@ ipv6nd_env(char **env, const char *prefix, const struct interface *ifp)
                 * from the prefix information options as well. */
                j = 0;
                TAILQ_FOREACH(ia, &rap->addrs, next) {
-                       if (!(ia->flags & IPV6_AF_AUTOCONF) ||
-                           ia->flags & IPV6_AF_TEMPORARY)
+                       if (!(ia->flags & IPV6_AF_AUTOCONF)
+#ifdef IPV6_AF_TEMPORARY
+                           || ia->flags & IPV6_AF_TEMPORARY
+#endif
+                           )
                                continue;
                        j++;
                        if (env) {
@@ -1379,7 +1392,7 @@ ipv6nd_expirera(void *arg)
                if (rap->lifetime) {
                        lt.tv_sec = (time_t)rap->lifetime;
                        lt.tv_nsec = 0;
-                       timespecadd(&rap->received, &lt, &expire);
+                       timespecadd(&rap->acquired, &lt, &expire);
                        if (rap->lifetime == 0 || timespeccmp(&now, &expire, >))
                        {
                                if (!rap->expired) {
index 200447923656b6332e5665b30e254838c8cc2249..4124b3b2c50289a2764e51a7a7622b140a7120ac 100644 (file)
--- a/ipv6nd.h
+++ b/ipv6nd.h
@@ -41,7 +41,7 @@ struct ra {
        char sfrom[INET6_ADDRSTRLEN];
        unsigned char *data;
        size_t data_len;
-       struct timespec received;
+       struct timespec acquired;
        unsigned char flags;
        uint32_t lifetime;
        uint32_t reachable;