]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[master] Merge branch 'trac3409'
authorMarcin Siodelski <marcin@isc.org>
Tue, 29 Apr 2014 20:19:56 +0000 (22:19 +0200)
committerMarcin Siodelski <marcin@isc.org>
Tue, 29 Apr 2014 20:19:56 +0000 (22:19 +0200)
Conflicts:
src/lib/dhcpsrv/d2_client_cfg.cc
src/lib/dhcpsrv/dhcp_parsers.cc

1  2 
configure.ac
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
src/lib/dhcpsrv/d2_client_cfg.cc
src/lib/dhcpsrv/dhcp_parsers.cc
src/lib/dhcpsrv/tests/cfgmgr_unittest.cc
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc

diff --cc configure.ac
Simple merge
index 473453f7fa3795fa2a0852b1a8af7af5cc876404,581996b2201afea62524a76478fb5accd454168e..49107dda603a7bc0626b5837093d049c87717487
@@@ -105,23 -92,9 +105,23 @@@ D2ClientConfig::validateContents() 
      }
  
      if (ncr_protocol_ != dhcp_ddns::NCR_UDP) {
-         isc_throw(D2ClientError, "D2ClientConfig: NCR Protocol:"
+         isc_throw(D2ClientError, "D2ClientConfig: NCR Protocol: "
 -                    << dhcp_ddns::ncrProtocolToString(ncr_protocol_)
 -                    << " is not yet supported");
 +                  << dhcp_ddns::ncrProtocolToString(ncr_protocol_)
 +                  << " is not yet supported");
 +    }
 +
 +    if (sender_ip_.getFamily() != server_ip_.getFamily()) {
 +        isc_throw(D2ClientError, "D2ClientConfig: address family mismatch: "
 +                  << "server-ip: " << server_ip_.toText()
 +                  << " is: " << (server_ip_.isV4() ? "IPv4" : "IPv6")
 +                  << " while sender-ip: "  << sender_ip_.toText()
 +                  << " is: " << (sender_ip_.isV4() ? "IPv4" : "IPv6"));
 +    }
 +
 +    if (server_ip_ == sender_ip_ && server_port_ == sender_port_) {
 +        isc_throw(D2ClientError, "D2ClientConfig: server and sender cannot"
 +                  " share the exact same IP address/port: "
 +                  << server_ip_.toText() << "/" << server_port_);
      }
  
      /// @todo perhaps more validation we should do yet?
index dddf2c048b6f3afee7516fcf9681c2cacb3eb97a,abf7c4421a6eefefd4dd0da6a256e893e3df6269..c3f809812a0cbd683f4f91fa5a1e297cca279992
@@@ -1262,95 -1364,89 +1364,110 @@@ D2ClientConfigParser::build(isc::data::
          parser->commit();
      }
  
