2024-01-29 10:17:26 +01:00
|
|
|
// Copyright (C) 2012-2024 Internet Systems Consortium, Inc. ("ISC")
|
2012-10-16 16:39:32 +01:00
|
|
|
//
|
2015-12-15 21:37:34 +01:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2012-10-29 13:43:31 +00:00
|
|
|
#ifndef MYSQL_LEASE_MGR_H
|
|
|
|
#define MYSQL_LEASE_MGR_H
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2020-11-05 01:23:11 +02:00
|
|
|
#include <asiolink/io_service.h>
|
2024-09-16 21:25:33 +03:00
|
|
|
#include <database/database_connection.h>
|
2013-01-10 16:32:24 +01:00
|
|
|
#include <dhcp/hwaddr.h>
|
2018-08-29 14:14:57 +02:00
|
|
|
#include <dhcpsrv/dhcpsrv_exceptions.h>
|
2024-09-16 21:25:33 +03:00
|
|
|
#include <dhcpsrv/lease_mgr_factory.h>
|
2023-02-21 10:15:43 +01:00
|
|
|
#include <dhcpsrv/tracking_lease_mgr.h>
|
2018-08-29 15:40:02 +02:00
|
|
|
#include <mysql/mysql_connection.h>
|
2012-11-16 11:19:19 +00:00
|
|
|
|
2012-11-06 12:58:10 +00:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
2013-03-07 23:00:23 +00:00
|
|
|
#include <boost/utility.hpp>
|
2015-12-01 09:50:22 +01:00
|
|
|
#include <mysql.h>
|
2012-11-16 11:19:19 +00:00
|
|
|
|
|
|
|
#include <time.h>
|
2019-10-23 20:29:05 +02:00
|
|
|
#include <vector>
|
|
|
|
#include <mutex>
|
2012-10-16 16:39:32 +01:00
|
|
|
|
|
|
|
namespace isc {
|
|
|
|
namespace dhcp {
|
|
|
|
|
2012-12-03 15:35:36 +00:00
|
|
|
// Forward declaration of the Lease exchange objects. These classes are defined
|
2012-11-06 12:58:10 +00:00
|
|
|
// in the .cc file.
|
2012-11-21 12:44:18 +00:00
|
|
|
class MySqlLease4Exchange;
|
2012-11-06 12:58:10 +00:00
|
|
|
class MySqlLease6Exchange;
|
|
|
|
|
2019-10-23 20:29:05 +02:00
|
|
|
/// @brief MySQL Lease Context
|
|
|
|
///
|
2019-11-18 14:57:06 +01:00
|
|
|
/// This class stores the thread context for the manager pool.
|
2020-01-27 15:55:03 +02:00
|
|
|
/// The class is needed by all get/update/delete functions which must use one
|
|
|
|
/// or more exchanges to perform database operations.
|
|
|
|
/// Each context provides a set of such exchanges for each thread.
|
|
|
|
/// The context instances are lazy initialized by the requesting thread by using
|
|
|
|
/// the manager's createContext function and are destroyed when the manager's
|
|
|
|
/// pool instance is destroyed.
|
2019-10-23 20:29:05 +02:00
|
|
|
class MySqlLeaseContext {
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// @brief Constructor
|
|
|
|
///
|
2019-11-18 14:57:06 +01:00
|
|
|
/// @param parameters See MySqlLeaseMgr constructor.
|
2021-03-18 23:32:07 +02:00
|
|
|
/// @param io_service_accessor The IOService accessor function.
|
2020-12-09 14:32:17 +02:00
|
|
|
/// @param db_reconnect_callback The connection recovery callback.
|
2020-11-05 01:23:11 +02:00
|
|
|
MySqlLeaseContext(const db::DatabaseConnection::ParameterMap& parameters,
|
2021-03-18 23:32:07 +02:00
|
|
|
db::IOServiceAccessorPtr io_service_accessor,
|
2020-12-09 14:32:17 +02:00
|
|
|
db::DbCallback db_reconnect_callback);
|
2019-10-23 20:29:05 +02:00
|
|
|
|
|
|
|
/// The exchange objects are used for transfer of data to/from the database.
|
|
|
|
/// They are pointed-to objects as the contents may change in "const" calls,
|
|
|
|
/// while the rest of this object does not. (At alternative would be to
|
|
|
|
/// declare them as "mutable".)
|
|
|
|
boost::scoped_ptr<MySqlLease4Exchange> exchange4_; ///< Exchange object
|
|
|
|
boost::scoped_ptr<MySqlLease6Exchange> exchange6_; ///< Exchange object
|
|
|
|
|
|
|
|
/// @brief MySQL connection
|
|
|
|
db::MySqlConnection conn_;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// @brief Type of pointers to contexts.
|
|
|
|
typedef boost::shared_ptr<MySqlLeaseContext> MySqlLeaseContextPtr;
|
|
|
|
|
|
|
|
/// @brief MySQL Lease Context Pool
|
|
|
|
///
|
|
|
|
/// This class provides a pool of contexts.
|
2021-01-22 01:36:41 +02:00
|
|
|
/// The manager will use this class to handle available contexts.
|
2020-01-27 15:55:03 +02:00
|
|
|
/// There is only one ContextPool per manager per back-end, which is created
|
|
|
|
/// and destroyed by the respective manager factory class.
|
2019-10-23 20:29:05 +02:00
|
|
|
class MySqlLeaseContextPool {
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// @brief The vector of available contexts.
|
|
|
|
std::vector<MySqlLeaseContextPtr> pool_;
|
|
|
|
|
2019-11-18 14:57:06 +01:00
|
|
|
/// @brief The mutex to protect pool access.
|
2019-10-23 20:29:05 +02:00
|
|
|
std::mutex mutex_;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// @brief Type of pointers to context pools.
|
|
|
|
typedef boost::shared_ptr<MySqlLeaseContextPool> MySqlLeaseContextPoolPtr;
|
|
|
|
|
2012-10-24 19:18:33 +01:00
|
|
|
/// @brief MySQL Lease Manager
|
2012-10-16 16:39:32 +01:00
|
|
|
///
|
2012-11-26 19:17:27 +00:00
|
|
|
/// This class provides the \ref isc::dhcp::LeaseMgr 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.
|
|
|
|
|
2023-02-21 10:15:43 +01:00
|
|
|
class MySqlLeaseMgr : public TrackingLeaseMgr {
|
2012-10-16 16:39:32 +01:00
|
|
|
public:
|
2015-04-17 13:39:45 +02:00
|
|
|
|
2012-10-16 16:39:32 +01:00
|
|
|
/// @brief Constructor
|
|
|
|
///
|
|
|
|
/// Uses the following keywords in the parameters passed to it to
|
|
|
|
/// connect to the database:
|
2012-10-24 19:18:33 +01:00
|
|
|
/// - 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)
|
2012-10-16 16:39:32 +01:00
|
|
|
///
|
2019-11-13 15:09:02 +01:00
|
|
|
/// Check the schema version and create an initial context.
|
2012-10-16 16:39:32 +01:00
|
|
|
///
|
|
|
|
/// @param parameters A data structure relating keywords and values
|
|
|
|
/// concerned with the database.
|
2012-10-24 19:18:33 +01:00
|
|
|
///
|
2012-11-08 12:14:10 +00:00
|
|
|
/// @throw isc::dhcp::NoDatabaseName Mandatory database name not given
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOpenError Error opening the database or the schema
|
2018-05-31 09:41:46 -04:00
|
|
|
/// version is incorrect.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-08 12:14:10 +00:00
|
|
|
/// failed.
|
2020-11-06 11:59:54 +02:00
|
|
|
MySqlLeaseMgr(const db::DatabaseConnection::ParameterMap& parameters);
|
2012-10-16 16:39:32 +01:00
|
|
|
|
|
|
|
/// @brief Destructor (closes database)
|
|
|
|
virtual ~MySqlLeaseMgr();
|
|
|
|
|
2019-12-05 00:12:41 +01:00
|
|
|
/// @brief Create a new context.
|
2019-10-23 20:29:05 +02:00
|
|
|
///
|
2019-11-18 16:02:02 +01:00
|
|
|
/// The database is opened with all the SQL commands pre-compiled.
|
2019-10-23 20:29:05 +02:00
|
|
|
///
|
2019-10-23 23:52:30 +02:00
|
|
|
/// @return A new (never null) context.
|
|
|
|
/// @throw isc::dhcp::NoDatabaseName Mandatory database name not given.
|
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
|
|
|
/// failed.
|
2019-11-13 15:09:02 +01:00
|
|
|
MySqlLeaseContextPtr createContext() const;
|
2019-10-23 20:29:05 +02:00
|
|
|
|
2020-11-05 01:23:11 +02:00
|
|
|
/// @brief Attempts to reconnect the server to the lease DB backend manager.
|
|
|
|
///
|
|
|
|
/// This is a self-rescheduling function that attempts to reconnect to the
|
|
|
|
/// server's lease DB backends after connectivity to one or more have been
|
|
|
|
/// lost. Upon entry it will attempt to reconnect via
|
|
|
|
/// @ref LeaseMgrFactory::create.
|
|
|
|
/// If this is successful, DHCP servicing is re-enabled and server returns
|
|
|
|
/// to normal operation.
|
|
|
|
///
|
|
|
|
/// If reconnection fails and the maximum number of retries has not been
|
|
|
|
/// exhausted, it will schedule a call to itself to occur at the
|
|
|
|
/// configured retry interval. DHCP service remains disabled.
|
|
|
|
///
|
|
|
|
/// If the maximum number of retries has been exhausted an error is logged
|
|
|
|
/// and the server shuts down.
|
|
|
|
///
|
2020-12-09 14:32:17 +02:00
|
|
|
/// This function is passed to the connection recovery mechanism. It will be
|
|
|
|
/// invoked when a connection loss is detected.
|
|
|
|
///
|
2020-11-05 01:23:11 +02:00
|
|
|
/// @param db_reconnect_ctl pointer to the ReconnectCtl containing the
|
|
|
|
/// configured reconnect parameters.
|
|
|
|
/// @return true if connection has been recovered, false otherwise.
|
2022-04-04 15:36:27 +02:00
|
|
|
static bool dbReconnect(util::ReconnectCtlPtr db_reconnect_ctl);
|
2020-11-05 01:23:11 +02:00
|
|
|
|
2015-06-19 14:30:51 +02:00
|
|
|
/// @brief Local version of getDBVersion() class method
|
|
|
|
static std::string getDBVersion();
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Adds an IPv4 lease
|
2012-10-16 16:39:32 +01:00
|
|
|
///
|
|
|
|
/// @param lease lease to be added
|
2012-10-20 22:52:25 +01:00
|
|
|
///
|
|
|
|
/// @result true if the lease was added, false if not (because a lease
|
|
|
|
/// with the same address was already there).
|
|
|
|
///
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-08 12:14:10 +00:00
|
|
|
/// failed.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual bool addLease(const Lease4Ptr& lease) override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Adds an IPv6 lease
|
2012-10-16 16:39:32 +01:00
|
|
|
///
|
|
|
|
/// @param lease lease to be added
|
2012-10-20 22:52:25 +01:00
|
|
|
///
|
|
|
|
/// @result true if the lease was added, false if not (because a lease
|
|
|
|
/// with the same address was already there).
|
|
|
|
///
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-08 12:14:10 +00:00
|
|
|
/// failed.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual bool addLease(const Lease6Ptr& lease) override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
|
|
|
/// @brief Returns an IPv4 lease for specified IPv4 address
|
|
|
|
///
|
|
|
|
/// This method return a lease that is associated with a given address.
|
2012-12-07 11:18:47 +00:00
|
|
|
/// For other query types (by hardware addr, by Client ID) there can be
|
2012-10-16 16:39:32 +01:00
|
|
|
/// several leases in different subnets (e.g. for mobile clients that
|
|
|
|
/// got address in different subnets). However, for a single address
|
|
|
|
/// there can be only one lease, so this method returns a pointer to
|
|
|
|
/// a single lease, not a container of leases.
|
|
|
|
///
|
|
|
|
/// @param addr address of the searched lease
|
|
|
|
///
|
|
|
|
/// @return smart pointer to the lease (or NULL if a lease is not found)
|
2012-11-30 15:49:42 +00:00
|
|
|
///
|
|
|
|
/// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to
|
|
|
|
/// fit into the space allocated for the result. This indicates a
|
|
|
|
/// programming error.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-30 15:49:42 +00:00
|
|
|
/// failed.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr) const override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
|
|
|
/// @brief Returns existing IPv4 leases for specified hardware address.
|
|
|
|
///
|
|
|
|
/// Although in the usual case there will be only one lease, for mobile
|
|
|
|
/// clients or clients with multiple static/fixed/reserved leases there
|
|
|
|
/// can be more than one. Thus return type is a container, not a single
|
|
|
|
/// pointer.
|
|
|
|
///
|
|
|
|
/// @param hwaddr hardware address of the client
|
|
|
|
///
|
|
|
|
/// @return lease collection
|
2012-11-30 15:49:42 +00:00
|
|
|
///
|
|
|
|
/// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to
|
|
|
|
/// fit into the space allocated for the result. This indicates a
|
|
|
|
/// programming error.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-30 15:49:42 +00:00
|
|
|
/// failed.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual Lease4Collection getLease4(const isc::dhcp::HWAddr& hwaddr) const override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
|
|
|
/// @brief Returns existing IPv4 leases for specified hardware address
|
|
|
|
/// and a subnet
|
|
|
|
///
|
|
|
|
/// There can be at most one lease for a given HW address in a single
|
|
|
|
/// pool, so this method with either return a single lease or NULL.
|
|
|
|
///
|
|
|
|
/// @param hwaddr hardware address of the client
|
|
|
|
/// @param subnet_id identifier of the subnet that lease must belong to
|
|
|
|
///
|
|
|
|
/// @return a pointer to the lease (or NULL if a lease is not found)
|
2012-11-30 15:49:42 +00:00
|
|
|
///
|
|
|
|
/// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to
|
|
|
|
/// fit into the space allocated for the result. This indicates a
|
|
|
|
/// programming error.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-30 15:49:42 +00:00
|
|
|
/// failed.
|
2013-01-10 16:32:24 +01:00
|
|
|
virtual Lease4Ptr getLease4(const isc::dhcp::HWAddr& hwaddr,
|
2022-06-24 18:05:35 +02:00
|
|
|
SubnetID subnet_id) const override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2019-12-05 15:33:56 +02:00
|
|
|
/// @brief Returns existing IPv4 leases for specified client-id
|
2012-10-16 16:39:32 +01:00
|
|
|
///
|
|
|
|
/// Although in the usual case there will be only one lease, for mobile
|
|
|
|
/// clients or clients with multiple static/fixed/reserved leases there
|
|
|
|
/// can be more than one. Thus return type is a container, not a single
|
|
|
|
/// pointer.
|
|
|
|
///
|
|
|
|
/// @param clientid client identifier
|
|
|
|
///
|
|
|
|
/// @return lease collection
|
2012-11-30 15:49:42 +00:00
|
|
|
///
|
|
|
|
/// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to
|
|
|
|
/// fit into the space allocated for the result. This indicates a
|
|
|
|
/// programming error.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-30 15:49:42 +00:00
|
|
|
/// failed.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual Lease4Collection getLease4(const ClientId& clientid) const override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
|
|
|
/// @brief Returns existing IPv4 lease for specified client-id
|
|
|
|
///
|
|
|
|
/// There can be at most one lease for a given HW address in a single
|
|
|
|
/// pool, so this method with either return a single lease or NULL.
|
|
|
|
///
|
|
|
|
/// @param clientid client identifier
|
|
|
|
/// @param subnet_id identifier of the subnet that lease must belong to
|
|
|
|
///
|
|
|
|
/// @return a pointer to the lease (or NULL if a lease is not found)
|
2012-11-30 15:49:42 +00:00
|
|
|
///
|
|
|
|
/// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to
|
|
|
|
/// fit into the space allocated for the result. This indicates a
|
|
|
|
/// programming error.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-30 15:49:42 +00:00
|
|
|
/// failed.
|
2012-10-16 16:39:32 +01:00
|
|
|
virtual Lease4Ptr getLease4(const ClientId& clientid,
|
2022-06-24 18:05:35 +02:00
|
|
|
SubnetID subnet_id) const override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2018-01-09 14:49:14 +01:00
|
|
|
/// @brief Returns all IPv4 leases for the particular subnet identifier.
|
|
|
|
///
|
|
|
|
/// @param subnet_id subnet identifier.
|
|
|
|
///
|
|
|
|
/// @return Lease collection (may be empty if no IPv4 lease found).
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual Lease4Collection getLeases4(SubnetID subnet_id) const override;
|
2018-01-09 14:49:14 +01:00
|
|
|
|
2019-10-16 19:02:43 +02:00
|
|
|
/// @brief Returns all IPv4 leases for the particular hostname.
|
|
|
|
///
|
|
|
|
/// @param hostname hostname in lower case.
|
|
|
|
///
|
|
|
|
/// @return Lease collection (may be empty if no IPv4 lease found).
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual Lease4Collection getLeases4(const std::string& hostname) const override;
|
2019-10-16 19:02:43 +02:00
|
|
|
|
2018-01-09 14:49:14 +01:00
|
|
|
/// @brief Returns all IPv4 leases.
|
|
|
|
///
|
|
|
|
/// @return Lease collection (may be empty if no IPv4 lease found).
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual Lease4Collection getLeases4() const override;
|
2018-01-09 14:49:14 +01:00
|
|
|
|
2018-06-25 21:47:20 +02:00
|
|
|
/// @brief Returns range of IPv4 leases using paging.
|
|
|
|
///
|
|
|
|
/// This method implements paged browsing of the lease database. The first
|
|
|
|
/// parameter specifies a page size. The second parameter is optional and
|
|
|
|
/// specifies the starting address of the range. This address is excluded
|
|
|
|
/// from the returned range. The IPv4 zero address (default) denotes that
|
|
|
|
/// the first page should be returned. There is no guarantee about the
|
|
|
|
/// order of returned leases.
|
|
|
|
///
|
|
|
|
/// The typical usage of this method is as follows:
|
|
|
|
/// - Get the first page of leases by specifying IPv4 zero address as the
|
|
|
|
/// beginning of the range.
|
|
|
|
/// - Last address of the returned range should be used as a starting
|
|
|
|
/// address for the next page in the subsequent call.
|
|
|
|
/// - If the number of leases returned is lower than the page size, it
|
|
|
|
/// indicates that the last page has been retrieved.
|
|
|
|
/// - If there are no leases returned it indicates that the previous page
|
|
|
|
/// was the last page.
|
|
|
|
///
|
|
|
|
/// @param lower_bound_address IPv4 address used as lower bound for the
|
|
|
|
/// returned range.
|
|
|
|
/// @param page_size maximum size of the page returned.
|
|
|
|
///
|
|
|
|
/// @return Lease collection (may be empty if no IPv4 lease found).
|
|
|
|
virtual Lease4Collection
|
|
|
|
getLeases4(const asiolink::IOAddress& lower_bound_address,
|
2022-06-24 18:05:35 +02:00
|
|
|
const LeasePageSize& page_size) const override;
|
2018-06-25 21:47:20 +02:00
|
|
|
|
2012-10-16 16:39:32 +01:00
|
|
|
/// @brief Returns existing IPv6 lease for a given IPv6 address.
|
|
|
|
///
|
|
|
|
/// For a given address, we assume that there will be only one lease.
|
2013-03-06 08:41:51 -06:00
|
|
|
/// The assumption here is that there will not be site or link-local
|
2012-10-16 16:39:32 +01:00
|
|
|
/// addresses used, so there is no way of having address duplication.
|
|
|
|
///
|
2013-09-06 14:51:59 +02:00
|
|
|
/// @param type specifies lease type: (NA, TA or PD)
|
2012-10-16 16:39:32 +01:00
|
|
|
/// @param addr address of the searched lease
|
|
|
|
///
|
|
|
|
/// @return smart pointer to the lease (or NULL if a lease is not found)
|
2012-10-24 19:18:33 +01:00
|
|
|
///
|
2012-11-08 12:14:10 +00:00
|
|
|
/// @throw isc::BadValue record retrieved from database had an invalid
|
|
|
|
/// lease type field.
|
2012-11-30 15:49:42 +00:00
|
|
|
/// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to
|
|
|
|
/// fit into the space allocated for the result. This indicates a
|
|
|
|
/// programming error.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-08 12:14:10 +00:00
|
|
|
/// failed.
|
2013-09-18 15:44:48 +02:00
|
|
|
virtual Lease6Ptr getLease6(Lease::Type type,
|
2022-06-24 18:05:35 +02:00
|
|
|
const isc::asiolink::IOAddress& addr) const override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
|
|
|
/// @brief Returns existing IPv6 leases for a given DUID+IA combination
|
|
|
|
///
|
|
|
|
/// Although in the usual case there will be only one lease, for mobile
|
|
|
|
/// clients or clients with multiple static/fixed/reserved leases there
|
|
|
|
/// can be more than one. Thus return type is a container, not a single
|
|
|
|
/// pointer.
|
|
|
|
///
|
2013-09-06 14:51:59 +02:00
|
|
|
/// @param type specifies lease type: (NA, TA or PD)
|
2012-10-16 16:39:32 +01:00
|
|
|
/// @param duid client DUID
|
|
|
|
/// @param iaid IA identifier
|
|
|
|
///
|
|
|
|
/// @return smart pointer to the lease (or NULL if a lease is not found)
|
2012-11-30 15:49:42 +00:00
|
|
|
///
|
|
|
|
/// @throw isc::BadValue record retrieved from database had an invalid
|
|
|
|
/// lease type field.
|
|
|
|
/// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to
|
|
|
|
/// fit into the space allocated for the result. This indicates a
|
|
|
|
/// programming error.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-30 15:49:42 +00:00
|
|
|
/// failed.
|
2013-09-18 15:44:48 +02:00
|
|
|
virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
|
2022-06-24 18:05:35 +02:00
|
|
|
uint32_t iaid) const override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
|
|
|
/// @brief Returns existing IPv6 lease for a given DUID+IA combination
|
|
|
|
///
|
2013-09-06 14:51:59 +02:00
|
|
|
/// @param type specifies lease type: (NA, TA or PD)
|
2012-10-16 16:39:32 +01:00
|
|
|
/// @param duid client DUID
|
|
|
|
/// @param iaid IA identifier
|
|
|
|
/// @param subnet_id subnet id of the subnet the lease belongs to
|
|
|
|
///
|
2013-09-06 18:16:50 +02:00
|
|
|
/// @return lease collection (may be empty if no lease is found)
|
2012-11-30 15:49:42 +00:00
|
|
|
///
|
|
|
|
/// @throw isc::BadValue record retrieved from database had an invalid
|
|
|
|
/// lease type field.
|
|
|
|
/// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to
|
|
|
|
/// fit into the space allocated for the result. This indicates a
|
|
|
|
/// programming error.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-30 15:49:42 +00:00
|
|
|
/// failed.
|
2013-09-18 15:44:48 +02:00
|
|
|
virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
|
2022-06-24 18:05:35 +02:00
|
|
|
uint32_t iaid, SubnetID subnet_id) const override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2018-03-16 14:42:24 +01:00
|
|
|
/// @brief Returns all IPv6 leases for the particular subnet identifier.
|
2018-01-13 00:24:41 +01:00
|
|
|
///
|
|
|
|
/// @param subnet_id subnet identifier.
|
|
|
|
///
|
|
|
|
/// @return Lease collection (may be empty if no IPv6 lease found).
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual Lease6Collection getLeases6(SubnetID subnet_id) const override;
|
2018-01-13 00:24:41 +01:00
|
|
|
|
2019-10-16 19:02:43 +02:00
|
|
|
/// @brief Returns all IPv6 leases for the particular hostname.
|
|
|
|
///
|
|
|
|
/// @param hostname hostname in lower case.
|
|
|
|
///
|
|
|
|
/// @return Lease collection (may be empty if no IPv6 lease found).
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual Lease6Collection getLeases6(const std::string& hostname) const override;
|
2019-10-16 19:02:43 +02:00
|
|
|
|
2018-01-13 00:24:41 +01:00
|
|
|
/// @brief Returns all IPv6 leases.
|
|
|
|
///
|
|
|
|
/// @return Lease collection (may be empty if no IPv6 lease found).
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual Lease6Collection getLeases6() const override;
|
2018-08-13 17:47:53 +02:00
|
|
|
|
|
|
|
/// @brief Returns all IPv6 leases for the DUID.
|
|
|
|
///
|
|
|
|
/// @todo: implement an optimised of the query using index.
|
2018-07-22 17:00:50 +02:00
|
|
|
/// @return Lease collection (may be empty if no IPv6 lease found)
|
|
|
|
/// for the DUID.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual Lease6Collection getLeases6(const DUID& duid) const override;
|
2019-10-16 19:02:43 +02:00
|
|
|
|
2018-06-26 10:27:07 +02:00
|
|
|
/// @brief Returns range of IPv6 leases using paging.
|
|
|
|
///
|
|
|
|
/// This method implements paged browsing of the lease database. The first
|
|
|
|
/// parameter specifies a page size. The second parameter is optional and
|
|
|
|
/// specifies the starting address of the range. This address is excluded
|
|
|
|
/// from the returned range. The IPv6 zero address (default) denotes that
|
|
|
|
/// the first page should be returned. There is no guarantee about the
|
|
|
|
/// order of returned leases.
|
|
|
|
///
|
|
|
|
/// The typical usage of this method is as follows:
|
|
|
|
/// - Get the first page of leases by specifying IPv6 zero address as the
|
|
|
|
/// beginning of the range.
|
|
|
|
/// - Last address of the returned range should be used as a starting
|
|
|
|
/// address for the next page in the subsequent call.
|
|
|
|
/// - If the number of leases returned is lower than the page size, it
|
|
|
|
/// indicates that the last page has been retrieved.
|
|
|
|
/// - If there are no leases returned it indicates that the previous page
|
|
|
|
/// was the last page.
|
|
|
|
///
|
2018-06-26 13:53:01 +02:00
|
|
|
/// @param lower_bound_address IPv6 address used as lower bound for the
|
2018-06-26 10:27:07 +02:00
|
|
|
/// returned range.
|
|
|
|
/// @param page_size maximum size of the page returned.
|
|
|
|
///
|
|
|
|
/// @return Lease collection (may be empty if no IPv6 lease found).
|
|
|
|
virtual Lease6Collection
|
|
|
|
getLeases6(const asiolink::IOAddress& lower_bound_address,
|
2022-06-24 18:05:35 +02:00
|
|
|
const LeasePageSize& page_size) const override;
|
2018-06-26 10:27:07 +02:00
|
|
|
|
2024-01-12 14:11:37 +01:00
|
|
|
/// @brief Returns a page of IPv6 leases for a subnet identifier.
|
|
|
|
///
|
|
|
|
/// @param subnet_id subnet identifier.
|
|
|
|
/// @param lower_bound_address IPv6 address used as lower bound for the
|
|
|
|
/// returned range.
|
|
|
|
/// @param page_size maximum size of the page returned.
|
|
|
|
///
|
|
|
|
/// @return collection of IPv6 leases
|
|
|
|
virtual Lease6Collection
|
|
|
|
getLeases6(SubnetID subnet_id,
|
|
|
|
const asiolink::IOAddress& lower_bound_address,
|
|
|
|
const LeasePageSize& page_size) const override;
|
|
|
|
|
2018-02-13 18:28:40 +02:00
|
|
|
/// @brief Returns a collection of expired DHCPv4 leases.
|
2015-08-20 19:25:38 +02:00
|
|
|
///
|
|
|
|
/// This method returns at most @c max_leases expired leases. The leases
|
|
|
|
/// returned haven't been reclaimed, i.e. the database query must exclude
|
|
|
|
/// reclaimed leases from the results returned.
|
|
|
|
///
|
|
|
|
/// @param [out] expired_leases A container to which expired leases returned
|
|
|
|
/// by the database backend are added.
|
|
|
|
/// @param max_leases A maximum number of leases to be returned. If this
|
|
|
|
/// value is set to 0, all expired (but not reclaimed) leases are returned.
|
2018-02-13 18:28:40 +02:00
|
|
|
virtual void getExpiredLeases4(Lease4Collection& expired_leases,
|
2022-06-24 18:05:35 +02:00
|
|
|
const size_t max_leases) const override;
|
2015-08-20 19:25:38 +02:00
|
|
|
|
2018-02-13 18:28:40 +02:00
|
|
|
/// @brief Returns a collection of expired DHCPv6 leases.
|
2015-08-20 19:25:38 +02:00
|
|
|
///
|
|
|
|
/// This method returns at most @c max_leases expired leases. The leases
|
|
|
|
/// returned haven't been reclaimed, i.e. the database query must exclude
|
|
|
|
/// reclaimed leases from the results returned.
|
|
|
|
///
|
|
|
|
/// @param [out] expired_leases A container to which expired leases returned
|
|
|
|
/// by the database backend are added.
|
|
|
|
/// @param max_leases A maximum number of leases to be returned. If this
|
|
|
|
/// value is set to 0, all expired (but not reclaimed) leases are returned.
|
2018-02-13 18:28:40 +02:00
|
|
|
virtual void getExpiredLeases6(Lease6Collection& expired_leases,
|
2022-06-24 18:05:35 +02:00
|
|
|
const size_t max_leases) const override;
|
2015-08-20 19:25:38 +02:00
|
|
|
|
2012-10-16 16:39:32 +01:00
|
|
|
/// @brief Updates IPv4 lease.
|
|
|
|
///
|
2012-11-23 18:23:21 +00:00
|
|
|
/// Updates the record of the lease in the database (as identified by the
|
|
|
|
/// address) with the data in the passed lease object.
|
|
|
|
///
|
2012-10-16 16:39:32 +01:00
|
|
|
/// @param lease4 The lease to be updated.
|
|
|
|
///
|
2018-08-29 14:14:57 +02:00
|
|
|
/// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not
|
2012-11-23 18:23:21 +00:00
|
|
|
/// exist.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-23 18:23:21 +00:00
|
|
|
/// failed.
|
2020-10-16 16:07:41 +03:00
|
|
|
///
|
2020-10-21 18:23:42 +03:00
|
|
|
/// @note The current_cltt_ and current_valid_lft_ are used to maximize the
|
|
|
|
/// chance that only one thread or process performs an update or delete
|
|
|
|
/// operation on the lease by matching these values with the expiration time
|
|
|
|
/// data in the database.
|
2020-10-20 20:09:22 +03:00
|
|
|
/// @note The UPDATE query uses WHERE expire = ? to update the lease only if
|
2020-10-16 16:07:41 +03:00
|
|
|
/// the value matches the one received on the SELECT query, effectively
|
2020-10-21 18:23:42 +03:00
|
|
|
/// enforcing no update on the lease between SELECT and UPDATE with
|
|
|
|
/// different expiration time.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual void updateLease4(const Lease4Ptr& lease4) override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2012-11-08 13:14:19 +00:00
|
|
|
/// @brief Updates IPv6 lease.
|
2012-10-16 16:39:32 +01:00
|
|
|
///
|
2012-11-23 18:23:21 +00:00
|
|
|
/// Updates the record of the lease in the database (as identified by the
|
|
|
|
/// address) with the data in the passed lease object.
|
|
|
|
///
|
2012-11-08 13:14:19 +00:00
|
|
|
/// @param lease6 The lease to be updated.
|
2012-10-16 16:39:32 +01:00
|
|
|
///
|
2018-08-29 14:14:57 +02:00
|
|
|
/// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not
|
2012-11-08 12:14:10 +00:00
|
|
|
/// exist.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-08 12:14:10 +00:00
|
|
|
/// failed.
|
2020-10-16 16:07:41 +03:00
|
|
|
///
|
2020-10-21 18:23:42 +03:00
|
|
|
/// @note The current_cltt_ and current_valid_lft_ are used to maximize the
|
|
|
|
/// chance that only one thread or process performs an update or delete
|
|
|
|
/// operation on the lease by matching these values with the expiration time
|
|
|
|
/// data in the database.
|
2020-10-20 20:09:22 +03:00
|
|
|
/// @note The UPDATE query uses WHERE expire = ? to update the lease only if
|
2020-10-16 16:07:41 +03:00
|
|
|
/// the value matches the one received on the SELECT query, effectively
|
2020-10-21 18:23:42 +03:00
|
|
|
/// enforcing no update on the lease between SELECT and UPDATE with
|
|
|
|
/// different expiration time.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual void updateLease6(const Lease6Ptr& lease6) override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2019-12-06 11:22:37 +02:00
|
|
|
/// @brief Deletes an IPv4 lease.
|
2012-10-16 16:39:32 +01:00
|
|
|
///
|
2019-12-06 20:06:05 +02:00
|
|
|
/// @param lease IPv4 lease being deleted.
|
2012-10-16 16:39:32 +01:00
|
|
|
///
|
2019-12-06 20:06:05 +02:00
|
|
|
/// @return true if deletion was successful, false if no such lease exists.
|
2020-10-16 16:07:41 +03:00
|
|
|
///
|
2020-10-21 18:23:42 +03:00
|
|
|
/// @note The current_cltt_ and current_valid_lft_ are used to maximize the
|
|
|
|
/// chance that only one thread or process performs an update or delete
|
|
|
|
/// operation on the lease by matching these values with the expiration time
|
|
|
|
/// data in the database.
|
2020-10-16 16:07:41 +03:00
|
|
|
/// @note The DELETE query uses WHERE expire = ? to delete the lease only if
|
|
|
|
/// the value matches the one received on the SELECT query, effectively
|
2020-10-21 18:23:42 +03:00
|
|
|
/// enforcing no update on the lease between SELECT and DELETE with
|
|
|
|
/// different expiration time.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual bool deleteLease(const Lease4Ptr& lease) override;
|
2019-12-06 11:22:37 +02:00
|
|
|
|
|
|
|
/// @brief Deletes an IPv6 lease.
|
2012-10-24 19:18:33 +01:00
|
|
|
///
|
2019-12-06 20:06:05 +02:00
|
|
|
/// @param lease IPv6 lease being deleted.
|
2019-12-06 11:22:37 +02:00
|
|
|
///
|
2019-12-06 20:06:05 +02:00
|
|
|
/// @return true if deletion was successful, false if no such lease exists.
|
2020-10-16 16:07:41 +03:00
|
|
|
///
|
2020-10-21 18:23:42 +03:00
|
|
|
/// @note The current_cltt_ and current_valid_lft_ are used to maximize the
|
|
|
|
/// chance that only one thread or process performs an update or delete
|
|
|
|
/// operation on the lease by matching these values with the expiration time
|
|
|
|
/// data in the database.
|
2020-10-16 16:07:41 +03:00
|
|
|
/// @note The DELETE query uses WHERE expire = ? to delete the lease only if
|
|
|
|
/// the value matches the one received on the SELECT query, effectively
|
2020-10-21 18:23:42 +03:00
|
|
|
/// enforcing no update on the lease between SELECT and DELETE with
|
|
|
|
/// different expiration time.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual bool deleteLease(const Lease6Ptr& lease) override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2015-08-20 19:25:38 +02:00
|
|
|
/// @brief Deletes all expired-reclaimed DHCPv4 leases.
|
|
|
|
///
|
|
|
|
/// @param secs Number of seconds since expiration of leases before
|
|
|
|
/// they can be removed. Leases which have expired later than this
|
|
|
|
/// time will not be deleted.
|
2015-09-03 11:35:25 +02:00
|
|
|
///
|
|
|
|
/// @return Number of leases deleted.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs) override;
|
2015-08-20 19:25:38 +02:00
|
|
|
|
2018-02-13 18:28:40 +02:00
|
|
|
/// @brief Deletes all expired-reclaimed DHCPv6 leases.
|
|
|
|
///
|
|
|
|
/// @param secs Number of seconds since expiration of leases before
|
|
|
|
/// they can be removed. Leases which have expired later than this
|
|
|
|
/// time will not be deleted.
|
|
|
|
///
|
|
|
|
/// @return Number of leases deleted.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs) override;
|
2018-02-13 18:28:40 +02:00
|
|
|
|
|
|
|
/// @brief Creates and runs the IPv4 lease stats query
|
|
|
|
///
|
|
|
|
/// It creates an instance of a MySqlLeaseStatsQuery4 and then
|
|
|
|
/// invokes its start method, which fetches its statistical data
|
2018-05-02 13:36:02 -04:00
|
|
|
/// result set by executing the ALL_LEASE_STATS4 query.
|
2018-02-13 18:28:40 +02:00
|
|
|
/// The query object is then returned.
|
|
|
|
///
|
|
|
|
/// @return The populated query as a pointer to an LeaseStatsQuery
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual LeaseStatsQueryPtr startLeaseStatsQuery4() override;
|
2018-02-13 18:28:40 +02:00
|
|
|
|
2023-05-24 15:04:49 +03:00
|
|
|
/// @brief Creates and runs the IPv4 lease stats query for all subnets and
|
|
|
|
/// pools
|
|
|
|
///
|
|
|
|
/// LeaseMgr derivations implement this method such that it creates and
|
|
|
|
/// returns an instance of an LeaseStatsQuery whose result set has been
|
|
|
|
/// populated with up to date IPv4 lease statistical data for all subnets
|
|
|
|
/// and pools.
|
|
|
|
/// Each row of the result set is an LeaseStatRow which ordered ascending
|
|
|
|
/// by subnet ID and pool ID.
|
|
|
|
///
|
|
|
|
/// @return A populated LeaseStatsQuery
|
|
|
|
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery4() override;
|
|
|
|
|
2018-05-02 13:36:02 -04:00
|
|
|
/// @brief Creates and runs the IPv4 lease stats query for a single subnet
|
|
|
|
///
|
|
|
|
/// It creates an instance of a MySqlLeaseStatsQuery4 for a single subnet
|
|
|
|
/// query and then invokes its start method in which the query constructs its
|
|
|
|
/// statistical data result set. The query object is then returned.
|
|
|
|
///
|
|
|
|
/// @param subnet_id id of the subnet for which stats are desired
|
|
|
|
/// @return A populated LeaseStatsQuery
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID& subnet_id) override;
|
2018-05-02 13:36:02 -04:00
|
|
|
|
|
|
|
/// @brief Creates and runs the IPv4 lease stats query for a single subnet
|
|
|
|
///
|
|
|
|
/// It creates an instance of a MySqlLeaseStatsQuery4 for a subnet range
|
|
|
|
/// query and then invokes its start method in which the query constructs its
|
|
|
|
/// statistical data result set. The query object is then returned.
|
|
|
|
///
|
|
|
|
/// @param first_subnet_id first subnet in the range of subnets
|
|
|
|
/// @param last_subnet_id last subnet in the range of subnets
|
|
|
|
/// @return A populated LeaseStatsQuery
|
|
|
|
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery4(const SubnetID& first_subnet_id,
|
2022-06-24 18:05:35 +02:00
|
|
|
const SubnetID& last_subnet_id) override;
|
2018-05-02 13:36:02 -04:00
|
|
|
|
2018-02-13 18:28:40 +02:00
|
|
|
/// @brief Creates and runs the IPv6 lease stats query
|
|
|
|
///
|
|
|
|
/// It creates an instance of a MySqlLeaseStatsQuery6 and then
|
|
|
|
/// invokes its start method, which fetches its statistical data
|
2018-05-02 13:36:02 -04:00
|
|
|
/// result set by executing the ALL_LEASE_STATS6 query.
|
2018-02-13 18:28:40 +02:00
|
|
|
/// The query object is then returned.
|
|
|
|
///
|
|
|
|
/// @return The populated query as a pointer to an LeaseStatsQuery
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual LeaseStatsQueryPtr startLeaseStatsQuery6() override;
|
2018-02-13 18:28:40 +02:00
|
|
|
|
2023-05-24 15:04:49 +03:00
|
|
|
/// @brief Creates and runs the IPv6 lease stats query for all subnets and
|
|
|
|
/// pools
|
|
|
|
///
|
|
|
|
/// LeaseMgr derivations implement this method such that it creates and
|
|
|
|
/// returns an instance of an LeaseStatsQuery whose result set has been
|
|
|
|
/// populated with up to date IPv6 lease statistical data for all subnets
|
|
|
|
/// and pools.
|
|
|
|
/// Each row of the result set is an LeaseStatRow which ordered ascending
|
|
|
|
/// by subnet ID and pool ID.
|
|
|
|
///
|
|
|
|
/// @return A populated LeaseStatsQuery
|
|
|
|
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery6() override;
|
|
|
|
|
2018-05-02 13:36:02 -04:00
|
|
|
/// @brief Creates and runs the IPv6 lease stats query for a single subnet
|
|
|
|
///
|
|
|
|
/// It creates an instance of a MySqlLeaseStatsQuery6 for a single subnet
|
|
|
|
/// query and then invokes its start method in which the query constructs its
|
|
|
|
/// statistical data result set. The query object is then returned.
|
|
|
|
///
|
|
|
|
/// @param subnet_id id of the subnet for which stats are desired
|
|
|
|
/// @return A populated LeaseStatsQuery
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID& subnet_id) override;
|
2018-05-02 13:36:02 -04:00
|
|
|
|
|
|
|
/// @brief Creates and runs the IPv6 lease stats query for a single subnet
|
|
|
|
///
|
|
|
|
/// It creates an instance of a MySqlLeaseStatsQuery6 for a subnet range
|
|
|
|
/// query and then invokes its start method in which the query constructs its
|
|
|
|
/// statistical data result set. The query object is then returned.
|
|
|
|
///
|
|
|
|
/// @param first_subnet_id first subnet in the range of subnets
|
|
|
|
/// @param last_subnet_id last subnet in the range of subnets
|
|
|
|
/// @return A populated LeaseStatsQuery
|
|
|
|
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6(const SubnetID& first_subnet_id,
|
2022-06-24 18:05:35 +02:00
|
|
|
const SubnetID& last_subnet_id) override;
|
2018-05-02 13:36:02 -04:00
|
|
|
|
2017-08-04 21:00:11 +02:00
|
|
|
/// @brief Removes specified IPv4 leases.
|
|
|
|
///
|
|
|
|
/// This rather dangerous method is able to remove all leases from specified
|
|
|
|
/// subnet.
|
|
|
|
///
|
|
|
|
/// @todo: Not implemented yet.
|
|
|
|
///
|
|
|
|
/// @param subnet_id identifier of the subnet
|
|
|
|
/// @return number of leases removed.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual size_t wipeLeases4(const SubnetID& subnet_id) override;
|
2017-08-04 21:00:11 +02:00
|
|
|
|
|
|
|
/// @brief Removed specified IPv6 leases.
|
|
|
|
///
|
|
|
|
/// This rather dangerous method is able to remove all leases from specified
|
|
|
|
/// subnet.
|
|
|
|
///
|
|
|
|
/// @todo: Not implemented yet.
|
|
|
|
///
|
|
|
|
/// @param subnet_id identifier of the subnet
|
|
|
|
/// @return number of leases removed.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual size_t wipeLeases6(const SubnetID& subnet_id) override;
|
2017-08-04 21:00:11 +02:00
|
|
|
|
2012-11-13 12:14:55 +00:00
|
|
|
/// @brief Return backend type
|
|
|
|
///
|
|
|
|
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
|
|
|
|
///
|
|
|
|
/// @return Type of the backend.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual std::string getType() const override {
|
2012-11-13 12:14:55 +00:00
|
|
|
return (std::string("mysql"));
|
|
|
|
}
|
|
|
|
|
2012-10-16 16:39:32 +01:00
|
|
|
/// @brief Returns backend name.
|
|
|
|
///
|
2019-12-05 15:33:56 +02:00
|
|
|
/// Each backend have specific name.
|
2012-11-13 12:14:55 +00:00
|
|
|
///
|
|
|
|
/// @return Name of the backend.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual std::string getName() const override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
|
|
|
/// @brief Returns description of the backend.
|
|
|
|
///
|
|
|
|
/// This description may be multiline text that describes the backend.
|
2012-11-13 12:14:55 +00:00
|
|
|
///
|
|
|
|
/// @return Description of the backend.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual std::string getDescription() const override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
|
|
|
/// @brief Returns backend version.
|
|
|
|
///
|
2023-10-18 18:30:33 +03:00
|
|
|
/// @param timer_name The DB reconnect timer name.
|
2012-10-16 16:39:32 +01:00
|
|
|
/// @return Version number as a pair of unsigned integers. "first" is the
|
|
|
|
/// major version number, "second" the minor number.
|
|
|
|
///
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-08 12:14:10 +00:00
|
|
|
/// failed.
|
2023-12-13 18:15:49 +02:00
|
|
|
virtual std::pair<uint32_t, uint32_t> getVersion(const std::string& timer_name = std::string()) const override;
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2012-10-20 22:52:25 +01:00
|
|
|
/// @brief Commit Transactions
|
|
|
|
///
|
|
|
|
/// Commits all pending database operations. On databases that don't
|
|
|
|
/// support transactions, this is a no-op.
|
|
|
|
///
|
2019-10-23 20:29:05 +02:00
|
|
|
/// MySQL supports transactions but this manager does not use them.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual void commit() override;
|
2012-10-20 22:52:25 +01:00
|
|
|
|
|
|
|
/// @brief Rollback Transactions
|
|
|
|
///
|
|
|
|
/// Rolls back all pending database operations. On databases that don't
|
|
|
|
/// support transactions, this is a no-op.
|
|
|
|
///
|
2019-10-23 20:29:05 +02:00
|
|
|
/// MySQL supports transactions but this manager does not use them.
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual void rollback() override;
|
2012-10-20 22:52:25 +01:00
|
|
|
|
2012-10-22 10:49:51 +01:00
|
|
|
/// @brief Statement Tags
|
2012-10-18 11:33:51 +01:00
|
|
|
///
|
2019-12-05 15:33:56 +02:00
|
|
|
/// The contents of the enum are indexes into the list of compiled SQL
|
|
|
|
/// statements
|
2012-10-18 11:33:51 +01:00
|
|
|
enum StatementIndex {
|
2015-09-07 13:58:22 +02:00
|
|
|
DELETE_LEASE4, // Delete from lease4 by address
|
|
|
|
DELETE_LEASE4_STATE_EXPIRED, // Delete expired lease4 in a given state
|
|
|
|
DELETE_LEASE6, // Delete from lease6 by address
|
|
|
|
DELETE_LEASE6_STATE_EXPIRED, // Delete expired lease6 in a given state
|
2018-01-09 14:49:14 +01:00
|
|
|
GET_LEASE4, // Get all IPv4 leases
|
2015-09-07 13:58:22 +02:00
|
|
|
GET_LEASE4_ADDR, // Get lease4 by address
|
|
|
|
GET_LEASE4_CLIENTID, // Get lease4 by client ID
|
|
|
|
GET_LEASE4_CLIENTID_SUBID, // Get lease4 by client ID & subnet ID
|
|
|
|
GET_LEASE4_HWADDR, // Get lease4 by HW address
|
|
|
|
GET_LEASE4_HWADDR_SUBID, // Get lease4 by HW address & subnet ID
|
2018-06-25 21:47:20 +02:00
|
|
|
GET_LEASE4_PAGE, // Get page of leases beginning with an address
|
2023-04-05 21:23:11 +02:00
|
|
|
GET_LEASE4_UCTX_PAGE, // Get page of leases with user context
|
2018-06-26 10:27:07 +02:00
|
|
|
GET_LEASE4_SUBID, // Get IPv4 leases by subnet ID
|
2019-10-16 19:02:43 +02:00
|
|
|
GET_LEASE4_HOSTNAME, // Get IPv4 leases by hostname
|
2015-09-07 13:58:22 +02:00
|
|
|
GET_LEASE4_EXPIRE, // Get lease4 by expiration.
|
2023-03-30 22:51:46 +02:00
|
|
|
GET_LEASE4_RELAYID, // Get page of lease by relay ID.
|
|
|
|
GET_LEASE4_RELAYID_QST, // Get page of leases by relay ID and query start time.
|
|
|
|
GET_LEASE4_RELAYID_QSET, // Get page of leases by relay ID and query start and end times.
|
|
|
|
GET_LEASE4_RELAYID_QET, // Get page of leases by relay ID and query end time.
|
|
|
|
GET_LEASE4_REMOTEID, // Get page of lease by remote ID.
|
|
|
|
GET_LEASE4_REMOTEID_QST, // Get page of leases by remote ID and query start time.
|
|
|
|
GET_LEASE4_REMOTEID_QSET, // Get page of leases by remote ID and query start and end times.
|
|
|
|
GET_LEASE4_REMOTEID_QET, // Get page of leases by remote ID and query end time.
|
2018-01-13 00:24:41 +01:00
|
|
|
GET_LEASE6, // Get all IPv6 leases
|
2023-05-25 18:46:47 +02:00
|
|
|
GET_LEASE6_ADDR, // Get lease6 by address and type
|
2015-09-07 13:58:22 +02:00
|
|
|
GET_LEASE6_DUID_IAID, // Get lease6 by DUID and IAID
|
|
|
|
GET_LEASE6_DUID_IAID_SUBID, // Get lease6 by DUID, IAID and subnet ID
|
2018-06-26 10:27:07 +02:00
|
|
|
GET_LEASE6_PAGE, // Get page of leases beginning with an address
|
2023-04-05 21:23:11 +02:00
|
|
|
GET_LEASE6_UCTX_PAGE, // Get page of leases with user context
|
2018-03-16 14:42:24 +01:00
|
|
|
GET_LEASE6_SUBID, // Get IPv6 leases by subnet ID
|
2024-01-12 14:11:37 +01:00
|
|
|
GET_LEASE6_SUBID_PAGE, // Get page of IPv6 leases by subnet ID
|
2018-07-22 17:00:50 +02:00
|
|
|
GET_LEASE6_DUID, // Get IPv6 leases by DUID
|
2019-10-16 19:02:43 +02:00
|
|
|
GET_LEASE6_HOSTNAME, // Get IPv6 leases by hostname
|
2015-09-07 13:58:22 +02:00
|
|
|
GET_LEASE6_EXPIRE, // Get lease6 by expiration.
|
|
|
|
INSERT_LEASE4, // Add entry to lease4 table
|
|
|
|
INSERT_LEASE6, // Add entry to lease6 table
|
|
|
|
UPDATE_LEASE4, // Update a Lease4 entry
|
|
|
|
UPDATE_LEASE6, // Update a Lease6 entry
|
2018-05-02 13:36:02 -04:00
|
|
|
ALL_LEASE4_STATS, // Fetches IPv4 lease statistics
|
|
|
|
SUBNET_LEASE4_STATS, // Fetched IPv4 lease stats for a single subnet.
|
|
|
|
SUBNET_RANGE_LEASE4_STATS, // Fetched IPv4 lease stats for a subnet range.
|
2023-05-24 15:04:49 +03:00
|
|
|
ALL_POOL_LEASE4_STATS, // Fetches IPv4 lease pool statistics
|
2018-05-02 13:36:02 -04:00
|
|
|
ALL_LEASE6_STATS, // Fetches IPv6 lease statistics
|
|
|
|
SUBNET_LEASE6_STATS, // Fetched IPv6 lease stats for a single subnet.
|
|
|
|
SUBNET_RANGE_LEASE6_STATS, // Fetched IPv6 lease stats for a subnet range.
|
2023-05-24 15:04:49 +03:00
|
|
|
ALL_POOL_LEASE6_STATS, // Fetches IPv6 lease pool statistics
|
2022-06-21 17:27:22 +03:00
|
|
|
CHECK_LEASE4_LIMITS, // Check if allocated IPv4 leases are inside the set limits.
|
|
|
|
CHECK_LEASE6_LIMITS, // Check if allocated IPv6 leases are inside the set limits.
|
2022-06-21 22:42:46 +03:00
|
|
|
IS_JSON_SUPPORTED, // Checks if JSON support is enabled in the database.
|
2022-06-29 20:56:45 +03:00
|
|
|
GET_LEASE4_COUNT_BY_CLASS, // Fetches the IPv4 lease count for a given class.
|
|
|
|
GET_LEASE6_COUNT_BY_CLASS, // Fetches the IPv6 lease count for given class and lease type.
|
2023-05-24 10:17:05 +02:00
|
|
|
WIPE_RELAY_ID6, // Wipe the lease6_relay_id table
|
|
|
|
WIPE_REMOTE_ID6, // Wipe the lease6_remote_id table
|
|
|
|
DELETE_RELAY_ID6, // Delete a lease6_relay_id entry by address
|
|
|
|
DELETE_REMOTE_ID6, // Delete a lease6_remote_id entry by address
|
|
|
|
ADD_RELAY_ID6, // Add a lease6_relay_id entry
|
|
|
|
ADD_REMOTE_ID6, // Add a lease6_remote_id entry
|
|
|
|
GET_RELAY_ID6, // Get lease6_relay_id entries
|
|
|
|
GET_REMOTE_ID6, // Get lease6_remote_id entries
|
2023-05-25 00:28:45 +02:00
|
|
|
COUNT_RELAY_ID6, // Count the lease6_relay_id number of entries
|
|
|
|
COUNT_REMOTE_ID6, // Count the lease6_remote_id number of entries
|
2015-09-07 13:58:22 +02:00
|
|
|
NUM_STATEMENTS // Number of statements
|
2012-10-18 11:33:51 +01:00
|
|
|
};
|
|
|
|
|
2012-11-04 20:20:21 +00:00
|
|
|
private:
|
2020-01-16 11:58:00 +02:00
|
|
|
|
2012-11-21 12:44:18 +00:00
|
|
|
/// @brief Add Lease Common Code
|
|
|
|
///
|
2012-12-03 15:35:36 +00:00
|
|
|
/// This method performs the common actions for both flavours (V4 and V6)
|
|
|
|
/// of the addLease method. It binds the contents of the lease object to
|
|
|
|
/// the prepared statement and adds it to the database.
|
2012-11-21 12:44:18 +00:00
|
|
|
///
|
2019-10-23 20:29:05 +02:00
|
|
|
/// @param ctx Context
|
2016-12-14 16:57:44 +02:00
|
|
|
/// @param stindex Index of statement being executed
|
2012-11-21 12:44:18 +00:00
|
|
|
/// @param bind MYSQL_BIND array that has been created for the type
|
|
|
|
/// of lease in question.
|
|
|
|
///
|
|
|
|
/// @return true if the lease was added, false if it was not added because
|
|
|
|
/// a lease with that address already exists in the database.
|
|
|
|
///
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-21 12:44:18 +00:00
|
|
|
/// failed.
|
2020-01-10 16:17:18 +02:00
|
|
|
bool addLeaseCommon(MySqlLeaseContextPtr& ctx,
|
2019-10-23 20:29:05 +02:00
|
|
|
StatementIndex stindex, std::vector<MYSQL_BIND>& bind);
|
2012-11-21 12:44:18 +00:00
|
|
|
|
2012-11-23 12:05:55 +00:00
|
|
|
/// @brief Get Lease Collection Common Code
|
|
|
|
///
|
|
|
|
/// This method performs the common actions for obtaining multiple leases
|
|
|
|
/// from the database.
|
|
|
|
///
|
2019-10-23 20:29:05 +02:00
|
|
|
/// @param ctx Context
|
2012-11-23 12:05:55 +00:00
|
|
|
/// @param stindex Index of statement being executed
|
2012-11-26 19:17:27 +00:00
|
|
|
/// @param bind MYSQL_BIND array for input parameters
|
2012-11-23 12:05:55 +00:00
|
|
|
/// @param exchange Exchange object to use
|
2019-12-05 15:33:56 +02:00
|
|
|
/// @param result Returned collection of leases. Note that any leases in
|
2012-12-03 15:35:36 +00:00
|
|
|
/// the collection when this method is called are not erased: the
|
|
|
|
/// new data is appended to the end.
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @param single If true, only a single data item is to be retrieved.
|
|
|
|
/// If more than one is present, a MultipleRecords exception will
|
|
|
|
/// be thrown.
|
|
|
|
///
|
|
|
|
/// @throw isc::dhcp::BadValue Data retrieved from the database was invalid.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-23 18:23:21 +00:00
|
|
|
/// failed.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::MultipleRecords Multiple records were retrieved
|
2012-11-23 18:23:21 +00:00
|
|
|
/// from the database where only one was expected.
|
2012-11-23 12:05:55 +00:00
|
|
|
template <typename Exchange, typename LeaseCollection>
|
2020-01-10 16:17:18 +02:00
|
|
|
void getLeaseCollection(MySqlLeaseContextPtr& ctx,
|
2019-12-05 15:33:56 +02:00
|
|
|
StatementIndex stindex,
|
|
|
|
MYSQL_BIND* bind,
|
2012-11-23 18:23:21 +00:00
|
|
|
Exchange& exchange, LeaseCollection& result,
|
|
|
|
bool single = false) const;
|
2012-11-23 12:05:55 +00:00
|
|
|
|
2019-12-05 15:33:56 +02:00
|
|
|
/// @brief Get Lease4 Collection
|
2012-11-06 12:58:10 +00:00
|
|
|
///
|
2012-11-23 18:23:21 +00:00
|
|
|
/// Gets a collection of Lease4 objects. This is just an interface to
|
|
|
|
/// the get lease collection common code.
|
2012-11-06 12:58:10 +00:00
|
|
|
///
|
2019-10-23 20:29:05 +02:00
|
|
|
/// @param ctx Context
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @param stindex Index of statement being executed
|
2012-11-26 19:17:27 +00:00
|
|
|
/// @param bind MYSQL_BIND array for input parameters
|
2019-12-05 15:59:47 +01:00
|
|
|
/// @param result LeaseCollection object returned. Note that any leases in
|
2012-12-03 15:35:36 +00:00
|
|
|
/// the collection when this method is called are not erased: the
|
|
|
|
/// new data is appended to the end.
|
2012-11-23 18:23:21 +00:00
|
|
|
///
|
|
|
|
/// @throw isc::dhcp::BadValue Data retrieved from the database was invalid.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-23 18:23:21 +00:00
|
|
|
/// failed.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::MultipleRecords Multiple records were retrieved
|
2012-11-23 18:23:21 +00:00
|
|
|
/// from the database where only one was expected.
|
2020-01-10 16:17:18 +02:00
|
|
|
void getLeaseCollection(MySqlLeaseContextPtr& ctx,
|
2019-12-05 15:33:56 +02:00
|
|
|
StatementIndex stindex,
|
|
|
|
MYSQL_BIND* bind,
|
2012-11-23 18:23:21 +00:00
|
|
|
Lease4Collection& result) const {
|
2019-10-23 20:29:05 +02:00
|
|
|
getLeaseCollection(ctx, stindex, bind, ctx->exchange4_, result);
|
2012-11-23 18:23:21 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 15:33:56 +02:00
|
|
|
/// @brief Get Lease6 Collection
|
2012-11-23 18:23:21 +00:00
|
|
|
///
|
|
|
|
/// Gets a collection of Lease6 objects. This is just an interface to
|
|
|
|
/// the get lease collection common code.
|
|
|
|
///
|
2019-10-23 20:29:05 +02:00
|
|
|
/// @param ctx Context
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @param stindex Index of statement being executed
|
2012-11-26 19:17:27 +00:00
|
|
|
/// @param bind MYSQL_BIND array for input parameters
|
2019-12-05 15:59:47 +01:00
|
|
|
/// @param result LeaseCollection object returned. Note that any existing
|
2012-12-03 15:35:36 +00:00
|
|
|
/// data in the collection is erased first.
|
2012-11-23 18:23:21 +00:00
|
|
|
///
|
|
|
|
/// @throw isc::dhcp::BadValue Data retrieved from the database was invalid.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-23 18:23:21 +00:00
|
|
|
/// failed.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::MultipleRecords Multiple records were retrieved
|
2012-11-23 18:23:21 +00:00
|
|
|
/// from the database where only one was expected.
|
2020-01-10 16:17:18 +02:00
|
|
|
void getLeaseCollection(MySqlLeaseContextPtr& ctx,
|
2019-12-05 15:33:56 +02:00
|
|
|
StatementIndex stindex,
|
|
|
|
MYSQL_BIND* bind,
|
2012-11-23 18:23:21 +00:00
|
|
|
Lease6Collection& result) const {
|
2019-10-23 20:29:05 +02:00
|
|
|
getLeaseCollection(ctx, stindex, bind, ctx->exchange6_, result);
|
2012-11-23 18:23:21 +00:00
|
|
|
}
|
|
|
|
|
2012-12-03 15:35:36 +00:00
|
|
|
/// @brief Get Lease4 Common Code
|
2012-11-23 18:23:21 +00:00
|
|
|
///
|
|
|
|
/// This method performs the common actions for the various getLease4()
|
|
|
|
/// methods. It acts as an interface to the getLeaseCollection() method,
|
2016-12-14 16:57:44 +02:00
|
|
|
/// but retrieving only a single lease.
|
2012-11-23 18:23:21 +00:00
|
|
|
///
|
2019-10-23 20:29:05 +02:00
|
|
|
/// @param ctx Context
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @param stindex Index of statement being executed
|
2012-11-26 19:17:27 +00:00
|
|
|
/// @param bind MYSQL_BIND array for input parameters
|
2019-12-05 15:59:47 +01:00
|
|
|
/// @param result Lease4 object returned
|
2020-01-10 16:17:18 +02:00
|
|
|
void getLease(MySqlLeaseContextPtr& ctx,
|
2019-12-05 15:33:56 +02:00
|
|
|
StatementIndex stindex,
|
|
|
|
MYSQL_BIND* bind,
|
2012-11-23 18:23:21 +00:00
|
|
|
Lease4Ptr& result) const;
|
|
|
|
|
2012-12-03 15:35:36 +00:00
|
|
|
/// @brief Get Lease6 Common Code
|
2012-11-23 18:23:21 +00:00
|
|
|
///
|
2019-12-05 16:01:56 +01:00
|
|
|
/// This method performs the common actions for the various getLease6()
|
2012-11-23 18:23:21 +00:00
|
|
|
/// methods. It acts as an interface to the getLeaseCollection() method,
|
2016-12-14 16:57:44 +02:00
|
|
|
/// but retrieving only a single lease.
|
2012-11-23 18:23:21 +00:00
|
|
|
///
|
2019-10-23 20:29:05 +02:00
|
|
|
/// @param ctx Context
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @param stindex Index of statement being executed
|
2012-11-26 19:17:27 +00:00
|
|
|
/// @param bind MYSQL_BIND array for input parameters
|
2019-12-05 15:59:47 +01:00
|
|
|
/// @param result Lease6 object returned
|
2020-01-10 16:17:18 +02:00
|
|
|
void getLease(MySqlLeaseContextPtr& ctx,
|
2019-12-05 15:33:56 +02:00
|
|
|
StatementIndex stindex,
|
|
|
|
MYSQL_BIND* bind,
|
2019-10-23 20:29:05 +02:00
|
|
|
Lease6Ptr& result) const;
|
2012-11-23 18:23:21 +00:00
|
|
|
|
2015-09-07 13:29:17 +02:00
|
|
|
/// @brief Get expired leases common code.
|
|
|
|
///
|
|
|
|
/// This method retrieves expired and not reclaimed leases from the
|
|
|
|
/// lease database. The returned leases are ordered by the expiration
|
|
|
|
/// time. The maximum number of leases to be returned is specified
|
|
|
|
/// as an argument.
|
|
|
|
///
|
|
|
|
/// @param [out] expired_leases Reference to the container where the
|
|
|
|
/// retrieved leases are put.
|
|
|
|
/// @param max_leases Maximum number of leases to be returned.
|
|
|
|
/// @param statement_index One of the @c GET_LEASE4_EXPIRE or
|
|
|
|
/// @c GET_LEASE6_EXPIRE.
|
|
|
|
///
|
|
|
|
/// @tparam One of the @c Lease4Collection or @c Lease6Collection.
|
|
|
|
template<typename LeaseCollection>
|
|
|
|
void getExpiredLeasesCommon(LeaseCollection& expired_leases,
|
|
|
|
const size_t max_leases,
|
|
|
|
StatementIndex statement_index) const;
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Update lease common code
|
|
|
|
///
|
|
|
|
/// Holds the common code for updating a lease. It binds the parameters
|
|
|
|
/// to the prepared statement, executes it, then checks how many rows
|
|
|
|
/// were affected.
|
2012-11-06 12:58:10 +00:00
|
|
|
///
|
2019-10-23 20:29:05 +02:00
|
|
|
/// @param ctx Context
|
2012-11-06 12:58:10 +00:00
|
|
|
/// @param stindex Index of prepared statement to be executed
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @param bind Array of MYSQL_BIND objects representing the parameters.
|
2012-11-06 12:58:10 +00:00
|
|
|
/// (Note that the number is determined by the number of parameters
|
|
|
|
/// in the statement.)
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @param lease Pointer to the lease object whose record is being updated.
|
2012-11-06 12:58:10 +00:00
|
|
|
///
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @throw NoSuchLease Could not update a lease because no lease matches
|
|
|
|
/// the address given.
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-08 12:14:10 +00:00
|
|
|
/// failed.
|
2012-11-23 18:23:21 +00:00
|
|
|
template <typename LeasePtr>
|
2020-01-10 16:17:18 +02:00
|
|
|
void updateLeaseCommon(MySqlLeaseContextPtr& ctx,
|
2019-12-05 15:33:56 +02:00
|
|
|
StatementIndex stindex,
|
|
|
|
MYSQL_BIND* bind,
|
2012-11-26 19:17:27 +00:00
|
|
|
const LeasePtr& lease);
|
2012-11-23 18:23:21 +00:00
|
|
|
|
|
|
|
/// @brief Delete lease common code
|
|
|
|
///
|
|
|
|
/// Holds the common code for deleting a lease. It binds the parameters
|
|
|
|
/// to the prepared statement, executes the statement and checks to
|
|
|
|
/// see how many rows were deleted.
|
|
|
|
///
|
2023-02-21 10:15:43 +01:00
|
|
|
/// @param ctx Context
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @param stindex Index of prepared statement to be executed
|
|
|
|
/// @param bind Array of MYSQL_BIND objects representing the parameters.
|
|
|
|
/// (Note that the number is determined by the number of parameters
|
|
|
|
/// in the statement.)
|
|
|
|
///
|
2015-09-07 13:58:22 +02:00
|
|
|
/// @return Number of deleted leases.
|
2012-11-23 18:23:21 +00:00
|
|
|
///
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-23 18:23:21 +00:00
|
|
|
/// failed.
|
2023-02-21 10:15:43 +01:00
|
|
|
uint64_t deleteLeaseCommon(MySqlLeaseContextPtr& ctx,
|
|
|
|
StatementIndex stindex,
|
2019-12-05 15:33:56 +02:00
|
|
|
MYSQL_BIND* bind);
|
2015-09-07 13:58:22 +02:00
|
|
|
|
|
|
|
/// @brief Delete expired-reclaimed leases.
|
|
|
|
///
|
|
|
|
/// @param secs Number of seconds since expiration of leases before
|
|
|
|
/// they can be removed. Leases which have expired later than this
|
|
|
|
/// time will not be deleted.
|
|
|
|
/// @param statement_index One of the @c DELETE_LEASE4_STATE_EXPIRED or
|
|
|
|
/// @c DELETE_LEASE6_STATE_EXPIRED.
|
|
|
|
///
|
|
|
|
/// @return Number of leases deleted.
|
|
|
|
uint64_t deleteExpiredReclaimedLeasesCommon(const uint32_t secs,
|
|
|
|
StatementIndex statement_index);
|
|
|
|
|
2022-06-21 17:27:22 +03:00
|
|
|
/// @brief Checks if the lease limits set in the given user context are exceeded.
|
|
|
|
/// Contains common logic used by @ref checkLimits4 and @ref checkLimits6.
|
|
|
|
///
|
|
|
|
/// @param user_context all or part of the lease's user context which, for the intents and
|
|
|
|
/// purposes of lease limiting should have the following format
|
|
|
|
/// (not all nodes are mandatory and values are given only as examples):
|
|
|
|
/// { "ISC": { "limits": { "client-classes": [ { "name": "foo", "address-limit": 2, "prefix-limit": 1 } ],
|
|
|
|
/// "subnet": { "id": 1, "address-limit": 2, "prefix-limit": 1 } } } }
|
|
|
|
///
|
|
|
|
/// @return a string describing a limit that is being exceeded, or an empty
|
|
|
|
/// string if no limits are exceeded
|
|
|
|
std::string
|
|
|
|
checkLimits(isc::data::ConstElementPtr const& user_context, StatementIndex const stindex) const;
|
|
|
|
|
|
|
|
/// @brief Checks if the IPv4 lease limits set in the given user context are exceeded.
|
|
|
|
/// MySQL implementation.
|
|
|
|
///
|
|
|
|
/// @param user_context all or part of the lease's user context which, for the intents and
|
|
|
|
/// purposes of lease limiting should have the following format
|
|
|
|
/// (not all nodes are mandatory and values are given only as examples):
|
|
|
|
/// { "ISC": { "limits": { "client-classes": [ { "name": "foo", "address-limit": 2 } ],
|
|
|
|
/// "subnet": { "id": 1, "address-limit": 2 } } } }
|
|
|
|
///
|
|
|
|
/// @return a string describing a limit that is being exceeded, or an empty
|
|
|
|
/// string if no limits are exceeded
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual std::string
|
|
|
|
checkLimits4(isc::data::ConstElementPtr const& user_context) const override;
|
2022-06-21 17:27:22 +03:00
|
|
|
|
|
|
|
/// @brief Checks if the IPv6 lease limits set in the given user context are exceeded.
|
|
|
|
/// MySQL implementation.
|
|
|
|
///
|
|
|
|
/// @param user_context all or part of the lease's user context which, for the intents and
|
|
|
|
/// purposes of lease limiting should have the following format
|
|
|
|
/// (not all nodes are mandatory and values are given only as examples):
|
|
|
|
/// { "ISC": { "limits": { "client-classes": [ { "name": "foo", "address-limit": 2, "prefix-limit": 1 } ],
|
|
|
|
/// "subnet": { "id": 1, "address-limit": 2, "prefix-limit": 1 } } } }
|
|
|
|
///
|
|
|
|
/// @return a string describing a limit that is being exceeded, or an empty
|
|
|
|
/// string if no limits are exceeded
|
2022-06-24 18:05:35 +02:00
|
|
|
virtual std::string
|
|
|
|
checkLimits6(isc::data::ConstElementPtr const& user_context) const override;
|
2022-06-21 17:27:22 +03:00
|
|
|
|
2022-06-27 11:08:33 +03:00
|
|
|
/// @brief Checks if JSON support is enabled in the database.
|
|
|
|
/// MySQL implementation.
|
|
|
|
///
|
|
|
|
/// @return true if there is JSON support, false otherwise
|
2022-07-06 15:56:23 +03:00
|
|
|
virtual bool isJsonSupported() const override;
|
2022-06-27 11:08:33 +03:00
|
|
|
|
2022-06-29 20:56:45 +03:00
|
|
|
/// @brief Returns the class lease count for a given class and lease type.
|
|
|
|
///
|
|
|
|
/// @param client_class client class for which the count is desired
|
|
|
|
/// @param ltype type of lease for which the count is desired. Defaults to
|
|
|
|
/// Lease::TYPE_V4.
|
|
|
|
///
|
|
|
|
/// @return number of leases
|
2022-07-06 15:56:23 +03:00
|
|
|
virtual size_t getClassLeaseCount(const ClientClass& client_class,
|
|
|
|
const Lease::Type& ltype = Lease::TYPE_V4) const override;
|
2022-06-29 20:56:45 +03:00
|
|
|
|
2022-07-04 21:34:01 +03:00
|
|
|
/// @brief Recount the leases per class for V4 leases.
|
2022-07-06 15:56:23 +03:00
|
|
|
virtual void recountClassLeases4() override;
|
2022-07-04 21:34:01 +03:00
|
|
|
|
|
|
|
/// @brief Recount the leases per class for V6 leases.
|
2022-07-06 15:56:23 +03:00
|
|
|
virtual void recountClassLeases6() override;
|
2022-07-04 21:34:01 +03:00
|
|
|
|
|
|
|
/// @brief Clears the class-lease count map.
|
2022-07-06 15:56:23 +03:00
|
|
|
virtual void clearClassLeaseCounts() override;
|
2022-07-04 21:34:01 +03:00
|
|
|
|
2022-09-05 17:43:04 +02:00
|
|
|
/// @brief Write V4 leases to a file.
|
|
|
|
virtual void writeLeases4(const std::string& /*filename*/) override;
|
|
|
|
|
|
|
|
/// @brief Write V6 leases to a file.
|
|
|
|
virtual void writeLeases6(const std::string& /*filename*/) override;
|
|
|
|
|
2012-10-20 22:52:25 +01:00
|
|
|
/// @brief Check Error and Throw Exception
|
|
|
|
///
|
2016-05-30 11:30:26 +02:00
|
|
|
/// This method invokes @ref MySqlConnection::checkError.
|
2012-10-20 22:52:25 +01:00
|
|
|
///
|
2019-10-23 20:29:05 +02:00
|
|
|
/// @param ctx Context
|
2012-10-20 22:52:25 +01:00
|
|
|
/// @param status Status code: non-zero implies an error
|
|
|
|
/// @param index Index of statement that caused the error
|
|
|
|
/// @param what High-level description of the error
|
|
|
|
///
|
2018-08-28 13:09:25 +02:00
|
|
|
/// @throw isc::db::DbOperationError An operation on the open database has
|
2012-11-08 12:14:10 +00:00
|
|
|
/// failed.
|
2020-01-10 16:17:18 +02:00
|
|
|
void checkError(MySqlLeaseContextPtr& ctx,
|
2019-10-23 20:29:05 +02:00
|
|
|
int status, StatementIndex index,
|
2015-10-23 16:41:27 -04:00
|
|
|
const char* what) const;
|
2012-10-20 22:52:25 +01:00
|
|
|
|
2023-05-25 02:29:39 +02:00
|
|
|
public:
|
2022-10-14 17:01:57 +02:00
|
|
|
/// The following queries are used to fulfill Bulk Lease Query
|
|
|
|
/// queries. They rely on relay data contained in lease's
|
|
|
|
/// user-context when the extended-store-info flag is enabled.
|
2022-09-22 11:38:19 -04:00
|
|
|
|
|
|
|
/// @brief Returns existing IPv4 leases with a given relay-id.
|
|
|
|
///
|
|
|
|
/// @param relay_id RAI Relay-ID sub-option value for relay_id of interest
|
|
|
|
/// @param lower_bound_address IPv4 address used as lower bound for the
|
|
|
|
/// returned range.
|
|
|
|
/// @param page_size maximum size of the page returned.
|
|
|
|
/// @param qry_start_time when not zero, only leases whose CLTT is greater than
|
|
|
|
/// or equal to this value will be included
|
|
|
|
/// @param qry_end_time when not zero, only leases whose CLTT is less than
|
|
|
|
/// or equal to this value will be included
|
|
|
|
///
|
|
|
|
/// @return collection of IPv4 leases
|
2022-09-22 23:23:31 +02:00
|
|
|
virtual Lease4Collection
|
|
|
|
getLeases4ByRelayId(const OptionBuffer& relay_id,
|
|
|
|
const asiolink::IOAddress& lower_bound_address,
|
|
|
|
const LeasePageSize& page_size,
|
|
|
|
const time_t& qry_start_time = 0,
|
|
|
|
const time_t& qry_end_time = 0) override;
|
2022-09-22 11:38:19 -04:00
|
|
|
|
|
|
|
/// @brief Returns existing IPv4 leases with a given remote-id.
|
|
|
|
///
|
|
|
|
/// @param remote_id RAI Remote-ID sub-option value for remote-id of interest
|
|
|
|
/// @param lower_bound_address IPv4 address used as lower bound for the
|
|
|
|
/// returned range.
|
|
|
|
/// @param page_size maximum size of the page returned.
|
|
|
|
/// @param qry_start_time when not zero, only leases whose CLTT is greater than
|
|
|
|
/// or equal to this value will be included. Defaults to zero.
|
|
|
|
/// @param qry_end_time when not zero, only leases whose CLTT is less than
|
|
|
|
/// or equal to this value will be included. Defaults to zero.
|
|
|
|
///
|
|
|
|
/// @return collection of IPv4 leases
|
2022-09-22 23:23:31 +02:00
|
|
|
virtual Lease4Collection
|
|
|
|
getLeases4ByRemoteId(const OptionBuffer& remote_id,
|
|
|
|
const asiolink::IOAddress& lower_bound_address,
|
|
|
|
const LeasePageSize& page_size,
|
|
|
|
const time_t& qry_start_time = 0,
|
|
|
|
const time_t& qry_end_time = 0) override;
|
2022-09-22 11:38:19 -04:00
|
|
|
|
|
|
|
/// @brief Returns existing IPv6 leases with a given relay-id.
|
|
|
|
///
|
2022-11-08 21:32:32 +01:00
|
|
|
/// @param relay_id DUID for relay_id of interest.
|
2022-09-22 11:38:19 -04:00
|
|
|
/// @param lower_bound_address IPv4 address used as lower bound for the
|
|
|
|
/// returned range.
|
|
|
|
/// @param page_size maximum size of the page returned.
|
|
|
|
///
|
|
|
|
/// @return collection of IPv6 leases
|
2022-09-22 23:23:31 +02:00
|
|
|
virtual Lease6Collection
|
|
|
|
getLeases6ByRelayId(const DUID& relay_id,
|
|
|
|
const asiolink::IOAddress& lower_bound_address,
|
|
|
|
const LeasePageSize& page_size) override;
|
2022-09-22 11:38:19 -04:00
|
|
|
|
|
|
|
/// @brief Returns existing IPv6 leases with a given remote-id.
|
|
|
|
///
|
2022-11-08 21:32:32 +01:00
|
|
|
/// @param remote_id remote-id option data of interest.
|
2022-09-22 11:38:19 -04:00
|
|
|
/// @param lower_bound_address IPv4 address used as lower bound for the
|
|
|
|
/// returned range.
|
|
|
|
/// @param page_size maximum size of the page returned.
|
|
|
|
///
|
|
|
|
/// @return collection of IPv6 leases
|
2022-09-22 23:23:31 +02:00
|
|
|
virtual Lease6Collection
|
|
|
|
getLeases6ByRemoteId(const OptionBuffer& remote_id,
|
|
|
|
const asiolink::IOAddress& lower_bound_address,
|
|
|
|
const LeasePageSize& page_size) override;
|
2022-09-22 11:38:19 -04:00
|
|
|
|
2023-04-05 21:23:11 +02:00
|
|
|
/// @brief Upgrade extended info (v4).
|
|
|
|
///
|
2023-05-22 23:11:02 +02:00
|
|
|
/// For all leases with a not null user context.
|
|
|
|
/// - sanitize the user context
|
|
|
|
/// - update relay and remote ids
|
|
|
|
/// - when the lease was modified update it in the database
|
|
|
|
/// This function implements the new BLQ hook command named
|
|
|
|
/// "extended-info4-upgrade".
|
|
|
|
///
|
2023-04-05 21:23:11 +02:00
|
|
|
/// @param page_size The page size used for retrieval.
|
|
|
|
/// @return The number of updates in the database.
|
2023-05-23 16:23:41 +02:00
|
|
|
virtual size_t upgradeExtendedInfo4(const LeasePageSize& page_size) override;
|
2023-04-05 21:23:11 +02:00
|
|
|
|
2023-05-26 11:12:12 +02:00
|
|
|
/// @brief Upgrade extended info (v6).
|
|
|
|
///
|
|
|
|
/// All leases with a not null user context.
|
|
|
|
/// - sanitize the user context
|
|
|
|
/// - update relay and remote id tables
|
|
|
|
/// - when the lease was modified update it in the database
|
|
|
|
/// This function implements the new BLQ hook command named
|
|
|
|
/// "extended-info6-upgrade".
|
|
|
|
///
|
|
|
|
/// @param page_size The page size used for retrieval.
|
|
|
|
/// @return The number of updates in the database.
|
|
|
|
virtual size_t upgradeExtendedInfo6(const LeasePageSize& page_size) override;
|
|
|
|
|
2023-05-25 01:38:11 +02:00
|
|
|
/// @brief Wipe by-relay-id table (v6).
|
|
|
|
virtual void wipeExtendedInfoTables6() override;
|
|
|
|
|
2023-05-25 14:55:07 +02:00
|
|
|
/// @brief Return the by-relay-id table size.
|
|
|
|
///
|
|
|
|
/// @return The size of the by-relay-id table.
|
|
|
|
virtual size_t byRelayId6size() const override;
|
|
|
|
|
|
|
|
/// @brief Return the by-remote-id table size.
|
|
|
|
///
|
|
|
|
/// @return The size of the by-remote-id table.
|
|
|
|
virtual size_t byRemoteId6size() const override;
|
|
|
|
|
2023-05-25 02:29:39 +02:00
|
|
|
private:
|
2023-02-21 10:15:43 +01:00
|
|
|
/// @brief Context RAII allocator.
|
2022-10-14 17:01:57 +02:00
|
|
|
class MySqlLeaseContextAlloc {
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// @brief Constructor
|
|
|
|
///
|
|
|
|
/// This constructor takes a context of the pool if one is available
|
|
|
|
/// or creates a new one.
|
|
|
|
///
|
|
|
|
/// @param mgr A parent instance
|
|
|
|
MySqlLeaseContextAlloc(const MySqlLeaseMgr& mgr);
|
|
|
|
|
|
|
|
/// @brief Destructor
|
|
|
|
///
|
|
|
|
/// This destructor puts back the context in the pool.
|
|
|
|
~MySqlLeaseContextAlloc();
|
|
|
|
|
|
|
|
/// @brief The context
|
|
|
|
MySqlLeaseContextPtr ctx_;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/// @brief The manager
|
|
|
|
const MySqlLeaseMgr& mgr_;
|
|
|
|
};
|
|
|
|
|
2023-02-21 10:15:43 +01:00
|
|
|
/// @brief Context RAII allocator for lease tracking.
|
|
|
|
///
|
|
|
|
/// This context should be used in the non-const calls that
|
|
|
|
/// may trigger callbacks for lease tracking.
|
|
|
|
class MySqlLeaseTrackingContextAlloc {
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// @brief Constructor
|
|
|
|
///
|
|
|
|
/// This constructor takes a context of the pool if one is available
|
|
|
|
/// or creates a new one.
|
|
|
|
///
|
|
|
|
/// @param mgr A parent instance
|
|
|
|
/// @param lease allocated or deallocated lease instance.
|
|
|
|
MySqlLeaseTrackingContextAlloc(MySqlLeaseMgr& mgr, const LeasePtr& lease);
|
|
|
|
|
|
|
|
/// @brief Destructor
|
|
|
|
///
|
|
|
|
/// This destructor puts back the context in the pool.
|
|
|
|
~MySqlLeaseTrackingContextAlloc();
|
|
|
|
|
|
|
|
/// @brief The context
|
|
|
|
MySqlLeaseContextPtr ctx_;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/// @brief The manager
|
|
|
|
MySqlLeaseMgr& mgr_;
|
|
|
|
|
|
|
|
/// @brief Tracked lease instance.
|
|
|
|
LeasePtr lease_;
|
|
|
|
};
|
|
|
|
|
2022-10-14 17:01:57 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
/// Extended information / Bulk Lease Query shared interface.
|
|
|
|
|
2022-10-14 02:27:32 +02:00
|
|
|
/// @brief Delete lease6 extended info from tables.
|
|
|
|
///
|
|
|
|
/// @param addr The address of the lease.
|
|
|
|
virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress& addr) override;
|
|
|
|
|
|
|
|
/// @brief Add lease6 extended info into by-relay-id table.
|
|
|
|
///
|
|
|
|
/// @param lease_addr The address of the lease.
|
|
|
|
/// @param relay_id The relay id from the relay header options.
|
|
|
|
virtual void addRelayId6(const isc::asiolink::IOAddress& lease_addr,
|
|
|
|
const std::vector<uint8_t>& relay_id) override;
|
|
|
|
|
|
|
|
/// @brief Add lease6 extended info into by-remote-id table.
|
|
|
|
///
|
|
|
|
/// @param lease_addr The address of the lease.
|
|
|
|
/// @param remote_id The remote id from the relay header options.
|
|
|
|
virtual void addRemoteId6(const isc::asiolink::IOAddress& lease_addr,
|
|
|
|
const std::vector<uint8_t>& remote_id) override;
|
|
|
|
|
2019-10-23 20:29:05 +02:00
|
|
|
private:
|
2023-05-25 02:29:39 +02:00
|
|
|
/// @brief Delete lease6 extended info from by-relay-id table.
|
|
|
|
///
|
|
|
|
/// @param addr The address of the lease.
|
|
|
|
void deleteRelayId6(const isc::asiolink::IOAddress& addr);
|
|
|
|
|
|
|
|
/// @brief Delete lease6 extended info from by-remote-id table.
|
|
|
|
///
|
|
|
|
/// @param addr The address of the lease.
|
|
|
|
void deleteRemoteId6(const isc::asiolink::IOAddress& addr);
|
2019-10-23 20:29:05 +02:00
|
|
|
|
2019-11-04 17:14:01 +01:00
|
|
|
// Members
|
|
|
|
|
2019-10-23 20:29:05 +02:00
|
|
|
/// @brief The parameters
|
|
|
|
db::DatabaseConnection::ParameterMap parameters_;
|
|
|
|
|
|
|
|
/// @brief The pool of contexts
|
|
|
|
MySqlLeaseContextPoolPtr pool_;
|
2020-11-12 23:36:48 +02:00
|
|
|
|
|
|
|
/// @brief Timer name used to register database reconnect timer.
|
|
|
|
std::string timer_name_;
|
2024-09-16 21:25:33 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
/// @brief Factory class method.
|
|
|
|
///
|
|
|
|
/// @param parameters A data structure relating keywords and values
|
|
|
|
/// concerned with the database.
|
|
|
|
///
|
|
|
|
/// @return The MySQL Lease Manager.
|
|
|
|
static TrackingLeaseMgrPtr
|
2024-09-17 00:10:10 +03:00
|
|
|
factory(const isc::db::DatabaseConnection::ParameterMap& parameters);
|
2012-10-16 16:39:32 +01:00
|
|
|
};
|
|
|
|
|
2024-09-17 23:43:15 +03:00
|
|
|
/// @brief Initialization structure used to register and deregister MySQL Lease Mgr.
|
2024-09-11 21:01:30 +03:00
|
|
|
struct MySqlLeaseMgrInit {
|
|
|
|
// Constructor registers
|
|
|
|
MySqlLeaseMgrInit() {
|
2024-09-18 12:20:29 +03:00
|
|
|
LeaseMgrFactory::registerFactory("mysql",
|
|
|
|
MySqlLeaseMgr::factory,
|
|
|
|
true,
|
2024-09-17 23:43:15 +03:00
|
|
|
MySqlLeaseMgr::getDBVersion);
|
2024-09-11 21:01:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destructor deregisters
|
|
|
|
~MySqlLeaseMgrInit() {
|
|
|
|
LeaseMgrFactory::deregisterFactory("mysql", true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-19 16:14:38 +02:00
|
|
|
} // namespace dhcp
|
|
|
|
} // namespace isc
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2012-10-29 13:43:31 +00:00
|
|
|
#endif // MYSQL_LEASE_MGR_H
|