Delete dump_bytes() and its helper functions
This change removes dump_bytes() as well as bprint_* functions
which are used for debugging purpose. Instead, use netdutils Slice
for hex dump since it's simpler and safer.
Log example from res_pquery():
V resolv : ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37806
V resolv : ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
V resolv : ;; QUERY SECTION:
V resolv : ;; google.com, type = A, class = IN
V resolv :
V resolv : ;; ANSWER SECTION:
V resolv : ;; google.com. 4m59s IN A X.X.X.X
V resolv :
V resolv :
V resolv : ;; ADDITIONAL SECTION:
V resolv : ; EDNS: version: 0, udp=512, flags=8000
V resolv :
V resolv : Hex dump:
V resolv : 93ae8180000100010000000106676f6f676c6503636f6d0000010001c00c0001
V resolv : 00010000012b0004acd9a06e0000290200000080000000
For debugging, we can use scapy to parse the hex dump:
pkt = "93ae8180000100010000000106676f6f676c6503636f6d0000010001c00c000100010000012b0004acd9a06e0000290200000080000000"
DNS(pkt.decode("hex")).show2()
Bug: 130686826
Bug: 139332724
Test: adb shell service call dnsresolver 10 i32 0 &&
atest --include-subdirs packages/modules/DnsResolver
Test: debugging logs were printed correctly
Test: No PII logs are revealed in default log severity
Change-Id: Ia298ff3e4ce5c9ff42a1a84cf3e34a7bda818519
diff --git a/res_debug.cpp b/res_debug.cpp
index 9d01cc5..f249456 100644
--- a/res_debug.cpp
+++ b/res_debug.cpp
@@ -97,9 +97,10 @@
#define LOG_TAG "resolv"
+#include "res_debug.h"
+
#include <sys/param.h>
#include <sys/socket.h>
-#include <sys/types.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
@@ -112,6 +113,7 @@
#include <errno.h>
#include <math.h>
#include <netdb.h>
+#include <netdutils/Slice.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
@@ -128,6 +130,7 @@
#endif
using android::base::StringAppendF;
+using android::netdutils::Slice;
struct res_sym {
int number; /* Identifying number, like T_MX */
@@ -150,6 +153,10 @@
LOG(VERBOSE) << s;
return;
}
+ if (rrnum == 0) {
+ int opcode = ns_msg_getflag(*handle, ns_f_opcode);
+ StringAppendF(&s, ";; %s SECTION:\n", p_section(section, opcode));
+ }
if (section == ns_s_qd)
StringAppendF(&s, ";;\t%s, type = %s, class = %s\n", ns_rr_name(rr),
p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr)));
@@ -277,6 +284,9 @@
do_section(&handle, ns_s_an);
do_section(&handle, ns_s_ns);
do_section(&handle, ns_s_ar);
+
+ LOG(VERBOSE) << "Hex dump:";
+ LOG(VERBOSE) << android::netdutils::toHex(Slice(const_cast<uint8_t*>(msg), len), 32);
}
/*