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.
*/
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
<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>
}
-void PacketCache::insert(DNSPacket *q, DNSPacket *r)
+void PacketCache::insert(DNSPacket *q, DNSPacket *r, unsigned int maxttl)
{
if(d_ttl < 0)
getTTLS();
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);
}
~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);
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;
// 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);