Kea
1.9.9-git
|
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 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. More... | |
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. More... | |
void | addClientClass4 (const std::string &class_name) |
Adds new client class for DHCPv4. More... | |
void | addClientClass6 (const std::string &class_name) |
Adds new client class for DHCPv6. More... | |
void | addReservation (const IPv6Resrv &reservation) |
Adds new IPv6 reservation. More... | |
const std::string & | getBootFileName () const |
Returns value of boot file name (file). More... | |
CfgOptionPtr | getCfgOption4 () |
Returns pointer to the DHCPv4 option data configuration for this host. More... | |
ConstCfgOptionPtr | getCfgOption4 () const |
Returns const pointer to the DHCPv4 option data configuration for this host. More... | |
CfgOptionPtr | getCfgOption6 () |
Returns pointer to the DHCPv6 option data configuration for this host. More... | |
ConstCfgOptionPtr | getCfgOption6 () const |
Returns const pointer to the DHCPv6 option data configuration for this host. More... | |
const ClientClasses & | getClientClasses4 () const |
Returns classes which DHCPv4 client is associated with. More... | |
const ClientClasses & | getClientClasses6 () const |
Returns classes which DHCPv6 client is associated with. More... | |
DuidPtr | getDuid () const |
Returns DUID for which the reservations are made. More... | |
HostID | getHostId () const |
Returns Host ID (primary key in MySQL, PostgreSQL and Cassandra backends) More... | |
const std::string & | getHostname () const |
Returns reserved hostname. More... | |
HWAddrPtr | getHWAddress () const |
Returns hardware address for which the reservations are made. More... | |
const std::vector< uint8_t > & | getIdentifier () const |
Returns the identifier in a binary form. More... | |
std::string | getIdentifierAsText () const |
Returns host identifier in a textual form. More... | |
IdentifierType | getIdentifierType () const |
Returns the identifier type. More... | |
const asiolink::IOAddress & | getIPv4Reservation () const |
Returns reserved IPv4 address. More... | |
SubnetID | getIPv4SubnetID () const |
Returns subnet identifier for IPv4 reservation. More... | |
IPv6ResrvRange | getIPv6Reservations (const IPv6Resrv::Type &type) const |
Returns IPv6 reservations of a specified type. More... | |
IPv6ResrvRange | getIPv6Reservations () const |
Returns all IPv6 reservations. More... | |
SubnetID | getIPv6SubnetID () const |
Returns subnet identifier for IPv6 reservations. More... | |
AuthKey | getKey () const |
Returns the key. More... | |
std::string | getLowerHostname () const |
Returns reserved hostname in lower case. More... | |
bool | getNegative () const |
Return the negative cache flag value. More... | |
const asiolink::IOAddress & | getNextServer () const |
Returns value of next server field (siaddr). More... | |
const std::string & | getServerHostname () const |
Returns value of server hostname (sname). More... | |
bool | hasIPv6Reservation () const |
Checks if there is at least one IPv6 reservation for this host. More... | |
bool | hasReservation (const IPv6Resrv &reservation) const |
Checks if specified IPv6 reservation exists for the host. More... | |
void | removeIPv4Reservation () |
Removes the IPv4 reservation. More... | |
void | setBootFileName (const std::string &boot_file_name) |
Sets new value for boot file name (file). More... | |
void | setHostId (HostID id) |
Sets Host ID (primary key in MySQL, PostgreSQL and Cassandra backends) More... | |
void | setHostname (const std::string &hostname) |
Sets new hostname. More... | |
void | setIdentifier (const uint8_t *identifier, const size_t len, const IdentifierType &type) |
Replaces currently used identifier with a new identifier. More... | |
void | setIdentifier (const std::string &identifier, const std::string &name) |
Replaces currently used identifier with a new identifier. More... | |
void | setIPv4Reservation (const asiolink::IOAddress &address) |
Sets new IPv4 reservation. More... | |
void | setIPv4SubnetID (const SubnetID ipv4_subnet_id) |
Sets new IPv4 subnet identifier. More... | |
void | setIPv6SubnetID (const SubnetID ipv6_subnet_id) |
Sets new IPv6 subnet identifier. More... | |
void | setKey (const AuthKey &key) |
sets key. More... | |
void | setNegative (bool negative) |
Sets the negative cached flag. More... | |
void | setNextServer (const asiolink::IOAddress &next_server) |
Sets new value for next server field (siaddr). More... | |
void | setServerHostname (const std::string &server_host_name) |
Sets new value for server hostname (sname). More... | |
isc::data::ElementPtr | toElement4 () const |
Unparses (converts to Element representation) IPv4 host. More... | |
isc::data::ElementPtr | toElement6 () const |
Unparses (converts to Element representation) IPv6 host. More... | |
std::string | toText () const |
Returns information about the host in the textual format. More... | |
Public Member Functions inherited from isc::data::UserContext | |
void | contextToElement (data::ElementPtr map) const |
Merge unparse a user_context object. More... | |
data::ConstElementPtr | getContext () const |
Returns const pointer to the user context. More... | |
void | setContext (const data::ConstElementPtr &ctx) |
Sets user context. More... | |
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. More... | |
static std::string | getIdentifierName (const IdentifierType &type) |
Returns name of the identifier of a specified type. More... | |
static IdentifierType | getIdentifierType (const std::string &identifier_name) |
Converts identifier name to identifier type. More... | |
Static Public Member Functions inherited from isc::data::UserContext | |
static data::ElementPtr | toElement (data::ConstElementPtr map) |
Copy an Element map. More... | |
Static Public Attributes | |
static const IdentifierType | LAST_IDENTIFIER_TYPE = IDENT_FLEX |
Constant pointing to the last identifier of the IdentifierType enumeration. More... | |
Additional Inherited Members | |
Protected Attributes inherited from isc::data::UserContext | |
data::ConstElementPtr | user_context_ |
Pointer to the user context (may be NULL) More... | |
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 137 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 175 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 380 of file host.cc.
References isc::dhcp::IPv6Resrv::getType(), hasReservation(), isc_throw, and isc::dhcp::IPv6Resrv::toText().
Referenced by isc::dhcp::CqlHostExchange::retrieve().
|
inline |
Returns value of boot file name (file).
Definition at line 631 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 640 of file host.h.
Referenced by isc::dhcp::CqlHostExchange::retrieve(), and 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 655 of file host.h.
Referenced by isc::dhcp::CqlHostExchange::retrieve(), and toElement6().
|
inline |
|
inline |
Returns classes which DHCPv4 client is associated with.
Definition at line 584 of file host.h.
Referenced by toElement4().
|
inline |
Returns classes which DHCPv6 client is associated with.
Definition at line 594 of file host.h.
Referenced by toElement6().
DuidPtr isc::dhcp::Host::getDuid | ( | ) | const |
Returns DUID for which the reservations are made.
Definition at line 249 of file host.cc.
References IDENT_DUID.
Referenced by toElement4(), and toElement6().
|
inline |
|
inline |
Returns reserved hostname.
Definition at line 569 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 243 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 212 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 256 of file host.cc.
Referenced by isc::dhcp::HostMgr::get4Any(), isc::dhcp::HostMgr::get6Any(), isc::dhcp::Dhcpv6Srv::initContext(), 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 262 of file host.cc.
References isc::util::encode::encodeHex(), IDENT_CIRCUIT_ID, IDENT_CLIENT_ID, IDENT_DUID, IDENT_FLEX, and IDENT_HWADDR.
|
static |
Returns name of the identifier of a specified type.
Definition at line 293 of file host.cc.
References IDENT_CIRCUIT_ID, IDENT_CLIENT_ID, IDENT_DUID, IDENT_FLEX, and IDENT_HWADDR.
Referenced by isc::dhcp::HostReservationIdsParser::parseInternal(), and isc::dhcp::CfgHostOperations::toElement().
Host::IdentifierType isc::dhcp::Host::getIdentifierType | ( | ) | const |
Returns the identifier type.
Definition at line 217 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 222 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 525 of file host.h.
Referenced by toElement4().
|
inline |
IPv6ResrvRange isc::dhcp::Host::getIPv6Reservations | ( | const IPv6Resrv::Type & | type | ) | const |
IPv6ResrvRange isc::dhcp::Host::getIPv6Reservations | ( | ) | const |
Returns all IPv6 reservations.
Definition at line 397 of file host.cc.
Referenced by hasReservation(), and toElement6().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Returns value of next server field (siaddr).
Definition at line 607 of file host.h.
Referenced by toElement4().
|
inline |
Returns value of server hostname (sname).
Definition at line 619 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 408 of file host.cc.
References getIPv6Reservations(), and isc::dhcp::IPv6Resrv::getType().
Referenced by addReservation(), and isc::dhcp::CqlHostExchange::retrieve().
void isc::dhcp::Host::removeIPv4Reservation | ( | ) |
Removes the IPv4 reservation.
Sets the IPv4 reserved address to 0.
Definition at line 375 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 466 of file host.cc.
References isc_throw, and isc::dhcp::Pkt4::MAX_FILE_LEN.
|
inline |
Sets Host ID (primary key in MySQL, PostgreSQL and Cassandra backends)
id | HostId value |
Definition at line 670 of file host.h.
Referenced by isc::dhcp::CqlHostExchange::retrieve().
|
inline |
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 318 of file host.cc.
References isc_throw.
Referenced by Host().
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 329 of file host.cc.
References isc::util::str::decodeFormattedHexString(), getIdentifierType(), isc_throw, and isc::util::str::quotedStringToBinary().
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 363 of file host.cc.
References isc_throw, isc::asiolink::IOAddress::isV4(), isc::asiolink::IOAddress::isV4Bcast(), and isc::asiolink::IOAddress::isV4Zero().
Referenced by 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 444 of file host.cc.
References isc_throw, isc::asiolink::IOAddress::isV4(), and isc::asiolink::IOAddress::isV4Bcast().
Referenced by 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 457 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 475 of file host.cc.
References isc::dhcp::ClientClasses::cbegin(), isc::dhcp::ClientClasses::cend(), isc::data::UserContext::contextToElement(), 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 537 of file host.cc.
References isc::dhcp::ClientClasses::cbegin(), isc::dhcp::ClientClasses::cend(), isc::data::UserContext::contextToElement(), 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 601 of file host.cc.
References isc::dhcp::ClientClasses::cbegin(), isc::dhcp::ClientClasses::cend(), 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 317 of file host.h.
Referenced by isc::dhcp::HostReservationIdsParser::parseInternal().