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

Commit dd210720 authored by chenbruce's avatar chenbruce
Browse files

[Resolver] Remove statp->pfcode, which was only used by dig

statp->pfcode is set to 0 by default and is used by dig. Remove it.

Test: full build, flash ROM, runtests.sh
Change-Id: Id63c5fcc5c64bc92bd190d0c628e8e12eecb9d6f
parent a1b37f12
Loading
Loading
Loading
Loading
+3 −11
Original line number Diff line number Diff line
@@ -1304,14 +1304,6 @@ static void cache_dump_mru(Cache* cache) {
    LOG(INFO) << temp;
}

// TODO: Rewrite to avoid creating a file in /data as temporary buffer (WAT).
static void dump_answer(const u_char* answer, int answerlen) {
    res_state statep;

    statep = res_get_state();
    res_pquery(statep, answer, answerlen);
}

/* This function tries to find a key within the hash table
 * In case of success, it will return a *pointer* to the hashed key.
 * In case of failure, it will return a *pointer* to NULL
@@ -1537,7 +1529,7 @@ void _resolv_cache_add(unsigned netid, const void* query, int querylen, const vo

    LOG(INFO) << __func__ << ": query:";
    dump_query((u_char*)query, querylen);
    dump_answer((u_char*) answer, answerlen);
    res_pquery((u_char*)answer, answerlen);
    if (kDumpData) {
        LOG(INFO) << "answer:";
        dump_bytes((u_char*)answer, answerlen);
+23 −34
Original line number Diff line number Diff line
@@ -147,8 +147,8 @@ static char* dbprint(char* p, char* end, const char* format, ...) {
    return p;
}

static void do_section(const res_state statp, ns_msg* handle, ns_sect section, int pflag) {
    int n, sflag, rrnum;
static void do_section(ns_msg* handle, ns_sect section) {
    int n, rrnum;
    int buflen = 2048;
    ns_opcode opcode;
    ns_rr rr;
@@ -157,8 +157,6 @@ static void do_section(const res_state statp, ns_msg* handle, ns_sect section, i
    /*
     * Print answer records.
     */
    sflag = (int) (statp->pfcode & pflag);
    if (statp->pfcode && !sflag) return;

    char* buf = (char*) malloc((size_t) buflen);
    if (buf == NULL) {
@@ -173,12 +171,8 @@ static void do_section(const res_state statp, ns_msg* handle, ns_sect section, i
        if (ns_parserr(handle, section, rrnum, &rr)) {
            if (errno != ENODEV)
                dbprint(p, end, ";; ns_parserr: %s", strerror(errno));
            else if (rrnum > 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1))
                dbprint(p, end, "\n");
            goto cleanup;
        }
        if (rrnum == 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1))
            dbprint(p, end, ";; %s SECTION:\n", p_section(section, opcode));
        if (section == ns_s_qd)
            dbprint(p, end, ";;\t%s, type = %s, class = %s\n", ns_rr_name(rr),
                    p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr)));
@@ -261,7 +255,7 @@ cleanup:
 * Print the contents of a query.
 * This is intended to be primarily a debugging routine.
 */
void res_pquery(const res_state statp, const u_char* msg, int len) {
void res_pquery(const u_char* msg, int len) {
    if (!WOULD_LOG(VERBOSE)) return;

    ns_msg handle;
@@ -284,11 +278,9 @@ void res_pquery(const res_state statp, const u_char* msg, int len) {
    /*
     * Print header fields.
     */
    if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX) || rcode)
    dbprint(p, end, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n", _res_opcodes[opcode],
            p_rcode((int)rcode), id);
    if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX)) p = dbprint(p, end, ";");
    if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD2)) {
    p = dbprint(p, end, ";");
    p = dbprint(p, end, "; flags:");
    if (ns_msg_getflag(handle, ns_f_qr)) p = dbprint(p, end, " qr");
    if (ns_msg_getflag(handle, ns_f_aa)) p = dbprint(p, end, " aa");
@@ -298,23 +290,20 @@ void res_pquery(const res_state statp, const u_char* msg, int len) {
    if (ns_msg_getflag(handle, ns_f_z)) p = dbprint(p, end, " ??");
    if (ns_msg_getflag(handle, ns_f_ad)) p = dbprint(p, end, " ad");
    if (ns_msg_getflag(handle, ns_f_cd)) p = dbprint(p, end, " cd");
    }
    if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD1)) {
    p = dbprint(p, end, "; %s: %d", p_section(ns_s_qd, (int)opcode), qdcount);
    p = dbprint(p, end, ", %s: %d", p_section(ns_s_an, (int)opcode), ancount);
    p = dbprint(p, end, ", %s: %d", p_section(ns_s_ns, (int)opcode), nscount);
    p = dbprint(p, end, ", %s: %d", p_section(ns_s_ar, (int)opcode), arcount);
    }

    LOG(VERBOSE) << temp;

    /*
     * Print the various sections.
     */
    do_section(statp, &handle, ns_s_qd, RES_PRF_QUES);
    do_section(statp, &handle, ns_s_an, RES_PRF_ANS);
    do_section(statp, &handle, ns_s_ns, RES_PRF_AUTH);
    do_section(statp, &handle, ns_s_ar, RES_PRF_ADD);
    do_section(&handle, ns_s_qd);
    do_section(&handle, ns_s_an);
    do_section(&handle, ns_s_ns);
    do_section(&handle, ns_s_ar);
    if (qdcount == 0 && ancount == 0 && nscount == 0 && arcount == 0) LOG(VERBOSE) << ";;";
}

