From f34f296242f36bf48f2715e0db58918b1601c851 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 6 Oct 2022 15:44:27 +0200 Subject: [PATCH 1/4] gnrc_netif_lorawan: add support for LINK_UP/_DOWN events --- .../gnrc/netif/lorawan/gnrc_netif_lorawan.c | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c b/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c index a8d0c816680c..8fb2365ce479 100644 --- a/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c +++ b/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c @@ -16,6 +16,8 @@ #include #include "fmt.h" +#include "net/gnrc/ipv6.h" +#include "net/gnrc/ipv6/nib.h" #include "net/gnrc/pktbuf.h" #include "net/gnrc/netif.h" #include "net/gnrc/netif/hdr.h" @@ -69,7 +71,14 @@ void gnrc_lorawan_mlme_confirm(gnrc_lorawan_t *mac, mlme_confirm_t *confirm) if (confirm->type == MLME_JOIN) { if (confirm->status == 0) { - DEBUG("gnrc_lorawan: join succeeded\n"); + gnrc_netif_lorawan_t *lw_netif = container_of(mac, gnrc_netif_lorawan_t, mac); + gnrc_netif_t *netif = container_of(lw_netif, gnrc_netif_t, lorawan); + + DEBUG("gnrc_lorawan: join succeeded %d\n", netif->pid); + if (netif->dev) { + netif->flags |= GNRC_NETIF_FLAGS_HAS_L2ADDR; + netif->dev->event_callback(netif->dev, NETDEV_EVENT_LINK_UP); + } } else { DEBUG("gnrc_lorawan: join failed\n"); @@ -217,6 +226,22 @@ static void _driver_cb(netdev_t *dev, netdev_event_t event) case NETDEV_EVENT_TX_COMPLETE: gnrc_lorawan_radio_tx_done_cb(mac); break; + case NETDEV_EVENT_LINK_UP: { + if (IS_USED(MODULE_GNRC_IPV6)) { + msg_t msg = { .type = GNRC_IPV6_NIB_IFACE_UP, .content = { .ptr = netif } }; + + msg_send(&msg, gnrc_ipv6_pid); + } + break; + } + case NETDEV_EVENT_LINK_DOWN: { + if (IS_USED(MODULE_GNRC_IPV6)) { + msg_t msg = { .type = GNRC_IPV6_NIB_IFACE_DOWN, .content = { .ptr = netif } }; + + msg_send(&msg, gnrc_ipv6_pid); + } + break; + } case NETDEV_EVENT_RX_TIMEOUT: gnrc_lorawan_radio_rx_timeout_cb(mac); break; @@ -578,6 +603,8 @@ static int _set(gnrc_netif_t *netif, const gnrc_netapi_opt_t *opt) &mlme_confirm); res = mlme_confirm.status; if (mlme_confirm.status == 0) { + netif->flags &= ~GNRC_NETIF_FLAGS_HAS_L2ADDR; + netif->dev->event_callback(netif->dev, NETDEV_EVENT_LINK_DOWN); /* reset netif as well */ _reset(netif); } From ab32ad50306ba487ec70220a39dc2b1813ef67bc Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 6 Oct 2022 15:48:52 +0200 Subject: [PATCH 2/4] gnrc_ipv6_nib: auto-configure link-local address on UP event --- sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c | 5 ++++- sys/net/gnrc/network_layer/ipv6/nib/nib.c | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) 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 1e5780764bd0..a76cb03778ec 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c @@ -56,7 +56,10 @@ void _auto_configure_addr(gnrc_netif_t *netif, const ipv6_addr_t *pfx, #if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LN) bool new_address = false; #endif /* CONFIG_GNRC_IPV6_NIB_6LN */ - gnrc_netif_ipv6_get_iid(netif, (eui64_t *)&addr.u64[1]); + if (gnrc_netif_ipv6_get_iid(netif, (eui64_t *)&addr.u64[1]) < 0) { + DEBUG("nib: Can't get IID on interface %u\n", netif->pid); + return; + } ipv6_addr_init_prefix(&addr, pfx, pfx_len); if ((idx = gnrc_netif_ipv6_addr_idx(netif, &addr)) < 0) { if ((idx = gnrc_netif_ipv6_addr_add_internal(netif, &addr, pfx_len, diff --git a/sys/net/gnrc/network_layer/ipv6/nib/nib.c b/sys/net/gnrc/network_layer/ipv6/nib/nib.c index 17cfe83108c8..e7ea453207aa 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/nib.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/nib.c @@ -136,6 +136,7 @@ void gnrc_ipv6_nib_iface_up(gnrc_netif_t *netif) netif->ipv6.rs_sent = 0; #endif /* CONFIG_GNRC_IPV6_NIB_6LN */ netif->ipv6.na_sent = 0; + _auto_configure_addr(netif, &ipv6_addr_link_local_prefix, 64U); if (!(gnrc_netif_is_rtr_adv(netif)) || (gnrc_netif_is_6ln(netif) && !gnrc_netif_is_6lbr(netif))) { uint32_t next_rs_time = random_uint32_range(0, NDP_MAX_RS_MS_DELAY); @@ -175,6 +176,12 @@ void gnrc_ipv6_nib_iface_down(gnrc_netif_t *netif, bool send_final_ra) #else (void)send_final_ra; #endif + for (unsigned i = 0; i < CONFIG_GNRC_NETIF_IPV6_ADDRS_NUMOF; i++) { + if (ipv6_addr_is_link_local(&netif->ipv6.addrs[i])) { + /* link-local address might change on reconnect */ + gnrc_netif_ipv6_addr_remove_internal(netif, &netif->ipv6.addrs[i]); + } + } gnrc_netif_release(netif); } @@ -201,7 +208,6 @@ void gnrc_ipv6_nib_init_iface(gnrc_netif_t *netif) return; } _add_static_lladdr(netif); - _auto_configure_addr(netif, &ipv6_addr_link_local_prefix, 64U); gnrc_netif_release(netif); } From 5f504ad70d9efb1dae31b173e4faaa6bd6a72949 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 6 Oct 2022 15:57:32 +0200 Subject: [PATCH 3/4] gnrc_netif_lorawan: add debug message for failed send --- sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c b/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c index 8fb2365ce479..37f25185413e 100644 --- a/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c +++ b/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c @@ -409,6 +409,7 @@ static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *payload) res = conf.status; if (res < 0) { + DEBUG("gnrc_netif: unable to send (%s)\n", strerror(-res)); gnrc_pktbuf_release_error(payload, res); } From 7f146b6712d583d9471bdd035d67d05a4d0e1a25 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 12 Oct 2022 09:35:19 +0200 Subject: [PATCH 4/4] tests/gnrc_ipv6_nib: up interface on initial initialization Since SLAAC now happens on the up event, the tests needs to ensure, that `gnrc_ipv6_nib_iface_up()` is called before assuming SLAAC happened. For the mock interface, this is done by gnrc_ipv6_nib_iface_up(). --- tests/gnrc_ipv6_nib/mockup_netif.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/gnrc_ipv6_nib/mockup_netif.c b/tests/gnrc_ipv6_nib/mockup_netif.c index 2271589d05f7..2f7503cb3b48 100644 --- a/tests/gnrc_ipv6_nib/mockup_netif.c +++ b/tests/gnrc_ipv6_nib/mockup_netif.c @@ -85,6 +85,7 @@ void _tests_init(void) ); _mock_netif = &_netif; expect(res == 0); + _common_set_up(); /* we do not want to test for SLAAC here so just assure the configured * address is valid */ expect(!ipv6_addr_is_unspecified(&_mock_netif->ipv6.addrs[0]));