]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3983] Support for 'decline-probation-period' implemented.
authorTomek Mrugalski <tomasz@isc.org>
Thu, 20 Aug 2015 18:51:28 +0000 (20:51 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Thu, 20 Aug 2015 18:51:28 +0000 (20:51 +0200)
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp6/json_config_parser.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/defaults.h [new file with mode: 0644]
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/srv_config.h

index 604f87d68390df7f80a4203ce7767d0c3d03682d..39f36521bce3e14029008808908bdfe011515497 100644 (file)
@@ -21,6 +21,7 @@
 #include <dhcpsrv/cfg_option.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcp4/json_config_parser.h>
+#include <dhcpsrv/defaults.h>
 #include <dhcpsrv/option_space_container.h>
 #include <dhcpsrv/parsers/dbaccess_parser.h>
 #include <dhcpsrv/parsers/dhcp_parsers.h>
@@ -375,7 +376,8 @@ namespace dhcp {
     DhcpConfigParser* parser = NULL;
     if ((config_id.compare("valid-lifetime") == 0)  ||
         (config_id.compare("renew-timer") == 0)  ||
-        (config_id.compare("rebind-timer") == 0))  {
+        (config_id.compare("rebind-timer") == 0) ||
+        (config_id.compare("decline-probation-period") == 0) )  {
         parser = new Uint32Parser(config_id,
                                  globalContext()->uint32_values_);
     } else if (config_id.compare("interfaces-config") == 0) {
@@ -411,7 +413,13 @@ namespace dhcp {
     return (parser);
 }
 
-void commitGlobalOptions() {
+/// @brief Commits global parameters
+///
+/// Currently this method sets the following global parameters:
+///
+/// - echo-client-id
+/// - decline-probation-period
+void commitGlobalParameters4() {
     // Although the function is modest for now, it is certain that the number
     // of global switches will increase over time, hence the name.
 
@@ -423,6 +431,16 @@ void commitGlobalOptions() {
     } catch (...) {
         // Ignore errors. This flag is optional
     }
+
+    // Set the probation period for decline handling.
+    try {
+        uint32_t probation_period = globalContext()->uint32_values_
+            ->getOptionalParam("decline-probation-period",
+                               DEFAULT_DECLINE_PROBATION_PERIOD);
+        CfgMgr::instance().getStagingCfg()->setDeclinePeriod(probation_period);
+    } catch (...) {
+        // That's not really needed.
+    }
 }
 
 isc::data::ConstElementPtr
@@ -592,7 +610,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
             // CfgMgr::commit() function.
 
             // Apply global options
-            commitGlobalOptions();
+            commitGlobalParameters4();
 
             // This occurs last as if it succeeds, there is no easy way
             // revert it.  As a result, the failure to commit a subsequent
index 17c04482b81bf4188d38d26ec2ede6ac8430a588..91c816a7d987da5adb4f7918d8cdca42594c9373 100644 (file)
@@ -32,6 +32,7 @@
 #include <dhcpsrv/cfg_hosts.h>
 #include <dhcpsrv/cfg_subnets4.h>
 #include <dhcpsrv/testutils/config_result_check.h>
+#include <dhcpsrv/defaults.h>
 #include <hooks/hooks_manager.h>
 
 #include "marker_file.h"
@@ -3647,4 +3648,49 @@ TEST_F(Dhcp4ParserTest, hostReservationPerSubnet) {
     EXPECT_EQ(Subnet::HR_ALL, subnet->getHostReservationMode());
 }
 
+/// Check that the decline-probation-period has a default value when not
+/// specified.
+TEST_F(Dhcp4ParserTest, declineTimerDefault) {
+    ConstElementPtr status;
+
+    string config = "{ " + genIfaceConfig() + "," +
+        "\"subnet4\": [ ]"
+        "}";
+
+    ElementPtr json = Element::fromJSON(config);
+
+    EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
+
+    // returned value should be 0 (success)
+    checkResult(status, 0);
+
+    // The value of decline-probation-perion must be equal to the
+    // default value.
+    EXPECT_EQ(DEFAULT_DECLINE_PROBATION_PERIOD,
+              CfgMgr::instance().getStagingCfg()->getDeclinePeriod());
+}
+
+/// Check that the decline-probation-period value can be set properly.
+TEST_F(Dhcp4ParserTest, declineTimer) {
+    ConstElementPtr status;
+
+    string config = "{ " + genIfaceConfig() + "," +
+        "\"decline-probation-period\": 12345,"
+        "\"subnet4\": [ ]"
+        "}";
+
+    ElementPtr json = Element::fromJSON(config);
+
+    EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
+
+    // returned value should be 0 (success)
+    checkResult(status, 0);
+
+    // The value of decline-probation-perion must be equal to the
+    // value specified.
+    EXPECT_EQ(12345,
+              CfgMgr::instance().getStagingCfg()->getDeclinePeriod());
+}
+
+
 }
index 3f3f45a60aa510c2c10daf7a811d3f6cbed75513..1474c8ca6de726c088ec1e79275c7b6dddce488c 100644 (file)
@@ -27,6 +27,7 @@
 #include <dhcpsrv/pool.h>
 #include <dhcpsrv/subnet.h>
 #include <dhcpsrv/triplet.h>
+#include <dhcpsrv/defaults.h>
 #include <dhcpsrv/parsers/dbaccess_parser.h>
 #include <dhcpsrv/parsers/dhcp_config_parser.h>
 #include <dhcpsrv/parsers/dhcp_parsers.h>
@@ -666,7 +667,8 @@ namespace dhcp {
     if ((config_id.compare("preferred-lifetime") == 0)  ||
         (config_id.compare("valid-lifetime") == 0)  ||
         (config_id.compare("renew-timer") == 0)  ||
-        (config_id.compare("rebind-timer") == 0))  {
+        (config_id.compare("rebind-timer") == 0) ||
+        (config_id.compare("decline-probation-period") == 0) )  {
         parser = new Uint32Parser(config_id,
                                  globalContext()->uint32_values_);
     } else if (config_id.compare("interfaces-config") == 0) {
@@ -702,6 +704,24 @@ namespace dhcp {
     return (parser);
 }
 
+/// @brief Commits global parameters
+///
+/// Currently this method sets the following global parameters:
+///
+/// - decline-probation-period
+void commitGlobalParameters6() {
+
+    // Set the probation period for decline handling.
+    try {
+        uint32_t probation_period = globalContext()->uint32_values_
+            ->getOptionalParam("decline-probation-period",
+                               DEFAULT_DECLINE_PROBATION_PERIOD);
+        CfgMgr::instance().getStagingCfg()->setDeclinePeriod(probation_period);
+    } catch (...) {
+        // That's not really needed.
+    }
+}
+
 isc::data::ConstElementPtr
 configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
     if (!config_set) {
@@ -870,6 +890,9 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
                 subnet_parser->commit();
             }
 
+            // Commit global options
+            commitGlobalParameters6();
+
             // No need to commit interface names as this is handled by the
             // CfgMgr::commit() function.
 
index 5296bc2d2c55ba15a4c075ae7ef911a55a084f8d..6e9f7383488c53933a3b0d37d39eb4bf8e3e6a27 100644 (file)
@@ -27,6 +27,7 @@
 #include <dhcpsrv/addr_utilities.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/cfg_hosts.h>
+#include <dhcpsrv/defaults.h>
 #include <dhcpsrv/subnet.h>
 #include <dhcpsrv/subnet_selector.h>
 #include <dhcpsrv/testutils/config_result_check.h>
@@ -3982,4 +3983,49 @@ TEST_F(Dhcp6ParserTest, rsooBogusName) {
     EXPECT_TRUE(errorContainsPosition(status, "<string>"));
 }
 
+/// Check that the decline-probation-period value can be set properly.
+TEST_F(Dhcp6ParserTest, declineTimerDefault) {
+
+    ConstElementPtr status;
+
+    string config_txt = "{ " + genIfaceConfig() + ","
+        "\"subnet6\": [  ] "
+        "}";
+    ElementPtr config = Element::fromJSON(config_txt);
+
+    EXPECT_NO_THROW(status = configureDhcp6Server(srv_, config));
+
+    // returned value should be 0 (success)
+    checkResult(status, 0);
+
+    // The value of decline-probation-perion must be equal to the
+    // default value.
+    EXPECT_EQ(DEFAULT_DECLINE_PROBATION_PERIOD,
+              CfgMgr::instance().getStagingCfg()->getDeclinePeriod());
+}
+
+/// Check that the decline-probation-period value can be set properly.
+TEST_F(Dhcp6ParserTest, declineTimer) {
+    ConstElementPtr status;
+
+    string config = "{ " + genIfaceConfig() + "," +
+        "\"decline-probation-period\": 12345,"
+        "\"subnet6\": [ ]"
+        "}";
+
+    ElementPtr json = Element::fromJSON(config);
+
+    EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json));
+
+    // returned value should be 0 (success)
+    checkResult(status, 0);
+
+    // The value of decline-probation-perion must be equal to the
+    // value specified.
+    EXPECT_EQ(12345,
+              CfgMgr::instance().getStagingCfg()->getDeclinePeriod());
+}
+
+
+
 };
index 1478e774ef750bb6fa800001e87089a888981c03..d36c3b3ad6808bae5433c2352ab2104c53cc0669 100644 (file)
@@ -92,6 +92,7 @@ libkea_dhcpsrv_la_SOURCES += csv_lease_file6.cc csv_lease_file6.h
 libkea_dhcpsrv_la_SOURCES += d2_client_cfg.cc d2_client_cfg.h
 libkea_dhcpsrv_la_SOURCES += d2_client_mgr.cc d2_client_mgr.h
 libkea_dhcpsrv_la_SOURCES += daemon.cc daemon.h
+libkea_dhcpsrv_la_SOURCES += defaults.h
 libkea_dhcpsrv_la_SOURCES += dhcpsrv_log.cc dhcpsrv_log.h
 libkea_dhcpsrv_la_SOURCES += host.cc host.h
 libkea_dhcpsrv_la_SOURCES += host_container.h
diff --git a/src/lib/dhcpsrv/defaults.h b/src/lib/dhcpsrv/defaults.h
new file mode 100644 (file)
index 0000000..2addfac
--- /dev/null
@@ -0,0 +1,38 @@
+// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+/// @file   defaults.h
+/// 
+/// @brief Contains the default values of the server.
+
+#ifndef DEFAULTS_H
+#define DEFAULTS_H
+
+#include <stdint.h>
+
+namespace isc {
+namespace dhcp {
+
+/// @brief Number of seconds after declined lease recovers
+///
+/// This define specifies the default value for decline probation period.
+/// Once a lease is declined, it will spend this amount of seconds as
+/// being unavailable. This is only the default value. Specific value may
+/// be defined in the configuration file. The default is 1 day.
+static const uint32_t DEFAULT_DECLINE_PROBATION_PERIOD = 24*3600;
+
+};
+};
+
+#endif
index 823c6708b4d4d4c1d99e72269c6e0d9dbccbacde..bdf4ea3763081a11654308b5097d05b556a2b840 100644 (file)
@@ -30,14 +30,16 @@ SrvConfig::SrvConfig()
     : sequence_(0), cfg_iface_(new CfgIface()),
       cfg_option_def_(new CfgOptionDef()), cfg_option_(new CfgOption()),
       cfg_subnets4_(new CfgSubnets4()), cfg_subnets6_(new CfgSubnets6()),
-      cfg_hosts_(new CfgHosts()), cfg_rsoo_(new CfgRSOO()) {
+      cfg_hosts_(new CfgHosts()), cfg_rsoo_(new CfgRSOO()),
+      decline_timer_(0) {
 }
 
 SrvConfig::SrvConfig(const uint32_t sequence)
     : sequence_(sequence), cfg_iface_(new CfgIface()),
       cfg_option_def_(new CfgOptionDef()), cfg_option_(new CfgOption()),
       cfg_subnets4_(new CfgSubnets4()), cfg_subnets6_(new CfgSubnets6()),
-      cfg_hosts_(new CfgHosts()), cfg_rsoo_(new CfgRSOO()) {
+      cfg_hosts_(new CfgHosts()), cfg_rsoo_(new CfgRSOO()),
+      decline_timer_(0) {
 }
 
 std::string
index 0f860e60b8b08838928cdaf4332668bda368c194..ba6149b62744d74f9d6a185262b7339b3cfd03dd 100644 (file)
@@ -376,6 +376,17 @@ public:
     /// @ref CfgSubnets6::removeStatistics for details.
     void removeStatistics();
 
+    /// @brief Sets decline probation-period
+    /// @param decline_timer number of seconds after declined lease is restored
+    void setDeclinePeriod(uint32_t decline_timer) {
+        decline_timer_ = decline_timer;
+    }
+
+    /// @brief
+    uint32_t getDeclinePeriod() const {
+        return (decline_timer_);
+    }
+
 private:
 
     /// @brief Sequence number identifying the configuration.
@@ -425,6 +436,9 @@ private:
 
     /// @brief Pointer to the control-socket information
     isc::data::ConstElementPtr control_socket_;
+
+    /// @brief Decline Period time
+    uint32_t decline_timer_;
 };
 
 /// @name Pointers to the @c SrvConfig object.