]> granicus.if.org Git - pdns/commitdiff
packetcache: use DNSName.toDNSString() as key
authorKees Monshouwer <mind04@monshouwer.org>
Fri, 5 Jun 2015 18:09:11 +0000 (20:09 +0200)
committermind04 <mind04@monshouwer.org>
Tue, 30 Jun 2015 06:12:46 +0000 (08:12 +0200)
pdns/packetcache.cc
pdns/packetcache.hh

index 62bf0e2606f4eb91876a00dcbdc268ca2b8339af..4d4735268a1c12d3e48767b80c9bdcbf7d12ecdf 100644 (file)
@@ -105,7 +105,7 @@ int PacketCache::get(DNSPacket *p, DNSPacket *cached, bool recursive)
     }
 
     uint16_t maxReplyLen = p->d_tcp ? 0xffff : p->getMaxReplyLen();
-    haveSomething=getEntryLocked(p->qdomain.toString() /*FIXME*/, p->qtype, PacketCache::PACKETCACHE, value, -1, recursive, maxReplyLen, p->d_dnssecOk, p->hasEDNS(), &age);
+    haveSomething=getEntryLocked(p->qdomain, p->qtype, PacketCache::PACKETCACHE, value, -1, recursive, maxReplyLen, p->d_dnssecOk, p->hasEDNS(), &age);
   }
   if(haveSomething) {
     (*d_statnumhit)++;
@@ -155,7 +155,7 @@ void PacketCache::insert(DNSPacket *q, DNSPacket *r, bool recursive, unsigned in
     if(minttl<ourttl)
       ourttl=minttl;
   }
-  insert(q->qdomain.toString() /*FIXME*/, q->qtype, PacketCache::PACKETCACHE, r->getString(), ourttl, -1, recursive,
+  insert(q->qdomain, q->qtype, PacketCache::PACKETCACHE, r->getString(), ourttl, -1, recursive,
     maxReplyLen, q->d_dnssecOk, q->hasEDNS());
 }
 
@@ -229,10 +229,10 @@ int PacketCache::purge(const string &match)
       cmap_t::const_iterator start=iter;
 
       for(; iter != mc.d_map.end(); ++iter) {
-        if(iter->qname.toString().compare(0, zone.size(), zone) != 0) { //TODO: check if there is a nicer method for this
-          break;
-        }
-        delcount++;
+       if(iter->qname.compare(0, zone.size(), zone) != 0) {
+         break;
+       }
+       delcount++;
       }
       mc.d_map.erase(start, iter);
     }
@@ -291,19 +291,10 @@ bool PacketCache::getEntryLocked(const DNSName &qname, const QType& qtype, Cache
 }
 
 
-string PacketCache::pcReverse(const DNSName &DNcontent)
+string PacketCache::pcReverse(DNSName content)
 {
-  typedef vector<pair<unsigned int, unsigned int> > parts_t;
-  parts_t parts;
-  string content = DNcontent.toString();
-  vstringtok(parts,toLower(content), ".");
-  string ret;
-  ret.reserve(content.size()+1);
-  for(parts_t::reverse_iterator i=parts.rbegin(); i!=parts.rend(); ++i) {
-    ret.append(1, (char)(i->second - i->first));
-    ret.append(content.c_str() + i->first, i->second - i->first);
-  }
-  return ret;
+  string ret=content.labelReverse().toDNSString();
+  return ret.substr(0, ret.size()-1);
 }
 
 map<char,int> PacketCache::getCounts()
index 556c81c73cbe0ea7a3de7e7e7916899ea5daa233..5eade02e33ab16aada04f8fdbc888af9f9c8ec2d 100644 (file)
@@ -70,14 +70,14 @@ public:
 
   map<char,int> getCounts();
 private:
-  bool getEntryLocked(const DNSName &qname, const QType& qtype, CacheEntryType cet, string& entry, int zoneID=-1,
+  bool getEntryLocked(const DNSName &content, const QType& qtype, CacheEntryType cet, string& entry, int zoneID=-1,
     bool meritsRecursion=false, unsigned int maxReplyLen=512, bool dnssecOk=false, bool hasEDNS=false, unsigned int *age=0);
-  string pcReverse(const DNSName &content);
+  string pcReverse(DNSName content);
   struct CacheEntry
   {
     CacheEntry() { qtype = ctype = 0; zoneID = -1; meritsRecursion=false; dnssecOk=false; hasEDNS=false;}
 
-    DNSName qname;
+    string qname;
     uint16_t qtype;
     uint16_t ctype;
     int zoneID;
@@ -98,7 +98,7 @@ private:
                 ordered_unique<
                       composite_key< 
                         CacheEntry,
-                        member<CacheEntry,DNSName,&CacheEntry::qname>,
+                        member<CacheEntry,string,&CacheEntry::qname>,
                         member<CacheEntry,uint16_t,&CacheEntry::qtype>,
                         member<CacheEntry,uint16_t, &CacheEntry::ctype>,
                         member<CacheEntry,int, &CacheEntry::zoneID>,
@@ -107,7 +107,7 @@ private:
                         member<CacheEntry,bool, &CacheEntry::dnssecOk>,
                         member<CacheEntry,bool, &CacheEntry::hasEDNS>
                         >,
-                        composite_key_compare<std::less<DNSName>, std::less<uint16_t>, std::less<uint16_t>, std::less<int>, std::less<bool>, 
+                        composite_key_compare<std::less<string>, std::less<uint16_t>, std::less<uint16_t>, std::less<int>, std::less<bool>, 
                           std::less<unsigned int>, std::less<bool>, std::less<bool> >
                             >,
                            sequenced<>
@@ -122,9 +122,9 @@ private:
   };
 
   vector<MapCombo> d_maps;
-  MapCombo& getMap(const DNSName& qname)
+  MapCombo& getMap(const std::string& qname) 
   {
-    return d_maps[burtle((const unsigned char*)qname.toString().c_str(), qname.toString().length(), 0) % d_maps.size()];
+    return d_maps[burtle((const unsigned char*)qname.c_str(), qname.length(), 0) % d_maps.size()];
   }