Kea 2.7.6
|
Represents a device with IPv4 and/or IPv6 reservations. More...
#include <host.h>
Public Types | |
enum | IdentifierType { IDENT_HWADDR , IDENT_DUID , IDENT_CIRCUIT_ID , IDENT_CLIENT_ID , IDENT_FLEX } |
Type of the host identifier. More... | |
Public Member Functions | |
Host (const std::string &identifier, const std::string &identifier_name, const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id, const asiolink::IOAddress &ipv4_reservation, const std::string &hostname="", const std::string &dhcp4_client_classes="", const std::string &dhcp6_client_classes="", const asiolink::IOAddress &next_server=asiolink::IOAddress::IPV4_ZERO_ADDRESS(), const std::string &server_host_name="", const std::string &boot_file_name="", const AuthKey &auth_key=AuthKey("")) | |
Constructor. | |
Host (const uint8_t *identifier, const size_t identifier_len, const IdentifierType &identifier_type, const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id, const asiolink::IOAddress &ipv4_reservation, const std::string &hostname="", const std::string &dhcp4_client_classes="", const std::string &dhcp6_client_classes="", const asiolink::IOAddress &next_server=asiolink::IOAddress::IPV4_ZERO_ADDRESS(), const std::string &server_host_name="", const std::string &boot_file_name="", const AuthKey &auth_key=AuthKey("")) | |
Constructor. | |
void | addClientClass4 (const std::string &class_name) |
Adds new client class for DHCPv4. | |
void | addClientClass6 (const std::string &class_name) |
Adds new client class for DHCPv6. | |
void | addReservation (const IPv6Resrv &reservation) |
Adds new IPv6 reservation. | |
void | encapsulateOptions () const |
Encapsulates host-specific options with their suboptions. | |
const std::string & | getBootFileName () const |
Returns value of boot file name (file). | |
CfgOptionPtr | getCfgOption4 () |
Returns pointer to the DHCPv4 option data configuration for this host. | |
ConstCfgOptionPtr | getCfgOption4 () const |
Returns const pointer to the DHCPv4 option data configuration for this host. | |
CfgOptionPtr | getCfgOption6 () |
Returns pointer to the DHCPv6 option data configuration for this host. | |
ConstCfgOptionPtr | getCfgOption6 () const |
Returns const pointer to the DHCPv6 option data configuration for this host. | |
const ClientClasses & | getClientClasses4 () const |
Returns classes which DHCPv4 client is associated with. | |
const ClientClasses & | getClientClasses6 () const |
Returns classes which DHCPv6 client is associated with. | |
DuidPtr | getDuid () const |
Returns DUID for which the reservations are made. | |
HostID | getHostId () const |
Returns Host ID (primary key in MySQL and PostgreSQL backends) | |
const std::string & | getHostname () const |
Returns reserved hostname. | |
HWAddrPtr | getHWAddress () const |
Returns hardware address for which the reservations are made. | |
const std::vector< uint8_t > & | getIdentifier () const |
Returns the identifier in a binary form. | |
std::string | getIdentifierAsText () const |
Returns host identifier in a textual form. | |
IdentifierType | getIdentifierType () const |
Returns the identifier type. | |
const asiolink::IOAddress & | getIPv4Reservation () const |
Returns reserved IPv4 address. | |
SubnetID | getIPv4SubnetID () const |
Returns subnet identifier for IPv4 reservation. | |
IPv6ResrvRange | getIPv6Reservations () const |
Returns all IPv6 reservations. | |
IPv6ResrvRange | getIPv6Reservations (const IPv6Resrv::Type &type) const |
Returns IPv6 reservations of a specified type. | |
SubnetID | getIPv6SubnetID () const |
Returns subnet identifier for IPv6 reservations. | |
AuthKey | getKey () const |
Returns the key. | |
std::string | getLowerHostname () const |
Returns reserved hostname in lower case. | |
bool | getNegative () const |
Return the negative cache flag value. | |
const asiolink::IOAddress & | getNextServer () const |
Returns value of next server field (siaddr). | |
const std::string & | getServerHostname () const |
Returns value of server hostname (sname). | |
bool | hasIPv6Reservation () const |
Checks if there is at least one IPv6 reservation for this host. | |
bool | hasReservation (const IPv6Resrv &reservation) const |
Checks if specified IPv6 reservation exists for the host. | |
void | removeIPv4Reservation () |
Removes the IPv4 reservation. | |
void | setBootFileName (const std::string &boot_file_name) |
Sets new value for boot file name (file). | |
void | setHostId (HostID id) |
Sets Host ID (primary key in MySQL and PostgreSQL backends) | |
void | setHostname (const std::string &hostname) |
Sets new hostname. | |
void | setIdentifier (const std::string &identifier, const std::string &name) |
Replaces currently used identifier with a new identifier. | |
void | setIdentifier (const uint8_t *identifier, const size_t len, const IdentifierType &type) |
Replaces currently used identifier with a new identifier. | |
void | setIPv4Reservation (const asiolink::IOAddress &address) |
Sets new IPv4 reservation. | |
void | setIPv4SubnetID (const SubnetID ipv4_subnet_id) |
Sets new IPv4 subnet identifier. | |
void | setIPv6SubnetID (const SubnetID ipv6_subnet_id) |
Sets new IPv6 subnet identifier. | |
void | setKey (const AuthKey &key) |
sets key. | |
void | setNegative (bool negative) |
Sets the negative cached flag. | |
void | setNextServer (const asiolink::IOAddress &next_server) |
Sets new value for next server field (siaddr). | |
void | setServerHostname (const std::string &server_host_name) |
Sets new value for server hostname (sname). | |
isc::data::ElementPtr | toElement4 () const |
Unparses (converts to Element representation) IPv4 host. | |
isc::data::ElementPtr | toElement6 () const |
Unparses (converts to Element representation) IPv6 host. | |
std::string | toText () const |
Returns information about the host in the textual format. | |
Public Member Functions inherited from isc::data::UserContext | |
void | contextToElement (data::ElementPtr map) const |
Merge unparse a user_context object. | |
data::ConstElementPtr | getContext () const |
Returns const pointer to the user context. | |
void | setContext (const data::ConstElementPtr &ctx) |
Sets user context. | |
Static Public Member Functions | |
static std::string | getIdentifierAsText (const IdentifierType &type, const uint8_t *value, const size_t length) |
Returns host identifier in textual form. | |
static size_t | getIdentifierMaxLength (const IdentifierType &type) |
Get maximum identifier length. | |
static std::string | getIdentifierName (const IdentifierType &type) |
Returns name of the identifier of a specified type. | |
static IdentifierType | getIdentifierType (const std::string &identifier_name) |
Converts identifier name to identifier type. | |
Static Public Member Functions inherited from isc::data::UserContext | |
static data::ElementPtr | toElement (data::ConstElementPtr map) |
Copy an Element map. | |
Static Public Attributes | |
static const IdentifierType | LAST_IDENTIFIER_TYPE = IDENT_FLEX |
Constant pointing to the last identifier of the IdentifierType enumeration. | |
Protected Member Functions | |
void | setIdentifierType (const IdentifierType &type) |
Set the identifier type. | |
Additional Inherited Members | |
Protected Attributes inherited from isc::data::UserContext | |
data::ConstElementPtr | user_context_ |
Pointer to the user context (may be NULL) | |
Represents a device with IPv4 and/or IPv6 reservations.
This class represents a network device which can be identified by a unique property, such as MAC address on the interface or client identifier (DUID), and for which some resources are statically assigned:
Note, that "host" in this context has a different meaning from host construed as device attached to a network with (possibly) multiple interfaces. For the MAC address based reservations, each interface on a network device maps to a single Host
object as each Host
object contains at most one MAC address. So, it is possible that a single device is associated with multiple distinct Host
objects if the device has multiple interfaces. Under normal circumstances, a non-mobile dual stack device using one interface should be represented by a single Host
object.
A DHCPv6 DUID is common for all interfaces on a device. Therefore, for DUID based reservations a Host
object may represent a network device with multiple interfaces. However, since Host
objects are grouped by subnets to which device's interfaces are connected a single instance of Host
object usually defines reservations for a single interface.
The Host
object combines reservations for both IPv4 and IPv6 resources to allow for correlation of the information about the dual stack devices using DHCPv4 and DHCPv6 respectively. For example: both the DHCPv4 and DHCPv6 servers may use the same database for storing host reservations, so the information about the DHCPv4 reservations are available for the DHCPv6 server and vice versa. Also, this approach allows for reserving common resources such as host name for DHCPv4 and DHCPv6 clients.
This class also holds pointers to specific DHCP options reserved for a host. Options instances are held in CfgOption
objects. There are two CfgOption
objects in this class, one holding DHCPv4 options, another one holding DHCPv6 options.
Type of the host identifier.
Currently supported identifiers are:
Enumerator | |
---|---|
IDENT_HWADDR | |
IDENT_DUID | |
IDENT_CIRCUIT_ID | |
IDENT_CLIENT_ID | |
IDENT_FLEX | Flexible host identifier. |
isc::dhcp::Host::Host | ( | const uint8_t * | identifier, |
const size_t | identifier_len, | ||
const IdentifierType & | identifier_type, | ||
const SubnetID | ipv4_subnet_id, | ||
const SubnetID | ipv6_subnet_id, | ||
const asiolink::IOAddress & | ipv4_reservation, | ||
const std::string & | hostname = "", | ||
const std::string & | dhcp4_client_classes = "", | ||
const std::string & | dhcp6_client_classes = "", | ||
const asiolink::IOAddress & | next_server = asiolink::IOAddress::IPV4_ZERO_ADDRESS(), | ||
const std::string & | server_host_name = "", | ||
const std::string & | boot_file_name = "", | ||
const AuthKey & | auth_key = AuthKey("") ) |
Constructor.
Creates a Host
object using an identifier in a binary format. This is most useful in cases where the identifier is obtained from the database. The constructor will create an instance of the HWAddr
or DUID
object depending on the identifier type.
identifier | Pointer to the binary value holding an identifier. |
identifier_len | Length of the identifier. |
identifier_type | Type of the identifier (hardware address or DUID). |
ipv4_subnet_id | Identifier of the IPv4 subnet to which the host is connected. |
ipv6_subnet_id | Identifier of the IPv6 subnet to which the host is connected. |
ipv4_reservation | An IPv4 address reserved for the client. If this address is set to 0, there is no reservation. |
hostname | Hostname to be allocated to both DHCPv4 and DHCPv6 clients. This is empty string if hostname is not allocated. |
dhcp4_client_classes | A string holding DHCPv4 client class names separated by commas. The names get trimmed by this constructor. |
dhcp6_client_classes | A string holding DHCPv6 client class names separated by commas. The names get trimmed by this constructor. |
next_server | IPv4 address of next server (siaddr). |
server_host_name | Server host name (a.k.a. sname). |
boot_file_name | Boot file name (a.k.a. file). |
auth_key | Authentication key. |
BadValue | if the provided values are invalid. In particular, if the identifier is invalid. |
Definition at line 177 of file host.cc.
References isc::asiolink::IOAddress::isV4Zero(), setIdentifier(), setIPv4Reservation(), and setNextServer().
isc::dhcp::Host::Host | ( | const std::string & | identifier, |
const std::string & | identifier_name, | ||
const SubnetID | ipv4_subnet_id, | ||
const SubnetID | ipv6_subnet_id, | ||
const asiolink::IOAddress & | ipv4_reservation, | ||
const std::string & | hostname = "", | ||
const std::string & | dhcp4_client_classes = "", | ||
const std::string & | dhcp6_client_classes = "", | ||
const asiolink::IOAddress & | next_server = asiolink::IOAddress::IPV4_ZERO_ADDRESS(), | ||
const std::string & | server_host_name = "", | ||
const std::string & | boot_file_name = "", | ||
const AuthKey & | auth_key = AuthKey("") ) |
Constructor.
Creates Host
object using an identifier in a textual format. This is useful in cases when the reservation is specified in the server configuration file. Identifiers can be specified in the following formats:
Note that it is possible to use textual representation, e.g. 'some identifier', which is converted to a vector of ASCII codes representing characters in a given string, excluding quotes. This is useful in cases when specific identifiers, e.g. circuit-id are manually assigned user friendly values.
identifier | Identifier in the textual format. The expected formats for the hardware address and other identifiers are provided above. |
identifier_name | One of the supported identifiers in the text form as described for IdentifierType. |
ipv4_subnet_id | Identifier of the IPv4 subnet to which the host is connected. |
ipv6_subnet_id | Identifier of the IPv6 subnet to which the host is connected. |
ipv4_reservation | An IPv4 address reserved for the client. If this address is set to 0, there is no reservation. |
hostname | Hostname to be allocated to both DHCPv4 and DHCPv6 clients. This is empty string if hostname is not allocated. |
dhcp4_client_classes | A string holding DHCPv4 client class names separated by commas. The names get trimmed by this constructor. |
dhcp6_client_classes | A string holding DHCPv6 client class names separated by commas. The names get trimmed by this constructor. |
next_server | IPv4 address of next server (siaddr). |
server_host_name | Server host name (a.k.a. sname). |
boot_file_name | Boot file name (a.k.a. file). |
auth_key | Authentication key. |
BadValue | if the provided values are invalid. In particular, if the identifier is invalid. |
Definition at line 215 of file host.cc.
References isc::asiolink::IOAddress::isV4Zero(), setIdentifier(), setIPv4Reservation(), and setNextServer().
void isc::dhcp::Host::addClientClass4 | ( | const std::string & | class_name | ) |
void isc::dhcp::Host::addClientClass6 | ( | const std::string & | class_name | ) |
void isc::dhcp::Host::addReservation | ( | const IPv6Resrv & | reservation | ) |
Adds new IPv6 reservation.
reservation | New IPv6 reservation to be appended. |
Definition at line 458 of file host.cc.
References isc::dhcp::IPv6Resrv::getType(), hasReservation(), isc_throw, and isc::dhcp::IPv6Resrv::toText().
void isc::dhcp::Host::encapsulateOptions | ( | ) | const |
|
inline |
Returns value of boot file name (file).
Definition at line 668 of file host.h.
Referenced by toElement4().
|
inline |
Returns pointer to the DHCPv4 option data configuration for this host.
Returned pointer can be used to add, remove and update options reserved for a host.
Definition at line 677 of file host.h.
Referenced by toElement4().
|
inline |
|
inline |
Returns pointer to the DHCPv6 option data configuration for this host.
Returned pointer can be used to add, remove and update options reserved for a host.
Definition at line 692 of file host.h.
Referenced by toElement6().
|
inline |
|
inline |
Returns classes which DHCPv4 client is associated with.
Definition at line 621 of file host.h.
Referenced by toElement4().
|
inline |
Returns classes which DHCPv6 client is associated with.
Definition at line 631 of file host.h.
Referenced by toElement6().
DuidPtr isc::dhcp::Host::getDuid | ( | ) | const |
Returns DUID for which the reservations are made.
Definition at line 305 of file host.cc.
References IDENT_DUID.
Referenced by toElement4(), and toElement6().
|
inline |
|
inline |
Returns reserved hostname.
Definition at line 606 of file host.h.
Referenced by toElement4(), and toElement6().
HWAddrPtr isc::dhcp::Host::getHWAddress | ( | ) | const |
Returns hardware address for which the reservations are made.
HWAddr
structure or null if the reservation is not associated with a hardware address. Definition at line 299 of file host.cc.
References isc::dhcp::HTYPE_ETHER, and IDENT_HWADDR.
Referenced by toElement4(), and toElement6().
const std::vector< uint8_t > & isc::dhcp::Host::getIdentifier | ( | ) | const |
Returns the identifier in a binary form.
Definition at line 268 of file host.cc.
Referenced by toElement4(), and toElement6().
std::string isc::dhcp::Host::getIdentifierAsText | ( | ) | const |
Returns host identifier in a textual form.
Definition at line 312 of file host.cc.
References getIdentifierAsText().
Referenced by isc::dhcp::CfgHosts::del4(), isc::dhcp::CfgHosts::del6(), isc::dhcp::HostMgr::get4Any(), isc::dhcp::HostMgr::get6Any(), getIdentifierAsText(), isc::dhcp::Dhcpv4Exchange::setHostIdentifiers(), isc::dhcp::Dhcpv6Srv::setHostIdentifiers(), and toText().
|
static |
Returns host identifier in textual form.
type | Identifier type. |
value | Pointer to a buffer holding identifier. |
length | Length of the identifier. |
Definition at line 318 of file host.cc.
References isc::util::encode::encodeHex(), IDENT_CIRCUIT_ID, IDENT_CLIENT_ID, IDENT_DUID, IDENT_FLEX, and IDENT_HWADDR.
|
static |
Get maximum identifier length.
This method returns the maximum identifier length.
type | Identifier type. |
Definition at line 252 of file host.cc.
References IDENT_CLIENT_ID, IDENT_DUID, IDENT_HWADDR, isc::dhcp::ClientId::MAX_CLIENT_ID_LEN, isc::dhcp::DUID::MAX_DUID_LEN, and isc::dhcp::HWAddr::MAX_HWADDR_LEN.
Referenced by setIdentifier(), and setIdentifier().
|
static |
Returns name of the identifier of a specified type.
Definition at line 349 of file host.cc.
References IDENT_CIRCUIT_ID, IDENT_CLIENT_ID, IDENT_DUID, IDENT_FLEX, and IDENT_HWADDR.
Referenced by isc::dhcp::HostReservationIdsParser::parseInternal(), setIdentifier(), and isc::dhcp::CfgHostOperations::toElement().
Host::IdentifierType isc::dhcp::Host::getIdentifierType | ( | ) | const |
Returns the identifier type.
Definition at line 273 of file host.cc.
Referenced by isc::dhcp::CfgHostOperations::addIdentifierType(), setIdentifier(), toElement4(), and toElement6().
|
static |
Converts identifier name to identifier type.
identifier_name | Identifier name. |
Definition at line 278 of file host.cc.
References IDENT_CIRCUIT_ID, IDENT_CLIENT_ID, IDENT_DUID, IDENT_FLEX, IDENT_HWADDR, and isc_throw.
|
inline |
Returns reserved IPv4 address.
Definition at line 562 of file host.h.
Referenced by toElement4().
|
inline |
IPv6ResrvRange isc::dhcp::Host::getIPv6Reservations | ( | ) | const |
Returns all IPv6 reservations.
Definition at line 475 of file host.cc.
Referenced by hasReservation(), and toElement6().
IPv6ResrvRange isc::dhcp::Host::getIPv6Reservations | ( | const IPv6Resrv::Type & | type | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Returns value of next server field (siaddr).
Definition at line 644 of file host.h.
Referenced by toElement4().
|
inline |
Returns value of server hostname (sname).
Definition at line 656 of file host.h.
Referenced by toElement4().
bool isc::dhcp::Host::hasIPv6Reservation | ( | ) | const |
bool isc::dhcp::Host::hasReservation | ( | const IPv6Resrv & | reservation | ) | const |
Checks if specified IPv6 reservation exists for the host.
reservation | A reservation to be checked for the host. |
Definition at line 486 of file host.cc.
References getIPv6Reservations(), and isc::dhcp::IPv6Resrv::getType().
Referenced by addReservation().
void isc::dhcp::Host::removeIPv4Reservation | ( | ) |
Removes the IPv4 reservation.
Sets the IPv4 reserved address to 0.
Definition at line 453 of file host.cc.
References isc::asiolink::IOAddress::IPV4_ZERO_ADDRESS().
void isc::dhcp::Host::setBootFileName | ( | const std::string & | boot_file_name | ) |
Sets new value for boot file name (file).
boot_file_name | New value of boot file name. |
BadValue | if boot file name is longer than 128 bytes. |
Definition at line 543 of file host.cc.
References isc_throw, and isc::dhcp::Pkt4::MAX_FILE_LEN.
|
inline |
|
inline |
void isc::dhcp::Host::setIdentifier | ( | const std::string & | identifier, |
const std::string & | name ) |
Replaces currently used identifier with a new identifier.
This method sets a new identifier type and value for a host. This method is called by the Host
constructor.
identifier | Reference to a new identifier in the textual format. |
name | One of the supported identifiers in the text form as described for IdentifierType. |
BadValue | if the identifier is invalid. |
Definition at line 389 of file host.cc.
References isc::util::str::decodeFormattedHexString(), getIdentifierMaxLength(), getIdentifierType(), isc_throw, and isc::util::str::quotedStringToBinary().
void isc::dhcp::Host::setIdentifier | ( | const uint8_t * | identifier, |
const size_t | len, | ||
const IdentifierType & | type ) |
Replaces currently used identifier with a new identifier.
This method sets a new identifier type and value for a host. This method is called by the Host
constructor.
identifier | Pointer to a buffer holding an identifier. |
len | Length of the identifier that the identifier points to. |
type | Identifier type. |
BadValue | if the identifier is invalid. |
Definition at line 374 of file host.cc.
References getIdentifierMaxLength(), getIdentifierName(), and isc_throw.
Referenced by Host(), and Host().
|
protected |
void isc::dhcp::Host::setIPv4Reservation | ( | const asiolink::IOAddress & | address | ) |
Sets new IPv4 reservation.
The new reservation removes a previous reservation.
address | Address to be reserved for the client. |
isc::BadValue | if the provided address is not an IPv4 address, is a 0 address or broadcast address. |
Definition at line 441 of file host.cc.
References isc_throw, isc::asiolink::IOAddress::isV4(), isc::asiolink::IOAddress::isV4Bcast(), and isc::asiolink::IOAddress::isV4Zero().
Referenced by Host(), and Host().
|
inline |
|
inline |
|
inline |
|
inline |
void isc::dhcp::Host::setNextServer | ( | const asiolink::IOAddress & | next_server | ) |
Sets new value for next server field (siaddr).
next_server | New address of a next server. |
isc::BadValue | if the provided address is not an IPv4 address, is broadcast address. |
Definition at line 521 of file host.cc.
References isc_throw, isc::asiolink::IOAddress::isV4(), and isc::asiolink::IOAddress::isV4Bcast().
Referenced by Host(), and Host().
void isc::dhcp::Host::setServerHostname | ( | const std::string & | server_host_name | ) |
Sets new value for server hostname (sname).
server_host_name | New value for server hostname. |
BadValue | if hostname is longer than 63 bytes. |
Definition at line 534 of file host.cc.
References isc_throw, and isc::dhcp::Pkt4::MAX_SNAME_LEN.
ElementPtr isc::dhcp::Host::toElement4 | ( | ) | const |
Unparses (converts to Element representation) IPv4 host.
Definition at line 552 of file host.cc.
References isc::data::UserContext::contextToElement(), isc::data::Element::create(), isc::data::Element::createList(), isc::data::Element::createMap(), isc::util::encode::encodeHex(), getBootFileName(), getCfgOption4(), getClientClasses4(), getDuid(), getHostname(), getHWAddress(), getIdentifier(), getIdentifierType(), getIPv4Reservation(), getNextServer(), getServerHostname(), IDENT_CIRCUIT_ID, IDENT_CLIENT_ID, IDENT_DUID, IDENT_FLEX, IDENT_HWADDR, isc_throw, isc::asiolink::IOAddress::isV4Zero(), and isc::asiolink::IOAddress::toText().
ElementPtr isc::dhcp::Host::toElement6 | ( | ) | const |
Unparses (converts to Element representation) IPv6 host.
Definition at line 613 of file host.cc.
References isc::data::UserContext::contextToElement(), isc::data::Element::create(), isc::data::Element::createList(), isc::data::Element::createMap(), isc::util::encode::encodeHex(), getCfgOption6(), getClientClasses6(), getDuid(), getHostname(), getHWAddress(), getIdentifier(), getIdentifierType(), getIPv6Reservations(), IDENT_CIRCUIT_ID, IDENT_CLIENT_ID, IDENT_DUID, IDENT_FLEX, IDENT_HWADDR, isc_throw, isc::dhcp::IPv6Resrv::TYPE_NA, and isc::dhcp::IPv6Resrv::TYPE_PD.
std::string isc::dhcp::Host::toText | ( | ) | const |
Returns information about the host in the textual format.
Definition at line 696 of file host.cc.
References getIdentifierAsText(), isc::asiolink::IOAddress::isV4Zero(), isc::asiolink::IOAddress::toText(), and isc::dhcp::AuthKey::toText().
|
static |
Constant pointing to the last identifier of the IdentifierType enumeration.
Definition at line 347 of file host.h.
Referenced by isc::dhcp::HostReservationIdsParser::parseInternal().