]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Make QClass a class, including toString() method
authorOtto <otto.moerbeek@open-xchange.com>
Tue, 30 Mar 2021 12:09:37 +0000 (14:09 +0200)
committerOtto <otto.moerbeek@open-xchange.com>
Tue, 30 Mar 2021 12:09:37 +0000 (14:09 +0200)
pdns/pdns_recursor.cc
pdns/qtype.cc
pdns/qtype.hh
pdns/sdig.cc
pdns/syncres.cc
pdns/syncres.hh

index 5d8b3c959f459f6eda703de4fe90620f044c86c8..0a5f002c3d09629af44e785552c00b223838dc90 100644 (file)
@@ -1326,8 +1326,6 @@ static void sendNODLookup(const DNSName& dname)
 {
   if (!(g_nodLookupDomain.isRoot())) {
     // Send a DNS A query to <domain>.g_nodLookupDomain
-    static const QType qt(QType::A);
-    static const uint16_t qc(QClass::IN);
     DNSName qname;
     try {
       qname = dname + g_nodLookupDomain;
@@ -1337,7 +1335,7 @@ static void sendNODLookup(const DNSName& dname)
       return;
     }
     vector<DNSRecord> dummy;
-    directResolve(qname, qt, qc, dummy);
+    directResolve(qname, QType::A, QClass::IN, dummy);
   }
 }
 
@@ -1393,7 +1391,7 @@ int getFakeAAAARecords(const DNSName& qname, ComboAddress prefix, vector<DNSReco
      again, possibly encountering the same CNAME(s), and we don't want to trigger the CNAME
      loop detection. */
   vector<DNSRecord> newRecords;
-  int rcode = directResolve(qname, QType(QType::A), QClass::IN, newRecords);
+  int rcode = directResolve(qname, QType::A, QClass::IN, newRecords);
 
   ret.reserve(ret.size() + newRecords.size());
   for (auto& record : newRecords) {
@@ -1473,7 +1471,7 @@ int getFakePTRRecords(const DNSName& qname, vector<DNSRecord>& ret)
   rr.d_content = std::make_shared<CNAMERecordContent>(newquery);
   ret.push_back(rr);
 
-  int rcode = directResolve(DNSName(newquery), QType(QType::PTR), QClass::IN, ret);
+  int rcode = directResolve(DNSName(newquery), QType::PTR, QClass::IN, ret);
 
   return rcode;
 }
index 7c23075b979700b5e46e855cb714a0535a21c050..caaf42f454b7fa718c98481ef03435adbb4c1db1 100644 (file)
@@ -160,3 +160,19 @@ QType &QType::operator=(const string &s)
   code = chartocode(s.c_str());
   return *this;
 }
+
+const std::string QClass::toString() const
+{
+  switch (qclass) {
+  case IN:
+    return "IN";
+  case CHAOS:
+    return "CHAOS";
+  case NONE:
+    return "NONE";
+  case ANY:
+    return "ANY";
+  default :
+    return "CLASS" + std::to_string(qclass);
+  }
+}
index bcb02e2dd933614cc3af2d4059ec29e1e10b39d0..02c5ef57f36bddf77751807965819a3e156d08d2 100644 (file)
@@ -146,5 +146,19 @@ inline size_t hash_value(const QType qtype) {
 
 struct QClass
 {
-  enum QClassEnum { IN = 1, CHAOS = 3, NONE = 254, ANY = 255 };
+  enum QClassEnum : uint16_t { IN = 1, CHAOS = 3, NONE = 254, ANY = 255 };
+
+  QClass(uint16_t code = 0) : qclass(code) {}
+
+  operator uint16_t() const {
+    return qclass;
+  }
+  uint16_t getCode() const
+  {
+    return qclass;
+  }
+  const std::string toString() const;
+
+private:
+  uint16_t qclass;
 };
index e2857f9ed7598c53810e39f3bb6f2209c25ca370..1d25fba414d7c83ef215bba712fd6e4c4a72f7c9 100644 (file)
@@ -46,23 +46,12 @@ static void usage()
        << endl;
 }
 
