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);
284 if (code_param.unspecified() && name_param.unspecified()) {
286 " 'code' or 'name' parameters to be specified"
287 <<
" (" << option_data->getPosition() <<
")");
299 if (!csv_format_param.unspecified() && csv_format_param) {
301 << space_param <<
"." << name_param
302 <<
"' having code '" << code_param
303 <<
"' does not exist ("
309 }
else if (!name_param.unspecified() && code_param.unspecified()) {
311 << space_param <<
"." << name_param
312 <<
"' does not exist ("
318 if (!name_param.unspecified() && (def->getName() != name_param.get())) {
320 << name_param <<
"' does not match the "
321 <<
"option definition: '" << space_param
322 <<
"." << def->getName() <<
"' ("
329 if (!cancel_param.unspecified() && cancel_param &&
330 data_param.unspecified()) {
333 code = def->getCode();
335 code =
static_cast<uint16_t
>(code_param);
338 bool persistent = !persist_param.unspecified() && persist_param;
340 return (make_pair(desc, space_param));
344 std::vector<uint8_t> binary;
345 std::vector<std::string> data_tokens;
349 if (def && (csv_format_param.unspecified() || csv_format_param)) {
366 if (binary.empty()) {
371 <<
" string of hexadecimal digits: " << data_param
386 OptionPtr option(
new Option(universe,
static_cast<uint16_t
>(code_param),
389 desc.option_ = option;
390 desc.persistent_ = !persist_param.unspecified() && persist_param;
391 desc.cancelled_ = !cancel_param.unspecified() && cancel_param;
396 bool use_csv = csv_format_param.unspecified() || csv_format_param;
398 def->optionFactory(universe, def->getCode(), data_tokens) :
399 def->optionFactory(universe, def->getCode(), binary);
400 desc.option_ = option;
401 desc.persistent_ = !persist_param.unspecified() && persist_param;
402 desc.cancelled_ = !cancel_param.unspecified() && cancel_param;
404 desc.formatted_value_ = data_param;
408 <<
" option definition (space: " << space_param
409 <<
", code: " << def->getCode() <<
"): "
418 if (desc.option_->getType() ==
DHO_PAD) {
420 <<
"reserved for PAD ("
421 << option_data->getPosition() <<
")");
422 }
else if (desc.option_->getType() ==
DHO_END) {
424 <<
"reserved for END ("
425 << option_data->getPosition() <<
")");
431 if (desc.option_->getType() == 0) {
433 <<
"reserved value ("
434 << option_data->getPosition() <<
")");
441 desc.setContext(user_context);
445 desc.client_classes_.fromElement(client_classes);
447 if (client_classes) {
448 for (
auto const& class_element : client_classes->listValue()) {
449 desc.addClientClass(class_element->stringValue());
455 return (make_pair(desc, space_param));
461 const uint16_t address_family,
463 : address_family_(address_family), cfg_option_def_(cfg_option_def) {
471 for (
auto const& data : option_data_list->listValue()) {
472 std::pair<OptionDescriptor, std::string> option =
473 option_parser->parse(data);
475 cfg->add(option.first, option.second);
482boost::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