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/ipv6nd.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/ipv6nd.c')
| -rw-r--r-- | src/ipv6nd.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/ipv6nd.c b/src/ipv6nd.c index ae057795..333bcb42 100644 --- a/src/ipv6nd.c +++ b/src/ipv6nd.c @@ -1594,7 +1594,8 @@ ipv6nd_expirera(void *arg) { struct interface *ifp; struct ra *rap, *ran; - struct timespec now, expire; + struct timespec now; + uint32_t elapsed; bool expired, valid; struct ipv6_addr *ia; size_t len, olen; @@ -1617,8 +1618,9 @@ ipv6nd_expirera(void *arg) continue; valid = false; if (rap->lifetime) { - timespecsub(&now, &rap->acquired, &expire); - if (expire.tv_sec > rap->lifetime) { + elapsed = (uint32_t)eloop_timespec_diff(&now, + &rap->acquired, NULL); + if (elapsed > rap->lifetime) { if (!rap->expired) { logwarnx("%s: %s: router expired", ifp->name, rap->sfrom); @@ -1627,8 +1629,7 @@ ipv6nd_expirera(void *arg) } } else { valid = true; - ltime = (unsigned int) - (rap->lifetime - expire.tv_sec); + ltime = rap->lifetime - elapsed; if (next == 0 || ltime < next) next = ltime; } @@ -1644,8 +1645,9 @@ ipv6nd_expirera(void *arg) valid = true; continue; } - timespecsub(&now, &ia->acquired, &expire); - if (expire.tv_sec > ia->prefix_vltime) { + elapsed = (uint32_t)eloop_timespec_diff(&now, + &ia->acquired, NULL); + if (elapsed > ia->prefix_vltime) { if (ia->flags & IPV6_AF_ADDED) { logwarnx("%s: expired address %s", ia->iface->name, ia->saddr); @@ -1660,15 +1662,15 @@ ipv6nd_expirera(void *arg) expired = true; } else { valid = true; - ltime = (unsigned int) - (ia->prefix_vltime - expire.tv_sec); + ltime = ia->prefix_vltime - elapsed; if (next == 0 || ltime < next) next = ltime; } } /* Work out expiry for ND options */ - timespecsub(&now, &rap->acquired, &expire); + elapsed = (uint32_t)eloop_timespec_diff(&now, + &rap->acquired, NULL); len = rap->data_len - sizeof(struct nd_router_advert); for (p = rap->data + sizeof(struct nd_router_advert); len >= sizeof(ndo); @@ -1719,13 +1721,13 @@ ipv6nd_expirera(void *arg) } ltime = ntohl(ltime); - if (expire.tv_sec > ltime) { + if (elapsed > ltime) { expired = true; continue; } valid = true; - ltime = (unsigned int)(ltime - expire.tv_sec); + ltime -= elapsed; if (next == 0 || ltime < next) next = ltime; } |
