/*
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 as
cleanup();
}
-
if(d_doRecursion && p->d.rd) { // wants recursion
if(!d_recursivettl) {
(*d_statnummiss)++;
return 0;
}
- haveSomething=getEntryLocked(p->qdomain, p->qtype, PacketCache::PACKETCACHE, value, -1, packetMeritsRecursion, p->getMaxReplyLen());
+ haveSomething=getEntryLocked(p->qdomain, p->qtype, PacketCache::PACKETCACHE, value, -1, packetMeritsRecursion, p->getMaxReplyLen(), p->d_dnssecOk);
}
if(haveSomething) {
(*d_statnumhit)++;
bool packetMeritsRecursion=d_doRecursion && q->d.rd;
insert(q->qdomain, q->qtype, PacketCache::PACKETCACHE, r->getString(), packetMeritsRecursion ? d_recursivettl : d_ttl, -1, packetMeritsRecursion,
- q->getMaxReplyLen());
+ q->getMaxReplyLen(), q->d_dnssecOk);
}
// 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, unsigned int maxReplyLen)
+ bool meritsRecursion, unsigned int maxReplyLen, bool dnssecOk)
{
if(!((d_ops++) % 300000)) {
cleanup();
val.ctype=cet;
val.meritsRecursion=meritsRecursion;
val.maxReplyLen = maxReplyLen;
-
+ val.dnssecOk = dnssecOk;
+
TryWriteLock l(&d_mut);
if(l.gotIt()) {
bool success;
*d_statnumentries=d_map.size();
return delcount;
}
-
+// called from ueberbackend
bool PacketCache::getEntry(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion,
- unsigned int maxReplyLen)
+ unsigned int maxReplyLen, bool dnssecOk)
{
if(d_ttl<0)
getTTLS();
S.inc( "deferred-cache-lookup");
return false;
}
- return getEntryLocked(qname, qtype, cet, value, zoneID, meritsRecursion, maxReplyLen);
+
+ return getEntryLocked(qname, qtype, cet, value, zoneID, meritsRecursion, maxReplyLen, dnssecOk);
}
+
bool PacketCache::getEntryLocked(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion,
- unsigned int maxReplyLen)
+ unsigned int maxReplyLen, bool dnssecOK)
{
-
uint16_t qt = qtype.getCode();
- cmap_t::const_iterator i=d_map.find(tie(qname, qt, cet, zoneID, meritsRecursion, maxReplyLen));
+ cmap_t::const_iterator i=d_map.find(tie(qname, qt, cet, zoneID, meritsRecursion, maxReplyLen, dnssecOK));
time_t now=time(0);
bool ret=(i!=d_map.end() && i->ttd > now);
if(ret)
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,
- unsigned int maxReplyLen=512);
+ unsigned int maxReplyLen=512, bool dnssecOk=false);
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, unsigned int maxReplyLen=512);
+ bool meritsRecursion=false, unsigned int maxReplyLen=512, bool dnssecOk=false);
int size(); //!< number of entries in the cache
void cleanup(); //!< force the cache to preen itself from expired packets
map<char,int> getCounts();
private:
bool getEntryLocked(const string &content, const QType& qtype, CacheEntryType cet, string& entry, int zoneID=-1,
- bool meritsRecursion=false, unsigned int maxReplyLen=512);
+ bool meritsRecursion=false, unsigned int maxReplyLen=512, bool dnssecOk=false);
struct CacheEntry
{
- CacheEntry() { qtype = ctype = 0; zoneID = -1; meritsRecursion=false;}
+ CacheEntry() { qtype = ctype = 0; zoneID = -1; meritsRecursion=false; dnssecOk=false;}
string qname;
uint16_t qtype;
time_t ttd;
bool meritsRecursion;
unsigned int maxReplyLen;
+ bool dnssecOk;
string value;
};
member<CacheEntry,uint16_t, &CacheEntry::ctype>,
member<CacheEntry,int, &CacheEntry::zoneID>,
member<CacheEntry,bool, &CacheEntry::meritsRecursion>,
- member<CacheEntry,unsigned int, &CacheEntry::maxReplyLen>
+ member<CacheEntry,unsigned int, &CacheEntry::maxReplyLen>,
+ member<CacheEntry,bool, &CacheEntry::dnssecOk>
>,
composite_key_compare<CIBackwardsStringCompare, std::less<uint16_t>, std::less<uint16_t>, std::less<int>, std::less<bool>,
- std::less<unsigned int> >
+ std::less<unsigned int>, std::less<bool> >
>,
sequenced<>
>