Kea 2.5.8
isc::dhcp::PgSqlHostDataSource Class Reference

PostgreSQL Host Data Source. More...

#include <pgsql_host_data_source.h>

+ Inheritance diagram for isc::dhcp::PgSqlHostDataSource:

Classes

class  PgSqlHostContextAlloc
 Context RAII Allocator. More...
 

Public Member Functions

 PgSqlHostDataSource (const db::DatabaseConnection::ParameterMap &parameters)
 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.
 
- Public Member Functions inherited from isc::dhcp::BaseHostDataSource
virtual ~BaseHostDataSource ()
 Default destructor implementation.
 
virtual void add (const HostPtr &host)=0
 Adds a new host to the collection.
 
virtual void commit ()
 Commit Transactions.
 
virtual bool del (const SubnetID &subnet_id, const asiolink::IOAddress &addr)=0
 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)=0
 Attempts to delete a host by (subnet-id4, identifier, identifier-type)
 
virtual bool del6 (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)=0
 Attempts to delete a host by (subnet-id6, identifier, identifier-type)
 
virtual ConstHostPtr get4 (const SubnetID &subnet_id, const asiolink::IOAddress &address) const =0
 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 =0
 Returns a host connected to the IPv4 subnet.
 
virtual ConstHostPtr get6 (const asiolink::IOAddress &prefix, const uint8_t prefix_len) const =0
 Returns a host using the specified IPv6 prefix.
 
virtual ConstHostPtr get6 (const SubnetID &subnet_id, const asiolink::IOAddress &address) const =0
 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 =0
 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 =0
 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 =0
 Returns a collection of hosts using the specified IPv4 address.
 
virtual ConstHostCollection getAll4 (const SubnetID &subnet_id) const =0
 Return all hosts in a DHCPv4 subnet.
 
virtual ConstHostCollection getAll4 (const SubnetID &subnet_id, const asiolink::IOAddress &address) const =0
 Returns all hosts connected to the IPv4 subnet and having a reservation for a specified address.
 
virtual ConstHostCollection getAll6 (const asiolink::IOAddress &address) const =0
 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 =0
 Return all hosts in a DHCPv6 subnet.
 
virtual ConstHostCollection getAll6 (const SubnetID &subnet_id, const asiolink::IOAddress &address) const =0
 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 =0
 Return all hosts with a hostname.
 
virtual ConstHostCollection getAllbyHostname4 (const std::string &hostname, const SubnetID &subnet_id) const =0
 Return all hosts with a hostname in a DHCPv4 subnet.
 
virtual ConstHostCollection getAllbyHostname6 (const std::string &hostname, const SubnetID &subnet_id) const =0
 Return all hosts with a hostname in a DHCPv6 subnet.
 
virtual ConstHostCollection getPage4 (const SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const =0
 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 =0
 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 =0
 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 =0
 Returns range of hosts.
 
virtual isc::db::DatabaseConnection::ParameterMap getParameters () const
 Return backend parameters.
 
virtual std::string getType () const =0
 Return backend type.
 
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)=0
 Controls whether IP reservations are unique or non-unique.
 
virtual void update (HostPtr const &host)
 Attempts to update an existing host entry.
 

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

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:

  • IDENT_HWADDR
  • IDENT_DUID
  • IDENT_CIRCUIT_ID
  • IDENT_CLIENT_ID

Definition at line 45 of file pgsql_host_data_source.h.

Constructor & Destructor Documentation

◆ PgSqlHostDataSource()

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:

  • 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::db::NoDatabaseNameMandatory database name not given
isc::db::DbOpenErrorError opening the database
isc::db::DbOperationErrorAn operation on the open database has failed.

Definition at line 2632 of file pgsql_host_data_source.cc.

◆ ~PgSqlHostDataSource()

isc::dhcp::PgSqlHostDataSource::~PgSqlHostDataSource ( )
virtual

Virtual destructor.

Frees database resources and closes the database connection through the destruction of member impl_.

Definition at line 2636 of file pgsql_host_data_source.cc.

Member Function Documentation

◆ add()

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

  1. IPV4_ADDRESS and DHCP4_SUBNET_ID combination must be unique
  2. IPV6 ADDRESS and PREFIX_LEN combination must be unique
  3. DHCP ID, DHCP ID TYPE, and DHCP4_SUBNET_ID combination must be unique
  4. DHCP ID, DHCP ID TYPE, and DHCP6_SUBNET_ID combination must be unique

In addition, violating the following referential constraints will a DbOperationError exception:

  1. DHCP ID TYPE must be defined in the HOST_IDENTIFIER_TYPE table
  2. For DHCP4 Options:
    1. HOST_ID must exist with HOSTS
    2. SCOPE_ID must be defined in DHCP_OPTION_SCOPE
  3. For DHCP6 Options:
    1. HOST_ID must exist with HOSTS
    2. SCOPE_ID must be defined in DHCP_OPTION_SCOPE
  4. For IPV6 Reservations:
    1. HOST_ID must exist with HOSTS
    2. Address and Prefix Length must be unique (DuplicateEntry)
