From: Tobias Brunner Date: Mon, 2 Oct 2023 12:58:50 +0000 (+0200) Subject: kernel-interface: Add method to increase refcount for allocated reqid X-Git-Tag: 5.9.12rc1~10^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e623f5792bdacfc7358b21ea5d10b43d3e5a3050;p=thirdparty%2Fstrongswan.git kernel-interface: Add method to increase refcount for allocated reqid --- diff --git a/src/libcharon/kernel/kernel_interface.c b/src/libcharon/kernel/kernel_interface.c index 844af7060c..ba5c03b9bf 100644 --- a/src/libcharon/kernel/kernel_interface.c +++ b/src/libcharon/kernel/kernel_interface.c @@ -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, diff --git a/src/libcharon/kernel/kernel_interface.h b/src/libcharon/kernel/kernel_interface.h index 9f8e9b7144..a70e7f8606 100644 --- a/src/libcharon/kernel/kernel_interface.h +++ b/src/libcharon/kernel/kernel_interface.h @@ -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. *