| 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 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/sys_byteorder.h" | 13 #include "base/sys_byteorder.h" |
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 16 #include "jingle/glue/utils.h" |
| 16 #include "net/base/ip_address_number.h" | 17 #include "net/base/ip_address_number.h" |
| 17 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 18 #include "net/base/network_change_notifier.h" | 19 #include "net/base/network_change_notifier.h" |
| 19 #include "net/base/network_interfaces.h" | 20 #include "net/base/network_interfaces.h" |
| 21 #include "third_party/webrtc/base/socketaddress.h" |
| 20 | 22 |
| 21 namespace content { | 23 namespace content { |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 rtc::AdapterType ConvertConnectionTypeToAdapterType( | 27 rtc::AdapterType ConvertConnectionTypeToAdapterType( |
| 26 net::NetworkChangeNotifier::ConnectionType type) { | 28 net::NetworkChangeNotifier::ConnectionType type) { |
| 27 switch (type) { | 29 switch (type) { |
| 28 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: | 30 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: |
| 29 return rtc::ADAPTER_TYPE_UNKNOWN; | 31 return rtc::ADAPTER_TYPE_UNKNOWN; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 66 } |
| 65 ++start_count_; | 67 ++start_count_; |
| 66 } | 68 } |
| 67 | 69 |
| 68 void IpcNetworkManager::StopUpdating() { | 70 void IpcNetworkManager::StopUpdating() { |
| 69 DCHECK_GT(start_count_, 0); | 71 DCHECK_GT(start_count_, 0); |
| 70 --start_count_; | 72 --start_count_; |
| 71 } | 73 } |
| 72 | 74 |
| 73 void IpcNetworkManager::OnNetworkListChanged( | 75 void IpcNetworkManager::OnNetworkListChanged( |
| 74 const net::NetworkInterfaceList& list) { | 76 const net::NetworkInterfaceList& list, |
| 75 | 77 const net::IPAddressNumber& default_ipv4_local_address, |
| 78 const net::IPAddressNumber& default_ipv6_local_address) { |
| 76 // Update flag if network list received for the first time. | 79 // Update flag if network list received for the first time. |
| 77 if (!network_list_received_) | 80 if (!network_list_received_) |
| 78 network_list_received_ = true; | 81 network_list_received_ = true; |
| 79 | 82 |
| 83 // Update the default local interfaces. |
| 84 set_default_local_addresses( |
| 85 jingle_glue::IPAddressNumberToIPAddress(default_ipv4_local_address), |
| 86 jingle_glue::IPAddressNumberToIPAddress(default_ipv6_local_address)); |
| 87 |
| 80 // rtc::Network uses these prefix_length to compare network | 88 // rtc::Network uses these prefix_length to compare network |
| 81 // interfaces discovered. | 89 // interfaces discovered. |
| 82 std::vector<rtc::Network*> networks; | 90 std::vector<rtc::Network*> networks; |
| 83 for (net::NetworkInterfaceList::const_iterator it = list.begin(); | 91 for (net::NetworkInterfaceList::const_iterator it = list.begin(); |
| 84 it != list.end(); it++) { | 92 it != list.end(); it++) { |
| 93 rtc::IPAddress ip_address = |
| 94 jingle_glue::IPAddressNumberToIPAddress(it->address); |
| 95 DCHECK(!ip_address.IsNil()); |
| 96 |
| 97 rtc::IPAddress prefix = rtc::TruncateIP(ip_address, it->prefix_length); |
| 98 scoped_ptr<rtc::Network> network( |
| 99 new rtc::Network(it->name, it->name, prefix, it->prefix_length, |
| 100 ConvertConnectionTypeToAdapterType(it->type))); |
| 101 network->set_default_local_address_provider(this); |
| 102 |
| 103 rtc::InterfaceAddress iface_addr; |
| 85 if (it->address.size() == net::kIPv4AddressSize) { | 104 if (it->address.size() == net::kIPv4AddressSize) { |
| 86 uint32 address; | 105 iface_addr = rtc::InterfaceAddress(ip_address); |
| 87 memcpy(&address, &it->address[0], sizeof(uint32)); | 106 } else { |
| 88 address = rtc::NetworkToHost32(address); | 107 DCHECK(it->address.size() == net::kIPv6AddressSize); |
| 89 rtc::IPAddress prefix = | 108 iface_addr = rtc::InterfaceAddress(ip_address, it->ip_address_attributes); |
| 90 rtc::TruncateIP(rtc::IPAddress(address), it->prefix_length); | |
| 91 rtc::Network* network = | |
| 92 new rtc::Network(it->name, it->name, prefix, it->prefix_length, | |
| 93 ConvertConnectionTypeToAdapterType(it->type)); | |
| 94 network->AddIP(rtc::IPAddress(address)); | |
| 95 networks.push_back(network); | |
| 96 } else if (it->address.size() == net::kIPv6AddressSize) { | |
| 97 in6_addr address; | |
| 98 memcpy(&address, &it->address[0], sizeof(in6_addr)); | |
| 99 rtc::InterfaceAddress ip6_addr(address, it->ip_address_attributes); | |
| 100 | 109 |
| 101 // Only allow non-deprecated IPv6 addresses which don't contain MAC. | 110 // Only allow non-private, non-deprecated IPv6 addresses which don't |
| 102 if (rtc::IPIsMacBased(ip6_addr) || | 111 // contain MAC. |
| 103 (it->ip_address_attributes & net::IP_ADDRESS_ATTRIBUTE_DEPRECATED)) { | 112 if (rtc::IPIsMacBased(iface_addr) || |
| 113 (it->ip_address_attributes & net::IP_ADDRESS_ATTRIBUTE_DEPRECATED) || |
| 114 rtc::IPIsPrivate(iface_addr)) { |
| 104 continue; | 115 continue; |
| 105 } | 116 } |
| 106 | |
| 107 if (!rtc::IPIsPrivate(ip6_addr)) { | |
| 108 rtc::IPAddress prefix = | |
| 109 rtc::TruncateIP(rtc::IPAddress(ip6_addr), it->prefix_length); | |
| 110 rtc::Network* network = | |
| 111 new rtc::Network(it->name, it->name, prefix, it->prefix_length, | |
| 112 ConvertConnectionTypeToAdapterType(it->type)); | |
| 113 network->AddIP(ip6_addr); | |
| 114 networks.push_back(network); | |
| 115 } | |
| 116 } | 117 } |
| 118 network->AddIP(iface_addr); |
| 119 networks.push_back(network.release()); |
| 117 } | 120 } |
| 118 | 121 |
| 119 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 122 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 120 switches::kAllowLoopbackInPeerConnection)) { | 123 switches::kAllowLoopbackInPeerConnection)) { |
| 121 std::string name_v4("loopback_ipv4"); | 124 std::string name_v4("loopback_ipv4"); |
| 122 rtc::IPAddress ip_address_v4(INADDR_LOOPBACK); | 125 rtc::IPAddress ip_address_v4(INADDR_LOOPBACK); |
| 123 rtc::Network* network_v4 = new rtc::Network( | 126 rtc::Network* network_v4 = new rtc::Network( |
| 124 name_v4, name_v4, ip_address_v4, 32, rtc::ADAPTER_TYPE_UNKNOWN); | 127 name_v4, name_v4, ip_address_v4, 32, rtc::ADAPTER_TYPE_UNKNOWN); |
| 128 network_v4->set_default_local_address_provider(this); |
| 125 network_v4->AddIP(ip_address_v4); | 129 network_v4->AddIP(ip_address_v4); |
| 126 networks.push_back(network_v4); | 130 networks.push_back(network_v4); |
| 127 | 131 |
| 128 std::string name_v6("loopback_ipv6"); | 132 std::string name_v6("loopback_ipv6"); |
| 129 rtc::IPAddress ip_address_v6(in6addr_loopback); | 133 rtc::IPAddress ip_address_v6(in6addr_loopback); |
| 130 rtc::Network* network_v6 = new rtc::Network( | 134 rtc::Network* network_v6 = new rtc::Network( |
| 131 name_v6, name_v6, ip_address_v6, 64, rtc::ADAPTER_TYPE_UNKNOWN); | 135 name_v6, name_v6, ip_address_v6, 64, rtc::ADAPTER_TYPE_UNKNOWN); |
| 136 network_v6->set_default_local_address_provider(this); |
| 132 network_v6->AddIP(ip_address_v6); | 137 network_v6->AddIP(ip_address_v6); |
| 133 networks.push_back(network_v6); | 138 networks.push_back(network_v6); |
| 134 } | 139 } |
| 135 | 140 |
| 136 bool changed = false; | 141 bool changed = false; |
| 137 NetworkManager::Stats stats; | 142 NetworkManager::Stats stats; |
| 138 MergeNetworkList(networks, &changed, &stats); | 143 MergeNetworkList(networks, &changed, &stats); |
| 139 if (changed) | 144 if (changed) |
| 140 SignalNetworksChanged(); | 145 SignalNetworksChanged(); |
| 141 | 146 |
| 142 // Send interface counts to UMA. | 147 // Send interface counts to UMA. |
| 143 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv4Interfaces", | 148 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv4Interfaces", |
| 144 stats.ipv4_network_count); | 149 stats.ipv4_network_count); |
| 145 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv6Interfaces", | 150 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv6Interfaces", |
| 146 stats.ipv6_network_count); | 151 stats.ipv6_network_count); |
| 147 } | 152 } |
| 148 | 153 |
| 149 void IpcNetworkManager::SendNetworksChangedSignal() { | 154 void IpcNetworkManager::SendNetworksChangedSignal() { |
| 150 SignalNetworksChanged(); | 155 SignalNetworksChanged(); |
| 151 } | 156 } |
| 152 | 157 |
| 153 } // namespace content | 158 } // namespace content |
| OLD | NEW |