Skip to content

Commit 24b49f4

Browse files
committed
net: if: Add locking
Add locking when accessing network interface. Fixes zephyrproject-rtos#33374 Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 59a51f0 commit 24b49f4

File tree

2 files changed

+654
-192
lines changed

2 files changed

+654
-192
lines changed

include/net/net_if.h

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,30 @@ static inline void net_if_stop_rs(struct net_if *iface)
709709
}
710710
#endif /* CONFIG_NET_IPV6_ND */
711711

712+
/** @cond INTERNAL_HIDDEN */
713+
714+
static inline int net_if_set_link_addr_unlocked(struct net_if *iface,
715+
uint8_t *addr, uint8_t len,
716+
enum net_link_type type)
717+
{
718+
if (net_if_flag_is_set(iface, NET_IF_UP)) {
719+
return -EPERM;
720+
}
721+
722+
net_if_get_link_addr(iface)->addr = addr;
723+
net_if_get_link_addr(iface)->len = len;
724+
net_if_get_link_addr(iface)->type = type;
725+
726+
net_hostname_set_postfix(addr, len);
727+
728+
return 0;
729+
}
730+
731+
int net_if_set_link_addr_locked(struct net_if *iface,
732+
uint8_t *addr, uint8_t len,
733+
enum net_link_type type);
734+
/** @endcond */
735+
712736
/**
713737
* @brief Set a network interface's link address
714738
*
@@ -724,17 +748,11 @@ static inline int net_if_set_link_addr(struct net_if *iface,
724748
uint8_t *addr, uint8_t len,
725749
enum net_link_type type)
726750
{
727-
if (net_if_flag_is_set(iface, NET_IF_UP)) {
728-
return -EPERM;
729-
}
730-
731-
net_if_get_link_addr(iface)->addr = addr;
732-
net_if_get_link_addr(iface)->len = len;
733-
net_if_get_link_addr(iface)->type = type;
734-
735-
net_hostname_set_postfix(addr, len);
736-
737-
return 0;
751+
#if defined(CONFIG_NET_RAW_MODE)
752+
return net_if_set_link_addr_unlocked(iface, addr, len, type);
753+
#else
754+
return net_if_set_link_addr_locked(iface, addr, len, type);
755+
#endif
738756
}
739757

740758
/**
@@ -808,12 +826,7 @@ static inline struct net_if_config *net_if_config_get(struct net_if *iface)
808826
*
809827
* @param router Pointer to existing router
810828
*/
811-
static inline void net_if_router_rm(struct net_if_router *router)
812-
{
813-
router->is_used = false;
814-
815-
/* FIXME - remove timer */
816-
}
829+
void net_if_router_rm(struct net_if_router *router);
817830

818831
/**
819832
* @brief Get the default network interface.
@@ -1061,12 +1074,7 @@ void net_if_mcast_monitor(struct net_if *iface, const struct in6_addr *addr,
10611074
*
10621075
* @param addr IPv6 multicast address
10631076
*/
1064-
static inline void net_if_ipv6_maddr_join(struct net_if_mcast_addr *addr)
1065-
{
1066-
NET_ASSERT(addr);
1067-
1068-
addr->is_joined = true;
1069-
}
1077+
void net_if_ipv6_maddr_join(struct net_if_mcast_addr *addr);
10701078

10711079
/**
10721080
* @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)
10871095
*
10881096
* @param addr IPv6 multicast address
10891097
*/
1090-
static inline void net_if_ipv6_maddr_leave(struct net_if_mcast_addr *addr)
1091-
{
1092-
NET_ASSERT(addr);
1093-
1094-
addr->is_joined = false;
1095-
}
1098+
void net_if_ipv6_maddr_leave(struct net_if_mcast_addr *addr);
10961099

10971100
/**
10981101
* @brief Return prefix that corresponds to this IPv6 address.

0 commit comments

Comments
 (0)