Kea 2.7.5
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.
 
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 &params)
 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::PositiongetPosition (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.
 

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 32 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.

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 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:

  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 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().

+ Here is the call graph for this function:

◆ extractCancelled()

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

Retrieves cancelled/never-send parameter as an optional value.

Returns
Value of the cancelled parameter, possibly unspecified.

Definition at line 189 of file option_data_parser.cc.

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

Referenced by createOption().

+ 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 61 of file option_data_parser.cc.

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

Referenced by createOption().

+ 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 127 of file option_data_parser.cc.

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

Referenced by createOption().

+ Here is the call graph for this function:

◆ extractData()

Optional< 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 113 of file option_data_parser.cc.

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

Referenced by createOption().

+ 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 94 of file option_data_parser.cc.

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

Referenced by createOption().

+ 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 176 of file option_data_parser.cc.

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

Referenced by createOption().

+ 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 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().

+ 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 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().

+ 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 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.

+ 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 179 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 182 of file option_data_parser.h.

Referenced by findOptionDefinition().


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