Merge "Minor style fixes"
am: b57df648c5

Change-Id: Ie740017c2aa75eed901f612898262d541afe3786
diff --git a/DnsProxyListener.cpp b/DnsProxyListener.cpp
index 033465c..f684ff2 100644
--- a/DnsProxyListener.cpp
+++ b/DnsProxyListener.cpp
@@ -300,7 +300,14 @@
 }
 
 void initDnsEvent(NetworkDnsEventReported* event) {
-    // The value 0 has the special meaning of unset/unknown in Westworld atoms.
+    // The value 0 has the special meaning of unset/unknown in Westworld atoms. So, we set both
+    // flags to -1 as default value.
+    //  1. The hints flag is only used in resolv_getaddrinfo. When user set it to -1 in
+    //     resolv_getaddrinfo, the flag will cause validation (validateHints) failure in
+    //     getaddrinfo, so it will not do DNS query and will upload DNS stats log with
+    //     return_code = RC_EAI_BADFLAGS.
+    //  2. The res_nsend flags are only used in resolv_res_nsend. When user set it to -1 in
+    //     resolv_res_nsend,res_nsend will do nothing special by the setting.
     event->set_hints_ai_flags(-1);
     event->set_res_nsend_flags(-1);
 }
diff --git a/DnsTlsDispatcher.cpp b/DnsTlsDispatcher.cpp
index d1c4022..58ef2a7 100644
--- a/DnsTlsDispatcher.cpp
+++ b/DnsTlsDispatcher.cpp
@@ -97,11 +97,10 @@
     for (const auto& server : orderedServers) {
         DnsQueryEvent* dnsQueryEvent =
                 statp->event->mutable_dns_query_events()->add_dns_query_event();
-        dnsQueryEvent->set_rcode(NS_R_INTERNAL_ERROR);
-        Stopwatch query_stopwatch;
+        Stopwatch queryStopwatch;
         code = this->query(server, statp->_mark, query, ans, resplen);
 
-        dnsQueryEvent->set_latency_micros(saturate_cast<int32_t>(query_stopwatch.timeTakenUs()));
+        dnsQueryEvent->set_latency_micros(saturate_cast<int32_t>(queryStopwatch.timeTakenUs()));
         dnsQueryEvent->set_dns_server_index(serverCount++);
         dnsQueryEvent->set_ip_version(ipFamilyToIPVersion(server.ss.ss_family));
         dnsQueryEvent->set_protocol(PROTO_DOT);
@@ -113,16 +112,18 @@
             case DnsTlsTransport::Response::success:
                 dnsQueryEvent->set_rcode(
                         static_cast<NsRcode>(reinterpret_cast<HEADER*>(ans.base())->rcode));
-                [[fallthrough]];
+                return code;
             case DnsTlsTransport::Response::limit_error:
+                dnsQueryEvent->set_rcode(NS_R_INTERNAL_ERROR);
                 return code;
             // These response codes might differ when trying other servers, so
             // keep iterating to see if we can get a different (better) result.
             case DnsTlsTransport::Response::network_error:
                 // Sync from res_tls_send in res_send.cpp
                 dnsQueryEvent->set_rcode(NS_R_TIMEOUT);
-                [[fallthrough]];
+                continue;
             case DnsTlsTransport::Response::internal_error:
+                dnsQueryEvent->set_rcode(NS_R_INTERNAL_ERROR);
                 continue;
             // No "default" statement.
         }
diff --git a/res_send.cpp b/res_send.cpp
index 17f71ed..85e8a58 100644
--- a/res_send.cpp
+++ b/res_send.cpp
@@ -416,9 +416,9 @@
     terrno = ETIMEDOUT;
 
     int anslen = 0;
-    Stopwatch cache_stopwatch;
+    Stopwatch cacheStopwatch;
     cache_status = resolv_cache_lookup(statp->netid, buf, buflen, ans, anssiz, &anslen, flags);
-    const int32_t cacheLatencyUs = saturate_cast<int32_t>(cache_stopwatch.timeTakenUs());
+    const int32_t cacheLatencyUs = saturate_cast<int32_t>(cacheStopwatch.timeTakenUs());
     if (cache_status == RESOLV_CACHE_FOUND) {
         HEADER* hp = (HEADER*)(void*)ans;
         *rcode = hp->rcode;
@@ -560,7 +560,7 @@
                 LOG(DEBUG) << __func__ << ": Querying server (# " << ns + 1
                            << ") address = " << abuf;
 
-            Stopwatch query_stopwatch;
+            Stopwatch queryStopwatch;
             if (v_circuit) {
                 /* Use VC; at most one attempt per server. */
                 bool shouldRecordStats = (attempt == 0);
@@ -570,7 +570,7 @@
                             &delay);
 
                 dnsQueryEvent->set_latency_micros(
-                        saturate_cast<int32_t>(query_stopwatch.timeTakenUs()));
+                        saturate_cast<int32_t>(queryStopwatch.timeTakenUs()));
                 dnsQueryEvent->set_dns_server_index(ns);
                 dnsQueryEvent->set_ip_version(ipFamilyToIPVersion(nsap->sa_family));
                 dnsQueryEvent->set_retry_times(attempt);
@@ -607,7 +607,7 @@
                             &gotsomewhere, &now, rcode, &delay);
 
                 dnsQueryEvent->set_latency_micros(
-                        saturate_cast<int32_t>(query_stopwatch.timeTakenUs()));
+                        saturate_cast<int32_t>(queryStopwatch.timeTakenUs()));
                 dnsQueryEvent->set_dns_server_index(ns);
                 dnsQueryEvent->set_ip_version(ipFamilyToIPVersion(nsap->sa_family));
                 dnsQueryEvent->set_retry_times(attempt);