1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-24 19:42:27 +03:00

MDNS MultiInterface (#7636)

* MDNS MultiInterface
* Move strlcat & strlcpy to __cplusplus
* Add LwipIntfCB.cpp to Makefile
This commit is contained in:
hreintke
2020-10-15 19:39:55 +02:00
committed by GitHub
parent 1c624dd76a
commit 9003b02889
8 changed files with 189 additions and 177 deletions

View File

@ -85,10 +85,8 @@ bool MDNSResponder::_process(bool p_bUserContext)
}
else
{
bResult = (m_netif != nullptr) &&
(m_netif->flags & NETIF_FLAG_UP) && // network interface is up and running
_updateProbeStatus() && // Probing
_checkServiceQueryCache(); // Service query cache check
bResult = _updateProbeStatus() && // Probing
_checkServiceQueryCache(); // Service query cache check
}
return bResult;
}
@ -99,13 +97,10 @@ bool MDNSResponder::_process(bool p_bUserContext)
bool MDNSResponder::_restart(void)
{
return ((m_netif != nullptr) &&
(m_netif->flags & NETIF_FLAG_UP) && // network interface is up and running
(_resetProbeStatus(true)) && // Stop and restart probing
return ((_resetProbeStatus(true)) && // Stop and restart probing
(_allocUDPContext())); // Restart UDP
}
/**
RECEIVING
*/
@ -192,8 +187,7 @@ bool MDNSResponder::_parseQuery(const MDNSResponder::stcMDNS_MsgHeader& p_MsgHea
{
// Define host replies, BUT only answer queries after probing is done
u8HostOrServiceReplies =
sendParameter.m_u8HostReplyMask |= (((m_bPassivModeEnabled) ||
(ProbingStatus_Done == m_HostProbeInformation.m_ProbingStatus))
sendParameter.m_u8HostReplyMask |= (((ProbingStatus_Done == m_HostProbeInformation.m_ProbingStatus))
? _replyMaskForHost(questionRR.m_Header, 0)
: 0);
DEBUG_EX_INFO(if (u8HostOrServiceReplies)
@ -222,8 +216,7 @@ bool MDNSResponder::_parseQuery(const MDNSResponder::stcMDNS_MsgHeader& p_MsgHea
for (stcMDNSService* pService = m_pServices; pService; pService = pService->m_pNext)
{
// Define service replies, BUT only answer queries after probing is done
uint8_t u8ReplyMaskForQuestion = (((m_bPassivModeEnabled) ||
(ProbingStatus_Done == pService->m_ProbeInformation.m_ProbingStatus))
uint8_t u8ReplyMaskForQuestion = (((ProbingStatus_Done == pService->m_ProbeInformation.m_ProbingStatus))
? _replyMaskForService(questionRR.m_Header, *pService, 0)
: 0);
u8HostOrServiceReplies |= (pService->m_u8ReplyMask |= u8ReplyMaskForQuestion);
@ -364,9 +357,8 @@ bool MDNSResponder::_parseQuery(const MDNSResponder::stcMDNS_MsgHeader& p_MsgHea
// IP4 address was asked for
#ifdef MDNS_IP4_SUPPORT
if ((AnswerType_A == pKnownRRAnswer->answerType()) &&
(((stcMDNS_RRAnswerA*)pKnownRRAnswer)->m_IPAddress == _getResponseMulticastInterface()))
(((stcMDNS_RRAnswerA*)pKnownRRAnswer)->m_IPAddress == m_pUDPContext->getInputNetif()->ip_addr))
{
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _parseQuery: IP4 address already known... skipping!\n")););
sendParameter.m_u8HostReplyMask &= ~ContentFlag_A;
} // else: RData NOT IP4 length !!
@ -399,7 +391,8 @@ bool MDNSResponder::_parseQuery(const MDNSResponder::stcMDNS_MsgHeader& p_MsgHea
#ifdef MDNS_IP4_SUPPORT
if (AnswerType_A == pKnownRRAnswer->answerType())
{
IPAddress localIPAddress(_getResponseMulticastInterface());
IPAddress localIPAddress(m_pUDPContext->getInputNetif()->ip_addr);
if (((stcMDNS_RRAnswerA*)pKnownRRAnswer)->m_IPAddress == localIPAddress)
{
// SAME IP address -> We've received an old message from ourselfs (same IP)
@ -1221,9 +1214,7 @@ bool MDNSResponder::_updateProbeStatus(void)
//
// Probe host domain
if ((ProbingStatus_ReadyToStart == m_HostProbeInformation.m_ProbingStatus) && // Ready to get started AND
//TODO: Fix the following to allow Ethernet shield or other interfaces
(_getResponseMulticastInterface() != IPAddress())) // Has IP address
if (ProbingStatus_ReadyToStart == m_HostProbeInformation.m_ProbingStatus)
{
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _updateProbeStatus: Starting host probing...\n")););
@ -2007,11 +1998,17 @@ uint8_t MDNSResponder::_replyMaskForHost(const MDNSResponder::stcMDNS_RRHeader&
// PTR request
#ifdef MDNS_IP4_SUPPORT
stcMDNS_RRDomain reverseIP4Domain;
if ((_buildDomainForReverseIP4(_getResponseMulticastInterface(), reverseIP4Domain)) &&
(p_RRHeader.m_Domain == reverseIP4Domain))
for (netif* pNetIf = netif_list; pNetIf; pNetIf = pNetIf->next)
{
// Reverse domain match
u8ReplyMask |= ContentFlag_PTR_IP4;
if (netif_is_up(pNetIf))
{
if ((_buildDomainForReverseIP4(pNetIf->ip_addr, reverseIP4Domain)) &&
(p_RRHeader.m_Domain == reverseIP4Domain))
{
// Reverse domain match
u8ReplyMask |= ContentFlag_PTR_IP4;
}
}
}
#endif
#ifdef MDNS_IP6_SUPPORT