bug 1444858 - TRR: respect network.dns.disableIPv6 r?valentin
MozReview-Commit-ID: 18STac9ASIB
--- a/netwerk/dns/TRRService.cpp
+++ b/netwerk/dns/TRRService.cpp
@@ -11,16 +11,17 @@
#include "TRR.h"
#include "TRRService.h"
#include "mozilla/Preferences.h"
static const char kOpenCaptivePortalLoginEvent[] = "captive-portal-login";
static const char kClearPrivateData[] = "clear-private-data";
static const char kPurge[] = "browser:purge-session-history";
+static const char kDisableIpv6Pref[] = "network.dns.disableIPv6";
#define TRR_PREF_PREFIX "network.trr."
#define TRR_PREF(x) TRR_PREF_PREFIX x
namespace mozilla {
namespace net {
#undef LOG
@@ -65,16 +66,17 @@ TRRService::Init()
observerService->AddObserver(this, kOpenCaptivePortalLoginEvent, true);
observerService->AddObserver(this, kClearPrivateData, true);
observerService->AddObserver(this, kPurge, true);
}
nsCOMPtr<nsIPrefBranch> prefBranch;
GetPrefBranch(getter_AddRefs(prefBranch));
if (prefBranch) {
prefBranch->AddObserver(TRR_PREF_PREFIX, this, true);
+ prefBranch->AddObserver(kDisableIpv6Pref, this, true);
}
ReadPrefs(NULL);
gTRRService = this;
LOG(("Initialized TRRService\n"));
return NS_OK;
@@ -89,17 +91,19 @@ TRRService::Enabled()
}
if (mConfirmationState == CONFIRM_TRYING) {
LOG(("TRRService::Enabled MaybeConfirm()\n"));
MaybeConfirm();
}
if (mConfirmationState != CONFIRM_OK) {
- LOG(("TRRService::Enabled mConfirmationState=%d\n", (int)mConfirmationState));
+ LOG(("TRRService::Enabled mConfirmationState=%d mCaptiveIsPassed=%d\n",
+ (int)mConfirmationState,
+ (int)mCaptiveIsPassed));
}
return (mConfirmationState == CONFIRM_OK);
}
void
TRRService::GetPrefBranch(nsIPrefBranch **result)
{
@@ -196,16 +200,22 @@ TRRService::ReadPrefs(const char *name)
}
}
if (!name || !strcmp(name, TRR_PREF("early-AAAA"))) {
bool tmp;
if (NS_SUCCEEDED(Preferences::GetBool(TRR_PREF("early-AAAA"), &tmp))) {
mEarlyAAAA = tmp;
}
}
+ if (!name || !strcmp(name, kDisableIpv6Pref)) {
+ bool tmp;
+ if (NS_SUCCEEDED(Preferences::GetBool(kDisableIpv6Pref, &tmp))) {
+ mDisableIPv6 = tmp;
+ }
+ }
return NS_OK;
}
nsresult
TRRService::GetURI(nsCString &result)
{
MutexAutoLock lock(mLock);
--- a/netwerk/dns/TRRService.h
+++ b/netwerk/dns/TRRService.h
@@ -32,16 +32,17 @@ public:
nsresult Init();
nsresult Start();
bool Enabled();
uint32_t Mode() { return mMode; }
bool AllowRFC1918() { return mRfc1918; }
bool UseGET() { return mUseGET; }
bool EarlyAAAA() { return mEarlyAAAA; }
+ bool DisableIPv6() { return mDisableIPv6; }
nsresult GetURI(nsCString &result);
nsresult GetCredentials(nsCString &result);
uint32_t GetRequestTimeout() { return mTRRTimeout; }
LookupStatus CompleteLookup(nsHostRecord *, nsresult, mozilla::net::AddrInfo *, bool pb) override;
void TRRBlacklist(const nsACString &host, bool privateBrowsing, bool aParentsToo);
bool IsTRRBlacklisted(const nsACString &host, bool privateBrowsing, bool fullhost);
@@ -64,16 +65,17 @@ private:
nsCString mConfirmationNS;
nsCString mBootstrapAddr;
Atomic<bool, Relaxed> mWaitForCaptive; // wait for the captive portal to say OK before using TRR
Atomic<bool, Relaxed> mRfc1918; // okay with local IP addresses in DOH responses?
Atomic<bool, Relaxed> 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
// TRR Blacklist storage
RefPtr<DataStorage> mTRRBLStorage;
Atomic<bool, Relaxed> mClearTRRBLStorage;
enum ConfirmationState {
CONFIRM_INIT = 0,
CONFIRM_TRYING = 1,
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -1129,16 +1129,19 @@ nsHostResolver::TrrLookup(nsHostRecord *
if (pushedTRR) {
rectype = pushedTRR->Type();
}
bool sendAgain;
bool madeQuery = false;
do {
sendAgain = false;
+ if ((TRRTYPE_AAAA == rectype) && gTRRService && gTRRService->DisableIPv6()) {
+ break;
+ }
LOG(("TRR Resolve %s type %d\n", rec->host.get(), (int)rectype));
RefPtr<TRR> trr;
MutexAutoLock trrlock(rec->mTrrLock);
trr = pushedTRR ? pushedTRR : new TRR(this, rec, rectype);
if (pushedTRR || NS_SUCCEEDED(NS_DispatchToMainThread(trr))) {
rec->mResolving++;
if (rectype == TRRTYPE_A) {
MOZ_ASSERT(!rec->mTrrA);