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

Commit ffe325ca authored by Bruce Chen's avatar Bruce Chen Committed by Gerrit Code Review
Browse files

Merge "Dead code removal - Remove res_setoptions()"

parents b0cd3dc6 018fdb25
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@
#include <android-base/strings.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <log/log.h>
#include <netdutils/DumpWriter.h>
#include <netdutils/NetworkConstants.h>  // SHA256_SIZE
#include <openssl/base64.h>
+5 −13
Original line number Diff line number Diff line
@@ -1659,7 +1659,7 @@ static int res_searchN(const char* name, res_target* target, res_state res, int*
    const char *cp, *const *domain;
    HEADER* hp;
    u_int dots;
    int trailing_dot, ret, saved_herrno;
    int ret, saved_herrno;
    int got_nodata = 0, got_servfail = 0, tried_as_is = 0;

    assert(name != NULL);
@@ -1671,8 +1671,7 @@ static int res_searchN(const char* name, res_target* target, res_state res, int*
    *herrno = HOST_NOT_FOUND; /* default, if we never query */
    dots = 0;
    for (cp = name; *cp; cp++) dots += (*cp == '.');
    trailing_dot = 0;
    if (cp > name && *--cp == '.') trailing_dot++;
    const bool trailing_dot = (cp > name && *--cp == '.') ? true : false;

    /*
     * If there are dots in the name already, let's just give it a try
@@ -1688,12 +1687,10 @@ static int res_searchN(const char* name, res_target* target, res_state res, int*

    /*
     * We do at least one level of search if
     *	- there is no dot and RES_DEFNAME is set, or
     *	- there is at least one dot, there is no trailing dot,
     *	  and RES_DNSRCH is set.
     *	- there is no dot, or
     *	- there is at least one dot and there is no trailing dot.
     */
    if ((!dots && (res->options & RES_DEFNAMES)) ||
        (dots && !trailing_dot && (res->options & RES_DNSRCH))) {
    if ((!dots) || (dots && !trailing_dot)) {
        int done = 0;

        /* Unfortunately we need to set stuff up before
@@ -1742,11 +1739,6 @@ static int res_searchN(const char* name, res_target* target, res_state res, int*
                    /* anything else implies that we're done */
                    done++;
            }
            /*
             * if we got here for some reason other than DNSRCH,
             * we only wanted one iteration of the loop, so stop.
             */
            if (!(res->options & RES_DNSRCH)) done++;
        }
    }

+8 −50
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@
#define ALIGNBYTES (sizeof(uintptr_t) - 1)
#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)

#define maybe_ok(res, nm, ok) (((res)->options & RES_NOCHECKNAME) != 0U || (ok)(nm) != 0)
#define maybe_ok(res, nm, ok) ((ok)(nm) != 0)
#define maybe_hnok(res, hn) maybe_ok((res), (hn), res_hnok)
#define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok)

@@ -109,8 +109,6 @@ static struct hostent* getanswer(const querybuf*, int, const char*, int, res_sta
static void convert_v4v6_hostent(struct hostent* hp, char** bpp, char* ep,
                                 std::function<void(struct hostent* hp)> mapping_param,
                                 std::function<void(char* src, char* dst)> mapping_addr);
static void map_v4v6_address(const char*, char*);
static void map_v4v6_hostent(struct hostent*, char**, char*);
static void pad_v4v6_hostent(struct hostent* hp, char** bpp, char* ep);
static void addrsort(char**, int, res_state);

@@ -120,8 +118,8 @@ static int dns_gethtbyname(const char* name, int af, getnamaddr* info);

static int gethostbyname_internal(const char* name, int af, res_state res, hostent* hp, char* hbuf,
                                  size_t hbuflen, const android_net_context* netcontext);
static int gethostbyname_internal_real(const char* name, int af, res_state res, hostent* hp,
                                       char* buf, size_t buflen);
static int gethostbyname_internal_real(const char* name, int af, hostent* hp, char* buf,
                                       size_t buflen);
static int android_gethostbyaddrfornetcontext_proxy_internal(const void*, socklen_t, int,
                                                             struct hostent*, char*, size_t,
                                                             const struct android_net_context*);
@@ -378,7 +376,6 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char*
            hent->h_name = bp;
            bp += n;
        }
        if (res->options & RES_USE_INET6) map_v4v6_hostent(hent, &bp, ep);
        if (hent->h_addrtype == AF_INET) pad_v4v6_hostent(hent, &bp, ep);
        goto success;
    }
