Loading PrivateDnsConfiguration.cpp +4 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include <android-base/format.h> #include <android-base/format.h> #include <android-base/logging.h> #include <android-base/logging.h> #include <android-base/stringprintf.h> #include <android-base/stringprintf.h> #include <android/binder_ibinder.h> #include <netdutils/Slice.h> #include <netdutils/Slice.h> #include <netdutils/ThreadUtil.h> #include <netdutils/ThreadUtil.h> #include <sys/socket.h> #include <sys/socket.h> Loading Loading @@ -444,6 +445,9 @@ int PrivateDnsConfiguration::setDoh(int32_t netId, uint32_t mark, const auto& doh = entry.getDohIdentity(sortedServers, name); const auto& doh = entry.getDohIdentity(sortedServers, name); if (!doh.ok()) continue; if (!doh.ok()) continue; // The internal tests are supposed to have root permission. if (entry.forTesting && AIBinder_getCallingUid() != AID_ROOT) continue; auto it = mDohTracker.find(netId); auto it = mDohTracker.find(netId); // Skip if the same server already exists and its status == success. // Skip if the same server already exists and its status == success. if (it != mDohTracker.end() && it->second == doh.value() && if (it != mDohTracker.end() && it->second == doh.value() && Loading PrivateDnsConfiguration.h +13 −3 Original line number Original line Diff line number Diff line Loading @@ -200,6 +200,7 @@ class PrivateDnsConfiguration { std::set<std::string> ips; std::set<std::string> ips; std::string host; std::string host; std::string httpsTemplate; std::string httpsTemplate; bool forTesting; base::Result<DohIdentity> getDohIdentity(const std::vector<std::string>& ips, base::Result<DohIdentity> getDohIdentity(const std::vector<std::string>& ips, const std::string& host) const { const std::string& host) const { if (!host.empty() && this->host != host) return Errorf("host {} not matched", host); if (!host.empty() && this->host != host) return Errorf("host {} not matched", host); Loading @@ -215,15 +216,24 @@ class PrivateDnsConfiguration { // TODO: Move below DoH relevant stuff into Rust implementation. // TODO: Move below DoH relevant stuff into Rust implementation. std::map<unsigned, DohIdentity> mDohTracker GUARDED_BY(mPrivateDnsLock); std::map<unsigned, DohIdentity> mDohTracker GUARDED_BY(mPrivateDnsLock); std::array<DohProviderEntry, 2> mAvailableDoHProviders = {{ std::array<DohProviderEntry, 3> mAvailableDoHProviders = {{ {"Google", {"Google", {"2001:4860:4860::8888", "2001:4860:4860::8844", "8.8.8.8", "8.8.4.4"}, {"2001:4860:4860::8888", "2001:4860:4860::8844", "8.8.8.8", "8.8.4.4"}, "dns.google", "dns.google", "https://dns.google/dns-query"}, "https://dns.google/dns-query", false}, {"Cloudflare", {"Cloudflare", {"2606:4700::6810:f8f9", "2606:4700::6810:f9f9", "104.16.248.249", "104.16.249.249"}, {"2606:4700::6810:f8f9", "2606:4700::6810:f9f9", "104.16.248.249", "104.16.249.249"}, "cloudflare-dns.com", "cloudflare-dns.com", "https://cloudflare-dns.com/dns-query"}, "https://cloudflare-dns.com/dns-query", false}, // The DoH provider for testing. {"ResolverTestProvider", {"127.0.0.3", "::1"}, "example.com", "https://example.com/dns-query", true}, }}; }}; struct RecordEntry { struct RecordEntry { Loading tests/Android.bp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -160,7 +160,9 @@ cc_test { srcs: [ srcs: [ "dns_responder/dns_responder.cpp", "dns_responder/dns_responder.cpp", "dnsresolver_binder_test.cpp", "dnsresolver_binder_test.cpp", "doh_frontend.cpp", "resolv_integration_test.cpp", "resolv_integration_test.cpp", "resolv_private_dns_test.cpp", "tun_forwarder.cpp", "tun_forwarder.cpp", ], ], header_libs: [ header_libs: [ Loading Loading @@ -188,6 +190,7 @@ cc_test { "netd_event_listener_interface-lateststable-ndk_platform", "netd_event_listener_interface-lateststable-ndk_platform", "libipchecksum", "libipchecksum", "resolv_unsolicited_listener", "resolv_unsolicited_listener", "libdoh_frontend_ffi", ], ], // This test talks to the DnsResolver module over a binary protocol on a socket, so keep it as // This test talks to the DnsResolver module over a binary protocol on a socket, so keep it as // multilib setting is worth because we might be able to get some coverage for the case where // multilib setting is worth because we might be able to get some coverage for the case where Loading tests/doh_frontend.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -60,7 +60,7 @@ bool DohFrontend::stopServer() { int DohFrontend::queries() const { int DohFrontend::queries() const { std::lock_guard guard(mMutex); std::lock_guard guard(mMutex); if (!mRustDoh) return -1; if (!mRustDoh) return 0; rust::Stats stats; rust::Stats stats; rust::frontend_stats(mRustDoh, &stats); rust::frontend_stats(mRustDoh, &stats); Loading tests/resolv_integration_test.cpp +0 −24 Original line number Original line Diff line number Diff line Loading @@ -19,7 +19,6 @@ #include <android-base/logging.h> #include <android-base/logging.h> #include <android-base/parseint.h> #include <android-base/parseint.h> #include <android-base/properties.h> #include <android-base/result.h> #include <android-base/result.h> #include <android-base/stringprintf.h> #include <android-base/stringprintf.h> #include <android-base/unique_fd.h> #include <android-base/unique_fd.h> Loading Loading @@ -126,18 +125,8 @@ using android::netdutils::ScopedAddrinfo; using android::netdutils::Stopwatch; using android::netdutils::Stopwatch; using android::netdutils::toHex; using android::netdutils::toHex; // TODO: move into libnetdutils? namespace { namespace { ScopedAddrinfo safe_getaddrinfo(const char* node, const char* service, const struct addrinfo* hints) { addrinfo* result = nullptr; if (getaddrinfo(node, service, hints, &result) != 0) { result = nullptr; // Should already be the case, but... } return ScopedAddrinfo(result); } std::pair<ScopedAddrinfo, int> safe_getaddrinfo_time_taken(const char* node, const char* service, std::pair<ScopedAddrinfo, int> safe_getaddrinfo_time_taken(const char* node, const char* service, const addrinfo& hints) { const addrinfo& hints) { Stopwatch s; Stopwatch s; Loading Loading @@ -172,19 +161,6 @@ struct NameserverStats { int internal_errors = 0; int internal_errors = 0; }; }; class ScopedSystemProperties { public: ScopedSystemProperties(const std::string& key, const std::string& value) : mStoredKey(key) { mStoredValue = android::base::GetProperty(key, ""); android::base::SetProperty(key, value); } ~ScopedSystemProperties() { android::base::SetProperty(mStoredKey, mStoredValue); } private: std::string mStoredKey; std::string mStoredValue; }; const bool isAtLeastR = (getApiLevel() >= 30); const bool isAtLeastR = (getApiLevel() >= 30); } // namespace } // namespace Loading Loading
PrivateDnsConfiguration.cpp +4 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include <android-base/format.h> #include <android-base/format.h> #include <android-base/logging.h> #include <android-base/logging.h> #include <android-base/stringprintf.h> #include <android-base/stringprintf.h> #include <android/binder_ibinder.h> #include <netdutils/Slice.h> #include <netdutils/Slice.h> #include <netdutils/ThreadUtil.h> #include <netdutils/ThreadUtil.h> #include <sys/socket.h> #include <sys/socket.h> Loading Loading @@ -444,6 +445,9 @@ int PrivateDnsConfiguration::setDoh(int32_t netId, uint32_t mark, const auto& doh = entry.getDohIdentity(sortedServers, name); const auto& doh = entry.getDohIdentity(sortedServers, name); if (!doh.ok()) continue; if (!doh.ok()) continue; // The internal tests are supposed to have root permission. if (entry.forTesting && AIBinder_getCallingUid() != AID_ROOT) continue; auto it = mDohTracker.find(netId); auto it = mDohTracker.find(netId); // Skip if the same server already exists and its status == success. // Skip if the same server already exists and its status == success. if (it != mDohTracker.end() && it->second == doh.value() && if (it != mDohTracker.end() && it->second == doh.value() && Loading
PrivateDnsConfiguration.h +13 −3 Original line number Original line Diff line number Diff line Loading @@ -200,6 +200,7 @@ class PrivateDnsConfiguration { std::set<std::string> ips; std::set<std::string> ips; std::string host; std::string host; std::string httpsTemplate; std::string httpsTemplate; bool forTesting; base::Result<DohIdentity> getDohIdentity(const std::vector<std::string>& ips, base::Result<DohIdentity> getDohIdentity(const std::vector<std::string>& ips, const std::string& host) const { const std::string& host) const { if (!host.empty() && this->host != host) return Errorf("host {} not matched", host); if (!host.empty() && this->host != host) return Errorf("host {} not matched", host); Loading @@ -215,15 +216,24 @@ class PrivateDnsConfiguration { // TODO: Move below DoH relevant stuff into Rust implementation. // TODO: Move below DoH relevant stuff into Rust implementation. std::map<unsigned, DohIdentity> mDohTracker GUARDED_BY(mPrivateDnsLock); std::map<unsigned, DohIdentity> mDohTracker GUARDED_BY(mPrivateDnsLock); std::array<DohProviderEntry, 2> mAvailableDoHProviders = {{ std::array<DohProviderEntry, 3> mAvailableDoHProviders = {{ {"Google", {"Google", {"2001:4860:4860::8888", "2001:4860:4860::8844", "8.8.8.8", "8.8.4.4"}, {"2001:4860:4860::8888", "2001:4860:4860::8844", "8.8.8.8", "8.8.4.4"}, "dns.google", "dns.google", "https://dns.google/dns-query"}, "https://dns.google/dns-query", false}, {"Cloudflare", {"Cloudflare", {"2606:4700::6810:f8f9", "2606:4700::6810:f9f9", "104.16.248.249", "104.16.249.249"}, {"2606:4700::6810:f8f9", "2606:4700::6810:f9f9", "104.16.248.249", "104.16.249.249"}, "cloudflare-dns.com", "cloudflare-dns.com", "https://cloudflare-dns.com/dns-query"}, "https://cloudflare-dns.com/dns-query", false}, // The DoH provider for testing. {"ResolverTestProvider", {"127.0.0.3", "::1"}, "example.com", "https://example.com/dns-query", true}, }}; }}; struct RecordEntry { struct RecordEntry { Loading
tests/Android.bp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -160,7 +160,9 @@ cc_test { srcs: [ srcs: [ "dns_responder/dns_responder.cpp", "dns_responder/dns_responder.cpp", "dnsresolver_binder_test.cpp", "dnsresolver_binder_test.cpp", "doh_frontend.cpp", "resolv_integration_test.cpp", "resolv_integration_test.cpp", "resolv_private_dns_test.cpp", "tun_forwarder.cpp", "tun_forwarder.cpp", ], ], header_libs: [ header_libs: [ Loading Loading @@ -188,6 +190,7 @@ cc_test { "netd_event_listener_interface-lateststable-ndk_platform", "netd_event_listener_interface-lateststable-ndk_platform", "libipchecksum", "libipchecksum", "resolv_unsolicited_listener", "resolv_unsolicited_listener", "libdoh_frontend_ffi", ], ], // This test talks to the DnsResolver module over a binary protocol on a socket, so keep it as // This test talks to the DnsResolver module over a binary protocol on a socket, so keep it as // multilib setting is worth because we might be able to get some coverage for the case where // multilib setting is worth because we might be able to get some coverage for the case where Loading
tests/doh_frontend.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -60,7 +60,7 @@ bool DohFrontend::stopServer() { int DohFrontend::queries() const { int DohFrontend::queries() const { std::lock_guard guard(mMutex); std::lock_guard guard(mMutex); if (!mRustDoh) return -1; if (!mRustDoh) return 0; rust::Stats stats; rust::Stats stats; rust::frontend_stats(mRustDoh, &stats); rust::frontend_stats(mRustDoh, &stats); Loading
tests/resolv_integration_test.cpp +0 −24 Original line number Original line Diff line number Diff line Loading @@ -19,7 +19,6 @@ #include <android-base/logging.h> #include <android-base/logging.h> #include <android-base/parseint.h> #include <android-base/parseint.h> #include <android-base/properties.h> #include <android-base/result.h> #include <android-base/result.h> #include <android-base/stringprintf.h> #include <android-base/stringprintf.h> #include <android-base/unique_fd.h> #include <android-base/unique_fd.h> Loading Loading @@ -126,18 +125,8 @@ using android::netdutils::ScopedAddrinfo; using android::netdutils::Stopwatch; using android::netdutils::Stopwatch; using android::netdutils::toHex; using android::netdutils::toHex; // TODO: move into libnetdutils? namespace { namespace { ScopedAddrinfo safe_getaddrinfo(const char* node, const char* service, const struct addrinfo* hints) { addrinfo* result = nullptr; if (getaddrinfo(node, service, hints, &result) != 0) { result = nullptr; // Should already be the case, but... } return ScopedAddrinfo(result); } std::pair<ScopedAddrinfo, int> safe_getaddrinfo_time_taken(const char* node, const char* service, std::pair<ScopedAddrinfo, int> safe_getaddrinfo_time_taken(const char* node, const char* service, const addrinfo& hints) { const addrinfo& hints) { Stopwatch s; Stopwatch s; Loading Loading @@ -172,19 +161,6 @@ struct NameserverStats { int internal_errors = 0; int internal_errors = 0; }; }; class ScopedSystemProperties { public: ScopedSystemProperties(const std::string& key, const std::string& value) : mStoredKey(key) { mStoredValue = android::base::GetProperty(key, ""); android::base::SetProperty(key, value); } ~ScopedSystemProperties() { android::base::SetProperty(mStoredKey, mStoredValue); } private: std::string mStoredKey; std::string mStoredValue; }; const bool isAtLeastR = (getApiLevel() >= 30); const bool isAtLeastR = (getApiLevel() >= 30); } // namespace } // namespace Loading