From c161fd8dbf2d6846a9498a8523e2150dde53ed67 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 3 Jun 2021 14:32:47 +0200 Subject: [PATCH 1/3] boards/same54-xpro: lock EUI provider to ethernet interface Otherwise the provider can be used for multiple interfaces but only return a single MAC address for all of them. --- boards/same54-xpro/include/eui_provider_params.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/boards/same54-xpro/include/eui_provider_params.h b/boards/same54-xpro/include/eui_provider_params.h index fbb7471c26bb..fe28dd48827c 100644 --- a/boards/same54-xpro/include/eui_provider_params.h +++ b/boards/same54-xpro/include/eui_provider_params.h @@ -38,6 +38,9 @@ static inline int _at24mac_get_eui48(uint8_t index, eui48_t *addr) * @{ */ #define EUI48_PROVIDER_FUNC _at24mac_get_eui48 +#ifndef EUI48_PROVIDER_TYPE +#define EUI48_PROVIDER_TYPE NETDEV_SAM0_ETH +#endif /** @} */ #ifdef __cplusplus From 204b80c6bfeed710436f2cbb2d274b316c0b5953 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 3 Jun 2021 17:55:21 +0200 Subject: [PATCH 2/3] boards/native: lock EUI64 provider to ZEP interface --- boards/native/include/eui_provider_params.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/boards/native/include/eui_provider_params.h b/boards/native/include/eui_provider_params.h index 0af230a2c9a2..ecedd6c61cb1 100644 --- a/boards/native/include/eui_provider_params.h +++ b/boards/native/include/eui_provider_params.h @@ -30,7 +30,9 @@ extern "C" { * @{ */ #define EUI64_PROVIDER_FUNC native_cli_get_eui64 -#define EUI64_PROVIDER_TYPE NETDEV_ANY +#ifndef EUI64_PROVIDER_TYPE +#define EUI64_PROVIDER_TYPE NETDEV_SOCKET_ZEP +#endif #define EUI64_PROVIDER_INDEX NETDEV_INDEX_ANY /** @} */ From 118e08607ad7343f96b073e0b4f558b6d0aba7f0 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 8 Jun 2021 12:02:08 +0200 Subject: [PATCH 3/3] net/eui_provider: prohibit use of NETDEV_ANY for EUI device type The EUI provider function only gets the index of a device within it's device type. Using NETDEV_ANY with two devices of different type causes the EUI provider to be used for both (since both interfaces are index 0 of their type). To prevent this, require EUI providers to be locked to an interface type. --- sys/include/net/eui_provider.h | 15 +++++++++------ .../link_layer/eui_provider/eui_provider.c | 19 +++++++++++++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/sys/include/net/eui_provider.h b/sys/include/net/eui_provider.h index 44f46a2d9de0..a85640681553 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 54e348ff11a8..95c5446adab2 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; }