net: ip: igmp: Ensure IGMP APIs work with offloaded interfaces

IGMP APIs are commonly used across the codebase to configure IPv4
multicast addresses on network interfaces. Sending IGMP reports however
works only for native interfaces as it uses low-level APIs. Therefore,
in order to make the APIs at least semi-functional for offloaded
interfaces as well (i.e. allow to configure multicast address on
the interface), return early in case interface is offloaded.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2025-05-07 15:34:08 +02:00 committed by Benjamin Cabé
commit e0a1e910ac

View file

@ -584,7 +584,7 @@ int net_ipv4_igmp_join(struct net_if *iface, const struct in_addr *addr,
const struct igmp_param *param)
{
struct net_if_mcast_addr *maddr;
int ret;
int ret = 0;
#if defined(CONFIG_NET_IPV4_IGMPV3)
if (param != NULL) {
@ -622,6 +622,10 @@ int net_ipv4_igmp_join(struct net_if *iface, const struct in_addr *addr,
net_if_ipv4_maddr_join(iface, maddr);
if (net_if_is_offloaded(iface)) {
goto out;
}
#if defined(CONFIG_NET_IPV4_IGMPV3)
ret = igmpv3_send_generic(iface, maddr);
#else
@ -640,6 +644,7 @@ int net_ipv4_igmp_join(struct net_if *iface, const struct in_addr *addr,
}
#endif
out:
net_if_mcast_monitor(iface, &maddr->address, true);
net_mgmt_event_notify_with_info(NET_EVENT_IPV4_MCAST_JOIN, iface, &maddr->address.in_addr,
@ -651,13 +656,17 @@ int net_ipv4_igmp_join(struct net_if *iface, const struct in_addr *addr,
int net_ipv4_igmp_leave(struct net_if *iface, const struct in_addr *addr)
{
struct net_if_mcast_addr *maddr;
int ret;
int ret = 0;
maddr = net_if_ipv4_maddr_lookup(addr, &iface);
if (!maddr) {
return -ENOENT;
}
if (net_if_is_offloaded(iface)) {
goto out;
}
#if defined(CONFIG_NET_IPV4_IGMPV3)
maddr->record_type = IGMPV3_CHANGE_TO_INCLUDE_MODE;
maddr->sources_len = 0;
@ -670,6 +679,7 @@ int net_ipv4_igmp_leave(struct net_if *iface, const struct in_addr *addr)
return ret;
}
out:
if (!net_if_ipv4_maddr_rm(iface, addr)) {
return -EINVAL;
}