diff options
| author | Roy Marples <roy@marples.name> | 2020-01-07 14:15:14 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2020-01-07 14:15:14 +0000 |
| commit | 3f49823f8c891ba7b221747dfef0056602a5dc75 (patch) | |
| tree | 02f09d3d3acd77a5560c46e6e00708966578ae34 /src/ipv6.c | |
| parent | 16c11c9dd1e561b9fb6eeb2d454c5707a442ab0c (diff) | |
| download | dhcpcd-3f49823f8c891ba7b221747dfef0056602a5dc75.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.c | 22 |
1 files changed, 10 insertions, 12 deletions
@@ -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; } } |
