Kea  1.5.0
isc::dhcp::MySqlHostDataSource Class Reference

MySQL Host Data Source. More...

#include <mysql_host_data_source.h>

+ Inheritance diagram for isc::dhcp::MySqlHostDataSource:

Public Member Functions

 MySqlHostDataSource (const db::DatabaseConnection::ParameterMap &parameters)
 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 a host 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 asiolink::IOAddress &address) const
 Returns a host connected to the IPv4 subnet and having a reservation for a specified IPv4 address. 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 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 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 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 asiolink::IOAddress &address) const
 Returns a collection of hosts using the specified IPv4 address. More...
 
virtual std::string getDescription () const
 Returns description of the backend. More...
 
virtual std::string getName () const
 Returns backend name. More...
 
virtual std::string getType () const
 Return backend type. More...
 
virtual std::pair< uint32_t, uint32_t > getVersion () const
 Returns backend version. More...
 
virtual void rollback ()
 Rollback Transactions. 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...
 

Detailed Description

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 30 of file mysql_host_data_source.h.

Constructor & Destructor Documentation

◆ MySqlHostDataSource()

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:

  • name - Name of the database to which to connect (mandatory)
  • host - Host to which to connect (optional, defaults to "localhost")
  • user - Username under which to connect (optional)
  • password - Password for "user" on the database (optional)

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
parametersA data structure relating keywords and values concerned with the database.
Exceptions
isc::dhcp::NoDatabaseNameMandatory database name not given
isc::db::DbOpenErrorError opening the database or the schema version is invalid.
isc::db::DbOperationErrorAn operation on the open database has failed.

Definition at line 2680 of file mysql_host_data_source.cc.

◆ ~MySqlHostDataSource()

isc::dhcp::MySqlHostDataSource::~MySqlHostDataSource ( )
virtual

Virtual destructor.

Releases prepared MySQL statements used by the backend.

Definition at line 2685 of file mysql_host_data_source.cc.

Member Function Documentation

◆ add()

void isc::dhcp::MySqlHostDataSource::add ( const HostPtr host)
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.

Parameters
hostPointer to the new Host object being added.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2690 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::addOptions(), isc::dhcp::MySqlHostDataSourceImpl::addResv(), isc::dhcp::MySqlHostDataSourceImpl::addStatement(), isc::dhcp::MySqlHostDataSourceImpl::checkReadOnly(), isc::db::MySqlTransaction::commit(), isc::dhcp::MySqlHostDataSourceImpl::conn_, isc::dhcp::MySqlHostDataSourceImpl::host_exchange_, isc::dhcp::MySqlHostDataSourceImpl::INSERT_HOST, isc::dhcp::MySqlHostDataSourceImpl::INSERT_V4_OPTION, isc::dhcp::MySqlHostDataSourceImpl::INSERT_V6_OPTION, and isc::db::MySqlConnection::mysql_.

+ Here is the call graph for this function:

◆ commit()

void isc::dhcp::MySqlHostDataSource::commit ( )
virtual

Commit Transactions.

Commits all pending database operations.

Reimplemented from isc::dhcp::BaseHostDataSource.

Definition at line 3042 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::checkReadOnly(), isc::db::MySqlConnection::commit(), and isc::dhcp::MySqlHostDataSourceImpl::conn_.

+ Here is the call graph for this function:

◆ del()

bool isc::dhcp::MySqlHostDataSource::del ( const SubnetID subnet_id,
const asiolink::IOAddress addr 
)
virtual

Attempts to delete a host by (subnet-id, address)

This method supports both v4 and v6.

Parameters
subnet_idsubnet identifier.
addrspecified address.
Returns
true if deletion was successful, false if the host was not there.
Exceptions
variousexceptions in case of errors

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2737 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::checkReadOnly(), del6(), isc::dhcp::MySqlHostDataSourceImpl::DEL_HOST_ADDR4, isc::dhcp::MySqlHostDataSourceImpl::delStatement(), get6(), isc::asiolink::IOAddress::isV4(), isc::db::MLM_TRUE, and isc::asiolink::IOAddress::toUint32().

+ Here is the call graph for this function:

◆ del4()

bool isc::dhcp::MySqlHostDataSource::del4 ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
)
virtual

Attempts to delete a host by (subnet4-id, identifier type, identifier)

This method supports v4 hosts only.

Parameters
subnet_idsubnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
true if deletion was successful, false if the host was not there.
Exceptions
variousexceptions in case of errors

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2772 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::checkReadOnly(), isc::dhcp::MySqlHostDataSourceImpl::DEL_HOST_SUBID4_ID, isc::dhcp::MySqlHostDataSourceImpl::delStatement(), and isc::db::MLM_TRUE.

+ Here is the call graph for this function:

◆ del6()

bool isc::dhcp::MySqlHostDataSource::del6 ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
)
virtual

Attempts to delete a host by (subnet6-id, identifier type, identifier)

This method supports v6 hosts only.

Parameters
subnet_idsubnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
true if deletion was successful, false if the host was not there.
Exceptions
variousexceptions in case of errors

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2808 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::checkReadOnly(), isc::dhcp::MySqlHostDataSourceImpl::DEL_HOST_SUBID6_ID, isc::dhcp::MySqlHostDataSourceImpl::delStatement(), and isc::db::MLM_TRUE.

Referenced by del().

+ Here is the call graph for this function:

◆ get4() [1/2]

ConstHostPtr isc::dhcp::MySqlHostDataSource::get4 ( const SubnetID subnet_id,
const asiolink::IOAddress address 
) const
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.

