From: Otto Moerbeek Date: Tue, 3 May 2022 07:05:21 +0000 (+0200) Subject: Use the level actually *used* to decide to update edns status. X-Git-Tag: auth-4.8.0-alpha0~55^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a885ffdd7f3790eac071ce50df1074b7e875fb8;p=thirdparty%2Fpdns.git Use the level actually *used* to decide to update edns status. Fold the logic to not update if no change and updating the timestamp to the setter. --- diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 3bf06b4d41..5beb4d400e 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -1077,14 +1077,11 @@ struct ednsstatus_t : public multi_index_container::type &ind, iterator it, SyncRes::EDNSStatus::EDNSMode mode) + void setMode(index::type &ind, iterator it, SyncRes::EDNSStatus::EDNSMode mode, time_t ts) { - it->mode = mode; - } - - void setTS(index::type &ind, iterator it, time_t ts) - { - ind.modify(it, [ts](SyncRes::EDNSStatus &s) { s.modeSetAt = ts; }); + if (it->mode != mode || it->modeSetAt == 0) { + ind.modify(it, [=](SyncRes::EDNSStatus &s) { s.mode = mode; s.modeSetAt = ts; }); + } } void prune(time_t cutoff) @@ -1494,12 +1491,10 @@ LWResult::Result SyncRes::asyncresolveWrapper(const ComboAddress& ip, bool ednsM auto &ind = lock->get(); if (ednsstatus->modeSetAt && ednsstatus->modeSetAt + 3600 < d_now.tv_sec) { lock->reset(ind, ednsstatus); - // cerr<<"Resetting EDNS Status for "<mode; } - const SyncRes::EDNSStatus::EDNSMode oldmode = mode; int EDNSLevel = 0; auto luaconfsLocal = g_luaconfs.getLocal(); ResolveContext ctx; @@ -1511,7 +1506,7 @@ LWResult::Result SyncRes::asyncresolveWrapper(const ComboAddress& ip, bool ednsM LWResult::Result ret; - for (int tries = 0; tries < 3; ++tries) { + for (int tries = 0; tries < 2; ++tries) { if (mode == EDNSStatus::NOEDNS) { g_stats.noEdnsOutQueries++; @@ -1541,37 +1536,27 @@ LWResult::Result SyncRes::asyncresolveWrapper(const ComboAddress& ip, bool ednsM break; } - // ret is LWResult::Result::Success - // ednsstatus might be cleared, so do a new lookup/insert - auto lock = s_ednsstatus.lock(); - auto ednsstatus = lock->insert(ip).first; - mode = ednsstatus->mode; - auto &ind = lock->get(); + if (EDNSLevel == 1) { + // We sent out with EDNS + // ret is LWResult::Result::Success + // ednsstatus in table might be pruned or changed by another request/thread, so do a new lookup/insert + auto lock = s_ednsstatus.lock(); + auto ednsstatus = lock->insert(ip).first; + auto &ind = lock->get(); - if (mode != EDNSStatus::NOEDNS) { if (res->d_validpacket && !res->d_haveEDNS && res->d_rcode == RCode::FormErr) { mode = EDNSStatus::NOEDNS; - lock->setMode(ind, ednsstatus, mode); + lock->setMode(ind, ednsstatus, mode, d_now.tv_sec); continue; } else if (!res->d_haveEDNS) { - if (mode != EDNSStatus::EDNSIGNORANT) { - mode = EDNSStatus::EDNSIGNORANT; - lock->setMode(ind, ednsstatus, mode); - } + lock->setMode(ind, ednsstatus, EDNSStatus::EDNSIGNORANT, d_now.tv_sec); } else { - if (mode != EDNSStatus::EDNSOK) { - mode = EDNSStatus::EDNSOK; - lock->setMode(ind, ednsstatus, mode); - } + lock->setMode(ind, ednsstatus, EDNSStatus::EDNSOK, d_now.tv_sec); } } - if (oldmode != mode || !ednsstatus->modeSetAt) { - lock->setTS(ind, ednsstatus, d_now.tv_sec); - } - break; } return ret; diff --git a/pdns/syncres.hh b/pdns/syncres.hh index b2ad364f43..161ed219a1 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -216,11 +216,11 @@ public: EDNSStatus(const ComboAddress &arg) : address(arg) {} ComboAddress address; time_t modeSetAt{0}; - mutable enum EDNSMode : uint8_t { UNKNOWN = 0, EDNSOK = 1, EDNSIGNORANT = 2, NOEDNS = 3 } mode{UNKNOWN}; + enum EDNSMode : uint8_t { UNKNOWN = 0, EDNSOK = 1, EDNSIGNORANT = 2, NOEDNS = 3 } mode{UNKNOWN}; std::string toString() const { - const std::array modes = { "Unknown", "OK", "Ignorant", "NoEDNS" }; + const std::array modes = { "Unknown", "OK", "Ignorant", "No" }; unsigned int m = static_cast(mode); if (m >= modes.size()) { return "?";