net: if: Add locking

Add locking when accessing network interface.

Fixes #33374

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2021-03-16 13:43:09 +02:00 committed by Jukka Rissanen
commit 24b49f4399
2 changed files with 654 additions and 192 deletions

View file

@ -709,6 +709,30 @@ static inline void net_if_stop_rs(struct net_if *iface)
} }
#endif /* CONFIG_NET_IPV6_ND */ #endif /* CONFIG_NET_IPV6_ND */
/** @cond INTERNAL_HIDDEN */
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)) {
return -EPERM;
}
net_if_get_link_addr(iface)->addr = addr;
net_if_get_link_addr(iface)->len = len;
net_if_get_link_addr(iface)->type = type;
net_hostname_set_postfix(addr, len);
return 0;
}
int net_if_set_link_addr_locked(struct net_if *iface,
uint8_t *addr, uint8_t len,
enum net_link_type type);
/** @endcond */
/** /**
* @brief Set a network interface's link address * @brief Set a network interface's link address
* *
@ -724,17 +748,11 @@ static inline int net_if_set_link_addr(struct net_if *iface,
uint8_t *addr, uint8_t len, uint8_t *addr, uint8_t len,
enum net_link_type type) enum net_link_type type)
{ {
if (net_if_flag_is_set(iface, NET_IF_UP)) { #if defined(CONFIG_NET_RAW_MODE)
return -EPERM; return net_if_set_link_addr_unlocked(iface, addr, len, type);
} #else
return net_if_set_link_addr_locked(iface, addr, len, type);
net_if_get_link_addr(iface)->addr = addr; #endif
net_if_get_link_addr(iface)->len = len;
net_if_get_link_addr(iface)->type = type;
net_hostname_set_postfix(addr, len);
return 0;
} }
/** /**
@ -808,12 +826,7 @@ static inline struct net_if_config *net_if_config_get(struct net_if *iface)
* *
* @param router Pointer to existing router * @param router Pointer to existing router
*/ */
static inline void net_if_router_rm(struct net_if_router *router) void net_if_router_rm(struct net_if_router *router);
{
router->is_used = false;
/* FIXME - remove timer */
}
/** /**
* @brief Get the default network interface. * @brief Get the default network interface.
@ -1061,12 +1074,7 @@ void net_if_mcast_monitor(struct net_if *iface, const struct in6_addr *addr,
* *
* @param addr IPv6 multicast address * @param addr IPv6 multicast address
*/ */
static inline void net_if_ipv6_maddr_join(struct net_if_mcast_addr *addr) void net_if_ipv6_maddr_join(struct net_if_mcast_addr *addr);
{
NET_ASSERT(addr);
addr->is_joined = true;
}
/** /**
* @brief Check if given multicast address is joined or not. * @brief Check if given multicast address is joined or not.
@ -1087,12 +1095,7 @@ static inline bool net_if_ipv6_maddr_is_joined(struct net_if_mcast_addr *addr)
* *
* @param addr IPv6 multicast address * @param addr IPv6 multicast address
*/ */
static inline void net_if_ipv6_maddr_leave(struct net_if_mcast_addr *addr) void net_if_ipv6_maddr_leave(struct net_if_mcast_addr *addr);
{
NET_ASSERT(addr);
addr->is_joined = false;
}
/** /**
* @brief Return prefix that corresponds to this IPv6 address. * @brief Return prefix that corresponds to this IPv6 address.

File diff suppressed because it is too large Load diff