From b56229307b41eb1133a8e533c808598157950a42 Mon Sep 17 00:00:00 2001 From: Kershaw Chang Date: Thu, 16 Jun 2022 09:56:06 +0000 Subject: [PATCH] Bug 1772111 - Refine TRR skiped reasons for retry, r=necko-reviewers,dragana Differential Revision: https://phabricator.services.mozilla.com/D148107 --- netwerk/dns/TRRSkippedReason.h | 23 +++++++++++++++++++++++ netwerk/dns/nsHostResolver.cpp | 8 +++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/netwerk/dns/TRRSkippedReason.h b/netwerk/dns/TRRSkippedReason.h index b480e08057f7..8ca13537be24 100644 --- a/netwerk/dns/TRRSkippedReason.h +++ b/netwerk/dns/TRRSkippedReason.h @@ -72,6 +72,29 @@ inline bool IsRelevantTRRSkipReason(TRRSkippedReason aReason) { return true; } +inline bool IsBlockedTRRRequest(TRRSkippedReason aReason) { + // See TRR::MaybeBlockRequest. These are the reasons that could block sending + // TRR requests. + return (aReason == TRRSkippedReason::TRR_EXCLUDED || + aReason == TRRSkippedReason::TRR_MODE_NOT_ENABLED || + aReason == TRRSkippedReason::TRR_HOST_BLOCKED_TEMPORARY); +} + +inline bool IsNonRecoverableTRRSkipReason(TRRSkippedReason aReason) { + // These are non-recoverable reasons and we'll fallback to native without + // retrying. + return (aReason == TRRSkippedReason::TRR_NXDOMAIN || + aReason == TRRSkippedReason::TRR_NO_ANSWERS || + aReason == TRRSkippedReason::TRR_DISABLED_FLAG || + aReason == TRRSkippedReason::TRR_RCODE_FAIL); +} + +inline bool IsFailedConfirmationOrNoConnectivity(TRRSkippedReason aReason) { + // TRR is in non-confirmed state now, so we don't try to use TRR at all. + return (aReason == TRRSkippedReason::TRR_NOT_CONFIRMED || + aReason == TRRSkippedReason::TRR_NO_CONNECTIVITY); +} + } // namespace net } // namespace mozilla diff --git a/netwerk/dns/nsHostResolver.cpp b/netwerk/dns/nsHostResolver.cpp index 1e8b57c33a8c..9ad816f0068c 100644 --- a/netwerk/dns/nsHostResolver.cpp +++ b/netwerk/dns/nsHostResolver.cpp @@ -1325,11 +1325,9 @@ bool nsHostResolver::MaybeRetryTRRLookup( return NS_SUCCEEDED(NativeLookup(aAddrRec, aLock)); } - if (aFirstAttemptSkipReason == TRRSkippedReason::TRR_RCODE_FAIL || - aFirstAttemptSkipReason == TRRSkippedReason::TRR_NO_ANSWERS || - aFirstAttemptSkipReason == TRRSkippedReason::TRR_NXDOMAIN || - aFirstAttemptSkipReason == TRRSkippedReason::TRR_DISABLED_FLAG || - aFirstAttemptSkipReason == TRRSkippedReason::TRR_NOT_CONFIRMED) { + if (IsFailedConfirmationOrNoConnectivity(aFirstAttemptSkipReason) || + IsNonRecoverableTRRSkipReason(aFirstAttemptSkipReason) || + IsBlockedTRRRequest(aFirstAttemptSkipReason)) { LOG( ("nsHostResolver::MaybeRetryTRRLookup retrying with native in strict " "mode, skip reason was %d",