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

Unified Diff: net/dns/host_resolver_impl.cc

Issue 2709393007: Add back "default address family" to HostResolver (Closed)
Patch Set: comments Created 3 years, 10 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/host_resolver_impl.cc
diff --git a/net/dns/host_resolver_impl.cc b/net/dns/host_resolver_impl.cc
index dfd47524a7b5445a24235160c62db09ac78fc204..7596c7762690cce0bfa3250f0f84b4a69aebf64f 100644
--- a/net/dns/host_resolver_impl.cc
+++ b/net/dns/host_resolver_impl.cc
@@ -2011,6 +2011,7 @@ HostResolverImpl::HostResolverImpl(
net_log_(net_log),
received_dns_config_(false),
num_dns_failures_(0),
+ default_address_family_(ADDRESS_FAMILY_UNSPECIFIED),
use_local_ipv6_(false),
last_ipv6_probe_result_(true),
resolved_known_ipv6_hostname_(false),
@@ -2184,6 +2185,15 @@ int HostResolverImpl::ResolveStaleFromCache(
return rv;
}
+void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) {
+ DCHECK(CalledOnValidThread());
+ default_address_family_ = address_family;
+}
+
+AddressFamily HostResolverImpl::GetDefaultAddressFamily() const {
+ return default_address_family_;
+}
+
bool HostResolverImpl::ResolveAsIP(const Key& key,
const RequestInfo& info,
const IPAddress* ip_address,
@@ -2196,6 +2206,11 @@ bool HostResolverImpl::ResolveAsIP(const Key& key,
*net_error = OK;
AddressFamily family = GetAddressFamily(*ip_address);
+ if (family == ADDRESS_FAMILY_IPV6 &&
+ default_address_family_ == ADDRESS_FAMILY_IPV4) {
+ // Don't return IPv6 addresses if default address family is set to IPv4.
+ *net_error = ERR_NAME_NOT_RESOLVED;
+ }
if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED &&
key.address_family != family) {
// Don't return IPv6 addresses for IPv4 queries, and vice versa.
@@ -2338,20 +2353,19 @@ HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
info.host_resolver_flags() | additional_resolver_flags_;
AddressFamily effective_address_family = info.address_family();
- if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) {
- if (!use_local_ipv6_ &&
- // When resolving IPv4 literals, there's no need to probe for IPv6.
- // When resolving IPv6 literals, there's no benefit to artificially
- // limiting our resolution based on a probe. Prior logic ensures
- // that this query is UNSPECIFIED (see info.address_family()
- // check above) so the code requesting the resolution should be amenable
- // to receiving a IPv6 resolution.
- ip_address == nullptr) {
- if (!IsIPv6Reachable(net_log)) {
- effective_address_family = ADDRESS_FAMILY_IPV4;
- effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6;
- }
- }
+ if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED)
+ effective_address_family = default_address_family_;
+
+ if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED &&
+ // When resolving IPv4 literals, there's no need to probe for IPv6.
+ // When resolving IPv6 literals, there's no benefit to artificially
+ // limiting our resolution based on a probe. Prior logic ensures
+ // that this query is UNSPECIFIED (see effective_address_family
+ // check above) so the code requesting the resolution should be amenable
+ // to receiving a IPv6 resolution.
+ !use_local_ipv6_ && ip_address == nullptr && !IsIPv6Reachable(net_log)) {
+ effective_address_family = ADDRESS_FAMILY_IPV4;
+ effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6;
}
return Key(info.hostname(), effective_address_family, effective_flags);
« 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