FreeRTOS / FreeRTOS-Plus-TCP

FreeRTOS-Plus-TCP library repository. +TCP files only. Submoduled into https://github.com/FreeRTOS/FreeRTOS and various other repos.
MIT License
146 stars 159 forks source link

Fix DNS to use correct DNS IP preference #1109

Closed tony-josi-aws closed 7 months ago

tony-josi-aws commented 7 months ago

Description

This PR updates DNS code to use correct DNS IP preference which was previously only set to xPreferenceIPv6 for IPv6 and then never updated.

Thanks @evpopov for detailed bug report: #1107

This PR also removes the unused variable xNeed_Endpoint, as xDNS_IP_Preference can be either xPreferenceIPv4 or xPreferenceIPv6 only.

Test Steps

Tested DNSv4 query after DNSv6 query [no IPv6 connection/endpoint]:


/*==================== dnsq4  aws.amazon.com (2/4) ====================*/

xHandleTestingCommand: the function xHandleTesting() was not called
pxDNSLookup: 'aws.amazon.com' IPv4 Sync DNS-clear = false
ARP 192.168.0.1 miss using 192.168.0.1
pxEasyFit: ARP 192.168.0.100 -> 192.168.0.1
ipARP_REPLY from 192.168.0.1 to 192.168.0.100 end-point 192.168.0.100
DNS_ReadReply returns -11
prvIncreaseDNS4Index: from 0 to 0
FreeRTOS_ProcessDNSCache: add: 'aws.amazon.com' @ 65.8.79.190 (TTL 54)
DNS[0xAF80]: The answer to 'aws.amazon.com' (65.8.79.190) will be stored
FreeRTOS_getaddrinfo: rc 0
Found Address: 65.8.79.190
dns query4: 'aws.amazon.com' = 65.8.79.190 rc = 0

/*==================== dnsq6  google.nl (3/4) ====================*/

xHandleTestingCommand: the function xHandleTesting() was not called
pxDNSLookup: 'google.nl' IPv6 Sync DNS-clear = false
Can not find a DNS address, along with an end-point.
Can not find a DNS address, along with an end-point.
Can not find a DNS address, along with an end-point.
Can not find a DNS address, along with an end-point.
FreeRTOS_getaddrinfo: rc -2
dns query6: 'google.nl' No results

/*==================== dnsq4  google.es (4/4) ====================*/

xHandleTestingCommand: the function xHandleTesting() was not called
pxDNSLookup: 'google.es' IPv4 Sync DNS-clear = false
FreeRTOS_ProcessDNSCache: add: 'google.es' @ 142.250.77.163 (TTL 300)
DNS[0x9513]: The answer to 'google.es' (142.250.77.163) will be stored
FreeRTOS_getaddrinfo: rc 0
Found Address: 142.250.77.163
dns query4: 'google.es' = 142.250.77.163 rc = 0
Server task now ready.
pxEasyFit: ARP 192.168.0.1 -> 192.168.0.100
ipARP_REQUEST from 192.168.0.1 to 192.168.0.100 end-point 192.168.0.100

Checklist:

Related Issue

1107

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

tony-josi-aws commented 7 months ago

/bot run formatting

moninom1 commented 7 months ago

Did you checked xPreferenceNone as we discussed? Can we use it in case where family is not provided?

tony-josi-aws commented 7 months ago

@moninom1

Did you checked xPreferenceNone as we discussed? Can we use it in case where family is not provided?

Since the xFamily is configured by the functions that call prvGetHostByNameOp all the calls are either FREERTOS_AF_INET6 or FREERTOS_AF_INET