1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
|
/* vim:set ts=4 sw=2 sts=2 et cin: */
/* 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/. */
#include "nsHostRecord.h"
#include "TRRQuery.h"
// Put DNSLogging.h at the end to avoid LOG being overwritten by other headers.
#include "DNSLogging.h"
#include "mozilla/StaticPrefs_network.h"
#include "mozilla/glean/NetwerkDnsMetrics.h"
#include "mozilla/ThreadSafety.h"
#include "TRRService.h"
#include "mozilla/ProfilerMarkers.h"
//----------------------------------------------------------------------------
// 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).
#define RES_KEY_FLAGS(_f) \
((_f) & \
((StaticPrefs::network_dns_always_ai_canonname() \
? 0 \
: nsIDNSService::RESOLVE_CANONICAL_NAME) | \
nsIDNSService::RESOLVE_DISABLE_TRR | \
nsIDNSService::RESOLVE_TRR_MODE_MASK | nsIDNSService::RESOLVE_IP_HINT))
#define IS_ADDR_TYPE(_type) ((_type) == nsIDNSService::RESOLVE_TYPE_DEFAULT)
#define IS_OTHER_TYPE(_type) ((_type) != nsIDNSService::RESOLVE_TYPE_DEFAULT)
//----------------------------------------------------------------------------
using namespace mozilla;
using namespace mozilla::net;
struct HostResolverMarker {
static constexpr mozilla::Span<const char> MarkerTypeName() {
return mozilla::MakeStringSpan("HostResolver");
}
static void StreamJSONMarkerData(
mozilla::baseprofiler::SpliceableJSONWriter& aWriter,
const mozilla::ProfilerString8View& aHost,
const mozilla::ProfilerString8View& aOriginSuffix, uint16_t aType,
uint32_t aFlags) {
aWriter.StringProperty("host", aHost);
aWriter.StringProperty("originSuffix", aOriginSuffix);
aWriter.IntProperty("qtype", aType);
aWriter.StringProperty("flags", nsPrintfCString("0x%x", aFlags));
}
static MarkerSchema MarkerTypeDisplay() {
using MS = MarkerSchema;
MS schema{MS::Location::MarkerChart, MS::Location::MarkerTable};
schema.SetTableLabel("{marker.data.host}");
schema.AddKeyFormat("host", MS::Format::SanitizedString,
MS::PayloadFlags::Searchable);
schema.AddKeyFormat("originSuffix", MS::Format::SanitizedString,
MS::PayloadFlags::Searchable);
schema.AddKeyFormat("qtype", MS::Format::Integer);
schema.AddKeyFormat("flags", MS::Format::String);
return schema;
}
};
nsHostKey::nsHostKey(const nsACString& aHost, const nsACString& aTrrServer,
uint16_t aType, nsIDNSService::DNSFlags aFlags,
uint16_t aAf, bool aPb, const nsACString& aOriginsuffix)
: host(aHost),
mTrrServer(aTrrServer),
type(aType),
flags(aFlags),
af(aAf),
pb(aPb),
originSuffix(aOriginsuffix) {}
nsHostKey::nsHostKey(const nsHostKey& other)
: host(other.host),
mTrrServer(other.mTrrServer),
type(other.type),
flags(other.flags),
af(other.af),
pb(other.pb),
originSuffix(other.originSuffix) {}
bool nsHostKey::operator==(const nsHostKey& other) const {
return host == other.host && mTrrServer == other.mTrrServer &&
type == other.type &&
RES_KEY_FLAGS(flags) == RES_KEY_FLAGS(other.flags) && af == other.af &&
originSuffix == other.originSuffix;
}
PLDHashNumber nsHostKey::Hash() const {
return AddToHash(HashString(host.get()), HashString(mTrrServer.get()), type,
RES_KEY_FLAGS(flags), af, HashString(originSuffix.get()));
}
size_t nsHostKey::SizeOfExcludingThis(
mozilla::MallocSizeOf mallocSizeOf) const {
size_t n = 0;
n += host.SizeOfExcludingThisIfUnshared(mallocSizeOf);
n += mTrrServer.SizeOfExcludingThisIfUnshared(mallocSizeOf);
n += originSuffix.SizeOfExcludingThisIfUnshared(mallocSizeOf);
return n;
}
//----------------------------------------------------------------------------
// nsHostRecord
//----------------------------------------------------------------------------
NS_IMPL_ISUPPORTS0(nsHostRecord)
nsHostRecord::nsHostRecord(const nsHostKey& key)
: nsHostKey(key), mTRRQuery("nsHostRecord.mTRRQuery") {}
void nsHostRecord::Invalidate() { mDoomed = true; }
void nsHostRecord::Cancel() {
RefPtr<TRRQuery> query;
{
auto lock = mTRRQuery.Lock();
query.swap(lock.ref());
}
if (query) {
query->Cancel(NS_ERROR_ABORT);
}
}
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;
if ((valid + grace) < 60) {
grace = 60 - valid;
LOG(("SetExpiration: artificially bumped grace to %d\n", grace));
}
mGraceStart = now + TimeDuration::FromSeconds(valid);
mValidEnd = now + TimeDuration::FromSeconds(valid + grace);
mTtl = valid;
}
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;
mTtl = uint32_t(aFromHostRecord->mTtl);
}
bool nsHostRecord::HasUsableResult(const mozilla::TimeStamp& now,
nsIDNSService::DNSFlags queryFlags) const {
if (mDoomed) {
return false;
}
return HasUsableResultInternal(now, queryFlags);
}
//----------------------------------------------------------------------------
// AddrHostRecord
//----------------------------------------------------------------------------
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;
}
NS_IMPL_ISUPPORTS_INHERITED(AddrHostRecord, nsHostRecord, AddrHostRecord)
AddrHostRecord::AddrHostRecord(const nsHostKey& key) : nsHostRecord(key) {}
AddrHostRecord::~AddrHostRecord() {
mCallbacks.clear();
glean::dns::blocklist_count.AccumulateSingleSample(mUnusableCount);
}
bool AddrHostRecord::Blocklisted(const NetAddr* aQuery) {
addr_info_lock.AssertCurrentThreadOwns();
LOG(("Checking unusable list for host [%s], host record [%p].\n", host.get(),
this));
// skip the string conversion for the common case of no blocklist
if (!mUnusableItems.Length()) {
return false;
}
char buf[kIPv6CStrBufSize];
if (!aQuery->ToStringBuffer(buf, sizeof(buf))) {
return false;
}
nsDependentCString strQuery(buf);
for (uint32_t i = 0; i < mUnusableItems.Length(); i++) {
if (mUnusableItems.ElementAt(i).Equals(strQuery)) {
LOG(("Address [%s] is blocklisted for host [%s].\n", buf, host.get()));
return true;
}
}
return false;
}
void AddrHostRecord::ReportUnusable(const NetAddr* aAddress) {
addr_info_lock.AssertCurrentThreadOwns();
LOG(
("Adding address to blocklist for host [%s], host record [%p]."
"used trr=%d\n",
host.get(), this, mTRRSuccess));
++mUnusableCount;
char buf[kIPv6CStrBufSize];
if (aAddress->ToStringBuffer(buf, sizeof(buf))) {
LOG(
("Successfully adding address [%s] to blocklist for host "
"[%s].\n",
buf, host.get()));
mUnusableItems.AppendElement(nsCString(buf));
}
}
void AddrHostRecord::ResetBlocklist() {
addr_info_lock.AssertCurrentThreadOwns();
LOG(("Resetting blocklist for host [%s], host record [%p].\n", host.get(),
this));
mUnusableItems.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 += mUnusableItems.ShallowSizeOfExcludingThis(mallocSizeOf);
for (size_t i = 0; i < mUnusableItems.Length(); i++) {
n += mUnusableItems[i].SizeOfExcludingThisIfUnshared(mallocSizeOf);
}
return n;
}
bool AddrHostRecord::HasUsableResultInternal(
const mozilla::TimeStamp& now, nsIDNSService::DNSFlags queryFlags) const {
// 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 addr_info || addr;
}
// Returns true if the entry can be removed, or false if it should be left.
// Sets ResolveAgain true for entries being resolved right now.
bool AddrHostRecord::RemoveOrRefresh(bool aTrrToo) {
// no need to flush TRRed names, they're not resolved "locally"
MutexAutoLock lock(addr_info_lock);
if (addr_info && !aTrrToo && addr_info->IsTRR()) {
return false;
}
if (LoadNative()) {
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.
StoreResolveAgain(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;
}
void AddrHostRecord::NotifyRetryingTrr() {
MOZ_ASSERT(mFirstTRRSkippedReason ==
mozilla::net::TRRSkippedReason::TRR_UNSET);
// Save the skip reason of our first attempt for recording telemetry later.
mFirstTRRSkippedReason = mTRRSkippedReason;
mTRRSkippedReason = mozilla::net::TRRSkippedReason::TRR_UNSET;
}
void AddrHostRecord::ResolveComplete() {
TimeStamp now = TimeStamp::Now();
if (LoadNativeUsed()) {
if (mNativeSuccess) {
glean::dns::native_lookup_time.AccumulateRawDuration(mNativeDuration);
profiler_add_marker(
"Native DNS Lookup", geckoprofiler::category::NETWORK,
MarkerOptions(MarkerTiming::Interval(mNativeStart, now),
MarkerThreadId::MainThread()),
HostResolverMarker{}, host, originSuffix, type, flags);
}
glean::dns::lookup_disposition
.Get(TRRService::ProviderKey(),
mNativeSuccess ? "osOK"_ns : "osFail"_ns)
.Add();
}
if (mResolverType == DNSResolverType::TRR) {
if (mTRRSuccess) {
MOZ_DIAGNOSTIC_ASSERT(mTRRSkippedReason ==
mozilla::net::TRRSkippedReason::TRR_OK);
glean::dns::trr_lookup_time.Get(TRRService::ProviderKey())
.AccumulateRawDuration(mTrrDuration);
profiler_add_marker(
"TRR DNS Lookup", geckoprofiler::category::NETWORK,
MarkerOptions(MarkerTiming::Interval(now - mTrrDuration, now),
MarkerThreadId::MainThread()),
HostResolverMarker{}, host, originSuffix, type, flags);
}
glean::dns::lookup_disposition
.Get(TRRService::ProviderKey(), mTRRSuccess ? "trrOK"_ns : "trrFail"_ns)
.Add();
}
if (nsHostResolver::Mode() == nsIDNSService::MODE_TRRFIRST ||
nsHostResolver::Mode() == nsIDNSService::MODE_TRRONLY) {
MOZ_ASSERT(mTRRSkippedReason != mozilla::net::TRRSkippedReason::TRR_UNSET);
glean::dns::trr_skip_reason_trr_first.Get(TRRService::ProviderKey())
.AccumulateSingleSample(static_cast<uint32_t>(mTRRSkippedReason));
if (!mTRRSuccess && LoadNativeUsed()) {
if (mNativeSuccess) {
glean::dns::trr_skip_reason_native_success
.Get(TRRService::ProviderKey())
.AccumulateSingleSample(static_cast<uint32_t>(mTRRSkippedReason));
} else {
glean::dns::trr_skip_reason_native_failed.Get(TRRService::ProviderKey())
.AccumulateSingleSample(static_cast<uint32_t>(mTRRSkippedReason));
}
}
if (IsRelevantTRRSkipReason(mTRRSkippedReason)) {
glean::dns::trr_relevant_skip_reason_trr_first
.Get(TRRService::ProviderKey())
.AccumulateSingleSample(static_cast<uint32_t>(mTRRSkippedReason));
if (!mTRRSuccess && LoadNativeUsed()) {
if (mNativeSuccess) {
glean::dns::trr_relevant_skip_reason_native_success
.Get(TRRService::ProviderKey())
.AccumulateSingleSample(static_cast<uint32_t>(mTRRSkippedReason));
} else {
glean::dns::trr_relevant_skip_reason_native_failed
.Get(TRRService::ProviderKey())
.AccumulateSingleSample(static_cast<uint32_t>(mTRRSkippedReason));
}
}
}
if (StaticPrefs::network_trr_retry_on_recoverable_errors() &&
nsHostResolver::Mode() == nsIDNSService::MODE_TRRFIRST) {
nsAutoCString telemetryKey(TRRService::ProviderKey());
if (mFirstTRRSkippedReason != mozilla::net::TRRSkippedReason::TRR_UNSET) {
telemetryKey.AppendLiteral("|");
telemetryKey.AppendInt(static_cast<uint32_t>(mFirstTRRSkippedReason));
if (mTRRSuccess) {
glean::dns::trr_skip_reason_retry_success
.Get(TRRService::ProviderKey())
.AccumulateSingleSample(
static_cast<uint32_t>(mFirstTRRSkippedReason));
} else {
glean::dns::trr_skip_reason_retry_failed
.Get(TRRService::ProviderKey())
.AccumulateSingleSample(
static_cast<uint32_t>(mFirstTRRSkippedReason));
}
}
glean::dns::trr_skip_reason_strict_mode.Get(telemetryKey)
.AccumulateSingleSample(static_cast<uint32_t>(mTRRSkippedReason));
if (mTRRSuccess) {
glean::dns::trr_attempt_count.Get(TRRService::ProviderKey())
.AccumulateSingleSample(mTrrAttempts);
}
}
}
if (mEffectiveTRRMode == nsIRequest::TRR_FIRST_MODE) {
if (flags & nsIDNSService::RESOLVE_DISABLE_TRR) {
// TRR is disabled on request, which is a next-level back-off method.
glean::dns::trr_disabled
.Get(TRRService::ProviderKey(),
mNativeSuccess ? "true"_ns : "false"_ns)
.Add();
} else {
if (mTRRSuccess) {
glean::dns::trr_first.Get(TRRService::ProviderKey(), "TRR"_ns).Add();
} else if (mNativeSuccess) {
if (mResolverType == DNSResolverType::TRR) {
glean::dns::trr_first
.Get(TRRService::ProviderKey(), "NativeAfterTRR"_ns)
.Add();
} else {
glean::dns::trr_first.Get(TRRService::ProviderKey(), "Native"_ns)
.Add();
}
} else {
glean::dns::trr_first.Get(TRRService::ProviderKey(), "BothFailed"_ns)
.Add();
}
}
}
switch (mEffectiveTRRMode) {
case nsIRequest::TRR_DISABLED_MODE:
glean::dns::lookup_algorithm
.EnumGet(glean::dns::LookupAlgorithmLabel::eNativeonly)
.Add();
break;
case nsIRequest::TRR_FIRST_MODE:
glean::dns::lookup_algorithm
.EnumGet(glean::dns::LookupAlgorithmLabel::eTrrfirst)
.Add();
break;
case nsIRequest::TRR_ONLY_MODE:
glean::dns::lookup_algorithm
.EnumGet(glean::dns::LookupAlgorithmLabel::eTrronly)
.Add();
break;
case nsIRequest::TRR_DEFAULT_MODE:
MOZ_ASSERT_UNREACHABLE("We should not have a default value here");
break;
}
if (mResolverType == DNSResolverType::TRR && !mTRRSuccess && mNativeSuccess &&
!LoadGetTtl() && TRRService::Get()) {
TRRService::Get()->AddToBlocklist(nsCString(host), originSuffix, pb, true);
}
}
AddrHostRecord::DnsPriority AddrHostRecord::GetPriority(
nsIDNSService::DNSFlags aFlags) {
if (IsHighPriority(aFlags)) {
return AddrHostRecord::DNS_PRIORITY_HIGH;
}
if (IsMediumPriority(aFlags)) {
return AddrHostRecord::DNS_PRIORITY_MEDIUM;
}
return AddrHostRecord::DNS_PRIORITY_LOW;
}
nsresult AddrHostRecord::GetTtl(uint32_t* aResult) {
NS_ENSURE_ARG(aResult);
*aResult = mTtl;
return NS_OK;
}
nsresult AddrHostRecord::GetLastUpdate(mozilla::TimeStamp* aLastUpdate) {
addr_info_lock.AssertCurrentThreadOwns();
*aLastUpdate = mLastUpdate;
return NS_OK;
}
//----------------------------------------------------------------------------
// TypeHostRecord
//----------------------------------------------------------------------------
NS_IMPL_ISUPPORTS_INHERITED(TypeHostRecord, nsHostRecord, TypeHostRecord,
nsIDNSTXTRecord, nsIDNSHTTPSSVCRecord)
TypeHostRecord::TypeHostRecord(const nsHostKey& key)
: nsHostRecord(key), DNSHTTPSSVCRecordBase(key.host) {}
TypeHostRecord::~TypeHostRecord() { mCallbacks.clear(); }
bool TypeHostRecord::HasUsableResultInternal(
const mozilla::TimeStamp& now, nsIDNSService::DNSFlags queryFlags) const {
if (CheckExpiration(now) == EXP_EXPIRED) {
return false;
}
if (negative) {
return true;
}
MOZ_PUSH_IGNORE_THREAD_SAFETY
// To avoid locking in a const method
return !mResults.is<Nothing>();
MOZ_POP_THREAD_SAFETY
}
bool TypeHostRecord::RefreshForNegativeResponse() const { return false; }
NS_IMETHODIMP TypeHostRecord::GetRecords(CopyableTArray<nsCString>& aRecords) {
// deep copy
MutexAutoLock lock(mResultsLock);
if (!mResults.is<TypeRecordTxt>()) {
return NS_ERROR_NOT_AVAILABLE;
}
aRecords = mResults.as<CopyableTArray<nsCString>>();
return NS_OK;
}
NS_IMETHODIMP TypeHostRecord::GetRecordsAsOneString(nsACString& aRecords) {
// deep copy
MutexAutoLock lock(mResultsLock);
if (!mResults.is<TypeRecordTxt>()) {
return NS_ERROR_NOT_AVAILABLE;
}
auto& results = mResults.as<CopyableTArray<nsCString>>();
for (uint32_t i = 0; i < results.Length(); i++) {
aRecords.Append(results[i]);
}
return NS_OK;
}
size_t TypeHostRecord::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) const {
size_t n = mallocSizeOf(this);
n += nsHostKey::SizeOfExcludingThis(mallocSizeOf);
n += SizeOfResolveHostCallbackListExcludingHead(mCallbacks, mallocSizeOf);
return n;
}
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;
}
NS_IMETHODIMP
TypeHostRecord::GetServiceModeRecord(bool aNoHttp2, bool aNoHttp3,
nsISVCBRecord** aRecord) {
return GetServiceModeRecordWithCname(aNoHttp2, aNoHttp3, ""_ns, aRecord);
}
NS_IMETHODIMP
TypeHostRecord::GetServiceModeRecordWithCname(bool aNoHttp2, bool aNoHttp3,
const nsACString& aCname,
nsISVCBRecord** aRecord) {
MutexAutoLock lock(mResultsLock);
if (!mResults.is<TypeRecordHTTPSSVC>()) {
return NS_ERROR_NOT_AVAILABLE;
}
auto& results = mResults.as<TypeRecordHTTPSSVC>();
nsCOMPtr<nsISVCBRecord> result = GetServiceModeRecordInternal(
aNoHttp2, aNoHttp3, results, mAllRecordsExcluded, true, aCname);
if (!result) {
return NS_ERROR_NOT_AVAILABLE;
}
result.forget(aRecord);
return NS_OK;
}
NS_IMETHODIMP
TypeHostRecord::IsTRR(bool* aResult) {
*aResult = (mResolverType == DNSResolverType::TRR);
return NS_OK;
}
NS_IMETHODIMP
TypeHostRecord::GetAllRecords(bool aNoHttp2, bool aNoHttp3,
const nsACString& aCname,
nsTArray<RefPtr<nsISVCBRecord>>& aResult) {
MutexAutoLock lock(mResultsLock);
if (!mResults.is<TypeRecordHTTPSSVC>()) {
return NS_ERROR_NOT_AVAILABLE;
}
auto& records = mResults.as<TypeRecordHTTPSSVC>();
bool notused;
GetAllRecordsInternal(aNoHttp2, aNoHttp3, aCname, records, false, ¬used,
¬used, aResult);
return NS_OK;
}
NS_IMETHODIMP
TypeHostRecord::GetAllRecordsWithEchConfig(
bool aNoHttp2, bool aNoHttp3, const nsACString& aCname,
bool* aAllRecordsHaveEchConfig, bool* aAllRecordsInH3ExcludedList,
nsTArray<RefPtr<nsISVCBRecord>>& aResult) {
MutexAutoLock lock(mResultsLock);
if (!mResults.is<TypeRecordHTTPSSVC>()) {
return NS_ERROR_NOT_AVAILABLE;
}
auto& records = mResults.as<TypeRecordHTTPSSVC>();
GetAllRecordsInternal(aNoHttp2, aNoHttp3, aCname, records, true,
aAllRecordsHaveEchConfig, aAllRecordsInH3ExcludedList,
aResult);
return NS_OK;
}
NS_IMETHODIMP
TypeHostRecord::GetHasIPAddresses(bool* aResult) {
NS_ENSURE_ARG(aResult);
MutexAutoLock lock(mResultsLock);
if (!mResults.is<TypeRecordHTTPSSVC>()) {
return NS_ERROR_NOT_AVAILABLE;
}
auto& results = mResults.as<TypeRecordHTTPSSVC>();
*aResult = HasIPAddressesInternal(results);
return NS_OK;
}
NS_IMETHODIMP
TypeHostRecord::GetAllRecordsExcluded(bool* aResult) {
NS_ENSURE_ARG(aResult);
MutexAutoLock lock(mResultsLock);
if (!mResults.is<TypeRecordHTTPSSVC>()) {
return NS_ERROR_NOT_AVAILABLE;
}
*aResult = mAllRecordsExcluded;
return NS_OK;
}
NS_IMETHODIMP
TypeHostRecord::GetTtl(uint32_t* aResult) {
NS_ENSURE_ARG(aResult);
*aResult = mTtl;
return NS_OK;
}
void TypeHostRecord::ResolveComplete() {
if (IsRelevantTRRSkipReason(mTRRSkippedReason)) {
glean::dns::trr_relevant_skip_reason_trr_first_type_rec
.Get(TRRService::ProviderKey())
.AccumulateSingleSample(static_cast<uint32_t>(mTRRSkippedReason));
}
if (mTRRSuccess) {
glean::dns::by_type_succeeded_lookup_time.AccumulateRawDuration(
mTrrDuration);
} else {
glean::dns::by_type_failed_lookup_time.AccumulateRawDuration(mTrrDuration);
}
}
|