1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et tw=80 : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsDNSService2_h__
8 #define nsDNSService2_h__
10 #include "DNSServiceBase.h"
11 #include "nsClassHashtable.h"
12 #include "nsPIDNSService.h"
13 #include "nsIIDNService.h"
14 #include "nsIMemoryReporter.h"
15 #include "nsIObserver.h"
16 #include "nsHostResolver.h"
18 #include "nsTHashSet.h"
19 #include "nsHashKeys.h"
20 #include "mozilla/Mutex.h"
21 #include "mozilla/Attributes.h"
22 #include "TRRService.h"
26 class DNSServiceWrapper final
: public nsPIDNSService
{
28 NS_DECL_THREADSAFE_ISUPPORTS
29 NS_FORWARD_NSPIDNSSERVICE(PIDNSService()->)
30 NS_FORWARD_NSIDNSSERVICE(DNSService()->)
32 DNSServiceWrapper() = default;
34 static already_AddRefed
<nsIDNSService
> GetSingleton();
35 static void SwitchToBackupDNSService();
38 ~DNSServiceWrapper() = default;
39 nsIDNSService
* DNSService();
40 nsPIDNSService
* PIDNSService();
42 mozilla::Mutex mLock
{"DNSServiceWrapper.mLock"};
43 nsCOMPtr
<nsIDNSService
> mDNSServiceInUse
;
44 nsCOMPtr
<nsIDNSService
> mBackupDNSService
;
47 class nsDNSService final
: public mozilla::net::DNSServiceBase
,
48 public nsPIDNSService
,
49 public nsIMemoryReporter
{
51 NS_DECL_ISUPPORTS_INHERITED
52 NS_DECL_NSPIDNSSERVICE
55 NS_DECL_NSIMEMORYREPORTER
57 nsDNSService() = default;
59 static already_AddRefed
<nsIDNSService
> GetXPCOMSingleton();
61 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf
) const;
63 bool GetOffline() const;
66 friend class nsAuthSSPI
;
67 friend class DNSServiceWrapper
;
69 nsresult
DeprecatedSyncResolve(
70 const nsACString
& aHostname
, nsIDNSService::DNSFlags flags
,
71 const mozilla::OriginAttributes
& aOriginAttributes
,
72 nsIDNSRecord
** result
);
75 ~nsDNSService() = default;
77 void ReadPrefs(const char* name
) override
;
78 static already_AddRefed
<nsDNSService
> GetSingleton();
80 uint16_t GetAFForLookup(const nsACString
& host
,
81 nsIDNSService::DNSFlags flags
);
83 nsresult
PreprocessHostname(bool aLocalDomain
, const nsACString
& aInput
,
84 nsIIDNService
* aIDN
, nsACString
& aACE
);
86 nsresult
AsyncResolveInternal(
87 const nsACString
& aHostname
, uint16_t type
, nsIDNSService::DNSFlags flags
,
88 nsIDNSAdditionalInfo
* aInfo
, nsIDNSListener
* aListener
,
89 nsIEventTarget
* target_
,
90 const mozilla::OriginAttributes
& aOriginAttributes
,
91 nsICancelable
** result
);
93 nsresult
CancelAsyncResolveInternal(
94 const nsACString
& aHostname
, uint16_t aType
,
95 nsIDNSService::DNSFlags aFlags
, nsIDNSAdditionalInfo
* aInfo
,
96 nsIDNSListener
* aListener
, nsresult aReason
,
97 const mozilla::OriginAttributes
& aOriginAttributes
);
99 nsresult
ResolveInternal(const nsACString
& aHostname
,
100 nsIDNSService::DNSFlags flags
,
101 const mozilla::OriginAttributes
& aOriginAttributes
,
102 nsIDNSRecord
** result
);
104 // Locks the mutex and returns an addreffed resolver. May return null.
105 already_AddRefed
<nsHostResolver
> GetResolverLocked();
107 RefPtr
<nsHostResolver
> mResolver
;
108 nsCOMPtr
<nsIIDNService
> mIDN
;
110 // mLock protects access to mResolver, mLocalDomains, mIPv4OnlyDomains and
111 // mFailedSVCDomainNames
112 mozilla::Mutex mLock MOZ_UNANNOTATED
{"nsDNSServer.mLock"};
114 // mIPv4OnlyDomains is a comma-separated list of domains for which only
115 // IPv4 DNS lookups are performed. This allows the user to disable IPv6 on
116 // a per-domain basis and work around broken DNS servers. See bug 68796.
117 nsCString mIPv4OnlyDomains
;
118 nsCString mForceResolve
;
119 bool mDisableIPv6
= false;
120 bool mBlockDotOnion
= false;
121 bool mNotifyResolution
= false;
122 bool mOfflineLocalhost
= false;
123 bool mForceResolveOn
= false;
124 nsTHashSet
<nsCString
> mLocalDomains
;
125 RefPtr
<mozilla::net::TRRService
> mTrrService
;
127 uint32_t mResCacheEntries
= 0;
128 uint32_t mResCacheExpiration
= 0;
129 uint32_t mResCacheGrace
= 0;
130 bool mResolverPrefsUpdated
= false;
131 nsClassHashtable
<nsCStringHashKey
, nsTArray
<nsCString
>> mFailedSVCDomainNames
;
134 already_AddRefed
<nsIDNSService
> GetOrInitDNSService();
136 #endif // nsDNSService2_h__