Kea  1.5.0
isc::dhcp::CfgOption Class Reference

Represents option data configuration for the DHCP server. More...

#include <cfg_option.h>

+ Inheritance diagram for isc::dhcp::CfgOption:

Public Member Functions

 CfgOption ()
 default constructor More...
 
void add (const OptionPtr &option, const bool persistent, const std::string &option_space)
 Adds instance of the option to the configuration. More...
 
void add (const OptionDescriptor &desc, const std::string &option_space)
 A variant of the CfgOption::add method which takes option descriptor as an argument. More...
 
void copyTo (CfgOption &other) const
 Copies this configuration to another configuration. More...
 
bool empty () const
 Indicates the object is empty. More...
 
void encapsulate ()
 Appends encapsulated options to top-level options. More...
 
template<typename Selector >
OptionDescriptor get (const Selector &key, const uint16_t option_code) const
 Returns option for the specified key and option code. More...
 
OptionContainerPtr getAll (const std::string &option_space) const
 Returns all options for the specified option space. More...
 
OptionContainerPtr getAll (const uint32_t vendor_id) const
 Returns vendor options for the specified vendor id. More...
 
std::list< std::string > getOptionSpaceNames () const
 Returns a list of configured option space names. More...
 
std::list< uint32_t > getVendorIds () const
 Returns a list of all configured vendor identifiers. More...
 
std::list< std::string > getVendorIdsSpaceNames () const
 Returns a list of option space names for configured vendor ids. More...
 
void mergeTo (CfgOption &other) const
 Merges this configuration to another configuration. More...
 
virtual isc::data::ElementPtr toElement () const
 Unparse a configuration object. More...
 
Methods and operators used for comparing objects.
bool equals (const CfgOption &other) const
 Check if configuration is equal to other configuration. More...
 
bool operator== (const CfgOption &other) const
 Equality operator. More...
 
bool operator!= (const CfgOption &other) const
 Inequality operator. More...
 
- Public Member Functions inherited from isc::data::CfgToElement
virtual ~CfgToElement ()
 Destructor. More...
 

Detailed Description

Represents option data configuration for the DHCP server.

This class holds a collection of options to be sent to a DHCP client. Options are grouped by the option space or vendor identifier (for vendor options).

The server configuration allows for specifying two distinct collections of options: global options and per-subnet options in which some options may overlap.

The collection of global options specify options being sent to the client belonging to any subnets, i.e. global options are "inherited" by all subnets.

The per-subnet options are configured for a particular subnet and are sent to clients which belong to this subnet. The values of the options specified for a particular subnet override the values of the global options.

This class represents a single collection of options (either global or per-subnet). Each subnet holds its own object of the CfgOption type. The CfgMgr holds a CfgOption object representing global options.

Note that having a separate copy of the CfgOption to represent global options is useful when the client requests stateless configuration from the DHCP server and no subnet is selected for this client. This client will only receive global options.

Definition at line 248 of file cfg_option.h.

Constructor & Destructor Documentation

◆ CfgOption()

isc::dhcp::CfgOption::CfgOption ( )

default constructor

Definition at line 31 of file cfg_option.cc.

Member Function Documentation

◆ add() [1/2]

void isc::dhcp::CfgOption::add ( const OptionPtr option,
const bool  persistent,
const std::string &  option_space 
)

Adds instance of the option to the configuration.

There are two types of options which may be passed to this method:

  • vendor options
  • non-vendor options

The non-vendor options are grouped by the name of the option space (specified in textual format). The vendor options are grouped by the vendor identifier, which is a 32-bit unsigned integer value.

In order to add new vendor option to the list the option space name (last argument of this method) should be specified as "vendor-X" where "X" is a 32-bit unsigned integer, e.g. "vendor-1234". Options for which the option_space argument doesn't follow this format are added as non-vendor options.

Parameters
optionPointer to the option being added.
persistentBoolean value which specifies if the option should be sent to the client regardless if requested (true), or nor (false)
option_spaceOption space name.
Exceptions
isc::BadValueif the option space is invalid.

Definition at line 46 of file cfg_option.cc.

◆ add() [2/2]

void isc::dhcp::CfgOption::add ( const OptionDescriptor desc,
const std::string &  option_space 
)

A variant of the CfgOption::add method which takes option descriptor as an argument.

Parameters
descOption descriptor holding option instance and other parameters pertaining to the option.
option_spaceOption space name.
Exceptions
isc::BadValueif the option space is invalid.

Definition at line 52 of file cfg_option.cc.

References isc_throw, and isc::dhcp::OptionDescriptor::option_.

◆ copyTo()

void isc::dhcp::CfgOption::copyTo ( CfgOption other) const

Copies this configuration to another configuration.

This method copies options configuration to another object.

Parameters
[out]otherAn object to copy the configuration to.

Definition at line 93 of file cfg_option.cc.

References isc::dhcp::OptionSpaceContainer< ContainerType, ItemType, Selector >::clearItems().

+ Here is the call graph for this function:

◆ empty()

bool isc::dhcp::CfgOption::empty ( ) const

Indicates the object is empty.

Returns
true when the object is empty

Definition at line 35 of file cfg_option.cc.

◆ encapsulate()

