]> granicus.if.org Git - pdns/commitdiff
silence 'sdig' EDNS-PING output, replace Utility::strcasecmp by boost::iequals, remov...
authorBert Hubert <bert.hubert@netherlabs.nl>
Wed, 23 Dec 2009 21:47:46 +0000 (21:47 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Wed, 23 Dec 2009 21:47:46 +0000 (21:47 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1468 d19b8d6e-7fed-0310-83ef-9ca221ded41b

17 files changed:
pdns/dns.cc
pdns/dnsparser.hh
pdns/dnswriter.cc
pdns/lwres.cc
pdns/notify.cc
pdns/nproxy.cc
pdns/packethandler.cc
pdns/pdns_recursor.cc
pdns/recpacketcache.hh
pdns/recursor_cache.hh
pdns/sdig.cc
pdns/syncres.cc
pdns/syncres.hh
pdns/unix_utility.cc
pdns/utility.hh
pdns/win32_utility.cc
pdns/zoneparser-tng.cc

index 9143b3cfb03117c027057b9667982acaefa689a0..7e6a4b8357211599ad46402407053508bf4ee707 100644 (file)
@@ -1,37 +1,30 @@
 #include "dns.hh"
 #include <stdexcept>
 
-void questionExpand(const char* packet, uint16_t len, char* qname, int maxlen, uint16_t& type)
+string questionExpand(const char* packet, uint16_t len, uint16_t& type)
 {
   type=0;
-  const unsigned char* end=(const unsigned char*)packet+len;
-  unsigned char* lbegin=(unsigned char*)packet+12;
-  unsigned char* pos=lbegin;
+  string ret;
+  if(len < 12) 
+    throw runtime_error("Error parsing question in incoming packet: packet too short");
+    
+  const unsigned char* end = (const unsigned char*)packet+len;
+  const unsigned char* pos = (const unsigned char*)packet+12;
   unsigned char labellen;
-
-  // 3www4ds9a2nl0
-  char *dst=qname;
-  char* lend=dst + maxlen;
   
   if(!*pos)
-    *dst++='.';
+    ret.assign(1, '.');
 
   while((labellen=*pos++) && pos < end) { // "scan and copy"
-    if(dst >= lend)
-      throw std::runtime_error("Label length exceeded destination length");
-    for(;labellen;--labellen)
-      *dst++ = *pos++;
-    *dst++='.';
+    if(pos + labellen > end)
+      throw runtime_error("Error parsing question in incoming packet: label extends beyond packet");
+      
+    ret.append((const char*)pos, labellen);
+    ret.append(1, '.');
+    pos += labellen;
   }
-  *dst=0;
 
-  if(pos + labellen + 2 <= end)  // is this correct XXX FIXME?
+  if(pos + labellen + 2 <= end)  
     type=(*pos)*256 + *(pos+1);
-}
-
-string questionExpand(const char* packet, uint16_t len, uint16_t& type)
-{
-  char tmp[512];
-  questionExpand(packet, len, tmp, sizeof(tmp), type);
-  return tmp;
+  return ret;
 }
index b918ea6ffa5e59a62051b358463dad971d1c9164..d99e3a659f64ceab8a055ec3d55b2cecae75ab76 100644 (file)
@@ -195,7 +195,7 @@ public:
   static uint16_t TypeToNumber(const string& name)
   {
     for(namemap_t::const_iterator i=getNamemap().begin(); i!=getNamemap().end();++i)
-      if(!Utility::strcasecmp(i->second.c_str(), name.c_str()))
+      if(boost::iequals(i->second, name))
        return i->first.second;
 
     throw runtime_error("Unknown DNS type '"+name+"'");
index 2c74cd753cce8b4e3e93393cf4e15f42b12829a4..6de1d183bad3e54dfdec8aef594c8c80f7f952d4 100644 (file)
@@ -68,7 +68,7 @@ void DNSPacketWriter::startRecord(const string& name, uint16_t qtype, uint32_t t
   d_stuff = 0; 
   d_rollbackmarker=d_content.size();
 
-  if(!strcasecmp(d_qname.c_str(), d_recordqname.c_str())) {  // don't do the whole label compression thing if we *know* we can get away with "see question"
+  if(boost::iequals(d_qname, d_recordqname)) {  // don't do the whole label compression thing if we *know* we can get away with "see question"
     static char marker[2]={0xc0, 0x0c};
     d_content.insert(d_content.end(), &marker[0], &marker[2]);
   }
@@ -165,7 +165,7 @@ DNSPacketWriter::lmap_t::iterator find(DNSPacketWriter::lmap_t& lmap, const stri
 {
   DNSPacketWriter::lmap_t::iterator ret;
   for(ret=lmap.begin(); ret != lmap.end(); ++ret)
-    if(!strcasecmp(ret->first.c_str() ,label.c_str()))
+    if(boost::iequals(ret->first ,label))
       break;
   return ret;
 }
index 13c09b4c06fe721b0fecb1ba9220310df16e2419..eb3433e3b4cb8a5f03c66fc9028d9fbe026f1878 100644 (file)
@@ -1,6 +1,6 @@
 /*
     PowerDNS Versatile Database Driven Nameserver
-    Copyright (C) 2002 - 2008 PowerDNS.COM BV
+    Copyright (C) 2002 - 2009 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 as 
@@ -173,7 +173,7 @@ int asyncresolve(const ComboAddress& ip, const string& domain, int type, bool do
       return 1; // this is "success", the error is set in lwr->d_rcode
     }
 
-    if(Utility::strcasecmp(domain.c_str(), mdp.d_qname.c_str())) { 
+    if(!boost::iequals(domain, mdp.d_qname)) { 
       if(domain.find((char)0)==string::npos) {// embedded nulls are too noisy
        L<<Logger::Notice<<"Packet purporting to come from remote server "<<ip.toString()<<" contained wrong answer: '" << domain << "' != '" << mdp.d_qname << "'" << endl;
        g_stats.unexpectedCount++;
index 428a3d5637d0675fdcce4e4e6261017676223556..0f6697749e259d094dc33e32a3474437cefa87ef 100644 (file)
@@ -74,12 +74,6 @@ int Utility::inet_pton( int af, const char *src, void *dst )
   return ::inet_pton(af, src, dst);
 }
 
-// Compares two string, ignoring the case.
-int Utility::strcasecmp( const char *s1, const char *s2 )
-{
-  return ::strcasecmp( s1, s2 );
-}
-
 // Returns the current time.
 int Utility::gettimeofday( struct timeval *tv, void *tz )
 {
index 746b6f753cb7ee53fb5519dafe651e215cfb2f8b..d2827fb7e4c658155e9127bbe66f14fa77d7db9d 100644 (file)
@@ -315,11 +315,6 @@ int Utility::inet_pton( int af, const char *src, void *dst )
   return ::inet_pton(af, src, dst);
 }
 
-// Compares two string, ignoring the case.
-int Utility::strcasecmp( const char *s1, const char *s2 )
-{
-  return ::strcasecmp( s1, s2 );
-}
 
 // Returns the current time.
 int Utility::gettimeofday( struct timeval *tv, void *tz )
index 5df42c835f6dac2a654a2896f5b7c53a72ced533..ca5ae15f646a345ab3cae8026ebd007d0875e60e 100644 (file)
@@ -842,7 +842,7 @@ DNSPacket *PacketHandler::questionOrRecurse(DNSPacket *p, bool *shouldRecurse)
          continue;
        }
          
-       if(!Utility::strcasecmp(subdomain.c_str(),sd.qname.c_str())) // about to break out of our zone
+       if(boost::iequals(subdomain,sd.qname)) // about to break out of our zone
          break; 
        
        B.lookup("NS", subdomain,p,zoneId);  // start our search at the backend
index f8d2dc6e1a0a0d699cf640c431bee9f295dfe578..d4eb27591cc27218eae63224a3cb0cf38b51515e 100644 (file)
@@ -1270,8 +1270,6 @@ void doResends(MT_t::waiters_t::iterator& iter, PacketID resend, const string& c
 
 void handleUDPServerResponse(int fd, FDMultiplexer::funcparam_t& var)
 {
-  //  static HTimer s_timer("udp server response processing");
-
   PacketID pid=any_cast<PacketID>(var);
   int len;
   char data[1500];
@@ -1314,7 +1312,13 @@ void handleUDPServerResponse(int fd, FDMultiplexer::funcparam_t& var)
       pident.type = 0;
     }
     else {
-      pident.domain=questionExpand(data, len, pident.type); // don't copy this from above - we need to do the actual read
+      try {
+       pident.domain=questionExpand(data, len, pident.type); // don't copy this from above - we need to do the actual read
+      }
+      catch(std::exception& e) {
+       L<<Logger::Warning<<"Error in packet from "<<sockAddrToString((struct sockaddr_in*) &fromaddr) << ": "<<e.what() << endl;
+       return;
+      }
     }
     string packet;
     packet.assign(data, len);
@@ -1333,7 +1337,7 @@ void handleUDPServerResponse(int fd, FDMultiplexer::funcparam_t& var)
       
       for(MT_t::waiters_t::iterator mthread=MT->d_waiters.begin(); mthread!=MT->d_waiters.end(); ++mthread) {
        if(pident.fd==mthread->key.fd && mthread->key.remote==pident.remote &&  mthread->key.type == pident.type &&
-          !Utility::strcasecmp(pident.domain.c_str(), mthread->key.domain.c_str())) {
+          boost::iequals(pident.domain, mthread->key.domain)) {
          mthread->key.nearMisses++;
        }
 
index 2bfb2c63727cd15aeb8d7d2740cced7b5d44ab06..fe5df204d0afc4974bf7c78cfaa7c8f0877cb795 100644 (file)
@@ -49,6 +49,8 @@ inline bool RecursorPacketCache::Entry::operator<(const struct RecursorPacketCac
   string qname=questionExpand(d_packet.c_str(), d_packet.length(), qtype);
   string rhsqname=questionExpand(rhs.d_packet.c_str(), rhs.d_packet.length(), rhsqtype);
 
+  // qtype is only known *after* questionExpand..
+
   return tie(qtype, qname) < tie(rhsqtype, rhsqname);
 }
 
index 35e6680d4e71fc7c7f4505f547f0a0de84c7e090..7a38eb02d4dcce1f73a30bf3f4740f9fc9122e4c 100644 (file)
 #include <boost/tuple/tuple_comparison.hpp>
 #include <boost/multi_index/key_extractors.hpp>
 #include <boost/multi_index/sequenced_index.hpp>
+// #include <boost/thread/shared_mutex.hpp>
 #include <boost/version.hpp>
-#if BOOST_VERSION >= 103300
-#include <boost/multi_index/hashed_index.hpp>
-#endif
 
 #undef max
 
@@ -113,7 +111,7 @@ private:
   bool attemptToRefreshNSTTL(const QType& qt, const set<DNSResourceRecord>& content, const CacheEntry& stored);
 
   pthread_rwlock_t d_rwlock;
-
+  // boost::shared_mutex d_smutex;
 };
 string DNSRR2String(const DNSResourceRecord& rr);
 DNSResourceRecord String2DNSRR(const string& qname, const QType& qt, const string& serial, uint32_t ttd);
index 35c755fbace84373a51832e406a35c7012ee3fcb..a516c50d51ea65439db1f2ca901e17d73e1441a6 100644 (file)
@@ -31,12 +31,14 @@ try
   NSRecordContent nrc2("ns2.powerdns.com");
   nrc2.toPacket(pw);
   */
+
     string ping("hallo!");
-  DNSPacketWriter::optvect_t opts;
+/*  DNSPacketWriter::optvect_t opts;
 
   opts.push_back(make_pair(5, ping));
   pw.addOpt(5200, 0, 0x8000, opts);
   pw.commit();
+*/
 
   Socket sock(InterNetwork, Datagram);
   ComboAddress dest(argv[1] + (*argv[1]=='@'), atoi(argv[2]));
index 096e71a01b73fe9557955de0ba2e9253186cad37..0d662a81776a73a64c5d43ae8bf4470dfa85df34 100644 (file)
@@ -77,8 +77,8 @@ bool SyncRes::s_noEDNS;
 int SyncRes::beginResolve(const string &qname, const QType &qtype, uint16_t qclass, vector<DNSResourceRecord>&ret)
 {
   s_queries++;
-  if( (qtype.getCode()==QType::PTR && !Utility::strcasecmp(qname.c_str(), "1.0.0.127.in-addr.arpa.")) ||
-      (qtype.getCode()==QType::A && qname.length()==10 && !Utility::strcasecmp(qname.c_str(), "localhost."))) {
+  if( (qtype.getCode()==QType::PTR && iequals(qname, "1.0.0.127.in-addr.arpa.")) ||
+      (qtype.getCode()==QType::A && qname.length()==10 && iequals(qname, "localhost."))) {
     ret.clear();
     DNSResourceRecord rr;
     rr.qname=qname;
@@ -94,7 +94,7 @@ int SyncRes::beginResolve(const string &qname, const QType &qtype, uint16_t qcla
   }
 
   if(qclass==3 && qtype.getCode()==QType::TXT && 
-        (!Utility::strcasecmp(qname.c_str(), "version.bind.") || !Utility::strcasecmp(qname.c_str(), "id.server.") || !Utility::strcasecmp(qname.c_str(), "version.pdns.") ) 
+        (iequals(qname, "version.bind.") || iequals(qname, "id.server.") || iequals(qname, "version.pdns.") ) 
      ) {
     ret.clear();
     DNSResourceRecord rr;
@@ -102,7 +102,7 @@ int SyncRes::beginResolve(const string &qname, const QType &qtype, uint16_t qcla
     rr.qtype=qtype;
     rr.qclass=qclass;
     rr.ttl=86400;
-    if(!Utility::strcasecmp(qname.c_str(),"version.bind.")  || !Utility::strcasecmp(qname.c_str(),"version.pdns."))
+    if(iequals(qname,"version.bind.")  || iequals(qname,"version.pdns."))
       rr.content="\""+::arg()["version-string"]+"\"";
     else
       rr.content="\""+s_serverID+"\"";
@@ -757,12 +757,11 @@ struct TCacheComp
 {
   bool operator()(const pair<string, QType>& a, const pair<string, QType>& b) const
   {
-    int cmp=Utility::strcasecmp(a.first.c_str(), b.first.c_str());
-    if(cmp < 0)
+    if(boost::ilexicographical_compare(a.first, b.first))
       return true;
-    if(cmp > 0)
+    if(boost::ilexicographical_compare(b.first, a.first))   
       return false;
-
+      
     return a.second < b.second;
   }
 };
@@ -1032,7 +1031,7 @@ int SyncRes::doResolveAt(set<string, CIStringCompare> nameservers, string auth,
          newtarget=i->content;
        }
        // for ANY answers we *must* have an authoritive answer
-       else if(i->d_place==DNSResourceRecord::ANSWER && !Utility::strcasecmp(i->qname.c_str(),qname.c_str()) && 
+       else if(i->d_place==DNSResourceRecord::ANSWER && boost::iequals(i->qname, qname) && 
                (
                 i->qtype==qtype || (lwr.d_aabit && (qtype==QType(QType::ANY) || magicAddrMatch(qtype, i->qtype) ) )
                ) 
index 974ed22c2995e036f975f41f05dbeca97fbabfa3..e8a3b3e71579ce182a6683adc76bd6d01d4c4ccc 100644 (file)
@@ -475,10 +475,9 @@ struct PacketID
     if( tie(remote, ourSock, type) > tie(b.remote, bSock, b.type))
       return false;
 
-    int cmp=Utility::strcasecmp(domain.c_str(), b.domain.c_str());
-    if(cmp < 0)
+    if(boost::ilexicographical_compare(domain, b.domain))
       return true;
-    if(cmp > 0)
+    if(boost::ilexicographical_compare(b.domain, domain))
       return false;
 
     return tie(fd, id) < tie(b.fd, b.id);
@@ -496,8 +495,7 @@ struct PacketIDBirthdayCompare: public binary_function<PacketID, PacketID, bool>
     if( tie(a.remote, ourSock, a.type) > tie(b.remote, bSock, b.type))
       return false;
 
-    int cmp=Utility::strcasecmp(a.domain.c_str(), b.domain.c_str());
-    return cmp < 0;
+    return boost::ilexicographical_compare(a.domain, b.domain);
   }
 };
 extern MemRecursorCache RC;
index f780296c2e1cf4137cde2a301401f5d26188fa50..ce96cb742e708aeba39f7e05cf621d145c8f7d46 100644 (file)
@@ -176,12 +176,6 @@ void Utility::srandom( unsigned int seed )
   ::srandom(seed);
 }
 
-// Compares two string, ignoring the case.
-int Utility::strcasecmp( const char *s1, const char *s2 )
-{
-  return ::strcasecmp( s1, s2 );
-}
-
 
 // Writes a vector.
 int Utility::writev(int socket, const iovec *vector, size_t count )
index 059a9126f08a521194985b0ba4c7f26975a2e6cc..82e73652219e878f8e6c181d8c9b456eb69aae92 100644 (file)
@@ -187,9 +187,6 @@ public:
   //! Sets the random seed.
   static void srandom( unsigned int seed );
 
-  //! Compares two strings and ignores case.
-  static int strcasecmp( const char *s1, const char *s2 );
-
   //! Drops the program's privileges.
   static void dropPrivs( int uid, int gid );
   
index eeb0ac13e8d7a3674b44cc90c3ca3496f2d2d8eb..3294b6b2991d2d878051492e0f13f7359d464df9 100644 (file)
@@ -380,13 +380,6 @@ void Utility::srandom( unsigned int seed )
 }
 
 
-// Compares two string, ignoring the case.
-int Utility::strcasecmp( const char *s1, const char *s2 )
-{
-  return strcmp( s1, s2 );
-}
-
-
 // Sleeps for a number of microseconds.
 void Utility::usleep( unsigned long usec )
 {
index 34dfa849038c8b9bb3cd029449c6920e457f0c48..fc8b04fd3cdf309895694947365c15f302aae589 100644 (file)
@@ -314,7 +314,7 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr)
 
     // cout<<"Next part: '"<<nextpart<<"'"<<endl;
     
-    if(!Utility::strcasecmp(nextpart.c_str(), "IN")) {
+    if(boost::iequals(nextpart, "IN")) {
       // cout<<"Ignoring 'IN'\n";
       continue;
     }