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

Unified Diff: net/dns/host_resolver_impl.cc

Issue 1177933002: Resolve RFC 6761 localhost names to loopback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rsleevi, mmenke comments 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 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 970ec1f457ade5ba90b1b2ac6224f57e782c0271..d751495bff5325a3a60201a227ae13fa28d1e6f2 100644
--- a/net/dns/host_resolver_impl.cc
+++ b/net/dns/host_resolver_impl.cc
@@ -74,8 +74,6 @@ const unsigned kNegativeCacheEntryTTLSeconds = 0;
// Minimum TTL for successful resolutions with DnsTask.
const unsigned kMinimumTTLSeconds = kCacheEntryTTLSeconds;
-const char kLocalhost[] = "localhost.";
-
// Time between IPv6 probes, i.e. for how long results of each IPv6 probe are
// cached.
const int kIPv6ProbePeriodMs = 1000;
@@ -1318,13 +1316,7 @@ class HostResolverImpl::Job : public PrioritizedDispatcher::Job,
}
void AddRequest(scoped_ptr<Request> req) {
- // .localhost queries are redirected to "localhost." to make sure
- // that they are never sent out on the network, per RFC 6761.
- if (IsLocalhostTLD(req->info().hostname())) {
- DCHECK_EQ(key_.hostname, kLocalhost);
- } else {
- DCHECK_EQ(key_.hostname, req->info().hostname());
- }
+ DCHECK_EQ(key_.hostname, req->info().hostname());
req->set_job(this);
priority_tracker_.Add(req->priority());
@@ -1997,6 +1989,10 @@ int HostResolverImpl::ResolveHelper(const Key& key,
source_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_HOSTS_HIT);
return OK;
}
+
+ if (ServeLocalhost(key, info, addresses))
+ return OK;
+
return ERR_DNS_CACHE_MISS;
}
@@ -2159,6 +2155,47 @@ bool HostResolverImpl::ServeFromHosts(const Key& key,
return !addresses->empty();
}
+bool HostResolverImpl::ServeLocalhost(const Key& key,
+ const RequestInfo& info,
+ AddressList* addresses) {
+ const unsigned char kLocalhostIPv4[] = {127, 0, 0, 1};
+ const unsigned char kLocalhostIPv6[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
+
+ bool isLocalhost6;
+ if (!IsLocalhostHostname(key.hostname, &isLocalhost6))
+ return false;
+
+ addresses->clear();
+
+ bool useIPv4 =
+ !isLocalhost6 && (key.address_family == ADDRESS_FAMILY_IPV4 ||
+ key.address_family == ADDRESS_FAMILY_UNSPECIFIED);
+ // If the family was restricted to IPv4 due to a detected lack of IPv6
estark 2015/06/11 02:35:32 Just wanted to flag this slightly weird thing. App
mmenke 2015/06/11 14:45:59 One option would be to make IsLocalhostHostname ta
estark 2015/06/11 17:16:47 Hmm? Sorry, I don't understand what problem this w
mmenke 2015/06/11 17:32:25 It's an alternative to passing the bool pointer, w
estark 2015/06/11 22:25:26 Ah, I see! Done.
+ // support, resolve with no restrictions. See SystemHostResolverCall
+ // for rationale.
+ bool useIPv6 = isLocalhost6 || key.address_family == ADDRESS_FAMILY_IPV6 ||
mmenke 2015/06/11 14:45:59 If the address family is ADDRESS_FAMILY_IPV4 and t
estark 2015/06/11 17:16:48 Done.
+ key.address_family == ADDRESS_FAMILY_UNSPECIFIED ||
+ (key.host_resolver_flags &
+ HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6);
+
+ if (useIPv4) {
+ addresses->push_back(
+ IPEndPoint(IPAddressNumber(kLocalhostIPv4,
+ kLocalhostIPv4 + arraysize(kLocalhostIPv4)),
+ info.port()));
+ }
+
+ if (useIPv6) {
+ addresses->push_back(
+ IPEndPoint(IPAddressNumber(kLocalhostIPv6,
+ kLocalhostIPv6 + arraysize(kLocalhostIPv6)),
+ info.port()));
+ }
+
+ return true;
+}
+
void HostResolverImpl::CacheResult(const Key& key,
const HostCache::Entry& entry,
base::TimeDelta ttl) {
@@ -2205,13 +2242,7 @@ HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
}
}
- std::string hostname = info.hostname();
- // Redirect .localhost queries to "localhost." to make sure that they
- // are never sent out on the network, per RFC 6761.
- if (IsLocalhostTLD(info.hostname()))
- hostname = kLocalhost;
-
- return Key(hostname, effective_address_family, effective_flags);
+ return Key(info.hostname(), effective_address_family, effective_flags);
}
bool HostResolverImpl::IsIPv6Reachable(const BoundNetLog& net_log) {
« 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