]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[208-move-logging-from-global-objects-to-global-params] Added deprecated/obsolete...
authorFrancis Dupont <fdupont@isc.org>
Wed, 9 Jan 2019 14:40:15 +0000 (15:40 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 22 May 2019 22:10:24 +0000 (18:10 -0400)
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/dhcp4_messages.mes
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/dhcp6_messages.mes
src/lib/process/d_controller.cc
src/lib/process/process_messages.mes

index bc06990c10d5eab7c9618c1f5269e156e445115d..1f34a06a187e5889b63f4b10f1b94ab6fc2f7d21 100644 (file)
@@ -329,9 +329,29 @@ ControlledDhcpv4Srv::commandConfigSetHandler(const string&,
     // configuration attempts.
     CfgMgr::instance().rollback();
 
-    // Check obsolete objects.
-
-    // Check deprecated objects.
+    // Check deprecated, obsolete or unknown objects.
+    set<string> deprecated;
+    set<string> obsolete;
+    set<string> unknown;
+    for (auto obj : args->mapValue()) {
+        const string& obj_name = obj.first;
+        if ((obj_name == "Dhcp4") || (obj_name == "Logging")) {
+            continue;
+        }
+        if ((obj_name == "Dhcp6") || (obj_name == "DhcpDdns")) {
+            // Candidates for deprecated.
+            continue;
+        }
+        if (obj_name == "Control-agent") {
+            deprecated.insert(obj_name);
+            continue;
+        }
+        if (obj_name == "Netconf") {
+            obsolete.insert(obj_name);
+            continue;
+        }
+        unknown.insert(obj_name);
+    }
 
     // Relocate Logging.
     Daemon::relocateLogging(args, "Dhcp4");
@@ -347,8 +367,45 @@ ControlledDhcpv4Srv::commandConfigSetHandler(const string&,
     CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
 
     // Log deprecated objects.
+    for (auto name : deprecated) {
+        LOG_WARN(dhcp4_logger, DHCP4_CONFIG_DEPRECATED_OBJECT).arg(name);
+    }
 
-    // Log obsolete objects and return an error.
+    // Log obsolete/unknown objects and return an error.
+    string bad;
+    bool bads = false;
+    for (auto name : obsolete) {
+        LOG_ERROR(dhcp4_logger, DHCP4_CONFIG_OBSOLETE_OBJECT).arg(name);
+        if (bad.empty()) {
+            bad = name;
+        } else {
+            bads = true;
+        }
+    }
+    for (auto name : unknown) {
+        LOG_ERROR(dhcp4_logger, DHCP4_CONFIG_UNKNOWN_OBJECT).arg(name);
+        if (bad.empty()) {
+            bad= name;
+        } else {
+            bads = true;
+        }
+    }
+    if (!obsolete.empty() || !unknown.empty()) {
+        // Rollback logging.
+        CfgMgr::instance().getCurrentCfg()->applyLoggingCfg();
+
+        // Return a failure response.
+        message = "Unsupported object";
+        if (bads) {
+            message += "s";
+        }
+        message = " '" + bad + "'";
+        if (bads) {
+            message += ", ...";
+        }
+        message += " in config";
+        return (isc::config::createAnswer(status_code, message));
+    }
 
     // Now we configure the server proper.
     ConstElementPtr result = processConfig(dhcp4);
index b3f58c2b2f3dbdae12ec68b08864db685e4ccc75..5eb3141184ba959881e958c33d8fca6f43189f66 100644 (file)
@@ -134,7 +134,7 @@ new configuration. It is output during server startup, and when an updated
 configuration is committed by the administrator.  Additional information
 may be provided.
 
-% DHCP4_CONFIG_DEPRECATED DHCPv4 server configuration includes a deprecated object: %1
+% DHCP4_CONFIG_DEPRECATED_OBJECT DHCPv4 server configuration includes a deprecated object: %1
 This warning message is issued when the configuration includes a deprecated
 object (i.e. a top level element) which will be ignored.
 
@@ -152,7 +152,7 @@ server will continue to use an old configuration.
 This is an informational message reporting that the configuration has
 been extended to include the specified IPv4 subnet.
 
-% DHCP4_CONFIG_OBSOLETE DHCPv4 server configuration includes an obsolete object: %1
+% DHCP4_CONFIG_OBSOLETE_OBJECT DHCPv4 server configuration includes an obsolete object: %1
 This error message is issued when the configuration includes an obsolete
 object (i.e. a top level element).
 
@@ -175,6 +175,10 @@ This is a debug message that is issued every time the server receives a
 configuration. That happens at start up and also when a server configuration
 change is committed by the administrator.
 
+% DHCP4_CONFIG_UNKNOWN_OBJECT DHCPv4 server configuration includes an unknown object: %1
+This error message is issued when the configuration includes an unknown
+object (i.e. a top level element).
+
 % DHCP4_CONFIG_UPDATE updated configuration received: %1
 A debug message indicating that the DHCPv4 server has received an
 updated configuration from the Kea configuration system.
index 0d3e3c5e34a33e0121a4fd1a4f64d525aefc0bb7..0b3a916562924f2bfdf6be846b517a4cf6cda7d9 100644 (file)
@@ -331,9 +331,29 @@ ControlledDhcpv6Srv::commandConfigSetHandler(const string&,
     // configuration attempts.
     CfgMgr::instance().rollback();
 
-    // Check obsolete objects.
-
-    // Check deprecated objects.
+    // Check deprecated, obsolete or unknown objects.
+    set<string> deprecated;
+    set<string> obsolete;
+    set<string> unknown;
+    for (auto obj : args->mapValue()) {
+        const string& obj_name = obj.first;
+        if ((obj_name == "Dhcp6") || (obj_name == "Logging")) {
+            continue;
+        }
+        if ((obj_name == "Dhcp4") || (obj_name == "DhcpDdns")) {
+            // Candidates for deprecated.
+            continue;
+        }
+        if (obj_name == "Control-agent") {
+            deprecated.insert(obj_name);
+            continue;
+        }
+        if (obj_name == "Netconf") {
+            obsolete.insert(obj_name);
+            continue;
+        }
+        unknown.insert(obj_name);
+    }
 
     // Relocate Logging.
     Daemon::relocateLogging(args, "Dhcp6");
@@ -349,8 +369,45 @@ ControlledDhcpv6Srv::commandConfigSetHandler(const string&,
     CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
 
     // Log deprecated objects.
+    for (auto name : deprecated) {
+        LOG_WARN(dhcp6_logger, DHCP6_CONFIG_DEPRECATED_OBJECT).arg(name);
+    }
 
-    // Log obsolete objects and return an error.
+    // Log obsolete/unknown objects and return an error.
+    string bad;
+    bool bads = false;
+    for (auto name : obsolete) {
+        LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_OBSOLETE_OBJECT).arg(name);
+        if (bad.empty()) {
+            bad = name;
+        } else {
+            bads = true;
+        }
+    }
+    for (auto name : unknown) {
+        LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_UNKNOWN_OBJECT).arg(name);
+        if (bad.empty()) {
+            bad= name;
+        } else {
+            bads = true;
+        }
+    }
+    if (!obsolete.empty() || !unknown.empty()) {
+        // Rollback logging.
+        CfgMgr::instance().getCurrentCfg()->applyLoggingCfg();
+
+        // Return a failure response.
+        message = "Unsupported object";
+        if (bads) {
+            message += "s";
+        }
+        message = " '" + bad + "'";
+        if (bads) {
+            message += ", ...";
+        }
+        message += " in config";
+        return (isc::config::createAnswer(status_code, message));
+    }
 
     // Now we configure the server proper.
     ConstElementPtr result = processConfig(dhcp6);
@@ -411,7 +468,7 @@ ControlledDhcpv6Srv::commandConfigTestHandler(const string&,
     // Check obsolete objects.
 
     // Relocate Logging. Note this allows to check the loggers configuration.
-    Daemon::relocateLogging(args, "Dhcp4");
+    Daemon::relocateLogging(args, "Dhcp6");
 
     // Log obsolete objects and return an error.
 
index 7328687f96d1baafacce2064342ffc7f8d4c2bb5..47dae7542208c85930d61764895b5afa1066b064 100644 (file)
@@ -98,7 +98,7 @@ new configuration. it is output during server startup, and when an updated
 configuration is committed by the administrator.  Additional information
 may be provided.
 
-% DHCP6_CONFIG_DEPRECATED DHCPv6 server configuration includes a deprecated object: %1
+% DHCP6_CONFIG_DEPRECATED_OBJECT DHCPv6 server configuration includes a deprecated object: %1
 This warning message is issued when the configuration includes a deprecated
 object (i.e. a top level element) which will be ignored.
 
@@ -108,7 +108,7 @@ If this is an initial configuration (during server's startup) the server
 will fail to start. If this is a dynamic reconfiguration attempt the
 server will continue to use an old configuration.
 
-% DHCP6_CONFIG_OBSOLETE DHCPv6 server configuration includes an obsolete object: %1
+% DHCP6_CONFIG_OBSOLETE_OBJECT DHCPv6 server configuration includes an obsolete object: %1
 This error message is issued when the configuration includes an obsolete
 object (i.e. a top level element).
 
@@ -126,6 +126,10 @@ This is a debug message that is issued every time the server receives a
 configuration. That happens start up and also when a server configuration
 change is committed by the administrator.
 
+% DHCP6_CONFIG_UNKNOWN_OBJECT DHCPv6 server configuration includes an unknown object: %1
+This error message is issued when the configuration includes an unknown
+object (i.e. a top level element).
+
 % DHCP6_CONFIG_UPDATE updated configuration received: %1
 A debug message indicating that the IPv6 DHCP server has received an
 updated configuration from the Kea configuration system.
index 2a8a185d7bbf73e04b41226a65f8960c287272db..40ed28f55795aafa537da4a050a6eea03444ca01 100644 (file)
@@ -191,13 +191,38 @@ DControllerBase::checkConfigOnly() {
                       " include not map '" << getAppName() << "' entry");
         }
 
-        // Check obsolete objects.
+        // Check obsolete or unknown objects.
+        std::set<std::string> unsupported;
+        for (auto obj : whole_config->mapValue()) {
+            const std::string& app_name = getAppName();
+            const std::string& obj_name = obj.first;
+            if ((obj_name == app_name) || (obj_name == "Logging")) {
+                continue;
+            }
+            if ((obj_name == "Dhcp4") || (obj_name == "Dhcp6") ||
+                (obj_name == "Control-agent") || (obj_name == "Netconf")) {
+                if ((app_name == "DhcpDdns") ||
+                    (app_name == "Control-agent")) {
+                    continue;
+                }
+                if (app_name == "Netconf") {
+                    unsupported.insert(obj_name);
+                    continue;
+                }
+            }
+            unsupported.insert(obj_name);
+        }
+        if (unsupported.size() == 1) {
+            isc_throw(InvalidUsage, "Unsupported object '"
+                      << *unsupported.begin() << "' in config");
+        } else if (unsupported.size() > 1) {
+            isc_throw(InvalidUsage, "Unsupported objects '"
+                      << *unsupported.begin() << "', ... in config");
+        }
 
         // Relocate Logging.
         Daemon::relocateLogging(whole_config, getAppName());
 
-        // Log obsolete objects and return an error.
-
         // Get an application process object.
         initProcess();
 
index b122cb6a47700dfd58995d61a473628741319f4c..50cbfeca51145e9c0772e8b76124ac961c8f3b21 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2016-2019 Internet Systems Consortium, Inc. ("ISC")
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -66,7 +66,7 @@ This critical error message indicates that the initial application
 configuration has failed. The service will start, but will not
 process requests until the configuration has been corrected.
 
-% DCTL_CONFIG_OBSOLETE server configuration includes an obsolete object: %1
+% DCTL_CONFIG_OBSOLETE_OBJECT server configuration includes an obsolete object: %1
 This error message is issued when the configuration includes an obsolete
 object (i.e. a top level element).
 
@@ -79,6 +79,10 @@ for parsing.
 This debug message is issued when the dummy handler for configuration
 events is called.  This only happens during initial startup.
 
+% DCTL_CONFIG_UNKNOWN_OBJECT server configuration includes an unknown object: %1
+This error message is issued when the configuration includes an unknown
+object (i.e. a top level element).
+
 % DCTL_CONFIG_UPDATE %1 updated configuration received: %2
 A debug message indicating that the controller has received an
 updated configuration from the Kea configuration system.