From: Tobias Brunner Date: Mon, 2 Oct 2023 13:08:49 +0000 (+0200) Subject: child-sa: Add method that returns a reference to an allocated reqid X-Git-Tag: 5.9.12rc1~10^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff269f7f1f6fbab4cbce061fd4f55b0976a14128;p=thirdparty%2Fstrongswan.git child-sa: Add method that returns a reference to an allocated reqid --- diff --git a/src/libcharon/sa/child_sa.c b/src/libcharon/sa/child_sa.c index 9e728bd458..494c36b2e8 100644 --- a/src/libcharon/sa/child_sa.c +++ b/src/libcharon/sa/child_sa.c @@ -361,6 +361,17 @@ METHOD(child_sa_t, get_reqid, uint32_t, return this->reqid; } +METHOD(child_sa_t, get_reqid_ref, uint32_t, + private_child_sa_t *this) +{ + if ((this->reqid_allocated || (!this->static_reqid && this->reqid)) && + charon->kernel->ref_reqid(charon->kernel, this->reqid) == SUCCESS) + { + return this->reqid; + } + return 0; +} + METHOD(child_sa_t, get_unique_id, uint32_t, private_child_sa_t *this) { @@ -2033,6 +2044,7 @@ child_sa_t *child_sa_create(host_t *me, host_t *other, child_cfg_t *config, .public = { .get_name = _get_name, .get_reqid = _get_reqid, + .get_reqid_ref = _get_reqid_ref, .get_unique_id = _get_unique_id, .get_config = _get_config, .get_state = _get_state, diff --git a/src/libcharon/sa/child_sa.h b/src/libcharon/sa/child_sa.h index 37f00277eb..0b7d111142 100644 --- a/src/libcharon/sa/child_sa.h +++ b/src/libcharon/sa/child_sa.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2019 Tobias Brunner + * Copyright (C) 2006-2023 Tobias Brunner * Copyright (C) 2006-2008 Martin Willi * Copyright (C) 2006 Daniel Roethlisberger * @@ -174,6 +174,18 @@ struct child_sa_t { */ uint32_t (*get_reqid)(child_sa_t *this); + /** + * Get an additional reference to the allocated reqid of this CHILD SA. + * + * For static reqids or until the reqid is allocated (if none was passed + * in the constructor), this returns 0. The returned reqid must be released + * via kernel_interface_t::release_reqid(). + * + * @return allocated reqid of the CHILD SA, 0 if reqid is static or + * not allocated yet + */ + uint32_t (*get_reqid_ref)(child_sa_t *this); + /** * Get the unique numerical identifier for this CHILD_SA. *