-static const string nameForClass(uint16_t qclass, uint16_t qtype)
+static const string nameForClass(QClass qclass, uint16_t qtype)
 {
   if (qtype == QType::OPT)
     return "IN";
 
-  switch (qclass) {
-  case QClass::IN:
-    return "IN";
-  case QClass::CHAOS:
-    return "CHAOS";
-  case QClass::NONE:
-    return "NONE";
-  case QClass::ANY:
-    return "ANY";
-  default:
-    return string("CLASS") + std::to_string(qclass);
-  }
+  return qclass.toString();
 }
 
 static std::unordered_set<uint16_t> s_expectedIDs;
@@ -71,7 +60,7 @@ static void fillPacket(vector<uint8_t>& packet, const string& q, const string& t
                        bool dnssec, const boost::optional<Netmask> ednsnm,
                        bool recurse, uint16_t xpfcode, uint16_t xpfversion,
                        uint64_t xpfproto, char* xpfsrc, char* xpfdst,
-                       uint16_t qclass, uint16_t qid)
+                       QClass qclass, uint16_t qid)
 {
   DNSPacketWriter pw(packet, DNSName(q), DNSRecordContent::TypeToNumber(t), qclass);
 
@@ -222,7 +211,7 @@ try {
   boost::optional<Netmask> ednsnm;
   uint16_t xpfcode = 0, xpfversion = 0, xpfproto = 0;
   char *xpfsrc = NULL, *xpfdst = NULL;
-  uint16_t qclass = QClass::IN;
+  QClass qclass = QClass::IN;
   string proxyheader;
   string subjectName;
   string caStore;
index 6170cdac1ffbd80eb2c40f04cad75c4cddf7e280..55559511bea90bdf11fea19cea29a474779ddf95 100644 (file)
@@ -121,7 +121,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, QClass qclass, vector<DNSRecord>&ret, unsigned int depth)
 {
   vState state = vState::Indeterminate;
   s_queries++;
@@ -179,7 +179,7 @@ int SyncRes::beginResolve(const DNSName &qname, const QType qtype, uint16_t qcla
  * - 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, const QType qtype, const QClass 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."),
@@ -4313,7 +4313,7 @@ void SyncRes::parseEDNSSubnetAddFor(const std::string& subnetlist)
 }
 
 // used by PowerDNSLua - note that this neglects to add the packet count & statistics back to pdns_ercursor.cc
-int directResolve(const DNSName& qname, const QType qtype, int qclass, vector<DNSRecord>& ret)
+int directResolve(const DNSName& qname, const QType qtype, const QClass qclass, vector<DNSRecord>& ret)
 {
   struct timeval now;
   gettimeofday(&now, 0);
index 1afc73c5675f596d86849f353c13e5b6796b451d..1a32e196f847b95cde287a7a5e495717be71f113 100644 (file)
@@ -602,7 +602,7 @@ public:
 
   explicit SyncRes(const struct timeval& now);
 
-  int beginResolve(const DNSName &qname, QType qtype, uint16_t qclass, vector<DNSRecord>&ret, unsigned int depth = 0);
+  int beginResolve(const DNSName &qname, QType qtype, QClass qclass, vector<DNSRecord>&ret, unsigned int depth = 0);
 
   void setId(int id)
   {
@@ -866,7 +866,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, bool& negIndicHasSignatures, unsigned int depth);
 
-  bool doSpecialNamesResolve(const DNSName &qname, QType qtype, const uint16_t qclass, vector<DNSRecord> &ret);
+  bool doSpecialNamesResolve(const DNSName &qname, QType qtype, const QClass 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;
 
@@ -1123,7 +1123,7 @@ typedef boost::function<void*(void)> pipefunc_t;
 void broadcastFunction(const pipefunc_t& func);
 void distributeAsyncFunction(const std::string& question, const pipefunc_t& func);
 
-int directResolve(const DNSName& qname, const QType qtype, int qclass, vector<DNSRecord>& ret);
+int directResolve(const DNSName& qname, const QType qtype, const QClass qclass, vector<DNSRecord>& ret);
 int followCNAMERecords(std::vector<DNSRecord>& ret, const QType qtype, int oldret);
 int getFakeAAAARecords(const DNSName& qname, ComboAddress prefix, vector<DNSRecord>& ret);
 int getFakePTRRecords(const DNSName& qname, vector<DNSRecord>& ret);