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 17 matching lines...) Expand all Loading... |
28 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
29 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
30 #include "base/threading/worker_pool.h" | 30 #include "base/threading/worker_pool.h" |
31 #include "base/time/time.h" | 31 #include "base/time/time.h" |
32 #include "base/values.h" | 32 #include "base/values.h" |
33 #include "net/base/address_family.h" | 33 #include "net/base/address_family.h" |
34 #include "net/base/address_list.h" | 34 #include "net/base/address_list.h" |
35 #include "net/base/dns_reloader.h" | 35 #include "net/base/dns_reloader.h" |
36 #include "net/base/dns_util.h" | 36 #include "net/base/dns_util.h" |
37 #include "net/base/host_port_pair.h" | 37 #include "net/base/host_port_pair.h" |
| 38 #include "net/base/ip_endpoint.h" |
38 #include "net/base/net_errors.h" | 39 #include "net/base/net_errors.h" |
39 #include "net/base/net_log.h" | 40 #include "net/base/net_log.h" |
40 #include "net/base/net_util.h" | 41 #include "net/base/net_util.h" |
41 #include "net/dns/address_sorter.h" | 42 #include "net/dns/address_sorter.h" |
42 #include "net/dns/dns_client.h" | 43 #include "net/dns/dns_client.h" |
43 #include "net/dns/dns_config_service.h" | 44 #include "net/dns/dns_config_service.h" |
44 #include "net/dns/dns_protocol.h" | 45 #include "net/dns/dns_protocol.h" |
45 #include "net/dns/dns_response.h" | 46 #include "net/dns/dns_response.h" |
46 #include "net/dns/dns_transaction.h" | 47 #include "net/dns/dns_transaction.h" |
47 #include "net/dns/host_resolver_proc.h" | 48 #include "net/dns/host_resolver_proc.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 RandIntCallback(), | 176 RandIntCallback(), |
176 net_log.net_log(), | 177 net_log.net_log(), |
177 net_log.source())); | 178 net_log.source())); |
178 int rv = socket->Connect(IPEndPoint(dest, 53)); | 179 int rv = socket->Connect(IPEndPoint(dest, 53)); |
179 if (rv != OK) | 180 if (rv != OK) |
180 return false; | 181 return false; |
181 IPEndPoint endpoint; | 182 IPEndPoint endpoint; |
182 rv = socket->GetLocalAddress(&endpoint); | 183 rv = socket->GetLocalAddress(&endpoint); |
183 if (rv != OK) | 184 if (rv != OK) |
184 return false; | 185 return false; |
185 DCHECK(endpoint.GetFamily() == ADDRESS_FAMILY_IPV6); | 186 DCHECK_EQ(ADDRESS_FAMILY_IPV6, endpoint.GetFamily()); |
186 const IPAddressNumber& address = endpoint.address(); | 187 const IPAddressNumber& address = endpoint.address(); |
187 bool is_link_local = (address[0] == 0xFE) && ((address[1] & 0xC0) == 0x80); | 188 bool is_link_local = (address[0] == 0xFE) && ((address[1] & 0xC0) == 0x80); |
188 if (is_link_local) | 189 if (is_link_local) |
189 return false; | 190 return false; |
190 const uint8 kTeredoPrefix[] = { 0x20, 0x01, 0, 0 }; | 191 const uint8 kTeredoPrefix[] = { 0x20, 0x01, 0, 0 }; |
191 bool is_teredo = std::equal(kTeredoPrefix, | 192 bool is_teredo = std::equal(kTeredoPrefix, |
192 kTeredoPrefix + arraysize(kTeredoPrefix), | 193 kTeredoPrefix + arraysize(kTeredoPrefix), |
193 address.begin()); | 194 address.begin()); |
194 if (is_teredo) | 195 if (is_teredo) |
195 return false; | 196 return false; |
(...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2025 DCHECK(addresses); | 2026 DCHECK(addresses); |
2026 DCHECK(net_error); | 2027 DCHECK(net_error); |
2027 IPAddressNumber ip_number; | 2028 IPAddressNumber ip_number; |
2028 if (!ParseIPLiteralToNumber(key.hostname, &ip_number)) | 2029 if (!ParseIPLiteralToNumber(key.hostname, &ip_number)) |
2029 return false; | 2030 return false; |
2030 | 2031 |
2031 DCHECK_EQ(key.host_resolver_flags & | 2032 DCHECK_EQ(key.host_resolver_flags & |
2032 ~(HOST_RESOLVER_CANONNAME | HOST_RESOLVER_LOOPBACK_ONLY | | 2033 ~(HOST_RESOLVER_CANONNAME | HOST_RESOLVER_LOOPBACK_ONLY | |
2033 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6), | 2034 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6), |
2034 0) << " Unhandled flag"; | 2035 0) << " Unhandled flag"; |
2035 bool ipv6_disabled = (default_address_family_ == ADDRESS_FAMILY_IPV4) && | 2036 |
2036 !probe_ipv6_support_; | |
2037 *net_error = OK; | 2037 *net_error = OK; |
2038 if ((ip_number.size() == kIPv6AddressSize) && ipv6_disabled) { | 2038 AddressFamily family = GetAddressFamily(ip_number); |
| 2039 if (family == ADDRESS_FAMILY_IPV6 && |
| 2040 !probe_ipv6_support_ && |
| 2041 default_address_family_ == ADDRESS_FAMILY_IPV4) { |
| 2042 // Don't return IPv6 addresses if default address family is set to IPv4, |
| 2043 // and probes are disabled. |
| 2044 *net_error = ERR_NAME_NOT_RESOLVED; |
| 2045 } else if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED && |
| 2046 key.address_family != family) { |
| 2047 // Don't return IPv6 addresses for IPv4 queries, and vice versa. |
2039 *net_error = ERR_NAME_NOT_RESOLVED; | 2048 *net_error = ERR_NAME_NOT_RESOLVED; |
2040 } else { | 2049 } else { |
2041 *addresses = AddressList::CreateFromIPAddress(ip_number, info.port()); | 2050 *addresses = AddressList::CreateFromIPAddress(ip_number, info.port()); |
2042 if (key.host_resolver_flags & HOST_RESOLVER_CANONNAME) | 2051 if (key.host_resolver_flags & HOST_RESOLVER_CANONNAME) |
2043 addresses->SetDefaultCanonicalName(); | 2052 addresses->SetDefaultCanonicalName(); |
2044 } | 2053 } |
2045 return true; | 2054 return true; |
2046 } | 2055 } |
2047 | 2056 |
2048 bool HostResolverImpl::ServeFromCache(const Key& key, | 2057 bool HostResolverImpl::ServeFromCache(const Key& key, |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2350 dns_client_->SetConfig(dns_config); | 2359 dns_client_->SetConfig(dns_config); |
2351 num_dns_failures_ = 0; | 2360 num_dns_failures_ = 0; |
2352 if (dns_client_->GetConfig()) | 2361 if (dns_client_->GetConfig()) |
2353 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2362 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
2354 } | 2363 } |
2355 | 2364 |
2356 AbortDnsTasks(); | 2365 AbortDnsTasks(); |
2357 } | 2366 } |
2358 | 2367 |
2359 } // namespace net | 2368 } // namespace net |
OLD | NEW |