diff --git a/sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c b/sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c index 0f41d9d002b7..920ab90eac2d 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c @@ -42,16 +42,19 @@ int gnrc_ipv6_nib_ft_add(const ipv6_addr_t *dst, unsigned dst_len, bool is_default_route = ((dst == NULL) || (dst_len == 0) || ipv6_addr_is_unspecified(dst)); - if (ltime < UINT32_MAX) { - /* UINT32_MAX means infinite lifetime. + uint32_t ltime_ms = 0; + if (ltime > 0 && ltime < UINT32_MAX) { + /* 0 or UINT32_MAX mean infinite lifetime. * The valid lifetime is given in seconds, but our timers work in * milliseconds, so we have to scale down to the smallest possible - * value (UINT32_MAX - 1). This is however alright since we ask for + * value (UINT32_MAX ms). This is however alright since we ask for * a new router advertisement before this timeout expires */ - ltime = (ltime > (UINT32_MAX / MS_PER_SEC)) ? (UINT32_MAX - 1) : ltime; + ltime_ms = ltime * MS_PER_SEC; + if (ltime_ms / MS_PER_SEC != ltime) { + /* If there was an overflow take the maximum */ + ltime_ms = UINT32_MAX; + } } - uint32_t ltime_ms = ltime * MS_PER_SEC; - if ((iface == 0) || ((is_default_route) && (next_hop == NULL))) { return -EINVAL; } @@ -65,7 +68,7 @@ int gnrc_ipv6_nib_ft_add(const ipv6_addr_t *dst, unsigned dst_len, } else { _prime_def_router = ptr; - if (ltime > 0) { + if (ltime_ms > 0) { _evtimer_add(ptr, GNRC_IPV6_NIB_RTR_TIMEOUT, &ptr->rtr_timeout, ltime_ms); } @@ -80,7 +83,7 @@ int gnrc_ipv6_nib_ft_add(const ipv6_addr_t *dst, unsigned dst_len, if (ptr == NULL) { res = -ENOMEM; } - else if (ltime > 0) { + else if (ltime_ms > 0) { _evtimer_add(ptr, GNRC_IPV6_NIB_ROUTE_TIMEOUT, &ptr->route_timeout, ltime_ms); }