Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 04f1d48c authored by Mike Yu's avatar Mike Yu
Browse files

Set the name for resolver threads

The threads in the resolver are renamed, including:
  - Threads for lookup (name: Dns_<netId>_<appId>)
  - Threads for private dns validation (name: TlsVerify_<netId>)
  - Threads for NAT64 prefix discovery (name: Nat64Pfx_<netId>)
  - Threads for communicating with private dns (name: TlsListen_<netId>)
  - Threads for reconnecting private dns (name: TlsReconn_<netId>)

Example from ps -AT:
root           756  3418     1 2501400   7352 futex_wait_queue_me 0 S Dns_105_1073
root           756  3419     1 2501400   7352 do_sys_poll         0 S TlsVerify_105
root           756  3420     1 2501400   7352 do_sys_poll         0 S TlsVerify_105
root           756  3422     1 2501400   7352 do_sys_poll         0 S TlsVerify_105
root           756  3428     1 2501400   7352 do_sys_poll         0 S TlsListen_105

Also, reveal some logs for private dns validation status to facilitate
debugging analysis.

Example:
  790  4364 W resolv  : Validating DnsTlsServer on netId 100
  790  4364 W resolv  : Validation failed
  790  4366 W resolv  : Validating DnsTlsServer on netId 100
  790  4366 W resolv  : Validation success

Bug: 128404051
Test: atest --include-subdirs packages/modules/DnsResolver
Change-Id: Ide93b1099535552a8615c71353226c1aa70462e3
parent 02eda069
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -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 @@ void Dns64Configuration::startPrefixDiscovery(unsigned netId) {
    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);
+21 −0
Original line number Diff line number Diff line
@@ -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 @@ bool getDns64Prefix(unsigned netId, netdutils::IPPrefix* prefix) {
    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 @@ void DnsProxyListener::GetAddrInfoHandler::run() {
    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 @@ void DnsProxyListener::ResNSendHandler::run() {
    }
}

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 @@ void DnsProxyListener::GetHostByNameHandler::run() {
    mClient->decRef();
}

std::string DnsProxyListener::GetHostByNameHandler::threadName() {
    return makeThreadName(mNetContext.dns_netid, mClient->getUid());
}

/*******************************************************
 *                  GetHostByAddr                      *
@@ -1260,5 +1277,9 @@ void DnsProxyListener::GetHostByAddrHandler::run() {
    mClient->decRef();
}

std::string DnsProxyListener::GetHostByAddrHandler::threadName() {
    return makeThreadName(mNetContext.dns_netid, mClient->getUid());
}

}  // namespace net
}  // namespace android
+4 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ class DnsProxyListener : public FrameworkListener {
        ~GetAddrInfoHandler();

        void run();
        std::string threadName();

      private:
        void doDns64Synthesis(int32_t* rv, addrinfo** res, NetworkDnsEventReported* event);
@@ -80,6 +81,7 @@ class DnsProxyListener : public FrameworkListener {
        ~GetHostByNameHandler();

        void run();
        std::string threadName();

      private:
        void doDns64Synthesis(int32_t* rv, hostent** hpp, NetworkDnsEventReported* event);
@@ -105,6 +107,7 @@ class DnsProxyListener : public FrameworkListener {
        ~GetHostByAddrHandler();

        void run();
        std::string threadName();

      private:
        void doDns64ReverseLookup(hostent** hpp, NetworkDnsEventReported* event);
@@ -131,6 +134,7 @@ class DnsProxyListener : public FrameworkListener {
        ~ResNSendHandler();

        void run();
        std::string threadName();

      private:
        SocketClient* mClient;  // ref counted
+6 −2
Original line number Diff line number Diff line
@@ -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 @@ bool DnsTlsSocket::sslWrite(const Slice buffer) {
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 } };
+7 −2
Original line number Diff line number Diff line
@@ -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::onClosed() {

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;
    }
Loading