From: Pieter Lexis Date: Fri, 10 Mar 2017 15:46:47 +0000 (+0100) Subject: create a doSpecialNamesResolve function X-Git-Tag: rec-4.1.0-alpha1~174^2~19 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=db50a7f476bacb3e442f6a53febde8a72fb0a92a;p=pdns create a doSpecialNamesResolve function --- diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 2eb4c0b6e..fd6368094 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -127,60 +127,84 @@ int SyncRes::beginResolve(const DNSName &qname, const QType &qtype, uint16_t qcl d_wasVariable=false; d_wasOutOfBand=false; + if (doSpecialNamesResolve(qname, qtype, qclass, ret)) + return 0; + if( (qtype.getCode() == QType::AXFR)) return -1; - static const DNSName arpa("1.0.0.127.in-addr.arpa."), localhost("localhost."), - versionbind("version.bind."), idserver("id.server."), versionpdns("version.pdns."); + if(qclass==QClass::ANY) + qclass=QClass::IN; + else if(qclass!=QClass::IN) + return -1; - if( (qtype.getCode()==QType::PTR && qname==arpa) || - (qtype.getCode()==QType::A && qname==localhost)) { - ret.clear(); - DNSRecord dr; - dr.d_name=qname; - dr.d_place = DNSResourceRecord::ANSWER; - dr.d_type=qtype.getCode(); - dr.d_class=QClass::IN; - dr.d_ttl=86400; - if(qtype.getCode()==QType::PTR) - dr.d_content=shared_ptr(DNSRecordContent::mastermake(QType::PTR, 1, "localhost.")); + set beenthere; + int res=doResolve(qname, qtype, ret, 0, beenthere); + return res; +} + +/*! Handles all special, built-in names + * Fills ret with an answer and returns true if it handled the query. + * + * Handles the following queries: + * + * - localhost. IN A + * - localhost. IN AAAA + * - 1.0.0.127.in-addr.arpa. IN PTR + * - 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. IN PTR + * - version.bind. CH TXT + * - version.pdns. CH TXT + * - id.server. CH TXT + * + * TODO handle ANY + */ +bool SyncRes::doSpecialNamesResolve(const DNSName &qname, const 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."); + + bool handled = false; + string content; + + if (qtype.getCode()==QType::PTR && (qname==arpa || qname==ip6_arpa)) { + handled = true; + content = "localhost."; + } + + if (qname == localhost) { + handled = true; + if (qtype==QType::A) + content = "127.0.0.1"; + if (qtype==QType::AAAA) + content = "::1"; + } + + if (qclass==QClass::CHAOS && qtype==QType::TXT && (qname==versionbind || qname==idserver || qname==versionpdns)) { + handled = true; + if(qname==versionbind || qname==versionpdns) + content = "\""+::arg()["version-string"]+"\""; else - dr.d_content=shared_ptr(DNSRecordContent::mastermake(QType::A, 1, "127.0.0.1")); - ret.push_back(dr); - d_wasOutOfBand=true; - return 0; + content = "\""+s_serverID+"\""; } - if(qclass==QClass::CHAOS && qtype.getCode()==QType::TXT && - (qname==versionbind || qname==idserver || qname==versionpdns ) - ) { + if (handled && !content.empty()) { ret.clear(); + d_wasOutOfBand=true; + DNSRecord dr; - dr.d_name=qname; - dr.d_type=qtype.getCode(); - dr.d_class=qclass; - dr.d_ttl=86400; + dr.d_name = qname; dr.d_place = DNSResourceRecord::ANSWER; - if(qname==versionbind || qname==versionpdns) - dr.d_content=shared_ptr(DNSRecordContent::mastermake(QType::TXT, 3, "\""+::arg()["version-string"]+"\"")); - else - dr.d_content=shared_ptr(DNSRecordContent::mastermake(QType::TXT, 3, "\""+s_serverID+"\"")); - + dr.d_type = qtype.getCode(); + dr.d_class = qclass; + dr.d_ttl = 86400; + dr.d_content=shared_ptr(DNSRecordContent::mastermake(qtype.getCode(), qclass, content)); ret.push_back(dr); - d_wasOutOfBand=true; - return 0; } - if(qclass==QClass::ANY) - qclass=QClass::IN; - else if(qclass!=QClass::IN) - return -1; - - set beenthere; - int res=doResolve(qname, qtype, ret, 0, beenthere); - return res; + return handled; } + //! This is the 'out of band resolver', in other words, the authoritative server bool SyncRes::doOOBResolve(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, int& res) { diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 344ef145f..8ca201da8 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -539,7 +539,8 @@ private: RCode::rcodes_ updateCacheFromRecords(const std::string& prefix, LWResult& lwr, const DNSName& qname, const DNSName& auth, NsSet& nameservers, const DNSName& tns, const boost::optional); 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, bool& sawDS); -private: + bool doSpecialNamesResolve(const DNSName &qname, const QType &qtype, const uint16_t &qclass, vector &ret); + ostringstream d_trace; shared_ptr d_pdl; string d_prefix;