]> granicus.if.org Git - pdns/commitdiff
teach recursor to shuffle, by moving shuffle logic away from dnspacket.cc and into...
authorBert Hubert <bert.hubert@netherlabs.nl>
Thu, 2 Mar 2006 20:19:03 +0000 (20:19 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Thu, 2 Mar 2006 20:19:03 +0000 (20:19 +0000)
silence an incorrect warning in dnspacket.cc
This closes ticket #54

git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@567 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/Makefile.am
pdns/dnspacket.cc
pdns/misc.cc
pdns/misc.hh
pdns/pdns_recursor.cc

index a20fb7f5814d2106d5c578556edb8c4962d16c91..ba4c11c10140e2d29d3522776a9f1e1d7e6afffe 100644 (file)
@@ -91,14 +91,16 @@ pdns_recursor_SOURCES=syncres.cc resolver.hh misc.cc unix_utility.cc qtype.cc \
 logger.cc statbag.cc dnspacket.cc arguments.cc  lwres.cc pdns_recursor.cc lwres.hh \
 mtasker.hh sillyrecords.cc syncres.hh recursor_cache.cc recursor_cache.hh dnsparser.cc \
 dnswriter.cc dnswriter.hh dnsrecords.cc dnsrecords.hh rcpgenerator.cc rcpgenerator.hh \
-base64.cc base64.hh zoneparser-tng.cc zoneparser-tng.hh
+base64.cc base64.hh zoneparser-tng.cc zoneparser-tng.hh 
 
 #../modules/gmysqlbackend/smysql.cc 
 
 pdns_recursor_LDFLAGS=
 pdns_recursor_LDADD=
 
-pdns_control_SOURCES=dynloader.cc dynmessenger.cc  arguments.cc logger.cc statbag.cc misc.cc unix_utility.cc
+pdns_control_SOURCES=dynloader.cc dynmessenger.cc  arguments.cc logger.cc statbag.cc \
+misc.cc unix_utility.cc qtype.cc
+
 pdns_control_INCLUDES=path.hh
 pdns_control_LDFLAGS=@THREADFLAGS@
 
index 3ec0499dd0c941f6c77d5d8d20bf5a0aa5523944..1023c2d32a12dec1e693f391d41e10fe76953714 100644 (file)
@@ -544,7 +544,7 @@ void DNSPacket::addSOARecord(const string &domain, const string & content, uint3
   
   uint32_t *i_p=(uint32_t *)piece5;
   
-  uint32_t soaoffset;
+  uint32_t soaoffset=0;
   if(soadata.serial && (soaoffset=arg().asNum("soa-serial-offset")))
     if(soadata.serial<soaoffset)
       soadata.serial+=soaoffset; // thank you DENIC
@@ -991,28 +991,7 @@ void DNSPacket::wrapup(void)
   stable_sort(rrs.begin(),rrs.end(),rrcomp);
 
   if(!d_tcp && !arg().mustDo("no-shuffle")) {
-    // now shuffle! start out with the ANSWER records  
-    vector<DNSResourceRecord>::iterator first, second;
-    for(first=rrs.begin();first!=rrs.end();++first) 
-      if(first->d_place==DNSResourceRecord::ANSWER && first->qtype.getCode() != QType::CNAME) // CNAME must come first
-       break;
-    for(second=first;second!=rrs.end();++second)
-      if(second->d_place!=DNSResourceRecord::ANSWER)
-       break;
-    
-    if(second-first>1)
-      random_shuffle(first,second);
-    
-    // now shuffle the additional records
-    for(first=second;first!=rrs.end();++first) 
-      if(first->d_place==DNSResourceRecord::ADDITIONAL && first->qtype.getCode() != QType::CNAME) // CNAME must come first
-       break;
-    for(second=first;second!=rrs.end();++second)
-      if(second->d_place!=DNSResourceRecord::ADDITIONAL)
-       break;
-    
-    if(second-first>1)
-      random_shuffle(first,second);
+    shuffle(rrs);
   }
   d_wrapped=true;
 
index d3cab3fc1d496a37cb72cd46658ebd9292286262..dd7932832f915f924b35106e667e6cb6675073bd 100644 (file)
@@ -350,3 +350,31 @@ string makeHexDump(const string& str)
 }
 
 
+
+// shuffle, maintaining some semblance of order
+void shuffle(vector<DNSResourceRecord>& rrs)
+{
+  vector<DNSResourceRecord>::iterator first, second;
+  for(first=rrs.begin();first!=rrs.end();++first) 
+    if(first->d_place==DNSResourceRecord::ANSWER && first->qtype.getCode() != QType::CNAME) // CNAME must come first
+      break;
+  for(second=first;second!=rrs.end();++second)
+    if(second->d_place!=DNSResourceRecord::ANSWER)
+      break;
+  
+  if(second-first>1)
+    random_shuffle(first,second);
+  
+  // now shuffle the additional records
+  for(first=second;first!=rrs.end();++first) 
+    if(first->d_place==DNSResourceRecord::ADDITIONAL && first->qtype.getCode() != QType::CNAME) // CNAME must come first
+      break;
+  for(second=first;second!=rrs.end();++second)
+    if(second->d_place!=DNSResourceRecord::ADDITIONAL)
+      break;
+  
+  if(second-first>1)
+    random_shuffle(first,second);
+
+  // we don't shuffle the rest
+}
index 04b65f319d892769cefe5ff72d72f2aff62fcd79..12f7b2f82d37dee57ea67c58f7a2fb78b65e53f3 100644 (file)
@@ -22,7 +22,7 @@
 
 
 #include "utility.hh"
-
+#include "dns.hh"
 #ifndef WIN32
 # include <sys/time.h>
 # include <sys/types.h>
@@ -41,6 +41,8 @@
 #include <stdexcept>
 #include <string>
 #include <ctype.h>
+#include <vector>
+
 using namespace std;
 bool chopOff(string &domain);
 bool endsOn(const string &domain, const string &suffix);
@@ -228,5 +230,5 @@ inline void unixDie(const string &why)
 }
 
 string makeHexDump(const string& str);
-
+void shuffle(vector<DNSResourceRecord>& rrs);
 #endif
index 5f4b81dfddcb382fd9a32906647785293357a674..00dfefaf773a032dfc19807ccf65cff18bbbfd20 100644 (file)
@@ -266,6 +266,7 @@ void primeHints(void)
   RC.replace("", QType(QType::NS), nsset); // and stuff in the cache
 }
 
+
 void startDoResolve(void *p)
 {
   try {
@@ -305,6 +306,7 @@ void startDoResolve(void *p)
     else {
       pw.getHeader()->rcode=res;
       if(ret.size()) {
+       shuffle(ret);
        for(vector<DNSResourceRecord>::const_iterator i=ret.begin();i!=ret.end();++i) {
          pw.startRecord(i->qname, i->qtype.getCode(), i->ttl, 1, (DNSPacketWriter::Place)i->d_place);
          shared_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(i->qtype.getCode(), 1, i->content));