2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-10-05 13:26:03 +00:00

[3705] Address review comments.

This commit is contained in:
Marcin Siodelski
2015-03-17 10:14:46 +01:00
parent e09a9fe719
commit b55dd296af
18 changed files with 466 additions and 161 deletions

View File

@@ -41,6 +41,7 @@
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <limits>
#include <map>
#include <vector>
@@ -575,10 +576,14 @@ public:
ParserCollection subnets_;
};
/// @brief parser for list of RSOO options
/// @brief Parser for list of RSOO options
///
/// This parser handles Dhcp6/relay-supplied-options entry.
/// It contains a list of option codes.
/// This parser handles Dhcp6/relay-supplied-options entry. It contains a
/// list of RSOO-enabled options which should be sent back to the client.
///
/// The option on this list can be specified using an option code or option
/// name. Therefore, the values on the list should always be enclosed in
/// "quotes".
class RSOOListConfigParser : public DhcpConfigParser {
public:
@@ -603,34 +608,47 @@ public:
///
/// @param value pointer to the content of parsed values
virtual void build(isc::data::ConstElementPtr value) {
try {
BOOST_FOREACH(ConstElementPtr source_elem, value->listValue()) {
std::string option_str = source_elem->stringValue();
// This option can be either code (integer) or name. Let's try code first
int64_t code = 0;
try {
code = boost::lexical_cast<int64_t>(option_str);
// Protect against the negative value and too high value.
if (code < 0) {
isc_throw(BadValue, "invalid option code value specified '"
<< option_str << "', the option code must be a"
" non-negative value");
// By default, there's only one RSOO option defined: 65
// http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml
CfgMgr::instance().getStagingCfg()->getCfgOption()->clearRSOO();
CfgMgr::instance().getStagingCfg()->getCfgOption()->addRSOO(D6O_ERP_LOCAL_DOMAIN_NAME);
} else if (code > std::numeric_limits<uint16_t>::max()) {
isc_throw(BadValue, "invalid option code value specified '"
<< option_str << "', the option code must not be"
" greater than '" << std::numeric_limits<uint16_t>::max()
<< "'");
}
BOOST_FOREACH(ConstElementPtr source_elem, value->listValue()) {
std::string option_str = source_elem->stringValue();
// This option can be either code (integer) or name. Let's try code first
uint16_t code = 0;
try {
code = boost::lexical_cast<uint16_t>(option_str);
} catch (const boost::bad_lexical_cast &) {
// Oh well, it's not a number
}
if (!code) {
OptionDefinitionPtr def = LibDHCP::getOptionDef(Option::V6, option_str);
if (def) {
code = def->getCode();
} else {
isc_throw(BadValue, "Unable to convert '" << option_str
<< "' to option code while parsing allowed"
<< "relay-supplied-options");
} catch (const boost::bad_lexical_cast &) {
// Oh well, it's not a number
}
if (!code) {
OptionDefinitionPtr def = LibDHCP::getOptionDef(Option::V6, option_str);
if (def) {
code = def->getCode();
} else {
isc_throw(BadValue, "unable to find option code for the "
" specified option name '" << option_str << "'"
" while parsing the list of enabled"
" relay-supplied-options");
}
}
CfgMgr::instance().getStagingCfg()->getCfgRSOO()->enable(code);
}
CfgMgr::instance().getStagingCfg()->getCfgOption()->addRSOO(code);
} catch (const std::exception& ex) {
// Rethrow exception with the appended position of the parsed
// element.
isc_throw(DhcpConfigError, ex.what() << " (" << value->getPosition() << ")");
}
}