Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7564665
gnrc/netapi: add notification message type
elenaf9 Jul 15, 2025
0408e39
nimble/netif: notify on BLE connection events
elenaf9 Jul 15, 2025
bf82b94
gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Jul 15, 2025
fbd2219
gnrc/ipv6: notify L3_ROUTING of discovered/ unreachable nodes
elenaf9 Jul 16, 2025
9715791
gnrc/rpl: iterate through parents that match addr
elenaf9 Jul 8, 2025
9030409
gnrc/rpl: handle L3 routing events from netapi
elenaf9 Jul 16, 2025
6cef5d6
nimble/rpble: don't send DIS on connection event
elenaf9 Jul 16, 2025
b6e19c2
fixup! gnrc/rpl: handle L3 routing events from netapi
elenaf9 Jul 17, 2025
f1b82ec
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Jul 17, 2025
4404817
fixup! gnrc/netapi: add notification message type
elenaf9 Jul 17, 2025
e9d25cb
fixup! gnrc/netapi: add notification message type
elenaf9 Jul 17, 2025
6570d30
fixup! nimble/netif: notify on BLE connection events
elenaf9 Jul 17, 2025
82b5059
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Jul 17, 2025
7e911b8
fixup! gnrc/ipv6: notify L3_ROUTING of discovered/ unreachable nodes
elenaf9 Jul 17, 2025
d8d7c81
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Jul 17, 2025
602e894
fixup! gnrc/netapi: add notification message type
elenaf9 Jul 30, 2025
418825f
fixup! gnrc/netapi: add notification message type
elenaf9 Jul 30, 2025
7755585
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Jul 30, 2025
2447cb8
fixup! gnrc/netapi: add notification message type
elenaf9 Aug 4, 2025
8c53e7a
fixup! fixup! gnrc/netapi: add notification message type
elenaf9 Aug 7, 2025
2c5bf74
gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 7, 2025
ad4c316
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 7, 2025
b8ae0f6
Merge branch 'master' of https://github.com/RIOT-OS/RIOT into gnrc/ne…
elenaf9 Aug 18, 2025
abb69a1
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 29, 2025
afb04c8
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 29, 2025
8c88416
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 29, 2025
bee053b
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 29, 2025
a7d5ac9
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 29, 2025
2079a8f
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Sep 3, 2025
30b2b7f
Apply suggestions from code review
elenaf9 Sep 4, 2025
2bfd90d
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Sep 4, 2025
7713680
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Sep 4, 2025
f57c38b
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Sep 4, 2025
2d5e9c5
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Sep 4, 2025
7de5975
fixup! Apply suggestions from code review
elenaf9 Sep 4, 2025
754fe9c
Like 7de59757a6da5b3b7367f1a0a2e87081c3e1887f
elenaf9 Sep 4, 2025
0c8d01d
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Sep 8, 2025
97a0422
fixup! gnrc/netapi: add notification message type
elenaf9 Sep 8, 2025
d57474d
fixup! nimble/netif: notify on BLE connection events
elenaf9 Sep 8, 2025
06c3e64
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Sep 8, 2025
5328407
fixup! gnrc/ipv6: notify L3_ROUTING of discovered/ unreachable nodes
elenaf9 Sep 8, 2025
00a8d28
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Sep 8, 2025
ed5ac34
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Oct 1, 2025
c45fd59
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Oct 1, 2025
6e33db2
fixup! gnrc/netapi: add notification message type
elenaf9 Oct 1, 2025
2ab900c
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Nov 25, 2025
d0df717
fixup! gnrc/rpl: handle L3 routing events from netapi
elenaf9 Nov 26, 2025
e263d97
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Nov 26, 2025
d20a7b5
fixup! fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Nov 26, 2025
11567f7
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Nov 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/nimble/netif/nimble_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,24 @@
ble_l2cap_recv_ready(event->receive.chan, rxb);
}

/**
* @brief Sends a netapi notification for a connection event.
*
* @param[in] notify The type of notification event.
* @param[in] addr BLE address of the node that (dis-)connected.
*/
static inline void _dispatch_connection_event(netnotify_t notify, uint8_t *addr)
{
netnotify_l2_connec_t event = {
.l2addr = addr,
.l2addr_len = BLE_ADDR_LEN,
.if_pid = _netif.pid,
};

gnrc_netapi_notify(GNRC_NETTYPE_L2_DISCOVERY, GNRC_NETREG_DEMUX_CTX_ALL,
notify, &event, sizeof(netnotify_l2_connec_t));
}

