summaryrefslogtreecommitdiffstats
path: root/src/ipv6.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2020-01-07 14:15:14 +0000
committerRoy Marples <roy@marples.name>2020-01-07 14:15:14 +0000
commit8fde4abcc885a033800d1cb1b9e13a14f5c4da49 (patch)
tree02f09d3d3acd77a5560c46e6e00708966578ae34 /src/ipv6.c
parent826d1f25e2e0fde83d7f2a1e36a8c927f80e92b7 (diff)
downloaddhcpcd-8fde4abcc885a033800d1cb1b9e13a14f5c4da49.tar.xz
eloop: reduce timers rather than calculating expiry
This saves the need to store a created date per timer, we just need to know when the timers were last changed which we can store in the eloop. This makes it easier to make the actual timeout for polling. While here, add the eloop_timespec_diff function to workout the elapsed time from usp to tsp even when time has wrapped on one or both times. This works if time wraps on the maximal size time_t allows AND we know that tsp is always newer than usp.
Diffstat (limited to 'src/ipv6.c')
-rw-r--r--src/ipv6.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/ipv6.c b/src/ipv6.c
index 7b2e8e67..3872d510 100644
--- a/src/ipv6.c
+++ b/src/ipv6.c
@@ -666,28 +666,26 @@ ipv6_addaddr1(struct ipv6_addr *ia, const struct timespec *now)
(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;
}
- timespecsub(now, &ia->acquired, &n);
+ elapsed = (uint32_t)eloop_timespec_diff(now, &ia->acquired,
+ NULL);
if (ia->prefix_pltime != ND6_INFINITE_LIFETIME) {
- ia->prefix_pltime -= (uint32_t)n.tv_sec;
- /* This can happen when confirming a
- * deprecated but still valid lease. */
- if (ia->prefix_pltime > pltime)
+ if (elapsed > ia->prefix_pltime)
ia->prefix_pltime = 0;
+ else
+ ia->prefix_pltime -= elapsed;
}
if (ia->prefix_vltime != ND6_INFINITE_LIFETIME) {
- ia->prefix_vltime -= (uint32_t)n.tv_sec;
- /* This should never happen. */
- if (ia->prefix_vltime > vltime) {
- logerrx("%s: %s: lifetime overflow",
- ifp->name, ia->saddr);
- ia->prefix_vltime = ia->prefix_pltime = 0;
- }
+ if (elapsed > ia->prefix_vltime)
+ ia->prefix_vltime = 0;
+ else
+ ia->prefix_vltime -= elapsed;
}
}