net: if: check for multicast address already registered

Add a check to stop a multicast address to be registered multiple times.
This can happen if the application is using net_if_ipv6_maddr_add()
directly.

Tested on the existing bluetooth/ipsp sample:

<wrn> net_if: Multicast address ff02::1 is is already registered.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
This commit is contained in:
Fabio Baltieri 2021-01-11 23:25:28 +00:00 committed by Johan Hedberg
commit 4a4c63519d
2 changed files with 15 additions and 0 deletions

View file

@ -1672,6 +1672,12 @@ struct net_if_mcast_addr *net_if_ipv6_maddr_add(struct net_if *iface,
return NULL;
}
if (net_if_ipv6_maddr_lookup(addr, &iface)) {
NET_WARN("Multicast address %s is is already registered.",
log_strdup(net_sprint_ipv6_addr(addr)));
return NULL;
}
for (i = 0; i < NET_IF_MAX_IPV6_MADDR; i++) {
if (ipv6->mcast[i].is_used) {
continue;