Kea  2.1.2-git
isc::dhcp::Option Class Reference

#include <option.h>

+ Inheritance diagram for isc::dhcp::Option:

Public Types

typedef OptionPtr Factory(Option::Universe u, uint16_t type, const OptionBuffer &buf)
 a factory function prototype More...
 
enum  Universe { V4, V6 }
 defines option universe DHCPv4 or DHCPv6 More...
 

Public Member Functions

 Option (Universe u, uint16_t type)
 ctor, used for options constructed, usually during transmission More...
 
 Option (Universe u, uint16_t type, const OptionBuffer &data)
 Constructor, used for received options. More...
 
 Option (Universe u, uint16_t type, OptionBufferConstIter first, OptionBufferConstIter last)
 Constructor, used for received options. More...
 
 Option (const Option &source)
 Copy constructor. More...
 
virtual ~Option ()
 just to force that every option has virtual dtor More...
 
void addOption (OptionPtr opt)
 Adds a sub-option. More...
 
virtual OptionPtr clone () const
 Copies this option and returns a pointer to the copy. More...
 
bool delOption (uint16_t type)
 Attempts to delete first suboption of requested type. More...
 
bool equals (const OptionPtr &other) const
 Checks if options are equal. More...
 
virtual bool equals (const Option &other) const
 Checks if two options are equal. More...
 
virtual const OptionBuffergetData () const
 Returns pointer to actual data. More...
 
std::string getEncapsulatedSpace () const
 Returns the name of the option space encapsulated by this option. More...
 
virtual uint16_t getHeaderLen () const
 Returns length of header (2 for v4, 4 for v6) More...
 
OptionPtr getOption (uint16_t type) const
 Returns shared_ptr to suboption of specific type. More...
 
const OptionCollectiongetOptions () const
 Returns all encapsulated options. More...
 
void getOptionsCopy (OptionCollection &options_copy) const
 Performs deep copy of suboptions. More...
 
uint16_t getType () const
 Returns option type (0-255 for DHCPv4, 0-65535 for DHCPv6) More...
 
uint16_t getUint16 () const
 Returns content of first word. More...
 
uint32_t getUint32 () const
 Returns content of first double word. More...
 
uint8_t getUint8 () const
 Returns content of first byte. More...
 
Universe getUniverse () const
 returns option universe (V4 or V6) More...
 
virtual uint16_t len () const
 Returns length of the complete option (data length + DHCPv4/DHCPv6 option header) More...
 
Optionoperator= (const Option &rhs)
 Assignment operator. More...
 
virtual void pack (isc::util::OutputBuffer &buf) const
 Writes option in wire-format to a buffer. More...
 
template<typename InputIterator >
void setData (InputIterator first, InputIterator last)
 Sets content of this option from buffer. More...
 
void setEncapsulatedSpace (const std::string &encapsulated_space)
 Sets the name of the option space encapsulated by this option. More...
 
void setUint16 (uint16_t value)
 Sets content of this option to a single uint16 value. More...
 
void setUint32 (uint32_t value)
 Sets content of this option to a single uint32 value. More...
 
void setUint8 (uint8_t value)
 Sets content of this option to a single uint8 value. More...
 
virtual std::vector< uint8_t > toBinary (const bool include_header=false) const
 Returns binary representation of the option. More...
 
virtual std::string toHexString (const bool include_header=false) const
 Returns string containing hexadecimal representation of option. More...
 
virtual std::string toString () const
 Returns string representation of the value. More...
 
virtual std::string toText (int indent=0) const
 Returns string representation of the option. More...
 
virtual void unpack (OptionBufferConstIter begin, OptionBufferConstIter end)
 Parses received buffer. More...
 
