Loading res_send.cpp +4 −6 Original line number Original line Diff line number Diff line Loading @@ -580,11 +580,8 @@ int res_nsend(ResState* statp, span<const uint8_t> msg, span<uint8_t> ans, int* if (!usable_servers[ns]) continue; if (!usable_servers[ns]) continue; *rcode = RCODE_INTERNAL_ERROR; *rcode = RCODE_INTERNAL_ERROR; // Get server addr const IPSockAddr& serverSockAddr = statp->nsaddrs[ns]; LOG(DEBUG) << __func__ << ": Querying server (# " << ns + 1 LOG(DEBUG) << __func__ << ": Querying server (# " << ns + 1 << ") address = " << serverSockAddr.toString(); << ") address = " << statp->nsaddrs[ns].toString(); ::android::net::Protocol query_proto = useTcp ? PROTO_TCP : PROTO_UDP; ::android::net::Protocol query_proto = useTcp ? PROTO_TCP : PROTO_UDP; time_t query_time = 0; time_t query_time = 0; Loading Loading @@ -650,8 +647,9 @@ int res_nsend(ResState* statp, span<const uint8_t> msg, span<uint8_t> ans, int* // KeepListening UDP mechanism is incompatible with usable_servers of legacy // KeepListening UDP mechanism is incompatible with usable_servers of legacy // stats, so keep the old logic for now. // stats, so keep the old logic for now. // TODO: Replace usable_servers of legacy stats with new one. // TODO: Replace usable_servers of legacy stats with new one. resolv_cache_add_resolver_stats_sample( resolv_cache_add_resolver_stats_sample(statp->netid, revision_id, statp->netid, revision_id, serverSockAddr, sample, params.max_samples); receivedServerAddr, sample, params.max_samples); resolv_stats_add(statp->netid, receivedServerAddr, dnsQueryEvent); resolv_stats_add(statp->netid, receivedServerAddr, dnsQueryEvent); } } } } Loading tests/resolv_integration_test.cpp +15 −3 Original line number Original line Diff line number Diff line Loading @@ -6122,9 +6122,15 @@ TEST_F(ResolverTest, KeepListeningUDP) { const struct TestConfig { const struct TestConfig { int retryCount; int retryCount; int delayTimeMs; int delayTimeMs; int expectedDns1Successes; int expectedDns1Timeouts; int expectedDns2Timeouts; } testConfigs[]{ } testConfigs[]{ {1, 1500}, {1, 1500, 1, 1, 0}, {2, 3500}, // Actually, there will be two timeouts and one success for DNS1. However, the // DnsResolver doesn't record the stats during the second iteration of DNS servers, so // the success and timeout of DNS1 is 0 and 1, respectively. {2, 3500, 0, 1, 1}, }; }; for (const std::string_view callType : {"getaddrinfo", "resnsend"}) { for (const std::string_view callType : {"getaddrinfo", "resnsend"}) { for (const auto& cfg : testConfigs) { for (const auto& cfg : testConfigs) { Loading @@ -6151,7 +6157,13 @@ TEST_F(ResolverTest, KeepListeningUDP) { int fd = resNetworkQuery(TEST_NETID, host_name, ns_c_in, ns_t_aaaa, 0); int fd = resNetworkQuery(TEST_NETID, host_name, ns_c_in, ns_t_aaaa, 0); expectAnswersValid(fd, AF_INET6, "::1.2.3.4"); expectAnswersValid(fd, AF_INET6, "::1.2.3.4"); } } // TODO(b/271405311): check that the DNS stats from getResolverInfo() is correct. const std::vector<NameserverStats> expectedCleartextDnsStats = { NameserverStats(listen_addr1) .setSuccesses(cfg.expectedDns1Successes) .setTimeouts(cfg.expectedDns1Timeouts), NameserverStats(listen_addr2).setTimeouts(cfg.expectedDns2Timeouts), }; EXPECT_TRUE(expectStatsEqualTo(expectedCleartextDnsStats)); thread.join(); thread.join(); } } } } Loading Loading
res_send.cpp +4 −6 Original line number Original line Diff line number Diff line Loading @@ -580,11 +580,8 @@ int res_nsend(ResState* statp, span<const uint8_t> msg, span<uint8_t> ans, int* if (!usable_servers[ns]) continue; if (!usable_servers[ns]) continue; *rcode = RCODE_INTERNAL_ERROR; *rcode = RCODE_INTERNAL_ERROR; // Get server addr const IPSockAddr& serverSockAddr = statp->nsaddrs[ns]; LOG(DEBUG) << __func__ << ": Querying server (# " << ns + 1 LOG(DEBUG) << __func__ << ": Querying server (# " << ns + 1 << ") address = " << serverSockAddr.toString(); << ") address = " << statp->nsaddrs[ns].toString(); ::android::net::Protocol query_proto = useTcp ? PROTO_TCP : PROTO_UDP; ::android::net::Protocol query_proto = useTcp ? PROTO_TCP : PROTO_UDP; time_t query_time = 0; time_t query_time = 0; Loading Loading @@ -650,8 +647,9 @@ int res_nsend(ResState* statp, span<const uint8_t> msg, span<uint8_t> ans, int* // KeepListening UDP mechanism is incompatible with usable_servers of legacy // KeepListening UDP mechanism is incompatible with usable_servers of legacy // stats, so keep the old logic for now. // stats, so keep the old logic for now. // TODO: Replace usable_servers of legacy stats with new one. // TODO: Replace usable_servers of legacy stats with new one. resolv_cache_add_resolver_stats_sample( resolv_cache_add_resolver_stats_sample(statp->netid, revision_id, statp->netid, revision_id, serverSockAddr, sample, params.max_samples); receivedServerAddr, sample, params.max_samples); resolv_stats_add(statp->netid, receivedServerAddr, dnsQueryEvent); resolv_stats_add(statp->netid, receivedServerAddr, dnsQueryEvent); } } } } Loading
tests/resolv_integration_test.cpp +15 −3 Original line number Original line Diff line number Diff line Loading @@ -6122,9 +6122,15 @@ TEST_F(ResolverTest, KeepListeningUDP) { const struct TestConfig { const struct TestConfig { int retryCount; int retryCount; int delayTimeMs; int delayTimeMs; int expectedDns1Successes; int expectedDns1Timeouts; int expectedDns2Timeouts; } testConfigs[]{ } testConfigs[]{ {1, 1500}, {1, 1500, 1, 1, 0}, {2, 3500}, // Actually, there will be two timeouts and one success for DNS1. However, the // DnsResolver doesn't record the stats during the second iteration of DNS servers, so // the success and timeout of DNS1 is 0 and 1, respectively. {2, 3500, 0, 1, 1}, }; }; for (const std::string_view callType : {"getaddrinfo", "resnsend"}) { for (const std::string_view callType : {"getaddrinfo", "resnsend"}) { for (const auto& cfg : testConfigs) { for (const auto& cfg : testConfigs) { Loading @@ -6151,7 +6157,13 @@ TEST_F(ResolverTest, KeepListeningUDP) { int fd = resNetworkQuery(TEST_NETID, host_name, ns_c_in, ns_t_aaaa, 0); int fd = resNetworkQuery(TEST_NETID, host_name, ns_c_in, ns_t_aaaa, 0); expectAnswersValid(fd, AF_INET6, "::1.2.3.4"); expectAnswersValid(fd, AF_INET6, "::1.2.3.4"); } } // TODO(b/271405311): check that the DNS stats from getResolverInfo() is correct. const std::vector<NameserverStats> expectedCleartextDnsStats = { NameserverStats(listen_addr1) .setSuccesses(cfg.expectedDns1Successes) .setTimeouts(cfg.expectedDns1Timeouts), NameserverStats(listen_addr2).setTimeouts(cfg.expectedDns2Timeouts), }; EXPECT_TRUE(expectStatsEqualTo(expectedCleartextDnsStats)); thread.join(); thread.join(); } } } } Loading