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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 if (hostname[hostname.size() - 1] == '.') { | 163 if (hostname[hostname.size() - 1] == '.') { |
164 return hostname.size() > kSuffixLen && | 164 return hostname.size() > kSuffixLen && |
165 !hostname.compare(hostname.size() - kSuffixLen, kSuffixLen, kSuffix); | 165 !hostname.compare(hostname.size() - kSuffixLen, kSuffixLen, kSuffix); |
166 } | 166 } |
167 return hostname.size() > kSuffixLenTrimmed && | 167 return hostname.size() > kSuffixLenTrimmed && |
168 !hostname.compare(hostname.size() - kSuffixLenTrimmed, kSuffixLenTrimmed, | 168 !hostname.compare(hostname.size() - kSuffixLenTrimmed, kSuffixLenTrimmed, |
169 kSuffix, kSuffixLenTrimmed); | 169 kSuffix, kSuffixLenTrimmed); |
170 } | 170 } |
171 | 171 |
172 // Attempts to connect a UDP socket to |dest|:80. | 172 // Attempts to connect a UDP socket to |dest|:80. |
173 int AttemptRoute(const IPAddressNumber& dest) { | 173 bool IsGloballyReachable(const IPAddressNumber& dest) { |
174 scoped_ptr<DatagramClientSocket> socket( | 174 scoped_ptr<DatagramClientSocket> socket( |
175 ClientSocketFactory::GetDefaultFactory()->CreateDatagramClientSocket( | 175 ClientSocketFactory::GetDefaultFactory()->CreateDatagramClientSocket( |
176 DatagramSocket::DEFAULT_BIND, | 176 DatagramSocket::DEFAULT_BIND, |
177 RandIntCallback(), | 177 RandIntCallback(), |
178 NULL, | 178 NULL, |
179 NetLog::Source())); | 179 NetLog::Source())); |
180 return socket->Connect(IPEndPoint(dest, 80)); | 180 int rv = socket->Connect(IPEndPoint(dest, 80)); |
| 181 if (rv != OK) |
| 182 return false; |
| 183 IPEndPoint endpoint; |
| 184 rv = socket->GetLocalAddress(&endpoint); |
| 185 if (rv != OK) |
| 186 return false; |
| 187 DCHECK(endpoint.GetFamily() == ADDRESS_FAMILY_IPV6); |
| 188 const IPAddressNumber& address = endpoint.address(); |
| 189 bool is_link_local = (address[0] == 0xFE) && ((address[1] & 0xC0) == 0x80); |
| 190 if (is_link_local) |
| 191 return false; |
| 192 const uint8 kTeredoPrefix[] = { 0x20, 0x01, 0, 0 }; |
| 193 bool is_teredo = std::equal(kTeredoPrefix, |
| 194 kTeredoPrefix + arraysize(kTeredoPrefix), |
| 195 address.begin()); |
| 196 if (is_teredo) |
| 197 return false; |
| 198 return true; |
181 } | 199 } |
182 | 200 |
183 // Provide a common macro to simplify code and readability. We must use a | 201 // Provide a common macro to simplify code and readability. We must use a |
184 // macro as the underlying HISTOGRAM macro creates static variables. | 202 // macro as the underlying HISTOGRAM macro creates static variables. |
185 #define DNS_HISTOGRAM(name, time) UMA_HISTOGRAM_CUSTOM_TIMES(name, time, \ | 203 #define DNS_HISTOGRAM(name, time) UMA_HISTOGRAM_CUSTOM_TIMES(name, time, \ |
186 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromHours(1), 100) | 204 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromHours(1), 100) |
187 | 205 |
188 // A macro to simplify code and readability. | 206 // A macro to simplify code and readability. |
189 #define DNS_HISTOGRAM_BY_PRIORITY(basename, priority, time) \ | 207 #define DNS_HISTOGRAM_BY_PRIORITY(basename, priority, time) \ |
190 do { \ | 208 do { \ |
(...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2026 HostResolverFlags effective_flags = | 2044 HostResolverFlags effective_flags = |
2027 info.host_resolver_flags() | additional_resolver_flags_; | 2045 info.host_resolver_flags() | additional_resolver_flags_; |
2028 AddressFamily effective_address_family = info.address_family(); | 2046 AddressFamily effective_address_family = info.address_family(); |
2029 | 2047 |
2030 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) { | 2048 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) { |
2031 base::TimeTicks start_time = base::TimeTicks::Now(); | 2049 base::TimeTicks start_time = base::TimeTicks::Now(); |
2032 // Google DNS address. | 2050 // Google DNS address. |
2033 const uint8 kIPv6Address[] = | 2051 const uint8 kIPv6Address[] = |
2034 { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, | 2052 { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, |
2035 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 }; | 2053 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 }; |
2036 int rv6 = AttemptRoute( | 2054 bool rv6 = IsGloballyReachable( |
2037 IPAddressNumber(kIPv6Address, kIPv6Address + arraysize(kIPv6Address))); | 2055 IPAddressNumber(kIPv6Address, kIPv6Address + arraysize(kIPv6Address))); |
2038 | 2056 |
2039 UMA_HISTOGRAM_TIMES("Net.IPv6ConnectDuration", | 2057 UMA_HISTOGRAM_TIMES("Net.IPv6ConnectDuration", |
2040 base::TimeTicks::Now() - start_time); | 2058 base::TimeTicks::Now() - start_time); |
2041 if (rv6 == OK) { | 2059 if (rv6) { |
2042 UMA_HISTOGRAM_BOOLEAN("Net.IPv6ConnectSuccessMatch", | 2060 UMA_HISTOGRAM_BOOLEAN("Net.IPv6ConnectSuccessMatch", |
2043 default_address_family_ == ADDRESS_FAMILY_UNSPECIFIED); | 2061 default_address_family_ == ADDRESS_FAMILY_UNSPECIFIED); |
2044 } else { | 2062 } else { |
2045 UMA_HISTOGRAM_BOOLEAN("Net.IPv6ConnectFailureMatch", | 2063 UMA_HISTOGRAM_BOOLEAN("Net.IPv6ConnectFailureMatch", |
2046 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED); | 2064 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED); |
2047 } | 2065 } |
2048 } | 2066 } |
2049 | 2067 |
2050 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED && | 2068 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED && |
2051 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) { | 2069 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2201 } | 2219 } |
2202 DnsConfig dns_config; | 2220 DnsConfig dns_config; |
2203 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2221 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
2204 dns_client_->SetConfig(dns_config); | 2222 dns_client_->SetConfig(dns_config); |
2205 num_dns_failures_ = 0; | 2223 num_dns_failures_ = 0; |
2206 if (dns_config.IsValid()) | 2224 if (dns_config.IsValid()) |
2207 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2225 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
2208 } | 2226 } |
2209 | 2227 |
2210 } // namespace net | 2228 } // namespace net |
OLD | NEW |