Kea  2.1.7-git
isc::dhcp::OptionDataParser Class Reference

Parser for option data value. More...

#include <option_data_parser.h>

+ Inheritance diagram for isc::dhcp::OptionDataParser:

Public Member Functions

 OptionDataParser (const uint16_t address_family, CfgOptionDefPtr cfg_option_def=CfgOptionDefPtr())
 Constructor. More...
 
virtual ~OptionDataParser ()
 Virtual destructor. More...
 
std::pair< OptionDescriptor, std::string > parse (isc::data::ConstElementPtr single_option)
 Parses ElementPtr containing option definition. More...
 
- 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. More...
 
uint32_t getUint32 (isc::data::ConstElementPtr scope, const std::string &name)
 Returns a value converted to uint32_t. More...
 
uint8_t getUint8 (ConstElementPtr scope, const std::string &name)
 Get an uint8_t value. More...
 
const isc::util::Triplet< uint32_t > parseIntTriplet (const data::ConstElementPtr &scope, const std::string &name)
 Parses an integer triplet. More...
 

Protected Member Functions

std::pair< OptionDescriptor, std::string > createOption (isc::data::ConstElementPtr option_data)
 Create option instance. More...
 
util::Optional< uint32_t > extractCode (data::ConstElementPtr parent) const
 Retrieves parsed option code as an optional value. More...
 
util::Optional< bool > extractCSVFormat (data::ConstElementPtr parent) const
 Retrieves csv-format parameter as an optional value. More...
 
std::string extractData (data::ConstElementPtr parent) const
 Retrieves option data as a string. More...
 
util::Optional< std::string > extractName (data::ConstElementPtr parent) const
 Retrieves parsed option name as an optional value. More...
 
util::Optional< bool > extractPersistent (data::ConstElementPtr parent) const
 Retrieves persistent/always-send parameter as an optional value. More...
 
std::string extractSpace (data::ConstElementPtr parent) const
 Retrieves option space name. More...
 
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. More...
 
- 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. More...
 
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. More...
 

Protected Attributes

uint16_t address_family_
 Address family: AF_INET or AF_INET6. More...
 
CfgOptionDefPtr cfg_option_def_
 Config option definitions. More...
 

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. More...
 
static void checkRequired (const SimpleRequiredKeywords &required, isc::data::ConstElementPtr scope)
 Checks that all required keywords are present. More...
 
static size_t deriveParams (isc::data::ConstElementPtr parent, isc::data::ElementPtr child, const ParamsList &params)
 Derives (inherits) parameters from parent scope to a child. More...
 
static isc::asiolink::IOAddress getAddress (const ConstElementPtr &scope, const std::string &name)
 Returns a IOAddress parameter from a scope. More...
 
static bool getBoolean (isc::data::ConstElementPtr scope, const std::string &name)
 Returns a boolean parameter from a scope. More...
 
static double getDouble (const ConstElementPtr &scope, const std::string &name)
 Returns a floating point parameter from a scope. More...
 
static int64_t getInteger (isc::data::ConstElementPtr scope, const std::string &name)
 Returns an integer parameter from a scope. More...
 
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. More...
 
static const data::Element::PositiongetPosition (const std::string &name, const data::ConstElementPtr parent)
 Utility method that returns position of an element. More...
 
static std::string getString (isc::data::ConstElementPtr scope, const std::string &name)
 Returns a string parameter from a scope. More...
 
static size_t setDefaults (isc::data::ElementPtr scope, const SimpleDefaults &default_values)
 Sets the default values. More...
 
static size_t setListDefaults (isc::data::ConstElementPtr list, const SimpleDefaults &default_values)
 Sets the default values for all entries in a list. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ OptionDataParser()

isc::dhcp::OptionDataParser::OptionDataParser ( const uint16_t  address_family,
CfgOptionDefPtr  cfg_option_def = CfgOptionDefPtr() 
)

Constructor.

Parameters
address_familyAddress family: AF_INET or AF_INET6.
cfg_option_defConfig option definitions (optional)

Definition at line 33 of file option_data_parser.cc.

◆ ~OptionDataParser()

virtual isc::dhcp::OptionDataParser::~OptionDataParser ( )
inlinevirtual

Virtual destructor.

Definition at line 52 of file option_data_parser.h.

References createOption(), extractCode(), extractCSVFormat(), extractData(), extractName(), extractPersistent(), extractSpace(), findOptionDefinition(), and parse().

+ Here is the call graph for this function:

Member Function Documentation

◆ createOption()

std::pair< OptionDescriptor, std::string > isc::dhcp::OptionDataParser::createOption ( isc::data::ConstElementPtr  option_data)
protected

Create option instance.

Creates an instance of an option and adds it to the provided options storage. If the option data parsed by build function are 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:

  1. ab:cd:ef - colon delimited
  2. ab cd ef - space delimited
  3. 0xabcdef - 0x prefixed (no delimiters)
  4. abcdef - no prefix or delimiters

A leading zero is assumed for odd number of digits in an octet or continuous string.

Parameters
option_dataAn element holding data for a single option being created.
Returns
created option descriptor
Exceptions
DhcpConfigErrorif parameters provided in the configuration are invalid.

