diff options
author | Razvan Becheriu <razvan@isc.org> | 2023-02-23 20:28:14 +0100 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2023-03-16 20:26:11 +0100 |
commit | 66df0bd1d7e7d77bc170b99b76ca52988fe14b1c (patch) | |
tree | 32f173f0af386cf0fdd23672da1f9ff9dcca1e9e | |
parent | [#2784] Added a ChangeLog entry (diff) | |
download | kea-66df0bd1d7e7d77bc170b99b76ca52988fe14b1c.tar.xz kea-66df0bd1d7e7d77bc170b99b76ca52988fe14b1c.zip |
[#2722] always perform config check before config set
-rw-r--r-- | src/bin/dhcp4/ctrl_dhcp4_srv.cc | 19 | ||||
-rw-r--r-- | src/bin/dhcp6/ctrl_dhcp6_srv.cc | 19 |
2 files changed, 32 insertions, 6 deletions
diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index f95e489d87..6e51e81c56 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -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(); diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 0d52d79c8f..be4475d746 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -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(); |