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

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: 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..394cdd7142312ce21a52d47489c72846e952b124 100644
--- a/net/dns/host_resolver_impl.cc
+++ b/net/dns/host_resolver_impl.cc
@@ -1954,26 +1954,30 @@ bool HostResolverImpl::ServeFromHosts(const Key& key,
// HOSTS lookups are case-insensitive.
std::string hostname = StringToLowerASCII(key.hostname);
- // 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;
+ if (key.address_family == ADDRESS_FAMILY_UNSPECIFIED) {
+ // 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.
+ // We prefer IPv6, "happy eyeballs" will fallback to IPv4 if needed.
mmenke 2013/03/27 19:58:02 nit: "fall back" (fallback is a noun, not a verb)
mmenke 2013/03/27 19:58:02 nit: Also, that comma should be a semi-colon, or
+ addresses->clear();
+ 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_IPV4));
+ if (it != hosts.end())
+ addresses->push_back(IPEndPoint(it->second, info.port()));
+ return !addresses->empty();
+ } else {
+ DnsHosts::const_iterator it = hosts.find(
+ DnsHostsKey(hostname, key.address_family));
mmenke 2013/03/27 19:58:02 optional: This may be a little prettier with both
- it = hosts.find(DnsHostsKey(hostname, ADDRESS_FAMILY_IPV6));
if (it == hosts.end())
return false;
+ *addresses = AddressList::CreateFromIPAddress(it->second, info.port());
mmenke 2013/03/27 19:58:02 I think it's a mistake to clear addresses on failu
}
-
- *addresses = AddressList::CreateFromIPAddress(it->second, info.port());
return true;
}
« 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