1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #20342 from fabian18/pr/fix_router_lifetime_and_ft_add_api

ipv6/nib: fix router lifetime handling in RIO and fix gnrc_ipv6_nib_ft_add() api
This commit is contained in:
benpicco 2024-02-06 19:38:12 +00:00 committed by GitHub
commit 83f3c4a396
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 17 deletions

View File

@ -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.

View File

@ -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)) ?
@ -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;

View File

@ -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;
}
@ -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);
}
}
}
@ -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 */