From: Otto Moerbeek Date: Tue, 6 Sep 2022 14:27:07 +0000 (+0200) Subject: Add stuct timeval queryTime to dq Lua object. X-Git-Tag: rec-4.9.0-alpha0~23^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7bb5ee1f3957f197bf6ece0d0d410f5cbfb4af37;p=thirdparty%2Fpdns.git 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. --- 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)),