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

Make DNS resolution order selectable during runtime or compile time #6865

Merged
merged 65 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
4d51978
Make DNS resolution order selectable during runtime or compile time (…
Dec 1, 2019
4288466
Merge branch 'master' into master
altelch Dec 2, 2019
ffb463d
Merge branch 'master' into master
altelch Dec 4, 2019
7706e66
Extend IPv6 example to show usage of new hostByName function with sel…
Dec 4, 2019
2b1de87
Merge branch 'master' of https://github.com/altelch/Arduino
Dec 4, 2019
a376fac
Merge branch 'master' into master
altelch Dec 4, 2019
4d507df
Fix function definition of fqdn_rt in IPv6.ino.
altelch Dec 4, 2019
cab31c1
Fix function call.
altelch Dec 4, 2019
6e9ff58
Fix missing bracket...
altelch Dec 4, 2019
8d944d3
Only run if built with dual stack support
altelch Dec 4, 2019
25fdfd4
Merge branch 'master' into master
altelch Dec 4, 2019
d546877
Make DNS resolution order selectable during runtime or compile time (…
Dec 1, 2019
50f79b8
Extend IPv6 example to show usage of new hostByName function with sel…
Dec 4, 2019
198f2eb
Fix function definition of fqdn_rt in IPv6 example.
Dec 4, 2019
116c212
Merge branch 'master' of https://github.com/altelch/Arduino
Dec 5, 2019
700247b
Implement enum class for resolve type
Dec 5, 2019
5bd5cd6
Fix example IPv6.ino
Dec 5, 2019
198cc1f
Fix typedef in ESP8266WiFiGeneric.h function call
Dec 5, 2019
37f3267
Change enum class definition to not depend on lwip/dns.h
Dec 5, 2019
7751792
Move err_t err definition outside switch. Fix typecast.
Dec 5, 2019
32e7e87
Always define DNSResolveType as pio test otherwise failes even if the…
Dec 7, 2019
1660cbe
Merge branch 'master' into master
altelch Dec 7, 2019
eae8010
Merge branch 'master' into master
altelch Dec 9, 2019
10a37cb
Merge branch 'master' into master
altelch Dec 10, 2019
d96e6b4
Merge branch 'master' into master
altelch Dec 10, 2019
5bc5d5f
Merge branch 'master' into master
altelch Dec 10, 2019
03b8011
Merge branch 'master' into master
altelch Dec 11, 2019
12f9cce
Merge branch 'master' into master
altelch Dec 12, 2019
52b6208
Merge branch 'master' into master
altelch Dec 13, 2019
82112df
Merge branch 'master' into master
altelch Dec 16, 2019
af2a88e
Merge branch 'master' into master
altelch Dec 16, 2019
e1c7209
Merge branch 'master' into master
altelch Dec 17, 2019
978570d
Merge branch 'master' into master
altelch Dec 19, 2019
f55b26c
Merge branch 'master' into master
altelch Dec 20, 2019
98034d4
Merge branch 'master' into master
altelch Dec 21, 2019
3c66eca
Merge branch 'master' into master
altelch Dec 22, 2019
b40ffb1
Merge branch 'master' into master
altelch Dec 25, 2019
a587b6f
Merge branch 'master' into master
altelch Dec 27, 2019
f0654d4
Merge branch 'master' into master
altelch Dec 29, 2019
c6b44cc
Merge branch 'master' into master
altelch Jan 7, 2020
45cfd3b
Merge branch 'master' into master
altelch Jan 9, 2020
09e34d8
Merge branch 'master' into master
altelch Jan 12, 2020
c6c0a18
Merge branch 'master' into master
altelch Jan 15, 2020
0dacf59
Merge branch 'master' into master
altelch Jan 18, 2020
838fc88
Merge branch 'master' into master
altelch Jan 24, 2020
f4aae68
Merge branch 'master' into master
altelch Jan 30, 2020
f9a098c
Merge branch 'master' into master
altelch Feb 1, 2020
efef2e7
Merge branch 'master' into master
altelch Feb 2, 2020
14d1441
Merge branch 'master' into master
altelch Feb 5, 2020
a61637e
Merge branch 'master' into master
altelch Feb 10, 2020
0aff6d2
Merge branch 'master' into master
altelch Feb 16, 2020
d1dccc1
Merge branch 'master' into master
altelch Feb 16, 2020
d748114
Merge branch 'master' into master
altelch Feb 20, 2020
021c18f
Merge branch 'master' into master
altelch Feb 22, 2020
edd97b9
Merge branch 'master' into master
altelch Feb 23, 2020
15f2648
Merge branch 'master' into master
altelch Feb 24, 2020
94be45c
Merge branch 'master' into master
altelch Feb 24, 2020
9cfb838
Merge branch 'master' into master
altelch Feb 25, 2020
24f55fe
Merge branch 'master' into master
altelch Feb 27, 2020
24d17ce
Merge branch 'master' into master
altelch Feb 28, 2020
0528d83
Merge branch 'master' into master
altelch Mar 15, 2020
8f9c5db
Merge branch 'master' into master
altelch Mar 31, 2020
863e8be
Merge branch 'master' into master
altelch Apr 4, 2020
77de061
Merge branch 'master' into master
altelch Apr 4, 2020
b2e59fa
Merge branch 'master' into master
d-a-v Apr 9, 2020
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: 21 additions & 3 deletions libraries/ESP8266WiFi/examples/IPv6/IPv6.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
arduino IPv6 example
released to public domain
Expand Down Expand Up @@ -27,7 +26,8 @@
#define STAPSK "your-password"
#endif

#define FQDN F("www.google.com") // with both IPv4 & IPv6 addresses
#define FQDN F("www.google.com") // with both IPv4 & IPv6 addresses
#define FQDN2 F("www.yahoo.com") // with both IPv4 & IPv6 addresses
#define FQDN6 F("ipv6.google.com") // does not resolve in IPv4
#define STATUSDELAY_MS 10000
#define TCP_PORT 23
Expand All @@ -50,6 +50,21 @@ void fqdn(Print& out, const String& fqdn) {
}
}

#if LWIP_IPV4 && LWIP_IPV6
void fqdn_rt(Print& out, const String& fqdn, DNSResolveType resolveType) {
out.print(F("resolving "));
out.print(fqdn);
out.print(F(": "));
IPAddress result;
if (WiFi.hostByName(fqdn.c_str(), result, 10000, resolveType)) {
result.printTo(out);
out.println();
} else {
out.println(F("timeout or not found"));
}
}
#endif

void status(Print& out) {
out.println(F("------------------------------"));
out.println(ESP.getFullVersion());
Expand Down Expand Up @@ -85,7 +100,10 @@ void status(Print& out) {
// an example is provided with a fqdn which does not resolve with IPv4
fqdn(out, FQDN);
fqdn(out, FQDN6);

#if LWIP_IPV4 && LWIP_IPV6
fqdn_rt(out, FQDN, DNSResolveType::DNS_AddrType_IPv4_IPv6); // IPv4 before IPv6
fqdn_rt(out, FQDN2, DNSResolveType::DNS_AddrType_IPv6_IPv4); // IPv6 before IPv4
#endif
out.println(F("------------------------------"));
}

Expand Down
57 changes: 56 additions & 1 deletion libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul
int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms)
{
ip_addr_t addr;
aResult = static_cast<uint32_t>(0);
aResult = static_cast<uint32_t>(INADDR_NONE);

if(aResult.fromString(aHostname)) {
// Host name is a IP address use it!
Expand All @@ -617,7 +617,61 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul
}

DEBUG_WIFI_GENERIC("[hostByName] request IP for: %s\n", aHostname);
#if LWIP_IPV4 && LWIP_IPV6
err_t err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult,LWIP_DNS_ADDRTYPE_DEFAULT);
#else
err_t err = dns_gethostbyname(aHostname, &addr, &wifi_dns_found_callback, &aResult);
#endif
if(err == ERR_OK) {
aResult = IPAddress(&addr);
} else if(err == ERR_INPROGRESS) {
_dns_lookup_pending = true;
delay(timeout_ms);
// will resume on timeout or when wifi_dns_found_callback fires
_dns_lookup_pending = false;
// will return here when dns_found_callback fires
if(aResult.isSet()) {
err = ERR_OK;
}
}

if(err != 0) {
DEBUG_WIFI_GENERIC("[hostByName] Host: %s lookup error: %d!\n", aHostname, (int)err);
} else {
DEBUG_WIFI_GENERIC("[hostByName] Host: %s IP: %s\n", aHostname, aResult.toString().c_str());
}

return (err == ERR_OK) ? 1 : 0;
}