static int _on_l2cap_client_evt(struct ble_l2cap_event *event, void *arg)
{
int handle = (int)arg;
Expand All @@ -349,6 +367,7 @@
conn->state |= NIMBLE_NETIF_L2CAP_CLIENT;
conn->state &= ~NIMBLE_NETIF_CONNECTING;
_notify(handle, NIMBLE_NETIF_CONNECTED_MASTER, conn->addr);
_dispatch_connection_event(NETNOTIFY_L2_CONNECTED, conn->addr);
break;
case BLE_L2CAP_EVENT_COC_DISCONNECTED:
assert(conn->state & NIMBLE_NETIF_L2CAP_CLIENT);
Expand Down Expand Up @@ -404,6 +423,7 @@
}

_notify(handle, NIMBLE_NETIF_CONNECTED_SLAVE, conn->addr);
_dispatch_connection_event(NETNOTIFY_L2_CONNECTED, conn->addr);
break;
case BLE_L2CAP_EVENT_COC_DISCONNECTED:
conn = nimble_netif_conn_from_gaphandle(event->disconnect.conn_handle);
Expand Down Expand Up @@ -450,7 +470,7 @@
{
struct ble_gap_conn_desc desc;
int res = ble_gap_conn_find(conn->gaphandle, &desc);
assert(res == 0) ;

Check warning on line 473 in pkg/nimble/netif/nimble_netif.c

View workflow job for this annotation

GitHub Actions / static-tests

semicolon is isolated from other tokens
(void)res;

conn->itvl = desc.conn_itvl;
Expand Down Expand Up @@ -498,6 +518,7 @@
nimble_netif_conn_free(handle, addr);
thread_flags_set(_netif_thread, FLAG_TX_NOTCONN);
_notify(handle, type, addr);
_dispatch_connection_event(NETNOTIFY_L2_DISCONNECTED, addr);
break;
}
case BLE_GAP_EVENT_CONN_UPDATE:
Expand Down Expand Up @@ -542,6 +563,7 @@
nimble_netif_conn_free(handle, addr);
thread_flags_set(_netif_thread, FLAG_TX_NOTCONN);
_notify(handle, type, addr);
_dispatch_connection_event(NETNOTIFY_L2_DISCONNECTED, addr);
break;
}
case BLE_GAP_EVENT_CONN_UPDATE:
Expand Down
3 changes: 0 additions & 3 deletions pkg/nimble/rpble/nimble_rpble.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ static void _on_netif_evt(int handle, nimble_netif_event_t event,
case NIMBLE_NETIF_CONNECTED_MASTER:
/* parent selected */
assert(_current_parent == handle);
/* send a DIS once connected to a (new) parent) */
gnrc_rpl_send_DIS(NULL, (ipv6_addr_t *) &ipv6_addr_all_rpl_nodes,
NULL, 0);
break;
case NIMBLE_NETIF_CONNECTED_SLAVE:
/* child added */
Expand Down
38 changes: 38 additions & 0 deletions sys/include/net/gnrc/ipv6/nib/nc.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,29 @@ static inline unsigned gnrc_ipv6_nib_nc_get_ar_state(const gnrc_ipv6_nib_nc_t *e
int gnrc_ipv6_nib_nc_set(const ipv6_addr_t *ipv6, unsigned iface,
const uint8_t *l2addr, size_t l2addr_len);

#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LN) || defined(DOXYGEN)
/**
* @brief Adds an unmanaged neighbor entry to the NIB if the interface represents a 6LN node
* and the IPv6 address can be constructed from the L2 address @p l2addr.
*
* @param[in] iface The interface to the neighbor.
* @param[in] l2addr The neighbor's layer 2 address.
* @param[in] l2addr_len Length of @p l2addr.
*
* @return 0 on success.
* @return -ENOTSUP, if the interface does not represent a 6LN or when
* gnrc_netif_t::device_type of the iface does not support IID conversion.
* @return -EINVAL, when @p addr_len is invalid for the
* gnrc_netif_t::device_type of @p netif.
* @return -ENOMEM, if no space is left in neighbor cache.
*/
int gnrc_ipv6_nib_nc_try_set_6ln(unsigned iface, const uint8_t *l2addr,
size_t l2addr_len);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only possible for 6LN nodes because otherwise we can't statically build an IPv6 address from the link-layer address. The IPv6 address is build as a reverse of the _resolve_addr_from_ipv6 that is used when resolving IPv6-> L2address, following the stateless address autoconfiguration section in the RFC.

#else /* CONFIG_GNRC_IPV6_NIB_6LN */
#define gnrc_ipv6_nib_nc_try_set_6ln(unsigned iface, const uint8_t *l2addr,
size_t l2addr_len) (-ENOTSUP)
#endif /* CONFIG_GNRC_IPV6_NIB_6LN */

/**
* @brief Deletes neighbor with address @p ipv6 from NIB
*
Expand All @@ -245,6 +268,21 @@ int gnrc_ipv6_nib_nc_set(const ipv6_addr_t *ipv6, unsigned iface,
*/
void gnrc_ipv6_nib_nc_del(const ipv6_addr_t *ipv6, unsigned iface);

/**
* @brief Deletes neighbor with link-layer address @p l2addr from NIB.
*
* @param[in] iface The interface to the neighbor.
* @param[in] l2addr The neighbor's l2addr address.
* @param[in] l2addr_len Length of @p l2addr.
*
*
* If the @p l2addr can't be found for a neighbor in the NIB nothing happens.
*
* @return True, if a neighbor with @p l2addr existed.
* @return False, otherwise.
*/
bool gnrc_ipv6_nib_nc_del_l2(unsigned iface, const uint8_t *l2addr, size_t l2addr_len);

/**
* @brief Mark neighbor with address @p ipv6 as reachable
*
Expand Down
35 changes: 34 additions & 1 deletion sys/include/net/gnrc/netapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

#include "thread.h"
#include "net/netopt.h"
#include "net/gnrc/netnotify.h"
#include "net/gnrc/nettype.h"
#include "net/gnrc/pkt.h"

Expand Down Expand Up @@ -88,10 +89,15 @@ extern "C" {
#define GNRC_NETAPI_MSG_TYPE_GET (0x0204)

/**
* @brief @ref core_msg type for replying to get and set option messages
* @brief @ref core_msg type for replying to get/ set option, and notify messages.
*/
#define GNRC_NETAPI_MSG_TYPE_ACK (0x0205)

/**
* @brief @ref core_msg type for sending event notifications to the network stack.
*/
#define GNRC_NETAPI_MSG_TYPE_NOTIFY (0x0207)

/**
* @brief Data structure to be send for setting (@ref GNRC_NETAPI_MSG_TYPE_SET)
* and getting (@ref GNRC_NETAPI_MSG_TYPE_GET) options
Expand All @@ -103,6 +109,15 @@ typedef struct {
uint16_t data_len; /**< size of the data / the buffer */
} gnrc_netapi_opt_t;

