From: Roy Marples Date: Fri, 15 May 2015 13:47:35 +0000 (+0000) Subject: For each ND, output the time of acquisition and the current time in seconds. X-Git-Tag: v6.9.0~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5c3ca19e92db0827b2d2f3ec49f53b732aec93c;p=thirdparty%2Fdhcpcd.git For each ND, output the time of acquisition and the current time in seconds. --- diff --git a/common.c b/common.c index 5317dcc8..f81663f6 100644 --- 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) diff --git a/common.h b/common.h index 619277a4..dfbc2e94 100644 --- 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 *, diff --git a/ipv6nd.c b/ipv6nd.c index 907ef80c..4f389dba 100644 --- 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, <, &expire); + timespecadd(&rap->acquired, <, &expire); if (rap->lifetime == 0 || timespeccmp(&now, &expire, >)) { if (!rap->expired) { diff --git a/ipv6nd.h b/ipv6nd.h index 20044792..4124b3b2 100644 --- 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;