Pass context limits on to id manager
authorReto Buerki <reet@codelabs.ch>
Thu, 9 Aug 2012 13:18:05 +0000 (15:18 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 19 Mar 2013 14:23:45 +0000 (15:23 +0100)
src/charon-tkm/src/tkm/tkm.c
src/charon-tkm/src/tkm/tkm_id_manager.c
src/charon-tkm/src/tkm/tkm_id_manager.h
src/charon-tkm/tests/id_manager_tests.c

index e913ddb..f78d49b 100644 (file)
@@ -75,9 +75,12 @@ bool tkm_init()
                return FALSE;
        }
 
+       /* only nonce and DH context limits are currently needed */
+       const tkm_limits_t limits = {nc, dh};
+
        INIT(this,
                .public = {
-                       .idmgr = tkm_id_manager_create(),
+                       .idmgr = tkm_id_manager_create(limits),
                },
        );
        tkm = &this->public;
index 5a657fa..8426a2c 100644 (file)
@@ -132,7 +132,7 @@ METHOD(tkm_id_manager_t, destroy, void,
 /*
  * see header file
  */
-tkm_id_manager_t *tkm_id_manager_create()
+tkm_id_manager_t *tkm_id_manager_create(const tkm_limits_t limits)
 {
        private_tkm_id_manager_t *this;
        int i, j;
index 9842979..9fbdb2d 100644 (file)
@@ -41,6 +41,11 @@ enum tkm_context_kind_t {
 extern enum_name_t *tkm_context_kind_names;
 
 /**
+ * TKM context limits.
+ */
+typedef uint64_t tkm_limits_t[TKM_CTX_MAX];
+
+/**
  * The tkm id manager hands out context ids for all context kinds (e.g. nonce).
  */
 struct tkm_id_manager_t {
@@ -74,8 +79,8 @@ struct tkm_id_manager_t {
 };
 
 /**
- * Create a tkm id manager instance.
+ * Create a tkm id manager instance using the given context limits.
  */
-tkm_id_manager_t *tkm_id_manager_create();
+tkm_id_manager_t *tkm_id_manager_create(const tkm_limits_t limits);
 
 #endif /** TKM_ID_MANAGER_H_ */
index a71727a..86e80ae 100644 (file)
  * for more details.
  */
 
-#include <stdlib.h>
 #include <check.h>
 
 #include "tkm_id_manager.h"
 
+static const tkm_limits_t limits = {125, 100};
+
 START_TEST(test_id_mgr_creation)
 {
        tkm_id_manager_t *idmgr = NULL;
 
-       idmgr = tkm_id_manager_create();
+       idmgr = tkm_id_manager_create(limits);
        fail_if(idmgr == NULL, "Error creating tkm id manager");
 
        idmgr->destroy(idmgr);
@@ -33,7 +34,7 @@ END_TEST
 START_TEST(test_acquire_id)
 {
        int i, id = 0;
-       tkm_id_manager_t *idmgr = tkm_id_manager_create();
+       tkm_id_manager_t *idmgr = tkm_id_manager_create(limits);
 
        for (i = 0; i < TKM_CTX_MAX; i++)
        {
@@ -51,7 +52,7 @@ END_TEST
 START_TEST(test_acquire_id_invalid_kind)
 {
        int id = 0;
-       tkm_id_manager_t *idmgr = tkm_id_manager_create();
+       tkm_id_manager_t *idmgr = tkm_id_manager_create(limits);
 
        id = idmgr->acquire_id(idmgr, TKM_CTX_MAX);
        fail_unless(id == 0, "Acquired id for invalid context kind %d", TKM_CTX_MAX);
@@ -69,7 +70,7 @@ END_TEST
 START_TEST(test_acquire_id_same)
 {
        int id1 = 0, id2 = 0;
-       tkm_id_manager_t *idmgr = tkm_id_manager_create();
+       tkm_id_manager_t *idmgr = tkm_id_manager_create(limits);
 
        id1 = idmgr->acquire_id(idmgr, TKM_CTX_NONCE);
        fail_unless(id1 > 0, "Unable to acquire first id");
@@ -87,7 +88,7 @@ START_TEST(test_release_id)
 {
        int i, id = 0;
        bool released = false;
-       tkm_id_manager_t *idmgr = tkm_id_manager_create();
+       tkm_id_manager_t *idmgr = tkm_id_manager_create(limits);
 
        for (i = 0; i < TKM_CTX_MAX; i++)
        {
@@ -107,7 +108,7 @@ END_TEST
 START_TEST(test_release_id_invalid_kind)
 {
        bool released = TRUE;
-       tkm_id_manager_t *idmgr = tkm_id_manager_create();
+       tkm_id_manager_t *idmgr = tkm_id_manager_create(limits);
 
        released = idmgr->release_id(idmgr, TKM_CTX_MAX, 1);
        fail_if(released, "Released id for invalid context kind %d", TKM_CTX_MAX);
@@ -125,7 +126,7 @@ END_TEST
 START_TEST(test_release_id_nonexistent)
 {
        bool released = FALSE;
-       tkm_id_manager_t *idmgr = tkm_id_manager_create();
+       tkm_id_manager_t *idmgr = tkm_id_manager_create(limits);
 
        released = idmgr->release_id(idmgr, TKM_CTX_NONCE, 1);
        fail_unless(released, "Release of nonexistent id failed");