Kea 2.7.5
|
Base class representing a DHCP option definition. More...
#include <option_definition.h>
Public Types | |
typedef std::vector< OptionDataType > | RecordFieldsCollection |
List of fields within the record. | |
typedef std::vector< OptionDataType >::const_iterator | RecordFieldsConstIter |
Const iterator for record data fields. | |
Public Member Functions | |
OptionDefinition (const std::string &name, const uint16_t code, const std::string &space, const OptionDataType type, const bool array_type=false) | |
Constructor. | |
OptionDefinition (const std::string &name, const uint16_t code, const std::string &space, const OptionDataType type, const char *encapsulated_space) | |
Constructor. | |
OptionDefinition (const std::string &name, const uint16_t code, const std::string &space, const std::string &type, const bool array_type=false) | |
Constructor. | |
OptionDefinition (const std::string &name, const uint16_t code, const std::string &space, const std::string &type, const char *encapsulated_space) | |
Constructor. | |
Public Member Functions inherited from isc::data::StampedElement | |
StampedElement () | |
Constructor. | |
void | delServerTag (const std::string &server_tag) |
Deletes server tag. | |
isc::data::ElementPtr | getMetadata () const |
Returns an object representing metadata to be returned with objects from the configuration backend. | |
std::set< ServerTag > | getServerTags () const |
Returns server tags. | |
bool | hasAllServerTag () const |
Checks if the element has 'all' server tag. | |
bool | hasServerTag (const ServerTag &server_tag) const |
Checks if the element has the given server tag. | |
void | setServerTag (const std::string &server_tag) |
Adds new server tag. | |
Public Member Functions inherited from isc::data::BaseStampedElement | |
BaseStampedElement () | |
Constructor. | |
uint64_t | getId () const |
Returns element's database identifier. | |
boost::posix_time::ptime | getModificationTime () const |
Returns timestamp. | |
void | setId (const uint64_t id) |
Sets element's database identifier. | |
void | setModificationTime (const boost::posix_time::ptime ×tamp) |
Sets timestamp to the explicitly provided value. | |
void | updateModificationTime () |
Sets timestamp to the current time. | |
Static Public Member Functions | |
static OptionDefinitionPtr | create (const std::string &name, const uint16_t code, const std::string &space, const OptionDataType type, const bool array_type=false) |
Factory function creating an instance of the OptionDefinition . | |
static OptionDefinitionPtr | create (const std::string &name, const uint16_t code, const std::string &space, const OptionDataType type, const char *encapsulated_space) |
Factory function creating an instance of the OptionDefinition . | |
static OptionDefinitionPtr | create (const std::string &name, const uint16_t code, const std::string &space, const std::string &type, const bool array_type=false) |
Factory function creating an instance of the OptionDefinition . | |
static OptionDefinitionPtr | create (const std::string &name, const uint16_t code, const std::string &space, const std::string &type, const char *encapsulated_space) |
Factory function creating an instance of the OptionDefinition . | |
Comparison functions and operators. | |
bool | equals (const OptionDefinition &other) const |
Check if option definition is equal to other. | |
bool | operator== (const OptionDefinition &other) const |
Equality operator. | |
bool | operator!= (const OptionDefinition &other) const |
Inequality operator. | |
void | addRecordField (const std::string &data_type_name) |
Adds data field to the record. | |
void | addRecordField (const OptionDataType data_type) |
Adds data field to the record. | |
bool | getArrayType () const |
Return array type indicator. | |
uint16_t | getCode () const |
Return option code. | |
std::string | getEncapsulatedSpace () const |
Return name of the encapsulated option space. | |
std::string | getName () const |
Return option name. | |
const RecordFieldsCollection & | getRecordFields () const |
Return list of record fields. | |
std::string | getOptionSpaceName () const |
Returns option space name. | |
OptionDataType | getType () const |
Return option data type. | |
data::ConstElementPtr | getContext () const |
Returns const pointer to the user context. | |
void | setContext (const data::ConstElementPtr &ctx) |
Sets user context. | |
void | contextToElement (data::ElementPtr map) const |
Merge unparse a user_context object. | |
void | validate () const |
Check if the option definition is valid. | |
OptionPtr | optionFactory (Option::Universe u, uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end, bool convenient_notation=false) const |
Option factory. | |
OptionPtr | optionFactory (Option::Universe u, uint16_t type, const OptionBuffer &buf=OptionBuffer()) const |
Option factory. | |
OptionPtr | optionFactory (Option::Universe u, uint16_t type, const std::vector< std::string > &values) const |
Option factory. | |
static OptionPtr | factoryAddrList4 (uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end) |
Factory to create option with address list. | |
static OptionPtr | factoryAddrList6 (uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end) |
Factory to create option with address list. | |
static OptionPtr | factoryEmpty (Option::Universe u, uint16_t type) |
Empty option factory. | |
static OptionPtr | factoryGeneric (Option::Universe u, uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end) |
Factory to create generic option. | |
static OptionPtr | factoryIA6 (uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end) |
Factory for IA-type of option. | |
static OptionPtr | factoryIAAddr6 (uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end) |
Factory for IAADDR-type of option. | |
static OptionPtr | factoryIAPrefix6 (uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end) |
Factory for IAPREFIX-type of option. | |
static OptionPtr | factoryOpaqueDataTuples (Option::Universe u, uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end) |
Factory to create option with tuple list. | |
static OptionPtr | factoryOpaqueDataTuples (Option::Universe u, uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end, OpaqueDataTuple::LengthFieldType length_field_type) |
Factory to create option with tuple list with explict tuple's length field type. | |
template<typename T > | |
static OptionPtr | factoryInteger (Option::Universe u, uint16_t type, const std::string &encapsulated_space, OptionBufferConstIter begin, OptionBufferConstIter end) |
Factory function to create option with integer value. | |
template<typename T > | |
static OptionPtr | factoryIntegerArray (Option::Universe u, uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end) |
Factory function to create option with array of integer values. | |
Additional Inherited Members | |
Protected Attributes inherited from isc::data::BaseStampedElement | |
uint64_t | id_ |
Database identifier of the configuration element. | |
boost::posix_time::ptime | timestamp_ |
Holds timestamp value. | |
Base class representing a DHCP option definition.
This is a base class representing a DHCP option definition, which describes the format of the option. In particular, it defines:
The option type specifies the data type(s) which an option conveys. If this is a single value the option type points to the data type of the value. For example, DHCPv6 option 8 comprises a two-byte option code, a two-byte option length and two-byte field that carries a uint16 value (RFC 8415 - http://ietf.org/rfc/rfc8415.txt). In such a case, the option type is defined as "uint16". Length and string tuples are a length on one (DHCPv4) or two (DHCPv6) bytes followed by a string of the given length.
When the option has a more complex structure, the option type may be defined as "array", "record" or even "array of records".
Array types should be used when the option contains multiple contiguous data values of the same type laid. For example, DHCPv6 option 6 includes multiple fields holding uint16 codes of requested DHCPv6 options (RFC 8415). Such an option can be represented with this class by setting the option type to "uint16" and the array indicator (array_type) to true. The number of elements in the array is effectively unlimited (although it is actually limited by the maximal DHCPv6 option length).
Should the option comprise data fields of different types, the "record" option type is used. In such cases the data field types within the record are specified using OptionDefinition::addRecordField.
When the OptionDefinition object has been successfully created, it can be queried to return the appropriate option factory function for the specified specified option format. There are a number of "standard" factory functions that cover well known (common) formats. If the particular format does not match any common format the generic factory function is returned.
The following data type strings are supported:
"record" (set of data fields of different types)
Extend the comment to describe "generic factories".
Extend this class with more factory functions.
Derive from UserContext without breaking the multi index.
Definition at line 138 of file option_definition.h.
typedef std::vector<OptionDataType> isc::dhcp::OptionDefinition::RecordFieldsCollection |
List of fields within the record.
Definition at line 142 of file option_definition.h.
typedef std::vector<OptionDataType>::const_iterator isc::dhcp::OptionDefinition::RecordFieldsConstIter |
Const iterator for record data fields.
Definition at line 144 of file option_definition.h.
|
explicit |
Constructor.
name | option name. |
code | option code. |
space | option space. |
type | option data type as string. |
array_type | array indicator, if true it indicates that the option fields are the array. |
Definition at line 48 of file option_definition.cc.
References isc::dhcp::OptionDataTypeUtil::getDataType().
|
explicit |
Constructor.
name | option name. |
code | option code. |
space | option space. |
type | option data type. |
array_type | array indicator, if true it indicates that the option fields are the array. |
Definition at line 67 of file option_definition.cc.
|
explicit |
Constructor.
This constructor sets the name of the option space that is encapsulated by this option. The encapsulated option space identifies sub-options that are carried within this option. This constructor does not allow to set array indicator because options comprising an array of data fields must not be used with sub-options.
name | option name. |
code | option code. |
space | option space. |
type | option data type given as string. |
encapsulated_space | name of the option space being encapsulated by this option. |
Definition at line 80 of file option_definition.cc.
|
explicit |
Constructor.
This constructor sets the name of the option space that is encapsulated by this option. The encapsulated option space identifies sub-options that are carried within this option. This constructor does not allow to set array indicator because options comprising an array of data fields must not be used with sub-options.
name | option name. |
code | option code. |
space | option space. |
type | option data type. |
encapsulated_space | name of the option space being encapsulated by this option. |
Definition at line 98 of file option_definition.cc.
void isc::dhcp::OptionDefinition::addRecordField | ( | const OptionDataType | data_type | ) |
Adds data field to the record.
data_type | data type for the field. |
isc::InvalidOperation | if option type is not set to RECORD_TYPE. |
isc::BadValue | if specified invalid data type. |
Definition at line 167 of file option_definition.cc.
References isc::dhcp::OptionDataTypeUtil::getDataTypeName(), isc_throw, isc::dhcp::OPT_ANY_ADDRESS_TYPE, isc::dhcp::OPT_EMPTY_TYPE, and isc::dhcp::OPT_RECORD_TYPE.
void isc::dhcp::OptionDefinition::addRecordField | ( | const std::string & | data_type_name | ) |
Adds data field to the record.
data_type_name | name of the data type for the field. |
isc::InvalidOperation | if option type is not set to RECORD_TYPE. |
isc::BadValue | if specified invalid data type. |
Definition at line 161 of file option_definition.cc.
References addRecordField(), and isc::dhcp::OptionDataTypeUtil::getDataType().
Referenced by addRecordField().
|
inline |
Merge unparse a user_context object.
Add user-context to map, but only if defined. Omit if it was not. Extract comment so it will be pretty-printed first.
map | A pointer to map where the user context will be unparsed. |
Definition at line 406 of file option_definition.h.
References isc::data::UserContext::contextToElement().
|
static |
Factory function creating an instance of the OptionDefinition
.
This function should be used to create an instance of the option definition within a hooks library in cases when the library may be unloaded before the object is destroyed. This ensures that the ownership of the object by the Kea process is retained.
name | option name. |
code | option code. |
space | option space. |
type | option data type. |
array_type | array indicator, if true it indicates that the option fields are the array. |
OptionDefinition
instance. Definition at line 123 of file option_definition.cc.
|
static |
Factory function creating an instance of the OptionDefinition
.
This function should be used to create an instance of the option definition within a hooks library in cases when the library may be unloaded before the object is destroyed. This ensures that the ownership of the object by the Kea process is retained.
name | option name. |
code | option code. |
space | option space. |
type | option data type. |
encapsulated_space | name of the option space being encapsulated by this option. |
OptionDefinition
instance. Definition at line 141 of file option_definition.cc.
|
static |
Factory function creating an instance of the OptionDefinition
.
This function should be used to create an instance of the option definition within a hooks library in cases when the library may be unloaded before the object is destroyed. This ensures that the ownership of the object by the Kea process is retained.
name | option name. |
code | option code. |
space | option space. |
type | option data type as string. |
array_type | array indicator, if true it indicates that the option fields are the array. |
OptionDefinition
instance. Definition at line 114 of file option_definition.cc.
|
static |
Factory function creating an instance of the OptionDefinition
.
This function should be used to create an instance of the option definition within a hooks library in cases when the library may be unloaded before the object is destroyed. This ensures that the ownership of the object by the Kea process is retained.
name | option name. |
code | option code. |
space | option space. |
type | option data type given as string. |
encapsulated_space | name of the option space being encapsulated by this option. |
OptionDefinition
instance. Definition at line 132 of file option_definition.cc.
bool isc::dhcp::OptionDefinition::equals | ( | const OptionDefinition & | other | ) | const |
Check if option definition is equal to other.
other | Option definition to compare to. |
Definition at line 150 of file option_definition.cc.
Referenced by operator!=(), and operator==().
|
static |
Factory to create option with address list.
type | option type. |
begin | iterator pointing to the beginning of the buffer with a list of IPv4 addresses. |
end | iterator pointing to the end of the buffer with a list of IPv4 addresses. |
isc::OutOfRange | if length of the provided option buffer is not multiple of IPV4 address length. |
Definition at line 739 of file option_definition.cc.
Referenced by optionFactory().
|
static |
Factory to create option with address list.
type | option type. |
begin | iterator pointing to the beginning of the buffer with a list of IPv6 addresses. |
end | iterator pointing to the end of the buffer with a list of IPv6 addresses. |
isc::OutOfaRange | if length of provided option buffer is not multiple of IPV6 address length. |
Definition at line 748 of file option_definition.cc.
Referenced by optionFactory().
|
static |
Empty option factory.
u | universe (V6 or V4). |
type | option type. |
Definition at line 758 of file option_definition.cc.
Referenced by optionFactory().
|
static |
Factory to create generic option.
u | universe (V6 or V4). |
type | option type. |
begin | iterator pointing to the beginning of the buffer. |
end | iterator pointing to the end of the buffer. |
Definition at line 764 of file option_definition.cc.
Referenced by optionFactory().
|
static |
Factory for IA-type of option.
type | option type. |
begin | iterator pointing to the beginning of the buffer. |
end | iterator pointing to the end of the buffer. |
isc::OutOfRange | if provided option buffer is too short or too long. Expected size is 12 bytes. |
Definition at line 772 of file option_definition.cc.
References isc_throw, and isc::dhcp::Option6IA::OPTION6_IA_LEN.
|
static |
Factory for IAADDR-type of option.
type | option type. |
begin | iterator pointing to the beginning of the buffer. |
end | iterator pointing to the end of the buffer. |
isc::OutOfRange | if provided option buffer is too short or too long. Expected size is 24 bytes. |
Definition at line 785 of file option_definition.cc.
References isc_throw, and isc::dhcp::Option6IAAddr::OPTION6_IAADDR_LEN.
|
static |
Factory for IAPREFIX-type of option.
type | option type. |
begin | iterator pointing to the beginning of the buffer. |
end | iterator pointing to the end of the buffer. |
isc::OutOfRange | if provided option buffer is too short. Expected minimum size is 25 bytes. |
Definition at line 799 of file option_definition.cc.
References isc_throw, and isc::dhcp::Option6IAPrefix::OPTION6_IAPREFIX_LEN.
|
inlinestatic |
Factory function to create option with integer value.
u | universe (V4 or V6). |
type | option type. |
encapsulated_space | An option space being encapsulated by the options created by this factory function. The options which belong to encapsulated option space are sub options of this option. |
begin | iterator pointing to the beginning of the buffer. |
end | iterator pointing to the end of the buffer. |
T | type of the data field (must be one of the uintX_t or intX_t). |
isc::OutOfRange | if provided option buffer length is invalid. |
Definition at line 621 of file option_definition.h.
|
inlinestatic |
Factory function to create option with array of integer values.
u | universe (V4 or V6). |
type | option type. |
begin | iterator pointing to the beginning of the buffer. |
end | iterator pointing to the end of the buffer. |
T | type of the data field (must be one of the uintX_t or intX_t). |
isc::OutOfRange | if provided option buffer length is invalid. |
Definition at line 641 of file option_definition.h.
|
static |
Factory to create option with tuple list.
u | option universe (V4 or V6). |
type | option type. |
begin | iterator pointing to the beginning of the buffer with a list of tuples. |
end | iterator pointing to the end of the buffer with a list of tuples. |
Definition at line 813 of file option_definition.cc.
Referenced by optionFactory().
|
static |
Factory to create option with tuple list with explict tuple's length field type.
u | option universe (V4 or V6). |
type | option type. |
begin | iterator pointing to the beginning of the buffer with a list of tuples. |
end | iterator pointing to the end of the buffer with a list of tuples. |
length_field_type | explicit tuple's length field type. |
Definition at line 824 of file option_definition.cc.
|
inline |
Return array type indicator.
The method returns the bool value to indicate whether the option is a single value or an array of values.
Definition at line 351 of file option_definition.h.
Referenced by isc::dhcp::OptionCustom::toText().
|
inline |
Return option code.
Definition at line 356 of file option_definition.h.
Referenced by optionFactory().
|
inline |
Returns const pointer to the user context.
Definition at line 390 of file option_definition.h.
References isc::data::UserContext::getContext().
|
inline |
Return name of the encapsulated option space.
Definition at line 361 of file option_definition.h.
Referenced by optionFactory().
|
inline |
|
inline |
Returns option space name.
Definition at line 380 of file option_definition.h.
|
inline |
Return list of record fields.
Definition at line 373 of file option_definition.h.
Referenced by isc::dhcp::OptionCustom::addArrayDataField(), optionFactory(), isc::dhcp::OptionCustom::toText(), and validate().
|
inline |
Return option data type.
Definition at line 387 of file option_definition.h.
Referenced by isc::dhcp::OptionCustom::addArrayDataField(), isc::dhcp::OptionCustom::addArrayDataField(), isc::dhcp::OptionCustom::addArrayDataField(), isc::dhcp::OptionCustom::addArrayDataField(), and isc::dhcp::OptionCustom::toText().
|
inline |
Inequality operator.
other | Option definition to compare to. |
Definition at line 324 of file option_definition.h.
References equals().
|
inline |
Equality operator.
other | Option definition to compare to. |
Definition at line 315 of file option_definition.h.
References equals().
OptionPtr isc::dhcp::OptionDefinition::optionFactory | ( | Option::Universe | u, |
uint16_t | type, | ||
const OptionBuffer & | buf = OptionBuffer() ) const |
Option factory.
This function creates an instance of DHCP option using whole provided buffer. This function may be used to create option which is to be sent in the outgoing packet.
u | option universe (V4 or V6). |
type | option type. |
buf | option buffer. |
InvalidOptionValue | if data for the option is invalid. |
Definition at line 301 of file option_definition.cc.
References optionFactory().
OptionPtr isc::dhcp::OptionDefinition::optionFactory | ( | Option::Universe | u, |
uint16_t | type, | ||
const std::vector< std::string > & | values ) const |
Option factory.
This function creates an instance of DHCP option using the vector of strings which carry data values for option data fields. The order of values in the vector corresponds to the order of data fields in the option. The supplied string values are cast to their actual data types which are determined based on the option definition. If cast fails due to type mismatch, an exception is thrown. This factory function can be used to create option instance when user specified option value in the comma separated values format in the configuration database. Provided string must be tokenized into the vector of string values and this vector can be supplied to this function.
u | option universe (V4 or V6). |
type | option type. |
values | a vector of values to be used to set data for an option. |
InvalidOptionValue | if data for the option is invalid. |
Definition at line 307 of file option_definition.cc.
References getCode(), getRecordFields(), isc_throw, isc::dhcp::OPT_EMPTY_TYPE, isc::dhcp::OPT_INTERNAL_TYPE, isc::dhcp::OPT_RECORD_TYPE, isc::dhcp::OPT_STRING_TYPE, optionFactory(), and isc::util::str::trim().
OptionPtr isc::dhcp::OptionDefinition::optionFactory | ( | Option::Universe | u, |
uint16_t | type, | ||
OptionBufferConstIter | begin, | ||
OptionBufferConstIter | end, | ||
bool | convenient_notation = false ) const |
Option factory.
This function creates an instance of DHCP option using provided chunk of buffer. This function may be used to create option which is to be sent in the outgoing packet.
u | option universe (V4 or V6). |
type | option type. |
begin | beginning of the option buffer. |
end | end of the option buffer. |
convenient_notation | flag which indicates that the buffer contains option data as a string formatted in user-friendly, convenient way. The flag is propagated to the option constructor, so that the data could be parsed properly. Defaults to false. |
InvalidOptionValue | if data for the option is invalid. |
Definition at line 186 of file option_definition.cc.
References factoryAddrList4(), factoryAddrList6(), factoryEmpty(), factoryGeneric(), factoryOpaqueDataTuples(), getEncapsulatedSpace(), isc_throw, isc::dhcp::OPT_BINARY_TYPE, isc::dhcp::OPT_EMPTY_TYPE, isc::dhcp::OPT_INT16_TYPE, isc::dhcp::OPT_INT32_TYPE, isc::dhcp::OPT_INT8_TYPE, isc::dhcp::OPT_INTERNAL_TYPE, isc::dhcp::OPT_IPV4_ADDRESS_TYPE, isc::dhcp::OPT_IPV6_ADDRESS_TYPE, isc::dhcp::OPT_STRING_TYPE, isc::dhcp::OPT_TUPLE_TYPE, isc::dhcp::OPT_UINT16_TYPE, isc::dhcp::OPT_UINT32_TYPE, isc::dhcp::OPT_UINT8_TYPE, and isc::Exception::what().
Referenced by optionFactory(), and optionFactory().
|
inline |
Sets user context.
ctx | user context to be stored. |
Definition at line 396 of file option_definition.h.
References isc::data::UserContext::setContext().
void isc::dhcp::OptionDefinition::validate | ( | ) | const |
Check if the option definition is valid.
Note that it is a responsibility of the code that created the OptionDefinition object to validate that it is valid. This function will not be called internally anywhere in this class to verify that the option definition is valid. Using invalid option definition to create an instance of the DHCP option leads to undefined behavior.
MalformedOptionDefinition | option definition is invalid. |
Definition at line 369 of file option_definition.cc.
References getRecordFields(), isc_throw, isc::dhcp::OPT_BINARY_TYPE, isc::dhcp::OPT_EMPTY_TYPE, isc::dhcp::OPT_INTERNAL_TYPE, isc::dhcp::OPT_RECORD_TYPE, isc::dhcp::OPT_STRING_TYPE, isc::dhcp::OPT_UNKNOWN_TYPE, and isc::dhcp::OptionSpace::validateName().