diff --git a/sys/include/net/gnrc/ipv6.h b/sys/include/net/gnrc/ipv6.h index f0a27847cfbf..4c0594b38bdd 100644 --- a/sys/include/net/gnrc/ipv6.h +++ b/sys/include/net/gnrc/ipv6.h @@ -181,6 +181,28 @@ extern "C" { #define CONFIG_GNRC_IPV6_STATIC_LLADDR_IS_FIXED 0 #endif +/** + * @brief Select interfaces by driver types for setting static link local + * addresses + * + * This option allows to explicitly include interfaces by matching their + * netdev driver types, encoded in a bitmask. + * See @ref netdev_type_t for possible values of netdev driver types. + * Matching NETDEV_ANY will include all netdev driver types. + * + * Example usage, includes AT86RF215 and MRF24J40 driver types: + * + * @code{.c} + * #define CONFIG_GNRC_IPV6_STATIC_LLADDR_NETDEV_MASK \ + * ((1UL << NETDEV_AT86RF215) | (1UL << NETDEV_MRF24J40)) + * @endcode + * + * A value of 0 will switch this selection feature off. + */ +#ifndef CONFIG_GNRC_IPV6_STATIC_LLADDR_NETDEV_MASK +#define CONFIG_GNRC_IPV6_STATIC_LLADDR_NETDEV_MASK 0ULL +#endif + /** * @brief Message queue size to use for the IPv6 thread. */ diff --git a/sys/net/gnrc/network_layer/ipv6/nib/nib.c b/sys/net/gnrc/network_layer/ipv6/nib/nib.c index ebeca2b23afe..ac7e3fcfa2e6 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/nib.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/nib.c @@ -116,6 +116,23 @@ void gnrc_ipv6_nib_init(void) static void _add_static_lladdr(gnrc_netif_t *netif) { #ifdef CONFIG_GNRC_IPV6_STATIC_LLADDR +#if (CONFIG_GNRC_IPV6_STATIC_LLADDR_NETDEV_MASK) > 0 +#ifndef MODULE_NETDEV_REGISTER +#error "Use of CONFIG_GNRC_IPV6_STATIC_LLADDR_NETDEV_MASK requires MODULE_NETDEV_REGISTER" +#endif + if (! (((CONFIG_GNRC_IPV6_STATIC_LLADDR_NETDEV_MASK) & (1ULL << netif->dev->type)) || + ((CONFIG_GNRC_IPV6_STATIC_LLADDR_NETDEV_MASK) & (1ULL << NETDEV_ANY)))) { + DEBUG("nib: interface #%u: not setting static link-local address " + "(netdev type %u not included)\n", + netif->pid, netif->dev->type); + return; + } +#endif + DEBUG("nib: interface #%u: adding static link-local address \"%s\"%s\n", + netif->pid, + CONFIG_GNRC_IPV6_STATIC_LLADDR, + IS_ACTIVE(CONFIG_GNRC_IPV6_STATIC_LLADDR_IS_FIXED) ? + " (fixed)" : " (+ interface number)"); /* parse addr from string and explicitly set a link local prefix * if ifnum > 1 each interface will get its own link local address * with CONFIG_GNRC_IPV6_STATIC_LLADDR + i