diff --git a/sys/net/gnrc/network_layer/ipv6/nib/_nib-arsm.c b/sys/net/gnrc/network_layer/ipv6/nib/_nib-arsm.c index 1ec45edf22..858af573d5 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/_nib-arsm.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/_nib-arsm.c @@ -93,7 +93,7 @@ void _handle_sl2ao(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6, const icmpv6_hdr_t *icmpv6, const ndp_opt_t *sl2ao) { assert(netif != NULL); - _nib_onl_entry_t *nce = _nib_onl_get(&ipv6->src, netif->pid); + _nib_onl_entry_t *nce = _nib_onl_nc_get(&ipv6->src, netif->pid); int l2addr_len; l2addr_len = gnrc_netif_ndp_addr_len_from_l2ao(netif, sl2ao); @@ -102,7 +102,7 @@ void _handle_sl2ao(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6, return; } #if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ARSM) - if ((nce != NULL) && (nce->mode & _NC) && + if ((nce != NULL) && ((nce->l2addr_len != l2addr_len) || (memcmp(nce->l2addr, sl2ao + 1, nce->l2addr_len) != 0)) && /* a 6LR MUST NOT modify an existing NCE based on an SL2AO in an RS @@ -113,7 +113,7 @@ void _handle_sl2ao(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6, _set_nud_state(netif, nce, GNRC_IPV6_NIB_NC_INFO_NUD_STATE_STALE); } #endif /* CONFIG_GNRC_IPV6_NIB_ARSM */ - if ((nce == NULL) || !(nce->mode & _NC)) { + if (nce == NULL) { DEBUG("nib: Creating NCE for (ipv6 = %s, iface = %u, nud_state = STALE)\n", ipv6_addr_to_str(addr_str, &ipv6->src, sizeof(addr_str)), netif->pid); diff --git a/sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.h b/sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.h index cc3e62a863..602bc3da92 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.h +++ b/sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.h @@ -350,6 +350,26 @@ _nib_onl_entry_t *_nib_onl_iter(const _nib_onl_entry_t *last); */ _nib_onl_entry_t *_nib_onl_get(const ipv6_addr_t *addr, unsigned iface); +/** + * @brief Gets a node by IPv6 address and interface from the neighbor cache + * + * @pre `(addr != NULL)` + * + * @param[in] addr The address of a node. Must not be NULL. + * @param[in] iface The interface to the node. May be 0 for any interface. + * + * @return The Neighbor Cache entry for node with @p addr and @p iface on success. + * @return NULL, if there is no such entry. + */ +static inline _nib_onl_entry_t *_nib_onl_nc_get(const ipv6_addr_t *addr, unsigned iface) +{ + _nib_onl_entry_t *nce = _nib_onl_get(addr, iface); + if (nce && (nce->mode & _NC)) { + return nce; + } + return NULL; +} + /** * @brief Creates or gets an existing node from the neighbor cache by address * diff --git a/sys/net/gnrc/network_layer/ipv6/nib/nib.c b/sys/net/gnrc/network_layer/ipv6/nib/nib.c index f86fee8c69..d5ca625d03 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/nib.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/nib.c @@ -213,14 +213,15 @@ int gnrc_ipv6_nib_get_next_hop_l2addr(const ipv6_addr_t *dst, gnrc_netif_acquire(netif); _nib_acquire(); do { /* XXX: hidden goto ;-) */ - _nib_onl_entry_t *node = _nib_onl_get(dst, - (netif == NULL) ? 0 : netif->pid); + _nib_onl_entry_t *node = _nib_onl_nc_get(dst, + (netif == NULL) ? 0 : netif->pid); /* consider neighbor cache entries first */ unsigned iface = (node == NULL) ? 0 : _nib_onl_get_if(node); if ((node != NULL) || _on_link(dst, &iface)) { - DEBUG("nib: %s is on-link or in NC, start address resolution\n", - ipv6_addr_to_str(addr_str, dst, sizeof(addr_str))); + DEBUG("nib: %s is %s, start address resolution\n", + ipv6_addr_to_str(addr_str, dst, sizeof(addr_str)), + node ? "in NC" : "on-link"); /* on-link prefixes return their interface */ if (!ipv6_addr_is_link_local(dst) && (iface != 0)) { /* release pre-assumed netif */ @@ -228,7 +229,7 @@ int gnrc_ipv6_nib_get_next_hop_l2addr(const ipv6_addr_t *dst, netif = _acquire_new_iface(iface); /* get node from proper interface */ if (netif != NULL) { - node = _nib_onl_get(dst, netif->pid); + node = _nib_onl_nc_get(dst, netif->pid); } } if ((netif == NULL) || @@ -284,8 +285,8 @@ int gnrc_ipv6_nib_get_next_hop_l2addr(const ipv6_addr_t *dst, /* get actual netif */ netif = _acquire_new_iface(route.iface); } - node = _nib_onl_get(&route.next_hop, - (netif != NULL) ? netif->pid : 0); + node = _nib_onl_nc_get(&route.next_hop, + (netif != NULL) ? netif->pid : 0); if (_resolve_addr(&route.next_hop, netif, pkt, nce, node)) { _call_route_info_cb(netif, GNRC_IPV6_NIB_ROUTE_INFO_TYPE_RN, @@ -532,7 +533,7 @@ static void _handle_rtr_sol(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6, break; } } - nce = _nib_onl_get(&ipv6->src, netif->pid); + nce = _nib_onl_nc_get(&ipv6->src, netif->pid); } if (!gnrc_netif_is_6ln(netif)) { uint32_t next_ra_delay = random_uint32_range(0, NDP_MAX_RA_DELAY); @@ -832,8 +833,8 @@ static void _send_delayed_nbr_adv(const gnrc_netif_t *netif, _nib_onl_entry_t *nce; uint8_t reply_flags = NDP_NBR_ADV_FLAGS_S; - nce = _nib_onl_get(tgt, netif->pid); - if ((nce == NULL) || !(nce->mode & _NC)) { + nce = _nib_onl_nc_get(tgt, netif->pid); + if (nce == NULL) { /* usually this should be the case, but when NCE is full, just * ignore the sending. Other nodes in this anycast group are * then preferred */ @@ -1124,8 +1125,7 @@ static void _handle_nbr_adv(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6, gnrc_netif_release(tgt_netif); } #endif /* CONFIG_GNRC_IPV6_NIB_SLAAC */ - if (((nce = _nib_onl_get(&nbr_adv->tgt, netif->pid)) != NULL) && - (nce->mode & _NC)) { + if ((nce = _nib_onl_nc_get(&nbr_adv->tgt, netif->pid)) != NULL) { #if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ARSM) bool tl2ao_avail = false; #endif /* CONFIG_GNRC_IPV6_NIB_ARSM */ @@ -1208,7 +1208,7 @@ static bool _resolve_addr(const ipv6_addr_t *dst, gnrc_netif_t *netif, return true; } #if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ARSM) - if ((entry != NULL) && (entry->mode & _NC) && _is_reachable(entry)) { + if ((entry != NULL) && _is_reachable(entry)) { if (_get_nud_state(entry) == GNRC_IPV6_NIB_NC_INFO_NUD_STATE_STALE) { _set_nud_state(netif, entry, GNRC_IPV6_NIB_NC_INFO_NUD_STATE_DELAY); _evtimer_add(entry, GNRC_IPV6_NIB_DELAY_TIMEOUT, @@ -1236,7 +1236,7 @@ static bool _resolve_addr(const ipv6_addr_t *dst, gnrc_netif_t *netif, DEBUG("nib: resolve address %s by probing neighbors\n", ipv6_addr_to_str(addr_str, dst, sizeof(addr_str))); - if ((entry == NULL) || !(entry->mode & _NC)) { + if (entry == NULL) { entry = _nib_nc_add(dst, (netif != NULL) ? netif->pid : 0, GNRC_IPV6_NIB_NC_INFO_NUD_STATE_INCOMPLETE); if (entry == NULL) {