From 92f679b8a9fec644f2e52d3f55c3cfec26036365 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 15 Oct 2021 17:35:46 +0200 Subject: [PATCH 1/2] dhcpv6_client: keep integers in retransmission calculations signed (cherry picked from commit d844de2263c91d58cff4fd83aaefff480f5297fb) --- sys/net/application_layer/dhcpv6/client.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sys/net/application_layer/dhcpv6/client.c b/sys/net/application_layer/dhcpv6/client.c index 27c7d06afb..842d0ffe67 100644 --- a/sys/net/application_layer/dhcpv6/client.c +++ b/sys/net/application_layer/dhcpv6/client.c @@ -480,12 +480,14 @@ static inline uint32_t _irt_ms(uint16_t irt, bool greater_irt) static inline uint32_t _sub_rt_ms(uint32_t rt_prev_ms, uint16_t mrt) { uint32_t sub_rt_ms = (2 * rt_prev_ms) + - ((get_rand_ms_factor() * rt_prev_ms) / MS_PER_SEC); + ((int32_t)(get_rand_ms_factor() * rt_prev_ms) / + (int32_t)MS_PER_SEC); if (sub_rt_ms > (mrt * MS_PER_SEC)) { uint32_t mrt_ms = mrt * MS_PER_SEC; - sub_rt_ms = mrt_ms + ((get_rand_ms_factor() * mrt_ms) / MS_PER_SEC); + sub_rt_ms = mrt_ms + ((int32_t)(get_rand_ms_factor() * mrt_ms) / + (int32_t)MS_PER_SEC); } return sub_rt_ms; } From 317d4423f323b68f5c729e74157a495214c1f823 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 15 Oct 2021 17:36:13 +0200 Subject: [PATCH 2/2] dhcpv6_client: add comment on why the division is needed (cherry picked from commit b1b0a9b4f5d4f60e7290556ecc7bf7dc3f9bd745) --- sys/net/application_layer/dhcpv6/client.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sys/net/application_layer/dhcpv6/client.c b/sys/net/application_layer/dhcpv6/client.c index 842d0ffe67..8809bcab78 100644 --- a/sys/net/application_layer/dhcpv6/client.c +++ b/sys/net/application_layer/dhcpv6/client.c @@ -473,6 +473,8 @@ static inline uint32_t _irt_ms(uint16_t irt, bool greater_irt) if (greater_irt && (factor < 0)) { factor = -factor; } + /* random factor is also in ms, but it is supposed to be without unit, + * so we need to divide by ms */ irt_ms += (factor * irt_ms) / MS_PER_SEC; return irt_ms; } @@ -480,12 +482,16 @@ static inline uint32_t _irt_ms(uint16_t irt, bool greater_irt) static inline uint32_t _sub_rt_ms(uint32_t rt_prev_ms, uint16_t mrt) { uint32_t sub_rt_ms = (2 * rt_prev_ms) + + /* random factor is also in ms, but it is supposed to + * be without unit, so we need to divide by ms */ ((int32_t)(get_rand_ms_factor() * rt_prev_ms) / (int32_t)MS_PER_SEC); if (sub_rt_ms > (mrt * MS_PER_SEC)) { uint32_t mrt_ms = mrt * MS_PER_SEC; + /* random factor is also in ms, but it is supposed to be without unit, + * so we need to divide by ms */ sub_rt_ms = mrt_ms + ((int32_t)(get_rand_ms_factor() * mrt_ms) / (int32_t)MS_PER_SEC); }