Parameters
hostPointer to the new Host object being added.
Exceptions
DuplicateEntryor DbOperationError dependent on the constraint violation

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2645 of file pgsql_host_data_source.cc.

References isc::db::PgSqlTransaction::commit(), isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, 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.

+ Here is the call graph for this function:

◆ commit()

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

Commit Transactions.

Commits all pending database operations.

Reimplemented from isc::dhcp::BaseHostDataSource.

Definition at line 3302 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_.

◆ del()

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

Attempts to delete hosts 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 2702 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, isc::dhcp::PgSqlHostDataSourceImpl::DEL_HOST_ADDR4, isc::dhcp::PgSqlHostDataSourceImpl::DEL_HOST_ADDR6, isc::asiolink::IOAddress::isV4(), and isc::asiolink::IOAddress::toText().

+ Here is the call graph for this function:

◆ del4()

bool isc::dhcp::PgSqlHostDataSource::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 2729 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, and isc::dhcp::PgSqlHostDataSourceImpl::DEL_HOST_SUBID4_ID.

◆ del6()

bool isc::dhcp::PgSqlHostDataSource::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 2756 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, and isc::dhcp::PgSqlHostDataSourceImpl::DEL_HOST_SUBID6_ID.

◆ get4() [1/2]

ConstHostPtr isc::dhcp::PgSqlHostDataSource::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.

Parameters
subnet_idSubnet identifier.
addressreserved IPv4 address.
Returns
Const Host object using a specified IPv4 address.
Exceptions
BadValueis given an IPv6 address

Implements isc::dhcp::BaseHostDataSource.

Definition at line 3055 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID_ADDR, isc_throw, and isc::asiolink::IOAddress::isV4().

+ Here is the call graph for this function:

◆ get4() [2/2]

ConstHostPtr isc::dhcp::PgSqlHostDataSource::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 3041 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, and isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID4_DHCPID.

◆ get6() [1/3]

ConstHostPtr isc::dhcp::PgSqlHostDataSource::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.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 3130 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_PREFIX, isc_throw, and isc::asiolink::IOAddress::isV6().

+ Here is the call graph for this function:

◆ get6() [2/3]

ConstHostPtr isc::dhcp::PgSqlHostDataSource::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 3164 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID6_ADDR, isc_throw, and isc::asiolink::IOAddress::isV6().

+ Here is the call graph for this function:

◆ get6() [3/3]

ConstHostPtr isc::dhcp::PgSqlHostDataSource::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 3116 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, and isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID6_DHCPID.

◆ getAll()

ConstHostCollection isc::dhcp::PgSqlHostDataSource::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 2783 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, and isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_DHCPID.

◆ getAll4() [1/3]

ConstHostCollection isc::dhcp::PgSqlHostDataSource::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 3022 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, and isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_ADDR.

◆ getAll4() [2/3]

ConstHostCollection isc::dhcp::PgSqlHostDataSource::getAll4 ( const SubnetID subnet_id) const
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.

Parameters
subnet_idsubnet identifier to filter by
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2807 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, and isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID4.

◆ getAll4() [3/3]

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

Parameters
subnet_idSubnet identifier.
addressreserved IPv4 address.
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 3089 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID_ADDR, isc_throw, and isc::asiolink::IOAddress::isV4().

+ Here is the call graph for this function:

◆ getAll6() [1/3]

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

Parameters
addressreserved IPv6 address/prefix.
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 3225 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_ADDR6, isc_throw, and isc::asiolink::IOAddress::isV6().

+ Here is the call graph for this function:

◆ getAll6() [2/3]

ConstHostCollection isc::dhcp::PgSqlHostDataSource::getAll6 ( const SubnetID subnet_id) const
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.

Parameters
subnet_idsubnet identifier to filter by
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2826 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, and isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID6.

◆ getAll6() [3/3]

ConstHostCollection isc::dhcp::PgSqlHostDataSource::getAll6 ( const SubnetID subnet_id,
const asiolink::IOAddress address 
) const
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.

Parameters
subnet_idSubnet identifier.
addressreserved IPv6 address/prefix.
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 3198 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID6_ADDR, isc_throw, and isc::asiolink::IOAddress::isV6().

+ Here is the call graph for this function:

◆ getAllbyHostname()

ConstHostCollection isc::dhcp::PgSqlHostDataSource::getAllbyHostname ( const std::string &  hostname) const
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).

Parameters
hostnameThe lower case hostname.
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2845 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, and isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_HOSTNAME.

◆ getAllbyHostname4()

ConstHostCollection isc::dhcp::PgSqlHostDataSource::getAllbyHostname4 ( const std::string &  hostname,
const SubnetID subnet_id 
) const
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.

Parameters
hostnameThe lower case hostname.
subnet_idSubnet identifier.
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2864 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, and isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_HOSTNAME_SUBID4.

◆ getAllbyHostname6()

ConstHostCollection isc::dhcp::PgSqlHostDataSource::getAllbyHostname6 ( const std::string &  hostname,
const SubnetID subnet_id 
) const
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.

