resolv: small improvements for debug logging
- use __func__ instead of the hand-written and often incorrect names
- fix a few cosmetic issues, such as those ugly ";;" prefixes
- add some logging around explore_fqdn and explore_numeric
- change the verbosity of a few messages
- replace compile-time DBG macro with verbosity checks in DnsProxyListener
- delete various unused functions in res_debug
- skip slow res_pquery() if log level is less than VERBOSE
TODO: convert the remaining ALOGx() lines to LOG(x). Leaving this for a
future patch.
Test: as follows:
adb shell setprop persist.sys.nw_dns_resolver_log DEBUG
atest reolv_integration_test
Change-Id: I7153f0c75d39d513fa006e0c1e5bf649d47ba154
diff --git a/res_debug.cpp b/res_debug.cpp
index cfd486d..55a919f 100644
--- a/res_debug.cpp
+++ b/res_debug.cpp
@@ -95,6 +95,8 @@
* IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
+#define LOG_TAG "res_debug"
+
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/types.h>
@@ -108,7 +110,6 @@
#include <errno.h>
#include <math.h>
#include <netdb.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
@@ -122,7 +123,8 @@
const char* humanname; /* Its fun name, like "mail exchanger" */
};
-/* add a formatted string to a bounded buffer */
+// add a formatted string to a bounded buffer
+// TODO: convert to std::string
static char* dbprint(char* p, char* end, const char* format, ...) {
int avail, n;
va_list args;
@@ -144,6 +146,7 @@
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;
@@ -258,8 +261,9 @@
* 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) {
+ if (!WOULD_LOG(VERBOSE)) return;
+
ns_msg handle;
int qdcount, ancount, nscount, arcount;
u_int opcode, rcode, id;
@@ -301,9 +305,7 @@
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))) {
- p = dbprint(p, end, " \n");
- }
+
LOG(VERBOSE) << temp;
/*
@@ -316,52 +318,6 @@
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) {
- char name[MAXDNAME];
- int n;
-
- if ((n = dn_expand(msg, msg + len, cp, name, (int) sizeof name)) < 0) return (NULL);
- if (name[0] == '\0')
- putc('.', file);
- else
- fputs(name, file);
- return (cp + n);
-}
-
-const u_char* p_cdname(const u_char* cp, const u_char* msg, FILE* file) {
- return (p_cdnname(cp, msg, PACKETSZ, file));
-}
-
-/* Return a fully-qualified domain name from a compressed name (with
- length supplied). */
-
-const u_char* p_fqnname(const u_char* cp, const u_char* msg, int msglen, char* name, int namelen) {
- int n;
- size_t newlen;
-
- if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0) return (NULL);
- newlen = strlen(name);
- if (newlen == 0 || name[newlen - 1] != '.') {
- if ((int) newlen + 1 >= namelen) /* Lack space for final dot */
- return (NULL);
- else
- strcpy(name + newlen, ".");
- }
- return (cp + n);
-}
-
-/* XXX: the rest of these functions need to become length-limited, too. */
-
-const u_char* p_fqname(const u_char* cp, const u_char* msg, FILE* file) {
- char name[MAXDNAME];
- const u_char* n;
-
- n = p_fqnname(cp, msg, MAXCDNAME, name, (int) sizeof name);
- if (n == NULL) return (NULL);
- fputs(name, file);
- return (n);
-}
-
/*
* Names of RR classes and qclasses. Classes and qclasses are the same, except
* that C_ANY is a qclass but not a class. (You can ask for records of class