From: Kevin Darbyshire-Bryant Date: Sun, 5 Nov 2023 15:43:27 +0000 (+0000) Subject: dhcpv6-ia: add some noise to the T1 and T2 periods X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=81ea5bfef775b8e2d4aae9826e84a040288864df;p=project%2Fodhcpd.git dhcpv6-ia: add some noise to the T1 and T2 periods Without this, all the clients get the same timeouts and try to renew addresses at the same time. Reduce the T1 & T2 by a pseudo random 0 to 127 seconds, thus the renew attempts are likely to be spread out a bit in time. Signed-off-by: Kevin Darbyshire-Bryant --- diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index 5af952d..edd7823 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -721,8 +721,11 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status, /* UINT32_MAX is RFC defined as infinite lease-time */ a->preferred_until = (floor_preferred_lifetime == UINT32_MAX) ? 0 : floor_preferred_lifetime + now; - o_ia.t1 = htonl((floor_preferred_lifetime == UINT32_MAX) ? floor_preferred_lifetime : floor_preferred_lifetime * 5 / 10); - o_ia.t2 = htonl((floor_preferred_lifetime == UINT32_MAX) ? floor_preferred_lifetime : floor_preferred_lifetime * 8 / 10); + /* if there's sufficient time left, subtract a pseudo random 127 seconds from the refresh timers */ + o_ia.t1 = htonl((floor_preferred_lifetime == UINT32_MAX) ? floor_preferred_liftime : (floor_preferred_liftime > 256) ? + floor_preferred_lifetime * 5 / 10 - ((rand() >> 8) & 0x7f) : floor_preferred_lifetime * 5 / 10); + o_ia.t2 = htonl((floor_preferred_lifetime == UINT32_MAX) ? floor_preferred_lifetime : (floor_preferred_lifetime > 256) ? + floor_preferred_lifetime * 8 / 10 - ((rand() >> 8) & 0x7f) : floor_preferred_lifetime * 8 / 10); if (!o_ia.t1) o_ia.t1 = htonl(1);