/**
* @brief Data structure to be send for notification events.
*/
typedef struct {
netnotify_t event; /**< the type of event */
void *data; /**< event data */
uint16_t data_len; /**< size of the data */
} gnrc_netapi_notify_t;

/**
* @brief Shortcut function for sending @ref GNRC_NETAPI_MSG_TYPE_SND or
* @ref GNRC_NETAPI_MSG_TYPE_RCV messages
Expand Down Expand Up @@ -183,6 +198,24 @@ static inline int gnrc_netapi_dispatch_send(gnrc_nettype_t type, uint32_t demux_
return gnrc_netapi_dispatch(type, demux_ctx, GNRC_NETAPI_MSG_TYPE_SND, pkt);
}

/**
* @brief Sends a @ref GNRC_NETAPI_MSG_TYPE_NOTIFY command to all subscribers to
* (@p type, @p demux_ctx).
*
* @note This blocks the sender until all registered subscribers have ack'ed the notification
* or sending has failed. The @p data can be freed after the function returned.
*
* @param[in] type Type of the targeted network module.
* @param[in] demux_ctx Demultiplexing context for @p type.
* @param[in] event Notification event type.
* @param[in] data Data associated with the event.
* @param[in] data_len Size of @p data.
*
* @return Number of subscribers to (@p type, @p demux_ctx).
*/
int gnrc_netapi_notify(gnrc_nettype_t type, uint32_t demux_ctx, netnotify_t event,
void *data, size_t data_len);

/**
* @brief Shortcut function for sending @ref GNRC_NETAPI_MSG_TYPE_RCV messages
*
Expand Down
43 changes: 43 additions & 0 deletions sys/include/net/gnrc/netnotify.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2025 Elena Frank <[email protected]>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include "sched.h"

/**
* @brief Definition of notification event types in the network stack.
*
* @note Expand at will.
*/
typedef enum {
NETNOTIFY_L2_CONNECTED,
NETNOTIFY_L2_DISCONNECTED,
NETNOTIFY_L3_DISCOVERED,
NETNOTIFY_L3_UNREACHABLE,
} netnotify_t;

/**
* @brief L2 (dis-)connection event data.
*/
typedef struct netnotify_l2_connec {
uint8_t *l2addr; /**< L2 address of the node */
uint8_t l2addr_len; /**< length of L2 address in byte */
kernel_pid_t if_pid; /**< PID of network interface */
} netnotify_l2_connec_t;


