]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1585] Checkpoint: did second phase
authorFrancis Dupont <fdupont@isc.org>
Fri, 18 Dec 2020 00:07:27 +0000 (01:07 +0100)
committerFrancis Dupont <fdupont@isc.org>
Mon, 11 Jan 2021 14:28:01 +0000 (15:28 +0100)
13 files changed:
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
src/hooks/dhcp/flex_option/tests/flex_option_unittests.cc
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc
src/lib/dhcp/libdhcp++.cc
src/lib/dhcp/option_definition.cc
src/lib/dhcp/option_definition.h
src/lib/dhcp/tests/libdhcp++_unittest.cc
src/lib/dhcp/tests/option_definition_unittest.cc
src/lib/dhcpsrv/benchmarks/generic_host_data_source_benchmark.cc
src/lib/dhcpsrv/cfg_option_def.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc

index 187d4063a389a66fe93438f6b557d1e468717601..88f14a0757da8336c58957524b0107da5b5fe27d 100644 (file)
@@ -2440,7 +2440,7 @@ TEST_F(Dhcp4ParserTest, optionDefDuplicate) {
     // revert to this original configuration.
     OptionDefSpaceContainer defs;
     OptionDefinitionPtr def(new OptionDefinition("bar", 233, "isc", "string"));
-    defs.addItem(def, "isc");
+    defs.addItem(def);
     LibDHCP::setRuntimeOptionDefs(defs);
     LibDHCP::commitRuntimeOptionDefs();
 
index 53ec0e9c9952fd9b87a6885292d0a9187da075ee..208b6687e567ddd7d99171c11fc9cb63f2510169 100644 (file)
@@ -2809,7 +2809,7 @@ TEST_F(Dhcp6ParserTest, optionDefDuplicate) {
     // revert to this original configuration.
     OptionDefSpaceContainer defs;
     OptionDefinitionPtr def(new OptionDefinition("bar", 233, "isc", "string"));
-    defs.addItem(def, "isc");
+    defs.addItem(def);
     LibDHCP::setRuntimeOptionDefs(defs);
     LibDHCP::commitRuntimeOptionDefs();
 
index a328e405341783a5a20df0413a9938f6e4b51cd0..d9739f58b0c0e89abd140fc13c4ef317c8a368be 100644 (file)
@@ -325,7 +325,7 @@ TEST_F(FlexOptionTest, optionConfigDefinedName) {
     OptionDefSpaceContainer defs;
     OptionDefinitionPtr def(new OptionDefinition("my-option", 222,
                                                  DHCP4_OPTION_SPACE, "string"));
-    defs.addItem(def, DHCP4_OPTION_SPACE);
+    defs.addItem(def);
     EXPECT_NO_THROW(LibDHCP::setRuntimeOptionDefs(defs));
 
     ElementPtr options = Element::createList();
index 7fbb0950f248110230fd057bebef1e1060496946..3fcd0274bec81b7b77a189c4c2cf7d48e0589ac5 100644 (file)
@@ -411,18 +411,12 @@ public:
         // proper output.
         defs.addItem(OptionDefinitionPtr(new OptionDefinition(
                          "vendor-encapsulated-1", 1,
-                         "vendor-encapsulated-options", "uint32")),
-                     "vendor-encapsulated-options");
+                         "vendor-encapsulated-options", "uint32")));
         defs.addItem(OptionDefinitionPtr(new OptionDefinition(
                          "option-254", 254, DHCP4_OPTION_SPACE,
-                         "ipv4-address", true)),
-                     DHCP4_OPTION_SPACE);
-        defs.addItem(OptionDefinitionPtr(new OptionDefinition(
-                         "isc-1", 1, "isc", "empty")),
-                     "isc");
-        defs.addItem(OptionDefinitionPtr(new OptionDefinition(
-                         "isc-2", 2, "isc", "ipv4-address", true)),
-                     "isc");
+                         "ipv4-address", true)));
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-1", 1, "isc", "empty")));
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-2", 2, "isc", "ipv4-address", true)));
 
         // Register option definitions.
         LibDHCP::setRuntimeOptionDefs(defs);
