Add more string matching rules for detecting VPN interfaces.

"tun", "utun" and "tap" interfaces will now be assumed to be VPNs, if
the type is otherwise unknown.

This CL also moves GetAdapterTypeFromName out of BasicNetworkManager,
so that other network manager classes (e.g., the one in Chromium) can
use it too.

Bug: chromium:805759
Change-Id: I9988619666e2a9449cf5c089d24cf7d3afde8239
Reviewed-on: https://webrtc-review.googlesource.com/43580
Reviewed-by: Zhi Huang <zhihuang@webrtc.org>
Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21767}
diff --git a/rtc_base/network.cc b/rtc_base/network.cc
index 56d7299..6d59888 100644
--- a/rtc_base/network.cc
+++ b/rtc_base/network.cc
@@ -153,6 +153,38 @@
   return ost.str();
 }
 
+AdapterType GetAdapterTypeFromName(const char* network_name) {
+  if (strncmp(network_name, "ipsec", 5) == 0 ||
+      strncmp(network_name, "tun", 3) == 0 ||
+      strncmp(network_name, "utun", 4) == 0 ||
+      strncmp(network_name, "tap", 3) == 0) {
+    return ADAPTER_TYPE_VPN;
+  }
+#if defined(WEBRTC_IOS)
+  // Cell networks are pdp_ipN on iOS.
+  if (strncmp(network_name, "pdp_ip", 6) == 0) {
+    return ADAPTER_TYPE_CELLULAR;
+  }
+  if (strncmp(network_name, "en", 2) == 0) {
+    // This may not be most accurate because sometimes Ethernet interface
+    // name also starts with "en" but it is better than showing it as
+    // "unknown" type.
+    // TODO(honghaiz): Write a proper IOS network manager.
+    return ADAPTER_TYPE_WIFI;
+  }
+#elif defined(WEBRTC_ANDROID)
+  if (strncmp(network_name, "rmnet", 5) == 0 ||
+      strncmp(network_name, "v4-rmnet", 8) == 0) {
+    return ADAPTER_TYPE_CELLULAR;
+  }
+  if (strncmp(network_name, "wlan", 4) == 0) {
+    return ADAPTER_TYPE_WIFI;
+  }
+#endif
+
+  return ADAPTER_TYPE_UNKNOWN;
+}
+
 NetworkManager::NetworkManager() {
 }
 
@@ -447,7 +479,14 @@
     if (cursor->ifa_flags & IFF_LOOPBACK) {
       adapter_type = ADAPTER_TYPE_LOOPBACK;
     } else {
-      adapter_type = GetAdapterTypeFromName(cursor->ifa_name);
+      // If there is a network_monitor, use it to get the adapter type.
+      // Otherwise, get the adapter type based on a few name matching rules.
+      if (network_monitor_) {
+        adapter_type = network_monitor_->GetAdapterType(cursor->ifa_name);
+      }
+      if (adapter_type == ADAPTER_TYPE_UNKNOWN) {
+        adapter_type = GetAdapterTypeFromName(cursor->ifa_name);
+      }
     }
     int prefix_length = CountIPMaskBits(mask);
     prefix = TruncateIP(ip, prefix_length);
@@ -777,44 +816,6 @@
   }
 }
 
-AdapterType BasicNetworkManager::GetAdapterTypeFromName(
-    const char* network_name) const {
-  // If there is a network_monitor, use it to get the adapter type.
-  // Otherwise, get the adapter type based on a few name matching rules.
-  if (network_monitor_) {
-    AdapterType type = network_monitor_->GetAdapterType(network_name);
-    if (type != ADAPTER_TYPE_UNKNOWN) {
-      return type;
-    }
-  }
-  if (strncmp(network_name, "ipsec", 5) == 0) {
-    return ADAPTER_TYPE_VPN;
-  }
-#if defined(WEBRTC_IOS)
-  // Cell networks are pdp_ipN on iOS.
-  if (strncmp(network_name, "pdp_ip", 6) == 0) {
-    return ADAPTER_TYPE_CELLULAR;
-  }
-  if (strncmp(network_name, "en", 2) == 0) {
-    // This may not be most accurate because sometimes Ethernet interface
-    // name also starts with "en" but it is better than showing it as
-    // "unknown" type.
-    // TODO(honghaiz): Write a proper IOS network manager.
-    return ADAPTER_TYPE_WIFI;
-  }
-#elif defined(WEBRTC_ANDROID)
-  if (strncmp(network_name, "rmnet", 5) == 0 ||
-      strncmp(network_name, "v4-rmnet", 8) == 0) {
-    return ADAPTER_TYPE_CELLULAR;
-  }
-  if (strncmp(network_name, "wlan", 4) == 0) {
-    return ADAPTER_TYPE_WIFI;
-  }
-#endif
-
-  return ADAPTER_TYPE_UNKNOWN;
-}
-
 IPAddress BasicNetworkManager::QueryDefaultLocalAddress(int family) const {
   RTC_DCHECK(thread_ == Thread::Current());
   RTC_DCHECK(thread_->socketserver() != nullptr);