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

Commit 54fd7454 authored by Luke Huang's avatar Luke Huang Committed by android-build-merger
Browse files

Merge "Fix asynchronous DNS API flag NO_CACHE_LOOKUP behavior"

am: 079af98866

Change-Id: Ib6ac80dac4dc761ed6f7d550d450d0919360cbe1
parents c2b88041 a1d74187
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -1411,8 +1411,10 @@ static resolv_cache_info* find_cache_info_locked(unsigned netid) REQUIRES(cache_
ResolvCacheStatus _resolv_cache_lookup(unsigned netid, const void* query, int querylen,
ResolvCacheStatus _resolv_cache_lookup(unsigned netid, const void* query, int querylen,
                                       void* answer, int answersize, int* answerlen,
                                       void* answer, int answersize, int* answerlen,
                                       uint32_t flags) {
                                       uint32_t flags) {
    // Skip cache lookup, return RESOLV_CACHE_NOTFOUND directly so that it is
    // possible to cache the answer of this query.
    if (flags & ANDROID_RESOLV_NO_CACHE_LOOKUP) {
    if (flags & ANDROID_RESOLV_NO_CACHE_LOOKUP) {
        return RESOLV_CACHE_SKIP;
        return RESOLV_CACHE_NOTFOUND;
    }
    }
    Entry key;
    Entry key;
    Entry** lookup;
    Entry** lookup;
@@ -1542,7 +1544,8 @@ void _resolv_cache_add(unsigned netid, const void* query, int querylen, const vo
    lookup = _cache_lookup_p(cache, key);
    lookup = _cache_lookup_p(cache, key);
    e = *lookup;
    e = *lookup;


    if (e != NULL) { /* should not happen */
    // Should only happen on ANDROID_RESOLV_NO_CACHE_LOOKUP
    if (e != NULL) {
        LOG(INFO) << __func__ << ": ALREADY IN CACHE (" << e << ") ? IGNORING ADD";
        LOG(INFO) << __func__ << ": ALREADY IN CACHE (" << e << ") ? IGNORING ADD";
        _cache_notify_waiting_tid_locked(cache, key);
        _cache_notify_waiting_tid_locked(cache, key);
        return;
        return;
@@ -1553,7 +1556,7 @@ void _resolv_cache_add(unsigned netid, const void* query, int querylen, const vo
        if (cache->num_entries >= cache->max_entries) {
        if (cache->num_entries >= cache->max_entries) {
            _cache_remove_oldest(cache);
            _cache_remove_oldest(cache);
        }
        }
        /* need to lookup again */
        // TODO: It looks useless, remove below code after having test to prove it.
        lookup = _cache_lookup_p(cache, key);
        lookup = _cache_lookup_p(cache, key);
        e = *lookup;
        e = *lookup;
        if (e != NULL) {
        if (e != NULL) {
+30 −0
Original line number Original line Diff line number Diff line
@@ -2116,6 +2116,36 @@ TEST_F(ResolverTest, Async_CacheFlags) {


    // Cache hits,  expect still 6 queries
    // Cache hits,  expect still 6 queries
    EXPECT_EQ(6U, GetNumQueries(dns, host_name));
    EXPECT_EQ(6U, GetNumQueries(dns, host_name));

    // Start to verify if ANDROID_RESOLV_NO_CACHE_LOOKUP does write response into cache
    dns.clearQueries();

    fd1 = resNetworkQuery(TEST_NETID, "howdy.example.com", ns_c_in, ns_t_aaaa,
                          ANDROID_RESOLV_NO_CACHE_LOOKUP);
    fd2 = resNetworkQuery(TEST_NETID, "howdy.example.com", ns_c_in, ns_t_aaaa,
                          ANDROID_RESOLV_NO_CACHE_LOOKUP);

    EXPECT_TRUE(fd1 != -1);
    EXPECT_TRUE(fd2 != -1);

    expectAnswersValid(fd2, AF_INET6, "::1.2.3.4");
    expectAnswersValid(fd1, AF_INET6, "::1.2.3.4");

    // Skip cache, expect 2 queries
    EXPECT_EQ(2U, GetNumQueries(dns, host_name));

    // Re-query without flags
    fd1 = resNetworkQuery(TEST_NETID, "howdy.example.com", ns_c_in, ns_t_aaaa, 0);
    fd2 = resNetworkQuery(TEST_NETID, "howdy.example.com", ns_c_in, ns_t_aaaa, 0);

    EXPECT_TRUE(fd1 != -1);
    EXPECT_TRUE(fd2 != -1);

    expectAnswersValid(fd2, AF_INET6, "::1.2.3.4");
    expectAnswersValid(fd1, AF_INET6, "::1.2.3.4");

    // Cache hits, expect still 2 queries
    EXPECT_EQ(2U, GetNumQueries(dns, host_name));
}
}


TEST_F(ResolverTest, Async_NoRetryFlag) {
TEST_F(ResolverTest, Async_NoRetryFlag) {