index d2520594c4f7872862fe8f21e35c5a6483d92168..d069b8eb6befd7266dd52ced307cbbd8a154bca5 100644 (file)
@@ -459,18 +459,12 @@ public:
         // proper output.
         defs.addItem(OptionDefinitionPtr(new OptionDefinition(
                          "vendor-encapsulated-1", 1,
-                         "vendor-encapsulated-options", "uint32")),
-                     "vendor-encapsulated-options");
+                         "vendor-encapsulated-options", "uint32")));
         defs.addItem(OptionDefinitionPtr(new OptionDefinition(
                          "option-1254", 1254, DHCP6_OPTION_SPACE,
-                         "ipv6-address", true)),
-                     DHCP6_OPTION_SPACE);
-        defs.addItem(OptionDefinitionPtr(new OptionDefinition(
-                         "isc-1", 1, "isc", "empty")),
-                     "isc");
-        defs.addItem(OptionDefinitionPtr(new OptionDefinition(
-                         "isc-2", 2, "isc", "ipv6-address", true)),
-                     "isc");
+                         "ipv6-address", true)));
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-1", 1, "isc", "empty")));
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-2", 2, "isc", "ipv6-address", true)));
 
         // Register option definitions.
         LibDHCP::setRuntimeOptionDefs(defs);
index fa3fb996cf4263d42a00e3bdf7416ebcd55bda23..237862673c905473146b8d6d2e52c85c87dcdfc3 100644 (file)
@@ -220,7 +220,7 @@ LibDHCP::setRuntimeOptionDefs(const OptionDefSpaceContainer& defs) {
         for (OptionDefContainer::const_iterator def = container->begin();
              def != container->end(); ++def) {
             OptionDefinitionPtr def_copy(new OptionDefinition(**def));
-            defs_copy.addItem(def_copy, *name);
+            defs_copy.addItem(def_copy);
         }
     }
     runtime_option_defs_ = defs_copy;
index be8efd4aad1f8f6a93d5a53bd6e6cf69b4526d83..293b6c85dd9406563fc2b44435ddf814a35847f7 100644 (file)
@@ -438,110 +438,6 @@ OptionDefinition::validate() const {
     }
 }
 
