]> granicus.if.org Git - pdns/commitdiff
remove old 'guillotine' truncate functionality which should've been disabled a long...
authorBert Hubert <bert.hubert@netherlabs.nl>
Fri, 7 Jan 2011 20:33:04 +0000 (20:33 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Fri, 7 Jan 2011 20:33:04 +0000 (20:33 +0000)
tought the packetcache about EDNS response size
no longer cache TCP answers for UDP usage
closes ticket 200
silence some debugging

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

pdns/dbdnsseckeeper.cc
pdns/dnspacket.cc
pdns/dnspacket.hh
pdns/packetcache.cc
pdns/packetcache.hh
pdns/packethandler.cc

index 7e47cc4c406560929bfdc744f3f7fdc701f980b4..fcf21ce4958a25ab286ebf23f4be299385656c90 100644 (file)
@@ -212,7 +212,7 @@ DNSKEYRecordContent getDNSKEYFor(DNSSECKeeper& dk, const std::string& qname, boo
     exit(1);
   }
   else if(dk.haveActiveKSKFor(qname, &dpk)) {
-    cerr<<"Found a KSK for '"<<qname<<"'"<<endl;
+//    cerr<<"Found a KSK for '"<<qname<<"'"<<endl;
     *rc=dpk.d_key;
     return dpk.getDNSKEY();
   } else {
index 7df6dfbe941e4d56d2ea80bdea36984b4d54c6cf..8312ef7063c1fd24848e8c3e7fb040069018264d 100644 (file)
@@ -310,12 +310,9 @@ void DNSPacket::wrapup(DNSSECKeeper* dk)
        pw.startRecord(pos->qname, pos->qtype.getCode(), pos->ttl, pos->qclass, (DNSPacketWriter::Place)pos->d_place); 
 
         drc->toPacket(pw);
-       
-       if(!d_tcp && pw.size() + 20 > getMaxReplyLen()) {
-         cerr<<"Truncating!"<<endl;
+       if(!d_tcp && pw.size() + 20 > getMaxReplyLen()) { // XXX FIXME, 20? what does it mean?
          pw.rollback();
          if(pos->d_place == DNSResourceRecord::ANSWER) {
-           cerr<<"Set TC bit"<<endl;
            pw.getHeader()->tc=1;
          }
          goto noCommit;
@@ -344,25 +341,6 @@ void DNSPacket::wrapup(DNSSECKeeper* dk)
   len=packet.size();
 }
 
-
-/** Truncates a packet that has already been wrapup()-ed, possibly via a call to getData(). Do not call this function
-    before having done this - it will possibly break your packet, or crash your program. 
-
-    This method sets the 'TC' bit in the stringbuffer, and caps the len attributed to new_length.
-*/ 
-
-void DNSPacket::truncate(int new_length)
-{
-  if(new_length>len || !d_wrapped)
-    return;
-
-  DLOG(L<<Logger::Warning<<"Truncating a packet to "<< remote.toString() <<endl);
-
-  len=new_length;
-  stringbuffer[2]|=2; // set TC
-}
-
-
 void DNSPacket::setQuestion(int op, const string &qd, int newqtype)
 {
   memset(&d,0,sizeof(d));
index e11a876524024ec96048893222be5ce25ea04c0f..0cc1307d58733b6386cf7a2469212792bb643216 100644 (file)
@@ -123,7 +123,6 @@ public:
 
   const char *getRaw(void); //!< provides access to the raw packet, possibly on a packet that has never been 'wrapped'
   void spoofQuestion(const string &qd); //!< paste in the exact right case of the question. Useful for PacketCache
-  void truncate(int new_length); // has documentation in source
 
   vector<DNSResourceRecord*> getAPRecords(); //!< get a vector with DNSResourceRecords that need additional processing
   vector<DNSResourceRecord*> getAnswerRecords(); //!< get a vector with DNSResourceRecords that are answers
index e57a3d903f36f3c2cd29ed3dd136a4f5feb76dfe..0140d135ca9fef13a63944c9b7a2c3ccdd2e20e5 100644 (file)
@@ -85,7 +85,7 @@ int PacketCache::get(DNSPacket *p, DNSPacket *cached)
       return 0;
     }
 
-    haveSomething=getEntryLocked(p->qdomain, p->qtype, PacketCache::PACKETCACHE, value, -1, packetMeritsRecursion);
+    haveSomething=getEntryLocked(p->qdomain, p->qtype, PacketCache::PACKETCACHE, value, -1, packetMeritsRecursion, p->getMaxReplyLen());
   }
   if(haveSomething) {
     (*d_statnumhit)++;
@@ -124,11 +124,13 @@ void PacketCache::insert(DNSPacket *q, DNSPacket *r)
 
   bool packetMeritsRecursion=d_doRecursion && q->d.rd;
 
-  insert(q->qdomain, q->qtype, PacketCache::PACKETCACHE, r->getString(), packetMeritsRecursion ? d_recursivettl : d_ttl, -1, packetMeritsRecursion);
+  insert(q->qdomain, q->qtype, PacketCache::PACKETCACHE, r->getString(), packetMeritsRecursion ? d_recursivettl : d_ttl, -1, packetMeritsRecursion, 
+    q->getMaxReplyLen());
 }
 
 // universal key appears to be: qname, qtype, kind (packet, query cache), optionally zoneid, meritsRecursion
-void PacketCache::insert(const string &qname, const QType& qtype, CacheEntryType cet, const string& value, unsigned int ttl, int zoneID, bool meritsRecursion)
+void PacketCache::insert(const string &qname, const QType& qtype, CacheEntryType cet, const string& value, unsigned int ttl, int zoneID, 
+  bool meritsRecursion, unsigned int maxReplyLen)
 {
   if(!((d_ops++) % 300000)) {
     cleanup();
@@ -145,6 +147,7 @@ void PacketCache::insert(const string &qname, const QType& qtype, CacheEntryType
   val.value=value;
   val.ctype=cet;
   val.meritsRecursion=meritsRecursion;
+  val.maxReplyLen = maxReplyLen;
 
   TryWriteLock l(&d_mut);
   if(l.gotIt()) { 
@@ -248,7 +251,8 @@ int PacketCache::purge(const vector<string> &matches)
   return delcount;
 }
 
-bool PacketCache::getEntry(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion)
+bool PacketCache::getEntry(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion, 
+  unsigned int maxReplyLen)
 {
   if(d_ttl<0) 
     getTTLS();
@@ -262,14 +266,16 @@ bool PacketCache::getEntry(const string &qname, const QType& qtype, CacheEntryTy
     S.inc( "deferred-cache-lookup");
     return false;
   }
-  return getEntryLocked(qname, qtype, cet, value, zoneID, meritsRecursion);
+  return getEntryLocked(qname, qtype, cet, value, zoneID, meritsRecursion, maxReplyLen);
 }
 
-bool PacketCache::getEntryLocked(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion)
+bool PacketCache::getEntryLocked(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion,
+  unsigned int maxReplyLen)
 {
 
   uint16_t qt = qtype.getCode();
-  cmap_t::const_iterator i=d_map.find(tie(qname, qt, cet, zoneID, meritsRecursion));
+  
+  cmap_t::const_iterator i=d_map.find(tie(qname, qt, cet, zoneID, meritsRecursion, maxReplyLen));
   time_t now=time(0);
   bool ret=(i!=d_map.end() && i->ttd > now);
   if(ret)
index 3d3843f04fb0b0c1cf7f89eb90278fa9386c76dd..1c44306ef5d69c47ed7a31bb77eecff63ac9611a 100644 (file)
@@ -1,6 +1,6 @@
 /*
     PowerDNS Versatile Database Driven Nameserver
-    Copyright (C) 2002 - 2008  PowerDNS.COM BV
+    Copyright (C) 2002 - 2011  PowerDNS.COM BV
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2
@@ -71,10 +71,12 @@ public:
 
   void insert(DNSPacket *q, DNSPacket *r);  //!< We copy the contents of *p into our cache. Do not needlessly call this to insert questions already in the cache as it wastes resources
 
-  void insert(const string &qname, const QType& qtype, CacheEntryType cet, const string& value, unsigned int ttl, int zoneID=-1, bool meritsRecursion=false);
+  void insert(const string &qname, const QType& qtype, CacheEntryType cet, const string& value, unsigned int ttl, int zoneID=-1, bool meritsRecursion=false,
+    unsigned int maxReplyLen=512);
 
   int get(DNSPacket *p, DNSPacket *q); //!< We return a dynamically allocated copy out of our cache. You need to delete it. You also need to spoof in the right ID with the DNSPacket.spoofID() method.
-  bool getEntry(const string &content, const QType& qtype, CacheEntryType cet, string& entry, int zoneID=-1, bool meritsRecursion=false);
+  bool getEntry(const string &content, const QType& qtype, CacheEntryType cet, string& entry, int zoneID=-1, 
+    bool meritsRecursion=false, unsigned int maxReplyLen=512);
 
   int size(); //!< number of entries in the cache
   void cleanup(); //!< force the cache to preen itself from expired packets
@@ -82,7 +84,8 @@ public:
 
   map<char,int> getCounts();
 private:
-  bool getEntryLocked(const string &content, const QType& qtype, CacheEntryType cet, string& entry, int zoneID=-1, bool meritsRecursion=false);
+  bool getEntryLocked(const string &content, const QType& qtype, CacheEntryType cet, string& entry, int zoneID=-1, 
+    bool meritsRecursion=false, unsigned int maxReplyLen=512);
   struct CacheEntry
   {
     CacheEntry() { qtype = ctype = 0; zoneID = -1; meritsRecursion=false;}
@@ -93,6 +96,7 @@ private:
     int zoneID;
     time_t ttd;
     bool meritsRecursion;
+    unsigned int maxReplyLen;
     string value;
   };
 
@@ -106,14 +110,16 @@ private:
                         CacheEntry,
                         member<CacheEntry,string,&CacheEntry::qname>,
                         member<CacheEntry,uint16_t,&CacheEntry::qtype>,
-                       member<CacheEntry,uint16_t, &CacheEntry::ctype>,
-                       member<CacheEntry,int, &CacheEntry::zoneID>,
-                       member<CacheEntry,bool, &CacheEntry::meritsRecursion>
-                      >,
-                 composite_key_compare<CIBackwardsStringCompare, std::less<uint16_t>, std::less<uint16_t>, std::less<int>, std::less<bool> >
-                >,
-               sequenced<>
-               >
+                        member<CacheEntry,uint16_t, &CacheEntry::ctype>,
+                        member<CacheEntry,int, &CacheEntry::zoneID>,
+                        member<CacheEntry,bool, &CacheEntry::meritsRecursion>,
+                        member<CacheEntry,unsigned int, &CacheEntry::maxReplyLen>
+                        >,
+                        composite_key_compare<CIBackwardsStringCompare, std::less<uint16_t>, std::less<uint16_t>, std::less<int>, std::less<bool>, 
+                          std::less<unsigned int> >
+                            >,
+                           sequenced<>
+                           >
   > cmap_t;
 
 
index 15c7d4441353efa67d6e2b668c919ee253a4c28f..906070de402af393fdc4417dbe1fbd259b8d0ba3 100644 (file)
@@ -600,7 +600,7 @@ void PacketHandler::addNSEC3(DNSPacket *p, DNSPacket *r, const string& target, c
     cerr<<"Could not get SOA for domain in NSEC3\n";
     return;
   }
-  cerr<<"salt in ph: '"<<makeHexDump(ns3rc.d_salt)<<"', narrow="<<narrow<<endl;
+  // cerr<<"salt in ph: '"<<makeHexDump(ns3rc.d_salt)<<"', narrow="<<narrow<<endl;
   string unhashed, before,after;
 
   // now add the closest encloser
@@ -611,7 +611,6 @@ void PacketHandler::addNSEC3(DNSPacket *p, DNSPacket *r, const string& target, c
   cerr<<"Done calling for closest encloser, before='"<<before<<"', after='"<<after<<"'"<<endl;
   emitNSEC3(ns3rc, auth, unhashed, fromBase32Hex(before), fromBase32Hex(after), target, r, mode);
 
-
   // now add the main nsec3
   unhashed = p->qdomain;
   hashed=toLower(toBase32Hex(hashQNameWithSalt(ns3rc.d_iterations, ns3rc.d_salt, unhashed)));
@@ -619,7 +618,6 @@ void PacketHandler::addNSEC3(DNSPacket *p, DNSPacket *r, const string& target, c
   cerr<<"Done calling for main, before='"<<before<<"', after='"<<after<<"'"<<endl;
   emitNSEC3( ns3rc, auth, unhashed, fromBase32Hex(before), fromBase32Hex(after), target, r, mode);
   
-
   // now add the *
   unhashed=dotConcat("*", auth);
   hashed=toLower(toBase32Hex(hashQNameWithSalt(ns3rc.d_iterations, ns3rc.d_salt, unhashed)));
@@ -1345,8 +1343,8 @@ DNSPacket *PacketHandler::questionOrRecurse(DNSPacket *p, bool *shouldRecurse)
     //    doDNSSECProcessing(p, r);
 
     r->wrapup(&d_dk); // needed for inserting in cache
-    if(!noCache) {
-      PC.insert(p,r); // in the packet cache
+    if(!p->d_tcp) {
+      PC.insert(p, r); // in the packet cache
     }
   }
   catch(DBException &e) {