]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Return a valid unix timestamp for Dynamic Block's `until`
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 20 Aug 2024 11:04:11 +0000 (13:04 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 20 Aug 2024 11:07:19 +0000 (13:07 +0200)
We internally use a timestamp obtained via `CLOCK_MONOTONIC` which
is quite useless to an external observer, so convert it to a normal
unix timestamp in the Lua accessor.

pdns/dnsdistdist/dnsdist-lua-inspection.cc

index f3cef29f1e4daa4d68549e5665f0aa69fa004ba2..b9828e0e8abbfd1cd9b5f82962dfffbed780d2f8 100644 (file)
@@ -1048,7 +1048,14 @@ void setupLuaInspection(LuaContext& luaCtx)
   /* DynBlock object accessors */
   luaCtx.registerMember("reason", &DynBlock::reason);
   luaCtx.registerMember("domain", &DynBlock::domain);
-  luaCtx.registerMember("until", &DynBlock::until);
+  luaCtx.registerMember<DynBlock, timespec>(
+    "until", [](const DynBlock& block) {
+      timespec nowMonotonic{};
+      gettime(&nowMonotonic);
+      timespec nowRealTime{};
+      gettime(&nowRealTime, true);
+      nowRealTime.tv_sec += (block.until.tv_sec - nowMonotonic.tv_sec);
+      return nowRealTime; }, [](DynBlock& block, [[maybe_unused]] timespec until) {});
   luaCtx.registerMember<DynBlock, unsigned int>(
     "blocks", [](const DynBlock& block) { return block.blocks.load(); }, [](DynBlock& block, [[maybe_unused]] unsigned int blocks) {});
   luaCtx.registerMember("action", &DynBlock::action);