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

Side by Side Diff: webrtc/base/network.cc

Issue 1531763006: Enable IPv6 temporary address filtering on iOS (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifdef HAVE_CONFIG_H 11 #ifdef HAVE_CONFIG_H
12 #include "config.h" 12 #include "config.h"
13 #endif 13 #endif
14 14
15 #include "webrtc/base/network.h" 15 #include "webrtc/base/network.h"
16 #include "webrtc/base/logging.h"
16 17
17 #if defined(WEBRTC_POSIX) 18 #if defined(WEBRTC_POSIX)
18 // linux/if.h can't be included at the same time as the posix sys/if.h, and 19 // linux/if.h can't be included at the same time as the posix sys/if.h, and
19 // it's transitively required by linux/route.h, so include that version on 20 // it's transitively required by linux/route.h, so include that version on
20 // linux instead of the standard posix one. 21 // linux instead of the standard posix one.
21 #if defined(WEBRTC_LINUX) 22 #if defined(WEBRTC_LINUX)
22 #include <linux/if.h> 23 #include <linux/if.h>
23 #include <linux/route.h> 24 #include <linux/route.h>
24 #elif !defined(__native_client__) 25 #elif !defined(__native_client__)
25 #include <net/if.h> 26 #include <net/if.h>
26 #endif 27 #endif
27 #include <sys/socket.h>
28 #include <sys/utsname.h>
29 #include <sys/ioctl.h>
30 #include <unistd.h>
31 #include <errno.h>
32
33 #if defined(WEBRTC_ANDROID)
34 #include "webrtc/base/ifaddrs-android.h"
35 #elif !defined(__native_client__)
36 #include <ifaddrs.h>
37 #endif
38
39 #endif // WEBRTC_POSIX 28 #endif // WEBRTC_POSIX
40 29
41 #if defined(WEBRTC_WIN) 30 #if defined(WEBRTC_WIN)
42 #include "webrtc/base/win32.h" 31 #include "webrtc/base/win32.h"
43 #include <Iphlpapi.h> 32 #include <Iphlpapi.h>
33 #else
34 #include "webrtc/base/ifaddrs_converter.h"
44 #endif 35 #endif
45 36
46 #include <stdio.h> 37 #include <stdio.h>
47 38
48 #include <algorithm> 39 #include <algorithm>
49 40
50 #include "webrtc/base/logging.h" 41 #include "webrtc/base/logging.h"
51 #include "webrtc/base/networkmonitor.h" 42 #include "webrtc/base/networkmonitor.h"
52 #include "webrtc/base/scoped_ptr.h" 43 #include "webrtc/base/scoped_ptr.h"
53 #include "webrtc/base/socket.h" // includes something that makes windows happy 44 #include "webrtc/base/socket.h" // includes something that makes windows happy
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 case ADAPTER_TYPE_VPN: 113 case ADAPTER_TYPE_VPN:
123 return "VPN"; 114 return "VPN";
124 case ADAPTER_TYPE_LOOPBACK: 115 case ADAPTER_TYPE_LOOPBACK:
125 return "Loopback"; 116 return "Loopback";
126 default: 117 default:
127 RTC_DCHECK(false) << "Invalid type " << type; 118 RTC_DCHECK(false) << "Invalid type " << type;
128 return std::string(); 119 return std::string();
129 } 120 }
130 } 121 }
131 122
132 bool IsIgnoredIPv6(const IPAddress& ip) { 123 bool IsIgnoredIPv6(const InterfaceAddress& ip) {
133 if (ip.family() != AF_INET6) { 124 if (ip.family() != AF_INET6) {
134 return false; 125 return false;
135 } 126 }
136 127
137 // Link-local addresses require scope id to be bound successfully. 128 // Link-local addresses require scope id to be bound successfully.
138 // However, our IPAddress structure doesn't carry that so the 129 // However, our IPAddress structure doesn't carry that so the
139 // information is lost and causes binding failure. 130 // information is lost and causes binding failure.
140 if (IPIsLinkLocal(ip)) { 131 if (IPIsLinkLocal(ip)) {
141 return true; 132 return true;
142 } 133 }
143 134
144 // Any MAC based IPv6 should be avoided to prevent the MAC tracking. 135 // Any MAC based IPv6 should be avoided to prevent the MAC tracking.
145 if (IPIsMacBased(ip)) { 136 if (IPIsMacBased(ip)) {
146 return true; 137 return true;
147 } 138 }
148 139
140 // Ignore deprecated IPv6.
141 if (ip.ipv6_flags() & IPV6_ADDRESS_FLAG_DEPRECATED) {
142 return true;
pthatcher1 2015/12/18 19:51:21 This (DEPRECATED) is new functionality, right? So
guoweis_webrtc 2015/12/21 20:26:34 This mimics chrome's logic. Yes, we had already. N
143 }
144
149 return false; 145 return false;
150 } 146 }
151 147
152 } // namespace 148 } // namespace
153 149
154 // These addresses are used as the targets to find out the default local address 150 // These addresses are used as the targets to find out the default local address
155 // on a multi-homed endpoint. They are actually DNS servers. 151 // on a multi-homed endpoint. They are actually DNS servers.
156 const char kPublicIPv4Host[] = "8.8.8.8"; 152 const char kPublicIPv4Host[] = "8.8.8.8";
157 const char kPublicIPv6Host[] = "2001:4860:4860::8888"; 153 const char kPublicIPv6Host[] = "2001:4860:4860::8888";
158 const int kPublicPort = 53; // DNS port. 154 const int kPublicPort = 53; // DNS port.
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 ASSERT(false); 372 ASSERT(false);
377 LOG(LS_WARNING) << "BasicNetworkManager doesn't work on NaCl yet"; 373 LOG(LS_WARNING) << "BasicNetworkManager doesn't work on NaCl yet";
378 return false; 374 return false;
379 } 375 }
380 376
381 #elif defined(WEBRTC_POSIX) 377 #elif defined(WEBRTC_POSIX)
382 void BasicNetworkManager::ConvertIfAddrs(struct ifaddrs* interfaces, 378 void BasicNetworkManager::ConvertIfAddrs(struct ifaddrs* interfaces,
383 bool include_ignored, 379 bool include_ignored,
384 NetworkList* networks) const { 380 NetworkList* networks) const {
385 NetworkMap current_networks; 381 NetworkMap current_networks;
382 rtc::scoped_ptr<IfAddrsConverter> ifaddrs_converter(
383 CreateIfAddrsConverter());
384
386 for (struct ifaddrs* cursor = interfaces; 385 for (struct ifaddrs* cursor = interfaces;
387 cursor != NULL; cursor = cursor->ifa_next) { 386 cursor != NULL; cursor = cursor->ifa_next) {
388 IPAddress prefix; 387 IPAddress prefix;
389 IPAddress mask; 388 IPAddress mask;
390 IPAddress ip; 389 InterfaceAddress ip;
391 int scope_id = 0; 390 int scope_id = 0;
392 391
393 // Some interfaces may not have address assigned. 392 // Some interfaces may not have address assigned.
394 if (!cursor->ifa_addr || !cursor->ifa_netmask) 393 if (!cursor->ifa_addr || !cursor->ifa_netmask) {
395 continue; 394 continue;
395 }
396 // Skip ones which are down.
397 if (!(IFF_RUNNING & cursor->ifa_flags)) {
398 continue;
399 }
pthatcher1 2015/12/18 19:51:21 This (IFF_RUNNING) is new functionality, right? S
guoweis_webrtc 2015/12/21 20:26:34 Done.
400 // Skip unknown family.
401 if (cursor->ifa_addr->sa_family != AF_INET &&
402 cursor->ifa_addr->sa_family != AF_INET6) {
403 continue;
404 }
405 // Skip IPv6 if not enabled.
406 if (cursor->ifa_addr->sa_family == AF_INET6 && !ipv6_enabled()) {
407 continue;
408 }
409 // Convert to InterfaceAddress.
410 if (!ifaddrs_converter->Convert(cursor, &ip, &mask)) {
411 continue;
412 }
396 413
397 switch (cursor->ifa_addr->sa_family) { 414 // Special case for IPv6 address.
398 case AF_INET: { 415 if (cursor->ifa_addr->sa_family == AF_INET6) {
399 ip = IPAddress( 416 if (IsIgnoredIPv6(ip)) {
400 reinterpret_cast<sockaddr_in*>(cursor->ifa_addr)->sin_addr);
401 mask = IPAddress(
402 reinterpret_cast<sockaddr_in*>(cursor->ifa_netmask)->sin_addr);
403 break;
404 }
405 case AF_INET6: {
406 if (ipv6_enabled()) {
407 ip = IPAddress(
408 reinterpret_cast<sockaddr_in6*>(cursor->ifa_addr)->sin6_addr);
409
410 if (IsIgnoredIPv6(ip)) {
411 continue;
412 }
413
414 mask = IPAddress(
415 reinterpret_cast<sockaddr_in6*>(cursor->ifa_netmask)->sin6_addr);
416 scope_id =
417 reinterpret_cast<sockaddr_in6*>(cursor->ifa_addr)->sin6_scope_id;
418 break;
419 } else {
420 continue;
421 }
422 }
423 default: {
424 continue; 417 continue;
425 } 418 }
419 scope_id =
420 reinterpret_cast<sockaddr_in6*>(cursor->ifa_addr)->sin6_scope_id;
426 } 421 }
427 422
428 int prefix_length = CountIPMaskBits(mask); 423 int prefix_length = CountIPMaskBits(mask);
429 prefix = TruncateIP(ip, prefix_length); 424 prefix = TruncateIP(ip, prefix_length);
430 std::string key = MakeNetworkKey(std::string(cursor->ifa_name), 425 std::string key = MakeNetworkKey(std::string(cursor->ifa_name),
431 prefix, prefix_length); 426 prefix, prefix_length);
432 auto existing_network = current_networks.find(key); 427 auto existing_network = current_networks.find(key);
433 if (existing_network == current_networks.end()) { 428 if (existing_network == current_networks.end()) {
434 AdapterType adapter_type = ADAPTER_TYPE_UNKNOWN; 429 AdapterType adapter_type = ADAPTER_TYPE_UNKNOWN;
435 if (cursor->ifa_flags & IFF_LOOPBACK) { 430 if (cursor->ifa_flags & IFF_LOOPBACK) {
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 std::stringstream ss; 906 std::stringstream ss;
912 // Print out the first space-terminated token of the network desc, plus 907 // Print out the first space-terminated token of the network desc, plus
913 // the IP address. 908 // the IP address.
914 ss << "Net[" << description_.substr(0, description_.find(' ')) 909 ss << "Net[" << description_.substr(0, description_.find(' '))
915 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_ 910 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_
916 << ":" << AdapterTypeToString(type_) << "]"; 911 << ":" << AdapterTypeToString(type_) << "]";
917 return ss.str(); 912 return ss.str();
918 } 913 }
919 914
920 } // namespace rtc 915 } // namespace rtc
OLDNEW
« webrtc/base/mac_ifaddrs_converter.cc ('K') | « webrtc/base/mac_ifaddrs_converter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698