]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Tidy rec-main.?? 16930/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 23 Feb 2026 14:08:42 +0000 (15:08 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 23 Feb 2026 14:45:04 +0000 (15:45 +0100)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/recursordist/pdns_recursor.cc
pdns/recursordist/rec-main.cc
pdns/recursordist/rec-main.hh
pdns/recursordist/syncres.hh

index 9c526c6f4fb9be09f2f5f50a756cdf9395de012a..0675a5601f56ee653d8054d6c7e7714b2cdebf8f 100644 (file)
@@ -32,6 +32,7 @@
 #include "validate-recursor.hh"
 #include "ratelimitedlog.hh"
 #include "ednsoptions.hh"
+#include "sanitizer.hh"
 
 #ifdef HAVE_SYSTEMD
 #include <systemd/sd-daemon.h>
index c17936d5643eb53c8736f5b022ce42f32aa3bd0c..c5378c6801979a831e6b5598da1038260e38d34f 100644 (file)
 #include "rec-main.hh"
 
 #include "aggressive_nsec.hh"
-#include "capabilities.hh"
 #include "arguments.hh"
-#include "dns_random.hh"
-#include "rec_channel.hh"
-#include "rec-tcpout.hh"
-#include "version.hh"
-#include "query-local-address.hh"
-#include "validate-recursor.hh"
-#include "pubsuffix.hh"
-#include "opensslsigners.hh"
-#include "ws-recursor.hh"
-#include "rec-taskqueue.hh"
-#include "secpoll-recursor.hh"
-#include "logging.hh"
+#include "capabilities.hh"
 #include "dnssec.hh"
+#include "opensslsigners.hh"
+#include "pubsuffix.hh"
+#include "query-local-address.hh"
 #include "rec-rust-lib/cxxsettings.hh"
-#include "json.hh"
+#include "rec-snmp.hh"
 #include "rec-system-resolve.hh"
+#include "rec-taskqueue.hh"
+#include "rec-tcpout.hh"
 #include "root-dnssec.hh"
-#include "ratelimitedlog.hh"
-#include "rec-rust-lib/rust/web.rs.h"
+#include "secpoll-recursor.hh"
+#include "threadname.hh"
+#include "version.hh"
+#include "ws-recursor.hh"
 
 #ifdef NOD_ENABLED
 #include "nod.hh"
@@ -52,9 +47,6 @@
 
 #ifdef HAVE_LIBSODIUM
 #include <sodium.h>
-
-#include <cstddef>
-#include <utility>
 #endif
 
 #ifdef HAVE_SYSTEMD
@@ -984,7 +976,7 @@ static void checkOrFixFDS(unsigned int listeningSockets, Logr::log_t log)
   // Static part: the FDs from the start, pipes, controlsocket, web socket, listen sockets
   unsigned int staticPart = 25; // general  allowance, including control socket, web, snmp
   // Handler thread gets one pipe, the others all of them
-  staticPart += 2 + (threads - 1) * (sizeof(RecThreadInfo::ThreadPipeSet) / sizeof(int)); // number of fd's in ThreadPipeSet
+  staticPart += 2 + ((threads - 1) * (sizeof(RecThreadInfo::ThreadPipeSet) / sizeof(int))); // number of fd's in ThreadPipeSet
   // listen sockets
   staticPart += listeningSockets;
   // Another fd per thread for poll/kqueue
@@ -998,7 +990,7 @@ static void checkOrFixFDS(unsigned int listeningSockets, Logr::log_t log)
   // plus each worker thread can have a number of idle outgoing TCP connections
   perWorker += TCPOutConnectionManager::s_maxIdlePerThread;
 
-  auto wantFDs = staticPart + workers * perWorker;
+  auto wantFDs = staticPart + (workers * perWorker);
 
   if (wantFDs > availFDs) {
     unsigned int hardlimit = getFilenumLimit(true);
@@ -2383,7 +2375,7 @@ static void handlePipeRequest(int fileDesc, FDMultiplexer::funcparam_t& /* var *
 
     __tsan_release(resp);
 
-    if (write(RecThreadInfo::self().getPipes().writeFromThread, &resp, sizeof(resp)) != sizeof(resp)) {
+    if (write(RecThreadInfo::self().getPipes().writeFromThread, static_cast<void*>(&resp), sizeof(resp)) != sizeof(resp)) {
       delete tmsg; // NOLINT: manual ownership handling
       unixDie("write to thread pipe returned wrong size or error");
     }
@@ -2400,18 +2392,18 @@ static void handleRCC(int fileDesc, FDMultiplexer::funcparam_t& /* var */)
     if (clientfd == -1) {
       throw PDNSException("accept failed");
     }
-    string msg = g_rcc.recv(clientfd).d_str;
+    string msg = RecursorControlChannel::recv(clientfd).d_str;
     log->info(Logr::Info, "Received rec_control command via control socket", "command", Logging::Loggable(msg));
 
     RecursorControlParser::func_t* command = nullptr;
     auto answer = RecursorControlParser::getAnswer(clientfd, msg, &command);
 
     if (command != doExitNicely) {
-      g_rcc.send(clientfd, answer);
+      RecursorControlChannel::send(clientfd, answer);
     }
     command();
     if (command == doExitNicely) {
-      g_rcc.send(clientfd, answer);
+      RecursorControlChannel::send(clientfd, answer);
     }
   }
   catch (const std::exception& e) {
@@ -2859,7 +2851,10 @@ static void recursorThread()
       checkFrameStreamExport(luaconfsLocal, luaconfsLocal->nodFrameStreamExportConfig, t_nodFrameStreamServersInfo);
 #endif
       for (const auto& rpz : luaconfsLocal->rpzs) {
-        string name = rpz.polName.empty() ? (rpz.zoneXFRParams.primaries.empty() ? "rpzFile" : rpz.zoneXFRParams.name) : rpz.polName;
+        string name = rpz.polName;
+        if (name.empty()) {
+          name = rpz.zoneXFRParams.primaries.empty() ? "rpzFile" : rpz.zoneXFRParams.name;
+        }
         t_Counters.at(rec::PolicyNameHits::policyName).counts[name] = 0;
       }
     }
@@ -3214,9 +3209,7 @@ int main(int argc, char** argv)
     g_quiet = ::arg().mustDo("quiet");
     s_logUrgency = (Logger::Urgency)::arg().asNum("loglevel");
 
-    if (s_logUrgency < Logger::Error) {
-      s_logUrgency = Logger::Error;
-    }
+    s_logUrgency = std::max(s_logUrgency, Logger::Error);
     if (!g_quiet && s_logUrgency < Logger::Info) { // Logger::Info=6, Logger::Debug=7
       s_logUrgency = Logger::Info; // if you do --quiet=no, you need Info to also see the query log
     }
@@ -3281,7 +3274,7 @@ static RecursorControlChannel::Answer* doReloadLuaScript()
     if (fname.empty()) {
       t_pdl.reset();
       log->info(Logr::Info, "Unloaded current lua script");
-      return new RecursorControlChannel::Answer{0, string("unloaded\n")};
+      return new RecursorControlChannel::Answer{0, string("unloaded\n")}; // NOLINT: manual ownership handling
     }
 
     t_pdl = std::make_shared<RecursorLua4>();
index bcdb4dcb1e29cda2914d935f2fc3f66c8d9274bb..524c03f39b029478e697c0b3a4370db14f3f8645 100644 (file)
 
 #pragma once
 
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
-#include "logger.hh"
 #include "logr.hh"
+#include "iputils.hh"
 #include "lua-recursor4.hh"
 #include "mplexer.hh"
-#include "namespaces.hh"
 #include "rec-lua-conf.hh"
 #include "rec-protozero.hh"
 #include "syncres.hh"
-#include "rec-snmp.hh"
 #include "rec_channel.hh"
-#include "threadname.hh"
 #include "recpacketcache.hh"
 #include "ratelimitedlog.hh"
-#include "protozero-trace.hh"
 #include "remote_logger.hh"
 
 #ifdef NOD_ENABLED
@@ -63,31 +57,31 @@ struct DNSComboWriter
   }
 
   // The address the query is coming from
