diff options
author | mallinath@chromium.org <mallinath@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-01 21:24:08 +0000 |
---|---|---|
committer | mallinath@chromium.org <mallinath@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-01 21:24:08 +0000 |
commit | a6fa9c2291b32921e98f3c65950ff3fb8024d217 (patch) | |
tree | 5f31ad017fe4d3e8bd23ef0ffb67927f2911534d /net | |
parent | 6f7ed06576acff050b1e222c456a9182ffd598bf (diff) | |
download | chromium_src-a6fa9c2291b32921e98f3c65950ff3fb8024d217.zip chromium_src-a6fa9c2291b32921e98f3c65950ff3fb8024d217.tar.gz chromium_src-a6fa9c2291b32921e98f3c65950ff3fb8024d217.tar.bz2 |
For WebRTC select IPv6 address which has least valid lifetime. This is
to make sure we don't expose a permanent IPv6 address which has infinite
valid lifetime.
This code change belongs to Windows specific platform.
R=agl@chromium.org
Review URL: https://codereview.chromium.org/217663002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260944 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/net_util.h | 4 | ||||
-rw-r--r-- | net/base/net_util_win.cc | 24 |
2 files changed, 26 insertions, 2 deletions
diff --git a/net/base/net_util.h b/net/base/net_util.h index 8a20a25..79116ce 100644 --- a/net/base/net_util.h +++ b/net/base/net_util.h @@ -532,11 +532,11 @@ typedef std::vector<NetworkInterface> NetworkInterfaceList; // Policy settings to include/exclude network interfaces. enum HostAddressSelectionPolicy { + INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES = 0x0, EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES = 0x1, - INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES = 0x2, // Include temp address only when interface has both permanent and // temp addresses. - INCLUDE_ONLY_TEMP_IPV6_ADDRESS_IF_POSSIBLE = 0x4, + INCLUDE_ONLY_TEMP_IPV6_ADDRESS_IF_POSSIBLE = 0x2, }; // Returns list of network interfaces except loopback interface. If an diff --git a/net/base/net_util_win.cc b/net/base/net_util_win.cc index de85ce5..14f3170d 100644 --- a/net/base/net_util_win.cc +++ b/net/base/net_util_win.cc @@ -159,6 +159,11 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) { return false; } + // These two variables are used below when this method is asked to pick a + // IPv6 address which has the shortest lifetime. + ULONG ipv6_valid_lifetime = 0; + scoped_ptr<NetworkInterface> ipv6_address; + for (IP_ADAPTER_ADDRESSES *adapter = adapters; adapter != NULL; adapter = adapter->Next) { // Ignore the loopback device. @@ -209,6 +214,22 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) { } uint32 index = (family == AF_INET) ? adapter->IfIndex : adapter->Ipv6IfIndex; + // Pick one IPv6 address with least valid lifetime. + // The reason we are checking |ValidLifeftime| as there is no other + // way identifying the interface type. Usually (and most likely) temp + // IPv6 will have a shorter ValidLifetime value then the permanent + // interface. + if (family == AF_INET6 && + (policy & INCLUDE_ONLY_TEMP_IPV6_ADDRESS_IF_POSSIBLE)) { + 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, endpoint.address(), net_prefix)); + continue; + } + } networks->push_back( NetworkInterface(adapter->AdapterName, base::SysWideToNativeMB(adapter->FriendlyName), @@ -218,6 +239,9 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) { } } + if (ipv6_address.get()) { + networks->push_back(*(ipv6_address.get())); + } return true; } |