]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
child-sa: Add method that returns a reference to an allocated reqid
authorTobias Brunner <tobias@strongswan.org>
Mon, 2 Oct 2023 13:08:49 +0000 (15:08 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 13 Nov 2023 11:02:11 +0000 (12:02 +0100)
src/libcharon/sa/child_sa.c
src/libcharon/sa/child_sa.h

index 9e728bd45874ad7678121fb51c0f3e991e38cea0..494c36b2e8209f3f2679bb9c379778a2ab428d6f 100644 (file)
@@ -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,
index 37f00277ebd91ddcb7b52d5671bcf02f19609070..0b7d1111429f6c60948d60e05744f93487132ab2 100644 (file)
@@ -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.
         *