From: Francis Dupont Date: Wed, 9 Jan 2019 14:40:15 +0000 (+0100) Subject: [208-move-logging-from-global-objects-to-global-params] Added deprecated/obsolete... X-Git-Tag: Kea-1.6.0-beta~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28a6f36117bc775951ff987293369fc60015f7e8;p=thirdparty%2Fkea.git [208-move-logging-from-global-objects-to-global-params] Added deprecated/obsolete/unknown object checks --- diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index bc06990c10..1f34a06a18 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -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 deprecated; + set obsolete; + set 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); diff --git a/src/bin/dhcp4/dhcp4_messages.mes b/src/bin/dhcp4/dhcp4_messages.mes index b3f58c2b2f..5eb3141184 100644 --- a/src/bin/dhcp4/dhcp4_messages.mes +++ b/src/bin/dhcp4/dhcp4_messages.mes @@ -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. diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 0d3e3c5e34..0b3a916562 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -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 deprecated; + set obsolete; + set 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. diff --git a/src/bin/dhcp6/dhcp6_messages.mes b/src/bin/dhcp6/dhcp6_messages.mes index 7328687f96..47dae75422 100644 --- a/src/bin/dhcp6/dhcp6_messages.mes +++ b/src/bin/dhcp6/dhcp6_messages.mes @@ -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. diff --git a/src/lib/process/d_controller.cc b/src/lib/process/d_controller.cc index 2a8a185d7b..40ed28f557 100644 --- a/src/lib/process/d_controller.cc +++ b/src/lib/process/d_controller.cc @@ -191,13 +191,38 @@ DControllerBase::checkConfigOnly() { " include not map '" << getAppName() << "' entry"); } - // Check obsolete objects. + // Check obsolete or unknown objects. + std::set 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(); diff --git a/src/lib/process/process_messages.mes b/src/lib/process/process_messages.mes index b122cb6a47..50cbfeca51 100644 --- a/src/lib/process/process_messages.mes +++ b/src/lib/process/process_messages.mes @@ -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.