]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Change dsmap_t to a set to prevent duplicates 4207/head
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 21 Jul 2016 14:43:47 +0000 (16:43 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Fri, 29 Jul 2016 12:01:17 +0000 (14:01 +0200)
pdns/rec-lua-conf.cc
pdns/rec_channel_rec.cc
pdns/toysdig.cc
pdns/validate.cc
pdns/validate.hh

index 1fdef761f39bc82622327db342a1ee71afc635cc..73822342e17c9f267d5b5c29cfececda2a64dbd0 100644 (file)
@@ -34,10 +34,7 @@ GlobalStateHolder<LuaConfigItems> g_luaconfs;
 LuaConfigItems::LuaConfigItems()
 {
   auto ds=unique_ptr<DSRecordContent>(dynamic_cast<DSRecordContent*>(DSRecordContent::make("19036 8 2 49aac11d7b6f6446702e54a1607371607a1a41855200fd2ce1cdde32f24e8fb5")));
-  dsmap_t dsmap;
-  dsmap.insert({ds->d_tag, *ds});
-  // this hurts physically
-  dsAnchors[DNSName(".")] = dsmap;
+  dsAnchors[DNSName(".")].insert(*ds);
 }
 
 /* DID YOU READ THE STORY ABOVE? */
@@ -223,11 +220,8 @@ void loadRecursorLuaConfig(const std::string& fname)
 
   Lua.writeFunction("addDS", [&lci](const std::string& who, const std::string& what) {
       DNSName zone(who);
-      dsmap_t dsmap = lci.dsAnchors[zone];
-
       auto ds = unique_ptr<DSRecordContent>(dynamic_cast<DSRecordContent*>(DSRecordContent::make(what)));
-      dsmap.insert({ds->d_tag, *ds});
-      lci.dsAnchors[zone] = dsmap;
+      lci.dsAnchors[zone].insert(*ds);
   });
 
   Lua.writeFunction("clearDS", [&lci](boost::optional<string> who) {
index e5b2dee050f1e733f730bced8464c98bf2a1d30a..1e8e77a50798c1a1c10e6960d9015a132ec911c1 100644 (file)
@@ -489,10 +489,8 @@ string doAddTA(T begin, T end)
   try {
     L<<Logger::Warning<<"Adding Trust Anchor for "<<who<<" with data '"<<what<<"', requested via control channel";
     g_luaconfs.modify([who, what](LuaConfigItems& lci) {
-      dsmap_t dsmap = lci.dsAnchors[who];
       auto ds = unique_ptr<DSRecordContent>(dynamic_cast<DSRecordContent*>(DSRecordContent::make(what)));
-      dsmap.insert({ds->d_tag, *ds});
-      lci.dsAnchors[who] = dsmap;
+      lci.dsAnchors[who].insert(*ds);
       });
     broadcastAccFunction<uint64_t>(boost::bind(pleaseWipePacketCache, who, true));
     L<<Logger::Warning<<endl;
@@ -552,7 +550,7 @@ static string getTAs()
   for (auto anchor : luaconf->dsAnchors) {
     ret += anchor.first.toLogString() + "\n";
     for (auto e : anchor.second) {
-      ret+="\t\t"+e.second.getZoneRepresentation() + "\n";
+      ret+="\t\t"+e.getZoneRepresentation() + "\n";
     }
   }
 
index 7f1bbbd4c7550115d108767822a49afc80c26ead..fefe41460954c9a93305be29b10d22bc0c2ff317 100644 (file)
@@ -101,10 +101,7 @@ GlobalStateHolder<LuaConfigItems> g_luaconfs;
 LuaConfigItems::LuaConfigItems()
 {
   auto ds=std::unique_ptr<DSRecordContent>(dynamic_cast<DSRecordContent*>(DSRecordContent::make("19036 8 2 49aac11d7b6f6446702e54a1607371607a1a41855200fd2ce1cdde32f24e8fb5")));
-  // this hurts physically
-  dsmap_t dsmap;
-  dsmap.insert({ds->d_tag, *ds});
-  dsAnchors[DNSName(".")] = dsmap;
+  dsAnchors[DNSName(".")].insert(*ds);
 }
 
 DNSFilterEngine::DNSFilterEngine() {}
index e70070f85e18ecda8364dc09c615d5df24b716d5..e1bf751bb21eb67e34dbaa36a8f2431d7bb57363 100644 (file)
@@ -256,13 +256,12 @@ vState getKeysFor(DNSRecordOracle& dro, const DNSName& zone, keyset_t &keyset)
     }
     LOG("got "<<tkeys.size()<<" keys and "<<sigs.size()<<" sigs from server"<<endl);
 
-    for(dsmap_t::const_iterator i=dsmap.begin(); i!=dsmap.end(); i++)
+    for(auto const& dsrc : dsmap)
     {
-      DSRecordContent dsrc=i->second;
-      auto r = getByTag(tkeys, i->first);
+      auto r = getByTag(tkeys, dsrc.d_tag);
       //      cerr<<"looking at DS with tag "<<dsrc.d_tag<<"/"<<i->first<<", got "<<r.size()<<" DNSKEYs for tag"<<endl;
 
-      for(const auto& drc : r) 
+      for(const auto& drc : r)
       {
        bool isValid = false;
        DSRecordContent dsrc2;
@@ -275,7 +274,7 @@ vState getKeysFor(DNSRecordOracle& dro, const DNSName& zone, keyset_t &keyset)
        }
 
         if(isValid) {
-         LOG("got valid DNSKEY (it matches the DS) with tag "<<dsrc.d_tag<<"/"<<i->first<<" for "<<qname<<endl);
+         LOG("got valid DNSKEY (it matches the DS) with tag "<<dsrc.d_tag<<" for "<<qname<<endl);
          
           validkeys.insert(drc);
          dotNode("DS", qname, "" /*std::to_string(dsrc.d_tag)*/, (boost::format("tag=%d, digest algo=%d, algo=%d") % dsrc.d_tag % static_cast<int>(dsrc.d_digesttype) % static_cast<int>(dsrc.d_algorithm)).str());
@@ -434,7 +433,7 @@ vState getKeysFor(DNSRecordOracle& dro, const DNSName& zone, keyset_t &keyset)
         {
           const auto dsrc=std::dynamic_pointer_cast<DSRecordContent>(*j);
           if(dsrc) {
-            dsmap.insert(make_pair(dsrc->d_tag, *dsrc));
+            dsmap.insert(*dsrc);
             // dotEdge(keyqname,
             //         "DNSKEY", keyqname, ,
             //         "DS", qname, std::to_string(dsrc.d_tag));
index b5d220e21aa7cffa8d30c810c76992316a75b336..00c555dda0f506386df75711a7cba5541e4ba745 100644 (file)
@@ -31,7 +31,7 @@ struct ContentSigPair
   // ponder adding a validate method that accepts a key
 };
 typedef map<pair<DNSName,uint16_t>, ContentSigPair> cspmap_t;
-typedef std::multimap<uint16_t, DSRecordContent> dsmap_t;
+typedef std::set<DSRecordContent> dsmap_t;
 void validateWithKeySet(const cspmap_t& rrsets, cspmap_t& validated, const std::set<DNSKEYRecordContent>& keys);
 cspmap_t harvestCSPFromRecs(const vector<DNSRecord>& recs);
 vState getKeysFor(DNSRecordOracle& dro, const DNSName& zone, std::set<DNSKEYRecordContent> &keyset);