Bug 1518730 - Only send AAAA TRR requests when the system has IPv6 connectivity r=dragana

This is an optimization. If we detect that the system can't use the IPv6
address, there's no point in making a request for it.

Depends on D33475

Differential Revision: https://phabricator.services.mozilla.com/D33476

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Valentin Gosu 2019-06-03 21:17:08 +00:00
Родитель b0786cdfb7
Коммит c3ee743b2d
5 изменённых файлов: 25 добавлений и 3 удалений

Просмотреть файл

@ -5534,6 +5534,8 @@ pref("network.trr.blacklist-duration", 60);
pref("network.trr.request-timeout", 1500);
// Allow AAAA entries to be used "early", before the A results are in
pref("network.trr.early-AAAA", false);
// When true, it only sends AAAA when the system has IPv6 connectivity
pref("network.trr.skip-AAAA-when-not-supported", true);
// Explicitly disable ECS (EDNS Client Subnet, RFC 7871)
pref("network.trr.disable-ECS", true);
// After this many failed TRR requests in a row, consider TRR borked

Просмотреть файл

@ -21,11 +21,15 @@ interface nsINetworkConnectivityService : nsISupports
};
/* If DNS v4/v6 queries actually work on the current network */
[infallible]
readonly attribute nsINetworkConnectivityService_ConnectivityState DNSv4;
[infallible]
readonly attribute nsINetworkConnectivityService_ConnectivityState DNSv6;
/* If connecting to IPv4/v6 works on the current network */
[infallible]
readonly attribute nsINetworkConnectivityService_ConnectivityState IPv4;
[infallible]
readonly attribute nsINetworkConnectivityService_ConnectivityState IPv6;
/* Starts the DNS request to check for DNS v4/v6 availability */

Просмотреть файл

@ -252,6 +252,14 @@ nsresult TRRService::ReadPrefs(const char* name) {
mEarlyAAAA = tmp;
}
}
if (!name || !strcmp(name, TRR_PREF("skip-AAAA-when-not-supported"))) {
bool tmp;
if (NS_SUCCEEDED(Preferences::GetBool(
TRR_PREF("skip-AAAA-when-not-supported"), &tmp))) {
mCheckIPv6Connectivity = tmp;
}
}
if (!name || !strcmp(name, kDisableIpv6Pref)) {
bool tmp;
if (NS_SUCCEEDED(Preferences::GetBool(kDisableIpv6Pref, &tmp))) {

Просмотреть файл

@ -35,6 +35,7 @@ class TRRService : public nsIObserver,
bool AllowRFC1918() { return mRfc1918; }
bool UseGET() { return mUseGET; }
bool EarlyAAAA() { return mEarlyAAAA; }
bool CheckIPv6Connectivity() { return mCheckIPv6Connectivity; }
bool DisableIPv6() { return mDisableIPv6; }
bool DisableECS() { return mDisableECS; }
nsresult GetURI(nsCString& result);
@ -85,8 +86,9 @@ class TRRService : public nsIObserver,
mCaptiveIsPassed; // set when captive portal check is passed
Atomic<bool, Relaxed> mUseGET; // do DOH using GET requests (instead of POST)
Atomic<bool, Relaxed> mEarlyAAAA; // allow use of AAAA results before A is in
Atomic<bool, Relaxed> mDisableIPv6; // don't even try
Atomic<bool, Relaxed> mDisableECS; // disable EDNS Client Subnet in requests
Atomic<bool, Relaxed> mCheckIPv6Connectivity; // check IPv6 connectivity
Atomic<bool, Relaxed> mDisableIPv6; // don't even try
Atomic<bool, Relaxed> mDisableECS; // disable EDNS Client Subnet in requests
Atomic<uint32_t, Relaxed>
mDisableAfterFails; // this many fails in a row means failed TRR service

Просмотреть файл

@ -45,6 +45,7 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs.h"
#include "mozilla/net/NetworkConnectivityService.h"
using namespace mozilla;
using namespace mozilla::net;
@ -1240,10 +1241,15 @@ nsresult nsHostResolver::TrrLookup(nsHostRecord* aRec, TRR* pushedTRR) {
}
bool sendAgain;
RefPtr<NetworkConnectivityService> ncs =
NetworkConnectivityService::GetSingleton();
do {
sendAgain = false;
if ((TRRTYPE_AAAA == rectype) && gTRRService &&
gTRRService->DisableIPv6()) {
(gTRRService->DisableIPv6() ||
(gTRRService->CheckIPv6Connectivity() &&
ncs->GetIPv6() == nsINetworkConnectivityService::NOT_AVAILABLE))) {
break;
}
LOG(("TRR Resolve %s type %d\n", addrRec->host.get(), (int)rectype));