]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[393-global-search-through-leases-by-mac-or-hostname-w-o-specifying-a-subnet-id]...
authorFrancis Dupont <fdupont@isc.org>
Wed, 16 Oct 2019 17:02:43 +0000 (19:02 +0200)
committerFrancis Dupont <fdupont@isc.org>
Fri, 25 Oct 2019 15:26:23 +0000 (17:26 +0200)
20 files changed:
src/lib/dhcpsrv/cql_lease_mgr.cc
src/lib/dhcpsrv/cql_lease_mgr.h
src/lib/dhcpsrv/dhcpsrv_messages.cc
src/lib/dhcpsrv/dhcpsrv_messages.h
src/lib/dhcpsrv/dhcpsrv_messages.mes
src/lib/dhcpsrv/lease_mgr.h
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/memfile_lease_mgr.h
src/lib/dhcpsrv/memfile_lease_storage.h
src/lib/dhcpsrv/mysql_lease_mgr.cc
src/lib/dhcpsrv/mysql_lease_mgr.h
src/lib/dhcpsrv/pgsql_lease_mgr.cc
src/lib/dhcpsrv/pgsql_lease_mgr.h
src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h
src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc

index 3bea54355bcf1742e3fc851f7965344fd6e16e3b..55913f554d95e86dcd2e79b865f07a70ff21d4a1 100644 (file)
@@ -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");
index ae042b3c46d2588658c3a7ab7829a0a0e74c3ed1..4760a3134a7b8a8dfa8e8ad282e36b93903394fd 100644 (file)
@@ -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
index 08c0d9dfacdc91bc51d8f38d54a3172ef88e739d..b866cfe2e49da1d565b1fa272d9d768cde35713d 100644 (file)
@@ -1,4 +1,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
 
 #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",
index 79e8c072befc0d8c31b209c5faa2448cdab46190..8fda345e74f724522c242f472f816fae97922f48 100644 (file)
@@ -1,4 +1,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;
index e8a544e1bc0c0a385f6076a6a574c2cb38a80e19..0c2d19d29b4267e2ffa639925e7423c2a7418504 100644 (file)
@@ -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
index 233f3539c88be593cb6eaaf8c6ab7ceafa21db67..eab1f644949bc8d0e7bea5bcd21e07caeba34f00 100644 (file)
@@ -1,4 +1,4 @@
-// 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.
     ///
index 93f84a5d64d7ca6cbb2886244c5a472cedfbfc0e..719ddb091e3ef470f7e522702a99d19bd9f679e9 100644 (file)
@@ -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);
index 49dbf3e0bf8acb7837b24789f560ac198b6a3fb1..b0832010aefaea234fe9c3db12612071146e8ebe 100644 (file)
@@ -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
index 3254eefe3a6ed3a6bb7133cca260883c4816b753..fd412e7b74735c681f890607227d40953712f884 100644 (file)
@@ -1,4 +1,4 @@
-// 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
index 8d741fa085aeda94d9cfc8df0265367543da9eb1..599045c86096ac6abf6f5e16a587ec0da7def1f8 100644 (file)
@@ -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 {
index a11009c8749c89748e76d82732614e898a20b5f4..1524d06676fd4007fbaba64c3b01172a854fd53b 100644 (file)
@@ -1,4 +1,4 @@
-// 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
index 26ff0c1c7be62ef5f618e04c902ab5e25512c7c7..3a015d574cfdfbfd9b3345896b43faf0d5515a41 100644 (file)
@@ -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"},
 
+    // GET_LEASE6_HOSTNAME
+    { 1, { OID_VARCHAR },
+      "get_lease6_hostname",
+      "SELECT address, duid, valid_lifetime, "
+        "extract(epoch from expire)::bigint, 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 = $1"},
+
     // GET_LEASE6_EXPIRE
     { 3, { OID_INT8, OID_TIMESTAMP, OID_INT8 },
       "get_lease6_expire",
@@ -1382,6 +1403,24 @@ PgSqlLeaseMgr::getLeases4(SubnetID subnet_id) const {
     return (result);
 }
 
+Lease4Collection
+PgSqlLeaseMgr::getLeases4(const string& hostname) const {
+    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET_HOSTNAME4)
+        .arg(hostname);
+
+    // Set up the WHERE clause value
+    PsqlBindArray bind_array;
+
+    // Hostname
+    bind_array.add(hostname);
+
+    // ... and get the data
+    Lease4Collection result;
+    getLeaseCollection(GET_LEASE4_HOSTNAME, bind_array, result);
+
+    return (result);
+}
+
 Lease4Collection
 PgSqlLeaseMgr::getLeases4() const {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET4);
@@ -1550,6 +1589,24 @@ PgSqlLeaseMgr::getLeases6(const DUID& duid) const {
     return (result);
 }
 
+Lease6Collection
+PgSqlLeaseMgr::getLeases6(const string& hostname) const {
+    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET_HOSTNAME6)
+        .arg(hostname);
+
+    // Set up the WHERE clause value
+    PsqlBindArray bind_array;
+
+    // Hostname
+    bind_array.add(hostname);
+
+    // ... and get the data
+    Lease6Collection result;
+    getLeaseCollection(GET_LEASE6_HOSTNAME, bind_array, result);
+
+    return (result);
+}
+
 Lease6Collection
 PgSqlLeaseMgr::getLeases6() const {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET6);