-bool
-OptionDefinition::haveIAx6Format(OptionDataType first_type) const {
-   return (haveType(OPT_RECORD_TYPE) &&
-           !getArrayType() &&
-           record_fields_.size() == 3 &&
-           record_fields_[0] == first_type &&
-           record_fields_[1] == OPT_UINT32_TYPE &&
-           record_fields_[2] == OPT_UINT32_TYPE);
-}
-
-bool
-OptionDefinition::haveIA6Format() const {
-    // Expect that IA_NA option format is defined as record.
-    // Although it consists of 3 elements of the same (uint32)
-    // type it can't be defined as array of uint32 elements because
-    // arrays do not impose limitations on number of elements in
-    // the array while this limitation is needed for IA_NA - need
-    // exactly 3 elements.
-    return (haveIAx6Format(OPT_UINT32_TYPE));
-}
-
-bool
-OptionDefinition::haveIAAddr6Format() const {
-    return (haveIAx6Format(OPT_IPV6_ADDRESS_TYPE));
-}
-
-bool
-OptionDefinition::haveIAPrefix6Format() const {
-    return (haveType(OPT_RECORD_TYPE) &&
-           !getArrayType() &&
-            record_fields_.size() == 4 &&
-            record_fields_[0] == OPT_UINT32_TYPE &&
-            record_fields_[1] == OPT_UINT32_TYPE &&
-            record_fields_[2] == OPT_UINT8_TYPE &&
-            record_fields_[3] == OPT_IPV6_ADDRESS_TYPE);
-}
-
-bool
-OptionDefinition::haveFqdn4Format() const {
-    return (haveType(OPT_RECORD_TYPE) &&
-           !getArrayType() &&
-            record_fields_.size() == 4 &&
-            record_fields_[0] == OPT_UINT8_TYPE &&
-            record_fields_[1] == OPT_UINT8_TYPE &&
-            record_fields_[2] == OPT_UINT8_TYPE &&
-            record_fields_[3] == OPT_FQDN_TYPE);
-}
-
-bool
-OptionDefinition::haveClientFqdnFormat() const {
-    return (haveType(OPT_RECORD_TYPE) &&
-           !getArrayType() &&
-            (record_fields_.size() == 2) &&
-            (record_fields_[0] == OPT_UINT8_TYPE) &&
-            (record_fields_[1] == OPT_FQDN_TYPE));
-}
-
-bool
-OptionDefinition::haveVendor4Format() const {
-    return (true);
-}
-
-bool
-OptionDefinition::haveVendor6Format() const {
-    return (getType() == OPT_UINT32_TYPE);
-}
-
-bool
-OptionDefinition::haveVendorClass4Format() const {
-    return (haveType(OPT_RECORD_TYPE) &&
-            (record_fields_.size() == 2) &&
-            (record_fields_[0] == OPT_UINT32_TYPE) &&
-            (record_fields_[1] == OPT_BINARY_TYPE));
-}
-
-bool
-OptionDefinition::haveVendorClass6Format() const {
-    return (haveType(OPT_RECORD_TYPE) &&
-            (record_fields_.size() == 2) &&
-            (record_fields_[0] == OPT_UINT32_TYPE) &&
-            (record_fields_[1] == OPT_BINARY_TYPE));
-}
-
-bool
-OptionDefinition::haveStatusCodeFormat() const {
-    return (haveType(OPT_RECORD_TYPE) &&
-            (record_fields_.size() == 2) &&
-            (record_fields_[0] == OPT_UINT16_TYPE) &&
-            (record_fields_[1] == OPT_STRING_TYPE));
-}
-
-bool
-OptionDefinition::haveServiceScopeFormat() const {
-    return (haveType(OPT_RECORD_TYPE) &&
-            (record_fields_.size() == 2) &&
-            (record_fields_[0] == OPT_BOOLEAN_TYPE) &&
-            (record_fields_[1] == OPT_STRING_TYPE));
-}
-
-bool
-OptionDefinition::haveOpaqueDataTuplesFormat() const {
-    return (haveType(OPT_TUPLE_TYPE) && getArrayType());
-}
-
 bool
 OptionDefinition::haveCompressedFqdnListFormat() const {
     return (haveType(OPT_FQDN_TYPE) && getArrayType());
@@ -911,62 +807,79 @@ OptionDefinition::factorySpecialFormatOption(Option::Universe u,
                                              OptionBufferConstIter begin,
                                              OptionBufferConstIter end) const {
     if ((u == Option::V6) && haveSpace(DHCP6_OPTION_SPACE)) {
-        if ((getCode() == D6O_IA_NA || getCode() == D6O_IA_PD) &&
-            haveIA6Format()) {
-            // Return Option6IA instance for IA_PD and IA_NA option
-            // types only. We don't want to return Option6IA for other
-            // options that comprise 3 UINT32 data fields because
-            // Option6IA accessors' and modifiers' names are derived
-            // from the IA_NA and IA_PD options' field names: IAID,
-            // T1, T2. Using functions such as getIAID, getT1 etc. for
-            // options other than IA_NA and IA_PD would be bad practice
-            // and cause confusion.
+        switch (getCode()) {
+        case D6O_IA_NA:
+        case D6O_IA_PD:
+            // Record of 3 uint32, no array.
             return (factoryIA6(getCode(), begin, end));
 
-        } else if (getCode() == D6O_IAADDR && haveIAAddr6Format()) {
-            // Return Option6IAAddr option instance for the IAADDR
-            // option only for the same reasons as described in
-            // for IA_NA and IA_PD above.
+        case D6O_IAADDR:
+            // Record of an IPv6 address followed by 2 uint32, no array.
             return (factoryIAAddr6(getCode(), begin, end));
-        } else if (getCode() == D6O_IAPREFIX && haveIAPrefix6Format()) {
+
+        case D6O_IAPREFIX:
+            // Record of 2 uint32, one uint8 and an IPv6 address, no array.
             return (factoryIAPrefix6(getCode(), begin, end));
-        } else if (getCode() == D6O_CLIENT_FQDN && haveClientFqdnFormat()) {
-            // FQDN option requires special processing. Thus, there is
-            // a specialized class to handle it.
+
+        case D6O_CLIENT_FQDN:
+            // Record of one uint8 and one FQDN, no array.
             return (OptionPtr(new Option6ClientFqdn(begin, end)));
-        } else if (getCode() == D6O_VENDOR_OPTS && haveVendor6Format()) {
-            // Vendor-Specific Information (option code 17)
+
+        case D6O_VENDOR_OPTS:
+            // Type uint32.
+            // Vendor-Specific Information (option code 17).
             return (OptionPtr(new OptionVendor(Option::V6, begin, end)));
-        } else if (getCode() == D6O_VENDOR_CLASS && haveVendorClass6Format()) {
+
+        case D6O_VENDOR_CLASS:
+            // Record of one uint32 and one string.
             // Vendor Class (option code 16).
             return (OptionPtr(new OptionVendorClass(Option::V6, begin, end)));
-        } else if (getCode() == D6O_STATUS_CODE && haveStatusCodeFormat()) {
-            // Status Code (option code 13)
+
+        case D6O_STATUS_CODE:
+            // Record of one uint16 and one string.
+            // Status Code (option code 13).
             return (OptionPtr(new Option6StatusCode(begin, end)));
-        } else if (getCode() == D6O_BOOTFILE_PARAM && haveOpaqueDataTuplesFormat()) {
-            // Bootfile params (option code 60)
+
+        case D6O_BOOTFILE_PARAM:
+            // Array of tuples.
+            // Bootfile params (option code 60).
             return (factoryOpaqueDataTuples(Option::V6, getCode(), begin, end));
-        } else if ((getCode() == D6O_PD_EXCLUDE) && haveType(OPT_IPV6_PREFIX_TYPE)) {
-            // Prefix Exclude (option code 67)
+
+        case D6O_PD_EXCLUDE:
+            // Type IPv6 prefix.
+            // Prefix Exclude (option code 67),
             return (OptionPtr(new Option6PDExclude(begin, end)));
+
+        default:
+            break;
         }
     } else if ((u == Option::V4) && haveSpace(DHCP4_OPTION_SPACE)) {
-        if ((getCode() == DHO_SERVICE_SCOPE) && haveServiceScopeFormat()) {
+        switch (getCode()) {
+        case DHO_SERVICE_SCOPE:
+            // Record of a boolean and a string.
             return (OptionPtr(new Option4SlpServiceScope(begin, end)));
-        } else if ((getCode() == DHO_FQDN) && haveFqdn4Format()) {
+
+        case DHO_FQDN:
+            // Record of 3 uint8 and a FQDN, no array.
             return (OptionPtr(new Option4ClientFqdn(begin, end)));
-        } else if (haveCompressedFqdnListFormat()) {
-            return (factoryFqdnList(Option::V4, begin, end));
-        } else if ((getCode() == DHO_VIVCO_SUBOPTIONS) &&
-                   haveVendorClass4Format()) {
+
+        case DHO_VIVCO_SUBOPTIONS:
+            // Record of uint32 followed by binary.
             // V-I Vendor Class (option code 124).
             return (OptionPtr(new OptionVendorClass(Option::V4, begin, end)));
-        } else if (getCode() == DHO_VIVSO_SUBOPTIONS && haveVendor4Format()) {
+
+        case DHO_VIVSO_SUBOPTIONS:
+            // Type uint32.
             // Vendor-Specific Information (option code 125).
             return (OptionPtr(new OptionVendor(Option::V4, begin, end)));
 
+        default:
+            break;
         }
     }
+    if ((u == Option::V4) && haveCompressedFqdnListFormat()) {
+        return (factoryFqdnList(Option::V4, begin, end));
+    }
     return (OptionPtr());
 }
 
index 5660d1b9d80d853c552669e265aeb62f5714f746..cef6ad5ce757c04e33402ee8c86ed98a5bf7ee65 100644 (file)
@@ -419,96 +419,6 @@ public:
     /// @throw MalformedOptionDefinition option definition is invalid.
     void validate() const;
 
-    /// @brief Check if specified format is IA_NA option format.
-    ///
-    /// @return true if specified format is IA_NA option format.
-    bool haveIA6Format() const;
-
-    /// @brief Check if specified format is IAADDR option format.
-    ///
-    /// @return true if specified format is IAADDR option format.
-    bool haveIAAddr6Format() const;
-
-    /// @brief Check if specified format is IAPREFIX option format.
-    ///
-    /// @return true if specified format is IAPREFIX option format.
-    bool haveIAPrefix6Format() const;
-
-    /// @brief Check if specified format is OPTION_CLIENT_FQDN option format.
-    ///
-    /// @return true of specified format is OPTION_CLIENT_FQDN option format,
-    /// false otherwise.
-    bool haveClientFqdnFormat() const;
-
-    /// @brief Check if option has format of the DHCPv4 Client FQDN
-    /// %Option.
-    ///
-    /// The encoding of the domain-name carried by the FQDN option is
-    /// conditional and is specified in the flags field of the option.
-    /// The domain-name can be encoded in the ASCII format or canonical
-    /// wire format. The ASCII format is deprecated, therefore canonical
-    /// format is selected for the FQDN option definition and this function
-    /// returns true if the option definition comprises the domain-name
-    /// field encoded in canonical format.
-    ///
-    /// @return true if option has the format of DHCPv4 Client FQDN
-    /// %Option.
-    bool haveFqdn4Format() const;
-
-    /// @brief Check if the option has format of Vendor-Identifying Vendor
-    /// Specific Options.
-    ///
-    /// @return Always true.
-    /// @todo The Vendor-Identifying Vendor-Specific Option has a complex format
-    /// which we do not support here. Therefore it is not really possible to
-    /// check that the current definition is valid. We may need to add support
-    /// for such option format or simply do not check the format for certain
-    /// options, e.g. vendor options, IA_NA, IAADDR and always return objects
-    /// of the certain type.
-    bool haveVendor4Format() const;
-
-    /// @brief Check if option has a format of the Vendor-Specific Information
-    /// %Option.
-    ///
-    /// The Vendor-Specific Information %Option comprises 32-bit enterprise id
-    /// and the suboptions.
-    ///
-    /// @return true if option definition conforms to the format of the
-    /// Vendor-Specific Information %Option.
-    bool haveVendor6Format() const;
-
-    /// @brief Check if the option has format of DHCPv4 V-I Vendor Class option.
-    ///
-    /// @return true if the option has the format of DHCPv4 Vendor Class option.
-    bool haveVendorClass4Format() const;
-
-    /// @brief Check if the option has format of DHCPv6 Vendor Class option.
-    ///
-    /// @return true if option has the format of DHCPv6 Vendor Class option.
-    bool haveVendorClass6Format() const;
-
-    /// @brief Check if option has format of the SLP Service Scope
-    /// %Option.
-    ///
-    /// The scope list in the SLP Service Scope option is optional
-    /// (i.e., as the error message in the DHCPv6 Status code option).
-    ///
-    /// @return true if option has the format of SLP Service Scope %Option.
-    bool haveServiceScopeFormat() const;
-
-    /// @brief Check if the option has format of DHCPv6 Status Code option.
-    ///
-    /// @return true if option has the format of DHCPv6 Status code option.
-    bool haveStatusCodeFormat() const;
-
-    /// @brief Check if the option has format of OpaqueDataTuples type options.
-    ///
-    /// @return true if option has the format of OpaqueDataTuples type options.
-    bool haveOpaqueDataTuplesFormat() const;
-
-    /// @brief Check if the option has format of CompressedFqdnList options.
-    bool haveCompressedFqdnListFormat() const;
-
     /// @brief Option factory.
     ///
     /// This function creates an instance of DHCP option using
@@ -714,6 +624,9 @@ public:
 
 private:
 
+    /// @brief Check if the option has format of CompressedFqdnList options.
+    bool haveCompressedFqdnListFormat() const;
+
     /// @brief Factory function to create option with a compressed FQDN list.
     ///
     /// @param u universe (V4 or V6).
@@ -747,17 +660,6 @@ private:
                                          OptionBufferConstIter begin,
                                          OptionBufferConstIter end) const;
 
-    /// @brief Check if specified option format is a record with 3 fields
-    /// where first one is custom, and two others are uint32.
-    ///
-    /// This is a helper function for functions that detect IA_NA and IAAddr
-    /// option formats.
-    ///
-    /// @param first_type type of the first data field.
-    ///
-    /// @return true if actual option format matches expected format.
-    bool haveIAx6Format(const OptionDataType first_type) const;
-
     /// @brief Check if specified type matches option definition type.
     ///
     /// @return true if specified type matches option definition type.
@@ -939,10 +841,27 @@ typedef OptionDefContainer::nth_index<2>::type OptionDefContainerNameIndex;
 typedef std::pair<OptionDefContainerNameIndex::const_iterator,
                   OptionDefContainerNameIndex::const_iterator> OptionDefContainerNameRange;
 
+/// Base type of option definition space container.
 typedef OptionSpaceContainer<
     OptionDefContainer, OptionDefinitionPtr, std::string
-> OptionDefSpaceContainer;
+> BaseOptionDefSpaceContainer;
+
+/// @brief Class of option definition space container.
+class OptionDefSpaceContainer : public BaseOptionDefSpaceContainer {
+public:
 
+    /// @brief Adds a new option definition to the container.
+    ///
+    /// The option definition already contains the option space.
+    ///
+    /// @note: this method hides the parent one so it becomes hard to get
+    /// a mismatch between the option definition and the space container.
+    ///
+    /// @param def reference to the option definition being added.
+    void addItem(const OptionDefinitionPtr& def) {
+        BaseOptionDefSpaceContainer::addItem(def, def->getOptionSpaceName());
+    }
+};
 
 } // namespace isc::dhcp
 } // namespace isc
