Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: webrtc/base/network.cc

Issue 1837823005: GetDefaultLocalAddress should return the bestIP (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/network.h ('k') | webrtc/base/network_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « webrtc/base/network.h ('k') | webrtc/base/network_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698