]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Improve the way QType behaves by defining proper conversion
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 4 Dec 2020 15:31:33 +0000 (16:31 +0100)
committerOtto <otto.moerbeek@open-xchange.com>
Wed, 10 Feb 2021 12:26:12 +0000 (13:26 +0100)
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.

pdns/qtype.cc
pdns/qtype.hh
pdns/syncres.cc
pdns/syncres.hh

index 31f383124ea86a8ad11e9e57e8145f708bc8a2ea..d33273bf546103871b4063ddafeffecb291409d0 100644 (file)
 
 static_assert(sizeof(QType) == 2, "QType is not 2 bytes in size, something is wrong!");
 
-vector<QType::namenum> QType::names;
-// XXX FIXME we need to do something with initializer order here!
-QType::init QType::initializer; 
-
-QType::QType()
+const vector<QType::namenum> 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<namenum>::iterator pos=names.begin();pos<names.end();++pos)
-    if(pos->second==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<namenum>::iterator pos;
-  for(pos=names.begin();pos<names.end();++pos)
-    if(pos->second==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<namenum>::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<uint16_t>(atoi(p+1));
   }
 
-  if(boost::starts_with(P, "TYPE"))
-    return atoi(p+4);
+  if (boost::starts_with(P, "TYPE")) {
+    return static_cast<uint16_t>(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;
-}
index 8cbf2441dc543acd901e70a95dcfe1c235fa134a..1751ac14f05c8a8b87fe1b8fe67430d02d2a84b4 100644 (file)
@@ -20,8 +20,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 #pragma once
-#include <string>
-#include <vector>
 #include "namespaces.hh"
 
 /** The QType class is meant to deal easily with the different kind of resource types, like 'A', 'NS',
 
 */
 
-
-
 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<string,uint16_t> namenum;
-  static vector<namenum> 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<string, uint16_t> namenum;
+  const static vector<namenum> 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<QType> {
+    std::size_t operator()(QType qtype) const noexcept {
+      return std::hash<uint16_t>{}(qtype.getCode());
+    }
+  };
+}
+
 struct QClass
 {
-  enum QClassEnum {IN=1, CHAOS=3, NONE=254, ANY=255};
+  enum QClassEnum { IN = 1, CHAOS = 3, NONE = 254, ANY = 255 };
 };
index a327f789d579791fad5ee541fef65c25570df975..7ff340e6ff1cbe17fc65397376db6bccc6172276 100644 (file)
@@ -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<uint16_t> SyncRes::s_redirectionQTypes = {QType::CNAME, QType::DNAME};
+const std::unordered_set<QType> 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<DNSRecord>&ret, unsigned int depth)
+int SyncRes::beginResolve(const DNSName &qname, const QType qtype, uint16_t qclass, vector<DNSRecord>&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<DNSRecord> &ret)
+bool SyncRes::doSpecialNamesResolve(const DNSName &qname, QType qtype, const uint16_t qclass, vector<DNSRecord> &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<DNSRecord>& records) const
   }
 }
 
