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

Commit c977ab77 authored by Bernie Innocenti's avatar Bernie Innocenti
Browse files

Inline res_state_ext into res_state

There was just one field left, so inline it into its parent and remove
this horror show entirely.

Test: m, flash, atest
Change-Id: I1f3e38d2dc335bfaf58b0d59c9dcb6f52ca91210
parent d35d2924
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";
            }
+1 −12
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.
@@ -105,11 +104,7 @@ void res_init(res_state statp) {
    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));
    }

    // The following dummy initialization is probably useless because
    // it's overwritten later by _resolv_populate_res_for_net().
@@ -119,7 +114,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;
}

@@ -146,12 +141,6 @@ void res_nclose(res_state statp) {
    }
}

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,
                       android::net::NetworkDnsEventReported* _Nonnull event) {
    if (statp != nullptr) {
+1 −4
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);
@@ -494,7 +492,6 @@ int res_nsend(res_state statp, const uint8_t* buf, int buflen, uint8_t* ans, int
     */
    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;
@@ -684,7 +681,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) {
+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