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 AttemptRoute(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 if (endpoint.GetFamily() == ADDRESS_FAMILY_IPV6) { | |
mmenke
2013/04/12 17:34:25
Is there any case this won't be the case? I would
szym
2013/04/12 17:35:52
I was considering calling AttemptRoute("8.8.8.8")
| |
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 } | |
199 return true; | |
181 } | 200 } |
182 | 201 |
183 // Provide a common macro to simplify code and readability. We must use a | 202 // Provide a common macro to simplify code and readability. We must use a |
184 // macro as the underlying HISTOGRAM macro creates static variables. | 203 // macro as the underlying HISTOGRAM macro creates static variables. |
185 #define DNS_HISTOGRAM(name, time) UMA_HISTOGRAM_CUSTOM_TIMES(name, time, \ | 204 #define DNS_HISTOGRAM(name, time) UMA_HISTOGRAM_CUSTOM_TIMES(name, time, \ |
186 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromHours(1), 100) | 205 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromHours(1), 100) |
187 | 206 |
188 // A macro to simplify code and readability. | 207 // A macro to simplify code and readability. |
189 #define DNS_HISTOGRAM_BY_PRIORITY(basename, priority, time) \ | 208 #define DNS_HISTOGRAM_BY_PRIORITY(basename, priority, time) \ |
190 do { \ | 209 do { \ |
(...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2026 HostResolverFlags effective_flags = | 2045 HostResolverFlags effective_flags = |
2027 info.host_resolver_flags() | additional_resolver_flags_; | 2046 info.host_resolver_flags() | additional_resolver_flags_; |
2028 AddressFamily effective_address_family = info.address_family(); | 2047 AddressFamily effective_address_family = info.address_family(); |
2029 | 2048 |
2030 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) { | 2049 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) { |
2031 base::TimeTicks start_time = base::TimeTicks::Now(); | 2050 base::TimeTicks start_time = base::TimeTicks::Now(); |
2032 // Google DNS address. | 2051 // Google DNS address. |
2033 const uint8 kIPv6Address[] = | 2052 const uint8 kIPv6Address[] = |
2034 { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, | 2053 { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, |
2035 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 }; | 2054 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 }; |
2036 int rv6 = AttemptRoute( | 2055 bool rv6 = AttemptRoute( |
2037 IPAddressNumber(kIPv6Address, kIPv6Address + arraysize(kIPv6Address))); | 2056 IPAddressNumber(kIPv6Address, kIPv6Address + arraysize(kIPv6Address))); |
2038 | 2057 |
2039 UMA_HISTOGRAM_TIMES("Net.IPv6ConnectDuration", | 2058 UMA_HISTOGRAM_TIMES("Net.IPv6ConnectDuration", |
2040 base::TimeTicks::Now() - start_time); | 2059 base::TimeTicks::Now() - start_time); |
2041 if (rv6 == OK) { | 2060 if (rv6) { |
2042 UMA_HISTOGRAM_BOOLEAN("Net.IPv6ConnectSuccessMatch", | 2061 UMA_HISTOGRAM_BOOLEAN("Net.IPv6ConnectSuccessMatch", |
2043 default_address_family_ == ADDRESS_FAMILY_UNSPECIFIED); | 2062 default_address_family_ == ADDRESS_FAMILY_UNSPECIFIED); |
2044 } else { | 2063 } else { |
2045 UMA_HISTOGRAM_BOOLEAN("Net.IPv6ConnectFailureMatch", | 2064 UMA_HISTOGRAM_BOOLEAN("Net.IPv6ConnectFailureMatch", |
2046 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED); | 2065 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED); |
2047 } | 2066 } |
2048 } | 2067 } |
2049 | 2068 |
2050 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED && | 2069 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED && |
2051 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) { | 2070 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2201 } | 2220 } |
2202 DnsConfig dns_config; | 2221 DnsConfig dns_config; |
2203 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2222 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
2204 dns_client_->SetConfig(dns_config); | 2223 dns_client_->SetConfig(dns_config); |
2205 num_dns_failures_ = 0; | 2224 num_dns_failures_ = 0; |
2206 if (dns_config.IsValid()) | 2225 if (dns_config.IsValid()) |
2207 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2226 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
2208 } | 2227 } |
2209 | 2228 |
2210 } // namespace net | 2229 } // namespace net |
OLD | NEW |