Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make TCPStart ip filter more IPv6 friendly #19199

Merged
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
8 changes: 5 additions & 3 deletions tasmota/tasmota_xdrv_driver/xdrv_41_tcp_bridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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 <TasmotaSerial.h>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down