diff --git a/sys/include/net/eui_provider.h b/sys/include/net/eui_provider.h index 44f46a2d9d..a856406815 100644 --- a/sys/include/net/eui_provider.h +++ b/sys/include/net/eui_provider.h @@ -75,10 +75,13 @@ * Recommendations * =============== * - * While it is possible to match EUIs with any netdev in a first come, first serve - * fashion (`NETDEV_ANY`, `NETDEV_INDEX_ANY`) it is recommended to fix the EUI - * providers to a device and interface to avoid them being used for 'virtual' - * interfaces. + * Do not use `NETDEV_ANY` as EUI device type. Otherwise if you have two + * interfaces both will match the same EUI. + * + * It is however possible to use `NETDEV_INDEX_ANY` if you have multiple + * interfaces of the same type and your EUI provider function takes the index + * into account (or returns error if the index is out of bounds with the + * available ids). * * Fixed addresses are only guaranteed if the network devices are also fixed. * E.g. if you usually have two netdevs and disable the first one at compile-time @@ -132,7 +135,7 @@ typedef int (*netdev_get_eui64_cb_t)(uint8_t index, eui64_t *addr); */ typedef struct { netdev_get_eui48_cb_t provider; /**< function to provide an EUI-48 */ - netdev_type_t type; /**< device type to match or `NETDEV_ANY` */ + netdev_type_t type; /**< device type to match */ uint8_t index; /**< device index to match or `NETDEV_INDEX_ANY` */ } eui48_conf_t; @@ -141,7 +144,7 @@ typedef struct { */ typedef struct { netdev_get_eui64_cb_t provider; /**< function to provide an EUI-64 */ - netdev_type_t type; /**< device type to match or `NETDEV_ANY` */ + netdev_type_t type; /**< device type to match */ uint8_t index; /**< device index to match or `NETDEV_INDEX_ANY` */ } eui64_conf_t; diff --git a/sys/net/link_layer/eui_provider/eui_provider.c b/sys/net/link_layer/eui_provider/eui_provider.c index 54e348ff11..95c5446ada 100644 --- a/sys/net/link_layer/eui_provider/eui_provider.c +++ b/sys/net/link_layer/eui_provider/eui_provider.c @@ -13,6 +13,7 @@ * @author Benjamin Valentin */ +#include "assert.h" #include "eui48_provider_params.h" #include "eui64_provider_params.h" #include "luid.h" @@ -23,8 +24,13 @@ void netdev_eui48_get(netdev_t *netdev, eui48_t *addr) unsigned i = EUI48_PROVIDER_NUMOF; while (i--) { #ifdef MODULE_NETDEV_REGISTER - if (eui48_conf[i].type != netdev->type && - eui48_conf[i].type != NETDEV_ANY) { + /* using NETDEV_ANY causes conflicts if there is another interface + * of a different type. Require EUI providers to be locked to an + * interface type for uniqueness. + */ + assert(eui48_conf[i].type != NETDEV_ANY); + + if (eui48_conf[i].type != netdev->type) { continue; } @@ -48,8 +54,13 @@ void netdev_eui64_get(netdev_t *netdev, eui64_t *addr) unsigned i = EUI64_PROVIDER_NUMOF; while (i--) { #ifdef MODULE_NETDEV_REGISTER - if (eui64_conf[i].type != netdev->type && - eui64_conf[i].type != NETDEV_ANY) { + /* using NETDEV_ANY causes conflicts if there is another interface + * of a different type. Require EUI providers to be locked to an + * interface type for uniqueness. + */ + assert(eui64_conf[i].type != NETDEV_ANY); + + if (eui64_conf[i].type != netdev->type) { continue; }