net: IPv6: Fix source address for mesh multicast destination

Currently there is chosen the link local address as a source address
for each multicast destination address. It is a bug for OpenThread
network where the mesh-local EID addres should be picked in this case.
This commit fixes it by distinquish the mesh local multicast among any
others.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
This commit is contained in:
Lukasz Maciejonczyk 2020-06-16 14:55:18 +02:00 committed by Carles Cufí
commit b0de2ee15b
2 changed files with 18 additions and 3 deletions

View file

@ -930,6 +930,20 @@ static inline bool net_ipv6_is_addr_mcast_iface(const struct in6_addr *addr)
return net_ipv6_is_addr_mcast_scope(addr, 0x01);
}
/**
* @brief Check if the IPv6 address is a mesh-local scope multicast
* address (FFx3::).
*
* @param addr IPv6 address.
*
* @return True if the address is a mesh-local scope multicast address,
* false otherwise.
*/
static inline bool net_ipv6_is_addr_mcast_mesh(const struct in6_addr *addr)
{
return net_ipv6_is_addr_mcast_scope(addr, 0x03);
}
/**
* @brief Check if the IPv6 address is a site scope multicast
* address (FFx5::).

View file

@ -2347,7 +2347,8 @@ static struct in6_addr *net_if_ipv6_get_best_match(struct net_if *iface,
/* Mesh local address can only be selected for the same
* subnet.
*/
if (ipv6->unicast[i].is_mesh_local && len < 64) {
if (ipv6->unicast[i].is_mesh_local && len < 64 &&
!net_ipv6_is_addr_mcast_mesh(dst)) {
continue;
}
@ -2366,8 +2367,8 @@ const struct in6_addr *net_if_ipv6_select_src_addr(struct net_if *dst_iface,
uint8_t best_match = 0U;
struct net_if *iface;
if (!net_ipv6_is_ll_addr(dst) && !net_ipv6_is_addr_mcast(dst)) {
if (!net_ipv6_is_ll_addr(dst) && (!net_ipv6_is_addr_mcast(dst) ||
net_ipv6_is_addr_mcast_mesh(dst))) {
for (iface = __net_if_start;
!dst_iface && iface != __net_if_end;
iface++) {