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 {
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;
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));
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
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)++;
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();
val.value=value;
val.ctype=cet;
val.meritsRecursion=meritsRecursion;
+ val.maxReplyLen = maxReplyLen;
TryWriteLock l(&d_mut);
if(l.gotIt()) {
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();
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)
/*
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
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
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;}
int zoneID;
time_t ttd;
bool meritsRecursion;
+ unsigned int maxReplyLen;
string value;
};
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;
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
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)));
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)));
// 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) {