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

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: 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 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 1936 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // HOSTS lookups are case-insensitive. 1954 // HOSTS lookups are case-insensitive.
1955 std::string hostname = StringToLowerASCII(key.hostname); 1955 std::string hostname = StringToLowerASCII(key.hostname);
1956 1956
1957 // If |address_family| is ADDRESS_FAMILY_UNSPECIFIED other implementations
1958 // (glibc and c-ares) return the first matching line. We have more
1959 // flexibility, but lose implicit ordering.
1960 // TODO(szym) http://crbug.com/117850
1961 const DnsHosts& hosts = dns_client_->GetConfig()->hosts; 1957 const DnsHosts& hosts = dns_client_->GetConfig()->hosts;
1962 DnsHosts::const_iterator it = hosts.find(
1963 DnsHostsKey(hostname,
1964 key.address_family == ADDRESS_FAMILY_UNSPECIFIED ?
1965 ADDRESS_FAMILY_IPV4 : key.address_family));
1966 1958
1967 if (it == hosts.end()) { 1959 if (key.address_family == ADDRESS_FAMILY_UNSPECIFIED) {
1968 if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED) 1960 // If |address_family| is ADDRESS_FAMILY_UNSPECIFIED other implementations
1969 return false; 1961 // (glibc and c-ares) return the first matching line. We have more
1962 // flexibility, but lose implicit ordering.
1963 // 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
1964 addresses->clear();
1965 DnsHosts::const_iterator it = hosts.find(
1966 DnsHostsKey(hostname, ADDRESS_FAMILY_IPV6));
1967 if (it != hosts.end())
1968 addresses->push_back(IPEndPoint(it->second, info.port()));
1969 it = hosts.find(DnsHostsKey(hostname, ADDRESS_FAMILY_IPV4));
1970 if (it != hosts.end())
1971 addresses->push_back(IPEndPoint(it->second, info.port()));
1972 return !addresses->empty();
1973 } else {
1974 DnsHosts::const_iterator it = hosts.find(
1975 DnsHostsKey(hostname, key.address_family));
mmenke 2013/03/27 19:58:02 optional: This may be a little prettier with both
1970 1976
1971 it = hosts.find(DnsHostsKey(hostname, ADDRESS_FAMILY_IPV6));
1972 if (it == hosts.end()) 1977 if (it == hosts.end())
1973 return false; 1978 return false;
1979 *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
1974 } 1980 }
1975
1976 *addresses = AddressList::CreateFromIPAddress(it->second, info.port());
1977 return true; 1981 return true;
1978 } 1982 }
1979 1983
1980 void HostResolverImpl::CacheResult(const Key& key, 1984 void HostResolverImpl::CacheResult(const Key& key,
1981 const HostCache::Entry& entry, 1985 const HostCache::Entry& entry,
1982 base::TimeDelta ttl) { 1986 base::TimeDelta ttl) {
1983 if (cache_.get()) 1987 if (cache_.get())
1984 cache_->Set(key, entry, base::TimeTicks::Now(), ttl); 1988 cache_->Set(key, entry, base::TimeTicks::Now(), ttl);
1985 } 1989 }
1986 1990
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 } 2175 }
2172 DnsConfig dns_config; 2176 DnsConfig dns_config;
2173 NetworkChangeNotifier::GetDnsConfig(&dns_config); 2177 NetworkChangeNotifier::GetDnsConfig(&dns_config);
2174 dns_client_->SetConfig(dns_config); 2178 dns_client_->SetConfig(dns_config);
2175 num_dns_failures_ = 0; 2179 num_dns_failures_ = 0;
2176 if (dns_config.IsValid()) 2180 if (dns_config.IsValid())
2177 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); 2181 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
2178 } 2182 }
2179 2183
2180 } // namespace net 2184 } // 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