[svn] commit: r3710 - in /branches/trac408/src/lib/nsas: nameserver_address_store.cc tests/nsas_test.h zone_entry.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Dec 3 17:50:52 UTC 2010
Author: vorner
Date: Fri Dec 3 17:50:52 2010
New Revision: 3710
Log:
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
Modified:
branches/trac408/src/lib/nsas/nameserver_address_store.cc
branches/trac408/src/lib/nsas/tests/nsas_test.h
branches/trac408/src/lib/nsas/zone_entry.cc
Modified: branches/trac408/src/lib/nsas/nameserver_address_store.cc
==============================================================================
--- branches/trac408/src/lib/nsas/nameserver_address_store.cc (original)
+++ branches/trac408/src/lib/nsas/nameserver_address_store.cc Fri Dec 3 17:50:52 2010
@@ -58,17 +58,6 @@
typedef shared_ptr<ZoneEntry> ZonePtr;
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.
Modified: branches/trac408/src/lib/nsas/tests/nsas_test.h
==============================================================================
--- branches/trac408/src/lib/nsas/tests/nsas_test.h (original)
+++ branches/trac408/src/lib/nsas/tests/nsas_test.h Fri Dec 3 17:50:52 2010
@@ -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"
@@ -56,12 +57,6 @@
public:
uint16_t getType() const
{return RRType::AAAA().getCode();}
-};
-
-class NS {
-public:
- uint16_t getType() const
- {return RRType::NS().getCode();}
};
class MX {
@@ -359,12 +354,11 @@
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")));
Modified: branches/trac408/src/lib/nsas/zone_entry.cc
==============================================================================
--- branches/trac408/src/lib/nsas/zone_entry.cc (original)
+++ branches/trac408/src/lib/nsas/zone_entry.cc Fri Dec 3 17:50:52 2010
@@ -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 @@
// 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 @@
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() {
More information about the bind10-changes
mailing list