]> granicus.if.org Git - pdns/commitdiff
recursor work, alignment issues
authorBert Hubert <bert.hubert@netherlabs.nl>
Thu, 16 Jan 2003 17:24:36 +0000 (17:24 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Thu, 16 Jan 2003 17:24:36 +0000 (17:24 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@137 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/Makefile.am
pdns/misc.cc
pdns/misc.hh
pdns/pdns_recursor.cc
pdns/syncres.cc
pdns/syncres.hh

index 45edf65a0e93227ee6002673c8e2748520736b59..8aa16833e990120b5dc7fe8f2ff19bfa4d5e4b19 100644 (file)
@@ -35,7 +35,7 @@ backends/bind/bindbackend.cc backends/bind/zoneparser2.cc \
 backends/bind/bindparser.cc backends/bind/bindlexer.c \
 backends/bind/huffman.cc backends/gsql/gsqlbackend.cc \
 backends/gsql/gsqlbackend.hh backends/gsql/ssql.hh \
-sillyrecords.cc recbcomm.hh recbcomm.cc
+sillyrecords.cc 
 
 #
 pdns_server_LDFLAGS= @moduleobjects@ @modulelibs@ @DYNLINKFLAGS@ @LIBDL@ @THREADFLAGS@
index de5ded5b24dcaf5db8bb9cdc0079693b2efc0a58..70e671fe4d95dbd175ba424bd48b0308c316a066 100644 (file)
@@ -313,10 +313,14 @@ void cleanSlashes(string &str)
   str=out;
 }
 
+
 const string sockAddrToString(struct sockaddr_in *remote, Utility::socklen_t socklen) 
 {    
-  if(socklen==sizeof(struct sockaddr_in))
-     return inet_ntoa(((struct sockaddr_in *)remote)->sin_addr);
+  if(socklen==sizeof(struct sockaddr_in)) {
+    struct sockaddr_in sip;
+    memcpy(&sip,(struct sockaddr_in*)remote,sizeof(sip));
+    return inet_ntoa(sip.sin_addr);
+  }
 #ifdef HAVE_IPV6
   else {
     char tmp[128];
index 8651631a3bb81b49abe3fa983c03e5a36d2ba97e..d950d319dcdb77e542fdcad7bbeb44f74f08d735 100644 (file)
@@ -69,6 +69,12 @@ inline void putLong(char* p, u_int32_t val)
   putLong((unsigned char *)p,val);
 }
 
+
+inline u_int32_t getLong(unsigned char *p)
+{
+  return (p[0]<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
+}
+
 void upperCase(string& s);
 
 struct ServiceTuple
index b8801aed7a74243b1043adee03588a477311fe04..886681f84825f27c8ad486f9a120e420ccf4e30a 100644 (file)
@@ -156,8 +156,8 @@ void startDoResolve(void *p)
     R->setA(false);
     R->setRA(true);
 
-    SyncRes<LWRes> sr;
-    L<<Logger::Error<<"["<<MT.getTid()<<"] new question arrived for '"<<P.qdomain<<"|"<<P.qtype.getName()<<"' from "<<P.getRemote()<<endl;
+    SyncRes sr;
+    L<<Logger::Error<<"["<<MT.getTid()<<"] question for '"<<P.qdomain<<"|"<<P.qtype.getName()<<"' from "<<P.getRemote()<<endl;
     sr.setId(MT.getTid());
     if(!P.d.rd)
       sr.setCacheOnly();
@@ -173,8 +173,8 @@ void startDoResolve(void *p)
 
     const char *buffer=R->getData();
     sendto(d_serversock,buffer,R->len,0,(struct sockaddr *)(R->remote),R->d_socklen);
-    L<<Logger::Error<<"["<<MT.getTid()<<"] sent answer to "<<(P.d.rd?"":"non-rd ")<<"question for '"<<P.qdomain<<"|"<<P.qtype.getName()<<"' to "<<P.getRemote();
-    L<<", "<<ntohs(R->d.ancount)<<" answers, "<<ntohs(R->d.arcount)<<" additional, took "<<sr.d_outqueries<<" packets"<<endl;
+    L<<Logger::Error<<"["<<MT.getTid()<<"] answer to "<<(P.d.rd?"":"non-rd ")<<"question '"<<P.qdomain<<"|"<<P.qtype.getName();
+    L<<"': "<<ntohs(R->d.ancount)<<" answers, "<<ntohs(R->d.arcount)<<" additional, took "<<sr.d_outqueries<<" packets, rcode="<<res<<endl;
     delete R;
   }
   catch(AhuException &ae) {
@@ -263,12 +263,12 @@ void houseKeeping(void *)
     if(qcounter) {
       L<<Logger::Error<<"stats: "<<qcounter<<" questions, "<<cache.size()<<" cache entries, "
        <<(int)((cacheHits*100.0)/(cacheHits+cacheMisses))<<"% cache hits";
-      L<<Logger::Error<<", outpacket/query ratio "<<(int)(SyncRes<LWRes>::s_outqueries*100.0/SyncRes<LWRes>::s_queries)<<"%"<<endl;
+      L<<Logger::Error<<", outpacket/query ratio "<<(int)(SyncRes::s_outqueries*100.0/SyncRes::s_queries)<<"%"<<endl;
     }
     last_stat=time(0);
   }
   if(time(0)-last_rootupdate>7200) {
-    SyncRes<LWRes> sr;
+    SyncRes sr;
     vector<DNSResourceRecord>ret;
 
     sr.setNoCache();
@@ -290,7 +290,7 @@ int main(int argc, char **argv)
     arg().set("soa-serial-offset","0")="0";
     arg().set("local-port","port to listen on")="5300";
     arg().set("local-address","port to listen on")="0.0.0.0";
-    arg().set("trace","if we should output heaps of logging")="true";
+    arg().set("trace","if we should output heaps of logging")="off";
     arg().set("daemon","Operate as a daemon")="no";
 
     arg().parse(argc, argv);
@@ -299,7 +299,7 @@ int main(int argc, char **argv)
     L.toConsole(Logger::Warning);
 
     if(arg().mustDo("trace"))
-      SyncRes<LWRes>::setLog(true);
+      SyncRes::setLog(true);
     
     makeClientSocket();
     makeServerSocket();
index 99733fe19bbbe21fde6adf47bcf8af23f1d6c2f5..6072a044b51b139a682d8b1f40e097a1d0702f04 100644 (file)
 #include "arguments.hh"
 #include "lwres.hh"
 
-template<class MultiPlexor>map<string,string> SyncRes<MultiPlexor>::s_negcache;
-template<class MultiPlexor>unsigned int SyncRes<MultiPlexor>::s_queries;
-template<class MultiPlexor>unsigned int SyncRes<MultiPlexor>::s_outqueries;
-template<class MultiPlexor>bool SyncRes<MultiPlexor>::s_log;
+map<string,string> SyncRes::s_negcache;
+unsigned int SyncRes::s_queries;
+unsigned int SyncRes::s_outqueries;
+bool SyncRes::s_log;
 
 #define LOG if(s_log)L<<Logger::Warning
 
 /** everything begins here - this is the entry point just after receiving a packet */
-template<>int SyncRes<>::beginResolve(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret)
+int SyncRes::beginResolve(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret)
 {
   set<GetBestNSAnswer> beenthere;
   s_queries++;
@@ -48,7 +48,7 @@ template<>int SyncRes<>::beginResolve(const string &qname, const QType &qtype, v
   return res;
 }
 
-template<class MultiPlexor>int SyncRes<MultiPlexor>::doResolve(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, int depth, set<GetBestNSAnswer>& beenthere)
+int SyncRes::doResolve(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, int depth, set<GetBestNSAnswer>& beenthere)
 {
   string prefix(d_prefix);
   prefix.append(depth, ' ');
@@ -78,7 +78,7 @@ template<class MultiPlexor>int SyncRes<MultiPlexor>::doResolve(const string &qna
   return res<0 ? RCode::ServFail : res;
 }
 
-template<class MultiPlexor>string SyncRes<MultiPlexor>::getA(const string &qname, int depth, set<GetBestNSAnswer>& beenthere)
+string SyncRes::getA(const string &qname, int depth, set<GetBestNSAnswer>& beenthere)
 {
   vector<DNSResourceRecord> res;
   string ret;
@@ -89,7 +89,7 @@ template<class MultiPlexor>string SyncRes<MultiPlexor>::getA(const string &qname
   return ret;
 }
 
-template<class MultiPlexor>void SyncRes<MultiPlexor>::getBestNSFromCache(const string &qname, set<DNSResourceRecord>&bestns, int depth, set<GetBestNSAnswer>& beenthere)
+void SyncRes::getBestNSFromCache(const string &qname, set<DNSResourceRecord>&bestns, int depth, set<GetBestNSAnswer>& beenthere)
 {
   string prefix(d_prefix), subdomain(qname);
   prefix.append(depth, ' ');
@@ -120,7 +120,7 @@ template<class MultiPlexor>void SyncRes<MultiPlexor>::getBestNSFromCache(const s
        answer.qname=toLower(qname); answer.bestns=bestns;
        if(beenthere.count(answer)) {
          LOG<<prefix<<qname<<": We have NS in cache for '"<<subdomain<<"' but part of LOOP! Trying less specific NS"<<endl;
-         for(typename set<GetBestNSAnswer>::const_iterator j=beenthere.begin();j!=beenthere.end();++j)
+         for( set<GetBestNSAnswer>::const_iterator j=beenthere.begin();j!=beenthere.end();++j)
            LOG<<prefix<<qname<<": beenthere: "<<j->qname<<" ("<<j->bestns.size()<<")"<<endl;
          bestns.clear();
        }
@@ -136,7 +136,7 @@ template<class MultiPlexor>void SyncRes<MultiPlexor>::getBestNSFromCache(const s
 
 
 /** doesn't actually do the work, leaves that to getBestNSFromCache */
-template<class MultiPlexor>string SyncRes<MultiPlexor>::getBestNSNamesFromCache(const string &qname,set<string>& nsset, int depth, set<GetBestNSAnswer>&beenthere)
+string SyncRes::getBestNSNamesFromCache(const string &qname,set<string>& nsset, int depth, set<GetBestNSAnswer>&beenthere)
 {
   string subdomain(qname);
 
@@ -150,7 +150,7 @@ template<class MultiPlexor>string SyncRes<MultiPlexor>::getBestNSNamesFromCache(
   return subdomain;
 }
 
-template<class MultiPlexor>bool SyncRes<MultiPlexor>::doCNAMECacheCheck(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, int depth, int &res)
+bool SyncRes::doCNAMECacheCheck(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, int depth, int &res)
 {
   string prefix(d_prefix), tuple=toLower(qname)+"|CNAME";
   prefix.append(depth, ' ');
@@ -182,7 +182,7 @@ template<class MultiPlexor>bool SyncRes<MultiPlexor>::doCNAMECacheCheck(const st
   return false;
 }
 
-template<class MultiPlexor>bool SyncRes<MultiPlexor>::doCacheCheck(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, int depth, int &res)
+bool SyncRes::doCacheCheck(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, int depth, int &res)
 {
   string prefix(d_prefix), tuple;
   prefix.append(depth, ' ');
@@ -232,7 +232,7 @@ template<class MultiPlexor>bool SyncRes<MultiPlexor>::doCacheCheck(const string
   return false;
 }
 
-template<class MultiPlexor>bool SyncRes<MultiPlexor>::moreSpecificThan(const string& a, const string &b)
+bool SyncRes::moreSpecificThan(const string& a, const string &b)
 {
   int counta=!a.empty(), countb=!b.empty();
   
@@ -245,7 +245,7 @@ template<class MultiPlexor>bool SyncRes<MultiPlexor>::moreSpecificThan(const str
   return counta>countb;
 }
 
-template<class MultiPlexor>vector<string> SyncRes<MultiPlexor>::shuffle(set<string> &nameservers)
+vector<string> SyncRes::shuffle(set<string> &nameservers)
 {
   vector<string> rnameservers;
   for(set<string>::const_iterator i=nameservers.begin();i!=nameservers.end();++i)
@@ -256,7 +256,7 @@ template<class MultiPlexor>vector<string> SyncRes<MultiPlexor>::shuffle(set<stri
 }
 
 /** returns -1 in case of no results, rcode otherwise */
-template<class MultiPlexor>int SyncRes<MultiPlexor>::doResolveAt(set<string> nameservers, string auth, const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, 
+int SyncRes::doResolveAt(set<string> nameservers, string auth, const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, 
                int depth, set<GetBestNSAnswer>&beenthere)
 {
   string prefix(d_prefix);
@@ -355,7 +355,7 @@ template<class MultiPlexor>int SyncRes<MultiPlexor>::doResolveAt(set<string> nam
          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)))  {
+       else if(i->d_place==DNSResourceRecord::ANSWER && toLower(i->qname)==toLower(qname) && (i->qtype==qtype || ( qtype==QType(QType::ANY) && aabit)))  {
          LOG<<prefix<<qname<<": answer is in: resolved to '"<<i->content<<"|"<<i->qtype.getName()<<"'"<<endl;
          done=true;
          ret.push_back(*i);
@@ -403,7 +403,7 @@ template<class MultiPlexor>int SyncRes<MultiPlexor>::doResolveAt(set<string> nam
   return -1;
 }
 
-template<class MultiPlexor>void SyncRes<MultiPlexor>::addCruft(const string &qname, vector<DNSResourceRecord>& ret)
+void SyncRes::addCruft(const string &qname, vector<DNSResourceRecord>& ret)
 {
   for(vector<DNSResourceRecord>::const_iterator k=ret.begin();k!=ret.end();++k)  // don't add stuff to an NXDOMAIN!
     if(k->d_place==DNSResourceRecord::AUTHORITY && k->qtype==QType(QType::SOA))
@@ -433,7 +433,7 @@ template<class MultiPlexor>void SyncRes<MultiPlexor>::addCruft(const string &qna
   LOG<<d_prefix<<qname<<": Done with additional processing"<<endl;
 }
 
-template<class MultiPlexor>void SyncRes<MultiPlexor>::addAuthorityRecords(const string& qname, vector<DNSResourceRecord>& ret, int depth)
+void SyncRes::addAuthorityRecords(const string& qname, vector<DNSResourceRecord>& ret, int depth)
 {
   set<DNSResourceRecord> bestns;
   set<GetBestNSAnswer>beenthere;
index 7b31525a5673bd851bbe9d0eebf6f9948b9da26b..401d24f72366df5ad2804adf0b05d0540cf06b36 100644 (file)
@@ -14,7 +14,7 @@ void replaceCache(const string &qname, const QType &qt, const set<DNSResourceRec
 int getCache(const string &qname, const QType& qt, set<DNSResourceRecord>* res=0);
 
 
-template<class MultiPlexor=LWRes> class SyncRes
+class SyncRes
 {
 public:
   SyncRes() : d_outqueries(0), d_cacheonly(false), d_nocache(false){}
@@ -60,7 +60,7 @@ private:
   static bool s_log;
   bool d_cacheonly;
   bool d_nocache;
-  MultiPlexor d_lwr;
+  LWRes d_lwr;
   static map<string,string> s_negcache;
   struct GetBestNSAnswer
   {