@@ -407,8 +404,8 @@ nospc:
    return NULL;
}

static int gethostbyname_internal_real(const char* name, int af, res_state res, hostent* hp,
                                       char* buf, size_t buflen) {
static int gethostbyname_internal_real(const char* name, int af, hostent* hp, char* buf,
                                       size_t buflen) {
    getnamaddr info;
    size_t size;

@@ -487,7 +484,6 @@ fake:
    buf += size;
    buflen -= size;
    HENT_SCOPY(hp->h_name, name, buf, buflen);
    if (res->options & RES_USE_INET6) map_v4v6_hostent(hp, &buf, buf + buflen);
    return 0;
}

@@ -495,7 +491,7 @@ fake:
static int gethostbyname_internal(const char* name, int af, res_state res, hostent* hp, char* hbuf,
                                  size_t hbuflen, const android_net_context* netcontext) {
    res_setnetcontext(res, netcontext);
    return gethostbyname_internal_real(name, af, res, hp, hbuf, hbuflen);
    return gethostbyname_internal_real(name, af, hp, hbuf, hbuflen);
}

static int android_gethostbyaddrfornetcontext_real(const void* addr, socklen_t len, int af,
@@ -604,15 +600,9 @@ struct hostent* netbsd_gethostent_r(FILE* hf, struct hostent* hent, char* buf, s

            res_state res = res_get_state();
            if (res == NULL) goto nospc;
            if (res->options & RES_USE_INET6) {
                map_v4v6_address(buf, buf);
                af = AF_INET6;
                len = NS_IN6ADDRSZ;
            } else {
            af = AF_INET;
            len = NS_INADDRSZ;
        }
        }

        /* if this is not something we're looking for, skip it. */
        if (hent->h_addrtype != 0 && hent->h_addrtype != af) continue;
@@ -656,23 +646,6 @@ nospc:
    return NULL;
}

static void map_v4v6_address(const char* src, char* dst) {
    u_char* p = (u_char*) dst;
    char tmp[NS_INADDRSZ];
    int i;

    _DIAGASSERT(src != NULL);
    _DIAGASSERT(dst != NULL);

    /* Stash a temporary copy so our caller can update in place. */
    memcpy(tmp, src, NS_INADDRSZ);
    /* Mark this ipv6 addr as a mapped ipv4. */
    for (i = 0; i < 10; i++) *p++ = 0x00;
    *p++ = 0xff;
    *p++ = 0xff;
    /* Retrieve the saved copy and we're done. */
    memcpy(p, tmp, NS_INADDRSZ);
}

static void convert_v4v6_hostent(struct hostent* hp, char** bpp, char* ep,
                                 std::function<void(struct hostent* hp)> map_param,
@@ -698,15 +671,6 @@ static void convert_v4v6_hostent(struct hostent* hp, char** bpp, char* ep,
    }
}

static void map_v4v6_hostent(struct hostent* hp, char** bpp, char* ep) {
    convert_v4v6_hostent(hp, bpp, ep,
                         [](struct hostent* hp) {
                             hp->h_addrtype = AF_INET6;
                             hp->h_length = NS_IN6ADDRSZ;
                         },
                         [](char* src, char* dst) { map_v4v6_address(src, dst); });
}

/* Reserve space for mapping IPv4 address to IPv6 address in place */
static void pad_v4v6_hostent(struct hostent* hp, char** bpp, char* ep) {
    convert_v4v6_hostent(hp, bpp, ep,
@@ -860,12 +824,6 @@ static int dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,
    hp->h_addr_list[0] = bf;
    hp->h_addr_list[1] = NULL;
    memcpy(bf, uaddr, (size_t) info->hp->h_length);
    if (info->hp->h_addrtype == AF_INET && (res->options & RES_USE_INET6)) {
        if (blen + NS_IN6ADDRSZ > info->buflen) goto nospc;
        map_v4v6_address(bf, bf);
        hp->h_addrtype = AF_INET6;
        hp->h_length = NS_IN6ADDRSZ;
    }

    /* Reserve enough space for mapping IPv4 address to IPv6 address in place */
    if (info->hp->h_addrtype == AF_INET) {
+0 −73
Original line number Diff line number Diff line
@@ -94,9 +94,6 @@
#include "res_state_ext.h"
#include "resolv_private.h"


static void res_setoptions(res_state, const char*, const char*);

/*
 * Resolver state default settings.
 */
@@ -190,7 +187,6 @@ int res_vinit(res_state statp, int preinit) {
        for (pp = statp->dnsrch; *pp; pp++) LOG(DEBUG) << "\t" << *pp;
    }

    if ((cp = getenv("RES_OPTIONS")) != NULL) res_setoptions(statp, cp, "env");
    if (nserv > 0) {
        statp->nscount = nserv;
        statp->options |= RES_INIT;
@@ -198,75 +194,6 @@ int res_vinit(res_state statp, int preinit) {
    return (0);
}

static void res_setoptions(res_state statp, const char* options, const char* source) {
    const char* cp = options;
    int i;
    res_state_ext* ext = statp->_u._ext.ext;

    LOG(DEBUG) << "res_setoptions(\"" << options << "\", \"" << source << "\")...";

    while (*cp) {
        /* skip leading and inner runs of spaces */
        while (*cp == ' ' || *cp == '\t') cp++;
        /* search for and process individual options */
        if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
            i = atoi(cp + sizeof("ndots:") - 1);
            if (i <= RES_MAXNDOTS)
                statp->ndots = i;
            else
                statp->ndots = RES_MAXNDOTS;
            LOG(DEBUG) << "\tndots=" << statp->ndots;

        } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
            if (!(statp->options & RES_DEBUG)) {
                LOG(DEBUG) << "res_setoptions(\"" << options << "\", \"" << source << "\")..";
                statp->options |= RES_DEBUG;
            }
            LOG(DEBUG) << "\tdebug";

        } else if (!strncmp(cp, "no_tld_query", sizeof("no_tld_query") - 1) ||
                   !strncmp(cp, "no-tld-query", sizeof("no-tld-query") - 1)) {
            statp->options |= RES_NOTLDQUERY;
        } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
            statp->options |= RES_USE_INET6;
        } else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) {
            statp->options |= RES_ROTATE;
        } else if (!strncmp(cp, "no-check-names", sizeof("no-check-names") - 1)) {
            statp->options |= RES_NOCHECKNAME;
        }
        else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) {
            statp->options |= RES_USE_EDNS0;
        }
        else if (!strncmp(cp, "dname", sizeof("dname") - 1)) {
            statp->options |= RES_USE_DNAME;
        } else if (!strncmp(cp, "nibble:", sizeof("nibble:") - 1)) {
            if (ext == NULL) goto skip;
            cp += sizeof("nibble:") - 1;
            i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix) - 1);
            strncpy(ext->nsuffix, cp, (size_t) i);
            ext->nsuffix[i] = '\0';
        } else if (!strncmp(cp, "nibble2:", sizeof("nibble2:") - 1)) {
            if (ext == NULL) goto skip;
            cp += sizeof("nibble2:") - 1;
            i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix2) - 1);
            strncpy(ext->nsuffix2, cp, (size_t) i);
            ext->nsuffix2[i] = '\0';
        } else if (!strncmp(cp, "v6revmode:", sizeof("v6revmode:") - 1)) {
            cp += sizeof("v6revmode:") - 1;
            /* "nibble" and "bitstring" used to be valid */
            if (!strncmp(cp, "single", sizeof("single") - 1)) {
                statp->options |= RES_NO_NIBBLE2;
            } else if (!strncmp(cp, "both", sizeof("both") - 1)) {
                statp->options &= ~RES_NO_NIBBLE2;
            }
        } else {
            /* XXX - print a warning here? */
        }
    skip:
        /* skip to next run of spaces */
        while (*cp && *cp != ' ' && *cp != '\t') cp++;
    }
}

/*
 * This routine is for closing the socket if a virtual circuit is used and
+1 −1
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ int res_nmkquery(res_state statp, int op, /* opcode of query */
    hp = (HEADER*) (void*) buf;
    hp->id = htons(arc4random_uniform(65536));
    hp->opcode = op;
    hp->rd = (statp->options & RES_RECURSE) != 0U;
    hp->rd = true;
    hp->ad = (statp->options & RES_USE_DNSSEC) != 0U;
    hp->rcode = NOERROR;
    cp = buf + HFIXEDSZ;
Loading