Skip to content

Commit

Permalink
fixup! ipv6/nib: fix lifetime handling in RIO handling
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian18 committed Feb 6, 2024
1 parent 59e3fa6 commit c4de18a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit c4de18a

Please sign in to comment.