| 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 "content/renderer/p2p/ipc_network_manager.h" | 5 #include "content/renderer/p2p/ipc_network_manager.h" |
| 6 #include <string> | 6 #include <string> |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/sys_byteorder.h" | 10 #include "base/sys_byteorder.h" |
| 11 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
| 12 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // According to http://www.ietf.org/rfc/rfc2373.txt, Appendix A, page 19. An | |
| 19 // address which contains MAC will have its 11th and 12th bytes as FF:FE as well | |
| 20 // as the U/L bit as 1. | |
| 21 bool IsMacBasedIPv6Address(const net::IPAddressNumber& ipaddress) { | |
| 22 return ((ipaddress[8] & 0x02) && ipaddress[11] == 0xFF && | |
| 23 ipaddress[12] == 0xFE); | |
| 24 } | |
| 25 | |
| 26 rtc::AdapterType ConvertConnectionTypeToAdapterType( | 18 rtc::AdapterType ConvertConnectionTypeToAdapterType( |
| 27 net::NetworkChangeNotifier::ConnectionType type) { | 19 net::NetworkChangeNotifier::ConnectionType type) { |
| 28 switch (type) { | 20 switch (type) { |
| 29 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: | 21 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: |
| 30 return rtc::ADAPTER_TYPE_UNKNOWN; | 22 return rtc::ADAPTER_TYPE_UNKNOWN; |
| 31 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: | 23 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: |
| 32 return rtc::ADAPTER_TYPE_ETHERNET; | 24 return rtc::ADAPTER_TYPE_ETHERNET; |
| 33 case net::NetworkChangeNotifier::CONNECTION_WIFI: | 25 case net::NetworkChangeNotifier::CONNECTION_WIFI: |
| 34 return rtc::ADAPTER_TYPE_WIFI; | 26 return rtc::ADAPTER_TYPE_WIFI; |
| 35 case net::NetworkChangeNotifier::CONNECTION_2G: | 27 case net::NetworkChangeNotifier::CONNECTION_2G: |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 memcpy(&address, &it->address[0], sizeof(uint32)); | 81 memcpy(&address, &it->address[0], sizeof(uint32)); |
| 90 address = rtc::NetworkToHost32(address); | 82 address = rtc::NetworkToHost32(address); |
| 91 rtc::IPAddress prefix = | 83 rtc::IPAddress prefix = |
| 92 rtc::TruncateIP(rtc::IPAddress(address), it->prefix_length); | 84 rtc::TruncateIP(rtc::IPAddress(address), it->prefix_length); |
| 93 rtc::Network* network = | 85 rtc::Network* network = |
| 94 new rtc::Network(it->name, it->name, prefix, it->prefix_length, | 86 new rtc::Network(it->name, it->name, prefix, it->prefix_length, |
| 95 ConvertConnectionTypeToAdapterType(it->type)); | 87 ConvertConnectionTypeToAdapterType(it->type)); |
| 96 network->AddIP(rtc::IPAddress(address)); | 88 network->AddIP(rtc::IPAddress(address)); |
| 97 networks.push_back(network); | 89 networks.push_back(network); |
| 98 } else if (it->address.size() == net::kIPv6AddressSize) { | 90 } else if (it->address.size() == net::kIPv6AddressSize) { |
| 91 in6_addr address; |
| 92 memcpy(&address, &it->address[0], sizeof(in6_addr)); |
| 93 rtc::InterfaceAddress ip6_addr(address, it->ip_address_attributes); |
| 94 |
| 99 // Only allow non-deprecated IPv6 addresses which don't contain MAC. | 95 // Only allow non-deprecated IPv6 addresses which don't contain MAC. |
| 100 if (IsMacBasedIPv6Address(it->address) || | 96 if (rtc::IPIsMacBased(ip6_addr) || |
| 101 (it->ip_address_attributes & net::IP_ADDRESS_ATTRIBUTE_DEPRECATED)) { | 97 (it->ip_address_attributes & net::IP_ADDRESS_ATTRIBUTE_DEPRECATED)) { |
| 102 continue; | 98 continue; |
| 103 } | 99 } |
| 104 | 100 |
| 105 in6_addr address; | |
| 106 memcpy(&address, &it->address[0], sizeof(in6_addr)); | |
| 107 rtc::InterfaceAddress ip6_addr(address, it->ip_address_attributes); | |
| 108 if (!rtc::IPIsPrivate(ip6_addr)) { | 101 if (!rtc::IPIsPrivate(ip6_addr)) { |
| 109 rtc::IPAddress prefix = | 102 rtc::IPAddress prefix = |
| 110 rtc::TruncateIP(rtc::IPAddress(ip6_addr), it->prefix_length); | 103 rtc::TruncateIP(rtc::IPAddress(ip6_addr), it->prefix_length); |
| 111 rtc::Network* network = | 104 rtc::Network* network = |
| 112 new rtc::Network(it->name, it->name, prefix, it->prefix_length, | 105 new rtc::Network(it->name, it->name, prefix, it->prefix_length, |
| 113 ConvertConnectionTypeToAdapterType(it->type)); | 106 ConvertConnectionTypeToAdapterType(it->type)); |
| 114 network->AddIP(ip6_addr); | 107 network->AddIP(ip6_addr); |
| 115 networks.push_back(network); | 108 networks.push_back(network); |
| 116 } | 109 } |
| 117 } | 110 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 145 stats.ipv4_network_count); | 138 stats.ipv4_network_count); |
| 146 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv6Interfaces", | 139 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv6Interfaces", |
| 147 stats.ipv6_network_count); | 140 stats.ipv6_network_count); |
| 148 } | 141 } |
| 149 | 142 |
| 150 void IpcNetworkManager::SendNetworksChangedSignal() { | 143 void IpcNetworkManager::SendNetworksChangedSignal() { |
| 151 SignalNetworksChanged(); | 144 SignalNetworksChanged(); |
| 152 } | 145 } |
| 153 | 146 |
| 154 } // namespace content | 147 } // namespace content |
| OLD | NEW |