diff options
author | Mike Yu <yumike@google.com> | 2023-07-07 09:48:52 +0000 |
---|---|---|
committer | Mike Yu <yumike@google.com> | 2023-07-07 11:22:15 +0000 |
commit | bf52841c57f05b9caff97c80d2d86d59ecf609e4 (patch) | |
tree | b7714dc8316598f81f7762336a29753a7f4dccc9 | |
parent | 930b664a16dd54d5afe85dfa36749210386c380b (diff) | |
download | DnsResolver-bf52841c57f05b9caff97c80d2d86d59ecf609e4.tar.gz |
Add toString for DnsTlsServer
This toString() will output the IP address as well as the provider
hostname. It makes the log clearer to tell us whether a private DNS
is for opportunistic or strict mode.
Test: atest
Change-Id: Ie260ced35be234190e6fca137c45a8944ff0d35c
-rw-r--r-- | DnsTlsDispatcher.cpp | 6 | ||||
-rw-r--r-- | DnsTlsServer.cpp | 5 | ||||
-rw-r--r-- | DnsTlsServer.h | 1 | ||||
-rw-r--r-- | PrivateDnsConfiguration.cpp | 4 |
4 files changed, 11 insertions, 5 deletions
diff --git a/DnsTlsDispatcher.cpp b/DnsTlsDispatcher.cpp index 452d28b8..6e0ced2a 100644 --- a/DnsTlsDispatcher.cpp +++ b/DnsTlsDispatcher.cpp @@ -71,7 +71,7 @@ std::list<DnsTlsServer> DnsTlsDispatcher::getOrderedAndUsableServerList( if (!xport->usable()) { // Don't use this xport. It will be removed after timeout // (IDLE_TIMEOUT minutes). - LOG(DEBUG) << "Skip using DoT server " << tlsServer.toIpString() << " on " + LOG(DEBUG) << "Skip using DoT server " << tlsServer.toString() << " on " << netId; continue; } @@ -231,7 +231,7 @@ DnsTlsTransport::Response DnsTlsDispatcher::query(const DnsTlsServer& server, un // a new xport will be created. const auto result = PrivateDnsConfiguration::getInstance().requestDotValidation( netId, PrivateDnsConfiguration::ServerIdentity{server}, mark); - LOG(WARNING) << "Requested validation for " << server.toIpString() << " with mark 0x" + LOG(WARNING) << "Requested validation for " << server.toString() << " with mark 0x" << std::hex << mark << ", " << (result.ok() ? "succeeded" : "failed: " + result.error().message()); } @@ -327,7 +327,7 @@ DnsTlsDispatcher::Transport* DnsTlsDispatcher::addTransport(const DnsTlsServer& ret = new Transport(server, mark, netId, mFactory.get(), triggerThr, unusableThr, queryTimeout); LOG(INFO) << "Transport is initialized with { " << triggerThr << ", " << unusableThr << ", " << queryTimeout << "ms }" - << " for server { " << server.toIpString() << "/" << server.name << " }"; + << " for server " << server.toString(); mStore[key].reset(ret); diff --git a/DnsTlsServer.cpp b/DnsTlsServer.cpp index 89ea8417..76825317 100644 --- a/DnsTlsServer.cpp +++ b/DnsTlsServer.cpp @@ -18,6 +18,7 @@ #include <algorithm> +#include <android-base/format.h> #include <netdutils/InternetAddresses.h> namespace { @@ -130,5 +131,9 @@ std::string DnsTlsServer::toIpString() const { return netdutils::IPSockAddr::toIPSockAddr(ss).ip().toString(); } +std::string DnsTlsServer::toString() const { + return fmt::format("{{{}/{}}}", toIpString(), name); +} + } // namespace net } // namespace android diff --git a/DnsTlsServer.h b/DnsTlsServer.h index ef364942..9d2ac5e6 100644 --- a/DnsTlsServer.h +++ b/DnsTlsServer.h @@ -63,6 +63,7 @@ struct DnsTlsServer { bool wasExplicitlyConfigured() const; std::string toIpString() const; + std::string toString() const; std::string provider() const { return name; } netdutils::IPSockAddr addr() const { return netdutils::IPSockAddr::toIPSockAddr(ss); } diff --git a/PrivateDnsConfiguration.cpp b/PrivateDnsConfiguration.cpp index 013cd1a5..d32d1007 100644 --- a/PrivateDnsConfiguration.cpp +++ b/PrivateDnsConfiguration.cpp @@ -365,11 +365,11 @@ void PrivateDnsConfiguration::startDotValidation(const ServerIdentity& identity, while (true) { // ::validate() is a blocking call that performs network operations. // It can take milliseconds to minutes, up to the SYN retry limit. - LOG(WARNING) << "Validating DnsTlsServer " << server.toIpString() << " with mark 0x" + LOG(WARNING) << "Validating DnsTlsServer " << server.toString() << " with mark 0x" << std::hex << server.validationMark(); const bool success = DnsTlsTransport::validate(server, server.validationMark()); LOG(WARNING) << "validateDnsTlsServer returned " << success << " for " - << server.toIpString(); + << server.toString(); const bool needs_reeval = this->recordDotValidation(identity, netId, success, isRevalidation); |