From 7bb5ee1f3957f197bf6ece0d0d410f5cbfb4af37 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Tue, 6 Sep 2022 16:27:07 +0200 Subject: [PATCH] Add stuct timeval queryTime to dq Lua object. This is the time the query was received. Value is the same as would be set in the protobuf message, so protobuf-use-kernel-timestamp is relevant. --- pdns/lua-recursor4.cc | 1 + pdns/lua-recursor4.hh | 1 + pdns/pdns_recursor.cc | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 1c8cbcb8a0..c0ecc8570d 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -205,6 +205,7 @@ void RecursorLua4::postPrepareContext() d_lw->registerMember("udpQueryDest", &DNSQuestion::udpQueryDest); d_lw->registerMember("udpCallback", &DNSQuestion::udpCallback); d_lw->registerMember("appliedPolicy", &DNSQuestion::appliedPolicy); + d_lw->registerMember("queryTime", &DNSQuestion::queryTime); d_lw->registerMember("policyName", [](const DNSFilterEngine::Policy& pol) -> std::string { diff --git a/pdns/lua-recursor4.hh b/pdns/lua-recursor4.hh index 2fabcc06c3..d0a476b9e0 100644 --- a/pdns/lua-recursor4.hh +++ b/pdns/lua-recursor4.hh @@ -112,6 +112,7 @@ public: bool& addPaddingToResponse; unsigned int tag{0}; std::map meta; + struct timeval queryTime; void addAnswer(uint16_t type, const std::string& content, boost::optional ttl, boost::optional name); void addRecord(uint16_t type, const std::string& content, DNSResourceRecord::Place place, boost::optional ttl, boost::optional name); diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 4469695996..7eecb655fe 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -997,6 +997,12 @@ void startDoResolve(void* p) dq.extendedErrorExtra = &dc->d_extendedErrorExtra; dq.meta = std::move(dc->d_meta); dq.fromAuthIP = &sr.d_fromAuthIP; + if (g_useKernelTimestamp && dc->d_kernelTimestamp.tv_sec != 0) { + dq.queryTime = dc->d_kernelTimestamp; + } + else { + dq.queryTime = dc->d_now; + } sr.d_slog = sr.d_slog->withValues("qname", Logging::Loggable(dc->d_mdp.d_qname), "qtype", Logging::Loggable(QType(dc->d_mdp.d_qtype)), -- 2.47.2