]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4341] Checkpoint: UT and doc to do
authorFrancis Dupont <fdupont@isc.org>
Sun, 22 Feb 2026 14:34:00 +0000 (15:34 +0100)
committerFrancis Dupont <fdupont@isc.org>
Thu, 7 May 2026 08:15:53 +0000 (10:15 +0200)
src/bin/d2/d2_process.cc
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/lib/config/http_command_config.cc
src/lib/config/http_command_config.h
src/lib/config/http_command_response_creator.cc
src/lib/config/http_command_response_creator.h

index c1e5c2ade7378e4704c33733c4171b0aa435965f..2412da1a9f37089c9583bb53066d331123300b52 100644 (file)
@@ -90,6 +90,9 @@ D2Process::init() {
     // Set the HTTP authentication default realm.
     HttpCommandConfig::DEFAULT_AUTHENTICATION_REALM = "kea-dhcp-ddns-server";
 
+    // Set the HTTP supported service.
+    HttpCommandConfig::SUPPORTED_SERVICE = "d2";
+
     // D2 server does not use the interface manager.
     UnixCommandMgr::instance().addExternalSockets(false);
     HttpCommandMgr::instance().addExternalSockets(false);
index 4993c6d9f48843ce7d5ca93509c77d97dd99f5f6..95064ec729802d81e180cbc6427a6a332eb806f7 100644 (file)
@@ -1489,6 +1489,9 @@ ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t server_port /*= DHCP4_SERVER_P
     // Set the HTTP authentication default realm.
     HttpCommandConfig::DEFAULT_AUTHENTICATION_REALM = "kea-dhcpv4-server";
 
+    // Set the HTTP supported service.
+    HttpCommandConfig::SUPPORTED_SERVICE = "dhcp4";
+
     // DatabaseConnection uses IO service to run asynchronous timers.
     DatabaseConnection::setIOService(getIOService());
 
index 22100d43b9606fe3ac54cdd84f42f9590d8696c2..99b982e2e8b03f0f3174310240c8b962dc821b23 100644 (file)
@@ -1279,6 +1279,9 @@ ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t server_port /*= DHCP6_SERVER_P
     // Set the HTTP authentication default realm.
     HttpCommandConfig::DEFAULT_AUTHENTICATION_REALM = "kea-dhcpv6-server";
 
+    // Set the HTTP supported service.
+    HttpCommandConfig::SUPPORTED_SERVICE = "dhcp6";
+
     // DatabaseConnection uses IO service to run asynchronous timers.
     DatabaseConnection::setIOService(getIOService());
 
index 478cbf7d5d44d24e09bd7fae08d8fb7cd6a6c467..4fb7fc162b2d372d6b216b11e0a6871aa399e235 100644 (file)
@@ -34,6 +34,8 @@ string HttpCommandConfig::DEFAULT_AUTHENTICATION_REALM = "";
 
 bool HttpCommandConfig::EMULATE_AGENT_RESPONSE = true;
 
+string HttpCommandConfig::SUPPORTED_SERVICE = "";
+
 HttpCommandConfig::HttpCommandConfig(ConstElementPtr config)
     : socket_type_("http"), socket_address_(DEFAULT_SOCKET_ADDRESS),
       socket_port_(DEFAULT_SOCKET_PORT), http_headers_(), auth_config_(),
index a4cc24e4c07b9e2d5f12051eba915ad009437a8a..3eff844ea222f3f204c75a60646348740d482b52 100644 (file)
@@ -179,6 +179,9 @@ public:
     /// @brief Emulation flag.
     static bool EMULATE_AGENT_RESPONSE;
 
+    /// @brief Suppoted service.
+    static std::string SUPPORTED_SERVICE;
+
 private:
     /// @brief Check TLS configuration.
     ///
index 46401055e72562dafe5e310758df54b3df0d5461..066d5b21126e78938b24603e96fbcc5accf89369 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <config.h>
 
+#include <cc/command_interpreter.h>
 #include <config/http_command_response_creator.h>
 #include <config/command_mgr.h>
 #include <config/config_log.h>
@@ -171,7 +172,11 @@ HttpCommandResponseCreator::createDynamicHttpResponse(HttpRequestPtr request) {
     // Process command doesn't generate exceptions but can possibly return
     // null response, if the handler is not implemented properly. This is
     // again an internal server issue.
-    ConstElementPtr response = config::CommandMgr::instance().processCommand(command);
+    // Check service first.
+    ConstElementPtr response = checkService(command);
+    if (!response) {
+        response = config::CommandMgr::instance().processCommand(command);
+    }
 
     if (!response) {
         // Notify the client that we have a problem with our server.
@@ -216,5 +221,43 @@ HttpCommandResponseCreator::createDynamicHttpResponse(HttpRequestPtr request) {
     return (http_response);
 }
 
+ConstElementPtr
+HttpCommandResponseCreator::checkService(ConstElementPtr command) const {
+    if (HttpCommandConfig::SUPPORTED_SERVICE.empty()) {
+        return (ConstElementPtr());
+    }
+
+    // Sanity checks (errors will be handled by processCommand).
+    if (!command || (command->getType() != Element::map)) {
+        return (ConstElementPtr());
+    }
+    ConstElementPtr services = command->get("service");
+    if (!services) {
+        return (ConstElementPtr());
+    }
+    if (services->getType() != Element::list) {
+        return (createAnswer(CONTROL_RESULT_ERROR, "service value must be a list"));
+    }
+    // Ignore empty service list as the control agent does.
+    if (services->empty()) {
+        return (ConstElementPtr());
+    }
+    if (services->size() != 1) {
+        return (createAnswer(CONTROL_RESULT_ERROR, "service value has more than one item"));
+    }
+    ConstElementPtr service = services->get(0);
+    if (!service || (service->getType() != Element::string)) {
+        return (createAnswer(CONTROL_RESULT_ERROR, "service name must be a string"));
+    }
+    string name = service->stringValue();
+    if (name.empty() || (name == HttpCommandConfig::SUPPORTED_SERVICE)) {
+        return (ConstElementPtr());
+    }
+    // Service name mismatch.
+    string msg = "unsupported service '" + name + "', expected '";
+    msg += HttpCommandConfig::SUPPORTED_SERVICE + "'";
+    return (createAnswer(CONTROL_RESULT_ERROR,msg));
+}
+
 } // end of namespace isc::config
 } // end of namespace isc
index 74f6696042d1ed140377b87def9ddb3f14d36789..3e6918847916b188526bb37eb79aea5154864e33 100644 (file)
@@ -87,6 +87,12 @@ private:
     virtual http::HttpResponsePtr
     createDynamicHttpResponse(http::HttpRequestPtr request);
 
+    /// @brief Check the service.
+    ///
+    /// @param command The command.
+    /// @return A response with the error or null.
+    data::ConstElementPtr checkService(data::ConstElementPtr command) const;
+
     /// @brief Returns HTTP control socket config.
     ///
     /// Used for HTTP authentication.