Kea
1.9.9-git
|
MySQL Host Data Source. More...
#include <mysql_host_data_source.h>
Classes | |
class | MySqlHostContextAlloc |
Context RAII Allocator. More... | |
Public Member Functions | |
MySqlHostDataSource (const db::DatabaseConnection::ParameterMap ¶meters) | |
Constructor. More... | |
virtual | ~MySqlHostDataSource () |
Virtual destructor. More... | |
virtual void | add (const HostPtr &host) |
Adds a new host to the collection. More... | |
virtual void | commit () |
Commit Transactions. More... | |
virtual bool | del (const SubnetID &subnet_id, const asiolink::IOAddress &addr) |
Attempts to delete hosts by (subnet-id, address) More... | |
virtual bool | del4 (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) |
Attempts to delete a host by (subnet4-id, identifier type, identifier) More... | |
virtual bool | del6 (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) |
Attempts to delete a host by (subnet6-id, identifier type, identifier) More... | |
virtual ConstHostPtr | get4 (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const |
Returns a host connected to the IPv4 subnet. More... | |
virtual ConstHostPtr | get4 (const SubnetID &subnet_id, const asiolink::IOAddress &address) const |
Returns a host connected to the IPv4 subnet and having a reservation for a specified IPv4 address. More... | |
virtual ConstHostPtr | get6 (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const |
Returns a host connected to the IPv6 subnet. More... | |
virtual ConstHostPtr | get6 (const asiolink::IOAddress &prefix, const uint8_t prefix_len) const |
Returns a host using the specified IPv6 prefix. More... | |
virtual ConstHostPtr | get6 (const SubnetID &subnet_id, const asiolink::IOAddress &address) const |
Returns a host connected to the IPv6 subnet and having a reservation for a specified IPv6 address or prefix. More... | |
virtual ConstHostCollection | getAll (const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const |
Return all hosts connected to any subnet for which reservations have been made using a specified identifier. More... | |
virtual ConstHostCollection | getAll4 (const SubnetID &subnet_id) const |
Return all hosts in a DHCPv4 subnet. More... | |
virtual ConstHostCollection | getAll4 (const asiolink::IOAddress &address) const |
Returns a collection of hosts using the specified IPv4 address. More... | |
virtual ConstHostCollection | getAll4 (const SubnetID &subnet_id, const asiolink::IOAddress &address) const |
Returns all hosts connected to the IPv4 subnet and having a reservation for a specified address. More... | |
virtual ConstHostCollection | getAll6 (const SubnetID &subnet_id) const |
Return all hosts in a DHCPv6 subnet. More... | |
virtual ConstHostCollection | getAll6 (const SubnetID &subnet_id, const asiolink::IOAddress &address) const |
Returns all hosts connected to the IPv6 subnet and having a reservation for a specified address or delegated prefix (lease). More... | |
virtual ConstHostCollection | getAllbyHostname (const std::string &hostname) const |
Return all hosts with a hostname. More... | |
virtual ConstHostCollection | getAllbyHostname4 (const std::string &hostname, const SubnetID &subnet_id) const |
Return all hosts with a hostname in a DHCPv4 subnet. More... | |
virtual ConstHostCollection | getAllbyHostname6 (const std::string &hostname, const SubnetID &subnet_id) const |
Return all hosts with a hostname in a DHCPv6 subnet. More... | |
virtual std::string | getDescription () const |
Returns description of the backend. More... | |
virtual std::string | getName () const |
Returns backend name. More... | |
virtual ConstHostCollection | getPage4 (const SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const |
Returns range of hosts in a DHCPv4 subnet. More... | |
virtual ConstHostCollection | getPage4 (size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const |
Returns range of hosts. More... | |
virtual ConstHostCollection | getPage6 (const SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const |
Returns range of hosts in a DHCPv6 subnet. More... | |
virtual ConstHostCollection | getPage6 (size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const |
Returns range of hosts. More... | |
virtual isc::db::DatabaseConnection::ParameterMap | getParameters () const |
Return backend parameters. More... | |
virtual std::string | getType () const |
Return backend type. More... | |
virtual std::pair< uint32_t, uint32_t > | getVersion () const |
Returns backend version. More... | |
virtual bool | isUnusable () |
Flag which indicates if the host manager has at least one unusable connection. More... | |
virtual void | rollback () |
Rollback Transactions. More... | |
virtual bool | setIPReservationsUnique (const bool unique) |
Controls whether IP reservations are unique or non-unique. More... | |
Public Member Functions inherited from isc::dhcp::BaseHostDataSource | |
virtual | ~BaseHostDataSource () |
Default destructor implementation. More... | |
Additional Inherited Members | |
Public Types inherited from isc::dhcp::BaseHostDataSource | |
enum | IdType { ID_HWADDR = 0, ID_DUID = 1 } |
Specifies the type of an identifier. More... | |
MySQL Host Data Source.
This class implements the isc::dhcp::BaseHostDataSource interface to the MySQL database. Use of this backend presupposes that a MySQL database is available and that the Kea schema has been created within it.
Definition at line 40 of file mysql_host_data_source.h.
isc::dhcp::MySqlHostDataSource::MySqlHostDataSource | ( | const db::DatabaseConnection::ParameterMap & | parameters | ) |
Constructor.
Uses the following keywords in the parameters passed to it to connect to the database:
If the database is successfully opened, the version number in the schema_version table will be checked against hard-coded value in the implementation file.
Finally, all the SQL commands are pre-compiled.
parameters | A data structure relating keywords and values concerned with the database. |
isc::dhcp::NoDatabaseName | Mandatory database name not given |
isc::db::DbOpenError | Error opening the database or the schema version is invalid. |
isc::db::DbOperationError | An operation on the open database has failed. |
Definition at line 3158 of file mysql_host_data_source.cc.
|
virtual |
Virtual destructor.
Releases prepared MySQL statements used by the backend.
Definition at line 3162 of file mysql_host_data_source.cc.
|
virtual |
Adds a new host to the collection.
The implementations of this method should guard against duplicate reservations for the same host, where possible. For example, when the reservation for the same HW address and subnet id is added twice, the addHost method should throw an DuplicateEntry exception. Note, that usually it is impossible to guard against adding duplicated host, where one instance is identified by HW address, another one by DUID.
host | Pointer to the new Host object being added. |
Implements isc::dhcp::BaseHostDataSource.
Definition at line 3171 of file mysql_host_data_source.cc.
References isc::db::MySqlTransaction::commit(), isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::INSERT_HOST_NON_UNIQUE_IP, isc::dhcp::MySqlHostDataSourceImpl::INSERT_HOST_UNIQUE_IP, isc::dhcp::MySqlHostDataSourceImpl::INSERT_V4_HOST_OPTION, and isc::dhcp::MySqlHostDataSourceImpl::INSERT_V6_HOST_OPTION.
|
virtual |
Commit Transactions.
Commits all pending database operations.
Reimplemented from isc::dhcp::BaseHostDataSource.
Definition at line 3928 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_.
|
virtual |
Attempts to delete hosts by (subnet-id, address)
This method supports both v4 and v6.
subnet_id | subnet identifier. |
addr | specified address. |
various | exceptions in case of errors |
Implements isc::dhcp::BaseHostDataSource.
Definition at line 3230 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::DEL_HOST_ADDR4, isc::dhcp::MySqlHostDataSourceImpl::DEL_HOST_ADDR6, isc::asiolink::IOAddress::isV4(), isc::db::MLM_TRUE, isc::asiolink::IOAddress::toText(), and isc::asiolink::IOAddress::toUint32().
|
virtual |
Attempts to delete a host by (subnet4-id, identifier type, identifier)
This method supports v4 hosts only.
subnet_id | subnet identifier. |
identifier_type | Identifier type. |
identifier_begin | Pointer to a beginning of a buffer containing an identifier. |
identifier_len | Identifier length. |
various | exceptions in case of errors |
Implements isc::dhcp::BaseHostDataSource.
Definition at line 3271 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::DEL_HOST_SUBID4_ID, and isc::db::MLM_TRUE.
|
virtual |
Attempts to delete a host by (subnet6-id, identifier type, identifier)
This method supports v6 hosts only.
subnet_id | subnet identifier. |
identifier_type | Identifier type. |
identifier_begin | Pointer to a beginning of a buffer containing an identifier. |
identifier_len | Identifier length. |
various | exceptions in case of errors |
Implements isc::dhcp::BaseHostDataSource.
Definition at line 3312 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::DEL_HOST_SUBID6_ID, and isc::db::MLM_TRUE.
|
virtual |
Returns a host connected to the IPv4 subnet.
subnet_id | Subnet identifier. |
identifier_type | Identifier type. |
identifier_begin | Pointer to a beginning of a buffer containing an identifier. |
identifier_len | Identifier length. |
Host
object for which reservation has been made using the specified identifier. Implements isc::dhcp::BaseHostDataSource.
Definition at line 3681 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, and isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID4_DHCPID.
|
virtual |
Returns a host connected to the IPv4 subnet and having a reservation for a specified IPv4 address.
One of the use cases for this method is to detect collisions between dynamically allocated addresses and reserved addresses. When the new address is assigned to a client, the allocation mechanism should check if this address is not reserved for some other host and do not allocate this address if reservation is present.
Implementations of this method should guard against invalid addresses, such as IPv6 address.
subnet_id | Subnet identifier. |
address | reserved IPv4 address. |
Host
object using a specified IPv4 address. Implements isc::dhcp::BaseHostDataSource.
Definition at line 3695 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID_ADDR, isc_throw, isc::asiolink::IOAddress::isV4(), isc::db::MLM_TRUE, and isc::asiolink::IOAddress::toUint32().
|
virtual |
Returns a host connected to the IPv6 subnet.
subnet_id | Subnet identifier. |
identifier_type | Identifier type. |
identifier_begin | Pointer to a beginning of a buffer containing an identifier. |
identifier_len | Identifier length. |
Host
object for which reservation has been made using the specified identifier. Implements isc::dhcp::BaseHostDataSource.
Definition at line 3764 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, and isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID6_DHCPID.
|
virtual |
Returns a host using the specified IPv6 prefix.
prefix | IPv6 prefix for which the Host object is searched. |
prefix_len | IPv6 prefix length. |
Host
object using a specified IPv6 prefix. Implements isc::dhcp::BaseHostDataSource.
Definition at line 3778 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_PREFIX, isc_throw, isc::asiolink::IOAddress::isV6(), isc::db::MLM_TRUE, and isc::asiolink::IOAddress::toText().
|
virtual |
Returns a host connected to the IPv6 subnet and having a reservation for a specified IPv6 address or prefix.
subnet_id | Subnet identifier. |
address | reserved IPv6 address/prefix. |
Host
object using a specified IPv6 address/prefix. Implements isc::dhcp::BaseHostDataSource.
Definition at line 3821 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID6_ADDR, isc_throw, isc::asiolink::IOAddress::isV6(), isc::db::MLM_TRUE, and isc::asiolink::IOAddress::toText().
|
virtual |
Return all hosts connected to any subnet for which reservations have been made using a specified identifier.
This method returns all Host
objects which represent reservations for a specified identifier. This method may return multiple hosts because a particular client may have reservations in multiple subnets.
identifier_type | Identifier type. |
identifier_begin | Pointer to a beginning of a buffer containing an identifier. |
identifier_len | Identifier length. |
Host
objects. Implements isc::dhcp::BaseHostDataSource.
Definition at line 3353 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_DHCPID, and isc::db::MLM_TRUE.
|
virtual |
Return all hosts in a DHCPv4 subnet.
This method returns all Host objects which represent reservations in a specified subnet.
subnet_id | subnet identifier to filter by |
Implements isc::dhcp::BaseHostDataSource.
Definition at line 3387 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID4, and isc::db::MLM_TRUE.
|
virtual |
Returns a collection of hosts using the specified IPv4 address.
This method may return multiple Host
objects if they are connected to different subnets.
address | IPv4 address for which the Host object is searched. |
Host
objects. Implements isc::dhcp::BaseHostDataSource.
Definition at line 3659 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_ADDR, isc::db::MLM_TRUE, and isc::asiolink::IOAddress::toUint32().
|
virtual |
Returns all hosts connected to the IPv4 subnet and having a reservation for a specified address.
In most cases it is desired that there is at most one reservation for a given IPv4 address within a subnet. In a default configuration, the backend does not allow for inserting more than one host with the same IPv4 reservation. In that case, the number of hosts returned by this function is 0 or 1.
If the backend is configured to allow multiple hosts with reservations for the same IPv4 address in the given subnet, this method can return more than one host.
The typical use case when a single IPv4 address is reserved for multiple hosts is when these hosts represent different interfaces of the same machine and each interface comes with a different MAC address. In that case, the same IPv4 address is assigned regardless of which interface is used by the DHCP client to communicate with the server.
subnet_id | Subnet identifier. |
address | reserved IPv4 address. |
Host
objects. Implements isc::dhcp::BaseHostDataSource.
Definition at line 3733 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID_ADDR, isc_throw, isc::asiolink::IOAddress::isV4(), isc::db::MLM_TRUE, and isc::asiolink::IOAddress::toUint32().
|
virtual |
Return all hosts in a DHCPv6 subnet.
This method returns all Host objects which represent reservations in a specified subnet.
subnet_id | subnet identifier to filter by |
Implements isc::dhcp::BaseHostDataSource.
Definition at line 3408 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID6, and isc::db::MLM_TRUE.
|
virtual |
Returns all hosts connected to the IPv6 subnet and having a reservation for a specified address or delegated prefix (lease).
In most cases it is desired that there is at most one reservation for a given IPv6 lease within a subnet. In a default configuration, the backend does not allow for inserting more than one host with the same IPv6 address or prefix. In that case, the number of hosts returned by this function is 0 or 1.
If the backend is configured to allow multiple hosts with reservations for the same IPv6 lease in the given subnet, this method can return more than one host.
The typical use case when a single IPv6 lease is reserved for multiple hosts is when these hosts represent different interfaces of the same machine and each interface comes with a different MAC address. In that case, the same IPv6 lease is assigned regardless of which interface is used by the DHCP client to communicate with the server.
subnet_id | Subnet identifier. |
address | reserved IPv6 address/prefix. |
Host
objects. Implements isc::dhcp::BaseHostDataSource.
Definition at line 3864 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID6_ADDR, isc_throw, isc::asiolink::IOAddress::isV6(), isc::db::MLM_TRUE, and isc::asiolink::IOAddress::toText().
|
virtual |
Return all hosts with a hostname.
This method returns all Host
objects which represent reservations using a specified hostname.
MySQL uses the case-insensitive hosts_by_hostname index on hostname.
hostname | The lower case hostname. |
Host
objects. Implements isc::dhcp::BaseHostDataSource.
Definition at line 3429 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, and isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_HOSTNAME.
|
virtual |
Return all hosts with a hostname in a DHCPv4 subnet.
This method returns all Host
objects which represent reservations using a specified hostname in a specified subnet.
hostname | The lower case hostname. |
subnet_id | Subnet identifier. |
Host
objects. Implements isc::dhcp::BaseHostDataSource.
Definition at line 3455 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_HOSTNAME_SUBID4, and isc::db::MLM_TRUE.
|
virtual |
Return all hosts with a hostname in a DHCPv6 subnet.
This method returns all Host
objects which represent reservations using a specified hostname in a specified subnet.
hostname | The lower case hostname. |
subnet_id | Subnet identifier. |
Host
objects. Implements isc::dhcp::BaseHostDataSource.
Definition at line 3488 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_HOSTNAME_SUBID6, and isc::db::MLM_TRUE.
|
virtual |
Returns description of the backend.
This description may be multiline text that describes the backend.
Definition at line 3917 of file mysql_host_data_source.cc.
|
virtual |
Returns backend name.
Each backend have specific name.
Definition at line 3902 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_.
|
virtual |
Returns range of hosts in a DHCPv4 subnet.
This method returns a page of Host
objects which represent reservations in a specified subnet.
subnet_id | Subnet identifier. |
source_index | Index of the source (unused). |
lower_host_id | Host identifier used as lower bound for the returned range. |
page_size | maximum size of the page returned. |
Host
objects (may be empty). Implements isc::dhcp::BaseHostDataSource.
Definition at line 3521 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID4_PAGE, isc::db::MLM_TRUE, and isc::dhcp::HostPageSize::page_size_.
|
virtual |
Returns range of hosts.
This method returns a page of Host
objects which represent reservations.
source_index | Index of the source (unused). |
lower_host_id | Host identifier used as lower bound for the returned range. |
page_size | maximum size of the page returned. |
Host
objects (may be empty). Implements isc::dhcp::BaseHostDataSource.
Definition at line 3597 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_PAGE4, isc::db::MLM_TRUE, and isc::dhcp::HostPageSize::page_size_.
|
virtual |
Returns range of hosts in a DHCPv6 subnet.
This method returns a page of Host
objects which represent reservations in a specified subnet.
subnet_id | Subnet identifier. |
source_index | Index of the source (unused). |
lower_host_id | Host identifier used as lower bound for the returned range. |
page_size | maximum size of the page returned. |
Host
objects (may be empty). Implements isc::dhcp::BaseHostDataSource.
Definition at line 3559 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID6_PAGE, isc::db::MLM_TRUE, and isc::dhcp::HostPageSize::page_size_.
|
virtual |
Returns range of hosts.
This method returns a page of Host
objects which represent reservations.
source_index | Index of the source (unused). |
lower_host_id | Host identifier used as lower bound for the returned range. |
page_size | maximum size of the page returned. |
Host
objects (may be empty). Implements isc::dhcp::BaseHostDataSource.
Definition at line 3628 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_, isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_PAGE6, isc::db::MLM_TRUE, and isc::dhcp::HostPageSize::page_size_.
|
virtual |
Return backend parameters.
Returns the backend parameters
Reimplemented from isc::dhcp::BaseHostDataSource.
Definition at line 3166 of file mysql_host_data_source.cc.
|
inlinevirtual |
Return backend type.
Returns the type of the backend (e.g. "mysql", "memfile" etc.)
Implements isc::dhcp::BaseHostDataSource.
Definition at line 411 of file mysql_host_data_source.h.
|
virtual |
Returns backend version.
isc::db::DbOperationError | An operation on the open database has failed. |
Definition at line 3923 of file mysql_host_data_source.cc.
|
virtual |
Flag which indicates if the host manager has at least one unusable connection.
Reimplemented from isc::dhcp::BaseHostDataSource.
Definition at line 3956 of file mysql_host_data_source.cc.
|
virtual |
Rollback Transactions.
Rolls back all pending database operations.
Reimplemented from isc::dhcp::BaseHostDataSource.
Definition at line 3939 of file mysql_host_data_source.cc.
References isc::dhcp::MySqlHostDataSource::MySqlHostContextAlloc::ctx_.
|
virtual |
Controls whether IP reservations are unique or non-unique.
In a typical case, the IP reservations are unique and backends verify prior to adding a host reservation to the database that the reservation for a given IP address/subnet does not exist. In some cases it may be required to allow non-unique IP reservations, e.g. in the case when a host has several interfaces and independently of which interface is used by this host to communicate with the DHCP server the same IP address should be assigned. In this case the unique
value should be set to false to disable the checks for uniqueness on the backend side.
unique | boolean flag indicating if the IP reservations must be unique within the subnet or can be non-unique. |
Implements isc::dhcp::BaseHostDataSource.
Definition at line 3950 of file mysql_host_data_source.cc.