]> granicus.if.org Git - pdns/commitdiff
dedup our AXFR signing, closing ticket 611 (plus remove duplicate ; in dnssecsigner.cc)
authorBert Hubert <bert.hubert@netherlabs.nl>
Tue, 6 Nov 2012 10:58:58 +0000 (10:58 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Tue, 6 Nov 2012 10:58:58 +0000 (10:58 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2856 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/dnssecsigner.cc
pdns/signingpipe.cc
pdns/signingpipe.hh

index 8460205046b177c439b192973aba5ba91c95e896..08c618d75c062109f76fe8f54c577139aee025c9 100644 (file)
@@ -35,7 +35,7 @@ int getRRSIGsForRRSET(DNSSECKeeper& dk, const std::string& signer, const std::st
 
   rrc.d_labels=countLabels(signQName); 
   rrc.d_originalttl=signTTL; 
-  rrc.d_siginception=getCurrentInception();;
+  rrc.d_siginception=getCurrentInception();
   rrc.d_sigexpire = rrc.d_siginception + 14*86400; // XXX should come from zone metadata
   rrc.d_signer = toLower(signer);
   rrc.d_tag = 0;
index 384ac3bfb356991f4221b5f9aa181548ec2a5bb8..7e0c1eae06981ad73ec2201be2436874ac6853fb 100644 (file)
@@ -106,16 +106,44 @@ ChunkedSigningPipe::~ChunkedSigningPipe()
   //cout<<"Did: "<<d_signed<<", records (!= chunks) submitted: "<<d_submitted<<endl;
 }
 
+namespace {
+bool dedupLessThan(const DNSResourceRecord& a, const DNSResourceRecord &b)
+{
+  if(tie(a.content, a.ttl) < tie(b.content, b.ttl))
+    return true;
+  if(a.qtype.getCode() == QType::MX || a.qtype.getCode() == QType::SRV)
+    return a.priority < b.priority;
+  return false;
+}
+
+bool dedupEqual(const DNSResourceRecord& a, const DNSResourceRecord &b)
+{
+  if(tie(a.content, a.ttl) != tie(b.content, b.ttl))
+    return false;
+  if(a.qtype.getCode() == QType::MX || a.qtype.getCode() == QType::SRV)
+    return a.priority == b.priority;
+  return true;
+}
+}
+
+void ChunkedSigningPipe::dedupRRSet()
+{
+  // our set contains contains records for one type and one name, but might not be sorted otherwise
+  sort(d_rrsetToSign->begin(), d_rrsetToSign->end(), dedupLessThan);
+  d_rrsetToSign->erase(unique(d_rrsetToSign->begin(), d_rrsetToSign->end(), dedupEqual), d_rrsetToSign->end());
+}
+
 bool ChunkedSigningPipe::submit(const DNSResourceRecord& rr)
 {
   ++d_submitted;
   // check if we have a full RRSET to sign
   if(!d_rrsetToSign->empty() && (d_rrsetToSign->begin()->qtype.getCode() != rr.qtype.getCode()  ||  !pdns_iequals(d_rrsetToSign->begin()->qname, rr.qname))) 
   {
+    dedupRRSet();
     sendRRSetToWorker();
   }
   d_rrsetToSign->push_back(rr);
-  return !d_chunks.empty() && d_chunks.front().size() >= d_maxchunkrecords;
+  return !d_chunks.empty() && d_chunks.front().size() >= d_maxchunkrecords; // "you can send more"
 }
 
 pair<vector<int>, vector<int> > ChunkedSigningPipe::waitForRW(bool rd, bool wr, int seconds)
index 043f0c72fc5ba3e6c4fdfe5a84588ea8d333b386..0a7ae49fb9b9815bbe6d543104f39aa94d37a5a5 100644 (file)
@@ -31,7 +31,7 @@ public:
   unsigned int getReady();
 private:
   void flushToSign();  
-  
+  void dedupRRSet();
   void sendRRSetToWorker(); // dispatch RRSET to worker
   void addSignedToChunks(chunk_t* signedChunk);
   pair<vector<int>, vector<int> > waitForRW(bool rd, bool wr, int seconds);