]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
added TNC_TNCC_ReserveAdditionalIMCID() function
authorAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 7 Dec 2011 16:31:49 +0000 (17:31 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 7 Dec 2011 16:31:49 +0000 (17:31 +0100)
src/libcharon/plugins/tnc_imc/tnc_imc.c
src/libcharon/plugins/tnc_imc/tnc_imc_bind_function.c
src/libcharon/plugins/tnc_imc/tnc_imc_manager.c
src/libtnccs/tnc/imc/imc.h
src/libtnccs/tnc/imc/imc_manager.h

index e13f770de3f6161fb92a02f85cf03a0066767148..6bd69dc874405eb7f83dbb9540f9966ebd4b28de 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2006 Mike McCauley
- * Copyright (C) 2010 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
+ * Copyright (C) 2010-2011 Andreas Steffen,
+ * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -21,6 +22,7 @@
 
 #include <debug.h>
 #include <library.h>
+#include <utils/linked_list.h>
 #include <threading/mutex.h>
 
 typedef struct private_tnc_imc_t private_tnc_imc_t;
@@ -55,6 +57,11 @@ struct private_tnc_imc_t {
         */
        TNC_IMCID id;
 
+       /**
+        * list of additional IMC IDs
+        */
+       linked_list_t *additional_ids;
+
        /**
         * List of message types supported by IMC - Vendor ID part
         */
@@ -88,6 +95,50 @@ METHOD(imc_t, get_id, TNC_IMCID,
        return this->id;
 }
 
+METHOD(imc_t, add_id, void,
+       private_tnc_imc_t *this, TNC_IMCID id)
+{
+       TNC_IMCID *new_id;
+
+       new_id = malloc_thing(TNC_IMCID);
+       *new_id = id;
+       this->additional_ids->insert_last(this->additional_ids, new_id);
+}
+
+METHOD(imc_t, has_id, bool,
+       private_tnc_imc_t *this, TNC_IMCID id)
+{
+       enumerator_t *enumerator;
+       TNC_IMCID *additional_id;
+       bool found = FALSE;
+
+       /* check primary IMC ID */
+       if (id == this->id)
+       {
+               return TRUE;
+       }
+
+       /* return if there are no additional IMC IDs */
+       if (this->additional_ids->get_count(this->additional_ids) == 0)
+       {
+               return FALSE;
+       }
+
+       /* check additional IMC IDs */
+       enumerator = this->additional_ids->create_enumerator(this->additional_ids);
+       while (enumerator->enumerate(enumerator, &additional_id))
+       {
+               if (id == *additional_id)
+               {
+                       found = TRUE;
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+
+       return found;
+}
+
 METHOD(imc_t, get_name, char*,
        private_tnc_imc_t *this)
 {
@@ -257,6 +308,7 @@ METHOD(imc_t, destroy, void,
 {
        dlclose(this->handle);
        this->mutex->destroy(this->mutex);
+       this->additional_ids->destroy_function(this->additional_ids, free);
        free(this->supported_vids);
        free(this->supported_subtypes);
        free(this->name);
@@ -275,6 +327,8 @@ imc_t* tnc_imc_create(char *name, char *path)
                .public = {
                        .set_id = _set_id,
                        .get_id = _get_id,
+                       .add_id = _add_id,
+                       .has_id = _has_id,
                        .get_name = _get_name,
                        .set_message_types = _set_message_types,
                        .set_message_types_long = _set_message_types_long,
@@ -283,6 +337,7 @@ imc_t* tnc_imc_create(char *name, char *path)
         },
                .name = name,
                .path = path,
+               .additional_ids = linked_list_create(),
                .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
        );
 
index b68899efd2132215c819c57d46fe8e7d09c3c970..1df10781fd2267cc553922b851e5752b72a8425a 100644 (file)
@@ -120,6 +120,19 @@ TNC_Result TNC_TNCC_SendMessageLong(TNC_IMCID imc_id,
                                                                msg_flags, msg, msg_len, msg_vid, msg_subtype);
 }
 
+/**
+ * Called by the IMC when it wants to reserve an additional IMC ID for itself
+ */
+TNC_Result TNC_TNCC_ReserveAdditionalIMCID(TNC_IMCID imc_id, TNC_UInt32 *new_id)
+{
+       if (!tnc->imcs->reserve_id(tnc->imcs, imc_id, new_id))
+       {
+               DBG1(DBG_TNC, "ignoring ReserveAdditionalIMCID() from unregistered IMC %u",
+                                          imc_id);
+               return TNC_RESULT_INVALID_PARAMETER;
+       }
+}
+
 /**
  * Called by the IMC when it needs a function pointer
  */
@@ -147,6 +160,10 @@ TNC_Result TNC_TNCC_BindFunction(TNC_IMCID id,
        {
                *function_pointer = (void*)TNC_TNCC_SendMessageLong;
        }
+    else if (streq(function_name, "TNC_TNCC_ReserveAdditionalIMCID"))
+       {
+               *function_pointer = (void*)TNC_TNCC_ReserveAdditionalIMCID;
+       }
     else
        {
                return TNC_RESULT_INVALID_PARAMETER;
index 3c1db376897593a7e0621eeb2acf53ca2f5573d5..5e06d9eb451a4119b835703820f3fdd31aa0c7b3 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2006 Mike McCauley
- * Copyright (C) 2010 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
+ * Copyright (C) 2010-2011 Andreas Steffen
+ * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -130,8 +131,30 @@ METHOD(imc_manager_t, is_registered, bool,
        enumerator = this->imcs->create_enumerator(this->imcs);
        while (enumerator->enumerate(enumerator, &imc))
        {
-               if (id == imc->get_id(imc))
+               if (imc->has_id(imc, id))
+               {
+                       found = TRUE;
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+
+       return found;
+}
+
+METHOD(imc_manager_t, reserve_id, bool,
+       private_tnc_imc_manager_t *this, TNC_IMCID id, TNC_UInt32 *new_id)
+{
+       enumerator_t *enumerator;
+       imc_t *imc;
+       bool found = FALSE;
+
+       enumerator = this->imcs->create_enumerator(this->imcs);
+       while (enumerator->enumerate(enumerator, &imc))
+       {
+               if (imc->get_id(imc))
                {
+                       imc->add_id(imc, this->next_imc_id++);
                        found = TRUE;
                        break;
                }
@@ -304,6 +327,7 @@ imc_manager_t* tnc_imc_manager_create(void)
                        .remove = _remove_, /* avoid name conflict with stdio.h */
                        .load = _load,
                        .is_registered = _is_registered,
+                       .reserve_id = _reserve_id,
                        .get_preferred_language = _get_preferred_language,
                        .notify_connection_change = _notify_connection_change,
                        .begin_handshake = _begin_handshake,
index 3545005ad856e5de73ce2547eac89e66829a25b1..3794fd26d4b81527b0b4e49a00038811119662cb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Andreas Steffen
+ * Copyright (C) 2010-2011 Andreas Steffen
  * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -143,6 +143,20 @@ struct imc_t {
         */
        TNC_IMCID (*get_id)(imc_t *this);
 
+       /**
+        * Assign an additional ID to an imc_t object.
+        *
+        * @param id                                    additional IMC ID to be assigned
+        */
+       void (*add_id)(imc_t *this, TNC_IMCID id);
+
+       /**
+        * Checks if the ID is assigned to the imc_t object.
+        *
+        * @return                                              TRUE if IMC ID is assigned to imc_t object
+        */
+       bool (*has_id)(imc_t *this, TNC_IMCID id);
+
        /**
         * Returns the name of an imc_t object.
         *
index 38eafbbee1ebb183a42571ce5564769f3e1ff505..ef2dcc6540994ffa53e96d43c0623b3d9732f761 100644 (file)
@@ -65,6 +65,15 @@ struct imc_manager_t {
         */
        bool (*is_registered)(imc_manager_t *this, TNC_IMCID id);
 
+       /**
+        * Reserve an additional ID for an IMC
+        *
+        * @param id                            ID of IMC instance
+        * @param new_id                        reserved ID assigned to IMC
+        * @return                                      TRUE if primary IMC ID was used
+        */
+       bool (*reserve_id)(imc_manager_t *this, TNC_IMCID id, TNC_UInt32 *new_id);
+
        /**
         * Return the preferred language for recommendations
         *