[svn] commit: r3988 - in /branches/trac226: ./ doc/ src/bin/auth/ src/bin/auth/benchmarks/ src/bin/auth/tests/ src/bin/auth/tests/testdata/ src/bin/bind10/ src/bin/bind10/tests/ src/bin/recurse/ src/lib/ src/lib/asiolink/ src/lib/cc/ src/lib/config/ src/lib/config/tests/ src/lib/config/tests/testdata/ src/lib/datasrc/ src/lib/datasrc/tests/ src/lib/dns/ src/lib/dns/tests/ src/lib/log/ src/lib/nsas/ src/lib/nsas/tests/ src/lib/python/isc/config/ src/lib/python/isc/config/tests/ src/lib/python/isc/utils/ src/lib/testutils/
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Dec 23 14:58:15 UTC 2010
Author: jreed
Date: Thu Dec 23 14:58:15 2010
New Revision: 3988
Log:
Catch up to trunk.
Added:
branches/trac226/src/lib/asiolink/
- copied from r3987, trunk/src/lib/asiolink/
branches/trac226/src/lib/config/tests/testdata/data22_9.data
- copied unchanged from r3987, trunk/src/lib/config/tests/testdata/data22_9.data
branches/trac226/src/lib/datasrc/rbtree.h
- copied unchanged from r3987, trunk/src/lib/datasrc/rbtree.h
branches/trac226/src/lib/datasrc/result.h
- copied unchanged from r3987, trunk/src/lib/datasrc/result.h
branches/trac226/src/lib/datasrc/tests/rbtree_unittest.cc
- copied unchanged from r3987, trunk/src/lib/datasrc/tests/rbtree_unittest.cc
branches/trac226/src/lib/datasrc/zone.h
- copied unchanged from r3987, trunk/src/lib/datasrc/zone.h
branches/trac226/src/lib/log/
- copied from r3987, trunk/src/lib/log/
branches/trac226/src/lib/testutils/
- copied from r3987, trunk/src/lib/testutils/
Removed:
branches/trac226/src/bin/auth/asio_link.cc
branches/trac226/src/bin/auth/asio_link.h
branches/trac226/src/bin/auth/tests/asio_link_unittest.cc
branches/trac226/src/lib/python/isc/utils/
Modified:
branches/trac226/ (props changed)
branches/trac226/ChangeLog
branches/trac226/configure.ac
branches/trac226/doc/Doxyfile
branches/trac226/src/bin/auth/Makefile.am
branches/trac226/src/bin/auth/auth_srv.cc
branches/trac226/src/bin/auth/auth_srv.h
branches/trac226/src/bin/auth/benchmarks/Makefile.am
branches/trac226/src/bin/auth/benchmarks/query_bench.cc
branches/trac226/src/bin/auth/main.cc
branches/trac226/src/bin/auth/tests/Makefile.am
branches/trac226/src/bin/auth/tests/auth_srv_unittest.cc
branches/trac226/src/bin/auth/tests/query_unittest.cc
branches/trac226/src/bin/auth/tests/testdata/ (props changed)
branches/trac226/src/bin/bind10/bind10.py.in (contents, props changed)
branches/trac226/src/bin/bind10/run_bind10.sh.in
branches/trac226/src/bin/bind10/tests/bind10_test.py
branches/trac226/src/bin/recurse/ (props changed)
branches/trac226/src/lib/Makefile.am
branches/trac226/src/lib/cc/session.cc
branches/trac226/src/lib/config/module_spec.cc
branches/trac226/src/lib/config/tests/module_spec_unittests.cc
branches/trac226/src/lib/config/tests/testdata/Makefile.am
branches/trac226/src/lib/config/tests/testdata/data22_8.data
branches/trac226/src/lib/datasrc/Makefile.am
branches/trac226/src/lib/datasrc/memory_datasrc.cc
branches/trac226/src/lib/datasrc/memory_datasrc.h
branches/trac226/src/lib/datasrc/tests/Makefile.am
branches/trac226/src/lib/datasrc/tests/memory_datasrc_unittest.cc
branches/trac226/src/lib/datasrc/tests/zonetable_unittest.cc
branches/trac226/src/lib/datasrc/zonetable.cc
branches/trac226/src/lib/datasrc/zonetable.h
branches/trac226/src/lib/dns/buffer.h
branches/trac226/src/lib/dns/masterload.h
branches/trac226/src/lib/dns/message.h
branches/trac226/src/lib/dns/messagerenderer.h
branches/trac226/src/lib/dns/tests/unittest_util.cc
branches/trac226/src/lib/dns/tests/unittest_util.h
branches/trac226/src/lib/nsas/address_entry.cc
branches/trac226/src/lib/nsas/hash_key.h
branches/trac226/src/lib/nsas/hash_table.h
branches/trac226/src/lib/nsas/lru_list.h
branches/trac226/src/lib/nsas/nameserver_address.cc
branches/trac226/src/lib/nsas/nameserver_address_store.cc
branches/trac226/src/lib/nsas/nameserver_entry.cc
branches/trac226/src/lib/nsas/nameserver_entry.h
branches/trac226/src/lib/nsas/tests/address_entry_unittest.cc
branches/trac226/src/lib/nsas/tests/fetchable_unittest.cc
branches/trac226/src/lib/nsas/tests/hash_deleter_unittest.cc
branches/trac226/src/lib/nsas/tests/hash_key_unittest.cc
branches/trac226/src/lib/nsas/tests/hash_table_unittest.cc
branches/trac226/src/lib/nsas/tests/hash_unittest.cc
branches/trac226/src/lib/nsas/tests/lru_list_unittest.cc
branches/trac226/src/lib/nsas/tests/nameserver_address_store_unittest.cc
branches/trac226/src/lib/nsas/tests/nameserver_address_unittest.cc
branches/trac226/src/lib/nsas/tests/nameserver_entry_unittest.cc
branches/trac226/src/lib/nsas/tests/nsas_entry_compare_unittest.cc
branches/trac226/src/lib/nsas/tests/random_number_generator_unittest.cc
branches/trac226/src/lib/nsas/tests/run_unittests.cc
branches/trac226/src/lib/nsas/tests/zone_entry_unittest.cc
branches/trac226/src/lib/nsas/zone_entry.cc
branches/trac226/src/lib/nsas/zone_entry.h
branches/trac226/src/lib/python/isc/config/ccsession.py
branches/trac226/src/lib/python/isc/config/config_data.py
branches/trac226/src/lib/python/isc/config/module_spec.py
branches/trac226/src/lib/python/isc/config/tests/ccsession_test.py
branches/trac226/src/lib/python/isc/config/tests/config_data_test.py
branches/trac226/src/lib/python/isc/config/tests/module_spec_test.py
Modified: branches/trac226/ChangeLog
==============================================================================
--- branches/trac226/ChangeLog (original)
+++ branches/trac226/ChangeLog Thu Dec 23 14:58:15 2010
@@ -1,10 +1,38 @@
- 131. [bug] jreed
+ 136. [bug] jreed
Fix run_*.sh scripts that are used for development testing
so they use a msgq socket file in the build tree.
(Trac #226, svn NNNN)
+ 135. [bug] jelte
+ bindctl (and the configuration manager in general) now no longer
+ accepts 'unknown' data; i.e. data for modules that it does not know
+ about, or configuration items that are not specified in the .spec
+ files.
+ (Trac #202, svn r3967)
+
+ 134. [func] vorner
+ b10-recurse supports timeouts and retries in forwarder mode.
+ (Trac #401, svn r3660)
+
+ 133. [func] vorner
+ New temporary logging function available in isc::log. It is used by
+ b10-recurse.
+ (Trac #393, r3602)
+
+ 132. [func] vorner
+ The b10-recursive is configured through config manager.
+ It has "listen_on" and "forward_addresses" options.
+ (Trac #389, r3448)
+
+ 131. [func] feng, jerry
+ src/lib/datasrc: Introduced two template classes RBTree and RBNode
+ to provide the generic map with domain name as key and anything as
+ the value. Because of some unresolved design issue, the new classes
+ are only intended to be used by memory zone and zone table.
+ (Trac #397, svn r3890)
+
130. [func] jerry
- src/lib/datasrc: Introduced a new class MemoryDataSrc to provide
+ src/lib/datasrc: Introduced a new class MemoryDataSrc to provide
the general interface for memory data source. For the initial
implementation, we don't make it a derived class of AbstractDataSrc
because the interface is so different(we'll eventually consider this
Modified: branches/trac226/configure.ac
==============================================================================
--- branches/trac226/configure.ac (original)
+++ branches/trac226/configure.ac Thu Dec 23 14:58:15 2010
@@ -195,14 +195,15 @@
# specify the default warning flags in CXXFLAGS and let specific modules
# "override" the default.
-# This may be used to try compiler flags.
+# This may be used to try linker flags.
AC_DEFUN([BIND10_CXX_TRY_FLAG], [
AC_MSG_CHECKING([whether $CXX supports $1])
bind10_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $1"
- AC_COMPILE_IFELSE([ ], [bind10_cxx_flag=yes], [bind10_cxx_flag=no])
+ AC_LINK_IFELSE([int main(void){ return 0;} ],
+ [bind10_cxx_flag=yes], [bind10_cxx_flag=no])
CXXFLAGS="$bind10_save_CXXFLAGS"
if test "x$bind10_cxx_flag" = "xyes"; then
@@ -367,13 +368,31 @@
LIBS_SAVES="$LIBS"
CPPFLAGS="$BOOST_INCLUDES $CPPFLAGS $MULTITHREADING_FLAG"
need_libboost_thread=0
+need_sunpro_workaround=0
AC_TRY_LINK([
#include <boost/thread.hpp>
],[
boost::mutex m;
],
[ AC_MSG_RESULT(yes (without libboost_thread)) ],
- [ LIBS=" $LIBS -lboost_thread"
+
+ # there is one specific problem with SunStudio 5.10
+ # where including boost/thread causes a compilation failure
+ # There is a workaround in boost but it checks the version not being 5.10
+ # This will probably be fixed in the future, in which case this
+ # is only a temporary workaround
+ [ AC_TRY_LINK([
+#if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100
+#undef __SUNPRO_CC
+#define __SUNPRO_CC 0x5090
+#endif
+#include <boost/thread.hpp>
+],[
+boost::mutex m;
+],
+ [ AC_MSG_RESULT(yes (with SUNOS workaround))
+ need_sunpro_workaround=1 ],
+ [ LIBS=" $LIBS -lboost_thread"
AC_TRY_LINK([
#include <boost/thread.hpp>
],[
@@ -385,10 +404,13 @@
AC_MSG_ERROR([boost::mutex cannot be linked in this build environment.
Perhaps you are using an older version of Boost that requires libboost_thread for the mutex support, which does not appear to be available.
You may want to check the availability of the library or to upgrade Boost.])
- ])])
+ ])])])
CPPFLAGS="$CPPFLAGS_SAVES"
LIBS="$LIBS_SAVES"
AM_CONDITIONAL(NEED_LIBBOOST_THREAD, test $need_libboost_thread = 1)
+if test $need_sunpro_workaround = 1; then
+ AC_DEFINE([NEED_SUNPRO_WORKAROUND], [], [Need boost sunstudio workaround])
+fi
#
# Check availability of gtest, which will be used for unit tests.
@@ -534,9 +556,9 @@
src/bin/msgq/tests/Makefile
src/bin/auth/Makefile
src/bin/auth/tests/Makefile
- src/bin/auth/tests/testdata/Makefile
src/bin/auth/benchmarks/Makefile
src/bin/recurse/Makefile
+ src/bin/recurse/tests/Makefile
src/bin/xfrin/Makefile
src/bin/xfrin/tests/Makefile
src/bin/xfrout/Makefile
@@ -553,6 +575,8 @@
src/bin/usermgr/Makefile
src/bin/tests/Makefile
src/lib/Makefile
+ src/lib/asiolink/Makefile
+ src/lib/asiolink/tests/Makefile
src/lib/bench/Makefile
src/lib/bench/example/Makefile
src/lib/bench/tests/Makefile
@@ -587,6 +611,9 @@
src/lib/datasrc/Makefile
src/lib/datasrc/tests/Makefile
src/lib/xfr/Makefile
+ src/lib/log/Makefile
+ src/lib/testutils/Makefile
+ src/lib/testutils/testdata/Makefile
src/lib/nsas/Makefile
src/lib/nsas/tests/Makefile
])
@@ -603,9 +630,8 @@
src/bin/xfrout/xfrout.spec.pre
src/bin/xfrout/tests/xfrout_test
src/bin/xfrout/run_b10-xfrout.sh
- src/bin/recurse/recurse.py
src/bin/recurse/recurse.spec.pre
- src/bin/recurse/run_b10-recurse.sh
+ src/bin/recurse/spec_config.h.pre
src/bin/zonemgr/zonemgr.py
src/bin/zonemgr/zonemgr.spec.pre
src/bin/zonemgr/tests/zonemgr_test
Modified: branches/trac226/doc/Doxyfile
==============================================================================
--- branches/trac226/doc/Doxyfile (original)
+++ branches/trac226/doc/Doxyfile Thu Dec 23 14:58:15 2010
@@ -568,7 +568,7 @@
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
-INPUT = ../src/lib/cc ../src/lib/config ../src/lib/dns ../src/lib/exceptions ../src/lib/datasrc ../src/bin/auth ../src/lib/bench ../src/lib/nsas
+INPUT = ../src/lib/cc ../src/lib/config ../src/lib/dns ../src/lib/exceptions ../src/lib/datasrc ../src/bin/auth ../src/lib/bench ../src/lib/log ../src/lib/asiolink/ ../src/lib/nsas
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
Modified: branches/trac226/src/bin/auth/Makefile.am
==============================================================================
--- branches/trac226/src/bin/auth/Makefile.am (original)
+++ branches/trac226/src/bin/auth/Makefile.am Thu Dec 23 14:58:15 2010
@@ -3,8 +3,9 @@
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
-AM_CPPFLAGS += -I$(top_builddir)/src/lib/cc
-AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
+AM_CPPFLAGS += -I$(top_srcdir)/src/lib/cc -I$(top_builddir)/src/lib/cc
+AM_CPPFLAGS += -I$(top_srcdir)/src/lib/asiolink
+AM_CPPFLAGS += -I$(top_builddir)/src/lib/asiolink
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CXXFLAGS = $(B10_CXXFLAGS)
@@ -33,26 +34,6 @@
spec_config.h: spec_config.h.pre
$(SED) -e "s|@@LOCALSTATEDIR@@|$(localstatedir)|" spec_config.h.pre >$@
-# This is a wrapper library solely used for b10-auth. The ASIO header files
-# have some code fragments that would hit gcc's unused-parameter warning,
-# which would make the build fail with -Werror (our default setting).
-# We don't want to lower the warning level for our own code just for ASIO,
-# so as a workaround we extract the ASIO related code into a separate library,
-# only for which we accept the unused-parameter warning.
-lib_LIBRARIES = libasio_link.a
-libasio_link_a_SOURCES = asio_link.cc asio_link.h
-# Note: the ordering matters: -Wno-... must follow -Wextra (defined in
-# B10_CXXFLAGS)
-libasio_link_a_CXXFLAGS = $(AM_CXXFLAGS)
-if USE_GXX
-libasio_link_a_CXXFLAGS += -Wno-unused-parameter
-endif
-if USE_CLANGPP
-# Same for clang++, but we need to turn off -Werror completely.
-libasio_link_a_CXXFLAGS += -Wno-error
-endif
-libasio_link_a_CPPFLAGS = $(AM_CPPFLAGS)
-
BUILT_SOURCES = spec_config.h
pkglibexec_PROGRAMS = b10-auth
b10_auth_SOURCES = auth_srv.cc auth_srv.h
@@ -65,7 +46,7 @@
b10_auth_LDADD += $(top_builddir)/src/lib/config/libcfgclient.la
b10_auth_LDADD += $(top_builddir)/src/lib/cc/libcc.la
b10_auth_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
-b10_auth_LDADD += libasio_link.a
+b10_auth_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
b10_auth_LDADD += $(top_builddir)/src/lib/xfr/libxfr.la
b10_auth_LDADD += $(SQLITE_LIBS)
Modified: branches/trac226/src/bin/auth/auth_srv.cc
==============================================================================
--- branches/trac226/src/bin/auth/auth_srv.cc (original)
+++ branches/trac226/src/bin/auth/auth_srv.cc Thu Dec 23 14:58:15 2010
@@ -14,12 +14,20 @@
// $Id$
+#include <config.h>
+
#include <netinet/in.h>
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
+
+#include <asiolink/asiolink.h>
+
+#include <config/ccsession.h>
+
+#include <cc/data.h>
#include <exceptions/exceptions.h>
@@ -34,22 +42,16 @@
#include <dns/rrset.h>
#include <dns/rrttl.h>
#include <dns/message.h>
-#include <config/ccsession.h>
-#include <cc/data.h>
-#include <exceptions/exceptions.h>
#include <datasrc/query.h>
#include <datasrc/data_source.h>
#include <datasrc/static_datasrc.h>
#include <datasrc/sqlite3_datasrc.h>
-#include <cc/data.h>
-
#include <xfr/xfrout_client.h>
#include <auth/common.h>
#include <auth/auth_srv.h>
-#include <auth/asio_link.h>
using namespace std;
@@ -61,7 +63,7 @@
using namespace isc::data;
using namespace isc::config;
using namespace isc::xfr;
-using namespace asio_link;
+using namespace asiolink;
class AuthSrvImpl {
private:
@@ -73,32 +75,34 @@
~AuthSrvImpl();
isc::data::ConstElementPtr setDbFile(isc::data::ConstElementPtr config);
- bool processNormalQuery(const IOMessage& io_message, Message& message,
- MessageRenderer& response_renderer);
- bool processAxfrQuery(const IOMessage& io_message, Message& message,
- MessageRenderer& response_renderer);
- bool processNotify(const IOMessage& io_message, Message& message,
- MessageRenderer& response_renderer);
+ bool processNormalQuery(const IOMessage& io_message, MessagePtr message,
+ OutputBufferPtr buffer);
+ bool processAxfrQuery(const IOMessage& io_message, MessagePtr message,
+ OutputBufferPtr buffer);
+ bool processNotify(const IOMessage& io_message, MessagePtr message,
+ OutputBufferPtr buffer);
+
+ /// Currently non-configurable, but will be.
+ static const uint16_t DEFAULT_LOCAL_UDPSIZE = 4096;
+
+ /// These members are public because AuthSrv accesses them directly.
+ ModuleCCSession* config_session_;
+ bool verbose_mode_;
+ AbstractSession* xfrin_session_;
+
+ /// Hot spot cache
+ isc::datasrc::HotCache cache_;
+private:
std::string db_file_;
- ModuleCCSession* config_session_;
+
MetaDataSrc data_sources_;
/// We keep a pointer to the currently running sqlite datasource
/// so that we can specifically remove that one should the database
/// file change
ConstDataSrcPtr cur_datasrc_;
- bool verbose_mode_;
-
- AbstractSession* xfrin_session_;
-
bool xfrout_connected_;
AbstractXfroutClient& xfrout_client_;
-
- /// Currently non-configurable, but will be.
- static const uint16_t DEFAULT_LOCAL_UDPSIZE = 4096;
-
- /// Hot spot cache
- isc::datasrc::HotCache cache_;
};
AuthSrvImpl::AuthSrvImpl(const bool use_cache,
@@ -126,60 +130,127 @@
}
}
+// This is a derived class of \c DNSLookup, to serve as a
+// callback in the asiolink module. It calls
+// AuthSrv::processMessage() on a single DNS message.
+class MessageLookup : public DNSLookup {
+public:
+ MessageLookup(AuthSrv* srv) : server_(srv) {}
+ virtual void operator()(const IOMessage& io_message, MessagePtr message,
+ OutputBufferPtr buffer, DNSServer* server) const
+ {
+ server_->processMessage(io_message, message, buffer, server);
+ }
+private:
+ AuthSrv* server_;
+};
+
+// This is a derived class of \c DNSAnswer, to serve as a
+// callback in the asiolink module. It takes a completed
+// set of answer data from the DNS lookup and assembles it
+// into a wire-format response.
+class MessageAnswer : public DNSAnswer {
+public:
+ MessageAnswer(AuthSrv* srv) : server_(srv) {}
+ virtual void operator()(const IOMessage& io_message, MessagePtr message,
+ OutputBufferPtr buffer) const
+ {
+ MessageRenderer renderer(*buffer);
+ if (io_message.getSocket().getProtocol() == IPPROTO_UDP) {
+ ConstEDNSPtr edns(message->getEDNS());
+ renderer.setLengthLimit(edns ? edns->getUDPSize() :
+ Message::DEFAULT_MAX_UDPSIZE);
+ } else {
+ renderer.setLengthLimit(65535);
+ }
+ message->toWire(renderer);
+ if (server_->getVerbose()) {
+ cerr << "[b10-auth] sending a response (" << renderer.getLength()
+ << " bytes):\n" << message->toText() << endl;
+ }
+ }
+
+private:
+ AuthSrv* server_;
+};
+
+// This is a derived class of \c SimpleCallback, to serve
+// as a callback in the asiolink module. It checks for queued
+// configuration messages, and executes them if found.
+class ConfigChecker : public SimpleCallback {
+public:
+ ConfigChecker(AuthSrv* srv) : server_(srv) {}
+ virtual void operator()(const IOMessage&) const {
+ if (server_->getConfigSession()->hasQueuedMsgs()) {
+ server_->getConfigSession()->checkCommand();
+ }
+ }
+private:
+ AuthSrv* server_;
+};
+
AuthSrv::AuthSrv(const bool use_cache, AbstractXfroutClient& xfrout_client) :
- impl_(new AuthSrvImpl(use_cache, xfrout_client))
+ impl_(new AuthSrvImpl(use_cache, xfrout_client)),
+ checkin_(new ConfigChecker(this)),
+ dns_lookup_(new MessageLookup(this)),
+ dns_answer_(new MessageAnswer(this))
{}
AuthSrv::~AuthSrv() {
delete impl_;
+ delete checkin_;
+ delete dns_lookup_;
+ delete dns_answer_;
}
namespace {
class QuestionInserter {
public:
- QuestionInserter(Message* message) : message_(message) {}
+ QuestionInserter(MessagePtr message) : message_(message) {}
void operator()(const QuestionPtr question) {
message_->addQuestion(question);
}
- Message* message_;
+ MessagePtr message_;
};
void
-makeErrorMessage(Message& message, MessageRenderer& renderer,
+makeErrorMessage(MessagePtr message, OutputBufferPtr buffer,
const Rcode& rcode, const bool verbose_mode)
{
// extract the parameters that should be kept.
// XXX: with the current implementation, it's not easy to set EDNS0
// depending on whether the query had it. So we'll simply omit it.
- const qid_t qid = message.getQid();
- const bool rd = message.getHeaderFlag(Message::HEADERFLAG_RD);
- const bool cd = message.getHeaderFlag(Message::HEADERFLAG_CD);
- const Opcode& opcode = message.getOpcode();
+ const qid_t qid = message->getQid();
+ const bool rd = message->getHeaderFlag(Message::HEADERFLAG_RD);
+ const bool cd = message->getHeaderFlag(Message::HEADERFLAG_CD);
+ const Opcode& opcode = message->getOpcode();
vector<QuestionPtr> questions;
// If this is an error to a query or notify, we should also copy the
// question section.
if (opcode == Opcode::QUERY() || opcode == Opcode::NOTIFY()) {
- questions.assign(message.beginQuestion(), message.endQuestion());
- }
-
- message.clear(Message::RENDER);
- message.setQid(qid);
- message.setOpcode(opcode);
- message.setHeaderFlag(Message::HEADERFLAG_QR);
+ questions.assign(message->beginQuestion(), message->endQuestion());
+ }
+
+ message->clear(Message::RENDER);
+ message->setQid(qid);
+ message->setOpcode(opcode);
+ message->setHeaderFlag(Message::HEADERFLAG_QR);
if (rd) {
- message.setHeaderFlag(Message::HEADERFLAG_RD);
+ message->setHeaderFlag(Message::HEADERFLAG_RD);
}
if (cd) {
- message.setHeaderFlag(Message::HEADERFLAG_CD);
- }
- for_each(questions.begin(), questions.end(), QuestionInserter(&message));
- message.setRcode(rcode);
- message.toWire(renderer);
+ message->setHeaderFlag(Message::HEADERFLAG_CD);
+ }
+ for_each(questions.begin(), questions.end(), QuestionInserter(message));
+ message->setRcode(rcode);
+
+ MessageRenderer renderer(*buffer);
+ message->toWire(renderer);
if (verbose_mode) {
cerr << "[b10-auth] sending an error response (" <<
- renderer.getLength() << " bytes):\n" << message.toText() << endl;
+ renderer.getLength() << " bytes):\n" << message->toText() << endl;
}
}
}
@@ -219,143 +290,147 @@
return (impl_->config_session_);
}
-bool
-AuthSrv::processMessage(const IOMessage& io_message, Message& message,
- MessageRenderer& response_renderer)
+void
+AuthSrv::processMessage(const IOMessage& io_message, MessagePtr message,
+ OutputBufferPtr buffer, DNSServer* server)
{
InputBuffer request_buffer(io_message.getData(), io_message.getDataSize());
// First, check the header part. If we fail even for the base header,
// just drop the message.
try {
- message.parseHeader(request_buffer);
+ message->parseHeader(request_buffer);
// Ignore all responses.
- if (message.getHeaderFlag(Message::HEADERFLAG_QR)) {
+ if (message->getHeaderFlag(Message::HEADERFLAG_QR)) {
if (impl_->verbose_mode_) {
cerr << "[b10-auth] received unexpected response, ignoring"
<< endl;
}
- return (false);
+ server->resume(false);
+ return;
}
} catch (const Exception& ex) {
- return (false);
- }
-
- // Parse the message. On failure, return an appropriate error.
+ if (impl_->verbose_mode_) {
+ cerr << "[b10-auth] DNS packet exception: " << ex.what() << endl;
+ }
+ server->resume(false);
+ return;
+ }
+
try {
- message.fromWire(request_buffer);
+ // Parse the message.
+ message->fromWire(request_buffer);
} catch (const DNSProtocolError& error) {
if (impl_->verbose_mode_) {
cerr << "[b10-auth] returning " << error.getRcode().toText()
<< ": " << error.what() << endl;
}
- makeErrorMessage(message, response_renderer, error.getRcode(),
+ makeErrorMessage(message, buffer, error.getRcode(),
impl_->verbose_mode_);
- return (true);
+ server->resume(true);
+ return;
} catch (const Exception& ex) {
if (impl_->verbose_mode_) {
cerr << "[b10-auth] returning SERVFAIL: " << ex.what() << endl;
}
- makeErrorMessage(message, response_renderer, Rcode::SERVFAIL(),
+ makeErrorMessage(message, buffer, Rcode::SERVFAIL(),
impl_->verbose_mode_);
- return (true);
+ server->resume(true);
+ return;
} // other exceptions will be handled at a higher layer.
if (impl_->verbose_mode_) {
- cerr << "[b10-auth] received a message:\n" << message.toText() << endl;
+ cerr << "[b10-auth] received a message:\n" << message->toText() << endl;
}
// Perform further protocol-level validation.
- if (message.getOpcode() == Opcode::NOTIFY()) {
- return (impl_->processNotify(io_message, message, response_renderer));
- } else if (message.getOpcode() != Opcode::QUERY()) {
+ bool sendAnswer = true;
+ if (message->getOpcode() == Opcode::NOTIFY()) {
+ sendAnswer = impl_->processNotify(io_message, message, buffer);
+ } else if (message->getOpcode() != Opcode::QUERY()) {
if (impl_->verbose_mode_) {
cerr << "[b10-auth] unsupported opcode" << endl;
}
- makeErrorMessage(message, response_renderer, Rcode::NOTIMP(),
+ makeErrorMessage(message, buffer, Rcode::NOTIMP(),
impl_->verbose_mode_);
- return (true);
- }
-
- if (message.getRRCount(Message::SECTION_QUESTION) != 1) {
- makeErrorMessage(message, response_renderer, Rcode::FORMERR(),
+ } else if (message->getRRCount(Message::SECTION_QUESTION) != 1) {
+ makeErrorMessage(message, buffer, Rcode::FORMERR(),
impl_->verbose_mode_);
- return (true);
- }
-
- ConstQuestionPtr question = *message.beginQuestion();
- const RRType &qtype = question->getType();
- if (qtype == RRType::AXFR()) {
- return (impl_->processAxfrQuery(io_message, message,
- response_renderer));
- } else if (qtype == RRType::IXFR()) {
- makeErrorMessage(message, response_renderer, Rcode::NOTIMP(),
- impl_->verbose_mode_);
- return (true);
} else {
- return (impl_->processNormalQuery(io_message, message,
- response_renderer));
- }
+ ConstQuestionPtr question = *message->beginQuestion();
+ const RRType &qtype = question->getType();
+ if (qtype == RRType::AXFR()) {
+ sendAnswer = impl_->processAxfrQuery(io_message, message, buffer);
+ } else if (qtype == RRType::IXFR()) {
+ makeErrorMessage(message, buffer, Rcode::NOTIMP(),
+ impl_->verbose_mode_);
+ } else {
+ sendAnswer = impl_->processNormalQuery(io_message, message, buffer);
+ }
+ }
+
+ server->resume(sendAnswer);
}
bool
-AuthSrvImpl::processNormalQuery(const IOMessage& io_message, Message& message,
- MessageRenderer& response_renderer)
+AuthSrvImpl::processNormalQuery(const IOMessage& io_message, MessagePtr message,
+ OutputBufferPtr buffer)
{
- ConstEDNSPtr remote_edns = message.getEDNS();
+ ConstEDNSPtr remote_edns = message->getEDNS();
const bool dnssec_ok = remote_edns && remote_edns->getDNSSECAwareness();
const uint16_t remote_bufsize = remote_edns ? remote_edns->getUDPSize() :
Message::DEFAULT_MAX_UDPSIZE;
- message.makeResponse();
- message.setHeaderFlag(Message::HEADERFLAG_AA);
- message.setRcode(Rcode::NOERROR());
+ message->makeResponse();
+ message->setHeaderFlag(Message::HEADERFLAG_AA);
+ message->setRcode(Rcode::NOERROR());
if (remote_edns) {
EDNSPtr local_edns = EDNSPtr(new EDNS());
local_edns->setDNSSECAwareness(dnssec_ok);
local_edns->setUDPSize(AuthSrvImpl::DEFAULT_LOCAL_UDPSIZE);
- message.setEDNS(local_edns);
+ message->setEDNS(local_edns);
}
try {
- Query query(message, cache_, dnssec_ok);
+ Query query(*message, cache_, dnssec_ok);
data_sources_.doQuery(query);
} catch (const Exception& ex) {
if (verbose_mode_) {
cerr << "[b10-auth] Internal error, returning SERVFAIL: " <<
ex.what() << endl;
}
- makeErrorMessage(message, response_renderer, Rcode::SERVFAIL(),
- verbose_mode_);
+ makeErrorMessage(message, buffer, Rcode::SERVFAIL(), verbose_mode_);
return (true);
}
+
+ MessageRenderer renderer(*buffer);
const bool udp_buffer =
(io_message.getSocket().getProtocol() == IPPROTO_UDP);
- response_renderer.setLengthLimit(udp_buffer ? remote_bufsize : 65535);
- message.toWire(response_renderer);
+ renderer.setLengthLimit(udp_buffer ? remote_bufsize : 65535);
+ message->toWire(renderer);
+
if (verbose_mode_) {
cerr << "[b10-auth] sending a response ("
- << response_renderer.getLength()
- << " bytes):\n" << message.toText() << endl;
+ << renderer.getLength()
+ << " bytes):\n" << message->toText() << endl;
}
return (true);
}
bool
-AuthSrvImpl::processAxfrQuery(const IOMessage& io_message, Message& message,
- MessageRenderer& response_renderer)
+AuthSrvImpl::processAxfrQuery(const IOMessage& io_message, MessagePtr message,
+ OutputBufferPtr buffer)
{
if (io_message.getSocket().getProtocol() == IPPROTO_UDP) {
if (verbose_mode_) {
cerr << "[b10-auth] AXFR query over UDP isn't allowed" << endl;
}
- makeErrorMessage(message, response_renderer, Rcode::FORMERR(),
- verbose_mode_);
+ makeErrorMessage(message, buffer, Rcode::FORMERR(), verbose_mode_);
return (true);
}
@@ -382,8 +457,7 @@
cerr << "[b10-auth] Error in handling XFR request: " << err.what()
<< endl;
}
- makeErrorMessage(message, response_renderer, Rcode::SERVFAIL(),
- verbose_mode_);
+ makeErrorMessage(message, buffer, Rcode::SERVFAIL(), verbose_mode_);
return (true);
}
@@ -391,28 +465,26 @@
}
bool
-AuthSrvImpl::processNotify(const IOMessage& io_message, Message& message,
- MessageRenderer& response_renderer)
+AuthSrvImpl::processNotify(const IOMessage& io_message, MessagePtr message,
+ OutputBufferPtr buffer)
{
// The incoming notify must contain exactly one question for SOA of the
// zone name.
- if (message.getRRCount(Message::SECTION_QUESTION) != 1) {
+ if (message->getRRCount(Message::SECTION_QUESTION) != 1) {
if (verbose_mode_) {
cerr << "[b10-auth] invalid number of questions in notify: "
- << message.getRRCount(Message::SECTION_QUESTION) << endl;
- }
- makeErrorMessage(message, response_renderer, Rcode::FORMERR(),
- verbose_mode_);
+ << message->getRRCount(Message::SECTION_QUESTION) << endl;
+ }
+ makeErrorMessage(message, buffer, Rcode::FORMERR(), verbose_mode_);
return (true);
}
- ConstQuestionPtr question = *message.beginQuestion();
+ ConstQuestionPtr question = *message->beginQuestion();
if (question->getType() != RRType::SOA()) {
if (verbose_mode_) {
cerr << "[b10-auth] invalid question RR type in notify: "
<< question->getType() << endl;
}
- makeErrorMessage(message, response_renderer, Rcode::FORMERR(),
- verbose_mode_);
+ makeErrorMessage(message, buffer, Rcode::FORMERR(), verbose_mode_);
return (true);
}
@@ -470,10 +542,12 @@
return (false);
}
- message.makeResponse();
- message.setHeaderFlag(Message::HEADERFLAG_AA);
- message.setRcode(Rcode::NOERROR());
- message.toWire(response_renderer);
+ message->makeResponse();
+ message->setHeaderFlag(Message::HEADERFLAG_AA);
+ message->setRcode(Rcode::NOERROR());
+
+ MessageRenderer renderer(*buffer);
+ message->toWire(renderer);
return (true);
}
Modified: branches/trac226/src/bin/auth/auth_srv.h
==============================================================================
--- branches/trac226/src/bin/auth/auth_srv.h (original)
+++ branches/trac226/src/bin/auth/auth_srv.h Thu Dec 23 14:58:15 2010
@@ -22,20 +22,12 @@
#include <cc/data.h>
#include <config/ccsession.h>
+#include <asiolink/asiolink.h>
+
namespace isc {
-namespace dns {
-class InputBuffer;
-class Message;
-class MessageRenderer;
-}
-
namespace xfr {
class AbstractXfroutClient;
-};
}
-
-namespace asio_link {
-class IOMessage;
}
/// \brief The implementation class for the \c AuthSrv class using the pimpl
@@ -84,11 +76,26 @@
isc::xfr::AbstractXfroutClient& xfrout_client);
~AuthSrv();
//@}
- /// \return \c true if the \a message contains a response to be returned;
- /// otherwise \c false.
- bool processMessage(const asio_link::IOMessage& io_message,
- isc::dns::Message& message,
- isc::dns::MessageRenderer& response_renderer);
+
+ /// \brief Process an incoming DNS message, then signal 'server' to resume
+ ///
+ /// A DNS query (or other message) has been received by a \c DNSServer
+ /// object. Find an answer, then post the \c DNSServer object on the
+ /// I/O service queue and return. When the server resumes, it can
+ /// send the reply.
+ ///
+ /// \param io_message The raw message received
+ /// \param message Pointer to the \c Message object
+ /// \param buffer Pointer to an \c OutputBuffer for the resposne
+ /// \param server Pointer to the \c DNSServer
+ void processMessage(const asiolink::IOMessage& io_message,
+ isc::dns::MessagePtr message,
+ isc::dns::OutputBufferPtr buffer,
+ asiolink::DNSServer* server);
+
+ /// \brief Set verbose flag
+ ///
+ /// \param on The new value of the verbose flag
/// \brief Enable or disable verbose logging.
///
@@ -103,6 +110,8 @@
/// This method never throws an exception.
///
/// \return \c true if verbose logging is enabled; otherwise \c false.
+
+ /// \brief Get the current value of the verbose flag
bool getVerbose() const;
/// \brief Updates the data source for the \c AuthSrv object.
@@ -161,6 +170,21 @@
/// \param config_session A pointer to \c ModuleCCSession object to receive
/// control commands and configuration updates.
void setConfigSession(isc::config::ModuleCCSession* config_session);
+
+ /// \brief Assign an ASIO IO Service queue to this Recursor object
+ void setIOService(asiolink::IOService& ios) { io_service_ = &ios; }
+
+ /// \brief Return this object's ASIO IO Service queue
+ asiolink::IOService& getIOService() const { return (*io_service_); }
+
+ /// \brief Return pointer to the DNS Lookup callback function
+ asiolink::DNSLookup* getDNSLookupProvider() const { return (dns_lookup_); }
+
+ /// \brief Return pointer to the DNS Answer callback function
+ asiolink::DNSAnswer* getDNSAnswerProvider() const { return (dns_answer_); }
+
+ /// \brief Return pointer to the Checkin callback function
+ asiolink::SimpleCallback* getCheckinProvider() const { return (checkin_); }
/// \brief Set or update the size (number of slots) of hot spot cache.
///
@@ -202,6 +226,10 @@
private:
AuthSrvImpl* impl_;
+ asiolink::IOService* io_service_;
+ asiolink::SimpleCallback* checkin_;
+ asiolink::DNSLookup* dns_lookup_;
+ asiolink::DNSAnswer* dns_answer_;
};
#endif // __AUTH_SRV_H
Modified: branches/trac226/src/bin/auth/benchmarks/Makefile.am
==============================================================================
--- branches/trac226/src/bin/auth/benchmarks/Makefile.am (original)
+++ branches/trac226/src/bin/auth/benchmarks/Makefile.am Thu Dec 23 14:58:15 2010
@@ -17,5 +17,5 @@
query_bench_LDADD += $(top_builddir)/src/lib/config/libcfgclient.la
query_bench_LDADD += $(top_builddir)/src/lib/cc/libcc.la
query_bench_LDADD += $(top_builddir)/src/lib/xfr/libxfr.la
-query_bench_LDADD += $(top_builddir)/src/bin/auth/libasio_link.a
+query_bench_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
query_bench_LDADD += $(SQLITE_LIBS)
Modified: branches/trac226/src/bin/auth/benchmarks/query_bench.cc
==============================================================================
--- branches/trac226/src/bin/auth/benchmarks/query_bench.cc (original)
+++ branches/trac226/src/bin/auth/benchmarks/query_bench.cc Thu Dec 23 14:58:15 2010
@@ -26,7 +26,6 @@
#include <dns/buffer.h>
#include <dns/message.h>
-#include <dns/messagerenderer.h>
#include <dns/name.h>
#include <dns/question.h>
#include <dns/rrclass.h>
@@ -34,7 +33,7 @@
#include <xfr/xfrout_client.h>
#include <auth/auth_srv.h>
-#include <auth/asio_link.h>
+#include <asiolink/asiolink.h>
using namespace std;
using namespace isc;
@@ -42,11 +41,21 @@
using namespace isc::dns;
using namespace isc::xfr;
using namespace isc::bench;
-using namespace asio_link;
+using namespace asiolink;
namespace {
// Commonly used constant:
XfroutClient xfrout_client("dummy_path"); // path doesn't matter
+
+// Just something to pass as the server to resume
+class DummyServer : public DNSServer {
+ public:
+ virtual void operator()(asio::error_code, size_t) { }
+ virtual void resume(const bool) { }
+ virtual DNSServer* clone() {
+ return new DummyServer(*this);
+ }
+};
class QueryBenchMark {
private:
@@ -56,12 +65,12 @@
typedef boost::shared_ptr<const IOEndpoint> IOEndpointPtr;
public:
QueryBenchMark(const int cache_slots, const char* const datasrc_file,
- const BenchQueries& queries, Message& query_message,
- MessageRenderer& renderer) :
+ const BenchQueries& queries, MessagePtr query_message,
+ OutputBufferPtr buffer) :
server_(new AuthSrv(cache_slots >= 0 ? true : false, xfrout_client)),
queries_(queries),
query_message_(query_message),
- renderer_(renderer),
+ buffer_(buffer),
dummy_socket(IOSocket::getDummyUDPSocket()),
dummy_endpoint(IOEndpointPtr(IOEndpoint::create(IPPROTO_UDP,
IOAddress("192.0.2.1"),
@@ -76,12 +85,13 @@
unsigned int run() {
BenchQueries::const_iterator query;
const BenchQueries::const_iterator query_end = queries_.end();
+ DummyServer server;
for (query = queries_.begin(); query != query_end; ++query) {
IOMessage io_message(&(*query)[0], (*query).size(), dummy_socket,
*dummy_endpoint);
- query_message_.clear(Message::PARSE);
- renderer_.clear();
- server_->processMessage(io_message, query_message_, renderer_);
+ query_message_->clear(Message::PARSE);
+ server_->processMessage(io_message, query_message_, buffer_,
+ &server);
}
return (queries_.size());
@@ -89,11 +99,12 @@
private:
AuthSrvPtr server_;
const BenchQueries& queries_;
- Message& query_message_;
- MessageRenderer& renderer_;
+ MessagePtr query_message_;
+ OutputBufferPtr buffer_;
IOSocket& dummy_socket;
IOEndpointPtr dummy_endpoint;
};
+
}
namespace isc {
@@ -143,9 +154,8 @@
BenchQueries queries;
loadQueryData(query_data_file, queries, RRClass::IN());
- OutputBuffer buffer(4096);
- MessageRenderer renderer(buffer);
- Message message(Message::PARSE);
+ OutputBufferPtr buffer(new OutputBuffer(4096));
+ MessagePtr message(new Message(Message::PARSE));
cout << "Parameters:" << endl;
cout << " Iterations: " << iteration << endl;
@@ -157,24 +167,24 @@
<< endl;
BenchMark<QueryBenchMark>(iteration,
QueryBenchMark(0, datasrc_file, queries, message,
- renderer));
+ buffer));
cout << "Benchmark enabling Hot Spot Cache with 10*#queries slots "
<< endl;
BenchMark<QueryBenchMark>(iteration,
QueryBenchMark(10 * queries.size(), datasrc_file,
- queries, message, renderer));
+ queries, message, buffer));
cout << "Benchmark enabling Hot Spot Cache with #queries/2 slots "
<< endl;
BenchMark<QueryBenchMark>(iteration,
QueryBenchMark(queries.size() / 2, datasrc_file,
- queries, message, renderer));
+ queries, message, buffer));
cout << "Benchmark disabling Hot Spot Cache" << endl;
BenchMark<QueryBenchMark>(iteration,
QueryBenchMark(-1, datasrc_file, queries,
- message, renderer));
+ message, buffer));
return (0);
}
Modified: branches/trac226/src/bin/auth/main.cc
==============================================================================
--- branches/trac226/src/bin/auth/main.cc (original)
+++ branches/trac226/src/bin/auth/main.cc Thu Dec 23 14:58:15 2010
@@ -43,7 +43,7 @@
#include <auth/common.h>
#include <auth/change_user.h>
#include <auth/auth_srv.h>
-#include <auth/asio_link.h>
+#include <asiolink/asiolink.h>
using namespace std;
using namespace isc::data;
@@ -51,20 +51,22 @@
using namespace isc::config;
using namespace isc::dns;
using namespace isc::xfr;
+using namespace asiolink;
namespace {
-bool verbose_mode = false;
-
-const string PROGRAM = "Auth";
-const char* DNSPORT = "5300";
+static bool verbose_mode = false;
+
+// Default port current 5300 for testing purposes
+static const string PROGRAM = "Auth";
+static const char* DNSPORT = "5300";
/* need global var for config/command handlers.
* todo: turn this around, and put handlers in the authserver
* class itself? */
-AuthSrv *auth_server;
-
-asio_link::IOService* io_service;
+static AuthSrv *auth_server;
+
+static IOService io_service;
ConstElementPtr
my_config_handler(ConstElementPtr new_config) {
@@ -80,7 +82,7 @@
/* let's add that message to our answer as well */
answer = createAnswer(0, args);
} else if (command == "shutdown") {
- io_service->stop();
+ io_service.stop();
}
return (answer);
@@ -88,7 +90,16 @@
void
usage() {
- cerr << "Usage: b10-auth [-a address] [-p port] [-4|-6] [-nv]" << endl;
+ cerr << "Usage: b10-auth [-a address] [-p port] [-u user] [-4|-6] [-nv]"
+ << endl;
+ cerr << "\t-a: specify the address to listen on (default: all) " << endl;
+ cerr << "\t-p: specify the port to listen on (default: " << DNSPORT << ")"
+ << endl;
+ cerr << "\t-4: listen on all IPv4 addresses (incompatible with -a)" << endl;
+ cerr << "\t-6: listen on all IPv6 addresses (incompatible with -a)" << endl;
+ cerr << "\t-n: do not cache answers in memory" << endl;
+ cerr << "\t-u: change process UID to the specified user" << endl;
+ cerr << "\t-v: verbose output" << endl;
exit(1);
}
} // end of anonymous namespace
@@ -140,12 +151,14 @@
}
if (!use_ipv4 && !use_ipv6) {
- cerr << "[b10-auth] Error: -4 and -6 can't coexist" << endl;
+ cerr << "[b10-auth] Error: Cannot specify both -4 and -6 "
+ << "at the same time" << endl;
usage();
}
if ((!use_ipv4 || !use_ipv6) && address != NULL) {
- cerr << "[b10-auth] Error: -4|-6 and -a can't coexist" << endl;
+ cerr << "[b10-auth] Error: Cannot specify -4 or -6 "
+ << "at the same time as -a" << endl;
usage();
}
@@ -176,6 +189,11 @@
auth_server->setVerbose(verbose_mode);
cout << "[b10-auth] Server created." << endl;
+ SimpleCallback* checkin = auth_server->getCheckinProvider();
+ DNSLookup* lookup = auth_server->getDNSLookupProvider();
+ DNSAnswer* answer = auth_server->getDNSAnswerProvider();
+
+ DNSService* dns_service;
if (address != NULL) {
// XXX: we can only specify at most one explicit address.
// This also means the server cannot run in the dual address
@@ -183,15 +201,17 @@
// We don't bother to fix this problem, however. The -a option
// is a short term workaround until we support dynamic listening
// port allocation.
- io_service = new asio_link::IOService(auth_server, *port,
- *address);
+ dns_service = new DNSService(io_service, *port, *address,
+ checkin, lookup, answer);
} else {
- io_service = new asio_link::IOService(auth_server, *port,
- use_ipv4, use_ipv6);
- }
+ dns_service = new DNSService(io_service, *port, use_ipv4,
+ use_ipv6, checkin, lookup,
+ answer);
+ }
+ auth_server->setIOService(io_service);
cout << "[b10-auth] IOService created." << endl;
- cc_session = new Session(io_service->get_io_service());
+ cc_session = new Session(io_service.get_io_service());
cout << "[b10-auth] Configuration session channel created." << endl;
config_session = new ModuleCCSession(specfile, *cc_session,
@@ -203,15 +223,15 @@
changeUser(uid);
}
- xfrin_session = new Session(io_service->get_io_service());
+ xfrin_session = new Session(io_service.get_io_service());
cout << "[b10-auth] Xfrin session channel created." << endl;
xfrin_session->establish(NULL);
xfrin_session_established = true;
cout << "[b10-auth] Xfrin session channel established." << endl;
- // XXX: with the current interface to asio_link we have to create
+ // XXX: with the current interface to asiolink we have to create
// auth_server before io_service while Session needs io_service.
- // In a next step of refactoring we should make asio_link independent
+ // In a next step of refactoring we should make asiolink independent
// from auth_server, and create io_service, auth_server, and
// sessions in that order.
auth_server->setXfrinSession(xfrin_session);
@@ -219,9 +239,11 @@
auth_server->updateConfig(ElementPtr());
cout << "[b10-auth] Server started." << endl;
- io_service->run();
+ io_service.run();
+
+ delete dns_service;
} catch (const std::exception& ex) {
- cerr << "[b10-auth] Initialization failed: " << ex.what() << endl;
+ cerr << "[b10-auth] Server failed: " << ex.what() << endl;
ret = 1;
}
@@ -232,7 +254,6 @@
delete xfrin_session;
delete config_session;
delete cc_session;
- delete io_service;
delete auth_server;
return (ret);
Modified: branches/trac226/src/bin/auth/tests/Makefile.am
==============================================================================
--- branches/trac226/src/bin/auth/tests/Makefile.am (original)
+++ branches/trac226/src/bin/auth/tests/Makefile.am Thu Dec 23 14:58:15 2010
@@ -1,11 +1,9 @@
-SUBDIRS = testdata .
-
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_builddir)/src/lib/dns -I$(top_srcdir)/src/bin
AM_CPPFLAGS += -I$(top_builddir)/src/lib/cc
AM_CPPFLAGS += $(BOOST_INCLUDES)
-AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(srcdir)/testdata\"
-AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/bin/auth/tests/testdata\"
+AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(top_srcdir)/src/lib/testutils/testdata\"
+AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/testutils/testdata\"
AM_CXXFLAGS = $(B10_CXXFLAGS)
@@ -26,7 +24,6 @@
run_unittests_SOURCES += auth_srv_unittest.cc
run_unittests_SOURCES += query_unittest.cc
run_unittests_SOURCES += change_user_unittest.cc
-run_unittests_SOURCES += asio_link_unittest.cc
run_unittests_SOURCES += run_unittests.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
@@ -34,10 +31,10 @@
run_unittests_LDADD += $(SQLITE_LIBS)
run_unittests_LDADD += $(top_builddir)/src/lib/datasrc/libdatasrc.la
run_unittests_LDADD += $(top_builddir)/src/lib/dns/libdns++.la
+run_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
run_unittests_LDADD += $(top_builddir)/src/lib/config/libcfgclient.la
run_unittests_LDADD += $(top_builddir)/src/lib/cc/libcc.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
-run_unittests_LDADD += $(top_builddir)/src/bin/auth/libasio_link.a
run_unittests_LDADD += $(top_builddir)/src/lib/xfr/libxfr.la
endif
Modified: branches/trac226/src/bin/auth/tests/auth_srv_unittest.cc
==============================================================================
--- branches/trac226/src/bin/auth/tests/auth_srv_unittest.cc (original)
+++ branches/trac226/src/bin/auth/tests/auth_srv_unittest.cc Thu Dec 23 14:58:15 2010
@@ -15,35 +15,16 @@
// $Id$
#include <config.h>
-
-#include <gtest/gtest.h>
-
-#include <dns/buffer.h>
-#include <dns/name.h>
-#include <dns/message.h>
-#include <dns/messagerenderer.h>
-#include <dns/opcode.h>
-#include <dns/rcode.h>
-#include <dns/rrclass.h>
-#include <dns/rrtype.h>
-
-#include <cc/data.h>
-#include <cc/session.h>
-
-#include <xfr/xfrout_client.h>
-
#include <auth/auth_srv.h>
-#include <auth/asio_link.h>
-
-#include <dns/tests/unittest_util.h>
-
-using isc::UnitTestUtil;
+#include <testutils/srv_unittest.h>
+
using namespace std;
using namespace isc::cc;
using namespace isc::dns;
using namespace isc::data;
using namespace isc::xfr;
-using namespace asio_link;
+using namespace asiolink;
+using isc::UnitTestUtil;
namespace {
const char* const CONFIG_TESTDB =
@@ -52,445 +33,83 @@
// the sqlite3 test).
const char* const BADCONFIG_TESTDB =
"{ \"database_file\": \"" TEST_DATA_DIR "/nodir/notexist\"}";
-const char* const DEFAULT_REMOTE_ADDRESS = "192.0.2.1";
-
-class AuthSrvTest : public ::testing::Test {
-private:
- class MockXfroutClient : public AbstractXfroutClient {
- public:
- MockXfroutClient() :
- is_connected_(false), connect_ok_(true), send_ok_(true),
- disconnect_ok_(true)
- {}
- virtual void connect();
- virtual void disconnect();
- virtual int sendXfroutRequestInfo(int tcp_sock, const void* msg_data,
- uint16_t msg_len);
- bool isConnected() const { return (is_connected_); }
- void disableConnect() { connect_ok_ = false; }
- void disableDisconnect() { disconnect_ok_ = false; }
- void enableDisconnect() { disconnect_ok_ = true; }
- void disableSend() { send_ok_ = false; }
- private:
- bool is_connected_;
- bool connect_ok_;
- bool send_ok_;
- bool disconnect_ok_;
- };
-
- class MockSession : public AbstractSession {
- public:
- MockSession() :
- // by default we return a simple "success" message.
- msg_(Element::fromJSON("{\"result\": [0, \"SUCCESS\"]}")),
- send_ok_(true), receive_ok_(true)
- {}
- virtual void establish(const char* socket_file);
- virtual void disconnect();
- virtual int group_sendmsg(ConstElementPtr msg, string group,
- string instance, string to);
- virtual bool group_recvmsg(ConstElementPtr& envelope,
- ConstElementPtr& msg,
- bool nonblock, int seq);
- virtual void subscribe(string group, string instance);
- virtual void unsubscribe(string group, string instance);
- virtual void startRead(boost::function<void()> read_callback);
- virtual int reply(ConstElementPtr envelope, ConstElementPtr newmsg);
- virtual bool hasQueuedMsgs() const;
- virtual void setTimeout(size_t) {}
- virtual size_t getTimeout() const { return 0; };
-
- void setMessage(ConstElementPtr msg) { msg_ = msg; }
- void disableSend() { send_ok_ = false; }
- void disableReceive() { receive_ok_ = false; }
-
- ConstElementPtr sent_msg;
- string msg_destination;
- private:
- ConstElementPtr msg_;
- bool send_ok_;
- bool receive_ok_;
- };
-
+
+class AuthSrvTest : public SrvTestBase {
protected:
- AuthSrvTest() : server(true, xfrout),
- request_message(Message::RENDER),
- parse_message(Message::PARSE), default_qid(0x1035),
- opcode(Opcode::QUERY()), qname("www.example.com"),
- qclass(RRClass::IN()), qtype(RRType::A()),
- io_message(NULL), endpoint(NULL), request_obuffer(0),
- request_renderer(request_obuffer),
- response_obuffer(0), response_renderer(response_obuffer)
- {
+ AuthSrvTest() : server(true, xfrout) {
server.setXfrinSession(¬ify_session);
}
- ~AuthSrvTest() {
- delete io_message;
- delete endpoint;
- }
- MockSession notify_session;
MockXfroutClient xfrout;
AuthSrv server;
- Message request_message;
- Message parse_message;
- const qid_t default_qid;
- const Opcode opcode;
- const Name qname;
- const RRClass qclass;
- const RRType qtype;
- IOMessage* io_message;
- const IOEndpoint* endpoint;
- OutputBuffer request_obuffer;
- MessageRenderer request_renderer;
- OutputBuffer response_obuffer;
- MessageRenderer response_renderer;
- vector<uint8_t> data;
-
- void createDataFromFile(const char* const datafile, int protocol);
- void createRequestMessage(const Opcode& opcode, const Name& request_name,
- const RRClass& rrclass, const RRType& rrtype);
- void createRequestPacket(const Opcode& opcode, const Name& request_name,
- const RRClass& rrclass, const RRType& rrtype,
- int protocol);
- void createRequestPacket(int protocol);
};
-
-void
-AuthSrvTest::MockSession::establish(const char*) {}
-
-void
-AuthSrvTest::MockSession::disconnect() {}
-
-void
-AuthSrvTest::MockSession::subscribe(string, string)
-{}
-
-void
-AuthSrvTest::MockSession::unsubscribe(string, string)
-{}
-
-void
-AuthSrvTest::MockSession::startRead(boost::function<void()>)
-{}
-
-int
-AuthSrvTest::MockSession::reply(ConstElementPtr, ConstElementPtr) {
- return (-1);
-}
-
-bool
-AuthSrvTest::MockSession::hasQueuedMsgs() const {
- return (false);
-}
-
-int
-AuthSrvTest::MockSession::group_sendmsg(ConstElementPtr msg, string group,
- string, string)
-{
- if (!send_ok_) {
- isc_throw(XfroutError, "mock session send is disabled for test");
- }
-
- sent_msg = msg;
- msg_destination = group;
- return (0);
-}
-
-bool
-AuthSrvTest::MockSession::group_recvmsg(ConstElementPtr&,
- ConstElementPtr& msg, bool, int)
-{
- if (!receive_ok_) {
- isc_throw(XfroutError, "mock session receive is disabled for test");
- }
-
- msg = msg_;
- return (true);
-}
-
-void
-AuthSrvTest::MockXfroutClient::connect() {
- if (!connect_ok_) {
- isc_throw(XfroutError, "xfrout connection disabled for test");
- }
- is_connected_ = true;
-}
-
-void
-AuthSrvTest::MockXfroutClient::disconnect() {
- if (!disconnect_ok_) {
- isc_throw(XfroutError,
- "closing xfrout connection is disabled for test");
- }
- is_connected_ = false;
-}
-
-int
-AuthSrvTest::MockXfroutClient::sendXfroutRequestInfo(const int,
- const void*,
- const uint16_t)
-{
- if (!send_ok_) {
- isc_throw(XfroutError, "xfrout connection send is disabled for test");
- }
- return (0);
-}
-
-
-// These are flags to indicate whether the corresponding flag bit of the
-// DNS header is to be set in the test cases. (Note that the flag values
-// is irrelevant to their wire-format values)
-const unsigned int QR_FLAG = 0x1;
-const unsigned int AA_FLAG = 0x2;
-const unsigned int TC_FLAG = 0x4;
-const unsigned int RD_FLAG = 0x8;
-const unsigned int RA_FLAG = 0x10;
-const unsigned int AD_FLAG = 0x20;
-const unsigned int CD_FLAG = 0x40;
-
-void
-AuthSrvTest::createDataFromFile(const char* const datafile,
- const int protocol = IPPROTO_UDP)
-{
- delete io_message;
- data.clear();
-
- delete endpoint;
- endpoint = IOEndpoint::create(protocol,
- IOAddress(DEFAULT_REMOTE_ADDRESS), 5300);
- UnitTestUtil::readWireData(datafile, data);
- io_message = new IOMessage(&data[0], data.size(),
- protocol == IPPROTO_UDP ?
- IOSocket::getDummyUDPSocket() :
- IOSocket::getDummyTCPSocket(), *endpoint);
-}
-
-void
-AuthSrvTest::createRequestMessage(const Opcode& opcode,
- const Name& request_name,
- const RRClass& rrclass,
- const RRType& rrtype)
-{
- request_message.clear(Message::RENDER);
- request_message.setOpcode(opcode);
- request_message.setRcode(Rcode::NOERROR());
- request_message.setQid(default_qid);
- request_message.addQuestion(Question(request_name, rrclass, rrtype));
-}
-
-void
-AuthSrvTest::createRequestPacket(const Opcode& opcode,
- const Name& request_name,
- const RRClass& rrclass, const RRType& rrtype,
- const int protocol = IPPROTO_UDP)
-{
- createRequestMessage(opcode, request_name, rrclass, rrtype);
- createRequestPacket(protocol);
-}
-
-void
-AuthSrvTest::createRequestPacket(const int protocol = IPPROTO_UDP) {
- request_message.toWire(request_renderer);
-
- delete io_message;
- endpoint = IOEndpoint::create(protocol,
- IOAddress(DEFAULT_REMOTE_ADDRESS), 5300);
- io_message = new IOMessage(request_renderer.getData(),
- request_renderer.getLength(),
- protocol == IPPROTO_UDP ?
- IOSocket::getDummyUDPSocket() :
- IOSocket::getDummyTCPSocket(), *endpoint);
-}
-
-void
-headerCheck(const Message& message, const qid_t qid, const Rcode& rcode,
- const uint16_t opcodeval, const unsigned int flags,
- const unsigned int qdcount,
- const unsigned int ancount, const unsigned int nscount,
- const unsigned int arcount)
-{
- EXPECT_EQ(qid, message.getQid());
- EXPECT_EQ(rcode, message.getRcode());
- EXPECT_EQ(opcodeval, message.getOpcode().getCode());
- EXPECT_EQ((flags & QR_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_QR));
- EXPECT_EQ((flags & AA_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_AA));
- EXPECT_EQ((flags & TC_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_TC));
- EXPECT_EQ((flags & RA_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_RA));
- EXPECT_EQ((flags & RD_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_RD));
- EXPECT_EQ((flags & AD_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_AD));
- EXPECT_EQ((flags & CD_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_CD));
-
- EXPECT_EQ(qdcount, message.getRRCount(Message::SECTION_QUESTION));
- EXPECT_EQ(ancount, message.getRRCount(Message::SECTION_ANSWER));
- EXPECT_EQ(nscount, message.getRRCount(Message::SECTION_AUTHORITY));
- EXPECT_EQ(arcount, message.getRRCount(Message::SECTION_ADDITIONAL));
-}
// Unsupported requests. Should result in NOTIMP.
TEST_F(AuthSrvTest, unsupportedRequest) {
- for (unsigned int i = 0; i < 16; ++i) {
- // set Opcode to 'i', which iterators over all possible codes except
- // the standard query and notify
- if (i == Opcode::QUERY().getCode() ||
- i == Opcode::NOTIFY().getCode()) {
- continue;
- }
- createDataFromFile("simplequery_fromWire.wire");
- data[2] = ((i << 3) & 0xff);
-
- parse_message.clear(Message::PARSE);
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- headerCheck(parse_message, default_qid, Rcode::NOTIMP(), i, QR_FLAG,
- 0, 0, 0, 0);
- }
+ UNSUPPORTED_REQUEST_TEST;
}
// Simple API check
TEST_F(AuthSrvTest, verbose) {
- EXPECT_FALSE(server.getVerbose());
- server.setVerbose(true);
- EXPECT_TRUE(server.getVerbose());
- server.setVerbose(false);
- EXPECT_FALSE(server.getVerbose());
+ VERBOSE_TEST;
}
// Multiple questions. Should result in FORMERR.
TEST_F(AuthSrvTest, multiQuestion) {
- createDataFromFile("multiquestion_fromWire.wire");
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- headerCheck(parse_message, default_qid, Rcode::FORMERR(), opcode.getCode(),
- QR_FLAG, 2, 0, 0, 0);
-
- QuestionIterator qit = parse_message.beginQuestion();
- EXPECT_EQ(Name("example.com"), (*qit)->getName());
- EXPECT_EQ(RRClass::IN(), (*qit)->getClass());
- EXPECT_EQ(RRType::A(), (*qit)->getType());
- ++qit;
- EXPECT_EQ(Name("example.com"), (*qit)->getName());
- EXPECT_EQ(RRClass::IN(), (*qit)->getClass());
- EXPECT_EQ(RRType::AAAA(), (*qit)->getType());
- ++qit;
- EXPECT_TRUE(qit == parse_message.endQuestion());
+ MULTI_QUESTION_TEST;
}
// Incoming data doesn't even contain the complete header. Must be silently
// dropped.
TEST_F(AuthSrvTest, shortMessage) {
- createDataFromFile("shortmessage_fromWire");
- EXPECT_FALSE(server.processMessage(*io_message, parse_message,
- response_renderer));
+ SHORT_MESSAGE_TEST;
}
// Response messages. Must be silently dropped, whether it's a valid response
// or malformed or could otherwise cause a protocol error.
TEST_F(AuthSrvTest, response) {
- // A valid (although unusual) response
- createDataFromFile("simpleresponse_fromWire.wire");
- EXPECT_FALSE(server.processMessage(*io_message, parse_message,
- response_renderer));
-
- // A response with a broken question section. must be dropped rather than
- // returning FORMERR.
- createDataFromFile("shortresponse_fromWire");
- EXPECT_FALSE(server.processMessage(*io_message, parse_message,
- response_renderer));
-
- // A response to iquery. must be dropped rather than returning NOTIMP.
- createDataFromFile("iqueryresponse_fromWire.wire");
- EXPECT_FALSE(server.processMessage(*io_message, parse_message,
- response_renderer));
+ RESPONSE_TEST;
}
// Query with a broken question
TEST_F(AuthSrvTest, shortQuestion) {
- createDataFromFile("shortquestion_fromWire");
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- // Since the query's question is broken, the question section of the
- // response should be empty.
- headerCheck(parse_message, default_qid, Rcode::FORMERR(), opcode.getCode(),
- QR_FLAG, 0, 0, 0, 0);
+ SHORT_QUESTION_TEST;
}
// Query with a broken answer section
TEST_F(AuthSrvTest, shortAnswer) {
- createDataFromFile("shortanswer_fromWire.wire");
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
-
- // This is a bogus query, but question section is valid. So the response
- // should copy the question section.
- headerCheck(parse_message, default_qid, Rcode::FORMERR(), opcode.getCode(),
- QR_FLAG, 1, 0, 0, 0);
-
- QuestionIterator qit = parse_message.beginQuestion();
- EXPECT_EQ(Name("example.com"), (*qit)->getName());
- EXPECT_EQ(RRClass::IN(), (*qit)->getClass());
- EXPECT_EQ(RRType::A(), (*qit)->getType());
- ++qit;
- EXPECT_TRUE(qit == parse_message.endQuestion());
+ SHORT_ANSWER_TEST;
}
// Query with unsupported version of EDNS.
TEST_F(AuthSrvTest, ednsBadVers) {
- createDataFromFile("queryBadEDNS_fromWire.wire");
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
-
- // The response must have an EDNS OPT RR in the additional section, but
- // it will be added automatically at the render time.
- // Note that the DNSSEC DO bit is cleared even if this bit in the query
- // is set. This is a limitation of the current implementation.
- headerCheck(parse_message, default_qid, Rcode::BADVERS(), opcode.getCode(),
- QR_FLAG, 1, 0, 0, 1);
- EXPECT_FALSE(parse_message.getEDNS()); // EDNS isn't added at this point
-
- parse_message.clear(Message::PARSE);
- InputBuffer ib(response_renderer.getData(), response_renderer.getLength());
- parse_message.fromWire(ib);
- EXPECT_EQ(Rcode::BADVERS(), parse_message.getRcode());
- EXPECT_TRUE(parse_message.getEDNS());
- EXPECT_FALSE(parse_message.getEDNS()->getDNSSECAwareness());
+ EDNS_BADVERS_TEST;
}
TEST_F(AuthSrvTest, AXFROverUDP) {
- // AXFR over UDP is invalid and should result in FORMERR.
- createRequestPacket(opcode, Name("example.com"), RRClass::IN(),
- RRType::AXFR(), IPPROTO_UDP);
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- headerCheck(parse_message, default_qid, Rcode::FORMERR(), opcode.getCode(),
- QR_FLAG, 1, 0, 0, 0);
+ AXFR_OVER_UDP_TEST;
}
TEST_F(AuthSrvTest, AXFRSuccess) {
EXPECT_FALSE(xfrout.isConnected());
- createRequestPacket(opcode, Name("example.com"), RRClass::IN(),
- RRType::AXFR(), IPPROTO_TCP);
+ UnitTestUtil::createRequestMessage(request_message, opcode, default_qid,
+ Name("example.com"), RRClass::IN(), RRType::AXFR());
+ createRequestPacket(request_message, IPPROTO_TCP);
// On success, the AXFR query has been passed to a separate process,
// so we shouldn't have to respond.
- EXPECT_FALSE(server.processMessage(*io_message, parse_message,
- response_renderer));
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_FALSE(dnsserv.hasAnswer());
EXPECT_TRUE(xfrout.isConnected());
}
TEST_F(AuthSrvTest, AXFRConnectFail) {
EXPECT_FALSE(xfrout.isConnected()); // check prerequisite
xfrout.disableConnect();
- createRequestPacket(opcode, Name("example.com"), RRClass::IN(),
- RRType::AXFR(), IPPROTO_TCP);
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- headerCheck(parse_message, default_qid, Rcode::SERVFAIL(),
+ UnitTestUtil::createRequestMessage(request_message, opcode, default_qid,
+ Name("example.com"), RRClass::IN(), RRType::AXFR());
+ createRequestPacket(request_message, IPPROTO_TCP);
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_TRUE(dnsserv.hasAnswer());
+ headerCheck(*parse_message, default_qid, Rcode::SERVFAIL(),
opcode.getCode(), QR_FLAG, 1, 0, 0, 0);
EXPECT_FALSE(xfrout.isConnected());
}
@@ -498,19 +117,21 @@
TEST_F(AuthSrvTest, AXFRSendFail) {
// first send a valid query, making the connection with the xfr process
// open.
- createRequestPacket(opcode, Name("example.com"), RRClass::IN(),
- RRType::AXFR(), IPPROTO_TCP);
- server.processMessage(*io_message, parse_message, response_renderer);
+ UnitTestUtil::createRequestMessage(request_message, opcode, default_qid,
+ Name("example.com"), RRClass::IN(), RRType::AXFR());
+ createRequestPacket(request_message, IPPROTO_TCP);
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
EXPECT_TRUE(xfrout.isConnected());
xfrout.disableSend();
- parse_message.clear(Message::PARSE);
- response_renderer.clear();
- createRequestPacket(opcode, Name("example.com"), RRClass::IN(),
- RRType::AXFR(), IPPROTO_TCP);
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- headerCheck(parse_message, default_qid, Rcode::SERVFAIL(),
+ parse_message->clear(Message::PARSE);
+ response_obuffer->clear();
+ UnitTestUtil::createRequestMessage(request_message, opcode, default_qid,
+ Name("example.com"), RRClass::IN(), RRType::AXFR());
+ createRequestPacket(request_message, IPPROTO_TCP);
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_TRUE(dnsserv.hasAnswer());
+ headerCheck(*parse_message, default_qid, Rcode::SERVFAIL(),
opcode.getCode(), QR_FLAG, 1, 0, 0, 0);
// The connection should have been closed due to the send failure.
@@ -522,10 +143,11 @@
// should it be thrown.
xfrout.disableSend();
xfrout.disableDisconnect();
- createRequestPacket(opcode, Name("example.com"), RRClass::IN(),
- RRType::AXFR(), IPPROTO_TCP);
+ UnitTestUtil::createRequestMessage(request_message, opcode, default_qid,
+ Name("example.com"), RRClass::IN(), RRType::AXFR());
+ createRequestPacket(request_message, IPPROTO_TCP);
EXPECT_THROW(server.processMessage(*io_message, parse_message,
- response_renderer),
+ response_obuffer, &dnsserv),
XfroutError);
EXPECT_TRUE(xfrout.isConnected());
// XXX: we need to re-enable disconnect. otherwise an exception would be
@@ -534,31 +156,31 @@
}
TEST_F(AuthSrvTest, notify) {
- createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
- RRType::SOA());
- request_message.setHeaderFlag(Message::HEADERFLAG_AA);
- createRequestPacket(IPPROTO_UDP);
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
+ UnitTestUtil::createRequestMessage(request_message, Opcode::NOTIFY(), default_qid,
+ Name("example.com"), RRClass::IN(), RRType::SOA());
+ request_message.setHeaderFlag(Message::HEADERFLAG_AA);
+ createRequestPacket(request_message, IPPROTO_UDP);
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_TRUE(dnsserv.hasAnswer());
// An internal command message should have been created and sent to an
// external module. Check them.
- EXPECT_EQ("Zonemgr", notify_session.msg_destination);
+ EXPECT_EQ("Zonemgr", notify_session.getMessageDest());
EXPECT_EQ("notify",
- notify_session.sent_msg->get("command")->get(0)->stringValue());
+ notify_session.getSentMessage()->get("command")->get(0)->stringValue());
ConstElementPtr notify_args =
- notify_session.sent_msg->get("command")->get(1);
+ notify_session.getSentMessage()->get("command")->get(1);
EXPECT_EQ("example.com.", notify_args->get("zone_name")->stringValue());
EXPECT_EQ(DEFAULT_REMOTE_ADDRESS,
notify_args->get("master")->stringValue());
EXPECT_EQ("IN", notify_args->get("zone_class")->stringValue());
// On success, the server should return a response to the notify.
- headerCheck(parse_message, default_qid, Rcode::NOERROR(),
+ headerCheck(*parse_message, default_qid, Rcode::NOERROR(),
Opcode::NOTIFY().getCode(), QR_FLAG | AA_FLAG, 1, 0, 0, 0);
// The question must be identical to that of the received notify
- ConstQuestionPtr question = *parse_message.beginQuestion();
+ ConstQuestionPtr question = *parse_message->beginQuestion();
EXPECT_EQ(Name("example.com"), question->getName());
EXPECT_EQ(RRClass::IN(), question->getClass());
EXPECT_EQ(RRType::SOA(), question->getType());
@@ -566,17 +188,17 @@
TEST_F(AuthSrvTest, notifyForCHClass) {
// Same as the previous test, but for the CH RRClass.
- createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::CH(),
- RRType::SOA());
- request_message.setHeaderFlag(Message::HEADERFLAG_AA);
- createRequestPacket(IPPROTO_UDP);
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
+ UnitTestUtil::createRequestMessage(request_message, Opcode::NOTIFY(), default_qid,
+ Name("example.com"), RRClass::CH(), RRType::SOA());
+ request_message.setHeaderFlag(Message::HEADERFLAG_AA);
+ createRequestPacket(request_message, IPPROTO_UDP);
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_TRUE(dnsserv.hasAnswer());
// Other conditions should be the same, so simply confirm the RR class is
// set correctly.
ConstElementPtr notify_args =
- notify_session.sent_msg->get("command")->get(1);
+ notify_session.getSentMessage()->get("command")->get(1);
EXPECT_EQ("CH", notify_args->get("zone_class")->stringValue());
}
@@ -587,118 +209,119 @@
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
request_message.setQid(default_qid);
request_message.toWire(request_renderer);
- createRequestPacket(IPPROTO_UDP);
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- headerCheck(parse_message, default_qid, Rcode::FORMERR(),
+ createRequestPacket(request_message, IPPROTO_UDP);
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_TRUE(dnsserv.hasAnswer());
+ headerCheck(*parse_message, default_qid, Rcode::FORMERR(),
Opcode::NOTIFY().getCode(), QR_FLAG, 0, 0, 0, 0);
}
TEST_F(AuthSrvTest, notifyMultiQuestions) {
- createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
- RRType::SOA());
+ UnitTestUtil::createRequestMessage(request_message, Opcode::NOTIFY(), default_qid,
+ Name("example.com"), RRClass::IN(), RRType::SOA());
// add one more SOA question
request_message.addQuestion(Question(Name("example.com"), RRClass::IN(),
RRType::SOA()));
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
- createRequestPacket(IPPROTO_UDP);
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- headerCheck(parse_message, default_qid, Rcode::FORMERR(),
+ createRequestPacket(request_message, IPPROTO_UDP);
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_TRUE(dnsserv.hasAnswer());
+ headerCheck(*parse_message, default_qid, Rcode::FORMERR(),
Opcode::NOTIFY().getCode(), QR_FLAG, 2, 0, 0, 0);
}
TEST_F(AuthSrvTest, notifyNonSOAQuestion) {
- createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
- RRType::NS());
- request_message.setHeaderFlag(Message::HEADERFLAG_AA);
- createRequestPacket(IPPROTO_UDP);
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- headerCheck(parse_message, default_qid, Rcode::FORMERR(),
+ UnitTestUtil::createRequestMessage(request_message, Opcode::NOTIFY(), default_qid,
+ Name("example.com"), RRClass::IN(), RRType::NS());
+ request_message.setHeaderFlag(Message::HEADERFLAG_AA);
+ createRequestPacket(request_message, IPPROTO_UDP);
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_TRUE(dnsserv.hasAnswer());
+ headerCheck(*parse_message, default_qid, Rcode::FORMERR(),
Opcode::NOTIFY().getCode(), QR_FLAG, 1, 0, 0, 0);
}
TEST_F(AuthSrvTest, notifyWithoutAA) {
// implicitly leave the AA bit off. our implementation will accept it.
- createRequestPacket(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
- RRType::SOA());
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- headerCheck(parse_message, default_qid, Rcode::NOERROR(),
+ UnitTestUtil::createRequestMessage(request_message, Opcode::NOTIFY(), default_qid,
+ Name("example.com"), RRClass::IN(), RRType::SOA());
+ createRequestPacket(request_message, IPPROTO_UDP);
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_TRUE(dnsserv.hasAnswer());
+ headerCheck(*parse_message, default_qid, Rcode::NOERROR(),
Opcode::NOTIFY().getCode(), QR_FLAG | AA_FLAG, 1, 0, 0, 0);
}
TEST_F(AuthSrvTest, notifyWithErrorRcode) {
- createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
- RRType::SOA());
+ UnitTestUtil::createRequestMessage(request_message, Opcode::NOTIFY(), default_qid,
+ Name("example.com"), RRClass::IN(), RRType::SOA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
request_message.setRcode(Rcode::SERVFAIL());
- createRequestPacket(IPPROTO_UDP);
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- headerCheck(parse_message, default_qid, Rcode::NOERROR(),
+ createRequestPacket(request_message, IPPROTO_UDP);
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_TRUE(dnsserv.hasAnswer());
+ headerCheck(*parse_message, default_qid, Rcode::NOERROR(),
Opcode::NOTIFY().getCode(), QR_FLAG | AA_FLAG, 1, 0, 0, 0);
}
TEST_F(AuthSrvTest, notifyWithoutSession) {
server.setXfrinSession(NULL);
- createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
- RRType::SOA());
- request_message.setHeaderFlag(Message::HEADERFLAG_AA);
- createRequestPacket(IPPROTO_UDP);
+ UnitTestUtil::createRequestMessage(request_message, Opcode::NOTIFY(), default_qid,
+ Name("example.com"), RRClass::IN(), RRType::SOA());
+ request_message.setHeaderFlag(Message::HEADERFLAG_AA);
+ createRequestPacket(request_message, IPPROTO_UDP);
// we simply ignore the notify and let it be resent if an internal error
// happens.
- EXPECT_FALSE(server.processMessage(*io_message, parse_message,
- response_renderer));
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_FALSE(dnsserv.hasAnswer());
}
TEST_F(AuthSrvTest, notifySendFail) {
notify_session.disableSend();
- createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
- RRType::SOA());
- request_message.setHeaderFlag(Message::HEADERFLAG_AA);
- createRequestPacket(IPPROTO_UDP);
-
- EXPECT_FALSE(server.processMessage(*io_message, parse_message,
- response_renderer));
+ UnitTestUtil::createRequestMessage(request_message, Opcode::NOTIFY(), default_qid,
+ Name("example.com"), RRClass::IN(), RRType::SOA());
+ request_message.setHeaderFlag(Message::HEADERFLAG_AA);
+ createRequestPacket(request_message, IPPROTO_UDP);
+
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_FALSE(dnsserv.hasAnswer());
}
TEST_F(AuthSrvTest, notifyReceiveFail) {
notify_session.disableReceive();
- createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
- RRType::SOA());
- request_message.setHeaderFlag(Message::HEADERFLAG_AA);
- createRequestPacket(IPPROTO_UDP);
- EXPECT_FALSE(server.processMessage(*io_message, parse_message,
- response_renderer));
+ UnitTestUtil::createRequestMessage(request_message, Opcode::NOTIFY(), default_qid,
+ Name("example.com"), RRClass::IN(), RRType::SOA());
+ request_message.setHeaderFlag(Message::HEADERFLAG_AA);
+ createRequestPacket(request_message, IPPROTO_UDP);
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_FALSE(dnsserv.hasAnswer());
}
TEST_F(AuthSrvTest, notifyWithBogusSessionMessage) {
notify_session.setMessage(Element::fromJSON("{\"foo\": 1}"));
- createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
- RRType::SOA());
- request_message.setHeaderFlag(Message::HEADERFLAG_AA);
- createRequestPacket(IPPROTO_UDP);
- EXPECT_FALSE(server.processMessage(*io_message, parse_message,
- response_renderer));
+ UnitTestUtil::createRequestMessage(request_message, Opcode::NOTIFY(), default_qid,
+ Name("example.com"), RRClass::IN(), RRType::SOA());
+ request_message.setHeaderFlag(Message::HEADERFLAG_AA);
+ createRequestPacket(request_message, IPPROTO_UDP);
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_FALSE(dnsserv.hasAnswer());
}
TEST_F(AuthSrvTest, notifyWithSessionMessageError) {
notify_session.setMessage(
Element::fromJSON("{\"result\": [1, \"FAIL\"]}"));
- createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
- RRType::SOA());
- request_message.setHeaderFlag(Message::HEADERFLAG_AA);
- createRequestPacket(IPPROTO_UDP);
- EXPECT_FALSE(server.processMessage(*io_message, parse_message,
- response_renderer));
+ UnitTestUtil::createRequestMessage(request_message, Opcode::NOTIFY(), default_qid,
+ Name("example.com"), RRClass::IN(), RRType::SOA());
+ request_message.setHeaderFlag(Message::HEADERFLAG_AA);
+ createRequestPacket(request_message, IPPROTO_UDP);
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_FALSE(dnsserv.hasAnswer());
}
void
@@ -723,9 +346,9 @@
// response should have the AA flag on, and have an RR in each answer
// and authority section.
createDataFromFile("examplequery_fromWire.wire");
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- headerCheck(parse_message, default_qid, Rcode::NOERROR(), opcode.getCode(),
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_TRUE(dnsserv.hasAnswer());
+ headerCheck(*parse_message, default_qid, Rcode::NOERROR(), opcode.getCode(),
QR_FLAG | AA_FLAG, 1, 1, 1, 0);
}
@@ -737,9 +360,9 @@
// in a SERVFAIL response, and the answer and authority sections should
// be empty.
createDataFromFile("badExampleQuery_fromWire.wire");
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- headerCheck(parse_message, default_qid, Rcode::SERVFAIL(),
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_TRUE(dnsserv.hasAnswer());
+ headerCheck(*parse_message, default_qid, Rcode::SERVFAIL(),
opcode.getCode(), QR_FLAG, 1, 0, 0, 0);
}
@@ -752,9 +375,9 @@
// The original data source should still exist.
createDataFromFile("examplequery_fromWire.wire");
- EXPECT_TRUE(server.processMessage(*io_message, parse_message,
- response_renderer));
- headerCheck(parse_message, default_qid, Rcode::NOERROR(), opcode.getCode(),
+ server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
+ EXPECT_TRUE(dnsserv.hasAnswer());
+ headerCheck(*parse_message, default_qid, Rcode::NOERROR(), opcode.getCode(),
QR_FLAG | AA_FLAG, 1, 1, 1, 0);
}
Modified: branches/trac226/src/bin/auth/tests/query_unittest.cc
==============================================================================
--- branches/trac226/src/bin/auth/tests/query_unittest.cc (original)
+++ branches/trac226/src/bin/auth/tests/query_unittest.cc Thu Dec 23 14:58:15 2010
@@ -18,6 +18,7 @@
#include <dns/rrtype.h>
#include <datasrc/zonetable.h>
+#include <datasrc/memory_datasrc.h>
#include <auth/query.h>
Modified: branches/trac226/src/bin/bind10/bind10.py.in
==============================================================================
--- branches/trac226/src/bin/bind10/bind10.py.in (original)
+++ branches/trac226/src/bin/bind10/bind10.py.in Thu Dec 23 14:58:15 2010
@@ -194,8 +194,9 @@
class BoB:
"""Boss of BIND class."""
- def __init__(self, msgq_socket_file=None, auth_port=5300, address=None,
- nocache=False, verbose=False, setuid=None, username=None):
+ def __init__(self, msgq_socket_file=None, dns_port=5300, address=None,
+ forward=None, nocache=False, verbose=False, setuid=None,
+ username=None):
"""
Initialize the Boss of BIND. This is a singleton (only one can run).
@@ -204,7 +205,12 @@
what it is doing.
"""
self.address = address
- self.auth_port = auth_port
+ self.dns_port = dns_port
+ self.forward = forward
+ if forward:
+ self.recursive = True
+ else:
+ self.recursive = False
self.cc_session = None
self.ccs = None
self.cfg_start_auth = True
@@ -417,19 +423,26 @@
Start the Authoritative server
"""
# XXX: this must be read from the configuration manager in the future
- authargs = ['b10-auth', '-p', str(self.auth_port)]
- if self.address:
- authargs += ['-a', str(self.address)]
- if self.nocache:
- authargs += ['-n']
+ if self.recursive:
+ dns_prog = 'b10-recurse'
+ else:
+ dns_prog = 'b10-auth'
+ dnsargs = [dns_prog]
+ if not self.recursive:
+ # The recursive uses configuration manager for these
+ dnsargs += ['-p', str(self.dns_port)]
+ if self.address:
+ dnsargs += ['-a', str(self.address)]
+ if self.nocache:
+ dnsargs += ['-n']
if self.uid:
- authargs += ['-u', str(self.uid)]
- if self.verbose:
- authargs += ['-v']
+ dnsargs += ['-u', str(self.uid)]
+ if self.verbose:
+ dnsargs += ['-v']
# ... and start
- self.start_process("b10-auth", authargs, c_channel_env,
- self.auth_port, self.address)
+ self.start_process("b10-auth", dnsargs, c_channel_env,
+ self.dns_port, self.address)
def start_recurse(self, c_channel_env):
"""
@@ -540,6 +553,7 @@
def stop_all_processes(self):
"""Stop all processes."""
cmd = { "command": ['shutdown']}
+
self.cc_session.group_sendmsg(cmd, 'Cmdctl', 'Cmdctl')
self.cc_session.group_sendmsg(cmd, "ConfigManager", "ConfigManager")
self.cc_session.group_sendmsg(cmd, "Auth", "Auth")
@@ -547,7 +561,7 @@
self.cc_session.group_sendmsg(cmd, "Xfrout", "Xfrout")
self.cc_session.group_sendmsg(cmd, "Xfrin", "Xfrin")
self.cc_session.group_sendmsg(cmd, "Zonemgr", "Zonemgr")
- self.cc_session.group_sendmsg(cmd, "Boss", "Stats")
+ self.cc_session.group_sendmsg(cmd, "Stats", "Stats")
def stop_process(self, process):
"""Stop the given process, friendly-like."""
@@ -713,7 +727,7 @@
a valid port number. Used by OptionParser() on startup."""
try:
if opt_str in ['-p', '--port']:
- parser.values.auth_port = isc.net.parse.port_parse(value)
+ parser.values.dns_port = isc.net.parse.port_parse(value)
else:
raise OptionValueError("Unknown option " + opt_str)
except ValueError as e:
@@ -725,6 +739,8 @@
try:
if opt_str in ['-a', '--address']:
parser.values.address = isc.net.parse.addr_parse(value)
+ elif opt_str in ['-f', '--forward']:
+ parser.values.forward = isc.net.parse.addr_parse(value)
else:
raise OptionValueError("Unknown option " + opt_str)
except ValueError:
@@ -744,17 +760,19 @@
parser = OptionParser(version=VERSION)
parser.add_option("-a", "--address", dest="address", type="string",
action="callback", callback=check_addr, default=None,
- help="address the b10-auth daemon will use (default: listen on all addresses)")
+ help="address the DNS server will use (default: listen on all addresses)")
+ parser.add_option("-f", "--forward", dest="forward", type="string",
+ action="callback", callback=check_addr, default=None,
+ help="nameserver to which DNS queries should be forwarded")
parser.add_option("-m", "--msgq-socket-file", dest="msgq_socket_file",
type="string", default=None,
help="UNIX domain socket file the b10-msgq daemon will use")
parser.add_option("-n", "--no-cache", action="store_true", dest="nocache",
- default=False, help="disable hot-spot cache in b10-auth")
- parser.add_option("-p", "--port", dest="auth_port", type="int",
+ default=False, help="disable hot-spot cache in authoritative DNS server")
+ parser.add_option("-p", "--port", dest="dns_port", type="int",
action="callback", callback=check_port, default=5300,
- help="port the b10-auth daemon will use (default 5300)")
- parser.add_option("-u", "--user", dest="user",
- type="string", default=None,
+ help="port the DNS server will use (default 5300)")
+ parser.add_option("-u", "--user", dest="user", type="string", default=None,
help="Change user after startup (must run as root)")
parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
help="display more about what is going on")
@@ -799,10 +817,6 @@
if options.verbose:
sys.stdout.write("%s\n" % VERSION)
- # TODO: set process name, perhaps by:
- # http://code.google.com/p/procname/
- # http://github.com/lericson/procname/
-
# Create wakeup pipe for signal handlers
wakeup_pipe = os.pipe()
signal.set_wakeup_fd(wakeup_pipe[1])
@@ -818,9 +832,9 @@
signal.signal(signal.SIGPIPE, signal.SIG_IGN)
# Go bob!
- boss_of_bind = BoB(options.msgq_socket_file, options.auth_port,
- options.address, options.nocache, options.verbose,
- setuid, username)
+ boss_of_bind = BoB(options.msgq_socket_file, options.dns_port,
+ options.address, options.forward, options.nocache,
+ options.verbose, setuid, username)
startup_result = boss_of_bind.startup()
if startup_result:
sys.stderr.write("[bind10] Error on startup: %s\n" % startup_result)
Modified: branches/trac226/src/bin/bind10/run_bind10.sh.in
==============================================================================
--- branches/trac226/src/bin/bind10/run_bind10.sh.in (original)
+++ branches/trac226/src/bin/bind10/run_bind10.sh.in Thu Dec 23 14:58:15 2010
@@ -20,10 +20,10 @@
BIND10_PATH=@abs_top_builddir@/src/bin/bind10
-PATH=@abs_top_builddir@/src/bin/msgq:@abs_top_builddir@/src/bin/auth:@abs_top_builddir@/src/bin/cfgmgr:@abs_top_builddir@/src/bin/cmdctl:@abs_top_builddir@/src/bin/stats:@abs_top_builddir@/src/bin/xfrin:@abs_top_builddir@/src/bin/xfrout:@abs_top_builddir@/src/bin/zonemgr:@abs_top_builddir@/src/bin/recurse:$PATH
+PATH=@abs_top_builddir@/src/bin/msgq:@abs_top_builddir@/src/bin/auth:@abs_top_builddir@/src/bin/recurse:@abs_top_builddir@/src/bin/cfgmgr:@abs_top_builddir@/src/bin/cmdctl:@abs_top_builddir@/src/bin/stats:@abs_top_builddir@/src/bin/xfrin:@abs_top_builddir@/src/bin/xfrout:@abs_top_builddir@/src/bin/zonemgr:$PATH
export PATH
-PYTHONPATH=@abs_top_builddir@/src/lib/python:@abs_top_builddir@/src/lib/dns/python/.libs:@abs_top_builddir@/src/lib/xfr/.libs
+PYTHONPATH=@abs_top_builddir@/src/lib/python:@abs_top_builddir@/src/lib/dns/python/.libs:@abs_top_builddir@/src/lib/xfr/.libs:@abs_top_builddir@/src/lib/log/.libs
export PYTHONPATH
# If necessary (rare cases), explicitly specify paths to dynamic libraries
Modified: branches/trac226/src/bin/bind10/tests/bind10_test.py
==============================================================================
--- branches/trac226/src/bin/bind10/tests/bind10_test.py (original)
+++ branches/trac226/src/bin/bind10/tests/bind10_test.py Thu Dec 23 14:58:15 2010
@@ -78,7 +78,7 @@
bob = BoB()
self.assertEqual(bob.verbose, False)
self.assertEqual(bob.msgq_socket_file, None)
- self.assertEqual(bob.auth_port, 5300)
+ self.assertEqual(bob.dns_port, 5300)
self.assertEqual(bob.address, None)
self.assertEqual(bob.cc_session, None)
self.assertEqual(bob.ccs, None)
@@ -95,7 +95,24 @@
bob = BoB("alt_socket_file")
self.assertEqual(bob.verbose, False)
self.assertEqual(bob.msgq_socket_file, "alt_socket_file")
- self.assertEqual(bob.auth_port, 5300)
+ self.assertEqual(bob.address, None)
+ self.assertEqual(bob.dns_port, 5300)
+ self.assertEqual(bob.cc_session, None)
+ self.assertEqual(bob.ccs, None)
+ self.assertEqual(bob.processes, {})
+ self.assertEqual(bob.dead_processes, {})
+ self.assertEqual(bob.runnable, False)
+ self.assertEqual(bob.uid, None)
+ self.assertEqual(bob.username, None)
+ self.assertEqual(bob.nocache, False)
+ self.assertEqual(bob.cfg_start_auth, True)
+ self.assertEqual(bob.cfg_start_recurse, False)
+
+ def test_init_alternate_dns_port(self):
+ bob = BoB(None, 9999)
+ self.assertEqual(bob.verbose, False)
+ self.assertEqual(bob.msgq_socket_file, None)
+ self.assertEqual(bob.dns_port, 9999)
self.assertEqual(bob.address, None)
self.assertEqual(bob.cc_session, None)
self.assertEqual(bob.ccs, None)
@@ -108,28 +125,11 @@
self.assertEqual(bob.cfg_start_auth, True)
self.assertEqual(bob.cfg_start_recurse, False)
- def test_init_alternate_auth_port(self):
- bob = BoB(None, 9999)
- self.assertEqual(bob.verbose, False)
- self.assertEqual(bob.msgq_socket_file, None)
- self.assertEqual(bob.auth_port, 9999)
- self.assertEqual(bob.address, None)
- self.assertEqual(bob.cc_session, None)
- self.assertEqual(bob.ccs, None)
- self.assertEqual(bob.processes, {})
- self.assertEqual(bob.dead_processes, {})
- self.assertEqual(bob.runnable, False)
- self.assertEqual(bob.uid, None)
- self.assertEqual(bob.username, None)
- self.assertEqual(bob.nocache, False)
- self.assertEqual(bob.cfg_start_auth, True)
- self.assertEqual(bob.cfg_start_recurse, False)
-
def test_init_alternate_address(self):
bob = BoB(None, 1234, IPAddr('127.127.127.127'))
self.assertEqual(bob.verbose, False)
self.assertEqual(bob.msgq_socket_file, None)
- self.assertEqual(bob.auth_port, 1234)
+ self.assertEqual(bob.dns_port, 1234)
self.assertEqual(bob.address.addr, socket.inet_aton('127.127.127.127'))
self.assertEqual(bob.cc_session, None)
self.assertEqual(bob.ccs, None)
Modified: branches/trac226/src/lib/Makefile.am
==============================================================================
--- branches/trac226/src/lib/Makefile.am (original)
+++ branches/trac226/src/lib/Makefile.am Thu Dec 23 14:58:15 2010
@@ -1,1 +1,2 @@
-SUBDIRS = exceptions dns cc config datasrc python xfr bench nsas
+SUBDIRS = exceptions dns cc config datasrc python xfr bench log asiolink \
+ testutils nsas
Modified: branches/trac226/src/lib/cc/session.cc
==============================================================================
--- branches/trac226/src/lib/cc/session.cc (original)
+++ branches/trac226/src/lib/cc/session.cc Thu Dec 23 14:58:15 2010
@@ -171,7 +171,7 @@
asio::async_read(socket_, asio::buffer(data, datalen),
boost::bind(&setResult, &read_result, _1));
asio::deadline_timer timer(socket_.io_service());
-
+
if (getTimeout() != 0) {
timer.expires_from_now(boost::posix_time::milliseconds(getTimeout()));
timer.async_wait(boost::bind(&setResult, &timer_result, _1));
Modified: branches/trac226/src/lib/config/module_spec.cc
==============================================================================
--- branches/trac226/src/lib/config/module_spec.cc (original)
+++ branches/trac226/src/lib/config/module_spec.cc Thu Dec 23 14:58:15 2010
@@ -330,14 +330,33 @@
ModuleSpec::validate_spec_list(ConstElementPtr spec, ConstElementPtr data,
const bool full, ElementPtr errors) const
{
+ bool validated = true;
std::string cur_item_name;
BOOST_FOREACH(ConstElementPtr cur_spec_el, spec->listValue()) {
if (!validate_spec(cur_spec_el, data, full, errors)) {
- return (false);
- }
- }
- return (true);
-}
-
-}
-}
+ validated = false;
+ }
+ }
+
+ typedef std::pair<std::string, ConstElementPtr> maptype;
+
+ BOOST_FOREACH(maptype m, data->mapValue()) {
+ bool found = false;
+ BOOST_FOREACH(ConstElementPtr cur_spec_el, spec->listValue()) {
+ if (cur_spec_el->get("item_name")->stringValue().compare(m.first) == 0) {
+ found = true;
+ }
+ }
+ if (!found) {
+ validated = false;
+ if (errors) {
+ errors->add(Element::create("Unknown item " + m.first));
+ }
+ }
+ }
+
+ return (validated);
+}
+
+}
+}
Modified: branches/trac226/src/lib/config/tests/module_spec_unittests.cc
==============================================================================
--- branches/trac226/src/lib/config/tests/module_spec_unittests.cc (original)
+++ branches/trac226/src/lib/config/tests/module_spec_unittests.cc Thu Dec 23 14:58:15 2010
@@ -166,8 +166,13 @@
EXPECT_TRUE(data_test(dd, "data22_6.data"));
EXPECT_TRUE(data_test(dd, "data22_7.data"));
EXPECT_FALSE(data_test(dd, "data22_8.data"));
+ EXPECT_FALSE(data_test(dd, "data22_9.data"));
ElementPtr errors = Element::createList();
EXPECT_FALSE(data_test_with_errors(dd, "data22_8.data", errors));
EXPECT_EQ("[ \"Type mismatch\" ]", errors->str());
+
+ errors = Element::createList();
+ EXPECT_FALSE(data_test_with_errors(dd, "data22_9.data", errors));
+ EXPECT_EQ("[ \"Unknown item value_does_not_exist\" ]", errors->str());
}
Modified: branches/trac226/src/lib/config/tests/testdata/Makefile.am
==============================================================================
--- branches/trac226/src/lib/config/tests/testdata/Makefile.am (original)
+++ branches/trac226/src/lib/config/tests/testdata/Makefile.am Thu Dec 23 14:58:15 2010
@@ -20,6 +20,7 @@
EXTRA_DIST += data22_6.data
EXTRA_DIST += data22_7.data
EXTRA_DIST += data22_8.data
+EXTRA_DIST += data22_9.data
EXTRA_DIST += spec1.spec
EXTRA_DIST += spec2.spec
EXTRA_DIST += spec3.spec
Modified: branches/trac226/src/lib/config/tests/testdata/data22_8.data
==============================================================================
--- branches/trac226/src/lib/config/tests/testdata/data22_8.data (original)
+++ branches/trac226/src/lib/config/tests/testdata/data22_8.data Thu Dec 23 14:58:15 2010
@@ -5,5 +5,6 @@
"value4": "foo",
"value5": [ 1, 2, 3 ],
"value6": { "v61": "bar", "v62": true },
- "value8": [ { "a": "d" }, { "a": 1 } ]
+ "value8": [ { "a": "d" }, { "a": 1 } ],
+ "value9": { "v91": "hi", "v92": { "v92a": "Hi", "v92b": 3 } }
}
Modified: branches/trac226/src/lib/datasrc/Makefile.am
==============================================================================
--- branches/trac226/src/lib/datasrc/Makefile.am (original)
+++ branches/trac226/src/lib/datasrc/Makefile.am Thu Dec 23 14:58:15 2010
@@ -15,5 +15,8 @@
libdatasrc_la_SOURCES += sqlite3_datasrc.h sqlite3_datasrc.cc
libdatasrc_la_SOURCES += query.h query.cc
libdatasrc_la_SOURCES += cache.h cache.cc
+libdatasrc_la_SOURCES += rbtree.h
libdatasrc_la_SOURCES += zonetable.h zonetable.cc
libdatasrc_la_SOURCES += memory_datasrc.h memory_datasrc.cc
+libdatasrc_la_SOURCES += zone.h
+libdatasrc_la_SOURCES += result.h
Modified: branches/trac226/src/lib/datasrc/memory_datasrc.cc
==============================================================================
--- branches/trac226/src/lib/datasrc/memory_datasrc.cc (original)
+++ branches/trac226/src/lib/datasrc/memory_datasrc.cc Thu Dec 23 14:58:15 2010
@@ -12,14 +12,77 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
+#include <map>
+#include <boost/shared_ptr.hpp>
+
#include <dns/name.h>
+#include <dns/rrclass.h>
+
#include <datasrc/memory_datasrc.h>
+#include <datasrc/rbtree.h>
using namespace std;
using namespace isc::dns;
namespace isc {
namespace datasrc {
+
+// Private data and hidden methods of MemoryZone
+struct MemoryZone::MemoryZoneImpl {
+ // Constructor
+ MemoryZoneImpl(const RRClass& zone_class, const Name& origin) :
+ zone_class_(zone_class), origin_(origin)
+ {}
+
+ // Information about the zone
+ RRClass zone_class_;
+ Name origin_;
+
+ // Some type aliases
+ /*
+ * Each domain consists of some RRsets. They will be looked up by the
+ * RRType.
+ *
+ * The use of map is questionable with regard to performance - there'll
+ * be usually only few RRsets in the domain, so the log n benefit isn't
+ * much and a vector/array might be faster due to its simplicity and
+ * continuous memory location. But this is unlikely to be a performance
+ * critical place and map has better interface for the lookups, so we use
+ * that.
+ */
+ typedef map<RRType, ConstRRsetPtr> Domain;
+ typedef boost::shared_ptr<Domain> DomainPtr;
+ // The tree stores domains
+ typedef RBTree<Domain> DomainTree;
+ typedef RBNode<Domain> DomainNode;
+ // The actual zone data
+ DomainTree domains_;
+};
+
+MemoryZone::MemoryZone(const RRClass& zone_class, const Name& origin) :
+ impl_(new MemoryZoneImpl(zone_class, origin))
+{
+}
+
+MemoryZone::~MemoryZone() {
+ delete impl_;
+}
+
+const Name&
+MemoryZone::getOrigin() const {
+ return (impl_->origin_);
+}
+
+const RRClass&
+MemoryZone::getClass() const {
+ return (impl_->zone_class_);
+}
+
+Zone::FindResult
+MemoryZone::find(const Name&, const RRType&) const {
+ // This is a tentative implementation that always returns NXDOMAIN.
+ return (FindResult(NXDOMAIN, RRsetPtr()));
+}
/// Implementation details for \c MemoryDataSrc hidden from the public
/// interface.
Modified: branches/trac226/src/lib/datasrc/memory_datasrc.h
==============================================================================
--- branches/trac226/src/lib/datasrc/memory_datasrc.h (original)
+++ branches/trac226/src/lib/datasrc/memory_datasrc.h Thu Dec 23 14:58:15 2010
@@ -23,6 +23,51 @@
};
namespace datasrc {
+
+/// A derived zone class intended to be used with the memory data source.
+class MemoryZone : public Zone {
+ ///
+ /// \name Constructors and Destructor.
+ ///
+ /// \b Note:
+ /// The copy constructor and the assignment operator are intentionally
+ /// defined as private, making this class non copyable.
+ //@{
+private:
+ MemoryZone(const MemoryZone& source);
+ MemoryZone& operator=(const MemoryZone& source);
+public:
+ /// \brief Constructor from zone parameters.
+ ///
+ /// This constructor internally involves resource allocation, and if
+ /// it fails, a corresponding standard exception will be thrown.
+ /// It never throws an exception otherwise.
+ ///
+ /// \param rrclass The RR class of the zone.
+ /// \param origin The origin name of the zone.
+ MemoryZone(const isc::dns::RRClass& rrclass, const isc::dns::Name& origin);
+
+ /// The destructor.
+ virtual ~MemoryZone();
+ //@}
+
+ /// \brief Returns the origin of the zone.
+ virtual const isc::dns::Name& getOrigin() const;
+ /// \brief Returns the class of the zone.
+ virtual const isc::dns::RRClass& getClass() const;
+ /// \brief Looks up an RRset in the zone.
+ ///
+ /// See documentation in \c Zone.
+ virtual FindResult find(const isc::dns::Name& name,
+ const isc::dns::RRType& type) const;
+
+private:
+ /// \name Hidden private data
+ //@{
+ struct MemoryZoneImpl;
+ MemoryZoneImpl* impl_;
+ //@}
+};
/// \brief A data source that uses in memory dedicated backend.
///
Modified: branches/trac226/src/lib/datasrc/tests/Makefile.am
==============================================================================
--- branches/trac226/src/lib/datasrc/tests/Makefile.am (original)
+++ branches/trac226/src/lib/datasrc/tests/Makefile.am Thu Dec 23 14:58:15 2010
@@ -24,6 +24,7 @@
run_unittests_SOURCES += query_unittest.cc
run_unittests_SOURCES += cache_unittest.cc
run_unittests_SOURCES += test_datasrc.h test_datasrc.cc
+run_unittests_SOURCES += rbtree_unittest.cc
run_unittests_SOURCES += zonetable_unittest.cc
run_unittests_SOURCES += memory_datasrc_unittest.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
Modified: branches/trac226/src/lib/datasrc/tests/memory_datasrc_unittest.cc
==============================================================================
--- branches/trac226/src/lib/datasrc/tests/memory_datasrc_unittest.cc (original)
+++ branches/trac226/src/lib/datasrc/tests/memory_datasrc_unittest.cc Thu Dec 23 14:58:15 2010
@@ -17,7 +17,6 @@
#include <dns/name.h>
#include <dns/rrclass.h>
-#include <datasrc/zonetable.h>
#include <datasrc/memory_datasrc.h>
#include <gtest/gtest.h>
@@ -112,4 +111,31 @@
EXPECT_EQ(Name("i.g.h"),
memory_datasrc.findZone(Name("z.i.g.h")).zone->getOrigin());
}
+
+/// \brief Test fixture for the MemoryZone class
+class MemoryZoneTest : public ::testing::Test {
+public:
+ MemoryZoneTest() :
+ class_(RRClass::IN()),
+ origin_("example.org"),
+ zone_(class_, origin_)
+ { }
+ // Some data to test with
+ RRClass class_;
+ Name origin_;
+ // The zone to torture by tests
+ MemoryZone zone_;
+};
+
+/**
+ * \brief Test MemoryZone::MemoryZone constructor.
+ *
+ * Takes the created zone and checks its properties they are the same
+ * as passed parameters.
+ */
+TEST_F(MemoryZoneTest, Constructor) {
+ ASSERT_EQ(class_, zone_.getClass());
+ ASSERT_EQ(origin_, zone_.getOrigin());
}
+
+}
Modified: branches/trac226/src/lib/datasrc/tests/zonetable_unittest.cc
==============================================================================
--- branches/trac226/src/lib/datasrc/tests/zonetable_unittest.cc (original)
+++ branches/trac226/src/lib/datasrc/tests/zonetable_unittest.cc Thu Dec 23 14:58:15 2010
@@ -18,6 +18,8 @@
#include <dns/rrclass.h>
#include <datasrc/zonetable.h>
+// We use MemoryZone to put something into the table
+#include <datasrc/memory_datasrc.h>
#include <gtest/gtest.h>
@@ -73,7 +75,7 @@
EXPECT_THROW(zone_table.addZone(ZonePtr()), isc::InvalidParameter);
}
-TEST_F(ZoneTableTest, removeZone) {
+TEST_F(ZoneTableTest, DISABLED_removeZone) {
EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone1));
EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone2));
EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone3));
Modified: branches/trac226/src/lib/datasrc/zonetable.cc
==============================================================================
--- branches/trac226/src/lib/datasrc/zonetable.cc (original)
+++ branches/trac226/src/lib/datasrc/zonetable.cc Thu Dec 23 14:58:15 2010
@@ -12,15 +12,12 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
-// Note: map and utility (for 'pair') are for temporary workaround.
-// we'll soon replace them with built-in intelligent backend structure.
-#include <map>
-#include <utility>
+#include <cassert>
#include <dns/name.h>
-#include <dns/rrclass.h>
#include <datasrc/zonetable.h>
+#include <datasrc/rbtree.h>
using namespace std;
using namespace isc::dns;
@@ -28,46 +25,77 @@
namespace isc {
namespace datasrc {
-struct MemoryZone::MemoryZoneImpl {
- MemoryZoneImpl(const RRClass& zone_class, const Name& origin) :
- zone_class_(zone_class), origin_(origin)
- {}
- RRClass zone_class_;
- Name origin_;
-};
+/// \short Private data and implementation of ZoneTable
+struct ZoneTable::ZoneTableImpl {
+ // Type aliases to make it shorter
+ typedef RBTree<Zone> ZoneTree;
+ typedef RBNode<Zone> ZoneNode;
+ // The actual storage
+ ZoneTree zones_;
-MemoryZone::MemoryZone(const RRClass& zone_class, const Name& origin) :
- impl_(new MemoryZoneImpl(zone_class, origin))
-{
-}
+ /*
+ * The implementation methods are here and just wrap-called in the
+ * ZoneTable. We have variables locally (without impl_->), have
+ * type aliases, etc. And they will get inlined anyway.
+ */
-MemoryZone::~MemoryZone() {
- delete impl_;
-}
+ // Implementation of ZoneTable::addZone
+ result::Result addZone(ZonePtr zone) {
+ // Sanity check
+ if (!zone) {
+ isc_throw(InvalidParameter,
+ "Null pointer is passed to ZoneTable::addZone()");
+ }
-const Name&
-MemoryZone::getOrigin() const {
- return (impl_->origin_);
-}
+ // Get the node where we put the zone
+ ZoneNode* node(NULL);
+ switch (zones_.insert(zone->getOrigin(), &node)) {
+ // This is OK
+ case ZoneTree::SUCCEED:
+ case ZoneTree::ALREADYEXIST:
+ break;
+ // Can Not Happen
+ default:
+ assert(0);
+ }
+ // Can Not Happen
+ assert(node);
-const RRClass&
-MemoryZone::getClass() const {
- return (impl_->zone_class_);
-}
+ // Is it empty? We either just created it or it might be nonterminal
+ if (node->isEmpty()) {
+ node->setData(zone);
+ return (result::SUCCESS);
+ } else { // There's something there already
+ return (result::EXIST);
+ }
+ }
-Zone::FindResult
-MemoryZone::find(const Name&, const RRType&) const {
- // This is a tentative implementation that always returns NXDOMAIN.
- return (FindResult(NXDOMAIN, RRsetPtr()));
-}
+ // Implementation of ZoneTable::findZone
+ ZoneTable::FindResult findZone(const Name& name) const {
+ ZoneNode *node(NULL);
+ result::Result my_result;
-// This is a temporary, inefficient implementation using std::map and handmade
-// iteration to realize longest match.
+ // Translate the return codes
+ switch (zones_.find(name, &node)) {
+ case ZoneTree::EXACTMATCH:
+ my_result = result::SUCCESS;
+ break;
+ case ZoneTree::PARTIALMATCH:
+ my_result = result::PARTIALMATCH;
+ break;
+ // We have no data there, so translate the pointer to NULL as well
+ case ZoneTree::NOTFOUND:
+ return (FindResult(result::NOTFOUND, ConstZonePtr()));
+ // Can Not Happen
+ default:
+ assert(0);
+ }
-struct ZoneTable::ZoneTableImpl {
- typedef map<Name, ZonePtr> ZoneMap;
- typedef pair<Name, ZonePtr> NameAndZone;
- ZoneMap zones;
+ // Can Not Happen (remember, NOTFOUND is handled)
+ assert(node);
+
+ return (FindResult(my_result, node->getData()));
+ }
};
ZoneTable::ZoneTable() : impl_(new ZoneTableImpl)
@@ -79,40 +107,21 @@
result::Result
ZoneTable::addZone(ZonePtr zone) {
- if (!zone) {
- isc_throw(InvalidParameter,
- "Null pointer is passed to ZoneTable::addZone()");
- }
-
- if (impl_->zones.insert(
- ZoneTableImpl::NameAndZone(zone->getOrigin(), zone)).second
- == true) {
- return (result::SUCCESS);
- } else {
- return (result::EXIST);
- }
+ return (impl_->addZone(zone));
}
result::Result
-ZoneTable::removeZone(const Name& origin) {
- return (impl_->zones.erase(origin) == 1 ? result::SUCCESS :
- result::NOTFOUND);
+ZoneTable::removeZone(const Name&) {
+ // TODO Implement
+ assert(0);
+ // This should not ever be returned, the assert should kill us by now
+ return (result::SUCCESS);
}
ZoneTable::FindResult
ZoneTable::findZone(const Name& name) const {
- // Inefficient internal loop to find a longest match.
- // This will be replaced with a single call to more intelligent backend.
- for (int i = 0; i < name.getLabelCount(); ++i) {
- Name matchname(name.split(i));
- ZoneTableImpl::ZoneMap::const_iterator found =
- impl_->zones.find(matchname);
- if (found != impl_->zones.end()) {
- return (FindResult(i == 0 ? result::SUCCESS :
- result::PARTIALMATCH, (*found).second));
- }
- }
- return (FindResult(result::NOTFOUND, ConstZonePtr()));
+ return (impl_->findZone(name));
}
+
} // end of namespace datasrc
} // end of namespace isc
Modified: branches/trac226/src/lib/datasrc/zonetable.h
==============================================================================
--- branches/trac226/src/lib/datasrc/zonetable.h (original)
+++ branches/trac226/src/lib/datasrc/zonetable.h Thu Dec 23 14:58:15 2010
@@ -19,6 +19,8 @@
#include <dns/rrset.h>
+#include <datasrc/zone.h>
+
namespace isc {
namespace dns {
class Name;
@@ -26,215 +28,6 @@
};
namespace datasrc {
-namespace result {
-/// Result codes of various public methods of in memory data source
-///
-/// The detailed semantics may differ in different methods.
-/// See the description of specific methods for more details.
-///
-/// Note: this is intended to be used from other data sources eventually,
-/// but for now it's specific to in memory data source and its backend.
-enum Result {
- SUCCESS, ///< The operation is successful.
- EXIST, ///< The search key is already stored.
- NOTFOUND, ///< The specified object is not found.
- PARTIALMATCH ///< \c Only a partial match is found.
-};
-}
-
-/// \brief The base class for a single authoritative zone
-///
-/// The \c Zone class is an abstract base class for representing
-/// a DNS zone as part of data source.
-///
-/// At the moment this is provided mainly for making the \c ZoneTable class
-/// and the authoritative query logic testable, and only provides a minimal
-/// set of features.
-/// This is why this class is defined in the same header file, but it may
-/// have to move to a separate header file when we understand what is
-/// necessary for this class for actual operation.
-///
-/// The idea is to provide a specific derived zone class for each data
-/// source, beginning with in memory one. At that point the derived classes
-/// will have more specific features. For example, they will maintain
-/// information about the location of a zone file, whether it's loaded in
-/// memory, etc.
-///
-/// It's not yet clear how the derived zone classes work with various other
-/// data sources when we integrate these components, but one possibility is
-/// something like this:
-/// - If the underlying database such as some variant of SQL doesn't have an
-/// explicit representation of zones (as part of public interface), we can
-/// probably use a "default" zone class that simply encapsulates the
-/// corresponding data source and calls a common "find" like method.
-/// - Some data source may want to specialize it by inheritance as an
-/// optimization. For example, in the current schema design of the sqlite3
-/// data source, its (derived) zone class would contain the information of
-/// the "zone ID".
-///
-/// <b>Note:</b> Unlike some other abstract base classes we don't name the
-/// class beginning with "Abstract". This is because we want to have
-/// commonly used definitions such as \c Result and \c ZonePtr, and we want
-/// to make them look more intuitive.
-class Zone {
-public:
- /// Result codes of the \c find() method.
- ///
- /// Note: the codes are tentative. We may need more, or we may find
- /// some of them unnecessary as we implement more details.
- enum Result {
- SUCCESS, ///< An exact match is found.
- DELEGATION, ///< The search encounters a zone cut.
- NXDOMAIN, ///< There is no domain name that matches the search name
- NXRRSET, ///< There is a matching name but no RRset of the search type
- CNAME, ///< The search encounters and returns a CNAME RR
- DNAME ///< The search encounters and returns a DNAME RR
- };
-
- /// A helper structure to represent the search result of \c find().
- ///
- /// This is a straightforward tuple of the result code and a pointer
- /// to the found RRset to represent the result of \c find()
- /// (there will be more members in the future - see the class
- /// description).
- /// We use this in order to avoid overloading the return value for both
- /// the result code ("success" or "not found") and the found object,
- /// i.e., avoid using \c NULL to mean "not found", etc.
- ///
- /// This is a simple value class whose internal state never changes,
- /// so for convenience we allow the applications to refer to the members
- /// directly.
- ///
- /// Note: we should eventually include a notion of "zone node", which
- /// corresponds to a particular domain name of the zone, so that we can
- /// find RRsets of a different RR type for that name (e.g. for type ANY
- /// query or to include DS RRs with delegation).
- ///
- /// Note: we may also want to include the closest enclosure "node" to
- /// optimize including the NSEC for no-wildcard proof (FWIW NSD does that).
- struct FindResult {
- FindResult(Result param_code,
- const isc::dns::ConstRRsetPtr param_rrset) :
- code(param_code), rrset(param_rrset)
- {}
- const Result code;
- const isc::dns::ConstRRsetPtr rrset;
- };
-
- ///
- /// \name Constructors and Destructor.
- ///
- //@{
-protected:
- /// The default constructor.
- ///
- /// This is intentionally defined as \c protected as this base class should
- /// never be instantiated (except as part of a derived class).
- Zone() {}
-public:
- /// The destructor.
- virtual ~Zone() {}
- //@}
-
- ///
- /// \name Getter Methods
- ///
- /// These methods should never throw an exception.
- //@{
- /// Return the origin name of the zone.
- virtual const isc::dns::Name& getOrigin() const = 0;
-
- /// Return the RR class of the zone.
- virtual const isc::dns::RRClass& getClass() const = 0;
- //@}
-
- ///
- /// \name Search Method
- ///
- //@{
- /// Search the zone for a given pair of domain name and RR type.
- ///
- /// Each derived version of this method searches the underlying backend
- /// for the data that best matches the given name and type.
- /// This method is expected to be "intelligent", and identifies the
- /// best possible answer for the search key. Specifically,
- /// - If the search name belongs under a zone cut, it returns the code
- /// of \c DELEGATION and the NS RRset at the zone cut.
- /// - If there is no matching name, it returns the code of \c NXDOMAIN,
- /// and, if DNSSEC is requested, the NSEC RRset that proves the
- /// non-existence.
- /// - If there is a matching name but no RRset of the search type, it
- /// returns the code of \c NXRRSET, and, if DNSSEC is required,
- /// the NSEC RRset for that name.
- /// - If there is a matching name with CNAME, it returns the code of
- /// \c CNAME and that CNAME RR.
- /// - If the search name matches a delegation point of DNAME, it returns
- /// the code of \c DNAME and that DNAME RR.
- ///
- /// A derived version of this method may involve internal resource
- /// allocation, especially for constructing the resulting RRset, and may
- /// throw an exception if it fails.
- /// It should not throw other types of exceptions.
- ///
- /// Note: It's quite likely that we'll need to specify search options.
- /// For example, we should be able to specify whether to allow returning
- /// glue records at or under a zone cut. We leave this interface open
- /// at this moment.
- ///
- /// \param name The domain name to be searched for.
- /// \param type The RR type to be searched for.
- /// \return A \c FindResult object enclosing the search result (see above).
- virtual FindResult find(const isc::dns::Name& name,
- const isc::dns::RRType& type) const = 0;
- //@}
-};
-
-/// \brief A pointer-like type pointing to a \c Zone object.
-typedef boost::shared_ptr<Zone> ZonePtr;
-
-/// \brief A pointer-like type pointing to a \c Zone object.
-typedef boost::shared_ptr<const Zone> ConstZonePtr;
-
-/// A derived zone class intended to be used with the memory data source.
-///
-/// Currently this is almost empty and is only used for testing the
-/// \c ZoneTable class. It will be substantially expanded, and will probably
-/// moved to a separate header file.
-class MemoryZone : public Zone {
- ///
- /// \name Constructors and Destructor.
- ///
- /// \b Note:
- /// The copy constructor and the assignment operator are intentionally
- /// defined as private, making this class non copyable.
- //@{
-private:
- MemoryZone(const MemoryZone& source);
- MemoryZone& operator=(const MemoryZone& source);
-public:
- /// \brief Constructor from zone parameters.
- ///
- /// This constructor internally involves resource allocation, and if
- /// it fails, a corresponding standard exception will be thrown.
- /// It never throws an exception otherwise.
- ///
- /// \param rrclass The RR class of the zone.
- /// \param origin The origin name of the zone.
- MemoryZone(const isc::dns::RRClass& rrclass, const isc::dns::Name& origin);
-
- /// The destructor.
- virtual ~MemoryZone();
- //@}
-
- virtual const isc::dns::Name& getOrigin() const;
- virtual const isc::dns::RRClass& getClass() const;
- virtual FindResult find(const isc::dns::Name& name,
- const isc::dns::RRType& type) const;
-
-private:
- struct MemoryZoneImpl;
- MemoryZoneImpl* impl_;
-};
/// \brief A set of authoritative zones.
///
@@ -278,8 +71,18 @@
//@}
/// Add a \c Zone to the \c ZoneTable.
- /// See the description of <code>MemoryDataSrc::addZone()</code> for more
- /// details.
+ ///
+ /// \c Zone must not be associated with a NULL pointer; otherwise
+ /// an exception of class \c InvalidParameter will be thrown.
+ /// If internal resource allocation fails, a corresponding standard
+ /// exception will be thrown.
+ /// This method never throws an exception otherwise.
+ ///
+ /// \param zone A \c Zone object to be added.
+ /// \return \c result::SUCCESS If the zone is successfully
+ /// added to the zone table.
+ /// \return \c result::EXIST The zone table already contains
+ /// zone of the same origin.
result::Result addZone(ZonePtr zone);
/// Remove a \c Zone of the given origin name from the \c ZoneTable.
@@ -294,8 +97,23 @@
result::Result removeZone(const isc::dns::Name& origin);
/// Find a \c Zone that best matches the given name in the \c ZoneTable.
- /// See the description of <code>MemoryDataSrc::findZone()</code> for more
- /// details.
+ ///
+ /// It searches the internal storage for a \c Zone that gives the
+ /// longest match against \c name, and returns the result in the
+ /// form of a \c FindResult object as follows:
+ /// - \c code: The result code of the operation.
+ /// - \c result::SUCCESS: A zone that gives an exact match
+ /// is found
+ /// - \c result::PARTIALMATCH: A zone whose origin is a
+ /// super domain of \c name is found (but there is no exact match)
+ /// - \c result::NOTFOUND: For all other cases.
+ /// - \c zone: A <Boost> shared pointer to the found \c Zone object if one
+ /// is found; otherwise \c NULL.
+ ///
+ /// This method never throws an exception.
+ ///
+ /// \param name A domain name for which the search is performed.
+ /// \return A \c FindResult object enclosing the search result (see above).
FindResult findZone(const isc::dns::Name& name) const;
private:
Modified: branches/trac226/src/lib/dns/buffer.h
==============================================================================
--- branches/trac226/src/lib/dns/buffer.h (original)
+++ branches/trac226/src/lib/dns/buffer.h Thu Dec 23 14:58:15 2010
@@ -25,6 +25,8 @@
#include <exceptions/exceptions.h>
+#include <boost/shared_ptr.hpp>
+
namespace isc {
namespace dns {
@@ -412,6 +414,16 @@
private:
std::vector<uint8_t> data_;
};
+
+/// \brief Pointer-like types pointing to \c InputBuffer or \c OutputBuffer
+///
+/// These types are expected to be used as an argument in asynchronous
+/// callback functions. The internal reference-counting will ensure that
+/// that ongoing state information will not be lost if the object
+/// that originated the asynchronous call falls out of scope.
+typedef boost::shared_ptr<InputBuffer> InputBufferPtr;
+typedef boost::shared_ptr<OutputBuffer> OutputBufferPtr;
+
}
}
#endif // __BUFFER_H
Modified: branches/trac226/src/lib/dns/masterload.h
==============================================================================
--- branches/trac226/src/lib/dns/masterload.h (original)
+++ branches/trac226/src/lib/dns/masterload.h Thu Dec 23 14:58:15 2010
@@ -30,7 +30,7 @@
/// \brief An exception that is thrown if an error occurs while loading a
/// master zone data.
-class MasterLoadError : public Exception {
+class MasterLoadError : public isc::Exception {
public:
MasterLoadError(const char* file, size_t line, const char* what) :
isc::Exception(file, line, what) {}
Modified: branches/trac226/src/lib/dns/message.h
==============================================================================
--- branches/trac226/src/lib/dns/message.h (original)
+++ branches/trac226/src/lib/dns/message.h Thu Dec 23 14:58:15 2010
@@ -517,6 +517,14 @@
MessageImpl* impl_;
};
+/// \brief Pointer-like type pointing to a \c Message
+///
+/// This type is expected to be used as an argument in asynchronous
+/// callback functions. The internal reference-counting will ensure that
+/// that ongoing state information will not be lost if the object
+/// that originated the asynchronous call falls out of scope.
+typedef boost::shared_ptr<Message> MessagePtr;
+
std::ostream& operator<<(std::ostream& os, const Message& message);
}
}
Modified: branches/trac226/src/lib/dns/messagerenderer.h
==============================================================================
--- branches/trac226/src/lib/dns/messagerenderer.h (original)
+++ branches/trac226/src/lib/dns/messagerenderer.h Thu Dec 23 14:58:15 2010
@@ -258,6 +258,7 @@
/// \param name A \c Name object to be written.
/// \param compress A boolean indicating whether to enable name compression.
void writeName(const Name& name, bool compress = true);
+ //@}
private:
struct MessageRendererImpl;
MessageRendererImpl* impl_;
Modified: branches/trac226/src/lib/dns/tests/unittest_util.cc
==============================================================================
--- branches/trac226/src/lib/dns/tests/unittest_util.cc (original)
+++ branches/trac226/src/lib/dns/tests/unittest_util.cc Thu Dec 23 14:58:15 2010
@@ -25,13 +25,15 @@
#include <gtest/gtest.h>
+#include <dns/rcode.h>
#include <dns/name.h>
+#include <dns/message.h>
#include <dns/tests/unittest_util.h>
using namespace std;
+using namespace isc::dns;
using isc::UnitTestUtil;
-using isc::dns::NameComparisonResult;
namespace {
class UnitTestUtilConfig {
@@ -175,3 +177,19 @@
}
return (::testing::AssertionSuccess());
}
+
+void
+UnitTestUtil::createRequestMessage(Message& message,
+ const Opcode& opcode,
+ const uint16_t qid,
+ const Name& name,
+ const RRClass& rrclass,
+ const RRType& rrtype)
+{
+ message.clear(Message::RENDER);
+ message.setOpcode(opcode);
+ message.setRcode(Rcode::NOERROR());
+ message.setQid(qid);
+ message.addQuestion(Question(name, rrclass, rrtype));
+}
+
Modified: branches/trac226/src/lib/dns/tests/unittest_util.h
==============================================================================
--- branches/trac226/src/lib/dns/tests/unittest_util.h (original)
+++ branches/trac226/src/lib/dns/tests/unittest_util.h Thu Dec 23 14:58:15 2010
@@ -21,6 +21,7 @@
#include <string>
#include <dns/name.h>
+#include <dns/message.h>
#include <gtest/gtest.h>
@@ -80,6 +81,20 @@
static ::testing::AssertionResult
matchName(const char* nameexp1, const char* nameexp2,
const isc::dns::Name& name1, const isc::dns::Name& name2);
+
+ ///
+ /// Populate a request message
+ ///
+ /// Create a request message in 'request_message' using the
+ /// opcode 'opcode' and the name/class/type query tuple specified in
+ /// 'name', 'rrclass' and 'rrtype.
+ static void
+ createRequestMessage(isc::dns::Message& request_message,
+ const isc::dns::Opcode& opcode,
+ const uint16_t qid,
+ const isc::dns::Name& name,
+ const isc::dns::RRClass& rrclass,
+ const isc::dns::RRType& rrtype);
};
}
#endif // __UNITTEST_UTIL_H
Modified: branches/trac226/src/lib/nsas/address_entry.cc
==============================================================================
--- branches/trac226/src/lib/nsas/address_entry.cc (original)
+++ branches/trac226/src/lib/nsas/address_entry.cc Thu Dec 23 14:58:15 2010
@@ -35,6 +35,8 @@
#define __STDC_LIMIT_MACROS
#include <stdint.h>
+#include <config.h>
+
#include "address_entry.h"
namespace isc {
Modified: branches/trac226/src/lib/nsas/hash_key.h
==============================================================================
--- branches/trac226/src/lib/nsas/hash_key.h (original)
+++ branches/trac226/src/lib/nsas/hash_key.h Thu Dec 23 14:58:15 2010
@@ -21,7 +21,6 @@
#include <stdint.h>
#include <string>
-#include <config.h>
namespace isc {
namespace nsas {
Modified: branches/trac226/src/lib/nsas/hash_table.h
==============================================================================
--- branches/trac226/src/lib/nsas/hash_table.h (original)
+++ branches/trac226/src/lib/nsas/hash_table.h Thu Dec 23 14:58:15 2010
@@ -17,14 +17,24 @@
#ifndef __HASH_TABLE_H
#define __HASH_TABLE_H
+// Workaround for a problem with boost and sunstudio 5.10
+// There is a version check in there that appears wrong,
+// which makes including boost/thread.hpp fail
+// This will probably be fixed in a future version of boost,
+// in which case this part can be removed then
+#ifdef NEED_SUNPRO_WORKAROUND
+#if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100
+#undef __SUNPRO_CC
+#define __SUNPRO_CC 0x5090
+#endif
+#endif // NEED_SUNPRO_WORKAROUND
+
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/interprocess/sync/sharable_lock.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
#include <boost/interprocess/sync/interprocess_upgradable_mutex.hpp>
#include <list>
-
-#include <config.h>
#include "hash.h"
#include "hash_key.h"
Modified: branches/trac226/src/lib/nsas/lru_list.h
==============================================================================
--- branches/trac226/src/lib/nsas/lru_list.h (original)
+++ branches/trac226/src/lib/nsas/lru_list.h Thu Dec 23 14:58:15 2010
@@ -20,12 +20,22 @@
#include <list>
#include <string>
+// Workaround for a problem with boost and sunstudio 5.10
+// There is a version check in there that appears wrong,
+// which makes including boost/thread.hpp fail
+// This will probably be fixed in a future version of boost,
+// in which case this part can be removed then
+#ifdef NEED_SUNPRO_WORKAROUND
+#if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100
+#undef __SUNPRO_CC
+#define __SUNPRO_CC 0x5090
+#endif
+#endif // NEED_SUNPRO_WORKAROUND
+
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
-
-#include <config.h>
namespace isc {
namespace nsas {
Modified: branches/trac226/src/lib/nsas/nameserver_address.cc
==============================================================================
--- branches/trac226/src/lib/nsas/nameserver_address.cc (original)
+++ branches/trac226/src/lib/nsas/nameserver_address.cc Thu Dec 23 14:58:15 2010
@@ -14,6 +14,8 @@
// $id$
+#include <config.h>
+
#include "nameserver_address.h"
#include "nameserver_entry.h"
Modified: branches/trac226/src/lib/nsas/nameserver_address_store.cc
==============================================================================
--- branches/trac226/src/lib/nsas/nameserver_address_store.cc (original)
+++ branches/trac226/src/lib/nsas/nameserver_address_store.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,21 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+
+#include <config.h>
+
+// Workaround for a problem with boost and sunstudio 5.10
+// There is a version check in there that appears wrong,
+// which makes including boost/thread.hpp fail
+// This will probably be fixed in a future version of boost,
+// in which case this part can be removed then
+#ifdef NEED_SUNPRO_WORKAROUND
+#if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100
+#undef __SUNPRO_CC
+#define __SUNPRO_CC 0x5090
+#endif
+#endif // NEED_SUNPRO_WORKAROUND
+
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
Modified: branches/trac226/src/lib/nsas/nameserver_entry.cc
==============================================================================
--- branches/trac226/src/lib/nsas/nameserver_entry.cc (original)
+++ branches/trac226/src/lib/nsas/nameserver_entry.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,8 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+
+#include <config.h>
#include <algorithm>
#include <functional>
Modified: branches/trac226/src/lib/nsas/nameserver_entry.h
==============================================================================
--- branches/trac226/src/lib/nsas/nameserver_entry.h (original)
+++ branches/trac226/src/lib/nsas/nameserver_entry.h Thu Dec 23 14:58:15 2010
@@ -16,6 +16,18 @@
#ifndef __NAMESERVER_ENTRY_H
#define __NAMESERVER_ENTRY_H
+
+// Workaround for a problem with boost and sunstudio 5.10
+// There is a version check in there that appears wrong,
+// which makes including boost/thread.hpp fail
+// This will probably be fixed in a future version of boost,
+// in which case this part can be removed then
+#ifdef NEED_SUNPRO_WORKAROUND
+#if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100
+#undef __SUNPRO_CC
+#define __SUNPRO_CC 0x5090
+#endif
+#endif // NEED_SUNPRO_WORKAROUND
#include <string>
#include <vector>
Modified: branches/trac226/src/lib/nsas/tests/address_entry_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/address_entry_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/address_entry_unittest.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+#include <config.h>
#include <limits.h>
#include <gtest/gtest.h>
Modified: branches/trac226/src/lib/nsas/tests/fetchable_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/fetchable_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/fetchable_unittest.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $id$
+#include <config.h>
#include "../fetchable.h"
Modified: branches/trac226/src/lib/nsas/tests/hash_deleter_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/hash_deleter_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/hash_deleter_unittest.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+#include <config.h>
#include <algorithm>
#include <string>
Modified: branches/trac226/src/lib/nsas/tests/hash_key_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/hash_key_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/hash_key_unittest.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+#include <config.h>
#include <algorithm>
#include <string>
Modified: branches/trac226/src/lib/nsas/tests/hash_table_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/hash_table_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/hash_table_unittest.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+#include <config.h>
#include <gtest/gtest.h>
#include <boost/shared_ptr.hpp>
Modified: branches/trac226/src/lib/nsas/tests/hash_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/hash_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/hash_unittest.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+#include <config.h>
#include <algorithm>
#include <string>
Modified: branches/trac226/src/lib/nsas/tests/lru_list_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/lru_list_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/lru_list_unittest.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+#include <config.h>
#include <iostream>
#include <algorithm>
Modified: branches/trac226/src/lib/nsas/tests/nameserver_address_store_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/nameserver_address_store_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/nameserver_address_store_unittest.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+#include <config.h>
/// \brief Test Deleter Objects
///
Modified: branches/trac226/src/lib/nsas/tests/nameserver_address_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/nameserver_address_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/nameserver_address_unittest.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+#include <config.h>
#include <gtest/gtest.h>
Modified: branches/trac226/src/lib/nsas/tests/nameserver_entry_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/nameserver_entry_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/nameserver_entry_unittest.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+#include <config.h>
#include <iostream>
#include <algorithm>
Modified: branches/trac226/src/lib/nsas/tests/nsas_entry_compare_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/nsas_entry_compare_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/nsas_entry_compare_unittest.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+#include <config.h>
#include <algorithm>
#include <string>
@@ -37,16 +38,18 @@
// Test of the comparison
TEST_F(NsasEntryCompareTest, Compare) {
+ std::string name1("test1");
+ std::string name2("test2");
// Construct a couple of different objects
- TestEntry entry1("test1", RRClass(42));
- TestEntry entry2("test1", RRClass(24));
- TestEntry entry3("test2", RRClass(42));
+ TestEntry entry1(name1, RRClass(42));
+ TestEntry entry2(name1, RRClass(24));
+ TestEntry entry3(name2, RRClass(42));
// Create corresponding hash key objects
- HashKey key1(entry1.getName(), entry1.getClass());
- HashKey key2(entry2.getName(), entry2.getClass());
- HashKey key3(entry3.getName(), entry3.getClass());
+ HashKey key1(name1, entry1.getClass());
+ HashKey key2(name1, entry2.getClass());
+ HashKey key3(name2, entry3.getClass());
// Perform the comparison
NsasEntryCompare<TestEntry> compare;
Modified: branches/trac226/src/lib/nsas/tests/random_number_generator_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/random_number_generator_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/random_number_generator_unittest.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+#include <config.h>
#include <gtest/gtest.h>
#include <boost/shared_ptr.hpp>
Modified: branches/trac226/src/lib/nsas/tests/run_unittests.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/run_unittests.cc (original)
+++ branches/trac226/src/lib/nsas/tests/run_unittests.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id: run_unittests.cc 3020 2010-09-26 03:47:26Z jinmei $
+#include <config.h>
#include <gtest/gtest.h>
Modified: branches/trac226/src/lib/nsas/tests/zone_entry_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/zone_entry_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/zone_entry_unittest.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+#include <config.h>
#include <gtest/gtest.h>
#include <boost/shared_ptr.hpp>
@@ -711,7 +712,7 @@
for (size_t i(0); i < 3; ++ i) {
double mu = repeats * ps[i];
double sigma = sqrt(repeats * ps[i] * (1 - ps[i]));
- ASSERT_TRUE(fabs(counts[i] - mu < 4 * sigma));
+ ASSERT_TRUE(fabs(counts[i] - mu) < 4 * sigma);
}
// reset the environment
Modified: branches/trac226/src/lib/nsas/zone_entry.cc
==============================================================================
--- branches/trac226/src/lib/nsas/zone_entry.cc (original)
+++ branches/trac226/src/lib/nsas/zone_entry.cc Thu Dec 23 14:58:15 2010
@@ -13,6 +13,8 @@
// PERFORMANCE OF THIS SOFTWARE.
// $id$
+
+#include <config.h>
#include "zone_entry.h"
#include "address_request_callback.h"
Modified: branches/trac226/src/lib/nsas/zone_entry.h
==============================================================================
--- branches/trac226/src/lib/nsas/zone_entry.h (original)
+++ branches/trac226/src/lib/nsas/zone_entry.h Thu Dec 23 14:58:15 2010
@@ -16,6 +16,18 @@
#ifndef __ZONE_ENTRY_H
#define __ZONE_ENTRY_H
+
+// Workaround for a problem with boost and sunstudio 5.10
+// There is a version check in there that appears wrong,
+// which makes including boost/thread.hpp fail
+// This will probably be fixed in a future version of boost,
+// in which case this part can be removed then
+#ifdef NEED_SUNPRO_WORKAROUND
+#if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100
+#undef __SUNPRO_CC
+#define __SUNPRO_CC 0x5090
+#endif
+#endif // NEED_SUNPRO_WORKAROUND
#include <string>
#include <vector>
Modified: branches/trac226/src/lib/python/isc/config/ccsession.py
==============================================================================
--- branches/trac226/src/lib/python/isc/config/ccsession.py (original)
+++ branches/trac226/src/lib/python/isc/config/ccsession.py Thu Dec 23 14:58:15 2010
@@ -224,7 +224,7 @@
if not self._config_handler:
answer = create_answer(2, self._module_name + " has no config handler")
elif not self.get_module_spec().validate_config(False, new_config, errors):
- answer = create_answer(1, " ".join(errors))
+ answer = create_answer(1, ", ".join(errors))
else:
isc.cc.data.remove_identical(new_config, self.get_local_config())
answer = self._config_handler(new_config)
@@ -422,7 +422,16 @@
"""Commit all local changes, send them through b10-cmdctl to
the configuration manager"""
if self.get_local_changes():
- self._conn.send_POST('/ConfigManager/set_config', [ self.get_local_changes() ])
- # todo: check result
- self.request_current_config()
- self.clear_local_changes()
+ response = self._conn.send_POST('/ConfigManager/set_config',
+ [ self.get_local_changes() ])
+ answer = isc.cc.data.parse_value_str(response.read().decode())
+ # answer is either an empty dict (on success), or one
+ # containing errors
+ if answer == {}:
+ self.request_current_config()
+ self.clear_local_changes()
+ elif "error" in answer:
+ print("Error: " + answer["error"])
+ print("Configuration not committed")
+ else:
+ raise ModuleCCSessionError("Unknown format of answer in commit(): " + str(answer))
Modified: branches/trac226/src/lib/python/isc/config/config_data.py
==============================================================================
--- branches/trac226/src/lib/python/isc/config/config_data.py (original)
+++ branches/trac226/src/lib/python/isc/config/config_data.py Thu Dec 23 14:58:15 2010
@@ -464,12 +464,15 @@
there is a specification for the given identifier, the type
is checked."""
spec_part = self.find_spec_part(identifier)
- if spec_part is not None and value is not None:
- id, list_indices = isc.cc.data.split_identifier_list_indices(identifier)
- if list_indices is not None \
- and spec_part['item_type'] == 'list':
- spec_part = spec_part['list_item_spec']
- check_type(spec_part, value)
+ if spec_part is not None:
+ if value is not None:
+ id, list_indices = isc.cc.data.split_identifier_list_indices(identifier)
+ if list_indices is not None \
+ and spec_part['item_type'] == 'list':
+ spec_part = spec_part['list_item_spec']
+ check_type(spec_part, value)
+ else:
+ raise isc.cc.data.DataNotFoundError(identifier)
# Since we do not support list diffs (yet?), we need to
# copy the currently set list of items to _local_changes
Modified: branches/trac226/src/lib/python/isc/config/module_spec.py
==============================================================================
--- branches/trac226/src/lib/python/isc/config/module_spec.py (original)
+++ branches/trac226/src/lib/python/isc/config/module_spec.py Thu Dec 23 14:58:15 2010
@@ -328,7 +328,24 @@
return True
def _validate_spec_list(module_spec, full, data, errors):
+ # we do not return immediately, there may be more errors
+ # so we keep a boolean to keep track if we found errors
+ validated = True
+
+ # check if the known items are correct
for spec_item in module_spec:
if not _validate_spec(spec_item, full, data, errors):
- return False
- return True
+ validated = False
+
+ # check if there are items in our data that are not in the
+ # specification
+ for item_name in data:
+ found = False
+ for spec_item in module_spec:
+ if spec_item["item_name"] == item_name:
+ found = True
+ if not found:
+ if errors != None:
+ errors.append("unknown item " + item_name)
+ validated = False
+ return validated
Modified: branches/trac226/src/lib/python/isc/config/tests/ccsession_test.py
==============================================================================
--- branches/trac226/src/lib/python/isc/config/tests/ccsession_test.py (original)
+++ branches/trac226/src/lib/python/isc/config/tests/ccsession_test.py Thu Dec 23 14:58:15 2010
@@ -290,7 +290,7 @@
mccs = self.create_session("spec2.spec", None, None, fake_session)
mccs.set_config_handler(self.my_config_handler_ok)
self.assertEqual(len(fake_session.message_queue), 0)
- cmd = isc.config.ccsession.create_command(isc.config.ccsession.COMMAND_CONFIG_UPDATE, { 'Spec2': { 'item1': 2 }})
+ cmd = isc.config.ccsession.create_command(isc.config.ccsession.COMMAND_CONFIG_UPDATE, { 'item1': 2 })
fake_session.group_sendmsg(cmd, 'Spec2')
self.assertEqual(len(fake_session.message_queue), 1)
mccs.check_command()
@@ -303,12 +303,12 @@
mccs = self.create_session("spec2.spec", None, None, fake_session)
mccs.set_config_handler(self.my_config_handler_err)
self.assertEqual(len(fake_session.message_queue), 0)
- cmd = isc.config.ccsession.create_command(isc.config.ccsession.COMMAND_CONFIG_UPDATE, { 'Spec2': { 'item1': 'aaa' }})
+ cmd = isc.config.ccsession.create_command(isc.config.ccsession.COMMAND_CONFIG_UPDATE, { 'item1': 'aaa' })
fake_session.group_sendmsg(cmd, 'Spec2')
self.assertEqual(len(fake_session.message_queue), 1)
mccs.check_command()
self.assertEqual(len(fake_session.message_queue), 1)
- self.assertEqual({'result': [1, 'just an error']},
+ self.assertEqual({'result': [1, 'aaa should be an integer']},
fake_session.get_message('Spec2', None))
def test_check_command5(self):
@@ -316,12 +316,12 @@
mccs = self.create_session("spec2.spec", None, None, fake_session)
mccs.set_config_handler(self.my_config_handler_exc)
self.assertEqual(len(fake_session.message_queue), 0)
- cmd = isc.config.ccsession.create_command(isc.config.ccsession.COMMAND_CONFIG_UPDATE, { 'Spec2': { 'item1': 'aaa' }})
+ cmd = isc.config.ccsession.create_command(isc.config.ccsession.COMMAND_CONFIG_UPDATE, { 'item1': 'aaa' })
fake_session.group_sendmsg(cmd, 'Spec2')
self.assertEqual(len(fake_session.message_queue), 1)
mccs.check_command()
self.assertEqual(len(fake_session.message_queue), 1)
- self.assertEqual({'result': [1, 'just an exception']},
+ self.assertEqual({'result': [1, 'aaa should be an integer']},
fake_session.get_message('Spec2', None))
def test_check_command6(self):
@@ -416,7 +416,7 @@
mccs = self.create_session("spec2.spec", None, None, fake_session)
mccs.set_config_handler(self.my_config_handler_ok)
self.assertEqual(len(fake_session.message_queue), 0)
- cmd = isc.config.ccsession.create_command(isc.config.ccsession.COMMAND_CONFIG_UPDATE, { 'Spec2': { 'item1': 2 }})
+ cmd = isc.config.ccsession.create_command(isc.config.ccsession.COMMAND_CONFIG_UPDATE, { 'item1': 2 })
self.assertEqual(len(fake_session.message_queue), 0)
env = { 'group':'Spec2', 'from':None }
mccs.check_command_without_recvmsg(cmd, env)
@@ -559,6 +559,14 @@
mccs.check_command()
self.assertEqual(len(fake_session.message_queue), 0)
+
+class fakeData:
+ def decode(self):
+ return "{}";
+
+class fakeAnswer:
+ def read(self):
+ return fakeData();
class fakeUIConn():
def __init__(self):
@@ -581,7 +589,7 @@
if name in self.post_answers:
return self.post_answers[name]
else:
- return None
+ return fakeAnswer()
class TestUIModuleCCSession(unittest.TestCase):
Modified: branches/trac226/src/lib/python/isc/config/tests/config_data_test.py
==============================================================================
--- branches/trac226/src/lib/python/isc/config/tests/config_data_test.py (original)
+++ branches/trac226/src/lib/python/isc/config/tests/config_data_test.py Thu Dec 23 14:58:15 2010
@@ -335,6 +335,8 @@
pass
def test_get_local_value(self):
+ module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec2.spec")
+ self.mcd.set_specification(module_spec)
value = self.mcd.get_local_value("Spec2/item1")
self.assertEqual(None, value)
self.mcd.set_value("Spec2/item1", 2)
@@ -464,12 +466,11 @@
module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec2.spec")
self.mcd.set_specification(module_spec)
self.mcd.set_value("Spec2/item1", 2)
- self.assertRaises(isc.cc.data.DataTypeError, self.mcd.set_value, "Spec2/item1", "asdf")
-
- self.mcd.set_value("Spec2/no_such_item", 4)
- value, status = self.mcd.get_value("Spec2/no_such_item")
- self.assertEqual(value, 4)
- self.assertEqual(MultiConfigData.LOCAL, status)
+ self.assertRaises(isc.cc.data.DataTypeError,
+ self.mcd.set_value, "Spec2/item1", "asdf")
+
+ self.assertRaises(isc.cc.data.DataNotFoundError,
+ self.mcd.set_value, "Spec2/no_such_item", 4)
self.mcd.set_value("Spec2/item5[0]", "c")
value, status = self.mcd.get_value("Spec2/item5[0]")
Modified: branches/trac226/src/lib/python/isc/config/tests/module_spec_test.py
==============================================================================
--- branches/trac226/src/lib/python/isc/config/tests/module_spec_test.py (original)
+++ branches/trac226/src/lib/python/isc/config/tests/module_spec_test.py Thu Dec 23 14:58:15 2010
@@ -312,6 +312,18 @@
self.assertEqual(False, isc.config.module_spec._validate_spec(spec, True, {}, None))
self.assertEqual(False, isc.config.module_spec._validate_spec(spec, True, {}, errors))
self.assertEqual(['non-optional item an_item missing'], errors)
+
+ def test_validate_unknown_items(self):
+ spec = [{ 'item_name': "an_item",
+ 'item_type': "string",
+ 'item_optional': True,
+ 'item_default': "asdf"
+ }]
+
+ errors = []
+ self.assertEqual(False, isc.config.module_spec._validate_spec_list(spec, True, { 'does_not_exist': 1 }, None))
+ self.assertEqual(False, isc.config.module_spec._validate_spec_list(spec, True, { 'does_not_exist': 1 }, errors))
+ self.assertEqual(['unknown item does_not_exist'], errors)
More information about the bind10-changes
mailing list