]> granicus.if.org Git - pdns/commitdiff
more work
authorBert Hubert <bert.hubert@netherlabs.nl>
Mon, 13 Jan 2003 22:36:34 +0000 (22:36 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Mon, 13 Jan 2003 22:36:34 +0000 (22:36 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@129 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/pdns_recursor.cc
pdns/syncres.cc

index bee6b9469d67a8c9122dc9da4c74bd8eca448dd3..da8840dfae0475b4cfad7f5c8119d7fca48bb5b5 100644 (file)
@@ -17,7 +17,6 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
  
-
 #include <iostream>
 #include <errno.h>
 #include <map>
@@ -100,14 +99,17 @@ int arecvfrom(char *data, int len, int flags, struct sockaddr *toaddr, socklen_t
 
 typedef map<string,set<DNSResourceRecord> > cache_t;
 cache_t cache;
+int cacheHits, cacheMisses;
 int getCache(const string &qname, const QType& qt, set<DNSResourceRecord>* res)
 {
   cache_t::const_iterator j=cache.find(toLower(qname)+"|"+qt.getName());
   if(j!=cache.end() && j->first==toLower(qname)+"|"+qt.getName() && j->second.begin()->ttl>(unsigned int)time(0)) {
     if(res)
       *res=j->second;
+    cacheHits++;
     return (unsigned int)j->second.begin()->ttl-time(0);
   }
+  cacheMisses++;
   return -1;
 }
 
@@ -295,6 +297,7 @@ int main(int argc, char **argv)
     
     PacketID pident;
     init();    
+    int counter=0;
     for(;;) {
       while(MT.schedule()); // housekeeping, let threads do their thing
       
@@ -360,6 +363,9 @@ int main(int argc, char **argv)
          else {
            cout<<"new question arrived for '"<<P.qdomain<<"|"<<P.qtype.getName()<<"' from "<<P.getRemote()<<endl;
            MT.makeThread(startDoResolve,(void*)new DNSPacket(P));
+           if(!((counter++)%100)) {
+             cout<<"stats: "<<counter<<" questions, "<<cache.size()<<" cache entries, "<<(cacheHits*100.0)/(cacheHits+cacheMisses)<<"% cache hits"<<endl;
+           }
          }
        }
       }
index cd0b7c0f1a479bc2dae650649311a8b170f34e8a..b3a4c2b52eb919bc86a9a49ec90c41cd839f7412 100644 (file)
@@ -141,6 +141,12 @@ template<class MultiPlexor>string SyncRes<MultiPlexor>::getBestNSNamesFromCache(
 
 template<class MultiPlexor>bool SyncRes<MultiPlexor>::doCNAMECacheCheck(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, int depth, int &res)
 {
+  if(depth>10) {
+    cout<<prefix<<qname<<": CNAME loop too deep, depth="<<depth<<endl;
+    res=RCode::ServFail;
+    return true;
+  }
+    
   string prefix, tuple=toLower(qname)+"|CNAME";
   prefix.assign(3*depth, ' ');
 
@@ -322,7 +328,7 @@ template<class MultiPlexor>int SyncRes<MultiPlexor>::doResolveAt(set<string> nam
       cout<<prefix<<qname<<": determining status after receiving this packet"<<endl;
 
       bool done=false, realreferral=false, negindic=false;
-      string newauth, soaname;
+      string newauth, soaname, newtarget;
 
       for(LWRes::res_t::const_iterator i=result.begin();i!=result.end();++i) {
        if(i->d_place==DNSResourceRecord::AUTHORITY && endsOn(qname,i->qname) && i->qtype.getCode()==QType::SOA) {
@@ -332,10 +338,8 @@ template<class MultiPlexor>int SyncRes<MultiPlexor>::doResolveAt(set<string> nam
          negindic=true;
        }
        else if(i->d_place==DNSResourceRecord::ANSWER && i->qname==qname && i->qtype.getCode()==QType::CNAME && (!(qtype==QType(QType::CNAME)))) {
-         cout<<prefix<<qname<<": got a CNAME referral, starting over with "<<i->content<<endl<<endl;
          ret.push_back(*i);
-         set<GetBestNSAnswer>beenthere2;
-         return doResolve(i->content, qtype, ret,0,beenthere2);
+         newtarget=i->content;
        }
        // for ANY answers we *must* have an authoritive answer
        else if(i->d_place==DNSResourceRecord::ANSWER && i->qname==qname && (i->qtype==qtype || ( qtype==QType(QType::ANY) && aabit)))  {
@@ -367,6 +371,11 @@ template<class MultiPlexor>int SyncRes<MultiPlexor>::doResolveAt(set<string> nam
        cout<<prefix<<qname<<": status=noerror, other types may exist, but we are done "<<(negindic ? "(have negative SOA)" : "")<<endl;
        return 0;
       }
+      if(!newtarget.empty()) {
+       cout<<prefix<<qname<<": status=got a CNAME referral, starting over with "<<newtarget<<endl<<endl;
+       set<GetBestNSAnswer>beenthere2;
+       return doResolve(newtarget, qtype, ret,0,beenthere2);
+      }
       else if(realreferral) {
        cout<<prefix<<qname<<": status=did not resolve, got "<<nsset.size()<<" NS, looping to them"<<endl;
        auth=newauth;