Commit 5bd76e38 authored by Francis Dupont's avatar Francis Dupont

[393-global-search-through-leases-by-mac-or-hostname-w-o-specifying-a-subnet-i...

[393-global-search-through-leases-by-mac-or-hostname-w-o-specifying-a-subnet-id] Added get leases 4 and 4 by hostname to the API
parent 465cfbd9
......@@ -231,6 +231,8 @@ public:
static constexpr StatementTag GET_LEASE4_PAGE = "GET_LEASE4_PAGE";
// Get lease4 by subnet ID
static constexpr StatementTag GET_LEASE4_SUBID = "GET_LEASE4_SUBID";
// Get lease4 by hostname
static constexpr StatementTag GET_LEASE4_HOSTNAME = "GET_LEASE4_HOSTNAME";
/// @}
private:
......@@ -255,6 +257,7 @@ constexpr StatementTag CqlLease4Exchange::GET_LEASE4_HWADDR_SUBID;
constexpr StatementTag CqlLease4Exchange::GET_LEASE4_LIMIT;
constexpr StatementTag CqlLease4Exchange::GET_LEASE4_PAGE;
constexpr StatementTag CqlLease4Exchange::GET_LEASE4_SUBID;
constexpr StatementTag CqlLease4Exchange::GET_LEASE4_HOSTNAME;
StatementMap CqlLease4Exchange::tagged_statements_{
......@@ -393,6 +396,16 @@ StatementMap CqlLease4Exchange::tagged_statements_{
"fqdn_fwd, fqdn_rev, hostname, state, user_context "
"FROM lease4 "
"WHERE subnet_id = ? "
"ALLOW FILTERING "}},
// Gets an IPv4 lease(s) with specified hostname
{GET_LEASE4_HOSTNAME,
{GET_LEASE4_HOSTNAME,
"SELECT "
"address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state, user_context "
"FROM lease4 "
"WHERE hostname = ? "
"ALLOW FILTERING "}}
};
......@@ -908,6 +921,7 @@ public:
static constexpr StatementTag GET_LEASE6_DUID_IAID_SUBID = "GET_LEASE6_DUID_IAID_SUBID";
static constexpr StatementTag GET_LEASE6_LIMIT = "GET_LEASE6_LIMIT";
static constexpr StatementTag GET_LEASE6_PAGE = "GET_LEASE6_PAGE";
static constexpr StatementTag GET_LEASE6_HOSTNAME = "GET_LEASE6_HOSTNAME";
// @}
private:
......@@ -949,6 +963,7 @@ constexpr StatementTag CqlLease6Exchange::GET_LEASE6_DUID_IAID;
constexpr StatementTag CqlLease6Exchange::GET_LEASE6_DUID_IAID_SUBID;
constexpr StatementTag CqlLease6Exchange::GET_LEASE6_LIMIT;
constexpr StatementTag CqlLease6Exchange::GET_LEASE6_PAGE;
constexpr StatementTag CqlLease6Exchange::GET_LEASE6_HOSTNAME;
StatementMap CqlLease6Exchange::tagged_statements_ = {
......@@ -1076,7 +1091,20 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
"FROM lease6 "
"WHERE TOKEN(address) > TOKEN(?) "
"LIMIT ? "
"ALLOW FILTERING "}}
"ALLOW FILTERING "}},
// Gets an IPv6 lease(s) with specified hostname
{GET_LEASE6_HOSTNAME,
{GET_LEASE6_HOSTNAME,
"SELECT "
"address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
"lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
"hwaddr_source, state, user_context "
"FROM lease6 "
"WHERE hostname = ? "
"ALLOW FILTERING "}},
};
CqlLease6Exchange::CqlLease6Exchange(const CqlConnection &connection)
......@@ -2216,6 +2244,25 @@ CqlLeaseMgr::getLeases4(SubnetID subnet_id) const {
return (result);
}
Lease4Collection
CqlLeaseMgr::getLeases4(const std::string& hostname) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_HOSTNAME4)
.arg(hostname);
// Set up the WHERE clause value
AnyArray data;
std::string hostname_data(hostname);
data.add(&hostname_data);
// Get the data.
Lease4Collection result;
std::unique_ptr<CqlLease4Exchange> exchange4(new CqlLease4Exchange(dbconn_));
exchange4->getLeaseCollection(CqlLease4Exchange::GET_LEASE4_HOSTNAME, data, result);
return (result);
}
Lease4Collection
CqlLeaseMgr::getLeases4() const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET4);
......@@ -2311,7 +2358,7 @@ CqlLeaseMgr::getLeases6(const DUID& duid) const {
// Set up the WHERE clause value
AnyArray data;
CassBlob duid_data(duid.getDuid());
data.add(&duid_data);
......@@ -2389,6 +2436,25 @@ CqlLeaseMgr::getLeases6(SubnetID) const {
isc_throw(NotImplemented, "getLeases6(subnet_id) is not implemented");
}
Lease6Collection
CqlLeaseMgr::getLeases6(const std::string& hostname) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_HOSTNAME6)
.arg(hostname);
// Set up the WHERE clause value
AnyArray data;
std::string hostname_data(hostname);
data.add(&hostname_data);
// Get the data.
Lease6Collection result;
std::unique_ptr<CqlLease6Exchange> exchange6(new CqlLease6Exchange(dbconn_));
exchange6->getLeaseCollection(CqlLease6Exchange::GET_LEASE6_HOSTNAME, data, result);
return (result);
}
Lease6Collection
CqlLeaseMgr::getLeases6() const {
isc_throw(NotImplemented, "getLeases6() is not implemented");
......
......@@ -207,6 +207,13 @@ public:
/// this backend.
virtual Lease4Collection getLeases4(SubnetID subnet_id) const override;
/// @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).
virtual Lease4Collection getLeases4(const std::string& hostname) const override;
/// @brief Returns all IPv4 leases.
///
/// @return Lease collection (may be empty if no IPv4 lease found).
......@@ -309,6 +316,13 @@ public:
/// this backend.
virtual Lease6Collection getLeases6(SubnetID subnet_id) const override;
/// @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).
virtual Lease6Collection getLeases6(const std::string& hostname) const override;
/// @brief Returns all IPv6 leases.
///
/// @return Lease collection (may be empty if no IPv6 lease found).
......@@ -320,7 +334,7 @@ public:
///
/// @return Lease collection (may be empty if no IPv6 lease found).
virtual Lease6Collection getLeases6(const DUID& duid) const override;
/// @brief Returns range of IPv6 leases using paging.
///
/// This method implements paged browsing of the lease database. The first
......
// File created from ../../../src/lib/dhcpsrv/dhcpsrv_messages.mes on Mon Sep 30 2019 13:41
// File created from ../../../src/lib/dhcpsrv/dhcpsrv_messages.mes on Wed Oct 16 2019 17:52
#include <cstddef>
#include <log/message_types.h>
......@@ -63,6 +63,8 @@ extern const isc::log::MessageID DHCPSRV_CQL_GET_CLIENTID = "DHCPSRV_CQL_GET_CLI
extern const isc::log::MessageID DHCPSRV_CQL_GET_CLIENTID_HWADDR_SUBID = "DHCPSRV_CQL_GET_CLIENTID_HWADDR_SUBID";
extern const isc::log::MessageID DHCPSRV_CQL_GET_EXPIRED4 = "DHCPSRV_CQL_GET_EXPIRED4";
extern const isc::log::MessageID DHCPSRV_CQL_GET_EXPIRED6 = "DHCPSRV_CQL_GET_EXPIRED6";
extern const isc::log::MessageID DHCPSRV_CQL_GET_HOSTNAME4 = "DHCPSRV_CQL_GET_HOSTNAME4";
extern const isc::log::MessageID DHCPSRV_CQL_GET_HOSTNAME6 = "DHCPSRV_CQL_GET_HOSTNAME6";
extern const isc::log::MessageID DHCPSRV_CQL_GET_HWADDR = "DHCPSRV_CQL_GET_HWADDR";
extern const isc::log::MessageID DHCPSRV_CQL_GET_IAID_DUID = "DHCPSRV_CQL_GET_IAID_DUID";
extern const isc::log::MessageID DHCPSRV_CQL_GET_IAID_SUBID_DUID = "DHCPSRV_CQL_GET_IAID_SUBID_DUID";
......@@ -119,6 +121,8 @@ extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_CLIENTID = "DHCPSRV_MEMFILE
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_CLIENTID_HWADDR_SUBID = "DHCPSRV_MEMFILE_GET_CLIENTID_HWADDR_SUBID";
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_EXPIRED4 = "DHCPSRV_MEMFILE_GET_EXPIRED4";
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_EXPIRED6 = "DHCPSRV_MEMFILE_GET_EXPIRED6";
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_HOSTNAME4 = "DHCPSRV_MEMFILE_GET_HOSTNAME4";
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_HOSTNAME6 = "DHCPSRV_MEMFILE_GET_HOSTNAME6";
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_HWADDR = "DHCPSRV_MEMFILE_GET_HWADDR";
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_IAID_DUID = "DHCPSRV_MEMFILE_GET_IAID_DUID";
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID = "DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID";
......@@ -169,6 +173,8 @@ extern const isc::log::MessageID DHCPSRV_MYSQL_GET_CLIENTID = "DHCPSRV_MYSQL_GET
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_DUID = "DHCPSRV_MYSQL_GET_DUID";
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_EXPIRED4 = "DHCPSRV_MYSQL_GET_EXPIRED4";
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_EXPIRED6 = "DHCPSRV_MYSQL_GET_EXPIRED6";
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_HOSTNAME4 = "DHCPSRV_MYSQL_GET_HOSTNAME4";
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_HOSTNAME6 = "DHCPSRV_MYSQL_GET_HOSTNAME6";
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_HWADDR = "DHCPSRV_MYSQL_GET_HWADDR";
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_IAID_DUID = "DHCPSRV_MYSQL_GET_IAID_DUID";
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_IAID_SUBID_DUID = "DHCPSRV_MYSQL_GET_IAID_SUBID_DUID";
......@@ -207,6 +213,8 @@ extern const isc::log::MessageID DHCPSRV_PGSQL_GET_CLIENTID = "DHCPSRV_PGSQL_GET
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_DUID = "DHCPSRV_PGSQL_GET_DUID";
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_EXPIRED4 = "DHCPSRV_PGSQL_GET_EXPIRED4";
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_EXPIRED6 = "DHCPSRV_PGSQL_GET_EXPIRED6";
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_HOSTNAME4 = "DHCPSRV_PGSQL_GET_HOSTNAME4";
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_HOSTNAME6 = "DHCPSRV_PGSQL_GET_HOSTNAME6";
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_HWADDR = "DHCPSRV_PGSQL_GET_HWADDR";
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_IAID_DUID = "DHCPSRV_PGSQL_GET_IAID_DUID";
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_IAID_SUBID_DUID = "DHCPSRV_PGSQL_GET_IAID_SUBID_DUID";
......@@ -299,6 +307,8 @@ const char* values[] = {
"DHCPSRV_CQL_GET_CLIENTID_HWADDR_SUBID", "obtaining IPv4 lease for client ID %1, hardware address %2 and subnet ID %3",
"DHCPSRV_CQL_GET_EXPIRED4", "obtaining maximum %1 of expired IPv4 leases",
"DHCPSRV_CQL_GET_EXPIRED6", "obtaining maximum %1 of expired IPv6 leases",
"DHCPSRV_CQL_GET_HOSTNAME4", "obtaining IPv4 leases for hostname %1",
"DHCPSRV_CQL_GET_HOSTNAME6", "obtaining IPv6 leases for hostname %1",
"DHCPSRV_CQL_GET_HWADDR", "obtaining IPv4 leases for hardware address %1",
"DHCPSRV_CQL_GET_IAID_DUID", "obtaining IPv6 leases for IAID %1 and DUID %2 and lease type %3",
"DHCPSRV_CQL_GET_IAID_SUBID_DUID", "obtaining IPv6 leases for IAID %1, Subnet ID %2, DUID %3 and lease type %4",
......@@ -355,6 +365,8 @@ const char* values[] = {
"DHCPSRV_MEMFILE_GET_CLIENTID_HWADDR_SUBID", "obtaining IPv4 lease for client ID %1, hardware address %2 and subnet ID %3",
"DHCPSRV_MEMFILE_GET_EXPIRED4", "obtaining maximum %1 of expired IPv4 leases",
"DHCPSRV_MEMFILE_GET_EXPIRED6", "obtaining maximum %1 of expired IPv6 leases",
"DHCPSRV_MEMFILE_GET_HOSTNAME4", "obtaining IPv4 leases for hostname %1",
"DHCPSRV_MEMFILE_GET_HOSTNAME6", "obtaining IPv6 leases for hostname %1",
"DHCPSRV_MEMFILE_GET_HWADDR", "obtaining IPv4 leases for hardware address %1",
"DHCPSRV_MEMFILE_GET_IAID_DUID", "obtaining IPv6 leases for IAID %1 and DUID %2 and lease type %3",
"DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID", "obtaining IPv6 leases for IAID %1, Subnet ID %2, DUID %3 and lease type %4",
......@@ -405,6 +417,8 @@ const char* values[] = {
"DHCPSRV_MYSQL_GET_DUID", "obtaining IPv6 lease for duid %1,",
"DHCPSRV_MYSQL_GET_EXPIRED4", "obtaining maximum %1 of expired IPv4 leases",
"DHCPSRV_MYSQL_GET_EXPIRED6", "obtaining maximum %1 of expired IPv6 leases",
"DHCPSRV_MYSQL_GET_HOSTNAME4", "obtaining IPv4 leases for hostname %1",
"DHCPSRV_MYSQL_GET_HOSTNAME6", "obtaining IPv6 leases for hostname %1",
"DHCPSRV_MYSQL_GET_HWADDR", "obtaining IPv4 leases for hardware address %1",
"DHCPSRV_MYSQL_GET_IAID_DUID", "obtaining IPv6 leases for IAID %1, DUID %2, lease type %3",
"DHCPSRV_MYSQL_GET_IAID_SUBID_DUID", "obtaining IPv6 leases for IAID %1, Subnet ID %2, DUID %3, lease type %4",
......@@ -443,6 +457,8 @@ const char* values[] = {
"DHCPSRV_PGSQL_GET_DUID", "obtaining IPv6 leases for DUID %1,",
"DHCPSRV_PGSQL_GET_EXPIRED4", "obtaining maximum %1 of expired IPv4 leases",
"DHCPSRV_PGSQL_GET_EXPIRED6", "obtaining maximum %1 of expired IPv6 leases",
"DHCPSRV_PGSQL_GET_HOSTNAME4", "obtaining IPv4 leases for hostname %1",
"DHCPSRV_PGSQL_GET_HOSTNAME6", "obtaining IPv6 leases for hostname %1",
"DHCPSRV_PGSQL_GET_HWADDR", "obtaining IPv4 leases for hardware address %1",
"DHCPSRV_PGSQL_GET_IAID_DUID", "obtaining IPv4 leases for IAID %1 and DUID %2, lease type %3",
"DHCPSRV_PGSQL_GET_IAID_SUBID_DUID", "obtaining IPv4 leases for IAID %1, Subnet ID %2, DUID %3, and lease type %4",
......
// File created from ../../../src/lib/dhcpsrv/dhcpsrv_messages.mes on Mon Sep 30 2019 13:41
// File created from ../../../src/lib/dhcpsrv/dhcpsrv_messages.mes on Wed Oct 16 2019 17:52
#ifndef DHCPSRV_MESSAGES_H
#define DHCPSRV_MESSAGES_H
......@@ -64,6 +64,8 @@ extern const isc::log::MessageID DHCPSRV_CQL_GET_CLIENTID;
extern const isc::log::MessageID DHCPSRV_CQL_GET_CLIENTID_HWADDR_SUBID;
extern const isc::log::MessageID DHCPSRV_CQL_GET_EXPIRED4;
extern const isc::log::MessageID DHCPSRV_CQL_GET_EXPIRED6;
extern const isc::log::MessageID DHCPSRV_CQL_GET_HOSTNAME4;
extern const isc::log::MessageID DHCPSRV_CQL_GET_HOSTNAME6;
extern const isc::log::MessageID DHCPSRV_CQL_GET_HWADDR;
extern const isc::log::MessageID DHCPSRV_CQL_GET_IAID_DUID;
extern const isc::log::MessageID DHCPSRV_CQL_GET_IAID_SUBID_DUID;
......@@ -120,6 +122,8 @@ extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_CLIENTID;
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_CLIENTID_HWADDR_SUBID;
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_EXPIRED4;
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_EXPIRED6;
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_HOSTNAME4;
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_HOSTNAME6;
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_HWADDR;
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_IAID_DUID;
extern const isc::log::MessageID DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID;
......@@ -170,6 +174,8 @@ extern const isc::log::MessageID DHCPSRV_MYSQL_GET_CLIENTID;
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_DUID;
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_EXPIRED4;
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_EXPIRED6;
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_HOSTNAME4;
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_HOSTNAME6;
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_HWADDR;
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_IAID_DUID;
extern const isc::log::MessageID DHCPSRV_MYSQL_GET_IAID_SUBID_DUID;
......@@ -208,6 +214,8 @@ extern const isc::log::MessageID DHCPSRV_PGSQL_GET_CLIENTID;
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_DUID;
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_EXPIRED4;
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_EXPIRED6;
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_HOSTNAME4;
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_HOSTNAME6;
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_HWADDR;
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_IAID_DUID;
extern const isc::log::MessageID DHCPSRV_PGSQL_GET_IAID_SUBID_DUID;
......
......@@ -303,6 +303,16 @@ A debug message issued when the server is attempting to obtain expired
IPv6 leases to reclaim them. The maximum number of leases to be retrieved
is logged in the message.
% DHCPSRV_CQL_GET_HOSTNAME4 obtaining IPv4 leases for hostname %1
A debug message issued when the server is attempting to obtain a set of
IPv4 leases from the Cassandra database for a client with the specified
hostname.
% DHCPSRV_CQL_GET_HOSTNAME6 obtaining IPv6 leases for hostname %1
A debug message issued when the server is attempting to obtain a set of
IPv6 leases from the Cassandra database for a client with the specified
hostname.
% DHCPSRV_CQL_GET_HWADDR obtaining IPv4 leases for hardware address %1
A debug message issued when the server is attempting to obtain a set of
IPv4 leases from the Cassandra database for a client with the specified
......@@ -579,6 +589,16 @@ A debug message issued when the server is attempting to obtain expired
IPv6 leases to reclaim them. The maximum number of leases to be retrieved
is logged in the message.
% DHCPSRV_MEMFILE_GET_HOSTNAME4 obtaining IPv4 leases for hostname %1
A debug message issued when the server is attempting to obtain a set of
IPv4 leases from the memory file database for a client with the specified
hostname.
% DHCPSRV_MEMFILE_GET_HOSTNAME6 obtaining IPv6 leases for hostname %1
A debug message issued when the server is attempting to obtain a set of
IPv6 leases from the memory file database for a client with the specified
hostname.
% DHCPSRV_MEMFILE_GET_HWADDR obtaining IPv4 leases for hardware address %1
A debug message issued when the server is attempting to obtain a set of
IPv4 leases from the memory file database for a client with the specified
......@@ -830,6 +850,16 @@ A debug message issued when the server is attempting to obtain expired
IPv6 leases to reclaim them. The maximum number of leases to be retrieved
is logged in the message.
% DHCPSRV_MYSQL_GET_HOSTNAME4 obtaining IPv4 leases for hostname %1
A debug message issued when the server is attempting to obtain a set
of IPv4 leases from the MySQL database for a client with the specified
hostname.
% DHCPSRV_MYSQL_GET_HOSTNAME6 obtaining IPv6 leases for hostname %1
A debug message issued when the server is attempting to obtain a set
of IPv6 leases from the MySQL database for a client with the specified
hostname.
% DHCPSRV_MYSQL_GET_HWADDR obtaining IPv4 leases for hardware address %1
A debug message issued when the server is attempting to obtain a set
of IPv4 leases from the MySQL database for a client with the specified
......@@ -1014,6 +1044,16 @@ A debug message issued when the server is attempting to obtain expired
IPv6 leases to reclaim them. The maximum number of leases to be retrieved
is logged in the message.
% DHCPSRV_PGSQL_GET_HOSTNAME4 obtaining IPv4 leases for hostname %1
A debug message issued when the server is attempting to obtain a set
of IPv4 leases from the PostgreSQL database for a client with the specified
hostname.
% DHCPSRV_PGSQL_GET_HOSTNAME6 obtaining IPv6 leases for hostname %1
A debug message issued when the server is attempting to obtain a set
of IPv6 leases from the PostgreSQL database for a client with the specified
hostname.
% DHCPSRV_PGSQL_GET_HWADDR obtaining IPv4 leases for hardware address %1
A debug message issued when the server is attempting to obtain a set
of IPv4 leases from the PostgreSQL database for a client with the specified
......
// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2019 Internet Systems Consortium, Inc. ("ISC")
//
// 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
......@@ -344,6 +344,13 @@ public:
/// @return Lease collection (may be empty if no IPv4 lease found).
virtual Lease4Collection getLeases4(SubnetID subnet_id) const = 0;
/// @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).
virtual Lease4Collection getLeases4(const std::string& hostname) const = 0;
/// @brief Returns all IPv4 leases.
///
/// @return Lease collection (may be empty if no IPv4 lease found).
......@@ -452,6 +459,13 @@ public:
/// @return Lease collection (may be empty if no IPv6 lease found).
virtual Lease6Collection getLeases6(SubnetID subnet_id) const = 0;
/// @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).
virtual Lease6Collection getLeases6(const std::string& hostname) const = 0;
/// @brief Returns all IPv6 leases.
///
/// @return Lease collection (may be empty if no IPv6 lease found).
......@@ -459,9 +473,9 @@ public:
/// @brief Returns collection of leases for matching DUID
///
/// @return Lease collection
/// @return Lease collection
/// (may be empty if no IPv6 lease found for the DUID).
virtual Lease6Collection getLeases6(const DUID& duid) const = 0;
virtual Lease6Collection getLeases6(const DUID& duid) const = 0;
/// @brief Returns range of IPv6 leases using paging.
///
......
......@@ -871,6 +871,24 @@ Memfile_LeaseMgr::getLeases4(SubnetID subnet_id) const {
return (collection);
}
Lease4Collection
Memfile_LeaseMgr::getLeases4(const std::string& hostname) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_HOSTNAME4)
.arg(hostname);
Lease4Collection collection;
const Lease4StorageHostnameIndex& idx = storage4_.get<HostnameIndexTag>();
std::pair<Lease4StorageHostnameIndex::const_iterator,
Lease4StorageHostnameIndex::const_iterator> l =
idx.equal_range(hostname);
for (auto lease = l.first; lease != l.second; ++lease) {
collection.push_back(Lease4Ptr(new Lease4(**lease)));
}
return (collection);
}
Lease4Collection
Memfile_LeaseMgr::getLeases4() const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET4);
......@@ -1002,6 +1020,24 @@ Memfile_LeaseMgr::getLeases6(SubnetID subnet_id) const {
return (collection);
}
Lease6Collection
Memfile_LeaseMgr::getLeases6(const std::string& hostname) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_HOSTNAME6)
.arg(hostname);
Lease6Collection collection;
const Lease6StorageHostnameIndex& idx = storage6_.get<HostnameIndexTag>();
std::pair<Lease6StorageHostnameIndex::const_iterator,
Lease6StorageHostnameIndex::const_iterator> l =
idx.equal_range(hostname);
for (auto lease = l.first; lease != l.second; ++lease) {
collection.push_back(Lease6Ptr(new Lease6(**lease)));
}
return (collection);
}
Lease6Collection
Memfile_LeaseMgr::getLeases6() const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET6);
......
......@@ -229,6 +229,13 @@ public:
/// @return Lease collection (may be empty if no IPv4 lease found).
virtual Lease4Collection getLeases4(SubnetID subnet_id) const;
/// @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).
virtual Lease4Collection getLeases4(const std::string& hostname) const;
/// @brief Returns all IPv4 leases.
///
/// @return Lease collection (may be empty if no IPv4 lease found).
......@@ -308,6 +315,13 @@ public:
/// @return Lease collection (may be empty if no IPv6 lease found).
virtual Lease6Collection getLeases6(SubnetID subnet_id) const;
/// @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).
virtual Lease6Collection getLeases6(const std::string& hostname) const;
/// @brief Returns all IPv6 leases.
///
/// @return Lease collection (may be empty if no IPv6 lease found).
......@@ -316,10 +330,10 @@ public:
/// @brief Returns IPv6 leases for the DUID.
///
/// @todo: implement an optimised of the query using index.
/// @return Lease collection (may be empty if no IPv6 lease found)
/// @return Lease collection (may be empty if no IPv6 lease found)
/// for the DUID.
virtual Lease6Collection getLeases6(const DUID& duid) const;
/// @brief Returns range of IPv6 leases using paging.
///
/// This method implements paged browsing of the lease database. The first
......
// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2015-2019 Internet Systems Consortium, Inc. ("ISC")
//
// 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
......@@ -46,7 +46,11 @@ struct ClientIdHWAddressSubnetIdIndexTag { };
struct SubnetIdIndexTag { };
/// @brief Tag for index using DUID.
struct DuidIndexTag { };
struct DuidIndexTag { };
/// @brief Tag for index using hostname.
struct HostnameIndexTag { };
/// @name Multi index containers holding DHCPv4 and DHCPv6 leases.
///
//@{
......@@ -125,6 +129,13 @@ typedef boost::multi_index_container<
boost::multi_index::const_mem_fun<Lease6,
const std::vector<uint8_t>&,
&Lease6::getDuidVector>
>,
// Specification of the sixth index starts here
// This index is used to retrieve leases for matching hostname.
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<HostnameIndexTag>,
boost::multi_index::member<Lease, std::string, &Lease::hostname_>
>
>
> Lease6Storage; // Specify the type name of this container.
......@@ -239,8 +250,15 @@ typedef boost::multi_index_container<
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<SubnetIdIndexTag>,
boost::multi_index::member<Lease, isc::dhcp::SubnetID, &Lease::subnet_id_>
>
>,
// Specification of the seventh index starts here
// This index is used to retrieve leases for matching hostname.
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<HostnameIndexTag>,
boost::multi_index::member<Lease, std::string, &Lease::hostname_>
>
>
> Lease4Storage; // Specify the type name for this container.
......@@ -265,6 +283,9 @@ typedef Lease6Storage::index<SubnetIdIndexTag>::type Lease6StorageSubnetIdIndex;
/// @brief DHCPv6 lease storage index by Subnet-id.
typedef Lease6Storage::index<DuidIndexTag>::type Lease6StorageDuidIndex;
/// @brief DHCPv6 lease storage index by hostname.
typedef Lease6Storage::index<HostnameIndexTag>::type Lease6StorageHostnameIndex;
/// @brief DHCPv4 lease storage index by address.
typedef Lease4Storage::index<AddressIndexTag>::type Lease4StorageAddressIndex;
......@@ -286,6 +307,9 @@ Lease4StorageClientIdHWAddressSubnetIdIndex;
/// @brief DHCPv4 lease storage index by client id, HW address and subnet id.
typedef Lease4Storage::index<SubnetIdIndexTag>::type Lease4StorageSubnetIdIndex;
/// @brief DHCPv4 lease storage index by hostname.
typedef Lease4Storage::index<HostnameIndexTag>::type Lease4StorageHostnameIndex;
//@}
} // end of isc::dhcp namespace
} // end of isc namespace
......
......@@ -159,6 +159,13 @@ tagged_statements = { {
"state, user_context "
"FROM lease4 "
"WHERE subnet_id = ?"},
{MySqlLeaseMgr::GET_LEASE4_HOSTNAME,
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
"state, user_context "
"FROM lease4 "
"WHERE hostname = ?"},
{MySqlLeaseMgr::GET_LEASE4_EXPIRE,
"SELECT address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, "
......@@ -233,6 +240,15 @@ tagged_statements = { {
"state, user_context "
"FROM lease6 "
"WHERE duid = ?"},
{MySqlLeaseMgr::GET_LEASE6_HOSTNAME,
"SELECT address, duid, valid_lifetime, "
"expire, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, "
"state, user_context "
"FROM lease6 "
"WHERE hostname = ?"},
{MySqlLeaseMgr::GET_LEASE6_EXPIRE,
"SELECT address, duid, valid_lifetime, "
"expire, subnet_id, pref_lifetime, "
......@@ -2096,6 +2112,27 @@ MySqlLeaseMgr::getLeases4(SubnetID subnet_id) const {
return (result);
}
Lease4Collection
MySqlLeaseMgr::getLeases4(const string& hostname) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET_HOSTNAME4)
.arg(hostname);
// Set up the WHERE clause value
MYSQL_BIND inbind[1];
memset(inbind, 0, sizeof(inbind));
// Hostname
inbind[0].buffer_type = MYSQL_TYPE_STRING;
inbind[0].buffer = const_cast<char*>(hostname.c_str());
inbind[0].buffer_length = hostname.length();
// ... and get the data
Lease4Collection result;
getLeaseCollection(GET_LEASE4_HOSTNAME, inbind, result);
return (result);
}
Lease4Collection
MySqlLeaseMgr::getLeases4() const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET4);
......@@ -2312,7 +2349,7 @@ Lease6Collection
MySqlLeaseMgr::getLeases6(const DUID& duid) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET_DUID)
.arg(duid.toText());
// Set up the WHERE clause value
MYSQL_BIND inbind[1];
memset(inbind, 0, sizeof(inbind));
......@@ -2325,14 +2362,35 @@ MySqlLeaseMgr::getLeases6(const DUID& duid) const {
const_cast<uint8_t*>(&duid_vector[0]));
inbind[0].buffer_length = duid_length;
inbind[0].length = &duid_length;
Lease6Collection result;
getLeaseCollection(GET_LEASE6_DUID, inbind, result);
return result;
}
Lease6Collection
MySqlLeaseMgr::getLeases6(const string& hostname) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET_HOSTNAME6)
.arg(hostname);
// Set up the WHERE clause value
MYSQL_BIND inbind[1];
memset(inbind, 0, sizeof(inbind));
// Hostname
inbind[0].buffer_type = MYSQL_TYPE_STRING;
inbind[0].buffer = const_cast<char*>(hostname.c_str());
inbind[0].buffer_length = hostname.length();
// ... and get the data
Lease6Collection result;
getLeaseCollection(GET_LEASE6_HOSTNAME, inbind, result);
return (result);
}
Lease6Collection
MySqlLeaseMgr::getLeases6(const asiolink::IOAddress& lower_bound_address,
const LeasePageSize& page_size) const {
......
// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2019 Internet Systems Consortium, Inc. ("ISC")
//
// 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
......@@ -202,6 +202,13 @@ public:
/// @return Lease collection (may be empty if no IPv4 lease found).
virtual Lease4Collection getLeases4(SubnetID subnet_id) const;
/// @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).
virtual Lease4Collection getLeases4(const std::string& hostname) const;
/// @brief Returns all IPv4 leases.
///
/// @return Lease collection (may be empty if no IPv4 lease found).
......@@ -305,6 +312,13 @@ public:
/// @return Lease collection (may be empty if no IPv6 lease found).
virtual Lease6Collection getLeases6(SubnetID subnet_id) const;
/// @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).
virtual Lease6Collection getLeases6(const std::string& hostname) const;
/// @brief Returns all IPv6 leases.
///
/// @return Lease collection (may be empty if no IPv6 lease found).
......@@ -316,7 +330,7 @@ public:
/// @return Lease collection (may be empty if no IPv6 lease found)
/// for the DUID.
virtual Lease6Collection getLeases6(const DUID& duid) const;
/// @brief Returns range of IPv6 leases using paging.
///
/// This method implements paged browsing of the lease database. The first
......@@ -581,6 +595,7 @@ public:
GET_LEASE4_HWADDR_SUBID, // Get lease4 by HW address & subnet ID
GET_LEASE4_PAGE, // Get page of leases beginning with an address
GET_LEASE4_SUBID, // Get IPv4 leases by subnet ID
GET_LEASE4_HOSTNAME, // Get IPv4 leases by hostname
GET_LEASE4_EXPIRE, // Get lease4 by expiration.
GET_LEASE6, // Get all IPv6 leases
GET_LEASE6_ADDR, // Get lease6 by address
......@@ -589,6 +604,7 @@ public:
GET_LEASE6_PAGE, // Get page of leases beginning with an address
GET_LEASE6_SUBID, // Get IPv6 leases by subnet ID
GET_LEASE6_DUID, // Get IPv6 leases by DUID
GET_LEASE6_HOSTNAME, // Get IPv6 leases by hostname
GET_LEASE6_EXPIRE, // Get lease6 by expiration.
INSERT_LEASE4, // Add entry to lease4 table
INSERT_LEASE6, // Add entry to lease6 table
......
......@@ -137,6 +137,16 @@ PgSqlTaggedStatement tagged_statements[] = {
"FROM lease4 "
"WHERE subnet_id = $1"},
// GET_LEASE4_HOSTNAME
{ 1, { OID_VARCHAR },
"get_lease4_hostname",
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
"state, user_context "
"FROM lease4 "
"WHERE hostname = $1"},
// GET_LEASE4_EXPIRE
{ 3, { OID_INT8, OID_TIMESTAMP, OID_INT8 },
"get_lease4_expire",
......@@ -228,6 +238,17 @@ PgSqlTaggedStatement tagged_statements[] = {
"FROM lease6 "
"WHERE duid = $1"},