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

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

Issue 1163903002: Remove "Default Address Family" behavior from the HostResolver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjust comment on TestHostResolverImpl Created 5 years, 6 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
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 1826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 if (max_retry_attempts == HostResolver::kDefaultRetryAttempts) 1837 if (max_retry_attempts == HostResolver::kDefaultRetryAttempts)
1838 max_retry_attempts = kDefaultMaxRetryAttempts; 1838 max_retry_attempts = kDefaultMaxRetryAttempts;
1839 } 1839 }
1840 1840
1841 HostResolverImpl::ProcTaskParams::~ProcTaskParams() {} 1841 HostResolverImpl::ProcTaskParams::~ProcTaskParams() {}
1842 1842
1843 HostResolverImpl::HostResolverImpl(const Options& options, NetLog* net_log) 1843 HostResolverImpl::HostResolverImpl(const Options& options, NetLog* net_log)
1844 : max_queued_jobs_(0), 1844 : max_queued_jobs_(0),
1845 proc_params_(NULL, options.max_retry_attempts), 1845 proc_params_(NULL, options.max_retry_attempts),
1846 net_log_(net_log), 1846 net_log_(net_log),
1847 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED),
1848 received_dns_config_(false), 1847 received_dns_config_(false),
1849 num_dns_failures_(0), 1848 num_dns_failures_(0),
1850 probe_ipv6_support_(true),
1851 use_local_ipv6_(false), 1849 use_local_ipv6_(false),
1852 last_ipv6_probe_result_(true), 1850 last_ipv6_probe_result_(true),
1853 resolved_known_ipv6_hostname_(false), 1851 resolved_known_ipv6_hostname_(false),
1854 additional_resolver_flags_(0), 1852 additional_resolver_flags_(0),
1855 fallback_to_proctask_(true), 1853 fallback_to_proctask_(true),
1856 weak_ptr_factory_(this), 1854 weak_ptr_factory_(this),
1857 probe_weak_ptr_factory_(this) { 1855 probe_weak_ptr_factory_(this) {
1858 if (options.enable_caching) 1856 if (options.enable_caching)
1859 cache_ = HostCache::CreateDefaultCache(); 1857 cache_ = HostCache::CreateDefaultCache();
1860 1858
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 2023
2026 void HostResolverImpl::CancelRequest(RequestHandle req_handle) { 2024 void HostResolverImpl::CancelRequest(RequestHandle req_handle) {
2027 DCHECK(CalledOnValidThread()); 2025 DCHECK(CalledOnValidThread());
2028 Request* req = reinterpret_cast<Request*>(req_handle); 2026 Request* req = reinterpret_cast<Request*>(req_handle);
2029 DCHECK(req); 2027 DCHECK(req);
2030 Job* job = req->job(); 2028 Job* job = req->job();
2031 DCHECK(job); 2029 DCHECK(job);
2032 job->CancelRequest(req); 2030 job->CancelRequest(req);
2033 } 2031 }
2034 2032
2035 void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) {
2036 DCHECK(CalledOnValidThread());
2037 default_address_family_ = address_family;
2038 probe_ipv6_support_ = false;
2039 }
2040
2041 AddressFamily HostResolverImpl::GetDefaultAddressFamily() const {
2042 return default_address_family_;
2043 }
2044
2045 void HostResolverImpl::SetDnsClientEnabled(bool enabled) { 2033 void HostResolverImpl::SetDnsClientEnabled(bool enabled) {
2046 DCHECK(CalledOnValidThread()); 2034 DCHECK(CalledOnValidThread());
2047 #if defined(ENABLE_BUILT_IN_DNS) 2035 #if defined(ENABLE_BUILT_IN_DNS)
2048 if (enabled && !dns_client_) { 2036 if (enabled && !dns_client_) {
2049 SetDnsClient(DnsClient::CreateClient(net_log_)); 2037 SetDnsClient(DnsClient::CreateClient(net_log_));
2050 } else if (!enabled && dns_client_) { 2038 } else if (!enabled && dns_client_) {
2051 SetDnsClient(scoped_ptr<DnsClient>()); 2039 SetDnsClient(scoped_ptr<DnsClient>());
2052 } 2040 }
2053 #endif 2041 #endif
2054 } 2042 }
(...skipping 26 matching lines...) Expand all
2081 if (ip_number == nullptr) 2069 if (ip_number == nullptr)
2082 return false; 2070 return false;
2083 2071
2084 DCHECK_EQ(key.host_resolver_flags & 2072 DCHECK_EQ(key.host_resolver_flags &
2085 ~(HOST_RESOLVER_CANONNAME | HOST_RESOLVER_LOOPBACK_ONLY | 2073 ~(HOST_RESOLVER_CANONNAME | HOST_RESOLVER_LOOPBACK_ONLY |
2086 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6), 2074 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6),
2087 0) << " Unhandled flag"; 2075 0) << " Unhandled flag";
2088 2076
2089 *net_error = OK; 2077 *net_error = OK;
2090 AddressFamily family = GetAddressFamily(*ip_number); 2078 AddressFamily family = GetAddressFamily(*ip_number);
2091 if (family == ADDRESS_FAMILY_IPV6 && 2079 if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED &&
2092 !probe_ipv6_support_ && 2080 key.address_family != family) {
2093 default_address_family_ == ADDRESS_FAMILY_IPV4) {
2094 // Don't return IPv6 addresses if default address family is set to IPv4,
2095 // and probes are disabled.
2096 *net_error = ERR_NAME_NOT_RESOLVED;
2097 } else if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED &&
2098 key.address_family != family) {
2099 // Don't return IPv6 addresses for IPv4 queries, and vice versa. 2081 // Don't return IPv6 addresses for IPv4 queries, and vice versa.
2100 *net_error = ERR_NAME_NOT_RESOLVED; 2082 *net_error = ERR_NAME_NOT_RESOLVED;
2101 } else { 2083 } else {
2102 *addresses = AddressList::CreateFromIPAddress(*ip_number, info.port()); 2084 *addresses = AddressList::CreateFromIPAddress(*ip_number, info.port());
2103 if (key.host_resolver_flags & HOST_RESOLVER_CANONNAME) 2085 if (key.host_resolver_flags & HOST_RESOLVER_CANONNAME)
2104 addresses->SetDefaultCanonicalName(); 2086 addresses->SetDefaultCanonicalName();
2105 } 2087 }
2106 return true; 2088 return true;
2107 } 2089 }
2108 2090
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2201 2183
2202 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( 2184 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
2203 const RequestInfo& info, 2185 const RequestInfo& info,
2204 const IPAddressNumber* ip_number, 2186 const IPAddressNumber* ip_number,
2205 const BoundNetLog& net_log) { 2187 const BoundNetLog& net_log) {
2206 HostResolverFlags effective_flags = 2188 HostResolverFlags effective_flags =
2207 info.host_resolver_flags() | additional_resolver_flags_; 2189 info.host_resolver_flags() | additional_resolver_flags_;
2208 AddressFamily effective_address_family = info.address_family(); 2190 AddressFamily effective_address_family = info.address_family();
2209 2191
2210 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) { 2192 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) {
2211 if (probe_ipv6_support_ && !use_local_ipv6_ && 2193 if (!use_local_ipv6_ &&
2212 // When resolving IPv4 literals, there's no need to probe for IPv6. 2194 // When resolving IPv4 literals, there's no need to probe for IPv6.
2213 // When resolving IPv6 literals, there's no benefit to artificially 2195 // When resolving IPv6 literals, there's no benefit to artificially
2214 // limiting our resolution based on a probe. Prior logic ensures 2196 // limiting our resolution based on a probe. Prior logic ensures
2215 // that this query is UNSPECIFIED (see info.address_family() 2197 // that this query is UNSPECIFIED (see info.address_family()
2216 // check above) and that |default_address_family_| is UNSPECIFIED 2198 // check above) so the code requesting the resolution should be amenable
2217 // (|prove_ipv6_support_| is false if |default_address_family_| is 2199 // to receiving a IPv6 resolution.
2218 // set) so the code requesting the resolution should be amenable to
2219 // receiving a IPv6 resolution.
2220 ip_number == nullptr) { 2200 ip_number == nullptr) {
2221 if (!IsIPv6Reachable(net_log)) { 2201 if (!IsIPv6Reachable(net_log)) {
2222 effective_address_family = ADDRESS_FAMILY_IPV4; 2202 effective_address_family = ADDRESS_FAMILY_IPV4;
2223 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; 2203 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6;
2224 } 2204 }
2225 } else {
2226 effective_address_family = default_address_family_;
2227 } 2205 }
2228 } 2206 }
2229 2207
2230 std::string hostname = info.hostname(); 2208 std::string hostname = info.hostname();
2231 // Redirect .localhost queries to "localhost." to make sure that they 2209 // Redirect .localhost queries to "localhost." to make sure that they
2232 // are never sent out on the network, per RFC 6761. 2210 // are never sent out on the network, per RFC 6761.
2233 if (IsLocalhostTLD(info.hostname())) 2211 if (IsLocalhostTLD(info.hostname()))
2234 hostname = kLocalhost; 2212 hostname = kLocalhost;
2235 2213
2236 return Key(hostname, effective_address_family, effective_flags); 2214 return Key(hostname, effective_address_family, effective_flags);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2434 dns_client_->SetConfig(dns_config); 2412 dns_client_->SetConfig(dns_config);
2435 num_dns_failures_ = 0; 2413 num_dns_failures_ = 0;
2436 if (dns_client_->GetConfig()) 2414 if (dns_client_->GetConfig())
2437 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); 2415 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
2438 } 2416 }
2439 2417
2440 AbortDnsTasks(); 2418 AbortDnsTasks();
2441 } 2419 }
2442 2420
2443 } // namespace net 2421 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698