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

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

Issue 2709393007: Add back "default address family" to HostResolver (Closed)
Patch Set: comments Created 3 years, 9 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') | net/dns/host_resolver_impl_unittest.cc » ('j') | 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 1993 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 2004
2005 HostResolverImpl::HostResolverImpl( 2005 HostResolverImpl::HostResolverImpl(
2006 const Options& options, 2006 const Options& options,
2007 NetLog* net_log, 2007 NetLog* net_log,
2008 scoped_refptr<base::TaskRunner> worker_task_runner) 2008 scoped_refptr<base::TaskRunner> worker_task_runner)
2009 : max_queued_jobs_(0), 2009 : max_queued_jobs_(0),
2010 proc_params_(NULL, options.max_retry_attempts), 2010 proc_params_(NULL, options.max_retry_attempts),
2011 net_log_(net_log), 2011 net_log_(net_log),
2012 received_dns_config_(false), 2012 received_dns_config_(false),
2013 num_dns_failures_(0), 2013 num_dns_failures_(0),
2014 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED),
2014 use_local_ipv6_(false), 2015 use_local_ipv6_(false),
2015 last_ipv6_probe_result_(true), 2016 last_ipv6_probe_result_(true),
2016 resolved_known_ipv6_hostname_(false), 2017 resolved_known_ipv6_hostname_(false),
2017 additional_resolver_flags_(0), 2018 additional_resolver_flags_(0),
2018 fallback_to_proctask_(true), 2019 fallback_to_proctask_(true),
2019 worker_task_runner_(std::move(worker_task_runner)), 2020 worker_task_runner_(std::move(worker_task_runner)),
2020 persist_initialized_(false), 2021 persist_initialized_(false),
2021 weak_ptr_factory_(this), 2022 weak_ptr_factory_(this),
2022 probe_weak_ptr_factory_(this) { 2023 probe_weak_ptr_factory_(this) {
2023 if (options.enable_caching) 2024 if (options.enable_caching)
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2177 ip_address_ptr = &ip_address; 2178 ip_address_ptr = &ip_address;
2178 2179
2179 Key key = GetEffectiveKeyForRequest(info, ip_address_ptr, source_net_log); 2180 Key key = GetEffectiveKeyForRequest(info, ip_address_ptr, source_net_log);
2180 2181
2181 int rv = ResolveHelper(key, info, ip_address_ptr, addresses, true, stale_info, 2182 int rv = ResolveHelper(key, info, ip_address_ptr, addresses, true, stale_info,
2182 source_net_log); 2183 source_net_log);
2183 LogFinishRequest(source_net_log, info, rv); 2184 LogFinishRequest(source_net_log, info, rv);
2184 return rv; 2185 return rv;
2185 } 2186 }
2186 2187
2188 void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) {
2189 DCHECK(CalledOnValidThread());
2190 default_address_family_ = address_family;
2191 }
2192
2193 AddressFamily HostResolverImpl::GetDefaultAddressFamily() const {
2194 return default_address_family_;
2195 }
2196
2187 bool HostResolverImpl::ResolveAsIP(const Key& key, 2197 bool HostResolverImpl::ResolveAsIP(const Key& key,
2188 const RequestInfo& info, 2198 const RequestInfo& info,
2189 const IPAddress* ip_address, 2199 const IPAddress* ip_address,
2190 int* net_error, 2200 int* net_error,
2191 AddressList* addresses) { 2201 AddressList* addresses) {
2192 DCHECK(addresses); 2202 DCHECK(addresses);
2193 DCHECK(net_error); 2203 DCHECK(net_error);
2194 if (ip_address == nullptr) 2204 if (ip_address == nullptr)
2195 return false; 2205 return false;
2196 2206
2197 *net_error = OK; 2207 *net_error = OK;
2198 AddressFamily family = GetAddressFamily(*ip_address); 2208 AddressFamily family = GetAddressFamily(*ip_address);
2209 if (family == ADDRESS_FAMILY_IPV6 &&
2210 default_address_family_ == ADDRESS_FAMILY_IPV4) {
2211 // Don't return IPv6 addresses if default address family is set to IPv4.
2212 *net_error = ERR_NAME_NOT_RESOLVED;
2213 }
2199 if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED && 2214 if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED &&
2200 key.address_family != family) { 2215 key.address_family != family) {
2201 // Don't return IPv6 addresses for IPv4 queries, and vice versa. 2216 // Don't return IPv6 addresses for IPv4 queries, and vice versa.
2202 *net_error = ERR_NAME_NOT_RESOLVED; 2217 *net_error = ERR_NAME_NOT_RESOLVED;
2203 } else { 2218 } else {
2204 *addresses = AddressList::CreateFromIPAddress(*ip_address, info.port()); 2219 *addresses = AddressList::CreateFromIPAddress(*ip_address, info.port());
2205 if (key.host_resolver_flags & HOST_RESOLVER_CANONNAME) 2220 if (key.host_resolver_flags & HOST_RESOLVER_CANONNAME)
2206 addresses->SetDefaultCanonicalName(); 2221 addresses->SetDefaultCanonicalName();
2207 } 2222 }
2208 return true; 2223 return true;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2331 } 2346 }
2332 2347
2333 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( 2348 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
2334 const RequestInfo& info, 2349 const RequestInfo& info,
2335 const IPAddress* ip_address, 2350 const IPAddress* ip_address,
2336 const NetLogWithSource& net_log) { 2351 const NetLogWithSource& net_log) {
2337 HostResolverFlags effective_flags = 2352 HostResolverFlags effective_flags =
2338 info.host_resolver_flags() | additional_resolver_flags_; 2353 info.host_resolver_flags() | additional_resolver_flags_;
2339 AddressFamily effective_address_family = info.address_family(); 2354 AddressFamily effective_address_family = info.address_family();
2340 2355
2341 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) { 2356 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED)
2342 if (!use_local_ipv6_ && 2357 effective_address_family = default_address_family_;
2343 // When resolving IPv4 literals, there's no need to probe for IPv6. 2358
2344 // When resolving IPv6 literals, there's no benefit to artificially 2359 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED &&
2345 // limiting our resolution based on a probe. Prior logic ensures 2360 // When resolving IPv4 literals, there's no need to probe for IPv6.
2346 // that this query is UNSPECIFIED (see info.address_family() 2361 // When resolving IPv6 literals, there's no benefit to artificially
2347 // check above) so the code requesting the resolution should be amenable 2362 // limiting our resolution based on a probe. Prior logic ensures
2348 // to receiving a IPv6 resolution. 2363 // that this query is UNSPECIFIED (see effective_address_family
2349 ip_address == nullptr) { 2364 // check above) so the code requesting the resolution should be amenable
2350 if (!IsIPv6Reachable(net_log)) { 2365 // to receiving a IPv6 resolution.
2351 effective_address_family = ADDRESS_FAMILY_IPV4; 2366 !use_local_ipv6_ && ip_address == nullptr && !IsIPv6Reachable(net_log)) {
2352 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; 2367 effective_address_family = ADDRESS_FAMILY_IPV4;
2353 } 2368 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6;
2354 }
2355 } 2369 }
2356 2370
2357 return Key(info.hostname(), effective_address_family, effective_flags); 2371 return Key(info.hostname(), effective_address_family, effective_flags);
2358 } 2372 }
2359 2373
2360 bool HostResolverImpl::IsIPv6Reachable(const NetLogWithSource& net_log) { 2374 bool HostResolverImpl::IsIPv6Reachable(const NetLogWithSource& net_log) {
2361 // Cache the result for kIPv6ProbePeriodMs (measured from after 2375 // Cache the result for kIPv6ProbePeriodMs (measured from after
2362 // IsGloballyReachable() completes). 2376 // IsGloballyReachable() completes).
2363 bool cached = true; 2377 bool cached = true;
2364 if ((base::TimeTicks::Now() - last_ipv6_probe_time_).InMilliseconds() > 2378 if ((base::TimeTicks::Now() - last_ipv6_probe_time_).InMilliseconds() >
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
2634 if (job_) 2648 if (job_)
2635 job_->CancelRequest(this); 2649 job_->CancelRequest(this);
2636 } 2650 }
2637 2651
2638 void HostResolverImpl::RequestImpl::ChangeRequestPriority( 2652 void HostResolverImpl::RequestImpl::ChangeRequestPriority(
2639 RequestPriority priority) { 2653 RequestPriority priority) {
2640 job_->ChangeRequestPriority(this, priority); 2654 job_->ChangeRequestPriority(this, priority);
2641 } 2655 }
2642 2656
2643 } // namespace net 2657 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.h ('k') | net/dns/host_resolver_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698