Skip to content

Commit

Permalink
Merge pull request #12776 from jacobbunk/tsig-qtype
Browse files Browse the repository at this point in the history
Make DNSQType.TSIG available in dnsdist
  • Loading branch information
rgacogne committed Jul 4, 2023
2 parents 2da1dfa + bc90e72 commit 4dabc73
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pdns/backends/gsql/gsqlbackend.cc
Expand Up @@ -2158,7 +2158,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]) && DNSRecordContent::isRegisteredType(r.qtype, r.qclass)) {
r.content = DNSRecordContent::upgradeContent(r.qname, r.qtype, row[0]);
}
else if (r.qtype==QType::MX || r.qtype==QType::SRV) {
Expand Down
5 changes: 5 additions & 0 deletions pdns/dnsparser.cc
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion pdns/dnsparser.hh
Expand Up @@ -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())
Expand All @@ -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:
Expand Down
11 changes: 4 additions & 7 deletions pdns/qtype.cc
Expand Up @@ -84,7 +84,7 @@ const map<const string, uint16_t> QType::names = {
{"EUI48", 108},
{"EUI64", 109},
{"TKEY", 249},
// {"TSIG", 250},
{"TSIG", 250},
{"IXFR", 251},
{"AXFR", 252},
{"MAILB", 253},
Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 11 additions & 0 deletions pdns/qtype.hh
Expand Up @@ -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);
Expand Down
20 changes: 13 additions & 7 deletions pdns/rfc2136handler.cc
Expand Up @@ -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;
}
Expand Down

0 comments on commit 4dabc73

Please sign in to comment.