]> granicus.if.org Git - pdns/commitdiff
make packet- and querycache honour TTLs from backend data. Based on a patch by Ruben...
authorPeter van Dijk <peter.van.dijk@netherlabs.nl>
Fri, 17 Feb 2012 11:31:17 +0000 (11:31 +0000)
committerPeter van Dijk <peter.van.dijk@netherlabs.nl>
Fri, 17 Feb 2012 11:31:17 +0000 (11:31 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2414 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/dnspacket.cc
pdns/dnspacket.hh
pdns/docs/pdns.xml
pdns/packetcache.cc
pdns/packetcache.hh
pdns/packethandler.cc
pdns/ueberbackend.cc

index 69c4790520da7805f4ce5dc0874aa30d26bc654e..93a2952fc8e4431bf208b5f14a3849a40ae84ddb 100644 (file)
@@ -227,6 +227,17 @@ bool DNSPacket::couldBeCached()
   return d_ednsping.empty() && !d_wantsnsid && qclass==QClass::IN;
 }
 
+unsigned int DNSPacket::getMinTTL()
+{
+  unsigned int minttl = UINT_MAX;
+  BOOST_FOREACH(DNSResourceRecord rr, d_rrs) {
+  if (rr.ttl < minttl)
+      minttl = rr.ttl;
+  }
+
+  return minttl;
+}
+
 /** Must be called before attempting to access getData(). This function stuffs all resource
  *  records found in rrs into the data buffer. It also frees resource records queued for us.
  */
index 87394711a821756a936446b435a5cce29cd9ba8b..3789dc27a49118d6c5cc1eb25f469a558dcd807d 100644 (file)
@@ -122,6 +122,7 @@ public:
   DTime d_dt; //!< the time this packet was created. replyPacket() copies this in for you, so d_dt becomes the time spent processing the question+answer
   void wrapup();  // writes out queued rrs, and generates the binary packet. also shuffles. also rectifies dnsheader 'd', and copies it to the stringbuffer
   void spoofQuestion(const string &qd); //!< paste in the exact right case of the question. Useful for PacketCache
+  unsigned int getMinTTL(); //!< returns lowest TTL of any record in the packet
 
   vector<DNSResourceRecord*> getAPRecords(); //!< get a vector with DNSResourceRecords that need additional processing
   vector<DNSResourceRecord*> getAnswerRecords(); //!< get a vector with DNSResourceRecords that are answers
index dc2baae39a574268fd44d99920a7eec07237d7ee..ffdfffe530f4bcccea0e774f3c459a58d613e65d 100644 (file)
       <para>
        Improvements:
        <itemizedlist>
+         <listitem>
+           <para>
+             The packet- and querycache now honour TTLs from backend data. Code in c2414.
+           </para>
+         </listitem>
          <listitem>
            <para>
              'pdns_control help' now shows useful usage information. Code in c2410.
-         </para>
+           </para>
          </listitem>
          <listitem>
            <para>
index 79b1b43ec34c5633d5da70a9e98a53b06c2898f5..851a6e6a8736ba1f5a7650ea8beeaa37adc66fd3 100644 (file)
@@ -110,7 +110,7 @@ void PacketCache::getTTLS()
 }
 
 
-void PacketCache::insert(DNSPacket *q, DNSPacket *r)
+void PacketCache::insert(DNSPacket *q, DNSPacket *r, unsigned int maxttl)
 {
   if(d_ttl < 0)
     getTTLS();
@@ -124,7 +124,10 @@ void PacketCache::insert(DNSPacket *q, DNSPacket *r)
 
   bool packetMeritsRecursion=d_doRecursion && q->d.rd;
   uint16_t maxReplyLen = q->d_tcp ? 0xffff : q->getMaxReplyLen();
-  insert(q->qdomain, q->qtype, PacketCache::PACKETCACHE, r->getString(), packetMeritsRecursion ? d_recursivettl : d_ttl, -1, packetMeritsRecursion, 
+  int ourttl = packetMeritsRecursion ? d_recursivettl : d_ttl;
+  if(maxttl<ourttl)
+    ourttl=maxttl;
+  insert(q->qdomain, q->qtype, PacketCache::PACKETCACHE, r->getString(), ourttl, -1, packetMeritsRecursion,
     maxReplyLen, q->d_dnssecOk);
 }
 
index 4a748b2df3725660acdcb54c4310955e7d002c64..0d5b179e2328421a406668007f4c47dc541f4bd8 100644 (file)
@@ -69,7 +69,7 @@ public:
   ~PacketCache();
   enum CacheEntryType { PACKETCACHE, QUERYCACHE};
 
-  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(DNSPacket *q, DNSPacket *r, unsigned int maxttl=UINT_MAX);  //!< 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,
     unsigned int maxReplyLen=512, bool dnssecOk=false);
index 42b05801229951888cc7bdc3d0d55b7627fbd960..9f80e7cae9aca924bbde17bd7aecf1f0a0188def 100644 (file)
@@ -1407,7 +1407,7 @@ DNSPacket *PacketHandler::questionOrRecurse(DNSPacket *p, bool *shouldRecurse)
       
     r->wrapup(); // needed for inserting in cache
     if(!noCache)
-      PC.insert(p, r); // in the packet cache
+      PC.insert(p, r, r->getMinTTL()); // in the packet cache
   }
   catch(DBException &e) {
     L<<Logger::Error<<"Database module reported condition which prevented lookup ("+e.reason+") sending out servfail"<<endl;
index b8c14e395813322074829957ddeebdbc42fc954d..1b81dfdd2290fa48eacdf9a69deccad783820dd3 100644 (file)
@@ -358,6 +358,11 @@ void UeberBackend::addCache(const Question &q, const vector<DNSResourceRecord> &
   //  L<<Logger::Warning<<"inserting: "<<q.qname+"|N|"+q.qtype.getName()+"|"+itoa(q.zoneId)<<endl;
   std::ostringstream ostr;
   boost::archive::binary_oarchive boa(ostr, boost::archive::no_header);
+
+  BOOST_FOREACH(DNSResourceRecord rr, rrs) {
+    if (rr.ttl < queryttl)
+      queryttl = rr.ttl;
+  }
   
   boa << rrs;
   PC.insert(q.qname, q.qtype, PacketCache::QUERYCACHE, ostr.str(), queryttl, q.zoneId);