]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[gitlab9] Imported relevant bits from github99
authorTomek Mrugalski <tomasz@isc.org>
Mon, 13 Aug 2018 15:47:53 +0000 (17:47 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Mon, 13 Aug 2018 18:16:33 +0000 (20:16 +0200)
 - Covers changes up to 4358737d43ee1b6c8618a1a8aa3cc7273634ed48,
   but without unnecessary things.

src/lib/dhcpsrv/cql_lease_mgr.cc
src/lib/dhcpsrv/cql_lease_mgr.h
src/lib/dhcpsrv/lease_mgr.h
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/memfile_lease_mgr.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/lease_mgr_unittest.cc
src/lib/dhcpsrv/testutils/host_data_source_utils.cc

index 7085ff436c8efd7d0e7410ffd0fae6c6c636b8ee..7ae9dc02d8e830ab9e68ab601e008fd8cda01352 100644 (file)
@@ -901,6 +901,7 @@ public:
     static constexpr StatementTag DELETE_LEASE6 = "DELETE_LEASE6";
     static constexpr StatementTag GET_LEASE6_EXPIRE = "GET_LEASE6_EXPIRE";
     static constexpr StatementTag GET_LEASE6_ADDR = "GET_LEASE6_ADDR";
+    static constexpr StatementTag GET_LEASE6_DUID = "GET_LEASE6_DUID";
     static constexpr StatementTag GET_LEASE6_DUID_IAID = "GET_LEASE6_DUID_IAID";
     static constexpr StatementTag GET_LEASE6_DUID_IAID_SUBID = "GET_LEASE6_DUID_IAID_SUBID";
     static constexpr StatementTag GET_LEASE6_LIMIT = "GET_LEASE6_LIMIT";
@@ -941,6 +942,7 @@ constexpr StatementTag CqlLease6Exchange::UPDATE_LEASE6;
 constexpr StatementTag CqlLease6Exchange::DELETE_LEASE6;
 constexpr StatementTag CqlLease6Exchange::GET_LEASE6_EXPIRE;
 constexpr StatementTag CqlLease6Exchange::GET_LEASE6_ADDR;
+constexpr StatementTag CqlLease6Exchange::GET_LEASE6_DUID;
 constexpr StatementTag CqlLease6Exchange::GET_LEASE6_DUID_IAID;
 constexpr StatementTag CqlLease6Exchange::GET_LEASE6_DUID_IAID_SUBID;
 constexpr StatementTag CqlLease6Exchange::GET_LEASE6_LIMIT;
@@ -1015,6 +1017,17 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
       "AND lease_type = ? "
       "ALLOW FILTERING "}},
 
