From 90b095acd865ad7170b57f7900bb9abdb07a1d88 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 4 May 2024 10:05:58 +0200 Subject: [PATCH] Improve error logging when TCP connections are prematurely closed by remote server Signed-off-by: DL6ER --- src/dnsmasq_interface.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/dnsmasq_interface.c b/src/dnsmasq_interface.c index 1691056aec..e8e8c4d875 100644 --- a/src/dnsmasq_interface.c +++ b/src/dnsmasq_interface.c @@ -3514,6 +3514,17 @@ void FTL_connection_error(const char *reason, const union mysockaddr *addr) // Make a private copy of the error const char *error = strerror(errno); + // Set log priority + int priority = LOG_ERR; + + // If this is a TCP connection error and errno == 0, this isn't a + // connection error but the remote side closed the connection + if(errno == 0 && strstr(reason, "TCP(read_write)") != NULL) + { + error = "Connection prematurely closed by remote server"; + priority = LOG_INFO; + } + // Format the address into a string (if available) in_port_t port = 0; char ip[ADDRSTRLEN + 1] = { 0 }; @@ -3525,7 +3536,7 @@ void FTL_connection_error(const char *reason, const union mysockaddr *addr) log_debug(DEBUG_QUERIES, "Connection error (%s#%u, ID %d): %s (%s)", ip, port, id, reason, error); // Log to pihole.log - my_syslog(LOG_ERR, "%s: %s", reason, error); + my_syslog(priority, "%s: %s", reason, error); // Add to Pi-hole diagnostics but do not add messages more often than // once every five seconds to avoid hammering the database with errors