Kea 2.7.5
|
Option with defined data fields represented as buffers that can be accessed using data field index. More...
#include <option_custom.h>
Public Member Functions | |
OptionCustom (const OptionDefinition &def, Universe u) | |
Constructor, used for options to be sent. | |
OptionCustom (const OptionDefinition &def, Universe u, const OptionBuffer &data) | |
Constructor, used for options to be sent. | |
OptionCustom (const OptionDefinition &def, Universe u, OptionBufferConstIter first, OptionBufferConstIter last) | |
Constructor, used for received options. | |
void | addArrayDataField (const asiolink::IOAddress &address) |
Create new buffer and set its value as an IP address. | |
void | addArrayDataField (const bool value) |
Create new buffer and store boolean value in it. | |
void | addArrayDataField (const OpaqueDataTuple &value) |
Create new buffer and store tuple value in it. | |
void | addArrayDataField (const PrefixLen &prefix_len, const asiolink::IOAddress &prefix) |
Create new buffer and store variable length prefix in it. | |
void | addArrayDataField (const PSIDLen &psid_len, const PSID &psid) |
Create new buffer and store PSID length / value in it. | |
void | addArrayDataField (const std::string &value) |
Create new buffer and store tuple value in it. | |
template<typename T > | |
void | addArrayDataField (const T value) |
Create new buffer and store integer value in it. | |
virtual OptionPtr | clone () const |
Copies this option and returns a pointer to the copy. | |
uint32_t | getDataFieldsNum () const |
Return a number of the data fields. | |
void | initialize (const OptionBufferConstIter first, const OptionBufferConstIter last) |
Sets content of this option from buffer. | |
virtual uint16_t | len () const |
Returns length of the complete option (data length + DHCPv4/DHCPv6 option header) | |
virtual void | pack (isc::util::OutputBuffer &buf, bool check=true) const |
Writes DHCP option in a wire format to a buffer. | |
asiolink::IOAddress | readAddress (const uint32_t index=0) const |
Read a buffer as IP address. | |
const OptionBuffer & | readBinary (const uint32_t index=0) const |
Read a buffer as binary data. | |
bool | readBoolean (const uint32_t index=0) const |
Read a buffer as boolean value. | |
std::string | readFqdn (const uint32_t index=0) const |
Read a buffer as FQDN. | |
template<typename T > | |
T | readInteger (const uint32_t index=0) const |
Read a buffer as integer value. | |
PrefixTuple | readPrefix (const uint32_t index=0) const |
Read a buffer as variable length prefix. | |
PSIDTuple | readPsid (const uint32_t index=0) const |
Read a buffer as a PSID length / value tuple. | |
std::string | readString (const uint32_t index=0) const |
Read a buffer as string value. | |
std::string | readTuple (const uint32_t index=0) const |
Read a buffer as length and string tuple. | |
void | readTuple (OpaqueDataTuple &tuple, const uint32_t index=0) const |
Read a buffer into a length and string tuple. | |
virtual std::string | toText (int indent=0) const |
Returns string representation of the option. | |
virtual void | unpack (OptionBufferConstIter begin, OptionBufferConstIter end) |
Parses received buffer. | |
void | writeAddress (const asiolink::IOAddress &address, const uint32_t index=0) |
Write an IP address into a buffer. | |
void | writeBinary (const OptionBuffer &buf, const uint32_t index=0) |
Write binary data into a buffer. | |
void | writeBoolean (const bool value, const uint32_t index=0) |
Write a boolean value into a buffer. | |
void | writeFqdn (const std::string &fqdn, const uint32_t index=0) |
Write an FQDN into a buffer. | |
template<typename T > | |
void | writeInteger (const T value, const uint32_t index=0) |
Write an integer value into a buffer. | |
void | writePrefix (const PrefixLen &prefix_len, const asiolink::IOAddress &prefix, const uint32_t index=0) |
Write prefix length and value into a buffer. | |
void | writePsid (const PSIDLen &psid_len, const PSID &psid, const uint32_t index=0) |
Write PSID length / value into a buffer. | |
void | writeString (const std::string &text, const uint32_t index=0) |
Write a string value into a buffer. | |
void | writeTuple (const OpaqueDataTuple &value, const uint32_t index=0) |
Write a length and string tuple into a buffer. | |
void | writeTuple (const std::string &value, const uint32_t index=0) |
Write a length and string tuple into a buffer. | |
Public Member Functions inherited from isc::dhcp::Option | |
Option (const Option &source) | |
Copy constructor. | |
Option (Universe u, uint16_t type) | |
ctor, used for options constructed, usually during transmission | |
Option (Universe u, uint16_t type, const OptionBuffer &data) | |
Constructor, used for received options. | |
Option (Universe u, uint16_t type, OptionBufferConstIter first, OptionBufferConstIter last) | |
Constructor, used for received options. | |
virtual | ~Option () |
just to force that every option has virtual dtor | |
void | addOption (OptionPtr opt) |
Adds a sub-option. | |
bool | delOption (uint16_t type) |
Attempts to delete first suboption of requested type. | |
virtual bool | equals (const Option &other) const |
Checks if two options are equal. | |
bool | equals (const OptionPtr &other) const |
Checks if options are equal. | |
virtual const OptionBuffer & | getData () const |
Returns pointer to actual data. | |
std::string | getEncapsulatedSpace () const |
Returns the name of the option space encapsulated by this option. | |
virtual uint16_t | getHeaderLen () const |
Returns length of header (2 for v4, 4 for v6) | |
OptionCollection & | getMutableOptions () |
Returns all encapsulated options. | |
OptionPtr | getOption (uint16_t type) const |
Returns shared_ptr to suboption of specific type. | |
const OptionCollection & | getOptions () const |
Returns all encapsulated options. | |
void | getOptionsCopy (OptionCollection &options_copy) const |
Performs deep copy of suboptions. | |
uint16_t | getType () const |
Returns option type (0-255 for DHCPv4, 0-65535 for DHCPv6) | |
uint16_t | getUint16 () const |
Returns content of first word. | |
uint32_t | getUint32 () const |
Returns content of first double word. | |
uint8_t | getUint8 () const |
Returns content of first byte. | |
Universe | getUniverse () const |
returns option universe (V4 or V6) | |
Option & | operator= (const Option &rhs) |
Assignment operator. | |
template<typename InputIterator > | |
void | setData (InputIterator first, InputIterator last) |
Sets content of this option from buffer. | |
void | setEncapsulatedSpace (const std::string &encapsulated_space) |
Sets the name of the option space encapsulated by this option. | |
void | setUint16 (uint16_t value) |
Sets content of this option to a single uint16 value. | |
void | setUint32 (uint32_t value) |
Sets content of this option to a single uint32 value. | |
void | setUint8 (uint8_t value) |
Sets content of this option to a single uint8 value. | |
virtual std::vector< uint8_t > | toBinary (const bool include_header=false) const |
Returns binary representation of the option. | |
virtual std::string | toHexString (const bool include_header=false) const |
Returns string containing hexadecimal representation of option. | |
virtual std::string | toString () const |
Returns string representation of the value. | |
virtual bool | valid () const |
returns if option is valid (e.g. | |
Additional Inherited Members | |
Public Types inherited from isc::dhcp::Option | |
typedef OptionPtr | Factory(Option::Universe u, uint16_t type, const OptionBuffer &buf) |
a factory function prototype | |
enum | Universe { V4 , V6 } |
defines option universe DHCPv4 or DHCPv6 More... | |
Static Public Member Functions inherited from isc::dhcp::Option | |
static OptionPtr | create (Universe u, uint16_t type) |
Factory function creating an instance of the Option . | |
static OptionPtr | create (Universe u, uint16_t type, const OptionBuffer &data) |
Factory function creating an instance of the Option . | |
static OptionPtr | factory (Option::Universe u, uint16_t type) |
Factory function to create instance of option. | |
static OptionPtr | factory (Option::Universe u, uint16_t type, const OptionBuffer &buf) |
Factory function to create instance of option. | |
Static Public Attributes inherited from isc::dhcp::Option | |
static bool | lenient_parsing_ |
Governs whether options should be parsed less strictly. | |
static const size_t | OPTION4_HDR_LEN = 2 |
length of the usual DHCPv4 option header (there are exceptions) | |
static const size_t | OPTION6_HDR_LEN = 4 |
length of any DHCPv6 option header | |
Protected Member Functions inherited from isc::dhcp::Option | |
void | check () const |
A protected method used for option correctness. | |
template<typename OptionType > | |
OptionPtr | cloneInternal () const |
Copies this option and returns a pointer to the copy. | |
std::string | headerToText (const int indent=0, const std::string &type_name="") const |
Returns option header in the textual format. | |
void | packHeader (isc::util::OutputBuffer &buf, bool check=true) const |
Store option's header in a buffer. | |
void | packOptions (isc::util::OutputBuffer &buf, bool check=true) const |
Store sub options in a buffer. | |
std::string | suboptionsToText (const int indent=0) const |
Returns collection of suboptions in the textual format. | |
void | unpackOptions (const OptionBuffer &buf) |
Builds a collection of sub options from the buffer. | |
Protected Attributes inherited from isc::dhcp::Option | |
OptionBuffer | data_ |
contains content of this data | |
std::string | encapsulated_space_ |
Name of the option space being encapsulated by this option. | |
OptionCollection | options_ |
collection for storing suboptions | |
uint16_t | type_ |
option type (0-255 for DHCPv4, 0-65535 for DHCPv6) | |
Universe | universe_ |
option universe (V4 or V6) | |
Option with defined data fields represented as buffers that can be accessed using data field index.
This class represents an option which has defined structure: data fields of specific types and order. Those fields can be accessed using indexes, where index 0 represents first data field within an option. The last field can be accessed using index equal to 'number of fields' - 1. Internally, the option data is stored as a collection of OptionBuffer objects, each representing data for a particular data field. This data can be converted to the actual data type using methods implemented within this class. This class is used to represent those options that can't be represented by any other specialized class (this excludes the Option class which is generic and can be used to represent any option).
Definition at line 31 of file option_custom.h.
isc::dhcp::OptionCustom::OptionCustom | ( | const OptionDefinition & | def, |
Universe | u ) |
Constructor, used for options to be sent.
This constructor creates an instance of an option with default data set for all data fields. The option buffers are allocated according to data size being stored in particular data fields. For variable size data empty buffers are created.
def | option definition. |
u | specifies universe (V4 or V6) |
Definition at line 21 of file option_custom.cc.
References isc::dhcp::Option::setEncapsulatedSpace().
isc::dhcp::OptionCustom::OptionCustom | ( | const OptionDefinition & | def, |
Universe | u, | ||
const OptionBuffer & | data ) |
Constructor, used for options to be sent.
This constructor creates an instance of an option from the whole supplied buffer. This constructor is mainly used to create an instances of options to be stored in outgoing DHCP packets. The buffer used to create the instance of an option can be created from the option data specified in server's configuration.
def | option definition. |
u | specifies universe (V4 or V6). |
data | content of the option. |
OutOfRange | if option buffer is truncated. |
Definition at line 29 of file option_custom.cc.
References isc::dhcp::Option::getData(), and isc::dhcp::Option::setEncapsulatedSpace().
isc::dhcp::OptionCustom::OptionCustom | ( | const OptionDefinition & | def, |
Universe | u, | ||
OptionBufferConstIter | first, | ||
OptionBufferConstIter | last ) |
Constructor, used for received options.
This constructor creates an instance an option from the portion of the buffer specified by iterators. This is mainly useful when parsing received packets. Such packets are represented by a single buffer holding option data and all sub options. Methods that are parsing a packet, supply relevant portions of the packet buffer to this constructor to create option instances out of it.
def | option definition. |
u | specifies universe (V4 or V6). |
first | iterator to the first element that should be copied. |
last | iterator to the next element after the last one to be copied. |
OutOfRange | if option buffer is truncated. |
Definition at line 38 of file option_custom.cc.
References isc::dhcp::Option::getData(), and isc::dhcp::Option::setEncapsulatedSpace().
void isc::dhcp::OptionCustom::addArrayDataField | ( | const asiolink::IOAddress & | address | ) |
Create new buffer and set its value as an IP address.
address | IPv4 or IPv6 address to be written to a buffer being created. |
Definition at line 54 of file option_custom.cc.
References isc::dhcp::OptionDefinition::getType(), isc_throw, isc::dhcp::OPT_IPV4_ADDRESS_TYPE, isc::dhcp::OPT_IPV6_ADDRESS_TYPE, and isc::dhcp::OptionDataTypeUtil::writeAddress().
void isc::dhcp::OptionCustom::addArrayDataField | ( | const bool | value | ) |
Create new buffer and store boolean value in it.
value | value to be stored in the created buffer. |
Definition at line 90 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::writeBool().
void isc::dhcp::OptionCustom::addArrayDataField | ( | const OpaqueDataTuple & | value | ) |
Create new buffer and store tuple value in it.
value | value to be stored as a tuple in the created buffer. |
Definition at line 81 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::writeTuple().
void isc::dhcp::OptionCustom::addArrayDataField | ( | const PrefixLen & | prefix_len, |
const asiolink::IOAddress & | prefix ) |
Create new buffer and store variable length prefix in it.
prefix_len | Prefix length. |
prefix | Prefix. |
Definition at line 99 of file option_custom.cc.
References isc::dhcp::OptionDefinition::getType(), isc_throw, isc::dhcp::OPT_IPV6_PREFIX_TYPE, and isc::dhcp::OptionDataTypeUtil::writePrefix().
Create new buffer and store PSID length / value in it.
Definition at line 114 of file option_custom.cc.
References isc::dhcp::OptionDefinition::getType(), isc_throw, isc::dhcp::OPT_PSID_TYPE, and isc::dhcp::OptionDataTypeUtil::writePsid().
void isc::dhcp::OptionCustom::addArrayDataField | ( | const std::string & | value | ) |
Create new buffer and store tuple value in it.
value | value to be stored as a tuple in the created buffer. |
Definition at line 71 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::getTupleLenFieldType(), isc::dhcp::Option::getUniverse(), and isc::dhcp::OptionDataTypeUtil::writeTuple().
|
inline |
Create new buffer and store integer value in it.
value | value to be stored in the created buffer. |
T | integer type of the value being stored. |
Definition at line 102 of file option_custom.h.
References isc::dhcp::OptionDefinition::getRecordFields(), isc::dhcp::OptionDefinition::getType(), isc_throw, and isc::dhcp::OPT_RECORD_TYPE.
|
virtual |
Copies this option and returns a pointer to the copy.
Reimplemented from isc::dhcp::Option.
Definition at line 49 of file option_custom.cc.
|
inline |
Return a number of the data fields.
Definition at line 146 of file option_custom.h.
Referenced by toText().
void isc::dhcp::OptionCustom::initialize | ( | const OptionBufferConstIter | first, |
const OptionBufferConstIter | last ) |
Sets content of this option from buffer.
Option will be resized to length of buffer.
first | iterator pointing to beginning of buffer to copy. |
last | iterator pointing to end of buffer to copy. |
Definition at line 698 of file option_custom.cc.
References isc::dhcp::Option::getData().
Referenced by unpack().
|
virtual |
Returns length of the complete option (data length + DHCPv4/DHCPv6 option header)
Reimplemented from isc::dhcp::Option.
Definition at line 681 of file option_custom.cc.
References isc::dhcp::Option::getHeaderLen(), and isc::dhcp::Option::options_.
|
virtual |
Writes DHCP option in a wire format to a buffer.
buf | output buffer (option will be stored there). |
check | if set to false, allows options larger than 255 for v4 |
Reimplemented from isc::dhcp::Option.
Definition at line 477 of file option_custom.cc.
References isc::dhcp::Option::check(), isc::dhcp::Option::packHeader(), and isc::dhcp::Option::packOptions().
IOAddress isc::dhcp::OptionCustom::readAddress | ( | const uint32_t | index = 0 | ) | const |
Read a buffer as IP address.
index | buffer index. |
isc::OutOfRange | if index is out of range. |
Definition at line 498 of file option_custom.cc.
References isc_throw, and isc::dhcp::OptionDataTypeUtil::readAddress().
const OptionBuffer & isc::dhcp::OptionCustom::readBinary | ( | const uint32_t | index = 0 | ) | const |
Read a buffer as binary data.
index | buffer index. |
isc::OutOfRange | if index is out of range. |
Definition at line 534 of file option_custom.cc.
bool isc::dhcp::OptionCustom::readBoolean | ( | const uint32_t | index = 0 | ) | const |
Read a buffer as boolean value.
index | buffer index. |
isc::OutOfRange | if index is out of range. |
Definition at line 578 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::readBool().
std::string isc::dhcp::OptionCustom::readFqdn | ( | const uint32_t | index = 0 | ) | const |
Read a buffer as FQDN.
index | buffer index. |
isc::OutOfRange | if buffer index is out of range. |
isc::dhcp::BadDataTypeCast | if a buffer being read does not hold a valid FQDN. |
Definition at line 592 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::readFqdn().
|
inline |
Read a buffer as integer value.
index | buffer index. |
integer | type of a value being returned. |
isc::OutOfRange | if index is out of range. |
isc::dhcp::InvalidDataType | if T is invalid. |
Definition at line 251 of file option_custom.h.
References isc_throw_assert.
Referenced by checkIAStatus().
PrefixTuple isc::dhcp::OptionCustom::readPrefix | ( | const uint32_t | index = 0 | ) | const |
Read a buffer as variable length prefix.
index | buffer index. |
isc::OutOfRange | of index is out of range. |
Definition at line 615 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::readPrefix().
PSIDTuple isc::dhcp::OptionCustom::readPsid | ( | const uint32_t | index = 0 | ) | const |
Read a buffer as a PSID length / value tuple.
index | buffer index. |
isc::OutOfRange | of index is out of range. |
Definition at line 635 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::readPsid().
std::string isc::dhcp::OptionCustom::readString | ( | const uint32_t | index = 0 | ) | const |
Read a buffer as string value.
index | buffer index. |
isc::OutOfRange | if index is out of range. |
Definition at line 654 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::readString().
std::string isc::dhcp::OptionCustom::readTuple | ( | const uint32_t | index = 0 | ) | const |
Read a buffer as length and string tuple.
index | buffer index. |
isc::OutOfRange | if index is out of range. |
Definition at line 547 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::getTupleLenFieldType(), isc::dhcp::Option::getUniverse(), and isc::dhcp::OptionDataTypeUtil::readTuple().
void isc::dhcp::OptionCustom::readTuple | ( | OpaqueDataTuple & | tuple, |
const uint32_t | index = 0 ) const |
Read a buffer into a length and string tuple.
tuple | tuple to fill. |
index | buffer index. |
isc::OutOfRange | if index is out of range. |
Definition at line 554 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::readTuple().
|
virtual |
Returns string representation of the option.
indent | number of spaces before printed text. |
Reimplemented from isc::dhcp::Option.
Definition at line 707 of file option_custom.cc.
References isc::dhcp::OptionDefinition::getArrayType(), getDataFieldsNum(), isc::dhcp::OptionDefinition::getRecordFields(), isc::dhcp::OptionDefinition::getType(), isc::dhcp::Option::headerToText(), isc::dhcp::OPT_RECORD_TYPE, and isc::dhcp::Option::suboptionsToText().
|
virtual |
Parses received buffer.
begin | iterator to first byte of option data |
end | iterator to end of option data (first byte after option end) |
Reimplemented from isc::dhcp::Option.
Definition at line 675 of file option_custom.cc.
References initialize().
void isc::dhcp::OptionCustom::writeAddress | ( | const asiolink::IOAddress & | address, |
const uint32_t | index = 0 ) |
Write an IP address into a buffer.
address | IP address being written. |
index | buffer index. |
isc::OutOfRange | if index is out of range. |
isc::dhcp::BadDataTypeCast | if IP address is invalid. |
Definition at line 516 of file option_custom.cc.
References isc_throw, and isc::dhcp::OptionDataTypeUtil::writeAddress().
void isc::dhcp::OptionCustom::writeBinary | ( | const OptionBuffer & | buf, |
const uint32_t | index = 0 ) |
Write binary data into a buffer.
buf | buffer holding binary data to be written. |
index | buffer index. |
Definition at line 540 of file option_custom.cc.
void isc::dhcp::OptionCustom::writeBoolean | ( | const bool | value, |
const uint32_t | index = 0 ) |
Write a boolean value into a buffer.
value | boolean value to be written. |
index | buffer index. |
isc::OutOfRange | if index is out of range. |
Definition at line 584 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::writeBool().
void isc::dhcp::OptionCustom::writeFqdn | ( | const std::string & | fqdn, |
const uint32_t | index = 0 ) |
Write an FQDN into a buffer.
fqdn | text representation of FQDN. |
index | buffer index. |
isc::OutOfRange | if index is out of range. |
Definition at line 598 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::writeFqdn().
|
inline |
Write an integer value into a buffer.
value | integer value to be written. |
index | buffer index. |
T | integer type of a value being written. |
isc::OutOfRange | if index is out of range. |
isc::dhcp::InvalidDataType | if T is invalid. |
Definition at line 273 of file option_custom.h.
void isc::dhcp::OptionCustom::writePrefix | ( | const PrefixLen & | prefix_len, |
const asiolink::IOAddress & | prefix, | ||
const uint32_t | index = 0 ) |
Write prefix length and value into a buffer.
prefix_len | Prefix length. |
prefix | Prefix value. |
index | Buffer index. |
isc::OutOfRange | if index is out of range. |
Definition at line 621 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::writePrefix().
void isc::dhcp::OptionCustom::writePsid | ( | const PSIDLen & | psid_len, |
const PSID & | psid, | ||
const uint32_t | index = 0 ) |
Write PSID length / value into a buffer.
psid_len | PSID length value. |
psid | PSID value in the range of 0 .. 2^(PSID length). |
index | buffer index. |
isc::dhcp::BadDataTypeCast | if PSID length or value is invalid. |
isc::OutOfRange | if index is out of range. |
Definition at line 641 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::writePsid().
void isc::dhcp::OptionCustom::writeString | ( | const std::string & | text, |
const uint32_t | index = 0 ) |
Write a string value into a buffer.
text | the string value to be written. |
index | buffer index. |
Definition at line 660 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::writeString().
void isc::dhcp::OptionCustom::writeTuple | ( | const OpaqueDataTuple & | value, |
const uint32_t | index = 0 ) |
Write a length and string tuple into a buffer.
value | value to be written. |
index | buffer index. |
Definition at line 570 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::writeTuple().
void isc::dhcp::OptionCustom::writeTuple | ( | const std::string & | value, |
const uint32_t | index = 0 ) |
Write a length and string tuple into a buffer.
value | value to be written. |
index | buffer index. |
Definition at line 561 of file option_custom.cc.
References isc::dhcp::OptionDataTypeUtil::getTupleLenFieldType(), isc::dhcp::Option::getUniverse(), and isc::dhcp::OptionDataTypeUtil::writeTuple().