From de8380380926152cc023795f37da283f741a4de3 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Wed, 31 Aug 2016 14:11:15 +0200 Subject: [PATCH] Add getZoneCuts() function --- pdns/validate.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pdns/validate.cc b/pdns/validate.cc index 62242de2a..534844c04 100644 --- a/pdns/validate.cc +++ b/pdns/validate.cc @@ -79,6 +79,38 @@ static dState getDenial(cspmap_t &validrrsets, DNSName qname, uint16_t qtype) return ret; } +/* + * Finds all the zone-cuts between begin (longest name) and end (shortest name), + * returns them all zone cuts, including end, but (possibly) not begin + */ +vector getZoneCuts(const DNSName& begin, const DNSName& end, DNSRecordOracle& dro) +{ + vector ret; + if(!begin.isPartOf(end)) + throw PDNSException(end.toLogString() + "is not part of " + begin.toString()); + + DNSName qname(end); + vector labelsToAdd = begin.makeRelative(end).getRawLabels(); + + // The shortest name is assumed to a zone cut + ret.push_back(qname); + while(qname != begin) { + qname = DNSName(labelsToAdd.back()) + qname; + labelsToAdd.pop_back(); + bool foundCut = false; + auto records = dro.get(qname, (uint16_t)QType::NS); + for (const auto record : records) { + if(record.d_name != qname || record.d_type != QType::NS) + continue; + foundCut = true; + break; + } + if (foundCut) + ret.push_back(qname); + } + return ret; +} + void validateWithKeySet(const cspmap_t& rrsets, cspmap_t& validated, const keyset_t& keys) { validated.clear(); -- 2.40.0