From: Otto Moerbeek Date: Fri, 4 Dec 2020 15:31:33 +0000 (+0100) Subject: Improve the way QType behaves by defining proper conversion X-Git-Tag: dnsdist-1.6.0-alpha2~46^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4e0e6ff98dd69e9194a53b5e6fdb116e4894e1d;p=thirdparty%2Fpdns.git Improve the way QType behaves by defining proper conversion operators and a hash function. I converted syncres.* for starters to stop using uint16_t for qtype and use QType everywhere. Note that I also changed const QType& in arg lists by QType, since it makes little sense to pass a 16 bit value by const reference. --- diff --git a/pdns/qtype.cc b/pdns/qtype.cc index 31f383124e..d33273bf54 100644 --- a/pdns/qtype.cc +++ b/pdns/qtype.cc @@ -30,23 +30,80 @@ static_assert(sizeof(QType) == 2, "QType is not 2 bytes in size, something is wrong!"); -vector QType::names; -// XXX FIXME we need to do something with initializer order here! -QType::init QType::initializer; - -QType::QType() +const vector QType::names = { + {"A", 1}, + {"NS", 2}, + {"CNAME", 5}, + {"SOA", 6}, + {"MB", 7}, + {"MG", 8}, + {"MR", 9}, + {"PTR", 12}, + {"HINFO", 13}, + {"MINFO", 14}, + {"MX", 15}, + {"TXT", 16}, + {"RP", 17}, + {"AFSDB", 18}, + {"SIG", 24}, + {"KEY", 25}, + {"AAAA", 28}, + {"LOC", 29}, + {"SRV", 33}, + {"NAPTR", 35}, + {"KX", 36}, + {"CERT", 37}, + {"A6", 38}, + {"DNAME", 39}, + {"OPT", 41}, + {"APL", 42}, + {"DS", 43}, + {"SSHFP", 44}, + {"IPSECKEY", 45}, + {"RRSIG", 46}, + {"NSEC", 47}, + {"DNSKEY", 48}, + {"DHCID", 49}, + {"NSEC3", 50}, + {"NSEC3PARAM", 51}, + {"TLSA", 52}, + {"SMIMEA", 53}, + {"RKEY", 57}, + {"CDS", 59}, + {"CDNSKEY", 60}, + {"OPENPGPKEY", 61}, + {"SVCB", 64}, + {"HTTPS", 65}, + {"SPF", 99}, + {"EUI48", 108}, + {"EUI64", 109}, + {"TKEY", 249}, + // {"TSIG", 250}, + {"IXFR", 251}, + {"AXFR", 252}, + {"MAILB", 253}, + {"MAILA", 254}, + {"ANY", 255}, + {"URI", 256}, + {"CAA", 257}, + {"DLV", 32769}, + {"ADDR", 65400}, + {"ALIAS", 65401}, + {"LUA", 65402}, +}; + +bool QType::isSupportedType() const { - code = 0; -} - -bool QType::isSupportedType() { - for(vector::iterator pos=names.begin();possecond==code) + for (const auto& pos : names) { + if (pos.second == code) { return true; + } + } return false; } -bool QType::isMetadataType() { +bool QType::isMetadataType() const +{ if (code == QType::AXFR || code == QType::MAILA || code == QType::MAILB || @@ -57,60 +114,44 @@ bool QType::isMetadataType() { return false; } -uint16_t QType::getCode() const -{ - return code; -} - const string QType::getName() const { - vector::iterator pos; - for(pos=names.begin();possecond==code) - return pos->first; - - return "TYPE"+itoa(code); -} - -QType &QType::operator=(uint16_t n) -{ - code=n; - return *this; + for (const auto& pos : names) { + if (pos.second == code) { + return pos.first; + } + } + return "TYPE" + itoa(code); } -int QType::chartocode(const char *p) +uint16_t QType::chartocode(const char *p) { string P = toUpper(p); - vector::iterator pos; - for(pos=names.begin(); pos < names.end(); ++pos) - if(pos->first == P) - return pos->second; - - if(*p=='#') { - return atoi(p+1); + for(const auto& pos: names) { + if (pos.first == P) { + return pos.second; + } + } + if (*p == '#') { + return static_cast(atoi(p+1)); } - if(boost::starts_with(P, "TYPE")) - return atoi(p+4); + if (boost::starts_with(P, "TYPE")) { + return static_cast(atoi(p+4)); + } return 0; } QType &QType::operator=(const char *p) { - code=chartocode(p); + code = chartocode(p); return *this; } QType &QType::operator=(const string &s) { - code=chartocode(s.c_str()); + code = chartocode(s.c_str()); return *this; } - - -QType::QType(uint16_t n): QType() -{ - code=n; -} diff --git a/pdns/qtype.hh b/pdns/qtype.hh index 8cbf2441dc..1751ac14f0 100644 --- a/pdns/qtype.hh +++ b/pdns/qtype.hh @@ -20,8 +20,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #pragma once -#include -#include #include "namespaces.hh" /** The QType class is meant to deal easily with the different kind of resource types, like 'A', 'NS', @@ -38,206 +36,123 @@ */ - - class QType { public: - QType(); //!< Naked constructor - explicit QType(uint16_t); //!< convert from an integer to a QType - QType(const QType& orig) : code(orig.code) + QType(uint16_t qtype = 0) : code(qtype) {} + QType(const QType& orig) : code(orig.code) {} + QType &operator=(uint16_t arg) { + code = arg; + return *this; } - QType &operator=(uint16_t); //!< Assigns integers to us - QType &operator=(const char *); //!< Assigns strings to us - QType &operator=(const string &); //!< Assigns strings to us - QType &operator=(const QType&rhs) //!< Assigns strings to us + QType &operator=(const char *); + QType &operator=(const string &); + QType &operator=(const QType& rhs) { - code=rhs.code; + code = rhs.code; return *this; } - - bool operator<(const QType& rhs) const + bool operator<(const QType rhs) const { return code < rhs.code; } - const string getName() const; //!< Get a string representation of this type - uint16_t getCode() const; //!< Get the integer representation of this type - bool isSupportedType(); - bool isMetadataType(); - - static int chartocode(const char *p); //!< convert a character string to a code - enum typeenum : uint16_t { - ENT=0, - A=1, - NS=2, - CNAME=5, - SOA=6, - MB=7, - MG=8, - MR=9, - PTR=12, - HINFO=13, - MINFO=14, - MX=15, - TXT=16, - RP=17, - AFSDB=18, - SIG=24, - KEY=25, - AAAA=28, - LOC=29, - SRV=33, - NAPTR=35, - KX=36, - CERT=37, - A6=38, - DNAME=39, - OPT=41, - APL=42, - DS=43, - SSHFP=44, - IPSECKEY=45, - RRSIG=46, - NSEC=47, - DNSKEY=48, - DHCID=49, - NSEC3=50, - NSEC3PARAM=51, - TLSA=52, - SMIMEA=53, - RKEY=57, - CDS=59, - CDNSKEY=60, - OPENPGPKEY=61, - SVCB=64, - HTTPS=65, - SPF=99, - EUI48=108, - EUI64=109, - TKEY=249, - TSIG=250, - IXFR=251, - AXFR=252, - MAILB=253, - MAILA=254, - ANY=255, - URI=256, - CAA=257, - DLV=32769, - ADDR=65400, - ALIAS=65401, - LUA=65402 - }; - - QType(typeenum orig) : code(orig) - { - } - - typedef pair namenum; - static vector names; - - inline bool operator==(const QType &comp) const { - return(comp.code==code); - } - - inline bool operator!=(const QType &comp) const { - return(comp.code!=code); + operator uint16_t() const { + return code; } - inline bool operator==(QType::typeenum comp) const { - return(comp==code); - } - - inline bool operator!=(QType::typeenum comp) const { - return(comp!=code); + const string getName() const; + uint16_t getCode() const + { + return code; } + bool isSupportedType() const; + bool isMetadataType() const; - inline bool operator==(uint16_t comp) const { - return(comp==code); - } + static uint16_t chartocode(const char* p); + + enum typeenum : uint16_t { + ENT = 0, + A = 1, + NS = 2, + CNAME = 5, + SOA = 6, + MB = 7, + MG = 8, + MR = 9, + PTR = 12, + HINFO = 13, + MINFO = 14, + MX = 15, + TXT = 16, + RP = 17, + AFSDB = 18, + SIG = 24, + KEY = 25, + AAAA = 28, + LOC = 29, + SRV = 33, + NAPTR = 35, + KX = 36, + CERT = 37, + A6 = 38, + DNAME = 39, + OPT = 41, + APL = 42, + DS = 43, + SSHFP = 44, + IPSECKEY = 45, + RRSIG = 46, + NSEC = 47, + DNSKEY = 48, + DHCID = 49, + NSEC3 = 50, + NSEC3PARAM = 51, + TLSA = 52, + SMIMEA = 53, + RKEY = 57, + CDS = 59, + CDNSKEY = 60, + OPENPGPKEY = 61, + SVCB = 64, + HTTPS = 65, + SPF = 99, + EUI48 = 108, + EUI64 = 109, + TKEY = 249, + TSIG = 250, + IXFR = 251, + AXFR = 252, + MAILB = 253, + MAILA = 254, + ANY = 255, + URI = 256, + CAA = 257, + DLV = 32769, + ADDR = 65400, + ALIAS = 65401, + LUA = 65402 + }; - inline bool operator!=(uint16_t comp) const { - return(comp!=code); - } + typedef pair namenum; + const static vector names; private: - static class init { - public: - void qtype_insert(const char* a, uint16_t num) - { - names.push_back(make_pair(string(a), num)); - } - - init() - { - qtype_insert("A", 1); - qtype_insert("NS", 2); - qtype_insert("CNAME", 5); - qtype_insert("SOA", 6); - qtype_insert("MB", 7); - qtype_insert("MG", 8); - qtype_insert("MR", 9); - qtype_insert("PTR", 12); - qtype_insert("HINFO", 13); - qtype_insert("MINFO", 14); - qtype_insert("MX", 15); - qtype_insert("TXT", 16); - qtype_insert("RP", 17); - qtype_insert("AFSDB", 18); - qtype_insert("SIG", 24); - qtype_insert("KEY", 25); - qtype_insert("AAAA", 28); - qtype_insert("LOC", 29); - qtype_insert("SRV", 33); - qtype_insert("NAPTR", 35); - qtype_insert("KX", 36); - qtype_insert("CERT", 37); - qtype_insert("A6", 38); - qtype_insert("DNAME", 39); - qtype_insert("OPT", 41); - qtype_insert("APL", 42); - qtype_insert("DS", 43); - qtype_insert("SSHFP", 44); - qtype_insert("IPSECKEY", 45); - qtype_insert("RRSIG", 46); - qtype_insert("NSEC", 47); - qtype_insert("DNSKEY", 48); - qtype_insert("DHCID", 49); - qtype_insert("NSEC3", 50); - qtype_insert("NSEC3PARAM", 51); - qtype_insert("TLSA", 52); - qtype_insert("SMIMEA", 53); - qtype_insert("RKEY", 57); - qtype_insert("CDS", 59); - qtype_insert("CDNSKEY", 60); - qtype_insert("OPENPGPKEY", 61); - qtype_insert("SVCB", 64); - qtype_insert("HTTPS", 65); - qtype_insert("SPF", 99); - qtype_insert("EUI48", 108); - qtype_insert("EUI64", 109); - qtype_insert("TKEY", 249); -// qtype_insert("TSIG", 250); - qtype_insert("IXFR", 251); - qtype_insert("AXFR", 252); - qtype_insert("MAILB", 253); - qtype_insert("MAILA", 254); - qtype_insert("ANY", 255); - qtype_insert("URI", 256); - qtype_insert("CAA", 257); - qtype_insert("DLV", 32769); - qtype_insert("ADDR", 65400); - qtype_insert("ALIAS", 65401); - qtype_insert("LUA", 65402); - } - } initializer; uint16_t code; }; +// Define hash function on QType. See https://en.cppreference.com/w/cpp/utility/hash +namespace std { + template<> struct hash { + std::size_t operator()(QType qtype) const noexcept { + return std::hash{}(qtype.getCode()); + } + }; +} + struct QClass { - enum QClassEnum {IN=1, CHAOS=3, NONE=254, ANY=255}; + enum QClassEnum { IN = 1, CHAOS = 3, NONE = 254, ANY = 255 }; }; diff --git a/pdns/syncres.cc b/pdns/syncres.cc index a327f789d5..7ff340e6ff 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -47,7 +47,7 @@ SuffixMatchNode SyncRes::s_ednsdomains; EDNSSubnetOpts SyncRes::s_ecsScopeZero; string SyncRes::s_serverID; SyncRes::LogMode SyncRes::s_lm; -const std::unordered_set SyncRes::s_redirectionQTypes = {QType::CNAME, QType::DNAME}; +const std::unordered_set SyncRes::s_redirectionQTypes = {QType::CNAME, QType::DNAME}; unsigned int SyncRes::s_maxnegttl; unsigned int SyncRes::s_maxbogusttl; @@ -133,7 +133,7 @@ SyncRes::SyncRes(const struct timeval& now) : d_authzonequeries(0), d_outquerie } /** everything begins here - this is the entry point just after receiving a packet */ -int SyncRes::beginResolve(const DNSName &qname, const QType &qtype, uint16_t qclass, vector&ret, unsigned int depth) +int SyncRes::beginResolve(const DNSName &qname, const QType qtype, uint16_t qclass, vector&ret, unsigned int depth) { vState state = vState::Indeterminate; s_queries++; @@ -186,7 +186,7 @@ int SyncRes::beginResolve(const DNSName &qname, const QType &qtype, uint16_t qcl * - trustanchor.server CH TXT * - negativetrustanchor.server CH TXT */ -bool SyncRes::doSpecialNamesResolve(const DNSName &qname, const QType &qtype, const uint16_t qclass, vector &ret) +bool SyncRes::doSpecialNamesResolve(const DNSName &qname, QType qtype, const uint16_t qclass, vector &ret) { static const DNSName arpa("1.0.0.127.in-addr.arpa."), ip6_arpa("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa."), localhost("localhost."), versionbind("version.bind."), idserver("id.server."), versionpdns("version.pdns."), trustanchorserver("trustanchor.server."), @@ -292,7 +292,7 @@ void SyncRes::AuthDomain::addSOA(std::vector& records) const } } -int SyncRes::AuthDomain::getRecords(const DNSName& qname, uint16_t qtype, std::vector& records) const +int SyncRes::AuthDomain::getRecords(const DNSName& qname, QType qtype, std::vector& records) const { int result = RCode::NoError; records.clear(); @@ -381,7 +381,7 @@ int SyncRes::AuthDomain::getRecords(const DNSName& qname, uint16_t qtype, std::v return result; } -bool SyncRes::doOOBResolve(const AuthDomain& domain, const DNSName &qname, const QType &qtype, vector&ret, int& res) +bool SyncRes::doOOBResolve(const AuthDomain& domain, const DNSName &qname, QType qtype, vector&ret, int& res) { d_authzonequeries++; s_authzonequeries++; @@ -390,7 +390,7 @@ bool SyncRes::doOOBResolve(const AuthDomain& domain, const DNSName &qname, const return true; } -bool SyncRes::doOOBResolve(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, int& res) +bool SyncRes::doOOBResolve(const DNSName &qname, QType qtype, vector&ret, unsigned int depth, int& res) { string prefix; if(doLog()) { @@ -641,7 +641,7 @@ LWResult::Result SyncRes::asyncresolveWrapper(const ComboAddress& ip, bool ednsM #define QLOG(x) LOG(prefix << " child=" << child << ": " << x << endl) -int SyncRes::doResolve(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, set& beenthere, vState& state) { +int SyncRes::doResolve(const DNSName &qname, QType qtype, vector&ret, unsigned int depth, set& beenthere, vState& state) { string prefix = d_prefix; prefix.append(depth, ' '); @@ -818,7 +818,7 @@ int SyncRes::doResolve(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, set& beenthere, vState& state, bool *fromCache, StopAtDelegation *stopAtDelegation, bool considerforwards) +int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, QType qtype, vector&ret, unsigned int depth, set& beenthere, vState& state, bool *fromCache, StopAtDelegation *stopAtDelegation, bool considerforwards) { string prefix; if(doLog()) { @@ -1092,7 +1092,7 @@ vector SyncRes::getAddrs(const DNSName &qname, unsigned int depth, // We have some IPv4 records, don't bother with going out to get IPv6, but do consult the cache // Once IPv6 adoption matters, this needs to be revisited res_t cset; - if (g_recCache->get(d_now.tv_sec, qname, QType(QType::AAAA), false, &cset, d_cacheRemote, d_refresh, d_routingTag) > 0) { + if (g_recCache->get(d_now.tv_sec, qname, QType::AAAA, false, &cset, d_cacheRemote, d_refresh, d_routingTag) > 0) { for (const auto &i : cset) { if (i.d_ttl > (unsigned int)d_now.tv_sec ) { if (auto rec = getRR(i)) { @@ -1157,7 +1157,7 @@ vector SyncRes::getAddrs(const DNSName &qname, unsigned int depth, return ret; } -void SyncRes::getBestNSFromCache(const DNSName &qname, const QType& qtype, vector& bestns, bool* flawedNSSet, unsigned int depth, set& beenthere, const boost::optional& cutOffDomain) +void SyncRes::getBestNSFromCache(const DNSName &qname, QType qtype, vector& bestns, bool* flawedNSSet, unsigned int depth, set& beenthere, const boost::optional& cutOffDomain) { string prefix; DNSName subdomain(qname); @@ -1176,7 +1176,7 @@ void SyncRes::getBestNSFromCache(const DNSName &qname, const QType& qtype, vecto vector ns; *flawedNSSet = false; - if(g_recCache->get(d_now.tv_sec, subdomain, QType(QType::NS), false, &ns, d_cacheRemote, d_refresh, d_routingTag) > 0) { + if(g_recCache->get(d_now.tv_sec, subdomain, QType::NS, false, &ns, d_cacheRemote, d_refresh, d_routingTag) > 0) { bestns.reserve(ns.size()); for(auto k=ns.cbegin();k!=ns.cend(); ++k) { @@ -1269,7 +1269,7 @@ SyncRes::domainmap_t::const_iterator SyncRes::getBestAuthZone(DNSName* qname) co } /** doesn't actually do the work, leaves that to getBestNSFromCache */ -DNSName SyncRes::getBestNSNamesFromCache(const DNSName &qname, const QType& qtype, NsSet& nsset, bool* flawedNSSet, unsigned int depth, set&beenthere) +DNSName SyncRes::getBestNSNamesFromCache(const DNSName &qname, QType qtype, NsSet& nsset, bool* flawedNSSet, unsigned int depth, set&beenthere) { string prefix; if (doLog()) { @@ -1369,7 +1369,7 @@ static bool scanForCNAMELoop(const DNSName& name, const vector& recor return false; } -bool SyncRes::doCNAMECacheCheck(const DNSName &qname, const QType &qtype, vector& ret, unsigned int depth, int &res, vState& state, bool wasAuthZone, bool wasForwardRecurse) +bool SyncRes::doCNAMECacheCheck(const DNSName &qname, QType qtype, vector& ret, unsigned int depth, int &res, vState& state, bool wasAuthZone, bool wasForwardRecurse) { string prefix; if(doLog()) { @@ -1390,13 +1390,13 @@ bool SyncRes::doCNAMECacheCheck(const DNSName &qname, const QType &qtype, vector uint32_t capTTL = std::numeric_limits::max(); DNSName foundName; DNSName authZone; - QType foundQT = QType(0); // 0 == QTYPE::ENT + QType foundQT = QType::ENT; LOG(prefix<get(d_now.tv_sec, qname, QType(QType::CNAME), !wasForwardRecurse && d_requireAuthData, &cset, d_cacheRemote, d_refresh, d_routingTag, d_doDNSSEC ? &signatures : nullptr, d_doDNSSEC ? &authorityRecs : nullptr, &d_wasVariable, &state, &wasAuth, &authZone) > 0) { + if (g_recCache->get(d_now.tv_sec, qname, QType::CNAME, !wasForwardRecurse && d_requireAuthData, &cset, d_cacheRemote, d_refresh, d_routingTag, d_doDNSSEC ? &signatures : nullptr, d_doDNSSEC ? &authorityRecs : nullptr, &d_wasVariable, &state, &wasAuth, &authZone) > 0) { foundName = qname; - foundQT = QType(QType::CNAME); + foundQT = QType::CNAME; } if (foundName.empty() && qname != g_rootdnsname) { @@ -1411,9 +1411,9 @@ bool SyncRes::doCNAMECacheCheck(const DNSName &qname, const QType &qtype, vector if (dnameName == qname && qtype != QType::DNAME) { // The client does not want a DNAME, but we've reached the QNAME already. So there is no match break; } - if (g_recCache->get(d_now.tv_sec, dnameName, QType(QType::DNAME), !wasForwardRecurse && d_requireAuthData, &cset, d_cacheRemote, d_refresh, d_routingTag, d_doDNSSEC ? &signatures : nullptr, d_doDNSSEC ? &authorityRecs : nullptr, &d_wasVariable, &state, &wasAuth, &authZone) > 0) { + if (g_recCache->get(d_now.tv_sec, dnameName, QType::DNAME, !wasForwardRecurse && d_requireAuthData, &cset, d_cacheRemote, d_refresh, d_routingTag, d_doDNSSEC ? &signatures : nullptr, d_doDNSSEC ? &authorityRecs : nullptr, &d_wasVariable, &state, &wasAuth, &authZone) > 0) { foundName = dnameName; - foundQT = QType(QType::DNAME); + foundQT = QType::DNAME; break; } } while(!labels.empty()); @@ -1589,7 +1589,7 @@ struct CacheEntry struct CacheKey { DNSName name; - uint16_t type; + QType type; DNSResourceRecord::Place place; bool operator<(const CacheKey& rhs) const { return tie(type, place, name) < tie(rhs.type, rhs.place, rhs.name); @@ -1612,14 +1612,14 @@ static void reapRecordsFromNegCacheEntryForValidation(tcache_t& tcache, const ve } } -static void reapRecordsForValidation(std::map& entries, const vector& records) +static void reapRecordsForValidation(std::map& entries, const vector& records) { for (const auto& rec : records) { entries[rec.d_type].records.push_back(rec); } } -static void reapSignaturesForValidation(std::map& entries, const vector>& signatures) +static void reapSignaturesForValidation(std::map& entries, const vector>& signatures) { for (const auto& sig : signatures) { entries[sig->d_type].signatures.push_back(sig); @@ -1696,7 +1696,7 @@ void SyncRes::computeNegCacheValidationStatus(const NegCache::NegCacheEntry& ne, } } -bool SyncRes::doCacheCheck(const DNSName &qname, const DNSName& authname, bool wasForwardedOrAuthZone, bool wasAuthZone, bool wasForwardRecurse, const QType &qtype, vector&ret, unsigned int depth, int &res, vState& state) +bool SyncRes::doCacheCheck(const DNSName &qname, const DNSName& authname, bool wasForwardedOrAuthZone, bool wasAuthZone, bool wasForwardRecurse, QType qtype, vector&ret, unsigned int depth, int &res, vState& state) { bool giveNegative=false; @@ -1746,7 +1746,7 @@ bool SyncRes::doCacheCheck(const DNSName &qname, const DNSName& authname, bool w negCacheName.prependRawLabel(labels.back()); labels.pop_back(); while(!labels.empty()) { - if (g_negCache->get(negCacheName, QType(0), d_now, ne, true)) { + if (g_negCache->get(negCacheName, QType::ENT, d_now, ne, true)) { if (ne.d_validationState == vState::Indeterminate && validationEnabled()) { // LOG(prefix << negCacheName << " negatively cached and vState::Indeterminate, trying to validate NXDOMAIN" << endl); // ... @@ -1824,7 +1824,7 @@ bool SyncRes::doCacheCheck(const DNSName &qname, const DNSName& authname, bool w } else { if (sqt == QType::ANY) { - std::map types; + std::map types; reapRecordsForValidation(types, cset); reapSignaturesForValidation(types, signatures); @@ -1834,7 +1834,7 @@ bool SyncRes::doCacheCheck(const DNSName &qname, const DNSName& authname, bool w cachedRecordState = validateDNSKeys(sqname, type.second.records, type.second.signatures, depth); } else { - cachedRecordState = SyncRes::validateRecordsWithSigs(depth, qname, qtype, sqname, QType(type.first), type.second.records, type.second.signatures); + cachedRecordState = SyncRes::validateRecordsWithSigs(depth, qname, qtype, sqname, type.first, type.second.records, type.second.signatures); } updateDNSSECValidationState(cachedState, cachedRecordState); } @@ -2000,7 +2000,7 @@ static uint32_t getRRSIGTTL(const time_t now, const std::shared_ptr nsecTypes = {QType::NSEC, QType::NSEC3}; +static const set nsecTypes = {QType::NSEC, QType::NSEC3}; /* Fills the authoritySOA and DNSSECRecords fields from ne with those found in the records * @@ -2104,7 +2104,7 @@ static bool rpzHitShouldReplaceContent(const DNSName& qname, const QType& qtype, return true; } -static void removeConflictingRecord(std::vector& records, const DNSName& name, uint16_t dtype) +static void removeConflictingRecord(std::vector& records, const DNSName& name, QType dtype) { for (auto it = records.begin(); it != records.end(); ) { bool remove = false; @@ -2434,7 +2434,7 @@ vState SyncRes::getDSRecords(const DNSName& zone, dsmap_t& ds, bool taOnly, unsi vState state = vState::Indeterminate; const bool oldCacheOnly = setCacheOnly(false); - int rcode = doResolve(zone, QType(QType::DS), dsrecords, depth + 1, beenthere, state); + int rcode = doResolve(zone, QType::DS, dsrecords, depth + 1, beenthere, state); setCacheOnly(oldCacheOnly); if (rcode == RCode::ServFail) { @@ -2720,7 +2720,7 @@ vState SyncRes::getDNSKeys(const DNSName& signer, skeyset_t& keys, unsigned int vState state = vState::Indeterminate; const bool oldCacheOnly = setCacheOnly(false); - int rcode = doResolve(signer, QType(QType::DNSKEY), records, depth + 1, beenthere, state); + int rcode = doResolve(signer, QType::DNSKEY, records, depth + 1, beenthere, state); setCacheOnly(oldCacheOnly); if (rcode == RCode::ServFail) { @@ -2969,10 +2969,10 @@ RCode::rcodes_ SyncRes::updateCacheFromRecords(unsigned int depth, LWResult& lwr rec.d_ttl = min(s_maxcachettl, rec.d_ttl); - if(!isCNAMEAnswer && rec.d_place == DNSResourceRecord::ANSWER && rec.d_type == QType::CNAME && (!(qtype==QType(QType::CNAME))) && rec.d_name == qname && !isDNAMEAnswer) { + if(!isCNAMEAnswer && rec.d_place == DNSResourceRecord::ANSWER && rec.d_type == QType::CNAME && (!(qtype==QType::CNAME)) && rec.d_name == qname && !isDNAMEAnswer) { isCNAMEAnswer = true; } - if(!isDNAMEAnswer && rec.d_place == DNSResourceRecord::ANSWER && rec.d_type == QType::DNAME && qtype != QType(QType::DNAME) && qname.isPartOf(rec.d_name)) { + if(!isDNAMEAnswer && rec.d_place == DNSResourceRecord::ANSWER && rec.d_type == QType::DNAME && qtype != QType::DNAME && qname.isPartOf(rec.d_name)) { isDNAMEAnswer = true; isCNAMEAnswer = false; } @@ -3277,7 +3277,7 @@ RCode::rcodes_ SyncRes::updateCacheFromRecords(unsigned int depth, LWResult& lwr } } if (doCache) { - g_recCache->replace(d_now.tv_sec, i->first.name, QType(i->first.type), i->second.records, i->second.signatures, authorityRecs, i->first.type == QType::DS ? true : isAA, auth, i->first.place == DNSResourceRecord::ANSWER ? ednsmask : boost::none, d_routingTag, recordState, remoteIP); + g_recCache->replace(d_now.tv_sec, i->first.name, i->first.type, i->second.records, i->second.signatures, authorityRecs, i->first.type == QType::DS ? true : isAA, auth, i->first.place == DNSResourceRecord::ANSWER ? ednsmask : boost::none, d_routingTag, recordState, remoteIP); } } @@ -3364,7 +3364,7 @@ bool SyncRes::processRecords(const std::string& prefix, const DNSName& qname, co /* if we get an NXDomain answer with a CNAME, the name does exist but the target does not */ ne.d_name = newtarget.empty() ? qname : newtarget; - ne.d_qtype = QType(0); // this encodes 'whole record' + ne.d_qtype = QType::ENT; // this encodes 'whole record' ne.d_auth = rec.d_name; harvestNXRecords(lwr.d_records, ne, d_now.tv_sec, &lowestTTL); @@ -3443,7 +3443,7 @@ bool SyncRes::processRecords(const std::string& prefix, const DNSName& qname, co // for ANY answers we *must* have an authoritative answer, unless we are forwarding recursively else if(rec.d_place==DNSResourceRecord::ANSWER && rec.d_name == qname && ( - rec.d_type==qtype.getCode() || ((lwr.d_aabit || sendRDQuery) && qtype == QType(QType::ANY)) + rec.d_type==qtype.getCode() || ((lwr.d_aabit || sendRDQuery) && qtype == QType::ANY) ) ) { @@ -3461,7 +3461,7 @@ bool SyncRes::processRecords(const std::string& prefix, const DNSName& qname, co uint32_t lowestTTL = rec.d_ttl; ne.d_name = qname; - ne.d_qtype = QType(0); // this encodes 'whole record' + ne.d_qtype = QType::ENT; // this encodes 'whole record' harvestNXRecords(lwr.d_records, ne, d_now.tv_sec, &lowestTTL); cspmap_t csp = harvestCSPFromNE(ne); @@ -3779,7 +3779,7 @@ bool SyncRes::doResolveAtThisIP(const std::string& prefix, const DNSName& qname, return true; } -void SyncRes::handleNewTarget(const std::string& prefix, const DNSName& qname, const DNSName& newtarget, uint16_t qtype, std::vector& ret, int& rcode, int depth, const std::vector& recordsFromAnswer, vState& state) +void SyncRes::handleNewTarget(const std::string& prefix, const DNSName& qname, const DNSName& newtarget, QType qtype, std::vector& ret, int& rcode, int depth, const std::vector& recordsFromAnswer, vState& state) { if (newtarget == qname) { LOG(prefix< beenthere; vState cnameState = vState::Indeterminate; - rcode = doResolve(newtarget, QType(qtype), ret, depth + 1, beenthere, cnameState); + rcode = doResolve(newtarget, qtype, ret, depth + 1, beenthere, cnameState); LOG(prefix<&ret, unsigned int depth, set&beenthere, vState& state, StopAtDelegation* stopAtDelegation) { @@ -4225,7 +4225,7 @@ int directResolve(const DNSName& qname, const QType& qtype, int qclass, vector ret; int res=-1; try { - res=sr.beginResolve(g_rootdnsname, QType(QType::NS), 1, ret, depth + 1); + res=sr.beginResolve(g_rootdnsname, QType::NS, 1, ret, depth + 1); if (g_dnssecmode != DNSSECMode::Off && g_dnssecmode != DNSSECMode::ProcessNoValidate) { auto state = sr.getValidationState(); if (vStateIsBogus(state)) { diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 5bb8821ae5..58dca42d0e 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -345,7 +345,7 @@ public: DNSName d_name; bool d_rdForward{false}; - int getRecords(const DNSName& qname, uint16_t qtype, std::vector& records) const; + int getRecords(const DNSName& qname, QType qtype, std::vector& records) const; bool isAuth() const { return d_servers.empty(); @@ -585,7 +585,7 @@ public: explicit SyncRes(const struct timeval& now); - int beginResolve(const DNSName &qname, const QType &qtype, uint16_t qclass, vector&ret, unsigned int depth = 0); + int beginResolve(const DNSName &qname, QType qtype, uint16_t qclass, vector&ret, unsigned int depth = 0); void setId(int id) { @@ -793,7 +793,7 @@ private: static EDNSSubnetOpts s_ecsScopeZero; static LogMode s_lm; static std::unique_ptr s_dontQuery; - const static std::unordered_set s_redirectionQTypes; + const static std::unordered_set s_redirectionQTypes; struct GetBestNSAnswer { @@ -810,21 +810,21 @@ private: typedef std::map zonesStates_t; enum StopAtDelegation { DontStop, Stop, Stopped }; - int doResolveAt(NsSet &nameservers, DNSName auth, bool flawedNSSet, const DNSName &qname, const QType &qtype, vector&ret, + int doResolveAt(NsSet &nameservers, DNSName auth, bool flawedNSSet, const DNSName &qname, QType qtype, vector&ret, unsigned int depth, set&beenthere, vState& state, StopAtDelegation* stopAtDelegation); bool doResolveAtThisIP(const std::string& prefix, const DNSName& qname, const QType& qtype, LWResult& lwr, boost::optional& ednsmask, const DNSName& auth, bool const sendRDQuery, const bool wasForwarded, const DNSName& nsName, const ComboAddress& remoteIP, bool doTCP, bool& truncated, bool& spoofed); bool processAnswer(unsigned int depth, LWResult& lwr, const DNSName& qname, const QType& qtype, DNSName& auth, bool wasForwarded, const boost::optional ednsmask, bool sendRDQuery, NsSet &nameservers, std::vector& ret, const DNSFilterEngine& dfe, bool* gotNewServers, int* rcode, vState& state, const ComboAddress& remoteIP); - int doResolve(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, set& beenthere, vState& state); - int doResolveNoQNameMinimization(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, set& beenthere, vState& state, bool* fromCache = NULL, StopAtDelegation* stopAtDelegation = NULL, bool considerforwards = true); - bool doOOBResolve(const AuthDomain& domain, const DNSName &qname, const QType &qtype, vector&ret, int& res); - bool doOOBResolve(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, int &res); + int doResolve(const DNSName &qname, QType qtype, vector&ret, unsigned int depth, set& beenthere, vState& state); + int doResolveNoQNameMinimization(const DNSName &qname, QType qtype, vector&ret, unsigned int depth, set& beenthere, vState& state, bool* fromCache = NULL, StopAtDelegation* stopAtDelegation = NULL, bool considerforwards = true); + bool doOOBResolve(const AuthDomain& domain, const DNSName &qname, QType qtype, vector&ret, int& res); + bool doOOBResolve(const DNSName &qname, QType qtype, vector&ret, unsigned int depth, int &res); bool isRecursiveForwardOrAuth(const DNSName &qname) const; domainmap_t::const_iterator getBestAuthZone(DNSName* qname) const; - bool doCNAMECacheCheck(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, int &res, vState& state, bool wasAuthZone, bool wasForwardRecurse); - bool doCacheCheck(const DNSName &qname, const DNSName& authname, bool wasForwardedOrAuthZone, bool wasAuthZone, bool wasForwardRecurse, const QType &qtype, vector&ret, unsigned int depth, int &res, vState& state); - void getBestNSFromCache(const DNSName &qname, const QType &qtype, vector&bestns, bool* flawedNSSet, unsigned int depth, set& beenthere, const boost::optional& cutOffDomain = boost::none); - DNSName getBestNSNamesFromCache(const DNSName &qname, const QType &qtype, NsSet& nsset, bool* flawedNSSet, unsigned int depth, set&beenthere); + bool doCNAMECacheCheck(const DNSName &qname, QType qtype, vector&ret, unsigned int depth, int &res, vState& state, bool wasAuthZone, bool wasForwardRecurse); + bool doCacheCheck(const DNSName &qname, const DNSName& authname, bool wasForwardedOrAuthZone, bool wasAuthZone, bool wasForwardRecurse, QType qtype, vector&ret, unsigned int depth, int &res, vState& state); + void getBestNSFromCache(const DNSName &qname, QType qtype, vector&bestns, bool* flawedNSSet, unsigned int depth, set& beenthere, const boost::optional& cutOffDomain = boost::none); + DNSName getBestNSNamesFromCache(const DNSName &qname, QType qtype, NsSet& nsset, bool* flawedNSSet, unsigned int depth, set&beenthere); inline vector> shuffleInSpeedOrder(NsSet &nameservers, const string &prefix); inline vector shuffleForwardSpeed(const vector &rnameservers, const string &prefix, const bool wasRd); @@ -841,7 +841,7 @@ private: 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, unsigned int depth); - bool doSpecialNamesResolve(const DNSName &qname, const QType &qtype, const uint16_t qclass, vector &ret); + bool doSpecialNamesResolve(const DNSName &qname, QType qtype, const uint16_t qclass, vector &ret); LWResult::Result asyncresolveWrapper(const ComboAddress& ip, bool ednsMANDATORY, const DNSName& domain, const DNSName& auth, int type, bool doTCP, bool sendRDQuery, struct timeval* now, boost::optional& srcmask, LWResult* res, bool* chained) const; @@ -864,7 +864,7 @@ private: bool lookForCut(const DNSName& qname, unsigned int depth, const vState existingState, vState& newState); void computeZoneCuts(const DNSName& begin, const DNSName& end, unsigned int depth); - void handleNewTarget(const std::string& prefix, const DNSName& qname, const DNSName& newtarget, uint16_t qtype, std::vector& ret, int& rcode, int depth, const std::vector& recordsFromAnswer, vState& state); + void handleNewTarget(const std::string& prefix, const DNSName& qname, const DNSName& newtarget, QType qtype, std::vector& ret, int& rcode, int depth, const std::vector& recordsFromAnswer, vState& state); void handlePolicyHit(const std::string& prefix, const DNSName& qname, const QType& qtype, vector& ret, bool& done, int& rcode, unsigned int depth);