[Resolver-log] Replacing unused debuging functions by LOG(x).
Removing printf/vlog/syslog/ ...etc debuging functions and using LOG(x).
Then we can configure the log verbosity in the resolver with:
// Set the minimum severity level for logging, returning the old severity.
LogSeverity SetMinimumLogSeverity(LogSeverity new_severity);
Bug: 121176138
Test: make; flash;
Test: The default severity is WARNING. Reboot device and check that only
WARNING/ERROR logs are printed.
Change-Id: Ib8de89a4cba96ded186579ccefaf88031066e508
diff --git a/resolv/DnsProxyListener.cpp b/resolv/DnsProxyListener.cpp
index e883005..d61a335 100644
--- a/resolv/DnsProxyListener.cpp
+++ b/resolv/DnsProxyListener.cpp
@@ -36,6 +36,7 @@
#include <vector>
#include <android-base/logging.h>
+#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android/multinetwork.h> // ResNsendFlags
#include <cutils/misc.h> // FIRST_APPLICATION_UID
@@ -56,6 +57,7 @@
#include "Stopwatch.h"
#include "netd_resolv/stats.h" // RCODE_TIMEOUT
#include "netdutils/InternetAddresses.h"
+#include "resolv_private.h"
#include "thread_util.h"
using aidl::android::net::metrics::INetdEventListener;
@@ -66,6 +68,9 @@
android::base::InitLogging(/*argv=*/nullptr);
android::base::SetDefaultTag("libnetd_resolv");
ALOGI("Initializing resolver");
+ const std::string logSeverityStr =
+ android::base::GetProperty("persist.sys.nw_dns_resolver_log", "WARNING");
+ android::base::SetMinimumLogSeverity(logSeverityStrToEnum(logSeverityStr));
if (!gDnsProxyListener.setCallbacks(callbacks)) {
ALOGE("Unable to set callbacks to DnsProxyListener");
diff --git a/resolv/getaddrinfo.cpp b/resolv/getaddrinfo.cpp
index 492b42f..9965ca1 100644
--- a/resolv/getaddrinfo.cpp
+++ b/resolv/getaddrinfo.cpp
@@ -49,9 +49,10 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
-#include <syslog.h>
#include <unistd.h>
+#include <android-base/logging.h>
+
#include "netd_resolv/resolv.h"
#include "resolv_cache.h"
#include "resolv_private.h"
@@ -798,8 +799,6 @@
/* code duplicate with gethnamaddr.c */
-static const char AskedForGot[] = "gethostby*.getanswer: asked for \"%s\", got \"%s\"";
-
#define BOUNDED_INCR(x) \
do { \
BOUNDS_CHECK(cp, x); \
@@ -931,9 +930,9 @@
}
} else if (type != qtype) {
if (type != T_KEY && type != T_SIG)
- syslog(LOG_NOTICE | LOG_AUTH,
- "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"", qname,
- p_class(C_IN), p_type(qtype), p_type(type));
+ LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << qname << " "
+ << p_class(C_IN) << " " << p_type(qtype) << "\", got type \""
+ << p_type(type) << "\"";
cp += n;
continue; /* XXX - had_error++ ? */
}
@@ -941,7 +940,8 @@
case T_A:
case T_AAAA:
if (strcasecmp(canonname, bp) != 0) {
- syslog(LOG_NOTICE | LOG_AUTH, AskedForGot, canonname, bp);
+ LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << canonname
+ << "\", got \"" << bp << "\"";
cp += n;
continue; /* XXX - had_error++ ? */
}
@@ -1605,17 +1605,14 @@
int type = t->qtype;
answer = t->answer;
anslen = t->anslen;
-#ifdef DEBUG
- if (res->options & RES_DEBUG) printf(";; res_queryN(%s, %d, %d)\n", name, cl, type);
-#endif
+
+ LOG(DEBUG) << ";; res_queryN(" << name << ", " << cl << " , " << type << ")";
n = res_nmkquery(res, QUERY, name, cl, type, NULL, 0, NULL, buf, sizeof(buf));
if (n > 0 && (res->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0 && !retried)
n = res_nopt(res, n, buf, sizeof(buf), anslen);
if (n <= 0) {
-#ifdef DEBUG
- if (res->options & RES_DEBUG) printf(";; res_queryN: mkquery failed\n");
-#endif
+ LOG(DEBUG) << ";; res_queryN: mkquery failed";
*herrno = NO_RECOVERY;
return n;
}
@@ -1628,16 +1625,11 @@
/* if the query choked with EDNS0, retry without EDNS0 */
if ((res->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0 &&
(res->_flags & RES_F_EDNS0ERR) && !retried) {
-#ifdef DEBUG
- if (res->options & RES_DEBUG) printf(";; res_queryN: retry without EDNS0\n");
-#endif
+ LOG(DEBUG) << ";; res_queryN: retry without EDNS0";
retried = true;
goto again;
}
-#ifdef DEBUG
- if (res->options & RES_DEBUG)
- printf(";; rcode = %u, ancount=%u\n", hp->rcode, ntohs(hp->ancount));
-#endif
+ LOG(DEBUG) << ";; rcode = " << hp->rcode << ", ancount=" << ntohs(hp->ancount);
continue;
}
@@ -1815,12 +1807,8 @@
assert(name != NULL);
/* XXX: target may be NULL??? */
-
-#ifdef DEBUG
- if (res->options & RES_DEBUG)
- printf(";; res_querydomain(%s, %s)\n", name, domain ? domain : "<Nil>");
-#endif
if (domain == NULL) {
+ LOG(DEBUG) << ";; res_querydomain(" << name << ", <Nil>)";
/*
* Check for trailing '.';
* copy without '.' if present.
@@ -1836,6 +1824,7 @@
} else
longname = name;
} else {
+ LOG(DEBUG) << ";; res_querydomain(" << name << ", " << domain << ")";
n = strlen(name);
d = strlen(domain);
if (n + 1 + d + 1 > sizeof(nbuf)) {
diff --git a/resolv/gethnamaddr.cpp b/resolv/gethnamaddr.cpp
index f709ab9..3bf5aed 100644
--- a/resolv/gethnamaddr.cpp
+++ b/resolv/gethnamaddr.cpp
@@ -51,6 +51,7 @@
* --Copyright--
*/
+#include <android-base/logging.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <assert.h>
@@ -67,7 +68,6 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
-#include <syslog.h>
#include <unistd.h>
#include <functional>
#include <vector>
@@ -87,17 +87,10 @@
#define ALIGNBYTES (sizeof(uintptr_t) - 1)
#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)
-#ifndef LOG_AUTH
-#define LOG_AUTH 0
-#endif
-
-
#define maybe_ok(res, nm, ok) (((res)->options & RES_NOCHECKNAME) != 0U || (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)
-static const char AskedForGot[] = "gethostby*.getanswer: asked for \"%s\", got \"%s\"";
-
#define MAXPACKET (8 * 1024)
typedef union {
@@ -110,9 +103,6 @@
char ac;
} align;
-#ifdef DEBUG
-static void debugprintf(const char*, res_state, ...) __attribute__((__format__(__printf__, 1, 3)));
-#endif
static struct hostent* getanswer(const querybuf*, int, const char*, int, res_state, struct hostent*,
char*, size_t, int*);
static void convert_v4v6_hostent(struct hostent* hp, char** bpp, char* ep,
@@ -138,25 +128,6 @@
const struct android_net_context* netcontext,
hostent** hp);
-#ifdef DEBUG
-static void debugprintf(const char* msg, res_state res, ...) {
- _DIAGASSERT(msg != NULL);
-
- if (res->options & RES_DEBUG) {
- int save = errno;
- va_list ap;
-
- va_start(ap, res);
- vprintf(msg, ap);
- va_end(ap);
-
- errno = save;
- }
-}
-#else
-#define debugprintf(msg, res, num) /*nada*/
-#endif
-
#define BOUNDED_INCR(x) \
do { \
BOUNDS_CHECK(cp, x); \
@@ -306,16 +277,17 @@
}
if (type != qtype) {
if (type != T_KEY && type != T_SIG)
- syslog(LOG_NOTICE | LOG_AUTH,
- "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"", qname,
- p_class(C_IN), p_type(qtype), p_type(type));
+ LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << qname << " "
+ << p_class(C_IN) << " " << p_type(qtype) << "\", got type \""
+ << p_type(type) << "\"";
cp += n;
continue; /* XXX - had_error++ ? */
}
switch (type) {
case T_PTR:
if (strcasecmp(tname, bp) != 0) {
- syslog(LOG_NOTICE | LOG_AUTH, AskedForGot, qname, bp);
+ LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << qname << "\", got \""
+ << bp << "\"";
cp += n;
continue; /* XXX - had_error++ ? */
}
@@ -342,7 +314,8 @@
case T_A:
case T_AAAA:
if (strcasecmp(hent->h_name, bp) != 0) {
- syslog(LOG_NOTICE | LOG_AUTH, AskedForGot, hent->h_name, bp);
+ LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << hent->h_name
+ << "\", got \"" << bp << "\"";
cp += n;
continue; /* XXX - had_error++ ? */
}
@@ -369,13 +342,13 @@
bp += sizeof(align) - (size_t)((u_long) bp % sizeof(align));
if (bp + n >= ep) {
- debugprintf("size (%d) too big\n", res, n);
+ LOG(DEBUG) << "size (" << n << ") too big";
had_error++;
continue;
}
if (hap >= &addr_ptrs[MAXADDRS - 1]) {
if (!toobig++) {
- debugprintf("Too many addresses (%d)\n", res, MAXADDRS);
+ LOG(DEBUG) << "Too many addresses (" << MAXADDRS << ")";
}
cp += n;
continue;
@@ -820,7 +793,7 @@
n = res_nsearch(res, name, C_IN, type, buf->buf, (int) sizeof(buf->buf), &herrno);
if (n < 0) {
free(buf);
- debugprintf("res_nsearch failed (%d)\n", res, n);
+ LOG(DEBUG) << "res_nsearch failed (" << n << ")";
// Pass herrno to catch more detailed errors rather than EAI_NODATA.
return herrnoToAiErrno(herrno);
}
@@ -885,7 +858,7 @@
n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, (int) sizeof(buf->buf), &herrno);
if (n < 0) {
free(buf);
- debugprintf("res_nquery failed (%d)\n", res, n);
+ LOG(DEBUG) << "res_nquery failed (" << n << ")";
return herrnoToAiErrno(herrno);
}
hp = getanswer(buf, n, qbuf, T_PTR, res, info->hp, info->buf, info->buflen, &herrno);
@@ -973,4 +946,4 @@
default:
return EAI_FAIL;
}
-}
\ No newline at end of file
+}
diff --git a/resolv/res_cache.cpp b/resolv/res_cache.cpp
index 98e6909..b3c4370 100644
--- a/resolv/res_cache.cpp
+++ b/resolv/res_cache.cpp
@@ -28,7 +28,6 @@
// NOTE: verbose logging MUST NOT be left enabled in production binaries.
// It floods logs at high rate, and can leak privacy-sensitive information.
-constexpr bool kVerboseLogging = false;
constexpr bool kDumpData = false;
#define LOG_TAG "res_cache"
@@ -56,14 +55,6 @@
#include "res_state_ext.h"
#include "resolv_private.h"
-#define VLOG if (!kVerboseLogging) {} else LOG(INFO)
-
-#ifndef RESOLV_ALLOW_VERBOSE_LOGGING
-static_assert(kVerboseLogging == false && kDumpData == false,
- "Verbose logging floods logs at high-rate and exposes privacy-sensitive information. "
- "Do not enable in release builds.");
-#endif
-
/* This code implements a small and *simple* DNS resolver cache.
*
* It is only used to cache DNS answers for a time defined by the smallest TTL
@@ -309,7 +300,7 @@
char *p = buff, *end = p + sizeof(buff);
p = bprint_hexdump(p, end, base, len);
- VLOG << buff;
+ LOG(INFO) << buff;
}
static time_t _time_now(void) {
@@ -491,7 +482,7 @@
* of the loop here */
}
/* malformed data */
- VLOG << "malformed QNAME";
+ LOG(INFO) << "malformed QNAME";
return 0;
}
@@ -507,12 +498,12 @@
!_dnsPacket_checkBytes(packet, 2, DNS_TYPE_MX) &&
!_dnsPacket_checkBytes(packet, 2, DNS_TYPE_AAAA) &&
!_dnsPacket_checkBytes(packet, 2, DNS_TYPE_ALL)) {
- VLOG << "unsupported TYPE";
+ LOG(INFO) << "unsupported TYPE";
return 0;
}
/* CLASS must be IN */
if (!_dnsPacket_checkBytes(packet, 2, DNS_CLASS_IN)) {
- VLOG << "unsupported CLASS";
+ LOG(INFO) << "unsupported CLASS";
return 0;
}
@@ -527,14 +518,14 @@
int qdCount, anCount, dnCount, arCount;
if (p + DNS_HEADER_SIZE > packet->end) {
- VLOG << "query packet too small";
+ LOG(INFO) << "query packet too small";
return 0;
}
/* QR must be set to 0, opcode must be 0 and AA must be 0 */
/* RA, Z, and RCODE must be 0 */
if ((p[2] & 0xFC) != 0 || (p[3] & 0xCF) != 0) {
- VLOG << "query packet flags unsupported";
+ LOG(INFO) << "query packet flags unsupported";
return 0;
}
@@ -563,12 +554,12 @@
arCount = (p[10] << 8) | p[11];
if (anCount != 0 || dnCount != 0 || arCount > 1) {
- VLOG << "query packet contains non-query records";
+ LOG(INFO) << "query packet contains non-query records";
return 0;
}
if (qdCount == 0) {
- VLOG << "query packet doesn't contain query record";
+ LOG(INFO) << "query packet doesn't contain query record";
return 0;
}
@@ -702,7 +693,7 @@
int c;
if (p >= end) { /* should not happen */
- VLOG << __func__ << ": INTERNAL_ERROR: read-overflow";
+ LOG(INFO) << __func__ << ": INTERNAL_ERROR: read-overflow";
break;
}
@@ -711,11 +702,11 @@
if (c == 0) break;
if (c >= 64) {
- VLOG << __func__ << ": INTERNAL_ERROR: malformed domain";
+ LOG(INFO) << __func__ << ": INTERNAL_ERROR: malformed domain";
break;
}
if (p + c >= end) {
- VLOG << __func__ << ": INTERNAL_ERROR: simple label read-overflow";
+ LOG(INFO) << __func__ << ": INTERNAL_ERROR: simple label read-overflow";
break;
}
while (c > 0) {
@@ -799,7 +790,7 @@
int c1, c2;
if (p1 >= end1 || p2 >= end2) {
- VLOG << __func__ << ": INTERNAL_ERROR: read-overflow";
+ LOG(INFO) << __func__ << ": INTERNAL_ERROR: read-overflow";
break;
}
c1 = *p1++;
@@ -812,11 +803,11 @@
return 1;
}
if (c1 >= 64) {
- VLOG << __func__ << ": INTERNAL_ERROR: malformed domain";
+ LOG(INFO) << __func__ << ": INTERNAL_ERROR: malformed domain";
break;
}
if ((p1 + c1 > end1) || (p2 + c1 > end2)) {
- VLOG << __func__ << ": INTERNAL_ERROR: simple label read-overflow";
+ LOG(INFO) << __func__ << ": INTERNAL_ERROR: simple label read-overflow";
break;
}
if (memcmp(p1, p2, c1) != 0) break;
@@ -825,7 +816,7 @@
/* we rely on the bound checks at the start of the loop */
}
/* not the same, or one is malformed */
- VLOG << "different DN";
+ LOG(INFO) << "different DN";
return 0;
}
@@ -873,12 +864,12 @@
/* compare RD, ignore TC, see comment in _dnsPacket_checkQuery */
if ((pack1->base[2] & 1) != (pack2->base[2] & 1)) {
- VLOG << "different RD";
+ LOG(INFO) << "different RD";
return 0;
}
if (pack1->base[3] != pack2->base[3]) {
- VLOG << "different CD or AD";
+ LOG(INFO) << "different CD or AD";
return 0;
}
@@ -890,7 +881,7 @@
count1 = _dnsPacket_readInt16(pack1);
count2 = _dnsPacket_readInt16(pack2);
if (count1 != count2 || count1 < 0) {
- VLOG << "different QDCOUNT";
+ LOG(INFO) << "different QDCOUNT";
return 0;
}
@@ -902,14 +893,14 @@
arcount1 = _dnsPacket_readInt16(pack1);
arcount2 = _dnsPacket_readInt16(pack2);
if (arcount1 != arcount2 || arcount1 < 0) {
- VLOG << "different ARCOUNT";
+ LOG(INFO) << "different ARCOUNT";
return 0;
}
/* compare the QDCOUNT QRs */
for (; count1 > 0; count1--) {
if (!_dnsPacket_isEqualQR(pack1, pack2)) {
- VLOG << "different QR";
+ LOG(INFO) << "different QR";
return 0;
}
}
@@ -917,7 +908,7 @@
/* compare the ARCOUNT RRs */
for (; arcount1 > 0; arcount1--) {
if (!_dnsPacket_isEqualRR(pack1, pack2)) {
- VLOG << "different additional RR";
+ LOG(INFO) << "different additional RR";
return 0;
}
}
@@ -1024,16 +1015,16 @@
result = ttl;
}
} else {
- VLOG << "ns_parserr failed ancount no = "
- << n << ". errno = " << strerror(errno);
+ LOG(INFO) << "ns_parserr failed ancount no = " << n
+ << ". errno = " << strerror(errno);
}
}
}
} else {
- VLOG << "ns_initparse failed: " << strerror(errno);
+ LOG(INFO) << "ns_initparse failed: " << strerror(errno);
}
- VLOG << "TTL = " << result;
+ LOG(INFO) << "TTL = " << result;
return result;
}
@@ -1271,7 +1262,7 @@
cache->num_entries = 0;
cache->last_id = 0;
- VLOG << "*** DNS CACHE FLUSHED ***";
+ LOG(INFO) << "*** DNS CACHE FLUSHED ***";
}
static resolv_cache* resolv_cache_create() {
@@ -1283,7 +1274,7 @@
cache->entries = (Entry*) calloc(sizeof(*cache->entries), cache->max_entries);
if (cache->entries) {
cache->mru_list.mru_prev = cache->mru_list.mru_next = &cache->mru_list;
- VLOG << __func__ << ": cache created";
+ LOG(INFO) << __func__ << ": cache created";
} else {
free(cache);
cache = NULL;
@@ -1293,19 +1284,15 @@
}
static void dump_query(const uint8_t* query, int querylen) {
- if (!kVerboseLogging) return;
-
char temp[256], *p = temp, *end = p + sizeof(temp);
DnsPacket pack[1];
_dnsPacket_init(pack, query, querylen);
p = dnsPacket_bprintQuery(pack, p, end);
- VLOG << temp;
+ LOG(INFO) << temp;
}
static void cache_dump_mru(Cache* cache) {
- if (!kVerboseLogging) return;
-
char temp[512], *p = temp, *end = p + sizeof(temp);
Entry* e;
@@ -1313,41 +1300,15 @@
for (e = cache->mru_list.mru_next; e != &cache->mru_list; e = e->mru_next)
p = bprint(p, end, " %d", e->id);
- VLOG << temp;
+ 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) {
- if (!kVerboseLogging) return;
-
res_state statep;
- FILE* fp;
- char* buf;
- int fileLen;
- fp = fopen("/data/reslog.txt", "w+e");
- if (fp != NULL) {
- statep = res_get_state();
-
- res_pquery(statep, answer, answerlen, fp);
-
- // Get file length
- fseek(fp, 0, SEEK_END);
- fileLen = ftell(fp);
- fseek(fp, 0, SEEK_SET);
- buf = (char*) malloc(fileLen + 1);
- if (buf != NULL) {
- // Read file contents into buffer
- fread(buf, fileLen, 1, fp);
- VLOG << buf;
- free(buf);
- }
- fclose(fp);
- remove("/data/reslog.txt");
- } else {
- errno = 0; // else debug is introducing error signals
- VLOG << __func__ << ": can't open file";
- }
+ statep = res_get_state();
+ res_pquery(statep, answer, answerlen);
}
/* This function tries to find a key within the hash table
@@ -1391,7 +1352,7 @@
entry_mru_add(e, &cache->mru_list);
cache->num_entries += 1;
- VLOG << __func__ << ": entry " << e->id << " added (count=" << cache->num_entries << ")";
+ LOG(INFO) << __func__ << ": entry " << e->id << " added (count=" << cache->num_entries << ")";
}
/* Remove an existing entry from the hash table,
@@ -1401,7 +1362,8 @@
static void _cache_remove_p(Cache* cache, Entry** lookup) {
Entry* e = *lookup;
- VLOG << __func__ << ": entry " << e->id << " removed (count=" << cache->num_entries - 1 << ")";
+ LOG(INFO) << __func__ << ": entry " << e->id << " removed (count=" << cache->num_entries - 1
+ << ")";
entry_mru_remove(e);
*lookup = e->hlink;
@@ -1416,10 +1378,10 @@
Entry** lookup = _cache_lookup_p(cache, oldest);
if (*lookup == NULL) { /* should not happen */
- VLOG << __func__ << ": OLDEST NOT IN HTABLE ?";
+ LOG(INFO) << __func__ << ": OLDEST NOT IN HTABLE ?";
return;
}
- VLOG << "Cache full - removing oldest";
+ LOG(INFO) << "Cache full - removing oldest";
dump_query(oldest->query, oldest->querylen);
_cache_remove_p(cache, lookup);
}
@@ -1435,7 +1397,7 @@
if (now >= e->expires) {
Entry** lookup = _cache_lookup_p(cache, e);
if (*lookup == NULL) { /* should not happen */
- VLOG << __func__ << ": ENTRY NOT IN HTABLE ?";
+ LOG(INFO) << __func__ << ": ENTRY NOT IN HTABLE ?";
return;
}
e = e->mru_next;
@@ -1461,12 +1423,12 @@
time_t now;
Cache* cache;
- VLOG << __func__ << ": lookup";
+ LOG(INFO) << __func__ << ": lookup";
dump_query((u_char*) query, querylen);
/* we don't cache malformed queries */
if (!entry_init_key(&key, query, querylen)) {
- VLOG << __func__ << ": unsupported query";
+ LOG(INFO) << __func__ << ": unsupported query";
return RESOLV_CACHE_UNSUPPORTED;
}
/* lookup cache */
@@ -1484,7 +1446,7 @@
e = *lookup;
if (e == NULL) {
- VLOG << "NOT IN CACHE";
+ LOG(INFO) << "NOT IN CACHE";
// If it is no-cache-store mode, we won't wait for possible query.
if (flags & ANDROID_RESOLV_NO_CACHE_STORE) {
return RESOLV_CACHE_SKIP;
@@ -1494,7 +1456,7 @@
return RESOLV_CACHE_NOTFOUND;
} else {
- VLOG << "Waiting for previous request";
+ LOG(INFO) << "Waiting for previous request";
// wait until (1) timeout OR
// (2) cv is notified AND no pending request matching the |key|
// (cv notifier should delete pending request before sending notification.)
@@ -1525,7 +1487,7 @@
/* remove stale entries here */
if (now >= e->expires) {
- VLOG << " NOT IN CACHE (STALE ENTRY " << *lookup << "DISCARDED)";
+ LOG(INFO) << " NOT IN CACHE (STALE ENTRY " << *lookup << "DISCARDED)";
dump_query(e->query, e->querylen);
_cache_remove_p(cache, lookup);
return RESOLV_CACHE_NOTFOUND;
@@ -1534,7 +1496,7 @@
*answerlen = e->answerlen;
if (e->answerlen > answersize) {
/* NOTE: we return UNSUPPORTED if the answer buffer is too short */
- VLOG << " ANSWER TOO LONG";
+ LOG(INFO) << " ANSWER TOO LONG";
return RESOLV_CACHE_UNSUPPORTED;
}
@@ -1546,7 +1508,7 @@
entry_mru_add(e, &cache->mru_list);
}
- VLOG << " FOUND IN CACHE entry=" << e;
+ LOG(INFO) << " FOUND IN CACHE entry=" << e;
return RESOLV_CACHE_FOUND;
}
@@ -1561,7 +1523,7 @@
/* don't assume that the query has already been cached
*/
if (!entry_init_key(key, query, querylen)) {
- VLOG << __func__ << ": passed invalid query?";
+ LOG(INFO) << __func__ << ": passed invalid query?";
return;
}
@@ -1572,11 +1534,11 @@
return;
}
- VLOG << __func__ << ": query:";
+ LOG(INFO) << __func__ << ": query:";
dump_query((u_char*) query, querylen);
dump_answer((u_char*) answer, answerlen);
if (kDumpData) {
- VLOG << "answer:";
+ LOG(INFO) << "answer:";
dump_bytes((u_char*) answer, answerlen);
}
@@ -1584,7 +1546,7 @@
e = *lookup;
if (e != NULL) { /* should not happen */
- VLOG << __func__ << ": ALREADY IN CACHE (" << e << ") ? IGNORING ADD";
+ LOG(INFO) << __func__ << ": ALREADY IN CACHE (" << e << ") ? IGNORING ADD";
_cache_notify_waiting_tid_locked(cache, key);
return;
}
@@ -1598,7 +1560,7 @@
lookup = _cache_lookup_p(cache, key);
e = *lookup;
if (e != NULL) {
- VLOG << __func__ << ": ALREADY IN CACHE (" << e << ") ? IGNORING ADD";
+ LOG(INFO) << __func__ << ": ALREADY IN CACHE (" << e << ") ? IGNORING ADD";
_cache_notify_waiting_tid_locked(cache, key);
return;
}
@@ -1727,7 +1689,7 @@
struct addrinfo* nsaddrinfo[MAXNS];
if (numservers > MAXNS) {
- VLOG << __func__ << ": numservers=" << numservers << ", MAXNS=" << MAXNS;
+ LOG(INFO) << __func__ << ": numservers=" << numservers << ", MAXNS=" << MAXNS;
return E2BIG;
}
@@ -1744,8 +1706,8 @@
for (int j = 0; j < i; j++) {
freeaddrinfo(nsaddrinfo[j]);
}
- VLOG << __func__ << ": getaddrinfo_numeric(" << servers[i]
- << ") = " << gai_strerror(rt);
+ LOG(INFO) << __func__ << ": getaddrinfo_numeric(" << servers[i]
+ << ") = " << gai_strerror(rt);
return EINVAL;
}
}
@@ -1770,7 +1732,7 @@
for (int i = 0; i < numservers; i++) {
cache_info->nsaddrinfo[i] = nsaddrinfo[i];
cache_info->nameservers[i] = strdup(servers[i]);
- VLOG << __func__ << ": netid = " << netid << ", addr = " << servers[i];
+ LOG(INFO) << __func__ << ": netid = " << netid << ", addr = " << servers[i];
}
cache_info->nscount = numservers;
@@ -1879,7 +1841,7 @@
if (info != NULL) {
int nserv;
struct addrinfo* ai;
- VLOG << __func__ << ": " << statp->netid;
+ LOG(INFO) << __func__ << ": " << statp->netid;
for (nserv = 0; nserv < MAXNS; nserv++) {
ai = info->nsaddrinfo[nserv];
if (ai == NULL) {
@@ -1898,7 +1860,7 @@
}
}
} else {
- VLOG << __func__ << ": found too long addrlen";
+ LOG(INFO) << __func__ << ": found too long addrlen";
}
}
statp->nscount = nserv;
@@ -1920,8 +1882,8 @@
int max_samples) {
// Note: This function expects max_samples > 0, otherwise a (harmless) modification of the
// allocated but supposedly unused memory for samples[0] will happen
- VLOG << __func__ << ": adding sample to stats, next = " << stats->sample_next
- << ", count = " << stats->sample_count;
+ LOG(INFO) << __func__ << ": adding sample to stats, next = " << stats->sample_next
+ << ", count = " << stats->sample_count;
stats->samples[stats->sample_next] = *sample;
if (stats->sample_count < max_samples) {
++stats->sample_count;
@@ -1950,7 +1912,7 @@
resolv_cache_info* info = find_cache_info_locked(netid);
if (info) {
if (info->nscount > MAXNS) {
- VLOG << __func__ << ": nscount " << info->nscount << " > MAXNS " << MAXNS;
+ LOG(INFO) << __func__ << ": nscount " << info->nscount << " > MAXNS " << MAXNS;
errno = EFAULT;
return -1;
}
@@ -1962,17 +1924,17 @@
// - there is only one address per addrinfo thanks to numeric resolution
int addrlen = info->nsaddrinfo[i]->ai_addrlen;
if (addrlen < (int) sizeof(struct sockaddr) || addrlen > (int) sizeof(servers[0])) {
- VLOG << __func__ << ": nsaddrinfo[" << i << "].ai_addrlen == " << addrlen;
+ LOG(INFO) << __func__ << ": nsaddrinfo[" << i << "].ai_addrlen == " << addrlen;
errno = EMSGSIZE;
return -1;
}
if (info->nsaddrinfo[i]->ai_addr == NULL) {
- VLOG << __func__ << ": nsaddrinfo[" << i << "].ai_addr == NULL";
+ LOG(INFO) << __func__ << ": nsaddrinfo[" << i << "].ai_addr == NULL";
errno = ENOENT;
return -1;
}
if (info->nsaddrinfo[i]->ai_next != NULL) {
- VLOG << __func__ << ": nsaddrinfo[" << i << "].ai_next != NULL";
+ LOG(INFO) << __func__ << ": nsaddrinfo[" << i << "].ai_next != NULL";
errno = ENOTUNIQ;
return -1;
}
diff --git a/resolv/res_debug.cpp b/resolv/res_debug.cpp
index f5a0aff..cfd486d 100644
--- a/resolv/res_debug.cpp
+++ b/resolv/res_debug.cpp
@@ -103,6 +103,7 @@
#include <arpa/nameser.h>
#include <netinet/in.h>
+#include <android-base/logging.h>
#include <ctype.h>
#include <errno.h>
#include <math.h>
@@ -121,12 +122,34 @@
const char* humanname; /* Its fun name, like "mail exchanger" */
};
-static void do_section(const res_state statp, ns_msg* handle, ns_sect section, int pflag,
- FILE* file) {
+/* add a formatted string to a bounded buffer */
+static char* dbprint(char* p, char* end, const char* format, ...) {
+ int avail, n;
+ va_list args;
+
+ avail = end - p;
+
+ if (avail <= 0) return p;
+
+ va_start(args, format);
+ n = vsnprintf(p, avail, format, args);
+ va_end(args);
+
+ /* certain C libraries return -1 in case of truncation */
+ if (n < 0 || n > avail) n = avail;
+
+ p += n;
+ /* certain C libraries do not zero-terminate in case of truncation */
+ if (p == end) p[-1] = 0;
+
+ return p;
+}
+static void do_section(const res_state statp, ns_msg* handle, ns_sect section, int pflag) {
int n, sflag, rrnum;
int buflen = 2048;
ns_opcode opcode;
ns_rr rr;
+ char temp[2048], *p = temp, *end = p + sizeof(temp);
/*
* Print answer records.
@@ -136,7 +159,8 @@
char* buf = (char*) malloc((size_t) buflen);
if (buf == NULL) {
- fprintf(file, ";; memory allocation failure\n");
+ dbprint(p, end, ";; memory allocation failure\n");
+ LOG(VERBOSE) << temp;
return;
}
@@ -145,23 +169,23 @@
for (;;) {
if (ns_parserr(handle, section, rrnum, &rr)) {
if (errno != ENODEV)
- fprintf(file, ";; ns_parserr: %s\n", strerror(errno));
+ dbprint(p, end, ";; ns_parserr: %s", strerror(errno));
else if (rrnum > 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1))
- putc('\n', file);
+ dbprint(p, end, "\n");
goto cleanup;
}
if (rrnum == 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1))
- fprintf(file, ";; %s SECTION:\n", p_section(section, opcode));
+ dbprint(p, end, ";; %s SECTION:\n", p_section(section, opcode));
if (section == ns_s_qd)
- fprintf(file, ";;\t%s, type = %s, class = %s\n", ns_rr_name(rr), p_type(ns_rr_type(rr)),
- p_class(ns_rr_class(rr)));
+ 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)));
else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) {
size_t rdatalen, ttl;
uint16_t optcode, optlen;
rdatalen = ns_rr_rdlen(rr);
ttl = ns_rr_ttl(rr);
- fprintf(file, "; EDNS: version: %zu, udp=%u, flags=%04zx\n", (ttl >> 16) & 0xff,
+ dbprint(p, end, "; EDNS: version: %zu, udp=%u, flags=%04zx\n", (ttl >> 16) & 0xff,
ns_rr_class(rr), ttl & 0xffff);
while (rdatalen >= 4) {
const u_char* cp = ns_rr_rdata(rr);
@@ -171,27 +195,33 @@
GETSHORT(optlen, cp);
if (optcode == NS_OPT_NSID) {
- fputs("; NSID: ", file);
+ p = dbprint(p, end, "; NSID: ");
if (optlen == 0) {
- fputs("; NSID\n", file);
+ p = dbprint(p, end, "; NSID\n");
} else {
- fputs("; NSID: ", file);
- for (i = 0; i < optlen; i++) fprintf(file, "%02x ", cp[i]);
- fputs(" (", file);
- for (i = 0; i < optlen; i++)
- fprintf(file, "%c", isprint(cp[i]) ? cp[i] : '.');
- fputs(")\n", file);
+ p = dbprint(p, end, "; NSID: ");
+ for (i = 0; i < optlen; i++) {
+ p = dbprint(p, end, "%02x ", cp[i]);
+ }
+ p = dbprint(p, end, " (");
+ for (i = 0; i < optlen; i++) {
+ p = dbprint(p, end, "%c", isprint(cp[i]) ? cp[i] : '.');
+ }
+ p = dbprint(p, end, ")\n");
}
} else {
if (optlen == 0) {
- fprintf(file, "; OPT=%u\n", optcode);
+ p = dbprint(p, end, "; OPT=%u\n", optcode);
} else {
- fprintf(file, "; OPT=%u: ", optcode);
- for (i = 0; i < optlen; i++) fprintf(file, "%02x ", cp[i]);
- fputs(" (", file);
- for (i = 0; i < optlen; i++)
- fprintf(file, "%c", isprint(cp[i]) ? cp[i] : '.');
- fputs(")\n", file);
+ p = dbprint(p, end, "; OPT=%u: ", optcode);
+ for (i = 0; i < optlen; i++) {
+ p = dbprint(p, end, "%02x ", cp[i]);
+ }
+ p = dbprint(p, end, " (");
+ for (i = 0; i < optlen; i++) {
+ p = dbprint(p, end, "%c", isprint(cp[i]) ? cp[i] : '.');
+ }
+ p = dbprint(p, end, ")\n");
}
}
rdatalen -= 4 + optlen;
@@ -206,34 +236,37 @@
buf = (char*) malloc((size_t)(buflen += 1024));
}
if (buf == NULL) {
- fprintf(file, ";; memory allocation failure\n");
+ p = dbprint(p, end, ";; memory allocation failure\n");
+ LOG(VERBOSE) << temp;
return;
}
continue;
}
- fprintf(file, ";; ns_sprintrr: %s\n", strerror(errno));
+ p = dbprint(p, end, ";; ns_sprintrr: %s\n", strerror(errno));
goto cleanup;
}
- fputs(buf, file);
- fputc('\n', file);
+ p = dbprint(p, end, ";; %s\n", buf);
}
rrnum++;
}
cleanup:
free(buf);
+ LOG(VERBOSE) << temp;
}
/*
* 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, FILE* file) {
+
+void res_pquery(const res_state statp, const u_char* msg, int len) {
ns_msg handle;
int qdcount, ancount, nscount, arcount;
u_int opcode, rcode, id;
+ char temp[2048], *p = temp, *end = p + sizeof(temp);
if (ns_initparse(msg, len, &handle) < 0) {
- fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
+ dbprint(p, end, ";; ns_initparse: %s\n", strerror(errno));
return;
}
opcode = ns_msg_getflag(handle, ns_f_opcode);
@@ -248,37 +281,39 @@
* Print header fields.
*/
if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX) || rcode)
- fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n", _res_opcodes[opcode],
- p_rcode((int) rcode), id);
- if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX)) putc(';', file);
+ 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)) {
- fprintf(file, "; flags:");
- if (ns_msg_getflag(handle, ns_f_qr)) fprintf(file, " qr");
- if (ns_msg_getflag(handle, ns_f_aa)) fprintf(file, " aa");
- if (ns_msg_getflag(handle, ns_f_tc)) fprintf(file, " tc");
- if (ns_msg_getflag(handle, ns_f_rd)) fprintf(file, " rd");
- if (ns_msg_getflag(handle, ns_f_ra)) fprintf(file, " ra");
- if (ns_msg_getflag(handle, ns_f_z)) fprintf(file, " ??");
- if (ns_msg_getflag(handle, ns_f_ad)) fprintf(file, " ad");
- if (ns_msg_getflag(handle, ns_f_cd)) fprintf(file, " cd");
+ 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");
+ if (ns_msg_getflag(handle, ns_f_tc)) p = dbprint(p, end, " tc");
+ if (ns_msg_getflag(handle, ns_f_rd)) p = dbprint(p, end, " rd");
+ if (ns_msg_getflag(handle, ns_f_ra)) p = dbprint(p, end, " ra");
+ 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)) {
- fprintf(file, "; %s: %d", p_section(ns_s_qd, (int) opcode), qdcount);
- fprintf(file, ", %s: %d", p_section(ns_s_an, (int) opcode), ancount);
- fprintf(file, ", %s: %d", p_section(ns_s_ns, (int) opcode), nscount);
- fprintf(file, ", %s: %d", p_section(ns_s_ar, (int) opcode), arcount);
+ 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);
}
if ((!statp->pfcode) || (statp->pfcode & (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
- putc('\n', file);
+ p = dbprint(p, end, " \n");
}
+ LOG(VERBOSE) << temp;
+
/*
* Print the various sections.
*/
- do_section(statp, &handle, ns_s_qd, RES_PRF_QUES, file);
- do_section(statp, &handle, ns_s_an, RES_PRF_ANS, file);
- do_section(statp, &handle, ns_s_ns, RES_PRF_AUTH, file);
- do_section(statp, &handle, ns_s_ar, RES_PRF_ADD, file);
- if (qdcount == 0 && ancount == 0 && nscount == 0 && arcount == 0) putc('\n', file);
+ 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);
+ if (qdcount == 0 && ancount == 0 && nscount == 0 && arcount == 0) LOG(VERBOSE) << ";;";
}
const u_char* p_cdnname(const u_char* cp, const u_char* msg, int len, FILE* file) {
@@ -516,3 +551,27 @@
const char* p_rcode(int rcode) {
return (sym_ntos(p_rcode_syms, rcode, (int*) 0));
}
+
+android::base::LogSeverity logSeverityStrToEnum(const std::string& logSeverityStr) {
+ android::base::LogSeverity logSeverityEnum;
+ if (logSeverityStr == "VERBOSE") {
+ logSeverityEnum = android::base::VERBOSE;
+ } else if (logSeverityStr == "DEBUG") {
+ logSeverityEnum = android::base::DEBUG;
+ } else if (logSeverityStr == "INFO") {
+ logSeverityEnum = android::base::INFO;
+ } else if (logSeverityStr == "WARNING") {
+ logSeverityEnum = android::base::WARNING;
+ } else if (logSeverityStr == "ERROR") {
+ logSeverityEnum = android::base::ERROR;
+ } else if (logSeverityStr == "FATAL_WITHOUT_ABORT") {
+ logSeverityEnum = android::base::FATAL_WITHOUT_ABORT;
+ } else if (logSeverityStr == "FATAL") {
+ logSeverityEnum = android::base::FATAL;
+ } else {
+ // Invalid parameter is treated as WARNING (default setting)
+ logSeverityEnum = android::base::WARNING;
+ }
+ LOG(INFO) << "logSeverityEnum " << logSeverityEnum;
+ return logSeverityEnum;
+}
diff --git a/resolv/res_init.cpp b/resolv/res_init.cpp
index 26cb9f3..a02e7f0 100644
--- a/resolv/res_init.cpp
+++ b/resolv/res_init.cpp
@@ -69,7 +69,6 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/time.h>
@@ -79,6 +78,7 @@
#include <arpa/nameser.h>
#include <netinet/in.h>
+#include <android-base/logging.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -92,10 +92,6 @@
#include "res_state_ext.h"
#include "resolv_private.h"
-/* Options. Should all be left alone. */
-#ifndef DEBUG
-#define DEBUG
-#endif
static void res_setoptions(res_state, const char*, const char*);
@@ -191,13 +187,9 @@
dots--;
}
*pp = NULL;
-#ifdef DEBUG
- if (statp->options & RES_DEBUG) {
- printf(";; res_init()... default dnsrch list:\n");
- for (pp = statp->dnsrch; *pp; pp++) printf(";;\t%s\n", *pp);
- printf(";;\t..END..\n");
- }
-#endif
+ LOG(DEBUG) << ";; res_init()... default dnsrch list:";
+ for (pp = statp->dnsrch; *pp; pp++) LOG(DEBUG) << ";;\t" << *pp;
+ LOG(DEBUG) << ";;\t..END..";
}
if ((cp = getenv("RES_OPTIONS")) != NULL) res_setoptions(statp, cp, "env");
@@ -213,10 +205,8 @@
int i;
res_state_ext* ext = statp->_u._ext.ext;
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; res_setoptions(\"%s\", \"%s\")...\n", options, source);
-#endif
+ LOG(DEBUG) << ";; res_setoptions(\"" << options << "\", \"" << source << "\")...";
+
while (*cp) {
/* skip leading and inner runs of spaces */
while (*cp == ' ' || *cp == '\t') cp++;
@@ -227,35 +217,34 @@
statp->ndots = i;
else
statp->ndots = RES_MAXNDOTS;
-#ifdef DEBUG
- if (statp->options & RES_DEBUG) printf(";;\tndots=%d\n", statp->ndots);
-#endif
+
+ LOG(DEBUG) << ";;\tndots=" << statp->ndots;
+
} else if (!strncmp(cp, "timeout:", sizeof("timeout:") - 1)) {
i = atoi(cp + sizeof("timeout:") - 1);
if (i <= RES_MAXRETRANS)
statp->retrans = i;
else
statp->retrans = RES_MAXRETRANS;
-#ifdef DEBUG
- if (statp->options & RES_DEBUG) printf(";;\ttimeout=%d\n", statp->retrans);
-#endif
+
+ LOG(DEBUG) << ";;\ttimeout=" << statp->retrans;
+
} else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)) {
i = atoi(cp + sizeof("attempts:") - 1);
if (i <= RES_MAXRETRY)
statp->retry = i;
else
statp->retry = RES_MAXRETRY;
-#ifdef DEBUG
- if (statp->options & RES_DEBUG) printf(";;\tattempts=%d\n", statp->retry);
-#endif
+
+ LOG(DEBUG) << ";;\tattempts=" << statp->retry;
+
} else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
-#ifdef DEBUG
if (!(statp->options & RES_DEBUG)) {
- printf(";; res_setoptions(\"%s\", \"%s\")..\n", options, source);
+ LOG(DEBUG) << ";; res_setoptions(\"" << options << "\", \"" << source << "\")..";
statp->options |= RES_DEBUG;
}
- printf(";;\tdebug\n");
-#endif
+ 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;
diff --git a/resolv/res_mkquery.cpp b/resolv/res_mkquery.cpp
index b2f97c7..b126540 100644
--- a/resolv/res_mkquery.cpp
+++ b/resolv/res_mkquery.cpp
@@ -79,12 +79,9 @@
#include <string.h>
#include <sys/types.h>
-#include "resolv_private.h"
+#include <android-base/logging.h>
-/* Options. Leave them on. */
-#ifndef DEBUG
-#define DEBUG
-#endif
+#include "resolv_private.h"
// Queries will be padded to a multiple of this length when EDNS0 is active.
constexpr uint16_t kEdns0Padding = 128;
@@ -114,11 +111,9 @@
int n;
u_char *dnptrs[20], **dpp, **lastdnptr;
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; res_nmkquery(%s, %s, %s, %s)\n", _res_opcodes[op], dname, p_class(cl),
- p_type(type));
-#endif
+ LOG(DEBUG) << ";; res_nmkquery(" << _res_opcodes[op] << ", " << dname << ", " << p_class(cl)
+ << ", " << p_type(type) << ")";
+
/*
* Initialize header fields.
*/
@@ -206,9 +201,7 @@
u_char *cp, *ep;
u_int16_t flags = 0;
-#ifdef DEBUG
- if ((statp->options & RES_DEBUG) != 0U) printf(";; res_nopt()\n");
-#endif
+ LOG(DEBUG) << ";; " << __func__;
hp = (HEADER*) (void*) buf;
cp = buf + n0;
@@ -227,9 +220,7 @@
*cp++ = NOERROR; /* extended RCODE */
*cp++ = 0; /* EDNS version */
if (statp->options & RES_USE_DNSSEC) {
-#ifdef DEBUG
- if (statp->options & RES_DEBUG) printf(";; res_opt()... ENDS0 DNSSEC\n");
-#endif
+ LOG(DEBUG) << ";; " << __func__ << "... ENDS0 DNSSEC";
flags |= NS_OPT_DNSSEC_OK;
}
ns_put16(flags, cp);
diff --git a/resolv/res_query.cpp b/resolv/res_query.cpp
index acf6160..f5da81f 100644
--- a/resolv/res_query.cpp
+++ b/resolv/res_query.cpp
@@ -83,14 +83,11 @@
#include <string.h>
#include <unistd.h>
+#include <android-base/logging.h>
+
#include "resolv_cache.h"
#include "resolv_private.h"
-/* Options. Leave them on. */
-#ifndef DEBUG
-#define DEBUG
-#endif
-
#if PACKETSZ > 1024
#define MAXPACKET PACKETSZ
#else
@@ -123,17 +120,13 @@
again:
hp->rcode = NOERROR; /* default */
-#ifdef DEBUG
- if (statp->options & RES_DEBUG) printf(";; res_query(%s, %d, %d)\n", name, cl, type);
-#endif
+ LOG(DEBUG) << ";; res_query(" << name << ", " << cl << ", " << type;
n = res_nmkquery(statp, QUERY, name, cl, type, NULL, 0, NULL, buf, sizeof(buf));
if (n > 0 && (statp->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0U && !retried)
n = res_nopt(statp, n, buf, sizeof(buf), anslen);
if (n <= 0) {
-#ifdef DEBUG
- if (statp->options & RES_DEBUG) printf(";; res_query: mkquery failed\n");
-#endif
+ LOG(DEBUG) << ";; res_query: mkquery failed";
*herrno = NO_RECOVERY;
return n;
}
@@ -142,13 +135,12 @@
/* if the query choked with EDNS0, retry without EDNS0 */
if ((statp->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0U &&
(statp->_flags & RES_F_EDNS0ERR) && !retried) {
- if (statp->options & RES_DEBUG) printf(";; res_nquery: retry without EDNS0\n");
+ LOG(DEBUG) << ";; res_nquery: retry without EDNS0";
retried = true;
goto again;
}
-#ifdef DEBUG
- if (statp->options & RES_DEBUG) printf(";; res_query: send error\n");
-#endif
+ LOG(DEBUG) << ";; res_query: send error";
+
// Note that rcodes SERVFAIL, NOTIMP, REFUSED may cause res_nquery() to return a general
// error code EAI_AGAIN, but mapping the error code from rcode as res_queryN() does for
// getaddrinfo(). Different rcodes trigger different behaviors:
@@ -175,11 +167,10 @@
}
if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; rcode = (%s), counts = an:%d ns:%d ar:%d\n", p_rcode(hp->rcode),
- ntohs(hp->ancount), ntohs(hp->nscount), ntohs(hp->arcount));
-#endif
+ LOG(DEBUG) << ";; rcode = (" << p_rcode(hp->rcode)
+ << "), counts = an:" << ntohs(hp->ancount) << " ns:" << ntohs(hp->nscount)
+ << " ar:" << ntohs(hp->arcount);
+
switch (hp->rcode) {
case NXDOMAIN:
*herrno = HOST_NOT_FOUND;
@@ -356,12 +347,8 @@
const char* longname = nbuf;
int n, d;
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; res_nquerydomain(%s, %s, %d, %d)\n", name, domain ? domain : "<Nil>", cl,
- type);
-#endif
if (domain == NULL) {
+ LOG(DEBUG) << ";; res_nquerydomain(" << name << ", <Nil>, " << cl << ", " << type << ")";
/*
* Check for trailing '.';
* copy without '.' if present.
@@ -378,6 +365,8 @@
} else
longname = name;
} else {
+ LOG(DEBUG) << ";; res_nquerydomain(" << name << ", " << domain << ", " << cl << ", " << type
+ << ")";
n = strlen(name);
d = strlen(domain);
if (n + d + 1 >= MAXDNAME) {
diff --git a/resolv/res_send.cpp b/resolv/res_send.cpp
index 5da47fd..66af1c2 100644
--- a/resolv/res_send.cpp
+++ b/resolv/res_send.cpp
@@ -74,7 +74,6 @@
* Send query to name server and wait for reply.
*/
-constexpr bool kVerboseLogging = false;
#define LOG_TAG "res_send"
#include <sys/param.h>
@@ -116,32 +115,6 @@
using namespace android::net;
using android::netdutils::Slice;
-#define VLOG if (!kVerboseLogging) {} else LOG(INFO)
-
-#ifndef RESOLV_ALLOW_VERBOSE_LOGGING
-static_assert(kVerboseLogging == false,
- "Verbose logging floods logs at high-rate and exposes privacy-sensitive information. "
- "Do not enable in release builds.");
-#endif
-
-#ifndef DEBUG
-#define Dprint(cond, args) /*empty*/
-#define DprintQ(cond, args, query, size) /*empty*/
-#else
-// TODO: convert to Android logging
-#define Dprint(cond, args) \
- if (cond) { \
- fprintf args; \
- } else { \
- }
-#define DprintQ(cond, args, query, size) \
- if (cond) { \
- fprintf args; \
- res_pquery(statp, query, size, stdout); \
- } else { \
- }
-#endif // DEBUG
-
static DnsTlsDispatcher sDnsTlsDispatcher;
static int get_salen(const struct sockaddr*);
@@ -150,8 +123,9 @@
time_t*, int*, int*);
static int send_dg(res_state, res_params* params, const u_char*, int, u_char*, int, int*, int, int*,
int*, time_t*, int*, int*);
-static void Aerror(const res_state, FILE*, const char*, int, const struct sockaddr*, int);
-static void Perror(const res_state, FILE*, const char*, int);
+static void Aerror(const res_state, const char*, int, const struct sockaddr*, int);
+static void Perror(const res_state, const char*, int);
+
static int sock_eq(struct sockaddr*, struct sockaddr*);
static int connect_with_timeout(int sock, const struct sockaddr* nsap, socklen_t salen,
const struct timespec timeout);
@@ -400,8 +374,9 @@
errno = EINVAL;
return -EINVAL;
}
- DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY),
- (stdout, ";; res_send()\n"), buf, buflen);
+ LOG(DEBUG) << ";; " << __func__;
+ res_pquery(statp, buf, buflen);
+
v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ;
gotsomewhere = 0;
terrno = ETIMEDOUT;
@@ -554,10 +529,9 @@
[[maybe_unused]] static const int niflags = NI_NUMERICHOST | NI_NUMERICSERV;
[[maybe_unused]] char abuf[NI_MAXHOST];
- Dprint(((statp->options & RES_DEBUG) &&
- getnameinfo(nsap, (socklen_t) nsaplen, abuf, sizeof(abuf), NULL, 0, niflags) ==
- 0),
- (stdout, ";; Querying server (# %d) address = %s\n", ns + 1, abuf));
+
+ if (getnameinfo(nsap, (socklen_t)nsaplen, abuf, sizeof(abuf), NULL, 0, niflags) == 0)
+ LOG(DEBUG) << ";; Querying server (# " << ns + 1 << ") address = " << abuf;
if (v_circuit) {
/* Use VC; at most one attempt per server. */
@@ -579,7 +553,7 @@
params.max_samples);
}
- VLOG << "used send_vc " << n;
+ LOG(INFO) << "used send_vc " << n;
if (n < 0) {
_resolv_cache_query_failed(statp->netid, buf, buflen, flags);
@@ -590,7 +564,7 @@
resplen = n;
} else {
/* Use datagrams. */
- VLOG << "using send_dg";
+ LOG(INFO) << "using send_dg";
n = send_dg(statp, ¶ms, buf, buflen, ans, anssiz, &terrno, ns, &v_circuit,
&gotsomewhere, &now, rcode, &delay);
@@ -603,7 +577,7 @@
params.max_samples);
}
- VLOG << "used send_dg " << n;
+ LOG(INFO) << "used send_dg " << n;
if (n < 0) {
_resolv_cache_query_failed(statp->netid, buf, buflen, flags);
@@ -611,17 +585,12 @@
return -terrno;
};
if (n == 0) goto next_ns;
- VLOG << "time=" << time(NULL);
if (v_circuit) goto same_ns;
resplen = n;
}
- Dprint((statp->options & RES_DEBUG) ||
- ((statp->pfcode & RES_PRF_REPLY) && (statp->pfcode & RES_PRF_HEAD1)),
- (stdout, ";; got answer:\n"));
-
- DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_REPLY),
- (stdout, "%s", ""), ans, (resplen > anssiz) ? anssiz : resplen);
+ LOG(DEBUG) << ";; got answer:";
+ res_pquery(statp, ans, (resplen > anssiz) ? anssiz : resplen);
if (cache_status == RESOLV_CACHE_NOTFOUND) {
_resolv_cache_add(statp->netid, buf, buflen, ans, resplen);
@@ -654,7 +623,6 @@
errno = terrno;
}
_resolv_cache_query_failed(statp->netid, buf, buflen, flags);
-
return -terrno;
}
@@ -707,7 +675,7 @@
msec = 1000; // Use at least 100ms
}
}
- VLOG << "using timeout of " << msec << " msec";
+ LOG(INFO) << "using timeout of " << msec << " msec";
struct timespec result;
result.tv_sec = msec / 1000;
@@ -728,7 +696,7 @@
u_short len;
u_char* cp;
- VLOG << "using send_vc";
+ LOG(INFO) << "using send_vc";
nsap = get_nsaddr(statp, (size_t) ns);
nsaplen = get_salen(nsap);
@@ -763,11 +731,11 @@
case EPROTONOSUPPORT:
case EPFNOSUPPORT:
case EAFNOSUPPORT:
- Perror(statp, stderr, "socket(vc)", errno);
+ Perror(statp, "socket(vc)", errno);
return 0;
default:
*terrno = errno;
- Perror(statp, stderr, "socket(vc)", errno);
+ Perror(statp, "socket(vc)", errno);
return -1;
}
}
@@ -776,21 +744,21 @@
if (setsockopt(statp->_vcsock, SOL_SOCKET, SO_MARK, &statp->_mark,
sizeof(statp->_mark)) < 0) {
*terrno = errno;
- Perror(statp, stderr, "setsockopt", errno);
+ Perror(statp, "setsockopt", errno);
return -1;
}
}
errno = 0;
if (random_bind(statp->_vcsock, nsap->sa_family) < 0) {
*terrno = errno;
- Aerror(statp, stderr, "bind/vc", errno, nsap, nsaplen);
+ Aerror(statp, "bind/vc", errno, nsap, nsaplen);
res_nclose(statp);
return (0);
}
if (connect_with_timeout(statp->_vcsock, nsap, (socklen_t) nsaplen,
get_timeout(statp, params, ns)) < 0) {
*terrno = errno;
- Aerror(statp, stderr, "connect/vc", errno, nsap, nsaplen);
+ Aerror(statp, "connect/vc", errno, nsap, nsaplen);
res_nclose(statp);
/*
* The way connect_with_timeout() is implemented prevents us from reliably
@@ -814,7 +782,7 @@
iov[1] = evConsIovec((void*) buf, (size_t) buflen);
if (writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) {
*terrno = errno;
- Perror(statp, stderr, "write failed", errno);
+ Perror(statp, "write failed", errno);
res_nclose(statp);
return (0);
}
@@ -830,7 +798,7 @@
}
if (n <= 0) {
*terrno = errno;
- Perror(statp, stderr, "read failed", errno);
+ Perror(statp, "read failed", errno);
res_nclose(statp);
/*
* A long running process might get its TCP
@@ -851,7 +819,7 @@
}
resplen = ns_get16(ans);
if (resplen > anssiz) {
- Dprint(statp->options & RES_DEBUG, (stdout, ";; response truncated\n"));
+ LOG(DEBUG) << ";; response truncated";
truncating = 1;
len = anssiz;
} else
@@ -860,7 +828,7 @@
/*
* Undersized message.
*/
- Dprint(statp->options & RES_DEBUG, (stdout, ";; undersized: %d\n", len));
+ LOG(DEBUG) << ";; undersized: " << len;
*terrno = EMSGSIZE;
res_nclose(statp);
return (0);
@@ -872,7 +840,7 @@
}
if (n <= 0) {
*terrno = errno;
- Perror(statp, stderr, "read(vc)", errno);
+ Perror(statp, "read(vc)", errno);
res_nclose(statp);
return (0);
}
@@ -901,9 +869,8 @@
* wait for the correct one.
*/
if (hp->id != anhp->id) {
- DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_REPLY),
- (stdout, ";; old answer (unexpected):\n"), ans,
- (resplen > anssiz) ? anssiz : resplen);
+ LOG(DEBUG) << ";; old answer (unexpected):";
+ res_pquery(statp, ans, (resplen > anssiz) ? anssiz : resplen);
goto read_len;
}
@@ -935,7 +902,7 @@
if (res != 0) {
struct timespec now = evNowTime();
struct timespec finish = evAddTime(now, timeout);
- VLOG << sock << " send_vc";
+ LOG(INFO) << sock << " send_vc";
res = retrying_poll(sock, POLLIN | POLLOUT, &finish);
if (res <= 0) {
res = -1;
@@ -943,7 +910,7 @@
}
done:
fcntl(sock, F_SETFL, origflags);
- VLOG << sock << " connect_with_const timeout returning " << res;
+ LOG(INFO) << sock << " connect_with_const timeout returning " << res;
return res;
}
@@ -951,7 +918,7 @@
struct timespec now, timeout;
retry:
- VLOG << " " << sock << " retrying_poll";
+ LOG(INFO) << " " << sock << " retrying_poll";
now = evNowTime();
if (evCmpTime(*finish, now) > 0)
@@ -961,13 +928,13 @@
struct pollfd fds = {.fd = sock, .events = events};
int n = ppoll(&fds, 1, &timeout, /*sigmask=*/NULL);
if (n == 0) {
- VLOG << " " << sock << "retrying_poll timeout";
+ LOG(INFO) << " " << sock << "retrying_poll timeout";
errno = ETIMEDOUT;
return 0;
}
if (n < 0) {
if (errno == EINTR) goto retry;
- VLOG << " " << sock << " retrying_poll got error " << n;
+ LOG(INFO) << " " << sock << " retrying_poll got error " << n;
return n;
}
if (fds.revents & (POLLIN | POLLOUT | POLLERR)) {
@@ -975,11 +942,11 @@
socklen_t len = sizeof(error);
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error) {
errno = error;
- VLOG << " " << sock << " retrying_poll dot error2 " << errno;
+ LOG(INFO) << " " << sock << " retrying_poll dot error2 " << errno;
return -1;
}
}
- VLOG << " " << sock << " retrying_poll returning " << n;
+ LOG(INFO) << " " << sock << " retrying_poll returning " << n;
return n;
}
@@ -1006,11 +973,11 @@
case EPROTONOSUPPORT:
case EPFNOSUPPORT:
case EAFNOSUPPORT:
- Perror(statp, stderr, "socket(dg)", errno);
+ Perror(statp, "socket(dg)", errno);
return (0);
default:
*terrno = errno;
- Perror(statp, stderr, "socket(dg)", errno);
+ Perror(statp, "socket(dg)", errno);
return (-1);
}
}
@@ -1036,28 +1003,28 @@
* the absence of a nameserver without timing out.
*/
if (random_bind(statp->_u._ext.nssocks[ns], nsap->sa_family) < 0) {
- Aerror(statp, stderr, "bind(dg)", errno, nsap, nsaplen);
+ Aerror(statp, "bind(dg)", errno, nsap, nsaplen);
res_nclose(statp);
return (0);
}
if (connect(statp->_u._ext.nssocks[ns], nsap, (socklen_t) nsaplen) < 0) {
- Aerror(statp, stderr, "connect(dg)", errno, nsap, nsaplen);
+ Aerror(statp, "connect(dg)", errno, nsap, nsaplen);
res_nclose(statp);
return (0);
}
#endif /* !CANNOT_CONNECT_DGRAM */
- Dprint(statp->options & RES_DEBUG, (stdout, ";; new DG socket\n"))
+ LOG(DEBUG) << ";; new DG socket";
}
s = statp->_u._ext.nssocks[ns];
#ifndef CANNOT_CONNECT_DGRAM
if (send(s, (const char*) buf, (size_t) buflen, 0) != buflen) {
- Perror(statp, stderr, "send", errno);
+ Perror(statp, "send", errno);
res_nclose(statp);
return (0);
}
#else /* !CANNOT_CONNECT_DGRAM */
if (sendto(s, (const char*) buf, buflen, 0, nsap, nsaplen) != buflen) {
- Aerror(statp, stderr, "sendto", errno, nsap, nsaplen);
+ Aerror(statp, "sendto", errno, nsap, nsaplen);
res_nclose(statp);
return (0);
}
@@ -1074,12 +1041,12 @@
if (n == 0) {
*rcode = RCODE_TIMEOUT;
- Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n"));
+ LOG(DEBUG) << ";; timeout";
*gotsomewhere = 1;
return (0);
}
if (n < 0) {
- Perror(statp, stderr, "poll", errno);
+ Perror(statp, "poll", errno);
res_nclose(statp);
return (0);
}
@@ -1088,7 +1055,7 @@
resplen = recvfrom(s, (char*) ans, (size_t) anssiz, 0, (struct sockaddr*) (void*) &from,
&fromlen);
if (resplen <= 0) {
- Perror(statp, stderr, "recvfrom", errno);
+ Perror(statp, "recvfrom", errno);
res_nclose(statp);
return (0);
}
@@ -1097,7 +1064,7 @@
/*
* Undersized message.
*/
- Dprint(statp->options & RES_DEBUG, (stdout, ";; undersized: %d\n", resplen));
+ LOG(DEBUG) << ";; undersized: " << resplen;
*terrno = EMSGSIZE;
res_nclose(statp);
return (0);
@@ -1108,8 +1075,8 @@
* XXX - potential security hazard could
* be detected here.
*/
- DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_REPLY),
- (stdout, ";; old answer:\n"), ans, (resplen > anssiz) ? anssiz : resplen);
+ LOG(DEBUG) << ";; old answer:";
+ res_pquery(statp, ans, (resplen > anssiz) ? anssiz : resplen);
goto retry;
}
if (!(statp->options & RES_INSECURE1) &&
@@ -1119,8 +1086,8 @@
* XXX - potential security hazard could
* be detected here.
*/
- DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_REPLY),
- (stdout, ";; not our server:\n"), ans, (resplen > anssiz) ? anssiz : resplen);
+ LOG(DEBUG) << ";; not our server:";
+ res_pquery(statp, ans, (resplen > anssiz) ? anssiz : resplen);
goto retry;
}
if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) {
@@ -1129,8 +1096,8 @@
* The case has to be captured here, as FORMERR packet do not
* carry query section, hence res_queriesmatch() returns 0.
*/
- DprintQ(statp->options & RES_DEBUG, (stdout, "server rejected query with EDNS0:\n"), ans,
- (resplen > anssiz) ? anssiz : resplen);
+ LOG(DEBUG) << "server rejected query with EDNS0:";
+ res_pquery(statp, ans, (resplen > anssiz) ? anssiz : resplen);
/* record the error */
statp->_flags |= RES_F_EDNS0ERR;
res_nclose(statp);
@@ -1143,16 +1110,16 @@
* XXX - potential security hazard could
* be detected here.
*/
- DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_REPLY),
- (stdout, ";; wrong query name:\n"), ans, (resplen > anssiz) ? anssiz : resplen);
+ LOG(DEBUG) << ";; wrong query name:";
+ res_pquery(statp, 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) {
- DprintQ(statp->options & RES_DEBUG, (stdout, "server rejected query:\n"), ans,
- (resplen > anssiz) ? anssiz : resplen);
+ LOG(DEBUG) << "server rejected query:";
+ res_pquery(statp, ans, (resplen > anssiz) ? anssiz : resplen);
res_nclose(statp);
/* don't retry if called from dig */
if (!statp->pfcode) {
@@ -1165,7 +1132,7 @@
* To get the rest of answer,
* use TCP with same server.
*/
- Dprint(statp->options & RES_DEBUG, (stdout, ";; truncated answer\n"));
+ LOG(DEBUG) << ";; truncated answer";
*v_circuit = 1;
res_nclose(statp);
return (1);
@@ -1180,10 +1147,8 @@
return (resplen);
}
-static void Aerror(const res_state statp, FILE* file, const char* string, int error,
+static void Aerror(const res_state statp, const char* string, int error,
const struct sockaddr* address, int alen) {
- if (!kVerboseLogging) return;
-
const int save = errno;
char hbuf[NI_MAXHOST];
char sbuf[NI_MAXSERV];
@@ -1197,17 +1162,16 @@
strncpy(sbuf, "?", sizeof(sbuf) - 1);
sbuf[sizeof(sbuf) - 1] = '\0';
}
- fprintf(file, "res_send: %s ([%s].%s): %s\n", string, hbuf, sbuf, strerror(error));
+ LOG(DEBUG) << "res_send: " << string << " ([" << hbuf << "]." << sbuf
+ << "): " << strerror(error);
}
errno = save;
}
-static void Perror(const res_state statp, FILE* file, const char* string, int error) {
- if (!kVerboseLogging) return;
-
+static void Perror(const res_state statp, const char* string, int error) {
const int save = errno;
if ((statp->options & RES_DEBUG) != 0U)
- fprintf(file, "res_send: %s: %s\n", string, strerror(error));
+ LOG(DEBUG) << "res_send: " << string << ": " << strerror(error);
errno = save;
}
@@ -1277,12 +1241,12 @@
}
}
- VLOG << __func__ << ": performing query over TLS";
+ LOG(INFO) << __func__ << ": performing query over TLS";
const auto response = sDnsTlsDispatcher.query(privateDnsStatus.validatedServers, mark, query,
answer, &resplen);
- VLOG << __func__ << ": TLS query result: " << static_cast<int>(response);
+ LOG(INFO) << __func__ << ": TLS query result: " << static_cast<int>(response);
if (privateDnsStatus.mode == PrivateDnsMode::OPPORTUNISTIC) {
// In opportunistic mode, handle falling back to cleartext in some
diff --git a/resolv/res_stats.cpp b/resolv/res_stats.cpp
index feba34f..5840ac6 100644
--- a/resolv/res_stats.cpp
+++ b/resolv/res_stats.cpp
@@ -13,8 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-constexpr bool kVerboseLogging = false;
#define LOG_TAG "res_stats"
#include <arpa/nameser.h>
@@ -25,13 +23,6 @@
#include "netd_resolv/stats.h"
-#define VLOG if (!kVerboseLogging) {} else LOG(INFO)
-
-#ifndef RESOLV_ALLOW_VERBOSE_LOGGING
-static_assert(kVerboseLogging == false,
- "Verbose logging floods logs at high-rate and exposes privacy-sensitive information. "
- "Do not enable in release builds.");
-#endif
// Calculate the round-trip-time from start time t0 and end time t1.
int _res_stats_calculate_rtt(const timespec* t1, const timespec* t0) {
@@ -43,7 +34,7 @@
// Create a sample for calculating server reachability statistics.
void _res_stats_set_sample(res_sample* sample, time_t now, int rcode, int rtt) {
- VLOG << __func__ << ": rcode = " << rcode << ", sec = " << rtt;
+ LOG(INFO) << __func__ << ": rcode = " << rcode << ", sec = " << rtt;
sample->at = now;
sample->rcode = rcode;
sample->rtt = rtt;
@@ -129,26 +120,22 @@
&rtt_avg, &last_sample_time);
if (successes >= 0 && errors >= 0 && timeouts >= 0) {
int total = successes + errors + timeouts;
- VLOG << "NS stats: S " << successes
- << " + E " << errors
- << " + T " << timeouts
- << " + I " << internal_errors
- << " = " << total
- << ", rtt = " << rtt_avg
- << ", min_samples = " << params->min_samples;
+ LOG(INFO) << "NS stats: S " << successes << " + E " << errors << " + T " << timeouts
+ << " + I " << internal_errors << " = " << total << ", rtt = " << rtt_avg
+ << ", min_samples = " << params->min_samples;
if (total >= params->min_samples && (errors > 0 || timeouts > 0)) {
int success_rate = successes * 100 / total;
- VLOG << "success rate " << success_rate;
+ LOG(INFO) << "success rate " << success_rate;
if (success_rate < params->success_threshold) {
time_t now = time(NULL);
if (now - last_sample_time > params->sample_validity) {
// Note: It might be worth considering to expire old servers after their expiry
// date has been reached, however the code for returning the ring buffer to its
// previous non-circular state would induce additional complexity.
- VLOG << "samples stale, retrying server";
+ LOG(INFO) << "samples stale, retrying server";
_res_stats_clear_samples(stats);
} else {
- VLOG << "too many resolution errors, ignoring server";
+ LOG(INFO) << "too many resolution errors, ignoring server";
return 0;
}
}
diff --git a/resolv/resolv_private.h b/resolv/resolv_private.h
index 852bb8d..79e8842 100644
--- a/resolv/resolv_private.h
+++ b/resolv/resolv_private.h
@@ -54,9 +54,11 @@
#ifndef NETD_RESOLV_PRIVATE_H
#define NETD_RESOLV_PRIVATE_H
+#include <android-base/logging.h>
#include <net/if.h>
#include <resolv.h>
#include <time.h>
+#include <string>
#include "netd_resolv/params.h"
#include "netd_resolv/resolv.h"
@@ -233,7 +235,8 @@
const char* p_section(int, int);
/* Things involving a resolver context. */
int res_ninit(res_state);
-void res_pquery(const res_state, const u_char*, int, FILE*);
+void res_pquery(const res_state, 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*);
int res_nquerydomain(res_state, const char*, const char*, int, int, u_char*, int, int*);
@@ -256,4 +259,7 @@
// Helper function for converting h_errno to the error codes visible to netd
int herrnoToAiErrno(int herrno);
+// switch resolver log severity
+android::base::LogSeverity logSeverityStrToEnum(const std::string& logSeverityStr);
+
#endif // NETD_RESOLV_PRIVATE_H