index 7f29b336bd78f922b5340d61ffbf4f064cc20ce6..51f5ea20ea609df4f696ab602aacdad37d9186f5 100644 (file)
@@ -187,7 +187,7 @@ public:
                                                                  code,
                                                                  space_name.str(),
                                                                  "string"));
-                defs.addItem(opt_def, space_name.str());
+                defs.addItem(opt_def);
             }
         }
     }
@@ -549,7 +549,7 @@ TEST_F(LibDhcpTest, unpackEmptyOption6) {
     // option definitions set when it detects that this definition is
     // not a standard definition.
     OptionDefSpaceContainer defs;
-    defs.addItem(opt_def, DHCP6_OPTION_SPACE);
+    defs.addItem(opt_def);
     LibDHCP::setRuntimeOptionDefs(defs);
     LibDHCP::commitRuntimeOptionDefs();
 
@@ -598,9 +598,9 @@ TEST_F(LibDhcpTest, unpackSubOptions6) {
 
     // Register created option definitions as runtime option definitions.
     OptionDefSpaceContainer defs;
-    ASSERT_NO_THROW(defs.addItem(opt_def, opt_def->getOptionSpaceName()));
-    ASSERT_NO_THROW(defs.addItem(opt_def2, opt_def2->getOptionSpaceName()));
-    ASSERT_NO_THROW(defs.addItem(opt_def3, opt_def3->getOptionSpaceName()));
+    ASSERT_NO_THROW(defs.addItem(opt_def));
+    ASSERT_NO_THROW(defs.addItem(opt_def2));
+    ASSERT_NO_THROW(defs.addItem(opt_def3));
     LibDHCP::setRuntimeOptionDefs(defs);
     LibDHCP::commitRuntimeOptionDefs();
 
@@ -921,7 +921,7 @@ TEST_F(LibDhcpTest, unpackEmptyOption4) {
     // option definitions set when it detects that this definition is
     // not a standard definition.
     OptionDefSpaceContainer defs;
-    defs.addItem(opt_def, DHCP4_OPTION_SPACE);
+    defs.addItem(opt_def);
     LibDHCP::setRuntimeOptionDefs(defs);
     LibDHCP::commitRuntimeOptionDefs();
 
@@ -972,9 +972,9 @@ TEST_F(LibDhcpTest, unpackSubOptions4) {
 
     // Register created option definitions as runtime option definitions.
     OptionDefSpaceContainer defs;
-    ASSERT_NO_THROW(defs.addItem(opt_def, opt_def->getOptionSpaceName()));
-    ASSERT_NO_THROW(defs.addItem(opt_def2, opt_def2->getOptionSpaceName()));
-    ASSERT_NO_THROW(defs.addItem(opt_def3, opt_def3->getOptionSpaceName()));
+    ASSERT_NO_THROW(defs.addItem(opt_def));
+    ASSERT_NO_THROW(defs.addItem(opt_def2));
+    ASSERT_NO_THROW(defs.addItem(opt_def3));
     LibDHCP::setRuntimeOptionDefs(defs);
     LibDHCP::commitRuntimeOptionDefs();
 
@@ -1045,10 +1045,10 @@ TEST_F(LibDhcpTest, unpackPadEnd) {
 
     // Register created option definitions as runtime option definitions.
     OptionDefSpaceContainer defs;
-    ASSERT_NO_THROW(defs.addItem(opt_def, DHCP4_OPTION_SPACE));
-    ASSERT_NO_THROW(defs.addItem(opt_def0, "my-space"));
-    ASSERT_NO_THROW(defs.addItem(opt_def255, "my-space"));
-    ASSERT_NO_THROW(defs.addItem(opt_def2, "my-space"));
+    ASSERT_NO_THROW(defs.addItem(opt_def));
+    ASSERT_NO_THROW(defs.addItem(opt_def0));
+    ASSERT_NO_THROW(defs.addItem(opt_def255));
+    ASSERT_NO_THROW(defs.addItem(opt_def2));
     LibDHCP::setRuntimeOptionDefs(defs);
     LibDHCP::commitRuntimeOptionDefs();
 
@@ -1129,8 +1129,8 @@ TEST_F(LibDhcpTest, option43Pad) {
 
     // Register created option definitions as runtime option definitions.
     OptionDefSpaceContainer defs;
-    ASSERT_NO_THROW(defs.addItem(opt_def1, space));
-    ASSERT_NO_THROW(defs.addItem(opt_def2, space));
+    ASSERT_NO_THROW(defs.addItem(opt_def1));
+    ASSERT_NO_THROW(defs.addItem(opt_def2));
     LibDHCP::setRuntimeOptionDefs(defs);
     LibDHCP::commitRuntimeOptionDefs();
 
@@ -1169,7 +1169,7 @@ TEST_F(LibDhcpTest, option43Pad) {
 
     // Create option definition for option 0 and register it.
     OptionDefinitionPtr opt_def0(new OptionDefinition("zero", 0, space, "uint8"));
-    ASSERT_NO_THROW(defs.addItem(opt_def0, space));
+    ASSERT_NO_THROW(defs.addItem(opt_def0));
     LibDHCP::clearRuntimeOptionDefs();
     LibDHCP::setRuntimeOptionDefs(defs);
     LibDHCP::commitRuntimeOptionDefs();
@@ -1227,7 +1227,7 @@ TEST_F(LibDhcpTest, option43End) {
 
     // Register created option definition as runtime option definitions.
     OptionDefSpaceContainer defs;
-    ASSERT_NO_THROW(defs.addItem(opt_def255, space));
+    ASSERT_NO_THROW(defs.addItem(opt_def255));
     LibDHCP::setRuntimeOptionDefs(defs);
     LibDHCP::commitRuntimeOptionDefs();
 
index a4447e031388db66abc7cd98d7cfedb6a839d16a..3540fe1f47a924326c7e7cb6d1dbb0032cb5bf29 100644 (file)
@@ -1410,53 +1410,6 @@ TEST_F(OptionDefinitionTest, integerInvalidType) {
     );
 }
 
-// The purpose of this test is to verify that helper methods
-// haveIA6Format and haveIAAddr6Format can be used to determine
-// IA_NA  and IAADDR option formats.
-TEST_F(OptionDefinitionTest, haveIAFormat) {
-    // IA_NA option format.
-    OptionDefinition opt_def1("OPTION_IA_NA", D6O_IA_NA, DHCP6_OPTION_SPACE,
-                              "record");
-    for (int i = 0; i < 3; ++i) {
-        opt_def1.addRecordField("uint32");
-    }
-    EXPECT_TRUE(opt_def1.haveIA6Format());
-    // Create non-matching format to check that this function does not
-    // return 'true' all the time.
-    OptionDefinition opt_def2("OPTION_IA_NA", D6O_IA_NA, DHCP6_OPTION_SPACE,
-                              "uint16");
-    EXPECT_FALSE(opt_def2.haveIA6Format());
-
-    // IAADDR option format.
-    OptionDefinition opt_def3("OPTION_IAADDR", D6O_IAADDR, DHCP6_OPTION_SPACE,
-                              "record");
-    opt_def3.addRecordField("ipv6-address");
-    opt_def3.addRecordField("uint32");
-    opt_def3.addRecordField("uint32");
-    EXPECT_TRUE(opt_def3.haveIAAddr6Format());
-    // Create non-matching format to check that this function does not
-    // return 'true' all the time.
-    OptionDefinition opt_def4("OPTION_IAADDR", D6O_IAADDR, DHCP6_OPTION_SPACE,
-                              "uint32", true);
-    EXPECT_FALSE(opt_def4.haveIAAddr6Format());
-}
-
-// This test verifies that haveClientFqdnFormat function recognizes that option
-// definition describes the format of DHCPv6 Client Fqdn Option Format.
-TEST_F(OptionDefinitionTest, haveClientFqdnFormat) {
-    OptionDefinition opt_def("OPTION_CLIENT_FQDN", D6O_CLIENT_FQDN,
-                             DHCP6_OPTION_SPACE, "record");
-    opt_def.addRecordField("uint8");
-    opt_def.addRecordField("fqdn");
-    EXPECT_TRUE(opt_def.haveClientFqdnFormat());
-
-    // Create option format which is not matching the Client FQDN option format
-    // to verify that tested function does dont always return true.
-    OptionDefinition opt_def_invalid("OPTION_CLIENT_FQDN", D6O_CLIENT_FQDN,
-                                     DHCP6_OPTION_SPACE, "uint8");
-    EXPECT_FALSE(opt_def_invalid.haveClientFqdnFormat());
-}
-
 // This test verifies that a definition of an option with a single IPv6
 // prefix can be created and used to create an instance of the option.
 TEST_F(OptionDefinitionTest, prefix) {
index b16d684ddece01007f83934e5a4d7d9e646101e9..fa9c774dfc709fd734a4998ddc95e67cfecd2906 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
 // Copyright (C) 2017 Deutsche Telekom AG.
 //
 // Authors: Andrei Pavel <andrei.pavel@qualitance.com>
@@ -120,12 +120,12 @@ GenericHostDataSourceBenchmark::addTestOptions(const HostPtr& host,
 
         // Add definitions for DHCPv4 non-standard options.
         defs.addItem(OptionDefinitionPtr(new OptionDefinition("vendor-encapsulated-1",
-                                         1, "uint32")), "vendor-encapsulated-options");
+                                         1, "vendor-encapsulated-options", "uint32")));
         defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-254", 254,
-                                         "ipv4-address", true)), DHCP4_OPTION_SPACE);
-        defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-1", 1, "empty")), "isc");
+                                         DHCP4_OPTION_SPACE, "ipv4-address", true)));
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-1", 1, "isc", "empty")));
         defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-2", 2,