Parameters
hostnameThe lower case hostname.
subnet_idSubnet identifier.
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2887 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, and isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_HOSTNAME_SUBID6.

◆ getDescription()

std::string isc::dhcp::PgSqlHostDataSource::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 3291 of file pgsql_host_data_source.cc.

◆ getName()

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

Returns the name of the open database.

Returns
String containing the name of the database

Definition at line 3276 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_.

◆ getPage4() [1/2]

ConstHostCollection isc::dhcp::PgSqlHostDataSource::getPage4 ( const SubnetID subnet_id,
size_t &  source_index,
uint64_t  lower_host_id,
const HostPageSize page_size 
) const
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.

Parameters
subnet_idSubnet identifier.
source_indexIndex of the source (unused).
lower_host_idHost identifier used as lower bound for the returned range.
page_sizemaximum size of the page returned.
Returns
Collection of const Host objects (may be empty).

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2910 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID4_PAGE, and isc::dhcp::HostPageSize::page_size_.

◆ getPage4() [2/2]

ConstHostCollection isc::dhcp::PgSqlHostDataSource::getPage4 ( size_t &  source_index,
uint64_t  lower_host_id,
const HostPageSize page_size 
) const
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.

Parameters
source_indexIndex of the source (unused).
lower_host_idHost identifier used as lower bound for the returned range.
page_sizemaximum size of the page returned.
Returns
Collection of const Host objects (may be empty).

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2970 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_PAGE4, and isc::dhcp::HostPageSize::page_size_.

◆ getPage6() [1/2]

ConstHostCollection isc::dhcp::PgSqlHostDataSource::getPage6 ( const SubnetID subnet_id,
size_t &  source_index,
uint64_t  lower_host_id,
const HostPageSize page_size 
) const
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.

Parameters
subnet_idSubnet identifier.
source_indexIndex of the source (unused).
lower_host_idHost identifier used as lower bound for the returned range.
page_sizemaximum size of the page returned.
Returns
Collection of const Host objects (may be empty).

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2940 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_SUBID6_PAGE, and isc::dhcp::HostPageSize::page_size_.

◆ getPage6() [2/2]

ConstHostCollection isc::dhcp::PgSqlHostDataSource::getPage6 ( size_t &  source_index,
uint64_t  lower_host_id,
const HostPageSize page_size 
) const
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.

Parameters
source_indexIndex of the source (unused).
lower_host_idHost identifier used as lower bound for the returned range.
page_sizemaximum size of the page returned.
Returns
Collection of const Host objects (may be empty).

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2996 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, isc::dhcp::PgSqlHostDataSourceImpl::GET_HOST_PAGE6, and isc::dhcp::HostPageSize::page_size_.

◆ getParameters()

DatabaseConnection::ParameterMap isc::dhcp::PgSqlHostDataSource::getParameters ( ) const
virtual

Return backend parameters.

Returns the backend parameters

Returns
Parameters of the backend.

Reimplemented from isc::dhcp::BaseHostDataSource.

Definition at line 2640 of file pgsql_host_data_source.cc.

◆ getType()

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

Return backend type.

Returns the type of database as the string "postgresql". This is same value as used for configuration purposes.

Returns
Type of the backend.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 490 of file pgsql_host_data_source.h.

◆ getVersion()

std::pair< uint32_t, uint32_t > isc::dhcp::PgSqlHostDataSource::getVersion ( const std::string &  timer_name = std::string()) const
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.

Parameters
timer_nameThe DB reconnect timer name.
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 3297 of file pgsql_host_data_source.cc.

◆ isUnusable()

bool isc::dhcp::PgSqlHostDataSource::isUnusable ( )
virtual

Flag which indicates if the host manager has at least one unusable connection.

Returns
true if there is at least one unusable connection, false otherwise

Reimplemented from isc::dhcp::BaseHostDataSource.

Definition at line 3330 of file pgsql_host_data_source.cc.

◆ rollback()

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

Rollback Transactions.

Rolls back all pending database operations.

Reimplemented from isc::dhcp::BaseHostDataSource.

Definition at line 3313 of file pgsql_host_data_source.cc.

References isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_.

◆ setIPReservationsUnique()

bool isc::dhcp::PgSqlHostDataSource::setIPReservationsUnique ( const bool  unique)
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.

Parameters
uniqueboolean flag indicating if the IP reservations must be unique within the subnet or can be non-unique.
Returns
always true because this backend supports both the case when the addresses must be unique and when they may be non-unique.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 3324 of file pgsql_host_data_source.cc.

◆ update()

void isc::dhcp::PgSqlHostDataSource::update ( HostPtr const &  host)
virtual

Implements BaseHostDataSource::update() for PostgreSQL.

Attempts to update an existing host entry.

Parameters
hostthe host up to date with the requested changes

Reimplemented from isc::dhcp::BaseHostDataSource.

Definition at line 3248 of file pgsql_host_data_source.cc.

References isc::db::PgSqlTransaction::commit(), isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_, and isc::dhcp::BaseHostDataSource::update().

+ Here is the call graph for this function:

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