summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRazvan Becheriu <razvan@isc.org>2019-11-12 16:19:53 +0100
committerRazvan Becheriu <razvan@isc.org>2020-01-15 10:54:25 +0100
commit1b27c56f567be1bed2cf05e4aece5050aee54ea9 (patch)
tree320abda56beb26795efd330b67baa0b8882bc903
parent[#1075] Add missing line to Makefile (diff)
downloadkea-1b27c56f567be1bed2cf05e4aece5050aee54ea9.tar.xz
kea-1b27c56f567be1bed2cf05e4aece5050aee54ea9.zip
[#889,!591] refactor code to have only one initialization function for option definitions
-rw-r--r--src/lib/dhcp/docsis3_option_defs.h17
-rw-r--r--src/lib/dhcp/libdhcp++.cc206
-rw-r--r--src/lib/dhcp/libdhcp++.h60
-rw-r--r--src/lib/dhcp/option_definition.cc4
-rw-r--r--src/lib/dhcp/option_space.h22
-rw-r--r--src/lib/dhcp/std_option_defs.h15
-rw-r--r--src/lib/dhcp/tests/libdhcp++_unittest.cc19
-rw-r--r--src/lib/yang/adaptor_option.cc6
8 files changed, 131 insertions, 218 deletions
diff --git a/src/lib/dhcp/docsis3_option_defs.h b/src/lib/dhcp/docsis3_option_defs.h
index 879ffd56ec..98e5ff8d99 100644
--- a/src/lib/dhcp/docsis3_option_defs.h
+++ b/src/lib/dhcp/docsis3_option_defs.h
@@ -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
diff --git a/src/lib/dhcp/libdhcp++.cc b/src/lib/dhcp/libdhcp++.cc
index 6c37b77efd..ee917e9a81 100644
--- a/src/lib/dhcp/libdhcp++.cc
+++ b/src/lib/dhcp/libdhcp++.cc
@@ -15,12 +15,10 @@
#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>
@@ -28,35 +26,46 @@
#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();
}
diff --git a/src/lib/dhcp/libdhcp++.h b/src/lib/dhcp/libdhcp++.h
index 2d29f1474b..4eec6a0a3d 100644
--- a/src/lib/dhcp/libdhcp++.h
+++ b/src/lib/dhcp/libdhcp++.h
@@ -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_;
};
diff --git a/src/lib/dhcp/option_definition.cc b/src/lib/dhcp/option_definition.cc
index 3e1fa740af..13b4f5c07f 100644
--- a/src/lib/dhcp/option_definition.cc
+++ b/src/lib/dhcp/option_definition.cc
@@ -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
diff --git a/src/lib/dhcp/option_space.h b/src/lib/dhcp/option_space.h
index a19fb8910f..368184d4ee 100644
--- a/src/lib/dhcp/option_space.h
+++ b/src/lib/dhcp/option_space.h
@@ -13,13 +13,17 @@
#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
diff --git a/src/lib/dhcp/std_option_defs.h b/src/lib/dhcp/std_option_defs.h
index b1f1042446..495c5d7305 100644
--- a/src/lib/dhcp/std_option_defs.h
+++ b/src/lib/dhcp/std_option_defs.h
@@ -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
diff --git a/src/lib/dhcp/tests/libdhcp++_unittest.cc b/src/lib/dhcp/tests/libdhcp++_unittest.cc
index 58f1656d16..83598af6d9 100644
--- a/src/lib/dhcp/tests/libdhcp++_unittest.cc
+++ b/src/lib/dhcp/tests/libdhcp++_unittest.cc
@@ -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
diff --git a/src/lib/yang/adaptor_option.cc b/src/lib/yang/adaptor_option.cc
index a177a40905..c99d3d86b0 100644
--- a/src/lib/yang/adaptor_option.cc
+++ b/src/lib/yang/adaptor_option.cc
@@ -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);