Kea 2.7.5
|
Factory for generating DUIDs (DHCP Unique Identifiers). More...
#include <duid_factory.h>
Public Member Functions | |
DUIDFactory (const std::string &storage_location="") | |
Constructor. | |
void | createEN (const uint32_t enterprise_id, const std::vector< uint8_t > &identifier) |
Generates DUID-EN. | |
void | createLL (const uint16_t htype, const std::vector< uint8_t > &ll_identifier) |
Generates DUID-LL. | |
void | createLLT (const uint16_t htype, const uint32_t time_in, const std::vector< uint8_t > &ll_identifier) |
Generates DUID-LLT. | |
DuidPtr | get () |
Returns current DUID. | |
bool | isStored () const |
Checks if generated DUID will be stored in the file. | |
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:
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.
isc::dhcp::DUIDFactory::DUIDFactory | ( | const std::string & | storage_location = "" | ) |
Constructor.
storage_location | Absolute path to the file where DUID is stored. |
Definition at line 43 of file duid_factory.cc.
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).
enterprise_id | Enterprise id. If this value is 0, a value from existing DUID is used or ISC's enterprise id if there is no DUID yet. |
identifier | Data 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, isc::util::fillRandom(), isc::util::readUint32(), isc::util::writeUint16(), and isc::util::writeUint32().
Referenced by isc::dhcp::CfgDUID::create(), and get().
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).
htype | Hardware 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_identifier | Data 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. |
isc::Unexpected | if 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::util::readUint16(), and isc::util::writeUint16().
Referenced by isc::dhcp::CfgDUID::create().
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).
htype | Hardware 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_in | Explicit 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_identifier | Data 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. |
isc::Unexpected | if 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().
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.
Definition at line 343 of file duid_factory.cc.
References createEN(), and createLLT().
Referenced by isc::dhcp::Dhcpv6Srv::Dhcpv6Srv(), and isc::dhcp::CfgDUID::create().
bool isc::dhcp::DUIDFactory::isStored | ( | ) | const |
Checks if generated DUID will be stored in the file.
Definition at line 48 of file duid_factory.cc.