Parcourir la source

Generate nameserver entries into the zoneentry

Updated tests to use real rdata instead of fake ones, because this one
needs to typecast them to correct type

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac408@3710 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner il y a 14 ans
Parent
commit
6c9124503c

+ 0 - 11
src/lib/nsas/nameserver_address_store.cc

@@ -60,17 +60,6 @@ typedef shared_ptr<NameserverEntry> NameserverPtr;
 typedef shared_ptr<AddressRequestCallback> CallbackPtr;
 
 /*
- * Create a nameserver.
- * Called inside a mutex so it is filled in attomically.
- */
-NameserverPtr
-newNs(const std::string* name, uint16_t class_code,
-    const vector<AbstractRRset>*)
-{
-    return (NameserverPtr(new NameserverEntry(*name, class_code)));
-}
-
-/*
  * Create a zone entry.
  * It is called inside the mutex so it is called and filled in attomically.
  * Pointers are used instead of references, because with references,

+ 4 - 10
src/lib/nsas/tests/nsas_test.h

@@ -32,6 +32,7 @@
 #include <dns/rrtype.h>
 #include <dns/rrttl.h>
 #include <dns/messagerenderer.h>
+#include <dns/rdataclass.h>
 #include "../nsas_entry.h"
 #include "../resolver_interface.h"
 
@@ -58,12 +59,6 @@ public:
     {return RRType::AAAA().getCode();}
 };
 
-class NS {
-public:
-    uint16_t getType() const
-    {return RRType::NS().getCode();}
-};
-
 class MX {
 public:
     uint16_t getType() const
@@ -359,12 +354,11 @@ protected:
         rrch_->addRdata(ConstRdataPtr(new RdataTest<A>("1324")));
 
         // NS records take a single name
-        rrns_->addRdata(ConstRdataPtr(new RdataTest<NS>("example.fr")));
-        rrns_->addRdata(ConstRdataPtr(new RdataTest<NS>("example.de")));
+        rrns_->addRdata(rdata::generic::NS("example.fr"));
+        rrns_->addRdata(rdata::generic::NS("example.de"));
 
         // Single NS record with 0 TTL
-        rr_single_->addRdata(ConstRdataPtr(new RdataTest<NS>(
-            "ns.example.net.")));
+        rr_single_->addRdata(rdata::generic::NS( "ns.example.net."));
 
         // AAAA records
         rrv6_->addRdata(ConstRdataPtr(new RdataTest<AAAA>("2001::1002")));

+ 57 - 0
src/lib/nsas/zone_entry.cc

@@ -21,6 +21,7 @@
 #include <algorithm>
 #include <boost/foreach.hpp>
 #include <dns/rrttl.h>
+#include <dns/rdataclass.h>
 
 using namespace std;
 using namespace boost;
@@ -35,6 +36,17 @@ namespace {
 // Shorter aliases for frequently used types
 typedef mutex::scoped_lock Lock; // Local lock, nameservers not locked
 typedef shared_ptr<AddressRequestCallback> CallbackPtr;
+
+/*
+ * Create a nameserver.
+ * Called inside a mutex so it is filled in atomically.
+ */
+shared_ptr<NameserverEntry>
+newNs(const std::string* name, const RRClass* class_code) {
+    return (shared_ptr<NameserverEntry>(new NameserverEntry(*name,
+        *class_code)));
+}
+
 }
 
 // A struct, the class is unaccessible anyway and is ours
@@ -50,6 +62,51 @@ struct ZoneEntry::ResolverCallback : public ResolverInterface::Callback {
         if (iterator->isLast()) {
             failureInternal(lock, answer->getTTL().getValue());
             return;
+        } else {
+            // Store the current ones so we can keep them
+            map<string, NameserverPtr> old;
+            BOOST_FOREACH(const NameserverPtr& ptr, entry_->nameservers_) {
+                old[ptr->getName()] = ptr;
+            }
+
+            // Now drop the old ones and insert the new ones
+            entry_->nameservers_.clear();
+            for (; !iterator->isLast(); iterator->next()) {
+                try {
+                    // Get the name from there
+                    Name ns_name(dynamic_cast<const rdata::generic::NS&>(
+                        iterator->getCurrent()).getNSName());
+                    // Try to find it in the old ones
+                    map<string, NameserverPtr>::iterator old_ns(old.find(
+                        ns_name.toText()));
+                    // It is not there, look it up in the table or create
+                    // new one
+                    if (old_ns == old.end()) {
+                        // Look it up or create it
+                        string ns_name_str(ns_name.toText());
+                        pair<bool, NameserverPtr> from_hash(
+                            entry_->nameserver_table_->getOrAdd(HashKey(
+                            ns_name_str, entry_->class_code_), bind(
+                            newNs, &ns_name_str, &entry_->class_code_)));
+                        // Touch it if it is not newly created
+                        if (!from_hash.first) {
+                            entry_->nameserver_lru_->touch(from_hash.second);
+                        }
+                        // And add it at last
+                        entry_->nameservers_.push_back(from_hash.second);
+                    } else {
+                        // We have it, so just use it
+                        entry_->nameservers_.push_back(old_ns->second);
+                    }
+                }
+                // OK, we skip this one it is not NS (log?)
+                catch (bad_cast&) { }
+            }
+
+            // It is unbelievable, but we found no nameservers there
+            if (entry_->nameservers_.empty()) {
+                failureInternal(lock, answer->getTTL().getValue());
+            }
         }
     }
     virtual void failure() {