No functional change intended.
}
uint32_t
-lifetime_left(uint32_t lifetime, const struct timespec *acquired, const struct timespec *now)
+lifetime_left(uint32_t lifetime, const struct timespec *acquired, struct timespec *now)
{
uint32_t elapsed;
+ struct timespec n;
if (lifetime == INFINITE_LIFETIME)
return lifetime;
+ if (now == NULL) {
+ timespecclear(&n);
+ now = &n;
+ }
+ if (!timespecisset(now))
+ clock_gettime(CLOCK_MONOTONIC, now);
+
elapsed = (uint32_t)eloop_timespec_diff(now, acquired, NULL);
if (elapsed > lifetime)
return 0;
int filemtime(const char *, time_t *);
char *get_line(char ** __restrict, ssize_t * __restrict);
int is_root_local(void);
-uint32_t lifetime_left(uint32_t, const struct timespec *, const struct timespec *);
+uint32_t lifetime_left(uint32_t, const struct timespec *, struct timespec *);
#endif
unsigned long long tsecs, usecs, secs;
long nsecs;
- if (tsp->tv_sec < 0) /* time wreapped */
+ if (tsp->tv_sec < 0) /* time wrapped */
tsecs = UTIME_MAX - (unsigned long long)(-tsp->tv_sec);
else
tsecs = (unsigned long long)tsp->tv_sec;
}
static int
-ipv6_addaddr1(struct ipv6_addr *ia, const struct timespec *now)
+ipv6_addaddr1(struct ipv6_addr *ia, struct timespec *now)
{
struct interface *ifp;
uint32_t pltime, vltime;
ia->prefix_vltime = ia->prefix_pltime = ND6_INFINITE_LIFETIME;
}
- if (timespecisset(&ia->acquired) &&
- (ia->prefix_pltime != ND6_INFINITE_LIFETIME ||
- ia->prefix_vltime != ND6_INFINITE_LIFETIME))
- {
- uint32_t elapsed;
- struct timespec n;
-
- if (now == NULL) {
- clock_gettime(CLOCK_MONOTONIC, &n);
- now = &n;
- }
- elapsed = (uint32_t)eloop_timespec_diff(now, &ia->acquired,
- NULL);
- if (ia->prefix_pltime != ND6_INFINITE_LIFETIME) {
- if (elapsed > ia->prefix_pltime)
- ia->prefix_pltime = 0;
- else
- ia->prefix_pltime -= elapsed;
- }
- if (ia->prefix_vltime != ND6_INFINITE_LIFETIME) {
- if (elapsed > ia->prefix_vltime)
- ia->prefix_vltime = 0;
- else
- ia->prefix_vltime -= elapsed;
- }
+ if (timespecisset(&ia->acquired)) {
+ ia->prefix_pltime = lifetime_left(ia->prefix_pltime,
+ &ia->acquired, now);
+ ia->prefix_vltime = lifetime_left(ia->prefix_vltime,
+ &ia->acquired, now);
}
loglevel = ia->flags & IPV6_AF_NEW ? LOG_INFO : LOG_DEBUG;
#endif
int
-ipv6_addaddr(struct ipv6_addr *ia, const struct timespec *now)
+ipv6_addaddr(struct ipv6_addr *ia, struct timespec *now)
{
int r;
#ifdef ALIAS_ADDR
IN6_IS_ADDR_UNSPECIFIED(&ia->addr))
return 0;
- if (!timespecisset(now))
- clock_gettime(CLOCK_MONOTONIC, now);
ipv6_addaddr(ia, now);
return ia->flags & IPV6_AF_NEW ? 1 : 0;
}
ipv6_deleteaddr(ap);
if (!(ap->iface->options->options &
DHCPCD_EXITING) && apf)
- {
- if (!timespecisset(&now))
- clock_gettime(CLOCK_MONOTONIC,
- &now);
ipv6_addaddr(apf, &now);
- }
if (drop == 2)
ipv6_freeaddr(ap);
}
}
void
-ipv6_addtempaddrs(struct interface *ifp, const struct timespec *now)
+ipv6_addtempaddrs(struct interface *ifp, struct timespec *now)
{
struct ipv6_state *state;
struct ipv6_addr *ia;
if (ctx->ra_routers == NULL)
return 0;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ timespecclear(&now);
TAILQ_FOREACH(rap, ctx->ra_routers, next) {
if (rap->expired)
#ifdef HAVE_ROUTE_PREF
rt->rt_pref = ipv6nd_rtpref(rinfo->flags);
#endif
- rt->rt_expires = lifetime_left(rinfo->lifetime, &rinfo->acquired, &now);
+ rt->rt_expires = lifetime_left(rinfo->lifetime,
+ &rinfo->acquired, &now);
rt_proto_add(routes, rt);
}
#ifdef HAVE_ROUTE_PREF
rt->rt_pref = ipv6nd_rtpref(rap->flags);
#endif
- rt->rt_expires = lifetime_left(addr->prefix_vltime, &addr->acquired, &now);
+ rt->rt_expires =
+ lifetime_left(addr->prefix_vltime,
+ &addr->acquired, &now);
rt_proto_add(routes, rt);
}
#ifdef HAVE_ROUTE_PREF
rt->rt_pref = ipv6nd_rtpref(rap->flags);
#endif
- rt->rt_expires = lifetime_left(rap->lifetime, &rap->acquired, &now);
+ rt->rt_expires = lifetime_left(rap->lifetime,
+ &rap->acquired, &now);
rt_proto_add(routes, rt);
}
void ipv6_checkaddrflags(void *);
void ipv6_markaddrsstale(struct interface *, unsigned int);
void ipv6_deletestaleaddrs(struct interface *);
-int ipv6_addaddr(struct ipv6_addr *, const struct timespec *);
+int ipv6_addaddr(struct ipv6_addr *, struct timespec *);
int ipv6_doaddr(struct ipv6_addr *, struct timespec *);
ssize_t ipv6_addaddrs(struct ipv6_addrhead *addrs);
void ipv6_deleteaddr(struct ipv6_addr *);
struct ipv6_addr *ipv6_createtempaddr(struct ipv6_addr *,
const struct timespec *);
struct ipv6_addr *ipv6_settemptime(struct ipv6_addr *, int);
-void ipv6_addtempaddrs(struct interface *, const struct timespec *);
+void ipv6_addtempaddrs(struct interface *, struct timespec *);
void ipv6_regentempaddrs(void *);
#endif
struct interface *ifp;
struct ra *rap, *ran;
struct timespec now;
- uint32_t elapsed;
bool expired, valid;
struct ipv6_addr *ia;
struct routeinfo *rinfo, *rinfob;
#endif
struct nd_opt_dnssl dnssl;
struct nd_opt_rdnss rdnss;
- unsigned int next = 0, ltime;
+ uint32_t next = 0, ltime, elapsed;
size_t nexpired = 0;
ifp = arg;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ timespecclear(&now);
expired = false;
TAILQ_FOREACH_SAFE(rap, ifp->ctx->ra_routers, next, ran) {
continue;
valid = false;
/* lifetime may be set to infinite by rfc4191 route information */
- if (rap->lifetime && rap->lifetime != ND6_INFINITE_LIFETIME) {
- elapsed = (uint32_t)eloop_timespec_diff(&now,
- &rap->acquired, NULL);
- if (elapsed >= rap->lifetime || rap->doexpire) {
+ if (rap->lifetime) {
+ ltime = lifetime_left(rap->lifetime,
+ &rap->acquired, &now);
+ if (ltime == 0 || rap->doexpire) {
if (!rap->expired) {
logwarnx("%s: %s: router expired",
ifp->name, rap->sfrom);
}
} else {
valid = true;
- ltime = rap->lifetime - elapsed;
if (next == 0 || ltime < next)
next = ltime;
}
TAILQ_FOREACH(ia, &rap->addrs, next) {
if (ia->prefix_vltime == 0)
continue;
- if (ia->prefix_vltime == ND6_INFINITE_LIFETIME &&
- !rap->doexpire)
- {
- valid = true;
- continue;
- }
- elapsed = (uint32_t)eloop_timespec_diff(&now,
- &ia->acquired, NULL);
- if (elapsed >= ia->prefix_vltime || rap->doexpire) {
+ ltime = lifetime_left(ia->prefix_vltime,
+ &ia->acquired, &now);
+ if (ltime == 0 || rap->doexpire) {
if (ia->flags & IPV6_AF_ADDED) {
logwarnx("%s: expired %s %s",
ia->iface->name,
expired = true;
} else {
valid = true;
- ltime = ia->prefix_vltime - elapsed;
if (next == 0 || ltime < next)
next = ltime;
}
/* Expire route information */
TAILQ_FOREACH_SAFE(rinfo, &rap->rinfos, next, rinfob) {
- if (rinfo->lifetime == ND6_INFINITE_LIFETIME &&
- !rap->doexpire)
- continue;
- elapsed = (uint32_t)eloop_timespec_diff(&now,
- &rinfo->acquired, NULL);
- if (elapsed >= rinfo->lifetime || rap->doexpire) {
+ ltime = lifetime_left(rinfo->lifetime,
+ &rinfo->acquired, &now);
+ if (ltime == 0 || rap->doexpire) {
logwarnx("%s: expired route %s",
rap->iface->name, rinfo->sprefix);
TAILQ_REMOVE(&rap->rinfos, rinfo, next);