Definition at line 257 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, extractCode(), extractCSVFormat(), extractData(), extractName(), extractPersistent(), extractSpace(), findOptionDefinition(), isc::dhcp::OptionDescriptor::formatted_value_, isc::util::Optional< T >::get(), isc::data::SimpleParser::getPosition(), isc_throw, isc::dhcp::OptionDescriptor::option_, isc::dhcp::OptionDescriptor::persistent_, isc::util::str::quotedStringToBinary(), isc::data::UserContext::setContext(), isc::util::str::tokens(), isc::util::Optional< T >::unspecified(), isc::dhcp::Option::V4, isc::dhcp::Option::V6, and isc::Exception::what().

Referenced by parse(), and ~OptionDataParser().

+ Here is the call graph for this function:

◆ extractCode()

Optional< uint32_t > isc::dhcp::OptionDataParser::extractCode ( data::ConstElementPtr  parent) const
protected

Retrieves parsed option code as an optional value.

Parameters
parentA data element holding full option data configuration.
Returns
Option code, possibly unspecified.
Exceptions
DhcpConfigErrorif option code is invalid.

Definition at line 62 of file option_data_parser.cc.

References address_family_, isc::data::SimpleParser::getInteger(), isc::data::SimpleParser::getPosition(), and isc_throw.

Referenced by createOption(), and ~OptionDataParser().

+ Here is the call graph for this function:

◆ extractCSVFormat()

Optional< bool > isc::dhcp::OptionDataParser::extractCSVFormat ( data::ConstElementPtr  parent) const
protected

Retrieves csv-format parameter as an optional value.

Returns
Value of the csv-format parameter, possibly unspecified.

Definition at line 128 of file option_data_parser.cc.

References isc::data::SimpleParser::getBoolean().

Referenced by createOption(), and ~OptionDataParser().

+ Here is the call graph for this function:

◆ extractData()

std::string isc::dhcp::OptionDataParser::extractData ( data::ConstElementPtr  parent) const
protected

Retrieves option data as a string.

Parameters
parentA data element holding full option data configuration.
Returns
Option data as a string. It will return empty string if option data is unspecified.

Definition at line 114 of file option_data_parser.cc.

References isc::data::SimpleParser::getString().

Referenced by createOption(), and ~OptionDataParser().

+ Here is the call graph for this function:

◆ extractName()

Optional< std::string > isc::dhcp::OptionDataParser::extractName ( data::ConstElementPtr  parent) const
protected

Retrieves parsed option name as an optional value.

Parameters
parentA data element holding full option data configuration.
Returns
Option name, possibly unspecified.
Exceptions
DhcpConfigErrorif option name is invalid.

Definition at line 95 of file option_data_parser.cc.

References isc::data::SimpleParser::getPosition(), isc::data::SimpleParser::getString(), and isc_throw.

Referenced by createOption(), and ~OptionDataParser().

+ Here is the call graph for this function:

◆ extractPersistent()

Optional< bool > isc::dhcp::OptionDataParser::extractPersistent ( data::ConstElementPtr  parent) const
protected

Retrieves persistent/always-send parameter as an optional value.

Returns
Value of the persistent parameter, possibly unspecified.

Definition at line 177 of file option_data_parser.cc.

References isc::data::SimpleParser::getBoolean().

Referenced by createOption(), and ~OptionDataParser().

+ Here is the call graph for this function:

◆ extractSpace()

std::string isc::dhcp::OptionDataParser::extractSpace ( data::ConstElementPtr  parent) const
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.

Parameters
parentA data element holding full option data configuration.
Returns
Option space name.

Definition at line 141 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(), and ~OptionDataParser().

+ Here is the call graph for this function:

◆ findOptionDefinition()

OptionDefinitionPtr isc::dhcp::OptionDataParser::findOptionDefinition ( const std::string &  option_space,
const util::Optional< uint32_t > &  option_code,
const util::Optional< std::string > &  option_name 
) const
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.

Parameters
option_spacename of the parameter option space
option_codeoption code to be used to find the option definition, if the option name is unspecified.
option_nameoption name to be used to lookup the option definition.
Returns
OptionDefinitionPtr of the option definition or an empty OptionDefinitionPtr if not found.
Exceptions
DhcpConfigErrorif the option space requested is not valid for this server.

Definition at line 190 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::util::Optional< T >::unspecified(), isc::dhcp::Option::V4, and isc::dhcp::Option::V6.

Referenced by createOption(), and ~OptionDataParser().

+ Here is the call graph for this function:

◆ parse()

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.

Parameters
single_optionElementPtr containing option definition
Returns
Option object wrapped in option description and an option space

Definition at line 39 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.

Referenced by isc::dhcp::OptionDataListParser::~OptionDataListParser(), and ~OptionDataParser().

+ Here is the call graph for this function:

Member Data Documentation

◆ address_family_

uint16_t isc::dhcp::OptionDataParser::address_family_
protected

Address family: AF_INET or AF_INET6.

Definition at line 173 of file option_data_parser.h.

Referenced by createOption(), extractCode(), extractSpace(), findOptionDefinition(), and parse().

◆ cfg_option_def_

CfgOptionDefPtr isc::dhcp::OptionDataParser::cfg_option_def_
protected

Config option definitions.

Definition at line 176 of file option_data_parser.h.

Referenced by findOptionDefinition().


The documentation for this class was generated from the following files: