Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS local lookups using mDNS repaired #1118

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 0 additions & 11 deletions source/FreeRTOS_DNS.c
Expand Up @@ -1249,17 +1249,6 @@
/* Make sure all fields of the 'sockaddr' are cleared. */
( void ) memset( ( void * ) &xAddress, 0, sizeof( xAddress ) );

#if ( ipconfigUSE_IPv6 != 0 )
moninom1 marked this conversation as resolved.
Show resolved Hide resolved
if( xFamily == ( BaseType_t ) FREERTOS_AF_INET6 )
{
xDNS_IP_Preference = xPreferenceIPv6;
}
else
{
xDNS_IP_Preference = xPreferenceIPv4;
}
#endif /* ( ipconfigUSE_IPv6 != 0 ) */

pxEndPoint = prvFillSockAddress( &xAddress, pcHostName );

if( pxEndPoint != NULL )
Expand Down
53 changes: 40 additions & 13 deletions source/FreeRTOS_DNS_Parser.c
Expand Up @@ -295,21 +295,52 @@
{
size_t uxBytesRead = 0U;
size_t uxResult;
BaseType_t xIsResponse = pdFALSE;

/* Start at the first byte after the header. */
xSet.pucUDPPayloadBuffer = pucUDPPayloadBuffer;
/* Skip 12-byte header. */
xSet.pucByte = &( pucUDPPayloadBuffer[ sizeof( DNSMessage_t ) ] );
xSet.uxSourceBytesRemaining -= sizeof( DNSMessage_t );

/* Skip any question records. */
/* The number of questions supplied. */
xSet.usQuestions = FreeRTOS_ntohs( xSet.pxDNSMessageHeader->usQuestions );
/* The number of answer records. */
xSet.usAnswers = FreeRTOS_ntohs( xSet.pxDNSMessageHeader->usAnswers );

if( xSet.usQuestions == 0U )
if( ( xSet.pxDNSMessageHeader->usFlags & dnsRX_FLAGS_MASK ) == dnsEXPECTED_RX_FLAGS )
{
/* The IP-stack will only accept DNS replies that have a copy
* of the questions. */
xReturn = pdFALSE;
break;
xIsResponse = pdTRUE;

if( xSet.usAnswers == 0U )
{
/* This is a reponse that does not include answers. */
xReturn = pdFALSE;
break;
}

if( xSet.usQuestions == 0U )
{
#if ( ( ipconfigUSE_LLMNR == 1 ) || ( ipconfigUSE_MDNS == 1 ) )
{
xSet.pcRequestedName = ( char * ) xSet.pucByte;
}
#endif

#if ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 )
uxResult = DNS_ReadNameField( &xSet,
sizeof( xSet.pcName ) );
#endif
}
}
else
{
if( xSet.usQuestions == 0U )
{
/* This is a query that does not include any question. */
xReturn = pdFALSE;
break;
}
}

for( x = 0U; x < xSet.usQuestions; x++ )
Expand Down Expand Up @@ -376,13 +407,9 @@
break;
}

/* Search through the answer records. */
xSet.pxDNSMessageHeader->usAnswers =
FreeRTOS_ntohs( xSet.pxDNSMessageHeader->usAnswers );

if( ( xSet.pxDNSMessageHeader->usFlags & dnsRX_FLAGS_MASK )
== dnsEXPECTED_RX_FLAGS )
if( xIsResponse == pdTRUE )
{
/* Search through the answer records. */
ulIPAddress = parseDNSAnswer( &( xSet ), ppxAddressInfo, &uxBytesRead );
}

Expand Down Expand Up @@ -608,7 +635,7 @@

struct freertos_addrinfo * pxNewAddress = NULL;

for( x = 0U; x < pxSet->pxDNSMessageHeader->usAnswers; x++ )
for( x = 0U; x < pxSet->usAnswers; x++ )
{
BaseType_t xDoAccept = pdFALSE;

Expand Down
1 change: 1 addition & 0 deletions source/include/FreeRTOS_DNS_Globals.h
Expand Up @@ -172,6 +172,7 @@
{
DNSMessage_t * pxDNSMessageHeader; /**< A pointer to the UDP payload buffer where the DNS message is stored. */
uint16_t usQuestions; /**< The number of DNS questions that were asked. */
uint16_t usAnswers; /**< The number of DNS answers that were given. */
uint8_t * pucUDPPayloadBuffer; /**< A pointer to the original UDP load buffer. */
uint8_t * pucByte; /**< A pointer that is used while parsing. */
size_t uxBufferLength; /**< The total number of bytes received in the UDP payload. */
Expand Down