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

Fix IPv6-only DNS by checking IPv6 first if have a public scope address #9443

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion libraries/Network/src/NetworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,32 @@ int NetworkManager::hostByName(const char* aHostname, IPAddress& aResult)

struct addrinfo hints;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a better way to init the structure. especially in CPP. Please keep it that way and only change the relevant fields before each call to lwip_getaddrinfo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;

// **Workaround**
// LWIP AF_UNSPEC always prefers IPv4 and doesn't check what network is
// available. See https://github.com/espressif/esp-idf/issues/13255
// Until that is fixed, as a work around if we have a global scope IPv6,
// then we check IPv6 only first.
if (hasGlobalV6) {
hints.ai_family = AF_INET6;
err = lwip_getaddrinfo(aHostname, servname, &hints, &res);

if (err == ERR_OK)
{
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)res->ai_addr;
// As an array of u8_t
aResult = IPAddress(IPv6, ipv6->sin6_addr.s6_addr);
log_d("DNS found IPv6 first %s", aResult.toString().c_str());
lwip_freeaddrinfo(res);
return 1;
}
}
// **End Workaround**

hints.ai_family = AF_UNSPEC;
err = lwip_getaddrinfo(aHostname, servname, &hints, &res);

if (err == ERR_OK)
{
if (res->ai_family == AF_INET6)
Expand Down