+0 −1
Original line number Diff line number Diff line
@@ -154,7 +154,6 @@ int res_vinit(res_state statp, int preinit) {
    nserv++;
    statp->nscount = 0;
    statp->ndots = 1;
    statp->pfcode = 0;
    statp->_vcsock = -1;
    statp->_flags = 0;
    statp->_u._ext.nscount = 0;
+10 −13
Original line number Diff line number Diff line
@@ -375,7 +375,7 @@ int res_nsend(res_state statp, const u_char* buf, int buflen, u_char* ans, int a
        return -EINVAL;
    }
    LOG(DEBUG) << __func__;
    res_pquery(statp, buf, buflen);
    res_pquery(buf, buflen);

    v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ;
    gotsomewhere = 0;
@@ -597,7 +597,7 @@ int res_nsend(res_state statp, const u_char* buf, int buflen, u_char* ans, int a
            }

            LOG(DEBUG) << "got answer:";
            res_pquery(statp, ans, (resplen > anssiz) ? anssiz : resplen);
            res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);

            if (cache_status == RESOLV_CACHE_NOTFOUND) {
                _resolv_cache_add(statp->netid, buf, buflen, ans, resplen);
@@ -877,7 +877,7 @@ read_len:
     */
    if (hp->id != anhp->id) {
        LOG(DEBUG) << "old answer (unexpected):";
        res_pquery(statp, ans, (resplen > anssiz) ? anssiz : resplen);
        res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
        goto read_len;
    }

@@ -1081,7 +1081,7 @@ retry:
         *	 be detected here.
         */
        LOG(DEBUG) << "old answer:";
        res_pquery(statp, ans, (resplen > anssiz) ? anssiz : resplen);
        res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
        goto retry;
    }
    if (!(statp->options & RES_INSECURE1) &&
@@ -1092,7 +1092,7 @@ retry:
         *	 be detected here.
         */
        LOG(DEBUG) << "not our server:";
        res_pquery(statp, ans, (resplen > anssiz) ? anssiz : resplen);
        res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
        goto retry;
    }
    if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) {
@@ -1102,7 +1102,7 @@ retry:
         * carry query section, hence res_queriesmatch() returns 0.
         */
        LOG(DEBUG) << "server rejected query with EDNS0:";
        res_pquery(statp, ans, (resplen > anssiz) ? anssiz : resplen);
        res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
        /* record the error */
        statp->_flags |= RES_F_EDNS0ERR;
        res_nclose(statp);
@@ -1116,21 +1116,18 @@ retry:
         *	 be detected here.
         */
        LOG(DEBUG) << "wrong query name:";
        res_pquery(statp, ans, (resplen > anssiz) ? anssiz : resplen);
        res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
        goto retry;
    }
    done = evNowTime();
    *delay = _res_stats_calculate_rtt(&done, &now);
    if (anhp->rcode == SERVFAIL || anhp->rcode == NOTIMP || anhp->rcode == REFUSED) {
        LOG(DEBUG) << "server rejected query:";
        res_pquery(statp, ans, (resplen > anssiz) ? anssiz : resplen);
        res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
        res_nclose(statp);
        /* don't retry if called from dig */
        if (!statp->pfcode) {
        *rcode = anhp->rcode;
        return 0;
    }
    }
    if (!(statp->options & RES_IGNTC) && anhp->tc) {
        /*
         * To get the rest of answer,
+1 −22
Original line number Diff line number Diff line
@@ -99,7 +99,6 @@ struct __res_state {
    u_short id;                            /* current message id */
    char* dnsrch[MAXDNSRCH + 1];           /* components of domain to search */
    char defdname[256];                    /* default domain (deprecated) */
    u_long pfcode;                         /* RES_PRF_ flags - see below. */
    unsigned ndots : 4;                    /* threshold for initial abs. query */
    unsigned nsort : 4;                    /* number of elements in sort_list[] */
    char unused[3];
@@ -180,26 +179,6 @@ void _res_stats_set_sample(res_sample* sample, time_t now, int rcode, int rtt);

#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH | RES_NO_NIBBLE2)

/*
 * Resolver "pfcode" values.  Used by dig.
 */
#define RES_PRF_STATS 0x00000001
#define RES_PRF_UPDATE 0x00000002
#define RES_PRF_CLASS 0x00000004
#define RES_PRF_CMD 0x00000008
#define RES_PRF_QUES 0x00000010
#define RES_PRF_ANS 0x00000020
#define RES_PRF_AUTH 0x00000040
#define RES_PRF_ADD 0x00000080
#define RES_PRF_HEAD1 0x00000100
#define RES_PRF_HEAD2 0x00000200
#define RES_PRF_TTLID 0x00000400
#define RES_PRF_HEADX 0x00000800
#define RES_PRF_QUERY 0x00001000
#define RES_PRF_REPLY 0x00002000
#define RES_PRF_INIT 0x00004000
#define RES_PRF_TRUNC 0x00008000
/*			0x00010000	*/

/*
 * Error code extending h_errno codes defined in bionic/libc/include/netdb.h.
@@ -235,7 +214,7 @@ int res_nameinquery(const char*, int, int, const u_char*, const u_char*);
int res_queriesmatch(const u_char*, const u_char*, const u_char*, const u_char*);
/* Things involving a resolver context. */
int res_ninit(res_state);
void res_pquery(const res_state, const u_char*, int);
void res_pquery(const u_char*, int);

int res_nquery(res_state, const char*, int, int, u_char*, int, int*);
int res_nsearch(res_state, const char*, int, int, u_char*, int, int*);