From: bert hubert Date: Mon, 18 Apr 2016 11:05:25 +0000 (+0200) Subject: implement an official pretty ordering for DNSRecords and use it X-Git-Tag: dnsdist-1.0.0~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23721d33a5f89fd3b0062285a1d8b79f30aa0362;p=thirdparty%2Fpdns.git implement an official pretty ordering for DNSRecords and use it --- diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index baf3a82a71..a0d6a727ac 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -286,6 +286,33 @@ struct DNSRecord return lzrp < rzrp; } + // this orders in canonical order and keeps the SOA record on top + static bool prettyCompare(const DNSRecord& a, const DNSRecord& b) + { + auto aType = (a.d_type == QType::SOA) ? 0 : a.d_type; + auto bType = (b.d_type == QType::SOA) ? 0 : b.d_type; + + if(a.d_name.canonCompare(b.d_name)) + return true; + if(b.d_name.canonCompare(a.d_name)) + return false; + + if(tie(aType, a.d_class, a.d_ttl) < tie(bType, b.d_class, b.d_ttl)) + return true; + + if(tie(aType, a.d_class, a.d_ttl) != tie(bType, b.d_class, b.d_ttl)) + return false; + + string lzrp, rzrp; + if(a.d_content) + lzrp=toLower(a.d_content->getZoneRepresentation()); + if(b.d_content) + rzrp=toLower(b.d_content->getZoneRepresentation()); + + return lzrp < rzrp; + } + + bool operator==(const DNSRecord& rhs) const { string lzrp, rzrp; diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index b664268918..98a9819722 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -923,16 +923,6 @@ int clearZone(DNSSECKeeper& dk, const DNSName &zone) { return EXIT_SUCCESS; } -bool prettyDROrder(const DNSRecord& a, const DNSRecord& b) -{ - if(a.d_type == QType::SOA && b.d_type != QType::SOA) - return true; - if(a.d_type != QType::SOA && b.d_type == QType::SOA) - return false; - - return agetZoneRepresentation(true)< diff; map, string> changed; - set_difference(pre.cbegin(), pre.cend(), post.cbegin(), post.cend(), back_inserter(diff), prettyDROrder); + set_difference(pre.cbegin(), pre.cend(), post.cbegin(), post.cend(), back_inserter(diff), DNSRecord::prettyCompare); for(const auto& d : diff) { ostringstream str; str<<'-'<< d.d_name <<" "<getZoneRepresentation(true)<