From 11f056040ed72bc41464aa9e549b02a92749d29f Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Wed, 26 Jul 2023 22:52:48 +0200 Subject: [PATCH] Make TCPStart ip filter more IPv6 friendly (#19199) --- tasmota/tasmota_xdrv_driver/xdrv_41_tcp_bridge.ino | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_41_tcp_bridge.ino b/tasmota/tasmota_xdrv_driver/xdrv_41_tcp_bridge.ino index b5c4a0789..1ac33358b 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_41_tcp_bridge.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_41_tcp_bridge.ino @@ -35,6 +35,7 @@ WiFiServer *server_tcp = nullptr; WiFiClient client_tcp[TCP_BRIDGE_CONNECTIONS]; uint8_t client_next = 0; uint8_t *tcp_buf = nullptr; // data transfer buffer +bool ip_filter_enabled = false; IPAddress ip_filter; #include @@ -65,7 +66,7 @@ void TCPLoop(void) AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "Got connection from %s"), new_client.remoteIP().toString().c_str()); // Check for IP filtering if it's enabled. - if (ip_filter) { + if (ip_filter_enabled) { if (ip_filter != new_client.remoteIP()) { AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "Rejected due to filtering")); new_client.stop(); @@ -173,9 +174,10 @@ void CmndTCPStart(void) { if (ArgC() == 2) { char sub_string[XdrvMailbox.data_len]; ip_filter.fromString(ArgV(sub_string, 2)); + ip_filter_enabled = true; } else { // Disable whitelist if previously set - ip_filter = (uint32_t)0; + ip_filter_enabled = false; } if (server_tcp) { @@ -191,7 +193,7 @@ void CmndTCPStart(void) { } if (tcp_port > 0) { AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "Starting TCP server on port %d"), tcp_port); - if (ip_filter) { + if (ip_filter_enabled) { AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "Filtering %s"), ip_filter.toString().c_str()); } server_tcp = new WiFiServer(tcp_port);