]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Allow clearing of specific entries in cookie table using rec_control
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 4 Sep 2025 10:04:04 +0000 (12:04 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 4 Sep 2025 10:04:04 +0000 (12:04 +0200)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/recursordist/docs/manpages/rec_control.1.rst
pdns/recursordist/lwres.cc
pdns/recursordist/lwres.hh
pdns/recursordist/rec_channel_rec.cc

index 921fe4a9f19dea5a40ba7990c977b0a48e59a6a0..1a57f0e85e4816dd800e0dad2c2a29636b43e1b8 100644 (file)
@@ -70,6 +70,9 @@ add-ta *DOMAIN* *DSRECORD*
 current-queries
     Shows the currently active queries.
 
+clear-cookies [*IP*...]
+    Remove entries from cookie table. If *IP* is ``*``, remove all.
+
 clear-dont-throttle-names *NAME* [*NAME*...]
     Remove names that are not allowed to be throttled. If *NAME* is ``*``, remove all
 
index 79ec6249872697779c310f3964e793c7bcbc6fc5..08020a56e6ee49d755ebb74f938f24158a4f139d 100644 (file)
@@ -70,10 +70,29 @@ bool g_ECSHardening;
 
 static LockGuarded<CookieStore> s_cookiestore;
 
-void clearCookies()
+uint64_t clearCookies(vector<string>::iterator begin, vector<string>::iterator end)
 {
   auto lock = s_cookiestore.lock();
-  lock->clear();
+  uint64_t count = 0;
+  if (begin == end) {
+    return 0;
+  }
+  if (*begin == "*") {
+    count = lock->size();
+    lock->clear();
+  }
+  else {
+    while (begin != end) {
+      try {
+        count += lock->erase(ComboAddress(*begin, 53));
+      }
+      catch (const PDNSException &) {
+        ;
+      }
+      ++begin;
+    }
+  }
+  return count;
 }
 
 void pruneCookies(time_t cutoff)
index 6a7e7007ae80d3e0b9c01598c46e86159b185971..2faada4dfec6f97af82cd75ff92afa8804d1f7a9 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);
-void clearCookies();
+uint64_t clearCookies(vector<string>::iterator begin, vector<string>::iterator end);
 void pruneCookies(time_t cutoff);
 void enableOutgoingCookies(bool flag);
index ddcfa817beefd7c269d0d77c4ba46de738aa1850..1640f4733f2c349cdaa488d6fa740e00314c371a 100644 (file)
@@ -1888,7 +1888,7 @@ static RecursorControlChannel::Answer help()
           "add-nta DOMAIN [REASON]          add a Negative Trust Anchor for DOMAIN with the comment REASON\n"
           "add-ta DOMAIN DSRECORD           add a Trust Anchor for DOMAIN with data DSRECORD\n"
           "current-queries                  show currently active queries\n"
-          // "clear-cookies                    clear cookie table\n" XXX undocumented for now
+          "clear-cookies [IP...]            clear entries from cookie table, if IP is '*' remove all entries\n"
           "clear-dont-throttle-names [N...] remove names that are not allowed to be throttled. If N is '*', remove all\n"
           "clear-dont-throttle-netmasks [N...]\n"
           "                                 remove netmasks that are not allowed to be throttled. If N is '*', remove all\n"
@@ -2108,8 +2108,8 @@ RecursorControlChannel::Answer RecursorControlParser::getAnswer(int socket, cons
     return doDumpCache(socket, begin, end);
   }
   if (cmd == "clear-cookies") {
-    clearCookies();
-    return {0, ""};
+    auto count = clearCookies(begin, end);
+    return {0, "Cleared " + std::to_string(count) + " entr" + addS(count, "y", "ies") + " from cookies table\n"};
   }
   if (cmd == "dump-cookies") {
     return doDumpToFile(socket, pleaseDumpCookiesMap, cmd, false);