From 85911bcfc16f7a46b1718bb6aecdb2ea5aca4498 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Sat, 6 Apr 2024 19:25:59 +0300 Subject: [PATCH] net: mdns_responder: Avoid joining IPv4 mcast group if iface is down Check if the interface is down before joining IPv4 mDNS multicast group. This avoids warning later when the network packet cannot be sent. Fixes #71121 Signed-off-by: Jukka Rissanen --- subsys/net/lib/dns/mdns_responder.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/subsys/net/lib/dns/mdns_responder.c b/subsys/net/lib/dns/mdns_responder.c index 15a4c27646..893a3692d3 100644 --- a/subsys/net/lib/dns/mdns_responder.c +++ b/subsys/net/lib/dns/mdns_responder.c @@ -99,8 +99,8 @@ static void mdns_iface_event_handler(struct net_mgmt_event_callback *cb, int ret = net_ipv4_igmp_join(iface, &local_addr4.sin_addr, NULL); if (ret < 0) { - NET_DBG("Cannot add IPv4 multicast address to iface %p", - iface); + NET_DBG("Cannot add IPv4 multicast address to iface %d", + net_if_get_by_iface(iface)); } #endif /* defined(CONFIG_NET_IPV4) */ } @@ -653,10 +653,25 @@ static void iface_ipv4_cb(struct net_if *iface, void *user_data) struct in_addr *addr = user_data; int ret; + if (!net_if_is_up(iface)) { + struct net_if_mcast_addr *maddr; + + NET_DBG("Interface %d is down, not joining mcast group yet", + net_if_get_by_iface(iface)); + + maddr = net_if_ipv4_maddr_add(iface, addr); + if (!maddr) { + NET_DBG("Cannot add multicast address %s", + net_sprint_ipv4_addr(addr)); + } + + return; + } + ret = net_ipv4_igmp_join(iface, addr, NULL); if (ret < 0) { - NET_DBG("Cannot add IPv4 multicast address to iface %p", - iface); + NET_DBG("Cannot add IPv4 multicast address to iface %d", + net_if_get_by_iface(iface)); } }