Commit fa64874f authored by zhanglikun's avatar zhanglikun
Browse files

Merge branch 'master' into trac595

parents 996e2593 44bf7654
187. [bug] zhang likun
Fix the assert error in class isc::cache::RRsetCache by adding the
check for empty pointer and test case for it.
(Trac #638, git 54e61304131965c4a1d88c9151f8697dcbb3ce12)
186. [bug] jelte
b10-resolver could stop with an assertion failure on certain kinds
of messages (there was a problem in error message creation). This
fixes that.
(Trac #607, git 25a5f4ec755bc09b54410fcdff22691283147f32)
185. [bug] vorner
Tests use port from private range (53210), lowering chance of
a conflict with something else (eg. running bind 10).
(Trac #523, git 301da7d26d41e64d87c0cf72727f3347aa61fb40)
184. [func]* vorner
Listening address and port configuration of b10-auth is the same as
for b10-resolver now. That means, it is configured through bindctl
at runtime, in the Auth/listen_on list, not through command line
arguments.
(Trac #575, #576, git f06ce638877acf6f8e1994962bf2dbfbab029edf)
183. [bug] jerry
src/bin/xfrout: Enable parallel sessions between xfrout server and
muti-Auth. The session needs to be created only on the first time
or if an error occur.
(Trac #419, git 1d60afb59e9606f312caef352ecb2fe488c4e751)
182. [func] jinmei
Support cppcheck for static code check on C++ code. If cppcheck
is available, 'make cppcheck' on the top source directory will run
the checker and should cleanly complete with an exit code of 0
(at least with cppcheck 1.47).
Note: the suppression list isn't included in the final
distributions. It should be created by hand or retrieved from
the git repository.
(Trac #613, git b973f67520682b63ef38b1451d309be9f4f4b218)
181. [func] feng
Add stop interface into dns server, so we can stop each running
server individually. With it, user can reconfigure her running server
with different ip address or port.
(Trac #388, git 6df94e2db856c1adc020f658cc77da5edc967555)
180. [build] jreed
Fix custom DESTDIR for make install. Patch from Jan Engelhardt.
(Trac #629, git 5ac67ede03892a5eacf42ce3ace1e4e376164c9f)
bind10-devel-20110224 released on February 24, 2011
179. [func] vorner
......
......@@ -70,6 +70,13 @@ clean-coverage: clean-cpp-coverage clean-python-coverage
report-coverage: report-cpp-coverage report-python-coverage
# for static C++ check using cppcheck (when available)
cppcheck:
cppcheck --enable=all --suppressions src/cppcheck-suppress.lst \
--quiet --error-exitcode=1 \
--template '{file}:{line}: check_fail: {message} ({severity},{id})' \
src
#### include external sources in the distributed tarball:
EXTRA_DIST = ext/asio/README
EXTRA_DIST += ext/asio/asio/local/stream_protocol.hpp
......
......@@ -14,18 +14,22 @@ AC_PROG_CXX
#
# On FreeBSD (and probably some others), clang++ does not meet an autoconf
# assumption in identifying libtool configuration regarding shared library:
# the configure script will execute "$CC -shared $CFLAGS -v -o" and expect
# the output contains -Lxxx or -Ryyy. This is the case for g++, but not for
# clang++, and, as a result, it will cause various errors in linking programs
# or running them with a shared object (such as some of our python scripts).
# the configure script will execute "$CC -shared $CFLAGS/$CXXFLAGS -v" and
# expect the output contains -Lxxx or -Ryyy. This is the case for g++, but
# not for clang++, and, as a result, it will cause various errors in linking
# programs or running them with a shared object (such as some of our python
# scripts).
# To work around this problem we define a temporary variable
# "CXX_LIBTOOL_LDFLAGS". It's expected to be defined as, e.g, "-L/usr/lib"
# to temporarily fake the output so that it will be compatible with that of
# g++.
CFLAGS_SAVED=$CFLAGS
CXXFLAGS_SAVED=$CXXFLAGS
CFLAGS="$CFLAGS $CXX_LIBTOOL_LDFLAGS"
CXXFLAGS="$CXXFLAGS $CXX_LIBTOOL_LDFLAGS"
AC_PROG_LIBTOOL
CFLAGS=$CFLAGS_SAVED
CXXFLAGS=$CXXFLAGS_SAVED
# Use C++ language
AC_LANG([C++])
......@@ -291,6 +295,7 @@ AC_SUBST(B10_CXXFLAGS)
AC_SEARCH_LIBS(inet_pton, [nsl])
AC_SEARCH_LIBS(recvfrom, [socket])
AC_SEARCH_LIBS(nanosleep, [rt])
# Checks for header files.
......@@ -676,6 +681,8 @@ AC_CONFIG_FILES([Makefile
src/lib/nsas/tests/Makefile
src/lib/cache/Makefile
src/lib/cache/tests/Makefile
src/lib/server_common/Makefile
src/lib/server_common/tests/Makefile
])
AC_OUTPUT([doc/version.ent
src/bin/cfgmgr/b10-cfgmgr.py
......
......@@ -568,7 +568,7 @@ WARN_LOGFILE =
# 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/bin/resolver ../src/lib/bench ../src/lib/log ../src/lib/asiolink/ ../src/lib/nsas ../src/lib/testutils ../src/lib/cache
INPUT = ../src/lib/cc ../src/lib/config ../src/lib/dns ../src/lib/exceptions ../src/lib/datasrc ../src/bin/auth ../src/bin/resolver ../src/lib/bench ../src/lib/log ../src/lib/asiolink/ ../src/lib/nsas ../src/lib/testutils ../src/lib/cache ../src/lib/server_common/
# 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
......
......@@ -52,10 +52,11 @@ b10_auth_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
b10_auth_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
b10_auth_LDADD += $(top_builddir)/src/lib/nsas/libnsas.la
b10_auth_LDADD += $(top_builddir)/src/lib/xfr/libxfr.la
b10_auth_LDADD += $(top_builddir)/src/lib/server_common/libserver_common.la
b10_auth_LDADD += $(SQLITE_LIBS)
# TODO: config.h.in is wrong because doesn't honor pkgdatadir
# and can't use @datadir@ because doesn't expand default ${prefix}
b10_authdir = $(DESTDIR)$(pkgdatadir)
b10_authdir = $(pkgdatadir)
b10_auth_DATA = auth.spec
......@@ -56,6 +56,41 @@
"item_type": "integer",
"item_optional": true,
"item_default": 60
},
{
"item_name": "listen_on",
"item_type": "list",
"item_optional": false,
"item_default": [
{
"address": "::1",
"port": 5300
},
{
"address": "127.0.0.1",
"port": 5300
}
],
"list_item_spec": {
"item_name": "address",
"item_type": "map",
"item_optional": false,
"item_default": {},
"map_item_spec": [
{
"item_name": "address",
"item_type": "string",
"item_optional": false,
"item_default": "::1"
},
{
"item_name": "port",
"item_type": "integer",
"item_optional": false,
"item_default": 5300
}
]
}
}
],
"commands": [
......
......@@ -69,6 +69,7 @@ using namespace isc::data;
using namespace isc::config;
using namespace isc::xfr;
using namespace asiolink;
using namespace isc::server_common::portconfig;
class AuthSrvImpl {
private:
......@@ -109,6 +110,9 @@ public:
/// Query counters for statistics
AuthCounters counters_;
/// Addresses we listen on
AddressList listen_addresses_;
private:
std::string db_file_;
......@@ -750,3 +754,18 @@ uint64_t
AuthSrv::getCounter(const AuthCounters::CounterType type) const {
return (impl_->counters_.getCounter(type));
}
const AddressList&
AuthSrv::getListenAddresses() const {
return (impl_->listen_addresses_);
}
void
AuthSrv::setListenAddresses(const AddressList& addresses) {
installListenAddresses(addresses, impl_->listen_addresses_, *dnss_);
}
void
AuthSrv::setDNSService(asiolink::DNSService& dnss) {
dnss_ = &dnss;
}
......@@ -25,6 +25,7 @@
#include <config/ccsession.h>
#include <asiolink/asiolink.h>
#include <server_common/portconfig.h>
#include <auth/statistics.h>
namespace isc {
......@@ -353,11 +354,24 @@ public:
/// \return the value of the counter.
uint64_t getCounter(const AuthCounters::CounterType type) const;
/**
* \brief Set and get the addresses we listen on.
*/
void setListenAddresses(const isc::server_common::portconfig::AddressList&
addreses);
const isc::server_common::portconfig::AddressList& getListenAddresses()
const;
/// \brief Assign an ASIO DNS Service queue to this Auth object
void setDNSService(asiolink::DNSService& dnss);
private:
AuthSrvImpl* impl_;
asiolink::SimpleCallback* checkin_;
asiolink::DNSLookup* dns_lookup_;
asiolink::DNSAnswer* dns_answer_;
asiolink::DNSService* dnss_;
};
#endif // __AUTH_SRV_H
......
......@@ -44,11 +44,7 @@
<refsynopsisdiv>
<cmdsynopsis>
<command>b10-auth</command>
<arg><option>-4</option></arg>
<arg><option>-6</option></arg>
<arg><option>-a <replaceable>address</replaceable></option></arg>
<arg><option>-n</option></arg>
<arg><option>-p <replaceable>number</replaceable></option></arg>
<arg><option>-u <replaceable>username</replaceable></option></arg>
<arg><option>-v</option></arg>
</cmdsynopsis>
......@@ -84,39 +80,6 @@
<para>The arguments are as follows:</para>
<variablelist>
<varlistentry>
<term><option>-4</option></term>
<listitem><para>
Enables IPv4 only mode.
This switch may not be used with <option>-6</option> nor
<option>-a</option>.
By default, it listens on both IPv4 and IPv6 (if capable).
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-6</option></term>
<listitem><para>
Enables IPv6 only mode.
This switch may not be used with <option>-4</option> nor
<option>-a</option>.
By default, it listens on both IPv4 and IPv6 (if capable).
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-a <replaceable>address</replaceable></option></term>
<listitem>
<para>The IPv4 or IPv6 address to listen on.
This switch may not be used with <option>-4</option> nor
<option>-6</option>.
The default is to listen on all addresses.
(This is a short term workaround. This argument may change.)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-n</option></term>
<listitem><para>
......@@ -129,16 +92,6 @@
<!-- TODO: this is SQLite3 only -->
</varlistentry>
<varlistentry>
<term><option>-p <replaceable>number</replaceable></option></term>
<listitem><para>
The port number it listens on.
The default is 5300.</para>
<note><simpara>This prototype runs on all interfaces
and on this nonstandard port.</simpara></note>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-u <replaceable>username</replaceable></option></term>
<listitem>
......
......@@ -23,4 +23,5 @@ query_bench_LDADD += $(top_builddir)/src/lib/xfr/libxfr.la
query_bench_LDADD += $(top_builddir)/src/lib/log/liblog.la
query_bench_LDADD += $(top_builddir)/src/lib/nsas/libnsas.la
query_bench_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
query_bench_LDADD += $(top_builddir)/src/lib/server_common/libserver_common.la
query_bench_LDADD += $(SQLITE_LIBS)
......@@ -77,7 +77,7 @@ protected:
dummy_socket(IOSocket::getDummyUDPSocket()),
dummy_endpoint(IOEndpointPtr(IOEndpoint::create(IPPROTO_UDP,
IOAddress("192.0.2.1"),
5300)))
53210)))
{}
public:
unsigned int run() {
......
......@@ -32,11 +32,14 @@
#include <auth/config.h>
#include <auth/common.h>
#include <server_common/portconfig.h>
using namespace std;
using boost::shared_ptr;
using namespace isc::dns;
using namespace isc::data;
using namespace isc::datasrc;
using namespace isc::server_common::portconfig;
namespace {
// Forward declaration
......@@ -210,6 +213,60 @@ public:
}
};
/**
* \brief Configuration parser for listen_on.
*
* It parses and sets the listening addresses of the server.
*
* It acts in unusual way. Since actually binding (changing) the sockets
* is an operation that is expected to throw often, it shouldn't happen
* in commit. Thefere we do it in build. But if the config is not committed
* then, we would have it wrong. So we store the old addresses and if
* commit is not called before destruction of the object, we return the
* old addresses (which is the same kind of dangerous operation, but it is
* expected that if we just managed to bind some and had the old ones binded
* before, it should work).
*
* We might do something better in future (like open only the ports that are
* extra, put them in in commit and close the old ones), but that's left out
* for now.
*/
class ListenAddressConfig : public AuthConfigParser {
public:
ListenAddressConfig(AuthSrv& server) :
server_(server)
{ }
~ ListenAddressConfig() {
if (rollbackAddresses_.get() != NULL) {
server_.setListenAddresses(*rollbackAddresses_);
}
}
private:
typedef auto_ptr<AddressList> AddrListPtr;
public:
virtual void build(ConstElementPtr config) {
AddressList newAddresses = parseAddresses(config, "listen_on");
AddrListPtr old(new AddressList(server_.getListenAddresses()));
server_.setListenAddresses(newAddresses);
/*
* Set the rollback addresses only after successful setting of the
* new addresses, so we don't try to rollback if the setup is
* unsuccessful (the above can easily throw).
*/
rollbackAddresses_ = old;
}
virtual void commit() {
rollbackAddresses_.release();
}
private:
AuthSrv& server_;
/**
* This is the old address list, if we expect to roll back. When we commit,
* this is set to NULL.
*/
AddrListPtr rollbackAddresses_;
};
// This is a generalized version of create function that can create
// an AuthConfigParser object for "internal" use.
AuthConfigParser*
......@@ -226,6 +283,8 @@ createAuthConfigParser(AuthSrv& server, const std::string& config_id,
return (new StatisticsIntervalConfig(server));
} else if (internal && config_id == "datasources/memory") {
return (new MemoryDatasourceConfig(server));
} else if (config_id == "listen_on") {
return (new ListenAddressConfig(server));
} else if (config_id == "_commit_throw") {
// This is for testing purpose only and should not appear in the
// actual configuration syntax. While this could crash the caller
......@@ -271,7 +330,7 @@ configureAuthServer(AuthSrv& server, ConstElementPtr config_set) {
parsers.push_back(parser);
}
} catch (const AuthConfigError& ex) {
throw ex; // simply rethrowing it
throw; // simply rethrowing it
} catch (const isc::Exception& ex) {
isc_throw(AuthConfigError, "Server configuration failed: " <<
ex.what());
......
......@@ -42,6 +42,7 @@
#include <auth/change_user.h>
#include <auth/auth_srv.h>
#include <asiolink/asiolink.h>
#include <log/dummylog.h>
using namespace std;
using namespace isc::data;
......@@ -55,9 +56,6 @@ namespace {
bool verbose_mode = false;
// Default port current 5300 for testing purposes
const char* DNSPORT = "5300";
/* need global var for config/command handlers.
* todo: turn this around, and put handlers in the authserver
* class itself? */
......@@ -76,13 +74,8 @@ my_command_handler(const string& command, ConstElementPtr args) {
void
usage() {
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 << ")"
cerr << "Usage: b10-auth [-u user] [-nv]"
<< 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;
......@@ -93,38 +86,20 @@ usage() {
int
main(int argc, char* argv[]) {
int ch;
const char* port = DNSPORT;
const char* address = NULL;
const char* uid = NULL;
bool use_ipv4 = true, use_ipv6 = true, cache = true;
bool cache = true;
while ((ch = getopt(argc, argv, "46a:np:u:v")) != -1) {
while ((ch = getopt(argc, argv, ":nu:v")) != -1) {
switch (ch) {
case '4':
// Note that -4 means "ipv4 only", we need to set "use_ipv6" here,
// not "use_ipv4". We could use something like "ipv4_only", but
// we found the negatively named variable could confuse the code
// logic.
use_ipv6 = false;
break;
case '6':
// The same note as -4 applies.
use_ipv4 = false;
break;
case 'n':
cache = false;
break;
case 'a':
address = optarg;
break;
case 'p':
port = optarg;
break;
case 'u':
uid = optarg;
break;
case 'v':
verbose_mode = true;
isc::log::denabled = true;
break;
case '?':
default:
......@@ -136,18 +111,6 @@ main(int argc, char* argv[]) {
usage();
}
if (!use_ipv4 && !use_ipv6) {
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: Cannot specify -4 or -6 "
<< "at the same time as -a" << endl;
usage();
}
int ret = 0;
// XXX: we should eventually pass io_service here.
......@@ -182,21 +145,8 @@ main(int argc, char* argv[]) {
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
// family mode if explicit addresses need to be specified.
// We don't bother to fix this problem, however. The -a option
// is a short term workaround until we support dynamic listening
// port allocation.
dns_service = new DNSService(io_service, *port, *address,
checkin, lookup, answer);
} else {
dns_service = new DNSService(io_service, *port, use_ipv4,
use_ipv6, checkin, lookup,
answer);
}
DNSService dns_service(io_service, checkin, lookup, answer);
auth_server->setDNSService(dns_service);
cout << "[b10-auth] DNSServices created." << endl;
cc_session = new Session(io_service.get_io_service());
......@@ -237,7 +187,6 @@ main(int argc, char* argv[]) {
cout << "[b10-auth] Server started." << endl;
io_service.run();
delete dns_service;
} catch (const std::exception& ex) {
cerr << "[b10-auth] Server failed: " << ex.what() << endl;
ret = 1;
......
......@@ -45,6 +45,7 @@ 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/lib/xfr/libxfr.la
run_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
run_unittests_LDADD += $(top_builddir)/src/lib/server_common/libserver_common.la
run_unittests_LDADD += $(top_builddir)/src/lib/nsas/libnsas.la
endif
......
......@@ -26,6 +26,8 @@
#include <dns/rrttl.h>
#include <dns/rdataclass.h>
#include <server_common/portconfig.h>
#include <datasrc/memory_datasrc.h>
#include <auth/auth_srv.h>
#include <auth/common.h>
......@@ -34,6 +36,7 @@
#include <dns/tests/unittest_util.h>
#include <testutils/dnsmessage_test.h>
#include <testutils/srv_test.h>
#include <testutils/portconfig.h>
using namespace std;
using namespace isc::cc;
......@@ -43,6 +46,7 @@ using namespace isc::data;
using namespace isc::xfr;
using namespace asiolink;
using namespace isc::testutils;
using namespace isc::server_common::portconfig;
using isc::UnitTestUtil;
namespace {
......@@ -55,7 +59,12 @@ const char* const BADCONFIG_TESTDB =
class AuthSrvTest : public SrvTestBase {
protected:
AuthSrvTest() : server(true, xfrout), rrclass(RRClass::IN()) {
AuthSrvTest() :
dnss_(ios_, NULL, NULL, NULL),
server(true, xfrout),
rrclass(RRClass::IN())
{
server.setDNSService(dnss_);
server.setXfrinSession(&notify_session);
server.setStatisticsSession(&statistics_session);
}
......@@ -63,6 +72,8 @@ protected:
server.processMessage(*io_message, parse_message, response_obuffer,
&dnsserv);
}
IOService ios_;
DNSService dnss_;
MockSession statistics_session;
MockXfroutClient xfrout;
AuthSrv server;
......@@ -633,7 +644,7 @@ TEST_F(AuthSrvTest, queryCounterUnexpected) {
// Modify the message.
delete io_message;
endpoint = IOEndpoint::create(IPPROTO_UDP,
IOAddress(DEFAULT_REMOTE_ADDRESS), 5300);
IOAddress(DEFAULT_REMOTE_ADDRESS), 53210);
io_message = new IOMessage(request_renderer.getData(),
request_renderer.getLength(),
getDummyUnknownSocket(), *endpoint);
......@@ -650,4 +661,9 @@ TEST_F(AuthSrvTest, stop) {
// If/when the interval timer has finer granularity we'll probably add
// our own tests here, so we keep this empty test case.
}
TEST_F(AuthSrvTest, listenAddresses) {
isc::testutils::portconfig::listenAddresses(server);
}
}
......@@ -30,6 +30,7 @@
#include <auth/common.h>
#include <testutils/mockups.h>
#include <testutils/portconfig.h>
using namespace isc::dns;
using namespace isc::data;
......@@ -39,7 +40,15 @@ using namespace asiolink;
namespace {
class AuthConfigTest : public ::testing::Test {
protected:
AuthConfigTest() : rrclass(RRClass::IN()), server(true