Set the name for resolver threads am: 04f1d48c3d am: 994c7abd86
am: f5eabb4d36
Change-Id: Ic0983355ffd74f4b9c8a1d809cd770d362753d00
diff --git a/Dns64Configuration.cpp b/Dns64Configuration.cpp
index 7f43d34..64c491c 100644
--- a/Dns64Configuration.cpp
+++ b/Dns64Configuration.cpp
@@ -15,7 +15,6 @@
*/
#define LOG_TAG "resolv"
-#define DBG 0
#include "Dns64Configuration.h"
@@ -24,6 +23,7 @@
#include <netdutils/BackoffSequence.h>
#include <netdutils/DumpWriter.h>
#include <netdutils/InternetAddresses.h>
+#include <netdutils/ThreadUtil.h>
#include <netid_client.h>
#include <thread>
#include <utility>
@@ -63,7 +63,9 @@
mDns64Configs.emplace(std::make_pair(netId, cfg));
// Note that capturing |cfg| in this lambda creates a copy.
- std::thread discovery_thread([this, cfg] {
+ std::thread discovery_thread([this, cfg, netId] {
+ netdutils::setThreadName(android::base::StringPrintf("Nat64Pfx_%u", netId).c_str());
+
// Make a mutable copy rather than mark the whole lambda mutable.
// No particular reason.
Dns64Config evalCfg(cfg);
diff --git a/DnsProxyListener.cpp b/DnsProxyListener.cpp
index f684ff2..9743acd 100644
--- a/DnsProxyListener.cpp
+++ b/DnsProxyListener.cpp
@@ -38,6 +38,7 @@
#include <android-base/stringprintf.h>
#include <android/multinetwork.h> // ResNsendFlags
#include <cutils/misc.h> // FIRST_APPLICATION_UID
+#include <cutils/multiuser.h>
#include <netdutils/InternetAddresses.h>
#include <netdutils/OperationLimiter.h>
#include <netdutils/ResponseCode.h>
@@ -518,6 +519,11 @@
return !gDnsResolv->resolverCtrl.getPrefix64(netId, prefix);
}
+std::string makeThreadName(unsigned netId, uint32_t uid) {
+ // The maximum of netId and app_id are 5-digit numbers.
+ return android::base::StringPrintf("Dns_%u_%u", netId, multiuser_get_app_id(uid));
+}
+
} // namespace
DnsProxyListener::DnsProxyListener() : FrameworkListener(SOCKET_NAME) {
@@ -715,6 +721,10 @@
mClient->decRef();
}
+std::string DnsProxyListener::GetAddrInfoHandler::threadName() {
+ return makeThreadName(mNetContext.dns_netid, mClient->getUid());
+}
+
namespace {
void addIpAddrWithinLimit(std::vector<std::string>* ip_addrs, const sockaddr* addr,
@@ -933,6 +943,10 @@
}
}
+std::string DnsProxyListener::ResNSendHandler::threadName() {
+ return makeThreadName(mNetContext.dns_netid, mClient->getUid());
+}
+
namespace {
bool sendCodeAndBe32(SocketClient* c, int code, int data) {
@@ -1107,6 +1121,9 @@
mClient->decRef();
}
+std::string DnsProxyListener::GetHostByNameHandler::threadName() {
+ return makeThreadName(mNetContext.dns_netid, mClient->getUid());
+}
/*******************************************************
* GetHostByAddr *
@@ -1260,5 +1277,9 @@
mClient->decRef();
}
+std::string DnsProxyListener::GetHostByAddrHandler::threadName() {
+ return makeThreadName(mNetContext.dns_netid, mClient->getUid());
+}
+
} // namespace net
} // namespace android
diff --git a/DnsProxyListener.h b/DnsProxyListener.h
index 9b71bc5..9090ac2 100644
--- a/DnsProxyListener.h
+++ b/DnsProxyListener.h
@@ -54,6 +54,7 @@
~GetAddrInfoHandler();
void run();
+ std::string threadName();
private:
void doDns64Synthesis(int32_t* rv, addrinfo** res, NetworkDnsEventReported* event);
@@ -80,6 +81,7 @@
~GetHostByNameHandler();
void run();
+ std::string threadName();
private:
void doDns64Synthesis(int32_t* rv, hostent** hpp, NetworkDnsEventReported* event);
@@ -105,6 +107,7 @@
~GetHostByAddrHandler();
void run();
+ std::string threadName();
private:
void doDns64ReverseLookup(hostent** hpp, NetworkDnsEventReported* event);
@@ -131,6 +134,7 @@
~ResNSendHandler();
void run();
+ std::string threadName();
private:
SocketClient* mClient; // ref counted
diff --git a/DnsTlsSocket.cpp b/DnsTlsSocket.cpp
index a1068f6..838886a 100644
--- a/DnsTlsSocket.cpp
+++ b/DnsTlsSocket.cpp
@@ -35,8 +35,9 @@
#include <Fwmark.h>
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
+#include <netdutils/SocketOption.h>
+#include <netdutils/ThreadUtil.h>
-#include "netdutils/SocketOption.h"
#include "private/android_filesystem_config.h" // AID_DNS
// NOTE: Inject CA certificate for internal testing -- do NOT enable in production builds
@@ -311,8 +312,11 @@
void DnsTlsSocket::loop() {
std::lock_guard guard(mLock);
std::deque<std::vector<uint8_t>> q;
-
const int timeout_msecs = DnsTlsSocket::kIdleTimeout.count() * 1000;
+
+ Fwmark mark;
+ mark.intValue = mMark;
+ netdutils::setThreadName(android::base::StringPrintf("TlsListen_%u", mark.netId).c_str());
while (true) {
// poll() ignores negative fds
struct pollfd fds[2] = { { .fd = -1 }, { .fd = -1 } };
diff --git a/DnsTlsTransport.cpp b/DnsTlsTransport.cpp
index efcf81a..3453765 100644
--- a/DnsTlsTransport.cpp
+++ b/DnsTlsTransport.cpp
@@ -18,14 +18,16 @@
#include "DnsTlsTransport.h"
+#include <Fwmark.h>
+#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
+#include <netdutils/ThreadUtil.h>
#include "DnsTlsSocketFactory.h"
#include "IDnsTlsSocketFactory.h"
-#include <android-base/logging.h>
-
namespace android {
namespace net {
@@ -104,6 +106,9 @@
void DnsTlsTransport::doReconnect() {
std::lock_guard guard(mLock);
+ Fwmark mark;
+ mark.intValue = mMark;
+ netdutils::setThreadName(android::base::StringPrintf("TlsReconn_%u", mark.netId).c_str());
if (mClosing) {
return;
}
diff --git a/PrivateDnsConfiguration.cpp b/PrivateDnsConfiguration.cpp
index e974d50..c91367f 100644
--- a/PrivateDnsConfiguration.cpp
+++ b/PrivateDnsConfiguration.cpp
@@ -19,7 +19,9 @@
#include "PrivateDnsConfiguration.h"
#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
#include <netdb.h>
+#include <netdutils/ThreadUtil.h>
#include <sys/socket.h>
#include "DnsTlsTransport.h"
@@ -55,8 +57,8 @@
int PrivateDnsConfiguration::set(int32_t netId, uint32_t mark,
const std::vector<std::string>& servers, const std::string& name,
const std::string& caCert) {
- LOG(VERBOSE) << "PrivateDnsConfiguration::set(" << netId << ", " << mark << ", "
- << servers.size() << ", " << name << ")";
+ LOG(DEBUG) << "PrivateDnsConfiguration::set(" << netId << ", 0x" << std::hex << mark << std::dec
+ << ", " << servers.size() << ", " << name << ")";
// Parse the list of servers that has been passed in
std::set<DnsTlsServer> tlsServers;
@@ -165,14 +167,14 @@
void PrivateDnsConfiguration::validatePrivateDnsProvider(const DnsTlsServer& server,
PrivateDnsTracker& tracker, unsigned netId,
uint32_t mark) REQUIRES(mPrivateDnsLock) {
- LOG(VERBOSE) << "validatePrivateDnsProvider(" << addrToString(&server.ss) << ", " << netId
- << ")";
-
tracker[server] = Validation::in_process;
- LOG(VERBOSE) << "Server " << addrToString(&server.ss)
- << " marked as in_process. Tracker now has size " << tracker.size();
+ LOG(DEBUG) << "Server " << addrToString(&server.ss) << " marked as in_process on netId "
+ << netId << ". Tracker now has size " << tracker.size();
+
// Note that capturing |server| and |netId| in this lambda create copies.
std::thread validate_thread([this, server, netId, mark] {
+ netdutils::setThreadName(android::base::StringPrintf("TlsVerify_%u", netId).c_str());
+
// cat /proc/sys/net/ipv4/tcp_syn_retries yields "6".
//
// Start with a 1 minute delay and backoff to once per hour.
@@ -194,9 +196,10 @@
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 on netId " << netId;
const bool success = DnsTlsTransport::validate(server, netId, mark);
- LOG(VERBOSE) << "validateDnsTlsServer returned " << success << " for "
- << addrToString(&server.ss);
+ LOG(DEBUG) << "validateDnsTlsServer returned " << success << " for "
+ << addrToString(&server.ss);
const bool needs_reeval = this->recordPrivateDnsValidation(server, netId, success);
if (!needs_reeval) {
@@ -258,9 +261,9 @@
for (const auto& it : listeners) {
it->onPrivateDnsValidationEvent(netId, addrToString(&server.ss), server.name, success);
}
- LOG(VERBOSE) << "Sent validation " << (success ? "success" : "failure")
- << " event on netId " << netId << " for " << addrToString(&server.ss)
- << " with hostname " << server.name;
+ LOG(DEBUG) << "Sent validation " << (success ? "success" : "failure") << " event on netId "
+ << netId << " for " << addrToString(&server.ss) << " with hostname {"
+ << server.name << "}";
} else {
LOG(ERROR)
<< "Validation event not sent since no INetdEventListener receiver is available.";
@@ -268,16 +271,14 @@
if (success) {
tracker[server] = Validation::success;
- LOG(VERBOSE) << "Validation succeeded for " << addrToString(&server.ss)
- << "! Tracker now has " << tracker.size() << " entries.";
} else {
// Validation failure is expected if a user is on a captive portal.
// TODO: Trigger a second validation attempt after captive portal login
// succeeds.
tracker[server] = (reevaluationStatus == NEEDS_REEVALUATION) ? Validation::in_process
: Validation::fail;
- LOG(VERBOSE) << "Validation failed for " << addrToString(&server.ss) << "!";
}
+ LOG(WARNING) << "Validation " << (success ? "success" : "failed");
return reevaluationStatus;
}