]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2722] always perform config check before config set
authorRazvan Becheriu <razvan@isc.org>
Thu, 23 Feb 2023 19:28:14 +0000 (21:28 +0200)
committerRazvan Becheriu <razvan@isc.org>
Thu, 16 Mar 2023 19:26:11 +0000 (21:26 +0200)
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc

index f95e489d877b62ca90b6a73447a9b67c6b7db42a..6e51e81c567817c4f7b387948ccb78c84007d3df 100644 (file)
@@ -176,7 +176,7 @@ ControlledDhcpv4Srv::loadConfigFile(const std::string& file_name) {
                 "no details available";
             isc_throw(isc::BadValue, reason);
         }
-    }  catch (const std::exception& ex) {
+    } catch (const std::exception& ex) {
         // If configuration failed at any stage, we drop the staging
         // configuration and continue to use the previous one.
         CfgMgr::instance().rollback();
@@ -386,6 +386,20 @@ ControlledDhcpv4Srv::commandConfigSetHandler(const string&,
     // stop thread pool (if running)
     MultiThreadingCriticalSection cs;
 
+    // We are starting the configuration process so we should remove any
+    // staging configuration that has been created during previous
+    // configuration attempts.
+    CfgMgr::instance().rollback();
+
+    // Let's first check the config
+    ConstElementPtr result = checkConfig(dhcp4);
+
+    int rcode = 0;
+    isc::config::parseAnswer(rcode, result);
+    if (rcode != CONTROL_RESULT_SUCCESS) {
+        return (result);
+    }
+
     // disable multi-threading (it will be applied by new configuration)
     // this must be done in order to properly handle MT to ST transition
     // when 'multi-threading' structure is missing from new config
@@ -407,12 +421,11 @@ ControlledDhcpv4Srv::commandConfigSetHandler(const string&,
     CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
 
     // Now we configure the server proper.
-    ConstElementPtr result = processConfig(dhcp4);
+    result = processConfig(dhcp4);
 
     // If the configuration parsed successfully, apply the new logger
     // configuration and the commit the new configuration.  We apply
     // the logging first in case there's a configuration failure.
-    int rcode = 0;
     isc::config::parseAnswer(rcode, result);
     if (rcode == CONTROL_RESULT_SUCCESS) {
         CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
index 0d52d79c8f88600fc0cb632acd2ff0d83dabe3c1..be4475d74621f1a0cceeadf75fdafedc9574d2b3 100644 (file)
@@ -144,7 +144,7 @@ ControlledDhcpv6Srv::loadConfigFile(const std::string& file_name) {
                 "no details available";
             isc_throw(isc::BadValue, reason);
         }
-    }  catch (const std::exception& ex) {
+    } catch (const std::exception& ex) {
         // If configuration failed at any stage, we drop the staging
         // configuration and continue to use the previous one.
         CfgMgr::instance().rollback();
@@ -389,6 +389,20 @@ ControlledDhcpv6Srv::commandConfigSetHandler(const string&,
     // stop thread pool (if running)
     MultiThreadingCriticalSection cs;
 
+    // We are starting the configuration process so we should remove any
+    // staging configuration that has been created during previous
+    // configuration attempts.
+    CfgMgr::instance().rollback();
+
+    // Let's first check the config
+    ConstElementPtr result = checkConfig(dhcp6);
+
+    int rcode = 0;
+    isc::config::parseAnswer(rcode, result);
+    if (rcode != CONTROL_RESULT_SUCCESS) {
+        return (result);
+    }
+
     // disable multi-threading (it will be applied by new configuration)
     // this must be done in order to properly handle MT to ST transition
     // when 'multi-threading' structure is missing from new config
@@ -410,12 +424,11 @@ ControlledDhcpv6Srv::commandConfigSetHandler(const string&,
     CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
 
     // Now we configure the server proper.
-    ConstElementPtr result = processConfig(dhcp6);
+    result = processConfig(dhcp6);
 
     // If the configuration parsed successfully, apply the new logger
     // configuration and the commit the new configuration.  We apply
     // the logging first in case there's a configuration failure.
-    int rcode = 0;
     isc::config::parseAnswer(rcode, result);
     if (rcode == CONTROL_RESULT_SUCCESS) {
         CfgMgr::instance().getStagingCfg()->applyLoggingCfg();