-  void setRemote(const ComboAddress& sa)
+  void setRemote(const ComboAddress& address)
   {
-    d_remote = sa;
+    d_remote = address;
   }
 
   // The address we assume the query is coming from, might be set by proxy protocol
-  void setSource(const ComboAddress& sa)
+  void setSource(const ComboAddress& address)
   {
-    d_source = sa;
+    d_source = address;
   }
 
-  void setMappedSource(const ComboAddress& sa)
+  void setMappedSource(const ComboAddress& address)
   {
-    d_mappedSource = sa;
+    d_mappedSource = address;
   }
 
-  void setLocal(const ComboAddress& sa)
+  void setLocal(const ComboAddress& address)
   {
-    d_local = sa;
+    d_local = address;
   }
 
   // The address we assume the query is sent to, might be set by proxy protocol
-  void setDestination(const ComboAddress& sa)
+  void setDestination(const ComboAddress& address)
   {
-    d_destination = sa;
+    d_destination = address;
   }
 
   void setSocket(int sock)
@@ -167,31 +161,25 @@ extern DoneRunning g_doneRunning;
 // but after you call 'returnSocket' on it, don't assume anything anymore
 class UDPClientSocks
 {
-  unsigned int d_numsocks;
-
 public:
-  UDPClientSocks() :
-    d_numsocks(0)
-  {
-  }
-
   LWResult::Result getSocket(const ComboAddress& toaddr, const std::optional<ComboAddress>& localAddress, int* fileDesc);
 
   // return a socket to the pool, or simply erase it
   void returnSocket(int fileDesc);
 
 private:
+  unsigned int d_numsocks{0};
   // returns -1 for errors which might go away, throws for ones that won't
   static int makeClientSocket(int family, const std::optional<ComboAddress>& localAddress);
 };
 
-enum class PaddingMode
+enum class PaddingMode : uint8_t
 {
   Always,
   PaddedQueries
 };
 
-typedef MTasker<std::shared_ptr<PacketID>, PacketBuffer, PacketIDCompare> MT_t;
+using MT_t = MTasker<std::shared_ptr<PacketID>, PacketBuffer, PacketIDCompare>;
 extern thread_local std::unique_ptr<MT_t> g_multiTasker; // the big MTasker
 extern std::unique_ptr<RecursorPacketCache> g_packetCache;
 
@@ -289,7 +277,7 @@ extern thread_local FrameStreamServersInfo t_nodFrameStreamServersInfo;
 extern std::vector<bool> g_avoidUdpSourcePorts;
 
 /* without reuseport, all listeners share the same sockets */
-typedef vector<pair<int, std::function<void(int, boost::any&)>>> deferredAdd_t;
+using deferredAdd_t = vector<pair<int, std::function<void(int, boost::any&)>>>;
 
 inline MT_t* getMT()
 {
@@ -298,30 +286,30 @@ inline MT_t* getMT()
 
 /* this function is called with both a string and a vector<uint8_t> representing a packet */
 template <class T>
-static bool sendResponseOverTCP(const std::unique_ptr<DNSComboWriter>& dc, const T& packet)
+static bool sendResponseOverTCP(const std::unique_ptr<DNSComboWriter>& comboWriter, const T& packet)
 {
-  uint8_t buf[2];
+  std::array<uint8_t, 2> buf{};
   buf[0] = packet.size() / 256;
   buf[1] = packet.size() % 256;
 
-  Utility::iovec iov[2];
-  iov[0].iov_base = (void*)buf;
+  std::array<Utility::iovec, 2> iov{};
+  iov[0].iov_base = static_cast<void*>(buf.data());
   iov[0].iov_len = 2;
-  iov[1].iov_base = (void*)&*packet.begin();
+  iov[1].iov_base = static_cast<void*>(const_cast<typename T::value_type*>(packet.data()));
   iov[1].iov_len = packet.size();
 
-  int wret = Utility::writev(dc->d_socket, iov, 2);
+  int wret = Utility::writev(comboWriter->d_socket, iov.data(), iov.size());
   bool hadError = true;
 
   if (wret == 0) {
-    g_log << Logger::Warning << "EOF writing TCP answer to " << dc->getRemote() << endl;
+    g_log << Logger::Warning << "EOF writing TCP answer to " << comboWriter->getRemote() << endl;
   }
   else if (wret < 0) {
     int err = errno;
-    g_log << Logger::Warning << "Error writing TCP answer to " << dc->getRemote() << ": " << strerror(err) << endl;
+    g_log << Logger::Warning << "Error writing TCP answer to " << comboWriter->getRemote() << ": " << stringerror(err) << endl;
   }
   else if ((unsigned int)wret != 2 + packet.size()) {
-    g_log << Logger::Warning << "Oops, partial answer sent to " << dc->getRemote() << " for " << dc->d_mdp.d_qname << " (size=" << (2 + packet.size()) << ", sent " << wret << ")" << endl;
+    g_log << Logger::Warning << "Oops, partial answer sent to " << comboWriter->getRemote() << " for " << comboWriter->d_mdp.d_qname << " (size=" << (2 + packet.size()) << ", sent " << wret << ")" << endl;
   }
   else {
     hadError = false;
@@ -530,7 +518,7 @@ public:
     return deferredAdds;
   }
 
-  const ThreadPipeSet& getPipes() const
+  [[nodiscard]] const ThreadPipeSet& getPipes() const
   {
     return pipes;
   }
@@ -635,7 +623,7 @@ bool checkForCacheHit(bool qnameParsed, unsigned int tag, const string& data,
                       RecursorPacketCache::OptPBData& pbData, bool tcp, const ComboAddress& source, const ComboAddress& mappedSource);
 void protobufLogResponse(pdns::ProtoZero::RecMessage& message);
 void protobufLogResponse(const DNSName& qname, QType qtype, const struct dnsheader* header, LocalStateHolder<LuaConfigItems>& luaconfsLocal,
-                         const RecursorPacketCache::OptPBData& pbData, const struct timeval& tv,
+                         const RecursorPacketCache::OptPBData& pbData, const struct timeval& tval,
                          bool tcp, const ComboAddress& source, const ComboAddress& destination,
                          const ComboAddress& mappedSource, const EDNSSubnetOpts& ednssubnet,
                          const boost::uuids::uuid& uniqueId, const string& requestorId, const string& deviceId,
@@ -661,12 +649,12 @@ void startLuaConfigDelayedThreads(const LuaConfigItems& luaConfig, uint64_t gene
 void activateLuaConfig(LuaConfigItems& lci);
 unsigned int authWaitTimeMSec(const std::unique_ptr<MT_t>& mtasker);
 
-#define LOCAL_NETS "127.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 169.254.0.0/16, 192.168.0.0/16, 172.16.0.0/12, ::1/128, fc00::/7, fe80::/10"
-#define LOCAL_NETS_INVERSE "!127.0.0.0/8, !10.0.0.0/8, !100.64.0.0/10, !169.254.0.0/16, !192.168.0.0/16, !172.16.0.0/12, !::1/128, !fc00::/7, !fe80::/10"
+static const std::string LOCAL_NETS = "127.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 169.254.0.0/16, 192.168.0.0/16, 172.16.0.0/12, ::1/128, fc00::/7, fe80::/10";
+static const std::string LOCAL_NETS_INVERSE = "!127.0.0.0/8, !10.0.0.0/8, !100.64.0.0/10, !169.254.0.0/16, !192.168.0.0/16, !172.16.0.0/12, !::1/128, !fc00::/7, !fe80::/10";
 // Bad Nets taken from both:
 // http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
 // and
 // http://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
 // where such a network may not be considered a valid destination
-#define BAD_NETS "0.0.0.0/8, 192.0.0.0/24, 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24, 240.0.0.0/4, ::/96, ::ffff:0:0/96, 100::/64, 2001:db8::/32"
-#define DONT_QUERY LOCAL_NETS ", " BAD_NETS
+static const std::string BAD_NETS = "0.0.0.0/8, 192.0.0.0/24, 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24, 240.0.0.0/4, ::/96, ::ffff:0:0/96, 100::/64, 2001:db8::/32";
+static const std::string DONT_QUERY = LOCAL_NETS + ", " + BAD_NETS;
index aa905b2ea1ab81ea3538d86d33f2d292d05c9112..2a349205e4e813fc821f582604c519fb651d8686 100644 (file)
@@ -950,8 +950,6 @@ using addrringbuf_t = boost::circular_buffer<ComboAddress>;
 extern thread_local std::unique_ptr<addrringbuf_t> t_servfailremotes, t_largeanswerremotes, t_remotes, t_bogusremotes, t_timeouts;
 
 extern thread_local std::unique_ptr<boost::circular_buffer<pair<DNSName, uint16_t>>> t_queryring, t_servfailqueryring, t_bogusqueryring;
-extern thread_local std::shared_ptr<NetmaskGroup> t_allowFrom;
-extern thread_local std::shared_ptr<NetmaskGroup> t_allowNotifyFrom;
 extern unsigned int g_networkTimeoutMsec;
 extern uint16_t g_outgoingEDNSBufsize;
 extern std::atomic<uint32_t> g_maxCacheEntries, g_maxPacketCacheEntries;