]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#889,!591] refactor code to have only one initialization function for option definitions
authorRazvan Becheriu <razvan@isc.org>
Tue, 12 Nov 2019 15:19:53 +0000 (17:19 +0200)
committerRazvan Becheriu <razvan@isc.org>
Tue, 12 Nov 2019 15:19:53 +0000 (17:19 +0200)
src/lib/dhcp/docsis3_option_defs.h
src/lib/dhcp/libdhcp++.cc
src/lib/dhcp/libdhcp++.h
src/lib/dhcp/option_definition.cc
src/lib/dhcp/option_space.h
src/lib/dhcp/std_option_defs.h
src/lib/dhcp/tests/libdhcp++_unittest.cc
src/lib/yang/adaptor_option.cc

index 879ffd56eccd5da9c5f75ddbaf35ba794dd433aa..98e5ff8d991696093e4dddc58205e7c31d3edf75 100644 (file)
@@ -19,13 +19,15 @@ namespace dhcp {
 #define DOCSIS3_V4_TFTP_SERVERS 2
 
 /// @brief Definitions of standard DHCPv4 options.
-const OptionDefParams DOCSIS3_V4_DEFS[] = {
+const OptionDefParams DOCSIS3_V4_OPTION_DEFINITIONS[] = {
     { "oro", DOCSIS3_V4_ORO, OPT_UINT8_TYPE, true, NO_RECORD_DEF, "" },
     { "tftp-servers", DOCSIS3_V4_TFTP_SERVERS, OPT_IPV4_ADDRESS_TYPE, true, NO_RECORD_DEF, "" }
 };
 
 /// Number of option definitions defined.
-const int DOCSIS3_V4_DEFS_SIZE  = sizeof(DOCSIS3_V4_DEFS) / sizeof(OptionDefParams);
+const int DOCSIS3_V4_OPTION_DEFINITIONS_SIZE =
+    sizeof(DOCSIS3_V4_OPTION_DEFINITIONS) /
+    sizeof(DOCSIS3_V4_OPTION_DEFINITIONS[0]);
 
 /// @todo define remaining docsis3 v6 codes
 #define DOCSIS3_V6_ORO 1
@@ -43,7 +45,7 @@ const int DOCSIS3_V4_DEFS_SIZE  = sizeof(DOCSIS3_V4_DEFS) / sizeof(OptionDefPara
 #define DOCSIS3_V6_CMTS_CM_MAC 1026
 
 /// @brief Definitions of standard DHCPv6 options.
-const OptionDefParams DOCSIS3_V6_DEFS[] = {
+const OptionDefParams DOCSIS3_V6_OPTION_DEFINITIONS[] = {
     { "oro",            DOCSIS3_V6_ORO, OPT_UINT16_TYPE, true, NO_RECORD_DEF, "" },
     { "device-type",    DOCSIS3_V6_DEVICE_TYPE, OPT_STRING_TYPE, false, NO_RECORD_DEF, "" },
     { "vendor-type",    DOCSIS3_V6_VENDOR_NAME, OPT_STRING_TYPE, false, NO_RECORD_DEF, "" },
@@ -58,14 +60,15 @@ const OptionDefParams DOCSIS3_V6_DEFS[] = {
 };
 
 /// Number of option definitions defined.
-const int DOCSIS3_V6_DEFS_SIZE =
-    sizeof(DOCSIS3_V6_DEFS) / sizeof(DOCSIS3_V6_DEFS[0]);
+const int DOCSIS3_V6_OPTION_DEFINITIONS_SIZE =
+    sizeof(DOCSIS3_V6_OPTION_DEFINITIONS) /
+    sizeof(DOCSIS3_V6_OPTION_DEFINITIONS[0]);
 
 /// The class as specified in vendor-class option by the devices
 extern const char* DOCSIS3_CLASS_EROUTER;
 extern const char* DOCSIS3_CLASS_MODEM;
 
-}; // isc::dhcp namespace
-}; // isc namespace
+}  // namespace dhcp
+}  // namespace isc
 
 #endif // DOCSIS3_OPTION_DEFS_H
index 6c37b77efdb605d0672d12872c8cdbe1be627da1..ee917e9a8113e7eef389369e1eabacf7bbf7f8ce 100644 (file)
 #include <dhcp/option6_iaaddr.h>
 #include <dhcp/option_definition.h>
 #include <dhcp/option_int_array.h>
-#include <dhcp/option_space.h>
 #include <dhcp/std_option_defs.h>
 #include <dhcp/docsis3_option_defs.h>
 #include <exceptions/exceptions.h>
 #include <util/buffer.h>
-#include <dhcp/option_definition.h>
 
 #include <boost/lexical_cast.hpp>
 #include <boost/shared_array.hpp>
 
 #include <limits>
 #include <list>
+#include <mutex>
 
 using namespace std;
 using namespace isc::dhcp;
 using namespace isc::util;
 
+namespace isc {
+namespace dhcp {
+
+namespace {
+
+const OptionDefParamsEncapsulation OPTION_DEF_PARAMS[] = {
+    { STANDARD_V4_OPTION_DEFINITIONS,       STANDARD_V4_OPTION_DEFINITIONS_SIZE,     DHCP4_OPTION_SPACE          },
+    { STANDARD_V6_OPTION_DEFINITIONS,       STANDARD_V6_OPTION_DEFINITIONS_SIZE,     DHCP6_OPTION_SPACE          },
+    { DOCSIS3_V4_OPTION_DEFINITIONS,        DOCSIS3_V4_OPTION_DEFINITIONS_SIZE,      DOCSIS3_V4_OPTION_SPACE     },
+    { DOCSIS3_V6_OPTION_DEFINITIONS,        DOCSIS3_V6_OPTION_DEFINITIONS_SIZE,      DOCSIS3_V6_OPTION_SPACE     },
+    { ISC_V6_OPTION_DEFINITIONS,            ISC_V6_OPTION_DEFINITIONS_SIZE,          ISC_V6_OPTION_SPACE         },
+    { MAPE_V6_OPTION_DEFINITIONS,           MAPE_V6_OPTION_DEFINITIONS_SIZE,         MAPE_V6_OPTION_SPACE        },
+    { MAPT_V6_OPTION_DEFINITIONS,           MAPT_V6_OPTION_DEFINITIONS_SIZE,         MAPT_V6_OPTION_SPACE        },
+    { LW_V6_OPTION_DEFINITIONS,             LW_V6_OPTION_DEFINITIONS_SIZE,           LW_V6_OPTION_SPACE          },
+    { V4V6_RULE_OPTION_DEFINITIONS,         V4V6_RULE_OPTION_DEFINITIONS_SIZE,       V4V6_RULE_OPTION_SPACE      },
+    { V4V6_BIND_OPTION_DEFINITIONS,         V4V6_BIND_OPTION_DEFINITIONS_SIZE,       V4V6_BIND_OPTION_SPACE      },
+    { LAST_RESORT_V4_OPTION_DEFINITIONS,    LAST_RESORT_V4_OPTION_DEFINITIONS_SIZE,  LAST_RESORT_V4_OPTION_SPACE },
+    { NULL,                                 0,                                       ""                          }
+};
+
+}  // namespace
+
+}  // namespace dhcp
+}  // namespace isc
+
 // static array with factories for options
 std::map<unsigned short, Option::Factory*> LibDHCP::v4factories_;
 
 // static array with factories for options
 std::map<unsigned short, Option::Factory*> LibDHCP::v6factories_;
 
-// Static container with DHCPv4 option definitions.
-OptionDefContainerPtr LibDHCP::v4option_defs_(new OptionDefContainer());
-
-// Static container with DHCPv6 option definitions.
-OptionDefContainerPtr LibDHCP::v6option_defs_(new OptionDefContainer());
-
 // Static container with option definitions grouped by option space.
 OptionDefContainers LibDHCP::option_defs_;
 
-// Static container with vendor option definitions for DHCPv4.
-VendorOptionDefContainers LibDHCP::vendor4_defs_;
-
-// Static container with vendor option definitions for DHCPv6.
-VendorOptionDefContainers LibDHCP::vendor6_defs_;
-
-// Static container with last resort option definitions for DHCPv4.
-OptionDefContainerPtr LibDHCP::lastresort_defs_(new OptionDefContainer());
-
 // Static container with option definitions created in runtime.
 StagedValue<OptionDefSpaceContainer> LibDHCP::runtime_option_defs_;
 
@@ -79,21 +88,12 @@ void initOptionSpace(OptionDefContainerPtr& defs,
 
 const OptionDefContainerPtr&
 LibDHCP::getOptionDefs(const std::string& space) {
+    static mutex local_mutex;
+    std::lock_guard<std::mutex> lock(local_mutex);
     // If any of the containers is not initialized, it means that we haven't
     // initialized option definitions at all.
-    if (v4option_defs_->empty()) {
-        initStdOptionDefs4();
-        initVendorOptsDocsis4();
-        initStdOptionDefs6();
-        initVendorOptsDocsis6();
-        initLastResortOptionDefs();
-    }
-
-    if (space == DHCP4_OPTION_SPACE) {
-        return (v4option_defs_);
-
-    } else if (space == DHCP6_OPTION_SPACE) {
-        return (v6option_defs_);
+    if (option_defs_.end() == option_defs_.find(space)) {
+        initOptionDefs(space);
     }
 
     OptionDefContainers::const_iterator container = option_defs_.find(space);
@@ -103,41 +103,20 @@ LibDHCP::getOptionDefs(const std::string& space) {
     return (null_option_def_container_);
 }
 
-const OptionDefContainerPtr&
-LibDHCP::getVendorOption4Defs(const uint32_t vendor_id) {
-
-    if (vendor_id == VENDOR_ID_CABLE_LABS &&
-        vendor4_defs_.find(VENDOR_ID_CABLE_LABS) == vendor4_defs_.end()) {
-        initVendorOptsDocsis4();
-    }
-
-    VendorOptionDefContainers::const_iterator def = vendor4_defs_.find(vendor_id);
-    if (def == vendor4_defs_.end()) {
-        // No such vendor-id space
-        return (null_option_def_container_);
-    }
-    return (def->second);
-}
-
-const OptionDefContainerPtr&
-LibDHCP::getVendorOption6Defs(const uint32_t vendor_id) {
-
-    if (vendor_id == VENDOR_ID_CABLE_LABS &&
-        vendor6_defs_.find(VENDOR_ID_CABLE_LABS) == vendor6_defs_.end()) {
-        initVendorOptsDocsis6();
-    }
-
-    if (vendor_id == ENTERPRISE_ID_ISC &&
-        vendor6_defs_.find(ENTERPRISE_ID_ISC) == vendor6_defs_.end()) {
-        initVendorOptsIsc6();
-    }
-
-    VendorOptionDefContainers::const_iterator def = vendor6_defs_.find(vendor_id);
-    if (def == vendor6_defs_.end()) {
-        // No such vendor-id space
-        return (null_option_def_container_);
+const OptionDefContainerPtr
+LibDHCP::getVendorOptionDefs(const Option::Universe u, const uint32_t vendor_id) {
+    if (Option::V4 == u) {
+        if (VENDOR_ID_CABLE_LABS == vendor_id) {
+            return getOptionDefs(DOCSIS3_V4_OPTION_SPACE);
+        }
+    } else if (Option::V6 == u) {
+        if (VENDOR_ID_CABLE_LABS == vendor_id) {
+            return getOptionDefs(DOCSIS3_V6_OPTION_SPACE);
+        } else if (ENTERPRISE_ID_ISC == vendor_id) {
+            return getOptionDefs(ISC_V6_OPTION_SPACE);
+        }
     }
-    return (def->second);
+    return (null_option_def_container_);
 }
 
 OptionDefinitionPtr
@@ -165,14 +144,13 @@ LibDHCP::getOptionDef(const std::string& space, const std::string& name) {
 OptionDefinitionPtr
 LibDHCP::getVendorOptionDef(const Option::Universe u, const uint32_t vendor_id,
                             const std::string& name) {
-    OptionDefContainerPtr defs = (u == Option::V4 ? getVendorOption4Defs(vendor_id) :
-                                  getVendorOption6Defs(vendor_id));
+    const OptionDefContainerPtr option_defs_ptr = getVendorOptionDefs(u, vendor_id);
 
-    if (!defs) {
+    if (!option_defs_ptr) {
         return (OptionDefinitionPtr());
     }
 
-    const OptionDefContainerNameIndex& idx = defs->get<2>();
+    const OptionDefContainerNameIndex& idx = option_defs_ptr->get<2>();
     const OptionDefContainerNameRange& range = idx.equal_range(name);
     if (range.first != range.second) {
         return (*range.first);
@@ -183,17 +161,16 @@ LibDHCP::getVendorOptionDef(const Option::Universe u, const uint32_t vendor_id,
 OptionDefinitionPtr
 LibDHCP::getVendorOptionDef(const Option::Universe u, const uint32_t vendor_id,
                             const uint16_t code) {
-    OptionDefContainerPtr defs = (u == Option::V4 ? getVendorOption4Defs(vendor_id) :
-                                  getVendorOption6Defs(vendor_id));
+    const OptionDefContainerPtr option_defs_ptr = getVendorOptionDefs(u, vendor_id);
 
-    if (!defs) {
+    if (!option_defs_ptr) {
         // Weird universe or unknown vendor_id. We don't care. No definitions
         // one way or another
         // What is it anyway?
         return (OptionDefinitionPtr());
     }
 
-    const OptionDefContainerTypeIndex& idx = defs->get<1>();
+    const OptionDefContainerTypeIndex& idx = option_defs_ptr->get<1>();
     const OptionDefContainerTypeRange& range = idx.equal_range(code);
     if (range.first != range.second) {
         return (*range.first);
@@ -288,7 +265,7 @@ LibDHCP::getLastResortOptionDef(const std::string& space, const std::string& nam
 OptionDefContainerPtr
 LibDHCP::getLastResortOptionDefs(const std::string& space) {
     if (space == DHCP4_OPTION_SPACE) {
-        return (lastresort_defs_);
+        return getOptionDefs(LAST_RESORT_V4_OPTION_SPACE);
     }
     return (null_option_def_container_);
 }
@@ -622,14 +599,15 @@ size_t LibDHCP::unpackVendorOptions6(const uint32_t vendor_id,
     size_t length = buf.size();
 
     // Get the list of option definitions for this particular vendor-id
-    const OptionDefContainerPtr& option_defs = LibDHCP::getVendorOption6Defs(vendor_id);
+    const OptionDefContainerPtr option_defs_ptr =
+        LibDHCP::getVendorOptionDefs(Option::V6, vendor_id);
 
     // Get the search index #1. It allows to search for option definitions
     // using option code. If there's no such vendor-id space, we're out of luck
     // anyway.
     const OptionDefContainerTypeIndex* idx = NULL;
-    if (option_defs) {
-        idx = &(option_defs->get<1>());
+    if (option_defs_ptr) {
+        idx = &(option_defs_ptr->get<1>());
     }
 
     // The buffer being read comprises a set of options, each starting with
@@ -715,12 +693,13 @@ size_t LibDHCP::unpackVendorOptions4(const uint32_t vendor_id, const OptionBuffe
     size_t offset = 0;
 
     // Get the list of standard option definitions.
-    const OptionDefContainerPtr& option_defs = LibDHCP::getVendorOption4Defs(vendor_id);
+    const OptionDefContainerPtr option_defs_ptr =
+        LibDHCP::getVendorOptionDefs(Option::V4, vendor_id);
     // Get the search index #1. It allows to search for option definitions
     // using option code.
     const OptionDefContainerTypeIndex* idx = NULL;
-    if (option_defs) {
-        idx = &(option_defs->get<1>());
+    if (option_defs_ptr) {
+        idx = &(option_defs_ptr->get<1>());
     }
 
     // The buffer being read comprises a set of options, each starting with
@@ -807,7 +786,7 @@ size_t LibDHCP::unpackVendorOptions4(const uint32_t vendor_id, const OptionBuffe
             options.insert(std::make_pair(opt_type, opt));
             offset += opt_len;
 
-        } // end of data-chunk
+        }  // end of data-chunk
 
         break; // end of the vendor block.
     }
@@ -880,11 +859,10 @@ void LibDHCP::OptionFactoryRegister(Option::Universe u,
             isc_throw(BadValue, "There is already DHCPv6 factory registered "
                      << "for option type "  << opt_type);
         }
-        v6factories_[opt_type]=factory;
+        v6factories_[opt_type] = factory;
         return;
     }
-    case Option::V4:
-    {
+    case Option::V4: {
         // Option 0 is special (a one octet-long, equal 0) PAD option. It is never
         // instantiated as an Option object, but rather consumed during packet parsing.
         if (opt_type == 0) {
@@ -896,11 +874,11 @@ void LibDHCP::OptionFactoryRegister(Option::Universe u,
         if (opt_type > 254) {
             isc_throw(BadValue, "Too big option type for DHCPv4, only 0-254 allowed.");
         }
-        if (v4factories_.find(opt_type)!=v4factories_.end()) {
+        if (v4factories_.find(opt_type) != v4factories_.end()) {
             isc_throw(BadValue, "There is already DHCPv4 factory registered "
                      << "for option type "  << opt_type);
         }
-        v4factories_[opt_type]=factory;
+        v4factories_[opt_type] = factory;
         return;
     }
     default:
@@ -910,50 +888,18 @@ void LibDHCP::OptionFactoryRegister(Option::Universe u,
     return;
 }
 
-void
-LibDHCP::initStdOptionDefs4() {
-    initOptionSpace(v4option_defs_, STANDARD_V4_OPTION_DEFINITIONS,
-                    STANDARD_V4_OPTION_DEFINITIONS_SIZE);
-}
-
-void
-LibDHCP::initStdOptionDefs6() {
-    initOptionSpace(v6option_defs_, STANDARD_V6_OPTION_DEFINITIONS,
-                    STANDARD_V6_OPTION_DEFINITIONS_SIZE);
-    initOptionSpace(option_defs_[MAPE_V6_OPTION_SPACE], MAPE_V6_OPTION_DEFINITIONS,
-                    MAPE_V6_OPTION_DEFINITIONS_SIZE);
-    initOptionSpace(option_defs_[MAPT_V6_OPTION_SPACE], MAPT_V6_OPTION_DEFINITIONS,
-                    MAPT_V6_OPTION_DEFINITIONS_SIZE);
-    initOptionSpace(option_defs_[LW_V6_OPTION_SPACE], LW_V6_OPTION_DEFINITIONS,
-                    LW_V6_OPTION_DEFINITIONS_SIZE);
-    initOptionSpace(option_defs_[V4V6_RULE_OPTION_SPACE], V4V6_RULE_OPTION_DEFINITIONS,
-                    V4V6_RULE_OPTION_DEFINITIONS_SIZE);
-    initOptionSpace(option_defs_[V4V6_BIND_OPTION_SPACE], V4V6_BIND_OPTION_DEFINITIONS,
-                    V4V6_BIND_OPTION_DEFINITIONS_SIZE);
-}
-
-void
-LibDHCP::initLastResortOptionDefs() {
-    initOptionSpace(lastresort_defs_, LAST_RESORT_V4_OPTION_DEFINITIONS,
-                    LAST_RESORT_V4_OPTION_DEFINITIONS_SIZE);
-}
-
-void
-LibDHCP::initVendorOptsDocsis4() {
-    initOptionSpace(vendor4_defs_[VENDOR_ID_CABLE_LABS], DOCSIS3_V4_DEFS,
-                    DOCSIS3_V4_DEFS_SIZE);
-}
-
-void
-LibDHCP::initVendorOptsDocsis6() {
-    initOptionSpace(vendor6_defs_[VENDOR_ID_CABLE_LABS], DOCSIS3_V6_DEFS,
-                    DOCSIS3_V6_DEFS_SIZE);
-}
-
-void
-LibDHCP::initVendorOptsIsc6() {
-    initOptionSpace(vendor6_defs_[ENTERPRISE_ID_ISC], ISC_V6_OPTION_DEFINITIONS,
-                    ISC_V6_OPTION_DEFINITIONS_SIZE);
+void LibDHCP::initOptionDefs(const std::string &space) {
+    if (option_defs_.end() == option_defs_.find(space)) {
+        option_defs_[space] = OptionDefContainerPtr(new OptionDefContainer);
+        for (uint32_t i = 0; OPTION_DEF_PARAMS[i].optionDefParams; ++i) {
+            if (space == OPTION_DEF_PARAMS[i].space) {
+                initOptionSpace(option_defs_[space],
+                                OPTION_DEF_PARAMS[i].optionDefParams,
+                                OPTION_DEF_PARAMS[i].size);
+                break;
+            }
+        }
+    }
 }
 
 uint32_t
@@ -969,7 +915,6 @@ LibDHCP::optionSpaceToVendorId(const std::string& option_space) {
         std::string x = option_space.substr(7);
 
         check = boost::lexical_cast<int64_t>(x);
-
     } catch (const boost::bad_lexical_cast &) {
         return (0);
     }
@@ -990,7 +935,6 @@ void initOptionSpace(OptionDefContainerPtr& defs,
     // case.
     if (!defs) {
         defs.reset(new OptionDefContainer());
-
     } else {
         defs->clear();
     }
index 2d29f1474bae08a29fe460e270544d29c47dcbf9..4eec6a0a3d624aaf8d38994281eeb6c4e6427e6f 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <dhcp/option_definition.h>
 #include <dhcp/option_space_container.h>
+#include <dhcp/option_space.h>
 #include <dhcp/pkt4.h>
 #include <dhcp/pkt6.h>
 #include <util/buffer.h>
@@ -26,7 +27,7 @@ class LibDHCP {
 public:
 
     /// Map of factory functions.
-    typedef std::map<unsigned short, Option::Factory*>  FactoryMap;
+    typedef std::map<unsigned short, Option::Factory*> FactoryMap;
 
     /// @brief Returns collection of option definitions.
     ///
@@ -281,21 +282,15 @@ public:
                                       uint16_t type,
                                       Option::Factory * factory);
 
-    /// @brief Returns v4 option definitions for a given vendor
+    /// @brief Returns option definitions for given universe and vendor
     ///
+    /// @param u option universe
     /// @param vendor_id enterprise-id of a given vendor
-    /// @return a container for a given vendor (or NULL if no option
-    ///         definitions are defined)
-    static const OptionDefContainerPtr&
-    getVendorOption4Defs(const uint32_t vendor_id);
-
-    /// @brief Returns v6 option definitions for a given vendor
     ///
-    /// @param vendor_id enterprise-id of a given vendor
     /// @return a container for a given vendor (or NULL if no option
     ///         definitions are defined)
-    static const OptionDefContainerPtr&
-    getVendorOption6Defs(const uint32_t vendor_id);
+    static const OptionDefContainerPtr
+    getVendorOptionDefs(Option::Universe u, const uint32_t vendor_id);
 
     /// @brief Parses provided buffer as DHCPv6 vendor options and creates
     ///        Option objects.
@@ -371,37 +366,14 @@ public:
     static uint32_t optionSpaceToVendorId(const std::string& option_space);
 
 private:
-
-    /// Initialize standard DHCPv4 option definitions.
+    /// Initialize DHCP option definitions.
     ///
-    /// The method creates option definitions for all DHCPv4 options.
-    /// Currently this function is not implemented.
+    /// The method creates option definitions for all DHCP options.
     ///
     /// @throw std::bad alloc if system went out of memory.
     /// @throw MalformedOptionDefinition if any of the definitions
     /// are incorrect. This is programming error.
-    static void initStdOptionDefs4();
-
-    /// Initialize standard DHCPv6 option definitions.
-    ///
-    /// The method creates option definitions for all DHCPv6 options.
-    ///
-    /// @throw std::bad_alloc if system went out of memory.
-    /// @throw MalformedOptionDefinition if any of the definitions
-    /// is incorrect. This is a programming error.
-    static void initStdOptionDefs6();
-
-    /// Initialize last resort DHCPv4 option definitions.
-    static void initLastResortOptionDefs();
-
-    /// Initialize DOCSIS DHCPv4 option definitions.
-    static void initVendorOptsDocsis4();
-
-    /// Initialize DOCSIS DHCPv6 option definitions.
-    static void initVendorOptsDocsis6();
-
-    /// Initialize private DHCPv6 option definitions.
-    static void initVendorOptsIsc6();
+    static void initOptionDefs(const std::string& space);
 
     /// pointers to factories that produce DHCPv6 options
     static FactoryMap v4factories_;
@@ -409,24 +381,10 @@ private:
     /// pointers to factories that produce DHCPv6 options
     static FactoryMap v6factories_;
 
-    /// Container with DHCPv4 option definitions.
-    static OptionDefContainerPtr v4option_defs_;
-
-    /// Container with DHCPv6 option definitions.
-    static OptionDefContainerPtr v6option_defs_;
 
     /// Container that holds option definitions for various option spaces.
     static OptionDefContainers option_defs_;
 
-    /// Container for v4 vendor option definitions
-    static VendorOptionDefContainers vendor4_defs_;
-
-    /// Container for v6 vendor option definitions
-    static VendorOptionDefContainers vendor6_defs_;
-
-    /// Container with DHCPv4 last resort option definitions.
-    static OptionDefContainerPtr lastresort_defs_;
-
     /// Container for additional option definitions created in runtime.
     static util::StagedValue<OptionDefSpaceContainer> runtime_option_defs_;
 };
index 3e1fa740af1eab684b47aa22c63d091dc3e0dea8..13b4f5c07f56ab37308d7f677440934666397d53 100644 (file)
@@ -708,9 +708,9 @@ OptionDefinition::writeToBuffer(Option::Universe u,
             OptionDataTypeUtil::writePrefix(PrefixLen(len), address, buf);
 
             return;
-    }
+        }
     case OPT_PSID_TYPE:
-    {
+        {
         std::string txt = value;
 
         // first let's remove any whitespaces
index a19fb8910f0f46c9ca8b2fa06593ed79be54b5fc..368184d4eec0be92f621d147fd7dccf20aefffb7 100644 (file)
 #include <stdint.h>
 #include <string>
 
-#define DHCP4_OPTION_SPACE      "dhcp4"
-#define DHCP6_OPTION_SPACE      "dhcp6"
-#define MAPE_V6_OPTION_SPACE    "s46-cont-mape-options"
-#define MAPT_V6_OPTION_SPACE    "s46-cont-mapt-options"
-#define LW_V6_OPTION_SPACE      "s46-cont-lw-options"
-#define V4V6_RULE_OPTION_SPACE  "s46-rule-options"
-#define V4V6_BIND_OPTION_SPACE  "s46-v4v6bind-options"
+#define DHCP4_OPTION_SPACE          "dhcp4"
+#define DHCP6_OPTION_SPACE          "dhcp6"
+#define DOCSIS3_V4_OPTION_SPACE     "docsis3-v4"
+#define DOCSIS3_V6_OPTION_SPACE     "docsis3-v6"
+#define ISC_V6_OPTION_SPACE         "4o6"
+#define MAPE_V6_OPTION_SPACE        "s46-cont-mape-options"
+#define MAPT_V6_OPTION_SPACE        "s46-cont-mapt-options"
+#define LW_V6_OPTION_SPACE          "s46-cont-lw-options"
+#define V4V6_RULE_OPTION_SPACE      "s46-rule-options"
+#define V4V6_BIND_OPTION_SPACE      "s46-v4v6bind-options"
+#define LAST_RESORT_V4_OPTION_SPACE "last-resort-v4"
 
 namespace isc {
 namespace dhcp {
@@ -183,7 +187,7 @@ private:
     uint32_t enterprise_number_; ///< IANA assigned enterprise number.
 };
 
-} // namespace isc::dhcp
-} // namespace isc
+}  // namespace dhcp
+}  // namespace isc
 
 #endif // OPTION_SPACE_H
index b1f1042446e585c8025f0f9d87e32ae814fbb6b3..495c5d7305575ad1c3b35f0704a3283d2acdf6f2 100644 (file)
@@ -272,7 +272,8 @@ const OptionDefParams STANDARD_V4_OPTION_DEFINITIONS[] = {
 
 /// Number of option definitions defined.
 const int STANDARD_V4_OPTION_DEFINITIONS_SIZE =
-    sizeof(STANDARD_V4_OPTION_DEFINITIONS) / sizeof(STANDARD_V4_OPTION_DEFINITIONS[0]);
+    sizeof(STANDARD_V4_OPTION_DEFINITIONS) /
+    sizeof(STANDARD_V4_OPTION_DEFINITIONS[0]);
 
 /// Last resort definitions (only option 43 for now, these definitions
 /// are applied in deferred unpacking when none is found).
@@ -281,7 +282,9 @@ const OptionDefParams LAST_RESORT_V4_OPTION_DEFINITIONS[] = {
       OPT_EMPTY_TYPE, false, NO_RECORD_DEF, "vendor-encapsulated-options-space" }
 };
 
-const int LAST_RESORT_V4_OPTION_DEFINITIONS_SIZE = 1;
+const int LAST_RESORT_V4_OPTION_DEFINITIONS_SIZE =
+    sizeof(LAST_RESORT_V4_OPTION_DEFINITIONS) /
+    sizeof(LAST_RESORT_V4_OPTION_DEFINITIONS[0]);
 
 /// Start Definition of DHCPv6 options
 
@@ -425,7 +428,7 @@ const OptionDefParams STANDARD_V6_OPTION_DEFINITIONS[] = {
     { "v6-access-domain", D6O_V6_ACCESS_DOMAIN, OPT_FQDN_TYPE, false,
       NO_RECORD_DEF, "" },
     { "sip-ua-cs-list", D6O_SIP_UA_CS_LIST, OPT_FQDN_TYPE, true,
-      NO_RECORD_DEF, "" },      
+      NO_RECORD_DEF, "" },
     { "bootfile-url", D6O_BOOTFILE_URL, OPT_STRING_TYPE, false, NO_RECORD_DEF, "" },
     { "bootfile-param", D6O_BOOTFILE_PARAM, OPT_TUPLE_TYPE, true, NO_RECORD_DEF, "" },
     { "client-arch-type", D6O_CLIENT_ARCH_TYPE, OPT_UINT16_TYPE, true, NO_RECORD_DEF, "" },
@@ -544,9 +547,9 @@ const int V4V6_BIND_OPTION_DEFINITIONS_SIZE =
     sizeof(V4V6_BIND_OPTION_DEFINITIONS) /
     sizeof(V4V6_BIND_OPTION_DEFINITIONS[0]);
 
-} // unnamed namespace
+}  // namespace
 
-} // namespace dhcp
-} // namespace isc
+}  // namespace dhcp
+}  // namespace isc
 
 #endif // STD_OPTION_DEFS_H
index 58f1656d162c2169b5ca8b2ce48b6a3aa8a4d099..83598af6d9432e297d192ec6416a0478b4db685b 100644 (file)
@@ -24,7 +24,6 @@
 #include <dhcp/option_int.h>
 #include <dhcp/option_int_array.h>
 #include <dhcp/option_opaque_data_tuples.h>
-#include <dhcp/option_space.h>
 #include <dhcp/option_string.h>
 #include <dhcp/option_vendor.h>
 #include <dhcp/option_vendor_class.h>
@@ -437,7 +436,7 @@ TEST_F(LibDhcpTest, unpackOptions6) {
 
     EXPECT_NO_THROW ({
             LibDHCP::unpackOptions6(OptionBuffer(buf.begin(), buf.begin() + sizeof(v6packed)),
-                                    "dhcp6", options);
+                                    DHCP6_OPTION_SPACE, options);
     });
 
     EXPECT_EQ(options.size(), 6); // there should be 5 options
@@ -780,7 +779,7 @@ TEST_F(LibDhcpTest, unpackOptions4) {
     list<uint16_t> deferred;
 
     ASSERT_NO_THROW(
-        LibDHCP::unpackOptions4(v4packed, "dhcp4", options, deferred);
+        LibDHCP::unpackOptions4(v4packed, DHCP4_OPTION_SPACE, options, deferred);
     );
 
     isc::dhcp::OptionCollection::const_iterator x = options.find(12);
@@ -1917,8 +1916,8 @@ TEST_F(LibDhcpTest, getOptionDefByName4) {
 // This test checks if the definition of the DHCPv6 vendor option can
 // be searched by option name.
 TEST_F(LibDhcpTest, getVendorOptionDefByName6) {
-    const OptionDefContainerPtr& defs =
-        LibDHCP::getVendorOption6Defs(VENDOR_ID_CABLE_LABS);
+    const OptionDefContainerPtr defs =
+        LibDHCP::getVendorOptionDefs(Option::V6, VENDOR_ID_CABLE_LABS);
     ASSERT_TRUE(defs);
     for (OptionDefContainer::const_iterator def = defs->begin();
          def != defs->end(); ++def) {
@@ -1933,8 +1932,8 @@ TEST_F(LibDhcpTest, getVendorOptionDefByName6) {
 // This test checks if the definition of the DHCPv4 vendor option can
 // be searched by option name.
 TEST_F(LibDhcpTest, getVendorOptionDefByName4) {
-    const OptionDefContainerPtr& defs =
-        LibDHCP::getVendorOption4Defs(VENDOR_ID_CABLE_LABS);
+    const OptionDefContainerPtr defs =
+        LibDHCP::getVendorOptionDefs(Option::V4, VENDOR_ID_CABLE_LABS);
     ASSERT_TRUE(defs);
     for (OptionDefContainer::const_iterator def = defs->begin();
          def != defs->end(); ++def) {
@@ -2079,7 +2078,7 @@ TEST_F(LibDhcpTest, vendorClass6) {
     isc::util::encode::decodeHex(vendor_class_hex, bin);
 
     ASSERT_NO_THROW ({
-            LibDHCP::unpackOptions6(bin, "dhcp6", options);
+            LibDHCP::unpackOptions6(bin, DHCP6_OPTION_SPACE, options);
         });
 
     EXPECT_EQ(options.size(), 1); // There should be 1 option.
@@ -2198,7 +2197,7 @@ TEST_F(LibDhcpTest, sw46options) {
 
     OptionBuffer buf(mape_bin);
 
-    size_t parsed;
+    size_t parsed = 0;
 
     EXPECT_NO_THROW (parsed = LibDHCP::unpackOptions6(buf, "dhcp6", options));
     EXPECT_EQ(mape_bin.size(), parsed);
@@ -2257,4 +2256,4 @@ TEST_F(LibDhcpTest, sw46options) {
     EXPECT_EQ("type=00093, len=00004: 8 (uint8) len=6,psid=63 (psid)", portparam->toText());
 }
 
-} // end of anonymous space
+}  // namespace
index a177a40905d4e595c84bcbbe84e7c386d28a0fa6..c99d3d86b0bd5659bff0cda67a7022f3011a66f3 100644 (file)
@@ -83,12 +83,14 @@ AdaptorOption::initCodes(OptionCodes& codes, const string& space) {
         initCodesInternal(codes, space, LAST_RESORT_V4_OPTION_DEFINITIONS,
                           LAST_RESORT_V4_OPTION_DEFINITIONS_SIZE);
         initCodesInternal(codes, "vendor-4491",
-                          DOCSIS3_V4_DEFS, DOCSIS3_V4_DEFS_SIZE);
+                          DOCSIS3_V4_OPTION_DEFINITIONS,
+                          DOCSIS3_V4_OPTION_DEFINITIONS_SIZE);
     } else if (space == "dhcp6") {
         initCodesInternal(codes, space, STANDARD_V6_OPTION_DEFINITIONS,
                           STANDARD_V6_OPTION_DEFINITIONS_SIZE);
         initCodesInternal(codes, "vendor-4491",
-                          DOCSIS3_V6_DEFS, DOCSIS3_V6_DEFS_SIZE);
+                          DOCSIS3_V6_OPTION_DEFINITIONS,
+                          DOCSIS3_V6_OPTION_DEFINITIONS_SIZE);
         initCodesInternal(codes, MAPE_V6_OPTION_SPACE,
                           MAPE_V6_OPTION_DEFINITIONS,
                           MAPE_V6_OPTION_DEFINITIONS_SIZE);