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

Commit 0161acd3 authored by waynema's avatar waynema
Browse files

Add RESOLVER_PARAMS_RETRY_COUNT for configuring the retries.

Test: built / flashed / booted
      netd_unit_test, netd_integration_test, libnetd_resolv_test

Change-Id: I68db331b3c8ad8e43696816642f4d5941138c8bc
parent ab9762b6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ inline const std::vector<int> kDefaultParams = {
        25,      // success threshod in percent
        8,   8,  // {MIN,MAX}_SAMPLES
        100,     // BASE_TIMEOUT_MSEC
        2,       // retry count
};

class DnsResponderClient {
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ struct __res_params {
    uint8_t min_samples;        // min # samples needed for statistics to be considered meaningful
    uint8_t max_samples;        // max # samples taken into account for statistics
    int base_timeout_msec;      // base query retry timeout (if 0, use RES_TIMEOUT)
    int retry_count;            // number of retries
};

// The DNS over TLS mode on a specific netId.
+1 −0
Original line number Diff line number Diff line
@@ -1712,6 +1712,7 @@ static void resolv_set_default_params(struct __res_params* params) {
    params->min_samples = 0;
    params->max_samples = 0;
    params->base_timeout_msec = 0;  // 0 = legacy algorithm
    params->retry_count = 0;
}

int resolv_set_nameservers_for_net(unsigned netid, const char** servers, const int numservers,
+7 −5
Original line number Diff line number Diff line
@@ -506,17 +506,19 @@ int res_nsend(res_state statp, const u_char* buf, int buflen, u_char* ans, int a
        statp->_u._ext.nstimes[lastns] = nstime;
    }

    struct res_stats stats[MAXNS];
    struct __res_params params;
    int revision_id = resolv_cache_get_resolver_stats(statp->netid, &params, stats);
    bool usable_servers[MAXNS];
    android_net_res_stats_get_usable_servers(&params, stats, statp->nscount, usable_servers);
    if (params.retry_count != 0) statp->retry = params.retry_count;

    /*
     * Send request, RETRY times, or until successful.
     */
    int retryTimes = (flags & ANDROID_RESOLV_NO_RETRY) ? 1 : statp->retry;

    for (int attempt = 0; attempt < retryTimes; ++attempt) {
        struct res_stats stats[MAXNS];
        struct __res_params params;
        int revision_id = resolv_cache_get_resolver_stats(statp->netid, &params, stats);
        bool usable_servers[MAXNS];
        android_net_res_stats_get_usable_servers(&params, stats, statp->nscount, usable_servers);

        for (int ns = 0; ns < statp->nscount; ns++) {
            if (!usable_servers[ns]) continue;
+13 −15
Original line number Diff line number Diff line
@@ -134,15 +134,14 @@ class ResolverTest : public ::testing::Test {
            return false;
        }
        *params = __res_params{
            .sample_validity = static_cast<uint16_t>(
                    params32[INetd::RESOLVER_PARAMS_SAMPLE_VALIDITY]),
            .success_threshold = static_cast<uint8_t>(
                    params32[INetd::RESOLVER_PARAMS_SUCCESS_THRESHOLD]),
            .min_samples = static_cast<uint8_t>(
                    params32[INetd::RESOLVER_PARAMS_MIN_SAMPLES]),
            .max_samples = static_cast<uint8_t>(
                    params32[INetd::RESOLVER_PARAMS_MAX_SAMPLES]),
                .sample_validity =
                        static_cast<uint16_t>(params32[INetd::RESOLVER_PARAMS_SAMPLE_VALIDITY]),
                .success_threshold =
                        static_cast<uint8_t>(params32[INetd::RESOLVER_PARAMS_SUCCESS_THRESHOLD]),
                .min_samples = static_cast<uint8_t>(params32[INetd::RESOLVER_PARAMS_MIN_SAMPLES]),
                .max_samples = static_cast<uint8_t>(params32[INetd::RESOLVER_PARAMS_MAX_SAMPLES]),
                .base_timeout_msec = params32[INetd::RESOLVER_PARAMS_BASE_TIMEOUT_MSEC],
                .retry_count = params32[INetd::RESOLVER_PARAMS_RETRY_COUNT],
        };
        *wait_for_pending_req_timeout_count = wait_for_pending_req_timeout_count32[0];
        return ResolverStats::decodeAll(stats32, stats);
@@ -433,11 +432,9 @@ TEST_F(ResolverTest, GetHostByName_numeric) {
TEST_F(ResolverTest, BinderSerialization) {
    using android::net::INetd;
    std::vector<int> params_offsets = {
        INetd::RESOLVER_PARAMS_SAMPLE_VALIDITY,
        INetd::RESOLVER_PARAMS_SUCCESS_THRESHOLD,
        INetd::RESOLVER_PARAMS_MIN_SAMPLES,
        INetd::RESOLVER_PARAMS_MAX_SAMPLES,
        INetd::RESOLVER_PARAMS_BASE_TIMEOUT_MSEC,
            INetd::RESOLVER_PARAMS_SAMPLE_VALIDITY,   INetd::RESOLVER_PARAMS_SUCCESS_THRESHOLD,
            INetd::RESOLVER_PARAMS_MIN_SAMPLES,       INetd::RESOLVER_PARAMS_MAX_SAMPLES,
            INetd::RESOLVER_PARAMS_BASE_TIMEOUT_MSEC, INetd::RESOLVER_PARAMS_RETRY_COUNT,
    };
    const int size = static_cast<int>(params_offsets.size());
    EXPECT_EQ(size, INetd::RESOLVER_PARAMS_COUNT);
@@ -888,6 +885,7 @@ TEST_F(ResolverTest, EmptySetup) {
    EXPECT_EQ(kDefaultParams[INetd::RESOLVER_PARAMS_MAX_SAMPLES], res_params.max_samples);
    EXPECT_EQ(kDefaultParams[INetd::RESOLVER_PARAMS_BASE_TIMEOUT_MSEC],
              res_params.base_timeout_msec);
    EXPECT_EQ(kDefaultParams[INetd::RESOLVER_PARAMS_RETRY_COUNT], res_params.retry_count);
}

TEST_F(ResolverTest, SearchPathChange) {