-
Notifications
You must be signed in to change notification settings - Fork 166
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
Add macro checks for DNS Cache to fix build issue #1200
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ BLXNS | |
bmcr | ||
BMSR | ||
BPDG | ||
BPIALL | ||
brgintclr | ||
brginten | ||
brgintstat | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,110 +56,114 @@ | |
* | ||
* @return If a fully formed name was found, then return the number of bytes processed in pucByte. | ||
*/ | ||
size_t DNS_ReadNameField( ParseSet_t * pxSet, | ||
size_t uxDestLen ) | ||
{ | ||
size_t uxNameLen = 0U; | ||
size_t uxIndex = 0U; | ||
size_t uxSourceLen = pxSet->uxSourceBytesRemaining; | ||
const uint8_t * pucByte = pxSet->pucByte; | ||
|
||
/* uxCount gets the values from pucByte and counts down to 0. | ||
* No need to have a different type than that of pucByte */ | ||
size_t uxCount; | ||
#if ( ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) ) | ||
|
||
if( uxSourceLen == ( size_t ) 0U ) | ||
size_t DNS_ReadNameField( ParseSet_t * pxSet, | ||
size_t uxDestLen ) | ||
{ | ||
/* Return 0 value in case of error. */ | ||
uxIndex = 0U; | ||
} | ||
size_t uxNameLen = 0U; | ||
size_t uxIndex = 0U; | ||
size_t uxSourceLen = pxSet->uxSourceBytesRemaining; | ||
const uint8_t * pucByte = pxSet->pucByte; | ||
|
||
/* Determine if the name is the fully coded name, or an offset to the name | ||
* elsewhere in the message. */ | ||
else if( ( pucByte[ uxIndex ] & dnsNAME_IS_OFFSET ) == dnsNAME_IS_OFFSET ) | ||
{ | ||
/* Jump over the two byte offset. */ | ||
if( uxSourceLen > sizeof( uint16_t ) ) | ||
{ | ||
uxIndex += sizeof( uint16_t ); | ||
} | ||
else | ||
/* uxCount gets the values from pucByte and counts down to 0. | ||
* No need to have a different type than that of pucByte */ | ||
size_t uxCount; | ||
|
||
if( uxSourceLen == ( size_t ) 0U ) | ||
{ | ||
/* Return 0 value in case of error. */ | ||
uxIndex = 0U; | ||
} | ||
} | ||
else | ||
{ | ||
/* 'uxIndex' points to the full name. Walk over the string. */ | ||
while( ( uxIndex < uxSourceLen ) && ( pucByte[ uxIndex ] != ( uint8_t ) 0x00U ) ) | ||
{ | ||
/* If this is not the first time through the loop, then add a | ||
* separator in the output. */ | ||
if( ( uxNameLen > 0U ) ) | ||
{ | ||
/* | ||
* uxNameLen can never be greater than uxDestLen, since there are checks | ||
* outside this condition, so the check is removed. | ||
*/ | ||
pxSet->pcName[ uxNameLen ] = '.'; | ||
uxNameLen++; | ||
} | ||
|
||
/* Process the first/next sub-string. */ | ||
uxCount = ( size_t ) pucByte[ uxIndex ]; | ||
|
||
/* uxIndex should point to the first character now, unless uxCount | ||
* is an offset field. */ | ||
uxIndex++; | ||
|
||
if( ( uxIndex + uxCount ) > uxSourceLen ) | ||
/* Determine if the name is the fully coded name, or an offset to the name | ||
* elsewhere in the message. */ | ||
else if( ( pucByte[ uxIndex ] & dnsNAME_IS_OFFSET ) == dnsNAME_IS_OFFSET ) | ||
{ | ||
/* Jump over the two byte offset. */ | ||
if( uxSourceLen > sizeof( uint16_t ) ) | ||
{ | ||
uxIndex = 0U; | ||
break; | ||
uxIndex += sizeof( uint16_t ); | ||
} | ||
|
||
if( ( uxNameLen + uxCount ) >= uxDestLen ) | ||
else | ||
{ | ||
uxIndex = 0U; | ||
break; | ||
} | ||
|
||
while( uxCount-- != 0U ) | ||
{ | ||
/* | ||
* uxNameLen can never be greater than uxDestLen, since there are checks | ||
* outside this condition, so the check is removed. | ||
*/ | ||
pxSet->pcName[ uxNameLen ] = ( char ) pucByte[ uxIndex ]; | ||
uxNameLen++; | ||
uxIndex++; | ||
} | ||
} | ||
|
||
/* Confirm that a fully formed name was found. */ | ||
if( uxIndex > 0U ) | ||
else | ||
{ | ||
/* Here, there is no need to check for pucByte[ uxindex ] == 0 because: | ||
* When we break out of the above while loop, uxIndex is made 0 thereby | ||
* failing above check. Whenever we exit the loop otherwise, either | ||
* pucByte[ uxIndex ] == 0 (which makes the check here unnecessary) or | ||
* uxIndex >= uxSourceLen (which makes sure that we do not go in the 'if' | ||
* case). | ||
*/ | ||
if( uxIndex < uxSourceLen ) | ||
/* 'uxIndex' points to the full name. Walk over the string. */ | ||
while( ( uxIndex < uxSourceLen ) && ( pucByte[ uxIndex ] != ( uint8_t ) 0x00U ) ) | ||
{ | ||
pxSet->pcName[ uxNameLen ] = '\0'; | ||
/* If this is not the first time through the loop, then add a | ||
* separator in the output. */ | ||
if( ( uxNameLen > 0U ) ) | ||
{ | ||
/* | ||
* uxNameLen can never be greater than uxDestLen, since there are checks | ||
* outside this condition, so the check is removed. | ||
*/ | ||
pxSet->pcName[ uxNameLen ] = '.'; | ||
uxNameLen++; | ||
} | ||
|
||
/* Process the first/next sub-string. */ | ||
uxCount = ( size_t ) pucByte[ uxIndex ]; | ||
|
||
/* uxIndex should point to the first character now, unless uxCount | ||
* is an offset field. */ | ||
uxIndex++; | ||
|
||
if( ( uxIndex + uxCount ) > uxSourceLen ) | ||
{ | ||
uxIndex = 0U; | ||
break; | ||
} | ||
|
||
if( ( uxNameLen + uxCount ) >= uxDestLen ) | ||
{ | ||
uxIndex = 0U; | ||
break; | ||
} | ||
|
||
while( uxCount-- != 0U ) | ||
{ | ||
/* | ||
* uxNameLen can never be greater than uxDestLen, since there are checks | ||
* outside this condition, so the check is removed. | ||
*/ | ||
pxSet->pcName[ uxNameLen ] = ( char ) pucByte[ uxIndex ]; | ||
uxNameLen++; | ||
uxIndex++; | ||
} | ||
} | ||
else | ||
|
||
/* Confirm that a fully formed name was found. */ | ||
if( uxIndex > 0U ) | ||
{ | ||
uxIndex = 0U; | ||
/* Here, there is no need to check for pucByte[ uxindex ] == 0 because: | ||
* When we break out of the above while loop, uxIndex is made 0 thereby | ||
* failing above check. Whenever we exit the loop otherwise, either | ||
* pucByte[ uxIndex ] == 0 (which makes the check here unnecessary) or | ||
* uxIndex >= uxSourceLen (which makes sure that we do not go in the 'if' | ||
* case). | ||
*/ | ||
if( uxIndex < uxSourceLen ) | ||
{ | ||
pxSet->pcName[ uxNameLen ] = '\0'; | ||
uxIndex++; | ||
} | ||
else | ||
{ | ||
uxIndex = 0U; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return uxIndex; | ||
} | ||
return uxIndex; | ||
} | ||
#endif /* ( ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) ) */ | ||
|
||
/** | ||
* @brief Simple routine that jumps over the NAME field of a resource record. | ||
|
@@ -456,19 +460,23 @@ | |
#if ( ipconfigUSE_IPv6 != 0 ) | ||
{ | ||
/*logging*/ | ||
FreeRTOS_printf( ( "prvParseDNS_HandleLLMNRRequest[%s]: type %04X\n", xSet.pcName, xSet.usType ) ); | ||
#if ( ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) ) | ||
FreeRTOS_printf( ( "prvParseDNS_HandleLLMNRRequest[%s]: type %04X\n", xSet.pcName, xSet.usType ) ); | ||
#endif /* ( ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) ) */ | ||
|
||
xEndPoint.usDNSType = ( uint8_t ) xSet.usType; | ||
} | ||
#endif /* ( ipconfigUSE_IPv6 != 0 ) */ | ||
|
||
/* If this is not a reply to our DNS request, it might be an mDNS or an LLMNR | ||
* request. Ask the application if it uses the name. */ | ||
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) | ||
xDNSHookReturn = xApplicationDNSQueryHook( xSet.pcName ); | ||
#else | ||
xDNSHookReturn = xApplicationDNSQueryHook_Multi( &xEndPoint, xSet.pcName ); | ||
#endif | ||
#if ( ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) ) | ||
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) | ||
xDNSHookReturn = xApplicationDNSQueryHook( xSet.pcName ); | ||
#else | ||
xDNSHookReturn = xApplicationDNSQueryHook_Multi( &xEndPoint, xSet.pcName ); | ||
#endif /* ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) */ | ||
#endif /* ( ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) ) */ | ||
|
||
/* During the early stages of boot or after a DHCP lease expires, our end-point | ||
* may have an IP address of 0.0.0.0. Do not respond to name queries with that address. */ | ||
|
@@ -735,10 +743,12 @@ | |
&( pxSet->pucByte[ sizeof( DNSAnswerRecord_t ) ] ), | ||
ipSIZE_OF_IPv6_ADDRESS ); | ||
|
||
if( ppxAddressInfo != NULL ) | ||
{ | ||
pxNewAddress = pxNew_AddrInfo( pxSet->pcName, FREERTOS_AF_INET6, xIP_Address.xIPAddress.xIP_IPv6.ucBytes ); | ||
} | ||
#if ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add some more comments in the code to help developers understand why wrapping this is still working if pxNewAddress is NULL when CACHE/CALLBACK are disabled. |
||
if( ppxAddressInfo != NULL ) | ||
{ | ||
pxNewAddress = pxNew_AddrInfo( pxSet->pcName, FREERTOS_AF_INET6, xIP_Address.xIPAddress.xIP_IPv6.ucBytes ); | ||
} | ||
#endif /* ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) */ | ||
|
||
xIP_Address.xIs_IPv6 = pdTRUE; | ||
|
||
|
@@ -763,12 +773,14 @@ | |
pvCopyDest = &( pxSet->ulIPAddress ); | ||
( void ) memcpy( pvCopyDest, pvCopySource, pxSet->uxAddressLength ); | ||
|
||
if( ppxAddressInfo != NULL ) | ||
{ | ||
const uint8_t * ucBytes = ( uint8_t * ) &( pxSet->ulIPAddress ); | ||
#if ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) | ||
if( ppxAddressInfo != NULL ) | ||
{ | ||
const uint8_t * ucBytes = ( uint8_t * ) &( pxSet->ulIPAddress ); | ||
|
||
pxNewAddress = pxNew_AddrInfo( pxSet->pcName, FREERTOS_AF_INET4, ucBytes ); | ||
} | ||
pxNewAddress = pxNew_AddrInfo( pxSet->pcName, FREERTOS_AF_INET4, ucBytes ); | ||
} | ||
#endif /* ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) */ | ||
|
||
xIP_Address.xIPAddress.ulIP_IPv4 = pxSet->ulIPAddress; | ||
xIP_Address.xIs_IPv6 = pdFALSE; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change forces user to enable CACHE or CALLBACK while using MDNS/LLMNR, which I think is incorrect.