virtual bool valid () const
 returns if option is valid (e.g. More...
 

Static Public Member Functions

static OptionPtr create (Universe u, uint16_t type)
 Factory function creating an instance of the Option. More...
 
static OptionPtr create (Universe u, uint16_t type, const OptionBuffer &data)
 Factory function creating an instance of the Option. More...
 
static OptionPtr factory (Option::Universe u, uint16_t type, const OptionBuffer &buf)
 Factory function to create instance of option. More...
 
static OptionPtr factory (Option::Universe u, uint16_t type)
 Factory function to create instance of option. More...
 

Static Public Attributes

static bool lenient_parsing_
 Governs whether options should be parsed less strictly. More...
 
static const size_t OPTION4_HDR_LEN = 2
 length of the usual DHCPv4 option header (there are exceptions) More...
 
static const size_t OPTION6_HDR_LEN = 4
 length of any DHCPv6 option header More...
 

Protected Member Functions

void check () const
 A protected method used for option correctness. More...
 
template<typename OptionType >
OptionPtr cloneInternal () const
 Copies this option and returns a pointer to the copy. More...
 
std::string headerToText (const int indent=0, const std::string &type_name="") const
 Returns option header in the textual format. More...
 
void packHeader (isc::util::OutputBuffer &buf) const
 Store option's header in a buffer. More...
 
void packOptions (isc::util::OutputBuffer &buf) const
 Store sub options in a buffer. More...
 
std::string suboptionsToText (const int indent=0) const
 Returns collection of suboptions in the textual format. More...
 
void unpackOptions (const OptionBuffer &buf)
 Builds a collection of sub options from the buffer. More...
 

Protected Attributes

OptionBuffer data_
 contains content of this data More...
 
std::string encapsulated_space_
 Name of the option space being encapsulated by this option. More...
 
OptionCollection options_
 collection for storing suboptions More...
 
uint16_t type_
 option type (0-255 for DHCPv4, 0-65535 for DHCPv6) More...
 
Universe universe_
 option universe (V4 or V6) More...
 

Detailed Description

Definition at line 73 of file option.h.

Member Typedef Documentation

◆ Factory

typedef OptionPtr isc::dhcp::Option::Factory(Option::Universe u, uint16_t type, const OptionBuffer &buf)

a factory function prototype

Parameters
uoption universe (DHCPv4 or DHCPv6)
typeoption type
bufpointer to a buffer
Todo:
Passing a separate buffer for each option means that a copy was done. We can avoid it by passing 2 iterators.
Returns
a pointer to a created option object

Definition at line 95 of file option.h.

Member Enumeration Documentation

◆ Universe

defines option universe DHCPv4 or DHCPv6

Enumerator
V4 
V6 

Definition at line 82 of file option.h.

Constructor & Destructor Documentation

◆ Option() [1/4]

isc::dhcp::Option::Option ( Universe  u,
uint16_t  type 
)

ctor, used for options constructed, usually during transmission

Parameters
uoption universe (DHCPv4 or DHCPv6)
typeoption type

Definition at line 40 of file option.cc.

References check().

+ Here is the call graph for this function:

◆ Option() [2/4]

isc::dhcp::Option::Option ( Universe  u,
uint16_t  type,
const OptionBuffer data 
)

Constructor, used for received options.

This constructor takes vector<uint8_t>& which is used in cases when content of the option will be copied and stored within option object. V4 Options follow that approach already.

Todo:
Migrate V6 options to that approach.
Parameters
uspecifies universe (V4 or V6)
typeoption type (0-255 for V4 and 0-65535 for V6)
datacontent of the option

Definition at line 45 of file option.cc.

References check().

+ Here is the call graph for this function:

◆ Option() [3/4]

isc::dhcp::Option::Option ( Universe  u,
uint16_t  type,
OptionBufferConstIter  first,
OptionBufferConstIter  last 
)

Constructor, used for received options.

This constructor is similar to the previous one, but it does not take the whole vector<uint8_t>, but rather subset of it.

Todo:
This can be templated to use different containers, not just vector. Prototype should look like this: template<typename InputIterator> Option(Universe u, uint16_t type, InputIterator first, InputIterator last);

vector<int8_t> myData; Example usage: new Option(V4, 123, myData.begin()+1, myData.end()-1) This will create DHCPv4 option of type 123 that contains data from trimmed (first and last byte removed) myData vector.

Parameters
uspecifies universe (V4 or V6)
typeoption type (0-255 for V4 and 0-65535 for V6)
firstiterator to the first element that should be copied
lastiterator to the next element after the last one to be copied.

Definition at line 50 of file option.cc.

References check().

+ Here is the call graph for this function:

◆ Option() [4/4]

isc::dhcp::Option::Option ( const Option source)

Copy constructor.

This constructor makes a deep copy of the option and all of the suboptions. It calls getOptionsCopy to deep copy suboptions.

Parameters
sourceOption to be copied.

Definition at line 56 of file option.cc.

References getOptionsCopy(), and options_.

+ Here is the call graph for this function:

◆ ~Option()

isc::dhcp::Option::~Option ( )
virtual

just to force that every option has virtual dtor

Definition at line 401 of file option.cc.

References lenient_parsing_.

Member Function Documentation

◆ addOption()

void isc::dhcp::Option::addOption ( OptionPtr  opt)

Adds a sub-option.

Some DHCPv6 options can have suboptions. This method allows adding options within options.

Note: option is passed by value. That is very convenient as it allows downcasting from any derived classes, e.g. shared_ptr<Option6_IA> type can be passed directly, without any casts. That would not be possible with passing by reference. addOption() is expected to be used in many places. Requiring casting is not feasible.

Parameters
optshared pointer to a suboption that is going to be added.

Definition at line 348 of file option.cc.

References getOption(), isc_throw, options_, universe_, and V4.

Referenced by isc::dhcp::Dhcpv6Srv::releaseIA_NA(), and isc::dhcp::Dhcpv6Srv::releaseIA_PD().

+ Here is the call graph for this function:

◆ check()

void isc::dhcp::Option::check ( ) const
protected

A protected method used for option correctness.

It is used in constructors. In there are any problems detected (like specifying type > 255 for DHCPv4 option), it will throw BadValue or OutOfRange exceptions.

TODO Larger options can be stored as separate instances of DHCPv4 options. Clients MUST concatenate them. Fortunately, there are no such large options used today.

Definition at line 91 of file option.cc.

References data_, isc_throw, type_, universe_, V4, and V6.

Referenced by Option().

◆ clone()

OptionPtr isc::dhcp::Option::clone ( ) const
virtual

Copies this option and returns a pointer to the copy.

This function must be overridden in the derived classes to make a copy of the derived type. The simplest way to do it is by calling cloneInternal function with an appropriate template parameter.

Returns
Pointer to the copy of the option.

Reimplemented in isc::dhcp::Option4ClientFqdn, isc::dhcp::Option6ClientFqdn, isc::dhcp::Option4SlpServiceScope, isc::dhcp::OptionIntArray< T >, isc::dhcp::OptionInt< T >, isc::dhcp::OptionCustom, isc::dhcp::Option4AddrLst, isc::dhcp::Option6IAPrefix, isc::dhcp::OptionVendorClass, isc::dhcp::OptionOpaqueDataTuples, isc::dhcp::OptionString, isc::dhcp::OptionVendor, isc::dhcp::Option6PDExclude, isc::dhcp::Option6IAAddr, isc::dhcp::Option6AddrLst, isc::dhcp::Option6Auth, isc::dhcp::Option6IA, and isc::dhcp::Option6StatusCode.

Definition at line 86 of file option.cc.

◆ cloneInternal()

template<typename OptionType >
OptionPtr isc::dhcp::Option::cloneInternal ( ) const
inlineprotected

Copies this option and returns a pointer to the copy.

The deep copy of the option is performed by calling copy constructor of the option of a given type. Derived classes call this method in the implementations of clone methods to create a copy of the option of their type.

Template Parameters
OptionTypeType of the option of which a clone should be created.

Definition at line 478 of file option.h.

Referenced by isc::dhcp::OptionInt< T >::clone(), and isc::dhcp::OptionIntArray< T >::clone().

◆ create() [1/2]

OptionPtr isc::dhcp::Option::create ( Universe  u,
uint16_t  type 
)
static

Factory function creating an instance of the Option.

This function should be used to create an instance of the DHCP option 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.

Parameters
uspecifies universe (V4 or V6)
typeoption type (0-255 for V4 and 0-65535 for V6)
Returns
Pointer to the Option instance.

Definition at line 64 of file option.cc.

◆ create() [2/2]

OptionPtr isc::dhcp::Option::create ( Universe  u,
uint16_t  type,
const OptionBuffer data 
)
static

Factory function creating an instance of the Option.

This function should be used to create an instance of the DHCP option 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.

Parameters
uspecifies universe (V4 or V6)
typeoption type (0-255 for V4 and 0-65535 for V6)
datacontent of the option
Returns
Pointer to the Option instance.

Definition at line 69 of file option.cc.

◆ delOption()

bool isc::dhcp::Option::delOption ( uint16_t  type)

Attempts to delete first suboption of requested type.

Parameters
typeType of option to be deleted.
Returns
true if option was deleted, false if no such option existed

Definition at line 234 of file option.cc.

References options_.

◆ equals() [1/2]

bool isc::dhcp::Option::equals ( const OptionPtr other) const

Checks if options are equal.

This method calls a virtual equals function to compare objects. This method is not meant to be overridden in the derived classes. Instead, the other equals function must be overridden.

Parameters
otherPointer to the option to compare this option to.
Returns
true if both options are equal, false otherwise.

Definition at line 392 of file option.cc.

◆ equals() [2/2]

bool isc::dhcp::Option::equals ( const Option other) const
virtual

Checks if two options are equal.

Equality verifies option type and option content. Care should be taken when using this method. Implementation for derived classes should be provided when this method is expected to be used. It is safe in general, as the first check (different types) will detect differences between base Option and derived objects.

Parameters
otherInstance of the option to compare to.
Returns
true if options are equal, false otherwise.

Definition at line 396 of file option.cc.

References getData(), and getType().

+ Here is the call graph for this function:

◆ factory() [1/2]

OptionPtr isc::dhcp::Option::factory ( Option::Universe  u,
uint16_t  type,
const OptionBuffer buf 
)
static

Factory function to create instance of option.

Factory method creates instance of specified option. The option to be created has to have corresponding factory function registered with LibDHCP::OptionFactoryRegister.

Parameters
uuniverse of the option (V4 or V6)
typeoption-type
bufoption-buffer
Returns
instance of option.
Exceptions
isc::InvalidOperationif there is no factory function registered for specified option type.

Definition at line 33 of file option.cc.

◆ factory() [2/2]

static OptionPtr isc::dhcp::Option::factory ( Option::Universe  u,
uint16_t  type 
)
inlinestatic

Factory function to create instance of option.

Factory method creates instance of specified option. The option to be created has to have corresponding factory function registered with LibDHCP::OptionFactoryRegister. This method creates empty OptionBuffer object. Use this factory function if it is not needed to pass custom buffer.

Parameters
uuniverse of the option (V4 or V6)
typeoption-type
Returns
instance of option.
Exceptions
isc::InvalidOperationif there is no factory function registered for specified option type.

Definition at line 130 of file option.h.

◆ getData()

virtual const OptionBuffer& isc::dhcp::Option::getData ( ) const
inlinevirtual

Returns pointer to actual data.

Returns
pointer to actual data (or reference to an empty vector if there is no data)

Definition at line 310 of file option.h.

Referenced by equals(), isc::dhcp::OptionString::getValue(), isc::dhcp::OptionCustom::initialize(), isc::dhcp::OptionString::len(), isc::dhcp::OptionCustom::OptionCustom(), and isc::dhcp::OptionString::pack().

◆ getEncapsulatedSpace()

std::string isc::dhcp::Option::getEncapsulatedSpace ( ) const
inline

Returns the name of the option space encapsulated by this option.

Returns
name of the option space encapsulated by this option.

Definition at line 423 of file option.h.

Referenced by isc::dhcp::OptionCustom::addArrayDataField(), and unpackOptions().

◆ getHeaderLen()

◆ getOption()

OptionPtr isc::dhcp::Option::getOption ( uint16_t  type) const

Returns shared_ptr to suboption of specific type.

Parameters
typetype of requested suboption
Returns
shared_ptr to requested suboption

Definition at line 211 of file option.cc.

References options_.

Referenced by addOption(), isc::ha::CommunicationState6::analyzeMessageInternal(), isc::dhcp::Pkt6::getMACFromDocsisCMTS(), isc::dhcp::Pkt6::getMACFromDocsisModem(), isc::dhcp::CfgSubnets4::initSelector(), and isc::dhcp::Dhcpv6Srv::requiredClassify().

◆ getOptions()

const OptionCollection& isc::dhcp::Option::getOptions ( ) const
inline

Returns all encapsulated options.

Warning
This function returns a reference to the container holding encapsulated options, which is valid as long as the object which returned it exists.

Definition at line 338 of file option.h.

Referenced by isc::dhcp::Dhcpv6Srv::processConfirm().

◆ getOptionsCopy()

void isc::dhcp::Option::getOptionsCopy ( OptionCollection options_copy) const

Performs deep copy of suboptions.

This method calls clone method to deep copy each option.

Parameters
[out]options_copyContainer where copied options are stored.

Definition at line 221 of file option.cc.

References isc::data::copy(), and options_.

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

+ Here is the call graph for this function:

◆ getType()

◆ getUint16()

uint16_t isc::dhcp::Option::getUint16 ( ) const

Returns content of first word.

Exceptions
isc::OutOfRangeThrown if the option has a length less than 2.
Returns
uint16_t value stored on first two bytes

Definition at line 367 of file option.cc.

References data_, and isc::util::readUint16().

+ Here is the call graph for this function:

◆ getUint32()

uint32_t isc::dhcp::Option::getUint32 ( ) const

Returns content of first double word.

Exceptions
isc::OutOfRangeThrown if the option has a length less than 4.
Returns
uint32_t value stored on first four bytes

Definition at line 372 of file option.cc.

References data_, and isc::util::readUint32().

+ Here is the call graph for this function:

◆ getUint8()

uint8_t isc::dhcp::Option::getUint8 ( ) const

Returns content of first byte.

Exceptions
isc::OutOfRangeThrown if the option has a length of 0.
Returns
value of the first byte

Definition at line 359 of file option.cc.

References data_, isc_throw, and type_.

◆ getUniverse()

◆ headerToText()

std::string isc::dhcp::Option::headerToText ( const int  indent = 0,
const std::string &  type_name = "" 
) const
protected

Returns option header in the textual format.

This protected method should be called by the derived classes in their respective toText implementations.

Parameters
indentNumber of spaces to insert before the text.
type_nameOption type name. If empty, the option name is omitted.
Returns
Option header in the textual format.

Definition at line 304 of file option.cc.

References getHeaderLen(), getUniverse(), len(), type_, and V4.

Referenced by isc::dhcp::Option6AddrLst::toText(), isc::dhcp::Option6IA::toText(), isc::dhcp::Option6StatusCode::toText(), isc::dhcp::Option6IAAddr::toText(), isc::dhcp::Option6PDExclude::toText(), isc::dhcp::OptionVendor::toText(), isc::dhcp::Option4AddrLst::toText(), isc::dhcp::Option6IAPrefix::toText(), isc::dhcp::OptionString::toText(), isc::dhcp::Option4SlpServiceScope::toText(), isc::dhcp::OptionInt< T >::toText(), toText(), isc::dhcp::OptionIntArray< T >::toText(), and isc::dhcp::OptionCustom::toText().

+ Here is the call graph for this function:

◆ len()

◆ operator=()

Option & isc::dhcp::Option::operator= ( const Option rhs)

Assignment operator.

The assignment operator performs a deep copy of the option and its suboptions. It calls getOptionsCopy to deep copy suboptions.

Parameters
rhsOption to be assigned.

Definition at line 74 of file option.cc.

References data_, encapsulated_space_, getOptionsCopy(), options_, type_, and universe_.

Referenced by isc::dhcp::Option6ClientFqdn::operator=(), and isc::dhcp::Option4ClientFqdn::operator=().

+ Here is the call graph for this function:

◆ pack()

void isc::dhcp::Option::pack ( isc::util::OutputBuffer buf) const
virtual

Writes option in wire-format to a buffer.

Writes option in wire-format to buffer, returns pointer to first unused byte after stored option (that is useful for writing options one after another).

Parameters
bufpointer to a buffer
Exceptions
BadValueUniverse of the option is neither V4 nor V6.

Reimplemented in isc::dhcp::OptionCustom, isc::dhcp::Option4ClientFqdn, isc::dhcp::Option6ClientFqdn, isc::dhcp::Option4SlpServiceScope, isc::dhcp::OptionIntArray< T >, isc::dhcp::OptionInt< T >, isc::dhcp::Option4AddrLst, isc::dhcp::OptionString, isc::dhcp::Option6IAPrefix, isc::dhcp::OptionVendorClass, isc::dhcp::OptionOpaqueDataTuples, isc::dhcp::Option6PDExclude, isc::dhcp::OptionVendor, isc::dhcp::Option6IAAddr, isc::dhcp::Option6AddrLst, isc::dhcp::Option6Auth, isc::dhcp::Option6IA, and isc::dhcp::Option6StatusCode.

Definition at line 114 of file option.cc.

References data_, packHeader(), packOptions(), and isc::util::OutputBuffer::writeData().

Referenced by toBinary().

+ Here is the call graph for this function:

◆ packHeader()

void isc::dhcp::Option::packHeader ( isc::util::OutputBuffer buf) const
protected

Store option's header in a buffer.

This method writes option's header into a buffer in the on-wire format. The universe set for the particular option is used to determine whether option code and length are stored as 2-byte (for DHCPv6) or single-byte (for DHCPv4) values. For DHCPv4 options, this method checks if the length does not exceed 255 bytes and throws exception if it does. This method is used by derived classes to pack option's header into a buffer. This method should not be called directly by other classes.

Parameters
[out]bufoutput buffer.

TODO Larger options can be stored as separate instances of DHCPv4 options. Clients MUST concatenate them. Fortunately, there are no such large options used today.

Definition at line 126 of file option.cc.

References getHeaderLen(), isc_throw, len(), type_, universe_, V4, isc::util::OutputBuffer::writeUint16(), and isc::util::OutputBuffer::writeUint8().

Referenced by isc::dhcp::Option6StatusCode::pack(), isc::dhcp::OptionVendor::pack(), isc::dhcp::Option6PDExclude::pack(), isc::dhcp::OptionOpaqueDataTuples::pack(), isc::dhcp::OptionVendorClass::pack(), isc::dhcp::OptionString::pack(), isc::dhcp::OptionInt< T >::pack(), isc::dhcp::OptionIntArray< T >::pack(), isc::dhcp::Option4SlpServiceScope::pack(), isc::dhcp::Option6ClientFqdn::pack(), pack(), isc::dhcp::Option4ClientFqdn::pack(), and isc::dhcp::OptionCustom::pack().

+ Here is the call graph for this function:

◆ packOptions()

void isc::dhcp::Option::packOptions ( isc::util::OutputBuffer buf) const
protected

Store sub options in a buffer.

This method stores all sub-options defined for a particular option in a on-wire format in output buffer provided. This function is called by pack function in this class or derived classes that override pack.

Parameters
[out]bufoutput buffer.
Todo:
The set of exceptions thrown by this function depend on exceptions thrown by pack methods invoked on objects representing sub options. We should consider whether to aggregate those into one exception which can be documented here.

Definition at line 146 of file option.cc.

References isc_throw, options_, isc::dhcp::LibDHCP::packOptions4(), isc::dhcp::LibDHCP::packOptions6(), universe_, V4, and V6.

Referenced by isc::dhcp::Option6IA::pack(), isc::dhcp::Option6IAAddr::pack(), isc::dhcp::OptionVendor::pack(), isc::dhcp::Option6IAPrefix::pack(), isc::dhcp::OptionInt< T >::pack(), pack(), and isc::dhcp::OptionCustom::pack().

+ Here is the call graph for this function:

◆ setData()

template<typename InputIterator >
void isc::dhcp::Option::setData ( InputIterator  first,
InputIterator  last 
)
inline

Sets content of this option from buffer.

Option will be resized to length of buffer.

Parameters
firstiterator pointing to beginning of buffer to copy.
lastiterator pointing to end of buffer to copy.
Template Parameters
InputIteratortype of the iterator representing the limits of the buffer to be assigned to a data_ buffer.

Definition at line 408 of file option.h.

Referenced by isc::dhcp::OptionCustom::initialize(), isc::dhcp::OptionString::setValue(), isc::dhcp::OptionString::unpack(), isc::dhcp::Option6ClientFqdn::unpack(), unpack(), isc::dhcp::Option4ClientFqdn::unpack(), and isc::dhcp::OptionCustom::writeInteger().

◆ setEncapsulatedSpace()

void isc::dhcp::Option::setEncapsulatedSpace ( const std::string &  encapsulated_space)
inline

Sets the name of the option space encapsulated by this option.

Parameters
encapsulated_spacename of the option space encapsulated by this option.

Definition at line 416 of file option.h.

Referenced by isc::dhcp::Option6IA::Option6IA(), isc::dhcp::Option6IAAddr::Option6IAAddr(), isc::dhcp::Option6IAPrefix::Option6IAPrefix(), isc::dhcp::OptionCustom::OptionCustom(), and isc::dhcp::OptionInt< T >::OptionInt().

◆ setUint16()

void isc::dhcp::Option::setUint16 ( uint16_t  value)

Sets content of this option to a single uint16 value.

Option it resized appropriately (to length of 2 octets).

Parameters
valuevalue to be set

Definition at line 382 of file option.cc.

References data_, and isc::util::writeUint16().

+ Here is the call graph for this function:

◆ setUint32()

void isc::dhcp::Option::setUint32 ( uint32_t  value)

Sets content of this option to a single uint32 value.

Option it resized appropriately (to length of 4 octets).

Parameters
valuevalue to be set

Definition at line 387 of file option.cc.

References data_, and isc::util::writeUint32().

+ Here is the call graph for this function:

◆ setUint8()

void isc::dhcp::Option::setUint8 ( uint8_t  value)

Sets content of this option to a single uint8 value.

Option it resized appropriately (to length of 1 octet).

Parameters
valuevalue to be set

Definition at line 377 of file option.cc.

References data_.

◆ suboptionsToText()

std::string isc::dhcp::Option::suboptionsToText ( const int  indent = 0) const
protected

Returns collection of suboptions in the textual format.

This protected method should be called by the derived classes in their respective toText implementations to append the suboptions held by this option. Note that there are some option types which don't have suboptions because they contain variable length fields. For such options this method is not called.

Parameters
indentNumber of spaces to insert before the text.

Definition at line 323 of file option.cc.

References options_.

Referenced by isc::dhcp::Option6IA::toText(), isc::dhcp::Option6IAAddr::toText(), isc::dhcp::OptionVendor::toText(), isc::dhcp::Option6IAPrefix::toText(), isc::dhcp::OptionInt< T >::toText(), toText(), and isc::dhcp::OptionCustom::toText().

◆ toBinary()

std::vector< uint8_t > isc::dhcp::Option::toBinary ( const bool  include_header = false) const
virtual

Returns binary representation of the option.

Parameters
include_headerBoolean flag which indicates if the output should also contain header fields. The default is that it shouldn't include header fields.
Returns
Vector holding binary representation of the option.

Definition at line 269 of file option.cc.

References isc::util::OutputBuffer::getData(), getHeaderLen(), isc::util::OutputBuffer::getLength(), getType(), isc_throw, len(), and pack().

Referenced by toHexString().

+ Here is the call graph for this function:

◆ toHexString()

std::string isc::dhcp::Option::toHexString ( const bool  include_header = false) const
virtual

Returns string containing hexadecimal representation of option.

Parameters
include_headerBoolean flag which indicates if the output should also contain header fields. The default is that it shouldn't include header fields.
Returns
String containing hexadecimal representation of the option.

Definition at line 290 of file option.cc.

References isc::util::encode::encodeHex(), and toBinary().

+ Here is the call graph for this function:

◆ toString()

std::string isc::dhcp::Option::toString ( ) const
virtual

Returns string representation of the value.

This is terse representation used in cases where client classification refers to a specific option.

Returns
string that represents the value of the option.
Todo:
: Implement actual conversion in derived classes.

Reimplemented in isc::dhcp::OptionString.

Definition at line 263 of file option.cc.

References toText().

+ Here is the call graph for this function:

◆ toText()

std::string isc::dhcp::Option::toText ( int  indent = 0) const
virtual

◆ unpack()

void isc::dhcp::Option::unpack ( OptionBufferConstIter  begin,
OptionBufferConstIter  end 
)
virtual

◆ unpackOptions()

void isc::dhcp::Option::unpackOptions ( const OptionBuffer buf)
protected

Builds a collection of sub options from the buffer.

This method parses the provided buffer and builds a collection of objects representing sub options. This function may throw different exceptions when option assembly fails.

Parameters
bufbuffer to be parsed.
Todo:
The set of exceptions thrown by this function depend on exceptions thrown by unpack methods invoked on objects representing sub options. We should consider whether to aggregate those into one exception which can be documented here.

Definition at line 165 of file option.cc.

References isc::dhcp::DHO_VENDOR_ENCAPSULATED_OPTIONS, getEncapsulatedSpace(), getType(), isc_throw, options_, universe_, isc::dhcp::LibDHCP::unpackOptions4(), isc::dhcp::LibDHCP::unpackOptions6(), V4, and V6.

Referenced by isc::dhcp::OptionCustom::addArrayDataField(), isc::dhcp::Option6IA::unpack(), and isc::dhcp::OptionInt< T >::unpack().

+ Here is the call graph for this function:

◆ valid()

bool isc::dhcp::Option::valid ( ) const
virtual

returns if option is valid (e.g.

option may be truncated)

Returns
true, if option is valid

Reimplemented in isc::perfdhcp::LocalizedOption.

Definition at line 202 of file option.cc.

References universe_, V4, and V6.

Referenced by isc::dhcp::Option6IAAddr::setValid().

Member Data Documentation

◆ data_

OptionBuffer isc::dhcp::Option::data_
protected

◆ encapsulated_space_

std::string isc::dhcp::Option::encapsulated_space_
protected

Name of the option space being encapsulated by this option.

Definition at line 578 of file option.h.

Referenced by operator=().

◆ lenient_parsing_

bool isc::dhcp::Option::lenient_parsing_
static

Governs whether options should be parsed less strictly.

Populated on configuration commit.

When enabled:

  • Tuples are parsed as length-value pairs as usual, but if a length surpasses the total option length, the rest of the option buffer is parsed as the next value. This more commonly affects DHCPv6's vendor class option (16), but it also affects custom options that are defined with tuple fields.

Definition at line 464 of file option.h.

Referenced by isc::dhcp::SrvConfig::configureLowerLevelLibraries(), isc::dhcp::OpaqueDataTuple::unpack(), and ~Option().

◆ OPTION4_HDR_LEN

const size_t isc::dhcp::Option::OPTION4_HDR_LEN = 2
static

length of the usual DHCPv4 option header (there are exceptions)

Definition at line 76 of file option.h.

Referenced by getHeaderLen(), isc::dhcp::Dhcpv4Exchange::initResponse4o6(), isc::dhcp::OptionInt< T >::len(), and isc::dhcp::OptionIntArray< T >::len().

◆ OPTION6_HDR_LEN

◆ options_

◆ type_

◆ universe_


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