diff options
author | martijn <martijn@martijnc.be> | 2016-03-03 11:49:26 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-03 19:50:15 +0000 |
commit | 6e03065cee6ad249a6b8b14e9f690ee6efb86703 (patch) | |
tree | 648efd10258f3cc96ea279e5eb9261193fc59a3a | |
parent | 8bb1f7eba92e0353d7223b11a07b442f3fa449f4 (diff) | |
download | chromium_src-6e03065cee6ad249a6b8b14e9f690ee6efb86703.zip chromium_src-6e03065cee6ad249a6b8b14e9f690ee6efb86703.tar.gz chromium_src-6e03065cee6ad249a6b8b14e9f690ee6efb86703.tar.bz2 |
Migrate net::NetworkInterface to net::IPAddress.
Also adds a new constructor that takes an IPAddress and deprecates the constructor that takes an IPAddressNumber.
BUG=496258
Review URL: https://codereview.chromium.org/1735983003
Cr-Commit-Position: refs/heads/master@{#379064}
-rw-r--r-- | chrome/browser/extensions/api/dial/dial_service.cc | 7 | ||||
-rw-r--r-- | chrome/browser/media/webrtc_logging_handler_host.cc | 2 | ||||
-rw-r--r-- | chrome/browser/printing/cloud_print/privet_traffic_detector.cc | 9 | ||||
-rw-r--r-- | content/browser/renderer_host/pepper/pepper_network_monitor_host.cc | 2 | ||||
-rw-r--r-- | content/renderer/p2p/ipc_network_manager.cc | 12 | ||||
-rw-r--r-- | extensions/browser/api/socket/socket_api.cc | 2 | ||||
-rw-r--r-- | extensions/browser/api/system_network/system_network_api.cc | 2 | ||||
-rw-r--r-- | net/base/network_interfaces.cc | 18 | ||||
-rw-r--r-- | net/base/network_interfaces.h | 12 | ||||
-rw-r--r-- | net/base/network_interfaces_unittest.cc | 64 |
10 files changed, 74 insertions, 56 deletions
diff --git a/chrome/browser/extensions/api/dial/dial_service.cc b/chrome/browser/extensions/api/dial/dial_service.cc index d90eb04..b9a5615 100644 --- a/chrome/browser/extensions/api/dial/dial_service.cc +++ b/chrome/browser/extensions/api/dial/dial_service.cc @@ -474,8 +474,7 @@ void DialServiceImpl::SendNetworkList(const NetworkInterfaceList& networks) { for (NetworkInterfaceList::const_iterator iter = networks.begin(); iter != networks.end(); ++iter) { net::AddressFamily addr_family = net::GetAddressFamily(iter->address); - VLOG(2) << "Found " << iter->name << ", " - << net::IPAddressToString(iter->address) + VLOG(2) << "Found " << iter->name << ", " << iter->address.ToString() << ", address family: " << addr_family; if (addr_family == net::ADDRESS_FAMILY_IPV4) { InterfaceIndexAddressFamily interface_index_addr_family = @@ -489,9 +488,9 @@ void DialServiceImpl::SendNetworkList(const NetworkInterfaceList& networks) { VLOG(2) << "Encountered " << "interface index: " << iter->interface_index << ", " << "address family: " << addr_family << " for the first time, " - << "adding IP address " << net::IPAddressToString(iter->address) + << "adding IP address " << iter->address.ToString() << " to list."; - ip_addresses.push_back(iter->address); + ip_addresses.push_back(iter->address.bytes()); } else { VLOG(2) << "Already encountered " << "interface index: " << iter->interface_index << ", " diff --git a/chrome/browser/media/webrtc_logging_handler_host.cc b/chrome/browser/media/webrtc_logging_handler_host.cc index 53b7f5a..79690ff 100644 --- a/chrome/browser/media/webrtc_logging_handler_host.cc +++ b/chrome/browser/media/webrtc_logging_handler_host.cc @@ -631,7 +631,7 @@ void WebRtcLoggingHandlerHost::LogInitialInfoOnIOThread( it != network_list.end(); ++it) { LogToCircularBuffer( "Name: " + it->friendly_name + ", Address: " + - IPAddressToSensitiveString(it->address) + ", Type: " + + IPAddressToSensitiveString(it->address.bytes()) + ", Type: " + net::NetworkChangeNotifier::ConnectionTypeToString(it->type)); } diff --git a/chrome/browser/printing/cloud_print/privet_traffic_detector.cc b/chrome/browser/printing/cloud_print/privet_traffic_detector.cc index eabffe2..c088722 100644 --- a/chrome/browser/printing/cloud_print/privet_traffic_detector.cc +++ b/chrome/browser/printing/cloud_print/privet_traffic_detector.cc @@ -11,6 +11,7 @@ #include "base/metrics/histogram.h" #include "base/single_thread_task_runner.h" #include "base/sys_byteorder.h" +#include "net/base/ip_address.h" #include "net/base/net_errors.h" #include "net/base/network_interfaces.h" #include "net/dns/dns_protocol.h" @@ -42,8 +43,7 @@ void GetNetworkListOnFileThread( } } - net::IPAddressNumber localhost_prefix(4, 0); - localhost_prefix[0] = 127; + net::IPAddress localhost_prefix(127, 0, 0, 0); ip4_networks.push_back( net::NetworkInterface("lo", "lo", @@ -145,9 +145,8 @@ int PrivetTrafficDetector::Bind() { bool PrivetTrafficDetector::IsSourceAcceptable() const { for (size_t i = 0; i < networks_.size(); ++i) { - if (net::IPNumberMatchesPrefix(recv_addr_.address().bytes(), - networks_[i].address, - networks_[i].prefix_length)) { + if (net::IPAddressMatchesPrefix(recv_addr_.address(), networks_[i].address, + networks_[i].prefix_length)) { return true; } } diff --git a/content/browser/renderer_host/pepper/pepper_network_monitor_host.cc b/content/browser/renderer_host/pepper/pepper_network_monitor_host.cc index 2d07e2a..211906a 100644 --- a/content/browser/renderer_host/pepper/pepper_network_monitor_host.cc +++ b/content/browser/renderer_host/pepper/pepper_network_monitor_host.cc @@ -106,7 +106,7 @@ void PepperNetworkMonitorHost::SendNetworkList( network_copy.addresses.resize( 1, ppapi::NetAddressPrivateImpl::kInvalidNetAddress); bool result = ppapi::NetAddressPrivateImpl::IPEndPointToNetAddress( - network.address, 0, &(network_copy.addresses[0])); + network.address.bytes(), 0, &(network_copy.addresses[0])); DCHECK(result); // TODO(sergeyu): Currently net::NetworkInterfaceList provides diff --git a/content/renderer/p2p/ipc_network_manager.cc b/content/renderer/p2p/ipc_network_manager.cc index 025fc0c..4850d55 100644 --- a/content/renderer/p2p/ipc_network_manager.cc +++ b/content/renderer/p2p/ipc_network_manager.cc @@ -90,7 +90,7 @@ void IpcNetworkManager::OnNetworkListChanged( for (net::NetworkInterfaceList::const_iterator it = list.begin(); it != list.end(); it++) { rtc::IPAddress ip_address = - jingle_glue::IPAddressNumberToIPAddress(it->address); + jingle_glue::IPAddressNumberToIPAddress(it->address.bytes()); DCHECK(!ip_address.IsNil()); rtc::IPAddress prefix = rtc::TruncateIP(ip_address, it->prefix_length); @@ -100,11 +100,12 @@ void IpcNetworkManager::OnNetworkListChanged( network->set_default_local_address_provider(this); rtc::InterfaceAddress iface_addr; - if (it->address.size() == net::kIPv4AddressSize) { - use_default_ipv4_address |= (default_ipv4_local_address == it->address); + if (it->address.IsIPv4()) { + use_default_ipv4_address |= + (default_ipv4_local_address == it->address.bytes()); iface_addr = rtc::InterfaceAddress(ip_address); } else { - DCHECK(it->address.size() == net::kIPv6AddressSize); + DCHECK(it->address.IsIPv6()); iface_addr = rtc::InterfaceAddress(ip_address, it->ip_address_attributes); // Only allow non-private, non-deprecated IPv6 addresses which don't @@ -115,7 +116,8 @@ void IpcNetworkManager::OnNetworkListChanged( continue; } - use_default_ipv6_address |= (default_ipv6_local_address == it->address); + use_default_ipv6_address |= + (default_ipv6_local_address == it->address.bytes()); } network->AddIP(iface_addr); networks.push_back(network.release()); diff --git a/extensions/browser/api/socket/socket_api.cc b/extensions/browser/api/socket/socket_api.cc index 88b2a83..5ca184c 100644 --- a/extensions/browser/api/socket/socket_api.cc +++ b/extensions/browser/api/socket/socket_api.cc @@ -800,7 +800,7 @@ void SocketGetNetworkListFunction::SendResponseOnUIThread( linked_ptr<api::socket::NetworkInterface> info = make_linked_ptr(new api::socket::NetworkInterface); info->name = i->name; - info->address = net::IPAddressToString(i->address); + info->address = i->address.ToString(); info->prefix_length = i->prefix_length; create_arg.push_back(info); } diff --git a/extensions/browser/api/system_network/system_network_api.cc b/extensions/browser/api/system_network/system_network_api.cc index b6b6685..0cf8d0a 100644 --- a/extensions/browser/api/system_network/system_network_api.cc +++ b/extensions/browser/api/system_network/system_network_api.cc @@ -70,7 +70,7 @@ void SystemNetworkGetNetworkInterfacesFunction::SendResponseOnUIThread( linked_ptr<api::system_network::NetworkInterface> info = make_linked_ptr(new api::system_network::NetworkInterface); info->name = i->name; - info->address = net::IPAddressToString(i->address); + info->address = i->address.ToString(); info->prefix_length = i->prefix_length; create_arg.push_back(info); } diff --git a/net/base/network_interfaces.cc b/net/base/network_interfaces.cc index 96a9ef4..c4e4b27 100644 --- a/net/base/network_interfaces.cc +++ b/net/base/network_interfaces.cc @@ -28,14 +28,28 @@ NetworkInterface::NetworkInterface(const std::string& name, const IPAddressNumber& address, uint32_t prefix_length, int ip_address_attributes) + : NetworkInterface(name, + friendly_name, + interface_index, + type, + IPAddress(address), + prefix_length, + ip_address_attributes) {} + +NetworkInterface::NetworkInterface(const std::string& name, + const std::string& friendly_name, + uint32_t interface_index, + NetworkChangeNotifier::ConnectionType type, + const IPAddress& address, + uint32_t prefix_length, + int ip_address_attributes) : name(name), friendly_name(friendly_name), interface_index(interface_index), type(type), address(address), prefix_length(prefix_length), - ip_address_attributes(ip_address_attributes) { -} + ip_address_attributes(ip_address_attributes) {} NetworkInterface::NetworkInterface(const NetworkInterface& other) = default; diff --git a/net/base/network_interfaces.h b/net/base/network_interfaces.h index a4246e2..96ea5d5 100644 --- a/net/base/network_interfaces.h +++ b/net/base/network_interfaces.h @@ -12,6 +12,7 @@ #include "base/macros.h" #include "base/memory/scoped_ptr.h" +#include "net/base/ip_address.h" #include "net/base/ip_address_number.h" #include "net/base/net_export.h" #include "net/base/network_change_notifier.h" @@ -40,6 +41,8 @@ enum IPAddressAttributes { // interface. struct NET_EXPORT NetworkInterface { NetworkInterface(); + // Deprecated. Use the IPAddress constructor instead. + // https://crbug.com/496258. NetworkInterface(const std::string& name, const std::string& friendly_name, uint32_t interface_index, @@ -47,6 +50,13 @@ struct NET_EXPORT NetworkInterface { const IPAddressNumber& address, uint32_t prefix_length, int ip_address_attributes); + NetworkInterface(const std::string& name, + const std::string& friendly_name, + uint32_t interface_index, + NetworkChangeNotifier::ConnectionType type, + const IPAddress& address, + uint32_t prefix_length, + int ip_address_attributes); NetworkInterface(const NetworkInterface& other); ~NetworkInterface(); @@ -54,7 +64,7 @@ struct NET_EXPORT NetworkInterface { std::string friendly_name; // Same as |name| on non-Windows. uint32_t interface_index; // Always 0 on Android. NetworkChangeNotifier::ConnectionType type; - IPAddressNumber address; + IPAddress address; uint32_t prefix_length; int ip_address_attributes; // Combination of |IPAddressAttributes|. }; diff --git a/net/base/network_interfaces_unittest.cc b/net/base/network_interfaces_unittest.cc index c4b72df..74075ad 100644 --- a/net/base/network_interfaces_unittest.cc +++ b/net/base/network_interfaces_unittest.cc @@ -90,8 +90,8 @@ class IPAttributesGetterTest : public internal::IPAttributesGetterMac { bool FillIfaddrs(ifaddrs* interfaces, const char* ifname, uint flags, - const IPAddressNumber& ip_address, - const IPAddressNumber& ip_netmask, + const IPAddress& ip_address, + const IPAddress& ip_netmask, sockaddr_storage sock_addrs[2]) { interfaces->ifa_next = NULL; interfaces->ifa_name = const_cast<char*>(ifname); @@ -130,17 +130,9 @@ TEST(NetworkInterfacesTest, GetNetworkList) { EXPECT_FALSE(it->friendly_name.empty()); // Verify that the address is correct. - EXPECT_TRUE(it->address.size() == kIPv4AddressSize || - it->address.size() == kIPv6AddressSize) - << "Invalid address of size " << it->address.size(); - bool all_zeroes = true; - for (size_t i = 0; i < it->address.size(); ++i) { - if (it->address[i] != 0) { - all_zeroes = false; - break; - } - } - EXPECT_FALSE(all_zeroes); + EXPECT_TRUE(it->address.IsValid()) << "Invalid address of size " + << it->address.size(); + EXPECT_FALSE(it->address.IsZero()); EXPECT_GT(it->prefix_length, 1u); EXPECT_LE(it->prefix_length, it->address.size() * 8); @@ -233,9 +225,8 @@ char* GetInterfaceNameVM(int interface_index, char* ifname) { } TEST(NetworkInterfacesTest, GetNetworkListTrimming) { - IPAddressNumber ipv6_local_address( - kIPv6LocalAddr, kIPv6LocalAddr + arraysize(kIPv6LocalAddr)); - IPAddressNumber ipv6_address(kIPv6Addr, kIPv6Addr + arraysize(kIPv6Addr)); + IPAddress ipv6_local_address(kIPv6LocalAddr); + IPAddress ipv6_address(kIPv6Addr); NetworkInterfaceList results; ::base::hash_set<int> online_links; @@ -251,7 +242,8 @@ TEST(NetworkInterfacesTest, GetNetworkListTrimming) { }; // Address of offline links should be ignored. - ASSERT_TRUE(address_map.insert(std::make_pair(ipv6_address, msg)).second); + ASSERT_TRUE( + address_map.insert(std::make_pair(ipv6_address.bytes(), msg)).second); EXPECT_TRUE(internal::GetNetworkListImpl( &results, INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES, online_links, address_map, GetInterfaceName)); @@ -263,7 +255,8 @@ TEST(NetworkInterfacesTest, GetNetworkListTrimming) { // Local address should be trimmed out. address_map.clear(); ASSERT_TRUE( - address_map.insert(std::make_pair(ipv6_local_address, msg)).second); + address_map.insert(std::make_pair(ipv6_local_address.bytes(), msg)) + .second); EXPECT_TRUE(internal::GetNetworkListImpl( &results, INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES, online_links, address_map, GetInterfaceName)); @@ -271,7 +264,8 @@ TEST(NetworkInterfacesTest, GetNetworkListTrimming) { // vmware address should return by default. address_map.clear(); - ASSERT_TRUE(address_map.insert(std::make_pair(ipv6_address, msg)).second); + ASSERT_TRUE( + address_map.insert(std::make_pair(ipv6_address.bytes(), msg)).second); EXPECT_TRUE(internal::GetNetworkListImpl( &results, INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES, online_links, address_map, GetInterfaceNameVM)); @@ -283,7 +277,8 @@ TEST(NetworkInterfacesTest, GetNetworkListTrimming) { // vmware address should be trimmed out if policy specified so. address_map.clear(); - ASSERT_TRUE(address_map.insert(std::make_pair(ipv6_address, msg)).second); + ASSERT_TRUE( + address_map.insert(std::make_pair(ipv6_address.bytes(), msg)).second); EXPECT_TRUE(internal::GetNetworkListImpl( &results, EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES, online_links, address_map, GetInterfaceNameVM)); @@ -293,7 +288,8 @@ TEST(NetworkInterfacesTest, GetNetworkListTrimming) { // Addresses with banned attributes should be ignored. address_map.clear(); msg.ifa_flags = IFA_F_TENTATIVE; - ASSERT_TRUE(address_map.insert(std::make_pair(ipv6_address, msg)).second); + ASSERT_TRUE( + address_map.insert(std::make_pair(ipv6_address.bytes(), msg)).second); EXPECT_TRUE(internal::GetNetworkListImpl( &results, INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES, online_links, address_map, GetInterfaceName)); @@ -304,7 +300,8 @@ TEST(NetworkInterfacesTest, GetNetworkListTrimming) { // attributes should be translated correctly. address_map.clear(); msg.ifa_flags = IFA_F_TEMPORARY; - ASSERT_TRUE(address_map.insert(std::make_pair(ipv6_address, msg)).second); + ASSERT_TRUE( + address_map.insert(std::make_pair(ipv6_address.bytes(), msg)).second); EXPECT_TRUE(internal::GetNetworkListImpl( &results, INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES, online_links, address_map, GetInterfaceName)); @@ -319,7 +316,8 @@ TEST(NetworkInterfacesTest, GetNetworkListTrimming) { // attributes should be translated correctly. address_map.clear(); msg.ifa_flags = IFA_F_DEPRECATED; - ASSERT_TRUE(address_map.insert(std::make_pair(ipv6_address, msg)).second); + ASSERT_TRUE( + address_map.insert(std::make_pair(ipv6_address.bytes(), msg)).second); EXPECT_TRUE(internal::GetNetworkListImpl( &results, INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES, online_links, address_map, GetInterfaceName)); @@ -334,11 +332,9 @@ TEST(NetworkInterfacesTest, GetNetworkListTrimming) { #elif defined(OS_MACOSX) TEST(NetworkInterfacesTest, GetNetworkListTrimming) { - IPAddressNumber ipv6_local_address( - kIPv6LocalAddr, kIPv6LocalAddr + arraysize(kIPv6LocalAddr)); - IPAddressNumber ipv6_address(kIPv6Addr, kIPv6Addr + arraysize(kIPv6Addr)); - IPAddressNumber ipv6_netmask(kIPv6Netmask, - kIPv6Netmask + arraysize(kIPv6Netmask)); + IPAddress ipv6_local_address(kIPv6LocalAddr); + IPAddress ipv6_address(kIPv6Addr); + IPAddress ipv6_netmask(kIPv6Netmask); NetworkInterfaceList results; IPAttributesGetterTest ip_attributes_getter; @@ -432,8 +428,8 @@ TEST(NetworkInterfacesTest, GetNetworkListTrimming) { // |adapter_address| once the function is returned. bool FillAdapterAddress(IP_ADAPTER_ADDRESSES* adapter_address, const char* ifname, - const IPAddressNumber& ip_address, - const IPAddressNumber& ip_netmask, + const IPAddress& ip_address, + const IPAddress& ip_netmask, sockaddr_storage sock_addrs[2]) { adapter_address->AdapterName = const_cast<char*>(ifname); adapter_address->FriendlyName = const_cast<PWCHAR>(L"interface"); @@ -481,11 +477,9 @@ bool FillAdapterAddress(IP_ADAPTER_ADDRESSES* adapter_address, } TEST(NetworkInterfacesTest, GetNetworkListTrimming) { - IPAddressNumber ipv6_local_address( - kIPv6LocalAddr, kIPv6LocalAddr + arraysize(kIPv6LocalAddr)); - IPAddressNumber ipv6_address(kIPv6Addr, kIPv6Addr + arraysize(kIPv6Addr)); - IPAddressNumber ipv6_prefix(kIPv6AddrPrefix, - kIPv6AddrPrefix + arraysize(kIPv6AddrPrefix)); + IPAddress ipv6_local_address(kIPv6LocalAddr); + IPAddress ipv6_address(kIPv6Addr); + IPAddress ipv6_prefix(kIPv6AddrPrefix); NetworkInterfaceList results; sockaddr_storage addresses[2]; |