]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Apply suggestions from Habbie (the trivial ones first)
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 9 May 2025 09:56:53 +0000 (11:56 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 4 Sep 2025 09:05:16 +0000 (11:05 +0200)
pdns/ednscookies.cc
pdns/recursordist/lwres.cc
pdns/recursordist/lwres.hh
pdns/recursordist/rec-cookiestore.cc
pdns/recursordist/rec-cookiestore.hh
pdns/recursordist/rec-main.cc
pdns/recursordist/rec-tcpout.cc
pdns/recursordist/rec-tcpout.hh
pdns/recursordist/rec_channel_rec.cc

index 5be4a3d593ac485bb5a6a2f2ac68738b03852e1c..89350c04d016465e2ac5b65cfb840f3658895308 100644 (file)
@@ -68,7 +68,7 @@ string EDNSCookiesOpt::makeOptString() const
 string EDNSCookiesOpt::toDisplayString() const
 {
   std::ostringstream str;
-  str <<  makeHexDump(client, "");
+  str << makeHexDump(client, "");
   if (!server.empty()) {
     str << '|';
     if (server.length() != 16) {
index ebaa116295f2393f6a70dc4e388b6214e78cb9e4..1c3d095d32c1ae843860fbab254765a006124322 100644 (file)
@@ -58,7 +58,7 @@
 
 static bool g_cookies = false;
 
-void setAuthCookies(bool flag)
+void enableOutgoingCookies(bool flag)
 {
   g_cookies = flag;
 }
@@ -70,11 +70,10 @@ bool g_ECSHardening;
 
 static LockGuarded<CookieStore> s_cookiestore;
 
-std::string clearCookies()
+void clearCookies()
 {
   auto lock = s_cookiestore.lock();
   lock->clear();
-  return "";
 }
 
 void pruneCookies(time_t cutoff)
@@ -90,7 +89,7 @@ uint64_t dumpCookies(int fileDesc)
     auto lock = s_cookiestore.lock();
     copy = *lock;
   }
-  return CookieStore::dump(copy, fileDesc);
+  return copy.dump(fileDesc);
 }
 
 void remoteLoggerQueueData(RemoteLoggerInterface& rli, const std::string& data)
@@ -327,7 +326,7 @@ static bool tcpconnect(const OptLog& log, const ComboAddress& remote, const std:
 {
   dnsOverTLS = SyncRes::s_dot_to_port_853 && remote.getPort() == 853;
 
-  connection = t_tcp_manager.get(std::make_pair(remote, localBind));
+  connection = t_tcp_manager.get({remote, localBind});
   if (connection.d_handler) {
     return false;
   }
@@ -475,7 +474,7 @@ static std::pair<bool, LWResult::Result> incomingCookie(const OptLog& log, const
   auto found = lock->find(address);
 
   if (found == lock->end()) {
-    // We receivd cookie (we might have sent one out) but the server is not in the table?
+    // We received cookie (we might have sent one out) but the server is not in the table?
     // This is a case of cannot happen, unless rec_control clear-cookies was called
     VLOG(log, "Cookie from " << address.toString() << " not found back in table" << endl);
     lwr.d_rcode = RCode::FormErr;
@@ -522,7 +521,7 @@ static std::pair<bool, LWResult::Result> incomingCookie(const OptLog& log, const
       }
       else {
         VLOG(log, "Malformed cookie in reply from " << address.toString() << ", dropping as if was a timeout" << endl);
-        // Do something special if we get malformed repeatedly? And or consider current status?
+        // Do something special if we get malformed repeatedly? And/or consider current status?
         lwr.d_validpacket = false;
         ++t_Counters.at(rec::Counter::cookieMalformed);
         return {true, LWResult::Result::Timeout};
@@ -814,23 +813,23 @@ static LWResult::Result asyncresolve(const OptLog& log, const ComboAddress& addr
       if (found != lock->end()) {
         switch (found->getSupport()) {
         case CookieEntry::Support::Probing:
-          VLOG(log, "No cookie in repy from " << address.toString() << ", was probing, setting support to Unsupported" << endl);
+          VLOG(log, "No cookie in reply from " << address.toString() << ", was probing, setting support to Unsupported" << endl);
           found->setSupport(CookieEntry::Support::Unsupported, now->tv_sec);
           ++t_Counters.at(rec::Counter::cookiesUnsupported);
           break;
         case CookieEntry::Support::Unsupported:
           // We could have detected the server does not support cookies in the meantime
-          VLOG(log, "No cookie in repy from " << address.toString() << ", cookie state is Unsupported, fine" << endl);
+          VLOG(log, "No cookie in reply from " << address.toString() << ", cookie state is Unsupported, fine" << endl);
           break;
         case CookieEntry::Support::Supported:
           // RFC says: ignore replies not containing any cookie info, equivalent to timeout
-          VLOG(log, "No cookie in repy from " << address.toString() << ", cookie state is Supported, dropping packet as if it timed out)" << endl);
+          VLOG(log, "No cookie in reply from " << address.toString() << ", cookie state is Supported, dropping packet as if it timed out)" << endl);
           return LWResult::Result::Timeout;
           break;
         }
       }
       else {
-        VLOG(log, "No cookie in repy from " << address.toString() << ", cookie state is Unknown, dropping packet as if it timed out" << endl);
+        VLOG(log, "No cookie in reply from " << address.toString() << ", cookie state is Unknown, dropping packet as if it timed out" << endl);
         return LWResult::Result::Timeout;
       }
     }
index 2ca661d4e25098719357d190e338043f5560f0b5..6a7e7007ae80d3e0b9c01598c46e86159b185971 100644 (file)
@@ -100,6 +100,6 @@ LWResult::Result arecvfrom(PacketBuffer& packet, int flags, const ComboAddress&
 
 LWResult::Result asyncresolve(const OptLog& log, const ComboAddress& address, const DNSName& domain, int type, bool doTCP, bool sendRDQuery, int EDNS0Level, struct timeval* now, boost::optional<Netmask>& srcmask, const ResolveContext& context, const std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>>& outgoingLoggers, const std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>>& fstrmLoggers, const std::set<uint16_t>& exportTypes, LWResult* lwr, bool* chained);
 uint64_t dumpCookies(int fileDesc);
-std::string clearCookies();
+void clearCookies();
 void pruneCookies(time_t cutoff);
-void setAuthCookies(bool flag);
+void enableOutgoingCookies(bool flag);
index adda2ecbb37b71c78d3f3af707f1dd258c9db617..c19832d94f00dd6194e36b53bcca2bb5266982c4 100644 (file)
@@ -33,7 +33,7 @@ void CookieStore::prune(time_t cutoff)
   ind.erase(ind.begin(), ind.upper_bound(cutoff));
 }
 
-uint64_t CookieStore::dump(const CookieStore& copy, int fileDesc)
+uint64_t CookieStore::dump(int fileDesc) const
 {
   int newfd = dup(fileDesc);
   if (newfd == -1) {
@@ -47,7 +47,7 @@ uint64_t CookieStore::dump(const CookieStore& copy, int fileDesc)
   uint64_t count = 0;
 
   fprintf(filePtr.get(), "; cookie dump follows\n; server\tlocal\tcookie\tsupport\tts\n");
-  for (const auto& entry : copy) {
+  for (const auto& entry : *this) {
     count++;
     timebuf_t tmp;
     fprintf(filePtr.get(), "%s\t%s\t%s\t%s\t%s\n",
index 76b56af9f3876ca71f9a96eab60f1f983575cd5b..b51f8cc634e204a4c72028d2c9a8c9827d1f9368 100644 (file)
@@ -60,7 +60,7 @@ struct CookieEntry
 
   static std::string toString(Support support)
   {
-    static const std::array<std::string, 4> names = {
+    static const std::array<std::string, 3> names = {
       "Unsupported",
       "Supported",
       "Probing"};
@@ -100,5 +100,5 @@ class CookieStore : public multi_index_container<CookieEntry,
 {
 public:
   void prune(time_t cutoff);
-  static uint64_t dump(const CookieStore&, int fileDesc);
+  [[nodiscard]] uint64_t dump(int fileDesc) const;
 };
index 9a0645d3c42b087f3d134348f3a2fd9059ddb51c..01b6c4f6c9f34eef74c8aac5abdb625e5ff893b7 100644 (file)
@@ -2203,7 +2203,7 @@ static int serviceMain(Logr::log_t log)
   g_paddingOutgoing = ::arg().mustDo("edns-padding-out");
   g_ECSHardening = ::arg().mustDo("edns-subnet-harden");
 
-  setAuthCookies(::arg().mustDo("outgoing-cookies"));
+  enableOutgoingCookies(::arg().mustDo("outgoing-cookies"));
 
   RecThreadInfo::setNumDistributorThreads(::arg().asNum("distributor-threads"));
   RecThreadInfo::setNumUDPWorkerThreads(::arg().asNum("threads"));
index a4427771f2cac45b56b69106b5c003e1b54bb9ba..2abfb78c04bdfc2d5b3b8a809b222ad6a38fbea9 100644 (file)
@@ -51,7 +51,7 @@ void TCPOutConnectionManager::cleanup(const struct timeval& now)
   }
 }
 
-void TCPOutConnectionManager::store(const struct timeval& now, const pair_t& pair, Connection&& connection)
+void TCPOutConnectionManager::store(const struct timeval& now, const endpoints_t& pair, Connection&& connection)
 {
   ++connection.d_numqueries;
   if (s_maxQueries > 0 && connection.d_numqueries >= s_maxQueries) {
@@ -73,7 +73,7 @@ void TCPOutConnectionManager::store(const struct timeval& now, const pair_t& pai
   d_idle_connections.emplace(pair, std::move(connection));
 }
 
-TCPOutConnectionManager::Connection TCPOutConnectionManager::get(const pair_t& pair)
+TCPOutConnectionManager::Connection TCPOutConnectionManager::get(const endpoints_t& pair)
 {
   if (d_idle_connections.count(pair) > 0) {
     auto connection = d_idle_connections.extract(pair);
index 5ff80ffcecf0d2f1298ca1e74e1d21bc0e53dfff..26d973b3713a1324981b5454cb5b46e4e2557110 100644 (file)
@@ -53,10 +53,10 @@ public:
     size_t d_numqueries{0};
   };
 
-  using pair_t = std::pair<ComboAddress, std::optional<ComboAddress>>;
+  using endpoints_t = std::pair<ComboAddress, std::optional<ComboAddress>>;
 
-  void store(const struct timeval& now, const pair_t& pair, Connection&& connection);
-  Connection get(const pair_t& pair);
+  void store(const struct timeval& now, const endpoints_t& pair, Connection&& connection);
+  Connection get(const endpoints_t& pair);
   void cleanup(const struct timeval& now);
 
   [[nodiscard]] size_t size() const
@@ -71,7 +71,7 @@ public:
 private:
   // This does not take into account that we can have multiple connections with different hosts (via SNI) to the same IP.
   // That is OK, since we are connecting by IP only at the moment.
-  std::multimap<pair_t, Connection> d_idle_connections;
+  std::multimap<endpoints_t, Connection> d_idle_connections;
 };
 
 extern thread_local TCPOutConnectionManager t_tcp_manager;
index d030f956c2bc673f4f5f2caa5caafaf1889a0ad9..57f6f13a489f7944e02cd5d69a2e9471c0a8324f 100644 (file)
@@ -2108,7 +2108,8 @@ RecursorControlChannel::Answer RecursorControlParser::getAnswer(int socket, cons
     return doDumpCache(socket, begin, end);
   }
   if (cmd == "clear-cookies") {
-    return {0, clearCookies()};
+    clearCookies();
+    return {0, ""};
   }
   if (cmd == "dump-cookies") {
     return doDumpToFile(socket, pleaseDumpCookiesMap, cmd, false);