]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1598] convert reservation-mode from CB to new flags
authorRazvan Becheriu <razvan@isc.org>
Tue, 12 Jan 2021 17:22:59 +0000 (19:22 +0200)
committerRazvan Becheriu <razvan@isc.org>
Tue, 19 Jan 2021 11:37:45 +0000 (13:37 +0200)
src/lib/dhcpsrv/parsers/base_network_parser.cc
src/lib/dhcpsrv/parsers/simple_parser4.cc
src/lib/dhcpsrv/parsers/simple_parser6.cc
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/tests/network_unittest.cc

index 55f3dc9ec62e4ff9c0cbe7d71130d1062e7ce10f..b372445421f70692485e884f6883ecc7f14f51f2 100644 (file)
@@ -25,7 +25,7 @@ BaseNetworkParser::moveReservationMode(ElementPtr config) {
         config->contains("reservations-in-subnet") ||
         config->contains("reservations-out-of-pool")) {
         isc_throw(DhcpConfigError, "invalid use of both 'reservation-mode'"
-                  " one of 'reservations-global', 'reservations-in-subnet'"
+                  " and one of 'reservations-global', 'reservations-in-subnet'"
                   " or 'reservations-out-of-pool' parameters");
     }
     std::string hr_mode = getString(config, "reservation-mode");
index 5095451f95c3680cf08ff5c6327bdcccc9e9c327..48d4a3efbd15aa5e7f75ffa5e1f5ea8855d7dc7d 100644 (file)
@@ -70,6 +70,7 @@ const SimpleKeywords SimpleParser4::GLOBAL4_PARAMETERS = {
     { "reservations",                   Element::list },
     { "config-control",                 Element::map },
     { "server-tag",                     Element::string },
+    { "reservation-mode",               Element::string },
     { "reservations-global",            Element::boolean },
     { "reservations-in-subnet",         Element::boolean },
     { "reservations-out-of-pool",       Element::boolean },
index e9317d7187ea5759e860a56ebabc9c54bc09456a..7b715082921e82c711c0b74ef819f215b60aeb74 100644 (file)
@@ -71,6 +71,7 @@ const SimpleKeywords SimpleParser6::GLOBAL6_PARAMETERS = {
     { "reservations",                   Element::list },
     { "config-control",                 Element::map },
     { "server-tag",                     Element::string },
+    { "reservation-mode",               Element::string },
     { "reservations-global",            Element::boolean },
     { "reservations-in-subnet",         Element::boolean },
     { "reservations-out-of-pool",       Element::boolean },
index a0f0fee87abd14da534442b8a4e86a85d4d895cc..81698ff22109f026e163be03dd5b117572bee905 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 #include <exceptions/exceptions.h>
 #include <dhcpsrv/cfgmgr.h>
+#include <dhcpsrv/parsers/base_network_parser.h>
 #include <dhcpsrv/parsers/simple_parser4.h>
 #include <dhcpsrv/srv_config.h>
 #include <dhcpsrv/lease_mgr_factory.h>
@@ -218,30 +219,39 @@ SrvConfig::merge6(SrvConfig& other) {
 
 void
 SrvConfig::mergeGlobals(SrvConfig& other) {
+    auto config_set = getConfiguredGlobals();
+    ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(config_set);
+    // If the deprecated reservation-mode is found in database, overwrite other
+    // reservation flags so there is no conflict when merging to new flags.
+    if (other.getConfiguredGlobals()->find("reservation-mode")) {
+        mutable_cfg->remove("reservations-global");
+        mutable_cfg->remove("reservations-in-subnet");
+        mutable_cfg->remove("reservations-out-of-pool");
+    }
     // Iterate over the "other" globals, adding/overwriting them into
     // this config's list of globals.
     for (auto other_global : other.getConfiguredGlobals()->mapValue()) {
         addConfiguredGlobal(other_global.first, other_global.second);
     }
 
+    // Merge the reservation-mode to new reservation flags.
+    BaseNetworkParser::moveReservationMode(mutable_cfg);
+
     // A handful of values are stored as members in SrvConfig. So we'll
-    // iterate over the merged globals, setting approprate members.
-    for (auto merged_global : getConfiguredGlobals()->mapValue()) {
+    // iterate over the merged globals, setting appropriate members.
+    for (auto merged_global : config_set->mapValue()) {
         std::string name = merged_global.first;
         ConstElementPtr element = merged_global.second;
         try {
             if (name == "decline-probation-period") {
                 setDeclinePeriod(element->intValue());
-            }
-            else if (name == "echo-client-id") {
+            } else if (name == "echo-client-id") {
                 // echo-client-id is v4 only, but we'll let upstream
                 // worry about that.
                 setEchoClientId(element->boolValue());
-            }
-            else if (name == "dhcp4o6-port") {
+            } else if (name == "dhcp4o6-port") {
                 setDhcp4o6Port(element->intValue());
-            }
-            else if (name == "server-tag") {
+            } else if (name == "server-tag") {
                 setServerTag(element->stringValue());
             } else if (name == "ip-reservations-unique") {
                 setIPReservationsUnique(element->boolValue());
index c8312fd4770ee33cf33b8c139fdeadc056da7447..4b8ff071220bbba657a90150d4e2a08dd402a115 100644 (file)
@@ -638,7 +638,7 @@ TEST_F(NetworkReservationTest, errors) {
         "\"reservations-global\": true\n"
         "}";
     std::string expected = "invalid use of both 'reservation-mode'"
-        " one of 'reservations-global', 'reservations-in-subnet'"
+        " and one of 'reservations-global', 'reservations-in-subnet'"
         " or 'reservations-out-of-pool' parameters";
     TestError(config, expected);