gnrc/nib: add NIB event bus

Add a message bus where threads can listen for nib events.

Currently only the GNRC_IPV6_NIB_EVENT_ADDR_VALID event is
implemented which informs subscribers that an address got
valid.
This commit is contained in:
Benjamin Valentin 2020-05-05 00:52:49 +02:00
parent 85100ad61a
commit 3974a04623
5 changed files with 47 additions and 0 deletions

View File

@ -71,9 +71,31 @@ extern "C" {
* @brief Per-Interface Event Message Busses
*/
typedef enum {
#ifdef MODULE_GNRC_IPV6
GNRC_NETIF_BUS_IPV6, /**< provides @ref gnrc_ipv6_event_t
messages to subscribers */
#endif
GNRC_NETIF_BUS_NUMOF
} gnrc_netif_bus_t;
/**
* @brief Event types for GNRC_NETIF_BUS_IPV6 per-interface message bus
*/
typedef enum {
/**
* @brief Address becomes valid
*
* The event is generated when an address on the interface becomes valid.
* The message payload contains a pointer to the respective
* @ref ipv6_addr_t struct.
*
* @note If the address on the interface changed between sending
* the event and processing it, the pointer will point to the new address
* which might *not* be valid.
*/
GNRC_IPV6_EVENT_ADDR_VALID,
} gnrc_ipv6_event_t;
/**
* @brief Operations to an interface
*/

View File

@ -284,6 +284,25 @@ void gnrc_netif_ipv6_group_leave_internal(gnrc_netif_t *netif,
*/
int gnrc_netif_ipv6_group_idx(gnrc_netif_t *netif,
const ipv6_addr_t *addr);
/**
* @brief Posts a message to the IPv6 event bus of the interface
*
* @param[in] netif Pointer to the interface
* @param[in] type [Type of the event](@ref gnrc_ipv6_event_t)
* @param[in] ctx The context of the event
*/
static inline void gnrc_netif_ipv6_bus_post(gnrc_netif_t *netif, int type,
const void *ctx)
{
#ifdef MODULE_GNRC_NETIF_BUS
msg_bus_post(&netif->bus[GNRC_NETIF_BUS_IPV6], type, ctx);
#else
(void) netif;
(void) type;
(void) ctx;
#endif
}
#endif /* IS_USED(MODULE_GNRC_NETIF_IPV6) || defined(DOXYGEN) */
/**

View File

@ -665,6 +665,8 @@ int gnrc_netif_ipv6_addr_add_internal(gnrc_netif_t *netif,
gnrc_ipv6_nib_pl_set(netif->pid, addr, pfx_len,
UINT32_MAX, UINT32_MAX);
}
gnrc_netif_ipv6_bus_post(netif, GNRC_IPV6_EVENT_ADDR_VALID, &netif->ipv6.addrs[idx]);
}
#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_SLAAC)
else if (!gnrc_netif_is_6ln(netif)) {

View File

@ -110,6 +110,8 @@ uint8_t _handle_aro(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6,
GNRC_IPV6_NIB_REREG_ADDRESS,
&netif->ipv6.addrs_timers[idx],
rereg_time);
gnrc_netif_ipv6_bus_post(netif, GNRC_IPV6_EVENT_ADDR_VALID,
&netif->ipv6.addrs[idx]);
break;
}
case SIXLOWPAN_ND_STATUS_DUP:

View File

@ -78,6 +78,7 @@ void _auto_configure_addr(gnrc_netif_t *netif, const ipv6_addr_t *pfx,
* locked here) */
netif->ipv6.addrs_flags[idx] &= ~GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_MASK;
netif->ipv6.addrs_flags[idx] |= GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_VALID;
gnrc_netif_ipv6_bus_post(netif, GNRC_IPV6_EVENT_ADDR_VALID, &netif->ipv6.addrs[idx]);
}
#endif /* CONFIG_GNRC_IPV6_NIB_6LN */
#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LN)
@ -211,6 +212,7 @@ void _handle_valid_addr(const ipv6_addr_t *addr)
if (idx >= 0) {
netif->ipv6.addrs_flags[idx] &= ~GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_MASK;
netif->ipv6.addrs_flags[idx] |= GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_VALID;
gnrc_netif_ipv6_bus_post(netif, GNRC_IPV6_EVENT_ADDR_VALID, &netif->ipv6.addrs[idx]);
}
if (netif != NULL) {
/* was acquired in `_get_netif_state()` */