Commit d8f39b7a authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[master] Merge branch 'trac4211'

parents e66caf26 333527b0
......@@ -2533,7 +2533,7 @@ should include options from the isc option space:
"server-id": {
"type": "EN",
"enterprise-id": 2495,
"identifier": "87ABEF7A5BB545",
"identifier": "87ABEF7A5BB545"
},
...
}
......@@ -2577,7 +2577,7 @@ should include options from the isc option space:
"server-id": {
"type": "LL",
"htype": 8,
"identifier": "A65DC7410F05",
"identifier": "A65DC7410F05"
},
...
}
......@@ -2599,6 +2599,32 @@ should include options from the isc option space:
location: <userinput>[kea-install-dir]/var/kea/kea-dhcp6-serverid
</userinput>.
</para>
<para>In some uncommon deployments where no stable storage is
available, it is desired to configure the server to not try to
store the server identifier on the stable storage. It is controlled
by the value of <command>persist</command> boolean parameter:
<screen>
"Dhcp6": {
"server-id": {
"type": "EN",
"enterprise-id": 2495,
"identifier": "87ABEF7A5BB545",
"persist": false
},
...
}
</screen>
</para>
<para>The default value of the "persist" parameter is
<command>true</command> which configures the server to store the
server identifier on a disk.</para>
<para>In the example above, the server is configured to not store
the generated server identifier on a disk. But, if the server
identifier is not modified in the configuration the same value
will be used after server restart, because entire server
identifier is explicitly specified in a configuration.</para>
</section>
<section id="stateless-dhcp6">
......
......@@ -38,6 +38,13 @@
"item_type": "integer",
"item_optional": true,
"item_default": 0
},
{
"item_name": "persist",
"item_type": "boolean",
"item_optional": true,
"item_default": true,
"item_description": "Indicates if generated server identifier should be stored in a stable storage."
}
]
},
......
......@@ -175,16 +175,6 @@ namespace dhcp {
const std::string Dhcpv6Srv::VENDOR_CLASS_PREFIX("VENDOR_CLASS_");
/// @brief file name of a server-id file
///
/// Server must store its duid in persistent storage that must not change
/// between restarts. This is name of the file that is created in dataDir
/// (see isc::dhcp::CfgMgr::getDataDir()). It is a text file that uses
/// double digit hex values separated by colons format, e.g.
/// 01:ff:02:03:06:80:90:ab:cd:ef. Server will create it during first
/// run and then use it afterwards.
static const char* SERVER_DUID_FILE = "kea-dhcp6-serverid";
Dhcpv6Srv::Dhcpv6Srv(uint16_t port)
: port_(port), serverid_(), shutdown_(true), alloc_engine_()
{
......@@ -201,8 +191,8 @@ Dhcpv6Srv::Dhcpv6Srv(uint16_t port)
return;
}
string duid_file = CfgMgr::instance().getDataDir() + "/" + string(SERVER_DUID_FILE);
DUIDFactory duid_factory(duid_file);
// Create a DUID instance but do not store it into a file.
DUIDFactory duid_factory;
DuidPtr duid = duid_factory.get();
serverid_.reset(new Option(Option::V6, D6O_SERVERID, duid->getDuid()));
......
......@@ -21,6 +21,7 @@
#include <dhcpsrv/lease.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcp6/ctrl_dhcp6_srv.h>
#include <dhcp6/tests/dhcp6_test_utils.h>
#include <hooks/hooks_manager.h>
#include <stats/stats_mgr.h>
#include <testutils/unix_control_client.h>
......@@ -58,9 +59,10 @@ public:
using Dhcpv6Srv::receivePacket;
};
class CtrlDhcpv6SrvTest : public ::testing::Test {
class CtrlDhcpv6SrvTest : public BaseServerTest {
public:
CtrlDhcpv6SrvTest() {
CtrlDhcpv6SrvTest()
: BaseServerTest() {
reset();
}
......
......@@ -26,7 +26,7 @@ namespace test {
/// @brief Base class for test fixure classes used to validate the DHCPv6
/// message processing by the server.
class Dhcpv6MessageTest : public isc::dhcp::test::Dhcpv6SrvTest {
class Dhcpv6MessageTest : public Dhcpv6SrvTest {
public:
/// @brief Constructor.
///
......
......@@ -26,6 +26,10 @@ CONFIG="{
{ \"interfaces-config\": {
\"interfaces\": [ ]
},
\"server-id\": {
\"type\": \"LLT\",
\"persist\": false
},
\"preferred-lifetime\": 3000,
\"valid-lifetime\": 4000,
\"renew-timer\": 1000,
......@@ -291,7 +295,7 @@ lfc_timer_test() {
# Create a configuration with the LFC enabled, by replacing the section
# with the lfc-interval and persist parameters.
LFC_CONFIG=$(printf "${CONFIG}" | sed -e 's/\"lfc-interval\": 0/\"lfc-interval\": 1/g' \
| sed -e 's/\"persist\": false/\"persist\": true/g')
| sed -e 's/\"persist\": false,/\"persist\": true,/g')
# Create new configuration file.
create_config "${LFC_CONFIG}"
# Instruct Kea to log to the specific file.
......
......@@ -21,6 +21,8 @@
#include <util/pointer_util.h>
#include <cc/command_interpreter.h>
#include <stats/stats_mgr.h>
#include <cstdio>
#include <sstream>
#include <string.h>
using namespace isc::data;
......@@ -32,10 +34,24 @@ namespace isc {
namespace dhcp {
namespace test {
const char* NakedDhcpv6SrvTest::DUID_FILE = "server-id-test.txt";
const char* BaseServerTest::DUID_FILE = "kea-dhcp6-serverid";
BaseServerTest::BaseServerTest()
: original_datadir_(CfgMgr::instance().getDataDir()) {
CfgMgr::instance().setDataDir(TEST_DATA_BUILDDIR);
}
BaseServerTest::~BaseServerTest() {
// Remove test DUID file.
std::ostringstream s;
s << CfgMgr::instance().getDataDir() << "/" << DUID_FILE;
static_cast<void>(::remove(s.str().c_str()));
// Revert to original data directory.
CfgMgr::instance().setDataDir(original_datadir_);
}
Dhcpv6SrvTest::Dhcpv6SrvTest()
:srv_(0) {
: NakedDhcpv6SrvTest(), srv_(0) {
subnet_ = isc::dhcp::Subnet6Ptr
(new isc::dhcp::Subnet6(isc::asiolink::IOAddress("2001:db8:1::"),
48, 1000, 2000, 3000, 4000));
......
......@@ -42,6 +42,30 @@ namespace isc {
namespace dhcp {
namespace test {
/// @brief Base class for DHCPv6 server testing.
///
/// Currently it configures the test data path directory in
/// the @c CfgMgr. When the object is destroyed, the original
/// path is reverted.
class BaseServerTest : public ::testing::Test {
public:
/// @brief Location of a test DUID file
static const char* DUID_FILE;
/// @brief Constructor.
BaseServerTest();
/// @brief Destructor.
virtual ~BaseServerTest();
private:
/// @brief Holds the original data directory.
std::string original_datadir_;
};
/// @brief "naked" Dhcpv6Srv class that exposes internal members
class NakedDhcpv6Srv: public isc::dhcp::Dhcpv6Srv {
public:
......@@ -131,15 +155,12 @@ public:
/// @brief Test fixture for any tests requiring blank/empty configuration
/// serves as base class for additional tests
class NakedDhcpv6SrvTest : public ::testing::Test {
class NakedDhcpv6SrvTest : public BaseServerTest {
public:
/// @brief Constructor
NakedDhcpv6SrvTest();
/// @brief Location of a test DUID file
static const char* DUID_FILE;
// Generate IA_NA or IA_PD option with specified parameters
boost::shared_ptr<isc::dhcp::Option6IA> generateIA
(uint16_t type, uint32_t iaid, uint32_t t1, uint32_t t2);
......
......@@ -20,6 +20,7 @@
#include <dhcp/duid.h>
#include <dhcp/iface_mgr.h>
#include <dhcp6/ctrl_dhcp6_srv.h>
#include <dhcp6/tests/dhcp6_test_utils.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/lease.h>
#include <dhcpsrv/lease_mgr_factory.h>
......@@ -53,9 +54,10 @@ public:
};
class JSONFileBackendTest : public ::testing::Test {
class JSONFileBackendTest : public dhcp::test::BaseServerTest {
public:
JSONFileBackendTest() {
JSONFileBackendTest()
: BaseServerTest() {
}
~JSONFileBackendTest() {
......
......@@ -57,6 +57,10 @@ config="{
\"interfaces-config\": {
\"interfaces\": [ ]
},
\"server-id\": {
\"type\": \"LLT\",
\"persist\": false
},
\"preferred-lifetime\": 3000,
\"valid-lifetime\": 4000,
\"renew-timer\": 1000,
......
# The following build order must be maintained.
SUBDIRS = exceptions util log hooks cryptolink dns cc asiolink dhcp config stats \
asiodns testutils dhcp_ddns eval dhcpsrv cfgrpt
SUBDIRS = exceptions util log hooks cryptolink dns cc asiolink testutils dhcp config \
stats asiodns dhcp_ddns eval dhcpsrv cfgrpt
......@@ -117,6 +117,7 @@ libdhcp___unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la
libdhcp___unittests_LDADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la
libdhcp___unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
libdhcp___unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
libdhcp___unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
libdhcp___unittests_LDADD += $(LOG4CPLUS_LIBS) $(CRYPTO_LIBS)
libdhcp___unittests_LDADD += $(BOOST_LIBS) $(GTEST_LDADD)
endif
......
......@@ -16,6 +16,7 @@
#include <dhcp/dhcp4.h>
#include <dhcp/duid_factory.h>
#include <dhcp/tests/iface_mgr_test_config.h>
#include <testutils/io_utils.h>
#include <util/encode/hex.h>
#include <util/range_utilities.h>
#include <boost/algorithm/string.hpp>
......@@ -187,20 +188,7 @@ DUIDFactoryTest::removeDefaultFile() const {
std::string
DUIDFactoryTest::readDefaultFile() const {
std::ifstream ifs;
ifs.open(absolutePath(DEFAULT_DUID_FILE).c_str(), std::ifstream::in);
if (!ifs.good()) {
return (std::string());
}
std::string buf;
std::ostringstream output;
while (!ifs.eof() && ifs.good()) {
ifs >> buf;
output << buf;
}
ifs.close();
return (output.str());
return (dhcp::test::readFile(absolutePath(DEFAULT_DUID_FILE)));
}
std::vector<uint8_t>
......
......@@ -27,7 +27,7 @@ namespace dhcp {
CfgDUID::CfgDUID()
: type_(DUID::DUID_LLT), identifier_(), htype_(0), time_(0),
enterprise_id_(0) {
enterprise_id_(0), persist_(true) {
}
void
......@@ -57,7 +57,7 @@ CfgDUID::setIdentifier(const std::string& identifier_as_hex) {
DuidPtr
CfgDUID::create(const std::string& duid_file_path) const {
// Use DUID factory to create a DUID instance.
DUIDFactory factory(duid_file_path);
DUIDFactory factory(persist() ? duid_file_path : "");
switch (getType()) {
case DUID::DUID_LLT:
......
......@@ -100,6 +100,22 @@ public:
enterprise_id_ = enterprise_id;
}
/// @brief Checks if server identifier should be stored on disk.
///
/// @return true if the server identifier should be stored on
/// the disk, false otherwise.
bool persist() const {
return (persist_);
}
/// @brief Sets a boolean flag indicating if the server identifier
/// should be stored on the disk (if true) or not (if false).
///
/// @param persist New value of the flag.
void setPersist(const bool persist) {
persist_ = persist;
}
/// @brief Creates instance of a DUID from the current configuration.
///
/// @param duid_file_path Absolute path to a DUID file.
......@@ -123,6 +139,9 @@ private:
/// @brief Enterprise id used for DUID-EN.
uint32_t enterprise_id_;
/// @brief Boolean flag which indicates if server identifier should
/// be stored on the disk.
bool persist_;
};
/// @name Pointers to the @c CfgDUID objects.
......
......@@ -67,10 +67,15 @@ CfgMgr::addOptionSpace6(const OptionSpacePtr& space) {
}
std::string CfgMgr::getDataDir() {
std::string CfgMgr::getDataDir() const {
return (datadir_);
}
void
CfgMgr::setDataDir(const std::string& datadir) {
datadir_ = datadir;
}
bool
CfgMgr::isDuplicate(const Subnet6& subnet) const {
for (Subnet6Collection::const_iterator subnet_it = subnets6_.begin();
......
......@@ -131,7 +131,12 @@ public:
/// This method returns a path to writeable directory that DHCP servers
/// can store data in.
/// @return data directory
std::string getDataDir();
std::string getDataDir() const;
/// @brief Sets new data directory.
///
/// @param datadir New data directory.
void setDataDir(const std::string& datadir);
/// @brief Sets whether server should send back client-id in DHCPv4
///
......
......@@ -50,6 +50,8 @@ DUIDConfigParser::build(isc::data::ConstElementPtr duid_configuration) {
setTime(element.second->intValue());
} else if (element.first == "enterprise-id") {
setEnterpriseId(element.second->intValue());
} else if (element.first == "persist") {
setPersist(element.second->boolValue());
} else {
isc_throw(DhcpConfigError, "unsupported configuration "
"parameter '" << element.first << "'");
......@@ -118,6 +120,12 @@ DUIDConfigParser::setEnterpriseId(const int64_t enterprise_id) const {
cfg->setEnterpriseId(static_cast<uint32_t>(enterprise_id));
}
void
DUIDConfigParser::setPersist(const bool persist) {
const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
cfg->setPersist(persist);
}
template<typename NumericType>
void
DUIDConfigParser::checkRange(const std::string& parameter_name,
......
......@@ -75,6 +75,13 @@ private:
/// @param enterprise_id Enterprise id.
void setEnterpriseId(const int64_t enterprise_id) const;
/// @brief Set persistence flag.
///
/// @param persist A boolean value indicating if the server
/// identifier should be stored on the disk (if true) or
/// not (if false).
void setPersist(const bool persist);
/// @brief Verifies if the specified parameter is in range.
///
/// Each numeric value must be in range of [0 .. max_value], where
......
......@@ -164,6 +164,7 @@ libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la
libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la
libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
libdhcpsrv_unittests_LDADD += $(LOG4CPLUS_LIBS) $(CRYPTO_LIBS)
libdhcpsrv_unittests_LDADD += $(BOOST_LIBS) $(GTEST_LDADD)
endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment