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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/dns/host_resolver_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1933 matching lines...) Expand 10 before | Expand all | Expand 10 after
1944 return true; 1944 return true;
1945 } 1945 }
1946 1946
1947 bool HostResolverImpl::ServeFromHosts(const Key& key, 1947 bool HostResolverImpl::ServeFromHosts(const Key& key,
1948 const RequestInfo& info, 1948 const RequestInfo& info,
1949 AddressList* addresses) { 1949 AddressList* addresses) {
1950 DCHECK(addresses); 1950 DCHECK(addresses);
1951 if (!HaveDnsConfig()) 1951 if (!HaveDnsConfig())
1952 return false; 1952 return false;
1953 1953
1954 addresses->clear();
1955
1954 // HOSTS lookups are case-insensitive. 1956 // HOSTS lookups are case-insensitive.
1955 std::string hostname = StringToLowerASCII(key.hostname); 1957 std::string hostname = StringToLowerASCII(key.hostname);
1956 1958
1959 const DnsHosts& hosts = dns_client_->GetConfig()->hosts;
1960
1957 // If |address_family| is ADDRESS_FAMILY_UNSPECIFIED other implementations 1961 // If |address_family| is ADDRESS_FAMILY_UNSPECIFIED other implementations
1958 // (glibc and c-ares) return the first matching line. We have more 1962 // (glibc and c-ares) return the first matching line. We have more
1959 // flexibility, but lose implicit ordering. 1963 // flexibility, but lose implicit ordering.
1960 // TODO(szym) http://crbug.com/117850 1964 // We prefer IPv6 because "happy eyeballs" will fall back to IPv4 if
1961 const DnsHosts& hosts = dns_client_->GetConfig()->hosts; 1965 // necessary.
1962 DnsHosts::const_iterator it = hosts.find( 1966 if (key.address_family == ADDRESS_FAMILY_IPV6 ||
1963 DnsHostsKey(hostname, 1967 key.address_family == ADDRESS_FAMILY_UNSPECIFIED) {
1964 key.address_family == ADDRESS_FAMILY_UNSPECIFIED ? 1968 DnsHosts::const_iterator it = hosts.find(
1965 ADDRESS_FAMILY_IPV4 : key.address_family)); 1969 DnsHostsKey(hostname, ADDRESS_FAMILY_IPV6));
1966 1970 if (it != hosts.end())
1967 if (it == hosts.end()) { 1971 addresses->push_back(IPEndPoint(it->second, info.port()));
1968 if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED)
1969 return false;
1970
1971 it = hosts.find(DnsHostsKey(hostname, ADDRESS_FAMILY_IPV6));
1972 if (it == hosts.end())
1973 return false;
1974 } 1972 }
1975 1973
1976 *addresses = AddressList::CreateFromIPAddress(it->second, info.port()); 1974 if (key.address_family == ADDRESS_FAMILY_IPV4 ||
1977 return true; 1975 key.address_family == ADDRESS_FAMILY_UNSPECIFIED) {
1976 DnsHosts::const_iterator it = hosts.find(
1977 DnsHostsKey(hostname, ADDRESS_FAMILY_IPV4));
1978 if (it != hosts.end())
1979 addresses->push_back(IPEndPoint(it->second, info.port()));
1980 }
1981
1982 return !addresses->empty();
1978 } 1983 }
1979 1984
1980 void HostResolverImpl::CacheResult(const Key& key, 1985 void HostResolverImpl::CacheResult(const Key& key,
1981 const HostCache::Entry& entry, 1986 const HostCache::Entry& entry,
1982 base::TimeDelta ttl) { 1987 base::TimeDelta ttl) {
1983 if (cache_.get()) 1988 if (cache_.get())
1984 cache_->Set(key, entry, base::TimeTicks::Now(), ttl); 1989 cache_->Set(key, entry, base::TimeTicks::Now(), ttl);
1985 } 1990 }
1986 1991
1987 void HostResolverImpl::RemoveJob(Job* job) { 1992 void HostResolverImpl::RemoveJob(Job* job) {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 } 2176 }
2172 DnsConfig dns_config; 2177 DnsConfig dns_config;
2173 NetworkChangeNotifier::GetDnsConfig(&dns_config); 2178 NetworkChangeNotifier::GetDnsConfig(&dns_config);
2174 dns_client_->SetConfig(dns_config); 2179 dns_client_->SetConfig(dns_config);
2175 num_dns_failures_ = 0; 2180 num_dns_failures_ = 0;
2176 if (dns_config.IsValid()) 2181 if (dns_config.IsValid())
2177 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); 2182 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
2178 } 2183 }
2179 2184
2180 } // namespace net 2185 } // namespace net
OLDNEW
« 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