net: iface: Improve thread safety of net_if_ipv*_maddr_* functions
Provide an extra struct net_if * iface parameter to net_if_ipv*_maddr_join/leave functions, so that the corresponding interface context, the mcast address belong to, can be locked for the operation. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
parent
45cb3f9813
commit
ff0fd2d7a7
@ -140,6 +140,14 @@ Changes in this release
|
||||
using picolibc, only applications using picolibc will be affected by this
|
||||
change at this time.
|
||||
|
||||
* The following network interface APIs now take additional,
|
||||
``struct net_if * iface`` parameter:
|
||||
|
||||
* :c:func:`net_if_ipv4_maddr_join`
|
||||
* :c:func:`net_if_ipv4_maddr_leave`
|
||||
* :c:func:`net_if_ipv6_maddr_join`
|
||||
* :c:func:`net_if_ipv6_maddr_leave`
|
||||
|
||||
Removed APIs in this release
|
||||
============================
|
||||
|
||||
|
||||
@ -1265,9 +1265,11 @@ void net_if_mcast_monitor(struct net_if *iface, const struct net_addr *addr,
|
||||
/**
|
||||
* @brief Mark a given multicast address to be joined.
|
||||
*
|
||||
* @param iface Network interface the address belongs to
|
||||
* @param addr IPv6 multicast address
|
||||
*/
|
||||
void net_if_ipv6_maddr_join(struct net_if_mcast_addr *addr);
|
||||
void net_if_ipv6_maddr_join(struct net_if *iface,
|
||||
struct net_if_mcast_addr *addr);
|
||||
|
||||
/**
|
||||
* @brief Check if given multicast address is joined or not.
|
||||
@ -1286,9 +1288,11 @@ static inline bool net_if_ipv6_maddr_is_joined(struct net_if_mcast_addr *addr)
|
||||
/**
|
||||
* @brief Mark a given multicast address to be left.
|
||||
*
|
||||
* @param iface Network interface the address belongs to
|
||||
* @param addr IPv6 multicast address
|
||||
*/
|
||||
void net_if_ipv6_maddr_leave(struct net_if_mcast_addr *addr);
|
||||
void net_if_ipv6_maddr_leave(struct net_if *iface,
|
||||
struct net_if_mcast_addr *addr);
|
||||
|
||||
/**
|
||||
* @brief Return prefix that corresponds to this IPv6 address.
|
||||
@ -1819,9 +1823,11 @@ struct net_if_mcast_addr *net_if_ipv4_maddr_lookup(const struct in_addr *addr,
|
||||
/**
|
||||
* @brief Mark a given multicast address to be joined.
|
||||
*
|
||||
* @param iface Network interface the address belongs to
|
||||
* @param addr IPv4 multicast address
|
||||
*/
|
||||
void net_if_ipv4_maddr_join(struct net_if_mcast_addr *addr);
|
||||
void net_if_ipv4_maddr_join(struct net_if *iface,
|
||||
struct net_if_mcast_addr *addr);
|
||||
|
||||
/**
|
||||
* @brief Check if given multicast address is joined or not.
|
||||
@ -1840,9 +1846,11 @@ static inline bool net_if_ipv4_maddr_is_joined(struct net_if_mcast_addr *addr)
|
||||
/**
|
||||
* @brief Mark a given multicast address to be left.
|
||||
*
|
||||
* @param iface Network interface the address belongs to
|
||||
* @param addr IPv4 multicast address
|
||||
*/
|
||||
void net_if_ipv4_maddr_leave(struct net_if_mcast_addr *addr);
|
||||
void net_if_ipv4_maddr_leave(struct net_if *iface,
|
||||
struct net_if_mcast_addr *addr);
|
||||
|
||||
/**
|
||||
* @brief Get the IPv4 address of the given router
|
||||
|
||||
@ -304,7 +304,7 @@ int net_ipv4_igmp_join(struct net_if *iface, const struct in_addr *addr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
net_if_ipv4_maddr_join(maddr);
|
||||
net_if_ipv4_maddr_join(iface, maddr);
|
||||
|
||||
net_if_mcast_monitor(iface, &maddr->address, true);
|
||||
|
||||
@ -333,7 +333,7 @@ int net_ipv4_igmp_leave(struct net_if *iface, const struct in_addr *addr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
net_if_ipv4_maddr_leave(maddr);
|
||||
net_if_ipv4_maddr_leave(iface, maddr);
|
||||
|
||||
net_if_mcast_monitor(iface, &maddr->address, false);
|
||||
|
||||
@ -374,7 +374,7 @@ void net_ipv4_igmp_init(struct net_if *iface)
|
||||
}
|
||||
}
|
||||
|
||||
net_if_ipv4_maddr_join(maddr);
|
||||
net_if_ipv4_maddr_join(iface, maddr);
|
||||
|
||||
net_if_mcast_monitor(iface, &maddr->address, true);
|
||||
}
|
||||
|
||||
@ -207,7 +207,7 @@ int net_ipv6_mld_join(struct net_if *iface, const struct in6_addr *addr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
net_if_ipv6_maddr_join(maddr);
|
||||
net_if_ipv6_maddr_join(iface, maddr);
|
||||
|
||||
net_if_mcast_monitor(iface, &maddr->address, true);
|
||||
|
||||
|
||||
@ -2098,18 +2098,24 @@ out:
|
||||
return ifmaddr;
|
||||
}
|
||||
|
||||
void net_if_ipv6_maddr_leave(struct net_if_mcast_addr *addr)
|
||||
void net_if_ipv6_maddr_leave(struct net_if *iface, struct net_if_mcast_addr *addr)
|
||||
{
|
||||
NET_ASSERT(iface);
|
||||
NET_ASSERT(addr);
|
||||
|
||||
net_if_lock(iface);
|
||||
addr->is_joined = false;
|
||||
net_if_unlock(iface);
|
||||
}
|
||||
|
||||
void net_if_ipv6_maddr_join(struct net_if_mcast_addr *addr)
|
||||
void net_if_ipv6_maddr_join(struct net_if *iface, struct net_if_mcast_addr *addr)
|
||||
{
|
||||
NET_ASSERT(iface);
|
||||
NET_ASSERT(addr);
|
||||
|
||||
net_if_lock(iface);
|
||||
addr->is_joined = true;
|
||||
net_if_unlock(iface);
|
||||
}
|
||||
|
||||
static void remove_prefix_addresses(struct net_if *iface,
|
||||
@ -3874,18 +3880,24 @@ out:
|
||||
return addr;
|
||||
}
|
||||
|
||||
void net_if_ipv4_maddr_leave(struct net_if_mcast_addr *addr)
|
||||
void net_if_ipv4_maddr_leave(struct net_if *iface, struct net_if_mcast_addr *addr)
|
||||
{
|
||||
NET_ASSERT(iface);
|
||||
NET_ASSERT(addr);
|
||||
|
||||
net_if_lock(iface);
|
||||
addr->is_joined = false;
|
||||
net_if_unlock(iface);
|
||||
}
|
||||
|
||||
void net_if_ipv4_maddr_join(struct net_if_mcast_addr *addr)
|
||||
void net_if_ipv4_maddr_join(struct net_if *iface, struct net_if_mcast_addr *addr)
|
||||
{
|
||||
NET_ASSERT(iface);
|
||||
NET_ASSERT(addr);
|
||||
|
||||
net_if_lock(iface);
|
||||
addr->is_joined = true;
|
||||
net_if_unlock(iface);
|
||||
}
|
||||
|
||||
static void iface_ipv4_init(int if_count)
|
||||
|
||||
@ -273,7 +273,7 @@ void add_ipv6_maddr_to_zephyr(struct openthread_context *context)
|
||||
net_ipv6_is_addr_mcast_link_all_nodes(
|
||||
(struct in6_addr *)(&maddress->mAddress)))) {
|
||||
|
||||
net_if_ipv6_maddr_join(zmaddr);
|
||||
net_if_ipv6_maddr_join(context->iface, zmaddr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1560,7 +1560,7 @@ ZTEST(net_ipv6, test_y_dst_unjoined_group_mcast_recv)
|
||||
/* add multicast address to interface but do not join the group yet */
|
||||
maddr = net_if_ipv6_maddr_add(TEST_NET_IF, &mcast_unjoined_group);
|
||||
|
||||
net_if_ipv6_maddr_leave(maddr);
|
||||
net_if_ipv6_maddr_leave(TEST_NET_IF, maddr);
|
||||
|
||||
/* receive multicast on interface that did not join the group yet.
|
||||
* Expectation: packet should be dropped by first interface on IP
|
||||
@ -1573,7 +1573,7 @@ ZTEST(net_ipv6, test_y_dst_unjoined_group_mcast_recv)
|
||||
"dropped.");
|
||||
|
||||
/* now join the multicast group and attempt to receive again */
|
||||
net_if_ipv6_maddr_join(maddr);
|
||||
net_if_ipv6_maddr_join(TEST_NET_IF, maddr);
|
||||
verdict = recv_msg(&addr, &mcast_unjoined_group);
|
||||
|
||||
zassert_equal(verdict, NET_OK,
|
||||
@ -1593,6 +1593,7 @@ ZTEST(net_ipv6, test_dst_is_other_iface_mcast_recv)
|
||||
struct in6_addr in6_addr_any = IN6ADDR_ANY_INIT;
|
||||
struct in6_addr addr = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0x1 } } };
|
||||
struct net_if *test_iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
|
||||
struct net_if_mcast_addr *maddr;
|
||||
struct net_context *ctx;
|
||||
enum net_verdict verdict;
|
||||
@ -1604,11 +1605,9 @@ ZTEST(net_ipv6, test_dst_is_other_iface_mcast_recv)
|
||||
net_ctx_recv(ctx);
|
||||
|
||||
/* Join multicast group on second interface. */
|
||||
maddr = net_if_ipv6_maddr_add(
|
||||
net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)),
|
||||
&mcast_iface2);
|
||||
maddr = net_if_ipv6_maddr_add(test_iface, &mcast_iface2);
|
||||
zassert_not_null(maddr, "Cannot add multicast address to interface");
|
||||
net_if_ipv6_maddr_join(maddr);
|
||||
net_if_ipv6_maddr_join(test_iface, maddr);
|
||||
|
||||
/* Receive multicast on first interface that did not join the group.
|
||||
* Expectation: packet should be dropped by first interface on IP
|
||||
@ -1623,10 +1622,9 @@ ZTEST(net_ipv6, test_dst_is_other_iface_mcast_recv)
|
||||
"Packet sent to multicast group joined by second "
|
||||
"interface not dropped");
|
||||
|
||||
net_if_ipv6_maddr_leave(maddr);
|
||||
net_if_ipv6_maddr_leave(test_iface, maddr);
|
||||
|
||||
net_if_ipv6_maddr_rm(net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)),
|
||||
&mcast_iface2);
|
||||
net_if_ipv6_maddr_rm(test_iface, &mcast_iface2);
|
||||
|
||||
net_context_put(ctx);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user