Kea  2.1.7-git
isc::dhcp::DUIDFactory Class Reference

Factory for generating DUIDs (DHCP Unique Identifiers). More...

#include <duid_factory.h>

+ Inheritance diagram for isc::dhcp::DUIDFactory:

Public Member Functions

 DUIDFactory (const std::string &storage_location="")
 Constructor. More...
 
void createEN (const uint32_t enterprise_id, const std::vector< uint8_t > &identifier)
 Generates DUID-EN. More...
 
void createLL (const uint16_t htype, const std::vector< uint8_t > &ll_identifier)
 Generates DUID-LL. More...
 
void createLLT (const uint16_t htype, const uint32_t time_in, const std::vector< uint8_t > &ll_identifier)
 Generates DUID-LLT. More...
 
DuidPtr get ()
 Returns current DUID. More...
 
bool isStored () const
 Checks if generated DUID will be stored in the file. More...
 

Detailed Description

Factory for generating DUIDs (DHCP Unique Identifiers).

DHCPv6 clients and servers are identified by DUIDs (see RFC 8415). DUIDs are unique identifiers carried in the appropriate DHCP options. RFC 8415 defines 4 types of DUIDs:

  1. DUID-LLT
  2. DUID-EN
  3. DUID-LL
  4. DUID-UUID

of which the DUID-LLT is recommended for all general purpose computing devices. Future specifications may define new DUID types. The current implementation of the class only supports DUID types defined in RFC 8415.

In most cases DUIDs can be generated automatically, i.e. no manual configuration is required. For example, DUID-LLT is composed of the current time and link layer address and type of one of the network interfaces. Once the DUID is generated it should be stored in the persistent storage and used by a server or client even when the network interface which address had been used to generate the DUID is removed.

In some cases administrators may elect to use other types of DUIDs, which are easier to generate (in case of lack of persistent storage or when specifics of the device favors some generation methods), e.g. DUID-EN doesn't rely on the link layer addresses of interfaces present in the system.

In some cases administrators may want to influence the value of the generated DUID. For example, DUID-EN includes enterprise identifier and the administrator may want to select this identifier.

This class allows for selecting a type of DUID to be generated. It also allows for setting desired values for the components of the DUIDs being generated, while leaving other components unspecified. For example an administrator may elect to set the enterprise id for the DUID-EN and leave the variable length identifier unspecified. The variable length identifier will be autogenerated.

This class is also responsible for storing the generated DUID in a file. The location of this file is specified in the class constructor. If this location is not specified the DUID is not stored, i.e. is lost when the server or client shuts down. However, the DUID may be reconstructed according to the configuration of the client or server when they are back online.

Definition at line 63 of file duid_factory.h.

Constructor & Destructor Documentation

◆ DUIDFactory()

isc::dhcp::DUIDFactory::DUIDFactory ( const std::string &  storage_location = "")

Constructor.

Parameters
storage_locationAbsolute path to the file where DUID is stored.

Definition at line 43 of file duid_factory.cc.

Member Function Documentation

◆ createEN()

void isc::dhcp::DUIDFactory::createEN ( const uint32_t  enterprise_id,
const std::vector< uint8_t > &  identifier 
)

Generates DUID-EN.

This method generates DUID-EN (DUID Enterprise).

Parameters
enterprise_idEnterprise id. If this value is 0, a value from existing DUID is used or ISC's enterprise id if there is no DUID yet.
identifierData to be used as variable length identifier. If this is an empty vector, an identifier from existing DUID is used. If there is no DUID yet, the 6-bytes long vector with random values is generated.

Definition at line 121 of file duid_factory.cc.

References isc::dhcp::DUID::DUID_EN, and isc::util::readUint32().

Referenced by isc::dhcp::CfgDUID::create(), and get().

+ Here is the call graph for this function:

◆ createLL()

void isc::dhcp::DUIDFactory::createLL ( const uint16_t  htype,
const std::vector< uint8_t > &  ll_identifier 
)

Generates DUID-LL.

This method generates DUID-LL (Link Layer).

Parameters
htypeHardware type. If this is set to 0 and link layer address is empty a value from existing DUID or a default value of HTYPE_ETHER is used. Otherwise a link layer type of selected interface is used.
ll_identifierData to be used as link layer address. If this is an empty vector this method will try to use link layer address from existing DUID. If there is no DUID yet, it will iterate over all active interfaces and will pick link layer address of one of them.
Exceptions
isc::Unexpectedif none of the interfaces includes has a suitable link layer address.

Definition at line 188 of file duid_factory.cc.

References isc::dhcp::DUID::DUID_LL, isc::dhcp::HTYPE_ETHER, isc::dhcp::IfaceMgr::instance(), isc_throw, isc::util::isRangeZero(), isStored(), isc::dhcp::DUID::MIN_DUID_LEN, isc::util::readUint16(), isc::dhcp::DUID::toText(), and isc::util::writeUint16().

Referenced by isc::dhcp::CfgDUID::create().

+ Here is the call graph for this function:

◆ createLLT()

void isc::dhcp::DUIDFactory::createLLT ( const uint16_t  htype,
const uint32_t  time_in,
const std::vector< uint8_t > &  ll_identifier 
)

Generates DUID-LLT.

This method generates DUID-LLT (Link Layer plus Time).

Parameters
htypeHardware type. If this is set to 0 and link layer address is empty a value from existing DUID or a default value of HTYPE_ETHER is used. Otherwise a link layer type of selected interface is used.
time_inExplicit value of time for the DUID. If this is set to 0 a value from existing DUID or current time is used, otherwise a value specified is used.
ll_identifierData to be used as link layer address. If this is an empty vector this method will try to use link layer address from existing DUID. If there is no DUID yet, it will iterate over all active interfaces and will pick link layer address of one of them.
Exceptions
isc::Unexpectedif none of the interfaces includes has a suitable link layer address.

Definition at line 53 of file duid_factory.cc.

References isc::dhcp::DUID::DUID_LLT, DUID_TIME_EPOCH, isc::dhcp::HTYPE_ETHER, isc::util::readUint16(), isc::util::readUint32(), isc::util::writeUint16(), and isc::util::writeUint32().

Referenced by isc::dhcp::CfgDUID::create(), and get().

+ Here is the call graph for this function:

◆ get()

DuidPtr isc::dhcp::DUIDFactory::get ( )

Returns current DUID.

This method first checks if the DUID has been generated, i.e. as a result of calling DUIDFactory::createLLT. If the DUID hasn't been generated, this method will try to read the DUID from the persistent storage. If the DUID is found in persistent storage it is returned. Otherwise, the DUID-LLT is generated and returned. In some cases the generation of the DUID-LLT may fail, e.g. when there are no interfaces with a suitable link layer address. In this case, this method will generate DUID-EN, with the ISC enterprise id. If this fails, e.g. as a result of error while storing the generated DUID-EN, exception is thrown.

Returns
Instance of the DUID read from file, or generated.

Definition at line 343 of file duid_factory.cc.

References createEN(), createLLT(), isc::dhcp::DUID::fromText(), and isStored().

Referenced by isc::dhcp::CfgDUID::create(), and isc::dhcp::Dhcpv6Srv::Dhcpv6Srv().

+ Here is the call graph for this function:

◆ isStored()

bool isc::dhcp::DUIDFactory::isStored ( ) const

Checks if generated DUID will be stored in the file.

Returns
true if generated DUIDs are stored in a file, false otherwise.

Definition at line 48 of file duid_factory.cc.

Referenced by createLL(), and get().


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