Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: net/dns/host_resolver_impl.cc

Issue 1138833003: Reduce frequency of IPv6 probes in HostResolverImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/dns/host_resolver_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/dns/host_resolver_impl.h" 5 #include "net/dns/host_resolver_impl.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <Winsock2.h> 8 #include <Winsock2.h>
9 #elif defined(OS_POSIX) 9 #elif defined(OS_POSIX)
10 #include <netdb.h> 10 #include <netdb.h>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const unsigned kCacheEntryTTLSeconds = 60; 67 const unsigned kCacheEntryTTLSeconds = 60;
68 68
69 // Default TTL for unsuccessful resolutions with ProcTask. 69 // Default TTL for unsuccessful resolutions with ProcTask.
70 const unsigned kNegativeCacheEntryTTLSeconds = 0; 70 const unsigned kNegativeCacheEntryTTLSeconds = 0;
71 71
72 // Minimum TTL for successful resolutions with DnsTask. 72 // Minimum TTL for successful resolutions with DnsTask.
73 const unsigned kMinimumTTLSeconds = kCacheEntryTTLSeconds; 73 const unsigned kMinimumTTLSeconds = kCacheEntryTTLSeconds;
74 74
75 const char kLocalhost[] = "localhost."; 75 const char kLocalhost[] = "localhost.";
76 76
77 // Time between IPv6 probes, i.e. for how long results of each IPv6 probe are
78 // cached.
79 const int kIpv6ProbePeriodMs = 1000;
80
77 // We use a separate histogram name for each platform to facilitate the 81 // We use a separate histogram name for each platform to facilitate the
78 // display of error codes by their symbolic name (since each platform has 82 // display of error codes by their symbolic name (since each platform has
79 // different mappings). 83 // different mappings).
80 const char kOSErrorsForGetAddrinfoHistogramName[] = 84 const char kOSErrorsForGetAddrinfoHistogramName[] =
81 #if defined(OS_WIN) 85 #if defined(OS_WIN)
82 "Net.OSErrorsForGetAddrinfo_Win"; 86 "Net.OSErrorsForGetAddrinfo_Win";
83 #elif defined(OS_MACOSX) 87 #elif defined(OS_MACOSX)
84 "Net.OSErrorsForGetAddrinfo_Mac"; 88 "Net.OSErrorsForGetAddrinfo_Mac";
85 #elif defined(OS_LINUX) 89 #elif defined(OS_LINUX)
86 "Net.OSErrorsForGetAddrinfo_Linux"; 90 "Net.OSErrorsForGetAddrinfo_Linux";
(...skipping 1721 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 1812
1809 HostResolverImpl::HostResolverImpl(const Options& options, NetLog* net_log) 1813 HostResolverImpl::HostResolverImpl(const Options& options, NetLog* net_log)
1810 : max_queued_jobs_(0), 1814 : max_queued_jobs_(0),
1811 proc_params_(NULL, options.max_retry_attempts), 1815 proc_params_(NULL, options.max_retry_attempts),
1812 net_log_(net_log), 1816 net_log_(net_log),
1813 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), 1817 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED),
1814 received_dns_config_(false), 1818 received_dns_config_(false),
1815 num_dns_failures_(0), 1819 num_dns_failures_(0),
1816 probe_ipv6_support_(true), 1820 probe_ipv6_support_(true),
1817 use_local_ipv6_(false), 1821 use_local_ipv6_(false),
1822 last_ipv6_probe_result_(false),
1818 resolved_known_ipv6_hostname_(false), 1823 resolved_known_ipv6_hostname_(false),
1819 additional_resolver_flags_(0), 1824 additional_resolver_flags_(0),
1820 fallback_to_proctask_(true), 1825 fallback_to_proctask_(true),
1821 weak_ptr_factory_(this), 1826 weak_ptr_factory_(this),
1822 probe_weak_ptr_factory_(this) { 1827 probe_weak_ptr_factory_(this) {
1823 if (options.enable_caching) 1828 if (options.enable_caching)
1824 cache_ = HostCache::CreateDefaultCache(); 1829 cache_ = HostCache::CreateDefaultCache();
1825 1830
1826 PrioritizedDispatcher::Limits job_limits = options.GetDispatcherLimits(); 1831 PrioritizedDispatcher::Limits job_limits = options.GetDispatcherLimits();
1827 dispatcher_.reset(new PrioritizedDispatcher(job_limits)); 1832 dispatcher_.reset(new PrioritizedDispatcher(job_limits));
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
2160 if (result) { 2165 if (result) {
2161 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; 2166 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY;
2162 } else { 2167 } else {
2163 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; 2168 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY;
2164 } 2169 }
2165 } 2170 }
2166 2171
2167 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( 2172 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
2168 const RequestInfo& info, 2173 const RequestInfo& info,
2169 const IPAddressNumber* ip_number, 2174 const IPAddressNumber* ip_number,
2170 const BoundNetLog& net_log) const { 2175 const BoundNetLog& net_log) {
2171 HostResolverFlags effective_flags = 2176 HostResolverFlags effective_flags =
2172 info.host_resolver_flags() | additional_resolver_flags_; 2177 info.host_resolver_flags() | additional_resolver_flags_;
2173 AddressFamily effective_address_family = info.address_family(); 2178 AddressFamily effective_address_family = info.address_family();
2174 2179
2175 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) { 2180 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) {
2176 if (probe_ipv6_support_ && !use_local_ipv6_ && 2181 if (probe_ipv6_support_ && !use_local_ipv6_ &&
2177 // When resolving IPv4 literals, there's no need to probe for IPv6. 2182 // When resolving IPv4 literals, there's no need to probe for IPv6.
2178 // When resolving IPv6 literals, there's no benefit to artificially 2183 // When resolving IPv6 literals, there's no benefit to artificially
2179 // limiting our resolution based on a probe. Prior logic ensures 2184 // limiting our resolution based on a probe. Prior logic ensures
2180 // that this query is UNSPECIFIED (see info.address_family() 2185 // that this query is UNSPECIFIED (see info.address_family()
2181 // check above) and that |default_address_family_| is UNSPECIFIED 2186 // check above) and that |default_address_family_| is UNSPECIFIED
2182 // (|prove_ipv6_support_| is false if |default_address_family_| is 2187 // (|prove_ipv6_support_| is false if |default_address_family_| is
2183 // set) so the code requesting the resolution should be amenable to 2188 // set) so the code requesting the resolution should be amenable to
2184 // receiving a IPv6 resolution. 2189 // receiving a IPv6 resolution.
2185 ip_number == nullptr) { 2190 ip_number == nullptr) {
2186 // Google DNS address. 2191 bool ipv6_available = ProbeIpv6SupportCached(net_log);
2187 const uint8 kIPv6Address[] = 2192 if (!ipv6_available) {
2188 { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00,
2189 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 };
2190 IPAddressNumber address(kIPv6Address,
2191 kIPv6Address + arraysize(kIPv6Address));
2192 bool rv6 = IsGloballyReachable(address, net_log);
2193 net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_IPV6_REACHABILITY_CHECK,
2194 NetLog::BoolCallback("ipv6_available", rv6));
2195 if (!rv6) {
2196 effective_address_family = ADDRESS_FAMILY_IPV4; 2193 effective_address_family = ADDRESS_FAMILY_IPV4;
2197 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; 2194 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6;
2198 } 2195 }
2196 net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_IPV6_REACHABILITY_CHECK,
2197 NetLog::BoolCallback("ipv6_available", ipv6_available));
mmenke 2015/05/12 14:39:59 Think this makes more sense in ProbeIpv6SupportCac
Sergey Ulanov 2015/05/12 19:22:24 Done.
2199 } else { 2198 } else {
2200 effective_address_family = default_address_family_; 2199 effective_address_family = default_address_family_;
2201 } 2200 }
2202 } 2201 }
2203 2202
2204 std::string hostname = info.hostname(); 2203 std::string hostname = info.hostname();
2205 // Redirect .localhost queries to "localhost." to make sure that they 2204 // Redirect .localhost queries to "localhost." to make sure that they
2206 // are never sent out on the network, per RFC 6761. 2205 // are never sent out on the network, per RFC 6761.
2207 if (IsLocalhostTLD(info.hostname())) 2206 if (IsLocalhostTLD(info.hostname()))
2208 hostname = kLocalhost; 2207 hostname = kLocalhost;
2209 2208
2210 return Key(hostname, effective_address_family, effective_flags); 2209 return Key(hostname, effective_address_family, effective_flags);
2211 } 2210 }
2212 2211
2212 bool HostResolverImpl::ProbeIpv6SupportCached(const BoundNetLog& net_log) {
mmenke 2015/05/12 14:39:59 Think this method name is a little weird. Maybe I
Sergey Ulanov 2015/05/12 19:22:24 Done. Thanks for suggesting a better name!
2213 base::TimeTicks now = base::TimeTicks::Now();
2214
2215 if ((now - last_ipv6_probe_time_).InMilliseconds() > kIpv6ProbePeriodMs) {
2216 // Google DNS address.
2217 IPAddressNumber address =
2218 { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00,
2219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 };
2220 last_ipv6_probe_result_ = IsGloballyReachable(address, net_log);
2221 last_ipv6_probe_time_ = now;
2222 }
2223 return last_ipv6_probe_result_;
2224 }
2225
2213 void HostResolverImpl::AbortAllInProgressJobs() { 2226 void HostResolverImpl::AbortAllInProgressJobs() {
2214 // In Abort, a Request callback could spawn new Jobs with matching keys, so 2227 // In Abort, a Request callback could spawn new Jobs with matching keys, so
2215 // first collect and remove all running jobs from |jobs_|. 2228 // first collect and remove all running jobs from |jobs_|.
2216 ScopedVector<Job> jobs_to_abort; 2229 ScopedVector<Job> jobs_to_abort;
2217 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ) { 2230 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ) {
2218 Job* job = it->second; 2231 Job* job = it->second;
2219 if (job->is_running()) { 2232 if (job->is_running()) {
2220 jobs_to_abort.push_back(job); 2233 jobs_to_abort.push_back(job);
2221 jobs_.erase(it++); 2234 jobs_.erase(it++);
2222 } else { 2235 } else {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 for (JobMap::iterator it = jobs_.begin(); self.get() && it != jobs_.end();) { 2285 for (JobMap::iterator it = jobs_.begin(); self.get() && it != jobs_.end();) {
2273 Job* job = it->second; 2286 Job* job = it->second;
2274 ++it; 2287 ++it;
2275 // This could remove |job| from |jobs_|, but iterator will remain valid. 2288 // This could remove |job| from |jobs_|, but iterator will remain valid.
2276 job->ServeFromHosts(); 2289 job->ServeFromHosts();
2277 } 2290 }
2278 } 2291 }
2279 2292
2280 void HostResolverImpl::OnIPAddressChanged() { 2293 void HostResolverImpl::OnIPAddressChanged() {
2281 resolved_known_ipv6_hostname_ = false; 2294 resolved_known_ipv6_hostname_ = false;
2295 last_ipv6_probe_time_ = base::TimeTicks();
2282 // Abandon all ProbeJobs. 2296 // Abandon all ProbeJobs.
2283 probe_weak_ptr_factory_.InvalidateWeakPtrs(); 2297 probe_weak_ptr_factory_.InvalidateWeakPtrs();
2284 if (cache_.get()) 2298 if (cache_.get())
2285 cache_->clear(); 2299 cache_->clear();
2286 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 2300 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
2287 new LoopbackProbeJob(probe_weak_ptr_factory_.GetWeakPtr()); 2301 new LoopbackProbeJob(probe_weak_ptr_factory_.GetWeakPtr());
2288 #endif 2302 #endif
2289 AbortAllInProgressJobs(); 2303 AbortAllInProgressJobs();
2290 // |this| may be deleted inside AbortAllInProgressJobs(). 2304 // |this| may be deleted inside AbortAllInProgressJobs().
2291 } 2305 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2392 dns_client_->SetConfig(dns_config); 2406 dns_client_->SetConfig(dns_config);
2393 num_dns_failures_ = 0; 2407 num_dns_failures_ = 0;
2394 if (dns_client_->GetConfig()) 2408 if (dns_client_->GetConfig())
2395 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); 2409 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
2396 } 2410 }
2397 2411
2398 AbortDnsTasks(); 2412 AbortDnsTasks();
2399 } 2413 }
2400 2414
2401 } // namespace net 2415 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698