From 42123122181c2dc41b8e73274cfb4676fc747f9b Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 3 Jun 2021 18:20:33 +0200 Subject: [PATCH] dnsdist: Appease the formatting gods --- pdns/dnsdist-idstate.hh | 77 +++++++++++++---------- pdns/dnsdistdist/dnsdist-session-cache.cc | 4 +- pdns/dnsdistdist/dnsdist-tcp.hh | 22 ++++--- 3 files changed, 60 insertions(+), 43 deletions(-) diff --git a/pdns/dnsdist-idstate.hh b/pdns/dnsdist-idstate.hh index 580db0d9d2..76afc52df8 100644 --- a/pdns/dnsdist-idstate.hh +++ b/pdns/dnsdist-idstate.hh @@ -37,41 +37,50 @@ using QTag = std::unordered_map; struct StopWatch { - StopWatch(bool realTime=false): d_needRealTime(realTime) + StopWatch(bool realTime = false) : + d_needRealTime(realTime) { } - void start() { + void start() + { if (gettime(&d_start, d_needRealTime) < 0) { unixDie("Getting timestamp"); } } - void set(const struct timespec& from) { + void set(const struct timespec& from) + { d_start = from; } - double udiff() const { + double udiff() const + { struct timespec now; if (gettime(&now, d_needRealTime) < 0) { unixDie("Getting timestamp"); } - return 1000000.0*(now.tv_sec - d_start.tv_sec) + (now.tv_nsec - d_start.tv_nsec)/1000.0; + return 1000000.0 * (now.tv_sec - d_start.tv_sec) + (now.tv_nsec - d_start.tv_nsec) / 1000.0; } - double udiffAndSet() { + double udiffAndSet() + { struct timespec now; if (gettime(&now, d_needRealTime) < 0) { unixDie("Getting timestamp"); } - auto ret= 1000000.0*(now.tv_sec - d_start.tv_sec) + (now.tv_nsec - d_start.tv_nsec)/1000.0; + auto ret = 1000000.0 * (now.tv_sec - d_start.tv_sec) + (now.tv_nsec - d_start.tv_nsec) / 1000.0; d_start = now; return ret; } - struct timespec d_start{0,0}; + struct timespec d_start + { + 0, 0 + }; + private: bool d_needRealTime{false}; }; @@ -87,9 +96,11 @@ private: struct IDState { - IDState(): sentTime(true), tempFailureTTL(boost::none) { origDest.sin4.sin_family = 0;} + 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), cacheKeyUDP(rhs.cacheKeyUDP), origFD(rhs.origFD), delayMsec(rhs.delayMsec), qtype(rhs.qtype), qclass(rhs.qclass), origID(rhs.origID), origFlags(rhs.origFlags), cacheFlags(rhs.cacheFlags), protocol(rhs.protocol), 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), cacheKeyUDP(rhs.cacheKeyUDP), origFD(rhs.origFD), delayMsec(rhs.delayMsec), qtype(rhs.qtype), qclass(rhs.qclass), origID(rhs.origID), origFlags(rhs.origFlags), cacheFlags(rhs.cacheFlags), 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"); @@ -219,39 +230,39 @@ struct IDState wrapping around if necessary, and we set an atomic signed 64-bit value, so that we still have -1 when the state is unused and the value of our counter otherwise. */ - boost::optional subnet{boost::none}; // 40 - ComboAddress origRemote; // 28 - ComboAddress origDest; // 28 + boost::optional subnet{boost::none}; // 40 + ComboAddress origRemote; // 28 + ComboAddress origDest; // 28 ComboAddress hopRemote; ComboAddress hopLocal; - DNSName qname; // 24 - StopWatch sentTime; // 16 - std::shared_ptr dnsCryptQuery{nullptr}; // 16 - std::shared_ptr packetCache{nullptr}; // 16 - std::shared_ptr qTag{nullptr}; // 16 - boost::optional tempFailureTTL; // 8 - const ClientState* cs{nullptr}; // 8 - DOHUnit* du{nullptr}; // 8 - std::atomic usageIndicator{unusedIndicator}; // set to unusedIndicator to indicate this state is empty // 8 + DNSName qname; // 24 + StopWatch sentTime; // 16 + std::shared_ptr dnsCryptQuery{nullptr}; // 16 + std::shared_ptr packetCache{nullptr}; // 16 + std::shared_ptr qTag{nullptr}; // 16 + boost::optional tempFailureTTL; // 8 + const ClientState* cs{nullptr}; // 8 + DOHUnit* du{nullptr}; // 8 + std::atomic usageIndicator{unusedIndicator}; // set to unusedIndicator to indicate this state is empty // 8 std::atomic generation{0}; // increased every time a state is used, to be able to detect an ABA issue // 4 - uint32_t cacheKey{0}; // 4 - uint32_t cacheKeyNoECS{0}; // 4 + uint32_t cacheKey{0}; // 4 + uint32_t cacheKeyNoECS{0}; // 4 // DoH-only */ - uint32_t cacheKeyUDP{0}; // 4 - int origFD{-1}; // 4 + uint32_t cacheKeyUDP{0}; // 4 + int origFD{-1}; // 4 int delayMsec{0}; #ifdef __SANITIZE_THREAD__ std::atomic age{0}; #else - uint16_t age{0}; // 2 + uint16_t age{0}; // 2 #endif - uint16_t qtype{0}; // 2 - uint16_t qclass{0}; // 2 - uint16_t origID{0}; // 2 - uint16_t origFlags{0}; // 2 + uint16_t qtype{0}; // 2 + uint16_t qclass{0}; // 2 + uint16_t origID{0}; // 2 + uint16_t origFlags{0}; // 2 uint16_t cacheFlags{0}; // DNS flags as sent to the backend // 2 - dnsdist::Protocol protocol; // 1 - boost::optional uniqueId{boost::none}; // 17 (placed here to reduce the space lost to padding) + dnsdist::Protocol protocol; // 1 + boost::optional uniqueId{boost::none}; // 17 (placed here to reduce the space lost to padding) bool ednsAdded{false}; bool ecsAdded{false}; bool skipCache{false}; diff --git a/pdns/dnsdistdist/dnsdist-session-cache.cc b/pdns/dnsdistdist/dnsdist-session-cache.cc index ff7e8f6c38..be67c925d6 100644 --- a/pdns/dnsdistdist/dnsdist-session-cache.cc +++ b/pdns/dnsdistdist/dnsdist-session-cache.cc @@ -26,13 +26,11 @@ TLSSessionCache g_sessionCache; time_t const TLSSessionCache::s_cleanupDelay{60}; time_t const TLSSessionCache::s_sessionValidity{600}; - void TLSSessionCache::cleanup(time_t now, const std::lock_guard& lock) { time_t cutOff = now + s_sessionValidity; - for (auto it = d_sessions.begin(); it != d_sessions.end(); ) - { + for (auto it = d_sessions.begin(); it != d_sessions.end();) { if (it->second.d_lastUsed > cutOff || it->second.d_sessions.size() == 0) { it = d_sessions.erase(it); } diff --git a/pdns/dnsdistdist/dnsdist-tcp.hh b/pdns/dnsdistdist/dnsdist-tcp.hh index 02581e6874..99da15c094 100644 --- a/pdns/dnsdistdist/dnsdist-tcp.hh +++ b/pdns/dnsdistdist/dnsdist-tcp.hh @@ -23,10 +23,12 @@ struct ConnectionInfo { - ConnectionInfo(ClientState* cs_): cs(cs_), fd(-1) + ConnectionInfo(ClientState* cs_) : + cs(cs_), fd(-1) { } - ConnectionInfo(ConnectionInfo&& rhs): remote(rhs.remote), cs(rhs.cs), fd(rhs.fd) + ConnectionInfo(ConnectionInfo&& rhs) : + remote(rhs.remote), cs(rhs.cs), fd(rhs.fd) { rhs.cs = nullptr; rhs.fd = -1; @@ -68,7 +70,8 @@ struct InternalQuery { } - InternalQuery(PacketBuffer&& buffer, IDState&& state): d_idstate(std::move(state)), d_buffer(std::move(buffer)) + InternalQuery(PacketBuffer&& buffer, IDState&& state) : + d_idstate(std::move(state)), d_buffer(std::move(buffer)) { } @@ -118,7 +121,8 @@ struct TCPResponse : public TCPQuery memset(&d_cleartextDH, 0, sizeof(d_cleartextDH)); } - TCPResponse(PacketBuffer&& buffer, IDState&& state, std::shared_ptr conn): TCPQuery(std::move(buffer), std::move(state)), d_connection(conn) + TCPResponse(PacketBuffer&& buffer, IDState&& state, std::shared_ptr conn) : + TCPQuery(std::move(buffer), std::move(state)), d_connection(conn) { memset(&d_cleartextDH, 0, sizeof(d_cleartextDH)); } @@ -147,6 +151,7 @@ public: { return d_releaseConnection; } + protected: bool d_releaseConnection{true}; }; @@ -170,7 +175,8 @@ struct CrossProtocolQuery bool isXFR{false}; }; -class TCPClientCollection { +class TCPClientCollection +{ public: TCPClientCollection(size_t maxThreads); @@ -252,11 +258,13 @@ private: { } - TCPWorkerThread(int newConnPipe, int crossProtocolPipe): d_newConnectionPipe(newConnPipe), d_crossProtocolQueryPipe(crossProtocolPipe) + TCPWorkerThread(int newConnPipe, int crossProtocolPipe) : + d_newConnectionPipe(newConnPipe), d_crossProtocolQueryPipe(crossProtocolPipe) { } - TCPWorkerThread(TCPWorkerThread&& rhs): d_newConnectionPipe(rhs.d_newConnectionPipe), d_crossProtocolQueryPipe(rhs.d_crossProtocolQueryPipe) + TCPWorkerThread(TCPWorkerThread&& rhs) : + d_newConnectionPipe(rhs.d_newConnectionPipe), d_crossProtocolQueryPipe(rhs.d_crossProtocolQueryPipe) { rhs.d_newConnectionPipe = -1; rhs.d_crossProtocolQueryPipe = -1; -- 2.47.2