index c779fafaa6eb80dd5349efdeca4db75f2e1afce0..cd1ccbf74d041911f85906732047b5b9e335ccc2 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-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
@@ -183,6 +183,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).
@@ -277,6 +284,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).
@@ -288,7 +302,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
@@ -549,6 +563,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 expired lease4
         GET_LEASE6,                 // Get all IPv6 leases
         GET_LEASE6_ADDR,            // Get lease6 by address
@@ -557,6 +572,7 @@ public:
         GET_LEASE6_PAGE,            // Get page of IPv6 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 expired lease6
         INSERT_LEASE4,              // Add entry to lease4 table
         INSERT_LEASE6,              // Add entry to lease6 table
index 8c31f811d0ec8649b824fe4f90210d3d0acf9225..d07f33562969b83880089192305a518a097650f5 100644 (file)
@@ -582,6 +582,11 @@ TEST_F(CqlLeaseMgrTest, getLeases4SubnetId) {
     testGetLeases4SubnetId();
 }
 
+// This test checks that all IPv4 leases with a specified hostname are returned.
+TEST_F(CqlLeaseMgrTest, getLeases4Hostname) {
+    testGetLeases4Hostname();
+}
+
 // This test checks that all IPv4 leases are returned.
 TEST_F(CqlLeaseMgrTest, getLeases4) {
     testGetLeases4();
@@ -708,6 +713,11 @@ TEST_F(CqlLeaseMgrTest, getLease6DuidIaidSubnetIdSize) {
     testGetLease6DuidIaidSubnetIdSize();
 }
 
+// This test checks that all IPv6 leases with a specified hostname are returned.
+TEST_F(CqlLeaseMgrTest, getLeases6Hostname) {
+    testGetLeases6Hostname();
+}
+
 // Test that a range of IPv6 leases is returned with paging.
 TEST_F(CqlLeaseMgrTest, getLeases6Paged) {
     testGetLeases6Paged();
index eceec558d673477819ccf2d3a46500e800e39875..c140d8c90ffdeca480b2dc36a46508bc9bd97ac5 100644 (file)
@@ -1246,6 +1246,29 @@ GenericLeaseMgrTest::testGetLeases4SubnetId() {
     ASSERT_EQ(2, returned.size());
 }
 
+void
+GenericLeaseMgrTest::testGetLeases4Hostname() {
+    // Get the leases to be used for the test and add to the database.
+    vector<Lease4Ptr> leases = createLeases4();
+    for (size_t i = 0; i < leases.size(); ++i) {
+        EXPECT_TRUE(lmptr_->addLease(leases[i]));
+    }
+
+    // There should be no lease for hostname foobar.
+    Lease4Collection returned = lmptr_->getLeases4(string("foobar"));
+    EXPECT_TRUE(returned.empty());
+
+    // There should be exactly 4 leases for the hostname of the second lease.
+    ASSERT_FALSE(leases[1]->hostname_.empty());
+    returned = lmptr_->getLeases4(leases[1]->hostname_);
+    EXPECT_EQ(4, returned.size());
+
+    // And 3 for the forth lease.
+    ASSERT_FALSE(leases[3]->hostname_.empty());
+    returned = lmptr_->getLeases4(leases[3]->hostname_);
+    EXPECT_EQ(3, returned.size());
+}
+
 void
 GenericLeaseMgrTest::testGetLeases4() {
     // Get the leases to be used for the test and add to the database
@@ -1335,6 +1358,34 @@ GenericLeaseMgrTest::testGetLeases6SubnetId() {
     EXPECT_EQ(2, returned.size());
 }
 
+void
+GenericLeaseMgrTest::testGetLeases6Hostname() {
+    // Get the leases to be used for the test and add to the database.
+    vector<Lease6Ptr> leases = createLeases6();
+    for (size_t i = 0; i < leases.size(); ++i) {
+        EXPECT_TRUE(lmptr_->addLease(leases[i]));
+    }
+
+    // There should be no lease for hostname foobar.
+    Lease6Collection returned = lmptr_->getLeases6(string("foobar"));
+    EXPECT_TRUE(returned.empty());
+
+    // There should be exactly 4 leases for the hostname of the second lease.
+    ASSERT_FALSE(leases[1]->hostname_.empty());
+    returned = lmptr_->getLeases6(leases[1]->hostname_);
+    EXPECT_EQ(4, returned.size());
+
+    // One for the fifth lease.
+    ASSERT_FALSE(leases[4]->hostname_.empty());
+    returned = lmptr_->getLeases6(leases[4]->hostname_);
+    EXPECT_EQ(1, returned.size());
+
+    // And 3 for the sixth lease.
+    ASSERT_FALSE(leases[5]->hostname_.empty());
+    returned = lmptr_->getLeases6(leases[5]->hostname_);
+    EXPECT_EQ(3, returned.size());
+}
+
 void
 GenericLeaseMgrTest::testGetLeases6() {
     // Get the leases to be used for the test and add to the database
index a86632b440926d739ffda2b977fd4811c6183220..ebb3078f46321cf7793b7ba8b6c2b31576645105 100644 (file)
@@ -201,6 +201,9 @@ public:
     /// @brief Test method which returns all IPv4 leases for Subnet ID.
     void testGetLeases4SubnetId();
 
+    /// @brief Test method which returns all IPv4 leases for Hostname.
+    void testGetLeases4Hostname();
+
     /// @brief Test method which returns all IPv4 leases.
     void testGetLeases4();
 
@@ -210,6 +213,9 @@ public:
     /// @brief Test method which returns all IPv6 leases for Subnet ID.
     void testGetLeases6SubnetId();
 
+    /// @brief Test method which returns all IPv6 leases for Hostname.
+    void testGetLeases6Hostname();
+
     /// @brief Test making/fetching leases with IAIDs > signed 32-bit max.
     void testLease6LargeIaidCheck();
 
index da389a56aab3db5b0bfbbb4de7e15ed0fccb6929..3bb71843684e76c5c78de1a4551d9f3a2be8f37f 100644 (file)
@@ -1,4 +1,4 @@
-// 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
@@ -139,6 +139,15 @@ public:
         return (Lease4Collection());
     }
 
+    /// @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 {
+        return (Lease4Collection());
+    }
+
     /// @brief Returns all IPv4 leases.
     ///
     /// @return Lease collection (may be empty if no IPv4 lease found).
@@ -226,6 +235,15 @@ public:
         return (Lease6Collection());
     }
 
+    /// @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 {
+        return (Lease6Collection());
+    }
+
     /// @brief Returns all IPv6 leases.
     ///
     /// @return Lease collection (may be empty if no IPv6 lease found).
