From: Otto Moerbeek Date: Mon, 9 Dec 2024 08:32:02 +0000 (+0100) Subject: rec: log only one line per protocol for listening sockets, X-Git-Tag: rec-5.2.0-rc1~2^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a64daba105643349b5f9637547bde57775da6afb;p=thirdparty%2Fpdns.git rec: log only one line per protocol for listening sockets, Instead of addresses * threads * protocol lines --- diff --git a/pdns/recursordist/pdns_recursor.cc b/pdns/recursordist/pdns_recursor.cc index 4869d16d87..f395ad7aca 100644 --- a/pdns/recursordist/pdns_recursor.cc +++ b/pdns/recursordist/pdns_recursor.cc @@ -2682,7 +2682,7 @@ static void handleNewUDPQuestion(int fileDesc, FDMultiplexer::funcparam_t& /* va t_Counters.updateSnap(g_regressionTestMode); } -unsigned int makeUDPServerSockets(deferredAdd_t& deferredAdds, Logr::log_t log) +unsigned int makeUDPServerSockets(deferredAdd_t& deferredAdds, Logr::log_t log, bool doLog, unsigned int instances) { int one = 1; vector localAddresses; @@ -2771,8 +2771,9 @@ unsigned int makeUDPServerSockets(deferredAdd_t& deferredAdds, Logr::log_t log) deferredAdds.emplace_back(socketFd, handleNewUDPQuestion); g_listenSocketsAddresses[socketFd] = address; // this is written to only from the startup thread, not from the workers - SLOG(g_log << Logger::Info << "Listening for UDP queries on " << address.toStringWithPort() << endl, - log->info(Logr::Info, "Listening for queries", "proto", Logging::Loggable("UDP"), "address", Logging::Loggable(address))); + } + if (doLog) { + log->info(Logr::Info, "Listening for queries", "proto", Logging::Loggable("UDP"), "addresses", Logging::IterLoggable(localAddresses.cbegin(), localAddresses.cend()), "socketInstances", Logging::Loggable(instances), "reuseport", Logging::Loggable(g_reusePort)); } return localAddresses.size(); } diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 380c77a229..b06a55c04d 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -1891,7 +1891,7 @@ static unsigned int initDistribution(Logr::log_t log) for (unsigned int i = 0; i < RecThreadInfo::numDistributors(); i++, threadNum++) { auto& info = RecThreadInfo::info(threadNum); auto& deferredAdds = info.getDeferredAdds(); - count += makeUDPServerSockets(deferredAdds, log); + count += makeUDPServerSockets(deferredAdds, log, i == RecThreadInfo::numDistributors() - 1, RecThreadInfo::numDistributors()); } } else { @@ -1899,7 +1899,7 @@ static unsigned int initDistribution(Logr::log_t log) for (unsigned int i = 0; i < RecThreadInfo::numUDPWorkers(); i++, threadNum++) { auto& info = RecThreadInfo::info(threadNum); auto& deferredAdds = info.getDeferredAdds(); - count += makeUDPServerSockets(deferredAdds, log); + count += makeUDPServerSockets(deferredAdds, log, i == RecThreadInfo::numUDPWorkers() - 1, RecThreadInfo::numUDPWorkers()); } } threadNum = 1 + RecThreadInfo::numDistributors() + RecThreadInfo::numUDPWorkers(); @@ -1907,15 +1907,15 @@ static unsigned int initDistribution(Logr::log_t log) auto& info = RecThreadInfo::info(threadNum); auto& deferredAdds = info.getDeferredAdds(); auto& tcpSockets = info.getTCPSockets(); - count += makeTCPServerSockets(deferredAdds, tcpSockets, log); + count += makeTCPServerSockets(deferredAdds, tcpSockets, log, i == RecThreadInfo::numTCPWorkers() - 1, RecThreadInfo::numTCPWorkers()); } } else { std::set tcpSockets; /* we don't have reuseport so we can only open one socket per listening addr:port and everyone will listen on it */ - count += makeUDPServerSockets(s_deferredUDPadds, log); - count += makeTCPServerSockets(s_deferredTCPadds, tcpSockets, log); + count += makeUDPServerSockets(s_deferredUDPadds, log, true, 1); + count += makeTCPServerSockets(s_deferredTCPadds, tcpSockets, log, true, 1); // TCP queries are handled by TCP workers for (unsigned int i = 0; i < RecThreadInfo::numTCPWorkers(); i++) { diff --git a/pdns/recursordist/rec-main.hh b/pdns/recursordist/rec-main.hh index 98683bbf5d..1d07b75f3d 100644 --- a/pdns/recursordist/rec-main.hh +++ b/pdns/recursordist/rec-main.hh @@ -615,10 +615,10 @@ bool expectProxyProtocol(const ComboAddress& from, const ComboAddress& listenAdd void finishTCPReply(std::unique_ptr&, bool hadError, bool updateInFlight); void checkFastOpenSysctl(bool active, Logr::log_t); void checkTFOconnect(Logr::log_t); -unsigned int makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set& tcpSockets, Logr::log_t); +unsigned int makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set& tcpSockets, Logr::log_t, bool doLog, unsigned int instances); void handleNewTCPQuestion(int fileDesc, FDMultiplexer::funcparam_t&); -unsigned int makeUDPServerSockets(deferredAdd_t& deferredAdds, Logr::log_t); +unsigned int makeUDPServerSockets(deferredAdd_t& deferredAdds, Logr::log_t, bool doLog, unsigned int instances); string doTraceRegex(FDWrapper file, vector::const_iterator begin, vector::const_iterator end); extern bool g_luaSettingsInYAML; void startLuaConfigDelayedThreads(const LuaConfigItems& luaConfig, uint64_t generation); diff --git a/pdns/recursordist/rec-tcp.cc b/pdns/recursordist/rec-tcp.cc index a5794035dc..5fc4ec5d4a 100644 --- a/pdns/recursordist/rec-tcp.cc +++ b/pdns/recursordist/rec-tcp.cc @@ -1086,7 +1086,7 @@ LWResult::Result arecvtcp(PacketBuffer& data, const size_t len, shared_ptr& tcpSockets, Logr::log_t log) +unsigned int makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set& tcpSockets, Logr::log_t log, bool doLog, unsigned int instances) { vector localAddresses; stringtok(localAddresses, ::arg()["local-address"], " ,"); @@ -1186,12 +1186,13 @@ unsigned int makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set& tc // we don't need to update g_listenSocketsAddresses since it doesn't work for TCP/IP: // - fd is not that which we know here, but returned from accept() - SLOG(g_log << Logger::Info << "Listening for TCP queries on " << address.toStringWithPort() << endl, - log->info(Logr::Info, "Listening for queries", "protocol", Logging::Loggable("TCP"), "address", Logging::Loggable(address))); #ifdef TCP_DEFER_ACCEPT first = false; #endif } + if (doLog) { + log->info(Logr::Info, "Listening for queries", "protocol", Logging::Loggable("TCP"), "addresses", Logging::IterLoggable(localAddresses.cbegin(), localAddresses.cend()), "socketInstances", Logging::Loggable(instances), "reuseport", Logging::Loggable(g_reusePort)); + } return localAddresses.size(); }