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

Commit ba7bef92 authored by Luke Huang's avatar Luke Huang
Browse files

Implementation of control flags in asynchronous DNS query API

Flags definitions are in multinetwork.h

Test: built, flashed, booted
      system/netd/tests/runtests.sh passes

Change-Id: Iab1983b783d1470bc1cf23489abbef7a2d88e860
parent 9c2c06f3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1635,7 +1635,7 @@ static int res_queryN(const char* name, res_target* target, res_state res, int*
            return n;
        }

        n = res_nsend(res, buf, n, answer, anslen, &rcode);
        n = res_nsend(res, buf, n, answer, anslen, &rcode, 0);
        if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
            // Record rcode from DNS response header only if no timeout.
            // Keep rcode timeout for reporting later if any.
+5 −3
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@
 * This header contains declarations related to per-network DNS server selection.
 * They are used by system/netd/ and should not be exposed by the public NDK headers.
 */
#include <android/multinetwork.h>  // ResNsendFlags

#include <netinet/in.h>

#include "params.h"
@@ -113,9 +115,9 @@ LIBNETD_RESOLV_PUBLIC int android_getaddrinfofornetcontext(const char*, const ch
LIBNETD_RESOLV_PUBLIC bool resolv_has_nameservers(unsigned netid);

// Query dns with raw msg
// TODO: Add a way to control query parameter, like flags, or maybe res_options or even res_state.
LIBNETD_RESOLV_PUBLIC int resolv_res_nsend(const android_net_context* netContext, const u_char* msg,
                                           int msgLen, u_char* ans, int ansLen, int* rcode);
LIBNETD_RESOLV_PUBLIC int resolv_res_nsend(const android_net_context* netContext,
                                           const uint8_t* msg, int msgLen, uint8_t* ans, int ansLen,
                                           int* rcode, uint32_t flags);

// Set name servers for a network
LIBNETD_RESOLV_PUBLIC int resolv_set_nameservers_for_net(unsigned netid, const char** servers,
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ extern struct ResolvStub {
    void (*resolv_register_private_dns_callback)(private_dns_validated_callback callback);

    int (*resolv_res_nsend)(const android_net_context* netContext, const u_char* msg, int msgLen,
                            u_char* ans, int ansLen, int* rcode);
                            u_char* ans, int ansLen, int* rcode, uint32_t flags);

    int (*resolv_set_nameservers_for_net)(unsigned netid, const char** servers, unsigned numservers,
                                          const char* domains, const __res_params* params);
+15 −3
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ constexpr bool kDumpData = false;

#include <android-base/logging.h>

#include "netd_resolv/resolv.h"
#include "res_state_ext.h"
#include "resolv_cache.h"
#include "resolv_private.h"
@@ -1248,7 +1247,11 @@ static void _cache_notify_waiting_tid_locked(struct resolv_cache* cache, Entry*
}

/* notify the cache that the query failed */
void _resolv_cache_query_failed(unsigned netid, const void* query, int querylen) {
void _resolv_cache_query_failed(unsigned netid, const void* query, int querylen, uint32_t flags) {
    // We should not notify with these flags.
    if (flags & (ANDROID_RESOLV_NO_CACHE_STORE | ANDROID_RESOLV_NO_CACHE_LOOKUP)) {
        return;
    }
    Entry key[1];
    Cache* cache;

@@ -1463,7 +1466,11 @@ static void _cache_remove_expired(Cache* cache) {
}

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) {
    if (flags & ANDROID_RESOLV_NO_CACHE_LOOKUP) {
        return RESOLV_CACHE_SKIP;
    }
    Entry key[1];
    Entry** lookup;
    Entry* e;
@@ -1498,6 +1505,11 @@ ResolvCacheStatus _resolv_cache_lookup(unsigned netid, const void* query, int qu

    if (e == NULL) {
        VLOG << "NOT IN CACHE";
        // If it is no-cache-store mode, we won't wait for possible query.
        if (flags & ANDROID_RESOLV_NO_CACHE_STORE) {
            result = RESOLV_CACHE_SKIP;
            goto Exit;
        }
        // calling thread will wait if an outstanding request is found
        // that matching this query
        if (!_cache_check_pending_request_locked(&cache, key, netid) || cache == NULL) {
+1 −1
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ again:
        *herrno = NO_RECOVERY;
        return n;
    }
    n = res_nsend(statp, buf, n, answer, anslen, &rcode);
    n = res_nsend(statp, buf, n, answer, anslen, &rcode, 0);
    if (n < 0) {
        /* if the query choked with EDNS0, retry without EDNS0 */
        if ((statp->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0U &&
Loading