From: Bert Hubert Date: Fri, 7 Jan 2011 20:33:04 +0000 (+0000) Subject: remove old 'guillotine' truncate functionality which should've been disabled a long... X-Git-Tag: auth-3.0~417 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cf00d8d34d1e1e41b207c93b81757de489406861;p=pdns remove old 'guillotine' truncate functionality which should've been disabled a long time ago 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 --- diff --git a/pdns/dbdnsseckeeper.cc b/pdns/dbdnsseckeeper.cc index 7e47cc4c4..fcf21ce49 100644 --- a/pdns/dbdnsseckeeper.cc +++ b/pdns/dbdnsseckeeper.cc @@ -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, pos->qtype.getCode(), pos->ttl, pos->qclass, (DNSPacketWriter::Place)pos->d_place); drc->toPacket(pw); - - if(!d_tcp && pw.size() + 20 > getMaxReplyLen()) { - cerr<<"Truncating!"< getMaxReplyLen()) { // XXX FIXME, 20? what does it mean? pw.rollback(); if(pos->d_place == DNSResourceRecord::ANSWER) { - cerr<<"Set TC bit"<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< getAPRecords(); //!< get a vector with DNSResourceRecords that need additional processing vector getAnswerRecords(); //!< get a vector with DNSResourceRecords that are answers diff --git a/pdns/packetcache.cc b/pdns/packetcache.cc index e57a3d903..0140d135c 100644 --- a/pdns/packetcache.cc +++ b/pdns/packetcache.cc @@ -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 &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) diff --git a/pdns/packetcache.hh b/pdns/packetcache.hh index 3d3843f04..1c44306ef 100644 --- a/pdns/packetcache.hh +++ b/pdns/packetcache.hh @@ -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 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, member, - member, - member, - member - >, - composite_key_compare, std::less, std::less, std::less > - >, - sequenced<> - > + member, + member, + member, + member + >, + composite_key_compare, std::less, std::less, std::less, + std::less > + >, + sequenced<> + > > cmap_t; diff --git a/pdns/packethandler.cc b/pdns/packethandler.cc index 15c7d4441..906070de4 100644 --- a/pdns/packethandler.cc +++ b/pdns/packethandler.cc @@ -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: '"<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='"<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) {