mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
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.
This commit is contained in:
parent
204b80c6bf
commit
118e08607a
@ -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;
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user