index 96a9314ef9851ce29be8fc12f756d09b0596b335..d9548aeb81da7e9ddf2c540b5c8be10e687d394b 100644 (file)
@@ -926,6 +926,12 @@ TEST_F(MemfileLeaseMgrTest, getLeases4SubnetId) {
     testGetLeases4SubnetId();
 }
 
+// This test checks that all IPv4 leases with a specified hostname are returned.
+TEST_F(MemfileLeaseMgrTest, getLeases4Hostname) {
+    startBackend(V4);
+    testGetLeases4Hostname();
+}
+
 // This test checks that all IPv4 leases are returned.
 TEST_F(MemfileLeaseMgrTest, getLeases4) {
     startBackend(V4);
@@ -944,6 +950,12 @@ TEST_F(MemfileLeaseMgrTest, getLeases6SubnetId) {
     testGetLeases6SubnetId();
 }
 
+// This test checks that all IPv6 leases with a specified hostname are returned.
+TEST_F(MemfileLeaseMgrTest, getLeases6Hostname) {
+    startBackend(V6);
+    testGetLeases6Hostname();
+}
+
 // This test adds 3 leases  and verifies fetch by DUID.
 // Verifies retrival of non existant DUID fails
 TEST_F(MemfileLeaseMgrTest, getLeases6Duid) {
index 72a8ba8ef75c4934127775bcdb2ed612dc4b6e8b..e84d0f5aae4a025f5e70bc2c136d681a5de1dd05 100644 (file)
@@ -351,6 +351,11 @@ TEST_F(MySqlLeaseMgrTest, getLeases4SubnetId) {
     testGetLeases4SubnetId();
 }
 
+// This test checks that all IPv4 leases with a specified hostname are returned.
+TEST_F(MySqlLeaseMgrTest, getLeases4Hostname) {
+    testGetLeases4Hostname();
+}
+
 // This test checks that all IPv4 leases are returned.
 TEST_F(MySqlLeaseMgrTest, getLeases4) {
     testGetLeases4();
@@ -366,6 +371,11 @@ TEST_F(MySqlLeaseMgrTest, getLeases6SubnetId) {
     testGetLeases6SubnetId();
 }
 
+// This test checks that all IPv6 leases with a specified hostname are returned.
+TEST_F(MySqlLeaseMgrTest, getLeases6Hostname) {
+    testGetLeases6Hostname();
+}
+
 // This test checks that all IPv6 leases are returned.
 TEST_F(MySqlLeaseMgrTest, getLeases6) {
     testGetLeases6();
index ec783594b879fa57b4cbbc16fb701d871cb59ec7..1856186cd7f62b29f77e10158717c8a7deed8c5b 100644 (file)
@@ -341,6 +341,11 @@ TEST_F(PgSqlLeaseMgrTest, getLeases4SubnetId) {
     testGetLeases4SubnetId();
 }
 
+// This test checks that all IPv4 leases with a specified hostname are returned.
+TEST_F(PgSqlLeaseMgrTest, getLeases4Hostname) {
+    testGetLeases4Hostname();
+}
+
 // This test checks that all IPv4 leases are returned.
 TEST_F(PgSqlLeaseMgrTest, getLeases4) {
     testGetLeases4();
@@ -356,6 +361,11 @@ TEST_F(PgSqlLeaseMgrTest, getLeases6SubnetId) {
     testGetLeases6SubnetId();
 }
 
+// This test checks that all IPv6 leases with a specified hostname are returned.
+TEST_F(PgSqlLeaseMgrTest, getLeases6Hostname) {
+    testGetLeases6Hostname();
+}
+
 // This test checks that all IPv6 leases are returned.
 TEST_F(PgSqlLeaseMgrTest, getLeases6) {
     testGetLeases6();