2018-11-30 18:39:55 +03:00
|
|
|
/* vim:set ts=4 sw=2 sts=2 et cin: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2003-09-12 00:32:33 +04:00
|
|
|
|
|
|
|
#if defined(HAVE_RES_NINIT)
|
|
|
|
# include <sys/types.h>
|
|
|
|
# include <netinet/in.h>
|
2017-02-09 13:21:38 +03:00
|
|
|
# include <arpa/inet.h>
|
2003-09-12 00:32:33 +04:00
|
|
|
# include <arpa/nameser.h>
|
|
|
|
# include <resolv.h>
|
|
|
|
# define RES_RETRY_ON_FAILURE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2014-09-21 02:10:18 +04:00
|
|
|
#include <ctime>
|
2003-09-12 00:32:33 +04:00
|
|
|
#include "nsHostResolver.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2003-09-12 00:32:33 +04:00
|
|
|
#include "nsISupportsBase.h"
|
|
|
|
#include "nsISupportsUtils.h"
|
2018-06-27 22:29:12 +03:00
|
|
|
#include "nsIThreadManager.h"
|
2018-07-04 21:36:58 +03:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2015-02-19 08:14:00 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2018-07-04 21:36:58 +03:00
|
|
|
#include "nsXPCOMCIDInternal.h"
|
2003-09-12 00:32:33 +04:00
|
|
|
#include "prthread.h"
|
|
|
|
#include "prerror.h"
|
|
|
|
#include "prtime.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2015-09-16 06:49:53 +03:00
|
|
|
#include "PLDHashTable.h"
|
2003-09-12 00:32:33 +04:00
|
|
|
#include "plstr.h"
|
2018-11-19 18:23:39 +03:00
|
|
|
#include "nsQueryObject.h"
|
2005-09-23 01:38:12 +04:00
|
|
|
#include "nsURLHelper.h"
|
2012-06-12 21:06:20 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2018-09-15 11:10:21 +03:00
|
|
|
#include "nsThreadPool.h"
|
2014-09-21 02:10:18 +04:00
|
|
|
#include "GetAddrInfo.h"
|
2017-01-05 18:34:26 +03:00
|
|
|
#include "GeckoProfiler.h"
|
2018-02-01 12:20:49 +03:00
|
|
|
#include "TRR.h"
|
|
|
|
#include "TRRService.h"
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2012-03-13 02:53:18 +04:00
|
|
|
#include "mozilla/HashFunctions.h"
|
2011-12-17 06:24:17 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "mozilla/Telemetry.h"
|
2014-09-21 02:10:18 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_network.h"
|
2010-05-20 03:22:19 +04:00
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
using namespace mozilla;
|
2012-12-10 18:13:55 +04:00
|
|
|
using namespace mozilla::net;
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
|
2014-09-21 02:10:18 +04:00
|
|
|
// None of our implementations expose a TTL for negative responses, so we use a
|
|
|
|
// constant always.
|
|
|
|
static const unsigned int NEGATIVE_RECORD_LIFETIME = 60;
|
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2008-11-08 02:00:26 +03:00
|
|
|
// Use a persistent thread pool in order to avoid spinning up new threads all
|
|
|
|
// the time. In particular, thread creation results in a res_init() call from
|
|
|
|
// libc which is quite expensive.
|
|
|
|
//
|
|
|
|
// The pool dynamically grows between 0 and MAX_RESOLVER_THREADS in size. New
|
|
|
|
// requests go first to an idle thread. If that cannot be found and there are
|
|
|
|
// fewer than MAX_RESOLVER_THREADS currently in the pool a new thread is created
|
|
|
|
// for high priority requests. If the new request is at a lower priority a new
|
|
|
|
// thread will only be created if there are fewer than HighThreadThreshold
|
|
|
|
// currently outstanding. If a thread cannot be created or an idle thread
|
|
|
|
// located for the request it is queued.
|
|
|
|
//
|
|
|
|
// When the pool is greater than HighThreadThreshold in size a thread will be
|
|
|
|
// destroyed after ShortIdleTimeoutSeconds of idle time. Smaller pools use
|
|
|
|
// LongIdleTimeoutSeconds for a timeout period.
|
|
|
|
|
|
|
|
#define HighThreadThreshold MAX_RESOLVER_THREADS_FOR_ANY_PRIORITY
|
|
|
|
#define LongIdleTimeoutSeconds 300 // for threads 1 -> HighThreadThreshold
|
|
|
|
#define ShortIdleTimeoutSeconds \
|
|
|
|
60 // for threads HighThreadThreshold+1 -> MAX_RESOLVER_THREADS
|
|
|
|
|
2016-08-23 18:24:54 +03:00
|
|
|
static_assert(
|
|
|
|
HighThreadThreshold <= MAX_RESOLVER_THREADS,
|
|
|
|
"High Thread Threshold should be less equal Maximum allowed thread");
|
2003-09-12 00:32:33 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2020-01-18 16:48:34 +03:00
|
|
|
namespace mozilla::net {
|
2018-02-01 12:20:49 +03:00
|
|
|
LazyLogModule gHostResolverLog("nsHostResolver");
|
|
|
|
#define LOG(args) \
|
|
|
|
MOZ_LOG(mozilla::net::gHostResolverLog, mozilla::LogLevel::Debug, args)
|
2018-11-16 19:35:52 +03:00
|
|
|
#define LOG1(args) \
|
|
|
|
MOZ_LOG(mozilla::net::gHostResolverLog, mozilla::LogLevel::Error, args)
|
2018-02-01 12:20:49 +03:00
|
|
|
#define LOG_ENABLED() \
|
|
|
|
MOZ_LOG_TEST(mozilla::net::gHostResolverLog, mozilla::LogLevel::Debug)
|
2020-01-18 16:48:34 +03:00
|
|
|
} // namespace mozilla::net
|
2003-09-12 00:32:33 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#if defined(RES_RETRY_ON_FAILURE)
|
|
|
|
|
|
|
|
// this class represents the resolver state for a given thread. if we
|
|
|
|
// encounter a lookup failure, then we can invoke the Reset method on an
|
|
|
|
// instance of this class to reset the resolver (in case /etc/resolv.conf
|
|
|
|
// for example changed). this is mainly an issue on GNU systems since glibc
|
|
|
|
// only reads in /etc/resolv.conf once per thread. it may be an issue on
|
|
|
|
// other systems as well.
|
|
|
|
|
|
|
|
class nsResState {
|
|
|
|
public:
|
|
|
|
nsResState()
|
|
|
|
// initialize mLastReset to the time when this object
|
|
|
|
// is created. this means that a reset will not occur
|
|
|
|
// if a thread is too young. the alternative would be
|
|
|
|
// to initialize this to the beginning of time, so that
|
|
|
|
// the first failure would cause a reset, but since the
|
|
|
|
// thread would have just started up, it likely would
|
|
|
|
// already have current /etc/resolv.conf info.
|
|
|
|
: mLastReset(PR_IntervalNow()) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Reset() {
|
2003-09-12 00:32:33 +04:00
|
|
|
// reset no more than once per second
|
|
|
|
if (PR_IntervalToSeconds(PR_IntervalNow() - mLastReset) < 1) return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-07-17 02:37:28 +04:00
|
|
|
LOG(("Calling 'res_ninit'.\n"));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
mLastReset = PR_IntervalNow();
|
|
|
|
return (res_ninit(&_res) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
PRIntervalTime mLastReset;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // RES_RETRY_ON_FAILURE
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2013-07-20 02:40:00 +04:00
|
|
|
static inline bool IsHighPriority(uint16_t flags) {
|
|
|
|
return !(flags & (nsHostResolver::RES_PRIORITY_LOW |
|
|
|
|
nsHostResolver::RES_PRIORITY_MEDIUM));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsMediumPriority(uint16_t flags) {
|
|
|
|
return flags & nsHostResolver::RES_PRIORITY_MEDIUM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsLowPriority(uint16_t flags) {
|
|
|
|
return flags & nsHostResolver::RES_PRIORITY_LOW;
|
|
|
|
}
|
|
|
|
|
2020-02-07 12:42:00 +03:00
|
|
|
static nsIRequest::TRRMode EffectiveTRRMode(const nsCString& aHost,
|
|
|
|
ResolverMode aResolverMode,
|
|
|
|
nsIRequest::TRRMode aRequestMode);
|
|
|
|
|
2013-07-20 02:40:00 +04:00
|
|
|
//----------------------------------------------------------------------------
|
2004-09-01 23:55:58 +04:00
|
|
|
// this macro filters out any flags that are not used when constructing the
|
|
|
|
// host key. the significant flags are those that would affect the resulting
|
|
|
|
// host record (i.e., the flags that are passed down to PR_GetAddrInfoByName).
|
2020-01-07 23:20:38 +03:00
|
|
|
#define RES_KEY_FLAGS(_f) \
|
|
|
|
((_f) & (nsHostResolver::RES_CANON_NAME | nsHostResolver::RES_DISABLE_TRR | \
|
|
|
|
nsIDNSService::RESOLVE_TRR_MODE_MASK))
|
2018-08-24 17:09:22 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
#define IS_ADDR_TYPE(_type) ((_type) == nsIDNSService::RESOLVE_TYPE_DEFAULT)
|
|
|
|
#define IS_OTHER_TYPE(_type) ((_type) != nsIDNSService::RESOLVE_TYPE_DEFAULT)
|
|
|
|
|
2020-02-04 22:35:34 +03:00
|
|
|
nsHostKey::nsHostKey(const nsACString& aHost, const nsACString& aTrrServer,
|
|
|
|
uint16_t aType, uint16_t aFlags, uint16_t aAf, bool aPb,
|
|
|
|
const nsACString& aOriginsuffix)
|
2018-08-24 17:09:22 +03:00
|
|
|
: host(aHost),
|
2020-02-04 22:35:34 +03:00
|
|
|
mTrrServer(aTrrServer),
|
2018-09-22 23:54:11 +03:00
|
|
|
type(aType),
|
2018-08-24 17:09:22 +03:00
|
|
|
flags(aFlags),
|
|
|
|
af(aAf),
|
|
|
|
pb(aPb),
|
2020-01-07 23:20:38 +03:00
|
|
|
originSuffix(aOriginsuffix) {}
|
2004-09-01 23:55:58 +04:00
|
|
|
|
2017-12-23 01:08:17 +03:00
|
|
|
bool nsHostKey::operator==(const nsHostKey& other) const {
|
2020-02-07 12:42:00 +03:00
|
|
|
return host == other.host && mTrrServer == other.mTrrServer &&
|
|
|
|
type == other.type &&
|
2017-12-23 01:08:17 +03:00
|
|
|
RES_KEY_FLAGS(flags) == RES_KEY_FLAGS(other.flags) && af == other.af &&
|
|
|
|
originSuffix == other.originSuffix;
|
|
|
|
}
|
|
|
|
|
2018-01-08 01:22:01 +03:00
|
|
|
PLDHashNumber nsHostKey::Hash() const {
|
2020-02-04 22:35:34 +03:00
|
|
|
return AddToHash(HashString(host.get()), HashString(mTrrServer.get()), type,
|
|
|
|
RES_KEY_FLAGS(flags), af, HashString(originSuffix.get()));
|
2018-01-08 01:22:01 +03:00
|
|
|
}
|
|
|
|
|
2017-12-23 01:08:17 +03:00
|
|
|
size_t nsHostKey::SizeOfExcludingThis(
|
|
|
|
mozilla::MallocSizeOf mallocSizeOf) const {
|
|
|
|
size_t n = 0;
|
|
|
|
n += host.SizeOfExcludingThisIfUnshared(mallocSizeOf);
|
2020-02-04 22:35:34 +03:00
|
|
|
n += mTrrServer.SizeOfExcludingThisIfUnshared(mallocSizeOf);
|
2017-12-23 01:08:17 +03:00
|
|
|
n += originSuffix.SizeOfExcludingThisIfUnshared(mallocSizeOf);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2018-11-19 18:23:39 +03:00
|
|
|
NS_IMPL_ISUPPORTS0(nsHostRecord)
|
|
|
|
|
2017-12-23 01:08:17 +03:00
|
|
|
nsHostRecord::nsHostRecord(const nsHostKey& key)
|
2018-04-13 16:01:28 +03:00
|
|
|
: nsHostKey(key),
|
2020-02-07 12:42:00 +03:00
|
|
|
mEffectiveTRRMode(nsIRequest::TRR_DEFAULT_MODE),
|
2018-09-27 12:28:36 +03:00
|
|
|
mResolving(0),
|
|
|
|
negative(false),
|
|
|
|
mDoomed(false) {}
|
|
|
|
|
|
|
|
void nsHostRecord::Invalidate() { mDoomed = true; }
|
|
|
|
|
|
|
|
nsHostRecord::ExpirationStatus nsHostRecord::CheckExpiration(
|
|
|
|
const mozilla::TimeStamp& now) const {
|
|
|
|
if (!mGraceStart.IsNull() && now >= mGraceStart && !mValidEnd.IsNull() &&
|
|
|
|
now < mValidEnd) {
|
|
|
|
return nsHostRecord::EXP_GRACE;
|
|
|
|
}
|
|
|
|
if (!mValidEnd.IsNull() && now < mValidEnd) {
|
|
|
|
return nsHostRecord::EXP_VALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHostRecord::EXP_EXPIRED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHostRecord::SetExpiration(const mozilla::TimeStamp& now,
|
|
|
|
unsigned int valid, unsigned int grace) {
|
|
|
|
mValidStart = now;
|
2018-10-11 10:18:50 +03:00
|
|
|
if ((valid + grace) < 60) {
|
|
|
|
grace = 60 - valid;
|
|
|
|
LOG(("SetExpiration: artificially bumped grace to %d\n", grace));
|
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
mGraceStart = now + TimeDuration::FromSeconds(valid);
|
|
|
|
mValidEnd = now + TimeDuration::FromSeconds(valid + grace);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHostRecord::CopyExpirationTimesAndFlagsFrom(
|
|
|
|
const nsHostRecord* aFromHostRecord) {
|
|
|
|
// This is used to copy information from a cache entry to a record. All
|
|
|
|
// information necessary for HasUsableRecord needs to be copied.
|
|
|
|
mValidStart = aFromHostRecord->mValidStart;
|
|
|
|
mValidEnd = aFromHostRecord->mValidEnd;
|
|
|
|
mGraceStart = aFromHostRecord->mGraceStart;
|
|
|
|
mDoomed = aFromHostRecord->mDoomed;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsHostRecord::HasUsableResult(const mozilla::TimeStamp& now,
|
|
|
|
uint16_t queryFlags) const {
|
|
|
|
if (mDoomed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't use cached negative results for high priority queries.
|
|
|
|
if (negative && IsHighPriority(queryFlags)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CheckExpiration(now) == EXP_EXPIRED) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (negative) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return HasUsableResultInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t SizeOfResolveHostCallbackListExcludingHead(
|
|
|
|
const mozilla::LinkedList<RefPtr<nsResolveHostCallback>>& aCallbacks,
|
|
|
|
MallocSizeOf mallocSizeOf) {
|
|
|
|
size_t n = aCallbacks.sizeOfExcludingThis(mallocSizeOf);
|
|
|
|
|
|
|
|
for (const nsResolveHostCallback* t = aCallbacks.getFirst(); t;
|
|
|
|
t = t->getNext()) {
|
|
|
|
n += t->SizeOfIncludingThis(mallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2018-11-19 18:23:39 +03:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(AddrHostRecord, nsHostRecord, AddrHostRecord)
|
2018-09-27 12:28:36 +03:00
|
|
|
|
|
|
|
AddrHostRecord::AddrHostRecord(const nsHostKey& key)
|
|
|
|
: nsHostRecord(key),
|
|
|
|
addr_info_lock("AddrHostRecord.addr_info_lock"),
|
2018-04-13 16:01:28 +03:00
|
|
|
addr_info_gencnt(0),
|
|
|
|
addr_info(nullptr),
|
|
|
|
addr(nullptr),
|
2018-06-20 12:00:19 +03:00
|
|
|
mFirstTRRresult(NS_OK),
|
2018-04-13 16:01:28 +03:00
|
|
|
mTRRSuccess(0),
|
2018-05-13 00:36:26 +03:00
|
|
|
mNativeSuccess(0),
|
|
|
|
mNative(false),
|
2018-04-13 16:01:28 +03:00
|
|
|
mTRRUsed(false),
|
|
|
|
mNativeUsed(false),
|
|
|
|
onQueue(false),
|
|
|
|
usingAnyThread(false),
|
|
|
|
mDidCallbacks(false),
|
|
|
|
mGetTtl(false),
|
2018-05-13 00:36:26 +03:00
|
|
|
mResolveAgain(false),
|
2018-04-13 16:01:28 +03:00
|
|
|
mTrrAUsed(INIT),
|
|
|
|
mTrrAAAAUsed(INIT),
|
2018-09-27 12:28:36 +03:00
|
|
|
mTrrLock("AddrHostRecord.mTrrLock"),
|
2018-04-13 16:01:28 +03:00
|
|
|
mBlacklistedCount(0) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
AddrHostRecord::~AddrHostRecord() {
|
2018-11-19 18:23:39 +03:00
|
|
|
mCallbacks.clear();
|
2018-09-27 12:28:36 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::DNS_BLACKLIST_COUNT, mBlacklistedCount);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
bool AddrHostRecord::Blacklisted(NetAddr* aQuery) {
|
|
|
|
// must call locked
|
|
|
|
LOG(("Checking blacklist for host [%s], host record [%p].\n", host.get(),
|
|
|
|
this));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
// skip the string conversion for the common case of no blacklist
|
|
|
|
if (!mBlacklistedItems.Length()) {
|
|
|
|
return false;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
|
|
|
|
char buf[kIPv6CStrBufSize];
|
|
|
|
if (!NetAddrToString(aQuery, buf, sizeof(buf))) {
|
|
|
|
return false;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
nsDependentCString strQuery(buf);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mBlacklistedItems.Length(); i++) {
|
|
|
|
if (mBlacklistedItems.ElementAt(i).Equals(strQuery)) {
|
|
|
|
LOG(("Address [%s] is blacklisted for host [%s].\n", buf, host.get()));
|
|
|
|
return true;
|
2018-09-22 23:54:11 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
|
|
|
|
return false;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
void AddrHostRecord::ReportUnusable(NetAddr* aAddress) {
|
|
|
|
// must call locked
|
|
|
|
LOG(
|
|
|
|
("Adding address to blacklist for host [%s], host record [%p]."
|
|
|
|
"used trr=%d\n",
|
|
|
|
host.get(), this, mTRRSuccess));
|
|
|
|
|
|
|
|
++mBlacklistedCount;
|
|
|
|
|
|
|
|
char buf[kIPv6CStrBufSize];
|
|
|
|
if (NetAddrToString(aAddress, buf, sizeof(buf))) {
|
|
|
|
LOG(
|
|
|
|
("Successfully adding address [%s] to blacklist for host "
|
|
|
|
"[%s].\n",
|
|
|
|
buf, host.get()));
|
|
|
|
mBlacklistedItems.AppendElement(nsCString(buf));
|
|
|
|
}
|
2018-03-06 16:50:21 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
void AddrHostRecord::ResetBlacklist() {
|
|
|
|
// must call locked
|
|
|
|
LOG(("Resetting blacklist for host [%s], host record [%p].\n", host.get(),
|
|
|
|
this));
|
|
|
|
mBlacklistedItems.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t AddrHostRecord::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) const {
|
|
|
|
size_t n = mallocSizeOf(this);
|
|
|
|
|
|
|
|
n += nsHostKey::SizeOfExcludingThis(mallocSizeOf);
|
|
|
|
n += SizeOfResolveHostCallbackListExcludingHead(mCallbacks, mallocSizeOf);
|
|
|
|
|
|
|
|
n += addr_info ? addr_info->SizeOfIncludingThis(mallocSizeOf) : 0;
|
|
|
|
n += mallocSizeOf(addr.get());
|
|
|
|
|
|
|
|
n += mBlacklistedItems.ShallowSizeOfExcludingThis(mallocSizeOf);
|
|
|
|
for (size_t i = 0; i < mBlacklistedItems.Length(); i++) {
|
|
|
|
n += mBlacklistedItems[i].SizeOfExcludingThisIfUnshared(mallocSizeOf);
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AddrHostRecord::HasUsableResultInternal() const {
|
|
|
|
return addr_info || addr;
|
2014-09-21 02:10:18 +04:00
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
void AddrHostRecord::Cancel() {
|
|
|
|
MutexAutoLock trrlock(mTrrLock);
|
|
|
|
if (mTrrA) {
|
|
|
|
mTrrA->Cancel();
|
|
|
|
mTrrA = nullptr;
|
|
|
|
}
|
|
|
|
if (mTrrAAAA) {
|
|
|
|
mTrrAAAA->Cancel();
|
|
|
|
mTrrAAAA = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if the entry can be removed, or false if it should be left.
|
|
|
|
// Sets mResolveAgain true for entries being resolved right now.
|
2019-03-21 15:41:39 +03:00
|
|
|
bool AddrHostRecord::RemoveOrRefresh(bool aTrrToo) {
|
2018-09-27 12:28:36 +03:00
|
|
|
// no need to flush TRRed names, they're not resolved "locally"
|
|
|
|
MutexAutoLock lock(addr_info_lock);
|
2019-03-21 15:41:39 +03:00
|
|
|
if (addr_info && !aTrrToo && addr_info->IsTRR()) {
|
2018-09-27 12:28:36 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (mNative) {
|
|
|
|
if (!onQueue) {
|
|
|
|
// The request has been passed to the OS resolver. The resultant DNS
|
|
|
|
// record should be considered stale and not trusted; set a flag to
|
|
|
|
// ensure it is called again.
|
|
|
|
mResolveAgain = true;
|
|
|
|
}
|
|
|
|
// if Onqueue is true, the host entry is already added to the cache
|
|
|
|
// but is still pending to get resolved: just leave it in hash.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Already resolved; not in a pending state; remove from cache
|
|
|
|
return true;
|
2015-02-03 08:16:00 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
void AddrHostRecord::ResolveComplete() {
|
2018-02-01 12:20:49 +03:00
|
|
|
if (mNativeUsed) {
|
|
|
|
if (mNativeSuccess) {
|
|
|
|
uint32_t millis = static_cast<uint32_t>(mNativeDuration.ToMilliseconds());
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_NATIVE_LOOKUP_TIME, millis);
|
|
|
|
}
|
2020-05-30 11:39:02 +03:00
|
|
|
AccumulateCategoricalKeyed(
|
|
|
|
TRRService::AutoDetectedKey(),
|
|
|
|
mNativeSuccess ? Telemetry::LABELS_DNS_LOOKUP_DISPOSITION2::osOK
|
|
|
|
: Telemetry::LABELS_DNS_LOOKUP_DISPOSITION2::osFail);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
if (mTRRUsed) {
|
|
|
|
if (mTRRSuccess) {
|
|
|
|
uint32_t millis = static_cast<uint32_t>(mTrrDuration.ToMilliseconds());
|
2020-05-30 11:39:02 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::DNS_TRR_LOOKUP_TIME2,
|
|
|
|
TRRService::AutoDetectedKey(), millis);
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
2020-05-30 11:39:02 +03:00
|
|
|
AccumulateCategoricalKeyed(
|
|
|
|
TRRService::AutoDetectedKey(),
|
|
|
|
mTRRSuccess ? Telemetry::LABELS_DNS_LOOKUP_DISPOSITION2::trrOK
|
|
|
|
: Telemetry::LABELS_DNS_LOOKUP_DISPOSITION2::trrFail);
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
if (mTrrAUsed == OK) {
|
2020-05-30 11:39:02 +03:00
|
|
|
AccumulateCategoricalKeyed(
|
|
|
|
TRRService::AutoDetectedKey(),
|
|
|
|
Telemetry::LABELS_DNS_LOOKUP_DISPOSITION2::trrAOK);
|
2018-02-01 12:20:49 +03:00
|
|
|
} else if (mTrrAUsed == FAILED) {
|
2020-05-30 11:39:02 +03:00
|
|
|
AccumulateCategoricalKeyed(
|
|
|
|
TRRService::AutoDetectedKey(),
|
|
|
|
Telemetry::LABELS_DNS_LOOKUP_DISPOSITION2::trrAFail);
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mTrrAAAAUsed == OK) {
|
2020-05-30 11:39:02 +03:00
|
|
|
AccumulateCategoricalKeyed(
|
|
|
|
TRRService::AutoDetectedKey(),
|
|
|
|
Telemetry::LABELS_DNS_LOOKUP_DISPOSITION2::trrAAAAOK);
|
2018-02-01 12:20:49 +03:00
|
|
|
} else if (mTrrAAAAUsed == FAILED) {
|
2020-05-30 11:39:02 +03:00
|
|
|
AccumulateCategoricalKeyed(
|
|
|
|
TRRService::AutoDetectedKey(),
|
|
|
|
Telemetry::LABELS_DNS_LOOKUP_DISPOSITION2::trrAAAAFail);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 12:42:00 +03:00
|
|
|
if (mEffectiveTRRMode == nsIRequest::TRR_FIRST_MODE) {
|
2018-07-02 14:50:21 +03:00
|
|
|
if (flags & nsIDNSService::RESOLVE_DISABLE_TRR) {
|
|
|
|
// TRR is disabled on request, which is a next-level back-off method.
|
2020-05-30 11:39:02 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::DNS_TRR_DISABLED2,
|
|
|
|
TRRService::AutoDetectedKey(), mNativeSuccess);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-10-17 09:34:08 +03:00
|
|
|
if (mTRRSuccess) {
|
2020-05-30 11:39:02 +03:00
|
|
|
AccumulateCategoricalKeyed(TRRService::AutoDetectedKey(),
|
|
|
|
Telemetry::LABELS_DNS_TRR_FIRST3::TRR);
|
2018-10-17 09:34:08 +03:00
|
|
|
} else if (mNativeSuccess) {
|
|
|
|
if (mTRRUsed) {
|
2020-05-30 11:39:02 +03:00
|
|
|
AccumulateCategoricalKeyed(
|
|
|
|
TRRService::AutoDetectedKey(),
|
|
|
|
Telemetry::LABELS_DNS_TRR_FIRST3::NativeAfterTRR);
|
2018-07-02 14:50:21 +03:00
|
|
|
} else {
|
2020-05-30 11:39:02 +03:00
|
|
|
AccumulateCategoricalKeyed(TRRService::AutoDetectedKey(),
|
|
|
|
Telemetry::LABELS_DNS_TRR_FIRST3::Native);
|
2018-07-02 14:50:21 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2020-05-30 11:39:02 +03:00
|
|
|
AccumulateCategoricalKeyed(
|
|
|
|
TRRService::AutoDetectedKey(),
|
|
|
|
Telemetry::LABELS_DNS_TRR_FIRST3::BothFailed);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-05-10 14:02:00 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-05-10 14:02:00 +03:00
|
|
|
|
2020-02-07 12:42:00 +03:00
|
|
|
switch (mEffectiveTRRMode) {
|
|
|
|
case nsIRequest::TRR_DISABLED_MODE:
|
2018-02-01 12:20:49 +03:00
|
|
|
AccumulateCategorical(Telemetry::LABELS_DNS_LOOKUP_ALGORITHM::nativeOnly);
|
|
|
|
break;
|
2020-02-07 12:42:00 +03:00
|
|
|
case nsIRequest::TRR_FIRST_MODE:
|
2018-02-01 12:20:49 +03:00
|
|
|
AccumulateCategorical(Telemetry::LABELS_DNS_LOOKUP_ALGORITHM::trrFirst);
|
|
|
|
break;
|
2020-02-07 12:42:00 +03:00
|
|
|
case nsIRequest::TRR_ONLY_MODE:
|
2018-02-01 12:20:49 +03:00
|
|
|
AccumulateCategorical(Telemetry::LABELS_DNS_LOOKUP_ALGORITHM::trrOnly);
|
|
|
|
break;
|
2020-02-07 12:42:00 +03:00
|
|
|
case nsIRequest::TRR_DEFAULT_MODE:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("We should not have a default value here");
|
2019-06-01 12:44:20 +03:00
|
|
|
break;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mTRRUsed && !mTRRSuccess && mNativeSuccess && gTRRService) {
|
2018-10-22 18:38:18 +03:00
|
|
|
gTRRService->TRRBlacklist(nsCString(host), originSuffix, pb, true);
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
AddrHostRecord::DnsPriority AddrHostRecord::GetPriority(uint16_t aFlags) {
|
|
|
|
if (IsHighPriority(aFlags)) {
|
|
|
|
return AddrHostRecord::DNS_PRIORITY_HIGH;
|
2012-07-17 02:37:28 +04:00
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
if (IsMediumPriority(aFlags)) {
|
|
|
|
return AddrHostRecord::DNS_PRIORITY_MEDIUM;
|
2018-09-27 05:58:31 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
return AddrHostRecord::DNS_PRIORITY_LOW;
|
2011-07-21 17:18:01 +04:00
|
|
|
}
|
|
|
|
|
2020-05-04 22:56:51 +03:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(TypeHostRecord, nsHostRecord, TypeHostRecord,
|
|
|
|
nsIDNSTXTRecord, nsIDNSHTTPSSVCRecord)
|
2011-07-21 17:18:01 +04:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
TypeHostRecord::TypeHostRecord(const nsHostKey& key)
|
|
|
|
: nsHostRecord(key),
|
|
|
|
mTrrLock("TypeHostRecord.mTrrLock"),
|
|
|
|
mResultsLock("TypeHostRecord.mResultsLock") {}
|
2013-07-20 02:40:00 +04:00
|
|
|
|
2018-11-19 18:23:39 +03:00
|
|
|
TypeHostRecord::~TypeHostRecord() { mCallbacks.clear(); }
|
2018-09-27 05:58:31 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
bool TypeHostRecord::HasUsableResultInternal() const {
|
2020-05-04 22:56:51 +03:00
|
|
|
return !mResults.is<Nothing>();
|
2018-09-26 23:10:30 +03:00
|
|
|
}
|
2017-12-20 03:13:46 +03:00
|
|
|
|
2020-05-05 13:40:41 +03:00
|
|
|
NS_IMETHODIMP TypeHostRecord::GetRecords(CopyableTArray<nsCString>& aRecords) {
|
2018-09-27 12:28:36 +03:00
|
|
|
// deep copy
|
|
|
|
MutexAutoLock lock(mResultsLock);
|
2020-05-04 22:56:51 +03:00
|
|
|
|
|
|
|
if (!mResults.is<TypeRecordTxt>()) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2020-05-05 13:40:41 +03:00
|
|
|
aRecords = mResults.as<CopyableTArray<nsCString>>();
|
2020-05-04 22:56:51 +03:00
|
|
|
return NS_OK;
|
2018-09-27 12:28:36 +03:00
|
|
|
}
|
2017-12-20 03:13:46 +03:00
|
|
|
|
2020-05-04 22:56:51 +03:00
|
|
|
NS_IMETHODIMP TypeHostRecord::GetRecordsAsOneString(nsACString& aRecords) {
|
2018-09-27 12:28:36 +03:00
|
|
|
// deep copy
|
|
|
|
MutexAutoLock lock(mResultsLock);
|
2018-09-27 05:58:31 +03:00
|
|
|
|
2020-05-04 22:56:51 +03:00
|
|
|
if (!mResults.is<TypeRecordTxt>()) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2018-09-27 12:28:36 +03:00
|
|
|
}
|
2020-05-05 13:40:41 +03:00
|
|
|
auto& results = mResults.as<CopyableTArray<nsCString>>();
|
2020-05-04 22:56:51 +03:00
|
|
|
for (uint32_t i = 0; i < results.Length(); i++) {
|
|
|
|
aRecords.Append(results[i]);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2013-11-25 03:24:12 +04:00
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
size_t TypeHostRecord::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) const {
|
2013-11-25 03:24:12 +04:00
|
|
|
size_t n = mallocSizeOf(this);
|
|
|
|
|
2017-12-23 01:08:17 +03:00
|
|
|
n += nsHostKey::SizeOfExcludingThis(mallocSizeOf);
|
2017-12-20 03:13:46 +03:00
|
|
|
n += SizeOfResolveHostCallbackListExcludingHead(mCallbacks, mallocSizeOf);
|
2013-11-25 03:24:12 +04:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
void TypeHostRecord::Cancel() {
|
|
|
|
if (mTrr) {
|
|
|
|
mTrr->Cancel();
|
|
|
|
mTrr = nullptr;
|
2017-02-09 13:21:38 +03:00
|
|
|
}
|
2014-09-25 07:14:00 +04:00
|
|
|
}
|
|
|
|
|
2020-05-04 22:56:51 +03:00
|
|
|
uint32_t TypeHostRecord::GetType() {
|
|
|
|
MutexAutoLock lock(mResultsLock);
|
|
|
|
|
|
|
|
return mResults.match(
|
|
|
|
[](TypeRecordEmpty&) {
|
|
|
|
MOZ_ASSERT(false, "This should never be the case");
|
|
|
|
return nsIDNSService::RESOLVE_TYPE_DEFAULT;
|
|
|
|
},
|
|
|
|
[](TypeRecordTxt&) { return nsIDNSService::RESOLVE_TYPE_TXT; },
|
|
|
|
[](TypeRecordHTTPSSVC&) { return nsIDNSService::RESOLVE_TYPE_HTTPSSVC; });
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeRecordResultType TypeHostRecord::GetResults() {
|
|
|
|
MutexAutoLock lock(mResultsLock);
|
|
|
|
return mResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TypeHostRecord::GetRecords(nsTArray<RefPtr<nsISVCBRecord>>& aRecords) {
|
|
|
|
MutexAutoLock lock(mResultsLock);
|
|
|
|
if (!mResults.is<TypeRecordHTTPSSVC>()) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& results = mResults.as<TypeRecordHTTPSSVC>();
|
|
|
|
|
|
|
|
for (const SVCB& r : results) {
|
|
|
|
RefPtr<nsISVCBRecord> rec = new mozilla::net::SVCBRecord(r);
|
|
|
|
aRecords.AppendElement(rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2014-10-20 21:26:33 +04:00
|
|
|
static const char kPrefGetTtl[] = "network.dns.get-ttl";
|
2018-02-01 12:20:49 +03:00
|
|
|
static const char kPrefNativeIsLocalhost[] = "network.dns.native-is-localhost";
|
2018-07-04 22:25:28 +03:00
|
|
|
static const char kPrefThreadIdleTime[] =
|
|
|
|
"network.dns.resolver-thread-extra-idle-time-seconds";
|
2014-10-20 21:26:33 +04:00
|
|
|
static bool sGetTtlEnabled = false;
|
2018-02-01 12:20:49 +03:00
|
|
|
mozilla::Atomic<bool, mozilla::Relaxed> gNativeIsLocalhost;
|
2014-09-21 02:10:18 +04:00
|
|
|
|
2019-11-01 05:57:20 +03:00
|
|
|
static void DnsPrefChanged(const char* aPref, void* aSelf) {
|
2014-09-24 20:56:13 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
|
|
"Should be getting pref changed notification on main thread!");
|
|
|
|
|
2018-07-06 22:24:41 +03:00
|
|
|
MOZ_ASSERT(aSelf);
|
2014-09-24 20:56:13 +04:00
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
if (!strcmp(aPref, kPrefGetTtl)) {
|
2018-06-26 16:36:26 +03:00
|
|
|
#ifdef DNSQUERY_AVAILABLE
|
2018-02-01 12:20:49 +03:00
|
|
|
sGetTtlEnabled = Preferences::GetBool(kPrefGetTtl);
|
2018-06-26 16:36:26 +03:00
|
|
|
#endif
|
2018-02-01 12:20:49 +03:00
|
|
|
} else if (!strcmp(aPref, kPrefNativeIsLocalhost)) {
|
|
|
|
gNativeIsLocalhost = Preferences::GetBool(kPrefNativeIsLocalhost);
|
|
|
|
}
|
2014-09-21 02:10:18 +04:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS0(nsHostResolver)
|
2014-09-21 02:10:18 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsHostResolver::nsHostResolver(uint32_t maxCacheEntries,
|
2014-09-21 02:10:18 +04:00
|
|
|
uint32_t defaultCacheEntryLifetime,
|
|
|
|
uint32_t defaultGracePeriod)
|
2003-10-07 09:11:41 +04:00
|
|
|
: mMaxCacheEntries(maxCacheEntries),
|
2014-09-21 02:10:18 +04:00
|
|
|
mDefaultCacheLifetime(defaultCacheEntryLifetime),
|
|
|
|
mDefaultGracePeriod(defaultGracePeriod),
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
mLock("nsHostResolver.mLock"),
|
2018-08-09 19:56:02 +03:00
|
|
|
mIdleTaskCV(mLock, "nsHostResolver.mIdleTaskCV"),
|
2015-08-20 19:14:40 +03:00
|
|
|
mEvictionQSize(0),
|
|
|
|
mShutdown(true),
|
2018-08-09 19:56:02 +03:00
|
|
|
mNumIdleTasks(0),
|
2018-07-04 21:36:58 +03:00
|
|
|
mActiveTaskCount(0),
|
2009-01-14 20:18:27 +03:00
|
|
|
mActiveAnyThreadCount(0),
|
2008-11-08 02:00:26 +03:00
|
|
|
mPendingCount(0) {
|
2003-09-12 00:32:33 +04:00
|
|
|
mCreationTime = PR_Now();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-09 23:17:26 +03:00
|
|
|
mLongIdleTimeout = TimeDuration::FromSeconds(LongIdleTimeoutSeconds);
|
|
|
|
mShortIdleTimeout = TimeDuration::FromSeconds(ShortIdleTimeoutSeconds);
|
2003-09-12 00:32:33 +04:00
|
|
|
}
|
|
|
|
|
2016-11-01 15:44:09 +03:00
|
|
|
nsHostResolver::~nsHostResolver() = default;
|
2003-09-12 00:32:33 +04:00
|
|
|
|
|
|
|
nsresult nsHostResolver::Init() {
|
2018-02-01 12:20:49 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-09-21 02:10:18 +04:00
|
|
|
if (NS_FAILED(GetAddrInfoInit())) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2006-05-25 20:49:48 +04:00
|
|
|
|
2017-08-17 19:16:00 +03:00
|
|
|
LOG(("nsHostResolver::Init this=%p", this));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mShutdown = false;
|
2019-06-05 23:39:12 +03:00
|
|
|
mNCS = NetworkConnectivityService::GetSingleton();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-21 02:10:18 +04:00
|
|
|
// The preferences probably haven't been loaded from the disk yet, so we
|
|
|
|
// need to register a callback that will set up the experiment once they
|
|
|
|
// are. We also need to explicitly set a value for the props otherwise the
|
|
|
|
// callback won't be called.
|
|
|
|
{
|
2014-10-20 21:26:33 +04:00
|
|
|
DebugOnly<nsresult> rv = Preferences::RegisterCallbackAndCall(
|
|
|
|
&DnsPrefChanged, kPrefGetTtl, this);
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Could not register DNS TTL pref callback.");
|
2018-02-01 12:20:49 +03:00
|
|
|
rv = Preferences::RegisterCallbackAndCall(&DnsPrefChanged,
|
|
|
|
kPrefNativeIsLocalhost, this);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Could not register DNS pref callback.");
|
2014-09-21 02:10:18 +04:00
|
|
|
}
|
|
|
|
|
2006-05-25 20:49:48 +04:00
|
|
|
#if defined(HAVE_RES_NINIT)
|
|
|
|
// We want to make sure the system is using the correct resolver settings,
|
|
|
|
// so we force it to reload those settings whenever we startup a subsequent
|
|
|
|
// nsHostResolver instance. We assume that there is no reason to do this
|
|
|
|
// for the first nsHostResolver instance since that is usually created
|
|
|
|
// during application startup.
|
|
|
|
static int initCount = 0;
|
|
|
|
if (initCount++ > 0) {
|
2012-07-17 02:37:28 +04:00
|
|
|
LOG(("Calling 'res_ninit'.\n"));
|
2006-05-25 20:49:48 +04:00
|
|
|
res_ninit(&_res);
|
|
|
|
}
|
|
|
|
#endif
|
2018-02-01 12:20:49 +03:00
|
|
|
|
2018-07-04 22:25:28 +03:00
|
|
|
// We can configure the threadpool to keep threads alive for a while after
|
2018-08-09 19:56:02 +03:00
|
|
|
// the last ThreadFunc task has been executed.
|
2018-07-04 22:25:28 +03:00
|
|
|
int32_t poolTimeoutSecs = Preferences::GetInt(kPrefThreadIdleTime, 60);
|
|
|
|
uint32_t poolTimeoutMs;
|
|
|
|
if (poolTimeoutSecs < 0) {
|
|
|
|
// This means never shut down the idle threads
|
|
|
|
poolTimeoutMs = UINT32_MAX;
|
|
|
|
} else {
|
|
|
|
// We clamp down the idle time between 0 and one hour.
|
|
|
|
poolTimeoutMs =
|
|
|
|
mozilla::clamped<uint32_t>(poolTimeoutSecs * 1000, 0, 3600 * 1000);
|
2003-09-12 00:32:33 +04:00
|
|
|
}
|
|
|
|
|
2018-09-15 11:10:21 +03:00
|
|
|
nsCOMPtr<nsIThreadPool> threadPool = new nsThreadPool();
|
2018-07-04 21:36:58 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(threadPool->SetThreadLimit(MAX_RESOLVER_THREADS));
|
2008-11-08 02:00:26 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(threadPool->SetIdleThreadLimit(MAX_RESOLVER_THREADS));
|
2018-07-04 21:36:58 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(threadPool->SetIdleThreadTimeout(poolTimeoutMs));
|
|
|
|
MOZ_ALWAYS_SUCCEEDS(
|
|
|
|
threadPool->SetThreadStackSize(nsIThreadManager::kThreadPoolStackSize));
|
|
|
|
MOZ_ALWAYS_SUCCEEDS(threadPool->SetName(NS_LITERAL_CSTRING("DNS Resolver")));
|
2020-02-13 17:38:48 +03:00
|
|
|
mResolverThreads = ToRefPtr(std::move(threadPool));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-02-20 19:41:50 +03:00
|
|
|
void nsHostResolver::ClearPendingQueue(
|
|
|
|
LinkedList<RefPtr<nsHostRecord>>& aPendingQ) {
|
2008-11-08 02:00:26 +03:00
|
|
|
// loop through pending queue, erroring out pending lookups.
|
2018-02-20 19:41:50 +03:00
|
|
|
if (!aPendingQ.isEmpty()) {
|
|
|
|
for (RefPtr<nsHostRecord> rec : aPendingQ) {
|
2018-02-01 12:20:49 +03:00
|
|
|
rec->Cancel();
|
2018-09-27 12:28:36 +03:00
|
|
|
if (rec->IsAddrRecord()) {
|
2018-10-30 16:06:24 +03:00
|
|
|
CompleteLookup(rec, NS_ERROR_ABORT, nullptr, rec->pb,
|
|
|
|
rec->originSuffix);
|
2018-09-22 23:54:11 +03:00
|
|
|
} else {
|
2020-05-04 22:56:51 +03:00
|
|
|
mozilla::net::TypeRecordResultType empty(Nothing{});
|
|
|
|
CompleteLookupByType(rec, NS_ERROR_ABORT, empty, 0, rec->pb);
|
2008-11-08 02:00:26 +03:00
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2008-11-08 02:00:26 +03:00
|
|
|
}
|
|
|
|
|
2014-09-25 07:14:00 +04:00
|
|
|
//
|
|
|
|
// FlushCache() is what we call when the network has changed. We must not
|
|
|
|
// trust names that were resolved before this change. They may resolve
|
|
|
|
// differently now.
|
|
|
|
//
|
|
|
|
// This function removes all existing resolved host entries from the hash.
|
|
|
|
// Names that are in the pending queues can be left there. Entries in the
|
|
|
|
// cache that have 'Resolve' set true but not 'onQueue' are being resolved
|
|
|
|
// right now, so we need to mark them to get re-resolved on completion!
|
|
|
|
|
2019-03-21 15:41:39 +03:00
|
|
|
void nsHostResolver::FlushCache(bool aTrrToo) {
|
2015-06-11 03:09:32 +03:00
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
mEvictionQSize = 0;
|
|
|
|
|
|
|
|
// Clear the evictionQ and remove all its corresponding entries from
|
|
|
|
// the cache first
|
2018-02-20 19:41:50 +03:00
|
|
|
if (!mEvictionQ.isEmpty()) {
|
|
|
|
for (RefPtr<nsHostRecord> rec : mEvictionQ) {
|
2018-02-01 12:20:49 +03:00
|
|
|
rec->Cancel();
|
2018-01-08 01:22:01 +03:00
|
|
|
mRecordDB.Remove(*static_cast<nsHostKey*>(rec));
|
2015-06-11 03:09:32 +03:00
|
|
|
}
|
2018-02-20 19:41:50 +03:00
|
|
|
mEvictionQ.clear();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-06-11 03:09:32 +03:00
|
|
|
|
|
|
|
// Refresh the cache entries that are resolving RIGHT now, remove the rest.
|
2018-01-08 01:22:01 +03:00
|
|
|
for (auto iter = mRecordDB.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsHostRecord* record = iter.UserData();
|
2015-06-11 04:28:03 +03:00
|
|
|
// Try to remove the record, or mark it for refresh.
|
2018-09-27 12:28:36 +03:00
|
|
|
// By-type records are from TRR. We do not need to flush those entry
|
|
|
|
// when the network has change, because they are not local.
|
|
|
|
if (record->IsAddrRecord()) {
|
2018-11-19 18:23:39 +03:00
|
|
|
RefPtr<AddrHostRecord> addrRec = do_QueryObject(record);
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(addrRec);
|
2019-03-21 15:41:39 +03:00
|
|
|
if (addrRec->RemoveOrRefresh(aTrrToo)) {
|
2018-09-27 12:28:36 +03:00
|
|
|
if (record->isInList()) {
|
|
|
|
record->remove();
|
2015-06-11 04:28:03 +03:00
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
iter.Remove();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-06-11 04:28:03 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-25 07:14:00 +04:00
|
|
|
}
|
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
void nsHostResolver::Shutdown() {
|
2012-07-17 02:37:28 +04:00
|
|
|
LOG(("Shutting down host resolver.\n"));
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2014-09-21 02:10:18 +04:00
|
|
|
{
|
|
|
|
DebugOnly<nsresult> rv =
|
2014-10-20 21:26:33 +04:00
|
|
|
Preferences::UnregisterCallback(&DnsPrefChanged, kPrefGetTtl, this);
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Could not unregister DNS TTL pref callback.");
|
2014-09-21 02:10:18 +04:00
|
|
|
}
|
|
|
|
|
2018-02-20 19:41:50 +03:00
|
|
|
LinkedList<RefPtr<nsHostRecord>> pendingQHigh, pendingQMed, pendingQLow,
|
|
|
|
evictionQ;
|
2006-04-29 08:37:07 +04:00
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
{
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
MutexAutoLock lock(mLock);
|
2014-09-25 07:14:00 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mShutdown = true;
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2018-02-20 19:41:50 +03:00
|
|
|
// Move queues to temporary lists.
|
2018-05-30 22:15:35 +03:00
|
|
|
pendingQHigh = std::move(mHighQ);
|
|
|
|
pendingQMed = std::move(mMediumQ);
|
|
|
|
pendingQLow = std::move(mLowQ);
|
|
|
|
evictionQ = std::move(mEvictionQ);
|
2018-02-20 19:41:50 +03:00
|
|
|
|
2006-04-29 08:37:07 +04:00
|
|
|
mEvictionQSize = 0;
|
2008-11-08 02:00:26 +03:00
|
|
|
mPendingCount = 0;
|
2014-09-25 07:14:00 +04:00
|
|
|
|
2018-08-09 19:56:02 +03:00
|
|
|
if (mNumIdleTasks) mIdleTaskCV.NotifyAll();
|
|
|
|
|
2019-02-08 12:34:34 +03:00
|
|
|
for (auto iter = mRecordDB.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
iter.UserData()->Cancel();
|
|
|
|
}
|
2003-09-12 00:32:33 +04:00
|
|
|
// empty host database
|
2018-01-08 01:22:01 +03:00
|
|
|
mRecordDB.Clear();
|
2019-06-05 23:39:12 +03:00
|
|
|
|
|
|
|
mNCS = nullptr;
|
2003-09-12 00:32:33 +04:00
|
|
|
}
|
2014-09-25 07:14:00 +04:00
|
|
|
|
2018-02-20 19:41:50 +03:00
|
|
|
ClearPendingQueue(pendingQHigh);
|
|
|
|
ClearPendingQueue(pendingQMed);
|
|
|
|
ClearPendingQueue(pendingQLow);
|
2006-04-29 08:37:07 +04:00
|
|
|
|
2018-02-20 19:41:50 +03:00
|
|
|
if (!evictionQ.isEmpty()) {
|
|
|
|
for (RefPtr<nsHostRecord> rec : evictionQ) {
|
2018-02-01 12:20:49 +03:00
|
|
|
rec->Cancel();
|
2006-04-29 08:37:07 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2006-04-29 08:37:07 +04:00
|
|
|
|
2018-02-20 19:41:50 +03:00
|
|
|
pendingQHigh.clear();
|
|
|
|
pendingQMed.clear();
|
|
|
|
pendingQLow.clear();
|
|
|
|
evictionQ.clear();
|
|
|
|
|
2019-04-12 20:04:05 +03:00
|
|
|
// Shutdown the resolver threads, but with a timeout of 2 seconds (prefable).
|
2018-10-26 21:46:00 +03:00
|
|
|
// If the timeout is exceeded, any stuck threads will be leaked.
|
2019-04-12 20:04:05 +03:00
|
|
|
mResolverThreads->ShutdownWithTimeout(
|
|
|
|
StaticPrefs::network_dns_resolver_shutdown_timeout_ms());
|
2014-09-21 02:10:18 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
mozilla::DebugOnly<nsresult> rv = GetAddrInfoShutdown();
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to shutdown GetAddrInfo");
|
2014-09-21 02:10:18 +04:00
|
|
|
}
|
2008-11-08 02:00:26 +03:00
|
|
|
}
|
|
|
|
|
2020-02-04 22:35:34 +03:00
|
|
|
nsresult nsHostResolver::GetHostRecord(const nsACString& host,
|
2020-02-07 12:42:00 +03:00
|
|
|
const nsACString& aTrrServer,
|
|
|
|
uint16_t type, uint16_t flags,
|
|
|
|
uint16_t af, bool pb,
|
2018-02-01 12:20:49 +03:00
|
|
|
const nsCString& originSuffix,
|
|
|
|
nsHostRecord** result) {
|
|
|
|
MutexAutoLock lock(mLock);
|
2020-02-04 22:35:34 +03:00
|
|
|
nsHostKey key(host, aTrrServer, type, flags, af, pb, originSuffix);
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
RefPtr<nsHostRecord>& entry = mRecordDB.GetOrInsert(key);
|
|
|
|
if (!entry) {
|
2020-03-19 18:12:32 +03:00
|
|
|
if (IS_ADDR_TYPE(type)) {
|
|
|
|
entry = new AddrHostRecord(key);
|
|
|
|
} else {
|
|
|
|
entry = new TypeHostRecord(key);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
RefPtr<nsHostRecord> rec = entry;
|
2018-09-27 12:28:36 +03:00
|
|
|
if (rec->IsAddrRecord()) {
|
2018-11-19 18:23:39 +03:00
|
|
|
RefPtr<AddrHostRecord> addrRec = do_QueryObject(rec);
|
2018-09-27 12:28:36 +03:00
|
|
|
if (addrRec->addr) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
if (rec->mResolving) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2020-02-07 12:42:00 +03:00
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
*result = rec.forget().take();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-02-04 22:35:34 +03:00
|
|
|
nsresult nsHostResolver::ResolveHost(const nsACString& aHost,
|
2020-02-07 12:42:00 +03:00
|
|
|
const nsACString& aTrrServer,
|
|
|
|
uint16_t type,
|
2017-02-14 07:25:35 +03:00
|
|
|
const OriginAttributes& aOriginAttributes,
|
|
|
|
uint16_t flags, uint16_t af,
|
2017-12-20 03:13:46 +03:00
|
|
|
nsResolveHostCallback* aCallback) {
|
2018-09-27 12:28:36 +03:00
|
|
|
nsAutoCString host(aHost);
|
|
|
|
NS_ENSURE_TRUE(!host.IsEmpty(), NS_ERROR_UNEXPECTED);
|
|
|
|
|
2020-05-18 17:55:21 +03:00
|
|
|
nsAutoCString originSuffix;
|
|
|
|
aOriginAttributes.CreateSuffix(originSuffix);
|
|
|
|
LOG(("Resolving host [%s]<%s>%s%s type %d. [this=%p]\n", host.get(),
|
|
|
|
originSuffix.get(), flags & RES_BYPASS_CACHE ? " - bypassing cache" : "",
|
2018-09-27 12:28:36 +03:00
|
|
|
flags & RES_REFRESH_CACHE ? " - refresh cache" : "", type, this));
|
|
|
|
|
|
|
|
// ensure that we are working with a valid hostname before proceeding. see
|
|
|
|
// bug 304904 for details.
|
|
|
|
if (!net_IsValidHostName(host)) return NS_ERROR_UNKNOWN_HOST;
|
|
|
|
|
2003-10-07 09:11:41 +04:00
|
|
|
// By-Type requests use only TRR. If TRR is disabled we can return
|
|
|
|
// immediately.
|
2020-01-07 23:20:38 +03:00
|
|
|
if (IS_OTHER_TYPE(type) && Mode() == MODE_TRROFF) {
|
2015-10-18 08:24:48 +03:00
|
|
|
return NS_ERROR_UNKNOWN_HOST;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
// Used to try to parse to an IP address literal.
|
2003-10-07 09:11:41 +04:00
|
|
|
PRNetAddr tempAddr;
|
|
|
|
// Unfortunately, PR_StringToNetAddr does not properly initialize
|
2018-02-01 12:20:49 +03:00
|
|
|
// the output buffer in the case of IPv6 input. See bug 223145.
|
2018-09-27 12:28:36 +03:00
|
|
|
memset(&tempAddr, 0, sizeof(PRNetAddr));
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2003-10-07 09:11:41 +04:00
|
|
|
if (IS_OTHER_TYPE(type) &&
|
|
|
|
(PR_StringToNetAddr(host.get(), &tempAddr) == PR_SUCCESS)) {
|
|
|
|
// For by-type queries the host cannot be IP literal.
|
|
|
|
return NS_ERROR_UNKNOWN_HOST;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-10-07 09:11:41 +04:00
|
|
|
memset(&tempAddr, 0, sizeof(PRNetAddr));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-10-07 09:11:41 +04:00
|
|
|
RefPtr<nsResolveHostCallback> callback(aCallback);
|
|
|
|
// if result is set inside the lock, then we need to issue the
|
|
|
|
// callback before returning.
|
2018-01-08 01:22:01 +03:00
|
|
|
RefPtr<nsHostRecord> result;
|
2018-09-27 12:28:36 +03:00
|
|
|
nsresult status = NS_OK, rv = NS_OK;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mLock);
|
2018-01-08 01:22:01 +03:00
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
if (mShutdown) {
|
2020-03-19 18:12:32 +03:00
|
|
|
rv = NS_ERROR_NOT_INITIALIZED;
|
|
|
|
} else {
|
|
|
|
// check to see if there is already an entry for this |host|
|
|
|
|
// in the hash table. if so, then check to see if we can't
|
|
|
|
// just reuse the lookup result. otherwise, if there are
|
|
|
|
// any pending callbacks, then add to pending callbacks queue,
|
|
|
|
// and return. otherwise, add ourselves as first pending
|
|
|
|
// callback, and proceed to do the lookup.
|
|
|
|
|
|
|
|
if (gTRRService && gTRRService->IsExcludedFromTRR(host)) {
|
|
|
|
flags |= RES_DISABLE_TRR;
|
|
|
|
|
|
|
|
if (!aTrrServer.IsEmpty()) {
|
|
|
|
return NS_ERROR_UNKNOWN_HOST;
|
|
|
|
}
|
2019-11-21 13:02:33 +03:00
|
|
|
}
|
|
|
|
|
2020-03-19 18:12:32 +03:00
|
|
|
nsHostKey key(host, aTrrServer, type, flags, af,
|
|
|
|
(aOriginAttributes.mPrivateBrowsingId > 0), originSuffix);
|
|
|
|
RefPtr<nsHostRecord>& entry = mRecordDB.GetOrInsert(key);
|
|
|
|
if (!entry) {
|
|
|
|
if (IS_ADDR_TYPE(type)) {
|
|
|
|
entry = new AddrHostRecord(key);
|
|
|
|
} else {
|
|
|
|
entry = new TypeHostRecord(key);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2020-03-19 18:12:32 +03:00
|
|
|
RefPtr<nsHostRecord> rec = entry;
|
|
|
|
RefPtr<AddrHostRecord> addrRec = do_QueryObject(rec);
|
|
|
|
MOZ_ASSERT(rec, "Record should not be null");
|
|
|
|
MOZ_ASSERT((IS_ADDR_TYPE(type) && rec->IsAddrRecord() && addrRec) ||
|
|
|
|
(IS_OTHER_TYPE(type) && !rec->IsAddrRecord()));
|
|
|
|
|
|
|
|
// Check if the entry is vaild.
|
|
|
|
if (!(flags & RES_BYPASS_CACHE) &&
|
|
|
|
rec->HasUsableResult(TimeStamp::NowLoRes(), flags)) {
|
|
|
|
LOG((" Using cached record for host [%s].\n", host.get()));
|
|
|
|
// put reference to host record on stack...
|
|
|
|
result = rec;
|
|
|
|
if (IS_ADDR_TYPE(type)) {
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, METHOD_HIT);
|
|
|
|
}
|
2011-12-17 06:24:12 +04:00
|
|
|
|
2020-03-19 18:12:32 +03:00
|
|
|
// For entries that are in the grace period
|
|
|
|
// or all cached negative entries, use the cache but start a new
|
|
|
|
// lookup in the background
|
|
|
|
ConditionallyRefreshRecord(rec, host);
|
2018-09-27 12:28:36 +03:00
|
|
|
|
2020-03-19 18:12:32 +03:00
|
|
|
if (rec->negative) {
|
|
|
|
LOG((" Negative cache entry for host [%s].\n", host.get()));
|
|
|
|
if (IS_ADDR_TYPE(type)) {
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
|
|
|
|
METHOD_NEGATIVE_HIT);
|
|
|
|
}
|
|
|
|
status = NS_ERROR_UNKNOWN_HOST;
|
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
|
2020-03-19 18:12:32 +03:00
|
|
|
// Check whether host is a IP address for A/AAAA queries.
|
|
|
|
// For by-type records we have already checked at the beginning of
|
|
|
|
// this function.
|
|
|
|
} else if (addrRec && addrRec->addr) {
|
|
|
|
// if the host name is an IP address literal and has been
|
|
|
|
// parsed, go ahead and use it.
|
|
|
|
LOG((" Using cached address for IP Literal [%s].\n", host.get()));
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, METHOD_LITERAL);
|
|
|
|
result = rec;
|
|
|
|
} else if (addrRec &&
|
|
|
|
PR_StringToNetAddr(host.get(), &tempAddr) == PR_SUCCESS) {
|
|
|
|
// try parsing the host name as an IP address literal to short
|
|
|
|
// circuit full host resolution. (this is necessary on some
|
|
|
|
// platforms like Win9x. see bug 219376 for more details.)
|
|
|
|
LOG((" Host is IP Literal [%s].\n", host.get()));
|
|
|
|
|
|
|
|
// ok, just copy the result into the host record, and be
|
|
|
|
// done with it! ;-)
|
|
|
|
addrRec->addr = MakeUnique<NetAddr>();
|
|
|
|
PRNetAddrToNetAddr(&tempAddr, addrRec->addr.get());
|
|
|
|
// put reference to host record on stack...
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, METHOD_LITERAL);
|
|
|
|
result = rec;
|
|
|
|
|
|
|
|
// Check if we have received too many requests.
|
|
|
|
} else if (mPendingCount >= MAX_NON_PRIORITY_REQUESTS &&
|
|
|
|
!IsHighPriority(flags) && !rec->mResolving) {
|
|
|
|
LOG(
|
|
|
|
(" Lookup queue full: dropping %s priority request for "
|
|
|
|
"host [%s].\n",
|
|
|
|
IsMediumPriority(flags) ? "medium" : "low", host.get()));
|
2018-09-27 12:28:36 +03:00
|
|
|
if (IS_ADDR_TYPE(type)) {
|
2020-03-19 18:12:32 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, METHOD_OVERFLOW);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2020-03-19 18:12:32 +03:00
|
|
|
// This is a lower priority request and we are swamped, so refuse it.
|
|
|
|
rv = NS_ERROR_DNS_LOOKUP_QUEUE_FULL;
|
|
|
|
|
|
|
|
// Check if the offline flag is set.
|
|
|
|
} else if (flags & RES_OFFLINE) {
|
|
|
|
LOG((" Offline request for host [%s]; ignoring.\n", host.get()));
|
|
|
|
rv = NS_ERROR_OFFLINE;
|
|
|
|
|
|
|
|
// We do not have a valid result till here.
|
|
|
|
// A/AAAA request can check for an alternative entry like AF_UNSPEC.
|
|
|
|
// Otherwise we need to start a new query.
|
|
|
|
} else if (!rec->mResolving) {
|
|
|
|
// If this is an IPV4 or IPV6 specific request, check if there is
|
|
|
|
// an AF_UNSPEC entry we can use. Otherwise, hit the resolver...
|
|
|
|
if (addrRec && !(flags & RES_BYPASS_CACHE) &&
|
|
|
|
((af == PR_AF_INET) || (af == PR_AF_INET6))) {
|
|
|
|
// Check for an AF_UNSPEC entry.
|
|
|
|
|
|
|
|
const nsHostKey unspecKey(
|
|
|
|
host, aTrrServer, nsIDNSService::RESOLVE_TYPE_DEFAULT, flags,
|
|
|
|
PR_AF_UNSPEC, (aOriginAttributes.mPrivateBrowsingId > 0),
|
|
|
|
originSuffix);
|
|
|
|
RefPtr<nsHostRecord> unspecRec = mRecordDB.Get(unspecKey);
|
|
|
|
|
|
|
|
TimeStamp now = TimeStamp::NowLoRes();
|
|
|
|
if (unspecRec && unspecRec->HasUsableResult(now, flags)) {
|
|
|
|
MOZ_ASSERT(unspecRec->IsAddrRecord());
|
|
|
|
|
|
|
|
RefPtr<AddrHostRecord> addrUnspecRec = do_QueryObject(unspecRec);
|
|
|
|
MOZ_ASSERT(addrUnspecRec);
|
|
|
|
MOZ_ASSERT(addrUnspecRec->addr_info || addrUnspecRec->negative,
|
|
|
|
"Entry should be resolved or negative.");
|
|
|
|
|
|
|
|
LOG((" Trying AF_UNSPEC entry for host [%s] af: %s.\n", host.get(),
|
|
|
|
(af == PR_AF_INET) ? "AF_INET" : "AF_INET6"));
|
|
|
|
|
|
|
|
// We need to lock in case any other thread is reading
|
|
|
|
// addr_info.
|
|
|
|
MutexAutoLock lock(addrRec->addr_info_lock);
|
|
|
|
|
|
|
|
addrRec->addr_info = nullptr;
|
|
|
|
addrRec->addr_info_gencnt++;
|
|
|
|
if (unspecRec->negative) {
|
|
|
|
rec->negative = unspecRec->negative;
|
|
|
|
rec->CopyExpirationTimesAndFlagsFrom(unspecRec);
|
|
|
|
} else if (addrUnspecRec->addr_info) {
|
|
|
|
// Search for any valid address in the AF_UNSPEC entry
|
|
|
|
// in the cache (not blacklisted and from the right
|
|
|
|
// family).
|
|
|
|
NetAddrElement* addrIter =
|
|
|
|
addrUnspecRec->addr_info->mAddresses.getFirst();
|
|
|
|
while (addrIter) {
|
|
|
|
if ((af == addrIter->mAddress.inet.family) &&
|
|
|
|
!addrUnspecRec->Blacklisted(&addrIter->mAddress)) {
|
|
|
|
if (!addrRec->addr_info) {
|
|
|
|
addrRec->addr_info =
|
|
|
|
new AddrInfo(addrUnspecRec->addr_info->mHostName,
|
|
|
|
addrUnspecRec->addr_info->mCanonicalName,
|
|
|
|
addrUnspecRec->addr_info->IsTRR());
|
|
|
|
addrRec->addr_info_gencnt++;
|
|
|
|
rec->CopyExpirationTimesAndFlagsFrom(unspecRec);
|
|
|
|
}
|
|
|
|
addrRec->addr_info->AddAddress(new NetAddrElement(*addrIter));
|
2008-11-08 02:00:26 +03:00
|
|
|
}
|
2020-03-19 18:12:32 +03:00
|
|
|
addrIter = addrIter->getNext();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2020-03-19 18:12:32 +03:00
|
|
|
// Now check if we have a new record.
|
|
|
|
if (rec->HasUsableResult(now, flags)) {
|
|
|
|
result = rec;
|
|
|
|
if (rec->negative) {
|
|
|
|
status = NS_ERROR_UNKNOWN_HOST;
|
|
|
|
}
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, METHOD_HIT);
|
|
|
|
ConditionallyRefreshRecord(rec, host);
|
|
|
|
} else if (af == PR_AF_INET6) {
|
|
|
|
// For AF_INET6, a new lookup means another AF_UNSPEC
|
|
|
|
// lookup. We have already iterated through the
|
|
|
|
// AF_UNSPEC addresses, so we mark this record as
|
|
|
|
// negative.
|
|
|
|
LOG(
|
|
|
|
(" No AF_INET6 in AF_UNSPEC entry: "
|
|
|
|
"host [%s] unknown host.",
|
|
|
|
host.get()));
|
|
|
|
result = rec;
|
|
|
|
rec->negative = true;
|
2008-10-14 01:04:09 +04:00
|
|
|
status = NS_ERROR_UNKNOWN_HOST;
|
2020-03-19 18:12:32 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
|
|
|
|
METHOD_NEGATIVE_HIT);
|
2003-10-07 09:11:41 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:12:32 +03:00
|
|
|
// If this is a by-type request or if no valid record was found
|
|
|
|
// in the cache or this is an AF_UNSPEC request, then start a
|
|
|
|
// new lookup.
|
|
|
|
if (!result) {
|
|
|
|
LOG((" No usable record in cache for host [%s] type %d.", host.get(),
|
|
|
|
type));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-03-19 18:12:32 +03:00
|
|
|
if (flags & RES_REFRESH_CACHE) {
|
|
|
|
rec->Invalidate();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-03-19 18:12:32 +03:00
|
|
|
// Add callback to the list of pending callbacks.
|
|
|
|
rec->mCallbacks.insertBack(callback);
|
|
|
|
rec->flags = flags;
|
|
|
|
rv = NameLookup(rec);
|
|
|
|
if (IS_ADDR_TYPE(type)) {
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
|
|
|
|
METHOD_NETWORK_FIRST);
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv) && callback->isInList()) {
|
|
|
|
callback->remove();
|
|
|
|
} else {
|
|
|
|
LOG(
|
|
|
|
(" DNS lookup for host [%s] blocking "
|
|
|
|
"pending 'getaddrinfo' or trr query: "
|
|
|
|
"callback [%p]",
|
|
|
|
host.get(), callback.get()));
|
|
|
|
}
|
2020-03-19 16:06:48 +03:00
|
|
|
}
|
|
|
|
|
2020-03-19 18:12:32 +03:00
|
|
|
} else if (addrRec && addrRec->mDidCallbacks) {
|
|
|
|
// This is only for A/AAAA query.
|
|
|
|
// record is still pending more (TRR) data; make the callback
|
|
|
|
// at once
|
|
|
|
result = rec;
|
|
|
|
// make it count as a hit
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, METHOD_HIT);
|
|
|
|
|
|
|
|
LOG((" Host [%s] re-using early TRR resolve data\n", host.get()));
|
|
|
|
} else {
|
|
|
|
LOG(
|
|
|
|
(" Host [%s] is being resolved. Appending callback "
|
|
|
|
"[%p].",
|
|
|
|
host.get(), callback.get()));
|
2020-03-19 16:06:48 +03:00
|
|
|
|
2020-03-19 18:12:32 +03:00
|
|
|
rec->mCallbacks.insertBack(callback);
|
|
|
|
|
|
|
|
// Only A/AAAA records are place in a queue. The queues are for
|
|
|
|
// the native resolver, therefore by-type request are never put
|
|
|
|
// into a queue.
|
|
|
|
if (addrRec && addrRec->onQueue) {
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
|
|
|
|
METHOD_NETWORK_SHARED);
|
|
|
|
|
|
|
|
// Consider the case where we are on a pending queue of
|
|
|
|
// lower priority than the request is being made at.
|
|
|
|
// In that case we should upgrade to the higher queue.
|
|
|
|
|
|
|
|
if (IsHighPriority(flags) && !IsHighPriority(rec->flags)) {
|
|
|
|
// Move from (low|med) to high.
|
|
|
|
NS_ASSERTION(addrRec->onQueue,
|
|
|
|
"Moving Host Record Not Currently Queued");
|
|
|
|
rec->remove();
|
|
|
|
mHighQ.insertBack(rec);
|
|
|
|
rec->flags = flags;
|
|
|
|
ConditionallyCreateThread(rec);
|
|
|
|
} else if (IsMediumPriority(flags) && IsLowPriority(rec->flags)) {
|
|
|
|
// Move from low to med.
|
|
|
|
NS_ASSERTION(addrRec->onQueue,
|
|
|
|
"Moving Host Record Not Currently Queued");
|
|
|
|
rec->remove();
|
|
|
|
mMediumQ.insertBack(rec);
|
|
|
|
rec->flags = flags;
|
|
|
|
mIdleTaskCV.Notify();
|
|
|
|
}
|
2017-12-20 03:13:46 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 18:58:18 +03:00
|
|
|
if (result && callback->isInList()) {
|
2017-12-08 01:19:48 +03:00
|
|
|
callback->remove();
|
2014-09-21 02:10:18 +04:00
|
|
|
}
|
2019-10-09 18:58:18 +03:00
|
|
|
} // lock
|
|
|
|
|
|
|
|
if (result) {
|
2017-12-08 01:19:48 +03:00
|
|
|
callback->OnResolveHostComplete(this, result, status);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-21 02:10:18 +04:00
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2020-02-07 12:42:00 +03:00
|
|
|
void nsHostResolver::DetachCallback(
|
|
|
|
const nsACString& host, const nsACString& aTrrServer, uint16_t aType,
|
|
|
|
const OriginAttributes& aOriginAttributes, uint16_t flags, uint16_t af,
|
|
|
|
nsResolveHostCallback* aCallback, nsresult status) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsHostRecord> rec;
|
2017-12-20 03:13:46 +03:00
|
|
|
RefPtr<nsResolveHostCallback> callback(aCallback);
|
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
{
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
MutexAutoLock lock(mLock);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-02-14 07:25:35 +03:00
|
|
|
nsAutoCString originSuffix;
|
|
|
|
aOriginAttributes.CreateSuffix(originSuffix);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-02-04 22:35:34 +03:00
|
|
|
nsHostKey key(host, aTrrServer, aType, flags, af,
|
2018-02-01 12:20:49 +03:00
|
|
|
(aOriginAttributes.mPrivateBrowsingId > 0), originSuffix);
|
2018-01-08 01:22:01 +03:00
|
|
|
RefPtr<nsHostRecord> entry = mRecordDB.Get(key);
|
|
|
|
if (entry) {
|
2003-09-12 00:32:33 +04:00
|
|
|
// walk list looking for |callback|... we cannot assume
|
|
|
|
// that it will be there!
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-08 01:22:01 +03:00
|
|
|
for (nsResolveHostCallback* c : entry->mCallbacks) {
|
2017-12-20 03:13:46 +03:00
|
|
|
if (c == callback) {
|
2018-01-08 01:22:01 +03:00
|
|
|
rec = entry;
|
2017-12-20 03:13:46 +03:00
|
|
|
c->remove();
|
2003-09-12 00:32:33 +04:00
|
|
|
break;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-09-12 00:32:33 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2005-04-06 05:33:28 +04:00
|
|
|
// complete callback with the given status code; this would only be done if
|
|
|
|
// the record was in the process of being resolved.
|
2017-12-20 03:13:46 +03:00
|
|
|
if (rec) {
|
2017-12-08 01:19:48 +03:00
|
|
|
callback->OnResolveHostComplete(this, rec, status);
|
2017-12-20 03:13:46 +03:00
|
|
|
}
|
2003-09-12 00:32:33 +04:00
|
|
|
}
|
|
|
|
|
2018-08-09 19:56:02 +03:00
|
|
|
nsresult nsHostResolver::ConditionallyCreateThread(nsHostRecord* rec) {
|
|
|
|
if (mNumIdleTasks) {
|
|
|
|
// wake up idle tasks to process this lookup
|
|
|
|
mIdleTaskCV.Notify();
|
|
|
|
} else if ((mActiveTaskCount < HighThreadThreshold) ||
|
|
|
|
(IsHighPriority(rec->flags) &&
|
|
|
|
mActiveTaskCount < MAX_RESOLVER_THREADS)) {
|
|
|
|
nsCOMPtr<nsIRunnable> event = mozilla::NewRunnableMethod(
|
|
|
|
"nsHostResolver::ThreadFunc", this, &nsHostResolver::ThreadFunc);
|
|
|
|
mActiveTaskCount++;
|
|
|
|
nsresult rv =
|
|
|
|
mResolverThreads->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mActiveTaskCount--;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-08-09 19:56:02 +03:00
|
|
|
LOG((" Unable to find a thread for looking up host [%s].\n",
|
|
|
|
rec->host.get()));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-08-09 19:56:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-22 05:22:00 +03:00
|
|
|
// make sure the mTrrLock is held when this is used!
|
2018-09-27 12:28:36 +03:00
|
|
|
#define TRROutstanding() ((addrRec->mTrrA || addrRec->mTrrAAAA))
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
nsresult nsHostResolver::TrrLookup_unlocked(nsHostRecord* rec, TRR* pushedTRR) {
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
return TrrLookup(rec, pushedTRR);
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns error if no TRR resolve is issued
|
|
|
|
// it is impt this is not called while a native lookup is going on
|
2018-02-20 19:41:50 +03:00
|
|
|
nsresult nsHostResolver::TrrLookup(nsHostRecord* aRec, TRR* pushedTRR) {
|
2020-05-14 21:26:17 +03:00
|
|
|
if (Mode() == MODE_TRROFF || StaticPrefs::network_dns_disabled()) {
|
2020-01-07 23:20:38 +03:00
|
|
|
return NS_ERROR_UNKNOWN_HOST;
|
|
|
|
}
|
2020-05-28 09:58:04 +03:00
|
|
|
LOG(("TrrLookup host:%s af:%" PRId16, aRec->host.get(), aRec->af));
|
2020-01-07 23:20:38 +03:00
|
|
|
|
2018-02-20 19:41:50 +03:00
|
|
|
RefPtr<nsHostRecord> rec(aRec);
|
2018-02-01 12:20:49 +03:00
|
|
|
mLock.AssertCurrentThreadOwns();
|
2018-09-27 12:28:36 +03:00
|
|
|
|
2018-11-19 18:23:39 +03:00
|
|
|
RefPtr<AddrHostRecord> addrRec;
|
|
|
|
RefPtr<TypeHostRecord> typeRec;
|
2018-09-27 12:28:36 +03:00
|
|
|
|
|
|
|
if (rec->IsAddrRecord()) {
|
2018-11-19 18:23:39 +03:00
|
|
|
addrRec = do_QueryObject(rec);
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(addrRec);
|
|
|
|
} else {
|
2018-11-19 18:23:39 +03:00
|
|
|
typeRec = do_QueryObject(rec);
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(typeRec);
|
|
|
|
}
|
|
|
|
|
2018-02-22 05:22:00 +03:00
|
|
|
#ifdef DEBUG
|
2018-09-27 12:28:36 +03:00
|
|
|
if (rec->IsAddrRecord()) {
|
|
|
|
MutexAutoLock trrlock(addrRec->mTrrLock);
|
2018-02-22 05:22:00 +03:00
|
|
|
MOZ_ASSERT(!TRROutstanding());
|
|
|
|
}
|
|
|
|
#endif
|
2018-02-01 12:20:49 +03:00
|
|
|
MOZ_ASSERT(!rec->mResolving);
|
|
|
|
|
2020-02-07 12:42:00 +03:00
|
|
|
nsIRequest::TRRMode reqMode = rec->mEffectiveTRRMode;
|
|
|
|
if (rec->mTrrServer.IsEmpty() &&
|
|
|
|
(!gTRRService || !gTRRService->Enabled(reqMode))) {
|
2018-02-01 12:20:49 +03:00
|
|
|
LOG(("TrrLookup:: %s service not enabled\n", rec->host.get()));
|
|
|
|
return NS_ERROR_UNKNOWN_HOST;
|
|
|
|
}
|
|
|
|
|
2018-02-20 19:41:50 +03:00
|
|
|
if (rec->isInList()) {
|
2018-02-01 12:20:49 +03:00
|
|
|
// we're already on the eviction queue. This is a renewal
|
|
|
|
MOZ_ASSERT(mEvictionQSize);
|
2018-02-20 19:41:50 +03:00
|
|
|
AssertOnQ(rec, mEvictionQ);
|
|
|
|
|
|
|
|
rec->remove();
|
2018-02-01 12:20:49 +03:00
|
|
|
mEvictionQSize--;
|
|
|
|
}
|
2018-09-22 23:54:11 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
bool madeQuery = false;
|
2018-09-22 23:54:11 +03:00
|
|
|
|
|
|
|
if (addrRec) {
|
|
|
|
addrRec->mTRRSuccess = 0; // bump for each successful TRR response
|
|
|
|
addrRec->mTrrStart = TimeStamp::Now();
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->mTRRUsed = true; // this record gets TRR treatment
|
|
|
|
addrRec->mTrrAUsed = AddrHostRecord::INIT;
|
|
|
|
addrRec->mTrrAAAAUsed = AddrHostRecord::INIT;
|
2018-09-26 23:10:30 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
// If asking for AF_UNSPEC, issue both A and AAAA.
|
2018-09-22 23:54:11 +03:00
|
|
|
// If asking for AF_INET6 or AF_INET, do only that single type
|
2018-09-27 12:28:36 +03:00
|
|
|
enum TrrType rectype = (rec->af == AF_INET6) ? TRRTYPE_AAAA : TRRTYPE_A;
|
2018-09-26 23:10:30 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
if (pushedTRR) {
|
|
|
|
rectype = pushedTRR->Type();
|
|
|
|
}
|
|
|
|
bool sendAgain;
|
|
|
|
|
|
|
|
do {
|
|
|
|
sendAgain = false;
|
|
|
|
if ((TRRTYPE_AAAA == rectype) && gTRRService &&
|
2019-06-04 00:17:08 +03:00
|
|
|
(gTRRService->DisableIPv6() ||
|
2019-06-05 23:39:12 +03:00
|
|
|
(gTRRService->CheckIPv6Connectivity() && mNCS &&
|
|
|
|
mNCS->GetIPv6() == nsINetworkConnectivityService::NOT_AVAILABLE))) {
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
LOG(("TRR Resolve %s type %d\n", addrRec->host.get(), (int)rectype));
|
|
|
|
RefPtr<TRR> trr;
|
|
|
|
MutexAutoLock trrlock(addrRec->mTrrLock);
|
|
|
|
trr = pushedTRR ? pushedTRR : new TRR(this, rec, rectype);
|
2020-03-04 19:11:16 +03:00
|
|
|
if (pushedTRR || NS_SUCCEEDED(gTRRService->DispatchTRRRequest(trr))) {
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->mResolving++;
|
|
|
|
if (rectype == TRRTYPE_A) {
|
|
|
|
MOZ_ASSERT(!addrRec->mTrrA);
|
|
|
|
addrRec->mTrrA = trr;
|
|
|
|
addrRec->mTrrAUsed = AddrHostRecord::STARTED;
|
|
|
|
} else if (rectype == TRRTYPE_AAAA) {
|
|
|
|
MOZ_ASSERT(!addrRec->mTrrAAAA);
|
|
|
|
addrRec->mTrrAAAA = trr;
|
|
|
|
addrRec->mTrrAAAAUsed = AddrHostRecord::STARTED;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-09-27 12:28:36 +03:00
|
|
|
LOG(("TrrLookup called with bad type set: %d\n", rectype));
|
|
|
|
MOZ_ASSERT(0);
|
2018-09-27 05:58:31 +03:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
madeQuery = true;
|
2018-09-27 12:28:36 +03:00
|
|
|
if (!pushedTRR && (rec->af == AF_UNSPEC) && (rectype == TRRTYPE_A)) {
|
|
|
|
rectype = TRRTYPE_AAAA;
|
|
|
|
sendAgain = true;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
} while (sendAgain);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-09-27 12:28:36 +03:00
|
|
|
typeRec->mStart = TimeStamp::Now();
|
2020-05-04 22:56:51 +03:00
|
|
|
enum TrrType rectype;
|
|
|
|
|
|
|
|
// XXX this could use a more extensible approach.
|
|
|
|
if (rec->type == nsIDNSService::RESOLVE_TYPE_TXT) {
|
|
|
|
rectype = TRRTYPE_TXT;
|
|
|
|
} else if (rec->type == nsIDNSService::RESOLVE_TYPE_HTTPSSVC) {
|
|
|
|
rectype = TRRTYPE_HTTPSSVC;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
if (pushedTRR) {
|
2018-09-27 12:28:36 +03:00
|
|
|
rectype = pushedTRR->Type();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
LOG(("TRR Resolve %s type %d\n", typeRec->host.get(), (int)rectype));
|
2018-09-27 12:28:36 +03:00
|
|
|
RefPtr<TRR> trr;
|
|
|
|
MutexAutoLock trrlock(typeRec->mTrrLock);
|
|
|
|
trr = pushedTRR ? pushedTRR : new TRR(this, rec, rectype);
|
2020-03-04 19:11:16 +03:00
|
|
|
RefPtr<TRR> trrRequest = trr;
|
|
|
|
if (pushedTRR || NS_SUCCEEDED(gTRRService->DispatchTRRRequest(trr))) {
|
2018-09-27 12:28:36 +03:00
|
|
|
typeRec->mResolving++;
|
|
|
|
MOZ_ASSERT(!typeRec->mTrr);
|
|
|
|
typeRec->mTrr = trr;
|
|
|
|
madeQuery = true;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
return madeQuery ? NS_OK : NS_ERROR_UNKNOWN_HOST;
|
|
|
|
}
|
|
|
|
|
2018-02-20 19:41:50 +03:00
|
|
|
void nsHostResolver::AssertOnQ(nsHostRecord* rec,
|
|
|
|
LinkedList<RefPtr<nsHostRecord>>& q) {
|
2018-02-01 12:20:49 +03:00
|
|
|
#ifdef DEBUG
|
2018-02-20 19:41:50 +03:00
|
|
|
MOZ_ASSERT(!q.isEmpty());
|
|
|
|
MOZ_ASSERT(rec->isInList());
|
|
|
|
for (RefPtr<nsHostRecord> r : q) {
|
|
|
|
if (rec == r) {
|
|
|
|
return;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-20 19:41:50 +03:00
|
|
|
MOZ_ASSERT(false, "Did not find element");
|
2018-02-01 12:20:49 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-02-20 19:41:50 +03:00
|
|
|
nsresult nsHostResolver::NativeLookup(nsHostRecord* aRec) {
|
2020-05-14 21:26:17 +03:00
|
|
|
if (StaticPrefs::network_dns_disabled()) {
|
|
|
|
return NS_ERROR_UNKNOWN_HOST;
|
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
// Only A/AAAA request are resolve natively.
|
|
|
|
MOZ_ASSERT(aRec->IsAddrRecord());
|
2018-02-01 12:20:49 +03:00
|
|
|
mLock.AssertCurrentThreadOwns();
|
2018-09-27 12:28:36 +03:00
|
|
|
|
2018-02-20 19:41:50 +03:00
|
|
|
RefPtr<nsHostRecord> rec(aRec);
|
2018-11-19 18:23:39 +03:00
|
|
|
RefPtr<AddrHostRecord> addrRec;
|
|
|
|
addrRec = do_QueryObject(rec);
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(addrRec);
|
2018-02-01 12:20:49 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->mNativeStart = TimeStamp::Now();
|
2008-11-08 02:00:26 +03:00
|
|
|
|
|
|
|
// Add rec to one of the pending queues, possibly removing it from mEvictionQ.
|
2018-02-20 19:41:50 +03:00
|
|
|
if (rec->isInList()) {
|
2018-02-01 12:20:49 +03:00
|
|
|
MOZ_ASSERT(mEvictionQSize);
|
2018-02-20 19:41:50 +03:00
|
|
|
AssertOnQ(rec, mEvictionQ);
|
|
|
|
rec->remove(); // was on the eviction queue
|
2008-11-08 02:00:26 +03:00
|
|
|
mEvictionQSize--;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
switch (AddrHostRecord::GetPriority(rec->flags)) {
|
|
|
|
case AddrHostRecord::DNS_PRIORITY_HIGH:
|
2018-02-20 19:41:50 +03:00
|
|
|
mHighQ.insertBack(rec);
|
2014-09-21 02:10:18 +04:00
|
|
|
break;
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
case AddrHostRecord::DNS_PRIORITY_MEDIUM:
|
2018-02-20 19:41:50 +03:00
|
|
|
mMediumQ.insertBack(rec);
|
2014-09-21 02:10:18 +04:00
|
|
|
break;
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
case AddrHostRecord::DNS_PRIORITY_LOW:
|
2018-02-20 19:41:50 +03:00
|
|
|
mLowQ.insertBack(rec);
|
2014-09-21 02:10:18 +04:00
|
|
|
break;
|
|
|
|
}
|
2008-11-08 02:00:26 +03:00
|
|
|
mPendingCount++;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->mNative = true;
|
|
|
|
addrRec->mNativeUsed = true;
|
|
|
|
addrRec->onQueue = true;
|
|
|
|
addrRec->mResolving++;
|
2008-11-08 02:00:26 +03:00
|
|
|
|
2018-08-09 19:56:02 +03:00
|
|
|
nsresult rv = ConditionallyCreateThread(rec);
|
|
|
|
|
|
|
|
LOG((" DNS thread counters: total=%d any-live=%d idle=%d pending=%d\n",
|
2018-07-04 21:36:58 +03:00
|
|
|
static_cast<uint32_t>(mActiveTaskCount),
|
2015-08-20 19:14:40 +03:00
|
|
|
static_cast<uint32_t>(mActiveAnyThreadCount),
|
2018-08-09 19:56:02 +03:00
|
|
|
static_cast<uint32_t>(mNumIdleTasks),
|
2015-08-20 19:14:40 +03:00
|
|
|
static_cast<uint32_t>(mPendingCount)));
|
2008-11-08 02:00:26 +03:00
|
|
|
|
2018-08-09 19:56:02 +03:00
|
|
|
return rv;
|
2008-11-08 02:00:26 +03:00
|
|
|
}
|
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
ResolverMode nsHostResolver::Mode() {
|
|
|
|
if (gTRRService) {
|
|
|
|
return static_cast<ResolverMode>(gTRRService->Mode());
|
|
|
|
}
|
|
|
|
|
2020-02-07 12:42:00 +03:00
|
|
|
// If we don't have a TRR service just return MODE_TRROFF so we don't make
|
|
|
|
// any TRR requests by mistake.
|
|
|
|
return MODE_TRROFF;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
|
|
|
|
2020-01-07 23:20:38 +03:00
|
|
|
nsIRequest::TRRMode nsHostRecord::TRRMode() {
|
|
|
|
return nsIDNSService::GetTRRModeFromFlags(flags);
|
|
|
|
}
|
|
|
|
|
2020-02-07 12:42:00 +03:00
|
|
|
static nsIRequest::TRRMode EffectiveTRRMode(const nsCString& aHost,
|
|
|
|
ResolverMode aResolverMode,
|
|
|
|
nsIRequest::TRRMode aRequestMode) {
|
2020-01-07 23:20:38 +03:00
|
|
|
// For domains that are excluded from TRR or when parental control is enabled,
|
|
|
|
// we fallback to NativeLookup. This happens even in MODE_TRRONLY. By default
|
|
|
|
// localhost and local are excluded (so we cover *.local hosts) See the
|
|
|
|
// network.trr.excluded-domains pref.
|
|
|
|
bool skipTRR = true;
|
|
|
|
if (gTRRService) {
|
2020-02-07 12:42:00 +03:00
|
|
|
skipTRR = gTRRService->IsExcludedFromTRR(aHost) ||
|
2020-01-07 23:20:38 +03:00
|
|
|
(gTRRService->SkipTRRWhenParentalControlEnabled() &&
|
|
|
|
gTRRService->ParentalControlEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gTRRService) {
|
|
|
|
return aRequestMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skipTRR || aResolverMode == MODE_TRROFF ||
|
|
|
|
aRequestMode == nsIRequest::TRR_DISABLED_MODE ||
|
|
|
|
(aRequestMode == nsIRequest::TRR_DEFAULT_MODE &&
|
|
|
|
aResolverMode == MODE_NATIVEONLY)) {
|
|
|
|
return nsIRequest::TRR_DISABLED_MODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRequestMode == nsIRequest::TRR_DEFAULT_MODE &&
|
|
|
|
aResolverMode == MODE_TRRFIRST) {
|
|
|
|
return nsIRequest::TRR_FIRST_MODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRequestMode == nsIRequest::TRR_DEFAULT_MODE &&
|
|
|
|
aResolverMode == MODE_TRRONLY) {
|
|
|
|
return nsIRequest::TRR_ONLY_MODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aRequestMode;
|
|
|
|
}
|
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
// Kick-off a name resolve operation, using native resolver and/or TRR
|
|
|
|
nsresult nsHostResolver::NameLookup(nsHostRecord* rec) {
|
2020-05-28 09:58:04 +03:00
|
|
|
LOG(("NameLookup host:%s af:%" PRId16, rec->host.get(), rec->af));
|
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
nsresult rv = NS_ERROR_UNKNOWN_HOST;
|
|
|
|
if (rec->mResolving) {
|
|
|
|
LOG(("NameLookup %s while already resolving\n", rec->host.get()));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-02-04 22:35:34 +03:00
|
|
|
if (rec->mTrrServer.IsEmpty()) {
|
2020-02-07 12:42:00 +03:00
|
|
|
rec->mEffectiveTRRMode =
|
|
|
|
EffectiveTRRMode(rec->host, Mode(), rec->TRRMode());
|
2020-02-04 22:35:34 +03:00
|
|
|
} else {
|
2020-02-07 12:42:00 +03:00
|
|
|
rec->mEffectiveTRRMode = nsIRequest::TRR_ONLY_MODE;
|
2020-02-04 22:35:34 +03:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
if (rec->IsAddrRecord()) {
|
2018-11-19 18:23:39 +03:00
|
|
|
RefPtr<AddrHostRecord> addrRec = do_QueryObject(rec);
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(addrRec);
|
2018-09-22 23:54:11 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->mNativeUsed = false;
|
|
|
|
addrRec->mTRRUsed = false;
|
|
|
|
addrRec->mNativeSuccess = false;
|
|
|
|
addrRec->mTRRSuccess = 0;
|
|
|
|
addrRec->mDidCallbacks = false;
|
|
|
|
addrRec->mTrrAUsed = AddrHostRecord::INIT;
|
|
|
|
addrRec->mTrrAAAAUsed = AddrHostRecord::INIT;
|
2018-09-22 23:54:11 +03:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
|
2020-02-04 22:35:34 +03:00
|
|
|
if (!rec->mTrrServer.IsEmpty()) {
|
|
|
|
LOG(("NameLookup: %s use trr:%s", rec->host.get(), rec->mTrrServer.get()));
|
|
|
|
if (gTRRService->IsExcludedFromTRR(rec->host) ||
|
|
|
|
(gTRRService->SkipTRRWhenParentalControlEnabled() &&
|
|
|
|
gTRRService->ParentalControlEnabled())) {
|
|
|
|
return NS_ERROR_UNKNOWN_HOST;
|
|
|
|
}
|
|
|
|
return TrrLookup(rec);
|
|
|
|
}
|
|
|
|
|
2020-05-28 09:58:04 +03:00
|
|
|
LOG(("NameLookup: %s effectiveTRRmode: %d flags: %X", rec->host.get(),
|
|
|
|
rec->mEffectiveTRRMode, rec->flags));
|
2020-01-07 22:32:32 +03:00
|
|
|
|
2020-02-07 12:42:00 +03:00
|
|
|
if (rec->mEffectiveTRRMode != nsIRequest::TRR_DISABLED_MODE &&
|
2020-01-07 23:20:38 +03:00
|
|
|
!((rec->flags & RES_DISABLE_TRR))) {
|
2018-02-01 12:20:49 +03:00
|
|
|
rv = TrrLookup(rec);
|
|
|
|
}
|
|
|
|
|
2020-02-01 07:43:14 +03:00
|
|
|
bool serviceNotReady = !gTRRService || !gTRRService->IsConfirmed();
|
|
|
|
|
2020-02-07 12:42:00 +03:00
|
|
|
if (rec->mEffectiveTRRMode == nsIRequest::TRR_DISABLED_MODE ||
|
|
|
|
(rec->mEffectiveTRRMode == nsIRequest::TRR_FIRST_MODE &&
|
2020-06-04 14:12:19 +03:00
|
|
|
(rec->flags & RES_DISABLE_TRR || serviceNotReady || NS_FAILED(rv)))) {
|
2018-09-27 12:28:36 +03:00
|
|
|
if (!rec->IsAddrRecord()) {
|
2018-09-22 23:54:11 +03:00
|
|
|
return rv;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
|
|
|
rv = NativeLookup(rec);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2018-06-15 02:15:13 +03:00
|
|
|
nsresult nsHostResolver::ConditionallyRefreshRecord(nsHostRecord* rec,
|
|
|
|
const nsACString& host) {
|
2014-09-21 02:10:18 +04:00
|
|
|
if ((rec->CheckExpiration(TimeStamp::NowLoRes()) != nsHostRecord::EXP_VALID ||
|
2018-02-01 12:20:49 +03:00
|
|
|
rec->negative) &&
|
|
|
|
!rec->mResolving) {
|
2013-11-22 01:35:44 +04:00
|
|
|
LOG((" Using %s cache entry for host [%s] but starting async renewal.",
|
2018-06-15 02:15:13 +03:00
|
|
|
rec->negative ? "negative" : "positive", host.BeginReading()));
|
2018-02-01 12:20:49 +03:00
|
|
|
NameLookup(rec);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
if (rec->IsAddrRecord() && !rec->negative) {
|
2013-08-16 22:49:57 +04:00
|
|
|
// negative entries are constantly being refreshed, only
|
|
|
|
// track positive grace period induced renewals
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, METHOD_RENEWAL);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2013-08-16 22:49:57 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
void nsHostResolver::DeQueue(LinkedList<RefPtr<nsHostRecord>>& aQ,
|
|
|
|
AddrHostRecord** aResult) {
|
2018-02-20 19:41:50 +03:00
|
|
|
RefPtr<nsHostRecord> rec = aQ.popFirst();
|
2008-11-08 02:00:26 +03:00
|
|
|
mPendingCount--;
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(rec->IsAddrRecord());
|
2018-11-19 18:23:39 +03:00
|
|
|
RefPtr<AddrHostRecord> addrRec = do_QueryObject(rec);
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(addrRec);
|
|
|
|
addrRec->onQueue = false;
|
|
|
|
addrRec.forget(aResult);
|
2008-11-08 02:00:26 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
bool nsHostResolver::GetHostToLookup(AddrHostRecord** result) {
|
2018-08-09 19:56:02 +03:00
|
|
|
bool timedOut = false;
|
|
|
|
TimeDuration timeout;
|
|
|
|
TimeStamp epoch, now;
|
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
MutexAutoLock lock(mLock);
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2018-08-09 19:56:02 +03:00
|
|
|
timeout = (mNumIdleTasks >= HighThreadThreshold) ? mShortIdleTimeout
|
|
|
|
: mLongIdleTimeout;
|
|
|
|
epoch = TimeStamp::Now();
|
2014-09-21 02:10:18 +04:00
|
|
|
|
2018-08-09 19:56:02 +03:00
|
|
|
while (!mShutdown) {
|
|
|
|
// remove next record from Q; hand over owning reference. Check high, then
|
|
|
|
// med, then low
|
|
|
|
|
|
|
|
#define SET_GET_TTL(var, val) (var)->mGetTtl = sGetTtlEnabled && (val)
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2018-08-09 19:56:02 +03:00
|
|
|
if (!mHighQ.isEmpty()) {
|
|
|
|
DeQueue(mHighQ, result);
|
|
|
|
SET_GET_TTL(*result, false);
|
2018-08-07 10:03:57 +03:00
|
|
|
return true;
|
2008-11-08 02:00:26 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2018-08-09 19:56:02 +03:00
|
|
|
if (mActiveAnyThreadCount < HighThreadThreshold) {
|
|
|
|
if (!mMediumQ.isEmpty()) {
|
|
|
|
DeQueue(mMediumQ, result);
|
|
|
|
mActiveAnyThreadCount++;
|
|
|
|
(*result)->usingAnyThread = true;
|
|
|
|
SET_GET_TTL(*result, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mLowQ.isEmpty()) {
|
|
|
|
DeQueue(mLowQ, result);
|
|
|
|
mActiveAnyThreadCount++;
|
|
|
|
(*result)->usingAnyThread = true;
|
|
|
|
SET_GET_TTL(*result, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determining timeout is racy, so allow one cycle through checking the
|
|
|
|
// queues before exiting.
|
|
|
|
if (timedOut) break;
|
|
|
|
|
|
|
|
// wait for one or more of the following to occur:
|
|
|
|
// (1) the pending queue has a host record to process
|
|
|
|
// (2) the shutdown flag has been set
|
|
|
|
// (3) the thread has been idle for too long
|
|
|
|
|
|
|
|
mNumIdleTasks++;
|
|
|
|
mIdleTaskCV.Wait(timeout);
|
|
|
|
mNumIdleTasks--;
|
|
|
|
|
|
|
|
now = TimeStamp::Now();
|
|
|
|
|
|
|
|
if (now - epoch >= timeout) {
|
|
|
|
timedOut = true;
|
|
|
|
} else {
|
|
|
|
// It is possible that CondVar::Wait() was interrupted and returned
|
|
|
|
// early, in which case we will loop back and re-enter it. In that
|
|
|
|
// case we want to do so with the new timeout reduced to reflect
|
|
|
|
// time already spent waiting.
|
|
|
|
timeout -= now - epoch;
|
|
|
|
epoch = now;
|
2003-09-12 00:32:33 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2018-08-09 19:56:02 +03:00
|
|
|
// tell thread to exit...
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2003-09-12 00:32:33 +04:00
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
void nsHostResolver::PrepareRecordExpirationAddrRecord(
|
|
|
|
AddrHostRecord* rec) const {
|
2018-02-01 12:20:49 +03:00
|
|
|
// NOTE: rec->addr_info_lock is already held by parent
|
2014-09-21 02:10:18 +04:00
|
|
|
MOZ_ASSERT(((bool)rec->addr_info) != rec->negative);
|
2018-02-01 12:20:49 +03:00
|
|
|
mLock.AssertCurrentThreadOwns();
|
2014-09-21 02:10:18 +04:00
|
|
|
if (!rec->addr_info) {
|
|
|
|
rec->SetExpiration(TimeStamp::NowLoRes(), NEGATIVE_RECORD_LIFETIME, 0);
|
2018-05-16 23:05:03 +03:00
|
|
|
LOG(("Caching host [%s] negative record for %u seconds.\n", rec->host.get(),
|
|
|
|
NEGATIVE_RECORD_LIFETIME));
|
2014-09-21 02:10:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-20 21:26:33 +04:00
|
|
|
unsigned int lifetime = mDefaultCacheLifetime;
|
|
|
|
unsigned int grace = mDefaultGracePeriod;
|
2018-02-01 12:20:49 +03:00
|
|
|
|
2014-10-20 21:26:33 +04:00
|
|
|
unsigned int ttl = mDefaultCacheLifetime;
|
2018-05-10 13:32:00 +03:00
|
|
|
if (sGetTtlEnabled || rec->addr_info->IsTRR()) {
|
2014-09-21 02:10:18 +04:00
|
|
|
if (rec->addr_info && rec->addr_info->ttl != AddrInfo::NO_TTL_DATA) {
|
|
|
|
ttl = rec->addr_info->ttl;
|
|
|
|
}
|
2014-10-20 21:26:33 +04:00
|
|
|
lifetime = ttl;
|
|
|
|
grace = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-21 02:10:18 +04:00
|
|
|
|
|
|
|
rec->SetExpiration(TimeStamp::NowLoRes(), lifetime, grace);
|
2018-05-16 23:05:03 +03:00
|
|
|
LOG(("Caching host [%s] record for %u seconds (grace %d).", rec->host.get(),
|
|
|
|
lifetime, grace));
|
2014-09-21 02:10:18 +04:00
|
|
|
}
|
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
static nsresult merge_rrset(AddrInfo* rrto, AddrInfo* rrfrom) {
|
|
|
|
if (!rrto || !rrfrom) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
NetAddrElement* element;
|
|
|
|
while ((element = rrfrom->mAddresses.getFirst())) {
|
|
|
|
element->remove(); // unlist from old
|
|
|
|
rrto->AddAddress(element); // enlist on new
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-08 04:04:36 +03:00
|
|
|
static bool different_rrset(AddrInfo* rrset1, AddrInfo* rrset2) {
|
|
|
|
if (!rrset1 || !rrset2) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-30 10:30:27 +03:00
|
|
|
LOG(("different_rrset %s\n", rrset1->mHostName.get()));
|
2016-07-08 04:04:36 +03:00
|
|
|
nsTArray<NetAddr> orderedSet1;
|
|
|
|
nsTArray<NetAddr> orderedSet2;
|
|
|
|
|
2018-04-05 17:30:10 +03:00
|
|
|
if (rrset1->IsTRR() != rrset2->IsTRR()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-08 04:04:36 +03:00
|
|
|
for (NetAddrElement* element = rrset1->mAddresses.getFirst(); element;
|
|
|
|
element = element->getNext()) {
|
|
|
|
if (LOG_ENABLED()) {
|
|
|
|
char buf[128];
|
|
|
|
NetAddrToString(&element->mAddress, buf, 128);
|
|
|
|
LOG(("different_rrset add to set 1 %s\n", buf));
|
|
|
|
}
|
|
|
|
orderedSet1.InsertElementAt(orderedSet1.Length(), element->mAddress);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-08 04:04:36 +03:00
|
|
|
|
|
|
|
for (NetAddrElement* element = rrset2->mAddresses.getFirst(); element;
|
|
|
|
element = element->getNext()) {
|
|
|
|
if (LOG_ENABLED()) {
|
|
|
|
char buf[128];
|
|
|
|
NetAddrToString(&element->mAddress, buf, 128);
|
|
|
|
LOG(("different_rrset add to set 2 %s\n", buf));
|
|
|
|
}
|
|
|
|
orderedSet2.InsertElementAt(orderedSet2.Length(), element->mAddress);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-08 04:04:36 +03:00
|
|
|
|
|
|
|
if (orderedSet1.Length() != orderedSet2.Length()) {
|
|
|
|
LOG(("different_rrset true due to length change\n"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
orderedSet1.Sort();
|
|
|
|
orderedSet2.Sort();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < orderedSet1.Length(); ++i) {
|
|
|
|
if (!(orderedSet1[i] == orderedSet2[i])) {
|
|
|
|
LOG(("different_rrset true due to content change\n"));
|
|
|
|
return true;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-08 04:04:36 +03:00
|
|
|
LOG(("different_rrset false\n"));
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-22 23:54:11 +03:00
|
|
|
void nsHostResolver::AddToEvictionQ(nsHostRecord* rec) {
|
|
|
|
MOZ_ASSERT(!rec->isInList());
|
|
|
|
mEvictionQ.insertBack(rec);
|
|
|
|
if (mEvictionQSize < mMaxCacheEntries) {
|
|
|
|
mEvictionQSize++;
|
|
|
|
} else {
|
|
|
|
// remove first element on mEvictionQ
|
|
|
|
RefPtr<nsHostRecord> head = mEvictionQ.popFirst();
|
|
|
|
mRecordDB.Remove(*static_cast<nsHostKey*>(head.get()));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-22 23:54:11 +03:00
|
|
|
if (!head->negative) {
|
|
|
|
// record the age of the entry upon eviction.
|
|
|
|
TimeDuration age = TimeStamp::NowLoRes() - head->mValidStart;
|
2018-09-27 12:28:36 +03:00
|
|
|
if (rec->IsAddrRecord()) {
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_CLEANUP_AGE,
|
|
|
|
static_cast<uint32_t>(age.ToSeconds() / 60));
|
|
|
|
} else {
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_BY_TYPE_CLEANUP_AGE,
|
|
|
|
static_cast<uint32_t>(age.ToSeconds() / 60));
|
|
|
|
}
|
2018-09-22 23:54:11 +03:00
|
|
|
if (head->CheckExpiration(TimeStamp::Now()) !=
|
|
|
|
nsHostRecord::EXP_EXPIRED) {
|
2018-09-27 12:28:36 +03:00
|
|
|
if (rec->IsAddrRecord()) {
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_PREMATURE_EVICTION,
|
|
|
|
static_cast<uint32_t>(age.ToSeconds() / 60));
|
|
|
|
} else {
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_BY_TYPE_PREMATURE_EVICTION,
|
|
|
|
static_cast<uint32_t>(age.ToSeconds() / 60));
|
2018-09-22 23:54:11 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-09-22 23:54:11 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-09-22 23:54:11 +03:00
|
|
|
}
|
|
|
|
|
2014-09-25 07:14:00 +04:00
|
|
|
//
|
2017-12-08 01:19:48 +03:00
|
|
|
// CompleteLookup() checks if the resolving should be redone and if so it
|
2014-09-25 07:14:00 +04:00
|
|
|
// returns LOOKUP_RESOLVEAGAIN, but only if 'status' is not NS_ERROR_ABORT.
|
2018-10-30 16:06:24 +03:00
|
|
|
nsHostResolver::LookupStatus nsHostResolver::CompleteLookup(
|
|
|
|
nsHostRecord* rec, nsresult status, AddrInfo* aNewRRSet, bool pb,
|
|
|
|
const nsACString& aOriginsuffix) {
|
2018-02-01 12:20:49 +03:00
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
MOZ_ASSERT(rec);
|
|
|
|
MOZ_ASSERT(rec->pb == pb);
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(rec->IsAddrRecord());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-11-19 18:23:39 +03:00
|
|
|
RefPtr<AddrHostRecord> addrRec = do_QueryObject(rec);
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(addrRec);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-03-19 15:22:12 +03:00
|
|
|
RefPtr<AddrInfo> newRRSet(aNewRRSet);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-20 01:33:40 +03:00
|
|
|
bool trrResult = newRRSet && newRRSet->IsTRR();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
if (addrRec->mResolveAgain && (status != NS_ERROR_ABORT) && !trrResult) {
|
|
|
|
LOG(("nsHostResolver record %p resolve again due to flushcache\n",
|
|
|
|
addrRec.get()));
|
|
|
|
addrRec->mResolveAgain = false;
|
2018-02-20 01:33:40 +03:00
|
|
|
return LOOKUP_RESOLVEAGAIN;
|
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(addrRec->mResolving);
|
|
|
|
addrRec->mResolving--;
|
2018-02-01 12:20:49 +03:00
|
|
|
LOG(("nsHostResolver::CompleteLookup %s %p %X trr=%d stillResolving=%d\n",
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->host.get(), aNewRRSet, (unsigned int)status,
|
|
|
|
aNewRRSet ? aNewRRSet->IsTRR() : 0, addrRec->mResolving));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
if (trrResult) {
|
2018-09-27 12:28:36 +03:00
|
|
|
MutexAutoLock trrlock(addrRec->mTrrLock);
|
2018-02-01 12:20:49 +03:00
|
|
|
LOG(("TRR lookup Complete (%d) %s %s\n", newRRSet->IsTRR(),
|
|
|
|
newRRSet->mHostName.get(), NS_SUCCEEDED(status) ? "OK" : "FAILED"));
|
|
|
|
MOZ_ASSERT(TRROutstanding());
|
|
|
|
if (newRRSet->IsTRR() == TRRTYPE_A) {
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(addrRec->mTrrA);
|
|
|
|
addrRec->mTrrA = nullptr;
|
|
|
|
addrRec->mTrrAUsed =
|
2018-11-19 18:23:39 +03:00
|
|
|
NS_SUCCEEDED(status) ? AddrHostRecord::OK : AddrHostRecord::FAILED;
|
2018-02-01 12:20:49 +03:00
|
|
|
} else if (newRRSet->IsTRR() == TRRTYPE_AAAA) {
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(addrRec->mTrrAAAA);
|
|
|
|
addrRec->mTrrAAAA = nullptr;
|
|
|
|
addrRec->mTrrAAAAUsed =
|
|
|
|
NS_SUCCEEDED(status) ? AddrHostRecord::OK : AddrHostRecord::FAILED;
|
2018-02-01 12:20:49 +03:00
|
|
|
} else {
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(0);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
if (NS_SUCCEEDED(status)) {
|
|
|
|
addrRec->mTRRSuccess++;
|
|
|
|
if (addrRec->mTRRSuccess == 1) {
|
2018-06-21 13:02:03 +03:00
|
|
|
// Store the duration on first succesful TRR response. We
|
2018-09-27 12:28:36 +03:00
|
|
|
// don't know that there will be a second response nor can we
|
2019-06-01 12:44:20 +03:00
|
|
|
// tell which of two has useful data.
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->mTrrDuration = TimeStamp::Now() - addrRec->mTrrStart;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
if (TRROutstanding()) {
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->mFirstTRRresult = status;
|
|
|
|
if (NS_FAILED(status)) {
|
2018-02-01 12:20:49 +03:00
|
|
|
return LOOKUP_OK; // wait for outstanding
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
// There's another TRR complete pending. Wait for it and keep
|
2018-02-01 12:20:49 +03:00
|
|
|
// this RRset around until then.
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(!addrRec->mFirstTRR && newRRSet);
|
2019-03-19 15:22:12 +03:00
|
|
|
addrRec->mFirstTRR.swap(newRRSet); // autoPtr.swap()
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(addrRec->mFirstTRR && !newRRSet);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-06-01 12:44:20 +03:00
|
|
|
if (addrRec->mDidCallbacks) {
|
2018-02-01 12:20:49 +03:00
|
|
|
return LOOKUP_OK;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-06-04 00:13:22 +03:00
|
|
|
if (gTRRService && gTRRService->WaitForAllResponses()) {
|
|
|
|
LOG(("CompleteLookup: waiting for all responses!\n"));
|
|
|
|
return LOOKUP_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
if (addrRec->mTrrA && (!gTRRService || !gTRRService->EarlyAAAA())) {
|
2018-03-06 18:07:29 +03:00
|
|
|
// This is an early AAAA with a pending A response. Allowed
|
|
|
|
// only by pref.
|
2018-02-01 12:20:49 +03:00
|
|
|
LOG(("CompleteLookup: avoiding early use of TRR AAAA!\n"));
|
|
|
|
return LOOKUP_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
// we can do some callbacks with this partial result which requires
|
|
|
|
// a deep copy
|
2018-09-27 12:28:36 +03:00
|
|
|
newRRSet = new AddrInfo(addrRec->mFirstTRR);
|
2018-02-01 12:20:49 +03:00
|
|
|
MOZ_ASSERT(addrRec->mFirstTRR && newRRSet);
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-02-01 12:20:49 +03:00
|
|
|
// no more outstanding TRRs
|
|
|
|
// If mFirstTRR is set, merge those addresses into current set!
|
2018-09-27 12:28:36 +03:00
|
|
|
if (addrRec->mFirstTRR) {
|
2018-02-01 12:20:49 +03:00
|
|
|
if (NS_SUCCEEDED(status)) {
|
2019-06-04 00:05:27 +03:00
|
|
|
LOG(("Merging responses"));
|
2018-09-27 12:28:36 +03:00
|
|
|
merge_rrset(newRRSet, addrRec->mFirstTRR);
|
2018-02-01 12:20:49 +03:00
|
|
|
} else {
|
2019-06-04 00:05:27 +03:00
|
|
|
LOG(("Will use previous response"));
|
2019-03-19 15:22:12 +03:00
|
|
|
newRRSet.swap(addrRec->mFirstTRR); // transfers
|
2019-06-04 00:05:27 +03:00
|
|
|
// We must use the status of the first response, otherwise we'll
|
|
|
|
// pass an error result to the consumers.
|
|
|
|
status = addrRec->mFirstTRRresult;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->mFirstTRR = nullptr;
|
2016-07-08 04:04:36 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
if (NS_FAILED(addrRec->mFirstTRRresult) && NS_FAILED(status) &&
|
|
|
|
(addrRec->mFirstTRRresult != NS_ERROR_UNKNOWN_HOST) &&
|
2018-06-20 12:00:19 +03:00
|
|
|
(status != NS_ERROR_UNKNOWN_HOST)) {
|
|
|
|
// the errors are not failed resolves, that means
|
|
|
|
// something else failed, consider this as *TRR not used*
|
|
|
|
// for actually trying to resolve the host
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->mTRRUsed = false;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
if (!addrRec->mTRRSuccess) {
|
|
|
|
// no TRR success
|
|
|
|
newRRSet = nullptr;
|
|
|
|
status = NS_ERROR_UNKNOWN_HOST;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
2018-06-20 12:00:19 +03:00
|
|
|
|
2020-02-07 12:42:00 +03:00
|
|
|
if (!addrRec->mTRRSuccess &&
|
|
|
|
addrRec->mEffectiveTRRMode == nsIRequest::TRR_FIRST_MODE) {
|
2018-02-01 12:20:49 +03:00
|
|
|
MOZ_ASSERT(!addrRec->mResolving);
|
|
|
|
NativeLookup(addrRec);
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(addrRec->mResolving);
|
2018-02-01 12:20:49 +03:00
|
|
|
return LOOKUP_OK;
|
|
|
|
}
|
2018-03-13 12:37:50 +03:00
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
// continue
|
2014-08-21 18:53:11 +04:00
|
|
|
}
|
2009-01-14 20:18:27 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
} else { // native resolve completed
|
|
|
|
if (addrRec->usingAnyThread) {
|
|
|
|
mActiveAnyThreadCount--;
|
|
|
|
addrRec->usingAnyThread = false;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
2014-08-21 18:53:11 +04:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->mNative = false;
|
|
|
|
addrRec->mNativeSuccess = newRRSet ? true : false;
|
|
|
|
if (addrRec->mNativeSuccess) {
|
|
|
|
addrRec->mNativeDuration = TimeStamp::Now() - addrRec->mNativeStart;
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
// update record fields. We might have a addrRec->addr_info already if a
|
|
|
|
// previous lookup result expired and we're reresolving it or we get
|
|
|
|
// a late second TRR response.
|
2019-06-01 12:44:20 +03:00
|
|
|
if (!mShutdown) {
|
2018-09-27 12:28:36 +03:00
|
|
|
MutexAutoLock lock(addrRec->addr_info_lock);
|
2019-03-19 15:22:12 +03:00
|
|
|
RefPtr<AddrInfo> old_addr_info;
|
2018-09-27 12:28:36 +03:00
|
|
|
if (different_rrset(addrRec->addr_info, newRRSet)) {
|
2018-02-01 12:20:49 +03:00
|
|
|
LOG(("nsHostResolver record %p new gencnt\n", addrRec.get()));
|
|
|
|
old_addr_info = addrRec->addr_info;
|
2020-02-13 17:38:48 +03:00
|
|
|
addrRec->addr_info = std::move(newRRSet);
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->addr_info_gencnt++;
|
|
|
|
} else {
|
|
|
|
if (addrRec->addr_info && newRRSet) {
|
|
|
|
addrRec->addr_info->ttl = newRRSet->ttl;
|
2020-02-07 13:46:58 +03:00
|
|
|
// Update trr timings
|
|
|
|
addrRec->addr_info->SetTrrFetchDuration(
|
|
|
|
newRRSet->GetTrrFetchDuration());
|
|
|
|
addrRec->addr_info->SetTrrFetchDurationNetworkOnly(
|
|
|
|
newRRSet->GetTrrFetchDurationNetworkOnly());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2020-02-13 17:38:48 +03:00
|
|
|
old_addr_info = std::move(newRRSet);
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->negative = !addrRec->addr_info;
|
|
|
|
PrepareRecordExpirationAddrRecord(addrRec);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
bool doCallbacks = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-06-01 12:44:20 +03:00
|
|
|
if (trrResult && addrRec->mDidCallbacks) {
|
2018-02-01 12:20:49 +03:00
|
|
|
// already callback'ed on the first TRR response
|
|
|
|
LOG(("nsHostResolver Suppressing callback for second TRR response for %s\n",
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->host.get()));
|
2018-02-01 12:20:49 +03:00
|
|
|
doCallbacks = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
if (LOG_ENABLED()) {
|
2018-09-27 12:28:36 +03:00
|
|
|
MutexAutoLock lock(addrRec->addr_info_lock);
|
2018-02-01 12:20:49 +03:00
|
|
|
NetAddrElement* element;
|
2018-09-27 12:28:36 +03:00
|
|
|
if (addrRec->addr_info) {
|
|
|
|
for (element = addrRec->addr_info->mAddresses.getFirst(); element;
|
2018-02-01 12:20:49 +03:00
|
|
|
element = element->getNext()) {
|
|
|
|
char buf[128];
|
|
|
|
NetAddrToString(&element->mAddress, buf, sizeof(buf));
|
2018-09-27 12:28:36 +03:00
|
|
|
LOG(("CompleteLookup: %s has %s\n", addrRec->host.get(), buf));
|
2014-10-14 01:07:00 +04:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
} else {
|
2018-09-27 12:28:36 +03:00
|
|
|
LOG(("CompleteLookup: %s has NO address\n", addrRec->host.get()));
|
2003-09-12 00:32:33 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
if (doCallbacks) {
|
|
|
|
// get the list of pending callbacks for this lookup, and notify
|
|
|
|
// them that the lookup is complete.
|
2018-05-30 22:15:35 +03:00
|
|
|
mozilla::LinkedList<RefPtr<nsResolveHostCallback>> cbs =
|
|
|
|
std::move(rec->mCallbacks);
|
2018-02-01 12:20:49 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
LOG(("nsHostResolver record %p calling back dns users\n", addrRec.get()));
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
for (nsResolveHostCallback* c = cbs.getFirst(); c;
|
|
|
|
c = c->removeAndGetNext()) {
|
|
|
|
c->OnResolveHostComplete(this, rec, status);
|
2003-09-12 00:32:33 +04:00
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
addrRec->mDidCallbacks = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
if (!addrRec->mResolving && !mShutdown) {
|
|
|
|
addrRec->ResolveComplete();
|
2018-02-01 12:20:49 +03:00
|
|
|
|
2018-09-22 23:54:11 +03:00
|
|
|
AddToEvictionQ(rec);
|
2018-02-01 12:20:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DNSQUERY_AVAILABLE
|
|
|
|
// Unless the result is from TRR, resolve again to get TTL
|
|
|
|
bool fromTRR = false;
|
|
|
|
{
|
2018-09-27 12:28:36 +03:00
|
|
|
MutexAutoLock lock(addrRec->addr_info_lock);
|
|
|
|
if (addrRec->addr_info && addrRec->addr_info->IsTRR()) {
|
2018-02-01 12:20:49 +03:00
|
|
|
fromTRR = true;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
if (!fromTRR && !mShutdown && !addrRec->mGetTtl && !rec->mResolving &&
|
|
|
|
sGetTtlEnabled) {
|
|
|
|
LOG(("Issuing second async lookup for TTL for host [%s].",
|
|
|
|
addrRec->host.get()));
|
|
|
|
addrRec->flags = (addrRec->flags & ~RES_PRIORITY_MEDIUM) |
|
|
|
|
RES_PRIORITY_LOW | RES_DISABLE_TRR;
|
2018-02-01 12:20:49 +03:00
|
|
|
DebugOnly<nsresult> rv = NameLookup(rec);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Could not issue second async lookup for TTL.");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
#endif
|
2014-09-25 07:14:00 +04:00
|
|
|
return LOOKUP_OK;
|
2003-09-12 00:32:33 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-22 23:54:11 +03:00
|
|
|
nsHostResolver::LookupStatus nsHostResolver::CompleteLookupByType(
|
2020-05-04 22:56:51 +03:00
|
|
|
nsHostRecord* rec, nsresult status,
|
|
|
|
mozilla::net::TypeRecordResultType& aResult, uint32_t aTtl, bool pb) {
|
2018-09-22 23:54:11 +03:00
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
MOZ_ASSERT(rec);
|
|
|
|
MOZ_ASSERT(rec->pb == pb);
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(!rec->IsAddrRecord());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-11-19 18:23:39 +03:00
|
|
|
RefPtr<TypeHostRecord> typeRec = do_QueryObject(rec);
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(typeRec);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
MOZ_ASSERT(typeRec->mResolving);
|
|
|
|
typeRec->mResolving--;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
MutexAutoLock trrlock(typeRec->mTrrLock);
|
|
|
|
typeRec->mTrr = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
uint32_t duration = static_cast<uint32_t>(
|
|
|
|
(TimeStamp::Now() - typeRec->mStart).ToMilliseconds());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-22 23:54:11 +03:00
|
|
|
if (NS_FAILED(status)) {
|
2018-09-27 12:28:36 +03:00
|
|
|
LOG(("nsHostResolver::CompleteLookupByType record %p [%s] status %x\n",
|
|
|
|
typeRec.get(), typeRec->host.get(), (unsigned int)status));
|
|
|
|
typeRec->SetExpiration(TimeStamp::NowLoRes(), NEGATIVE_RECORD_LIFETIME, 0);
|
2020-05-04 22:56:51 +03:00
|
|
|
MOZ_ASSERT(aResult.is<TypeRecordEmpty>());
|
2018-09-22 23:54:11 +03:00
|
|
|
status = NS_ERROR_UNKNOWN_HOST;
|
2018-09-27 12:28:36 +03:00
|
|
|
typeRec->negative = true;
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_BY_TYPE_FAILED_LOOKUP_TIME, duration);
|
2018-09-22 23:54:11 +03:00
|
|
|
} else {
|
2020-05-04 22:56:51 +03:00
|
|
|
size_t recordCount = 0;
|
|
|
|
if (aResult.is<TypeRecordTxt>()) {
|
|
|
|
recordCount = aResult.as<TypeRecordTxt>().Length();
|
|
|
|
} else if (aResult.is<TypeRecordHTTPSSVC>()) {
|
|
|
|
recordCount = aResult.as<TypeRecordHTTPSSVC>().Length();
|
|
|
|
}
|
2018-09-27 12:28:36 +03:00
|
|
|
LOG(
|
|
|
|
("nsHostResolver::CompleteLookupByType record %p [%s], number of "
|
|
|
|
"records %zu\n",
|
2020-05-04 22:56:51 +03:00
|
|
|
typeRec.get(), typeRec->host.get(), recordCount));
|
2018-09-27 12:28:36 +03:00
|
|
|
MutexAutoLock typeLock(typeRec->mResultsLock);
|
2020-05-04 22:56:51 +03:00
|
|
|
typeRec->mResults = aResult;
|
2018-09-27 12:28:36 +03:00
|
|
|
typeRec->SetExpiration(TimeStamp::NowLoRes(), aTtl, mDefaultGracePeriod);
|
|
|
|
typeRec->negative = false;
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_BY_TYPE_SUCCEEDED_LOOKUP_TIME,
|
|
|
|
duration);
|
2018-09-22 23:54:11 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
mozilla::LinkedList<RefPtr<nsResolveHostCallback>> cbs =
|
|
|
|
std::move(typeRec->mCallbacks);
|
2018-09-22 23:54:11 +03:00
|
|
|
|
2018-09-27 12:28:36 +03:00
|
|
|
LOG(
|
|
|
|
("nsHostResolver::CompleteLookupByType record %p calling back dns "
|
|
|
|
"users\n",
|
|
|
|
typeRec.get()));
|
2018-09-22 23:54:11 +03:00
|
|
|
|
|
|
|
for (nsResolveHostCallback* c = cbs.getFirst(); c;
|
|
|
|
c = c->removeAndGetNext()) {
|
|
|
|
c->OnResolveHostComplete(this, rec, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
AddToEvictionQ(rec);
|
|
|
|
return LOOKUP_OK;
|
|
|
|
}
|
|
|
|
|
2018-06-15 02:15:13 +03:00
|
|
|
void nsHostResolver::CancelAsyncRequest(
|
2020-02-04 22:35:34 +03:00
|
|
|
const nsACString& host, const nsACString& aTrrServer, uint16_t aType,
|
2017-02-14 07:25:35 +03:00
|
|
|
const OriginAttributes& aOriginAttributes, uint16_t flags, uint16_t af,
|
|
|
|
nsIDNSListener* aListener, nsresult status)
|
2012-01-21 03:14:46 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
|
2018-02-01 12:20:49 +03:00
|
|
|
nsAutoCString originSuffix;
|
2017-02-14 07:25:35 +03:00
|
|
|
aOriginAttributes.CreateSuffix(originSuffix);
|
|
|
|
|
2012-01-21 03:14:46 +04:00
|
|
|
// Lookup the host record associated with host, flags & address family
|
2018-02-01 12:20:49 +03:00
|
|
|
|
2020-02-04 22:35:34 +03:00
|
|
|
nsHostKey key(host, aTrrServer, aType, flags, af,
|
2018-02-01 12:20:49 +03:00
|
|
|
(aOriginAttributes.mPrivateBrowsingId > 0), originSuffix);
|
2018-01-08 01:22:01 +03:00
|
|
|
RefPtr<nsHostRecord> rec = mRecordDB.Get(key);
|
|
|
|
if (rec) {
|
2013-09-19 23:28:26 +04:00
|
|
|
nsHostRecord* recPtr = nullptr;
|
2012-01-21 03:14:46 +04:00
|
|
|
|
2018-01-08 01:22:01 +03:00
|
|
|
for (RefPtr<nsResolveHostCallback> c : rec->mCallbacks) {
|
2017-12-20 03:13:46 +03:00
|
|
|
if (c->EqualsAsyncListener(aListener)) {
|
|
|
|
c->remove();
|
2018-01-08 01:22:01 +03:00
|
|
|
recPtr = rec;
|
2017-12-20 03:13:46 +03:00
|
|
|
c->OnResolveHostComplete(this, recPtr, status);
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-21 03:14:46 +04:00
|
|
|
// If there are no more callbacks, remove the hash table entry
|
2017-12-20 03:13:46 +03:00
|
|
|
if (recPtr && recPtr->mCallbacks.isEmpty()) {
|
2018-01-08 01:22:01 +03:00
|
|
|
mRecordDB.Remove(*static_cast<nsHostKey*>(recPtr));
|
2012-01-21 03:14:46 +04:00
|
|
|
// If record is on a Queue, remove it and then deref it
|
2018-02-20 19:41:50 +03:00
|
|
|
if (recPtr->isInList()) {
|
|
|
|
recPtr->remove();
|
2012-01-21 03:14:46 +04:00
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-01-21 03:14:46 +04:00
|
|
|
}
|
|
|
|
|
2013-11-25 03:24:12 +04:00
|
|
|
size_t nsHostResolver::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) const {
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
|
|
|
|
size_t n = mallocSizeOf(this);
|
2015-07-30 08:28:20 +03:00
|
|
|
|
2018-01-08 01:22:01 +03:00
|
|
|
n += mRecordDB.ShallowSizeOfExcludingThis(mallocSizeOf);
|
|
|
|
for (auto iter = mRecordDB.ConstIter(); !iter.Done(); iter.Next()) {
|
|
|
|
auto entry = iter.UserData();
|
|
|
|
n += entry->SizeOfIncludingThis(mallocSizeOf);
|
2015-07-30 08:28:20 +03:00
|
|
|
}
|
2013-11-25 03:24:12 +04:00
|
|
|
|
|
|
|
// The following fields aren't measured.
|
|
|
|
// - mHighQ, mMediumQ, mLowQ, mEvictionQ, because they just point to
|
2018-01-08 01:22:01 +03:00
|
|
|
// nsHostRecords that also pointed to by entries |mRecordDB|, and
|
|
|
|
// measured when |mRecordDB| is measured.
|
2013-11-25 03:24:12 +04:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2018-08-09 19:56:02 +03:00
|
|
|
void nsHostResolver::ThreadFunc() {
|
2013-11-22 01:35:44 +04:00
|
|
|
LOG(("DNS lookup thread - starting execution.\n"));
|
2012-06-12 21:06:20 +04:00
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
#if defined(RES_RETRY_ON_FAILURE)
|
|
|
|
nsResState rs;
|
|
|
|
#endif
|
2018-11-19 18:23:39 +03:00
|
|
|
RefPtr<AddrHostRecord> rec;
|
2019-03-19 15:22:12 +03:00
|
|
|
RefPtr<AddrInfo> ai;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-08-07 10:03:57 +03:00
|
|
|
do {
|
2018-08-09 19:56:02 +03:00
|
|
|
if (!rec) {
|
2018-11-19 18:23:39 +03:00
|
|
|
RefPtr<AddrHostRecord> tmpRec;
|
2018-08-09 19:56:02 +03:00
|
|
|
if (!GetHostToLookup(getter_AddRefs(tmpRec))) {
|
|
|
|
break; // thread shutdown signal
|
|
|
|
}
|
|
|
|
// GetHostToLookup() returns an owning reference
|
|
|
|
MOZ_ASSERT(tmpRec);
|
|
|
|
rec.swap(tmpRec);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-11-16 19:35:52 +03:00
|
|
|
LOG1(("DNS lookup thread - Calling getaddrinfo for host [%s].\n",
|
|
|
|
rec->host.get()));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-17 06:24:17 +04:00
|
|
|
TimeStamp startTime = TimeStamp::Now();
|
2014-09-21 02:10:18 +04:00
|
|
|
bool getTtl = rec->mGetTtl;
|
2018-06-25 09:03:44 +03:00
|
|
|
TimeDuration inQueue = startTime - rec->mNativeStart;
|
|
|
|
uint32_t ms = static_cast<uint32_t>(inQueue.ToMilliseconds());
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_NATIVE_QUEUING, ms);
|
2019-03-19 15:22:12 +03:00
|
|
|
nsresult status =
|
|
|
|
GetAddrInfo(rec->host, rec->af, rec->flags, getter_AddRefs(ai), getTtl);
|
2003-09-12 00:32:33 +04:00
|
|
|
#if defined(RES_RETRY_ON_FAILURE)
|
2014-09-21 02:10:18 +04:00
|
|
|
if (NS_FAILED(status) && rs.Reset()) {
|
2019-03-19 15:22:12 +03:00
|
|
|
status = GetAddrInfo(rec->host, rec->af, rec->flags, getter_AddRefs(ai),
|
|
|
|
getTtl);
|
2014-09-21 02:10:18 +04:00
|
|
|
}
|
2003-09-12 00:32:33 +04:00
|
|
|
#endif
|
2015-08-20 19:14:40 +03:00
|
|
|
|
|
|
|
{ // obtain lock to check shutdown and manage inter-module telemetry
|
|
|
|
MutexAutoLock lock(mLock);
|
2012-10-26 16:12:53 +04:00
|
|
|
|
2018-06-18 19:35:16 +03:00
|
|
|
if (!mShutdown) {
|
2018-11-16 19:35:52 +03:00
|
|
|
TimeDuration elapsed = TimeStamp::Now() - startTime;
|
|
|
|
uint32_t millis = static_cast<uint32_t>(elapsed.ToMilliseconds());
|
2015-02-19 08:14:00 +03:00
|
|
|
|
2018-10-30 16:06:24 +03:00
|
|
|
if (NS_SUCCEEDED(status)) {
|
2017-02-15 22:15:15 +03:00
|
|
|
Telemetry::HistogramID histogramID;
|
2018-10-30 16:06:24 +03:00
|
|
|
if (!rec->addr_info_gencnt) {
|
|
|
|
// Time for initial lookup.
|
|
|
|
histogramID = Telemetry::DNS_LOOKUP_TIME;
|
|
|
|
} else if (!getTtl) {
|
2014-09-25 07:14:00 +04:00
|
|
|
// Time for renewal; categorized by expiration strategy.
|
|
|
|
histogramID = Telemetry::DNS_RENEWAL_TIME;
|
|
|
|
} else {
|
|
|
|
// Time to get TTL; categorized by expiration strategy.
|
2018-05-16 23:05:03 +03:00
|
|
|
histogramID = Telemetry::DNS_RENEWAL_TIME_FOR_TTL;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-05-16 23:05:03 +03:00
|
|
|
Telemetry::Accumulate(histogramID, millis);
|
2014-09-25 07:14:00 +04:00
|
|
|
} else {
|
|
|
|
Telemetry::Accumulate(Telemetry::DNS_FAILED_LOOKUP_TIME, millis);
|
|
|
|
}
|
2018-08-09 19:56:02 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
|
2018-11-16 19:35:52 +03:00
|
|
|
LOG1(("DNS lookup thread - lookup completed for host [%s]: %s.\n",
|
|
|
|
rec->host.get(), ai ? "success" : "failure: unknown host"));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:14:00 +04:00
|
|
|
if (LOOKUP_RESOLVEAGAIN ==
|
2017-12-20 03:13:46 +03:00
|
|
|
CompleteLookup(rec, status, ai, rec->pb, rec->originSuffix)) {
|
2014-09-25 07:14:00 +04:00
|
|
|
// leave 'rec' assigned and loop to make a renewed host resolve
|
2018-05-16 23:05:03 +03:00
|
|
|
LOG(("DNS lookup thread - Re-resolving host [%s].\n", rec->host.get()));
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-09-27 12:28:36 +03:00
|
|
|
rec = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-08-09 19:56:02 +03:00
|
|
|
} while (true);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-07-04 21:36:58 +03:00
|
|
|
mActiveTaskCount--;
|
|
|
|
LOG(("DNS lookup thread - queue empty, task finished.\n"));
|
2003-09-12 00:32:33 +04:00
|
|
|
}
|
|
|
|
|
2018-03-21 16:35:53 +03:00
|
|
|
void nsHostResolver::SetCacheLimits(uint32_t aMaxCacheEntries,
|
|
|
|
uint32_t aDefaultCacheEntryLifetime,
|
|
|
|
uint32_t aDefaultGracePeriod) {
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
mMaxCacheEntries = aMaxCacheEntries;
|
|
|
|
mDefaultCacheLifetime = aDefaultCacheEntryLifetime;
|
|
|
|
mDefaultGracePeriod = aDefaultGracePeriod;
|
|
|
|
}
|
|
|
|
|
2014-09-21 02:10:18 +04:00
|
|
|
nsresult nsHostResolver::Create(uint32_t maxCacheEntries,
|
|
|
|
uint32_t defaultCacheEntryLifetime,
|
|
|
|
uint32_t defaultGracePeriod,
|
2003-09-12 00:32:33 +04:00
|
|
|
nsHostResolver** result) {
|
2018-07-03 00:46:16 +03:00
|
|
|
RefPtr<nsHostResolver> res = new nsHostResolver(
|
|
|
|
maxCacheEntries, defaultCacheEntryLifetime, defaultGracePeriod);
|
2003-09-12 00:32:33 +04:00
|
|
|
|
|
|
|
nsresult rv = res->Init();
|
2018-07-03 00:46:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2018-07-03 00:46:16 +03:00
|
|
|
res.forget(result);
|
|
|
|
return NS_OK;
|
2003-09-12 00:32:33 +04:00
|
|
|
}
|
2012-12-10 18:13:55 +04:00
|
|
|
|
2015-06-11 04:28:03 +03:00
|
|
|
void nsHostResolver::GetDNSCacheEntries(nsTArray<DNSCacheEntries>* args) {
|
2018-05-22 18:29:34 +03:00
|
|
|
MutexAutoLock lock(mLock);
|
2018-01-08 01:22:01 +03:00
|
|
|
for (auto iter = mRecordDB.Iter(); !iter.Done(); iter.Next()) {
|
2015-06-11 04:28:03 +03:00
|
|
|
// We don't pay attention to address literals, only resolved domains.
|
|
|
|
// Also require a host.
|
2018-01-08 01:22:01 +03:00
|
|
|
nsHostRecord* rec = iter.UserData();
|
2015-06-11 04:28:03 +03:00
|
|
|
MOZ_ASSERT(rec, "rec should never be null here!");
|
2018-09-27 12:28:36 +03:00
|
|
|
|
|
|
|
if (!rec) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-11-19 18:23:39 +03:00
|
|
|
// For now we only show A/AAAA records.
|
2018-09-27 12:28:36 +03:00
|
|
|
if (!rec->IsAddrRecord()) {
|
2015-06-11 04:28:03 +03:00
|
|
|
continue;
|
|
|
|
}
|
2012-12-10 18:13:55 +04:00
|
|
|
|
2015-06-11 04:28:03 +03:00
|
|
|
RefPtr<AddrHostRecord> addrRec = do_QueryObject(rec);
|
|
|
|
MOZ_ASSERT(addrRec);
|
|
|
|
if (!addrRec || !addrRec->addr_info) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-12-10 18:13:55 +04:00
|
|
|
|
2015-06-11 04:28:03 +03:00
|
|
|
DNSCacheEntries info;
|
|
|
|
info.hostname = rec->host;
|
2018-09-27 12:28:36 +03:00
|
|
|
info.family = rec->af;
|
|
|
|
info.expiration =
|
|
|
|
(int64_t)(rec->mValidEnd - TimeStamp::NowLoRes()).ToSeconds();
|
2015-06-11 04:28:03 +03:00
|
|
|
if (info.expiration <= 0) {
|
|
|
|
// We only need valid DNS cache entries
|
2018-09-27 12:28:36 +03:00
|
|
|
continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-12-10 18:13:55 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
{
|
2018-09-27 12:28:36 +03:00
|
|
|
MutexAutoLock lock(addrRec->addr_info_lock);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-06-11 04:28:03 +03:00
|
|
|
NetAddr* addr = nullptr;
|
2018-09-27 12:28:36 +03:00
|
|
|
NetAddrElement* addrElement = addrRec->addr_info->mAddresses.getFirst();
|
2012-12-24 01:08:43 +04:00
|
|
|
if (addrElement) {
|
|
|
|
addr = &addrElement->mAddress;
|
2012-12-10 18:13:55 +04:00
|
|
|
}
|
2015-06-11 04:28:03 +03:00
|
|
|
while (addr) {
|
|
|
|
char buf[kIPv6CStrBufSize];
|
|
|
|
if (NetAddrToString(addr, buf, sizeof(buf))) {
|
|
|
|
info.hostaddr.AppendElement(buf);
|
2012-12-10 18:13:55 +04:00
|
|
|
}
|
2015-06-11 04:28:03 +03:00
|
|
|
addr = nullptr;
|
|
|
|
addrElement = addrElement->getNext();
|
|
|
|
if (addrElement) {
|
|
|
|
addr = &addrElement->mAddress;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2015-06-11 04:28:03 +03:00
|
|
|
info.TRR = addrRec->addr_info->IsTRR();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-05-20 19:46:26 +03:00
|
|
|
info.originAttributesSuffix = iter.Key().originSuffix;
|
|
|
|
|
2020-05-05 13:40:41 +03:00
|
|
|
args->AppendElement(std::move(info));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-12-10 18:13:55 +04:00
|
|
|
}
|
2018-02-01 12:20:49 +03:00
|
|
|
|
|
|
|
#undef LOG
|
|
|
|
#undef LOG_ENABLED
|