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

Unified Diff: net/dns/host_resolver_impl.cc

Issue 12681017: [net/dns] When serving AF_UNSPEC addresses from DnsHosts, serve one from each family. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move comment and ->clear Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | 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 91475ec827a42cb2ea70a03c61cd2575ffbd13e7..abb34d845e2c6db153475aef0504c0649035a42b 100644
--- a/net/dns/host_resolver_impl.cc
+++ b/net/dns/host_resolver_impl.cc
@@ -1951,30 +1951,35 @@ bool HostResolverImpl::ServeFromHosts(const Key& key,
if (!HaveDnsConfig())
return false;
+ addresses->clear();
+
// HOSTS lookups are case-insensitive.
std::string hostname = StringToLowerASCII(key.hostname);
+ const DnsHosts& hosts = dns_client_->GetConfig()->hosts;
+
// If |address_family| is ADDRESS_FAMILY_UNSPECIFIED other implementations
// (glibc and c-ares) return the first matching line. We have more
// flexibility, but lose implicit ordering.
- // TODO(szym) http://crbug.com/117850
- const DnsHosts& hosts = dns_client_->GetConfig()->hosts;
- DnsHosts::const_iterator it = hosts.find(
- DnsHostsKey(hostname,
- key.address_family == ADDRESS_FAMILY_UNSPECIFIED ?
- ADDRESS_FAMILY_IPV4 : key.address_family));
-
- if (it == hosts.end()) {
- if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED)
- return false;
+ // We prefer IPv6 because "happy eyeballs" will fall back to IPv4 if
+ // necessary.
+ if (key.address_family == ADDRESS_FAMILY_IPV6 ||
+ key.address_family == ADDRESS_FAMILY_UNSPECIFIED) {
+ DnsHosts::const_iterator it = hosts.find(
+ DnsHostsKey(hostname, ADDRESS_FAMILY_IPV6));
+ if (it != hosts.end())
+ addresses->push_back(IPEndPoint(it->second, info.port()));
+ }
- it = hosts.find(DnsHostsKey(hostname, ADDRESS_FAMILY_IPV6));
- if (it == hosts.end())
- return false;
+ if (key.address_family == ADDRESS_FAMILY_IPV4 ||
+ key.address_family == ADDRESS_FAMILY_UNSPECIFIED) {
+ DnsHosts::const_iterator it = hosts.find(
+ DnsHostsKey(hostname, ADDRESS_FAMILY_IPV4));
+ if (it != hosts.end())
+ addresses->push_back(IPEndPoint(it->second, info.port()));
}
- *addresses = AddressList::CreateFromIPAddress(it->second, info.port());
- return true;
+ return !addresses->empty();
}
void HostResolverImpl::CacheResult(const Key& key,
« no previous file with comments | « no previous file | net/dns/host_resolver_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698