void isc::dhcp::CfgOption::encapsulate ( )

Appends encapsulated options to top-level options.

This method iterates over the top-level options (from "dhcp4" and "dhcp6" option space) and checks which option spaces these options encapsulate. For each encapsulated option space, the options from this option space are appended to top-level options.

Definition at line 101 of file cfg_option.cc.

References DHCP4_OPTION_SPACE, and DHCP6_OPTION_SPACE.

◆ equals()

bool isc::dhcp::CfgOption::equals ( const CfgOption other) const

Check if configuration is equal to other configuration.

Parameters
otherAn object holding configuration to compare to.
Returns
true if configurations are equal, false otherwise.

Definition at line 40 of file cfg_option.cc.

Referenced by operator!=(), and operator==().

◆ get()

template<typename Selector >
OptionDescriptor isc::dhcp::CfgOption::get ( const Selector &  key,
const uint16_t  option_code 
) const
inline

Returns option for the specified key and option code.

The key should be a string, in which case it specifies an option space name, or an uint32_t value, in which case it specifies a vendor identifier.

Note
If there are multiple options with the same key, only one will be returned. No indication will be given of the presence of others, and the instance returned is not determinable.
Parameters
keyOption space name or vendor identifier.
option_codeCode of the option to be returned.
Template Parameters
Selectorone of: std::string or uint32_t
Returns
Descriptor of the option. If option hasn't been found, the descriptor holds NULL option.

Definition at line 388 of file cfg_option.h.

References getAll().

+ Here is the call graph for this function:

◆ getAll() [1/2]

OptionContainerPtr isc::dhcp::CfgOption::getAll ( const std::string &  option_space) const

Returns all options for the specified option space.

This method will not return vendor options, i.e. having option space name in the format of "vendor-X" where X is 32-bit unsigned integer. See getAll(uint32_t) for vendor options.

Parameters
option_spaceName of the option space.
Returns
Pointer to the container holding returned options. This container is empty if no options have been found.

Definition at line 183 of file cfg_option.cc.

Referenced by get().

◆ getAll() [2/2]

OptionContainerPtr isc::dhcp::CfgOption::getAll ( const uint32_t  vendor_id) const

Returns vendor options for the specified vendor id.

Parameters
vendor_idVendor id for which options are to be returned.
Returns
Pointer to the container holding returned options. This container is empty if no options have been found.

Definition at line 188 of file cfg_option.cc.

◆ getOptionSpaceNames()

std::list<std::string> isc::dhcp::CfgOption::getOptionSpaceNames ( ) const
inline

Returns a list of configured option space names.

The returned option space names exclude vendor option spaces, such as "vendor-1234". These are returned by the getVendorIdsSpaceNames.

Returns
List comprising option space names.

Definition at line 414 of file cfg_option.h.

References isc::dhcp::OptionSpaceContainer< ContainerType, ItemType, Selector >::getOptionSpaceNames().

+ Here is the call graph for this function:

◆ getVendorIds()

std::list<uint32_t> isc::dhcp::CfgOption::getVendorIds ( ) const
inline

Returns a list of all configured vendor identifiers.

Definition at line 419 of file cfg_option.h.

References isc::dhcp::OptionSpaceContainer< ContainerType, ItemType, Selector >::getOptionSpaceNames().

+ Here is the call graph for this function:

◆ getVendorIdsSpaceNames()

std::list< std::string > isc::dhcp::CfgOption::getVendorIdsSpaceNames ( ) const

Returns a list of option space names for configured vendor ids.

For each vendor-id the option space name returned is constructed as "vendor-XYZ" where XYZ is a uint32_t value without leading zeros.

Returns
List comprising option space names for vendor options.

Definition at line 70 of file cfg_option.cc.

◆ mergeTo()

void isc::dhcp::CfgOption::mergeTo ( CfgOption other) const

Merges this configuration to another configuration.

This method iterates over the configuration items held in this configuration and copies them to the configuration specified as a parameter. If an item exists in the destination it is not copied.

Note
: this method is not longer used so should become private.
Parameters
[out]otherConfiguration object to merge to.

Definition at line 85 of file cfg_option.cc.

◆ operator!=()

bool isc::dhcp::CfgOption::operator!= ( const CfgOption other) const
inline

Inequality operator.

Parameters
otherAn object holding configuration to compare to.
Returns
true if configurations are unequal, false otherwise.

Definition at line 283 of file cfg_option.h.

References equals().

+ Here is the call graph for this function:

◆ operator==()

bool isc::dhcp::CfgOption::operator== ( const CfgOption other) const
inline

Equality operator.

Parameters
otherAn object holding configuration to compare to.
Returns
true if configurations are equal, false otherwise.

Definition at line 274 of file cfg_option.h.

References equals().

+ Here is the call graph for this function:

◆ toElement()

ElementPtr isc::dhcp::CfgOption::toElement ( ) const
virtual

Unparse a configuration object.

Returns
a pointer to unparsed configuration

Implements isc::data::CfgToElement.

Definition at line 193 of file cfg_option.cc.

References isc::data::Element::create(), isc::data::Element::createList(), isc::data::Element::createMap(), and isc::util::encode::encodeHex().

+ Here is the call graph for this function:

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