1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_DNS_LOOPBACK_ONLY_H_ 6 #define NET_DNS_LOOPBACK_ONLY_H_ 7 8 #include <type_traits> 9 #include "base/functional/callback.h" 10 #include "net/base/net_export.h" 11 12 namespace net { 13 14 // Results in true if it can determine that only loopback addresses are 15 // configured. I.e. if at most 127.0.0.1 and ::1 are routable. Note this results 16 // in true as long as there are no non-loopback, active internet connections. 17 // There do not have to be any loopback interfaces for this to result in true. 18 // Also results in false if it cannot determine this. 19 // 20 // The result is always passed to `finished_cb`, which is posted to the current 21 // thread. 22 // 23 // If the result cannot be computed without blocking, this will post a 24 // CONTINUE_ON_SHUTDOWN task to a thread pool which can take 40-100ms on some 25 // systems. 26 // 27 // IMPORTANT NOTE: the Posix (except Android) and Fuchsia implementations 28 // consider IPv6 link-local addresses to be loopback, because network interfaces 29 // may be configured with IPv6 link-local addresses regardless of network 30 // connectivity and are not used for network connections. IPv4 link-local 31 // addresses are part of APIPA, can be used for network connections, and are not 32 // typically configured automatically for network interfaces. See 33 // https://codereview.chromium.org/3331024 when this behavior was originally 34 // added, and the linked bug https://crbug.com/55041 for an example. Otherwise, 35 // if IPv6 link-local addresses are not considered loopback, then 36 // host_resolver_system_task.cc will always use AI_ADDRCONFIG for getaddrinfo() 37 // on a system with link-local IPv6 addresses, and then because there are no 38 // non-loopback IPv4 addresses configured, getaddrinfo() will refuse to resolve 39 // any name to any IPv4 address. This is problematic because then localhost will 40 // not resolve to 127.0.0.1. 41 // 42 // See https://fedoraproject.org/wiki/QA/Networking/NameResolution/ADDRCONFIG 43 // for a writeup on the issues that AI_ADDRCONFIG, as well as its handling of 44 // IPv6 link-local addresses, can cause. 45 void NET_EXPORT 46 RunHaveOnlyLoopbackAddressesJob(base::OnceCallback<void(bool)> finished_cb); 47 48 } // namespace net 49 50 #endif // NET_DNS_LOOPBACK_ONLY_H_ 51