Kea: pgsql_host_data_source.h Source File

| Kea 2.2.0

pgsql_host_data_source.h
Go to the documentation of this file.
1// Copyright (C) 2016-2021 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef PGSQL_HOST_DATA_SOURCE_H
8#define PGSQL_HOST_DATA_SOURCE_H
9
10#include <database/database_connection.h>
11#include <dhcpsrv/base_host_data_source.h>
12#include <pgsql/pgsql_connection.h>
13#include <pgsql/pgsql_exchange.h>
14
15namespace isc {
16namespace dhcp {
17
19class PgSqlHostDataSourceImpl;
20
22 typedef boost::shared_ptr<PgSqlHostDataSourceImpl> PgSqlHostDataSourceImplPtr;
23
25class PgSqlHostContext;
26
28 typedef boost::shared_ptr<PgSqlHostContext> PgSqlHostContextPtr;
29
45 class PgSqlHostDataSource : public BaseHostDataSource {
46public:
47
70 PgSqlHostDataSource(const db::DatabaseConnection::ParameterMap& parameters);
71
76 virtual ~PgSqlHostDataSource();
77
83 virtual isc::db::DatabaseConnection::ParameterMap getParameters() const;
84
118 virtual void add(const HostPtr& host);
119
128 virtual bool del(const SubnetID& subnet_id,
129 const asiolink::IOAddress& addr);
130
143 virtual bool del4(const SubnetID& subnet_id,
144 const Host::IdentifierType& identifier_type,
145 const uint8_t* identifier_begin,
146 const size_t identifier_len);
147
160 virtual bool del6(const SubnetID& subnet_id,
161 const Host::IdentifierType& identifier_type,
162 const uint8_t* identifier_begin,
163 const size_t identifier_len);
164
178 virtual ConstHostCollection getAll(const Host::IdentifierType& identifier_type,
179 const uint8_t* identifier_begin,
180 const size_t identifier_len) const;
181
191 virtual ConstHostCollection getAll4(const SubnetID& subnet_id) const;
192
202 virtual ConstHostCollection getAll6(const SubnetID& subnet_id) const;
203
214 virtual ConstHostCollection getAllbyHostname(const std::string& hostname) const;
215
225 virtual ConstHostCollection getAllbyHostname4(const std::string& hostname,
226 const SubnetID& subnet_id) const;
227
237 virtual ConstHostCollection getAllbyHostname6(const std::string& hostname,
238 const SubnetID& subnet_id) const;
239
257 virtual ConstHostCollection getPage4(const SubnetID& subnet_id,
258 size_t& source_index,
259 uint64_t lower_host_id,
260 const HostPageSize& page_size) const;
261
279 virtual ConstHostCollection getPage6(const SubnetID& subnet_id,
280 size_t& source_index,
281 uint64_t lower_host_id,
282 const HostPageSize& page_size) const;
283
300 virtual ConstHostCollection getPage4(size_t& source_index,
301 uint64_t lower_host_id,
302 const HostPageSize& page_size) const;
303
320 virtual ConstHostCollection getPage6(size_t& source_index,
321 uint64_t lower_host_id,
322 const HostPageSize& page_size) const;
323
332 virtual ConstHostCollection getAll4(const asiolink::IOAddress& address) const;
333
344 virtual ConstHostPtr get4(const SubnetID& subnet_id,
345 const Host::IdentifierType& identifier_type,
346 const uint8_t* identifier_begin,
347 const size_t identifier_len) const;
348
363 virtual ConstHostPtr get4(const SubnetID& subnet_id,
364 const asiolink::IOAddress& address) const;
365
389 virtual ConstHostCollection
390 getAll4(const SubnetID& subnet_id,
391 const asiolink::IOAddress& address) const;
392
403 virtual ConstHostPtr get6(const SubnetID& subnet_id,
404 const Host::IdentifierType& identifier_type,
405 const uint8_t* identifier_begin,
406 const size_t identifier_len) const;
407
414 virtual ConstHostPtr get6(const asiolink::IOAddress& prefix,
415 const uint8_t prefix_len) const;
416
424 virtual ConstHostPtr get6(const SubnetID& subnet_id,
425 const asiolink::IOAddress& address) const;
426
450 virtual ConstHostCollection
451 getAll6(const SubnetID& subnet_id,
452 const asiolink::IOAddress& address) const;
453
460 virtual std::string getType() const {
461 return (std::string("postgresql"));
462 }
463
467 virtual std::string getName() const;
468
474 virtual std::string getDescription() const;
475
489 virtual std::pair<uint32_t, uint32_t> getVersion() const;
490
494 virtual void commit();
495
499 virtual void rollback();
500
516 virtual bool setIPReservationsUnique(const bool unique);
517
523 virtual bool isUnusable();
524
526 class PgSqlHostContextAlloc {
527 public:
528
535 PgSqlHostContextAlloc(PgSqlHostDataSourceImpl& mgr);
536
540 ~PgSqlHostContextAlloc();
541
543 PgSqlHostContextPtr ctx_;
544
545 private:
547 PgSqlHostDataSourceImpl& mgr_;
548 };
549
550private:
552 PgSqlHostDataSourceImplPtr impl_;
553};
554
555}
556}
557
558#endif // PGSQL_HOST_DATA_SOURCE_H
base_host_data_source.h
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic)
Definition: io_address.h:45
isc::db::DatabaseConnection::ParameterMap
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Definition: database_connection.h:115
isc::dhcp::BaseHostDataSource
Base interface for the classes implementing simple data source for host reservations.
Definition: base_host_data_source.h:80
isc::dhcp::HostPageSize
Wraps value holding size of the page with host reservations.
Definition: base_host_data_source.h:45
isc::dhcp::Host::IdentifierType
IdentifierType
Type of the host identifier.
Definition: host.h:307
isc::dhcp::PgSqlHostContext
PostgreSQL Host Context.
Definition: pgsql_host_data_source.cc:1307
isc::dhcp::PgSqlHostDataSourceImpl
Implementation of the PgSqlHostDataSource.
Definition: pgsql_host_data_source.cc:1373
isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc
Context RAII Allocator.
Definition: pgsql_host_data_source.h:526
isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::ctx_
PgSqlHostContextPtr ctx_
The context.
Definition: pgsql_host_data_source.h:543
isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::~PgSqlHostContextAlloc
~PgSqlHostContextAlloc()
Destructor.
Definition: pgsql_host_data_source.cc:2205
isc::dhcp::PgSqlHostDataSource::PgSqlHostContextAlloc::PgSqlHostContextAlloc
PgSqlHostContextAlloc(PgSqlHostDataSourceImpl &mgr)
Constructor.
Definition: pgsql_host_data_source.cc:2180
isc::dhcp::PgSqlHostDataSource
PostgreSQL Host Data Source.
Definition: pgsql_host_data_source.h:45
isc::dhcp::PgSqlHostDataSource::del6
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)
Definition: pgsql_host_data_source.cc:2710
isc::dhcp::PgSqlHostDataSource::get4
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.
Definition: pgsql_host_data_source.cc:2995
isc::dhcp::PgSqlHostDataSource::isUnusable
virtual bool isUnusable()
Flag which indicates if the host manager has at least one unusable connection.
Definition: pgsql_host_data_source.cc:3235
isc::dhcp::PgSqlHostDataSource::getName
virtual std::string getName() const
Returns the name of the open database.
Definition: pgsql_host_data_source.cc:3181
isc::dhcp::PgSqlHostDataSource::getAll
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 iden...
Definition: pgsql_host_data_source.cc:2737
isc::dhcp::PgSqlHostDataSource::getDescription
virtual std::string getDescription() const
Returns description of the backend.
Definition: pgsql_host_data_source.cc:3196
isc::dhcp::PgSqlHostDataSource::getAllbyHostname4
virtual ConstHostCollection getAllbyHostname4(const std::string &hostname, const SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv4 subnet.
Definition: pgsql_host_data_source.cc:2818
isc::dhcp::PgSqlHostDataSource::getPage6
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.
Definition: pgsql_host_data_source.cc:2894
isc::dhcp::PgSqlHostDataSource::del
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete hosts by (subnet-id, address)
Definition: pgsql_host_data_source.cc:2656
isc::dhcp::PgSqlHostDataSource::getPage4
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.
Definition: pgsql_host_data_source.cc:2864
isc::dhcp::PgSqlHostDataSource::rollback
virtual void rollback()
Rollback Transactions.
Definition: pgsql_host_data_source.cc:3218
isc::dhcp::PgSqlHostDataSource::getVersion
virtual std::pair< uint32_t, uint32_t > getVersion() const
Returns backend version.
Definition: pgsql_host_data_source.cc:3202
isc::dhcp::PgSqlHostDataSource::del4
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)
Definition: pgsql_host_data_source.cc:2683
isc::dhcp::PgSqlHostDataSource::getAll6
virtual ConstHostCollection getAll6(const SubnetID &subnet_id) const
Return all hosts in a DHCPv6 subnet.
Definition: pgsql_host_data_source.cc:2780
isc::dhcp::PgSqlHostDataSource::getAllbyHostname6
virtual ConstHostCollection getAllbyHostname6(const std::string &hostname, const SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv6 subnet.
Definition: pgsql_host_data_source.cc:2841
isc::dhcp::PgSqlHostDataSource::commit
virtual void commit()
Commit Transactions.
Definition: pgsql_host_data_source.cc:3207
isc::dhcp::PgSqlHostDataSource::setIPReservationsUnique
virtual bool setIPReservationsUnique(const bool unique)
Controls whether IP reservations are unique or non-unique.
Definition: pgsql_host_data_source.cc:3229
isc::dhcp::PgSqlHostDataSource::getAll4
virtual ConstHostCollection getAll4(const SubnetID &subnet_id) const
Return all hosts in a DHCPv4 subnet.
Definition: pgsql_host_data_source.cc:2761
isc::dhcp::PgSqlHostDataSource::getParameters
virtual isc::db::DatabaseConnection::ParameterMap getParameters() const
Return backend parameters.
Definition: pgsql_host_data_source.cc:2593
isc::dhcp::PgSqlHostDataSource::PgSqlHostDataSource
PgSqlHostDataSource(const db::DatabaseConnection::ParameterMap &parameters)
Constructor.
Definition: pgsql_host_data_source.cc:2585
isc::dhcp::PgSqlHostDataSource::add
virtual void add(const HostPtr &host)
Adds a new host to the collection.
Definition: pgsql_host_data_source.cc:2598
isc::dhcp::PgSqlHostDataSource::get6
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.
Definition: pgsql_host_data_source.cc:3070
isc::dhcp::PgSqlHostDataSource::~PgSqlHostDataSource
virtual ~PgSqlHostDataSource()
Virtual destructor.
Definition: pgsql_host_data_source.cc:2589
isc::dhcp::PgSqlHostDataSource::getAllbyHostname
virtual ConstHostCollection getAllbyHostname(const std::string &hostname) const
Return all hosts with a hostname.
Definition: pgsql_host_data_source.cc:2799
isc::dhcp::PgSqlHostDataSource::getType
virtual std::string getType() const
Return backend type.
Definition: pgsql_host_data_source.h:460
database_connection.h
isc::dhcp::PgSqlHostContextPtr
boost::shared_ptr< PgSqlHostContext > PgSqlHostContextPtr
Type of pointers to contexts.
Definition: pgsql_host_data_source.h:25
isc::dhcp::HostPtr
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:785
isc::dhcp::ConstHostCollection
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:791
isc::dhcp::SubnetID
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition: subnet_id.h:24
isc::dhcp::ConstHostPtr
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition: host.h:788
isc::dhcp::PgSqlHostDataSourceImplPtr
boost::shared_ptr< PgSqlHostDataSourceImpl > PgSqlHostDataSourceImplPtr
Type of pointers to PgSqlHostDataSourceImpl.
Definition: pgsql_host_data_source.h:19
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143
pgsql_connection.h
pgsql_exchange.h