Skip to content

Commit

Permalink
Merge pull request #20342 from fabian18/pr/fix_router_lifetime_and_ft…
Browse files Browse the repository at this point in the history
…_add_api

ipv6/nib: fix router lifetime handling in RIO and fix gnrc_ipv6_nib_ft_add() api
  • Loading branch information
benpicco authored Feb 6, 2024
2 parents a16199f + fef5c8c commit 83f3c4a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion sys/include/net/gnrc/ipv6/nib/ft.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int gnrc_ipv6_nib_ft_get(const ipv6_addr_t *dst, gnrc_pktsnip_t *pkt,
*/
int gnrc_ipv6_nib_ft_add(const ipv6_addr_t *dst, unsigned dst_len,
const ipv6_addr_t *next_hop, unsigned iface,
uint16_t lifetime);
uint32_t lifetime);

/**
* @brief Deletes a route from forwarding table.
Expand Down
13 changes: 2 additions & 11 deletions sys/net/gnrc/network_layer/ipv6/nib/nib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ static uint32_t _handle_pio(gnrc_netif_t *netif, const icmpv6_hdr_t *icmpv6,

if (valid_ltime < UINT32_MAX) { /* UINT32_MAX means infinite lifetime */
/* the valid lifetime is given in seconds, but our timers work in
* microseconds, so we have to scale down to the smallest possible
* milliseconds, so we have to scale down to the smallest possible
* value (UINT32_MAX - 1). This is however alright since we ask for
* a new router advertisement before this timeout expires */
valid_ltime = (valid_ltime > (UINT32_MAX / MS_PER_SEC)) ?
Expand Down Expand Up @@ -1720,20 +1720,11 @@ static uint32_t _handle_rio(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6,
DEBUG(" - Route lifetime: %" PRIu32 "\n",
byteorder_ntohl(rio->route_ltime));

if (route_ltime < UINT32_MAX) { /* UINT32_MAX means infinite lifetime */
/* the valid lifetime is given in seconds, but our timers work in
* microseconds, so we have to scale down to the smallest possible
* value (UINT32_MAX - 1). This is however alright since we ask for
* a new router advertisement before this timeout expires */
route_ltime = (route_ltime > (UINT32_MAX / MS_PER_SEC)) ?
(UINT32_MAX - 1) : route_ltime * MS_PER_SEC;
}

if (route_ltime == 0) {
gnrc_ipv6_nib_ft_del(&rio->prefix, rio->prefix_len);
} else {
gnrc_ipv6_nib_ft_add(&rio->prefix, rio->prefix_len, &ipv6->src,
netif->pid, route_ltime);
netif->pid, route_ltime == UINT32_MAX ? 0 : route_ltime);
}

return route_ltime;
Expand Down
21 changes: 16 additions & 5 deletions sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,23 @@ int gnrc_ipv6_nib_ft_get(const ipv6_addr_t *dst, gnrc_pktsnip_t *pkt,

int gnrc_ipv6_nib_ft_add(const ipv6_addr_t *dst, unsigned dst_len,
const ipv6_addr_t *next_hop, unsigned iface,
uint16_t ltime)
uint32_t ltime)
{
int res = 0;
bool is_default_route = ((dst == NULL) || (dst_len == 0) ||
ipv6_addr_is_unspecified(dst));

uint32_t ltime_ms;
/* 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 ms). This is however alright since we ask for
* a new router advertisement before this timeout expires */
if (ltime > UINT32_MAX / MS_PER_SEC) {
ltime_ms = UINT32_MAX;
}
else {
ltime_ms = ltime * MS_PER_SEC;
}
if ((iface == 0) || ((is_default_route) && (next_hop == NULL))) {
return -EINVAL;
}
Expand All @@ -55,9 +66,9 @@ 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_PER_SEC);
&ptr->rtr_timeout, ltime_ms);
}
}
}
Expand All @@ -70,9 +81,9 @@ 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_PER_SEC);
&ptr->route_timeout, ltime_ms);
}
}
#else /* CONFIG_GNRC_IPV6_NIB_ROUTER */
Expand Down

0 comments on commit 83f3c4a

Please sign in to comment.