From 129f34fd0b8bf183f17552c3268a7eae39dafc32 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Fri, 9 Dec 2022 13:54:19 +0100 Subject: [PATCH] net: if: Allow to set LL address after interface was brough admin UP Bluetooth IPSP L2 sets the LL address only after establishing Bluetooth connection. As this can take place after the interface was brough UP by the application, the network interface API should not block such attempt. Instead, verify the NET_IF_RUNNING flag. For the same reason, move the assert verifying that LL address is set from net_if_up() (which only puts the interface in the admin UP state) into the function that transitions the interface into operational UP state. Signed-off-by: Robert Lubos --- include/zephyr/net/net_if.h | 2 +- subsys/net/ip/net_if.c | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/zephyr/net/net_if.h b/include/zephyr/net/net_if.h index 754ea7342bf..3b38b785571 100644 --- a/include/zephyr/net/net_if.h +++ b/include/zephyr/net/net_if.h @@ -857,7 +857,7 @@ static inline int net_if_set_link_addr_unlocked(struct net_if *iface, uint8_t *addr, uint8_t len, enum net_link_type type) { - if (net_if_flag_is_set(iface, NET_IF_UP)) { + if (net_if_flag_is_set(iface, NET_IF_RUNNING)) { return -EPERM; } diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index f8a4d2ebc59..f72b319658c 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -4035,6 +4035,21 @@ static inline bool is_iface_offloaded(struct net_if *iface) static void notify_iface_up(struct net_if *iface) { + /* In many places it's assumed that link address was set with + * net_if_set_link_addr(). Better check that now. + */ +#if defined(CONFIG_NET_L2_CANBUS_RAW) + if (IS_ENABLED(CONFIG_NET_SOCKETS_CAN) && + (net_if_l2(iface) == &NET_L2_GET_NAME(CANBUS_RAW))) { + /* CAN does not require link address. */ + } else +#endif /* CONFIG_NET_L2_CANBUS_RAW */ + { + if (!is_iface_offloaded(iface)) { + NET_ASSERT(net_if_get_link_addr(iface)->addr != NULL); + } + } + net_if_flag_set(iface, NET_IF_RUNNING); net_mgmt_event_notify(NET_EVENT_IF_UP, iface); net_virtual_enable(iface); @@ -4172,19 +4187,6 @@ int net_if_up(struct net_if *iface) goto out; } - /* In many places it's assumed that link address was set with - * net_if_set_link_addr(). Better check that now. - */ -#if defined(CONFIG_NET_L2_CANBUS_RAW) - if (IS_ENABLED(CONFIG_NET_SOCKETS_CAN) && - (net_if_l2(iface) == &NET_L2_GET_NAME(CANBUS_RAW))) { - /* CAN does not require link address. */ - } else -#endif /* CONFIG_NET_L2_CANBUS_RAW */ - { - NET_ASSERT(net_if_get_link_addr(iface)->addr != NULL); - } - done: net_if_flag_set(iface, NET_IF_UP); net_mgmt_event_notify(NET_EVENT_IF_ADMIN_UP, iface);