-     bool enable_updates = boolean_values_->getParam("enable-updates");
-     if (!enable_updates && (client_config->mapValue().size() == 1)) {
-         // 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.
-         local_client_config_.reset(new D2ClientConfig());
-         return;
-     }
+     /// @todo Create configuration from the configuration parameters. Because
+     /// the validation of the D2 configuration is atomic, there is no way to
+     /// tell which parameter is invalid. Therefore, we catch all exceptions
+     /// and append the line number of the parent element. In the future we
+     /// may should extend D2ClientConfig code so as it returns the name of
+     /// the invalid parameter.
+     try {
+         bool enable_updates = boolean_values_->getParam("enable-updates");
+         if (!enable_updates && (client_config->mapValue().size() == 1)) {
+             // 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.
+             local_client_config_.reset(new D2ClientConfig());
  
-     // Get all parameters that are needed to create the D2ClientConfig.
-     asiolink::IOAddress server_ip(string_values_->
-                                   getOptionalParam("server-ip",
-                                                    D2ClientConfig::
-                                                    DFT_SERVER_IP));
-     uint32_t server_port = uint32_values_->getOptionalParam("server-port",
-                                                              D2ClientConfig::
-                                                              DFT_SERVER_PORT);
-     // The default sender IP depends on the server IP family
-     asiolink::IOAddress
-         sender_ip(string_values_->
-                   getOptionalParam("sender-ip",
-                                    (server_ip.isV4() ?
-                                     D2ClientConfig::DFT_V4_SENDER_IP :
-                                     D2ClientConfig::DFT_V6_SENDER_IP)));
-     uint32_t sender_port = uint32_values_->getOptionalParam("sender-port",
-                                                              D2ClientConfig::
-                                                              DFT_SENDER_PORT);
-     uint32_t max_queue_size
-         = uint32_values_->getOptionalParam("max-queue-size",
-                                             D2ClientConfig::
-                                             DFT_MAX_QUEUE_SIZE);
-     dhcp_ddns::NameChangeProtocol ncr_protocol
-         = dhcp_ddns::stringToNcrProtocol(string_values_->
-                                          getOptionalParam("ncr-protocol",
-                                                           D2ClientConfig::
-                                                           DFT_NCR_PROTOCOL));
-     dhcp_ddns::NameChangeFormat ncr_format
-         = dhcp_ddns::stringToNcrFormat(string_values_->
-                                        getOptionalParam("ncr-format",
-                                                           D2ClientConfig::
-                                                           DFT_NCR_FORMAT));
-     std::string generated_prefix = string_values_->
-                                    getOptionalParam("generated-prefix",
-                                                     D2ClientConfig::
-                                                     DFT_GENERATED_PREFIX);
-     std::string qualifying_suffix = string_values_->
-                                     getOptionalParam("qualifying-suffix",
-                                                      D2ClientConfig::
-                                                      DFT_QUALIFYING_SUFFIX);
-     bool always_include_fqdn = boolean_values_->
-                                getOptionalParam("always-include-fqdn",
-                                                 D2ClientConfig::
-                                                 DFT_ALWAYS_INCLUDE_FQDN);
+             return;
+         }
  
-     bool override_no_update = boolean_values_->
-                               getOptionalParam("override-no-update",
+         // Get all parameters that are needed to create the D2ClientConfig.
+         IOAddress server_ip =
+             IOAddress(string_values_->getOptionalParam("server-ip",
+                                                        D2ClientConfig::
+                                                        DFT_SERVER_IP));
+         uint32_t server_port =
+             uint32_values_->getOptionalParam("server-port",
+                                              D2ClientConfig::DFT_SERVER_PORT);
 -        dhcp_ddns::NameChangeProtocol ncr_protocol
 -            = dhcp_ddns::stringToNcrProtocol(string_values_->
 -                                             getOptionalParam("ncr-protocol",
 -                                                              D2ClientConfig::
 -                                                              DFT_NCR_PROTOCOL));
++        // The default sender IP depends on the server IP family
++        asiolink::IOAddress
++            sender_ip(string_values_->
++                      getOptionalParam("sender-ip",
++                                       (server_ip.isV4() ?
++                                        D2ClientConfig::DFT_V4_SENDER_IP :
++                                        D2ClientConfig::DFT_V6_SENDER_IP)));
++
++        uint32_t sender_port =
++            uint32_values_->getOptionalParam("sender-port",
++                                             D2ClientConfig::
++                                             DFT_SENDER_PORT);
++        uint32_t max_queue_size
++            = uint32_values_->getOptionalParam("max-queue-size",
 +                                               D2ClientConfig::
-                                                DFT_OVERRIDE_NO_UPDATE);
-     bool override_client_update = boolean_values_->
-                                   getOptionalParam("override-client-update",
-                                                    D2ClientConfig::
-                                                    DFT_OVERRIDE_CLIENT_UPDATE);
-     bool replace_client_name = boolean_values_->
-                                getOptionalParam("replace-client-name",
++                                               DFT_MAX_QUEUE_SIZE);
++
++        dhcp_ddns::NameChangeProtocol ncr_protocol =
++            dhcp_ddns::stringToNcrProtocol(string_values_->
++                                           getOptionalParam("ncr-protocol",
++                                                            D2ClientConfig::
++                                                            DFT_NCR_PROTOCOL));
+         dhcp_ddns::NameChangeFormat ncr_format
+             = dhcp_ddns::stringToNcrFormat(string_values_->
+                                            getOptionalParam("ncr-format",
+                                                             D2ClientConfig::
+                                                             DFT_NCR_FORMAT));
+         std::string generated_prefix =
+             string_values_->getOptionalParam("generated-prefix",
+                                              D2ClientConfig::
+                                              DFT_GENERATED_PREFIX);
+         std::string qualifying_suffix =
+             string_values_->getOptionalParam("qualifying-suffix",
+                                              D2ClientConfig::
+                                              DFT_QUALIFYING_SUFFIX);
+         bool always_include_fqdn =
+             boolean_values_->getOptionalParam("always-include-fqdn",
 -                                              D2ClientConfig::
 -                                              DFT_ALWAYS_INCLUDE_FQDN);
 +                                                D2ClientConfig::
-                                                 DFT_REPLACE_CLIENT_NAME);
-     // Attempt to create the new client config.
-     local_client_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,
-                                                   generated_prefix,
-                                                   qualifying_suffix));
++                                                DFT_ALWAYS_INCLUDE_FQDN);
+         bool override_no_update =
+             boolean_values_->getOptionalParam("override-no-update",
+                                               D2ClientConfig::
+                                               DFT_OVERRIDE_NO_UPDATE);
+         bool override_client_update =
+             boolean_values_->getOptionalParam("override-client-update",
+                                               D2ClientConfig::
+                                               DFT_OVERRIDE_CLIENT_UPDATE);
+         bool replace_client_name =
+             boolean_values_->getOptionalParam("replace-client-name",
+                                               D2ClientConfig::
+                                               DFT_REPLACE_CLIENT_NAME);
+         // Attempt to create the new client config.
+         local_client_config_.reset(new D2ClientConfig(enable_updates,
+                                                       server_ip,
 -                                                      server_port, ncr_protocol,
++                                                      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,
+                                                       generated_prefix,
+                                                       qualifying_suffix));
+     }  catch (const std::exception& ex) {
+         isc_throw(DhcpConfigError, ex.what() << " ("
+                   << client_config->getPosition() << ")");
+     }
  }
  
  isc::dhcp::ParserPtr