From: Remi Gacogne Date: Fri, 12 May 2023 10:53:00 +0000 (+0200) Subject: Clarify which types are supported, implemented, meta, etc X-Git-Tag: dnsdist-1.8.1~5^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a589270957379a4e67a332d09557f8cb4be558d;p=thirdparty%2Fpdns.git Clarify which types are supported, implemented, meta, etc (cherry picked from commit 2e63e431478aa4ffbc59b1e821ad755f2b12db9c) --- diff --git a/pdns/backends/gsql/gsqlbackend.cc b/pdns/backends/gsql/gsqlbackend.cc index ead6243d68..4143f99dfe 100644 --- a/pdns/backends/gsql/gsqlbackend.cc +++ b/pdns/backends/gsql/gsqlbackend.cc @@ -2156,7 +2156,7 @@ void GSQLBackend::extractRecord(SSqlStatement::row_t& row, DNSResourceRecord& r) r.qtype=row[3]; - if (d_upgradeContent && DNSRecordContent::isUnknownType(row[3]) && r.qtype.isSupportedType()) { + if (d_upgradeContent && DNSRecordContent::isUnknownType(row[3]) && r.qtype.isSupportedType() && !r.qtype.isMetadataType() && DNSRecordContent::isRegisteredType(r.qtype, r.qclass) && r.qtype != QType::NSEC && r.qtype != QType::NSEC3 && r.qtype != QType::ANY) { r.content = DNSRecordContent::upgradeContent(r.qname, r.qtype, row[0]); } else if (r.qtype==QType::MX || r.qtype==QType::SRV) { diff --git a/pdns/dnsparser.cc b/pdns/dnsparser.cc index 7f755793ce..b7c6a9bbe7 100644 --- a/pdns/dnsparser.cc +++ b/pdns/dnsparser.cc @@ -195,6 +195,11 @@ DNSRecordContent::zmakermap_t& DNSRecordContent::getZmakermap() return zmakermap; } +bool DNSRecordContent::isRegisteredType(uint16_t rtype, uint16_t rclass) +{ + return getTypemap().count(pair(rclass, rtype)) != 0; +} + DNSRecord::DNSRecord(const DNSResourceRecord& rr): d_name(rr.qname) { d_type = rr.qtype.getCode(); diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index 4b22a7ac7c..014087ef35 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -268,7 +268,7 @@ public: throw runtime_error("Unknown DNS type '"+name+"'"); } - static const string NumberToType(uint16_t num, uint16_t classnum=1) + static const string NumberToType(uint16_t num, uint16_t classnum = QClass::IN) { auto iter = getT2Namemap().find(pair(classnum, num)); if(iter == getT2Namemap().end()) @@ -277,6 +277,11 @@ public: return iter->second; } + /** + * \brief Return whether we have implemented a content representation for this type + */ + static bool isRegisteredType(uint16_t rtype, uint16_t rclass = QClass::IN); + virtual uint16_t getType() const = 0; protected: diff --git a/pdns/qtype.cc b/pdns/qtype.cc index f8069f8696..a0d5732cd1 100644 --- a/pdns/qtype.cc +++ b/pdns/qtype.cc @@ -119,13 +119,10 @@ bool QType::isSupportedType() const bool QType::isMetadataType() const { - if (code == QType::AXFR || - code == QType::MAILA || - code == QType::MAILB || - code == QType::TSIG || - code == QType::IXFR) + // rfc6895 section 3.1, note ANY is 255 and falls outside the range + if (code == QType::OPT || (code >= rfc6895MetaLowerBound && code <= rfc6895MetaUpperBound)) { return true; - + } return false; } diff --git a/pdns/qtype.hh b/pdns/qtype.hh index e66dbefff5..f5a879bef8 100644 --- a/pdns/qtype.hh +++ b/pdns/qtype.hh @@ -57,7 +57,18 @@ public: return code; } + /** + * \brief Return whether we know the name of this type. + * + * This does not presume that we have an implemented a content representation for this type, + * for that please see DNSRecordContent::isRegisteredType(). + */ bool isSupportedType() const; + /** + * \brief Whether the type is either a QTYPE or Meta-Type as defined by rfc6895 section 3.1. + * + * Note that ANY is 255 and falls outside the range. + */ bool isMetadataType() const; static uint16_t chartocode(const char* p); diff --git a/pdns/rfc2136handler.cc b/pdns/rfc2136handler.cc index ceeb2d3c6f..2f993bfa4a 100644 --- a/pdns/rfc2136handler.cc +++ b/pdns/rfc2136handler.cc @@ -68,25 +68,31 @@ int PacketHandler::checkUpdatePrerequisites(const DNSRecord *rr, DomainInfo *di) // Method implements section 3.4.1 of RFC2136 int PacketHandler::checkUpdatePrescan(const DNSRecord *rr) { // The RFC stats that d_class != ZCLASS, but we only support the IN class. - if (rr->d_class != QClass::IN && rr->d_class != QClass::NONE && rr->d_class != QClass::ANY) + if (rr->d_class != QClass::IN && rr->d_class != QClass::NONE && rr->d_class != QClass::ANY) { return RCode::FormErr; + } QType qtype = QType(rr->d_type); - if (! qtype.isSupportedType()) + if (!qtype.isSupportedType()) { return RCode::FormErr; + } - if ((rr->d_class == QClass::NONE || rr->d_class == QClass::ANY) && rr->d_ttl != 0) + if ((rr->d_class == QClass::NONE || rr->d_class == QClass::ANY) && rr->d_ttl != 0) { return RCode::FormErr; + } - if (rr->d_class == QClass::ANY && rr->d_clen != 0) + if (rr->d_class == QClass::ANY && rr->d_clen != 0) { return RCode::FormErr; + } - if (qtype.isMetadataType()) - return RCode::FormErr; + if (qtype.isMetadataType()) { + return RCode::FormErr; + } - if (rr->d_class != QClass::ANY && qtype.getCode() == QType::ANY) + if (rr->d_class != QClass::ANY && qtype.getCode() == QType::ANY) { return RCode::FormErr; + } return RCode::NoError; }