8000 Add DNS forwarder to DNSServer by mhightower83 · Pull Request #7237 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Add DNS forwarder to DNSServer #7237

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

Merged
merged 39 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
407e481
Added DNS forwarder support.
mhightower83 Apr 21, 2020
0e33d6e
Added example to use DNS forwarder
mhightower83 Apr 22, 2020
63f8958
Cleanup for CI
mhightower83 Apr 22, 2020
aa430d0
Fixed insert error
mhightower83 Apr 22, 2020
a101809
Add/updated comments. Remove commented code.
mhightower83 Apr 22, 2020
3fc1be2
Merge branch 'master' into pr-dns-forwarder
mhightower83 Apr 23, 2020
ad62a7f
Added missing include for unsupported build environment
mhightower83 Apr 23, 2020
ee97777
Updated HTML to limit/remove screen flash when using show password.
mhightower83 Apr 25, 2020
16d02f6
Merge branch 'master' into pr-dns-forwarder
mhightower83 Apr 27, 2020
6755a5b
Reserved space in String page. Re-adjusted size of chuncks.
mhightower83 Apr 27, 2020
7453544
Merge branch 'master' into pr-dns-forwarder
mhightower83 May 3, 2020
10f6311
Added logic to handle dividing large PROGMEM strings into smaller chunks
mhightower83 May 5, 2020
96eacc3
Merge branch 'master' into pr-dns-forwarder
mhightower83 May 31, 2020
1b67f96
Merge branch 'pr-dns-forwarder' of github.com:mhightower83/Arduino in…
mhightower83 May 31, 2020
eb1f508
Merge branch 'master' into pr-dns-forwarder
mhightower83 Jun 19, 2020
88d1abf
Merge branch 'master' into pr-dns-forwarder
mhightower83 Jul 7, 2020
5370ba3
Merge branch 'pr-dns-forwarder' of github.com:mhightower83/Arduino in…
mhightower83 Jul 10, 2020
f9371b3
Corrected case statement in getPhyModeChar().
mhightower83 Jul 10, 2020
33aed64
Merge branch 'master' into pr-dns-forwarder
mhightower83 Jul 10, 2020
0613216
Fixed errors.
mhightower83 Jul 10, 2020
1ef128c
typo
mhightower83 Jul 11, 2020
696c865
Merge branch 'master' into pr-dns-forwarder
mhightower83 Jul 17, 2020
22769c5
Merge branch 'master' into pr-dns-forwarder
mhightower83 Jul 21, 2020
ff5d79a
Merge branch 'master' into pr-dns-forwarder
mhightower83 Sep 2, 2020
e09e6e8
Merge branch 'master' into pr-dns-forwarder
mhightower83 Sep 17, 2020
ab0472e
Merge branch 'master' into pr-dns-forwarder
mhightower83 Oct 2, 2020
64a8191
Merge branch 'master' into pr-dns-forwarder
mhightower83 Nov 16, 2020
7178c2e
Merge branch 'master' into pr-dns-forwarder
mhightower83 Dec 6, 2020
f605f12
Merge branch 'master' into pr-dns-forwarder
mhightower83 Jul 28, 2021
aa138b5
Merge branch 'master' into pr-dns-forwarder
mhightower83 Jan 12, 2022
682d08d
Merge branch 'master' into pr-dns-forwarder
mhightower83 Feb 10, 2022
3681092
Merge branch 'master' into pr-dns-forwarder
mhightower83 Apr 19, 2022
5a69137
Merge branch 'master' into pr-dns-forwarder
mhightower83 Apr 22, 2022
6d95e41
Added inline to constexpr
mhightower83 Apr 27, 2022
32fe7e1
Updates
mhightower83 May 1, 2022
dda4e04
Update libraries/DNSServer/examples/NAPTCaptivePortal/NAPTCaptivePort…
mhightower83 May 2, 2022
8afa9ca
Update libraries/DNSServer/examples/NAPTCaptivePortal/NAPTCaptivePort…
mhightower83 May 2, 2022
1da9785
Merge branch 'master' into pr-dns-forwarder
mhightower83 May 2, 2022
ea3e971
style
mhightower83 May 6, 2022
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
Prev Previous commit
Next Next commit
Cleanup for CI
  • Loading branch information
mhightower83 committed Apr 22, 2020
commit 63f895870d1159abb28a30a2c1a0632a66ec6262
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
#include <ESP8266WiFi.h>
#include <lwip/napt.h>
#include <lwip/dns.h>
#include <dhcpserver.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <ESP8266mDNS.h>
#include <EEPROM.h>

#define NAPT 1000
#define NAPT_PORT 10

/*
This example shows the use of the 'DNS forwarder' feature in the DNSServer.
It does so by combining two examples CaptivePortalAdvanced and
Expand Down Expand Up @@ -80,6 +67,22 @@
before experimenting with a private address.
*/


#if LWIP_FEATURES && !LWIP_IPV6

#include <ESP8266WiFi.h>
#include <lwip/napt.h>
#include <lwip/dns.h>
#include <dhcpserver.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <ESP8266mDNS.h>
#include <EEPROM.h>

#define NAPT 1000
#define NAPT_PORT 10

/*
Some defines for debugging
*/
Expand Down Expand Up @@ -113,9 +116,6 @@
#endif


