2018-02-01 12:20:49 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef TRRService_h_
|
|
|
|
#define TRRService_h_
|
|
|
|
|
|
|
|
#include "mozilla/Atomics.h"
|
|
|
|
#include "mozilla/DataStorage.h"
|
|
|
|
#include "nsHostResolver.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
|
2019-08-24 00:17:15 +03:00
|
|
|
class nsDNSService;
|
2018-02-01 12:20:49 +03:00
|
|
|
class nsIPrefBranch;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
class TRRService : public nsIObserver,
|
2018-03-09 11:05:48 +03:00
|
|
|
public nsITimerCallback,
|
2018-02-01 12:20:49 +03:00
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public AHostResolver {
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
2018-03-09 11:05:48 +03:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
TRRService();
|
|
|
|
nsresult Init();
|
|
|
|
nsresult Start();
|
|
|
|
bool Enabled();
|
|
|
|
|
|
|
|
uint32_t Mode() { return mMode; }
|
|
|
|
bool AllowRFC1918() { return mRfc1918; }
|
|
|
|
bool UseGET() { return mUseGET; }
|
2018-03-06 18:07:29 +03:00
|
|
|
bool EarlyAAAA() { return mEarlyAAAA; }
|
2019-06-04 00:17:08 +03:00
|
|
|
bool CheckIPv6Connectivity() { return mCheckIPv6Connectivity; }
|
2019-06-04 00:13:22 +03:00
|
|
|
bool WaitForAllResponses() { return mWaitForAllResponses; }
|
2018-03-12 15:19:22 +03:00
|
|
|
bool DisableIPv6() { return mDisableIPv6; }
|
2018-08-13 18:45:15 +03:00
|
|
|
bool DisableECS() { return mDisableECS; }
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult GetURI(nsCString& result);
|
|
|
|
nsresult GetCredentials(nsCString& result);
|
2019-08-26 22:52:20 +03:00
|
|
|
uint32_t GetRequestTimeout();
|
2018-02-01 12:20:49 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
LookupStatus CompleteLookup(nsHostRecord*, nsresult, mozilla::net::AddrInfo*,
|
|
|
|
bool pb,
|
|
|
|
const nsACString& aOriginSuffix) override;
|
|
|
|
LookupStatus CompleteLookupByType(nsHostRecord*, nsresult,
|
|
|
|
const nsTArray<nsCString>*, uint32_t,
|
2018-09-22 23:54:11 +03:00
|
|
|
bool pb) override;
|
2019-05-01 11:47:10 +03:00
|
|
|
void TRRBlacklist(const nsACString& host, const nsACString& originSuffix,
|
2018-10-22 18:38:18 +03:00
|
|
|
bool privateBrowsing, bool aParentsToo);
|
2019-05-01 11:47:10 +03:00
|
|
|
bool IsTRRBlacklisted(const nsACString& aHost,
|
|
|
|
const nsACString& aOriginSuffix, bool aPrivateBrowsing,
|
2018-10-22 18:38:18 +03:00
|
|
|
bool aParentsToo);
|
2019-05-01 11:47:10 +03:00
|
|
|
bool IsExcludedFromTRR(const nsACString& aHost);
|
2018-02-01 12:20:49 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool MaybeBootstrap(const nsACString& possible, nsACString& result);
|
2018-10-17 10:59:43 +03:00
|
|
|
enum TrrOkay { OKAY_NORMAL = 0, OKAY_TIMEOUT = 1, OKAY_BAD = 2 };
|
|
|
|
void TRRIsOkay(enum TrrOkay aReason);
|
2019-08-24 00:17:15 +03:00
|
|
|
bool ParentalControlEnabled() const { return mParentalControlEnabled; }
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~TRRService();
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult ReadPrefs(const char* name);
|
|
|
|
void GetPrefBranch(nsIPrefBranch** result);
|
2018-02-01 12:20:49 +03:00
|
|
|
void MaybeConfirm();
|
2019-02-01 23:46:00 +03:00
|
|
|
void MaybeConfirm_locked();
|
2019-08-24 00:17:15 +03:00
|
|
|
friend class ::nsDNSService;
|
|
|
|
void GetParentalControlEnabledInternal();
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
bool mInitialized;
|
|
|
|
Atomic<uint32_t, Relaxed> mMode;
|
|
|
|
Atomic<uint32_t, Relaxed> mTRRBlacklistExpireTime;
|
|
|
|
|
2019-02-01 23:46:00 +03:00
|
|
|
Mutex mLock;
|
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
nsCString mPrivateURI; // main thread only
|
|
|
|
nsCString mPrivateCred; // main thread only
|
|
|
|
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)
|
2018-03-06 18:07:29 +03:00
|
|
|
Atomic<bool, Relaxed> mEarlyAAAA; // allow use of AAAA results before A is in
|
2019-06-04 00:17:08 +03:00
|
|
|
Atomic<bool, Relaxed> mCheckIPv6Connectivity; // check IPv6 connectivity
|
2019-06-04 00:13:22 +03:00
|
|
|
Atomic<bool, Relaxed> mWaitForAllResponses; // Don't notify until all are in
|
|
|
|
Atomic<bool, Relaxed> mDisableIPv6; // don't even try
|
2019-06-04 00:17:08 +03:00
|
|
|
Atomic<bool, Relaxed> mDisableECS; // disable EDNS Client Subnet in requests
|
2018-10-03 14:53:46 +03:00
|
|
|
Atomic<uint32_t, Relaxed>
|
|
|
|
mDisableAfterFails; // this many fails in a row means failed TRR service
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
// TRR Blacklist storage
|
2019-02-01 23:46:00 +03:00
|
|
|
// mTRRBLStorage is only modified on the main thread, but we query whether it
|
|
|
|
// is initialized or not off the main thread as well. Therefore we need to
|
|
|
|
// lock while creating it and while accessing it off the main thread.
|
2018-02-01 12:20:49 +03:00
|
|
|
RefPtr<DataStorage> mTRRBLStorage;
|
|
|
|
Atomic<bool, Relaxed> mClearTRRBLStorage;
|
|
|
|
|
2019-03-21 15:41:41 +03:00
|
|
|
// A set of domains that we should not use TRR for.
|
|
|
|
nsTHashtable<nsCStringHashKey> mExcludedDomains;
|
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
enum ConfirmationState {
|
|
|
|
CONFIRM_INIT = 0,
|
|
|
|
CONFIRM_TRYING = 1,
|
|
|
|
CONFIRM_OK = 2,
|
|
|
|
CONFIRM_FAILED = 3
|
|
|
|
};
|
|
|
|
Atomic<ConfirmationState, Relaxed> mConfirmationState;
|
2018-03-09 11:05:48 +03:00
|
|
|
RefPtr<TRR> mConfirmer;
|
|
|
|
nsCOMPtr<nsITimer> mRetryConfirmTimer;
|
|
|
|
uint32_t mRetryConfirmInterval; // milliseconds until retry
|
2018-10-03 14:53:46 +03:00
|
|
|
Atomic<uint32_t, Relaxed> mTRRFailures;
|
2019-08-24 00:17:15 +03:00
|
|
|
bool mParentalControlEnabled;
|
2018-02-01 12:20:49 +03:00
|
|
|
};
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
extern TRRService* gTRRService;
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // TRRService_h_
|