Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/dns/TRRService.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#ifndef TRRService_h_
7
#define TRRService_h_
8
9
#include "mozilla/Atomics.h"
10
#include "mozilla/DataStorage.h"
11
#include "nsHostResolver.h"
12
#include "nsIObserver.h"
13
#include "nsWeakReference.h"
14
15
class nsIPrefBranch;
16
17
namespace mozilla {
18
namespace net {
19
20
class TRRService
21
  : public nsIObserver
22
  , public nsITimerCallback
23
  , public nsSupportsWeakReference
24
  , public AHostResolver
25
{
26
public:
27
  NS_DECL_THREADSAFE_ISUPPORTS
28
  NS_DECL_NSIOBSERVER
29
  NS_DECL_NSITIMERCALLBACK
30
31
  TRRService();
32
  nsresult Init();
33
  nsresult Start();
34
  bool Enabled();
35
36
0
  uint32_t Mode() { return mMode; }
37
0
  bool AllowRFC1918() { return mRfc1918; }
38
0
  bool UseGET() { return mUseGET; }
39
0
  bool EarlyAAAA() { return mEarlyAAAA; }
40
0
  bool DisableIPv6() { return mDisableIPv6; }
41
0
  bool DisableECS() { return mDisableECS; }
42
  nsresult GetURI(nsCString &result);
43
  nsresult GetCredentials(nsCString &result);
44
0
  uint32_t GetRequestTimeout() { return mTRRTimeout; }
45
46
  LookupStatus CompleteLookup(nsHostRecord *, nsresult, mozilla::net::AddrInfo *, bool pb) override;
47
  LookupStatus CompleteLookupByType(nsHostRecord *, nsresult, const nsTArray<nsCString> *, uint32_t, bool pb) override;
48
  void TRRBlacklist(const nsACString &host, bool privateBrowsing, bool aParentsToo);
49
  bool IsTRRBlacklisted(const nsACString &host, bool privateBrowsing, bool fullhost);
50
51
  bool MaybeBootstrap(const nsACString &possible, nsACString &result);
52
53
private:
54
  virtual  ~TRRService();
55
  nsresult ReadPrefs(const char *name);
56
  void GetPrefBranch(nsIPrefBranch **result);
57
  void MaybeConfirm();
58
59
  bool                      mInitialized;
60
  Atomic<uint32_t, Relaxed> mMode;
61
  Atomic<uint32_t, Relaxed> mTRRBlacklistExpireTime;
62
  Atomic<uint32_t, Relaxed> mTRRTimeout;
63
64
  Mutex mLock; // protects mPrivate* string
65
  nsCString mPrivateURI; // main thread only
66
  nsCString mPrivateCred; // main thread only
67
  nsCString mConfirmationNS;
68
  nsCString mBootstrapAddr;
69
70
  Atomic<bool, Relaxed> mWaitForCaptive; // wait for the captive portal to say OK before using TRR
71
  Atomic<bool, Relaxed> mRfc1918; // okay with local IP addresses in DOH responses?
72
  Atomic<bool, Relaxed> mCaptiveIsPassed; // set when captive portal check is passed
73
  Atomic<bool, Relaxed> mUseGET; // do DOH using GET requests (instead of POST)
74
  Atomic<bool, Relaxed> mEarlyAAAA; // allow use of AAAA results before A is in
75
  Atomic<bool, Relaxed> mDisableIPv6; // don't even try
76
  Atomic<bool, Relaxed> mDisableECS;  // disable EDNS Client Subnet in requests
77
78
  // TRR Blacklist storage
79
  RefPtr<DataStorage> mTRRBLStorage;
80
  Atomic<bool, Relaxed> mClearTRRBLStorage;
81
82
  enum ConfirmationState {
83
    CONFIRM_INIT = 0,
84
    CONFIRM_TRYING = 1,
85
    CONFIRM_OK = 2,
86
    CONFIRM_FAILED = 3
87
  };
88
  Atomic<ConfirmationState, Relaxed>  mConfirmationState;
89
  RefPtr<TRR> mConfirmer;
90
  nsCOMPtr<nsITimer> mRetryConfirmTimer;
91
  uint32_t mRetryConfirmInterval; // milliseconds until retry
92
};
93
94
extern TRRService *gTRRService;
95
96
} // namespace net
97
} // namespace mozilla
98
99
#endif // TRRService_h_