From: Remi Gacogne Date: Tue, 20 Aug 2024 11:04:11 +0000 (+0200) Subject: dnsdist: Return a valid unix timestamp for Dynamic Block's `until` X-Git-Tag: dnsdist-1.9.7~10^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=65a0789fc16dd41d24c226cce46c04e418815c1a;p=thirdparty%2Fpdns.git dnsdist: Return a valid unix timestamp for Dynamic Block's `until` 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) --- diff --git a/pdns/dnsdist-lua-inspection.cc b/pdns/dnsdist-lua-inspection.cc index ba7dfdb92d..05b37978aa 100644 --- a/pdns/dnsdist-lua-inspection.cc +++ b/pdns/dnsdist-lua-inspection.cc @@ -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( + "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("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);