Loading Android.bp +4 −3 Original line number Diff line number Diff line Loading @@ -198,6 +198,7 @@ cc_library { "libcutils", "libnetdutils", "libdoh_ffi", "libmodules-utils-build", "libprotobuf-cpp-lite", "libstatslog_resolv", "libstatspush_compat", Loading Loading @@ -328,7 +329,7 @@ filegroup { rust_ffi_static { name: "libdoh_ffi", crate_name: "doh", srcs: ["doh.rs"], srcs: ["doh/doh.rs"], edition: "2018", rlibs: [ Loading Loading @@ -360,7 +361,7 @@ rust_ffi_static { rust_test { name: "doh_unit_test", crate_name: "doh", srcs: ["doh.rs"], srcs: ["doh/doh.rs"], edition: "2018", test_suites: ["general-tests"], auto_gen_config: true, Loading @@ -386,7 +387,7 @@ rust_test { rust_ffi_static { name: "libdoh_ffi_for_test", crate_name: "doh", srcs: ["doh.rs"], srcs: ["doh/doh.rs"], edition: "2018", rlibs: [ Loading DnsStats.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -284,6 +284,9 @@ void DnsStats::dump(DumpWriter& dw) { dw.println("over UDP"); dumpStatsMap(mStats[PROTO_UDP]); dw.println("over DOH"); dumpStatsMap(mStats[PROTO_DOH]); dw.println("over TLS"); dumpStatsMap(mStats[PROTO_DOT]); Loading DnsStatsTest.cpp +13 −11 Original line number Diff line number Diff line Loading @@ -117,7 +117,8 @@ class DnsStatsTest : public ::testing::Test { void verifyDumpOutput(const std::vector<StatsData>& tcpData, const std::vector<StatsData>& udpData, const std::vector<StatsData>& dotData, const std::vector<StatsData>& mdnsData) { const std::vector<StatsData>& mdnsData, const std::vector<StatsData>& dohData) { // A pattern to capture three matches: // server address (empty allowed), the statistics, and the score. const std::regex pattern(R"(\s{4,}([0-9a-fA-F:\.]*)[ ]?([<(].*[>)])[ ]?(\S*))"); Loading Loading @@ -149,6 +150,7 @@ class DnsStatsTest : public ::testing::Test { }; check(udpData, "UDP", &dumpString); check(dohData, "DOH", &dumpString); check(dotData, "TLS", &dumpString); check(tcpData, "TCP", &dumpString); check(mdnsData, "MDNS", &dumpString); Loading @@ -173,7 +175,7 @@ class DnsStatsTest : public ::testing::Test { TEST_F(DnsStatsTest, SetAddrs) { // Check before any operation to mDnsStats. verifyDumpOutput({}, {}, {}, {}); verifyDumpOutput({}, {}, {}, {}, {}); static const struct { std::vector<std::string> servers; Loading Loading @@ -230,7 +232,7 @@ TEST_F(DnsStatsTest, SetAddrs) { EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_DOT, expectedStats, NO_AVERAGE_LATENCY)); } verifyDumpOutput({}, {}, {}, {}); verifyDumpOutput({}, {}, {}, {}, {}); } TEST_F(DnsStatsTest, SetServersDifferentPorts) { Loading @@ -249,7 +251,7 @@ TEST_F(DnsStatsTest, SetServersDifferentPorts) { EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_TCP, {}, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, {}, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_DOT, {}, NO_AVERAGE_LATENCY)); verifyDumpOutput({}, {}, {}, {}); verifyDumpOutput({}, {}, {}, {}, {}); EXPECT_TRUE(mDnsStats.setAddrs(std::vector(servers.begin() + 2, servers.end()), PROTO_TCP)); EXPECT_TRUE(mDnsStats.setAddrs(std::vector(servers.begin() + 2, servers.end()), PROTO_UDP)); Loading @@ -264,7 +266,7 @@ TEST_F(DnsStatsTest, SetServersDifferentPorts) { EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_TCP, expectedStats, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, expectedStats, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_DOT, expectedStats, NO_AVERAGE_LATENCY)); verifyDumpOutput(expectedStats, expectedStats, expectedStats, {}); verifyDumpOutput(expectedStats, expectedStats, expectedStats, {}, {}); } TEST_F(DnsStatsTest, AddStatsAndClear) { Loading Loading @@ -311,7 +313,7 @@ TEST_F(DnsStatsTest, AddStatsAndClear) { EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, expectedStatsForUdp, 10ms)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_DOT, {}, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_MDNS, expectedStatsForMdns, 10ms)); verifyDumpOutput(expectedStatsForTcp, expectedStatsForUdp, {}, expectedStatsForMdns); verifyDumpOutput(expectedStatsForTcp, expectedStatsForUdp, {}, expectedStatsForMdns, {}); // Clear stats. EXPECT_TRUE(mDnsStats.setAddrs({}, PROTO_TCP)); Loading @@ -322,7 +324,7 @@ TEST_F(DnsStatsTest, AddStatsAndClear) { EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, {}, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_DOT, {}, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_MDNS, {}, NO_AVERAGE_LATENCY)); verifyDumpOutput({}, {}, {}, {}); verifyDumpOutput({}, {}, {}, {}, {}); } TEST_F(DnsStatsTest, StatsRemainsInExistentServer) { Loading Loading @@ -350,7 +352,7 @@ TEST_F(DnsStatsTest, StatsRemainsInExistentServer) { }; EXPECT_THAT(mDnsStats.getStats(PROTO_UDP), UnorderedElementsAreArray(expectedStats)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, expectedStats, 106ms)); verifyDumpOutput({}, expectedStats, {}, {}); verifyDumpOutput({}, expectedStats, {}, {}, {}); // Update the server list, the stats of 127.0.0.2 will remain. servers = { Loading @@ -366,7 +368,7 @@ TEST_F(DnsStatsTest, StatsRemainsInExistentServer) { }; EXPECT_THAT(mDnsStats.getStats(PROTO_UDP), UnorderedElementsAreArray(expectedStats)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, expectedStats, 130ms)); verifyDumpOutput({}, expectedStats, {}, {}); verifyDumpOutput({}, expectedStats, {}, {}, {}); // Let's add a record to 127.0.0.2 again. EXPECT_TRUE(mDnsStats.addStats(servers[0], recordNoError)); Loading @@ -377,7 +379,7 @@ TEST_F(DnsStatsTest, StatsRemainsInExistentServer) { }; EXPECT_THAT(mDnsStats.getStats(PROTO_UDP), UnorderedElementsAreArray(expectedStats)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, expectedStats, 106ms)); verifyDumpOutput({}, expectedStats, {}, {}); verifyDumpOutput({}, expectedStats, {}, {}, {}); } TEST_F(DnsStatsTest, AddStatsRecords_100000) { Loading Loading @@ -451,7 +453,7 @@ TEST_F(DnsStatsTest, AddStatsRecords_100000) { EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, expectedStats, 99935500us)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_DOT, expectedStats, 99935500us)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_MDNS, expectedMdnsStats, 99935500us)); verifyDumpOutput(expectedStats, expectedStats, expectedStats, expectedMdnsStats); verifyDumpOutput(expectedStats, expectedStats, expectedStats, expectedMdnsStats, {}); } TEST_F(DnsStatsTest, GetServers_SortingByLatency) { Loading PrivateDnsConfiguration.cpp +27 −5 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ #include "ResolverEventReporter.h" #include "doh.h" #include "netd_resolv/resolv.h" #include "resolv_cache.h" #include "resolv_private.h" #include "util.h" Loading Loading @@ -386,6 +387,16 @@ void PrivateDnsConfiguration::setObserver(PrivateDnsValidationObserver* observer mObserver = observer; } base::Result<netdutils::IPSockAddr> PrivateDnsConfiguration::getDohServer(unsigned netId) const { std::lock_guard guard(mPrivateDnsLock); auto it = mDohTracker.find(netId); if (it != mDohTracker.end()) { return netdutils::IPSockAddr::toIPSockAddr(it->second.ipAddr, 443); } return Errorf("Failed to get DoH Server: netId {} not found", netId); } void PrivateDnsConfiguration::notifyValidationStateUpdate(const netdutils::IPSockAddr& sockaddr, Validation validation, uint32_t netId) const { Loading Loading @@ -418,16 +429,20 @@ void PrivateDnsConfiguration::initDohLocked() { [](uint32_t net_id, bool success, const char* ip_addr, const char* host) { android::net::PrivateDnsConfiguration::getInstance().onDohStatusUpdate( net_id, success, ip_addr, host); }); }, [](int32_t sock) { resolv_tag_socket(sock, AID_DNS, NET_CONTEXT_INVALID_PID); }); } int PrivateDnsConfiguration::setDoh(int32_t netId, uint32_t mark, const std::vector<std::string>& servers, const std::string& name, const std::string& caCert) { if (servers.empty()) return 0; LOG(DEBUG) << "PrivateDnsConfiguration::setDoh(" << netId << ", 0x" << std::hex << mark << std::dec << ", " << servers.size() << ", " << name << ")"; std::lock_guard guard(mPrivateDnsLock); if (servers.empty()) { clearDohLocked(netId); return 0; } // Sort the input servers to ensure that we could get the server vector at the same order. std::vector<std::string> sortedServers = servers; Loading Loading @@ -462,6 +477,7 @@ int PrivateDnsConfiguration::setDoh(int32_t netId, uint32_t mark, dohId.status); mPrivateDnsLog.push(std::move(record)); LOG(INFO) << __func__ << ": Upgrading server to DoH: " << name; resolv_stats_set_addrs(netId, PROTO_DOH, {dohId.ipAddr}, 443); int probeTimeout = Experiments::getInstance()->getFlag("doh_probe_timeout_ms", kDohProbeDefaultTimeoutMs); Loading @@ -473,14 +489,20 @@ int PrivateDnsConfiguration::setDoh(int32_t netId, uint32_t mark, } LOG(INFO) << __func__ << ": No suitable DoH server found"; clearDohLocked(netId); return 0; } void PrivateDnsConfiguration::clearDoh(unsigned netId) { LOG(DEBUG) << "PrivateDnsConfiguration::clearDoh (" << netId << ")"; std::lock_guard guard(mPrivateDnsLock); void PrivateDnsConfiguration::clearDohLocked(unsigned netId) { LOG(DEBUG) << "PrivateDnsConfiguration::clearDohLocked (" << netId << ")"; if (mDohDispatcher != nullptr) doh_net_delete(mDohDispatcher, netId); mDohTracker.erase(netId); resolv_stats_set_addrs(netId, PROTO_DOH, {}, 443); } void PrivateDnsConfiguration::clearDoh(unsigned netId) { std::lock_guard guard(mPrivateDnsLock); clearDohLocked(netId); } ssize_t PrivateDnsConfiguration::dohQuery(unsigned netId, const Slice query, const Slice answer, Loading PrivateDnsConfiguration.h +4 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,9 @@ class PrivateDnsConfiguration { void onDohStatusUpdate(uint32_t netId, bool success, const char* ipAddr, const char* host) EXCLUDES(mPrivateDnsLock); base::Result<netdutils::IPSockAddr> getDohServer(unsigned netId) const EXCLUDES(mPrivateDnsLock); private: typedef std::map<ServerIdentity, std::unique_ptr<IPrivateDnsServer>> PrivateDnsTracker; Loading Loading @@ -147,6 +150,7 @@ class PrivateDnsConfiguration { unsigned netId) REQUIRES(mPrivateDnsLock); void initDohLocked() REQUIRES(mPrivateDnsLock); void clearDohLocked(unsigned netId) REQUIRES(mPrivateDnsLock); mutable std::mutex mPrivateDnsLock; std::map<unsigned, PrivateDnsMode> mPrivateDnsModes GUARDED_BY(mPrivateDnsLock); Loading Loading
Android.bp +4 −3 Original line number Diff line number Diff line Loading @@ -198,6 +198,7 @@ cc_library { "libcutils", "libnetdutils", "libdoh_ffi", "libmodules-utils-build", "libprotobuf-cpp-lite", "libstatslog_resolv", "libstatspush_compat", Loading Loading @@ -328,7 +329,7 @@ filegroup { rust_ffi_static { name: "libdoh_ffi", crate_name: "doh", srcs: ["doh.rs"], srcs: ["doh/doh.rs"], edition: "2018", rlibs: [ Loading Loading @@ -360,7 +361,7 @@ rust_ffi_static { rust_test { name: "doh_unit_test", crate_name: "doh", srcs: ["doh.rs"], srcs: ["doh/doh.rs"], edition: "2018", test_suites: ["general-tests"], auto_gen_config: true, Loading @@ -386,7 +387,7 @@ rust_test { rust_ffi_static { name: "libdoh_ffi_for_test", crate_name: "doh", srcs: ["doh.rs"], srcs: ["doh/doh.rs"], edition: "2018", rlibs: [ Loading
DnsStats.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -284,6 +284,9 @@ void DnsStats::dump(DumpWriter& dw) { dw.println("over UDP"); dumpStatsMap(mStats[PROTO_UDP]); dw.println("over DOH"); dumpStatsMap(mStats[PROTO_DOH]); dw.println("over TLS"); dumpStatsMap(mStats[PROTO_DOT]); Loading
DnsStatsTest.cpp +13 −11 Original line number Diff line number Diff line Loading @@ -117,7 +117,8 @@ class DnsStatsTest : public ::testing::Test { void verifyDumpOutput(const std::vector<StatsData>& tcpData, const std::vector<StatsData>& udpData, const std::vector<StatsData>& dotData, const std::vector<StatsData>& mdnsData) { const std::vector<StatsData>& mdnsData, const std::vector<StatsData>& dohData) { // A pattern to capture three matches: // server address (empty allowed), the statistics, and the score. const std::regex pattern(R"(\s{4,}([0-9a-fA-F:\.]*)[ ]?([<(].*[>)])[ ]?(\S*))"); Loading Loading @@ -149,6 +150,7 @@ class DnsStatsTest : public ::testing::Test { }; check(udpData, "UDP", &dumpString); check(dohData, "DOH", &dumpString); check(dotData, "TLS", &dumpString); check(tcpData, "TCP", &dumpString); check(mdnsData, "MDNS", &dumpString); Loading @@ -173,7 +175,7 @@ class DnsStatsTest : public ::testing::Test { TEST_F(DnsStatsTest, SetAddrs) { // Check before any operation to mDnsStats. verifyDumpOutput({}, {}, {}, {}); verifyDumpOutput({}, {}, {}, {}, {}); static const struct { std::vector<std::string> servers; Loading Loading @@ -230,7 +232,7 @@ TEST_F(DnsStatsTest, SetAddrs) { EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_DOT, expectedStats, NO_AVERAGE_LATENCY)); } verifyDumpOutput({}, {}, {}, {}); verifyDumpOutput({}, {}, {}, {}, {}); } TEST_F(DnsStatsTest, SetServersDifferentPorts) { Loading @@ -249,7 +251,7 @@ TEST_F(DnsStatsTest, SetServersDifferentPorts) { EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_TCP, {}, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, {}, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_DOT, {}, NO_AVERAGE_LATENCY)); verifyDumpOutput({}, {}, {}, {}); verifyDumpOutput({}, {}, {}, {}, {}); EXPECT_TRUE(mDnsStats.setAddrs(std::vector(servers.begin() + 2, servers.end()), PROTO_TCP)); EXPECT_TRUE(mDnsStats.setAddrs(std::vector(servers.begin() + 2, servers.end()), PROTO_UDP)); Loading @@ -264,7 +266,7 @@ TEST_F(DnsStatsTest, SetServersDifferentPorts) { EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_TCP, expectedStats, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, expectedStats, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_DOT, expectedStats, NO_AVERAGE_LATENCY)); verifyDumpOutput(expectedStats, expectedStats, expectedStats, {}); verifyDumpOutput(expectedStats, expectedStats, expectedStats, {}, {}); } TEST_F(DnsStatsTest, AddStatsAndClear) { Loading Loading @@ -311,7 +313,7 @@ TEST_F(DnsStatsTest, AddStatsAndClear) { EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, expectedStatsForUdp, 10ms)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_DOT, {}, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_MDNS, expectedStatsForMdns, 10ms)); verifyDumpOutput(expectedStatsForTcp, expectedStatsForUdp, {}, expectedStatsForMdns); verifyDumpOutput(expectedStatsForTcp, expectedStatsForUdp, {}, expectedStatsForMdns, {}); // Clear stats. EXPECT_TRUE(mDnsStats.setAddrs({}, PROTO_TCP)); Loading @@ -322,7 +324,7 @@ TEST_F(DnsStatsTest, AddStatsAndClear) { EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, {}, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_DOT, {}, NO_AVERAGE_LATENCY)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_MDNS, {}, NO_AVERAGE_LATENCY)); verifyDumpOutput({}, {}, {}, {}); verifyDumpOutput({}, {}, {}, {}, {}); } TEST_F(DnsStatsTest, StatsRemainsInExistentServer) { Loading Loading @@ -350,7 +352,7 @@ TEST_F(DnsStatsTest, StatsRemainsInExistentServer) { }; EXPECT_THAT(mDnsStats.getStats(PROTO_UDP), UnorderedElementsAreArray(expectedStats)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, expectedStats, 106ms)); verifyDumpOutput({}, expectedStats, {}, {}); verifyDumpOutput({}, expectedStats, {}, {}, {}); // Update the server list, the stats of 127.0.0.2 will remain. servers = { Loading @@ -366,7 +368,7 @@ TEST_F(DnsStatsTest, StatsRemainsInExistentServer) { }; EXPECT_THAT(mDnsStats.getStats(PROTO_UDP), UnorderedElementsAreArray(expectedStats)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, expectedStats, 130ms)); verifyDumpOutput({}, expectedStats, {}, {}); verifyDumpOutput({}, expectedStats, {}, {}, {}); // Let's add a record to 127.0.0.2 again. EXPECT_TRUE(mDnsStats.addStats(servers[0], recordNoError)); Loading @@ -377,7 +379,7 @@ TEST_F(DnsStatsTest, StatsRemainsInExistentServer) { }; EXPECT_THAT(mDnsStats.getStats(PROTO_UDP), UnorderedElementsAreArray(expectedStats)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, expectedStats, 106ms)); verifyDumpOutput({}, expectedStats, {}, {}); verifyDumpOutput({}, expectedStats, {}, {}, {}); } TEST_F(DnsStatsTest, AddStatsRecords_100000) { Loading Loading @@ -451,7 +453,7 @@ TEST_F(DnsStatsTest, AddStatsRecords_100000) { EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_UDP, expectedStats, 99935500us)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_DOT, expectedStats, 99935500us)); EXPECT_NO_FAILURE(verifyDnsStatsContent(PROTO_MDNS, expectedMdnsStats, 99935500us)); verifyDumpOutput(expectedStats, expectedStats, expectedStats, expectedMdnsStats); verifyDumpOutput(expectedStats, expectedStats, expectedStats, expectedMdnsStats, {}); } TEST_F(DnsStatsTest, GetServers_SortingByLatency) { Loading
PrivateDnsConfiguration.cpp +27 −5 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ #include "ResolverEventReporter.h" #include "doh.h" #include "netd_resolv/resolv.h" #include "resolv_cache.h" #include "resolv_private.h" #include "util.h" Loading Loading @@ -386,6 +387,16 @@ void PrivateDnsConfiguration::setObserver(PrivateDnsValidationObserver* observer mObserver = observer; } base::Result<netdutils::IPSockAddr> PrivateDnsConfiguration::getDohServer(unsigned netId) const { std::lock_guard guard(mPrivateDnsLock); auto it = mDohTracker.find(netId); if (it != mDohTracker.end()) { return netdutils::IPSockAddr::toIPSockAddr(it->second.ipAddr, 443); } return Errorf("Failed to get DoH Server: netId {} not found", netId); } void PrivateDnsConfiguration::notifyValidationStateUpdate(const netdutils::IPSockAddr& sockaddr, Validation validation, uint32_t netId) const { Loading Loading @@ -418,16 +429,20 @@ void PrivateDnsConfiguration::initDohLocked() { [](uint32_t net_id, bool success, const char* ip_addr, const char* host) { android::net::PrivateDnsConfiguration::getInstance().onDohStatusUpdate( net_id, success, ip_addr, host); }); }, [](int32_t sock) { resolv_tag_socket(sock, AID_DNS, NET_CONTEXT_INVALID_PID); }); } int PrivateDnsConfiguration::setDoh(int32_t netId, uint32_t mark, const std::vector<std::string>& servers, const std::string& name, const std::string& caCert) { if (servers.empty()) return 0; LOG(DEBUG) << "PrivateDnsConfiguration::setDoh(" << netId << ", 0x" << std::hex << mark << std::dec << ", " << servers.size() << ", " << name << ")"; std::lock_guard guard(mPrivateDnsLock); if (servers.empty()) { clearDohLocked(netId); return 0; } // Sort the input servers to ensure that we could get the server vector at the same order. std::vector<std::string> sortedServers = servers; Loading Loading @@ -462,6 +477,7 @@ int PrivateDnsConfiguration::setDoh(int32_t netId, uint32_t mark, dohId.status); mPrivateDnsLog.push(std::move(record)); LOG(INFO) << __func__ << ": Upgrading server to DoH: " << name; resolv_stats_set_addrs(netId, PROTO_DOH, {dohId.ipAddr}, 443); int probeTimeout = Experiments::getInstance()->getFlag("doh_probe_timeout_ms", kDohProbeDefaultTimeoutMs); Loading @@ -473,14 +489,20 @@ int PrivateDnsConfiguration::setDoh(int32_t netId, uint32_t mark, } LOG(INFO) << __func__ << ": No suitable DoH server found"; clearDohLocked(netId); return 0; } void PrivateDnsConfiguration::clearDoh(unsigned netId) { LOG(DEBUG) << "PrivateDnsConfiguration::clearDoh (" << netId << ")"; std::lock_guard guard(mPrivateDnsLock); void PrivateDnsConfiguration::clearDohLocked(unsigned netId) { LOG(DEBUG) << "PrivateDnsConfiguration::clearDohLocked (" << netId << ")"; if (mDohDispatcher != nullptr) doh_net_delete(mDohDispatcher, netId); mDohTracker.erase(netId); resolv_stats_set_addrs(netId, PROTO_DOH, {}, 443); } void PrivateDnsConfiguration::clearDoh(unsigned netId) { std::lock_guard guard(mPrivateDnsLock); clearDohLocked(netId); } ssize_t PrivateDnsConfiguration::dohQuery(unsigned netId, const Slice query, const Slice answer, Loading
PrivateDnsConfiguration.h +4 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,9 @@ class PrivateDnsConfiguration { void onDohStatusUpdate(uint32_t netId, bool success, const char* ipAddr, const char* host) EXCLUDES(mPrivateDnsLock); base::Result<netdutils::IPSockAddr> getDohServer(unsigned netId) const EXCLUDES(mPrivateDnsLock); private: typedef std::map<ServerIdentity, std::unique_ptr<IPrivateDnsServer>> PrivateDnsTracker; Loading Loading @@ -147,6 +150,7 @@ class PrivateDnsConfiguration { unsigned netId) REQUIRES(mPrivateDnsLock); void initDohLocked() REQUIRES(mPrivateDnsLock); void clearDohLocked(unsigned netId) REQUIRES(mPrivateDnsLock); mutable std::mutex mPrivateDnsLock; std::map<unsigned, PrivateDnsMode> mPrivateDnsModes GUARDED_BY(mPrivateDnsLock); Loading