Chromium Code Reviews| Index: webrtc/base/network.cc |
| diff --git a/webrtc/base/network.cc b/webrtc/base/network.cc |
| index 4780e2f88d463ce9a9862e9da9b74a8c04e324d7..bbec317298bf2ee78055e5560ebcafa78bc7d9eb 100644 |
| --- a/webrtc/base/network.cc |
| +++ b/webrtc/base/network.cc |
| @@ -361,12 +361,30 @@ bool NetworkManagerBase::GetDefaultLocalAddress(int family, |
| *ipaddr = default_local_ipv4_address_; |
| return true; |
| } else if (family == AF_INET6 && !default_local_ipv6_address_.IsNil()) { |
| - *ipaddr = default_local_ipv6_address_; |
| + // Using the best IP on the same network as the default IPv6 address |
| + // prevents potential IP leaking. |
| + Network* network = GetNetworkFromAddress(default_local_ipv6_address_); |
|
pthatcher1
2016/03/30 17:25:06
I think this could be a little more clear:
*ipadd
honghaiz3
2016/03/30 18:02:59
Revised. 1. we don't need to assign *ipaddr twice
|
| + *ipaddr = (network != nullptr) ? network->GetBestIP() |
|
pthatcher1
2016/03/30 17:25:06
How do we know that GetBestIP() will return an ipv
honghaiz3
2016/03/30 18:02:59
IPv6 address and IPv4 address will be contained in
|
| + : default_local_ipv6_address_; |
| return true; |
| } |
| return false; |
| } |
| +Network* NetworkManagerBase::GetNetworkFromAddress( |
| + const rtc::IPAddress& ip) const { |
| + for (Network* network : networks_) { |
| + const auto& ips = network->GetIPs(); |
| + if (std::find_if(ips.begin(), ips.end(), |
| + [ip](const InterfaceAddress& existing_ip) { |
| + return ip == static_cast<rtc::IPAddress>(existing_ip); |
| + }) != ips.end()) { |
| + return network; |
| + } |
| + } |
| + return nullptr; |
| +} |
| + |
| BasicNetworkManager::BasicNetworkManager() |
| : thread_(NULL), sent_first_update_(false), start_count_(0), |
| ignore_non_default_routes_(false) { |