]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3543] tentative fix
authorFrancis Dupont <fdupont@isc.org>
Sat, 18 Aug 2018 22:06:52 +0000 (00:06 +0200)
committerFrancis Dupont <fdupont@isc.org>
Thu, 27 Dec 2018 20:00:18 +0000 (21:00 +0100)
src/bin/d2/d2_cfg_mgr.cc
src/bin/d2/d2_cfg_mgr.h
src/bin/d2/d2_process.cc
src/bin/d2/d2_process.h

index 35a16f0b0faab353e2f68456ef5b8fca83e2f5b7..2efce2ae621059de10c8658ccd6030fade0100a3 100644 (file)
@@ -35,8 +35,7 @@ D2CfgContext::D2CfgContext()
       forward_mgr_(new DdnsDomainListMgr("forward-ddns")),
       reverse_mgr_(new DdnsDomainListMgr("reverse-ddns")),
       keys_(new TSIGKeyInfoMap()),
-      control_socket_(ConstElementPtr()),
-      old_control_socket_(ConstElementPtr()) {
+      control_socket_(ConstElementPtr()) {
 }
 
 D2CfgContext::D2CfgContext(const D2CfgContext& rhs) : ConfigBase(rhs) {
@@ -54,7 +53,6 @@ D2CfgContext::D2CfgContext(const D2CfgContext& rhs) : ConfigBase(rhs) {
     keys_ = rhs.keys_;
 
     control_socket_ = rhs.control_socket_;
-    old_control_socket_ = rhs.old_control_socket_;
 }
 
 D2CfgContext::~D2CfgContext() {
@@ -247,6 +245,11 @@ D2CfgMgr::getD2Params() {
     return (getD2CfgContext()->getD2Params());
 }
 
+const isc::data::ConstElementPtr
+D2CfgMgr::getControlSocketInfo() {
+    return (getD2CfgContext()->getControlSocketInfo());
+}
+
 std::string
 D2CfgMgr::getConfigSummary(const uint32_t) {
     return (getD2Params()->getConfigSummary());
index 888653d80e622d507f2feb37fb374c25d7f8eeef..878ae3b63c7f6761272671878b5acf5b3ffb063e 100644 (file)
@@ -92,26 +92,15 @@ public:
 
     /// @brief Returns information about control socket
     ///
-    /// @param old When true returns the "old" value
     /// @return pointer to the Element that holds control-socket map
-    const isc::data::ConstElementPtr getControlSocketInfo(bool old = false) const {
-        if (!old) {
-            return (control_socket_);
-        } else {
-            return (old_control_socket_);
-        }
+    const isc::data::ConstElementPtr getControlSocketInfo() const {
+        return (control_socket_);
     }
 
     /// @brief Sets information about the control socket
     /// @param control_socket Element that holds control-socket map
-    /// @param old When true sets the "old" value.
-    void setControlSocketInfo(const isc::data::ConstElementPtr& control_socket,
-                              bool old = false) {
-        if (!old) {
-            control_socket_ = control_socket;
-        } else {
-            old_control_socket_ = control_socket;
-        }
+    void setControlSocketInfo(const isc::data::ConstElementPtr& control_socket) {
+        control_socket_ = control_socket;
     }
 
     /// @brief Unparse a configuration object
@@ -141,9 +130,6 @@ private:
 
     /// @brief Pointer to the control-socket information
     isc::data::ConstElementPtr control_socket_;
-
-    /// @brief Pointer to the old control-socket information
-    isc::data::ConstElementPtr old_control_socket_;
 };
 
 /// @brief Defines a pointer for DdnsDomain instances.
@@ -284,6 +270,11 @@ public:
     /// @return reference to const D2ParamsPtr
     const D2ParamsPtr& getD2Params();
 
+    /// @brief Returns information about control socket
+    ///
+    /// @return pointer to the Element that holds control-socket map
+    const isc::data::ConstElementPtr getControlSocketInfo();
+
     /// @brief Returns configuration summary in the textual format.
     ///
     /// @param selection Bitfield which describes the parts of the configuration
index dbf8ee4ab35fb88a3de57f7e90d3cc38f2705396..b76bdd368a4d1b0b77395b23487d0f599aef83d0 100644 (file)
@@ -199,6 +199,8 @@ D2Process::configure(isc::data::ConstElementPtr config_set, bool check_only) {
         .arg(check_only ? "check" : "update")
         .arg(config_set->str());
 
+    isc::data::ConstElementPtr current_socket;
+    current_socket = getD2CfgMgr()->getControlSocketInfo();
     isc::data::ConstElementPtr answer;
     answer = getCfgMgr()->simpleParseConfig(config_set, check_only);
     if (check_only) {
@@ -219,7 +221,9 @@ D2Process::configure(isc::data::ConstElementPtr config_set, bool check_only) {
 
     // Set the command channel.
     try {
-        configureCommandChannel();
+        isc::data::ConstElementPtr staging_socket;
+        staging_socket = getD2CfgMgr()->getControlSocketInfo();
+        configureCommandChannel(current_socket, staging_socket);
     } catch (const isc::Exception& ex) {
         answer = isc::config::createAnswer(2, ex.what());
         return (answer);
@@ -245,45 +249,26 @@ D2Process::configure(isc::data::ConstElementPtr config_set, bool check_only) {
 }
 
 void
-D2Process::configureCommandChannel() {
-    D2CfgMgrPtr mgr = getD2CfgMgr();
-    if (!mgr) {
-        return;
-    }
-    D2CfgContextPtr ctx = mgr->getD2CfgContext();
-    if (!ctx) {
-        return;
-    }
-    D2ControllerPtr ctrl =
-        boost::dynamic_pointer_cast<D2Controller>(D2Controller::instance());
-    if (!ctrl) {
-        return;
-    }
-
-    // Get the previous config.
-    isc::data::ConstElementPtr old_sock_cfg = ctx->getControlSocketInfo(true);
-
-    // Get the new config.
-    isc::data::ConstElementPtr sock_cfg = ctx->getControlSocketInfo();
-
+D2Process::configureCommandChannel(isc::data::ConstElementPtr current_cfg,
+                                   isc::data::ConstElementPtr staging_cfg) {
     // Determine if the socket configuration has changed. It has if
     // both old and new configuration is specified but respective
     // data elements aren't equal.
-    bool sock_changed = (old_sock_cfg && (old_sock_cfg->size() > 0) &&
-                         sock_cfg && (sock_cfg->size() > 0) &&
-                         !sock_cfg->equals(*old_sock_cfg));
-    if (old_sock_cfg && (old_sock_cfg->size() > 0) &&
-        (!sock_cfg || (sock_cfg->size() == 0) || sock_changed)) {
+    bool sock_changed = (current_cfg && (current_cfg->size() > 0) &&
+                         staging_cfg && (staging_cfg->size() > 0) &&
+                         !staging_cfg->equals(*current_cfg));
+    if (current_cfg && (current_cfg->size() > 0) &&
+        (!staging_cfg || (staging_cfg->size() == 0) || sock_changed)) {
         // Close the existing socket.
         isc::config::CommandMgr::instance().closeCommandSocket();
-        ctx->setControlSocketInfo(isc::data::ConstElementPtr(), true);
     }
-    if (sock_cfg && (sock_cfg->size() > 0) &&
-        (!old_sock_cfg || (old_sock_cfg->size() == 0) || sock_changed)) {
+    if (staging_cfg && (staging_cfg->size() > 0) &&
+        (!current_cfg || (current_cfg->size() == 0) || sock_changed)) {
         // Assume that CommandMgr works with D2 I/O.
+        D2ControllerPtr ctrl =
+            boost::dynamic_pointer_cast<D2Controller>(D2Controller::instance());
         ctrl->registerCommands();
-        isc::config::CommandMgr::instance().openCommandSocket(sock_cfg, true);
-        ctx->setControlSocketInfo(sock_cfg, true);
+        isc::config::CommandMgr::instance().openCommandSocket(staging_cfg, true);
     }
 }
 
index 83fa834cb162efdb9e50ecbb085ffe6ac3fc91f1..bd739f5483dceff09ade71ba0c664a4555083e35 100644 (file)
@@ -256,8 +256,10 @@ protected:
 
     /// @brief Configure the command channel.
     ///
-    /// Strip down code used in DHCPv4 / DHCPv6 servers.
-    void configureCommandChannel();
+    /// @param current_cfg current configuration of the control socket.
+    /// @param staging_cfg staging configuration of the control socket.
+    void configureCommandChannel(isc::data::ConstElementPtr current_cfg,
+                                 isc::data::ConstElementPtr staging_cfg);
 
 public:
     /// @brief Returns a pointer to the configuration manager.