From d6e8cc569c95957f62b419843132f4d1cf135c98 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 29 Jun 2021 11:46:28 +0200 Subject: [PATCH] dnsdist: Pass the exact protocol around via the IDState --- pdns/dnsdist-tcp.cc | 2 +- pdns/dnsdist.cc | 2 +- pdns/dnsdist.hh | 6 ++++-- pdns/dnsdistdist/dnsdist-idstate.cc | 5 +++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 9dceeb559c..cf253caf7c 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -585,7 +585,7 @@ void IncomingTCPConnectionState::handleResponse(std::shared_ptrd_handler.isTLS() ? DNSQuestion::Protocol::DoT : DNSQuestion::Protocol::DoTCP); + DNSResponse dr = makeDNSResponseFromIDState(ids, response.d_buffer); memcpy(&response.d_cleartextDH, dr.getHeader(), sizeof(response.d_cleartextDH)); diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index f1a2fb9403..920fc78bb8 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -636,7 +636,7 @@ void responderThread(std::shared_ptr dss) dh->id = ids->origID; - DNSResponse dr = makeDNSResponseFromIDState(*ids, response, DNSQuestion::Protocol::DoUDP); + DNSResponse dr = makeDNSResponseFromIDState(*ids, response); if (dh->tc && g_truncateTC) { truncateTC(response, dr.getMaximumSize(), qnameWireLength); } diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 75c393a59d..2ec6e2c485 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -572,7 +572,7 @@ struct IDState { IDState(): sentTime(true), tempFailureTTL(boost::none) { origDest.sin4.sin_family = 0;} IDState(const IDState& orig) = delete; - IDState(IDState&& rhs): subnet(rhs.subnet), origRemote(rhs.origRemote), origDest(rhs.origDest), hopRemote(rhs.hopRemote), hopLocal(rhs.hopLocal), qname(std::move(rhs.qname)), sentTime(rhs.sentTime), dnsCryptQuery(std::move(rhs.dnsCryptQuery)), packetCache(std::move(rhs.packetCache)), qTag(std::move(rhs.qTag)), tempFailureTTL(rhs.tempFailureTTL), cs(rhs.cs), du(std::move(rhs.du)), cacheKey(rhs.cacheKey), cacheKeyNoECS(rhs.cacheKeyNoECS), origFD(rhs.origFD), delayMsec(rhs.delayMsec), qtype(rhs.qtype), qclass(rhs.qclass), origID(rhs.origID), origFlags(rhs.origFlags), ednsAdded(rhs.ednsAdded), ecsAdded(rhs.ecsAdded), skipCache(rhs.skipCache), destHarvested(rhs.destHarvested), dnssecOK(rhs.dnssecOK), useZeroScope(rhs.useZeroScope) + IDState(IDState&& rhs): subnet(rhs.subnet), origRemote(rhs.origRemote), origDest(rhs.origDest), hopRemote(rhs.hopRemote), hopLocal(rhs.hopLocal), qname(std::move(rhs.qname)), sentTime(rhs.sentTime), dnsCryptQuery(std::move(rhs.dnsCryptQuery)), packetCache(std::move(rhs.packetCache)), qTag(std::move(rhs.qTag)), tempFailureTTL(rhs.tempFailureTTL), cs(rhs.cs), du(std::move(rhs.du)), cacheKey(rhs.cacheKey), cacheKeyNoECS(rhs.cacheKeyNoECS), origFD(rhs.origFD), delayMsec(rhs.delayMsec), qtype(rhs.qtype), qclass(rhs.qclass), origID(rhs.origID), origFlags(rhs.origFlags), protocol(rhs.protocol), ednsAdded(rhs.ednsAdded), ecsAdded(rhs.ecsAdded), skipCache(rhs.skipCache), destHarvested(rhs.destHarvested), dnssecOK(rhs.dnssecOK), useZeroScope(rhs.useZeroScope) { if (rhs.isInUse()) { throw std::runtime_error("Trying to move an in-use IDState"); @@ -622,6 +622,7 @@ struct IDState qclass = rhs.qclass; origID = rhs.origID; origFlags = rhs.origFlags; + protocol = rhs.protocol; uniqueId = std::move(rhs.uniqueId); ednsAdded = rhs.ednsAdded; ecsAdded = rhs.ecsAdded; @@ -727,6 +728,7 @@ struct IDState uint16_t qclass{0}; // 2 uint16_t origID{0}; // 2 uint16_t origFlags{0}; // 2 + DNSQuestion::Protocol protocol; // 1 boost::optional uniqueId{boost::none}; // 17 (placed here to reduce the space lost to padding) bool ednsAdded{false}; bool ecsAdded{false}; @@ -1316,7 +1318,7 @@ static const size_t s_maxPacketCacheEntrySize{4096}; // don't cache responses la enum class ProcessQueryResult { Drop, SendAnswer, PassToBackend }; ProcessQueryResult processQuery(DNSQuestion& dq, ClientState& cs, LocalHolders& holders, std::shared_ptr& selectedBackend); -DNSResponse makeDNSResponseFromIDState(IDState& ids, PacketBuffer& data, DNSQuestion::Protocol proto); +DNSResponse makeDNSResponseFromIDState(IDState& ids, PacketBuffer& data); void setIDStateFromDNSQuestion(IDState& ids, DNSQuestion& dq, DNSName&& qname); int pickBackendSocketForSending(std::shared_ptr& state); diff --git a/pdns/dnsdistdist/dnsdist-idstate.cc b/pdns/dnsdistdist/dnsdist-idstate.cc index 978680e599..a88ab219d9 100644 --- a/pdns/dnsdistdist/dnsdist-idstate.cc +++ b/pdns/dnsdistdist/dnsdist-idstate.cc @@ -1,9 +1,9 @@ #include "dnsdist.hh" -DNSResponse makeDNSResponseFromIDState(IDState& ids, PacketBuffer& data, DNSQuestion::Protocol proto) +DNSResponse makeDNSResponseFromIDState(IDState& ids, PacketBuffer& data) { - DNSResponse dr(&ids.qname, ids.qtype, ids.qclass, &ids.origDest, &ids.origRemote, data, proto, &ids.sentTime.d_start); + DNSResponse dr(&ids.qname, ids.qtype, ids.qclass, &ids.origDest, &ids.origRemote, data, ids.protocol, &ids.sentTime.d_start); dr.origFlags = ids.origFlags; dr.ecsAdded = ids.ecsAdded; dr.ednsAdded = ids.ednsAdded; @@ -37,6 +37,7 @@ void setIDStateFromDNSQuestion(IDState& ids, DNSQuestion& dq, DNSName&& qname) ids.qname = std::move(qname); ids.qtype = dq.qtype; ids.qclass = dq.qclass; + ids.protocol = dq.protocol; ids.delayMsec = dq.delayMsec; ids.tempFailureTTL = dq.tempFailureTTL; ids.origFlags = dq.origFlags; -- 2.47.2