Skip to content

Commit

Permalink
Merge pull request #14643 from rgacogne/ddist-19-backport-14570
Browse files Browse the repository at this point in the history
dnsdist-1.9.x: Backport 14570 - Return a valid unix timestamp for Dynamic Block's `until`
  • Loading branch information
rgacogne authored Sep 10, 2024
2 parents 838bdae + 8edbd7e commit a61151f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pdns/dnsdist-lua-inspection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,28 @@ 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);

auto seconds = block.until.tv_sec - nowMonotonic.tv_sec;
auto nseconds = block.until.tv_nsec - nowMonotonic.tv_nsec;
if (nseconds < 0) {
seconds -= 1;
nseconds += 1000000000;
}

nowRealTime.tv_sec += seconds;
nowRealTime.tv_nsec += nseconds;
if (nowRealTime.tv_nsec > 1000000000) {
nowRealTime.tv_sec += 1;
nowRealTime.tv_nsec -= 1000000000;
}

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);
Expand Down

0 comments on commit a61151f

Please sign in to comment.