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

License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
---
 chrome/browser/about_flags.cc                            | 4 ++++
 chrome/browser/flag_descriptions.cc                      | 4 ++++
 chrome/browser/flag_descriptions.h                       | 3 +++
 components/subresource_filter/tools/BUILD.gn             | 6 ++++++
 .../url_formatter/spoof_checks/top_domains/BUILD.gn      | 3 ++-
 net/dns/host_resolver_manager.cc                         | 9 ++++++++-
 services/network/public/cpp/features.cc                  | 4 ++++
 services/network/public/cpp/features.h                   | 2 ++
 8 files changed, 33 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
@@ -6036,6 +6036,10 @@ const FeatureEntry kFeatureEntries[] = {
     {"enable-reader-mode-in-cct", flag_descriptions::kReaderModeInCCTName,
      flag_descriptions::kReaderModeInCCTDescription, kOsAndroid,
      FEATURE_VALUE_TYPE(chrome::android::kReaderModeInCCT)},
+    {"ipv6-probing",
+     flag_descriptions::kIPv6ProbingName,
+     flag_descriptions::kIPv6ProbingDescription, kOsAll,
+     FEATURE_VALUE_TYPE(network::features::kIPv6Probing)},
 #endif  // BUILDFLAG(IS_ANDROID)
 
     {"shopping-list", commerce::flag_descriptions::kShoppingListName,
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
@@ -3578,6 +3578,10 @@ const char kCCTRealTimeEngagementSignalsDescription[] =
     "Enables sending real-time engagement signals (e.g. scroll) through "
     "CustomTabsCallback.";
 
+const char kIPv6ProbingName[] = "Enable IPv6 probing.";
+const char kIPv6ProbingDescription[] =
+    "Send IPv6 probes to a RIPE DNS address to verify IPv6 connectivity.";
+
 const char kChimeAlwaysShowNotificationDescription[] =
     "A debug flag to always show Chime notification after receiving a payload.";
 const char kChimeAlwaysShowNotificationName[] =
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
@@ -807,6 +807,9 @@ extern const char kEnableWasmLazyCompilationName[];
 extern const char kEnableWasmLazyCompilationDescription[];
 
 extern const char kEnableWasmTieringName[];
+extern const char kIPv6ProbingName[];
+extern const char kIPv6ProbingDescription[];
+
 extern const char kEnableWasmTieringDescription[];
 
 extern const char kEvDetailsInPageInfoName[];
diff --git a/components/subresource_filter/tools/BUILD.gn b/components/subresource_filter/tools/BUILD.gn
--- a/components/subresource_filter/tools/BUILD.gn
+++ b/components/subresource_filter/tools/BUILD.gn
@@ -50,6 +50,8 @@ if (!is_ios) {
     deps = [
       ":tools_lib",
       "//base",
+      "//components/network_session_configurator/common",
+      "//services/network/public/cpp"
     ]
   }
 
@@ -61,6 +63,8 @@ if (!is_ios) {
       ":tools_lib",
       "../core/common",
       "//base",
+      "//components/network_session_configurator/common",
+      "//services/network/public/cpp",
     ]
   }
 
@@ -70,6 +74,8 @@ if (!is_ios) {
       "ruleset_converter:support",
       "//base",
       "//third_party/protobuf:protobuf_lite",
+      "//components/network_session_configurator/common",
+      "//services/network/public/cpp"
     ]
   }
 
diff --git a/components/url_formatter/spoof_checks/top_domains/BUILD.gn b/components/url_formatter/spoof_checks/top_domains/BUILD.gn
--- a/components/url_formatter/spoof_checks/top_domains/BUILD.gn
+++ b/components/url_formatter/spoof_checks/top_domains/BUILD.gn
@@ -89,7 +89,8 @@ executable("make_top_domain_list_variables") {
     "//base:i18n",
     "//components/url_formatter/spoof_checks/common_words:common",
     "//third_party/icu",
-    "//components/network_session_configurator/common"
+    "//components/network_session_configurator/common",
+    "//services/network/public/cpp",
   ]
   if (is_ios) {
     frameworks = [ "UIKit.framework" ]
diff --git a/net/dns/host_resolver_manager.cc b/net/dns/host_resolver_manager.cc
--- a/net/dns/host_resolver_manager.cc
+++ b/net/dns/host_resolver_manager.cc
@@ -104,6 +104,7 @@
 #include "net/log/net_log_event_type.h"
 #include "net/log/net_log_source.h"
 #include "net/log/net_log_source_type.h"
+#include "services/network/public/cpp/features.h"
 #include "net/log/net_log_with_source.h"
 #include "net/socket/client_socket_factory.h"
 #include "net/socket/datagram_client_socket.h"
@@ -3727,8 +3728,14 @@ bool HostResolverManager::IsIPv6Reachable(const NetLogWithSource& net_log) {
   if (last_ipv6_probe_time_.is_null() ||
       (tick_clock_->NowTicks() - last_ipv6_probe_time_).InMilliseconds() >
           kIPv6ProbePeriodMs) {
-    SetLastIPv6ProbeResult(
+
+    if (!base::FeatureList::IsEnabled(network::features::kIPv6Probing)) {
+      // pretend IPv6 connectivy probe is successful when probing is disabled
+      SetLastIPv6ProbeResult(true);
+    } else {
+      SetLastIPv6ProbeResult(
         IsGloballyReachable(IPAddress(kIPv6ProbeAddress), net_log));
+    }
     cached = false;
   }
   net_log.AddEvent(
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
@@ -38,6 +38,10 @@ BASE_FEATURE(kThrottleDelayable,
              "ThrottleDelayable",
              base::FEATURE_ENABLED_BY_DEFAULT);
 
+// Enable IPv6 ping probes to RIPE DNS.
+const base::Feature kIPv6Probing{"IPv6Probing",
+                                       base::FEATURE_ENABLED_BY_DEFAULT};
+
 // When kPriorityRequestsDelayableOnSlowConnections is enabled, HTTP
 // requests fetched from a SPDY/QUIC/H2 proxies can be delayed by the
 // ResourceScheduler just as HTTP/1.1 resources are. However, requests from such
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 @@ COMPONENT_EXPORT(NETWORK_CPP) BASE_DECLARE_FEATURE(kNetworkErrorLogging);
 COMPONENT_EXPORT(NETWORK_CPP) BASE_DECLARE_FEATURE(kReporting);
 COMPONENT_EXPORT(NETWORK_CPP) BASE_DECLARE_FEATURE(kThrottleDelayable);
 COMPONENT_EXPORT(NETWORK_CPP)
+extern const base::Feature kIPv6Probing;
+COMPONENT_EXPORT(NETWORK_CPP)
 BASE_DECLARE_FEATURE(kDelayRequestsOnMultiplexedConnections);
 COMPONENT_EXPORT(NETWORK_CPP)
 BASE_DECLARE_FEATURE(kPauseBrowserInitiatedHeavyTrafficForP2P);
--
2.25.1
