diff options
| author | Mike Yu <yumike@google.com> | 2020-02-07 20:15:15 +0800 |
|---|---|---|
| committer | Mike Yu <yumike@google.com> | 2020-02-20 17:30:48 +0800 |
| commit | c573a3d76a3ace472353e6620a91a4b8b54cb0f8 (patch) | |
| tree | cf9cd2f2fb4a535d481550e4d2148b54e04434e3 /res_cache.cpp | |
| parent | e48f7b54a5028bb97f6b7db180de79c175be8ca2 (diff) | |
| download | platform_packages_modules_DnsResolver-c573a3d76a3ace472353e6620a91a4b8b54cb0f8.tar.gz platform_packages_modules_DnsResolver-c573a3d76a3ace472353e6620a91a4b8b54cb0f8.tar.bz2 platform_packages_modules_DnsResolver-c573a3d76a3ace472353e6620a91a4b8b54cb0f8.zip | |
Retrieve the res_stats based on a given list of nameserver addresses
Similar to aosp/1136436, each independent lookup thread should get
the stats based on its own nameserver address list rather than the
list stored in NetConfig.
With this change, plus aosp/1136436, it's able to populate nameserver
addresses in random order to lookup threads without the worry of
breaking the legacy stats stored in NetConfig.
Bug: 137169582
Test: cd packages/modules/DnsResolver && atest
Change-Id: I8d5c639326d2931bf7e5f5ae668e7aba830e00fb
Diffstat (limited to 'res_cache.cpp')
| -rw-r--r-- | res_cache.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/res_cache.cpp b/res_cache.cpp index 744a97d6..9942541c 100644 --- a/res_cache.cpp +++ b/res_cache.cpp @@ -1786,16 +1786,33 @@ 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; + } + } } - return -1; + *params = info->params; + return info->revision_id; } void resolv_cache_add_resolver_stats_sample(unsigned netid, int revision_id, |
