diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-12-25 23:32:14 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-12-25 23:32:14 +0000 |
commit | 57156c6cc52858b5d72d14c87227805747e44696 (patch) | |
tree | 82bc831f4666961e1be61d0f2600363f6edad7f2 | |
parent | a72b4da5ff0c29cfcf398436c0e27dfeb0489996 (diff) | |
parent | a7212b94ea2072dfd5fdc65a19f64ddbb17ee0e8 (diff) | |
download | DnsResolver-57156c6cc52858b5d72d14c87227805747e44696.tar.gz |
Snap for 11253470 from a7212b94ea2072dfd5fdc65a19f64ddbb17ee0e8 to sdk-release
Change-Id: If9b8cbfa322604d43ee82ec92edb5ca984148bb9
-rw-r--r-- | Android.bp | 1 | ||||
-rw-r--r-- | Dns64Configuration.cpp | 4 | ||||
-rw-r--r-- | Dns64Configuration.h | 3 | ||||
-rw-r--r-- | DnsProxyListener.cpp | 6 | ||||
-rw-r--r-- | ResolverController.cpp | 2 | ||||
-rw-r--r-- | ResolverController.h | 2 | ||||
-rw-r--r-- | tests/Android.bp | 1 | ||||
-rw-r--r-- | tests/resolv_integration_test.cpp | 2 | ||||
-rw-r--r-- | tests/resolv_private_dns_test.cpp | 25 |
9 files changed, 29 insertions, 17 deletions
@@ -275,7 +275,6 @@ cc_library { "libprotobuf-cpp-lite", "libstatslog_resolv", "libsysutils", - "libutils", "netd_event_listener_interface-lateststable-ndk", "server_configurable_flags", "stats_proto", diff --git a/Dns64Configuration.cpp b/Dns64Configuration.cpp index fc1428db..c09ce368 100644 --- a/Dns64Configuration.cpp +++ b/Dns64Configuration.cpp @@ -24,7 +24,6 @@ #include <netdutils/DumpWriter.h> #include <netdutils/InternetAddresses.h> #include <netdutils/ThreadUtil.h> -#include <utils/StrongPointer.h> #include <thread> #include <utility> @@ -37,7 +36,6 @@ namespace android { -using android::sp; using netdutils::DumpWriter; using netdutils::IPAddress; using netdutils::IPPrefix; @@ -63,7 +61,7 @@ void Dns64Configuration::startPrefixDiscovery(unsigned netId) { // Emplace a copy of |cfg| in the map. mDns64Configs.emplace(std::make_pair(netId, cfg)); - const sp<Dns64Configuration> thiz = sp<Dns64Configuration>::fromExisting(this); + const std::shared_ptr<Dns64Configuration> thiz = shared_from_this(); // Note that capturing |cfg| in this lambda creates a copy. std::thread discovery_thread([thiz, cfg, netId] { setThreadName(fmt::format("Nat64Pfx_{}", netId)); diff --git a/Dns64Configuration.h b/Dns64Configuration.h index 4170e32d..35d3afed 100644 --- a/Dns64Configuration.h +++ b/Dns64Configuration.h @@ -27,7 +27,6 @@ #include <android-base/thread_annotations.h> #include <netdutils/DumpWriter.h> #include <netdutils/InternetAddresses.h> -#include <utils/RefBase.h> struct android_net_context; @@ -49,7 +48,7 @@ namespace net { * Thread-safety: All public methods in this class MUST be thread-safe. * (In other words: this class handles all its locking privately.) */ -class Dns64Configuration : virtual public RefBase { +class Dns64Configuration : public std::enable_shared_from_this<Dns64Configuration> { public: // Simple data struct for passing back packet NAT64 prefix event information to the // Dns64PrefixCallback callback. diff --git a/DnsProxyListener.cpp b/DnsProxyListener.cpp index e70ddb40..8064aef7 100644 --- a/DnsProxyListener.cpp +++ b/DnsProxyListener.cpp @@ -685,7 +685,8 @@ IsUidBlockedFn resolveIsUidNetworkingBlockedFn() { InitFn ADnsHelper_init = reinterpret_cast<InitFn>(dlsym(handle, "ADnsHelper_init")); if (!ADnsHelper_init) { LOG(ERROR) << __func__ << ": " << dlerror(); - abort(); + // TODO: Change to abort() when NDK is finalized + return nullptr; } const int ret = (*ADnsHelper_init)(); if (ret) { @@ -697,7 +698,8 @@ IsUidBlockedFn resolveIsUidNetworkingBlockedFn() { reinterpret_cast<IsUidBlockedFn>(dlsym(handle, "ADnsHelper_isUidNetworkingBlocked")); if (!f) { LOG(ERROR) << __func__ << ": " << dlerror(); - abort(); + // TODO: Change to abort() when NDK is finalized + return nullptr; } return f; } diff --git a/ResolverController.cpp b/ResolverController.cpp index 757e3f74..3198ec25 100644 --- a/ResolverController.cpp +++ b/ResolverController.cpp @@ -155,7 +155,7 @@ int getDnsInfo(unsigned netId, std::vector<std::string>* servers, std::vector<st } // namespace ResolverController::ResolverController() - : mDns64Configuration(android::sp<Dns64Configuration>::make( + : mDns64Configuration(make_shared<Dns64Configuration>( [](uint32_t netId, uint32_t uid, android_net_context* netcontext) { gResNetdCallbacks.get_network_context(netId, uid, netcontext); }, diff --git a/ResolverController.h b/ResolverController.h index b74cff92..c2fc8e77 100644 --- a/ResolverController.h +++ b/ResolverController.h @@ -66,7 +66,7 @@ class ResolverController { void dump(netdutils::DumpWriter& dw, unsigned netId); private: - android::sp<Dns64Configuration> mDns64Configuration; + std::shared_ptr<Dns64Configuration> mDns64Configuration; }; } // namespace net } // namespace android diff --git a/tests/Android.bp b/tests/Android.bp index b1266037..d18deaab 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -274,7 +274,6 @@ cc_test { "libstatslog_resolv", "libstatspush_compat", "libsysutils", - "libutils", "resolv_stats_test_utils", "server_configurable_flags", "stats_proto", diff --git a/tests/resolv_integration_test.cpp b/tests/resolv_integration_test.cpp index ef2bf1e5..d3e0c59e 100644 --- a/tests/resolv_integration_test.cpp +++ b/tests/resolv_integration_test.cpp @@ -4833,7 +4833,7 @@ TEST_F(ResolverTest, ConnectTlsServerTimeout_ConcurrentQueries) { // DOT_SERVER_UNRESPONSIVE_TIME_MS, DoT queries should timeout. TEST_F(ResolverTest, QueryTlsServerTimeout) { constexpr int DOT_SERVER_UNRESPONSIVE_TIME_MS = 2000; - constexpr int TIMING_TOLERANCE_MS = 200; + constexpr int TIMING_TOLERANCE_MS = 500; constexpr char hostname1[] = "query1.example.com."; const std::vector<DnsRecord> records = { {hostname1, ns_type::ns_t_a, "1.2.3.4"}, diff --git a/tests/resolv_private_dns_test.cpp b/tests/resolv_private_dns_test.cpp index c9b8f46c..1f5a2328 100644 --- a/tests/resolv_private_dns_test.cpp +++ b/tests/resolv_private_dns_test.cpp @@ -541,6 +541,13 @@ TEST_P(TransportParameterizedTest, BlockDnsQuery) { dot_backend.addMapping(r.host_name, r.type, r.addr); doh_backend.addMapping(r.host_name, r.type, r.addr); + // TODO: Remove the flags and fix the test. + // These two flags are not necessary for this test case because the test does not expect DNS + // queries to be sent by DNS resolver. However, We should still set these two flags so that we + // don't forget to set them when writing similar tests in the future by referring to this one. + ScopedSystemProperties sp1(kDotAsyncHandshakeFlag, "0"); + ScopedSystemProperties sp2(kDotMaxretriesFlag, "3"); + auto parcel = DnsResponderClient::GetDefaultResolverParamsParcel(); ASSERT_TRUE(mDnsClient.SetResolversFromParcel(parcel)); @@ -575,14 +582,14 @@ TEST_P(TransportParameterizedTest, BlockDnsQuery) { // DataSaver information is only meaningful after V. // TODO: Add 'else' to check that DNS queries are not blocked before V. if (android::modules::sdklevel::IsAtLeastV()) { - expectQueriesAreBlocked(); + EXPECT_NO_FAILURE(expectQueriesAreBlocked()); } } else { // Block network access by setting UID firewall rules. ScopeBlockedUIDRule scopeBlockUidRule(mDnsClient.netdService(), TEST_UID); - expectQueriesAreBlocked(); + EXPECT_NO_FAILURE(expectQueriesAreBlocked()); } - expectQueries(0 /* dns */, 0 /* dot */, 0 /* doh */); + EXPECT_NO_FAILURE(expectQueries(0 /* dns */, 0 /* dot */, 0 /* doh */)); } } @@ -601,6 +608,13 @@ TEST_P(TransportParameterizedTest, BlockDnsQuery_FlaggedOff) { doh_backend.addMapping(r.host_name, r.type, r.addr); ScopedSystemProperties sp1(kFailFastOnUidNetworkBlockingFlag, "0"); + // TODO: Remove the flags and fix the test. + // Context: Fake DoT server closes SSL connection after replying to each query. But a single DNS + // API can send two queries for A and AAAA. One of them will failed in MTS because the current + // setting pushed by server is no retry. + ScopedSystemProperties sp2(kDotAsyncHandshakeFlag, "0"); + ScopedSystemProperties sp3(kDotMaxretriesFlag, "3"); + resetNetwork(); auto parcel = DnsResponderClient::GetDefaultResolverParamsParcel(); @@ -642,11 +656,12 @@ TEST_P(TransportParameterizedTest, BlockDnsQuery_FlaggedOff) { if (testParamHasDoh()) { EXPECT_NO_FAILURE(expectQueries(0 /* dns */, 0 /* dot */, 2 /* doh */)); - dot.clearQueries(); + doh.clearQueries(); } else { EXPECT_NO_FAILURE(expectQueries(0 /* dns */, 2 /* dot */, 0 /* doh */)); - doh.clearQueries(); + dot.clearQueries(); } + flushCache(); } } |