]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Store the initial query time in the internal state as well
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 14 Dec 2022 16:29:27 +0000 (17:29 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 14 Dec 2022 17:17:12 +0000 (18:17 +0100)
That way it is available in the response.

16 files changed:
pdns/dnsdist-idstate.hh
pdns/dnsdist-lua-actions.cc
pdns/dnsdist-lua-rules.cc
pdns/dnsdist-protobuf.cc
pdns/dnsdist-tcp.cc
pdns/dnsdist.cc
pdns/dnsdist.hh
pdns/dnsdistdist/dnsdist-nghttp2.cc
pdns/dnsdistdist/dnsdist-rules.hh
pdns/dnsdistdist/dnsdist-tcp-downstream.cc
pdns/dnsdistdist/doh.cc
pdns/dnsdistdist/test-dnsdistkvs_cc.cc
pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc
pdns/dnsdistdist/test-dnsdistrules_cc.cc
pdns/test-dnsdist_cc.cc
pdns/test-dnsdistpacketcache_cc.cc

index 33699761b2c2ca005a2662af42e8ea7f10b35fba..4a180af8676d0b58d6973ce4d9d55168a8bb49f6 100644 (file)
@@ -118,7 +118,7 @@ struct InternalQueryState
   ComboAddress hopLocal;
   DNSName qname; // 24
   std::string poolName; // 24
-  StopWatch sentTime; // 16
+  StopWatch queryRealTime{true}; // 16
   std::shared_ptr<DNSDistPacketCache> packetCache{nullptr}; // 16
   std::unique_ptr<DNSCryptQuery> dnsCryptQuery{nullptr}; // 8
   std::unique_ptr<QTag> qTag{nullptr}; // 8
index 12ce2793a6e2d911107eb1c48b5b0eff6c602012..b36f4bad973217c134adc52cb1042b243f50d30c 100644 (file)
@@ -1045,7 +1045,7 @@ public:
     if (!fp) {
       if (!d_verboseOnly || g_verbose) {
         if (d_includeTimestamp) {
-          infolog("[%u.%u] Packet from %s for %s %s with id %d", static_cast<unsigned long long>(dq->queryTime.tv_sec), static_cast<unsigned long>(dq->queryTime.tv_nsec), dq->ids.origRemote.toStringWithPort(), dq->ids.qname.toString(), QType(dq->ids.qtype).toString(), dq->getHeader()->id);
+          infolog("[%u.%u] Packet from %s for %s %s with id %d", static_cast<unsigned long long>(dq->getQueryRealTime().tv_sec), static_cast<unsigned long>(dq->getQueryRealTime().tv_nsec), dq->ids.origRemote.toStringWithPort(), dq->ids.qname.toString(), QType(dq->ids.qtype).toString(), dq->getHeader()->id);
         }
         else {
           infolog("Packet from %s for %s %s with id %d", dq->ids.origRemote.toStringWithPort(), dq->ids.qname.toString(), QType(dq->ids.qtype).toString(), dq->getHeader()->id);
@@ -1056,8 +1056,8 @@ public:
       if (d_binary) {
         const auto& out = dq->ids.qname.getStorage();
         if (d_includeTimestamp) {
-          uint64_t tv_sec = static_cast<uint64_t>(dq->queryTime.tv_sec);
-          uint32_t tv_nsec = static_cast<uint32_t>(dq->queryTime.tv_nsec);
+          uint64_t tv_sec = static_cast<uint64_t>(dq->getQueryRealTime().tv_sec);
+          uint32_t tv_nsec = static_cast<uint32_t>(dq->getQueryRealTime().tv_nsec);
           fwrite(&tv_sec, sizeof(tv_sec), 1, fp.get());
           fwrite(&tv_nsec, sizeof(tv_nsec), 1, fp.get());
         }
@@ -1076,7 +1076,7 @@ public:
       }
       else {
         if (d_includeTimestamp) {
-          fprintf(fp.get(), "[%llu.%lu] Packet from %s for %s %s with id %d\n", static_cast<unsigned long long>(dq->queryTime.tv_sec), static_cast<unsigned long>(dq->queryTime.tv_nsec), dq->ids.origRemote.toStringWithPort().c_str(), dq->ids.qname.toString().c_str(), QType(dq->ids.qtype).toString().c_str(), dq->getHeader()->id);
+          fprintf(fp.get(), "[%llu.%lu] Packet from %s for %s %s with id %d\n", static_cast<unsigned long long>(dq->getQueryRealTime().tv_sec), static_cast<unsigned long>(dq->getQueryRealTime().tv_nsec), dq->ids.origRemote.toStringWithPort().c_str(), dq->ids.qname.toString().c_str(), QType(dq->ids.qtype).toString().c_str(), dq->getHeader()->id);
         }
         else {
           fprintf(fp.get(), "Packet from %s for %s %s with id %d\n", dq->ids.origRemote.toStringWithPort().c_str(), dq->ids.qname.toString().c_str(), QType(dq->ids.qtype).toString().c_str(), dq->getHeader()->id);
@@ -1157,7 +1157,7 @@ public:
     if (!fp) {
       if (!d_verboseOnly || g_verbose) {
         if (d_includeTimestamp) {
-          infolog("[%u.%u] Answer to %s for %s %s (%s) with id %d", static_cast<unsigned long long>(dr->queryTime.tv_sec), static_cast<unsigned long>(dr->queryTime.tv_nsec), dr->ids.origRemote.toStringWithPort(), dr->ids.qname.toString(), QType(dr->ids.qtype).toString(), RCode::to_s(dr->getHeader()->rcode), dr->getHeader()->id);
+          infolog("[%u.%u] Answer to %s for %s %s (%s) with id %d", static_cast<unsigned long long>(dr->getQueryRealTime().tv_sec), static_cast<unsigned long>(dr->getQueryRealTime().tv_nsec), dr->ids.origRemote.toStringWithPort(), dr->ids.qname.toString(), QType(dr->ids.qtype).toString(), RCode::to_s(dr->getHeader()->rcode), dr->getHeader()->id);
         }
         else {
           infolog("Answer to %s for %s %s (%s) with id %d", dr->ids.origRemote.toStringWithPort(), dr->ids.qname.toString(), QType(dr->ids.qtype).toString(), RCode::to_s(dr->getHeader()->rcode), dr->getHeader()->id);
@@ -1166,7 +1166,7 @@ public:
     }
     else {
       if (d_includeTimestamp) {
-        fprintf(fp.get(), "[%llu.%lu] Answer to %s for %s %s (%s) with id %d\n", static_cast<unsigned long long>(dr->queryTime.tv_sec), static_cast<unsigned long>(dr->queryTime.tv_nsec), dr->ids.origRemote.toStringWithPort().c_str(), dr->ids.qname.toString().c_str(), QType(dr->ids.qtype).toString().c_str(), RCode::to_s(dr->getHeader()->rcode).c_str(), dr->getHeader()->id);
+        fprintf(fp.get(), "[%llu.%lu] Answer to %s for %s %s (%s) with id %d\n", static_cast<unsigned long long>(dr->getQueryRealTime().tv_sec), static_cast<unsigned long>(dr->getQueryRealTime().tv_nsec), dr->ids.origRemote.toStringWithPort().c_str(), dr->ids.qname.toString().c_str(), QType(dr->ids.qtype).toString().c_str(), RCode::to_s(dr->getHeader()->rcode).c_str(), dr->getHeader()->id);
       }
       else {
         fprintf(fp.get(), "Answer to %s for %s %s (%s) with id %d\n", dr->ids.origRemote.toStringWithPort().c_str(), dr->ids.qname.toString().c_str(), QType(dr->ids.qtype).toString().c_str(), RCode::to_s(dr->getHeader()->rcode).c_str(), dr->getHeader()->id);
@@ -1438,7 +1438,7 @@ public:
     data.clear();
 
     DnstapMessage::ProtocolType protocol = ProtocolToDNSTap(dq->getProtocol());
-    DnstapMessage message(data, !dq->getHeader()->qr ? DnstapMessage::MessageType::client_query : DnstapMessage::MessageType::client_response, d_identity, &dq->ids.origRemote, &dq->ids.origDest, protocol, reinterpret_cast<const char*>(dq->getData().data()), dq->getData().size(), &dq->queryTime, nullptr);
+    DnstapMessage message(data, !dq->getHeader()->qr ? DnstapMessage::MessageType::client_query : DnstapMessage::MessageType::client_response, d_identity, &dq->ids.origRemote, &dq->ids.origDest, protocol, reinterpret_cast<const char*>(dq->getData().data()), dq->getData().size(), &dq->getQueryRealTime(), nullptr);
     {
       if (d_alterFunc) {
         auto lock = g_lua.lock();
@@ -1571,7 +1571,7 @@ public:
     data.clear();
 
     DnstapMessage::ProtocolType protocol = ProtocolToDNSTap(dr->getProtocol());
-    DnstapMessage message(data, DnstapMessage::MessageType::client_response, d_identity, &dr->ids.origRemote, &dr->ids.origDest, protocol, reinterpret_cast<const char*>(dr->getData().data()), dr->getData().size(), &dr->queryTime, &now);
+    DnstapMessage message(data, DnstapMessage::MessageType::client_response, d_identity, &dr->ids.origRemote, &dr->ids.origDest, protocol, reinterpret_cast<const char*>(dr->getData().data()), dr->getData().size(), &dr->getQueryRealTime(), &now);
     {
       if (d_alterFunc) {
         auto lock = g_lua.lock();
index 07bb3efd32367365b13ec0e42ce948f76b2aebf6..0506492e00339170f94ac9a64673f5bcac44a6da 100644 (file)
@@ -461,6 +461,7 @@ void setupLuaRules(LuaContext& luaCtx)
         i.ids.protocol = dnsdist::Protocol::DoUDP;
         i.ids.origRemote = ComboAddress("127.0.0.1");
         i.ids.origRemote.sin4.sin_addr.s_addr = random();
+        i.ids.queryRealTime.start();
         GenericDNSPacketWriter<PacketBuffer> pw(i.packet, i.ids.qname, i.ids.qtype);
         items.push_back(std::move(i));
       }
@@ -471,13 +472,13 @@ void setupLuaRules(LuaContext& luaCtx)
       sw.start();
       for (unsigned int n = 0; n < times; ++n) {
         item& i = items[n % items.size()];
-        DNSQuestion dq(i.ids, i.packet, sw.d_start);
+        DNSQuestion dq(i.ids, i.packet);
 
         if (rule->matches(&dq)) {
           matches++;
         }
       }
-      double udiff=sw.udiff();
+      double udiff = sw.udiff();
       g_outputBuffer=(boost::format("Had %d matches out of %d, %.1f qps, in %.1f usec\n") % matches % times % (1000000*(1.0*times/udiff)) % udiff).str();
 
     });
index be73fb9081972e34477dbde28d95dbac6e9bdba6..29e9b84c62eb4fe8c3a5bd4ad1ee81ff2fbcad1b 100644 (file)
@@ -164,7 +164,7 @@ void DNSDistProtoBufMessage::serialize(std::string& data) const
     m.setQueryTime(d_queryTime->first, d_queryTime->second);
   }
   else {
-    m.setQueryTime(d_dq.queryTime.tv_sec, d_dq.queryTime.tv_nsec / 1000);
+    m.setQueryTime(d_dq.getQueryRealTime().tv_sec, d_dq.getQueryRealTime().tv_nsec / 1000);
   }
 
   if (d_dr != nullptr) {
index 150c8de657196c6b047f9b8841ff16a1d8ac0b3f..fbb04c2d82dda1d91e82b109b2053e29a704036b 100644 (file)
@@ -249,7 +249,7 @@ static void handleResponseSent(std::shared_ptr<IncomingTCPConnectionState>& stat
   if (currentResponse.d_selfGenerated == false && currentResponse.d_connection && currentResponse.d_connection->getDS()) {
     const auto& ds = currentResponse.d_connection->getDS();
     const auto& ids = currentResponse.d_idstate;
-    double udiff = ids.sentTime.udiff();
+    double udiff = ids.queryRealTime.udiff();
     vinfolog("Got answer from %s, relayed to %s (%s, %d bytes), took %f usec", ds->d_config.remote.toStringWithPort(), ids.origRemote.toStringWithPort(), (state->d_handler.isTLS() ? "DoT" : "TCP"), currentResponse.d_buffer.size(), udiff);
 
     auto backendProtocol = ds->getProtocol();
@@ -539,7 +539,7 @@ void IncomingTCPConnectionState::handleResponse(const struct timeval& now, TCPRe
       ++response.d_connection->getDS()->responses;
     }
 
-    DNSResponse dr(ids, response.d_buffer, ids.sentTime.d_start, response.d_connection->getDS());
+    DNSResponse dr(ids, response.d_buffer, response.d_connection->getDS());
 
     memcpy(&response.d_cleartextDH, dr.getHeader(), sizeof(response.d_cleartextDH));
 
@@ -647,17 +647,13 @@ static void handleQuery(std::shared_ptr<IncomingTCPConnectionState>& state, cons
     }
   }
 
-  /* we need an accurate ("real") value for the response and
-     to store into the IDS, but not for insertion into the
-     rings for example */
-  struct timespec queryRealTime;
-  gettime(&queryRealTime, true);
   InternalQueryState ids;
   ids.origDest = state->d_proxiedDestination;
   ids.origRemote = state->d_proxiedRemote;
   ids.cs = state->d_ci.cs;
+  ids.queryRealTime.start();
 
-  auto dnsCryptResponse = checkDNSCryptQuery(*state->d_ci.cs, state->d_buffer, ids.dnsCryptQuery, queryRealTime.tv_sec, true);
+  auto dnsCryptResponse = checkDNSCryptQuery(*state->d_ci.cs, state->d_buffer, ids.dnsCryptQuery, ids.queryRealTime.d_start.tv_sec, true);
   if (dnsCryptResponse) {
     TCPResponse response;
     state->d_state = IncomingTCPConnectionState::State::idle;
@@ -696,7 +692,7 @@ static void handleQuery(std::shared_ptr<IncomingTCPConnectionState>& state, cons
     ids.protocol = dnsdist::Protocol::DoT;
   }
 
-  DNSQuestion dq(ids, state->d_buffer, queryRealTime);
+  DNSQuestion dq(ids, state->d_buffer);
   const uint16_t* flags = getFlagsFromDNSHeader(dq.getHeader());
   ids.origFlags = *flags;
 
index d122976a4c7142dfe6934c18961ed66bb018cfd5..9a415673d691caa5f6f53928e358a488a6a3d23b 100644 (file)
@@ -636,7 +636,7 @@ void handleResponseSent(const DNSName& qname, const QType& qtype, double udiff,
 
 static void handleResponseForUDPClient(InternalQueryState& ids, PacketBuffer& response, uint16_t maxPayloadSize, const std::vector<DNSDistResponseRuleAction>& respRuleActions, const std::vector<DNSDistResponseRuleAction>& cacheInsertedRespRuleActions, const std::shared_ptr<DownstreamState>& ds, bool selfGenerated, std::optional<uint16_t> queryId)
 {
-  DNSResponse dr(ids, response, ids.sentTime.d_start, ds);
+  DNSResponse dr(ids, response, ds);
 
   if (maxPayloadSize > 0 && response.size() > maxPayloadSize) {
     vinfolog("Got a response of size %d while the initial UDP payload size was %d, truncating", response.size(), maxPayloadSize);
@@ -673,7 +673,7 @@ static void handleResponseForUDPClient(InternalQueryState& ids, PacketBuffer& re
   }
 
   if (!selfGenerated) {
-    double udiff = ids.sentTime.udiff();
+    double udiff = ids.queryRealTime.udiff();
     if (!muted) {
       vinfolog("Got answer from %s, relayed to %s (UDP), took %f usec", ds->d_config.remote.toStringWithPort(), ids.origRemote.toStringWithPort(), udiff);
     }
@@ -778,7 +778,7 @@ void responderThread(std::shared_ptr<DownstreamState> dss)
         dh->id = ids->internal.origID;
         ++dss->responses;
 
-        double udiff = ids->internal.sentTime.udiff();
+        double udiff = ids->internal.queryRealTime.udiff();
         // do that _before_ the processing, otherwise it's not fair to the backend
         dss->latencyUsec = (127.0 * dss->latencyUsec / 128.0) + udiff / 128.0;
         dss->reportResponse(dh->rcode);
@@ -1254,7 +1254,7 @@ static void queueResponse(const ClientState& cs, const PacketBuffer& response, c
 static bool prepareOutgoingResponse(LocalHolders& holders, ClientState& cs, DNSQuestion& dq, bool cacheHit)
 {
   std::shared_ptr<DownstreamState> ds{nullptr};
-  DNSResponse dr(dq.ids, dq.getMutableData(), dq.queryTime, ds);
+  DNSResponse dr(dq.ids, dq.getMutableData(), ds);
 
   if (!applyRulesToResponse(cacheHit ? *holders.cacheHitRespRuleactions : *holders.selfAnsweredRespRuleactions, dr)) {
     return false;
@@ -1587,13 +1587,9 @@ static void processUDPQuery(ClientState& cs, LocalHolders& holders, const struct
       return;
     }
 
-    /* we need an accurate ("real") value for the response and
-       to store into the IDS, but not for insertion into the
-       rings for example */
-    struct timespec queryRealTime;
-    gettime(&queryRealTime, true);
+    ids.queryRealTime.start();
 
-    auto dnsCryptResponse = checkDNSCryptQuery(cs, query, ids.dnsCryptQuery, queryRealTime.tv_sec, false);
+    auto dnsCryptResponse = checkDNSCryptQuery(cs, query, ids.dnsCryptQuery, ids.queryRealTime.d_start.tv_sec, false);
     if (dnsCryptResponse) {
       sendUDPResponse(cs.udpFD, query, 0, dest, remote);
       return;
@@ -1623,7 +1619,7 @@ static void processUDPQuery(ClientState& cs, LocalHolders& holders, const struct
     if (ids.dnsCryptQuery) {
       ids.protocol = dnsdist::Protocol::DNSCryptUDP;
     }
-    DNSQuestion dq(ids, query, queryRealTime);
+    DNSQuestion dq(ids, query);
     const uint16_t* flags = getFlagsFromDNSHeader(dq.getHeader());
     ids.origFlags = *flags;
 
index 203f1b2a706094765a43f6c58e3f623ff7ee7254..f7111d131e1a9373e1bc5866e17ff9590f6e860a 100644 (file)
@@ -63,8 +63,8 @@ using QTag = std::unordered_map<string, string>;
 
 struct DNSQuestion
 {
-  DNSQuestion(InternalQueryState& ids_, PacketBuffer& data_, const struct timespec& queryTime_):
-    data(data_), ids(ids_), queryTime(queryTime_), ecsPrefixLength(ids.origRemote.sin4.sin_family == AF_INET ? g_ECSSourcePrefixV4 : g_ECSSourcePrefixV6), ecsOverride(g_ECSOverride) {
+  DNSQuestion(InternalQueryState& ids_, PacketBuffer& data_):
+    data(data_), ids(ids_), ecsPrefixLength(ids.origRemote.sin4.sin_family == AF_INET ? g_ECSSourcePrefixV4 : g_ECSSourcePrefixV6), ecsOverride(g_ECSOverride) {
   }
   DNSQuestion(const DNSQuestion&) = delete;
   DNSQuestion& operator=(const DNSQuestion&) = delete;
@@ -134,6 +134,11 @@ struct DNSQuestion
     ids.qTag->insert_or_assign(key, value);
   }
 
+  const struct timespec& getQueryRealTime() const
+  {
+    return ids.queryRealTime.d_start;
+  }
+
 protected:
   PacketBuffer& data;
 
@@ -143,7 +148,6 @@ public:
   std::string sni; /* Server Name Indication, if any (DoT or DoH) */
   mutable std::shared_ptr<std::map<uint16_t, EDNSOptionView> > ednsOptions;
   std::unique_ptr<std::vector<ProxyProtocolValue>> proxyProtocolValues{nullptr};
-  const struct timespec& queryTime;
   uint16_t ecsPrefixLength;
   uint8_t ednsRCode{0};
   bool ecsOverride;
@@ -153,8 +157,8 @@ public:
 
 struct DNSResponse : DNSQuestion
 {
-  DNSResponse(InternalQueryState& ids_, PacketBuffer& data_, const struct timespec& queryTime_, const std::shared_ptr<DownstreamState>& downstream):
-    DNSQuestion(ids_, data_, queryTime_), d_downstream(downstream) { }
+  DNSResponse(InternalQueryState& ids_, PacketBuffer& data_, const std::shared_ptr<DownstreamState>& downstream):
+    DNSQuestion(ids_, data_), d_downstream(downstream) { }
   DNSResponse(const DNSResponse&) = delete;
   DNSResponse& operator=(const DNSResponse&) = delete;
   DNSResponse(DNSResponse&&) = default;
index c57a361fce1e488bc0b6281db13f899e353566e6..56884d0f31bca98bf63527e0eb77d5505e7d3840 100644 (file)
@@ -136,7 +136,7 @@ void DoHConnectionToBackend::handleResponse(PendingRequest&& request)
   gettimeofday(&now, nullptr);
   try {
     if (!d_healthCheckQuery) {
-      const double udiff = request.d_query.d_idstate.sentTime.udiff();
+      const double udiff = request.d_query.d_idstate.queryRealTime.udiff();
       d_ds->updateTCPLatency(udiff);
       if (request.d_buffer.size() >= sizeof(dnsheader)) {
         dnsheader dh;
index e21582fb204ce06f48b06949792b36357ce09c23..fdf9edc01f362b183c144810b16ba8b39cf79e47 100644 (file)
@@ -96,7 +96,7 @@ public:
 
   bool matches(const DNSQuestion* dq) const override
   {
-    cleanupIfNeeded(dq->queryTime);
+    cleanupIfNeeded(dq->getQueryRealTime());
 
     ComboAddress zeroport(dq->ids.origRemote);
     zeroport.sin4.sin_port=0;
index 2c5a4f3811b6b2cf5ba085cb7c3ff572b9bdba05..113f3fbbfd40575c671b3287b2d3fce7f18a32ce 100644 (file)
@@ -668,7 +668,7 @@ IOState TCPConnectionToBackend::handleResponse(std::shared_ptr<TCPConnectionToBa
 
   --conn->d_ds->outstanding;
   auto ids = std::move(it->second.d_query.d_idstate);
-  const double udiff = ids.sentTime.udiff();
+  const double udiff = ids.queryRealTime.udiff();
   conn->d_ds->updateTCPLatency(udiff);
   if (d_responseBuffer.size() >= sizeof(dnsheader)) {
     dnsheader dh;
index ff3bea223bb6e481fd1c9c086dfe12606fa92121..9ecb25b28424d4b8338da575a8ed8b5cdc2dc6e7 100644 (file)
@@ -454,7 +454,7 @@ public:
 
     du->response = std::move(response.d_buffer);
     du->ids = std::move(response.d_idstate);
-    DNSResponse dr(du->ids, du->response, du->ids.sentTime.d_start, du->downstream);
+    DNSResponse dr(du->ids, du->response, du->downstream);
 
     static thread_local LocalStateHolder<vector<DNSDistResponseRuleAction>> localRespRuleActions = g_respruleactions.getLocal();
     static thread_local LocalStateHolder<vector<DNSDistResponseRuleAction>> localCacheInsertedRespRuleActions = g_cacheInsertedRespRuleActions.getLocal();
@@ -474,7 +474,7 @@ public:
 
     du = std::move(dr.ids.du);
 
-    double udiff = du->ids.sentTime.udiff();
+    double udiff = du->ids.queryRealTime.udiff();
     vinfolog("Got answer from %s, relayed to %s (https), took %f usec", du->downstream->d_config.remote.toStringWithPort(), du->ids.origRemote.toStringWithPort(), udiff);
 
     auto backendProtocol = du->downstream->getProtocol();
@@ -585,12 +585,7 @@ static void processDOHQuery(DOHUnitUniquePtr&& unit)
 
     ++cs.queries;
     ++g_stats.queries;
-
-    /* we need an accurate ("real") value for the response and
-       to store into the IDS, but not for insertion into the
-       rings for example */
-    struct timespec queryRealTime;
-    gettime(&queryRealTime, true);
+    du->ids.queryRealTime.start();
 
     {
       /* don't keep that pointer around, it will be invalidated if the buffer is ever resized */
@@ -615,7 +610,7 @@ static void processDOHQuery(DOHUnitUniquePtr&& unit)
     }
 
     du->ids.qname = DNSName(reinterpret_cast<const char*>(du->query.data()), du->query.size(), sizeof(dnsheader), false, &du->ids.qtype, &du->ids.qclass);
-    DNSQuestion dq(du->ids, du->query, queryRealTime);
+    DNSQuestion dq(du->ids, du->query);
     const uint16_t* flags = getFlagsFromDNSHeader(dq.getHeader());
     ids.origFlags = *flags;
     du->ids.cs = &cs;
@@ -1601,7 +1596,7 @@ void handleUDPResponseForDoH(DOHUnitUniquePtr&& du, PacketBuffer&& udpResponse,
     static thread_local LocalStateHolder<vector<DNSDistResponseRuleAction>> localRespRuleActions = g_respruleactions.getLocal();
     static thread_local LocalStateHolder<vector<DNSDistResponseRuleAction>> localcacheInsertedRespRuleActions = g_cacheInsertedRespRuleActions.getLocal();
 
-    DNSResponse dr(du->ids, du->response, du->ids.sentTime.d_start, du->downstream);
+    DNSResponse dr(du->ids, du->response, du->downstream);
     dnsheader cleartextDH;
     memcpy(&cleartextDH, dr.getHeader(), sizeof(cleartextDH));
 
@@ -1615,7 +1610,7 @@ void handleUDPResponseForDoH(DOHUnitUniquePtr&& du, PacketBuffer&& udpResponse,
     }
 
     du = std::move(dr.ids.du);
-    double udiff = du->ids.sentTime.udiff();
+    double udiff = du->ids.queryRealTime.udiff();
     vinfolog("Got answer from %s, relayed to %s (https), took %f usec", du->downstream->d_config.remote.toStringWithPort(), du->ids.origRemote.toStringWithPort(), udiff);
 
     handleResponseSent(du->ids, udiff, dr.ids.origRemote, du->downstream->d_config.remote, du->response.size(), cleartextDH, du->downstream->getProtocol());
index 2d2f62bfe888ddad771a99807a9e5921cfc0b41a..8c5d756d1b8fd1390eb41816450c00e35112f1d6 100644 (file)
@@ -309,13 +309,12 @@ BOOST_AUTO_TEST_CASE(test_LMDB) {
   ids.origRemote = ComboAddress("192.0.2.128:42");
   PacketBuffer packet(sizeof(dnsheader));
   ids.protocol = dnsdist::Protocol::DoUDP;
-  struct timespec queryRealTime;
-  gettime(&queryRealTime, true);
+  ids.queryRealTime.start();
   struct timespec expiredTime;
   /* the internal QPS limiter does not use the real time */
   gettime(&expiredTime);
 
-  DNSQuestion dq(ids, packet, queryRealTime);
+  DNSQuestion dq(ids, packet);
   ComboAddress v4Masked(v4ToMask);
   ComboAddress v6Masked(v6ToMask);
   v4Masked.truncate(25);
@@ -395,13 +394,12 @@ BOOST_AUTO_TEST_CASE(test_CDB) {
   ids.origRemote = ComboAddress("192.0.2.128:42");
   PacketBuffer packet(sizeof(dnsheader));
   ids.protocol = dnsdist::Protocol::DoUDP;
-  struct timespec queryRealTime;
-  gettime(&queryRealTime, true);
+  ids.queryRealTime.start();
   struct timespec expiredTime;
   /* the internal QPS limiter does not use the real time */
   gettime(&expiredTime);
 
-  DNSQuestion dq(ids, packet, queryRealTime);
+  DNSQuestion dq(ids, packet);
   ComboAddress v4Masked(v4ToMask);
   ComboAddress v6Masked(v6ToMask);
   v4Masked.truncate(25);
index fd3bd3615fcf9a597edf24487e5d64d4db0edc86..c7e638b219674524ca5c28a00cd53ec6e609b6b9 100644 (file)
@@ -108,7 +108,6 @@ std::atomic<bool> g_configurationDone{false};
 static DNSQuestion getDQ(const DNSName* providedName = nullptr)
 {
   static const DNSName qname("powerdns.com.");
-  static struct timespec queryRealTime;
   static PacketBuffer packet(sizeof(dnsheader));
   static InternalQueryState ids;
   ids.origDest = ComboAddress("127.0.0.1:53");
@@ -117,9 +116,9 @@ static DNSQuestion getDQ(const DNSName* providedName = nullptr)
   ids.qtype = QType::A;
   ids.qclass = QClass::IN;
   ids.protocol = dnsdist::Protocol::DoUDP;
-  gettime(&queryRealTime, true);
+  ids.queryRealTime.start();
 
-  DNSQuestion dq(ids, packet, queryRealTime);
+  DNSQuestion dq(ids, packet);
   return dq;
 }
 
index 6ace4199ac9bdd880b912d649de1f9a2a9667076..b8adc5916d16fd3b61a52fd25af9a5a139cdc01a 100644 (file)
@@ -18,7 +18,6 @@ void checkParameterBound(const std::string& parameter, uint64_t value, size_t ma
 static DNSQuestion getDQ(const DNSName* providedName = nullptr)
 {
   static const DNSName qname("powerdns.com.");
-  static struct timespec queryRealTime;
   static PacketBuffer packet(sizeof(dnsheader));
   static InternalQueryState ids;
   ids.origDest = ComboAddress("127.0.0.1:53");
@@ -27,9 +26,9 @@ static DNSQuestion getDQ(const DNSName* providedName = nullptr)
   ids.qtype = QType::A;
   ids.qclass = QClass::IN;
   ids.protocol = dnsdist::Protocol::DoUDP;
-  gettime(&queryRealTime, true);
+  ids.queryRealTime.start();
 
-  DNSQuestion dq(ids, packet, queryRealTime);
+  DNSQuestion dq(ids, packet);
   return dq;
 }
 
@@ -50,14 +49,13 @@ BOOST_AUTO_TEST_CASE(test_MaxQPSIPRule) {
   ids.origDest = ComboAddress("127.0.0.1:53");
   ids.origRemote = ComboAddress("192.0.2.1:42");
   ids.protocol = dnsdist::Protocol::DoUDP;
+  ids.queryRealTime.start();
   PacketBuffer packet(sizeof(dnsheader));
-  struct timespec queryRealTime;
-  gettime(&queryRealTime, true);
   struct timespec expiredTime;
   /* the internal QPS limiter does not use the real time */
   gettime(&expiredTime);
 
-  DNSQuestion dq(ids, packet, queryRealTime);
+  DNSQuestion dq(ids, packet);
 
   for (size_t idx = 0; idx < maxQPS; idx++) {
     /* let's use different source ports, it shouldn't matter */
index d0cc62c638281d75feddbb68096fc61dd2ec7973..be7a43d3e6256d2da71497d8376a13f4965b07a5 100644 (file)
@@ -67,12 +67,11 @@ static void validateQuery(const PacketBuffer& packet, bool hasEdns=true, bool ha
 
 static void validateECS(const PacketBuffer& packet, const ComboAddress& expected)
 {
-  struct timespec queryTime;
   InternalQueryState ids;
   ids.protocol = dnsdist::Protocol::DoUDP;
   ids.origRemote = ComboAddress("::1");
   ids.qname = DNSName(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, &ids.qclass);
-  DNSQuestion dq(ids, const_cast<PacketBuffer&>(packet), queryTime);
+  DNSQuestion dq(ids, const_cast<PacketBuffer&>(packet));
   BOOST_CHECK(parseEDNSOptions(dq));
   BOOST_REQUIRE(dq.ednsOptions != nullptr);
   BOOST_CHECK_EQUAL(dq.ednsOptions->size(), 1U);
@@ -103,8 +102,6 @@ BOOST_AUTO_TEST_CASE(test_addXPF)
 {
   static const uint16_t xpfOptionCode = 65422;
 
-  struct timespec queryTime;
-  gettime(&queryTime);  // does not have to be accurate ("realTime") in tests
   DNSName name("www.powerdns.com.");
   InternalQueryState ids;
   ids.protocol = dnsdist::Protocol::DoUDP;
@@ -121,7 +118,7 @@ BOOST_AUTO_TEST_CASE(test_addXPF)
 
     /* large enough packet */
     ids.qname = DNSName(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, &ids.qclass);
-    DNSQuestion dq(ids, const_cast<PacketBuffer&>(packet), queryTime);
+    DNSQuestion dq(ids, const_cast<PacketBuffer&>(packet));
     BOOST_CHECK_EQUAL(ids.qname, name);
     BOOST_CHECK(ids.qtype == QType::A);
 
@@ -137,7 +134,7 @@ BOOST_AUTO_TEST_CASE(test_addXPF)
     /* packet is already too large for the 4096 limit over UDP */
     packet.resize(4096);
     ids.qname = DNSName(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, &ids.qclass);
-    DNSQuestion dq(ids, const_cast<PacketBuffer&>(packet), queryTime);
+    DNSQuestion dq(ids, const_cast<PacketBuffer&>(packet));
     BOOST_CHECK_EQUAL(ids.qname, name);
     BOOST_CHECK(ids.qtype == QType::A);
 
@@ -152,7 +149,7 @@ BOOST_AUTO_TEST_CASE(test_addXPF)
 
     /* packet with trailing data (overriding it) */
     ids.qname = DNSName(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, &ids.qclass);
-    DNSQuestion dq(ids, const_cast<PacketBuffer&>(packet), queryTime);
+    DNSQuestion dq(ids, const_cast<PacketBuffer&>(packet));
     BOOST_CHECK_EQUAL(ids.qname, name);
     BOOST_CHECK(ids.qtype == QType::A);
 
@@ -325,7 +322,6 @@ BOOST_AUTO_TEST_CASE(addECSWithoutEDNSAlreadyParsed)
   InternalQueryState ids;
   ids.origRemote = ComboAddress("192.0.2.1");
   ids.protocol = dnsdist::Protocol::DoUDP;
-  struct timespec queryTime;
   bool ednsAdded = false;
   bool ecsAdded = false;
   DNSName name("www.powerdns.com.");
@@ -341,7 +337,7 @@ BOOST_AUTO_TEST_CASE(addECSWithoutEDNSAlreadyParsed)
   BOOST_CHECK(ids.qtype == QType::A);
   BOOST_CHECK(ids.qclass == QClass::IN);
 
-  DNSQuestion dq(ids, packet, queryTime);
+  DNSQuestion dq(ids, packet);
   /* Parse the options before handling ECS, simulating a Lua rule asking for EDNS Options */
   BOOST_CHECK(!parseEDNSOptions(dq));
 
@@ -364,7 +360,7 @@ BOOST_AUTO_TEST_CASE(addECSWithoutEDNSAlreadyParsed)
   BOOST_CHECK_EQUAL(ids.qname, name);
   BOOST_CHECK(ids.qtype == QType::A);
   BOOST_CHECK(ids.qclass == QClass::IN);
-  DNSQuestion dq2(ids, packet, queryTime);
+  DNSQuestion dq2(ids, packet);
 
   BOOST_CHECK(handleEDNSClientSubnet(dq2, ednsAdded, ecsAdded));
   BOOST_CHECK_GT(packet.size(), query.size());
@@ -425,7 +421,6 @@ BOOST_AUTO_TEST_CASE(addECSWithEDNSNoECSAlreadyParsed) {
   InternalQueryState ids;
   ids.origRemote = ComboAddress("2001:DB8::1");
   ids.protocol = dnsdist::Protocol::DoUDP;
-  struct timespec queryTime;
   bool ednsAdded = false;
   bool ecsAdded = false;
   DNSName name("www.powerdns.com.");
@@ -443,7 +438,7 @@ BOOST_AUTO_TEST_CASE(addECSWithEDNSNoECSAlreadyParsed) {
   BOOST_CHECK(ids.qtype == QType::A);
   BOOST_CHECK(ids.qclass == QClass::IN);
 
-  DNSQuestion dq(ids, packet, queryTime);
+  DNSQuestion dq(ids, packet);
   /* Parse the options before handling ECS, simulating a Lua rule asking for EDNS Options */
   BOOST_CHECK(parseEDNSOptions(dq));
 
@@ -464,7 +459,7 @@ BOOST_AUTO_TEST_CASE(addECSWithEDNSNoECSAlreadyParsed) {
   BOOST_CHECK_EQUAL(ids.qname, name);
   BOOST_CHECK(ids.qtype == QType::A);
   BOOST_CHECK(ids.qclass == QClass::IN);
-  DNSQuestion dq2(ids, packet, queryTime);
+  DNSQuestion dq2(ids, packet);
 
   BOOST_CHECK(handleEDNSClientSubnet(dq2, ednsAdded, ecsAdded));
   BOOST_CHECK_GT(packet.size(), query.size());
@@ -521,7 +516,6 @@ BOOST_AUTO_TEST_CASE(replaceECSWithSameSizeAlreadyParsed) {
   ids.origRemote = remote;
   ids.protocol = dnsdist::Protocol::DoUDP;
   ids.qname = DNSName("www.powerdns.com.");
-  struct timespec queryTime;
 
   PacketBuffer query;
   GenericDNSPacketWriter<PacketBuffer> pw(query, ids.qname, QType::A, QClass::IN, 0);
@@ -544,7 +538,7 @@ BOOST_AUTO_TEST_CASE(replaceECSWithSameSizeAlreadyParsed) {
   BOOST_CHECK(qtype == QType::A);
   BOOST_CHECK(qclass == QClass::IN);
 
-  DNSQuestion dq(ids, packet, queryTime);
+  DNSQuestion dq(ids, packet);
   dq.ecsOverride = true;
 
   /* Parse the options before handling ECS, simulating a Lua rule asking for EDNS Options */
@@ -1423,13 +1417,13 @@ BOOST_AUTO_TEST_CASE(rewritingWithoutECSWhenLastOption) {
   validateResponse(newResponse, true, 1);
 }
 
-static DNSQuestion turnIntoResponse(InternalQueryState& ids, PacketBuffer& query, struct timespec& queryRealTime, bool resizeBuffer=true)
+static DNSQuestion turnIntoResponse(InternalQueryState& ids, PacketBuffer& query, bool resizeBuffer=true)
 {
   if (resizeBuffer) {
     query.resize(4096);
   }
 
-  auto dq = DNSQuestion(ids, query, queryRealTime);
+  auto dq = DNSQuestion(ids, query);
 
   BOOST_CHECK(addEDNSToQueryTurnedResponse(dq));
 
@@ -1445,10 +1439,9 @@ static int getZ(const DNSName& qname, const uint16_t qtype, const uint16_t qclas
   ids.qclass = qclass;
   ids.origDest = ComboAddress("127.0.0.1");
   ids.origRemote = ComboAddress("127.0.0.1");
-  struct timespec queryRealTime;
-  gettime(&queryRealTime, true);
+  ids.queryRealTime.start();
 
-  auto dq = DNSQuestion(ids, query, queryRealTime);
+  auto dq = DNSQuestion(ids, query);
 
   return getEDNSZ(dq);
 }
@@ -1556,6 +1549,7 @@ BOOST_AUTO_TEST_CASE(test_addEDNSToQueryTurnedResponse) {
   ids.qclass = QClass::IN;
   ids.origDest = ComboAddress("127.0.0.1");
   ids.origRemote = ComboAddress("127.0.0.1");
+  ids.queryRealTime.start();
   uint16_t z;
   uint16_t udpPayloadSize;
   EDNSSubnetOpts ecsOpts;
@@ -1566,8 +1560,6 @@ BOOST_AUTO_TEST_CASE(test_addEDNSToQueryTurnedResponse) {
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::COOKIE, cookiesOptionStr);
   opts.emplace_back(EDNSOptionCode::ECS, origECSOptionStr);
-  struct timespec queryRealTime;
-  gettime(&queryRealTime, true);
 
   {
     /* no EDNS */
@@ -1577,7 +1569,7 @@ BOOST_AUTO_TEST_CASE(test_addEDNSToQueryTurnedResponse) {
     pw.getHeader()->rcode = RCode::NXDomain;
     pw.commit();
 
-    auto dq = turnIntoResponse(ids, query, queryRealTime);
+    auto dq = turnIntoResponse(ids, query);
     BOOST_CHECK_EQUAL(getEDNSZ(dq), 0);
     BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(dq.getData().data()), dq.getData().size(), &udpPayloadSize, &z), false);
     BOOST_CHECK_EQUAL(z, 0);
@@ -1592,7 +1584,7 @@ BOOST_AUTO_TEST_CASE(test_addEDNSToQueryTurnedResponse) {
     pw.commit();
 
     query.resize(query.size() - (/* RDLEN */ sizeof(uint16_t) + /* last byte of TTL / Z */ 1));
-    auto dq = turnIntoResponse(ids, query, queryRealTime, false);
+    auto dq = turnIntoResponse(ids, query, false);
     BOOST_CHECK_EQUAL(getEDNSZ(dq), 0);
     BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(dq.getData().data()), dq.getData().size(), &udpPayloadSize, &z), false);
     BOOST_CHECK_EQUAL(z, 0);
@@ -1606,7 +1598,7 @@ BOOST_AUTO_TEST_CASE(test_addEDNSToQueryTurnedResponse) {
     pw.addOpt(512, 0, 0);
     pw.commit();
 
-    auto dq = turnIntoResponse(ids, query, queryRealTime);
+    auto dq = turnIntoResponse(ids, query);
     BOOST_CHECK_EQUAL(getEDNSZ(dq), 0);
     BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(dq.getData().data()), dq.getData().size(), &udpPayloadSize, &z), true);
     BOOST_CHECK_EQUAL(z, 0);
@@ -1620,7 +1612,7 @@ BOOST_AUTO_TEST_CASE(test_addEDNSToQueryTurnedResponse) {
     pw.addOpt(512, 0, EDNS_HEADER_FLAG_DO);
     pw.commit();
 
-    auto dq = turnIntoResponse(ids, query, queryRealTime);
+    auto dq = turnIntoResponse(ids, query);
     BOOST_CHECK_EQUAL(getEDNSZ(dq), EDNS_HEADER_FLAG_DO);
     BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(dq.getData().data()), dq.getData().size(), &udpPayloadSize, &z), true);
     BOOST_CHECK_EQUAL(z, EDNS_HEADER_FLAG_DO);
@@ -1634,7 +1626,7 @@ BOOST_AUTO_TEST_CASE(test_addEDNSToQueryTurnedResponse) {
     pw.addOpt(512, 0, 0, opts);
     pw.commit();
 
-    auto dq = turnIntoResponse(ids, query, queryRealTime);
+    auto dq = turnIntoResponse(ids, query);
     BOOST_CHECK_EQUAL(getEDNSZ(dq), 0);
     BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(dq.getData().data()), dq.getData().size(), &udpPayloadSize, &z), true);
     BOOST_CHECK_EQUAL(z, 0);
@@ -1648,7 +1640,7 @@ BOOST_AUTO_TEST_CASE(test_addEDNSToQueryTurnedResponse) {
     pw.addOpt(512, 0, EDNS_HEADER_FLAG_DO, opts);
     pw.commit();
 
-    auto dq = turnIntoResponse(ids, query, queryRealTime);
+    auto dq = turnIntoResponse(ids, query);
     BOOST_CHECK_EQUAL(getEDNSZ(dq), EDNS_HEADER_FLAG_DO);
     BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(dq.getData().data()), dq.getData().size(), &udpPayloadSize, &z), true);
     BOOST_CHECK_EQUAL(z, EDNS_HEADER_FLAG_DO);
@@ -1905,8 +1897,6 @@ BOOST_AUTO_TEST_CASE(test_setNegativeAndAdditionalSOA) {
   ids.origRemote = ComboAddress("192.0.2.1");
   ids.protocol = dnsdist::Protocol::DoUDP;
 
-  struct timespec queryTime;
-  gettime(&queryTime);  // does not have to be accurate ("realTime") in tests
   ComboAddress remote;
   DNSName name("www.powerdns.com.");
 
@@ -1925,7 +1915,7 @@ BOOST_AUTO_TEST_CASE(test_setNegativeAndAdditionalSOA) {
     auto packet = query;
 
     ids.qname = DNSName(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, nullptr);
-    DNSQuestion dq(ids, packet, queryTime);
+    DNSQuestion dq(ids, packet);
 
     BOOST_CHECK(setNegativeAndAdditionalSOA(dq, true, DNSName("zone."), 42, DNSName("mname."), DNSName("rname."), 1, 2, 3, 4 , 5, false));
     BOOST_CHECK(packet.size() > query.size());
@@ -1947,7 +1937,7 @@ BOOST_AUTO_TEST_CASE(test_setNegativeAndAdditionalSOA) {
     auto packet = queryWithEDNS;
 
     ids.qname = DNSName(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, nullptr);
-    DNSQuestion dq(ids, packet, queryTime);
+    DNSQuestion dq(ids, packet);
 
     BOOST_CHECK(setNegativeAndAdditionalSOA(dq, true, DNSName("zone."), 42, DNSName("mname."), DNSName("rname."), 1, 2, 3, 4 , 5, false));
     BOOST_CHECK(packet.size() > queryWithEDNS.size());
@@ -1973,7 +1963,7 @@ BOOST_AUTO_TEST_CASE(test_setNegativeAndAdditionalSOA) {
     auto packet = query;
 
     ids.qname = DNSName(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, nullptr);
-    DNSQuestion dq(ids, packet, queryTime);
+    DNSQuestion dq(ids, packet);
 
     BOOST_CHECK(setNegativeAndAdditionalSOA(dq, false, DNSName("zone."), 42, DNSName("mname."), DNSName("rname."), 1, 2, 3, 4 , 5, false));
     BOOST_CHECK(packet.size() > query.size());
@@ -1995,7 +1985,7 @@ BOOST_AUTO_TEST_CASE(test_setNegativeAndAdditionalSOA) {
     auto packet = queryWithEDNS;
 
     ids.qname = DNSName(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, nullptr);
-    DNSQuestion dq(ids, packet, queryTime);
+    DNSQuestion dq(ids, packet);
 
     BOOST_CHECK(setNegativeAndAdditionalSOA(dq, false, DNSName("zone."), 42, DNSName("mname."), DNSName("rname."), 1, 2, 3, 4 , 5, false));
     BOOST_CHECK(packet.size() > queryWithEDNS.size());
@@ -2023,7 +2013,7 @@ BOOST_AUTO_TEST_CASE(test_setNegativeAndAdditionalSOA) {
     auto packet = query;
 
     ids.qname = DNSName(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, nullptr);
-    DNSQuestion dq(ids, packet, queryTime);
+    DNSQuestion dq(ids, packet);
 
     BOOST_CHECK(setNegativeAndAdditionalSOA(dq, true, DNSName("zone."), 42, DNSName("mname."), DNSName("rname."), 1, 2, 3, 4 ,
  5, true));
@@ -2046,7 +2036,7 @@ BOOST_AUTO_TEST_CASE(test_setNegativeAndAdditionalSOA) {
     auto packet = queryWithEDNS;
 
     ids.qname = DNSName(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, nullptr);
-    DNSQuestion dq(ids, packet, queryTime);
+    DNSQuestion dq(ids, packet);
 
     BOOST_CHECK(setNegativeAndAdditionalSOA(dq, true, DNSName("zone."), 42, DNSName("mname."), DNSName("rname."), 1, 2, 3, 4 , 5, true));
     BOOST_CHECK(packet.size() > queryWithEDNS.size());
@@ -2072,7 +2062,7 @@ BOOST_AUTO_TEST_CASE(test_setNegativeAndAdditionalSOA) {
     auto packet = query;
 
     ids.qname = DNSName(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, nullptr);
-    DNSQuestion dq(ids, packet, queryTime);
+    DNSQuestion dq(ids, packet);
 
     BOOST_CHECK(setNegativeAndAdditionalSOA(dq, false, DNSName("zone."), 42, DNSName("mname."), DNSName("rname."), 1, 2, 3, 4 , 5, true));
     BOOST_CHECK(packet.size() > query.size());
@@ -2094,7 +2084,7 @@ BOOST_AUTO_TEST_CASE(test_setNegativeAndAdditionalSOA) {
     auto packet = queryWithEDNS;
 
     ids.qname = DNSName(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, nullptr);
-    DNSQuestion dq(ids, packet, queryTime);
+    DNSQuestion dq(ids, packet);
 
     BOOST_CHECK(setNegativeAndAdditionalSOA(dq, false, DNSName("zone."), 42, DNSName("mname."), DNSName("rname."), 1, 2, 3, 4 , 5, true));
     BOOST_CHECK(packet.size() > queryWithEDNS.size());
@@ -2119,7 +2109,6 @@ BOOST_AUTO_TEST_CASE(getEDNSOptionsWithoutEDNS) {
   InternalQueryState ids;
   ids.origRemote = ComboAddress("192.168.1.25");
   ids.protocol = dnsdist::Protocol::DoUDP;
-  struct timespec queryTime;
 
   const DNSName name("www.powerdns.com.");
   const ComboAddress v4("192.0.2.1");
@@ -2138,7 +2127,7 @@ BOOST_AUTO_TEST_CASE(getEDNSOptionsWithoutEDNS) {
     uint16_t qtype;
     uint16_t qclass;
     DNSName qname(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &qtype, &qclass, &consumed);
-    DNSQuestion dq(ids, packet, queryTime);
+    DNSQuestion dq(ids, packet);
 
     BOOST_CHECK(!parseEDNSOptions(dq));
   }
@@ -2159,7 +2148,7 @@ BOOST_AUTO_TEST_CASE(getEDNSOptionsWithoutEDNS) {
     uint16_t qtype;
     uint16_t qclass;
     DNSName qname(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &qtype, &qclass, &consumed);
-    DNSQuestion dq(ids, packet, queryTime);
+    DNSQuestion dq(ids, packet);
 
     BOOST_CHECK(!parseEDNSOptions(dq));
   }
@@ -2180,7 +2169,7 @@ BOOST_AUTO_TEST_CASE(getEDNSOptionsWithoutEDNS) {
     uint16_t qtype;
     uint16_t qclass;
     DNSName qname(reinterpret_cast<const char*>(packet.data()), packet.size(), sizeof(dnsheader), false, &qtype, &qclass, &consumed);
-    DNSQuestion dq(ids, packet, queryTime);
+    DNSQuestion dq(ids, packet);
 
     BOOST_CHECK(!parseEDNSOptions(dq));
   }
@@ -2195,9 +2184,8 @@ BOOST_AUTO_TEST_CASE(test_setEDNSOption)
   ids.qname = DNSName("powerdns.com.");
   ids.qtype = QType::A;
   ids.qclass = QClass::IN;
+  ids.queryRealTime.start();
 
-  struct timespec queryRealTime;
-  gettime(&queryRealTime, true);
   struct timespec expiredTime;
   /* the internal QPS limiter does not use the real time */
   gettime(&expiredTime);
@@ -2207,7 +2195,7 @@ BOOST_AUTO_TEST_CASE(test_setEDNSOption)
   pw.addOpt(4096, 0, EDNS_HEADER_FLAG_DO);
   pw.commit();
 
-  DNSQuestion dq(ids, packet, queryRealTime);
+  DNSQuestion dq(ids, packet);
 
   std::string result;
   EDNSCookiesOpt cookiesOpt("deadbeefdeadbeef");
index 7eea14ee192020e5470755f3ded3fa019bdf16eb..33f6afabf75fb0c95af6edc17d920cd19ad7e9f8 100644 (file)
@@ -21,8 +21,6 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) {
   const size_t maxEntries = 150000;
   DNSDistPacketCache PC(maxEntries, 86400, 1);
   BOOST_CHECK_EQUAL(PC.getSize(), 0U);
-  struct timespec queryTime;
-  gettime(&queryTime);  // does not have to be accurate ("realTime") in tests
 
   size_t counter = 0;
   size_t skipped = 0;
@@ -54,7 +52,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) {
 
       uint32_t key = 0;
       boost::optional<Netmask> subnet;
-      DNSQuestion dq(ids, query, queryTime);
+      DNSQuestion dq(ids, query);
       bool found = PC.get(dq, 0, &key, subnet, dnssecOK, receivedOverUDP);
       BOOST_CHECK_EQUAL(found, false);
       BOOST_CHECK(!subnet);
@@ -85,7 +83,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) {
       pwQ.getHeader()->rd = 1;
       uint32_t key = 0;
       boost::optional<Netmask> subnet;
-      DNSQuestion dq(ids, query, queryTime);
+      DNSQuestion dq(ids, query);
       bool found = PC.get(dq, 0, &key, subnet, dnssecOK, receivedOverUDP);
       if (found == true) {
         auto removed = PC.expungeByName(ids.qname);
@@ -104,7 +102,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) {
       pwQ.getHeader()->rd = 1;
       uint32_t key = 0;
       boost::optional<Netmask> subnet;
-      DNSQuestion dq(ids, query, queryTime);
+      DNSQuestion dq(ids, query);
       if (PC.get(dq, pwQ.getHeader()->id, &key, subnet, dnssecOK, receivedOverUDP)) {
         matches++;
       }
@@ -133,8 +131,6 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSharded) {
   const size_t numberOfShards = 10;
   DNSDistPacketCache PC(maxEntries, 86400, 1, 60, 3600, 60, false, numberOfShards);
   BOOST_CHECK_EQUAL(PC.getSize(), 0U);
-  struct timespec queryTime;
-  gettime(&queryTime);  // does not have to be accurate ("realTime") in tests
 
   size_t counter = 0;
   size_t skipped = 0;
@@ -167,7 +163,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSharded) {
 
       uint32_t key = 0;
       boost::optional<Netmask> subnet;
-      DNSQuestion dq(ids, query, queryTime);
+      DNSQuestion dq(ids, query);
       bool found = PC.get(dq, 0, &key, subnet, dnssecOK, receivedOverUDP);
       BOOST_CHECK_EQUAL(found, false);
       BOOST_CHECK(!subnet);
@@ -198,7 +194,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSharded) {
       pwQ.getHeader()->rd = 1;
       uint32_t key = 0;
       boost::optional<Netmask> subnet;
-      DNSQuestion dq(ids, query, queryTime);
+      DNSQuestion dq(ids, query);
       if (PC.get(dq, pwQ.getHeader()->id, &key, subnet, dnssecOK, receivedOverUDP)) {
         matches++;
       }
@@ -238,8 +234,6 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheTCP) {
   ids.qtype = QType::A;
   ids.qclass = QClass::IN;
   ids.protocol = dnsdist::Protocol::DoUDP;
-  struct timespec queryTime;
-  gettime(&queryTime);  // does not have to be accurate ("realTime") in tests
 
   ComboAddress remote;
   bool dnssecOK = false;
@@ -266,7 +260,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheTCP) {
       /* UDP */
       uint32_t key = 0;
       boost::optional<Netmask> subnet;
-      DNSQuestion dq(ids, query, queryTime);
+      DNSQuestion dq(ids, query);
       bool found = PC.get(dq, 0, &key, subnet, dnssecOK, receivedOverUDP);
       BOOST_CHECK_EQUAL(found, false);
       BOOST_CHECK(!subnet);
@@ -282,7 +276,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheTCP) {
       uint32_t key = 0;
       boost::optional<Netmask> subnet;
       ids.protocol = dnsdist::Protocol::DoTCP;
-      DNSQuestion dq(ids, query, queryTime);
+      DNSQuestion dq(ids, query);
       bool found = PC.get(dq, 0, &key, subnet, dnssecOK, !receivedOverUDP);
       BOOST_CHECK_EQUAL(found, false);
       BOOST_CHECK(!subnet);
@@ -306,8 +300,6 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheServFailTTL) {
   ids.qtype = QType::A;
   ids.qclass = QClass::IN;
   ids.protocol = dnsdist::Protocol::DoUDP;
-  struct timespec queryTime;
-  gettime(&queryTime);  // does not have to be accurate ("realTime") in tests
 
   ComboAddress remote;
   bool dnssecOK = false;
@@ -330,7 +322,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheServFailTTL) {
 
     uint32_t key = 0;
     boost::optional<Netmask> subnet;
-    DNSQuestion dq(ids, query, queryTime);
+    DNSQuestion dq(ids, query);
     bool found = PC.get(dq, 0, &key, subnet, dnssecOK, receivedOverUDP);
     BOOST_CHECK_EQUAL(found, false);
     BOOST_CHECK(!subnet);
@@ -363,8 +355,6 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheNoDataTTL) {
   ids.qtype = QType::A;
   ids.qclass = QClass::IN;
   ids.protocol = dnsdist::Protocol::DoUDP;
-  struct timespec queryTime;
-  gettime(&queryTime);  // does not have to be accurate ("realTime") in tests
 
   try {
     DNSName name("nodata");
@@ -388,7 +378,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheNoDataTTL) {
 
     uint32_t key = 0;
     boost::optional<Netmask> subnet;
-    DNSQuestion dq(ids, query, queryTime);
+    DNSQuestion dq(ids, query);
     bool found = PC.get(dq, 0, &key, subnet, dnssecOK, receivedOverUDP);
     BOOST_CHECK_EQUAL(found, false);
     BOOST_CHECK(!subnet);
@@ -418,8 +408,6 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheNXDomainTTL) {
   ids.qtype = QType::A;
   ids.qclass = QClass::IN;
   ids.protocol = dnsdist::Protocol::DoUDP;
-  struct timespec queryTime;
-  gettime(&queryTime);  // does not have to be accurate ("realTime") in tests
 
   ComboAddress remote;
   bool dnssecOK = false;
@@ -445,7 +433,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheNXDomainTTL) {
 
     uint32_t key = 0;
     boost::optional<Netmask> subnet;
-    DNSQuestion dq(ids, query, queryTime);
+    DNSQuestion dq(ids, query);
     bool found = PC.get(dq, 0, &key, subnet, dnssecOK, receivedOverUDP);
     BOOST_CHECK_EQUAL(found, false);
     BOOST_CHECK(!subnet);
@@ -471,14 +459,11 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheTruncated) {
   const size_t maxEntries = 150000;
   DNSDistPacketCache PC(maxEntries, /* maxTTL */ 86400, /* minTTL */ 1, /* tempFailureTTL */ 60, /* maxNegativeTTL */ 1);
 
-  struct timespec queryTime;
-  gettime(&queryTime);  // does not have to be accurate ("realTime") in tests
-
   InternalQueryState ids;
   ids.qtype = QType::A;
   ids.qclass = QClass::IN;
   ids.protocol = dnsdist::Protocol::DoUDP;
-  ids.sentTime.start();  // does not have to be accurate ("realTime") in tests
+  ids.queryRealTime.start();  // does not have to be accurate ("realTime") in tests
   bool dnssecOK = false;
 
   try {
@@ -502,7 +487,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheTruncated) {
 
     uint32_t key = 0;
     boost::optional<Netmask> subnet;
-    DNSQuestion dq(ids, query, queryTime);
+    DNSQuestion dq(ids, query);
     bool found = PC.get(dq, 0, &key, subnet, dnssecOK, receivedOverUDP);
     BOOST_CHECK_EQUAL(found, false);
     BOOST_CHECK(!subnet);
@@ -532,8 +517,6 @@ static void threadMangler(unsigned int offset)
   ids.qtype = QType::A;
   ids.qclass = QClass::IN;
   ids.protocol = dnsdist::Protocol::DoUDP;
-  struct timespec queryTime;
-  gettime(&queryTime);  // does not have to be accurate ("realTime") in tests
 
   try {
     ComboAddress remote;
@@ -556,7 +539,7 @@ static void threadMangler(unsigned int offset)
 
       uint32_t key = 0;
       boost::optional<Netmask> subnet;
-      DNSQuestion dq(ids, query, queryTime);
+      DNSQuestion dq(ids, query);
       g_PC.get(dq, 0, &key, subnet, dnssecOK, receivedOverUDP);
 
       g_PC.insert(key, subnet, *(getFlagsFromDNSHeader(dq.getHeader())), dnssecOK, ids.qname, QType::A, QClass::IN, response, receivedOverUDP, 0, boost::none);
@@ -577,8 +560,6 @@ static void threadReader(unsigned int offset)
   ids.qclass = QClass::IN;
   ids.qname = DNSName("www.powerdns.com.");
   ids.protocol = dnsdist::Protocol::DoUDP;
-  struct timespec queryTime;
-  gettime(&queryTime);  // does not have to be accurate ("realTime") in tests
   bool dnssecOK = false;
   try
   {
@@ -591,7 +572,7 @@ static void threadReader(unsigned int offset)
 
       uint32_t key = 0;
       boost::optional<Netmask> subnet;
-      DNSQuestion dq(ids, query, queryTime);
+      DNSQuestion dq(ids, query);
       bool found = g_PC.get(dq, 0, &key, subnet, dnssecOK, receivedOverUDP);
       if (!found) {
        g_missing++;
@@ -652,8 +633,6 @@ BOOST_AUTO_TEST_CASE(test_PCCollision) {
   uint32_t secondKey;
   boost::optional<Netmask> subnetOut;
   bool dnssecOK = false;
-  struct timespec queryTime;
-  gettime(&queryTime);  // does not have to be accurate ("realTime") in tests
 
   /* lookup for a query with a first ECS value,
      insert a corresponding response */
@@ -670,8 +649,8 @@ BOOST_AUTO_TEST_CASE(test_PCCollision) {
     pwQ.commit();
 
     ComboAddress remote("192.0.2.1");
-    ids.sentTime.start();
-    DNSQuestion dq(ids, query, queryTime);
+    ids.queryRealTime.start();
+    DNSQuestion dq(ids, query);
     bool found = PC.get(dq, 0, &key, subnetOut, dnssecOK, receivedOverUDP);
     BOOST_CHECK_EQUAL(found, false);
     BOOST_REQUIRE(subnetOut);
@@ -712,8 +691,8 @@ BOOST_AUTO_TEST_CASE(test_PCCollision) {
     pwQ.commit();
 
     ComboAddress remote("192.0.2.1");
-    ids.sentTime.start();
-    DNSQuestion dq(ids, query, queryTime);
+    ids.queryRealTime.start();
+    DNSQuestion dq(ids, query);
     bool found = PC.get(dq, 0, &secondKey, subnetOut, dnssecOK, receivedOverUDP);
     BOOST_CHECK_EQUAL(found, false);
     BOOST_CHECK_EQUAL(secondKey, key);
@@ -777,8 +756,6 @@ BOOST_AUTO_TEST_CASE(test_PCDNSSECCollision) {
   uint16_t qid = 0x42;
   uint32_t key;
   boost::optional<Netmask> subnetOut;
-  struct timespec queryTime;
-  gettime(&queryTime);  // does not have to be accurate ("realTime") in tests
 
   /* lookup for a query with DNSSEC OK,
      insert a corresponding response with DO set,
@@ -792,9 +769,9 @@ BOOST_AUTO_TEST_CASE(test_PCDNSSECCollision) {
     pwQ.commit();
 
     ComboAddress remote("192.0.2.1");
-    ids.sentTime.start();
+    ids.queryRealTime.start();
     ids.origRemote = remote;
-    DNSQuestion dq(ids, query, queryTime);
+    DNSQuestion dq(ids, query);
     bool found = PC.get(dq, 0, &key, subnetOut, true, receivedOverUDP);
     BOOST_CHECK_EQUAL(found, false);