From 48a241789265cae9f3f3744b0d9a004c4d067cb4 Mon Sep 17 00:00:00 2001 From: xnumad <34810600+xnumad@users.noreply.github.com> Date: Mon, 26 Aug 2024 10:50:20 +0200 Subject: [PATCH 1/2] gnrc/ipv6: `nib route`: hide off-link PLEs --- sys/include/net/gnrc/ipv6/nib/ft.h | 3 ++- sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/include/net/gnrc/ipv6/nib/ft.h b/sys/include/net/gnrc/ipv6/nib/ft.h index 817c5a394e..0d8182ce58 100644 --- a/sys/include/net/gnrc/ipv6/nib/ft.h +++ b/sys/include/net/gnrc/ipv6/nib/ft.h @@ -112,7 +112,8 @@ void gnrc_ipv6_nib_ft_del(const ipv6_addr_t *dst, unsigned dst_len); * * The iteration over all forwarding table entries in the NIB includes all * entries added via @p gnrc_ipv6_nib_ft_add() and entries that are currently - * in the Destination Cache, in the Prefix List, and in the Default Router List. + * in the Destination Cache, in the Prefix List (only if they're on-link), + * and in the Default Router List. * * Usage example: * diff --git a/sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c b/sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c index f739de1df1..afbaf5f3ba 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c @@ -133,6 +133,7 @@ bool gnrc_ipv6_nib_ft_iter(const ipv6_addr_t *next_hop, unsigned iface, while ((offl = _nib_offl_iter(offl))) { assert(offl->mode != 0); if ((offl->next_hop != NULL) && + (offl->mode != _PL || offl->flags & _PFX_ON_LINK) && ((iface == 0) || (iface == _nib_onl_get_if(offl->next_hop))) && ((next_hop == NULL) || ipv6_addr_equal(&offl->next_hop->ipv6, next_hop))) { From 92b77ed944a76439e497d27d7cabf1da014535aa Mon Sep 17 00:00:00 2001 From: xnumad <34810600+xnumad@users.noreply.github.com> Date: Mon, 2 Sep 2024 18:10:57 +0200 Subject: [PATCH 2/2] gnrc_ipv6_nib: refactor Co-Authored-By: benpicco --- sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c | 27 ++++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c b/sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c index afbaf5f3ba..2aecb5cdf1 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/nib_ft.c @@ -132,15 +132,26 @@ bool gnrc_ipv6_nib_ft_iter(const ipv6_addr_t *next_hop, unsigned iface, while ((offl = _nib_offl_iter(offl))) { assert(offl->mode != 0); - if ((offl->next_hop != NULL) && - (offl->mode != _PL || offl->flags & _PFX_ON_LINK) && - ((iface == 0) || (iface == _nib_onl_get_if(offl->next_hop))) && - ((next_hop == NULL) || ipv6_addr_equal(&offl->next_hop->ipv6, - next_hop))) { - _nib_ft_get(offl, fte); - *state = offl; - return true; + if (offl->next_hop == NULL) { + /* 'holey' NIB / dangling reference. + * there is no next hop (not even an interface) */ + continue; } + if (offl->mode == _PL && !(offl->flags & _PFX_ON_LINK)) { + /* prefix list entry is off-link */ + continue; + } + if (iface && iface != _nib_onl_get_if(offl->next_hop)) { + /* interface does not match */ + continue; + } + if (next_hop && !ipv6_addr_equal(&offl->next_hop->ipv6, next_hop)) { + /* next hop does not match */ + continue; + } + _nib_ft_get(offl, fte); + *state = offl; + return true; } *state = NULL; }