feat(dns): Check type of IP addresses and clear DNS cache if they changed #9476
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.
Description of Change
Check if the device has a global IPv6 address, and if the status has changed (changing from no address to having an address, or vice-versa) clear the DNS cache.
For consistency, the code also checks if you have an IPv4 address, and handles that similarly.
Tests scenarios
Tested with M5Stack Core 2, using the following PlatformIO configuration and the test app from https://github.com/sgryphon/iot-demo-build/tree/main/m5stack/m5unified_wifi_https
PlatformIO configuration:
Results after change:
These are the same as before the change.
The failure is because the device is on an IPv6-only network, but DNS is hard coded to return IPv4 first, so a dual-stack destination does not work (it gets the unusable IPv4), but an IPv6 only destination is fine. An IPv4-only destination also fails, even though NAT64 is active, because it uses the IPv4 address instead of the DNS64 address.
Results for other network types all work, although dual-stack to dual-stack, where both are available, uses IPv4.
Failing example connecting to a dual-stack destination. Note the DNS cache is cleared as the flag changes from the default of false to true. This is also the first DNS request for the app. It fails because IPv4 is returned for the dual-stack destination, even though we can't use.
Log connecting to an IPv6-only destination. No need to clear the cache, as then network has not changed. As the destination is also IPv6-only, we get the IPv6 result, which works.
Related links
Requested to split the IPv6 DNS fix into separate PRs that implement the address type check separately, and then the bug fix workaround to dynamically check DNS based on the available address types.
Note that the bug will also be fixed if the LWIP change, to implement RFC6724 destination address selection, is merged.