Dhcpv4Exchange::copyDefaultOptions() {
// Let's copy client-id to response. See RFC6842.
// It is possible to disable RFC6842 to keep backward compatibility
- bool echo = CfgMgr::instance().echoClientId();
+ bool echo = CfgMgr::instance().getCurrentCfg()->getEchoClientId();
OptionPtr client_id = query_->getOption(DHO_DHCP_CLIENT_IDENTIFIER);
if (client_id && echo) {
resp_->addOption(client_id);
// Set whether v4 server is supposed to echo back client-id
// (yes = RFC6842 compatible, no = backward compatibility)
bool echo_client_id = getBoolean(global, "echo-client-id");
- CfgMgr::instance().echoClientId(echo_client_id);
+ cfg->setEchoClientId(echo_client_id);
// Set the probation period for decline handling.
uint32_t probation_period =
ASSERT_NO_THROW(json_true = parseDHCP4(config_true));
// Let's check the default. It should be true
- ASSERT_TRUE(CfgMgr::instance().echoClientId());
+ ASSERT_TRUE(CfgMgr::instance().getStagingCfg()->getEchoClientId());
// Now check that "false" configuration is really applied.
ConstElementPtr status;
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json_false));
- ASSERT_FALSE(CfgMgr::instance().echoClientId());
+ ASSERT_FALSE(CfgMgr::instance().getStagingCfg()->getEchoClientId());
CfgMgr::instance().clear();
// Now check that "true" configuration is really applied.
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json_true));
- ASSERT_TRUE(CfgMgr::instance().echoClientId());
+ ASSERT_TRUE(CfgMgr::instance().getStagingCfg()->getEchoClientId());
// In any case revert back to the default value (true)
- CfgMgr::instance().echoClientId(true);
+ CfgMgr::instance().getStagingCfg()->setEchoClientId(true);
}
// This test checks that the global match-client-id parameter is optional
-// Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
checkResponse(offer, DHCPOFFER, 1234);
checkClientId(offer, clientid);
- CfgMgr::instance().echoClientId(false);
+ ConstSrvConfigPtr cfg = CfgMgr::instance().getCurrentCfg();
+ const Subnet4Collection* subnets = cfg->getCfgSubnets4()->getAll();
+ ASSERT_EQ(1, subnets->size());
+ CfgMgr::instance().clear();
+ CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->add(subnets->at(0));
+ CfgMgr::instance().getStagingCfg()->setEchoClientId(false);
+ CfgMgr::instance().commit();
+
offer = srv.processDiscover(dis);
// Check if we get response at all
checkResponse(ack, DHCPACK, 1234);
checkClientId(ack, clientid);
- CfgMgr::instance().echoClientId(false);
+ ConstSrvConfigPtr cfg = CfgMgr::instance().getCurrentCfg();
+ const Subnet4Collection* subnets = cfg->getCfgSubnets4()->getAll();
+ ASSERT_EQ(1, subnets->size());
+ CfgMgr::instance().clear();
+ CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->add(subnets->at(0));
+ CfgMgr::instance().getStagingCfg()->setEchoClientId(false);
+ CfgMgr::instance().commit();
+
ack = srv.processRequest(dis);
// Check if we get response at all
// Make sure that we revert to default value
CfgMgr::instance().clear();
- CfgMgr::instance().echoClientId(true);
LibDHCP::clearRuntimeOptionDefs();
void Dhcpv4SrvTest::checkClientId(const Pkt4Ptr& rsp, const OptionPtr& expected_clientid) {
- bool include_clientid = CfgMgr::instance().echoClientId();
+ bool include_clientid =
+ CfgMgr::instance().getCurrentCfg()->getEchoClientId();
// check that server included our own client-id
OptionPtr opt = rsp->getOption(DHO_DHCP_CLIENT_IDENTIFIER);
#include <dhcp/libdhcp++.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/dhcpsrv_log.h>
-#include <dhcpsrv/subnet_id.h>
#include <stats/stats_mgr.h>
#include <sstream>
#include <string>
datadir_ = datadir;
}
-bool
-CfgMgr::isDuplicate(const Subnet6& subnet) const {
- for (Subnet6Collection::const_iterator subnet_it = subnets6_.begin();
- subnet_it != subnets6_.end(); ++subnet_it) {
- if ((*subnet_it)->getID() == subnet.getID()) {
- return (true);
- }
- }
- return (false);
-}
-
-
void
CfgMgr::setD2ClientConfig(D2ClientConfigPtr& new_config) {
ensureCurrentAllocated();
}
CfgMgr::CfgMgr()
- : datadir_(DHCP_DATA_DIR), echo_v4_client_id_(true),
- d2_client_mgr_(), verbose_mode_(false) {
+ : datadir_(DHCP_DATA_DIR), d2_client_mgr_(), verbose_mode_(false) {
// DHCP_DATA_DIR must be set set with -DDHCP_DATA_DIR="..." in Makefile.am
// Note: the definition of DHCP_DATA_DIR needs to include quotation marks
// See AM_CPPFLAGS definition in Makefile.am
#include <dhcp/classify.h>
#include <dhcpsrv/d2_client_mgr.h>
#include <dhcpsrv/pool.h>
-#include <dhcpsrv/subnet.h>
#include <dhcpsrv/srv_config.h>
#include <util/buffer.h>
/// @brief Configuration Manager
///
/// This singleton class holds the whole configuration for DHCPv4 and DHCPv6
-/// servers. It currently holds information about zero or more subnets6.
-/// Each subnet may contain zero or more pools. Pool4 and Pool6 is the most
-/// basic "chunk" of configuration. It contains a range of assignable
-/// addresses.
+/// servers.
///
-/// Below is a sketch of configuration inheritance (not implemented yet).
+/// Below is a sketch of configuration inheritance.
/// Let's investigate the following configuration:
///
/// @code
/// routines, so there is no storage capability in a global scope for
/// subnet-specific parameters.
///
-/// @todo: Implement Subnet4 support (ticket #2237)
-/// @todo: Implement option definition support
-/// @todo: Implement parameter inheritance
class CfgMgr : public boost::noncopyable {
public:
/// @param datadir New data directory.
void setDataDir(const std::string& datadir);
- /// @brief Sets whether server should send back client-id in DHCPv4
- ///
- /// This is a compatibility flag. The default (true) is compliant with
- /// RFC6842. False is for backward compatibility.
- ///
- /// @param echo should the client-id be sent or not
- void echoClientId(const bool echo) {
- echo_v4_client_id_ = echo;
- }
-
- /// @brief Returns whether server should send back client-id in DHCPv4.
- /// @return true if client-id should be returned, false otherwise.
- bool echoClientId() const {
- return (echo_v4_client_id_);
- }
-
/// @brief Updates the DHCP-DDNS client configuration to the given value.
///
/// Passes the new configuration to the D2ClientMgr instance,
/// @brief virtual destructor
virtual ~CfgMgr();
- /// @brief a container for IPv6 subnets.
- ///
- /// That is a simple vector of pointers. It does not make much sense to
- /// optimize access time (e.g. using a map), because typical search
- /// pattern will use calling inRange() method on each subnet until
- /// a match is found.
- Subnet6Collection subnets6_;
-
private:
/// @brief Checks if current configuration is created and creates it if needed.
/// default current configuration.
void ensureCurrentAllocated();
- /// @brief Checks that the IPv6 subnet with the given id already exists.
- ///
- /// @param subnet Subnet for which this function will check if the other
- /// subnet with equal id already exists.
- /// @return true if the duplicate subnet exists.
- bool isDuplicate(const Subnet6& subnet) const;
-
/// @brief Container for defined DHCPv6 option spaces.
OptionSpaceCollection spaces6_;
/// @brief directory where data files (e.g. server-id) are stored
std::string datadir_;
- /// Indicates whether v4 server should send back client-id
- bool echo_v4_client_id_;
-
/// @brief Manages the DHCP-DDNS client and its configuration.
D2ClientMgr d2_client_mgr_;
cfg_host_operations4_(CfgHostOperations::createConfig4()),
cfg_host_operations6_(CfgHostOperations::createConfig6()),
class_dictionary_(new ClientClassDictionary()),
- decline_timer_(0), dhcp4o6_port_(0),
+ decline_timer_(0), echo_v4_client_id_(true), dhcp4o6_port_(0),
d2_client_config_(new D2ClientConfig()) {
}
cfg_host_operations4_(CfgHostOperations::createConfig4()),
cfg_host_operations6_(CfgHostOperations::createConfig6()),
class_dictionary_(new ClientClassDictionary()),
- decline_timer_(0), dhcp4o6_port_(0),
+ decline_timer_(0), echo_v4_client_id_(true), dhcp4o6_port_(0),
d2_client_config_(new D2ClientConfig()) {
}
return (decline_timer_);
}
+ /// @brief Sets whether server should send back client-id in DHCPv4
+ ///
+ /// This is a compatibility flag. The default (true) is compliant with
+ /// RFC6842. False is for backward compatibility.
+ ///
+ /// @param echo should the client-id be sent or not
+ void setEchoClientId(const bool echo) {
+ echo_v4_client_id_ = echo;
+ }
+
+ /// @brief Returns whether server should send back client-id in DHCPv4.
+ /// @return true if client-id should be returned, false otherwise.
+ bool getEchoClientId() const {
+ return (echo_v4_client_id_);
+ }
+
/// @brief Sets DHCP4o6 IPC port
///
/// DHCPv4-over-DHCPv6 uses a UDP socket for interserver communication,
/// lease is recovered back to available state. Expressed in seconds.
uint32_t decline_timer_;
+ /// @brief Indicates whether v4 server should send back client-id
+ bool echo_v4_client_id_;
+
/// @brief DHCP4o6 IPC port
///
/// DHCPv4-over-DHCPv6 uses a UDP socket for interserver communication,
-// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
/// @todo decide if a duplicate vendor space is allowed.
}
-// This test verifies that RFC6842 (echo client-id) compatibility may be
-// configured.
-TEST_F(CfgMgrTest, echoClientId) {
- CfgMgr& cfg_mgr = CfgMgr::instance();
-
- // Check that the default is true
- EXPECT_TRUE(cfg_mgr.echoClientId());
-
- // Check that it can be modified to false
- cfg_mgr.echoClientId(false);
- EXPECT_FALSE(cfg_mgr.echoClientId());
-
- // Check that the default value can be restored
- cfg_mgr.echoClientId(true);
- EXPECT_TRUE(cfg_mgr.echoClientId());
-}
-
// This test checks the D2ClientMgr wrapper methods.
TEST_F(CfgMgrTest, d2ClientConfig) {
// After CfgMgr construction, D2ClientMgr member should be initialized
EXPECT_EQ(ref_dictionary_->getClasses()->size(), cd->getClasses()->size());
}
+// This test verifies that RFC6842 (echo client-id) compatibility may be
+// configured.
+TEST_F(SrvConfigTest, echoClientId) {
+ SrvConfig conf;
+
+ // Check that the default is true
+ EXPECT_TRUE(conf.getEchoClientId());
+
+ // Check that it can be modified to false
+ conf.setEchoClientId(false);
+ EXPECT_FALSE(conf.getEchoClientId());
+
+ // Check that the default value can be restored
+ conf.setEchoClientId(true);
+ EXPECT_TRUE(conf.getEchoClientId());
+
+ // Check the other constructor has the same default
+ SrvConfig conf1(1);
+ EXPECT_TRUE(conf1.getEchoClientId());
+}
+
// This test checks if entire configuration can be copied and that the sequence
// number is not affected.
TEST_F(SrvConfigTest, copy) {