From 13638944264c924e26a622db3125715f22c1d678 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 11 Dec 2024 17:59:10 +0100 Subject: [PATCH 1/5] gnrc/ipv6/nib: add newline in debug message --- sys/net/gnrc/network_layer/ipv6/nib/nib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/net/gnrc/network_layer/ipv6/nib/nib.c b/sys/net/gnrc/network_layer/ipv6/nib/nib.c index 3cfb7d2aad3d..fbf99cea2e6a 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/nib.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/nib.c @@ -781,7 +781,7 @@ static void _handle_rtr_adv(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6, else { dr = _nib_drl_get(&ipv6->src, netif->pid); - DEBUG("nib: router lifetime was 0. Removing router and routes via it."); + DEBUG("nib: router lifetime was 0. Removing router and routes via it.\n"); if (dr != NULL) { _handle_rtr_timeout(dr); } From d708e95681c8c1c5c57c8321644ae3207ad1263c Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 11 Dec 2024 19:31:36 +0100 Subject: [PATCH 2/5] gnrc_ipv6_nib: fix misplaced assert() --- sys/net/gnrc/network_layer/ipv6/nib/_nib-router.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/net/gnrc/network_layer/ipv6/nib/_nib-router.c b/sys/net/gnrc/network_layer/ipv6/nib/_nib-router.c index 76ee917483ba..0302a37d9827 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/_nib-router.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/_nib-router.c @@ -251,8 +251,8 @@ static gnrc_pktsnip_t *_build_ext_opts(gnrc_netif_t *netif, } #endif /* CONFIG_GNRC_IPV6_NIB_DNS */ if (gnrc_netif_is_6lr(netif)) { - assert(abr != NULL); #if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_MULTIHOP_P6C) + assert(abr != NULL); uint16_t ltime_min; gnrc_pktsnip_t *abro; From 314968cf86a5ffffcb037e1872b92ceb5716cea5 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 9 Dec 2024 19:33:42 +0100 Subject: [PATCH 3/5] gnrc/ipv6/nib: make ABR run-time configurable --- sys/include/net/gnrc/ipv6/nib/conf.h | 9 +++++- sys/include/net/netopt.h | 7 +++++ sys/net/gnrc/netif/gnrc_netif.c | 31 +++++++++++++++++++ .../gnrc/network_layer/ipv6/nib/_nib-router.h | 2 +- sys/net/gnrc/network_layer/ipv6/nib/nib.c | 27 +++++++++++----- sys/shell/cmds/gnrc_netif.c | 4 +++ 6 files changed, 71 insertions(+), 9 deletions(-) diff --git a/sys/include/net/gnrc/ipv6/nib/conf.h b/sys/include/net/gnrc/ipv6/nib/conf.h index 90a9bf4b9df3..4c61a1f06ea0 100644 --- a/sys/include/net/gnrc/ipv6/nib/conf.h +++ b/sys/include/net/gnrc/ipv6/nib/conf.h @@ -125,12 +125,19 @@ extern "C" { #endif /** - * @brief activate router advertising at interface start-up + * @brief activate router advertising at interface start-up */ #ifndef CONFIG_GNRC_IPV6_NIB_ADV_ROUTER #define CONFIG_GNRC_IPV6_NIB_ADV_ROUTER 0 #endif +/** + * @brief activate authoritative border router functionality at interface start-up + */ +#ifndef CONFIG_GNRC_IPV6_NIB_ABR +#define CONFIG_GNRC_IPV6_NIB_ABR CONFIG_GNRC_IPV6_NIB_6LBR +#endif + /** * @brief Include a Route Information Option for subnets * on other interfaces in normal Router Advertisements diff --git a/sys/include/net/netopt.h b/sys/include/net/netopt.h index 213418a7c33f..d1ca42c9fdeb 100644 --- a/sys/include/net/netopt.h +++ b/sys/include/net/netopt.h @@ -563,6 +563,13 @@ typedef enum { */ NETOPT_6LO_IPHC, + /** + * @brief (@ref netopt_enable_t) authoritative border router + * + * @see [RFC 6775](https://datatracker.ietf.org/doc/html/rfc6775#section-4.3) + */ + NETOPT_6LO_ABR, + /** * @brief (uint8_t) retry amount from missing ACKs of the last transmission * diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 6b6619bfc086..fae2e4287b50 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -304,6 +304,15 @@ int gnrc_netif_get_from_netdev(gnrc_netif_t *netif, gnrc_netapi_opt_t *opt) res = sizeof(netopt_enable_t); break; #endif /* MODULE_GNRC_SIXLOWPAN_IPHC */ +#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LBR) + case NETOPT_6LO_ABR: + assert(opt->data_len == sizeof(netopt_enable_t)); + *((netopt_enable_t *)opt->data) = (netif->flags & GNRC_NETIF_FLAGS_6LO_ABR) + ? NETOPT_ENABLE + : NETOPT_DISABLE; + res = sizeof(netopt_enable_t); + break; +#endif default: break; } @@ -409,6 +418,28 @@ int gnrc_netif_set_from_netdev(gnrc_netif_t *netif, res = sizeof(netopt_enable_t); break; #endif /* MODULE_GNRC_SIXLOWPAN_IPHC */ +#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LBR) + case NETOPT_6LO_ABR: + assert(opt->data_len == sizeof(netopt_enable_t)); + + extern void _start_search_rtr(gnrc_netif_t *netif); + extern void _stop_search_rtr(gnrc_netif_t *netif); + + if (*(((netopt_enable_t *)opt->data)) == NETOPT_ENABLE) { + netif->flags |= GNRC_NETIF_FLAGS_6LO_ABR; + if (!(netif->flags & GNRC_NETIF_FLAGS_6LO_ABR)) { + _stop_search_rtr(netif); + } + } + else { + if (netif->flags & GNRC_NETIF_FLAGS_6LO_ABR) { + _start_search_rtr(netif); + } + netif->flags &= ~GNRC_NETIF_FLAGS_6LO_ABR; + } + res = sizeof(netopt_enable_t); + break; +#endif case NETOPT_RAWMODE: if (*(((netopt_enable_t *)opt->data)) == NETOPT_ENABLE) { netif->flags |= GNRC_NETIF_FLAGS_RAWMODE; diff --git a/sys/net/gnrc/network_layer/ipv6/nib/_nib-router.h b/sys/net/gnrc/network_layer/ipv6/nib/_nib-router.h index df08b67de480..b6dfd5bfc327 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/_nib-router.h +++ b/sys/net/gnrc/network_layer/ipv6/nib/_nib-router.h @@ -50,7 +50,7 @@ static inline void _init_iface_router(gnrc_netif_t *netif) netif->flags |= GNRC_NETIF_FLAGS_IPV6_RTR_ADV; } - if (IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LBR)) { + if (IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ABR)) { netif->flags |= GNRC_NETIF_FLAGS_6LO_ABR; } } diff --git a/sys/net/gnrc/network_layer/ipv6/nib/nib.c b/sys/net/gnrc/network_layer/ipv6/nib/nib.c index fbf99cea2e6a..3f559612890a 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/nib.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/nib.c @@ -108,8 +108,10 @@ static inline bool _should_search_rtr(const gnrc_netif_t *netif) /* 6LBR interface does not send RS. A non-advertising router sends RS or a 6LN that is advertising or not has to refetch router information */ - return !gnrc_netif_is_6lbr(netif) && - (!gnrc_netif_is_rtr_adv(netif) || gnrc_netif_is_6ln(netif)); + if (gnrc_netif_is_6lbr(netif)) { + return false; + } + return !gnrc_netif_is_rtr_adv(netif) || gnrc_netif_is_6ln(netif); } void gnrc_ipv6_nib_init(void) @@ -167,6 +169,19 @@ static void _add_static_lladdr(gnrc_netif_t *netif) #endif } +void _start_search_rtr(gnrc_netif_t *netif) +{ + uint32_t next_rs_time = random_uint32_range(0, NDP_MAX_RS_MS_DELAY); + + _evtimer_add(netif, GNRC_IPV6_NIB_SEARCH_RTR, &netif->ipv6.search_rtr, + next_rs_time); +} + +void _stop_search_rtr(gnrc_netif_t *netif) +{ + _evtimer_del(&netif->ipv6.search_rtr); +} + void gnrc_ipv6_nib_iface_up(gnrc_netif_t *netif) { assert(netif != NULL); @@ -185,11 +200,9 @@ void gnrc_ipv6_nib_iface_up(gnrc_netif_t *netif) } _add_static_lladdr(netif); _auto_configure_addr(netif, &ipv6_addr_link_local_prefix, 64U); - if (_should_search_rtr(netif)) { - uint32_t next_rs_time = random_uint32_range(0, NDP_MAX_RS_MS_DELAY); - _evtimer_add(netif, GNRC_IPV6_NIB_SEARCH_RTR, &netif->ipv6.search_rtr, - next_rs_time); + if (_should_search_rtr(netif)) { + _start_search_rtr(netif); } #if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ROUTER) else { @@ -208,7 +221,7 @@ void gnrc_ipv6_nib_iface_down(gnrc_netif_t *netif, bool send_final_ra) _deinit_iface_arsm(netif); if (_should_search_rtr(netif)) { - _evtimer_del(&netif->ipv6.search_rtr); + _stop_search_rtr(netif); } #if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ROUTER) else { diff --git a/sys/shell/cmds/gnrc_netif.c b/sys/shell/cmds/gnrc_netif.c index c827939a1f7d..227e8733af6b 100644 --- a/sys/shell/cmds/gnrc_netif.c +++ b/sys/shell/cmds/gnrc_netif.c @@ -62,6 +62,7 @@ static const struct { netopt_t opt; } flag_cmds[] = { { "6lo", NETOPT_6LO }, + { "abr", NETOPT_6LO_ABR }, { "ack_req", NETOPT_ACK_REQ }, { "gts", NETOPT_GTS_TX }, { "pan_coord", NETOPT_PAN_COORD }, @@ -887,6 +888,9 @@ static void _netif_list(netif_t *iface) #ifdef MODULE_GNRC_SIXLOWPAN line_thresh = _netif_list_flag(iface, NETOPT_6LO, "6LO ", line_thresh); #endif +#if CONFIG_GNRC_IPV6_NIB_6LBR + line_thresh = _netif_list_flag(iface, NETOPT_6LO_ABR, "ABR ", line_thresh); +#endif #ifdef MODULE_GNRC_SIXLOWPAN_IPHC line_thresh += _LINE_THRESHOLD + 1; /* enforce linebreak after this option */ line_thresh = _netif_list_flag(iface, NETOPT_6LO_IPHC, "IPHC ", From 08cf5926bc609c8d8c21801a447aa805f163f12f Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 11 Dec 2024 19:29:45 +0100 Subject: [PATCH 4/5] gnrc/ipv6/nib: introduce CONFIG_GNRC_IPV6_NIB_MULTIHOP_P6C_AUTO_ADV --- sys/include/net/gnrc/ipv6/nib/conf.h | 7 +++++++ sys/net/gnrc/network_layer/ipv6/nib/nib.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sys/include/net/gnrc/ipv6/nib/conf.h b/sys/include/net/gnrc/ipv6/nib/conf.h index 4c61a1f06ea0..a44cdf40cccf 100644 --- a/sys/include/net/gnrc/ipv6/nib/conf.h +++ b/sys/include/net/gnrc/ipv6/nib/conf.h @@ -233,6 +233,13 @@ extern "C" { #endif #endif +/** + * @brief Start sending RAs when a RA has been received + */ +#ifndef CONFIG_GNRC_IPV6_NIB_MULTIHOP_P6C_AUTO_ADV +#define CONFIG_GNRC_IPV6_NIB_MULTIHOP_P6C_AUTO_ADV CONFIG_GNRC_IPV6_NIB_MULTIHOP_P6C +#endif + /** * @brief Multihop duplicate address detection * diff --git a/sys/net/gnrc/network_layer/ipv6/nib/nib.c b/sys/net/gnrc/network_layer/ipv6/nib/nib.c index 3f559612890a..f3046b91b947 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/nib.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/nib.c @@ -920,7 +920,7 @@ static void _handle_rtr_adv(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6, } #if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LN) if (gnrc_netif_is_6ln(netif) && !gnrc_netif_is_6lbr(netif)) { - if (IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_MULTIHOP_P6C)) { + if (IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_MULTIHOP_P6C_AUTO_ADV)) { _set_rtr_adv(netif); } /* but re-fetch information from router in time */ From a8407ee574a18d1c11a8658f4d39f8bd2334aa21 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 13 Jan 2025 16:46:29 +0100 Subject: [PATCH 5/5] fixup! gnrc/ipv6/nib: make ABR run-time configurable --- sys/net/gnrc/netif/gnrc_netif.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index fae2e4287b50..7effee2ab07c 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -426,13 +426,15 @@ int gnrc_netif_set_from_netdev(gnrc_netif_t *netif, extern void _stop_search_rtr(gnrc_netif_t *netif); if (*(((netopt_enable_t *)opt->data)) == NETOPT_ENABLE) { - netif->flags |= GNRC_NETIF_FLAGS_6LO_ABR; if (!(netif->flags & GNRC_NETIF_FLAGS_6LO_ABR)) { + /* we were no ABR before */ _stop_search_rtr(netif); } + netif->flags |= GNRC_NETIF_FLAGS_6LO_ABR; } else { if (netif->flags & GNRC_NETIF_FLAGS_6LO_ABR) { + /* we were a ABR before */ _start_search_rtr(netif); } netif->flags &= ~GNRC_NETIF_FLAGS_6LO_ABR;