#if !(LWIP_FEATURES && !LWIP_IPV6)
#error "Requirements: LWIP_FEATURES && ! LWIP_IPV6"
#endif

/* Set these to your desired softAP credentials. They are not configurable at runtime */
#ifndef APSSID
Expand Down Expand Up @@ -168,21 +168,21 @@ void setup() {
CONSOLE_PRINTLN("\r\n\r\nNAPT with Configuration Portal ...");

staModeConnectedHandler = WiFi.onStationModeConnected(
[](WiFiEventStationModeConnected data) {
// Keep a copy of the BSSID for the AP that WLAN connects to.
// This is used in the WLAN report on WiFi Details page.
memcpy(bssid, data.bssid, sizeof(bssid));
[](WiFiEventStationModeConnected data) {
// Keep a copy of the BSSID for the AP that WLAN connects to.
// This is used in the WLAN report on WiFi Details page.
memcpy(bssid, data.bssid, sizeof(bssid));
});

staModeDisconnectedHandler = WiFi.onStationModeDisconnected(
[](WiFiEventStationModeDisconnected data) {
(void)data;
if (dnsServer.isForwarding()) {
dnsServer.disableForwarder("*");
dnsServer.setTTL(0);
// Reminder, Serial.println() will not work from these callbacks.
// For debug printf use ets_uart_printf().
}
[](WiFiEventStationModeDisconnected data) {
(void)data;
if (dnsServer.isForwarding()) {
dnsServer.disableForwarder("*");
dnsServer.setTTL(0);
// Reminder, Serial.println() will not work from these callbacks.
// For debug printf use ets_uart_printf().
}
});

/* You can remove the password parameter if you want the AP to be open. */
Expand Down Expand Up @@ -364,3 +364,15 @@ void loop() {
//HTTP
server.handleClient();
}

#else

void setup() {
Serial.begin(115200);
Serial.printf("\n\nNAPT not supported in this configuration\n");
}

#endif

void loop() {
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

#if LWIP_FEATURES && !LWIP_IPV6

// Substitution list:
// {t} - target name
// {1} - The target to redirect to, in absolute URL form.
Expand Down Expand Up @@ -41,3 +44,5 @@ void sendPortalRedirect(String path, String targetName) {
reply.replace("{1}", path);
server.send(302, "text/html", reply);
}

#endif // LWIP_FEATURES && !LWIP_IPV6
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

#if LWIP_FEATURES && !LWIP_IPV6

/** Load WLAN credentials from EEPROM */
void loadCredentials() {
EEPROM.begin(512);
Expand Down Expand Up @@ -26,3 +29,5 @@ void saveCredentials() {
EEPROM.commit();
EEPROM.end();
}

#endif // LWIP_FEATURES && !LWIP_IPV6
18 changes: 11 additions & 7 deletions libraries/DNSServer/examples/NAPTCaptivePortal/handleHttp.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#if LWIP_FEATURES && !LWIP_IPV6

#include "WifiHttp.h"
String& sendIfOver(String & str, size_t threshold = 512);

Expand All @@ -13,9 +15,9 @@ void addNoCacheHeader() {
String& sendIfOver(String & str, size_t threshold) {
size_t len = str.length();
if (len > threshold) {
maxPage = std::max(maxPage, len);
server.sendContent(str);
str = "";
maxPage = std::max(maxPage, len);
server.sendContent(str);
str = "";
}
return str;
}
Expand Down Expand Up @@ -68,8 +70,8 @@ boolean captivePortal() {
}

if (hAddr.isSet() ||
(server.hostHeader() != (String(myHostname) + ".local") && // arrived here by mDNS
server.hostHeader() != String(myHostname))) { // arrived here by local router DNS
(server.hostHeader() != (String(myHostname) + ".local") && // arrived here by mDNS
server.hostHeader() != String(myHostname))) { // arrived here by local router DNS
String whereTo = String("http://") + server.client().localIP().toString();
sendPortalRedirect(whereTo, F("Captive Portal Example"));
return true;
Expand Down Expand Up @@ -178,8 +180,8 @@ void handleWifi() {
sendIfOver(page);
}
} else {
page += FPSTR(configNoAPs);
sendIfOver(page);
page += FPSTR(configNoAPs);
sendIfOver(page);
}

page += FPSTR(configEnd);
Expand Down Expand Up @@ -217,3 +219,5 @@ void handleNotFound() {
addNoCacheHeader();
server.send(404, F("text/plain"), message);
}

#endif // LWIP_FEATURES && !LWIP_IPV6
6 changes: 5 additions & 1 deletion libraries/DNSServer/examples/NAPTCaptivePortal/tools.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
These functions may exist in other projects
*/

#if LWIP_FEATURES && !LWIP_IPV6

/*
Returns a descriptive string for WiFi.status() value
*/
Expand Down Expand Up @@ -72,10 +74,12 @@ char getPhyModeChar(WiFiPhyMode_t i) {
String macToString(const unsigned char* mac) {
char buf[20];
int rc = snprintf(buf, sizeof(buf), PSTR("%02X:%02X:%02X:%02X:%02X:%02X"),
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

if (rc < 0 || rc >= (int)sizeof(buf)) {
return emptyString;
}
return String(buf);
}

#endif // LWIP_FEATURES && !LWIP_IPV6
0