From: csagan5 <32685696+csagan5@users.noreply.github.com>
Date: Sun, 18 Nov 2018 13:06:49 +0100
Subject: Add flag to disable IPv6 probes

---
 chrome/browser/about_flags.cc           |  5 +++++
 chrome/browser/flag_descriptions.cc     |  4 ++++
 chrome/browser/flag_descriptions.h      |  3 +++
 net/dns/host_resolver_impl.cc           | 10 ++++++++--
 services/network/public/cpp/features.cc |  3 +++
 services/network/public/cpp/features.h  |  2 ++
 6 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -2975,6 +2975,11 @@ const FeatureEntry kFeatureEntries[] = {
      FEATURE_VALUE_TYPE(features::kHandwritingGesture)},
 #endif  // OS_CHROMEOS
 
+    {"ipv6-probing",
+     flag_descriptions::kIPv6ProbingName,
+     flag_descriptions::kIPv6ProbingDescription, kOsAll,
+     FEATURE_VALUE_TYPE(network::features::kIPv6Probing)},
+
 #if !defined(OS_ANDROID)
     {"enable-picture-in-picture",
      flag_descriptions::kEnablePictureInPictureName,
diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
--- a/chrome/browser/flag_descriptions.cc
+++ b/chrome/browser/flag_descriptions.cc
@@ -842,6 +842,10 @@ const char kOOPHPStackModeNative[] = "Native";
 const char kOOPHPStackModeNativeWithThreadNames[] = "Native with thread names";
 const char kOOPHPStackModePseudo[] = "Trace events";
 
+const char kIPv6ProbingName[] = "Enable IPv6 probing.";
+const char kIPv6ProbingDescription[] =
+    "Send IPv6 probes to a RIPE DNS address to verify IPv6 connectivity.";
+
 const char kEnablePictureInPictureName[] = "Enable Picture-in-Picture.";
 const char kEnablePictureInPictureDescription[] =
     "Show Picture-in-Picture in browser context menu and video native "
diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
--- a/chrome/browser/flag_descriptions.h
+++ b/chrome/browser/flag_descriptions.h
@@ -498,6 +498,9 @@ extern const char kDownloadAutoResumptionNativeDescription[];
 extern const char kEnableNewDownloadBackendName[];
 extern const char kEnableNewDownloadBackendDescription[];
 
+extern const char kIPv6ProbingName[];
+extern const char kIPv6ProbingDescription[];
+
 extern const char kEnablePictureInPictureName[];
 extern const char kEnablePictureInPictureDescription[];
 
diff --git a/net/dns/host_resolver_impl.cc b/net/dns/host_resolver_impl.cc
--- a/net/dns/host_resolver_impl.cc
+++ b/net/dns/host_resolver_impl.cc
@@ -81,6 +81,7 @@
 #include "net/log/net_log_with_source.h"
 #include "net/socket/client_socket_factory.h"
 #include "net/socket/datagram_client_socket.h"
+#include "services/network/public/cpp/features.h"
 #include "url/url_canon_ip.h"
 
 #if BUILDFLAG(ENABLE_MDNS)
@@ -2751,8 +2752,13 @@ bool HostResolverImpl::IsIPv6Reachable(const NetLogWithSource& net_log) {
   bool cached = true;
   if ((tick_clock_->NowTicks() - last_ipv6_probe_time_).InMilliseconds() >
       kIPv6ProbePeriodMs) {
-    last_ipv6_probe_result_ =
-        IsGloballyReachable(IPAddress(kIPv6ProbeAddress), net_log);
+    if (!base::FeatureList::IsEnabled(network::features::kIPv6Probing)) {
+      // pretend IPv6 connectivy probe is successful when probing is disabled
+      last_ipv6_probe_result_ = true;
+    } else {
+      last_ipv6_probe_result_ =
+          IsGloballyReachable(IPAddress(kIPv6ProbeAddress), net_log);
+    }
     last_ipv6_probe_time_ = tick_clock_->NowTicks();
     cached = false;
   }
diff --git a/services/network/public/cpp/features.cc b/services/network/public/cpp/features.cc
--- a/services/network/public/cpp/features.cc
+++ b/services/network/public/cpp/features.cc
@@ -16,6 +16,9 @@ const base::Feature kExpectCTReporting{"ExpectCTReporting",
 
 const base::Feature kNetworkErrorLogging{"NetworkErrorLogging",
                                          base::FEATURE_ENABLED_BY_DEFAULT};
+
+const base::Feature kIPv6Probing{"IPv6Probing",
+                                       base::FEATURE_DISABLED_BY_DEFAULT};
 // Enables the network service.
 const base::Feature kNetworkService {
   "NetworkService",
diff --git a/services/network/public/cpp/features.h b/services/network/public/cpp/features.h
--- a/services/network/public/cpp/features.h
+++ b/services/network/public/cpp/features.h
@@ -18,6 +18,8 @@ extern const base::Feature kNetworkErrorLogging;
 COMPONENT_EXPORT(NETWORK_CPP)
 extern const base::Feature kNetworkService;
 COMPONENT_EXPORT(NETWORK_CPP)
+extern const base::Feature kIPv6Probing;
+COMPONENT_EXPORT(NETWORK_CPP)
 extern const base::Feature kOutOfBlinkCors;
 COMPONENT_EXPORT(NETWORK_CPP)
 extern const base::Feature kReporting;
-- 
2.11.0

