]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3590] Removed unused isDuplicate and move echo client-id from CfgMgr to SrvConfig
authorFrancis Dupont <fdupont@isc.org>
Sat, 11 Feb 2017 09:29:40 +0000 (10:29 +0100)
committerFrancis Dupont <fdupont@isc.org>
Sat, 11 Feb 2017 09:29:40 +0000 (10:29 +0100)
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/dhcp4_test_utils.cc
src/lib/dhcpsrv/cfgmgr.cc
src/lib/dhcpsrv/cfgmgr.h
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/srv_config.h
src/lib/dhcpsrv/tests/cfgmgr_unittest.cc
src/lib/dhcpsrv/tests/srv_config_unittest.cc

index f13de734aae0e19b7665001d4e013142b1f96f16..adf1fcc6e790ea19715fd8d7ec2e1878e64860cc 100644 (file)
@@ -257,7 +257,7 @@ void
 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);
index 7e49264c03d2a048129a230f7a90b39e57d85d25..865f86a17989ccd4d6b1ad41eb05d31925eff893 100644 (file)
@@ -331,7 +331,7 @@ public:
         // 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 =
index 243936bdd98aaafb09f2937ad4395cb06ec7030a..cbb7c9bbaba8d18b4f203c8a7af8c751ce2e1e67 100644 (file)
@@ -1210,21 +1210,21 @@ TEST_F(Dhcp4ParserTest, echoClientId) {
     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
index 0c86a115ea999cd8902e24a21f8ddc54ff7fa626..6c5c25265cd0b1510a4cebdaeb4ba0e901831123 100644 (file)
@@ -1,4 +1,4 @@
-// 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
@@ -744,7 +744,14 @@ TEST_F(Dhcpv4SrvTest, discoverEchoClientId) {
     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
@@ -812,7 +819,14 @@ TEST_F(Dhcpv4SrvTest, requestEchoClientId) {
     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
index 0d4175a1a6a1fe4aaaffe16f10c109d9d7fb777c..7924125962aa76d14177b612c88a08992bfcc117 100644 (file)
@@ -83,7 +83,6 @@ Dhcpv4SrvTest::~Dhcpv4SrvTest() {
 
     // Make sure that we revert to default value
     CfgMgr::instance().clear();
-    CfgMgr::instance().echoClientId(true);
 
     LibDHCP::clearRuntimeOptionDefs();
 
@@ -360,7 +359,8 @@ void Dhcpv4SrvTest::checkServerId(const Pkt4Ptr& rsp, const OptionPtr& expected_
 
 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);
index 6cf5801f7f5716fd6a134f7da4244925f6b01042..0aaf14da142c62e4425ffaf4f81a9161bdcd41ba 100644 (file)
@@ -10,7 +10,6 @@
 #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>
@@ -68,18 +67,6 @@ CfgMgr::setDataDir(const std::string& datadir) {
     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();
@@ -211,8 +198,7 @@ CfgMgr::getStagingCfg() {
 }
 
 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
index aff077d2c68f06d8bfac38ffbb508d4cf0f57b51..d76015b0b16c3f3ec0a30827253ca01143b4c509 100644 (file)
@@ -13,7 +13,6 @@
 #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>
 
@@ -41,12 +40,9 @@ public:
 /// @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
@@ -71,9 +67,6 @@ public:
 /// 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:
 
@@ -130,22 +123,6 @@ 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,
@@ -317,14 +294,6 @@ protected:
     /// @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.
@@ -334,13 +303,6 @@ private:
     /// 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_;
 
@@ -350,9 +312,6 @@ private:
     /// @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_;
 
index cb69f7d30fabe649de216e8e1207d2ad6026d6ec..15bfd03d31b91644719b0eb41533d85db4f204a3 100644 (file)
@@ -29,7 +29,7 @@ SrvConfig::SrvConfig()
       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()) {
 }
 
@@ -43,7 +43,7 @@ SrvConfig::SrvConfig(const uint32_t sequence)
       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()) {
 }
 
index dcf91049841fa77d71879b2c278cec1fcde9055c..4bfa4ccae311cba3bc578de8ad77035b151aebc3 100644 (file)
@@ -470,6 +470,22 @@ public:
         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,
@@ -583,6 +599,9 @@ private:
     /// 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,
index a6de68d7dd6e6bc3ca1161a8fcf863ed698d7f26..59082dc2cb2d0f790a3ebacffc8cc2b0291a5651 100644 (file)
@@ -1,4 +1,4 @@
-// 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
@@ -383,23 +383,6 @@ TEST_F(CfgMgrTest, optionSpace6) {
     /// @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
index 86f48b4357db2eb068de8fd1f5626678925887ee..3a870836753417120604fba5f4bf3a06a27bf148 100644 (file)
@@ -261,6 +261,27 @@ TEST_F(SrvConfigTest, classDictionaryBasics) {
     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) {