From c9bae5ea9bfe288b6a546bd9723893d05b0cfe93 Mon Sep 17 00:00:00 2001 From: Daniel Elstner Date: Tue, 20 Sep 2016 23:22:04 +0200 Subject: [PATCH] Fix bug #49134: Do not announce invalid IPv4 address via mDNS In a dual stack configuration it is not really feasible to wait until the IPv4 address is valid before starting the mDNS responder. If there is no DHCPv4 server in the network, the IPv4 address may never become valid, which should however not preclude IPv6 mDNS from working. --- src/apps/mdns/mdns.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 7c02c914..5bf15d8c 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -681,9 +681,11 @@ check_host(struct netif *netif, struct mdns_rr_info *rr, u8_t *reverse_v6_reply) } #endif #if LWIP_IPV4 - res = mdns_build_reverse_v4_domain(&mydomain, netif_ip4_addr(netif)); - if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain)) { - replies |= REPLY_HOST_PTR_V4; + if (!ip4_addr_isany_val(*netif_ip4_addr(netif))) { + res = mdns_build_reverse_v4_domain(&mydomain, netif_ip4_addr(netif)); + if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain)) { + replies |= REPLY_HOST_PTR_V4; + } } #endif } @@ -693,7 +695,8 @@ check_host(struct netif *netif, struct mdns_rr_info *rr, u8_t *reverse_v6_reply) if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain)) { /* TODO return NSEC if unsupported protocol requested */ #if LWIP_IPV4 - if (rr->type == DNS_RRTYPE_A || rr->type == DNS_RRTYPE_ANY) { + if (!ip4_addr_isany_val(*netif_ip4_addr(netif)) + && (rr->type == DNS_RRTYPE_A || rr->type == DNS_RRTYPE_ANY)) { replies |= REPLY_HOST_A; } #endif @@ -1497,10 +1500,14 @@ mdns_announce(struct netif *netif, const ip_addr_t *destination) memset(&announce, 0, sizeof(announce)); announce.netif = netif; announce.cache_flush = 1; - announce.host_replies = REPLY_HOST_A | REPLY_HOST_AAAA | REPLY_HOST_PTR_V4 | REPLY_HOST_PTR_V6; +#if LWIP_IPV4 + if (!ip4_addr_isany_val(*netif_ip4_addr(netif))) + announce.host_replies = REPLY_HOST_A | REPLY_HOST_PTR_V4; +#endif #if LWIP_IPV6 for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) { if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i))) { + announce.host_replies |= REPLY_HOST_AAAA | REPLY_HOST_PTR_V6; announce.host_reverse_v6_replies |= (1 << i); } }