]> 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>
Mon, 9 Sep 2024 14:08:06 +0000 (16:08 +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.

(cherry picked from commit 8cb758ae0c791866f8a6a4f76e41470754d04316)

pdns/dnsdist-lua-inspection.cc

index ba7dfdb92d624dee66026c5294701cc2fc6ce58b..05b37978aa010c3e2af9bd3ac726c597c9da1a37 100644 (file)
@@ -956,7 +956,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);
   luaCtx.registerMember("warning", &DynBlock::warning);