Commit 743182ec authored by Francis Dupont's avatar Francis Dupont
Browse files

[5073a] Main code finished

parent 6a4d93f0
......@@ -2858,9 +2858,9 @@ Dhcpv4Srv::deferredUnpack(Pkt4Ptr& query)
if (!def) {
def = LibDHCP::getRuntimeOptionDef(DHCP4_OPTION_SPACE, code);
}
// Option 43 has a last resort definition
if ((code == DHO_VENDOR_ENCAPSULATED_OPTIONS) && !def) {
def = LibDHCP::last_resort_option43_def;
// Finish by last resort definition
if (!def) {
def = LibDHCP::getLastResortOptionDef(DHCP4_OPTION_SPACE, code);
}
// If not defined go to the next option
if (!def) {
......
......@@ -3179,7 +3179,6 @@ TEST_F(Dhcp4ParserTest, domainSearchOption) {
" domain-search option"));
}
#if 0
// The goal of this test is to verify that the standard option can
// be configured to encapsulate multiple other options.
TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
......@@ -3430,7 +3429,7 @@ TEST_F(Dhcp4ParserTest, vendorOptionsCsv) {
CfgMgr::instance().getStagingCfg()->getCfgOption()->get(5678, 100);
ASSERT_FALSE(desc2.option_);
}
#endif
// Tests of the hooks libraries configuration. All tests have the pre-
// condition (checked in the test fixture's SetUp() method) that no hooks
......
This diff is collapsed.
......@@ -54,15 +54,15 @@ 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_;
// Null container.
const OptionDefContainerPtr null_option_def_container_(new OptionDefContainer());
// Option 43 definition.
OptionDefinitionPtr LibDHCP::last_resort_option43_def;
// Those two vendor classes are used for cable modems:
/// DOCSIS3.0 compatible cable modem
......@@ -86,6 +86,7 @@ LibDHCP::getOptionDefs(const std::string& space) {
initVendorOptsDocsis4();
initStdOptionDefs6();
initVendorOptsDocsis6();
initLastResortOptionDefs();
}
if (space == DHCP4_OPTION_SPACE) {
......@@ -260,6 +261,38 @@ LibDHCP::commitRuntimeOptionDefs() {
runtime_option_defs_.commit();
}
OptionDefinitionPtr
LibDHCP::getLastResortOptionDef(const std::string& space, const uint16_t code) {
OptionDefContainerPtr container = getLastResortOptionDefs(space);
const OptionDefContainerTypeIndex& index = container->get<1>();
const OptionDefContainerTypeRange& range = index.equal_range(code);
if (range.first != range.second) {
return (*range.first);
}
return (OptionDefinitionPtr());
}
OptionDefinitionPtr
LibDHCP::getLastResortOptionDef(const std::string& space, const std::string& name) {
OptionDefContainerPtr container = getLastResortOptionDefs(space);
const OptionDefContainerNameIndex& index = container->get<2>();
const OptionDefContainerNameRange& range = index.equal_range(name);
if (range.first != range.second) {
return (*range.first);
}
return (OptionDefinitionPtr());
}
OptionDefContainerPtr
LibDHCP::getLastResortOptionDefs(const std::string& space) {
if (space == DHCP4_OPTION_SPACE) {
return (lastresort_defs_);
}
return (null_option_def_container_);
}
bool
LibDHCP::deferOption(const std::string& space, const uint16_t code) {
return ((space == DHCP4_OPTION_SPACE) &&
......@@ -831,11 +864,6 @@ void
LibDHCP::initStdOptionDefs4() {
initOptionSpace(v4option_defs_, STANDARD_V4_OPTION_DEFINITIONS,
STANDARD_V4_OPTION_DEFINITIONS_SIZE);
last_resort_option43_def.reset(new OptionDefinition(
LAST_RESORT_OPTION43_DEFINITION.name,
LAST_RESORT_OPTION43_DEFINITION.code,
LAST_RESORT_OPTION43_DEFINITION.type,
LAST_RESORT_OPTION43_DEFINITION.array));
}
void
......@@ -854,6 +882,12 @@ LibDHCP::initStdOptionDefs6() {
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,
......
......@@ -113,6 +113,33 @@ public:
static OptionDefContainerPtr
getRuntimeOptionDefs(const std::string& space);
/// @brief Returns last resort option definition by space and option code.
///
/// @param space Option space name.
/// @param code Option code.
///
/// @return Pointer to option definition or NULL if it doesn't exist.
static OptionDefinitionPtr getLastResortOptionDef(const std::string& space,
const uint16_t code);
/// @brief Returns last resort option definition by space and option name.
///
/// @param space Option space name.
/// @param name Option name.
///
/// @return Pointer to option definition or NULL if it doesn't exist.
static OptionDefinitionPtr getLastResortOptionDef(const std::string& space,
const std::string& name);
/// @brief Returns last resort option definitions for specified option
/// space name.
///
/// @param space Option space name.
///
/// @return Pointer to the container holding option definitions or NULL.
static OptionDefContainerPtr
getLastResortOptionDefs(const std::string& space);
/// @brief Checks if an option unpacking has to be deferred.
///
/// DHCPv4 option 43 and 224-254 unpacking is done after classification.
......@@ -123,9 +150,6 @@ public:
/// @return True if option processing should be deferred.
static bool deferOption(const std::string& space, const uint16_t code);
/// @brief Last resort definition for DHCPv4 option 43
static OptionDefinitionPtr last_resort_option43_def;
/// @brief Factory function to create instance of option.
///
/// Factory method creates instance of specified option. The option
......@@ -357,6 +381,8 @@ private:
/// is incorrect. This is a programming error.
static void initStdOptionDefs6();
static void initLastResortOptionDefs();
static void initVendorOptsDocsis4();
static void initVendorOptsDocsis6();
......@@ -385,6 +411,9 @@ private:
/// 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_;
};
......
......@@ -216,12 +216,14 @@ const OptionDefParams STANDARD_V4_OPTION_DEFINITIONS[] = {
const int STANDARD_V4_OPTION_DEFINITIONS_SIZE =
sizeof(STANDARD_V4_OPTION_DEFINITIONS) / sizeof(STANDARD_V4_OPTION_DEFINITIONS[0]);
/// Last resort definition for option 43
const OptionDefParams LAST_RESORT_OPTION43_DEFINITION = {
"vendor-encapsulated-options", DHO_VENDOR_ENCAPSULATED_OPTIONS,
OPT_EMPTY_TYPE, false, NO_RECORD_DEF, "vendor-encapsulated-options-space"
/// Last resort definitions (only option 43 for now).
const OptionDefParams LAST_RESORT_V4_OPTION_DEFINITIONS[] = {
{ "vendor-encapsulated-options", DHO_VENDOR_ENCAPSULATED_OPTIONS,
OPT_EMPTY_TYPE, false, NO_RECORD_DEF, "vendor-encapsulated-options-space" }
};
const int LAST_RESORT_V4_OPTION_DEFINITIONS_SIZE = 1;
/// Start Definition of DHCPv6 options
// client-fqdn
......
......@@ -211,6 +211,9 @@ CfgOption::toElement() const {
if (!def) {
def = LibDHCP::getRuntimeOptionDef(*name, code);
}
if (!def) {
def = LibDHCP::getLastResortOptionDef(*name, code);
}
if (def) {
map->set("name", Element::create(def->getName()));
}
......
......@@ -215,6 +215,11 @@ OptionDataParser::findOptionDefinition(const std::string& option_space,
def = LibDHCP::getRuntimeOptionDef(option_space, search_key);
}
if (!def) {
// Finish by last resort definitions.
def = LibDHCP::getLastResortOptionDef(option_space, search_key);
}
return (def);
}
......
......@@ -89,6 +89,10 @@ EvalContext::convertOptionName(const std::string& option_name,
option_def = LibDHCP::getRuntimeOptionDef(global_space, option_name);
}
if (!option_def) {
option_def = LibDHCP::getLastResortOptionDef(global_space, option_name);
}
if (!option_def) {
error(loc, "option '" + option_name + "' is not defined");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment