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

Commit 163c8cc3 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9773888 from 155c7432 to mainline-mediaprovider-release

Change-Id: I78ec340106f7ea540200722688a19205dcbf1c74
parents 6746d721 155c7432
Loading
Loading
Loading
Loading
+13 −18
Original line number Original line Diff line number Diff line
@@ -156,10 +156,10 @@ const std::vector<IPSockAddr> mdns_addrs = {IPSockAddr::toIPSockAddr("ff02::fb",


static int setupUdpSocket(ResState* statp, const sockaddr* sockap, unique_fd* fd_out, int* terrno);
static int setupUdpSocket(ResState* statp, const sockaddr* sockap, unique_fd* fd_out, int* terrno);
static int send_dg(ResState* statp, res_params* params, span<const uint8_t> msg, span<uint8_t> ans,
static int send_dg(ResState* statp, res_params* params, span<const uint8_t> msg, span<uint8_t> ans,
                   int* terrno, size_t* ns, int* v_circuit, int* gotsomewhere, time_t* at,
                   int* terrno, size_t* ns, int* v_circuit, int* gotsomewhere, int* rcode,
                   int* rcode, int* delay);
                   int* delay);
static int send_vc(ResState* statp, res_params* params, span<const uint8_t> msg, span<uint8_t> ans,
static int send_vc(ResState* statp, res_params* params, span<const uint8_t> msg, span<uint8_t> ans,
                   int* terrno, size_t ns, time_t* at, int* rcode, int* delay);
                   int* terrno, size_t ns, int* rcode, int* delay);
static int send_mdns(ResState* statp, span<const uint8_t> msg, span<uint8_t> ans, int* terrno,
static int send_mdns(ResState* statp, span<const uint8_t> msg, span<uint8_t> ans, int* terrno,
                     int* rcode);
                     int* rcode);
static void dump_error(const char*, const struct sockaddr*);
static void dump_error(const char*, const struct sockaddr*);
@@ -580,14 +580,11 @@ int res_nsend(ResState* statp, span<const uint8_t> msg, span<uint8_t> ans, int*
            if (!usable_servers[ns]) continue;
            if (!usable_servers[ns]) continue;


            *rcode = RCODE_INTERNAL_ERROR;
            *rcode = RCODE_INTERNAL_ERROR;

            // Get server addr
            const IPSockAddr& serverSockAddr = statp->nsaddrs[ns];
            LOG(DEBUG) << __func__ << ": Querying server (# " << ns + 1
            LOG(DEBUG) << __func__ << ": Querying server (# " << ns + 1
                       << ") address = " << serverSockAddr.toString();
                       << ") address = " << statp->nsaddrs[ns].toString();


            ::android::net::Protocol query_proto = useTcp ? PROTO_TCP : PROTO_UDP;
            ::android::net::Protocol query_proto = useTcp ? PROTO_TCP : PROTO_UDP;
            time_t query_time = 0;
            const time_t query_time = time(nullptr);
            int delay = 0;
            int delay = 0;
            bool fallbackTCP = false;
            bool fallbackTCP = false;
            const bool shouldRecordStats = (attempt == 0);
            const bool shouldRecordStats = (attempt == 0);
@@ -600,8 +597,7 @@ int res_nsend(ResState* statp, span<const uint8_t> msg, span<uint8_t> ans, int*
            if (useTcp) {
            if (useTcp) {
                // TCP; at most one attempt per server.
                // TCP; at most one attempt per server.
                attempt = retryTimes;
                attempt = retryTimes;
                resplen =
                resplen = send_vc(statp, &params, msg, ans, &terrno, ns, rcode, &delay);
                        send_vc(statp, &params, msg, ans, &terrno, ns, &query_time, rcode, &delay);


                if (msg.size() <= PACKETSZ && resplen <= 0 &&
                if (msg.size() <= PACKETSZ && resplen <= 0 &&
                    statp->tc_mode == aidl::android::net::IDnsResolver::TC_MODE_UDP_TCP) {
                    statp->tc_mode == aidl::android::net::IDnsResolver::TC_MODE_UDP_TCP) {
@@ -613,7 +609,7 @@ int res_nsend(ResState* statp, span<const uint8_t> msg, span<uint8_t> ans, int*
            } else {
            } else {
                // UDP
                // UDP
                resplen = send_dg(statp, &params, msg, ans, &terrno, &actualNs, &useTcp,
                resplen = send_dg(statp, &params, msg, ans, &terrno, &actualNs, &useTcp,
                                  &gotsomewhere, &query_time, rcode, &delay);
                                  &gotsomewhere, rcode, &delay);
                fallbackTCP = useTcp ? true : false;
                fallbackTCP = useTcp ? true : false;
                retry_count_for_event = attempt;
                retry_count_for_event = attempt;
                LOG(INFO) << __func__ << ": used send_dg " << resplen << " terrno: " << terrno;
                LOG(INFO) << __func__ << ": used send_dg " << resplen << " terrno: " << terrno;
@@ -650,8 +646,9 @@ int res_nsend(ResState* statp, span<const uint8_t> msg, span<uint8_t> ans, int*
                    // KeepListening UDP mechanism is incompatible with usable_servers of legacy
                    // KeepListening UDP mechanism is incompatible with usable_servers of legacy
                    // stats, so keep the old logic for now.
                    // stats, so keep the old logic for now.
                    // TODO: Replace usable_servers of legacy stats with new one.
                    // TODO: Replace usable_servers of legacy stats with new one.
                    resolv_cache_add_resolver_stats_sample(
                    resolv_cache_add_resolver_stats_sample(statp->netid, revision_id,
                            statp->netid, revision_id, serverSockAddr, sample, params.max_samples);
                                                           receivedServerAddr, sample,
                                                           params.max_samples);
                    resolv_stats_add(statp->netid, receivedServerAddr, dnsQueryEvent);
                    resolv_stats_add(statp->netid, receivedServerAddr, dnsQueryEvent);
                }
                }
            }
            }
@@ -710,8 +707,7 @@ static struct timespec get_timeout(ResState* statp, const res_params* params, co
}
}


static int send_vc(ResState* statp, res_params* params, span<const uint8_t> msg, span<uint8_t> ans,
static int send_vc(ResState* statp, res_params* params, span<const uint8_t> msg, span<uint8_t> ans,
                   int* terrno, size_t ns, time_t* at, int* rcode, int* delay) {
                   int* terrno, size_t ns, int* rcode, int* delay) {
    *at = time(NULL);
    *delay = 0;
    *delay = 0;
    const HEADER* hp = (const HEADER*)(const void*)msg.data();
    const HEADER* hp = (const HEADER*)(const void*)msg.data();
    HEADER* anhp = (HEADER*)(void*)ans.data();
    HEADER* anhp = (HEADER*)(void*)ans.data();
@@ -1092,8 +1088,8 @@ static int setupUdpSocket(ResState* statp, const sockaddr* sockap, unique_fd* fd
}
}


static int send_dg(ResState* statp, res_params* params, span<const uint8_t> msg, span<uint8_t> ans,
static int send_dg(ResState* statp, res_params* params, span<const uint8_t> msg, span<uint8_t> ans,
                   int* terrno, size_t* ns, int* v_circuit, int* gotsomewhere, time_t* at,
                   int* terrno, size_t* ns, int* v_circuit, int* gotsomewhere, int* rcode,
                   int* rcode, int* delay) {
                   int* delay) {
    // It should never happen, but just in case.
    // It should never happen, but just in case.
    if (*ns >= statp->nsaddrs.size()) {
    if (*ns >= statp->nsaddrs.size()) {
        LOG(ERROR) << __func__ << ": Out-of-bound indexing: " << ns;
        LOG(ERROR) << __func__ << ": Out-of-bound indexing: " << ns;
@@ -1101,7 +1097,6 @@ static int send_dg(ResState* statp, res_params* params, span<const uint8_t> msg,
        return -1;
        return -1;
    }
    }


    *at = time(nullptr);
    *delay = 0;
    *delay = 0;
    const sockaddr_storage ss = statp->nsaddrs[*ns];
    const sockaddr_storage ss = statp->nsaddrs[*ns];
    const sockaddr* nsap = reinterpret_cast<const sockaddr*>(&ss);
    const sockaddr* nsap = reinterpret_cast<const sockaddr*>(&ss);
+43 −10
Original line number Original line Diff line number Diff line
@@ -154,12 +154,17 @@ struct NameserverStats {
        internal_errors = val;
        internal_errors = val;
        return *this;
        return *this;
    }
    }
    NameserverStats& setRttAvg(int val) {
        rtt_avg = val;
        return *this;
    }


    const std::string server;
    const std::string server;
    int successes = 0;
    int successes = 0;
    int errors = 0;
    int errors = 0;
    int timeouts = 0;
    int timeouts = 0;
    int internal_errors = 0;
    int internal_errors = 0;
    int rtt_avg = -1;
};
};


const bool isAtLeastR = (getApiLevel() >= 30);
const bool isAtLeastR = (getApiLevel() >= 30);
@@ -349,7 +354,7 @@ class ResolverTest : public NetNativeTestBase {
            }
            }
            const int index = std::distance(res_servers.begin(), it);
            const int index = std::distance(res_servers.begin(), it);


            // The check excludes rtt_avg, last_sample_time, and usable since they will be obsolete
            // The check excludes last_sample_time and usable since they will be obsolete
            // after |res_stats| is retrieved from NetConfig.dnsStats rather than NetConfig.nsstats.
            // after |res_stats| is retrieved from NetConfig.dnsStats rather than NetConfig.nsstats.
            switch (cmp) {
            switch (cmp) {
                case StatsCmp::EQ:
                case StatsCmp::EQ:
@@ -357,12 +362,21 @@ class ResolverTest : public NetNativeTestBase {
                    EXPECT_EQ(res_stats[index].errors, stats.errors);
                    EXPECT_EQ(res_stats[index].errors, stats.errors);
                    EXPECT_EQ(res_stats[index].timeouts, stats.timeouts);
                    EXPECT_EQ(res_stats[index].timeouts, stats.timeouts);
                    EXPECT_EQ(res_stats[index].internal_errors, stats.internal_errors);
                    EXPECT_EQ(res_stats[index].internal_errors, stats.internal_errors);
                    // A negative rtt_avg means that there is no effective rtt in the
                    // stats. The value should be deterministic.
                    // See android_net_res_stats_aggregate() for mor details.
                    if (res_stats[index].rtt_avg < 0 || stats.rtt_avg < 0) {
                        EXPECT_EQ(res_stats[index].rtt_avg, stats.rtt_avg);
                    } else {
                        EXPECT_NEAR(res_stats[index].rtt_avg, stats.rtt_avg, 200);
                    }
                    break;
                    break;
                case StatsCmp::LE:
                case StatsCmp::LE:
                    EXPECT_LE(res_stats[index].successes, stats.successes);
                    EXPECT_LE(res_stats[index].successes, stats.successes);
                    EXPECT_LE(res_stats[index].errors, stats.errors);
                    EXPECT_LE(res_stats[index].errors, stats.errors);
                    EXPECT_LE(res_stats[index].timeouts, stats.timeouts);
                    EXPECT_LE(res_stats[index].timeouts, stats.timeouts);
                    EXPECT_LE(res_stats[index].internal_errors, stats.internal_errors);
                    EXPECT_LE(res_stats[index].internal_errors, stats.internal_errors);
                    EXPECT_LE(res_stats[index].rtt_avg, stats.rtt_avg);
                    break;
                    break;
                default:
                default:
                    ADD_FAILURE() << "Unknown comparator " << static_cast<int>(cmp);
                    ADD_FAILURE() << "Unknown comparator " << static_cast<int>(cmp);
@@ -1407,7 +1421,7 @@ TEST_F(ResolverTest, SkipBadServersDueToInternalError) {
        const std::vector<NameserverStats> targetStats = {
        const std::vector<NameserverStats> targetStats = {
                NameserverStats(listen_addr1).setInternalErrors(5),
                NameserverStats(listen_addr1).setInternalErrors(5),
                NameserverStats(listen_addr2).setInternalErrors(5),
                NameserverStats(listen_addr2).setInternalErrors(5),
                NameserverStats(listen_addr3).setSuccesses(setupParams.maxSamples),
                NameserverStats(listen_addr3).setSuccesses(setupParams.maxSamples).setRttAvg(1),
        };
        };
        EXPECT_TRUE(expectStatsNotGreaterThan(targetStats));
        EXPECT_TRUE(expectStatsNotGreaterThan(targetStats));


@@ -1461,7 +1475,7 @@ TEST_F(ResolverTest, SkipBadServersDueToTimeout) {


        const std::vector<NameserverStats> targetStats = {
        const std::vector<NameserverStats> targetStats = {
                NameserverStats(listen_addr1).setTimeouts(5),
                NameserverStats(listen_addr1).setTimeouts(5),
                NameserverStats(listen_addr2).setSuccesses(setupParams.maxSamples),
                NameserverStats(listen_addr2).setSuccesses(setupParams.maxSamples).setRttAvg(1),
        };
        };
        EXPECT_TRUE(expectStatsNotGreaterThan(targetStats));
        EXPECT_TRUE(expectStatsNotGreaterThan(targetStats));


@@ -1930,7 +1944,7 @@ TEST_F(ResolverTest, ResolverStats) {
    const std::vector<NameserverStats> expectedCleartextDnsStats = {
    const std::vector<NameserverStats> expectedCleartextDnsStats = {
            NameserverStats(listen_addr1).setTimeouts(1),
            NameserverStats(listen_addr1).setTimeouts(1),
            NameserverStats(listen_addr2).setErrors(1),
            NameserverStats(listen_addr2).setErrors(1),
            NameserverStats(listen_addr3).setSuccesses(1),
            NameserverStats(listen_addr3).setSuccesses(1).setRttAvg(1),
    };
    };
    EXPECT_TRUE(expectStatsEqualTo(expectedCleartextDnsStats));
    EXPECT_TRUE(expectStatsEqualTo(expectedCleartextDnsStats));
}
}
@@ -1988,7 +2002,7 @@ TEST_F(ResolverTest, AlwaysUseLatestSetupParamsInLookups) {
    const std::vector<NameserverStats> expectedCleartextDnsStats = {
    const std::vector<NameserverStats> expectedCleartextDnsStats = {
            NameserverStats(listen_addr1),
            NameserverStats(listen_addr1),
            NameserverStats(listen_addr2),
            NameserverStats(listen_addr2),
            NameserverStats(listen_addr3).setSuccesses(1),
            NameserverStats(listen_addr3).setSuccesses(1).setRttAvg(1),
    };
    };
    EXPECT_TRUE(expectStatsEqualTo(expectedCleartextDnsStats));
    EXPECT_TRUE(expectStatsEqualTo(expectedCleartextDnsStats));
}
}
@@ -5535,7 +5549,7 @@ TEST_F(ResolverTest, RepeatedSetup_ResolverStatusRemains) {
    // Check the stats as expected.
    // Check the stats as expected.
    const std::vector<NameserverStats> expectedCleartextDnsStats = {
    const std::vector<NameserverStats> expectedCleartextDnsStats = {
            NameserverStats(unusable_listen_addr).setInternalErrors(1),
            NameserverStats(unusable_listen_addr).setInternalErrors(1),
            NameserverStats(listen_addr).setSuccesses(1),
            NameserverStats(listen_addr).setSuccesses(1).setRttAvg(1),
    };
    };
    EXPECT_TRUE(expectStatsEqualTo(expectedCleartextDnsStats));
    EXPECT_TRUE(expectStatsEqualTo(expectedCleartextDnsStats));
    EXPECT_EQ(GetNumQueries(dns, hostname), 1U);
    EXPECT_EQ(GetNumQueries(dns, hostname), 1U);
@@ -6122,9 +6136,15 @@ TEST_F(ResolverTest, KeepListeningUDP) {
    const struct TestConfig {
    const struct TestConfig {
        int retryCount;
        int retryCount;
        int delayTimeMs;
        int delayTimeMs;
        int expectedDns1Successes;
        int expectedDns1Timeouts;
        int expectedDns2Timeouts;
    } testConfigs[]{
    } testConfigs[]{
            {1, 1500},
            {1, 1500, 1, 1, 0},
            {2, 3500},
            // Actually, there will be two timeouts and one success for DNS1. However, the
            // DnsResolver doesn't record the stats during the second iteration of DNS servers, so
            // the success and timeout of DNS1 is 0 and 1, respectively.
            {2, 3500, 0, 1, 1},
    };
    };
    for (const std::string_view callType : {"getaddrinfo", "resnsend"}) {
    for (const std::string_view callType : {"getaddrinfo", "resnsend"}) {
        for (const auto& cfg : testConfigs) {
        for (const auto& cfg : testConfigs) {
@@ -6151,7 +6171,18 @@ TEST_F(ResolverTest, KeepListeningUDP) {
                int fd = resNetworkQuery(TEST_NETID, host_name, ns_c_in, ns_t_aaaa, 0);
                int fd = resNetworkQuery(TEST_NETID, host_name, ns_c_in, ns_t_aaaa, 0);
                expectAnswersValid(fd, AF_INET6, "::1.2.3.4");
                expectAnswersValid(fd, AF_INET6, "::1.2.3.4");
            }
            }
            // TODO(b/271405311): check that the DNS stats from getResolverInfo() is correct.
            const std::vector<NameserverStats> expectedCleartextDnsStats = {
                    NameserverStats(listen_addr1)
                            .setSuccesses(cfg.expectedDns1Successes)
                            .setTimeouts(cfg.expectedDns1Timeouts)
                            // TODO(271406438): Fix the latency bug in the stats and correct the
                            // value to be 1500.
                            .setRttAvg(cfg.retryCount == 1 ? 500 : -1),
                    NameserverStats(listen_addr2)
                            .setTimeouts(cfg.expectedDns2Timeouts)
                            .setRttAvg(-1),
            };
            EXPECT_TRUE(expectStatsEqualTo(expectedCleartextDnsStats));
            thread.join();
            thread.join();
        }
        }
    }
    }
@@ -6266,7 +6297,9 @@ TEST_F(ResolverTest, BlockDnsQueryUidDoesNotLeadToBadServer) {
    // If api level >= 30 (R+), expect all query packets to be blocked, hence we should not see any
    // If api level >= 30 (R+), expect all query packets to be blocked, hence we should not see any
    // of their stats show up. Otherwise, all queries should succeed.
    // of their stats show up. Otherwise, all queries should succeed.
    const std::vector<NameserverStats> expectedDnsStats = {
    const std::vector<NameserverStats> expectedDnsStats = {
            NameserverStats(listen_addr1).setSuccesses(isAtLeastR ? 0 : setupParams.maxSamples),
            NameserverStats(listen_addr1)
                    .setSuccesses(isAtLeastR ? 0 : setupParams.maxSamples)
                    .setRttAvg(isAtLeastR ? -1 : 1),
            NameserverStats(listen_addr2),
            NameserverStats(listen_addr2),
    };
    };
    expectStatsEqualTo(expectedDnsStats);
    expectStatsEqualTo(expectedDnsStats);