Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1990 if (ServeFromCache(key, info, &net_error, addresses)) { | 1990 if (ServeFromCache(key, info, &net_error, addresses)) { |
| 1991 source_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CACHE_HIT); | 1991 source_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CACHE_HIT); |
| 1992 return net_error; | 1992 return net_error; |
| 1993 } | 1993 } |
| 1994 // TODO(szym): Do not do this if nsswitch.conf instructs not to. | 1994 // TODO(szym): Do not do this if nsswitch.conf instructs not to. |
| 1995 // http://crbug.com/117655 | 1995 // http://crbug.com/117655 |
| 1996 if (ServeFromHosts(key, info, addresses)) { | 1996 if (ServeFromHosts(key, info, addresses)) { |
| 1997 source_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_HOSTS_HIT); | 1997 source_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_HOSTS_HIT); |
| 1998 return OK; | 1998 return OK; |
| 1999 } | 1999 } |
| 2000 | |
| 2001 // Per RFC 6761 section 6.3, resolve localhost to loopback without | |
| 2002 // sending it out on the network. | |
| 2003 if (IsLocalhost(base::StringToLowerASCII(key.hostname))) { | |
|
Ryan Sleevi
2015/06/11 00:34:03
BUG: Should IsLocalhost be doing the case conversi
estark
2015/06/11 02:35:32
Done.
| |
| 2004 addresses->clear(); | |
| 2005 IPAddressNumber ip_address; | |
| 2006 ParseIPLiteralToNumber("127.0.0.1", &ip_address); | |
|
Ryan Sleevi
2015/06/11 00:34:03
BUG 1: This isn't correct for localhost6 (which sh
estark
2015/06/11 02:35:32
Done by factoring out the hostname check of IsLoca
| |
| 2007 addresses->push_back(IPEndPoint(ip_address, info.port())); | |
| 2008 return OK; | |
| 2009 } | |
| 2010 | |
| 2000 return ERR_DNS_CACHE_MISS; | 2011 return ERR_DNS_CACHE_MISS; |
| 2001 } | 2012 } |
| 2002 | 2013 |
| 2003 int HostResolverImpl::ResolveFromCache(const RequestInfo& info, | 2014 int HostResolverImpl::ResolveFromCache(const RequestInfo& info, |
| 2004 AddressList* addresses, | 2015 AddressList* addresses, |
| 2005 const BoundNetLog& source_net_log) { | 2016 const BoundNetLog& source_net_log) { |
| 2006 DCHECK(CalledOnValidThread()); | 2017 DCHECK(CalledOnValidThread()); |
| 2007 DCHECK(addresses); | 2018 DCHECK(addresses); |
| 2008 | 2019 |
| 2009 // Update the net log and notify registered observers. | 2020 // Update the net log and notify registered observers. |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2202 effective_address_family = ADDRESS_FAMILY_IPV4; | 2213 effective_address_family = ADDRESS_FAMILY_IPV4; |
| 2203 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; | 2214 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
| 2204 } | 2215 } |
| 2205 } | 2216 } |
| 2206 } | 2217 } |
| 2207 | 2218 |
| 2208 std::string hostname = info.hostname(); | 2219 std::string hostname = info.hostname(); |
| 2209 // Redirect .localhost queries to "localhost." to make sure that they | 2220 // Redirect .localhost queries to "localhost." to make sure that they |
| 2210 // are never sent out on the network, per RFC 6761. | 2221 // are never sent out on the network, per RFC 6761. |
| 2211 if (IsLocalhostTLD(info.hostname())) | 2222 if (IsLocalhostTLD(info.hostname())) |
| 2212 hostname = kLocalhost; | 2223 hostname = kLocalhost; |
|
mmenke
2015/06/11 00:36:51
Peppering this file with multiple localhost checks
estark
2015/06/11 02:35:32
Ah, that's nice, we don't need both. Removed.
| |
| 2213 | 2224 |
| 2214 return Key(hostname, effective_address_family, effective_flags); | 2225 return Key(hostname, effective_address_family, effective_flags); |
| 2215 } | 2226 } |
| 2216 | 2227 |
| 2217 bool HostResolverImpl::IsIPv6Reachable(const BoundNetLog& net_log) { | 2228 bool HostResolverImpl::IsIPv6Reachable(const BoundNetLog& net_log) { |
| 2218 base::TimeTicks now = base::TimeTicks::Now(); | 2229 base::TimeTicks now = base::TimeTicks::Now(); |
| 2219 bool cached = true; | 2230 bool cached = true; |
| 2220 if ((now - last_ipv6_probe_time_).InMilliseconds() > kIPv6ProbePeriodMs) { | 2231 if ((now - last_ipv6_probe_time_).InMilliseconds() > kIPv6ProbePeriodMs) { |
| 2221 IPAddressNumber address(kIPv6ProbeAddress, | 2232 IPAddressNumber address(kIPv6ProbeAddress, |
| 2222 kIPv6ProbeAddress + arraysize(kIPv6ProbeAddress)); | 2233 kIPv6ProbeAddress + arraysize(kIPv6ProbeAddress)); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2412 dns_client_->SetConfig(dns_config); | 2423 dns_client_->SetConfig(dns_config); |
| 2413 num_dns_failures_ = 0; | 2424 num_dns_failures_ = 0; |
| 2414 if (dns_client_->GetConfig()) | 2425 if (dns_client_->GetConfig()) |
| 2415 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2426 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
| 2416 } | 2427 } |
| 2417 | 2428 |
| 2418 AbortDnsTasks(); | 2429 AbortDnsTasks(); |
| 2419 } | 2430 } |
| 2420 | 2431 |
| 2421 } // namespace net | 2432 } // namespace net |
| OLD | NEW |