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

Commit 66917e7d authored by Mike Yu's avatar Mike Yu Committed by Automerger Merge Worker
Browse files

Merge "Add some DoH tests in resolv_integration_test" am: 05c45a0e

Original change: https://android-review.googlesource.com/c/platform/packages/modules/DnsResolver/+/1771146

Change-Id: I7143e0128f4ddfc4bebbb1a2043212d1bdaa5dfd
parents 1955d102 05c45a0e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <android-base/format.h>
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#include <android/binder_ibinder.h>
#include <netdutils/Slice.h>
#include <netdutils/ThreadUtil.h>
#include <sys/socket.h>
@@ -444,6 +445,9 @@ int PrivateDnsConfiguration::setDoh(int32_t netId, uint32_t mark,
        const auto& doh = entry.getDohIdentity(sortedServers, name);
        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);
        // Skip if the same server already exists and its status == success.
        if (it != mDohTracker.end() && it->second == doh.value() &&
+13 −3
Original line number Diff line number Diff line
@@ -200,6 +200,7 @@ class PrivateDnsConfiguration {
        std::set<std::string> ips;
        std::string host;
        std::string httpsTemplate;
        bool forTesting;
        base::Result<DohIdentity> getDohIdentity(const std::vector<std::string>& ips,
                                                 const std::string& host) const {
            if (!host.empty() && this->host != host) return Errorf("host {} not matched", host);
@@ -215,15 +216,24 @@ class PrivateDnsConfiguration {

    // TODO: Move below DoH relevant stuff into Rust implementation.
    std::map<unsigned, DohIdentity> mDohTracker GUARDED_BY(mPrivateDnsLock);
    std::array<DohProviderEntry, 2> mAvailableDoHProviders = {{
    std::array<DohProviderEntry, 3> mAvailableDoHProviders = {{
            {"Google",
             {"2001:4860:4860::8888", "2001:4860:4860::8844", "8.8.8.8", "8.8.4.4"},
             "dns.google",
             "https://dns.google/dns-query"},
             "https://dns.google/dns-query",
             false},
            {"Cloudflare",
             {"2606:4700::6810:f8f9", "2606:4700::6810:f9f9", "104.16.248.249", "104.16.249.249"},
             "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 {
+3 −0
Original line number Diff line number Diff line
@@ -160,7 +160,9 @@ cc_test {
    srcs: [
        "dns_responder/dns_responder.cpp",
        "dnsresolver_binder_test.cpp",
        "doh_frontend.cpp",
        "resolv_integration_test.cpp",
        "resolv_private_dns_test.cpp",
        "tun_forwarder.cpp",
    ],
    header_libs: [
@@ -188,6 +190,7 @@ cc_test {
        "netd_event_listener_interface-lateststable-ndk_platform",
        "libipchecksum",
        "resolv_unsolicited_listener",
        "libdoh_frontend_ffi",
    ],
    // 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
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ bool DohFrontend::stopServer() {

int DohFrontend::queries() const {
    std::lock_guard guard(mMutex);
    if (!mRustDoh) return -1;
    if (!mRustDoh) return 0;

    rust::Stats stats;
    rust::frontend_stats(mRustDoh, &stats);
+0 −24
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@

#include <android-base/logging.h>
#include <android-base/parseint.h>
#include <android-base/properties.h>
#include <android-base/result.h>
#include <android-base/stringprintf.h>
#include <android-base/unique_fd.h>
@@ -126,18 +125,8 @@ using android::netdutils::ScopedAddrinfo;
using android::netdutils::Stopwatch;
using android::netdutils::toHex;

// TODO: move into libnetdutils?
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,
                                                           const addrinfo& hints) {
    Stopwatch s;
@@ -172,19 +161,6 @@ struct NameserverStats {
    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);

}  // namespace
Loading