1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-18 19:13:51 +01:00

Merge pull request #21454 from benpicco/gnrc_ipv6_nib_get_next_hop_l2addr-cleanup

gnrc/ipv6/nib: clean up `gnrc_ipv6_nib_get_next_hop_l2addr()`
This commit is contained in:
benpicco 2025-07-24 11:35:14 +00:00 committed by GitHub
commit cdfdd215f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -304,12 +304,12 @@ int gnrc_ipv6_nib_get_next_hop_l2addr(const ipv6_addr_t *dst,
DEBUG("nib: get next hop link-layer address of %s%%%u\n", DEBUG("nib: get next hop link-layer address of %s%%%u\n",
ipv6_addr_to_str(addr_str, dst, sizeof(addr_str)), ipv6_addr_to_str(addr_str, dst, sizeof(addr_str)),
(netif != NULL) ? (unsigned)netif->pid : 0U); netif ? (unsigned)netif->pid : 0);
gnrc_netif_acquire(netif); gnrc_netif_acquire(netif);
_nib_acquire(); _nib_acquire();
do { /* XXX: hidden goto ;-) */
_nib_onl_entry_t *node = _nib_onl_nc_get(dst, _nib_onl_entry_t *node = _nib_onl_nc_get(dst, netif ? netif->pid : 0);
(netif == NULL) ? 0 : netif->pid);
/* consider neighbor cache entries first */ /* consider neighbor cache entries first */
unsigned iface = (node == NULL) ? 0 : _nib_onl_get_if(node); unsigned iface = (node == NULL) ? 0 : _nib_onl_get_if(node);
@ -339,39 +339,41 @@ int gnrc_ipv6_nib_get_next_hop_l2addr(const ipv6_addr_t *dst,
gnrc_pktbuf_release_error(pkt, EHOSTUNREACH); gnrc_pktbuf_release_error(pkt, EHOSTUNREACH);
} }
res = -EHOSTUNREACH; res = -EHOSTUNREACH;
break;
} }
goto out;
} }
else {
gnrc_ipv6_nib_ft_t route; gnrc_ipv6_nib_ft_t route;
DEBUG("nib: %s is off-link, resolve route\n", DEBUG("nib: %s is off-link, resolve route\n",
ipv6_addr_to_str(addr_str, dst, sizeof(addr_str))); ipv6_addr_to_str(addr_str, dst, sizeof(addr_str)));
res = _nib_get_route(dst, pkt, &route); res = _nib_get_route(dst, pkt, &route);
if ((res < 0) || ipv6_addr_is_unspecified(&route.next_hop)) {
/* If ARSM is not active only use link-local as next hop */
if (!IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ARSM) &&
ipv6_addr_is_unspecified(&route.next_hop) &&
!ipv6_addr_is_link_local(dst)) {
res = -ENETUNREACH;
}
if (res < 0) {
DEBUG("nib: no route to %s found or is prefix list entry, " DEBUG("nib: no route to %s found or is prefix list entry, "
"search neighbor cache\n", "search neighbor cache\n",
ipv6_addr_to_str(addr_str, dst, sizeof(addr_str))); ipv6_addr_to_str(addr_str, dst, sizeof(addr_str)));
if ((res == 0) && if (pkt != NULL) {
/* If ARSM is not active only use link-local as next hop */ gnrc_icmpv6_error_dst_unr_send(ICMPV6_ERROR_DST_UNR_NO_ROUTE, pkt);
(IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ARSM) || gnrc_pktbuf_release_error(pkt, ENETUNREACH);
ipv6_addr_is_link_local(dst))) { }
res = -ENETUNREACH;
goto out;
}
if (ipv6_addr_is_unspecified(&route.next_hop)) {
DEBUG("nib: prefix list entry => taking dst as next hop\n"); DEBUG("nib: prefix list entry => taking dst as next hop\n");
memcpy(&route.next_hop, dst, sizeof(route.next_hop)); memcpy(&route.next_hop, dst, sizeof(route.next_hop));
} }
else {
res = -ENETUNREACH;
if (pkt != NULL) {
gnrc_icmpv6_error_dst_unr_send(
ICMPV6_ERROR_DST_UNR_NO_ROUTE,
pkt
);
gnrc_pktbuf_release_error(pkt, ENETUNREACH);
}
break;
}
}
if ((netif != NULL) && (netif->pid != (int)route.iface)) { if ((netif != NULL) && (netif->pid != (int)route.iface)) {
/* release pre-assumed netif */ /* release pre-assumed netif */
gnrc_netif_release(netif); gnrc_netif_release(netif);
@ -380,8 +382,8 @@ int gnrc_ipv6_nib_get_next_hop_l2addr(const ipv6_addr_t *dst,
/* get actual netif */ /* get actual netif */
netif = _acquire_new_iface(route.iface); netif = _acquire_new_iface(route.iface);
} }
node = _nib_onl_nc_get(&route.next_hop,
(netif != NULL) ? netif->pid : 0); node = _nib_onl_nc_get(&route.next_hop, netif ? netif->pid : 0);
if (_resolve_addr(&route.next_hop, netif, pkt, nce, node)) { if (_resolve_addr(&route.next_hop, netif, pkt, nce, node)) {
_call_route_info_cb(netif, _call_route_info_cb(netif,
GNRC_IPV6_NIB_ROUTE_INFO_TYPE_RN, GNRC_IPV6_NIB_ROUTE_INFO_TYPE_RN,
@ -396,10 +398,11 @@ int gnrc_ipv6_nib_get_next_hop_l2addr(const ipv6_addr_t *dst,
* we also shouldn't release */ * we also shouldn't release */
res = -EHOSTUNREACH; res = -EHOSTUNREACH;
} }
}
} while (0); out:
_nib_release(); _nib_release();
gnrc_netif_release(netif); gnrc_netif_release(netif);
return res; return res;
} }