#if LWIP_IPV4 && LWIP_IPV6
int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, DNSResolveType resolveType)
{
ip_addr_t addr;
err_t err;
aResult = static_cast<uint32_t>(INADDR_NONE);

if(aResult.fromString(aHostname)) {
// Host name is a IP address use it!
DEBUG_WIFI_GENERIC("[hostByName] Host: %s is a IP!\n", aHostname);
return 1;
}

DEBUG_WIFI_GENERIC("[hostByName] request IP for: %s\n", aHostname);
switch(resolveType)
{
// Use selected addrtype
case DNSResolveType::DNS_AddrType_IPv4:
case DNSResolveType::DNS_AddrType_IPv6:
case DNSResolveType::DNS_AddrType_IPv4_IPv6:
case DNSResolveType::DNS_AddrType_IPv6_IPv4:
err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult, (uint8_t) resolveType);
break;
default:
err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns_found_callback, &aResult, LWIP_DNS_ADDRTYPE_DEFAULT); // If illegal type, use default.
break;
}

if(err == ERR_OK) {
aResult = IPAddress(&addr);
} else if(err == ERR_INPROGRESS) {
Expand All @@ -639,6 +693,7 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul

return (err == ERR_OK) ? 1 : 0;
}
#endif

/**
* DNS callback
Expand Down
11 changes: 11 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ typedef std::shared_ptr<WiFiEventHandlerOpaque> WiFiEventHandler;

typedef void (*WiFiEventCb)(WiFiEvent_t);

enum class DNSResolveType: uint8_t
{
DNS_AddrType_IPv4 = 0, // LWIP_DNS_ADDRTYPE_IPV4 = 0
DNS_AddrType_IPv6, // LWIP_DNS_ADDRTYPE_IPV6 = 1
DNS_AddrType_IPv4_IPv6, // LWIP_DNS_ADDRTYPE_IPV4_IPV6 = 2
DNS_AddrType_IPv6_IPv4 // LWIP_DNS_ADDRTYPE_IPV6_IPV4 = 3
d-a-v marked this conversation as resolved.
Show resolved Hide resolved
};

struct WiFiState;

class ESP8266WiFiGenericClass {
Expand Down Expand Up @@ -113,6 +121,9 @@ class ESP8266WiFiGenericClass {
public:
int hostByName(const char* aHostname, IPAddress& aResult);
int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms);
#if LWIP_IPV4 && LWIP_IPV6
int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, DNSResolveType resolveType);
#endif
bool getPersistent();

protected:
Expand Down