]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2869] Implemented new deletes
authorFrancis Dupont <fdupont@isc.org>
Thu, 25 May 2023 00:29:39 +0000 (02:29 +0200)
committerFrancis Dupont <fdupont@isc.org>
Thu, 6 Jul 2023 20:11:32 +0000 (22:11 +0200)
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

index 48e7f6d27392a92027f9f5822f8efdeeca434ad7..a6aef3ad204af026532e61c75a2ec08d565472e5 100644 (file)
@@ -3812,8 +3812,69 @@ MySqlLeaseMgr::checkError(MySqlLeaseContextPtr& ctx,
 }
 
 void
-MySqlLeaseMgr::deleteExtendedInfo6(const IOAddress& /* addr */) {
-    isc_throw(NotImplemented, "MySqlLeaseMgr::deleteExtendedInfo6 not implemented");
+MySqlLeaseMgr::deleteExtendedInfo6(const IOAddress& addr) {
+    deleteRelayId6(addr);
+    deleteRemoteId6(addr);
+}
+
+void
+MySqlLeaseMgr::deleteRelayId6(const IOAddress& addr) {
+    // Get a context.
+    MySqlLeaseContextAlloc get_context(*this);
+    MySqlLeaseContextPtr ctx = get_context.ctx_;
+
+    // Bind the lease address.
+    MYSQL_BIND bind[1];
+    memset(bind, 0, sizeof(bind));
+
+    std::vector<uint8_t> addr_data = addr.toBytes();
+    // Do not check the address length as it does not really matter.
+    unsigned long addr_length = addr_data.size();
+    bind[0].buffer_type = MYSQL_TYPE_BLOB;
+    bind[0].buffer = reinterpret_cast<char*>(&addr_data[0]);
+    bind[0].buffer_length = addr_length;
+    bind[0].length = &addr_length;
+
+    // Delete from lease6_relay_id table.
+    StatementIndex stindex = DELETE_RELAY_ID6;
+
+    // Bind the input parameters to the statement.
+    int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
+    checkError(ctx, status, stindex, "unable to bind WHERE clause parameter");
+
+    // Execute.
+    status = MysqlExecuteStatement(ctx->conn_.statements_[stindex]);
+    checkError(ctx, status, stindex, "unable to execute");
+}
+
+void
+MySqlLeaseMgr::deleteRemoteId6(const IOAddress& addr) {
+    // Get a context.
+    MySqlLeaseContextAlloc get_context(*this);
+    MySqlLeaseContextPtr ctx = get_context.ctx_;
+
+    // Bind the lease address.
+    MYSQL_BIND bind[1];
+    memset(bind, 0, sizeof(bind));
+
+    std::vector<uint8_t> addr_data = addr.toBytes();
+    // Do not check the address length as it does not really matter.
+    unsigned long addr_length = addr_data.size();
+    bind[0].buffer_type = MYSQL_TYPE_BLOB;
+    bind[0].buffer = reinterpret_cast<char*>(&addr_data[0]);
+    bind[0].buffer_length = addr_length;
+    bind[0].length = &addr_length;
+
+    // Delete from lease6_remote_id table.
+    StatementIndex stindex = DELETE_REMOTE_ID6;
+
+    // Bind the input parameters to the statement.
+    int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
+    checkError(ctx, status, stindex, "unable to bind WHERE clause parameter");
+
+    // Execute.
+    status = MysqlExecuteStatement(ctx->conn_.statements_[stindex]);
+    checkError(ctx, status, stindex, "unable to execute");
 }
 
 void
index 5472db03c479bc680b5fbe62febcdcf877a18892..925731d2921b00b765af8e25a2e77f1ba3b75233 100644 (file)
@@ -1071,6 +1071,7 @@ private:
                     int status, StatementIndex index,
                     const char* what) const;
 
+public:
     /// The following queries are used to fulfill Bulk Lease Query
     /// queries. They rely on relay data contained in lease's
     /// user-context when the extended-store-info flag is enabled.
@@ -1186,6 +1187,7 @@ private:
     /// @brief Wipe by-relay-id table (v6).
     virtual void wipeExtendedInfoTables6() override;
 
+private:
     /// @brief Context RAII allocator.
     class MySqlLeaseContextAlloc {
     public:
@@ -1289,6 +1291,15 @@ protected:
                               const std::vector<uint8_t>& remote_id) override;
 
 private:
