Loading res_cache.cpp +23 −6 Original line number Diff line number Diff line Loading @@ -1786,18 +1786,35 @@ uint32_t resolv_cache_get_subsampling_denom(unsigned netid, int return_code) { return denom; } int resolv_cache_get_resolver_stats(unsigned netid, res_params* params, res_stats stats[MAXNS]) { int resolv_cache_get_resolver_stats(unsigned netid, res_params* params, res_stats stats[MAXNS], const std::vector<IPSockAddr>& serverSockAddrs) { std::lock_guard guard(cache_mutex); NetConfig* info = find_netconfig_locked(netid); if (info) { memcpy(stats, info->nsstats, sizeof(info->nsstats)); *params = info->params; return info->revision_id; } if (!info) return -1; for (size_t i = 0; i < serverSockAddrs.size(); i++) { for (size_t j = 0; j < info->nameserverSockAddrs.size(); j++) { // Should never happen. Just in case because of the fix-sized array |stats|. if (j >= MAXNS) { LOG(WARNING) << __func__ << ": unexpected size " << j; return -1; } // It's possible that the server is not found, e.g. when a new list of nameservers // is updated to the NetConfig just after this look up thread being populated. // Keep the server valid as-is (by means of keeping stats[i] unset), but we should // think about if there's a better way. if (info->nameserverSockAddrs[j] == serverSockAddrs[i]) { stats[i] = info->nsstats[j]; break; } } } *params = info->params; return info->revision_id; } void resolv_cache_add_resolver_stats_sample(unsigned netid, int revision_id, const IPSockAddr& serverSockAddr, const res_sample& sample, int max_samples) { Loading res_send.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -460,9 +460,9 @@ int res_nsend(res_state statp, const uint8_t* buf, int buflen, uint8_t* ans, int } } res_stats stats[MAXNS]; res_stats stats[MAXNS]{}; res_params params; int revision_id = resolv_cache_get_resolver_stats(statp->netid, ¶ms, stats); int revision_id = resolv_cache_get_resolver_stats(statp->netid, ¶ms, stats, statp->nsaddrs); if (revision_id < 0) { // TODO: Remove errno once callers stop using it errno = ESRCH; Loading resolv_private.h +4 −2 Original line number Diff line number Diff line Loading @@ -120,9 +120,11 @@ struct ResState { typedef ResState* res_state; /* Retrieve a local copy of the stats for the given netid. The buffer must have space for * MAXNS __resolver_stats. Returns the revision id of the resolvers used. * MAXNS res_stats. Returns the revision id of the resolvers used or -1 on failure. */ int resolv_cache_get_resolver_stats(unsigned netid, res_params* params, res_stats stats[MAXNS]); int resolv_cache_get_resolver_stats( unsigned netid, res_params* params, res_stats stats[MAXNS], const std::vector<android::netdutils::IPSockAddr>& serverSockAddrs); /* Add a sample to the shared struct for the given netid and server, provided that the * revision_id of the stored servers has not changed. Loading Loading
res_cache.cpp +23 −6 Original line number Diff line number Diff line Loading @@ -1786,18 +1786,35 @@ uint32_t resolv_cache_get_subsampling_denom(unsigned netid, int return_code) { return denom; } int resolv_cache_get_resolver_stats(unsigned netid, res_params* params, res_stats stats[MAXNS]) { int resolv_cache_get_resolver_stats(unsigned netid, res_params* params, res_stats stats[MAXNS], const std::vector<IPSockAddr>& serverSockAddrs) { std::lock_guard guard(cache_mutex); NetConfig* info = find_netconfig_locked(netid); if (info) { memcpy(stats, info->nsstats, sizeof(info->nsstats)); *params = info->params; return info->revision_id; } if (!info) return -1; for (size_t i = 0; i < serverSockAddrs.size(); i++) { for (size_t j = 0; j < info->nameserverSockAddrs.size(); j++) { // Should never happen. Just in case because of the fix-sized array |stats|. if (j >= MAXNS) { LOG(WARNING) << __func__ << ": unexpected size " << j; return -1; } // It's possible that the server is not found, e.g. when a new list of nameservers // is updated to the NetConfig just after this look up thread being populated. // Keep the server valid as-is (by means of keeping stats[i] unset), but we should // think about if there's a better way. if (info->nameserverSockAddrs[j] == serverSockAddrs[i]) { stats[i] = info->nsstats[j]; break; } } } *params = info->params; return info->revision_id; } void resolv_cache_add_resolver_stats_sample(unsigned netid, int revision_id, const IPSockAddr& serverSockAddr, const res_sample& sample, int max_samples) { Loading
res_send.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -460,9 +460,9 @@ int res_nsend(res_state statp, const uint8_t* buf, int buflen, uint8_t* ans, int } } res_stats stats[MAXNS]; res_stats stats[MAXNS]{}; res_params params; int revision_id = resolv_cache_get_resolver_stats(statp->netid, ¶ms, stats); int revision_id = resolv_cache_get_resolver_stats(statp->netid, ¶ms, stats, statp->nsaddrs); if (revision_id < 0) { // TODO: Remove errno once callers stop using it errno = ESRCH; Loading
resolv_private.h +4 −2 Original line number Diff line number Diff line Loading @@ -120,9 +120,11 @@ struct ResState { typedef ResState* res_state; /* Retrieve a local copy of the stats for the given netid. The buffer must have space for * MAXNS __resolver_stats. Returns the revision id of the resolvers used. * MAXNS res_stats. Returns the revision id of the resolvers used or -1 on failure. */ int resolv_cache_get_resolver_stats(unsigned netid, res_params* params, res_stats stats[MAXNS]); int resolv_cache_get_resolver_stats( unsigned netid, res_params* params, res_stats stats[MAXNS], const std::vector<android::netdutils::IPSockAddr>& serverSockAddrs); /* Add a sample to the shared struct for the given netid and server, provided that the * revision_id of the stored servers has not changed. Loading