Kea 2.7.3
|
Utility class for option data types. More...
#include <option_data_types.h>
Static Public Member Functions | |
static OptionDataType | getDataType (const std::string &data_type) |
Return option data type from its name. | |
static int | getDataTypeLen (const OptionDataType data_type) |
Get data type buffer length. | |
static const std::string & | getDataTypeName (const OptionDataType data_type) |
Return option data type name from the data type enumerator. | |
static unsigned int | getLabelCount (const std::string &text_name) |
Return the number of labels in the Name. | |
static OpaqueDataTuple::LengthFieldType | getTupleLenFieldType (Option::Universe u) |
Returns Length Field Type for a tuple. | |
static asiolink::IOAddress | readAddress (const std::vector< uint8_t > &buf, const short family) |
Read IPv4 or IPv6 address from a buffer. | |
static bool | readBool (const std::vector< uint8_t > &buf) |
Read boolean value from a buffer. | |
static std::string | readFqdn (const std::vector< uint8_t > &buf) |
Read FQDN from a buffer as a string value. | |
template<typename T > | |
static T | readInt (const std::vector< uint8_t > &buf) |
Read integer value from a buffer. | |
static PrefixTuple | readPrefix (const std::vector< uint8_t > &buf) |
Read prefix from a buffer. | |
static PSIDTuple | readPsid (const std::vector< uint8_t > &buf) |
Read PSID length / value tuple from a buffer. | |
static std::string | readString (const std::vector< uint8_t > &buf) |
Read string value from a buffer. | |
static void | readTuple (const std::vector< uint8_t > &buf, OpaqueDataTuple &tuple) |
Read length and string tuple from a buffer. | |
static std::string | readTuple (const std::vector< uint8_t > &buf, OpaqueDataTuple::LengthFieldType lengthfieldtype) |
Read length and string tuple from a buffer. | |
static void | writeAddress (const asiolink::IOAddress &address, std::vector< uint8_t > &buf) |
Append IPv4 or IPv6 address to a buffer. | |
static void | writeBinary (const std::string &hex_str, std::vector< uint8_t > &buf) |
Append hex-encoded binary values to a buffer. | |
static void | writeBool (const bool value, std::vector< uint8_t > &buf) |
Append boolean value into a buffer. | |
static void | writeFqdn (const std::string &fqdn, std::vector< uint8_t > &buf, const bool downcase=false) |
Append FQDN into a buffer. | |
template<typename T > | |
static void | writeInt (const T value, std::vector< uint8_t > &buf) |
Append integer or unsigned integer value to a buffer. | |
static void | writePrefix (const PrefixLen &prefix_len, const asiolink::IOAddress &prefix, std::vector< uint8_t > &buf) |
Append prefix into a buffer. | |
static void | writePsid (const PSIDLen &psid_len, const PSID &psid, std::vector< uint8_t > &buf) |
Append PSID length/value into a buffer. | |
static void | writeString (const std::string &value, std::vector< uint8_t > &buf) |
Write UTF8-encoded string into a buffer. | |
static void | writeTuple (const OpaqueDataTuple &tuple, std::vector< uint8_t > &buf) |
Append length and string tuple to a buffer. | |
static void | writeTuple (const std::string &value, OpaqueDataTuple::LengthFieldType lengthfieldtype, std::vector< uint8_t > &buf) |
Append length and string tuple to a buffer. | |
Utility class for option data types.
This class provides a set of utility functions to operate on supported DHCP option data types. It includes conversion between enumerator values representing data types and data type names. It also includes a set of functions that write data into option buffers and read data from option buffers. The data being written and read are converted from/to actual data types.
Definition at line 331 of file option_data_types.h.
|
static |
Return option data type from its name.
data_type | data type name. |
Definition at line 83 of file option_data_types.cc.
Referenced by isc::dhcp::OptionDefinition::OptionDefinition(), and isc::dhcp::OptionDefinition::addRecordField().
|
static |
Get data type buffer length.
This function returns the size of a particular data type. Values returned by this function correspond to the data type sizes defined in OptionDataTypeTraits (IPV4_ADDRESS_TYPE and IPV6_ADDRESS_TYPE are exceptions here) so they rather indicate the fixed length of the data being written into the buffer, not the size of the particular data type. Thus for data types such as string, binary etc. for which the buffer length can't be determined this function returns 0. In addition, this function returns the data sizes for IPV4_ADDRESS_TYPE and IPV6_ADDRESS_TYPE as their buffer representations have fixed data lengths: 4 and 16 respectively.
data_type | data type which size is to be returned. |
Definition at line 98 of file option_data_types.cc.
References isc::dhcp::OPT_BOOLEAN_TYPE, isc::dhcp::OPT_INT16_TYPE, isc::dhcp::OPT_INT32_TYPE, isc::dhcp::OPT_INT8_TYPE, isc::dhcp::OPT_IPV4_ADDRESS_TYPE, isc::dhcp::OPT_IPV6_ADDRESS_TYPE, isc::dhcp::OPT_PSID_TYPE, isc::dhcp::OPT_UINT16_TYPE, isc::dhcp::OPT_UINT32_TYPE, and isc::dhcp::OPT_UINT8_TYPE.
|
static |
Return option data type name from the data type enumerator.
data_type | option data type. |
Definition at line 129 of file option_data_types.cc.
Referenced by isc::dhcp::OptionDefinition::addRecordField(), isc::dhcp::CfgOptionDef::toElementWithMetadata(), isc::dhcp::OptionInt< T >::toText(), and isc::dhcp::OptionIntArray< T >::toText().
|
static |
Return the number of labels in the Name.
If the specified name is empty the 0 is returned.
text_name | A text representation of the name. |
isc::dhcp::BadDataTypeCast | if provided name is malformed. |
Definition at line 376 of file option_data_types.cc.
References isc::dns::Name::getLabelCount(), isc_throw, and isc::Exception::what().
|
static |
Returns Length Field Type for a tuple.
Returns Length Field Type for a tuple basing on the given Option v4/v6 Universe.
u | specifies universe (V4 or V6) |
Definition at line 197 of file option_data_types.cc.
References isc::dhcp::OpaqueDataTuple::LENGTH_1_BYTE, isc::dhcp::OpaqueDataTuple::LENGTH_2_BYTES, and isc::dhcp::Option::V4.
Referenced by isc::dhcp::OptionOpaqueDataTuples::OptionOpaqueDataTuples(), isc::dhcp::OptionOpaqueDataTuples::OptionOpaqueDataTuples(), isc::dhcp::OptionCustom::addArrayDataField(), isc::dhcp::OptionVendorClass::addTuple(), isc::dhcp::OptionCustom::readTuple(), isc::dhcp::OptionVendorClass::setTuple(), isc::dhcp::OptionVendorClass::unpack(), isc::dhcp::DnrInstance::unpackAdn(), and isc::dhcp::OptionCustom::writeTuple().
|
static |
Read IPv4 or IPv6 address from a buffer.
buf | input buffer. |
family | address family: AF_INET or AF_INET6. |
isc::dhcp::BadDataTypeCast | when the data being read is truncated. |
Definition at line 150 of file option_data_types.cc.
References isc::asiolink::IOAddress::fromBytes(), and isc_throw.
Referenced by isc::dhcp::OptionCustom::readAddress().
|
static |
Read boolean value from a buffer.
buf | input buffer. |
isc::dhcp::BadDataTypeCast | when the data being read is truncated or the value is invalid (neither 1 nor 0). |
Definition at line 317 of file option_data_types.cc.
References isc_throw.
Referenced by isc::dhcp::OptionCustom::readBoolean().
|
static |
Read FQDN from a buffer as a string value.
The format of an FQDN within a buffer complies with RFC1035, section 3.1.
buf | input buffer holding a FQDN. |
BadDataTypeCast | if a FQDN stored within a buffer is invalid (e.g. empty, contains invalid characters, truncated). |
Definition at line 338 of file option_data_types.cc.
References isc_throw, isc::dns::Name::toText(), and isc::Exception::what().
Referenced by isc::dhcp::OptionCustom::readFqdn().
|
inlinestatic |
Read integer value from a buffer.
buf | input buffer. |
integer | type of the returned value. |
isc::dhcp::BadDataTypeCast | when the data in the buffer is truncated. |
Definition at line 462 of file option_data_types.h.
References isc_throw, isc::util::readUint16(), and isc::util::readUint32().
|
static |
Read prefix from a buffer.
This method reads prefix length and a prefix value from a buffer. The prefix value has variable length and this length is determined from the first byte of the buffer. If the length is not divisible by 8, the prefix is padded with zeros to the next byte boundary.
buf | input buffer holding a prefix length / prefix tuple. |
Definition at line 394 of file option_data_types.cc.
References isc::asiolink::IOAddress::fromBytes(), isc::asiolink::IOAddress::IPV6_ZERO_ADDRESS(), isc_throw, and isc::Exception::what().
Referenced by isc::dhcp::OptionCustom::readPrefix().
|
static |
Read PSID length / value tuple from a buffer.
This method reads three bytes from a buffer. The first byte holds a PSID length value. The remaining two bytes contain a zero padded PSID value.
isc::dhcp::BadDataTypeCast | if PSID length or value held in the buffer is incorrect or the buffer is truncated. |
Definition at line 528 of file option_data_types.cc.
References isc_throw, and isc::util::readUint16().
Referenced by isc::dhcp::OptionCustom::readPsid().
|
static |
Read string value from a buffer.
To be compliant with RFC 2132, Sec. 2, trailing NULLs are trimmed.
buf | input buffer. |
isc::dhcp::OutOfRange | is the payload contains only NULLs. |
Definition at line 594 of file option_data_types.cc.
References isc_throw, and isc::util::str::seekTrimmed().
Referenced by isc::dhcp::OptionCustom::readString().
|
static |
Read length and string tuple from a buffer.
buf | input buffer. |
tuple | reference of the tuple to read into |
isc::dhcp::BadDataTypeCast | when the data being read is truncated. |
Definition at line 247 of file option_data_types.cc.
References isc_throw, and isc::Exception::what().
|
static |
Read length and string tuple from a buffer.
buf | input buffer. |
lengthfieldtype | LENGTH_1_BYTE (DHCPv4) or LENGTH_2_BYTES (DHCPv6) |
isc::dhcp::BadDataTypeCast | when the data being read is truncated. |
Definition at line 205 of file option_data_types.cc.
References isc_throw, isc::dhcp::OpaqueDataTuple::LENGTH_1_BYTE, isc::dhcp::OpaqueDataTuple::LENGTH_2_BYTES, and isc::util::readUint16().
Referenced by isc::dhcp::OptionCustom::readTuple(), and isc::dhcp::OptionCustom::readTuple().
|
static |
Append IPv4 or IPv6 address to a buffer.
address | IPv4 or IPv6 address. | |
[out] | buf | output buffer. |
Definition at line 172 of file option_data_types.cc.
Referenced by isc::dhcp::OptionCustom::addArrayDataField(), and isc::dhcp::OptionCustom::writeAddress().
|
static |
Append hex-encoded binary values to a buffer.
hex_str | string representing a binary value encoded with hexadecimal digits (without 0x prefix). | |
[out] | buf | output buffer. |
Definition at line 179 of file option_data_types.cc.
References isc::util::encode::decodeHex(), isc_throw, and isc::Exception::what().
|
static |
Append boolean value into a buffer.
The bool value is encoded in a buffer in such a way that "1" means "true" and "0" means "false".
value | boolean value to be written. | |
[out] | buf | output buffer. |
Definition at line 332 of file option_data_types.cc.
Referenced by isc::dhcp::OptionCustom::addArrayDataField(), and isc::dhcp::OptionCustom::writeBoolean().
|
static |
Append FQDN into a buffer.
This method appends the Fully Qualified Domain Name (FQDN) represented as string value into a buffer. The format of the FQDN being stored into a buffer complies with RFC1035, section 3.1.
fqdn | fully qualified domain name to be written. | |
[out] | buf | output buffer. |
downcase | indicates if the FQDN should be converted to lower case (if true). By default it is not converted. |
isc::dhcp::BadDataTypeCast | if provided FQDN is invalid. |
Definition at line 359 of file option_data_types.cc.
References isc_throw, and isc::Exception::what().
Referenced by isc::dhcp::OptionCustom::writeFqdn().
|
inlinestatic |
Append integer or unsigned integer value to a buffer.
value | an integer value to be written into a buffer. | |
[out] | buf | output buffer. |
data | type of the value. |
Definition at line 504 of file option_data_types.h.
References isc_throw, isc::util::writeUint16(), and isc::util::writeUint32().
|
static |
Append prefix into a buffer.
This method writes prefix length (1 byte) followed by a variable length prefix.
prefix_len | Prefix length in bits (0 to 128). | |
prefix | Prefix value. | |
[out] | buf | Output buffer. |
Definition at line 490 of file option_data_types.cc.
References isc_throw.
Referenced by isc::dhcp::OptionCustom::addArrayDataField(), and isc::dhcp::OptionCustom::writePrefix().
|
static |
Append PSID length/value into a buffer.
This method appends 1 byte of PSID length and 2 bytes of PSID value into a buffer. The PSID value contains a PSID length number of significant bits, followed by 16 - PSID length zero bits.
psid_len | PSID length in the range of 0 to 16 holding the number of significant bits within the PSID value. | |
psid | PSID value, where the lowest value is 0, and the highest value is 2^(PSID length)-1. | |
[out] | buf | output buffer. |
isc::dhcp::BadDataTypeCast | if specified psid_len or psid value is incorrect. |
Definition at line 571 of file option_data_types.cc.
References isc_throw, and isc::util::writeUint16().
Referenced by isc::dhcp::OptionCustom::addArrayDataField(), and isc::dhcp::OptionCustom::writePsid().
|
static |
Write UTF8-encoded string into a buffer.
value | string value to be written into a buffer. | |
[out] | buf | output buffer. |
Definition at line 612 of file option_data_types.cc.
Referenced by isc::dhcp::OptionCustom::writeString().
|
static |
Append length and string tuple to a buffer.
tuple | length and string tuple | |
[out] | buf | output buffer. |
Definition at line 286 of file option_data_types.cc.
References isc_throw, isc::dhcp::OpaqueDataTuple::LENGTH_1_BYTE, isc::dhcp::OpaqueDataTuple::LENGTH_2_BYTES, and isc::util::writeUint16().
|
static |
Append length and string tuple to a buffer.
value | length and string tuple | |
lengthfieldtype | LENGTH_1_BYTE (DHCPv4) or LENGTH_2_BYTES (DHCPv6) | |
[out] | buf | output buffer. |
Definition at line 257 of file option_data_types.cc.
References isc_throw, isc::dhcp::OpaqueDataTuple::LENGTH_1_BYTE, isc::dhcp::OpaqueDataTuple::LENGTH_2_BYTES, and isc::util::writeUint16().
Referenced by isc::dhcp::OptionCustom::addArrayDataField(), isc::dhcp::OptionCustom::addArrayDataField(), isc::dhcp::OptionCustom::writeTuple(), and isc::dhcp::OptionCustom::writeTuple().