From: Otto Date: Tue, 30 Mar 2021 12:09:37 +0000 (+0200) Subject: Make QClass a class, including toString() method X-Git-Tag: dnsdist-1.6.0-rc1~13^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5153bf3553f3c7e99ebaac201b5c5254ba397c8a;p=thirdparty%2Fpdns.git Make QClass a class, including toString() method --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 5d8b3c959f..0a5f002c3d 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1326,8 +1326,6 @@ static void sendNODLookup(const DNSName& dname) { if (!(g_nodLookupDomain.isRoot())) { // Send a DNS A query to .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 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 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& ret) rr.d_content = std::make_shared(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; } diff --git a/pdns/qtype.cc b/pdns/qtype.cc index 7c23075b97..caaf42f454 100644 --- a/pdns/qtype.cc +++ b/pdns/qtype.cc @@ -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); + } +} diff --git a/pdns/qtype.hh b/pdns/qtype.hh index bcb02e2dd9..02c5ef57f3 100644 --- a/pdns/qtype.hh +++ b/pdns/qtype.hh @@ -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; }; diff --git a/pdns/sdig.cc b/pdns/sdig.cc index e2857f9ed7..1d25fba414 100644 --- a/pdns/sdig.cc +++ b/pdns/sdig.cc @@ -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 s_expectedIDs; @@ -71,7 +60,7 @@ static void fillPacket(vector& packet, const string& q, const string& t bool dnssec, const boost::optional 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 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; diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 6170cdac1f..55559511be 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -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&ret, unsigned int depth) +int SyncRes::beginResolve(const DNSName &qname, const QType qtype, QClass qclass, vector&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 &ret) +bool SyncRes::doSpecialNamesResolve(const DNSName &qname, const QType qtype, const QClass 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."), @@ -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& ret) +int directResolve(const DNSName& qname, const QType qtype, const QClass qclass, vector& ret) { struct timeval now; gettimeofday(&now, 0); diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 1afc73c567..1a32e196f8 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -602,7 +602,7 @@ public: explicit SyncRes(const struct timeval& now); - int beginResolve(const DNSName &qname, QType qtype, uint16_t qclass, vector&ret, unsigned int depth = 0); + int beginResolve(const DNSName &qname, QType qtype, QClass qclass, vector&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, 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); - bool doSpecialNamesResolve(const DNSName &qname, QType qtype, const uint16_t qclass, vector &ret); + bool doSpecialNamesResolve(const DNSName &qname, QType qtype, const QClass 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; @@ -1123,7 +1123,7 @@ typedef boost::function 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& ret); +int directResolve(const DNSName& qname, const QType qtype, const QClass qclass, vector& ret); int followCNAMERecords(std::vector& ret, const QType qtype, int oldret); int getFakeAAAARecords(const DNSName& qname, ComboAddress prefix, vector& ret); int getFakePTRRecords(const DNSName& qname, vector& ret);