implement IMC and IMV manager classes
This commit is contained in:
@@ -11,7 +11,8 @@ plugin_LTLIBRARIES = libstrongswan-tnc-imv.la
|
||||
endif
|
||||
|
||||
libstrongswan_tnc_imv_la_SOURCES = \
|
||||
tnc_imv_plugin.h tnc_imv_plugin.c tnc_imv.h tnc_imv.c
|
||||
tnc_imv_plugin.h tnc_imv_plugin.c tnc_imv.h tnc_imv.c \
|
||||
tnc_imv_manager.h tnc_imv_manager.c
|
||||
|
||||
libstrongswan_tnc_imv_la_LDFLAGS = -module -avoid-version
|
||||
|
||||
|
||||
@@ -40,12 +40,24 @@ struct private_tnc_imv_t {
|
||||
TNC_IMVID id;
|
||||
};
|
||||
|
||||
METHOD(imv_t, set_id, void,
|
||||
private_tnc_imv_t *this, TNC_IMVID id)
|
||||
{
|
||||
this->id = id;
|
||||
}
|
||||
|
||||
METHOD(imv_t, get_id, TNC_IMVID,
|
||||
private_tnc_imv_t *this)
|
||||
{
|
||||
return this->id;
|
||||
}
|
||||
|
||||
METHOD(imv_t, get_name, char*,
|
||||
private_tnc_imv_t *this)
|
||||
{
|
||||
return this->name;
|
||||
}
|
||||
|
||||
METHOD(imv_t, destroy, void,
|
||||
private_tnc_imv_t *this)
|
||||
{
|
||||
@@ -56,14 +68,16 @@ METHOD(imv_t, destroy, void,
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
imv_t* tnc_imv_create(char *name, char *filename, TNC_IMVID id)
|
||||
imv_t* tnc_imv_create(char *name, char *filename)
|
||||
{
|
||||
private_tnc_imv_t *this;
|
||||
void *handle;
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.set_id = _set_id,
|
||||
.get_id = _get_id,
|
||||
.get_name = _get_name,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
);
|
||||
@@ -114,10 +128,87 @@ imv_t* tnc_imv_create(char *name, char *filename, TNC_IMVID id)
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
DBG2(DBG_TNC, "IMV '%s' loaded successfully with ID %u", name, id);
|
||||
this->name = strdup(name);
|
||||
this->id = id;
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the IMV to inform a TNCS about the set of message types the IMV
|
||||
* is able to receive
|
||||
*/
|
||||
TNC_Result TNC_TNCS_ReportMessageTypes(TNC_IMVID imv_id,
|
||||
TNC_MessageTypeList supported_types,
|
||||
TNC_UInt32 type_count)
|
||||
{
|
||||
DBG2(DBG_TNC,"TNCS_ReportMessageTypes %u %u", imv_id, type_count);
|
||||
return TNC_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the IMV to ask a TNCS to retry an Integrity Check Handshake
|
||||
*/
|
||||
TNC_Result TNC_TNCS_RequestHandshakeRetry(TNC_IMVID imv_id,
|
||||
TNC_ConnectionID connection_id,
|
||||
TNC_RetryReason reason)
|
||||
{
|
||||
DBG2(DBG_TNC,"TNCS_RequestHandshakeRetry %u %u", imv_id, connection_id);
|
||||
return TNC_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the IMV when an IMV-IMC message is to be sent
|
||||
*/
|
||||
TNC_Result TNC_TNCS_SendMessage(TNC_IMVID imv_id,
|
||||
TNC_ConnectionID connection_id,
|
||||
TNC_BufferReference message,
|
||||
TNC_UInt32 message_len,
|
||||
TNC_MessageType message_type)
|
||||
{
|
||||
DBG2(DBG_TNC,"TNCS_SendMessage %u %u '%s' %u %0x", imv_id, connection_id,
|
||||
message, message_len, message_type);
|
||||
return TNC_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the IMV to deliver its IMV Action Recommendation and IMV Evaluation
|
||||
* Result to the TNCS
|
||||
*/
|
||||
TNC_Result TNC_TNCS_ProvideRecommendation(TNC_IMVID imv_id,
|
||||
TNC_ConnectionID connection_id,
|
||||
TNC_IMV_Action_Recommendation recommendation,
|
||||
TNC_IMV_Evaluation_Result evaluation)
|
||||
{
|
||||
DBG2(DBG_TNC,"TNCS_ProvideRecommendation %u %u", imv_id, connection_id);
|
||||
return TNC_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the IMV when it needs a function pointer
|
||||
*/
|
||||
TNC_Result TNC_TNCS_BindFunction(TNC_IMVID id,
|
||||
char *function_name,
|
||||
void **function_pointer)
|
||||
{
|
||||
if (streq(function_name, "TNC_TNCS_ReportMessageTypes"))
|
||||
{
|
||||
*function_pointer = (void*)TNC_TNCS_ReportMessageTypes;
|
||||
}
|
||||
else if (streq(function_name, "TNC_TNCS_RequestHandshakeRetry"))
|
||||
{
|
||||
*function_pointer = (void*)TNC_TNCS_RequestHandshakeRetry;
|
||||
}
|
||||
else if (streq(function_name, "TNC_TNCS_SendMessage"))
|
||||
{
|
||||
*function_pointer = (void*)TNC_TNCS_SendMessage;
|
||||
}
|
||||
else if (streq(function_name, "TNC_TNCS_ProvideRecommendation"))
|
||||
{
|
||||
*function_pointer = (void*)TNC_TNCS_ProvideRecommendation;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TNC_RESULT_INVALID_PARAMETER;
|
||||
}
|
||||
return TNC_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -29,9 +29,8 @@
|
||||
*
|
||||
* @param name name of the IMV
|
||||
* @param filename path to the dynamic IMV library
|
||||
* @param id ID of the IMV
|
||||
* @return instance of the imv_t interface
|
||||
*/
|
||||
imv_t* tnc_imv_create(char *name, char *filename, TNC_IMVID id);
|
||||
imv_t* tnc_imv_create(char *name, char *filename);
|
||||
|
||||
#endif /** TNC_IMV_H_ @}*/
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Mike McCauley
|
||||
* Copyright (C) 2010 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
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include "tnc_imv_manager.h"
|
||||
|
||||
#include <tnc/imv/imv_manager.h>
|
||||
#include <tnc/tncifimv.h>
|
||||
|
||||
#include <debug.h>
|
||||
#include <library.h>
|
||||
#include <utils/linked_list.h>
|
||||
|
||||
typedef struct private_tnc_imv_manager_t private_tnc_imv_manager_t;
|
||||
|
||||
struct private_tnc_imv_manager_t {
|
||||
|
||||
/**
|
||||
* Public members of imv_manager_t.
|
||||
*/
|
||||
imv_manager_t public;
|
||||
|
||||
/**
|
||||
* Linked list of IMVs
|
||||
*/
|
||||
linked_list_t *imvs;
|
||||
|
||||
/**
|
||||
* Next IMV ID to be assigned
|
||||
*/
|
||||
TNC_IMVID next_imv_id;
|
||||
};
|
||||
|
||||
METHOD(imv_manager_t, add, bool,
|
||||
private_tnc_imv_manager_t *this, imv_t *imv)
|
||||
{
|
||||
TNC_Version version;
|
||||
|
||||
/* Initialize the IMV module */
|
||||
imv->set_id(imv, this->next_imv_id);
|
||||
if (imv->initialize(imv->get_id(imv), TNC_IFIMV_VERSION_1,
|
||||
TNC_IFIMV_VERSION_1, &version) != TNC_RESULT_SUCCESS)
|
||||
{
|
||||
DBG1(DBG_TNC, "could not initialize IMV '%s'",
|
||||
imv->get_name(imv));
|
||||
return FALSE;
|
||||
}
|
||||
if (imv->provide_bind_function(imv->get_id(imv), TNC_TNCS_BindFunction)
|
||||
!= TNC_RESULT_SUCCESS)
|
||||
{
|
||||
DBG1(DBG_TNC, "could not provide bind function for IMV '%s'",
|
||||
imv->get_name(imv));
|
||||
return FALSE;
|
||||
}
|
||||
this->imvs->insert_last(this->imvs, imv);
|
||||
this->next_imv_id++;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(imv_manager_t, notify_connection_change, void,
|
||||
private_tnc_imv_manager_t *this, TNC_ConnectionID id,
|
||||
TNC_ConnectionState state)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
imv_t *imv;
|
||||
|
||||
enumerator = this->imvs->create_enumerator(this->imvs);
|
||||
while (enumerator->enumerate(enumerator, &imv))
|
||||
{
|
||||
if (imv->notify_connection_change)
|
||||
{
|
||||
imv->notify_connection_change(imv->get_id(imv), id, state);
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
}
|
||||
|
||||
METHOD(imv_manager_t, destroy, void,
|
||||
private_tnc_imv_manager_t *this)
|
||||
{
|
||||
imv_t *imv;
|
||||
|
||||
while (this->imvs->remove_last(this->imvs, (void**)&imv) == SUCCESS)
|
||||
{
|
||||
if (imv->terminate &&
|
||||
imv->terminate(imv->get_id(imv)) != TNC_RESULT_SUCCESS)
|
||||
{
|
||||
DBG1(DBG_TNC, "IMV '%s' not terminated successfully",
|
||||
imv->get_name(imv));
|
||||
}
|
||||
imv->destroy(imv);
|
||||
}
|
||||
this->imvs->destroy(this->imvs);
|
||||
free(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
imv_manager_t* tnc_imv_manager_create(void)
|
||||
{
|
||||
private_tnc_imv_manager_t *this;
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.add = _add,
|
||||
.notify_connection_change = _notify_connection_change,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.imvs = linked_list_create(),
|
||||
.next_imv_id = 1,
|
||||
);
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @defgroup tnc_imv_manager tnc_imv_manager
|
||||
* @{ @ingroup tnc_imv
|
||||
*/
|
||||
|
||||
#ifndef TNC_IMV_MANAGER_H_
|
||||
#define TNC_IMV_MANAGER_H_
|
||||
|
||||
#include <tnc/imv/imv_manager.h>
|
||||
|
||||
/**
|
||||
* Create an IMC manager instance.
|
||||
*/
|
||||
imv_manager_t *tnc_imv_manager_create();
|
||||
|
||||
#endif /** TNC_IMV_MANAGER_H_ @}*/
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "tnc_imv_plugin.h"
|
||||
#include "tnc_imv_manager.h"
|
||||
#include "tnc_imv.h"
|
||||
|
||||
#include <daemon.h>
|
||||
@@ -21,18 +22,7 @@
|
||||
METHOD(plugin_t, destroy, void,
|
||||
tnc_imv_plugin_t *this)
|
||||
{
|
||||
imv_t *imv;
|
||||
|
||||
while (charon->imvs->remove_last(charon->imvs, (void**)&imv) == SUCCESS)
|
||||
{
|
||||
if (imv->terminate &&
|
||||
imv->terminate(imv->get_id(imv)) != TNC_RESULT_SUCCESS)
|
||||
{
|
||||
DBG1(DBG_TNC, "IMV '%s' not terminated successfully",
|
||||
imv->get_name(imv));
|
||||
}
|
||||
imv->destroy(imv);
|
||||
}
|
||||
charon->imvs->destroy(charon->imvs);
|
||||
free(this);
|
||||
}
|
||||
|
||||
@@ -41,8 +31,6 @@ METHOD(plugin_t, destroy, void,
|
||||
*/
|
||||
plugin_t *tnc_imv_plugin_create()
|
||||
{
|
||||
TNC_IMVID next_id = 1;
|
||||
TNC_Version version;
|
||||
char *tnc_config, *name, *filename;
|
||||
tnc_imv_plugin_t *this;
|
||||
imv_t *imv;
|
||||
@@ -56,24 +44,19 @@ plugin_t *tnc_imv_plugin_create()
|
||||
tnc_config = lib->settings->get_str(lib->settings,
|
||||
"charon.plugins.tnc-imv.tnc_config", "/etc/tnc_config");
|
||||
|
||||
/* Create IMV manager */
|
||||
charon->imvs = tnc_imv_manager_create();
|
||||
|
||||
/* Create and register IMVs */
|
||||
name = "Dummy";
|
||||
filename = "/usr/local/lib/libdummyimv.so";
|
||||
imv = tnc_imv_create(name, filename, next_id);
|
||||
imv = tnc_imv_create(name, filename);
|
||||
if (imv)
|
||||
{
|
||||
/* Initialize the module */
|
||||
if (imv->initialize(next_id, TNC_IFIMV_VERSION_1, TNC_IFIMV_VERSION_1,
|
||||
&version) != TNC_RESULT_SUCCESS)
|
||||
if (!charon->imvs->add(charon->imvs, imv))
|
||||
{
|
||||
DBG1(DBG_TNC, "could not initialize IMV '%s'\n",
|
||||
imv->get_name(imv));
|
||||
imv->destroy(imv);
|
||||
}
|
||||
else
|
||||
{
|
||||
charon->imvs->insert_last(charon->imvs, imv);
|
||||
next_id++;
|
||||
}
|
||||
}
|
||||
return &this->plugin;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user