-                                         "ipv4-address", true)), "isc");
+                                         "isc", "ipv4-address", true)));
     }
 
     if ((added_options == DHCP6_ONLY) || (added_options == DHCP4_AND_DHCP6)) {
@@ -148,10 +148,10 @@ GenericHostDataSourceBenchmark::addTestOptions(const HostPtr& host,
 
         // Add definitions for DHCPv6 non-standard options.
         defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-1024", 1024,
-                                         "ipv6-address", true)), DHCP6_OPTION_SPACE);
-        defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-1", 1, "empty")), "isc2");
+                                         DHCP6_OPTION_SPACE, "ipv6-address", true)));
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-1", 1, "isc2", "empty")));
         defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-2", 2,
-                                         "ipv6-address", true)), "isc2");
+                                         "isc2", "ipv6-address", true)));
     }
 
     // Register created "runtime" option definitions. They will be used by a
index 5b66495e90ead8d2bcdc0893bee696f955fe21d1..8b6288bac3f2b959935a2386f872b2180edc9f24 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2020 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
@@ -78,14 +78,19 @@ CfgOptionDef::equals(const CfgOptionDef& other) const {
 void
 CfgOptionDef::add(const OptionDefinitionPtr& def,
                   const std::string& option_space) {
-    if (!OptionSpace::validateName(option_space)) {
-        isc_throw(BadValue, "invalid option space name '"
-                  << option_space << "'");
-
     // Option definition being added must be a valid pointer.
-    } else if (!def) {
+    if (!def) {
         isc_throw(MalformedOptionDefinition,
                   "option definition must not be NULL");
+
+    } else if (option_space != def->getOptionSpaceName()) {
+        isc_throw(BadValue, "option space name '"
+                  << option_space << "' is not def one '"
+                  << def->getOptionSpaceName() << "'");
+    } else if (!OptionSpace::validateName(option_space)) {
+        isc_throw(BadValue, "invalid option space name '"
+                  << option_space << "'");
+
     // Must not duplicate an option definition.
     } else if (get(option_space, def->getCode())) {
         isc_throw(DuplicateOptionDefinition, "option definition with code '"
@@ -107,7 +112,7 @@ CfgOptionDef::add(const OptionDefinitionPtr& def,
                   << option_space << "'");
     }
     // Add the definition.
-    option_definitions_.addItem(def, option_space);
+    option_definitions_.addItem(def);
 }
 
 OptionDefContainerPtr
index ee470a351889dc0098fdc1669505c33525393596..a2c31ef374d71397bca5d981386cfd016b8377af 100644 (file)
@@ -136,18 +136,12 @@ GenericHostDataSourceTest::addTestOptions(const HostPtr& host,
         // Add definitions for DHCPv4 non-standard options.
         defs.addItem(OptionDefinitionPtr(new OptionDefinition(
                          "vendor-encapsulated-1", 1,
-                         "vendor-encapsulated-options", "uint32")),
-                     "vendor-encapsulated-options");
+                         "vendor-encapsulated-options", "uint32")));
         defs.addItem(OptionDefinitionPtr(new OptionDefinition(
                          "option-254", 254, DHCP4_OPTION_SPACE,
-                         "ipv4-address", true)),
-                     DHCP4_OPTION_SPACE);
-        defs.addItem(OptionDefinitionPtr(new OptionDefinition(
-                         "isc-1", 1, "isc", "empty")),
-                     "isc");
-        defs.addItem(OptionDefinitionPtr(new OptionDefinition(
-                         "isc-2", 2, "isc", "ipv4-address", true)),
-                     "isc");
+                         "ipv4-address", true)));
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-1", 1, "isc", "empty")));
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-2", 2, "isc", "ipv4-address", true)));
     }
 
     if ((added_options == DHCP6_ONLY) || (added_options == DHCP4_AND_DHCP6)) {
@@ -173,14 +167,9 @@ GenericHostDataSourceTest::addTestOptions(const HostPtr& host,
         // Add definitions for DHCPv6 non-standard options.
         defs.addItem(OptionDefinitionPtr(new OptionDefinition(
                          "option-1024", 1024, DHCP6_OPTION_SPACE,
-                         "ipv6-address", true)),
-                     DHCP6_OPTION_SPACE);
-        defs.addItem(OptionDefinitionPtr(new OptionDefinition(
-                         "option-1", 1, "isc2", "empty")),
-                     "isc2");
-        defs.addItem(OptionDefinitionPtr(new OptionDefinition(
-                         "option-2", 2, "isc2", "ipv6-address", true)),
-                     "isc2");
+                         "ipv6-address", true)));
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-1", 1, "isc2", "empty")));
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-2", 2, "isc2", "ipv6-address", true)));
     }
 
     // Register created "runtime" option definitions. They will be used by a