2014-05-13 18:00:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "webrtc/base/network.h"
|
|
|
|
|
|
|
|
|
|
#if defined(WEBRTC_POSIX)
|
|
|
|
|
// linux/if.h can't be included at the same time as the posix sys/if.h, and
|
|
|
|
|
// it's transitively required by linux/route.h, so include that version on
|
|
|
|
|
// linux instead of the standard posix one.
|
|
|
|
|
#if defined(WEBRTC_LINUX)
|
|
|
|
|
#include <linux/if.h>
|
|
|
|
|
#include <linux/route.h>
|
|
|
|
|
#elif !defined(__native_client__)
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
|
|
#if defined(WEBRTC_ANDROID)
|
|
|
|
|
#include "webrtc/base/ifaddrs-android.h"
|
|
|
|
|
#elif !defined(__native_client__)
|
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif // WEBRTC_POSIX
|
|
|
|
|
|
|
|
|
|
#if defined(WEBRTC_WIN)
|
|
|
|
|
#include "webrtc/base/win32.h"
|
|
|
|
|
#include <Iphlpapi.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
#include "webrtc/base/logging.h"
|
|
|
|
|
#include "webrtc/base/scoped_ptr.h"
|
|
|
|
|
#include "webrtc/base/socket.h" // includes something that makes windows happy
|
|
|
|
|
#include "webrtc/base/stream.h"
|
|
|
|
|
#include "webrtc/base/stringencode.h"
|
|
|
|
|
#include "webrtc/base/thread.h"
|
|
|
|
|
|
|
|
|
|
namespace rtc {
|
|
|
|
|
namespace {
|
|
|
|
|
|
2015-01-30 00:09:28 +00:00
|
|
|
// Turning on IPv6 could make many IPv6 interfaces available for connectivity
|
|
|
|
|
// check and delay the call setup time. kMaxIPv6Networks is the default upper
|
|
|
|
|
// limit of IPv6 networks but could be changed by set_max_ipv6_networks().
|
|
|
|
|
const int kMaxIPv6Networks = 5;
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
const uint32 kUpdateNetworksMessage = 1;
|
|
|
|
|
const uint32 kSignalNetworksMessage = 2;
|
|
|
|
|
|
|
|
|
|
// Fetch list of networks every two seconds.
|
|
|
|
|
const int kNetworksUpdateIntervalMs = 2000;
|
|
|
|
|
|
|
|
|
|
const int kHighestNetworkPreference = 127;
|
|
|
|
|
|
2014-09-09 13:54:45 +00:00
|
|
|
typedef struct {
|
|
|
|
|
Network* net;
|
2014-09-09 23:42:40 +00:00
|
|
|
std::vector<InterfaceAddress> ips;
|
2014-09-09 13:54:45 +00:00
|
|
|
} AddressList;
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
bool CompareNetworks(const Network* a, const Network* b) {
|
|
|
|
|
if (a->prefix_length() == b->prefix_length()) {
|
|
|
|
|
if (a->name() == b->name()) {
|
|
|
|
|
return a->prefix() < b->prefix();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return a->name() < b->name();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SortNetworks(const Network* a, const Network* b) {
|
|
|
|
|
// Network types will be preferred above everything else while sorting
|
|
|
|
|
// Networks.
|
|
|
|
|
|
|
|
|
|
// Networks are sorted first by type.
|
|
|
|
|
if (a->type() != b->type()) {
|
|
|
|
|
return a->type() < b->type();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 22:37:29 +00:00
|
|
|
IPAddress ip_a = a->GetBestIP();
|
|
|
|
|
IPAddress ip_b = b->GetBestIP();
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
// After type, networks are sorted by IP address precedence values
|
|
|
|
|
// from RFC 3484-bis
|
2014-09-17 22:37:29 +00:00
|
|
|
if (IPAddressPrecedence(ip_a) != IPAddressPrecedence(ip_b)) {
|
|
|
|
|
return IPAddressPrecedence(ip_a) > IPAddressPrecedence(ip_b);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(mallinath) - Add VPN and Link speed conditions while sorting.
|
|
|
|
|
|
|
|
|
|
// Networks are sorted last by key.
|
|
|
|
|
return a->key() > b->key();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string AdapterTypeToString(AdapterType type) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case ADAPTER_TYPE_UNKNOWN:
|
|
|
|
|
return "Unknown";
|
|
|
|
|
case ADAPTER_TYPE_ETHERNET:
|
|
|
|
|
return "Ethernet";
|
|
|
|
|
case ADAPTER_TYPE_WIFI:
|
|
|
|
|
return "Wifi";
|
|
|
|
|
case ADAPTER_TYPE_CELLULAR:
|
|
|
|
|
return "Cellular";
|
|
|
|
|
case ADAPTER_TYPE_VPN:
|
|
|
|
|
return "VPN";
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
case ADAPTER_TYPE_LOOPBACK:
|
|
|
|
|
return "Loopback";
|
2014-05-13 18:00:26 +00:00
|
|
|
default:
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
DCHECK(false) << "Invalid type " << type;
|
2014-05-13 18:00:26 +00:00
|
|
|
return std::string();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 14:43:20 +00:00
|
|
|
bool IsIgnoredIPv6(const IPAddress& ip) {
|
|
|
|
|
if (ip.family() != AF_INET6) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Link-local addresses require scope id to be bound successfully.
|
|
|
|
|
// However, our IPAddress structure doesn't carry that so the
|
|
|
|
|
// information is lost and causes binding failure.
|
|
|
|
|
if (IPIsLinkLocal(ip)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Any MAC based IPv6 should be avoided to prevent the MAC tracking.
|
|
|
|
|
if (IPIsMacBased(ip)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
std::string MakeNetworkKey(const std::string& name, const IPAddress& prefix,
|
|
|
|
|
int prefix_length) {
|
|
|
|
|
std::ostringstream ost;
|
|
|
|
|
ost << name << "%" << prefix.ToString() << "/" << prefix_length;
|
|
|
|
|
return ost.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetworkManager::NetworkManager() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetworkManager::~NetworkManager() {
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-30 00:09:28 +00:00
|
|
|
NetworkManagerBase::NetworkManagerBase()
|
2015-08-19 10:32:46 -07:00
|
|
|
: enumeration_permission_(NetworkManager::kEnumerationAllowed),
|
|
|
|
|
max_ipv6_networks_(kMaxIPv6Networks),
|
|
|
|
|
ipv6_enabled_(true) {
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetworkManagerBase::~NetworkManagerBase() {
|
2014-12-01 23:18:27 +00:00
|
|
|
for (const auto& kv : networks_map_) {
|
|
|
|
|
delete kv.second;
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 10:32:46 -07:00
|
|
|
NetworkManager::EnumerationPermission
|
|
|
|
|
NetworkManagerBase::enumeration_permission() const {
|
|
|
|
|
return enumeration_permission_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 18:44:01 +00:00
|
|
|
void NetworkManagerBase::GetAnyAddressNetworks(NetworkList* networks) {
|
|
|
|
|
if (!ipv4_any_address_network_) {
|
|
|
|
|
const rtc::IPAddress ipv4_any_address(INADDR_ANY);
|
|
|
|
|
ipv4_any_address_network_.reset(
|
|
|
|
|
new rtc::Network("any", "any", ipv4_any_address, 0));
|
|
|
|
|
ipv4_any_address_network_->AddIP(ipv4_any_address);
|
|
|
|
|
}
|
|
|
|
|
networks->push_back(ipv4_any_address_network_.get());
|
|
|
|
|
|
|
|
|
|
if (ipv6_enabled()) {
|
|
|
|
|
if (!ipv6_any_address_network_) {
|
|
|
|
|
const rtc::IPAddress ipv6_any_address(in6addr_any);
|
|
|
|
|
ipv6_any_address_network_.reset(
|
|
|
|
|
new rtc::Network("any", "any", ipv6_any_address, 0));
|
|
|
|
|
ipv6_any_address_network_->AddIP(ipv6_any_address);
|
|
|
|
|
}
|
|
|
|
|
networks->push_back(ipv6_any_address_network_.get());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
void NetworkManagerBase::GetNetworks(NetworkList* result) const {
|
2015-01-30 00:09:28 +00:00
|
|
|
int ipv6_networks = 0;
|
|
|
|
|
result->clear();
|
|
|
|
|
for (Network* network : networks_) {
|
|
|
|
|
// Keep the number of IPv6 networks under |max_ipv6_networks_|.
|
|
|
|
|
if (network->prefix().family() == AF_INET6) {
|
|
|
|
|
if (ipv6_networks >= max_ipv6_networks_) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
++ipv6_networks;
|
|
|
|
|
}
|
|
|
|
|
result->push_back(network);
|
|
|
|
|
}
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetworkManagerBase::MergeNetworkList(const NetworkList& new_networks,
|
|
|
|
|
bool* changed) {
|
2015-01-28 19:34:05 +00:00
|
|
|
NetworkManager::Stats stats;
|
|
|
|
|
MergeNetworkList(new_networks, changed, &stats);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetworkManagerBase::MergeNetworkList(const NetworkList& new_networks,
|
|
|
|
|
bool* changed,
|
|
|
|
|
NetworkManager::Stats* stats) {
|
2014-09-09 13:54:45 +00:00
|
|
|
// AddressList in this map will track IP addresses for all Networks
|
|
|
|
|
// with the same key.
|
|
|
|
|
std::map<std::string, AddressList> consolidated_address_list;
|
2014-05-13 18:00:26 +00:00
|
|
|
NetworkList list(new_networks);
|
2014-09-09 13:54:45 +00:00
|
|
|
|
|
|
|
|
// Result of Network merge. Element in this list should have unique key.
|
2014-05-13 18:00:26 +00:00
|
|
|
NetworkList merged_list;
|
|
|
|
|
std::sort(list.begin(), list.end(), CompareNetworks);
|
|
|
|
|
|
|
|
|
|
*changed = false;
|
|
|
|
|
|
|
|
|
|
if (networks_.size() != list.size())
|
|
|
|
|
*changed = true;
|
|
|
|
|
|
|
|
|
|
// First, build a set of network-keys to the ipaddresses.
|
2014-12-01 23:18:27 +00:00
|
|
|
for (Network* network : list) {
|
2014-05-13 18:00:26 +00:00
|
|
|
bool might_add_to_merged_list = false;
|
2014-12-01 23:18:27 +00:00
|
|
|
std::string key = MakeNetworkKey(network->name(),
|
|
|
|
|
network->prefix(),
|
|
|
|
|
network->prefix_length());
|
2014-09-09 13:54:45 +00:00
|
|
|
if (consolidated_address_list.find(key) ==
|
|
|
|
|
consolidated_address_list.end()) {
|
|
|
|
|
AddressList addrlist;
|
2014-12-01 23:18:27 +00:00
|
|
|
addrlist.net = network;
|
2014-09-09 13:54:45 +00:00
|
|
|
consolidated_address_list[key] = addrlist;
|
2014-05-13 18:00:26 +00:00
|
|
|
might_add_to_merged_list = true;
|
|
|
|
|
}
|
2014-12-01 23:18:27 +00:00
|
|
|
const std::vector<InterfaceAddress>& addresses = network->GetIPs();
|
2014-09-09 13:54:45 +00:00
|
|
|
AddressList& current_list = consolidated_address_list[key];
|
2014-12-01 23:18:27 +00:00
|
|
|
for (const InterfaceAddress& address : addresses) {
|
|
|
|
|
current_list.ips.push_back(address);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
if (!might_add_to_merged_list) {
|
2014-12-01 23:18:27 +00:00
|
|
|
delete network;
|
2015-01-28 19:34:05 +00:00
|
|
|
} else {
|
|
|
|
|
if (current_list.ips[0].family() == AF_INET) {
|
|
|
|
|
stats->ipv4_network_count++;
|
|
|
|
|
} else {
|
|
|
|
|
ASSERT(current_list.ips[0].family() == AF_INET6);
|
|
|
|
|
stats->ipv6_network_count++;
|
|
|
|
|
}
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Next, look for existing network objects to re-use.
|
2014-12-01 23:18:27 +00:00
|
|
|
for (const auto& kv : consolidated_address_list) {
|
|
|
|
|
const std::string& key = kv.first;
|
|
|
|
|
Network* net = kv.second.net;
|
|
|
|
|
auto existing = networks_map_.find(key);
|
2014-05-13 18:00:26 +00:00
|
|
|
if (existing == networks_map_.end()) {
|
|
|
|
|
// This network is new. Place it in the network map.
|
|
|
|
|
merged_list.push_back(net);
|
|
|
|
|
networks_map_[key] = net;
|
2014-09-09 13:54:45 +00:00
|
|
|
// Also, we might have accumulated IPAddresses from the first
|
|
|
|
|
// step, set it here.
|
2014-12-01 23:18:27 +00:00
|
|
|
net->SetIPs(kv.second.ips, true);
|
2014-05-13 18:00:26 +00:00
|
|
|
*changed = true;
|
|
|
|
|
} else {
|
|
|
|
|
// This network exists in the map already. Reset its IP addresses.
|
2014-12-01 23:18:27 +00:00
|
|
|
*changed = existing->second->SetIPs(kv.second.ips, *changed);
|
2014-05-13 18:00:26 +00:00
|
|
|
merged_list.push_back(existing->second);
|
|
|
|
|
if (existing->second != net) {
|
|
|
|
|
delete net;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
networks_ = merged_list;
|
|
|
|
|
|
|
|
|
|
// If the network lists changes, we resort it.
|
2015-01-28 19:34:05 +00:00
|
|
|
if (*changed) {
|
2014-05-13 18:00:26 +00:00
|
|
|
std::sort(networks_.begin(), networks_.end(), SortNetworks);
|
|
|
|
|
// Now network interfaces are sorted, we should set the preference value
|
|
|
|
|
// for each of the interfaces we are planning to use.
|
|
|
|
|
// Preference order of network interfaces might have changed from previous
|
|
|
|
|
// sorting due to addition of higher preference network interface.
|
|
|
|
|
// Since we have already sorted the network interfaces based on our
|
|
|
|
|
// requirements, we will just assign a preference value starting with 127,
|
|
|
|
|
// in decreasing order.
|
|
|
|
|
int pref = kHighestNetworkPreference;
|
2014-12-01 23:18:27 +00:00
|
|
|
for (Network* network : networks_) {
|
|
|
|
|
network->set_preference(pref);
|
2014-05-13 18:00:26 +00:00
|
|
|
if (pref > 0) {
|
|
|
|
|
--pref;
|
|
|
|
|
} else {
|
|
|
|
|
LOG(LS_ERROR) << "Too many network interfaces to handle!";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BasicNetworkManager::BasicNetworkManager()
|
|
|
|
|
: thread_(NULL), sent_first_update_(false), start_count_(0),
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
network_ignore_mask_(kDefaultNetworkIgnoreMask),
|
2014-05-13 18:00:26 +00:00
|
|
|
ignore_non_default_routes_(false) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BasicNetworkManager::~BasicNetworkManager() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if defined(__native_client__)
|
|
|
|
|
|
|
|
|
|
bool BasicNetworkManager::CreateNetworks(bool include_ignored,
|
|
|
|
|
NetworkList* networks) const {
|
|
|
|
|
ASSERT(false);
|
|
|
|
|
LOG(LS_WARNING) << "BasicNetworkManager doesn't work on NaCl yet";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#elif defined(WEBRTC_POSIX)
|
|
|
|
|
void BasicNetworkManager::ConvertIfAddrs(struct ifaddrs* interfaces,
|
|
|
|
|
bool include_ignored,
|
|
|
|
|
NetworkList* networks) const {
|
|
|
|
|
NetworkMap current_networks;
|
|
|
|
|
for (struct ifaddrs* cursor = interfaces;
|
|
|
|
|
cursor != NULL; cursor = cursor->ifa_next) {
|
|
|
|
|
IPAddress prefix;
|
|
|
|
|
IPAddress mask;
|
|
|
|
|
IPAddress ip;
|
|
|
|
|
int scope_id = 0;
|
|
|
|
|
|
|
|
|
|
// Some interfaces may not have address assigned.
|
|
|
|
|
if (!cursor->ifa_addr || !cursor->ifa_netmask)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
switch (cursor->ifa_addr->sa_family) {
|
|
|
|
|
case AF_INET: {
|
|
|
|
|
ip = IPAddress(
|
|
|
|
|
reinterpret_cast<sockaddr_in*>(cursor->ifa_addr)->sin_addr);
|
|
|
|
|
mask = IPAddress(
|
|
|
|
|
reinterpret_cast<sockaddr_in*>(cursor->ifa_netmask)->sin_addr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AF_INET6: {
|
|
|
|
|
if (ipv6_enabled()) {
|
|
|
|
|
ip = IPAddress(
|
|
|
|
|
reinterpret_cast<sockaddr_in6*>(cursor->ifa_addr)->sin6_addr);
|
2015-03-17 14:43:20 +00:00
|
|
|
|
|
|
|
|
if (IsIgnoredIPv6(ip)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
mask = IPAddress(
|
|
|
|
|
reinterpret_cast<sockaddr_in6*>(cursor->ifa_netmask)->sin6_addr);
|
|
|
|
|
scope_id =
|
|
|
|
|
reinterpret_cast<sockaddr_in6*>(cursor->ifa_addr)->sin6_scope_id;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int prefix_length = CountIPMaskBits(mask);
|
|
|
|
|
prefix = TruncateIP(ip, prefix_length);
|
|
|
|
|
std::string key = MakeNetworkKey(std::string(cursor->ifa_name),
|
|
|
|
|
prefix, prefix_length);
|
2014-12-01 23:18:27 +00:00
|
|
|
auto existing_network = current_networks.find(key);
|
2014-05-13 18:00:26 +00:00
|
|
|
if (existing_network == current_networks.end()) {
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
AdapterType adapter_type = ADAPTER_TYPE_UNKNOWN;
|
|
|
|
|
if (cursor->ifa_flags & IFF_LOOPBACK) {
|
|
|
|
|
adapter_type = ADAPTER_TYPE_LOOPBACK;
|
|
|
|
|
}
|
2015-04-07 11:51:56 -07:00
|
|
|
#if defined(WEBRTC_IOS)
|
|
|
|
|
// Cell networks are pdp_ipN on iOS.
|
|
|
|
|
if (strncmp(cursor->ifa_name, "pdp_ip", 6) == 0) {
|
|
|
|
|
adapter_type = ADAPTER_TYPE_CELLULAR;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
// TODO(phoglund): Need to recognize other types as well.
|
2014-05-13 18:00:26 +00:00
|
|
|
scoped_ptr<Network> network(new Network(cursor->ifa_name,
|
|
|
|
|
cursor->ifa_name,
|
|
|
|
|
prefix,
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
prefix_length,
|
|
|
|
|
adapter_type));
|
2014-05-13 18:00:26 +00:00
|
|
|
network->set_scope_id(scope_id);
|
|
|
|
|
network->AddIP(ip);
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
network->set_ignored(IsIgnoredNetwork(*network));
|
2014-05-13 18:00:26 +00:00
|
|
|
if (include_ignored || !network->ignored()) {
|
|
|
|
|
networks->push_back(network.release());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
(*existing_network).second->AddIP(ip);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BasicNetworkManager::CreateNetworks(bool include_ignored,
|
|
|
|
|
NetworkList* networks) const {
|
|
|
|
|
struct ifaddrs* interfaces;
|
|
|
|
|
int error = getifaddrs(&interfaces);
|
|
|
|
|
if (error != 0) {
|
|
|
|
|
LOG_ERR(LERROR) << "getifaddrs failed to gather interface data: " << error;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConvertIfAddrs(interfaces, include_ignored, networks);
|
|
|
|
|
|
|
|
|
|
freeifaddrs(interfaces);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#elif defined(WEBRTC_WIN)
|
|
|
|
|
|
|
|
|
|
unsigned int GetPrefix(PIP_ADAPTER_PREFIX prefixlist,
|
|
|
|
|
const IPAddress& ip, IPAddress* prefix) {
|
|
|
|
|
IPAddress current_prefix;
|
|
|
|
|
IPAddress best_prefix;
|
|
|
|
|
unsigned int best_length = 0;
|
|
|
|
|
while (prefixlist) {
|
|
|
|
|
// Look for the longest matching prefix in the prefixlist.
|
|
|
|
|
if (prefixlist->Address.lpSockaddr == NULL ||
|
|
|
|
|
prefixlist->Address.lpSockaddr->sa_family != ip.family()) {
|
|
|
|
|
prefixlist = prefixlist->Next;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
switch (prefixlist->Address.lpSockaddr->sa_family) {
|
|
|
|
|
case AF_INET: {
|
|
|
|
|
sockaddr_in* v4_addr =
|
|
|
|
|
reinterpret_cast<sockaddr_in*>(prefixlist->Address.lpSockaddr);
|
|
|
|
|
current_prefix = IPAddress(v4_addr->sin_addr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AF_INET6: {
|
|
|
|
|
sockaddr_in6* v6_addr =
|
|
|
|
|
reinterpret_cast<sockaddr_in6*>(prefixlist->Address.lpSockaddr);
|
|
|
|
|
current_prefix = IPAddress(v6_addr->sin6_addr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
prefixlist = prefixlist->Next;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (TruncateIP(ip, prefixlist->PrefixLength) == current_prefix &&
|
|
|
|
|
prefixlist->PrefixLength > best_length) {
|
|
|
|
|
best_prefix = current_prefix;
|
|
|
|
|
best_length = prefixlist->PrefixLength;
|
|
|
|
|
}
|
|
|
|
|
prefixlist = prefixlist->Next;
|
|
|
|
|
}
|
|
|
|
|
*prefix = best_prefix;
|
|
|
|
|
return best_length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BasicNetworkManager::CreateNetworks(bool include_ignored,
|
|
|
|
|
NetworkList* networks) const {
|
|
|
|
|
NetworkMap current_networks;
|
|
|
|
|
// MSDN recommends a 15KB buffer for the first try at GetAdaptersAddresses.
|
|
|
|
|
size_t buffer_size = 16384;
|
|
|
|
|
scoped_ptr<char[]> adapter_info(new char[buffer_size]);
|
|
|
|
|
PIP_ADAPTER_ADDRESSES adapter_addrs =
|
|
|
|
|
reinterpret_cast<PIP_ADAPTER_ADDRESSES>(adapter_info.get());
|
|
|
|
|
int adapter_flags = (GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_ANYCAST |
|
|
|
|
|
GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_INCLUDE_PREFIX);
|
|
|
|
|
int ret = 0;
|
|
|
|
|
do {
|
|
|
|
|
adapter_info.reset(new char[buffer_size]);
|
|
|
|
|
adapter_addrs = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(adapter_info.get());
|
|
|
|
|
ret = GetAdaptersAddresses(AF_UNSPEC, adapter_flags,
|
|
|
|
|
0, adapter_addrs,
|
|
|
|
|
reinterpret_cast<PULONG>(&buffer_size));
|
|
|
|
|
} while (ret == ERROR_BUFFER_OVERFLOW);
|
|
|
|
|
if (ret != ERROR_SUCCESS) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
int count = 0;
|
|
|
|
|
while (adapter_addrs) {
|
|
|
|
|
if (adapter_addrs->OperStatus == IfOperStatusUp) {
|
|
|
|
|
PIP_ADAPTER_UNICAST_ADDRESS address = adapter_addrs->FirstUnicastAddress;
|
|
|
|
|
PIP_ADAPTER_PREFIX prefixlist = adapter_addrs->FirstPrefix;
|
|
|
|
|
std::string name;
|
|
|
|
|
std::string description;
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
name = ToUtf8(adapter_addrs->FriendlyName,
|
|
|
|
|
wcslen(adapter_addrs->FriendlyName));
|
|
|
|
|
#endif
|
|
|
|
|
description = ToUtf8(adapter_addrs->Description,
|
|
|
|
|
wcslen(adapter_addrs->Description));
|
|
|
|
|
for (; address; address = address->Next) {
|
|
|
|
|
#ifndef _DEBUG
|
|
|
|
|
name = rtc::ToString(count);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
IPAddress ip;
|
|
|
|
|
int scope_id = 0;
|
|
|
|
|
scoped_ptr<Network> network;
|
|
|
|
|
switch (address->Address.lpSockaddr->sa_family) {
|
|
|
|
|
case AF_INET: {
|
|
|
|
|
sockaddr_in* v4_addr =
|
|
|
|
|
reinterpret_cast<sockaddr_in*>(address->Address.lpSockaddr);
|
|
|
|
|
ip = IPAddress(v4_addr->sin_addr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AF_INET6: {
|
|
|
|
|
if (ipv6_enabled()) {
|
|
|
|
|
sockaddr_in6* v6_addr =
|
|
|
|
|
reinterpret_cast<sockaddr_in6*>(address->Address.lpSockaddr);
|
|
|
|
|
scope_id = v6_addr->sin6_scope_id;
|
|
|
|
|
ip = IPAddress(v6_addr->sin6_addr);
|
2015-03-17 14:43:20 +00:00
|
|
|
|
|
|
|
|
if (IsIgnoredIPv6(ip)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IPAddress prefix;
|
|
|
|
|
int prefix_length = GetPrefix(prefixlist, ip, &prefix);
|
|
|
|
|
std::string key = MakeNetworkKey(name, prefix, prefix_length);
|
2014-12-01 23:18:27 +00:00
|
|
|
auto existing_network = current_networks.find(key);
|
2014-05-13 18:00:26 +00:00
|
|
|
if (existing_network == current_networks.end()) {
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
AdapterType adapter_type = ADAPTER_TYPE_UNKNOWN;
|
|
|
|
|
if (adapter_addrs->IfType == IF_TYPE_SOFTWARE_LOOPBACK) {
|
|
|
|
|
// TODO(phoglund): Need to recognize other types as well.
|
|
|
|
|
adapter_type = ADAPTER_TYPE_LOOPBACK;
|
|
|
|
|
}
|
2014-05-13 18:00:26 +00:00
|
|
|
scoped_ptr<Network> network(new Network(name,
|
|
|
|
|
description,
|
|
|
|
|
prefix,
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
prefix_length,
|
|
|
|
|
adapter_type));
|
2014-05-13 18:00:26 +00:00
|
|
|
network->set_scope_id(scope_id);
|
|
|
|
|
network->AddIP(ip);
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
bool ignored = IsIgnoredNetwork(*network);
|
|
|
|
|
network->set_ignored(ignored);
|
2014-05-13 18:00:26 +00:00
|
|
|
if (include_ignored || !network->ignored()) {
|
|
|
|
|
networks->push_back(network.release());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
(*existing_network).second->AddIP(ip);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Count is per-adapter - all 'Networks' created from the same
|
|
|
|
|
// adapter need to have the same name.
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
adapter_addrs = adapter_addrs->Next;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-09-17 22:37:29 +00:00
|
|
|
#endif // WEBRTC_WIN
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
#if defined(WEBRTC_LINUX)
|
|
|
|
|
bool IsDefaultRoute(const std::string& network_name) {
|
|
|
|
|
FileStream fs;
|
|
|
|
|
if (!fs.Open("/proc/net/route", "r", NULL)) {
|
|
|
|
|
LOG(LS_WARNING) << "Couldn't read /proc/net/route, skipping default "
|
|
|
|
|
<< "route check (assuming everything is a default route).";
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
std::string line;
|
|
|
|
|
while (fs.ReadLine(&line) == SR_SUCCESS) {
|
|
|
|
|
char iface_name[256];
|
|
|
|
|
unsigned int iface_ip, iface_gw, iface_mask, iface_flags;
|
|
|
|
|
if (sscanf(line.c_str(),
|
|
|
|
|
"%255s %8X %8X %4X %*d %*u %*d %8X",
|
|
|
|
|
iface_name, &iface_ip, &iface_gw,
|
|
|
|
|
&iface_flags, &iface_mask) == 5 &&
|
|
|
|
|
network_name == iface_name &&
|
|
|
|
|
iface_mask == 0 &&
|
|
|
|
|
(iface_flags & (RTF_UP | RTF_HOST)) == RTF_UP) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
bool BasicNetworkManager::IsIgnoredNetwork(const Network& network) const {
|
|
|
|
|
// Ignore networks on the explicit ignore list.
|
2014-12-01 23:18:27 +00:00
|
|
|
for (const std::string& ignored_name : network_ignore_list_) {
|
|
|
|
|
if (network.name() == ignored_name) {
|
2014-05-13 18:00:26 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
|
|
|
|
|
if (network_ignore_mask_ & network.type()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-05-13 18:00:26 +00:00
|
|
|
#if defined(WEBRTC_POSIX)
|
2015-01-07 17:20:52 +00:00
|
|
|
// Filter out VMware/VirtualBox interfaces, typically named vmnet1,
|
|
|
|
|
// vmnet8, or vboxnet0.
|
2014-05-13 18:00:26 +00:00
|
|
|
if (strncmp(network.name().c_str(), "vmnet", 5) == 0 ||
|
2015-01-07 17:20:52 +00:00
|
|
|
strncmp(network.name().c_str(), "vnic", 4) == 0 ||
|
|
|
|
|
strncmp(network.name().c_str(), "vboxnet", 7) == 0) {
|
2014-05-13 18:00:26 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#if defined(WEBRTC_LINUX)
|
|
|
|
|
// Make sure this is a default route, if we're ignoring non-defaults.
|
|
|
|
|
if (ignore_non_default_routes_ && !IsDefaultRoute(network.name())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#elif defined(WEBRTC_WIN)
|
|
|
|
|
// Ignore any HOST side vmware adapters with a description like:
|
|
|
|
|
// VMware Virtual Ethernet Adapter for VMnet1
|
|
|
|
|
// but don't ignore any GUEST side adapters with a description like:
|
|
|
|
|
// VMware Accelerated AMD PCNet Adapter #2
|
|
|
|
|
if (strstr(network.description().c_str(), "VMnet") != NULL) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Ignore any networks with a 0.x.y.z IP
|
|
|
|
|
if (network.prefix().family() == AF_INET) {
|
|
|
|
|
return (network.prefix().v4AddressAsHostOrderInteger() < 0x01000000);
|
|
|
|
|
}
|
2015-03-05 04:38:29 +00:00
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BasicNetworkManager::StartUpdating() {
|
|
|
|
|
thread_ = Thread::Current();
|
|
|
|
|
if (start_count_) {
|
|
|
|
|
// If network interfaces are already discovered and signal is sent,
|
|
|
|
|
// we should trigger network signal immediately for the new clients
|
|
|
|
|
// to start allocating ports.
|
|
|
|
|
if (sent_first_update_)
|
|
|
|
|
thread_->Post(this, kSignalNetworksMessage);
|
|
|
|
|
} else {
|
|
|
|
|
thread_->Post(this, kUpdateNetworksMessage);
|
|
|
|
|
}
|
|
|
|
|
++start_count_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BasicNetworkManager::StopUpdating() {
|
|
|
|
|
ASSERT(Thread::Current() == thread_);
|
|
|
|
|
if (!start_count_)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
--start_count_;
|
|
|
|
|
if (!start_count_) {
|
|
|
|
|
thread_->Clear(this);
|
|
|
|
|
sent_first_update_ = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BasicNetworkManager::OnMessage(Message* msg) {
|
|
|
|
|
switch (msg->message_id) {
|
|
|
|
|
case kUpdateNetworksMessage: {
|
|
|
|
|
DoUpdateNetworks();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kSignalNetworksMessage: {
|
|
|
|
|
SignalNetworksChanged();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
ASSERT(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BasicNetworkManager::DoUpdateNetworks() {
|
|
|
|
|
if (!start_count_)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ASSERT(Thread::Current() == thread_);
|
|
|
|
|
|
|
|
|
|
NetworkList list;
|
|
|
|
|
if (!CreateNetworks(false, &list)) {
|
|
|
|
|
SignalError();
|
|
|
|
|
} else {
|
|
|
|
|
bool changed;
|
|
|
|
|
MergeNetworkList(list, &changed);
|
|
|
|
|
if (changed || !sent_first_update_) {
|
|
|
|
|
SignalNetworksChanged();
|
|
|
|
|
sent_first_update_ = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
thread_->PostDelayed(kNetworksUpdateIntervalMs, this, kUpdateNetworksMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BasicNetworkManager::DumpNetworks(bool include_ignored) {
|
|
|
|
|
NetworkList list;
|
|
|
|
|
CreateNetworks(include_ignored, &list);
|
|
|
|
|
LOG(LS_INFO) << "NetworkManager detected " << list.size() << " networks:";
|
2014-12-01 23:18:27 +00:00
|
|
|
for (const Network* network : list) {
|
2014-05-13 18:00:26 +00:00
|
|
|
if (!network->ignored() || include_ignored) {
|
|
|
|
|
LOG(LS_INFO) << network->ToString() << ": "
|
|
|
|
|
<< network->description()
|
|
|
|
|
<< ((network->ignored()) ? ", Ignored" : "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Release the network list created previously.
|
|
|
|
|
// Do this in a seperated for loop for better readability.
|
2014-12-01 23:18:27 +00:00
|
|
|
for (Network* network : list) {
|
|
|
|
|
delete network;
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Network::Network(const std::string& name, const std::string& desc,
|
|
|
|
|
const IPAddress& prefix, int prefix_length)
|
|
|
|
|
: name_(name), description_(desc), prefix_(prefix),
|
|
|
|
|
prefix_length_(prefix_length),
|
|
|
|
|
key_(MakeNetworkKey(name, prefix, prefix_length)), scope_id_(0),
|
|
|
|
|
ignored_(false), type_(ADAPTER_TYPE_UNKNOWN), preference_(0) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Network::Network(const std::string& name, const std::string& desc,
|
|
|
|
|
const IPAddress& prefix, int prefix_length, AdapterType type)
|
|
|
|
|
: name_(name), description_(desc), prefix_(prefix),
|
|
|
|
|
prefix_length_(prefix_length),
|
|
|
|
|
key_(MakeNetworkKey(name, prefix, prefix_length)), scope_id_(0),
|
|
|
|
|
ignored_(false), type_(type), preference_(0) {
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-09 22:21:53 +00:00
|
|
|
Network::~Network() = default;
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
// Sets the addresses of this network. Returns true if the address set changed.
|
|
|
|
|
// Change detection is short circuited if the changed argument is true.
|
2014-09-09 23:42:40 +00:00
|
|
|
bool Network::SetIPs(const std::vector<InterfaceAddress>& ips, bool changed) {
|
2014-05-13 18:00:26 +00:00
|
|
|
// Detect changes with a nested loop; n-squared but we expect on the order
|
|
|
|
|
// of 2-3 addresses per network.
|
2014-12-01 23:18:27 +00:00
|
|
|
changed = changed || ips.size() != ips_.size();
|
|
|
|
|
if (!changed) {
|
|
|
|
|
for (const InterfaceAddress& ip : ips) {
|
|
|
|
|
if (std::find(ips_.begin(), ips_.end(), ip) == ips_.end()) {
|
|
|
|
|
changed = true;
|
|
|
|
|
break;
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-01 23:18:27 +00:00
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
ips_ = ips;
|
|
|
|
|
return changed;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:42:22 +00:00
|
|
|
// Select the best IP address to use from this Network.
|
2014-09-17 22:37:29 +00:00
|
|
|
IPAddress Network::GetBestIP() const {
|
2014-09-09 23:42:40 +00:00
|
|
|
if (ips_.size() == 0) {
|
|
|
|
|
return IPAddress();
|
|
|
|
|
}
|
2014-09-17 22:37:29 +00:00
|
|
|
|
|
|
|
|
if (prefix_.family() == AF_INET) {
|
|
|
|
|
return static_cast<IPAddress>(ips_.at(0));
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:42:22 +00:00
|
|
|
InterfaceAddress selected_ip, ula_ip;
|
|
|
|
|
|
2014-12-01 23:18:27 +00:00
|
|
|
for (const InterfaceAddress& ip : ips_) {
|
2015-02-27 18:42:22 +00:00
|
|
|
// Ignore any address which has been deprecated already.
|
|
|
|
|
if (ip.ipv6_flags() & IPV6_ADDRESS_FLAG_DEPRECATED)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// ULA address should only be returned when we have no other
|
|
|
|
|
// global IP.
|
|
|
|
|
if (IPIsULA(static_cast<const IPAddress&>(ip))) {
|
|
|
|
|
ula_ip = ip;
|
2014-09-17 22:37:29 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2015-02-27 18:42:22 +00:00
|
|
|
selected_ip = ip;
|
|
|
|
|
|
|
|
|
|
// Search could stop once a temporary non-deprecated one is found.
|
|
|
|
|
if (ip.ipv6_flags() & IPV6_ADDRESS_FLAG_TEMPORARY)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-09-17 22:37:29 +00:00
|
|
|
|
2015-02-27 18:42:22 +00:00
|
|
|
// No proper global IPv6 address found, use ULA instead.
|
|
|
|
|
if (IPIsUnspec(selected_ip) && !IPIsUnspec(ula_ip)) {
|
|
|
|
|
selected_ip = ula_ip;
|
2014-09-17 22:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:42:22 +00:00
|
|
|
return static_cast<IPAddress>(selected_ip);
|
2014-09-17 22:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Network::ToString() const {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
// Print out the first space-terminated token of the network desc, plus
|
|
|
|
|
// the IP address.
|
|
|
|
|
ss << "Net[" << description_.substr(0, description_.find(' '))
|
|
|
|
|
<< ":" << prefix_.ToSensitiveString() << "/" << prefix_length_
|
|
|
|
|
<< ":" << AdapterTypeToString(type_) << "]";
|
|
|
|
|
return ss.str();
|
2014-09-09 23:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
} // namespace rtc
|