Skip to content

Commit 11f0560

Browse files
authored
Make TCPStart ip filter more IPv6 friendly (#19199)
1 parent 1a91dc4 commit 11f0560

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Diff for: tasmota/tasmota_xdrv_driver/xdrv_41_tcp_bridge.ino

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ WiFiServer *server_tcp = nullptr;
3535
WiFiClient client_tcp[TCP_BRIDGE_CONNECTIONS];
3636
uint8_t client_next = 0;
3737
uint8_t *tcp_buf = nullptr; // data transfer buffer
38+
bool ip_filter_enabled = false;
3839
IPAddress ip_filter;
3940

4041
#include <TasmotaSerial.h>
@@ -65,7 +66,7 @@ void TCPLoop(void)
6566

6667
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "Got connection from %s"), new_client.remoteIP().toString().c_str());
6768
// Check for IP filtering if it's enabled.
68-
if (ip_filter) {
69+
if (ip_filter_enabled) {
6970
if (ip_filter != new_client.remoteIP()) {
7071
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "Rejected due to filtering"));
7172
new_client.stop();
@@ -173,9 +174,10 @@ void CmndTCPStart(void) {
173174
if (ArgC() == 2) {
174175
char sub_string[XdrvMailbox.data_len];
175176
ip_filter.fromString(ArgV(sub_string, 2));
177+
ip_filter_enabled = true;
176178
} else {
177179
// Disable whitelist if previously set
178-
ip_filter = (uint32_t)0;
180+
ip_filter_enabled = false;
179181
}
180182

181183
if (server_tcp) {
@@ -191,7 +193,7 @@ void CmndTCPStart(void) {
191193
}
192194
if (tcp_port > 0) {
193195
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "Starting TCP server on port %d"), tcp_port);
194-
if (ip_filter) {
196+
if (ip_filter_enabled) {
195197
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "Filtering %s"), ip_filter.toString().c_str());
196198
}
197199
server_tcp = new WiFiServer(tcp_port);

0 commit comments

Comments
 (0)