From: Remi Gacogne Date: Fri, 2 Jul 2021 08:30:43 +0000 (+0200) Subject: rec: Work around clueless servers sending AA=0 answers X-Git-Tag: dnsdist-1.7.0-alpha1~104^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b98cc14e66493599c7bac1bee26c3d116a660a6;p=thirdparty%2Fpdns.git rec: Work around clueless servers sending AA=0 answers --- diff --git a/pdns/recursordist/test-syncres_cc3.cc b/pdns/recursordist/test-syncres_cc3.cc index d0e1593200..57679ab67a 100644 --- a/pdns/recursordist/test-syncres_cc3.cc +++ b/pdns/recursordist/test-syncres_cc3.cc @@ -70,8 +70,8 @@ BOOST_AUTO_TEST_CASE(test_unauth_any) vector ret; int res = sr->beginResolve(target, QType(QType::ANY), QClass::IN, ret); - BOOST_CHECK_EQUAL(res, RCode::ServFail); - BOOST_CHECK_EQUAL(ret.size(), 0U); + BOOST_CHECK_EQUAL(res, RCode::NoError); + BOOST_CHECK_EQUAL(ret.size(), 1U); } static void test_no_data_f(bool qmin) @@ -274,14 +274,14 @@ BOOST_AUTO_TEST_CASE(test_answer_no_aa) vector ret; int res = sr->beginResolve(target, QType(QType::A), QClass::IN, ret); - BOOST_CHECK_EQUAL(res, RCode::ServFail); - BOOST_CHECK_EQUAL(ret.size(), 0U); + BOOST_CHECK_EQUAL(res, RCode::NoError); + BOOST_CHECK_EQUAL(ret.size(), 1U); /* check that the record in the answer section has not been cached */ const ComboAddress who; vector cached; vector> signatures; - BOOST_REQUIRE_EQUAL(g_recCache->get(now, target, QType(QType::A), false, &cached, who, 0, boost::none, &signatures), -1); + BOOST_REQUIRE_GT(g_recCache->get(now, target, QType(QType::A), false, &cached, who, 0, boost::none, &signatures), 0); } BOOST_AUTO_TEST_CASE(test_special_types) diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 4c34384137..6867b77e2e 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -2856,6 +2856,46 @@ vState SyncRes::validateRecordsWithSigs(unsigned int depth, const DNSName& qname return state; } +/* This function will check whether the answer should have the AA bit set, and will set if it should be set and isn't. + This is unfortunately needed to deal with very crappy so-called DNS servers */ +void SyncRes::fixupAnswer(const std::string& prefix, LWResult& lwr, const DNSName& qname, const QType qtype, const DNSName& auth, bool wasForwarded, bool rdQuery) +{ + const bool wasForwardRecurse = wasForwarded && rdQuery; + + if (wasForwardRecurse || lwr.d_aabit) { + /* easy */ + return; + } + + for (const auto& rec : lwr.d_records) { + + if (rec.d_type == QType::OPT) { + continue; + } + + if (rec.d_class != QClass::IN) { + continue; + } + + if (rec.d_type == QType::ANY) { + continue; + } + + if (rec.d_place == DNSResourceRecord::ANSWER && (rec.d_type == qtype || rec.d_type == QType::CNAME || qtype == QType::ANY) && rec.d_name == qname && rec.d_name.isPartOf(auth)) { + /* This is clearly an answer to the question we were asking, from an authoritative server that is allowed to send it. + We are going to assume this server is broken and does not know it should set the AA bit, even though it is DNS 101 */ + LOG(prefix<<"Received a record for "<& allowedAdditionals, const DNSRecord& rec) { switch(rec.d_type) { @@ -3034,6 +3074,7 @@ RCode::rcodes_ SyncRes::updateCacheFromRecords(unsigned int depth, LWResult& lwr prefix.append(depth, ' '); } + fixupAnswer(prefix, lwr, qname, qtype, auth, wasForwarded, rdQuery); sanitizeRecords(prefix, lwr, qname, qtype, auth, wasForwarded, rdQuery); std::vector> authorityRecs; diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 9396c315a1..8489797f86 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -860,6 +860,9 @@ private: vector retrieveAddressesForNS(const std::string& prefix, const DNSName& qname, vector>::const_iterator& tns, const unsigned int depth, set& beenthere, const vector>& rnameservers, NsSet& nameservers, bool& sendRDQuery, bool& pierceDontQuery, bool& flawedNSSet, bool cacheOnly, unsigned int& addressQueriesForNS); void sanitizeRecords(const std::string& prefix, LWResult& lwr, const DNSName& qname, const QType qtype, const DNSName& auth, bool wasForwarded, bool rdQuery); +/* This function will check whether the answer should have the AA bit set, and will set if it should be set and isn't. + This is unfortunately needed to deal with very crappy so-called DNS servers */ + void fixupAnswer(const std::string& prefix, LWResult& lwr, const DNSName& qname, const QType qtype, const DNSName& auth, bool wasForwarded, bool rdQuery); RCode::rcodes_ updateCacheFromRecords(unsigned int depth, LWResult& lwr, const DNSName& qname, const QType qtype, const DNSName& auth, bool wasForwarded, const boost::optional, vState& state, bool& needWildcardProof, bool& gatherWildcardProof, unsigned int& wildcardLabelsCount, bool sendRDQuery, const ComboAddress& remoteIP); bool processRecords(const std::string& prefix, const DNSName& qname, const QType qtype, const DNSName& auth, LWResult& lwr, const bool sendRDQuery, vector& ret, set& nsset, DNSName& newtarget, DNSName& newauth, bool& realreferral, bool& negindic, vState& state, const bool needWildcardProof, const bool gatherwildcardProof, const unsigned int wildcardLabelsCount, int& rcode, bool& negIndicHasSignatures, unsigned int depth);