Kea 2.7.5
|
Parser for option data value. More...
#include <option_data_parser.h>
Public Member Functions | |
OptionDataParser (const uint16_t address_family, CfgOptionDefPtr cfg_option_def=CfgOptionDefPtr()) | |
Constructor. | |
virtual | ~OptionDataParser () |
Virtual destructor. | |
std::pair< OptionDescriptor, std::string > | parse (isc::data::ConstElementPtr single_option) |
Parses ElementPtr containing option definition. | |
Public Member Functions inherited from isc::data::SimpleParser | |
uint16_t | getUint16 (isc::data::ConstElementPtr scope, const std::string &name) |
Returns a value converted to uint16_t. | |
uint32_t | getUint32 (isc::data::ConstElementPtr scope, const std::string &name) |
Returns a value converted to uint32_t. | |
uint8_t | getUint8 (ConstElementPtr scope, const std::string &name) |
Get an uint8_t value. | |
const isc::util::Triplet< uint32_t > | parseIntTriplet (const data::ConstElementPtr &scope, const std::string &name) |
Parses an integer triplet. | |
Protected Member Functions | |
std::pair< OptionDescriptor, std::string > | createOption (isc::data::ConstElementPtr option_data) |
Create option instance. | |
util::Optional< bool > | extractCancelled (data::ConstElementPtr parent) const |
Retrieves cancelled/never-send parameter as an optional value. | |
util::Optional< uint32_t > | extractCode (data::ConstElementPtr parent) const |
Retrieves parsed option code as an optional value. | |
util::Optional< bool > | extractCSVFormat (data::ConstElementPtr parent) const |
Retrieves csv-format parameter as an optional value. | |
util::Optional< std::string > | extractData (data::ConstElementPtr parent) const |
Retrieves option data as a string. | |
util::Optional< std::string > | extractName (data::ConstElementPtr parent) const |
Retrieves parsed option name as an optional value. | |
util::Optional< bool > | extractPersistent (data::ConstElementPtr parent) const |
Retrieves persistent/always-send parameter as an optional value. | |
std::string | extractSpace (data::ConstElementPtr parent) const |
Retrieves option space name. | |
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. | |
Protected Member Functions inherited from isc::data::SimpleParser | |
template<typename target_type , target_type convert> | |
target_type | getAndConvert (isc::data::ConstElementPtr scope, const std::string &name, const std::string &type_name) |
Returns a converted value from a scope. | |
template<typename int_type > | |
int_type | getIntType (isc::data::ConstElementPtr scope, const std::string &name) |
Returns an integer value with range checking from a scope. | |
Protected Attributes | |
uint16_t | address_family_ |
Address family: AF_INET or AF_INET6 . | |
CfgOptionDefPtr | cfg_option_def_ |
Config option definitions. | |
Additional Inherited Members | |
Static Public Member Functions inherited from isc::data::SimpleParser | |
static void | checkKeywords (const SimpleKeywords &keywords, isc::data::ConstElementPtr scope) |
Checks acceptable keywords with their expected type. | |
static void | checkRequired (const SimpleRequiredKeywords &required, isc::data::ConstElementPtr scope) |
Checks that all required keywords are present. | |
static size_t | deriveParams (isc::data::ConstElementPtr parent, isc::data::ElementPtr child, const ParamsList ¶ms) |
Derives (inherits) parameters from parent scope to a child. | |
static isc::asiolink::IOAddress | getAddress (const ConstElementPtr &scope, const std::string &name) |
Returns a IOAddress parameter from a scope. | |
static bool | getBoolean (isc::data::ConstElementPtr scope, const std::string &name) |
Returns a boolean parameter from a scope. | |
static double | getDouble (const ConstElementPtr &scope, const std::string &name) |
Returns a floating point parameter from a scope. | |
static int64_t | getInteger (isc::data::ConstElementPtr scope, const std::string &name) |
Returns an integer parameter from a scope. | |
static int64_t | getInteger (isc::data::ConstElementPtr scope, const std::string &name, int64_t min, int64_t max) |
Returns an integer parameter from a scope and checks its range. | |
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 size_t | setDefaults (isc::data::ElementPtr scope, const SimpleDefaults &default_values) |
Sets the default values. | |
static size_t | setListDefaults (isc::data::ConstElementPtr list, const SimpleDefaults &default_values) |
Sets the default values for all entries in a list. | |
Parser for option data value.
This parser parses configuration entries that specify value of a single option. These entries include option name, option code and data carried by the option. The option data can be specified in one of the two available formats: binary value represented as a string of hexadecimal digits or a list of comma separated values. The format being used is controlled by csv-format configuration parameter. When setting this value to True, the latter format is used. The subsequent values in the CSV format apply to relevant option data fields in the configured option. For example the configuration: "data" : "192.168.2.0, 56, hello world" can be used to set values for the option comprising IPv4 address, integer and string data field. Note that order matters. If the order of values does not match the order of data fields within an option the configuration will not be accepted. If parsing is successful then an instance of an option is created and added to the storage provided by the calling class.
Definition at line 42 of file option_data_parser.h.
isc::dhcp::OptionDataParser::OptionDataParser | ( | const uint16_t | address_family, |
CfgOptionDefPtr | cfg_option_def = CfgOptionDefPtr() ) |
Constructor.
address_family | Address family: AF_INET or AF_INET6 . |
cfg_option_def | Config option definitions (optional) |
Definition at line 32 of file option_data_parser.cc.
|
inlinevirtual |
Virtual destructor.
Definition at line 52 of file option_data_parser.h.
|
protected |
Create option instance.
Creates an instance of an option and adds it to the provided options storage. If the option data parsed by createOption function is invalid or insufficient this function emits an exception.
If the option data is given as a string containing a hexadecimal literal, then it is converted into binary format. These literals may contain upper and lower case digits. They may be octets delimited by colons or spaces (octets may be 1 or 2 digits) If not delimited octets then they must be a continuous string of digits with or without a "0x" prefix. Examples:
A leading zero is assumed for odd number of digits in an octet or continuous string.
option_data | An element holding data for a single option being created. |
DhcpConfigError | if parameters provided in the configuration are invalid. |
Definition at line 269 of file option_data_parser.cc.
References address_family_, isc::util::str::decodeFormattedHexString(), DHCP4_OPTION_SPACE, DHCP6_OPTION_SPACE, isc::dhcp::DHO_END, isc::dhcp::DHO_PAD, extractCancelled(), extractCode(), extractCSVFormat(), extractData(), extractName(), extractPersistent(), extractSpace(), findOptionDefinition(), isc::data::SimpleParser::getPosition(), isc_throw, isc::util::str::quotedStringToBinary(), isc::util::str::tokens(), isc::dhcp::Option::V4, isc::dhcp::Option::V6, and isc::Exception::what().
Referenced by parse().
|
protected |
Retrieves cancelled/never-send parameter as an optional value.
Definition at line 189 of file option_data_parser.cc.
References isc::data::SimpleParser::getBoolean().
Referenced by createOption().
|
protected |
Retrieves parsed option code as an optional value.
parent | A data element holding full option data configuration. |
DhcpConfigError | if option code is invalid. |
Definition at line 61 of file option_data_parser.cc.
References address_family_, isc::data::SimpleParser::getInteger(), isc::data::SimpleParser::getPosition(), and isc_throw.
Referenced by createOption().
|
protected |
Retrieves csv-format parameter as an optional value.
Definition at line 127 of file option_data_parser.cc.
References isc::data::SimpleParser::getBoolean().
Referenced by createOption().
|
protected |
Retrieves option data as a string.
parent | A data element holding full option data configuration. |
Definition at line 113 of file option_data_parser.cc.
References isc::data::SimpleParser::getString().
Referenced by createOption().
|
protected |
Retrieves parsed option name as an optional value.
parent | A data element holding full option data configuration. |
DhcpConfigError | if option name is invalid. |
Definition at line 94 of file option_data_parser.cc.
References isc::data::SimpleParser::getPosition(), isc::data::SimpleParser::getString(), and isc_throw.
Referenced by createOption().
|
protected |
Retrieves persistent/always-send parameter as an optional value.
Definition at line 176 of file option_data_parser.cc.
References isc::data::SimpleParser::getBoolean().
Referenced by createOption().
|
protected |
Retrieves option space name.
If option space name is not specified in the configuration the 'dhcp4' or 'dhcp6' option space name is returned, depending on the universe specified in the parser context.
parent | A data element holding full option data configuration. |
Definition at line 140 of file option_data_parser.cc.
References address_family_, DHCP4_OPTION_SPACE, DHCP6_OPTION_SPACE, isc::data::SimpleParser::getPosition(), isc::data::SimpleParser::getString(), isc_throw, isc::dhcp::OptionSpace::validateName(), and isc::Exception::what().
Referenced by createOption().
|
protectedvirtual |
Finds an option definition within an option space.
Given an option space and an option code, find the corresponding option definition within the option definition storage.
option_space | name of the parameter option space |
option_code | option code to be used to find the option definition, if the option name is unspecified. |
option_name | option name to be used to lookup the option definition. |
DhcpConfigError | if the option space requested is not valid for this server. |
Definition at line 202 of file option_data_parser.cc.
References address_family_, cfg_option_def_, isc::dhcp::LibDHCP::getLastResortOptionDef(), isc::dhcp::LibDHCP::getOptionDef(), isc::dhcp::LibDHCP::getRuntimeOptionDef(), isc::dhcp::LibDHCP::getVendorOptionDef(), isc::dhcp::LibDHCP::optionSpaceToVendorId(), isc::dhcp::Option::V4, and isc::dhcp::Option::V6.
Referenced by createOption().
std::pair< OptionDescriptor, std::string > isc::dhcp::OptionDataParser::parse | ( | isc::data::ConstElementPtr | single_option | ) |
Parses ElementPtr containing option definition.
This method parses ElementPtr containing the option definition, instantiates the option for it and then returns a pair of option descriptor (that holds that new option) and a string that specifies the option space.
Note: ElementPtr is expected to contain all fields. If your ElementPtr does not have them, please use isc::data::SimpleParser::setDefaults to fill the missing fields with default values.
single_option | ElementPtr containing option definition |
Definition at line 38 of file option_data_parser.cc.
References address_family_, isc::data::SimpleParser::checkKeywords(), createOption(), isc_throw, isc::dhcp::SimpleParser4::OPTION4_PARAMETERS, and isc::dhcp::SimpleParser6::OPTION6_PARAMETERS.
|
protected |
Address family: AF_INET
or AF_INET6
.
Definition at line 179 of file option_data_parser.h.
Referenced by createOption(), extractCode(), extractSpace(), findOptionDefinition(), and parse().
|
protected |
Config option definitions.
Definition at line 182 of file option_data_parser.h.
Referenced by findOptionDefinition().