-int SyncRes::AuthDomain::getRecords(const DNSName& qname, uint16_t qtype, std::vector<DNSRecord>& records) const
+int SyncRes::AuthDomain::getRecords(const DNSName& qname, QType qtype, std::vector<DNSRecord>& 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<DNSRecord>&ret, int& res)
+bool SyncRes::doOOBResolve(const AuthDomain& domain, const DNSName &qname, QType qtype, vector<DNSRecord>&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<DNSRecord>&ret, unsigned int depth, int& res)
+bool SyncRes::doOOBResolve(const DNSName &qname, QType qtype, vector<DNSRecord>&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<DNSRecord>&ret, unsigned int depth, set<GetBestNSAnswer>& beenthere, vState& state) {
+int SyncRes::doResolve(const DNSName &qname, QType qtype, vector<DNSRecord>&ret, unsigned int depth, set<GetBestNSAnswer>& beenthere, vState& state) {
 
   string prefix = d_prefix;
   prefix.append(depth, ' ');
@@ -818,7 +818,7 @@ int SyncRes::doResolve(const DNSName &qname, const QType &qtype, vector<DNSRecor
  * \param stopAtDelegation if non-nullptr and pointed-to value is Stop requests the callee to stop at a delegation, if so pointed-to value is set to Stopped
  * \return DNS RCODE or -1 (Error)
  */
-int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, const QType &qtype, vector<DNSRecord>&ret, unsigned int depth, set<GetBestNSAnswer>& beenthere, vState& state, bool *fromCache, StopAtDelegation *stopAtDelegation, bool considerforwards)
+int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, QType qtype, vector<DNSRecord>&ret, unsigned int depth, set<GetBestNSAnswer>& beenthere, vState& state, bool *fromCache, StopAtDelegation *stopAtDelegation, bool considerforwards)
 {
   string prefix;
   if(doLog()) {
@@ -1092,7 +1092,7 @@ vector<ComboAddress> 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<AAAARecordContent>(i)) {
@@ -1157,7 +1157,7 @@ vector<ComboAddress> SyncRes::getAddrs(const DNSName &qname, unsigned int depth,
   return ret;
 }
 
-void SyncRes::getBestNSFromCache(const DNSName &qname, const QType& qtype, vector<DNSRecord>& bestns, bool* flawedNSSet, unsigned int depth, set<GetBestNSAnswer>& beenthere, const boost::optional<DNSName>& cutOffDomain)
+void SyncRes::getBestNSFromCache(const DNSName &qname, QType qtype, vector<DNSRecord>& bestns, bool* flawedNSSet, unsigned int depth, set<GetBestNSAnswer>& beenthere, const boost::optional<DNSName>& cutOffDomain)
 {
   string prefix;
   DNSName subdomain(qname);
@@ -1176,7 +1176,7 @@ void SyncRes::getBestNSFromCache(const DNSName &qname, const QType& qtype, vecto
     vector<DNSRecord> 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<GetBestNSAnswer>&beenthere)
+DNSName SyncRes::getBestNSNamesFromCache(const DNSName &qname, QType qtype, NsSet& nsset, bool* flawedNSSet, unsigned int depth, set<GetBestNSAnswer>&beenthere)
 {
   string prefix;
   if (doLog()) {
@@ -1369,7 +1369,7 @@ static bool scanForCNAMELoop(const DNSName& name, const vector<DNSRecord>& recor
   return false;
 }
 
-bool SyncRes::doCNAMECacheCheck(const DNSName &qname, const QType &qtype, vector<DNSRecord>& ret, unsigned int depth, int &res, vState& state, bool wasAuthZone, bool wasForwardRecurse)
+bool SyncRes::doCNAMECacheCheck(const DNSName &qname, QType qtype, vector<DNSRecord>& 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<uint32_t>::max();
   DNSName foundName;
   DNSName authZone;
-  QType foundQT = QType(0); // 0 == QTYPE::ENT
+  QType foundQT = QType::ENT;
 
   LOG(prefix<<qname<<": Looking for CNAME cache hit of '"<<qname<<"|CNAME"<<"'"<<endl);
   /* we don't require auth data for forward-recurse lookups */
-  if (g_recCache->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<uint16_t, CacheEntry>& entries, const vector<DNSRecord>& records)
+static void reapRecordsForValidation(std::map<QType, CacheEntry>& entries, const vector<DNSRecord>& records)
 {
   for (const auto& rec : records) {
     entries[rec.d_type].records.push_back(rec);
   }
 }
 
-static void reapSignaturesForValidation(std::map<uint16_t, CacheEntry>& entries, const vector<std::shared_ptr<RRSIGRecordContent>>& signatures)
+static void reapSignaturesForValidation(std::map<QType, CacheEntry>& entries, const vector<std::shared_ptr<RRSIGRecordContent>>& 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<DNSRecord>&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<DNSRecord>&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<uint16_t, CacheEntry> types;
+            std::map<QType, CacheEntry> 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<RRSIGRecordC
   return res;
 }
 
-static const set<uint16_t> nsecTypes = {QType::NSEC, QType::NSEC3};
+static const set<QType> 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<DNSRecord>& records, const DNSName& name, uint16_t dtype)
+static void removeConflictingRecord(std::vector<DNSRecord>& 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<DNSRecord>& ret, int& rcode, int depth, const std::vector<DNSRecord>& recordsFromAnswer, vState& state)
+void SyncRes::handleNewTarget(const std::string& prefix, const DNSName& qname, const DNSName& newtarget, QType qtype, std::vector<DNSRecord>& ret, int& rcode, int depth, const std::vector<DNSRecord>& recordsFromAnswer, vState& state)
 {
   if (newtarget == qname) {
     LOG(prefix<<qname<<": status=got a CNAME referral to self, returning SERVFAIL"<<endl);
@@ -3827,7 +3827,7 @@ void SyncRes::handleNewTarget(const std::string& prefix, const DNSName& qname, c
 
   set<GetBestNSAnswer> 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<<qname<<": updating validation state for response to "<<qname<<" from "<<state<<" with the state from the CNAME quest: "<<cnameState<<endl);
   updateValidationState(state, cnameState);
 }
@@ -3951,7 +3951,7 @@ bool SyncRes::processAnswer(unsigned int depth, LWResult& lwr, const DNSName& qn
  *  -1 in case of no results
  *  rcode otherwise
  */
-int SyncRes::doResolveAt(NsSet &nameservers, DNSName auth, bool flawedNSSet, const DNSName &qname, const QType &qtype,
+int SyncRes::doResolveAt(NsSet &nameservers, DNSName auth, bool flawedNSSet, const DNSName &qname, QType qtype,
                          vector<DNSRecord>&ret,
                          unsigned int depth, set<GetBestNSAnswer>&beenthere, vState& state, StopAtDelegation* stopAtDelegation)
 {
@@ -4225,7 +4225,7 @@ int directResolve(const DNSName& qname, const QType& qtype, int qclass, vector<D
   SyncRes sr(now);
   int res = -1;
   try {
-    res = sr.beginResolve(qname, QType(qtype), qclass, ret, 0);
+    res = sr.beginResolve(qname, qtype, qclass, ret, 0);
   }
   catch(const PDNSException& e) {
     g_log<<Logger::Error<<"Failed to resolve "<<qname<<", got pdns exception: "<<e.reason<<endl;
@@ -4262,7 +4262,7 @@ int SyncRes::getRootNS(struct timeval now, asyncresolve_t asyncCallback, unsigne
   vector<DNSRecord> 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)) {
index 5bb8821ae571383dc1ee0a90b53a94e1afb43260..58dca42d0e094a9ebf2a70dab0d4a9187528c044 100644 (file)
@@ -345,7 +345,7 @@ public:
     DNSName d_name;
     bool d_rdForward{false};
 
-    int getRecords(const DNSName& qname, uint16_t qtype, std::vector<DNSRecord>& records) const;
+    int getRecords(const DNSName& qname, QType qtype, std::vector<DNSRecord>& 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<DNSRecord>&ret, unsigned int depth = 0);
+  int beginResolve(const DNSName &qname, QType qtype, uint16_t qclass, vector<DNSRecord>&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<NetmaskGroup> s_dontQuery;
-  const static std::unordered_set<uint16_t> s_redirectionQTypes;
+  const static std::unordered_set<QType> s_redirectionQTypes;
 
   struct GetBestNSAnswer
   {
@@ -810,21 +810,21 @@ private:
   typedef std::map<DNSName,vState> zonesStates_t;
   enum StopAtDelegation { DontStop, Stop, Stopped };
 
-  int doResolveAt(NsSet &nameservers, DNSName auth, bool flawedNSSet, const DNSName &qname, const QType &qtype, vector<DNSRecord>&ret,
+  int doResolveAt(NsSet &nameservers, DNSName auth, bool flawedNSSet, const DNSName &qname, QType qtype, vector<DNSRecord>&ret,
                   unsigned int depth, set<GetBestNSAnswer>&beenthere, vState& state, StopAtDelegation* stopAtDelegation);
   bool doResolveAtThisIP(const std::string& prefix, const DNSName& qname, const QType& qtype, LWResult& lwr, boost::optional<Netmask>& 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<Netmask> ednsmask, bool sendRDQuery, NsSet &nameservers, std::vector<DNSRecord>& ret, const DNSFilterEngine& dfe, bool* gotNewServers, int* rcode, vState& state, const ComboAddress& remoteIP);
 
-  int doResolve(const DNSName &qname, const QType &qtype, vector<DNSRecord>&ret, unsigned int depth, set<GetBestNSAnswer>& beenthere, vState& state);
-  int doResolveNoQNameMinimization(const DNSName &qname, const QType &qtype, vector<DNSRecord>&ret, unsigned int depth, set<GetBestNSAnswer>& beenthere, vState& state, bool* fromCache = NULL, StopAtDelegation* stopAtDelegation = NULL, bool considerforwards = true);
-  bool doOOBResolve(const AuthDomain& domain, const DNSName &qname, const QType &qtype, vector<DNSRecord>&ret, int& res);
-  bool doOOBResolve(const DNSName &qname, const QType &qtype, vector<DNSRecord>&ret, unsigned int depth, int &res);
+  int doResolve(const DNSName &qname, QType qtype, vector<DNSRecord>&ret, unsigned int depth, set<GetBestNSAnswer>& beenthere, vState& state);
+  int doResolveNoQNameMinimization(const DNSName &qname, QType qtype, vector<DNSRecord>&ret, unsigned int depth, set<GetBestNSAnswer>& beenthere, vState& state, bool* fromCache = NULL, StopAtDelegation* stopAtDelegation = NULL, bool considerforwards = true);
+  bool doOOBResolve(const AuthDomain& domain, const DNSName &qname, QType qtype, vector<DNSRecord>&ret, int& res);
+  bool doOOBResolve(const DNSName &qname, QType qtype, vector<DNSRecord>&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<DNSRecord>&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<DNSRecord>&ret, unsigned int depth, int &res, vState& state);
-  void getBestNSFromCache(const DNSName &qname, const QType &qtype, vector<DNSRecord>&bestns, bool* flawedNSSet, unsigned int depth, set<GetBestNSAnswer>& beenthere, const boost::optional<DNSName>& cutOffDomain = boost::none);
-  DNSName getBestNSNamesFromCache(const DNSName &qname, const QType &qtype, NsSet& nsset, bool* flawedNSSet, unsigned int depth, set<GetBestNSAnswer>&beenthere);
+  bool doCNAMECacheCheck(const DNSName &qname, QType qtype, vector<DNSRecord>&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<DNSRecord>&ret, unsigned int depth, int &res, vState& state);
+  void getBestNSFromCache(const DNSName &qname, QType qtype, vector<DNSRecord>&bestns, bool* flawedNSSet, unsigned int depth, set<GetBestNSAnswer>& beenthere, const boost::optional<DNSName>& cutOffDomain = boost::none);
+  DNSName getBestNSNamesFromCache(const DNSName &qname, QType qtype, NsSet& nsset, bool* flawedNSSet, unsigned int depth, set<GetBestNSAnswer>&beenthere);
 
   inline vector<std::pair<DNSName, float>> shuffleInSpeedOrder(NsSet &nameservers, const string &prefix);
   inline vector<ComboAddress> shuffleForwardSpeed(const vector<ComboAddress> &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<Netmask>, 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<DNSRecord>& ret, set<DNSName>& 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<DNSRecord> &ret);
+  bool doSpecialNamesResolve(const DNSName &qname, QType qtype, const uint16_t qclass, vector<DNSRecord> &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<Netmask>& 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<DNSRecord>& ret, int& rcode, int depth, const std::vector<DNSRecord>& recordsFromAnswer, vState& state);
+  void handleNewTarget(const std::string& prefix, const DNSName& qname, const DNSName& newtarget, QType qtype, std::vector<DNSRecord>& ret, int& rcode, int depth, const std::vector<DNSRecord>& recordsFromAnswer, vState& state);
 
   void handlePolicyHit(const std::string& prefix, const DNSName& qname, const QType& qtype, vector<DNSRecord>& ret, bool& done, int& rcode, unsigned int depth);