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

Commit f688d445 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 7655068 from fdf7b6d7 to tm-release

Change-Id: I4ba82b5419e33579ad13d2e3fe9d19e1c3f31cbf
parents 23e8c76c fdf7b6d7
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -294,8 +294,6 @@ void ResolverController::stopPrefix64Discovery(int32_t netId) {
int ResolverController::getPrefix64(unsigned netId, netdutils::IPPrefix* prefix) {
    netdutils::IPPrefix p = mDns64Configuration.getPrefix64(netId);
    if (p.family() != AF_INET6 || p.length() == 0) {
        LOG(INFO) << "No valid NAT64 prefix (" << netId << ", " << p.toString().c_str() << ")";

        return -ENOENT;
    }
    *prefix = p;
+2 −2
Original line number Diff line number Diff line
@@ -1199,7 +1199,7 @@ static void _cache_remove_oldest(Cache* cache) {
        return;
    }
    LOG(INFO) << __func__ << ": Cache full - removing oldest";
    res_pquery(oldest->query, oldest->querylen);
    res_pquery({oldest->query, oldest->querylen});
    _cache_remove_p(cache, lookup);
}

@@ -1304,7 +1304,7 @@ ResolvCacheStatus resolv_cache_lookup(unsigned netid, const void* query, int que
    /* remove stale entries here */
    if (now >= e->expires) {
        LOG(INFO) << __func__ << ": NOT IN CACHE (STALE ENTRY " << *lookup << "DISCARDED)";
        res_pquery(e->query, e->querylen);
        res_pquery({e->query, e->querylen});
        _cache_remove_p(cache, lookup);
        return RESOLV_CACHE_NOTFOUND;
    }
+16 −5
Original line number Diff line number Diff line
@@ -114,7 +114,6 @@
#include <inttypes.h>
#include <math.h>
#include <netdb.h>
#include <netdutils/Slice.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
@@ -132,7 +131,6 @@
#endif

using android::base::StringAppendF;
using android::netdutils::Slice;

struct res_sym {
    int number;            /* Identifying number, like T_MX */
@@ -233,18 +231,31 @@ static void do_section(ns_msg* handle, ns_sect section) {
    }
}

// Convert bytes to its hexadecimal representation.
// The returned string is double the size of input.
std::string bytesToHexStr(std::span<const uint8_t> bytes) {
    static char const hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
                                 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    std::string str;
    str.reserve(bytes.size() * 2);
    for (uint8_t ch : bytes) {
        str.append({hex[(ch & 0xf0) >> 4], hex[ch & 0xf]});
    }
    return str;
}

/*
 * Print the contents of a query.
 * This is intended to be primarily a debugging routine.
 */
void res_pquery(const uint8_t* msg, int len) {
void res_pquery(std::span<const uint8_t> msg) {
    if (!WOULD_LOG(VERBOSE)) return;

    ns_msg handle;
    int qdcount, ancount, nscount, arcount;
    uint32_t opcode, rcode, id;

    if (ns_initparse(msg, len, &handle) < 0) {
    if (ns_initparse(msg.data(), msg.size(), &handle) < 0) {
        PLOG(VERBOSE) << "ns_initparse failed";
        return;
    }
@@ -287,7 +298,7 @@ void res_pquery(const uint8_t* msg, int len) {
    do_section(&handle, ns_s_ar);

    LOG(VERBOSE) << "Hex dump:";
    LOG(VERBOSE) << android::netdutils::toHex(Slice(const_cast<uint8_t*>(msg), len), 32);
    LOG(VERBOSE) << bytesToHexStr(msg);
}

/*
+3 −3
Original line number Diff line number Diff line
@@ -17,10 +17,10 @@
#pragma once

#include <stdint.h>
#include <span>

// TODO: use netdutils::Slice for (msg, len).
void res_pquery(const uint8_t* msg, int len);

void res_pquery(std::span<const uint8_t> msg);
std::string bytesToHexStr(std::span<const uint8_t> bytes);
// Thread-unsafe functions returning pointers to static buffers :-(
// TODO: switch all res_debug to std::string
const char* p_type(int type);
+8 −8
Original line number Diff line number Diff line
@@ -443,7 +443,7 @@ int res_nsend(ResState* statp, const uint8_t* buf, int buflen, uint8_t* ans, int
        errno = EINVAL;
        return -EINVAL;
    }
    res_pquery(buf, buflen);
    res_pquery({buf, buflen});

    int anslen = 0;
    Stopwatch cacheStopwatch;
@@ -490,7 +490,7 @@ int res_nsend(ResState* statp, const uint8_t* buf, int buflen, uint8_t* ans, int
            return -terrno;
        }
        LOG(DEBUG) << __func__ << ": got answer:";
        res_pquery(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);
@@ -517,7 +517,7 @@ int res_nsend(ResState* statp, const uint8_t* buf, int buflen, uint8_t* ans, int
                                           Slice(ans, anssiz), rcode, &fallback);
        if (resplen > 0) {
            LOG(DEBUG) << __func__ << ": got answer from Private DNS";
            res_pquery(ans, resplen);
            res_pquery({ans, resplen});
            if (cache_status == RESOLV_CACHE_NOTFOUND) {
                resolv_cache_add(statp->netid, buf, buflen, ans, resplen);
            }
@@ -666,7 +666,7 @@ int res_nsend(ResState* statp, const uint8_t* buf, int buflen, uint8_t* ans, int
            }

            LOG(DEBUG) << __func__ << ": got answer:";
            res_pquery(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);
@@ -903,7 +903,7 @@ read_len:
     */
    if (hp->id != anhp->id) {
        LOG(DEBUG) << __func__ << ": ld answer (unexpected):";
        res_pquery(ans, resplen);
        res_pquery({ans, resplen});
        goto read_len;
    }

@@ -1168,7 +1168,7 @@ static int send_dg(ResState* statp, res_params* params, const uint8_t* buf, int
            if (needRetry =
                        ignoreInvalidAnswer(statp, from, buf, buflen, ans, anssiz, &receivedFromNs);
                needRetry) {
                res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
                res_pquery({ans, (resplen > anssiz) ? anssiz : resplen});
                continue;
            }

@@ -1178,7 +1178,7 @@ static int send_dg(ResState* statp, res_params* params, const uint8_t* buf, int
                //  The case has to be captured here, as FORMERR packet do not
                //  carry query section, hence res_queriesmatch() returns 0.
                LOG(DEBUG) << __func__ << ": server rejected query with EDNS0:";
                res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
                res_pquery({ans, (resplen > anssiz) ? anssiz : resplen});
                // record the error
                statp->flags |= RES_F_EDNS0ERR;
                *terrno = EREMOTEIO;
@@ -1189,7 +1189,7 @@ static int send_dg(ResState* statp, res_params* params, const uint8_t* buf, int
            *delay = res_stats_calculate_rtt(&done, &start_time);
            if (anhp->rcode == SERVFAIL || anhp->rcode == NOTIMP || anhp->rcode == REFUSED) {
                LOG(DEBUG) << __func__ << ": server rejected query:";
                res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
                res_pquery({ans, (resplen > anssiz) ? anssiz : resplen});
                *rcode = anhp->rcode;
                continue;
            }
Loading