Check warning on line 38 in sys/include/net/gnrc/netnotify.h

View workflow job for this annotation

GitHub Actions / static-tests

too many consecutive empty lines
#ifdef __cplusplus
}
#endif

/** @} */

Check failure on line 43 in sys/include/net/gnrc/netnotify.h

View workflow job for this annotation

GitHub Actions / static-tests

unbalanced grouping commands
4 changes: 4 additions & 0 deletions sys/include/net/gnrc/nettype.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@
GNRC_NETTYPE_ICMPV6, /**< Protocol is ICMPv6 */
#endif

GNRC_NETTYPE_L2_DISCOVERY, /**< L2 node discovery */

GNRC_NETTYPE_L3_ROUTING, /**< L3 routing info */

#if IS_USED(MODULE_GNRC_NETTYPE_CCN) || defined(DOXYGEN)
GNRC_NETTYPE_CCN, /**< Protocol is CCN */
GNRC_NETTYPE_CCN_CHUNK, /**< Protocol is CCN, packet contains a content
Expand Down Expand Up @@ -142,7 +146,7 @@

/**
* @brief Translates an Ether Type number to @ref gnrc_nettype_t
* @see [IANA, ETHER TYPES](http://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml)

Check warning on line 149 in sys/include/net/gnrc/nettype.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
*
* @param[in] type An Ether Type number
*
Expand Down Expand Up @@ -179,7 +183,7 @@

/**
* @brief Translates @ref gnrc_nettype_t to an Ether Type number
* @see [IANA, ETHER TYPES](http://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml)

Check warning on line 186 in sys/include/net/gnrc/nettype.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
*
* @param[in] type A protocol type
*
Expand Down
12 changes: 12 additions & 0 deletions sys/include/net/gnrc/rpl/dodag.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ void gnrc_rpl_dodag_remove_all_parents(gnrc_rpl_dodag_t *dodag);
bool gnrc_rpl_parent_add_by_addr(gnrc_rpl_dodag_t *dodag, ipv6_addr_t *addr,
gnrc_rpl_parent_t **parent);

/**
* @brief Iterate over all parents in all DODAGs with @p IPv6 address.
*
* @param[in] idx Index to start searching from.
* @param[in] addr IPV6 address of the parent.
* @param[out] parent Pointer to the parent if one was found. Otherwise NULL.
*
* @return Index > 0 to continue next search from, if parent was found.
* @return -ENONENT if not found
*/
int gnrc_rpl_parent_iter_by_addr(ipv6_addr_t *addr, gnrc_rpl_parent_t **parent, int idx);

Comment on lines 132 to 143
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoting from there for reviewer's convenience:

This function is a bit weird, but it is needed because, theoretically, if we have more than one RPL instance, the same node can be present as parent in multiple dodags, and thus appear multiple times in the gnrc_rpl_parents list.
We want to mark the parent as unreachable in all dodags.

I'm not knowledgeable enough with RPL to comment on this.

/**
* @brief Remove the @p parent from its DODAG.
*
Expand Down
38 changes: 38 additions & 0 deletions sys/net/gnrc/netapi/gnrc_netapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,41 @@

return numof;
}

int gnrc_netapi_notify(gnrc_nettype_t type, uint32_t demux_ctx, netnotify_t event,
void *data, size_t data_len)
{
gnrc_netapi_notify_t notify;
msg_t cmd;
msg_t ack;

notify.event = event;
notify.data = data;
notify.data_len = data_len;

cmd.type = GNRC_NETAPI_MSG_TYPE_NOTIFY;
cmd.content.ptr = (void *)&notify;

gnrc_netreg_acquire_shared();

int numof = gnrc_netreg_num(type, demux_ctx);

if (numof != 0) {
/* Look up the registered threads for this message type. */
gnrc_netreg_entry_t *sendto = gnrc_netreg_lookup(type, demux_ctx);

Check failure on line 166 in sys/net/gnrc/netapi/gnrc_netapi.c

View workflow job for this annotation

GitHub Actions / static-tests

trailing whitespace.
/* Dispatch to all registered threads sequentially. */
while (sendto) {
/* Need to wait for an ACK to ensure that the msg was received and that
there won't be any dangling pointers after the function returned. */
/* TODO: First send to all threads, then wait for all ACK's?*/
msg_send_receive(&cmd, &ack, sendto->target.pid);
assert(ack.type == GNRC_NETAPI_MSG_TYPE_ACK);
sendto = gnrc_netreg_getnext(sendto);
}
}

gnrc_netreg_release_shared();

return numof;
}
Loading
Loading