]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5145b] get rid of D2ClientConfig::isShortCutDisabled
authorFrancis Dupont <fdupont@isc.org>
Sat, 4 Mar 2017 15:49:24 +0000 (16:49 +0100)
committerFrancis Dupont <fdupont@isc.org>
Sat, 4 Mar 2017 15:49:24 +0000 (16:49 +0100)
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp6/json_config_parser.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.h
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc

index 5b6102f3706d83123eac567ea32e2f9db6dd3525..f809d742b6e618aa628347d128dae1248e219dd4 100644 (file)
@@ -520,10 +520,8 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
 
             // Legacy DhcpConfigParser stuff below
             if (config_pair.first == "dhcp-ddns") {
-                // Apply defaults if not in short cut
-                if (!D2ClientConfigParser::isShortCutDisabled(config_pair.second)) {
-                    D2ClientConfigParser::setAllDefaults(config_pair.second);
-                }
+                // Apply defaults
+                D2ClientConfigParser::setAllDefaults(config_pair.second);
                 D2ClientConfigParser parser;
                 D2ClientConfigPtr cfg = parser.parse(config_pair.second);
                 srv_cfg->setD2ClientConfig(cfg);
index c0298951495288149c22dd8d04bd9dbc8b6aa062..59b021d65fa6d54ab50bbcee662c98230e440285 100644 (file)
@@ -742,10 +742,8 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set,
             }
 
             if (config_pair.first == "dhcp-ddns") {
-                // Apply defaults if not in short cut
-                if (!D2ClientConfigParser::isShortCutDisabled(config_pair.second)) {
-                    D2ClientConfigParser::setAllDefaults(config_pair.second);
-                }
+                // Apply defaults
+                D2ClientConfigParser::setAllDefaults(config_pair.second);
                 D2ClientConfigParser parser;
                 D2ClientConfigPtr cfg = parser.parse(config_pair.second);
                 srv_config->setD2ClientConfig(cfg);
index f139696a5610c503d8687dbe4e74fcd83d0f3eb7..0073a35d1714d4fc434970e6bddd8aa77b267c7a 100644 (file)
@@ -989,25 +989,8 @@ D2ClientConfigPtr
 D2ClientConfigParser::parse(isc::data::ConstElementPtr client_config) {
     D2ClientConfigPtr new_config;
 
-    if (isShortCutDisabled(client_config)) {
-      // If enable-updates is the only parameter and it is false then
-      // we're done.  This allows for an abbreviated configuration entry
-      // that only contains that flag.  Use the default D2ClientConfig
-      // constructor to a create a disabled instance.
-      new_config.reset(new D2ClientConfig());
-      return (new_config);
-    }
-
-    // As isShortCutDisabled() was called this cannot fail
-    bool enable_updates = client_config->get("enable-updates")->boolValue();
-
     // Get all parameters that are needed to create the D2ClientConfig.
-    std::string qualifying_suffix;
-    bool found_qualifying_suffix = false;
-    if (client_config->contains("qualifying-suffix")) {
-            qualifying_suffix = getString(client_config, "qualifying-suffix");
-            found_qualifying_suffix = true;
-    }   
+    bool enable_updates = getBoolean(client_config, "enable-updates");
 
     IOAddress server_ip = getIOAddress(client_config, "server-ip");
 
@@ -1040,14 +1023,13 @@ D2ClientConfigParser::parse(isc::data::ConstElementPtr client_config) {
     std::string generated_prefix =
         getString(client_config, "generated-prefix");
 
-
-    // Qualifying-suffix is required when updates are enabled
-    if (enable_updates && !found_qualifying_suffix) {
-        isc_throw(DhcpConfigError,
-                  "parameter 'qualifying-suffix' is required when "
-                  "updates are enabled ("
-                  << client_config->getPosition() << ")");
-    }
+    // qualifying-suffix is the only parameter which has no default
+    std::string qualifying_suffix = "";
+    bool found_qualifying_suffix = false;
+    if (client_config->contains("qualifying-suffix")) {
+            qualifying_suffix = getString(client_config, "qualifying-suffix");
+            found_qualifying_suffix = true;
+    }   
 
     IOAddress sender_ip(0);
     if (sender_ip_str.empty()) {
@@ -1064,6 +1046,14 @@ D2ClientConfigParser::parse(isc::data::ConstElementPtr client_config) {
         }
     }
 
+    // Qualifying-suffix is required when updates are enabled
+    if (enable_updates && !found_qualifying_suffix) {
+        isc_throw(DhcpConfigError,
+                  "parameter 'qualifying-suffix' is required when "
+                  "updates are enabled ("
+                  << client_config->getPosition() << ")");
+    }
+
     // Now we check for logical errors. This repeats what is done in
     // D2ClientConfig::validate(), but doing it here permits us to
     // emit meaningful parameter position info in the error.
@@ -1102,19 +1092,19 @@ D2ClientConfigParser::parse(isc::data::ConstElementPtr client_config) {
     try {
         // Attempt to create the new client config.
         new_config.reset(new D2ClientConfig(enable_updates,
-                                                      server_ip,
-                                                      server_port,
-                                                      sender_ip,
-                                                      sender_port,
-                                                      max_queue_size,
-                                                      ncr_protocol,
-                                                      ncr_format,
-                                                      always_include_fqdn,
-                                                      override_no_update,
-                                                      override_client_update,
-                                                      replace_client_name_mode,
-                                                      generated_prefix,
-                                                      qualifying_suffix));
+                                            server_ip,
+                                            server_port,
+                                            sender_ip,
+                                            sender_port,
+                                            max_queue_size,
+                                            ncr_protocol,
+                                            ncr_format,
+                                            always_include_fqdn,
+                                            override_no_update,
+                                            override_client_update,
+                                            replace_client_name_mode,
+                                            generated_prefix,
+                                            qualifying_suffix));
 
     }  catch (const std::exception& ex) {
         isc_throw(DhcpConfigError, ex.what() << " ("
@@ -1124,12 +1114,6 @@ D2ClientConfigParser::parse(isc::data::ConstElementPtr client_config) {
     return(new_config);
 }
 
-bool
-D2ClientConfigParser::isShortCutDisabled(isc::data::ConstElementPtr d2_config) {
-    bool value = getBoolean(d2_config, "enable-updates");
-    return (!value && (d2_config->mapValue().size() == 1));
-}
-
 /// @brief This table defines default values for D2 client configuration
 const SimpleDefaults D2ClientConfigParser::D2_CLIENT_CONFIG_DEFAULTS = {
     // enable-updates is unconditionally required
index 6f43a8f01322306662bb6302c52eff726086197d..d84d976ec79162fc70e5dcf80bd55aeec36ad7ee 100644 (file)
@@ -761,17 +761,6 @@ public:
     /// @return returns a pointer to newly created D2ClientConfig.
     D2ClientConfigPtr parse(isc::data::ConstElementPtr d2_client_cfg);
 
-    /// @brief Check the short cut disabled updates condition
-    ///
-    /// The condition is that the d2 client configuration is
-    /// reduced to "enable-updates": false
-    ///
-    /// @param d2_config d2 client configuration
-    /// @return true if and only if the condition matches.
-    /// @throw DhcpConfigError if enable-updates is not present or
-    /// is not a boolean
-    static bool isShortCutDisabled(isc::data::ConstElementPtr d2_config);
-
     /// @brief Defaults for the D2 client configuration.
     static const isc::data::SimpleDefaults D2_CLIENT_CONFIG_DEFAULTS;
 
index 810f3dec0a7657509bcf78d3b0485dd8cfb002ab..e8c48e709d5983661c467641dd52a67a8b19a382 100644 (file)
@@ -530,8 +530,7 @@ public:
 
         /// D2 client configuration code is in this library
         ConstElementPtr d2_client = config->get("dhcp-ddns");
-        if (d2_client &&
-            !D2ClientConfigParser::isShortCutDisabled(d2_client)) {
+        if (d2_client) {
             D2ClientConfigParser::setAllDefaults(d2_client);
         }
     }