]> granicus.if.org Git - pdns/commitdiff
Implement a smarter dedup for filling packets in auth
authorbert hubert <bert.hubert@powerdns.com>
Tue, 12 Jun 2018 13:18:12 +0000 (15:18 +0200)
committerbert hubert <bert.hubert@powerdns.com>
Tue, 12 Jun 2018 13:18:12 +0000 (15:18 +0200)
pdns/dnspacket.cc
pdns/dnspacket.hh

index 8889a69c4b78b280d2148c437f5e0b415bd1b5ce..59ed0c067890d4827fe00336a9087791a56edcd6 100644 (file)
@@ -177,26 +177,30 @@ void DNSPacket::setOpcode(uint16_t opcode)
 void DNSPacket::clearRecords()
 {
   d_rrs.clear();
+  d_dedup.clear();
 }
 
 void DNSPacket::addRecord(const DNSZoneRecord &rr)
 {
   // this removes duplicates from the packet in case we are not compressing
   // for AXFR, no such checking is performed!
-  // cerr<<"addrecord, content=["<<rr.content<<"]"<<endl;
+
+  std::string ser;
   if(d_compress) {
-    for(auto i=d_rrs.begin();i!=d_rrs.end();++i) {
-      if(rr.dr == i->dr)  // XXX SUPER SLOW
+    ser=const_cast<DNSZoneRecord&>(rr).dr.d_content->serialize(rr.dr.d_name);
+    if(d_dedup.count({rr.dr.d_name, ser})) { // might be a dup
+      for(auto i=d_rrs.begin();i!=d_rrs.end();++i) {
+        if(rr.dr == i->dr)  // XXX SUPER SLOW
           return;
+      }
     }
   }
+  if(d_compress)
+    d_dedup.insert({rr.dr.d_name, ser});
 
-  // cerr<<"added to d_rrs"<<endl;
   d_rrs.push_back(rr);
 }
 
-
-
 vector<DNSZoneRecord*> DNSPacket::getAPRecords()
 {
   vector<DNSZoneRecord*> arrs;
index 81c1d6664c9acbab373250e6da150eb234dd27a4..3264855e4e9f9fa524eaa24dda1f63729afe821e 100644 (file)
@@ -29,7 +29,7 @@
 #include <sys/types.h>
 #include "iputils.hh"
 #include "ednssubnet.hh"
-
+#include <unordered_set>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <sys/time.h>
@@ -175,6 +175,7 @@ private:
   string d_tsigprevious;
 
   vector<DNSZoneRecord> d_rrs; // 8
+  std::unordered_set<pair<DNSName, std::string>, boost::hash< std::pair<DNSName, std::string> >  > d_dedup;
   string d_rawpacket; // this is where everything lives 8
   EDNSSubnetOpts d_eso;