]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
kernel-interface: Add method to increase refcount for allocated reqid
authorTobias Brunner <tobias@strongswan.org>
Mon, 2 Oct 2023 12:58:50 +0000 (14:58 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 13 Nov 2023 11:02:11 +0000 (12:02 +0100)
src/libcharon/kernel/kernel_interface.c
src/libcharon/kernel/kernel_interface.h

index 844af7060cf4e58b43ca2ede6dfc085a07994fe4..ba5c03b9bfc520f73e962f6409eed958ab8efb7e 100644 (file)
@@ -433,6 +433,23 @@ METHOD(kernel_interface_t, alloc_reqid, status_t,
        return SUCCESS;
 }
 
+METHOD(kernel_interface_t, ref_reqid, status_t,
+       private_kernel_interface_t *this, uint32_t reqid)
+{
+       reqid_entry_t *entry, tmpl = {
+               .reqid = reqid,
+       };
+
+       this->mutex->lock(this->mutex);
+       entry = this->reqids->get(this->reqids, &tmpl);
+       if (entry)
+       {
+               entry->refs++;
+       }
+       this->mutex->unlock(this->mutex);
+       return entry ? SUCCESS : NOT_FOUND;
+}
+
 METHOD(kernel_interface_t, release_reqid, status_t,
        private_kernel_interface_t *this, uint32_t reqid)
 {
@@ -1039,6 +1056,7 @@ kernel_interface_t *kernel_interface_create()
                        .get_spi = _get_spi,
                        .get_cpi = _get_cpi,
                        .alloc_reqid = _alloc_reqid,
+                       .ref_reqid = _ref_reqid,
                        .release_reqid = _release_reqid,
                        .add_sa = _add_sa,
                        .update_sa = _update_sa,
index 9f8e9b7144c8bb098e1fe86cb5225a874fc27cdd..a70e7f86066e53028f889800974e1e2af8e84b15 100644 (file)
@@ -158,6 +158,18 @@ struct kernel_interface_t {
                                                        uint32_t if_id_out, sec_label_t *label,
                                                        uint32_t *reqid);
 
+       /**
+        * Increase the reference count for the given reqid that was previously
+        * allocated by alloc_reqid().
+        *
+        * The reference must be released with a call to release_reqid().
+        *
+        * @param reqid         previously allocated reqid
+        * @return                      SUCCESS if refcount increased, NOT_FOUND if reqid is
+        *                                      unknown (shouldn't happen)
+        */
+       status_t (*ref_reqid)(kernel_interface_t *this, uint32_t reqid);
+
        /**
         * Release a previously allocated reqid.
         *