From ec48a28d41ad64f34a27905fb37594b48453666d Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 28 Jul 2017 15:38:29 +0200 Subject: [PATCH] dnsdist: Don't generate a fresh UUID until we really need it --- pdns/dnsdist-protobuf.cc | 4 ++-- pdns/dnsdist-tcp.cc | 3 --- pdns/dnsdist.cc | 4 ---- pdns/dnsdist.hh | 4 ++-- pdns/dnsrulactions.hh | 8 ++++++++ 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pdns/dnsdist-protobuf.cc b/pdns/dnsdist-protobuf.cc index 78724dda9..b0ba7e745 100644 --- a/pdns/dnsdist-protobuf.cc +++ b/pdns/dnsdist-protobuf.cc @@ -28,11 +28,11 @@ #ifdef HAVE_PROTOBUF #include "dnsmessage.pb.h" -DNSDistProtoBufMessage::DNSDistProtoBufMessage(const DNSQuestion& dq): DNSProtoBufMessage(Query, dq.uniqueId, dq.remote, dq.local, *dq.qname, dq.qtype, dq.qclass, dq.dh->id, dq.tcp, dq.len) +DNSDistProtoBufMessage::DNSDistProtoBufMessage(const DNSQuestion& dq): DNSProtoBufMessage(Query, dq.uniqueId ? *dq.uniqueId : t_uuidGenerator(), dq.remote, dq.local, *dq.qname, dq.qtype, dq.qclass, dq.dh->id, dq.tcp, dq.len) { }; -DNSDistProtoBufMessage::DNSDistProtoBufMessage(const DNSResponse& dr, bool includeCNAME): DNSProtoBufMessage(Response, dr.uniqueId, dr.remote, dr.local, *dr.qname, dr.qtype, dr.qclass, dr.dh->id, dr.tcp, dr.len) +DNSDistProtoBufMessage::DNSDistProtoBufMessage(const DNSResponse& dr, bool includeCNAME): DNSProtoBufMessage(Response, dr.uniqueId ? *dr.uniqueId : t_uuidGenerator(), dr.remote, dr.local, *dr.qname, dr.qtype, dr.qclass, dr.dh->id, dr.tcp, dr.len) { setQueryTime(dr.queryTime->tv_sec, dr.queryTime->tv_nsec / 1000); setResponseCode(dr.dh->rcode); diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 5d75e811a..4e3e1071a 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -331,9 +331,6 @@ void* tcpClientThread(int pipefd) unsigned int consumed = 0; DNSName qname(query, qlen, sizeof(dnsheader), false, &qtype, &qclass, &consumed); DNSQuestion dq(&qname, qtype, qclass, &dest, &ci.remote, dh, queryBuffer.capacity(), qlen, true); -#ifdef HAVE_PROTOBUF - dq.uniqueId = t_uuidGenerator(); -#endif string poolname; int delayMsec=0; diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 8bba4b3f5..01dfca48a 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1198,10 +1198,6 @@ static void processUDPQuery(ClientState& cs, LocalHolders& holders, const struct DNSName qname(query, len, sizeof(dnsheader), false, &qtype, &qclass, &consumed); DNSQuestion dq(&qname, qtype, qclass, dest.sin4.sin_family != 0 ? &dest : &cs.local, &remote, dh, queryBufferSize, len, false); -#ifdef HAVE_PROTOBUF - dq.uniqueId = t_uuidGenerator(); -#endif - string poolname; int delayMsec = 0; /* we need an accurate ("real") value for the response and diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 020e43e59..f745904b2 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -132,7 +132,7 @@ struct DNSQuestion DNSQuestion(const DNSName* name, uint16_t type, uint16_t class_, const ComboAddress* lc, const ComboAddress* rem, struct dnsheader* header, size_t bufferSize, uint16_t queryLen, bool isTcp): qname(name), qtype(type), qclass(class_), local(lc), remote(rem), dh(header), size(bufferSize), len(queryLen), ecsPrefixLength(rem->sin4.sin_family == AF_INET ? g_ECSSourcePrefixV4 : g_ECSSourcePrefixV6), tcp(isTcp), ecsOverride(g_ECSOverride) { } #ifdef HAVE_PROTOBUF - boost::uuids::uuid uniqueId; + boost::optional uniqueId; #endif const DNSName* qname; const uint16_t qtype; @@ -407,7 +407,7 @@ struct IDState std::shared_ptr dnsCryptQuery{0}; #endif #ifdef HAVE_PROTOBUF - boost::uuids::uuid uniqueId; + boost::optional uniqueId; #endif std::shared_ptr packetCache{nullptr}; const ClientState* cs{nullptr}; diff --git a/pdns/dnsrulactions.hh b/pdns/dnsrulactions.hh index 33e1d7da7..d8f22000c 100644 --- a/pdns/dnsrulactions.hh +++ b/pdns/dnsrulactions.hh @@ -1242,6 +1242,10 @@ public: DNSAction::Action operator()(DNSQuestion* dq, string* ruleresult) const override { #ifdef HAVE_PROTOBUF + if (!dq->uniqueId) { + dq->uniqueId = t_uuidGenerator(); + } + DNSDistProtoBufMessage message(*dq); { if (d_alterFunc) { @@ -1295,6 +1299,10 @@ public: DNSResponseAction::Action operator()(DNSResponse* dr, string* ruleresult) const override { #ifdef HAVE_PROTOBUF + if (!dr->uniqueId) { + dr->uniqueId = t_uuidGenerator(); + } + DNSDistProtoBufMessage message(*dr, d_includeCNAME); { if (d_alterFunc) { -- 2.40.0