![]() |
Kea 2.7.3
|
PostgreSQL Host Data Source. More...
#include <pgsql_host_data_source.h>
Classes | |
class | PgSqlHostContextAlloc |
Context RAII Allocator. More... | |
Public Member Functions | |
PgSqlHostDataSource (const db::DatabaseConnection::ParameterMap ¶meters) | |
Constructor. | |
virtual | ~PgSqlHostDataSource () |
Virtual destructor. | |
virtual void | add (const HostPtr &host) |
Adds a new host to the collection. | |
virtual void | commit () |
Commit Transactions. | |
virtual bool | del (const SubnetID &subnet_id, const asiolink::IOAddress &addr) |
Attempts to delete hosts by (subnet-id, address) | |
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) | |
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) | |
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. | |
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. | |
virtual ConstHostPtr | get6 (const asiolink::IOAddress &prefix, const uint8_t prefix_len) const |
Returns a host using the specified IPv6 prefix. | |
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. | |
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. | |
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. | |
virtual ConstHostCollection | getAll4 (const asiolink::IOAddress &address) const |
Returns a collection of hosts using the specified IPv4 address. | |
virtual ConstHostCollection | getAll4 (const SubnetID &subnet_id) const |
Return all hosts in a DHCPv4 subnet. | |
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. | |
virtual ConstHostCollection | getAll6 (const asiolink::IOAddress &address) const |
Returns all hosts having a reservation for a specified address or delegated prefix (lease) in all subnets. | |
virtual ConstHostCollection | getAll6 (const SubnetID &subnet_id) const |
Return all hosts in a DHCPv6 subnet. | |
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). | |
virtual ConstHostCollection | getAllbyHostname (const std::string &hostname) const |
Return all hosts with a hostname. | |
virtual ConstHostCollection | getAllbyHostname4 (const std::string &hostname, const SubnetID &subnet_id) const |
Return all hosts with a hostname in a DHCPv4 subnet. | |
virtual ConstHostCollection | getAllbyHostname6 (const std::string &hostname, const SubnetID &subnet_id) const |
Return all hosts with a hostname in a DHCPv6 subnet. | |
virtual std::string | getDescription () const |
Returns description of the backend. | |
virtual std::string | getName () const |
Returns the name of the open database. | |
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. | |
virtual ConstHostCollection | getPage4 (size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const |
Returns range of hosts. | |
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. | |
virtual ConstHostCollection | getPage6 (size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const |
Returns range of hosts. | |
virtual isc::db::DatabaseConnection::ParameterMap | getParameters () const |
Return backend parameters. | |
virtual std::string | getType () const |
Return backend type. | |
virtual std::pair< uint32_t, uint32_t > | getVersion (const std::string &timer_name=std::string()) const |
Returns backend version. | |
virtual bool | isUnusable () |
Flag which indicates if the host manager has at least one unusable connection. | |
virtual void | rollback () |
Rollback Transactions. | |
virtual bool | setIPReservationsUnique (const bool unique) |
Controls whether IP reservations are unique or non-unique. | |
void | update (HostPtr const &host) |
Implements BaseHostDataSource::update() for PostgreSQL. | |
![]() | |
virtual | ~BaseHostDataSource () |
Default destructor implementation. | |
Additional Inherited Members | |
![]() | |
enum | IdType { ID_HWADDR = 0 , ID_DUID = 1 } |
Specifies the type of an identifier. More... | |
PostgreSQL Host Data Source.
This class implements the isc::dhcp::BaseHostDataSource interface to the PostgreSQL database. Use of this backend presupposes that a PostgreSQL database is available and that the Kea schema has been created within it.
Reservations are uniquely identified by identifier type and value. The currently supported values are defined in Host::IdentifierType as well as in host_identifier_table:
Definition at line 45 of file pgsql_host_data_source.h.
isc::dhcp::PgSqlHostDataSource::PgSqlHostDataSource | ( | 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::db::NoDatabaseName | Mandatory database name not given |
isc::db::DbOpenError | Error opening the database |
isc::db::DbOperationError | An operation on the open database has failed. |
Definition at line 2675 of file pgsql_host_data_source.cc.
|
virtual |
Virtual destructor.
Frees database resources and closes the database connection through the destruction of member impl_.
Definition at line 2679 of file pgsql_host_data_source.cc.
|
virtual |
Adds a new host to the collection.
The method will insert the given host and all of its children (v4 options, v6 options, and v6 reservations) into the database. It relies on constraints defined as part of the PostgreSQL schema to defend against duplicate entries and to ensure referential integrity.
Violation of any of these constraints for a host will result in a DuplicateEntry exception:
In addition, violating the following referential constraints will a DbOperationError exception:
host | Pointer to the new Host object being added. |
DuplicateEntry | or DbOperationError dependent on the constraint violation |
Implements isc::dhcp::BaseHostDataSource.
Definition at line 2688 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::INSERT_HOST_NON_UNIQUE_IP, isc::dhcp::PgSqlHostDataSourceImpl::INSERT_HOST_UNIQUE_IP, isc::dhcp::PgSqlHostDataSourceImpl::INSERT_V4_HOST_OPTION, and isc::dhcp::PgSqlHostDataSourceImpl::INSERT_V6_HOST_OPTION.
|
virtual |
Commit Transactions.
Commits all pending database operations.
Reimplemented from isc::dhcp::BaseHostDataSource.
Definition at line 3345 of file pgsql_host_data_source.cc.
|
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 2745 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::DEL_HOST_ADDR4, isc::dhcp::PgSqlHostDataSourceImpl::DEL_HOST_ADDR6, isc::asiolink::IOAddress::isV4(), and isc::asiolink::IOAddress::toText().
|
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 2772 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::DEL_HOST_SUBID4_ID.
|
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 2799 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::DEL_HOST_SUBID6_ID.
|
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.
subnet_id | Subnet identifier. |
address | reserved IPv4 address. |
Host
object using a specified IPv4 address. BadValue | is given an IPv6 address |
Implements isc::dhcp::BaseHostDataSource.
Definition at line 3098 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID_ADDR, and isc_throw.
|
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 3084 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID4_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 3173 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_PREFIX, and isc_throw.
|
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 3207 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID6_ADDR, and isc_throw.
|
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 3159 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID6_DHCPID.
|
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 2826 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_DHCPID.
|
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 3065 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_ADDR.
|
virtual |
Return all hosts in a DHCPv4 subnet.
This method returns all Host objects which represent reservations in a specified subnet. Global reservations are returned for the subnet id 0.
subnet_id | subnet identifier to filter by |
Implements isc::dhcp::BaseHostDataSource.
Definition at line 2850 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID4.
|
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 3132 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID_ADDR, and isc_throw.
|
virtual |
Returns all hosts having a reservation for a specified address or delegated prefix (lease) in all subnets.
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.
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 per subnet.
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.
address | reserved IPv6 address/prefix. |
Host
objects. Implements isc::dhcp::BaseHostDataSource.
Definition at line 3268 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_ADDR6, and isc_throw.
|
virtual |
Return all hosts in a DHCPv6 subnet.
This method returns all Host objects which represent reservations in a specified subnet. Global reservations are returned for the subnet id 0.
subnet_id | subnet identifier to filter by |
Implements isc::dhcp::BaseHostDataSource.
Definition at line 2869 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID6.
|
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 3241 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID6_ADDR, and isc_throw.
|
virtual |
Return all hosts with a hostname.
This method returns all Host
objects which represent reservations using a specified hostname.
PostgreSQL uses the hosts_by_hostname index on LOWER(hostname).
hostname | The lower case hostname. |
Host
objects. Implements isc::dhcp::BaseHostDataSource.
Definition at line 2888 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::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 2907 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_HOSTNAME_SUBID4.
|
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 2930 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_HOSTNAME_SUBID6.
|
virtual |
Returns description of the backend.
This description may be multiline text that describes the backend.
Definition at line 3334 of file pgsql_host_data_source.cc.
|
virtual |
Returns the name of the open database.
Definition at line 3319 of file pgsql_host_data_source.cc.
|
virtual |
Returns range of hosts in a DHCPv4 subnet.
This method implements paged browsing of host databases. The parameters specify a page size, an index in sources and the starting host id of the range. If not zero this host id is excluded from the returned range. When a source is exhausted the index is updated. There is no guarantee about the order of returned host reservations, only the sources and reservations from the same source are ordered.
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 2953 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID4_PAGE.
|
virtual |
Returns range of hosts.
This method implements paged browsing of host databases. The parameters specify a page size, an index in sources and the starting host id of the range. If not zero this host id is excluded from the returned range. When a source is exhausted the index is updated. There is no guarantee about the order of returned host reservations, only the sources and reservations from the same source are ordered.
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 3013 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_PAGE4.
|
virtual |
Returns range of hosts in a DHCPv6 subnet.
This method implements paged browsing of host databases. The parameters specify a page size, an index in sources and the starting host id of the range. If not zero this host id is excluded from the returned range. When a source is exhausted the index is updated. There is no guarantee about the order of returned host reservations, only the sources and reservations from the same source are ordered.
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 2983 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID6_PAGE.
|
virtual |
Returns range of hosts.
This method implements paged browsing of host databases. The parameters specify a page size, an index in sources and the starting host id of the range. If not zero this host id is excluded from the returned range. When a source is exhausted the index is updated. There is no guarantee about the order of returned host reservations, only the sources and reservations from the same source are ordered.
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 3039 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_PAGE6.
|
virtual |
Return backend parameters.
Returns the backend parameters
Reimplemented from isc::dhcp::BaseHostDataSource.
Definition at line 2683 of file pgsql_host_data_source.cc.
|
inlinevirtual |
Return backend type.
Returns the type of database as the string "postgresql". This is same value as used for configuration purposes.
Implements isc::dhcp::BaseHostDataSource.
Definition at line 490 of file pgsql_host_data_source.h.
|
virtual |
Returns backend version.
The method is called by the constructor after opening the database but prior to preparing SQL statements, to verify that the schema version is correct. Thus it must not rely on a pre-prepared statement or formal statement execution error checking.
timer_name | The DB reconnect timer name. |
isc::db::DbOperationError | An operation on the open database has failed. |
Definition at line 3340 of file pgsql_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 3373 of file pgsql_host_data_source.cc.
|
virtual |
Rollback Transactions.
Rolls back all pending database operations.
Reimplemented from isc::dhcp::BaseHostDataSource.
Definition at line 3356 of file pgsql_host_data_source.cc.
|
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 3367 of file pgsql_host_data_source.cc.
|
virtual |
Implements BaseHostDataSource::update() for PostgreSQL.
Attempts to update an existing host entry.
host | the host up to date with the requested changes |
Reimplemented from isc::dhcp::BaseHostDataSource.
Definition at line 3291 of file pgsql_host_data_source.cc.
References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, and isc::dhcp::BaseHostDataSource::update().