Changeset 1830

Show
Ignore:
Timestamp:
01/07/11 21:33:04 (2 years ago)
Author:
ahu
Message:

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

Location:
trunk/pdns/pdns
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/dbdnsseckeeper.cc

    r1810 r1830  
    213213  } 
    214214  else if(dk.haveActiveKSKFor(qname, &dpk)) { 
    215     cerr<<"Found a KSK for '"<<qname<<"'"<<endl; 
     215//    cerr<<"Found a KSK for '"<<qname<<"'"<<endl; 
    216216    *rc=dpk.d_key; 
    217217    return dpk.getDNSKEY(); 
  • trunk/pdns/pdns/dnspacket.cc

    r1797 r1830  
    311311 
    312312        drc->toPacket(pw); 
    313          
    314         if(!d_tcp && pw.size() + 20 > getMaxReplyLen()) { 
    315           cerr<<"Truncating!"<<endl; 
     313        if(!d_tcp && pw.size() + 20 > getMaxReplyLen()) { // XXX FIXME, 20? what does it mean? 
    316314          pw.rollback(); 
    317315          if(pos->d_place == DNSResourceRecord::ANSWER) { 
    318             cerr<<"Set TC bit"<<endl; 
    319316            pw.getHeader()->tc=1; 
    320317          } 
     
    344341  len=packet.size(); 
    345342} 
    346  
    347  
    348 /** Truncates a packet that has already been wrapup()-ed, possibly via a call to getData(). Do not call this function 
    349     before having done this - it will possibly break your packet, or crash your program.  
    350  
    351     This method sets the 'TC' bit in the stringbuffer, and caps the len attributed to new_length. 
    352 */  
    353  
    354 void DNSPacket::truncate(int new_length) 
    355 { 
    356   if(new_length>len || !d_wrapped) 
    357     return; 
    358  
    359   DLOG(L<<Logger::Warning<<"Truncating a packet to "<< remote.toString() <<endl); 
    360  
    361   len=new_length; 
    362   stringbuffer[2]|=2; // set TC 
    363 } 
    364  
    365343 
    366344void DNSPacket::setQuestion(int op, const string &qd, int newqtype) 
  • trunk/pdns/pdns/dnspacket.hh

    r1797 r1830  
    124124  const char *getRaw(void); //!< provides access to the raw packet, possibly on a packet that has never been 'wrapped' 
    125125  void spoofQuestion(const string &qd); //!< paste in the exact right case of the question. Useful for PacketCache 
    126   void truncate(int new_length); // has documentation in source 
    127126 
    128127  vector<DNSResourceRecord*> getAPRecords(); //!< get a vector with DNSResourceRecords that need additional processing 
  • trunk/pdns/pdns/packetcache.cc

    r1709 r1830  
    8686    } 
    8787 
    88     haveSomething=getEntryLocked(p->qdomain, p->qtype, PacketCache::PACKETCACHE, value, -1, packetMeritsRecursion); 
     88    haveSomething=getEntryLocked(p->qdomain, p->qtype, PacketCache::PACKETCACHE, value, -1, packetMeritsRecursion, p->getMaxReplyLen()); 
    8989  } 
    9090  if(haveSomething) { 
     
    125125  bool packetMeritsRecursion=d_doRecursion && q->d.rd; 
    126126 
    127   insert(q->qdomain, q->qtype, PacketCache::PACKETCACHE, r->getString(), packetMeritsRecursion ? d_recursivettl : d_ttl, -1, packetMeritsRecursion); 
     127  insert(q->qdomain, q->qtype, PacketCache::PACKETCACHE, r->getString(), packetMeritsRecursion ? d_recursivettl : d_ttl, -1, packetMeritsRecursion,  
     128    q->getMaxReplyLen()); 
    128129} 
    129130 
    130131// universal key appears to be: qname, qtype, kind (packet, query cache), optionally zoneid, meritsRecursion 
    131 void PacketCache::insert(const string &qname, const QType& qtype, CacheEntryType cet, const string& value, unsigned int ttl, int zoneID, bool meritsRecursion) 
     132void PacketCache::insert(const string &qname, const QType& qtype, CacheEntryType cet, const string& value, unsigned int ttl, int zoneID,  
     133  bool meritsRecursion, unsigned int maxReplyLen) 
    132134{ 
    133135  if(!((d_ops++) % 300000)) { 
     
    146148  val.ctype=cet; 
    147149  val.meritsRecursion=meritsRecursion; 
     150  val.maxReplyLen = maxReplyLen; 
    148151 
    149152  TryWriteLock l(&d_mut); 
     
    249252} 
    250253 
    251 bool PacketCache::getEntry(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion) 
     254bool PacketCache::getEntry(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion,  
     255  unsigned int maxReplyLen) 
    252256{ 
    253257  if(d_ttl<0)  
     
    263267    return false; 
    264268  } 
    265   return getEntryLocked(qname, qtype, cet, value, zoneID, meritsRecursion); 
    266 } 
    267  
    268 bool PacketCache::getEntryLocked(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion) 
     269  return getEntryLocked(qname, qtype, cet, value, zoneID, meritsRecursion, maxReplyLen); 
     270} 
     271 
     272bool PacketCache::getEntryLocked(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion, 
     273  unsigned int maxReplyLen) 
    269274{ 
    270275 
    271276  uint16_t qt = qtype.getCode(); 
    272   cmap_t::const_iterator i=d_map.find(tie(qname, qt, cet, zoneID, meritsRecursion)); 
     277   
     278  cmap_t::const_iterator i=d_map.find(tie(qname, qt, cet, zoneID, meritsRecursion, maxReplyLen)); 
    273279  time_t now=time(0); 
    274280  bool ret=(i!=d_map.end() && i->ttd > now); 
  • trunk/pdns/pdns/packetcache.hh

    r1472 r1830  
    11/* 
    22    PowerDNS Versatile Database Driven Nameserver 
    3     Copyright (C) 2002 - 2008  PowerDNS.COM BV 
     3    Copyright (C) 2002 - 2011  PowerDNS.COM BV 
    44 
    55    This program is free software; you can redistribute it and/or modify 
     
    7272  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 
    7373 
    74   void insert(const string &qname, const QType& qtype, CacheEntryType cet, const string& value, unsigned int ttl, int zoneID=-1, bool meritsRecursion=false); 
     74  void insert(const string &qname, const QType& qtype, CacheEntryType cet, const string& value, unsigned int ttl, int zoneID=-1, bool meritsRecursion=false, 
     75    unsigned int maxReplyLen=512); 
    7576 
    7677  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. 
    77   bool getEntry(const string &content, const QType& qtype, CacheEntryType cet, string& entry, int zoneID=-1, bool meritsRecursion=false); 
     78  bool getEntry(const string &content, const QType& qtype, CacheEntryType cet, string& entry, int zoneID=-1,  
     79    bool meritsRecursion=false, unsigned int maxReplyLen=512); 
    7880 
    7981  int size(); //!< number of entries in the cache 
     
    8385  map<char,int> getCounts(); 
    8486private: 
    85   bool getEntryLocked(const string &content, const QType& qtype, CacheEntryType cet, string& entry, int zoneID=-1, bool meritsRecursion=false); 
     87  bool getEntryLocked(const string &content, const QType& qtype, CacheEntryType cet, string& entry, int zoneID=-1,  
     88    bool meritsRecursion=false, unsigned int maxReplyLen=512); 
    8689  struct CacheEntry 
    8790  { 
     
    9497    time_t ttd; 
    9598    bool meritsRecursion; 
     99    unsigned int maxReplyLen; 
    96100    string value; 
    97101  }; 
     
    107111                        member<CacheEntry,string,&CacheEntry::qname>, 
    108112                        member<CacheEntry,uint16_t,&CacheEntry::qtype>, 
    109                         member<CacheEntry,uint16_t, &CacheEntry::ctype>, 
    110                         member<CacheEntry,int, &CacheEntry::zoneID>, 
    111                         member<CacheEntry,bool, &CacheEntry::meritsRecursion> 
    112                       >, 
    113                   composite_key_compare<CIBackwardsStringCompare, std::less<uint16_t>, std::less<uint16_t>, std::less<int>, std::less<bool> > 
    114                 >, 
    115                sequenced<> 
    116                > 
     113                        member<CacheEntry,uint16_t, &CacheEntry::ctype>, 
     114                        member<CacheEntry,int, &CacheEntry::zoneID>, 
     115                        member<CacheEntry,bool, &CacheEntry::meritsRecursion>, 
     116                        member<CacheEntry,unsigned int, &CacheEntry::maxReplyLen> 
     117                        >, 
     118                        composite_key_compare<CIBackwardsStringCompare, std::less<uint16_t>, std::less<uint16_t>, std::less<int>, std::less<bool>,  
     119                          std::less<unsigned int> > 
     120                            >, 
     121                           sequenced<> 
     122                           > 
    117123  > cmap_t; 
    118124 
  • trunk/pdns/pdns/packethandler.cc

    r1829 r1830  
    601601    return; 
    602602  } 
    603   cerr<<"salt in ph: '"<<makeHexDump(ns3rc.d_salt)<<"', narrow="<<narrow<<endl; 
     603  // cerr<<"salt in ph: '"<<makeHexDump(ns3rc.d_salt)<<"', narrow="<<narrow<<endl; 
    604604  string unhashed, before,after; 
    605605 
     
    611611  cerr<<"Done calling for closest encloser, before='"<<before<<"', after='"<<after<<"'"<<endl; 
    612612  emitNSEC3(ns3rc, auth, unhashed, fromBase32Hex(before), fromBase32Hex(after), target, r, mode); 
    613  
    614613 
    615614  // now add the main nsec3 
     
    620619  emitNSEC3( ns3rc, auth, unhashed, fromBase32Hex(before), fromBase32Hex(after), target, r, mode); 
    621620   
    622  
    623621  // now add the * 
    624622  unhashed=dotConcat("*", auth); 
     
    13461344 
    13471345    r->wrapup(&d_dk); // needed for inserting in cache 
    1348     if(!noCache) { 
    1349       PC.insert(p,r); // in the packet cache 
     1346    if(!p->d_tcp) { 
     1347      PC.insert(p, r); // in the packet cache 
    13501348    } 
    13511349  }