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

Commit e6352200 authored by Bernie Innocenti's avatar Bernie Innocenti Committed by Gerrit Code Review
Browse files

Merge changes I4585b9d7,I90b48eab,I1f3e38d2

* changes:
  Delete the _u._ext nonsense from res_state
  Delete nameserver config change detection in res_nsend
  Inline res_state_ext into res_state
parents 0a423e4b bb330746
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@
#include <server_configurable_flags/get_flags.h>

#include "res_debug.h"
#include "res_state_ext.h"
#include "resolv_private.h"

using android::base::StringAppendF;
@@ -1582,8 +1581,8 @@ void _resolv_populate_res_for_net(res_state statp) {
                break;
            }

            if ((size_t) ai->ai_addrlen <= sizeof(statp->_u._ext.ext->nsaddrs[0])) {
                memcpy(&statp->_u._ext.ext->nsaddrs[nserv], ai->ai_addr, ai->ai_addrlen);
            if ((size_t)ai->ai_addrlen <= sizeof(statp->nsaddrs[0])) {
                memcpy(&statp->nsaddrs[nserv], ai->ai_addr, ai->ai_addrlen);
            } else {
                LOG(INFO) << __func__ << ": found too long addrlen";
            }
+8 −17
Original line number Diff line number Diff line
@@ -90,7 +90,6 @@
#include <unistd.h>

#include "netd_resolv/resolv.h"
#include "res_state_ext.h"
#include "resolv_private.h"

// Set up Resolver state default settings.
@@ -100,15 +99,13 @@ void res_init(res_state statp) {
    statp->id = arc4random_uniform(65536);
    statp->_mark = MARK_UNSET;

    statp->nscount = 0;
    statp->ndots = 1;
    statp->_vcsock = -1;
    statp->_flags = 0;
    statp->_u._ext.nscount = 0;
    statp->_u._ext.ext = (res_state_ext*) malloc(sizeof(*statp->_u._ext.ext));
    statp->netcontext_flags = 0;
    if (statp->_u._ext.ext != NULL) {
        memset(statp->_u._ext.ext, 0, sizeof(*statp->_u._ext.ext));

    for (int ns = 0; ns < MAXNS; ns++) {
        statp->nssocks[ns] = -1;
    }

    // The following dummy initialization is probably useless because
@@ -119,7 +116,7 @@ void res_init(res_state statp) {
            .sin.sin_family = AF_INET,
            .sin.sin_port = htons(NAMESERVER_PORT),
    };
    memcpy(&statp->_u._ext.ext->nsaddrs[0], &u, sizeof(u));
    memcpy(&statp->nsaddrs, &u, sizeof(u));
    statp->nscount = 1;
}

@@ -138,18 +135,12 @@ void res_nclose(res_state statp) {
        statp->_vcsock = -1;
        statp->_flags &= ~RES_F_VC;
    }
    for (ns = 0; ns < statp->_u._ext.nscount; ns++) {
        if (statp->_u._ext.nssocks[ns] != -1) {
            (void) close(statp->_u._ext.nssocks[ns]);
            statp->_u._ext.nssocks[ns] = -1;
        }
    for (ns = 0; ns < MAXNS; ns++) {
        if (statp->nssocks[ns] != -1) {
            close(statp->nssocks[ns]);
            statp->nssocks[ns] = -1;
        }
    }

void res_ndestroy(res_state statp) {
    res_nclose(statp);
    if (statp->_u._ext.ext != NULL) free(statp->_u._ext.ext);
    statp->_u._ext.ext = NULL;
}

void res_setnetcontext(res_state statp, const struct android_net_context* netcontext,
+9 −54
Original line number Diff line number Diff line
@@ -107,7 +107,6 @@
#include "netd_resolv/stats.h"
#include "private/android_filesystem_config.h"
#include "res_debug.h"
#include "res_state_ext.h"
#include "resolv_cache.h"
#include "stats.pb.h"

@@ -317,7 +316,6 @@ static int res_ourserver_p(res_state statp, const sockaddr* sa) {
            }
            break;
        case AF_INET6:
            if (statp->_u._ext.ext == NULL) break;
            in6p = (const struct sockaddr_in6*) (const void*) sa;
            for (ns = 0; ns < statp->nscount; ns++) {
                srv6 = (struct sockaddr_in6*) (void*) get_nsaddr(statp, (size_t) ns);
@@ -457,49 +455,6 @@ int res_nsend(res_state statp, const uint8_t* buf, int buflen, uint8_t* ans, int
        return -ESRCH;
    }

    /*
     * If the ns_addr_list in the resolver context has changed, then
     * invalidate our cached copy and the associated timing data.
     */
    if (statp->_u._ext.nscount != 0) {
        int needclose = 0;
        struct sockaddr_storage peer;
        socklen_t peerlen;

        if (statp->_u._ext.nscount != statp->nscount) {
            needclose++;
        } else {
            for (int ns = 0; ns < statp->nscount; ns++) {
                if (statp->_u._ext.nssocks[ns] == -1) continue;
                peerlen = sizeof(peer);
                if (getpeername(statp->_u._ext.nssocks[ns], (struct sockaddr*) (void*) &peer,
                                &peerlen) < 0) {
                    needclose++;
                    break;
                }
                if (!sock_eq((struct sockaddr*) (void*) &peer, get_nsaddr(statp, (size_t) ns))) {
                    needclose++;
                    break;
                }
            }
        }
        if (needclose) {
            res_nclose(statp);
            statp->_u._ext.nscount = 0;
        }
    }

    /*
     * Maybe initialize our private copy of the ns_addr_list.
     */
    if (statp->_u._ext.nscount == 0) {
        for (int ns = 0; ns < statp->nscount; ns++) {
            statp->_u._ext.nstimes[ns] = RES_MAXTIME;
            statp->_u._ext.nssocks[ns] = -1;
        }
        statp->_u._ext.nscount = statp->nscount;
    }

    res_stats stats[MAXNS];
    res_params params;
    int revision_id = resolv_cache_get_resolver_stats(statp->netid, &params, stats);
@@ -684,7 +639,7 @@ static int get_salen(const struct sockaddr* sa) {
}

static struct sockaddr* get_nsaddr(res_state statp, size_t n) {
    return (struct sockaddr*)(void*)&statp->_u._ext.ext->nsaddrs[n];
    return (struct sockaddr*)(void*)&statp->nsaddrs[n];
}

static struct timespec get_timeout(res_state statp, const res_params* params, const int ns) {
@@ -991,9 +946,9 @@ static int send_dg(res_state statp, res_params* params, const uint8_t* buf, int

    nsap = get_nsaddr(statp, (size_t) ns);
    nsaplen = get_salen(nsap);
    if (statp->_u._ext.nssocks[ns] == -1) {
        statp->_u._ext.nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
        if (statp->_u._ext.nssocks[ns] < 0) {
    if (statp->nssocks[ns] == -1) {
        statp->nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
        if (statp->nssocks[ns] < 0) {
            switch (errno) {
                case EPROTONOSUPPORT:
                case EPFNOSUPPORT:
@@ -1007,9 +962,9 @@ static int send_dg(res_state statp, res_params* params, const uint8_t* buf, int
            }
        }

        resolv_tag_socket(statp->_u._ext.nssocks[ns], statp->uid);
        resolv_tag_socket(statp->nssocks[ns], statp->uid);
        if (statp->_mark != MARK_UNSET) {
            if (setsockopt(statp->_u._ext.nssocks[ns], SOL_SOCKET, SO_MARK, &(statp->_mark),
            if (setsockopt(statp->nssocks[ns], SOL_SOCKET, SO_MARK, &(statp->_mark),
                           sizeof(statp->_mark)) < 0) {
                res_nclose(statp);
                return -1;
@@ -1019,19 +974,19 @@ static int send_dg(res_state statp, res_params* params, const uint8_t* buf, int
        // on the next socket operation when the server responds with an
        // ICMP port-unreachable error. This way we can detect the absence of
        // a nameserver without timing out.
        if (random_bind(statp->_u._ext.nssocks[ns], nsap->sa_family) < 0) {
        if (random_bind(statp->nssocks[ns], nsap->sa_family) < 0) {
            dump_error("bind(dg)", nsap, nsaplen);
            res_nclose(statp);
            return (0);
        }
        if (connect(statp->_u._ext.nssocks[ns], nsap, (socklen_t) nsaplen) < 0) {
        if (connect(statp->nssocks[ns], nsap, (socklen_t)nsaplen) < 0) {
            dump_error("connect(dg)", nsap, nsaplen);
            res_nclose(statp);
            return (0);
        }
        LOG(DEBUG) << __func__ << ": new DG socket";
    }
    s = statp->_u._ext.nssocks[ns];
    s = statp->nssocks[ns];
    if (send(s, (const char*) buf, (size_t) buflen, 0) != buflen) {
        PLOG(DEBUG) << __func__ << ": send: ";
        res_nclose(statp);
+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ static void res_thread_free(void* _rt) {
    LOG(VERBOSE) << __func__ << ": rt=" << rt << " for thread=" << gettid();

    res_static_done(rt->_rstatic);
    res_ndestroy(rt->_nres);
    res_nclose(rt->_nres);
    free(rt);
}

res_state_ext.h

deleted100644 → 0
+0 −13
Original line number Diff line number Diff line
/*	$NetBSD: res_private.h,v 1.1.1.1 2004/05/20 17:18:54 christos Exp $	*/

#ifndef NETD_RES_STATE_EXT_H
#define NETD_RES_STATE_EXT_H

#include "resolv_private.h"

// TODO: consider inlining into res_state
struct res_state_ext {
    sockaddr_union nsaddrs[MAXNS];
};

#endif  // NETD_RES_STATE_EXT_H
Loading