Commit 45d667c5 authored by guoweis's avatar guoweis Committed by Commit bot

Interface change for net_util.h for WebRTC IPv6 support.

Migrated from https://codereview.chromium.org/538243003/ as it was created under wrong identity.

Review URL: https://codereview.chromium.org/580283002

Cr-Commit-Position: refs/heads/master@{#296068}
parent e33aa242
......@@ -83,24 +83,40 @@ TEST_F(DialServiceTest, TestMultipleNetworkInterfaces) {
dial_service_.discovery_active_ = true;
net::NetworkInterfaceList interface_list;
interface_list.push_back(
net::NetworkInterface("network1", "network1", 0,
net::NetworkInterface("network1",
"network1",
0,
net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
mock_ip_, 0));
mock_ip_,
0,
net::IP_ADDRESS_ATTRIBUTE_NONE));
interface_list.push_back(
net::NetworkInterface("network2", "network2", 1,
net::NetworkInterface("network2",
"network2",
1,
net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
mock_ip_, 0));
mock_ip_,
0,
net::IP_ADDRESS_ATTRIBUTE_NONE));
interface_list.push_back(
net::NetworkInterface("network3", "network3", 2,
net::NetworkInterface("network3",
"network3",
2,
net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
mock_ip_, 0));
mock_ip_,
0,
net::IP_ADDRESS_ATTRIBUTE_NONE));
// "network4" is equivalent to "network2" because both the address family
// and interface index are the same.
interface_list.push_back(
net::NetworkInterface("network4", "network4", 1,
net::NetworkInterface("network4",
"network4",
1,
net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
mock_ip_, 0));
mock_ip_,
0,
net::IP_ADDRESS_ATTRIBUTE_NONE));
// 3 sockets * 4 requests per socket = 12 requests
EXPECT_CALL(mock_observer_, OnDiscoveryRequest(A<DialService*>())).Times(12);
......
......@@ -40,9 +40,13 @@ void GetNetworkListOnFileThread(
net::IPAddressNumber localhost_prefix(4, 0);
localhost_prefix[0] = 127;
ip4_networks.push_back(
net::NetworkInterface("lo", "lo", 0,
net::NetworkInterface("lo",
"lo",
0,
net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
localhost_prefix, 8));
localhost_prefix,
8,
net::IP_ADDRESS_ATTRIBUTE_NONE));
content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
base::Bind(callback, ip4_networks));
}
......
......@@ -312,28 +312,30 @@ TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) {
// Simulate a VPN connection. The proxy should be disabled.
MockSettings* settings = static_cast<MockSettings*>(settings_.get());
settings->network_interfaces_.reset(new net::NetworkInterfaceList());
settings->network_interfaces_->push_back(
net::NetworkInterface("tun0", /* network interface name */
"tun0", /* network interface friendly name */
0, /* interface index */
net::NetworkChangeNotifier::CONNECTION_WIFI,
net::IPAddressNumber(), /* IP address */
0 /* network prefix */
));
settings->network_interfaces_->push_back(net::NetworkInterface(
"tun0", /* network interface name */
"tun0", /* network interface friendly name */
0, /* interface index */
net::NetworkChangeNotifier::CONNECTION_WIFI,
net::IPAddressNumber(), /* IP address */
0, /* network prefix */
net::IP_ADDRESS_ATTRIBUTE_NONE /* ip address attribute */
));
settings_->OnIPAddressChanged();
base::MessageLoop::current()->RunUntilIdle();
CheckProxyConfigs(false, false, false);
// Check that the proxy is re-enabled if a non-VPN connection is later used.
settings->network_interfaces_.reset(new net::NetworkInterfaceList());
settings->network_interfaces_->push_back(
net::NetworkInterface("eth0", /* network interface name */
"eth0", /* network interface friendly name */
0, /* interface index */
net::NetworkChangeNotifier::CONNECTION_WIFI,
net::IPAddressNumber(),
0 /* network prefix */
));
settings->network_interfaces_->push_back(net::NetworkInterface(
"eth0", /* network interface name */
"eth0", /* network interface friendly name */
0, /* interface index */
net::NetworkChangeNotifier::CONNECTION_WIFI,
net::IPAddressNumber(),
0, /* network prefix */
net::IP_ADDRESS_ATTRIBUTE_NONE /* ip address attribute */
));
CheckProbeOnIPChange(kProbeURLWithOKResponse,
"OK",
true,
......
......@@ -29,6 +29,7 @@ IPC_STRUCT_TRAITS_BEGIN(net::NetworkInterface)
IPC_STRUCT_TRAITS_MEMBER(type)
IPC_STRUCT_TRAITS_MEMBER(address)
IPC_STRUCT_TRAITS_MEMBER(network_prefix)
IPC_STRUCT_TRAITS_MEMBER(ip_address_attributes)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(rtc::PacketTimeUpdateParams)
......
......@@ -62,7 +62,8 @@ TEST_F(IpcNetworkManagerTest, DISABLED_TestMergeNetworkList) {
0,
net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
ip_number,
64));
64,
net::IP_ADDRESS_ATTRIBUTE_NONE));
EXPECT_TRUE(net::ParseIPLiteralToNumber(kIPv6PublicAddrString2, &ip_number));
list.push_back(
......@@ -71,7 +72,8 @@ TEST_F(IpcNetworkManagerTest, DISABLED_TestMergeNetworkList) {
0,
net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
ip_number,
64));
64,
net::IP_ADDRESS_ATTRIBUTE_NONE));
network_manager_->OnNetworkListChanged(list);
network_manager_->GetNetworks(&networks);
......@@ -87,7 +89,8 @@ TEST_F(IpcNetworkManagerTest, DISABLED_TestMergeNetworkList) {
0,
net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
ip_number,
48));
48,
net::IP_ADDRESS_ATTRIBUTE_NONE));
network_manager_->OnNetworkListChanged(list);
......
......@@ -1004,13 +1004,15 @@ NetworkInterface::NetworkInterface(const std::string& name,
uint32 interface_index,
NetworkChangeNotifier::ConnectionType type,
const IPAddressNumber& address,
uint32 network_prefix)
uint32 network_prefix,
int ip_address_attributes)
: name(name),
friendly_name(friendly_name),
interface_index(interface_index),
type(type),
address(address),
network_prefix(network_prefix) {
network_prefix(network_prefix),
ip_address_attributes(ip_address_attributes) {
}
NetworkInterface::~NetworkInterface() {
......
......@@ -438,6 +438,24 @@ NET_EXPORT_PRIVATE int GetPortFromSockaddr(const struct sockaddr* address,
// machine.
NET_EXPORT_PRIVATE bool IsLocalhost(const std::string& host);
// A subset of IP address attributes which are actionable by the
// application layer. Currently unimplemented for all hosts;
// IP_ADDRESS_ATTRIBUTE_NONE is always returned.
enum IPAddressAttributes {
IP_ADDRESS_ATTRIBUTE_NONE = 0,
// A temporary address is dynamic by nature and will not contain MAC
// address. Presence of MAC address in IPv6 addresses can be used to
// track an endpoint and cause privacy concern. Please refer to
// RFC4941.
IP_ADDRESS_ATTRIBUTE_TEMPORARY = 1 << 0,
// A temporary address could become deprecated once the preferred
// lifetime is reached. It is still valid but shouldn't be used to
// create new connections.
IP_ADDRESS_ATTRIBUTE_DEPRECATED = 1 << 1,
};
// struct that is used by GetNetworkList() to represent a network
// interface.
struct NET_EXPORT NetworkInterface {
......@@ -447,7 +465,8 @@ struct NET_EXPORT NetworkInterface {
uint32 interface_index,
NetworkChangeNotifier::ConnectionType type,
const IPAddressNumber& address,
uint32 network_prefix);
uint32 network_prefix,
int ip_address_attributes);
~NetworkInterface();
std::string name;
......@@ -456,6 +475,7 @@ struct NET_EXPORT NetworkInterface {
NetworkChangeNotifier::ConnectionType type;
IPAddressNumber address;
uint32 network_prefix;
int ip_address_attributes; // Combination of |IPAddressAttributes|.
};
typedef std::vector<NetworkInterface> NetworkInterfaceList;
......
......@@ -140,9 +140,13 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
CHECK(base::StringToUint(network_tokenizer.token(), &index));
networks->push_back(
NetworkInterface(name, name, index,
NetworkInterface(name,
name,
index,
NetworkChangeNotifier::CONNECTION_UNKNOWN,
address, network_prefix));
address,
network_prefix,
IP_ADDRESS_ATTRIBUTE_NONE));
}
return true;
#else
......@@ -247,9 +251,13 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
net_mask = MaskPrefixLength(netmask.address());
}
}
network_info.interface = NetworkInterface(
name, name, if_nametoindex(name.c_str()),
connection_type, address.address(), net_mask);
network_info.interface = NetworkInterface(name,
name,
if_nametoindex(name.c_str()),
connection_type,
address.address(),
net_mask,
IP_ADDRESS_ATTRIBUTE_NONE);
network_infos.push_back(NetworkInterfaceInfo(network_info));
}
......
......@@ -190,20 +190,25 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
if (ipv6_valid_lifetime == 0 ||
ipv6_valid_lifetime > address->ValidLifetime) {
ipv6_valid_lifetime = address->ValidLifetime;
ipv6_address.reset(new NetworkInterface(adapter->AdapterName,
base::SysWideToNativeMB(adapter->FriendlyName),
index,
GetNetworkInterfaceType(adapter->IfType),
endpoint.address(),
net_prefix));
ipv6_address.reset(new NetworkInterface(
adapter->AdapterName,
base::SysWideToNativeMB(adapter->FriendlyName),
index,
GetNetworkInterfaceType(adapter->IfType),
endpoint.address(),
net_prefix,
IP_ADDRESS_ATTRIBUTE_NONE));
continue;
}
}
networks->push_back(
NetworkInterface(adapter->AdapterName,
base::SysWideToNativeMB(adapter->FriendlyName),
index, GetNetworkInterfaceType(adapter->IfType),
endpoint.address(), net_prefix));
index,
GetNetworkInterfaceType(adapter->IfType),
endpoint.address(),
net_prefix,
IP_ADDRESS_ATTRIBUTE_NONE));
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment