Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: content/renderer/p2p/ipc_network_manager.cc

Issue 1405963021: Add support for default local address in IpcNetworkManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IPAddressNumberToIPAddress. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 rtc::IPAddress ipv4;
85 jingle_glue::IPAddressNumberToIPAddress(default_ipv4_local_address, &ipv4);
86 rtc::IPAddress ipv6;
87 jingle_glue::IPAddressNumberToIPAddress(default_ipv6_local_address, &ipv6);
88 set_default_local_addresses(ipv4, ipv6);
89
80 // rtc::Network uses these prefix_length to compare network 90 // rtc::Network uses these prefix_length to compare network
81 // interfaces discovered. 91 // interfaces discovered.
82 std::vector<rtc::Network*> networks; 92 std::vector<rtc::Network*> networks;
83 for (net::NetworkInterfaceList::const_iterator it = list.begin(); 93 for (net::NetworkInterfaceList::const_iterator it = list.begin();
84 it != list.end(); it++) { 94 it != list.end(); it++) {
95 rtc::IPAddress ip_address;
85 if (it->address.size() == net::kIPv4AddressSize) { 96 if (it->address.size() == net::kIPv4AddressSize) {
86 uint32 address; 97 if (!jingle_glue::IPAddressNumberToIPAddress(it->address, &ip_address))
Sergey Ulanov 2015/11/11 21:10:02 This line is duplicated for ipv6 addresses below.
87 memcpy(&address, &it->address[0], sizeof(uint32)); 98 continue;
88 address = rtc::NetworkToHost32(address); 99 rtc::IPAddress prefix = rtc::TruncateIP(ip_address, it->prefix_length);
89 rtc::IPAddress prefix =
90 rtc::TruncateIP(rtc::IPAddress(address), it->prefix_length);
91 rtc::Network* network = 100 rtc::Network* network =
92 new rtc::Network(it->name, it->name, prefix, it->prefix_length, 101 new rtc::Network(it->name, it->name, prefix, it->prefix_length,
93 ConvertConnectionTypeToAdapterType(it->type)); 102 ConvertConnectionTypeToAdapterType(it->type));
94 network->AddIP(rtc::IPAddress(address)); 103 network->set_default_local_address_provider(this);
104 network->AddIP(ip_address);
95 networks.push_back(network); 105 networks.push_back(network);
96 } else if (it->address.size() == net::kIPv6AddressSize) { 106 } else if (it->address.size() == net::kIPv6AddressSize) {
97 in6_addr address; 107 if (!jingle_glue::IPAddressNumberToIPAddress(it->address, &ip_address))
98 memcpy(&address, &it->address[0], sizeof(in6_addr)); 108 continue;
99 rtc::InterfaceAddress ip6_addr(address, it->ip_address_attributes); 109 rtc::InterfaceAddress ip6_addr(ip_address, it->ip_address_attributes);
100 110
101 // Only allow non-deprecated IPv6 addresses which don't contain MAC. 111 // Only allow non-deprecated IPv6 addresses which don't contain MAC.
102 if (rtc::IPIsMacBased(ip6_addr) || 112 if (rtc::IPIsMacBased(ip6_addr) ||
103 (it->ip_address_attributes & net::IP_ADDRESS_ATTRIBUTE_DEPRECATED)) { 113 (it->ip_address_attributes & net::IP_ADDRESS_ATTRIBUTE_DEPRECATED)) {
104 continue; 114 continue;
105 } 115 }
106 116
107 if (!rtc::IPIsPrivate(ip6_addr)) { 117 if (!rtc::IPIsPrivate(ip6_addr)) {
108 rtc::IPAddress prefix = 118 rtc::IPAddress prefix = rtc::TruncateIP(ip6_addr, it->prefix_length);
Sergey Ulanov 2015/11/11 21:10:02 All this code (lines 118-124) is the same as for I
109 rtc::TruncateIP(rtc::IPAddress(ip6_addr), it->prefix_length);
110 rtc::Network* network = 119 rtc::Network* network =
111 new rtc::Network(it->name, it->name, prefix, it->prefix_length, 120 new rtc::Network(it->name, it->name, prefix, it->prefix_length,
112 ConvertConnectionTypeToAdapterType(it->type)); 121 ConvertConnectionTypeToAdapterType(it->type));
122 network->set_default_local_address_provider(this);
113 network->AddIP(ip6_addr); 123 network->AddIP(ip6_addr);
114 networks.push_back(network); 124 networks.push_back(network);
115 } 125 }
116 } 126 }
117 } 127 }
118 128
119 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 129 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
120 switches::kAllowLoopbackInPeerConnection)) { 130 switches::kAllowLoopbackInPeerConnection)) {
121 std::string name_v4("loopback_ipv4"); 131 std::string name_v4("loopback_ipv4");
122 rtc::IPAddress ip_address_v4(INADDR_LOOPBACK); 132 rtc::IPAddress ip_address_v4(INADDR_LOOPBACK);
123 rtc::Network* network_v4 = new rtc::Network( 133 rtc::Network* network_v4 = new rtc::Network(
124 name_v4, name_v4, ip_address_v4, 32, rtc::ADAPTER_TYPE_UNKNOWN); 134 name_v4, name_v4, ip_address_v4, 32, rtc::ADAPTER_TYPE_UNKNOWN);
135 network_v4->set_default_local_address_provider(this);
125 network_v4->AddIP(ip_address_v4); 136 network_v4->AddIP(ip_address_v4);
126 networks.push_back(network_v4); 137 networks.push_back(network_v4);
127 138
128 std::string name_v6("loopback_ipv6"); 139 std::string name_v6("loopback_ipv6");
129 rtc::IPAddress ip_address_v6(in6addr_loopback); 140 rtc::IPAddress ip_address_v6(in6addr_loopback);
130 rtc::Network* network_v6 = new rtc::Network( 141 rtc::Network* network_v6 = new rtc::Network(
131 name_v6, name_v6, ip_address_v6, 64, rtc::ADAPTER_TYPE_UNKNOWN); 142 name_v6, name_v6, ip_address_v6, 64, rtc::ADAPTER_TYPE_UNKNOWN);
143 network_v6->set_default_local_address_provider(this);
132 network_v6->AddIP(ip_address_v6); 144 network_v6->AddIP(ip_address_v6);
133 networks.push_back(network_v6); 145 networks.push_back(network_v6);
134 } 146 }
135 147
136 bool changed = false; 148 bool changed = false;
137 NetworkManager::Stats stats; 149 NetworkManager::Stats stats;
138 MergeNetworkList(networks, &changed, &stats); 150 MergeNetworkList(networks, &changed, &stats);
139 if (changed) 151 if (changed)
140 SignalNetworksChanged(); 152 SignalNetworksChanged();
141 153
142 // Send interface counts to UMA. 154 // Send interface counts to UMA.
143 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv4Interfaces", 155 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv4Interfaces",
144 stats.ipv4_network_count); 156 stats.ipv4_network_count);
145 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv6Interfaces", 157 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv6Interfaces",
146 stats.ipv6_network_count); 158 stats.ipv6_network_count);
147 } 159 }
148 160
149 void IpcNetworkManager::SendNetworksChangedSignal() { 161 void IpcNetworkManager::SendNetworksChangedSignal() {
150 SignalNetworksChanged(); 162 SignalNetworksChanged();
151 } 163 }
152 164
153 } // namespace content 165 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698