From: Remi Gacogne Date: Wed, 14 Dec 2022 16:29:27 +0000 (+0100) Subject: dnsdist: Store the initial query time in the internal state as well X-Git-Tag: dnsdist-1.8.0-rc1~147^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d5d15da1e3309871d7738f23d8e770d40562619f;p=thirdparty%2Fpdns.git dnsdist: Store the initial query time in the internal state as well That way it is available in the response. --- diff --git a/pdns/dnsdist-idstate.hh b/pdns/dnsdist-idstate.hh index 33699761b2..4a180af867 100644 --- a/pdns/dnsdist-idstate.hh +++ b/pdns/dnsdist-idstate.hh @@ -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 packetCache{nullptr}; // 16 std::unique_ptr dnsCryptQuery{nullptr}; // 8 std::unique_ptr qTag{nullptr}; // 8 diff --git a/pdns/dnsdist-lua-actions.cc b/pdns/dnsdist-lua-actions.cc index 12ce2793a6..b36f4bad97 100644 --- a/pdns/dnsdist-lua-actions.cc +++ b/pdns/dnsdist-lua-actions.cc @@ -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(dq->queryTime.tv_sec), static_cast(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(dq->getQueryRealTime().tv_sec), static_cast(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(dq->queryTime.tv_sec); - uint32_t tv_nsec = static_cast(dq->queryTime.tv_nsec); + uint64_t tv_sec = static_cast(dq->getQueryRealTime().tv_sec); + uint32_t tv_nsec = static_cast(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(dq->queryTime.tv_sec), static_cast(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(dq->getQueryRealTime().tv_sec), static_cast(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(dr->queryTime.tv_sec), static_cast(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(dr->getQueryRealTime().tv_sec), static_cast(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(dr->queryTime.tv_sec), static_cast(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(dr->getQueryRealTime().tv_sec), static_cast(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(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(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(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(dr->getData().data()), dr->getData().size(), &dr->getQueryRealTime(), &now); { if (d_alterFunc) { auto lock = g_lua.lock(); diff --git a/pdns/dnsdist-lua-rules.cc b/pdns/dnsdist-lua-rules.cc index 07bb3efd32..0506492e00 100644 --- a/pdns/dnsdist-lua-rules.cc +++ b/pdns/dnsdist-lua-rules.cc @@ -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 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(); }); diff --git a/pdns/dnsdist-protobuf.cc b/pdns/dnsdist-protobuf.cc index be73fb9081..29e9b84c62 100644 --- a/pdns/dnsdist-protobuf.cc +++ b/pdns/dnsdist-protobuf.cc @@ -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) { diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 150c8de657..fbb04c2d82 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -249,7 +249,7 @@ static void handleResponseSent(std::shared_ptr& 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& 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& 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; diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index d122976a4c..9a415673d6 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -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& respRuleActions, const std::vector& cacheInsertedRespRuleActions, const std::shared_ptr& ds, bool selfGenerated, std::optional 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 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 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; diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 203f1b2a70..f7111d131e 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -63,8 +63,8 @@ using QTag = std::unordered_map; 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 > ednsOptions; std::unique_ptr> 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& downstream): - DNSQuestion(ids_, data_, queryTime_), d_downstream(downstream) { } + DNSResponse(InternalQueryState& ids_, PacketBuffer& data_, const std::shared_ptr& downstream): + DNSQuestion(ids_, data_), d_downstream(downstream) { } DNSResponse(const DNSResponse&) = delete; DNSResponse& operator=(const DNSResponse&) = delete; DNSResponse(DNSResponse&&) = default; diff --git a/pdns/dnsdistdist/dnsdist-nghttp2.cc b/pdns/dnsdistdist/dnsdist-nghttp2.cc index c57a361fce..56884d0f31 100644 --- a/pdns/dnsdistdist/dnsdist-nghttp2.cc +++ b/pdns/dnsdistdist/dnsdist-nghttp2.cc @@ -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; diff --git a/pdns/dnsdistdist/dnsdist-rules.hh b/pdns/dnsdistdist/dnsdist-rules.hh index e21582fb20..fdf9edc01f 100644 --- a/pdns/dnsdistdist/dnsdist-rules.hh +++ b/pdns/dnsdistdist/dnsdist-rules.hh @@ -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; diff --git a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc index 2c5a4f3811..113f3fbbfd 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc +++ b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc @@ -668,7 +668,7 @@ IOState TCPConnectionToBackend::handleResponse(std::shared_ptrd_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; diff --git a/pdns/dnsdistdist/doh.cc b/pdns/dnsdistdist/doh.cc index ff3bea223b..9ecb25b284 100644 --- a/pdns/dnsdistdist/doh.cc +++ b/pdns/dnsdistdist/doh.cc @@ -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> localRespRuleActions = g_respruleactions.getLocal(); static thread_local LocalStateHolder> 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(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> localRespRuleActions = g_respruleactions.getLocal(); static thread_local LocalStateHolder> 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()); diff --git a/pdns/dnsdistdist/test-dnsdistkvs_cc.cc b/pdns/dnsdistdist/test-dnsdistkvs_cc.cc index 2d2f62bfe8..8c5d756d1b 100644 --- a/pdns/dnsdistdist/test-dnsdistkvs_cc.cc +++ b/pdns/dnsdistdist/test-dnsdistkvs_cc.cc @@ -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); diff --git a/pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc b/pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc index fd3bd3615f..c7e638b219 100644 --- a/pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc +++ b/pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc @@ -108,7 +108,6 @@ std::atomic 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; } diff --git a/pdns/dnsdistdist/test-dnsdistrules_cc.cc b/pdns/dnsdistdist/test-dnsdistrules_cc.cc index 6ace4199ac..b8adc5916d 100644 --- a/pdns/dnsdistdist/test-dnsdistrules_cc.cc +++ b/pdns/dnsdistdist/test-dnsdistrules_cc.cc @@ -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 */ diff --git a/pdns/test-dnsdist_cc.cc b/pdns/test-dnsdist_cc.cc index d0cc62c638..be7a43d3e6 100644 --- a/pdns/test-dnsdist_cc.cc +++ b/pdns/test-dnsdist_cc.cc @@ -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(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, &ids.qclass); - DNSQuestion dq(ids, const_cast(packet), queryTime); + DNSQuestion dq(ids, const_cast(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(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, &ids.qclass); - DNSQuestion dq(ids, const_cast(packet), queryTime); + DNSQuestion dq(ids, const_cast(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(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, &ids.qclass); - DNSQuestion dq(ids, const_cast(packet), queryTime); + DNSQuestion dq(ids, const_cast(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(packet.data()), packet.size(), sizeof(dnsheader), false, &ids.qtype, &ids.qclass); - DNSQuestion dq(ids, const_cast(packet), queryTime); + DNSQuestion dq(ids, const_cast(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 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::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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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"); diff --git a/pdns/test-dnsdistpacketcache_cc.cc b/pdns/test-dnsdistpacketcache_cc.cc index 7eea14ee19..33f6afabf7 100644 --- a/pdns/test-dnsdistpacketcache_cc.cc +++ b/pdns/test-dnsdistpacketcache_cc.cc @@ -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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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);