That way it is available in the response.
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
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);
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());
}
}
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);
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);
}
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);
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();
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();
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));
}
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();
});
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) {
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();
++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));
}
}
- /* 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;
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;
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);
}
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);
}
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);
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;
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;
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;
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;
ids.qTag->insert_or_assign(key, value);
}
+ const struct timespec& getQueryRealTime() const
+ {
+ return ids.queryRealTime.d_start;
+ }
+
protected:
PacketBuffer& data;
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;
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;
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;
bool matches(const DNSQuestion* dq) const override
{
- cleanupIfNeeded(dq->queryTime);
+ cleanupIfNeeded(dq->getQueryRealTime());
ComboAddress zeroport(dq->ids.origRemote);
zeroport.sin4.sin_port=0;
--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;
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();
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();
++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 */
}
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;
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));
}
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());
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);
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);
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");
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;
}
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");
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;
}
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 */
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);
{
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;
/* 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);
/* 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);
/* 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);
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.");
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));
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());
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.");
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));
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());
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);
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 */
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));
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);
}
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;
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 */
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);
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);
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);
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);
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);
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);
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.");
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());
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());
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());
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());
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));
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());
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());
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());
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");
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));
}
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));
}
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));
}
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);
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");
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;
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);
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);
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++;
}
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;
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);
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++;
}
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;
/* 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);
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);
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;
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);
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");
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);
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;
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);
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 {
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);
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;
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);
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
{
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++;
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 */
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);
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);
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,
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);