+    /// @brief Delete lease6 extended info from by-relay-id table.
+    ///
+    /// @param addr The address of the lease.
+    void deleteRelayId6(const isc::asiolink::IOAddress& addr);
+
+    /// @brief Delete lease6 extended info from by-remote-id table.
+    ///
+    /// @param addr The address of the lease.
+    void deleteRemoteId6(const isc::asiolink::IOAddress& addr);
 
     // Members
 
index a0c2f67167ad09f90fa4caadcde765a1176c4be9..45a0ca44d43e3904735f7cd185cb8e7719bf0115 100644 (file)
@@ -2978,8 +2978,67 @@ PgSqlLeaseMgr::rollback() {
 }
 
 void
-PgSqlLeaseMgr::deleteExtendedInfo6(const IOAddress& /* addr */) {
-    isc_throw(NotImplemented, "PgSqlLeaseMgr::deleteExtendedInfo6 not implemented");
+PgSqlLeaseMgr::deleteExtendedInfo6(const IOAddress& addr) {
+    deleteRelayId6(addr);
+    deleteRemoteId6(addr);
+}
+
+void
+PgSqlLeaseMgr::deleteRelayId6(const IOAddress& addr) {
+    // Set up the WHERE clause value.
+    PsqlBindArray bind_array;
+
+    std::vector<uint8_t> addr_data = addr.toBytes();
+    // Do not check the address length as it does not really matter.
+    bind_array.add(addr_data);
+
+    // Get a context.
+    PgSqlLeaseContextAlloc get_context(*this);
+    PgSqlLeaseContextPtr ctx = get_context.ctx_;
+
+    // Delete from lease6_relay_id table.
+    StatementIndex stindex = DELETE_RELAY_ID6;
+
+    PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
+                                 tagged_statements[stindex].nbparams,
+                                 &bind_array.values_[0],
+                                 &bind_array.lengths_[0],
+                                 &bind_array.formats_[0], 0));
+
+    int s = PQresultStatus(r);
+
+    if (s != PGRES_COMMAND_OK) {
+        ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
+    }
+}
+
+void
+PgSqlLeaseMgr::deleteRemoteId6(const IOAddress& addr) {
+    // Set up the WHERE clause value.
+    PsqlBindArray bind_array;
+
+    std::vector<uint8_t> addr_data = addr.toBytes();
+    // Do not check the address length as it does not really matter.
+    bind_array.add(addr_data);
+
+    // Get a context.
+    PgSqlLeaseContextAlloc get_context(*this);
+    PgSqlLeaseContextPtr ctx = get_context.ctx_;
+
+    // Delete from lease6_remote_id table.
+    StatementIndex stindex = DELETE_REMOTE_ID6;
+
+    PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
+                                 tagged_statements[stindex].nbparams,
+                                 &bind_array.values_[0],
+                                 &bind_array.lengths_[0],
+                                 &bind_array.formats_[0], 0));
+
+    int s = PQresultStatus(r);
+
+    if (s != PGRES_COMMAND_OK) {
+        ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
+    }
 }
 
 void
index b94de61494be03e1b07f4b7c74ce362ecf227078..fafeebfc2eb0985c970217cd15245f9c0e17fc2a 100644 (file)
@@ -972,6 +972,7 @@ private:
     std::string
     checkLimits(isc::data::ConstElementPtr const& user_context, StatementIndex const stindex) const;
 
+public:
     /// @brief Checks if the IPv4 lease limits set in the given user context are exceeded.
     /// PostgreSQL implementation.
     ///
@@ -1146,6 +1147,7 @@ private:
     /// @brief Write V6 leases to a file.
     virtual void writeLeases6(const std::string& /*filename*/) override;
 
+private:
     /// @brief Context RAII allocator.
     class PgSqlLeaseContextAlloc {
     public:
@@ -1249,6 +1251,15 @@ protected:
                               const std::vector<uint8_t>& remote_id) override;
 
 private:
+    /// @brief Delete lease6 extended info from by-relay-id table.
+    ///
+    /// @param addr The address of the lease.
+    void deleteRelayId6(const isc::asiolink::IOAddress& addr);
+
+    /// @brief Delete lease6 extended info from by-remote-id table.
+    ///
+    /// @param addr The address of the lease.
+    void deleteRemoteId6(const isc::asiolink::IOAddress& addr);
 
     // Members