// 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();
// 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();
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();
// 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);
// 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);
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;
}
}
-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());
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());
}
/// @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
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).
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.
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
code,
space_name.str(),
"string"));
- defs.addItem(opt_def, space_name.str());
+ defs.addItem(opt_def);
}
}
}
// 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();
// 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();
// 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();
// 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();
// 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();
// 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();
// 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();
// 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();
);
}
-// 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) {
-// 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>
// 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)) {
// 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
-// 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
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 '"
<< option_space << "'");
}
// Add the definition.
- option_definitions_.addItem(def, option_space);
+ option_definitions_.addItem(def);
}
OptionDefContainerPtr
// 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)) {
// 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