+    // Gets an IPv6 lease with specified duid
+    {GET_LEASE6_DUID,
+     {GET_LEASE6_DUID,
+      "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 "
+      "FROM lease6 "
+      "WHERE duid = ? "
+      "ALLOW FILTERING "}},
+
     // Gets an IPv6 lease(s) with specified duid and iaid
     {GET_LEASE6_DUID_IAID,
      {GET_LEASE6_DUID_IAID,
@@ -2280,6 +2293,25 @@ CqlLeaseMgr::getLease6(Lease::Type lease_type, const IOAddress &addr) const {
     return (result);
 }
 
+Lease6Collection
+CqlLeaseMgr::getLeases6(const DUID& duid) const {
+
+    // Set up the WHERE clause value
+    AnyArray data;
+    
+    CassBlob duid_data(duid.getDuid());
+
+    data.add(&duid_data);
+
+    // Get the data.
+    Lease6Collection result;
+    std::unique_ptr<CqlLease6Exchange> exchange6(new CqlLease6Exchange(dbconn_));
+    exchange6->getLeaseCollection(CqlLease6Exchange::GET_LEASE6_DUID, data, result);
+
+    return (result);
+    
+}
+
 Lease6Collection
 CqlLeaseMgr::getLeases6(Lease::Type lease_type, const DUID &duid, uint32_t iaid) const {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_IAID_DUID)
index 39382b2f4efaaced27a8ada18270916d4413b55b..5b7650786abf102651232712e9aac56c1e30c50d 100644 (file)
@@ -317,6 +317,11 @@ public:
     /// this backend.
     virtual Lease6Collection getLeases6() const override;
 
+    /// @brief Returns all IPv6 leases.
+    ///
+    /// @return Lease collection (may be empty if no IPv6 lease found).
+    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 642bb6b759f02a0ca0addaccd8eade294aafd9f4..474b4badc172e50494f70949d042daf9c59e4f8b 100644 (file)
@@ -458,6 +458,11 @@ public:
     /// @return Lease collection (may be empty if no IPv6 lease found).
     virtual Lease6Collection getLeases6() const = 0;
 
+    /// @brief Returns collection of lease for matching DUID
+    ///
+    /// @return Lease collection (may be empty if no IPv6 lease found for the DUID).
+    virtual Lease6Collection getLeases6(const DUID& duid) const = 0; 
+    
     /// @brief Returns range of IPv6 leases using paging.
     ///
     /// This method implements paged browsing of the lease database. The first
index a4b4a1114c3417029aeb8cdbf263416332073ad7..fde42392dba9cdfb010469298b50ef097d361c1e 100644 (file)
@@ -1015,6 +1015,19 @@ Memfile_LeaseMgr::getLeases6() const {
    return (collection);
 }
 
+Lease6Collection
+Memfile_LeaseMgr::getLeases6(const DUID& duid) const {
+   LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET6);
+
+   Lease6Collection collection;
+   for (auto lease = storage6_.begin(); lease != storage6_.end(); ++lease ) {
+       if ( (**lease).duid_->getDuid() == duid.getDuid() )
+            collection.push_back(Lease6Ptr(new Lease6(**lease)));
+   }
+
+   return (collection);
+}
+
 Lease6Collection
 Memfile_LeaseMgr::getLeases6(const asiolink::IOAddress& lower_bound_address,
                              const LeasePageSize& page_size) const {
index 66dedccb0d659cc14960191e16d47c571b68e519..f14cc5c96454e621bde7b0c50454eacbd839e553 100644 (file)
@@ -311,6 +311,12 @@ public:
     ///
     /// @return Lease collection (may be empty if no IPv6 lease found).
     virtual Lease6Collection getLeases6() const;
+
+    /// @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) for the DUID.
+    virtual Lease6Collection getLeases6(const DUID& duid) const;
     
     /// @brief Returns range of IPv6 leases using paging.
     ///
index 16c3327ce42aaa2f3684d8ca432be3832a597521..fdcd2a37b0c2c9b6378a4262e705b935dfea0b07 100644 (file)
@@ -184,7 +184,7 @@ tagged_statements = { {
                         "state, user_context "
                             "FROM lease6 "
                             "WHERE address = ? AND lease_type = ?"},
-    {MySqlLeaseMgr::GET_LEASE6_DUID_IAID,
+       {MySqlLeaseMgr::GET_LEASE6_DUID_IAID,
                     "SELECT address, duid, valid_lifetime, "
                         "expire, subnet_id, pref_lifetime, "
                         "lease_type, iaid, prefix_len, "
@@ -2220,6 +2220,23 @@ MySqlLeaseMgr::getLeases6() const {
     return (result);
 }
 
+Lease6Collection
+MySqlLeaseMgr::getLeases6(const DUID& duid) const {
+   LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET_DUID);
+   
+    Lease6Collection result =  getLeases6();
+    
+    //erase the ones not containing the matching DUID
+    for (auto iter = result.begin(); iter != result.end();
+            iter++) {
+        if ((*iter)->duid_->getDuid() != duid.getDuid()) {
+            result.erase(iter);
+        }
+    }
+
+    return result;
+}
+
 Lease6Collection
 MySqlLeaseMgr::getLeases6(const asiolink::IOAddress& lower_bound_address,
                           const LeasePageSize& page_size) const {
index 64fe4710a379d6ceca41ae6db74b8f6466a55978..332a9129f3b7cb36eb191cf22a69bd2507ca9afa 100644 (file)
@@ -308,6 +308,12 @@ public:
     ///
     /// @return Lease collection (may be empty if no IPv6 lease found).
     virtual Lease6Collection getLeases6() const;
+
+    /// @brief Returns all 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) for the DUID.
+    virtual Lease6Collection getLeases6(const DUID& duid) const;
     
     /// @brief Returns range of IPv6 leases using paging.
     ///
index fc3bc0dfd0c4dc108faeeecd7acc3c621995165f..a2ac2b746564e13698314e1356a63d1bc2936edb 100644 (file)
@@ -1506,6 +1506,25 @@ PgSqlLeaseMgr::getLeases6(SubnetID subnet_id) const {
     return (result);
 }
 
+Lease6Collection
+PgSqlLeaseMgr::getLeases6( const DUID& duid ) const {
+    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
+              DHCPSRV_PGSQL_GET_DUID)
+              .arg(duid.toText());
+
+    Lease6Collection result = getLeases6();
+
+    //erase the ones not containing the matching DUID
+    for (auto iter = result.begin(); iter != result.end();
+            iter++) {
+        if ((*iter)->duid_->getDuid() != duid.getDuid()) {
+            result.erase(iter);
+        }
+    }
+
+    return (result);
+}
+
 Lease6Collection
 PgSqlLeaseMgr::getLeases6() const {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET6);
index 8b69c46b97dea9c5d6a3170330ec3294ec6ad9b9..15bd714a7df7ae72c86e3e1062ea35e22bdfd3ca 100644 (file)
@@ -280,6 +280,12 @@ public:
     ///
     /// @return Lease collection (may be empty if no IPv6 lease found).
     virtual Lease6Collection getLeases6() const;
+
+    /// @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) for the DUID
+    virtual Lease6Collection getLeases6(const DUID& duid) const;
     
     /// @brief Returns range of IPv6 leases using paging.
     ///
index d32379fe8dd2e0a3c538ed8788ce723ef5b65075..40e262741a0b73f854d199f52a9c2d8a4c157314 100644 (file)
@@ -208,6 +208,14 @@ public:
         return (leases6_);
     }
 
+    /// @brief Returns collection of lease for matching DUID
+    ///
+    /// @param duid ignored
+    /// @return whatever is set in leases6_ field
+    virtual Lease6Collection getLeases6(const DUID& duid) const {
+        return (leases6_);
+    }
+
     /// @brief Returns all IPv6 leases for the particular subnet identifier.
     ///
     /// @param subnet_id subnet identifier.
index d76038b16770315fb672172294fc1a1403eb35b4..69a5c626d5021898d4d05b08e77d5cdc21b23668 100644 (file)
@@ -81,7 +81,7 @@ HostDataSourceUtils::initializeHost4(const std::string& address,
 }
 
 HostPtr
-HostDataSourceUtils::initializeHost6(std::string address,
+HostDataSourceUtils::initializeHost6(const std::string address,
                                      Host::IdentifierType identifier,
                                      bool prefix,
                                      bool new_identifier,
@@ -107,6 +107,7 @@ HostDataSourceUtils::initializeHost6(std::string address,
     ++subnet4;
     ++subnet6;
 
+    std::string default_string;
     HostPtr host(new Host(&ident[0], ident.size(), identifier, subnet4, subnet6,
                           IOAddress("0.0.0.0")));