summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Darbyshire-Bryant2023-11-05 15:43:27 +0000
committerKevin Darbyshire-Bryant2025-12-05 20:45:19 +0000
commit81ea5bfef775b8e2d4aae9826e84a040288864df (patch)
treee067c147741a5d02c847d8afb0645b82642bc187
parent79252ed0c0c26659a95729da0f2accaa0ddb458d (diff)
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 <ldir@darbyshire-bryant.me.uk>
-rw-r--r--src/dhcpv6-ia.c7
1 files changed, 5 insertions, 2 deletions
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);