]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Expose getNSSPeedsTable() to Lua script
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 3 Jul 2025 07:07:49 +0000 (09:07 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 9 Jul 2025 09:17:19 +0000 (11:17 +0200)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/recursordist/lua-recursor4.cc
pdns/recursordist/syncres.cc
pdns/recursordist/syncres.hh

index 906d5f2c7138064161fd4a5acbd7f945be8fcbe1..a1e03ffcacda6dcf6ec82bb6069c759f0ee5c6b3 100644 (file)
@@ -523,6 +523,11 @@ void RecursorLua4::postPrepareContext() // NOLINT(readability-function-cognitive
       return {dir, name};
   });
 
+  d_lw->writeFunction("getNSSpeedTable", []() {
+    std::string ret;
+    auto number = SyncRes::getNSSpeedTable(ret);
+    return std::tuple<std::string, size_t>{ret, number};
+  });
 
   if (!d_include_path.empty()) {
     includePath(d_include_path);
index 6a0c103e25ce330ac835727a84f2632662388732..7669e75a64092906d6cab97b9bf5782c5c027e8c 100644 (file)
@@ -240,9 +240,7 @@ public:
     float ret = std::numeric_limits<float>::max();
     const float factor = iter->getFactor(now);
     for (auto& entry : iter->d_collection) {
-      if (float tmp = entry.second.get(factor); tmp < ret) {
-        ret = tmp;
-      }
+      ret = std::min(ret, entry.second.get(factor));
     }
     ind.modify(iter, [&](DecayingEwmaCollection& dec) { dec.d_lastget = now; });
     return ret;
@@ -274,7 +272,7 @@ public:
   };
 
   template <typename T, typename U>
-  void getEntry(T& message, U entry)
+  void getEntry(T& message, U entry) const
   {
     message.add_bytes(PBNSSpeedEntry::required_bytes_name, entry->d_name.toString());
     message.add_int64(PBNSSpeedEntry::required_int64_lastgets, entry->d_lastget.tv_sec);
@@ -287,7 +285,7 @@ public:
     }
   }
 
-  size_t getPB(std::string& ret)
+  size_t getPB(std::string& ret) const
   {
     protozero::pbf_builder<PBNSSpeedDump> full(ret);
     full.add_string(PBNSSpeedDump::required_string_version, getPDNSVersion());
@@ -309,6 +307,12 @@ public:
 
 static LockGuarded<nsspeeds_t> s_nsSpeeds;
 
+size_t SyncRes::getNSSpeedTable(std::string& ret)
+{
+  const auto copy = *s_nsSpeeds.lock();
+  return copy.getPB(ret);
+}
+
 class Throttle
 {
 public:
index 09242aa09cbb7f81769a2469429f8dd6a0015d68..614741abe6b208e7bd870ea4351a53c23d65aca4 100644 (file)
@@ -170,6 +170,8 @@ public:
   static uint64_t doDumpSavedParentNSSets(int fileDesc);
   static uint64_t doDumpDoTProbeMap(int fileDesc);
 
+  static size_t getNSSpeedTable(std::string& ret);
+
   static int getRootNS(struct timeval now, asyncresolve_t asyncCallback, unsigned int depth, Logr::log_t);
   static void addDontQuery(const std::string& mask)
   {