20#include <boost/make_shared.hpp>
34 : address_family_(address_family), cfg_option_def_(cfg_option_def) {
37std::pair<OptionDescriptor, std::string>
48 std::pair<OptionDescriptor, std::string> opt =
createOption(single_option);
50 if (!opt.first.option_) {
53 "parser logic error: no option has been configured and"
54 " thus there is nothing to commit. Has build() been called?");
66 }
catch (
const std::exception&) {
69 return (Optional<uint32_t>());
73 code > std::numeric_limits<uint8_t>::max()) {
75 <<
"', it must not be greater than '"
76 <<
static_cast<int>(std::numeric_limits<uint8_t>::max())
81 code > std::numeric_limits<uint16_t>::max()) {
83 <<
"', it must not exceed '"
84 << std::numeric_limits<uint16_t>::max()
90 return (Optional<uint32_t>(code));
100 return (Optional<std::string>());
103 if (name.find(
" ") != std::string::npos) {
105 <<
"', space character is not allowed ("
109 return (Optional<std::string>(name));
120 return (Optional<std::string>());
123 return (Optional<std::string>(data));
128 bool csv_format =
true;
130 csv_format =
getBoolean(parent,
"csv-format");
133 return (Optional<bool>());
136 return (Optional<bool>(csv_format));
158 <<
"' option space name is reserved for DHCPv4 server");
163 <<
"' option space name is reserved for DHCPv6 server");
166 }
catch (
const std::exception& ex) {
177 bool persist =
false;
182 return (Optional<bool>());
185 return (Optional<bool>(persist));
195 return (Optional<bool>());
198 return (Optional<bool>(cancel));
203 const Optional<uint32_t>& option_code,
204 const Optional<std::string>& option_name)
const {
208 if (option_code.unspecified()) {
217 if (option_code.unspecified()) {
231 if (option_code.unspecified()) {
249 if (option_code.unspecified()) {
258 if (option_code.unspecified()) {
268std::pair<OptionDescriptor, std::string>
273 Optional<uint32_t> code_param =
extractCode(option_data);
274 Optional<std::string> name_param =
extractName(option_data);
278 Optional<std::string> data_param =
extractData(option_data);
283 if (code_param.unspecified() && name_param.unspecified()) {
285 " 'code' or 'name' parameters to be specified"
286 <<
" (" << option_data->getPosition() <<
")");
298 if (!csv_format_param.unspecified() && csv_format_param) {
300 << space_param <<
"." << name_param
301 <<
"' having code '" << code_param
302 <<
"' does not exist ("
308 }
else if (!name_param.unspecified() && code_param.unspecified()) {
310 << space_param <<
"." << name_param
311 <<
"' does not exist ("
317 if (!name_param.unspecified() && (def->getName() != name_param.get())) {
319 << name_param <<
"' does not match the "
320 <<
"option definition: '" << space_param
321 <<
"." << def->getName() <<
"' ("
328 if (!cancel_param.unspecified() && cancel_param &&
329 data_param.unspecified()) {
332 code = def->getCode();
334 code =
static_cast<uint16_t
>(code_param);
337 bool persistent = !persist_param.unspecified() && persist_param;
339 return (make_pair(desc, space_param));
343 std::vector<uint8_t> binary;
344 std::vector<std::string> data_tokens;
348 if (def && (csv_format_param.unspecified() || csv_format_param)) {
365 if (binary.empty()) {
370 <<
" string of hexadecimal digits: " << data_param
385 OptionPtr option(
new Option(universe,
static_cast<uint16_t
>(code_param),
388 desc.option_ = option;
389 desc.persistent_ = !persist_param.unspecified() && persist_param;
390 desc.cancelled_ = !cancel_param.unspecified() && cancel_param;
395 bool use_csv = csv_format_param.unspecified() || csv_format_param;
397 def->optionFactory(universe, def->getCode(), data_tokens) :
398 def->optionFactory(universe, def->getCode(), binary);
399 desc.option_ = option;
400 desc.persistent_ = !persist_param.unspecified() && persist_param;
401 desc.cancelled_ = !cancel_param.unspecified() && cancel_param;
403 desc.formatted_value_ = data_param;
407 <<
" option definition (space: " << space_param
408 <<
", code: " << def->getCode() <<
"): "
417 if (desc.option_->getType() ==
DHO_PAD) {
419 <<
"reserved for PAD ("
420 << option_data->getPosition() <<
")");
421 }
else if (desc.option_->getType() ==
DHO_END) {
423 <<
"reserved for END ("
424 << option_data->getPosition() <<
")");
430 if (desc.option_->getType() == 0) {
432 <<
"reserved value ("
433 << option_data->getPosition() <<
")");
440 desc.setContext(user_context);
444 return (make_pair(desc, space_param));
450 const uint16_t address_family,
452 : address_family_(address_family), cfg_option_def_(cfg_option_def) {
460 for (
auto const& data : option_data_list->listValue()) {
461 std::pair<OptionDescriptor, std::string> option =
462 option_parser->parse(data);
464 cfg->add(option.first, option.second);
471boost::shared_ptr<OptionDataParser>
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a function is called in a prohibited way.
static void checkKeywords(const SimpleKeywords &keywords, isc::data::ConstElementPtr scope)
Checks acceptable keywords with their expected type.
static const data::Element::Position & getPosition(const std::string &name, const data::ConstElementPtr parent)
Utility method that returns position of an element.
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
static bool getBoolean(isc::data::ConstElementPtr scope, const std::string &name)
Returns a boolean parameter from a scope.
static int64_t getInteger(isc::data::ConstElementPtr scope, const std::string &name)
Returns an integer parameter from a scope.
To be removed. Please use ConfigError instead.
static OptionDefinitionPtr getOptionDef(const std::string &space, const uint16_t code)
Return the first option definition matching a particular option code.
static OptionDefinitionPtr getVendorOptionDef(const Option::Universe u, const uint32_t vendor_id, const uint16_t code)
Returns vendor option definition for a given vendor-id and code.
static uint32_t optionSpaceToVendorId(const std::string &option_space)
Converts option space name to vendor id.
static OptionDefinitionPtr getRuntimeOptionDef(const std::string &space, const uint16_t code)
Returns runtime (non-standard) option definition by space and option code.
static OptionDefinitionPtr getLastResortOptionDef(const std::string &space, const uint16_t code)
Returns last resort option definition by space and option code.
CfgOptionDefPtr cfg_option_def_
Config option definitions.
virtual boost::shared_ptr< OptionDataParser > createOptionDataParser() const
Returns an instance of the OptionDataListParser to be used in parsing options.
void parse(const CfgOptionPtr &cfg, isc::data::ConstElementPtr option_data_list, bool encapsulate=true)
Parses a list of options, instantiates them and stores in cfg.
OptionDataListParser(const uint16_t address_family, CfgOptionDefPtr cfg_option_def=CfgOptionDefPtr())
Constructor.
uint16_t address_family_
Address family: AF_INET or AF_INET6.
util::Optional< std::string > extractData(data::ConstElementPtr parent) const
Retrieves option data as a string.
std::pair< OptionDescriptor, std::string > parse(isc::data::ConstElementPtr single_option)
Parses ElementPtr containing option definition.
uint16_t address_family_
Address family: AF_INET or AF_INET6.
std::string extractSpace(data::ConstElementPtr parent) const
Retrieves option space name.
util::Optional< bool > extractPersistent(data::ConstElementPtr parent) const
Retrieves persistent/always-send parameter as an optional value.
std::pair< OptionDescriptor, std::string > createOption(isc::data::ConstElementPtr option_data)
Create option instance.
util::Optional< bool > extractCSVFormat(data::ConstElementPtr parent) const
Retrieves csv-format parameter as an optional value.
util::Optional< uint32_t > extractCode(data::ConstElementPtr parent) const
Retrieves parsed option code as an optional value.
virtual OptionDefinitionPtr findOptionDefinition(const std::string &option_space, const util::Optional< uint32_t > &option_code, const util::Optional< std::string > &option_name) const
Finds an option definition within an option space.
CfgOptionDefPtr cfg_option_def_
Config option definitions.
util::Optional< std::string > extractName(data::ConstElementPtr parent) const
Retrieves parsed option name as an optional value.
util::Optional< bool > extractCancelled(data::ConstElementPtr parent) const
Retrieves cancelled/never-send parameter as an optional value.
OptionDataParser(const uint16_t address_family, CfgOptionDefPtr cfg_option_def=CfgOptionDefPtr())
Constructor.
static bool validateName(const std::string &name)
Checks that the provided option space name is valid.
Universe
defines option universe DHCPv4 or DHCPv6
static const isc::data::SimpleKeywords OPTION4_PARAMETERS
This table defines all option parameters.
static const isc::data::SimpleKeywords OPTION6_PARAMETERS
This table defines all option parameters.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
boost::shared_ptr< Option > OptionPtr
void decodeFormattedHexString(const string &hex_string, vector< uint8_t > &binary)
Converts a formatted string of hexadecimal digits into a vector.
vector< string > tokens(const string &text, const string &delim, bool escape)
Split string into tokens.
vector< uint8_t > quotedStringToBinary(const string "ed_string)
Converts a string in quotes into vector.
Defines the logger used by the top-level component of kea-lfc.
#define DHCP4_OPTION_SPACE
global std option spaces
#define DHCP6_OPTION_SPACE