Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions libraries/ESP8266mDNS/src/LEAmDNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include "LEAmDNS_Priv.h"
#include <LwipIntf.h>
#include <lwip/igmp.h>
#if LWIP_IPV6
#include <lwip/mld6.h>
#endif
#include <lwip/prot/dns.h>

// should be defined at build time
Expand Down Expand Up @@ -1298,9 +1301,13 @@ namespace MDNSImplementation
// Join multicast group(s)
for (netif* pNetIf = netif_list; pNetIf; pNetIf = pNetIf->next)
{
if (netif_is_up(pNetIf) && IPAddress(pNetIf->ip_addr).isSet())
if (!netif_is_up(pNetIf))
{
continue;
}
#ifdef MDNS_IP4_SUPPORT
if (IPAddress(pNetIf->ip_addr).isSet())
{
ip_addr_t multicast_addr_V4 = DNS_MQUERY_IPV4_GROUP_INIT;
if (!(pNetIf->flags & NETIF_FLAG_IGMP))
{
Expand All @@ -1326,21 +1333,22 @@ namespace MDNSImplementation
": %s) FAILED!\n"),
NETIFID_VAL(pNetIf), IPAddress(multicast_addr_V4).toString().c_str()););
}
}
#endif

#ifdef MDNS_IPV6_SUPPORT
ip_addr_t multicast_addr_V6 = DNS_MQUERY_IPV6_GROUP_INIT;
bResult
= ((bResult)
&& (ERR_OK == mld6_joingroup_netif(pNetIf, ip_2_ip6(&multicast_addr_V6))));
DEBUG_EX_ERR_IF(
!bResult,
DEBUG_OUTPUT.printf_P(
PSTR("[MDNSResponder] _createHost: mld6_joingroup_netif (" NETIFID_STR
") FAILED!\n"),
NETIFID_VAL(pNetIf)));
#endif
#if defined(MDNS_IP6_SUPPORT) || defined(MDNS_IP6_RESPONDER)
ip_addr_t multicast_addr_V6 = DNS_MQUERY_IPV6_GROUP_INIT;
if (ERR_OK == mld6_joingroup_netif(pNetIf, ip_2_ip6(&multicast_addr_V6)))
{
bResult = true;
}
else
{
DEBUG_EX_ERR(DEBUG_OUTPUT.printf_P(
PSTR("[MDNSResponder] _createHost: mld6_joingroup_netif (" NETIFID_STR
") FAILED!\n"),
NETIFID_VAL(pNetIf)););
}
#endif
}
return bResult;
}
Expand All @@ -1354,19 +1362,20 @@ namespace MDNSImplementation

for (netif* pNetIf = netif_list; pNetIf; pNetIf = pNetIf->next)
{
if (netif_is_up(pNetIf) && IPAddress(pNetIf->ip_addr).isSet())
if (netif_is_up(pNetIf))
{
bResult = true;

// Leave multicast group(s)
#ifdef MDNS_IP4_SUPPORT
ip_addr_t multicast_addr_V4 = DNS_MQUERY_IPV4_GROUP_INIT;
if (ERR_OK != igmp_leavegroup_netif(pNetIf, ip_2_ip4(&multicast_addr_V4)))
if ((IPAddress(pNetIf->ip_addr).isSet())
&& (ERR_OK != igmp_leavegroup_netif(pNetIf, ip_2_ip4(&multicast_addr_V4))))
{
DEBUG_EX_ERR(DEBUG_OUTPUT.printf_P(PSTR("\n")););
}
#endif
#ifdef MDNS_IPV6_SUPPORT
#if defined(MDNS_IP6_SUPPORT) || defined(MDNS_IP6_RESPONDER)
ip_addr_t multicast_addr_V6 = DNS_MQUERY_IPV6_GROUP_INIT;
if (ERR_OK
!= mld6_leavegroup_netif(
Expand Down
18 changes: 13 additions & 5 deletions libraries/ESP8266mDNS/src/LEAmDNS.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ namespace MDNSImplementation
#define MDNS_IP4_SUPPORT
#if LWIP_IPV6
//#define MDNS_IP6_SUPPORT
// Answer AAAA questions and announce the IPv6 addresses (over the IPv4 transport)
#define MDNS_IP6_RESPONDER
#endif

#ifdef MDNS_IP4_SUPPORT
#define MDNS_IP4_SIZE 4
#endif
#ifdef MDNS_IP6_SUPPORT
#if defined(MDNS_IP6_SUPPORT) || defined(MDNS_IP6_RESPONDER)
#define MDNS_IP6_SIZE 16
#endif
/*
Expand Down Expand Up @@ -1173,8 +1175,11 @@ namespace MDNSImplementation
stcMDNSServiceQuery* m_pServiceQueries;
MDNSDynamicServiceTxtCallbackFunc m_fnServiceTxtCallback;
stcProbeInformation m_HostProbeInformation;
bool m_bLwipCb;
bool m_bRestarting;
#ifdef MDNS_IP6_RESPONDER
uint8_t m_u8IP6AddressCount = 0; // re-announce when it changes (SLAAC comes after DHCP)
#endif
bool m_bLwipCb;
bool m_bRestarting;

/** CONTROL **/
/* MAINTENANCE */
Expand Down Expand Up @@ -1220,7 +1225,7 @@ namespace MDNSImplementation
/* SENDING */
bool _sendMDNSMessage(stcMDNSSendParameter& p_SendParameter);
bool _sendMDNSMessage_Multicast(MDNSResponder::stcMDNSSendParameter& p_rSendParameter);
bool _prepareMDNSMessage(stcMDNSSendParameter& p_SendParameter, IPAddress p_IPAddress);
bool _prepareMDNSMessage(stcMDNSSendParameter& p_SendParameter, const netif* p_pNetIf);
bool _sendMDNSServiceQuery(const stcMDNSServiceQuery& p_ServiceQuery);
bool _sendMDNSQuery(const stcMDNS_RRDomain& p_QueryDomain, uint16_t p_u16QueryType,
stcMDNSServiceQuery::stcAnswer* p_pKnownAnswers = 0);
Expand Down Expand Up @@ -1316,8 +1321,11 @@ namespace MDNSImplementation
stcMDNSSendParameter& p_rSendParameter);
bool _writeMDNSAnswer_TXT(stcMDNSService& p_rService,
stcMDNSSendParameter& p_rSendParameter);
#if defined(MDNS_IP6_SUPPORT) || defined(MDNS_IP6_RESPONDER)
static uint8_t _ip6AddressCount(const netif* p_pNetIf);
bool _writeMDNSAnswer_AAAA(const netif* p_pNetIf, stcMDNSSendParameter& p_rSendParameter);
#endif
#ifdef MDNS_IP6_SUPPORT
bool _writeMDNSAnswer_AAAA(IPAddress p_IPAddress, stcMDNSSendParameter& p_rSendParameter);
bool _writeMDNSAnswer_PTR_IP6(IPAddress p_IPAddress,
stcMDNSSendParameter& p_rSendParameter);
#endif
Expand Down
15 changes: 14 additions & 1 deletion libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ namespace MDNSImplementation
{
bResult = _updateProbeStatus() && // Probing
_checkServiceQueryCache(); // Service query cache check
#ifdef MDNS_IP6_RESPONDER
// IP6 addresses (SLAAC) usually come after the IP4 one, announce them once they do
const uint8_t u8IP6Count = _ip6AddressCount(0);
if ((ProbingStatus_Done == m_HostProbeInformation.m_ProbingStatus)
&& (u8IP6Count != m_u8IP6AddressCount))
{
m_u8IP6AddressCount = u8IP6Count;
_announce(true, true); // Services too, in an IP6 only net nothing went out yet
}
#endif
}
return bResult;
}
Expand Down Expand Up @@ -1778,6 +1788,9 @@ namespace MDNSImplementation
sendParameter.m_u8HostReplyMask |= ContentFlag_A; // A answer
sendParameter.m_u8HostReplyMask |= ContentFlag_PTR_IP4; // PTR_IP4 answer
#endif
#ifdef MDNS_IP6_RESPONDER
sendParameter.m_u8HostReplyMask |= ContentFlag_AAAA; // AAAA answer
#endif
#ifdef MDNS_IP6_SUPPORT
sendParameter.m_u8HostReplyMask |= ContentFlag_AAAA; // AAAA answer
sendParameter.m_u8HostReplyMask |= ContentFlag_PTR_IP6; // PTR_IP6 answer
Expand Down Expand Up @@ -2258,7 +2271,7 @@ namespace MDNSImplementation
u8ReplyMask |= ContentFlag_A;
}
#endif
#ifdef MDNS_IP6_SUPPORT
#if defined(MDNS_IP6_SUPPORT) || defined(MDNS_IP6_RESPONDER)
if ((DNS_RRTYPE_AAAA == p_RRHeader.m_Attributes.m_u16Type)
|| (DNS_RRTYPE_ANY == p_RRHeader.m_Attributes.m_u16Type))
{
Expand Down
4 changes: 4 additions & 0 deletions libraries/ESP8266mDNS/src/LEAmDNS_Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ namespace MDNSImplementation
m_pUDPContext = new UdpContext;
m_pUDPContext->ref();

#ifdef MDNS_IP6_RESPONDER
if (m_pUDPContext->listen(IP_ANY_TYPE, DNS_MQUERY_PORT)) // IP4 and IP6
#else
if (m_pUDPContext->listen(IP4_ADDR_ANY, DNS_MQUERY_PORT))
#endif
{
m_pUDPContext->setMulticastTTL(MDNS_MULTICAST_TTL);
m_pUDPContext->onRx(std::bind(&MDNSResponder::_callProcess, this));
Expand Down
Loading