diff --git a/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c b/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c index cb5631b459675..c5c5fe64a129f 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c @@ -185,6 +185,32 @@ int32_t _generate_temporary_addr(gnrc_netif_t *netif, const ipv6_addr_t *pfx, return 0; } +int _regen_temp_addr(gnrc_netif_t *netif, const ipv6_addr_t *addr, uint8_t retries, + const char *caller_description) { + //find associated prefix + uint32_t slaac_prefix_pref_until; + if (!_get_slaac_prefix_pref_until(netif, addr, &slaac_prefix_pref_until)) { + // at least one match is expected, + LOG_WARNING("nib: The temporary address smh outlived the SLAAC prefix valid lft."); + assert(false); + return -1; + } + + uint32_t now = evtimer_now_msec(); + assert(now < slaac_prefix_pref_until); + // else the temporary address smh outlived the SLAAC prefix preferred lft + + if (_generate_temporary_addr(netif, addr, + slaac_prefix_pref_until - now, + retries, + NULL) < 0) { + LOG_WARNING("nib: Temporary address regeneration failed%s.\n", caller_description); + return -1; + } + + return 0; +} + bool is_temporary_addr(const gnrc_netif_t *netif, const ipv6_addr_t *addr) { return gnrc_ipv6_nib_pl_has_prefix(netif->pid, addr, IPV6_ADDR_BIT_LEN); } @@ -327,27 +353,7 @@ void _remove_tentative_addr(gnrc_netif_t *netif, const ipv6_addr_t *addr) retries++; DEBUG("Trying regeneration of temporary address. (%u/%u)\n", retries, TEMP_IDGEN_RETRIES); - //find associated prefix - uint32_t slaac_prefix_pref_until; - if (!_get_slaac_prefix_pref_until(netif, addr, &slaac_prefix_pref_until)) { - // at least one match is expected, - LOG_WARNING("nib: The temporary address smh outlived the SLAAC prefix valid lft."); - assert(false); - return; - } - - uint32_t now = evtimer_now_msec(); - assert(now < slaac_prefix_pref_until); - // else the temporary address smh outlived the SLAAC prefix preferred lft - - if (_generate_temporary_addr(netif, addr, - slaac_prefix_pref_until - now, - retries, - NULL) < 0) { - LOG_WARNING("nib: Temporary address regeneration failed after DAD failure.\n"); - return; - } - + _regen_temp_addr(netif, addr, retries, " after DAD failure"); return; } #endif diff --git a/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.h b/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.h index 3b9738484ae37..b5940232f4c06 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.h +++ b/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.h @@ -136,6 +136,17 @@ int32_t _generate_temporary_addr(gnrc_netif_t *netif, const ipv6_addr_t *pfx, const uint8_t retries, int *idx); +/** + * @brief Regenerate a temporary address + * @param netif Network interface of the temporary address and the SLAAC prefix. + * @param addr Current temporary address (or any address in the SLAAC prefix for that matter) + * @param retries passed as-is to @ref _generate_temporary_addr + * @param caller_description Text detail for logging + * @return -1 on failure, 0 on success + */ +int _regen_temp_addr(gnrc_netif_t *netif, const ipv6_addr_t *addr, uint8_t retries, + const char *caller_description); + /** * @brief Check if the address is a temporary address. * (Assuming the provided address is a configured address. diff --git a/sys/net/gnrc/network_layer/ipv6/nib/nib.c b/sys/net/gnrc/network_layer/ipv6/nib/nib.c index 1ac5e9f706520..dfc740c1439f4 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/nib.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/nib.c @@ -1460,17 +1460,7 @@ static void _handle_regen_temp_addr(_nib_offl_entry_t *pfx) { gnrc_netif_t *netif = gnrc_netif_get_by_pid(_nib_onl_get_if(pfx->next_hop)); assert(netif != NULL); - uint32_t slaac_prefix_pref_until; - if (!_get_slaac_prefix_pref_until(netif, &pfx->pfx, &slaac_prefix_pref_until)) { - return; - } - assert(evtimer_now_msec() < slaac_prefix_pref_until); /*SLAAC prefix still preferred*/ - if (_generate_temporary_addr(netif, &pfx->pfx, - slaac_prefix_pref_until - evtimer_now_msec(), /*must be that of SLAAC prefix*/ - 0, NULL) < 0) { - LOG_WARNING("nib: Temporary address regeneration failed.\n"); - return; - } + _regen_temp_addr(netif, &pfx->pfx, 0, ""); } #endif