Browse Source

[2315] Do not allow to add option definitions to dhcp4 and dhcp6 spaces.

Marcin Siodelski 12 years ago
parent
commit
c6e109f7d6
3 changed files with 22 additions and 1 deletions
  1. 4 0
      src/lib/dhcpsrv/cfgmgr.cc
  2. 2 1
      src/lib/dhcpsrv/cfgmgr.h
  3. 16 0
      src/lib/dhcpsrv/tests/cfgmgr_unittest.cc

+ 4 - 0
src/lib/dhcpsrv/cfgmgr.cc

@@ -34,6 +34,10 @@ CfgMgr::addOptionDef(const OptionDefinitionPtr& def,
     // This will be implemented when #2313 is merged.
     if (option_space.empty()) {
         isc_throw(BadValue, "option space name must not be empty");
+    } else if (option_space == "dhcp4" || option_space == "dhcp6") {
+        isc_throw(BadValue, "unable to override definition of option"
+                  << " in standard option space '" << option_space
+                  << "'.");
     } else if (!def) {
         isc_throw(MalformedOptionDefinition, "option definition must not be NULL");
     } else if (getOptionDef(option_space, def->getCode())) {

+ 2 - 1
src/lib/dhcpsrv/cfgmgr.h

@@ -86,7 +86,8 @@ public:
     /// option definition already exists.
     /// @throw isc::dhcp::MalformedOptionDefinition when the pointer to
     /// an option definition is NULL.
-    /// @throw isc::BadValue when the option space name is empty.
+    /// @throw isc::BadValue when the option space name is empty or
+    /// option space name is one of reserved names: dhcp4 or dhcp6.
     void addOptionDef(const OptionDefinitionPtr& def,
                       const std::string& option_space);
 

+ 16 - 0
src/lib/dhcpsrv/tests/cfgmgr_unittest.cc

@@ -156,6 +156,22 @@ TEST_F(CfgMgrTest, getOptionDef) {
     ASSERT_FALSE(def);
 }
 
+// This test verifies that the function that adds new option definition
+// throws exceptions when arguments are invalid.
+TEST_F(CfgMgrTest, addOptionDefNegative) {
+    CfgMgr& cfg_mgr = CfgMgr::instance();
+    OptionDefinitionPtr def(new OptionDefinition("option-foo", 100, "uint16"));
+
+    // Try reserved option space names.
+    ASSERT_THROW(cfg_mgr.addOptionDef(def, "dhcp4"), isc::BadValue);
+    ASSERT_THROW(cfg_mgr.addOptionDef(def, "dhcp6"), isc::BadValue);
+    // Try empty option space name.
+    ASSERT_THROW(cfg_mgr.addOptionDef(def, ""), isc::BadValue);
+    // Try NULL option definition.
+    ASSERT_THROW(cfg_mgr.addOptionDef(OptionDefinitionPtr(), "isc"),
+                 isc::dhcp::MalformedOptionDefinition);
+}
+
 // This test verifies if the configuration manager is able to hold and return
 // valid leases
 TEST_F(CfgMgrTest, subnet4) {