Parameters
subnet_idSubnet identifier.
addressreserved IPv4 address.
Returns
Const Host object using a specified IPv4 address.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2904 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID_ADDR, isc::dhcp::MySqlHostDataSourceImpl::getHostCollection(), isc::dhcp::MySqlHostDataSourceImpl::host_exchange_, isc_throw, isc::asiolink::IOAddress::isV4(), isc::db::MLM_TRUE, and isc::asiolink::IOAddress::toUint32().

+ Here is the call graph for this function:

◆ get4() [2/2]

ConstHostPtr isc::dhcp::MySqlHostDataSource::get4 ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
) const
virtual

Returns a host connected to the IPv4 subnet.

Parameters
subnet_idSubnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
Const Host object for which reservation has been made using the specified identifier.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2893 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID4_DHCPID, isc::dhcp::MySqlHostDataSourceImpl::getHost(), and isc::dhcp::MySqlHostDataSourceImpl::host_exchange_.

+ Here is the call graph for this function:

◆ get6() [1/3]

ConstHostPtr isc::dhcp::MySqlHostDataSource::get6 ( const asiolink::IOAddress prefix,
const uint8_t  prefix_len 
) const
virtual

Returns a host using the specified IPv6 prefix.

Parameters
prefixIPv6 prefix for which the Host object is searched.
prefix_lenIPv6 prefix length.
Returns
Const Host object using a specified IPv6 prefix.
Todo:
: Check that prefix is v6 address, not v4.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2949 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_PREFIX, isc::dhcp::MySqlHostDataSourceImpl::getHostCollection(), isc::dhcp::MySqlHostDataSourceImpl::host_ipv6_exchange_, isc::db::MLM_TRUE, and isc::asiolink::IOAddress::toText().

+ Here is the call graph for this function:

◆ get6() [2/3]

ConstHostPtr isc::dhcp::MySqlHostDataSource::get6 ( const SubnetID subnet_id,
const asiolink::IOAddress address 
) const
virtual

Returns a host connected to the IPv6 subnet and having a reservation for a specified IPv6 address or prefix.

Parameters
subnet_idSubnet identifier.
addressreserved IPv6 address/prefix.
Returns
Const Host object using a specified IPv6 address/prefix.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2986 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID6_ADDR, isc::dhcp::MySqlHostDataSourceImpl::getHostCollection(), isc::dhcp::MySqlHostDataSourceImpl::host_ipv6_exchange_, isc::db::MLM_TRUE, and isc::asiolink::IOAddress::toText().

+ Here is the call graph for this function:

◆ get6() [3/3]

ConstHostPtr isc::dhcp::MySqlHostDataSource::get6 ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
) const
virtual

Returns a host connected to the IPv6 subnet.

Parameters
subnet_idSubnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
Const Host object for which reservation has been made using the specified identifier.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2938 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_SUBID6_DHCPID, isc::dhcp::MySqlHostDataSourceImpl::getHost(), and isc::dhcp::MySqlHostDataSourceImpl::host_ipv6_exchange_.

Referenced by del().

+ Here is the call graph for this function:

◆ getAll()

ConstHostCollection isc::dhcp::MySqlHostDataSource::getAll ( const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
) const
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.

Parameters
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2844 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_DHCPID, isc::dhcp::MySqlHostDataSourceImpl::getHostCollection(), isc::dhcp::MySqlHostDataSourceImpl::host_ipv46_exchange_, and isc::db::MLM_TRUE.

+ Here is the call graph for this function:

◆ getAll4()

ConstHostCollection isc::dhcp::MySqlHostDataSource::getAll4 ( const asiolink::IOAddress address) const
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.

Parameters
addressIPv4 address for which the Host object is searched.
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2874 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::GET_HOST_ADDR, isc::dhcp::MySqlHostDataSourceImpl::getHostCollection(), isc::dhcp::MySqlHostDataSourceImpl::host_exchange_, isc::db::MLM_TRUE, and isc::asiolink::IOAddress::toUint32().

+ Here is the call graph for this function:

◆ getDescription()

std::string isc::dhcp::MySqlHostDataSource::getDescription ( ) const
virtual

Returns description of the backend.

This description may be multiline text that describes the backend.

Returns
Description of the backend.

Definition at line 3032 of file mysql_host_data_source.cc.

◆ getName()

std::string isc::dhcp::MySqlHostDataSource::getName ( ) const
virtual

Returns backend name.

Each backend have specific name.

Returns
"mysql".

Definition at line 3022 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::conn_, and isc::db::DatabaseConnection::getParameter().

+ Here is the call graph for this function:

◆ getType()

virtual std::string isc::dhcp::MySqlHostDataSource::getType ( ) const
inlinevirtual

Return backend type.

Returns the type of the backend (e.g. "mysql", "memfile" etc.)

Returns
Type of the backend.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 216 of file mysql_host_data_source.h.

◆ getVersion()

std::pair< uint32_t, uint32_t > isc::dhcp::MySqlHostDataSource::getVersion ( ) const
virtual

Returns backend version.

Returns
Version number stored in the database, as a pair of unsigned integers. "first" is the major version number, "second" the minor number.
Exceptions
isc::db::DbOperationErrorAn operation on the open database has failed.

Definition at line 3037 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::getVersion().

+ Here is the call graph for this function:

◆ rollback()

void isc::dhcp::MySqlHostDataSource::rollback ( )
virtual

Rollback Transactions.

Rolls back all pending database operations.

Reimplemented from isc::dhcp::BaseHostDataSource.

Definition at line 3049 of file mysql_host_data_source.cc.

References isc::dhcp::MySqlHostDataSourceImpl::checkReadOnly(), isc::dhcp::MySqlHostDataSourceImpl::conn_, and isc::db::MySqlConnection::rollback().

+ Here is the call graph for this function:

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