diff --git a/include/net/net_if.h b/include/net/net_if.h index f0877c7755e..f4731568391 100644 --- a/include/net/net_if.h +++ b/include/net/net_if.h @@ -607,10 +607,12 @@ struct net_if_mcast_addr *net_if_ipv6_maddr_add(struct net_if *iface, bool net_if_ipv6_maddr_rm(struct net_if *iface, const struct in6_addr *addr); /** - * @brief Check if this IPv6 multicast address belongs to one of the interfaces. + * @brief Check if this IPv6 multicast address belongs to a specific interface + * or one of the interfaces. * * @param addr IPv6 address - * @param iface Pointer to interface is returned + * @param iface If *iface is null, then pointer to interface is returned, + * otherwise the *iface value needs to be matched. * * @return Pointer to interface multicast address, NULL if not found. */ diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 455c8d41774..fbce9c0b85e 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -554,6 +554,10 @@ struct net_if_mcast_addr *net_if_ipv6_maddr_lookup(const struct in6_addr *maddr, for (iface = __net_if_start; iface != __net_if_end; iface++) { int i; + if (ret && *ret && iface != *ret) { + continue; + } + for (i = 0; i < NET_IF_MAX_IPV6_MADDR; i++) { if (!iface->ipv6.mcast[i].is_used || iface->ipv6.mcast[i].address.family != AF_INET6) {