From: Otto Moerbeek Date: Fri, 9 May 2025 09:56:53 +0000 (+0200) Subject: Apply suggestions from Habbie (the trivial ones first) X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0aba49a8804c7a39ef7b4b0347f11ad5ea04f898;p=thirdparty%2Fpdns.git Apply suggestions from Habbie (the trivial ones first) --- diff --git a/pdns/ednscookies.cc b/pdns/ednscookies.cc index 5be4a3d59..89350c04d 100644 --- a/pdns/ednscookies.cc +++ b/pdns/ednscookies.cc @@ -68,7 +68,7 @@ string EDNSCookiesOpt::makeOptString() const string EDNSCookiesOpt::toDisplayString() const { std::ostringstream str; - str << makeHexDump(client, ""); + str << makeHexDump(client, ""); if (!server.empty()) { str << '|'; if (server.length() != 16) { diff --git a/pdns/recursordist/lwres.cc b/pdns/recursordist/lwres.cc index ebaa11629..1c3d095d3 100644 --- a/pdns/recursordist/lwres.cc +++ b/pdns/recursordist/lwres.cc @@ -58,7 +58,7 @@ static bool g_cookies = false; -void setAuthCookies(bool flag) +void enableOutgoingCookies(bool flag) { g_cookies = flag; } @@ -70,11 +70,10 @@ bool g_ECSHardening; static LockGuarded s_cookiestore; -std::string clearCookies() +void clearCookies() { auto lock = s_cookiestore.lock(); lock->clear(); - return ""; } void pruneCookies(time_t cutoff) @@ -90,7 +89,7 @@ uint64_t dumpCookies(int fileDesc) auto lock = s_cookiestore.lock(); copy = *lock; } - return CookieStore::dump(copy, fileDesc); + return copy.dump(fileDesc); } void remoteLoggerQueueData(RemoteLoggerInterface& rli, const std::string& data) @@ -327,7 +326,7 @@ static bool tcpconnect(const OptLog& log, const ComboAddress& remote, const std: { dnsOverTLS = SyncRes::s_dot_to_port_853 && remote.getPort() == 853; - connection = t_tcp_manager.get(std::make_pair(remote, localBind)); + connection = t_tcp_manager.get({remote, localBind}); if (connection.d_handler) { return false; } @@ -475,7 +474,7 @@ static std::pair incomingCookie(const OptLog& log, const auto found = lock->find(address); if (found == lock->end()) { - // We receivd cookie (we might have sent one out) but the server is not in the table? + // We received cookie (we might have sent one out) but the server is not in the table? // This is a case of cannot happen, unless rec_control clear-cookies was called VLOG(log, "Cookie from " << address.toString() << " not found back in table" << endl); lwr.d_rcode = RCode::FormErr; @@ -522,7 +521,7 @@ static std::pair incomingCookie(const OptLog& log, const } else { VLOG(log, "Malformed cookie in reply from " << address.toString() << ", dropping as if was a timeout" << endl); - // Do something special if we get malformed repeatedly? And or consider current status? + // Do something special if we get malformed repeatedly? And/or consider current status? lwr.d_validpacket = false; ++t_Counters.at(rec::Counter::cookieMalformed); return {true, LWResult::Result::Timeout}; @@ -814,23 +813,23 @@ static LWResult::Result asyncresolve(const OptLog& log, const ComboAddress& addr if (found != lock->end()) { switch (found->getSupport()) { case CookieEntry::Support::Probing: - VLOG(log, "No cookie in repy from " << address.toString() << ", was probing, setting support to Unsupported" << endl); + VLOG(log, "No cookie in reply from " << address.toString() << ", was probing, setting support to Unsupported" << endl); found->setSupport(CookieEntry::Support::Unsupported, now->tv_sec); ++t_Counters.at(rec::Counter::cookiesUnsupported); break; case CookieEntry::Support::Unsupported: // We could have detected the server does not support cookies in the meantime - VLOG(log, "No cookie in repy from " << address.toString() << ", cookie state is Unsupported, fine" << endl); + VLOG(log, "No cookie in reply from " << address.toString() << ", cookie state is Unsupported, fine" << endl); break; case CookieEntry::Support::Supported: // RFC says: ignore replies not containing any cookie info, equivalent to timeout - VLOG(log, "No cookie in repy from " << address.toString() << ", cookie state is Supported, dropping packet as if it timed out)" << endl); + VLOG(log, "No cookie in reply from " << address.toString() << ", cookie state is Supported, dropping packet as if it timed out)" << endl); return LWResult::Result::Timeout; break; } } else { - VLOG(log, "No cookie in repy from " << address.toString() << ", cookie state is Unknown, dropping packet as if it timed out" << endl); + VLOG(log, "No cookie in reply from " << address.toString() << ", cookie state is Unknown, dropping packet as if it timed out" << endl); return LWResult::Result::Timeout; } } diff --git a/pdns/recursordist/lwres.hh b/pdns/recursordist/lwres.hh index 2ca661d4e..6a7e7007a 100644 --- a/pdns/recursordist/lwres.hh +++ b/pdns/recursordist/lwres.hh @@ -100,6 +100,6 @@ LWResult::Result arecvfrom(PacketBuffer& packet, int flags, const ComboAddress& LWResult::Result asyncresolve(const OptLog& log, const ComboAddress& address, const DNSName& domain, int type, bool doTCP, bool sendRDQuery, int EDNS0Level, struct timeval* now, boost::optional& srcmask, const ResolveContext& context, const std::shared_ptr>>& outgoingLoggers, const std::shared_ptr>>& fstrmLoggers, const std::set& exportTypes, LWResult* lwr, bool* chained); uint64_t dumpCookies(int fileDesc); -std::string clearCookies(); +void clearCookies(); void pruneCookies(time_t cutoff); -void setAuthCookies(bool flag); +void enableOutgoingCookies(bool flag); diff --git a/pdns/recursordist/rec-cookiestore.cc b/pdns/recursordist/rec-cookiestore.cc index adda2ecbb..c19832d94 100644 --- a/pdns/recursordist/rec-cookiestore.cc +++ b/pdns/recursordist/rec-cookiestore.cc @@ -33,7 +33,7 @@ void CookieStore::prune(time_t cutoff) ind.erase(ind.begin(), ind.upper_bound(cutoff)); } -uint64_t CookieStore::dump(const CookieStore& copy, int fileDesc) +uint64_t CookieStore::dump(int fileDesc) const { int newfd = dup(fileDesc); if (newfd == -1) { @@ -47,7 +47,7 @@ uint64_t CookieStore::dump(const CookieStore& copy, int fileDesc) uint64_t count = 0; fprintf(filePtr.get(), "; cookie dump follows\n; server\tlocal\tcookie\tsupport\tts\n"); - for (const auto& entry : copy) { + for (const auto& entry : *this) { count++; timebuf_t tmp; fprintf(filePtr.get(), "%s\t%s\t%s\t%s\t%s\n", diff --git a/pdns/recursordist/rec-cookiestore.hh b/pdns/recursordist/rec-cookiestore.hh index 76b56af9f..b51f8cc63 100644 --- a/pdns/recursordist/rec-cookiestore.hh +++ b/pdns/recursordist/rec-cookiestore.hh @@ -60,7 +60,7 @@ struct CookieEntry static std::string toString(Support support) { - static const std::array names = { + static const std::array names = { "Unsupported", "Supported", "Probing"}; @@ -100,5 +100,5 @@ class CookieStore : public multi_index_container 0 && connection.d_numqueries >= s_maxQueries) { @@ -73,7 +73,7 @@ void TCPOutConnectionManager::store(const struct timeval& now, const pair_t& pai d_idle_connections.emplace(pair, std::move(connection)); } -TCPOutConnectionManager::Connection TCPOutConnectionManager::get(const pair_t& pair) +TCPOutConnectionManager::Connection TCPOutConnectionManager::get(const endpoints_t& pair) { if (d_idle_connections.count(pair) > 0) { auto connection = d_idle_connections.extract(pair); diff --git a/pdns/recursordist/rec-tcpout.hh b/pdns/recursordist/rec-tcpout.hh index 5ff80ffce..26d973b37 100644 --- a/pdns/recursordist/rec-tcpout.hh +++ b/pdns/recursordist/rec-tcpout.hh @@ -53,10 +53,10 @@ public: size_t d_numqueries{0}; }; - using pair_t = std::pair>; + using endpoints_t = std::pair>; - void store(const struct timeval& now, const pair_t& pair, Connection&& connection); - Connection get(const pair_t& pair); + void store(const struct timeval& now, const endpoints_t& pair, Connection&& connection); + Connection get(const endpoints_t& pair); void cleanup(const struct timeval& now); [[nodiscard]] size_t size() const @@ -71,7 +71,7 @@ public: private: // This does not take into account that we can have multiple connections with different hosts (via SNI) to the same IP. // That is OK, since we are connecting by IP only at the moment. - std::multimap d_idle_connections; + std::multimap d_idle_connections; }; extern thread_local TCPOutConnectionManager t_tcp_manager; diff --git a/pdns/recursordist/rec_channel_rec.cc b/pdns/recursordist/rec_channel_rec.cc index d030f956c..57f6f13a4 100644 --- a/pdns/recursordist/rec_channel_rec.cc +++ b/pdns/recursordist/rec_channel_rec.cc @@ -2108,7 +2108,8 @@ RecursorControlChannel::Answer RecursorControlParser::getAnswer(int socket, cons return doDumpCache(socket, begin, end); } if (cmd == "clear-cookies") { - return {0, clearCookies()}; + clearCookies(); + return {0, ""}; } if (cmd == "dump-cookies") { return doDumpToFile(socket, pleaseDumpCookiesMap, cmd, false);