moved recommendation handling to the tnc_imv plugin

This commit is contained in:
Andreas Steffen
2010-11-13 10:02:02 +01:00
parent 8f927116be
commit 10647add81
14 changed files with 310 additions and 152 deletions
-7
View File
@@ -48,13 +48,6 @@ struct imc_manager_t {
*/
imc_t* (*remove)(imc_manager_t *this, TNC_IMCID id);
/**
* Return the number of registered IMCs
*
* @return number of IMCs
*/
int (*get_count)(imc_manager_t *this);
/**
* Return the preferred language for recommendations
*
+4 -3
View File
@@ -22,6 +22,7 @@
#define IMV_MANAGER_H_
#include "imv.h"
#include "imv_recommendations.h"
#include <library.h>
@@ -49,11 +50,11 @@ struct imv_manager_t {
imv_t* (*remove)(imv_manager_t *this, TNC_IMVID id);
/**
* Return the number of registered IMVs
* Create an empty set of IMV recommendations and evaluations
*
* @return number of IMVs
* @return instance of a recommendations_t list
*/
int (*get_count)(imv_manager_t *this);
recommendations_t* (*create_recommendations)(imv_manager_t *this);
/**
* Enforce the TNC recommendation on the IKE_SA by either inserting an
@@ -0,0 +1,56 @@
/*
* 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 imv_recommendations imv_recommendations
* @{ @ingroup libcharon
*/
#ifndef IMV_RECOMMENDATIONS_H_
#define IMV_RECOMMENDATIONS_H_
#include <tnc/tncifimv.h>
#include <library.h>
typedef struct recommendations_t recommendations_t;
/**
* Collection of all IMV action recommendations and evaluation results
*/
struct recommendations_t {
/**
* Deliver an IMV action recommendation and IMV evaluation result to the TNCS
*
* @param imv_id ID of the IMV providing the recommendation
* @param recommendation action recommendation
* @param evaluation evaluation result
*/
TNC_Result (*provide_recommendation)(recommendations_t *this,
TNC_IMVID imv_id,
TNC_IMV_Action_Recommendation rec,
TNC_IMV_Evaluation_Result eval);
bool (*have_recommendation)(recommendations_t *this,
TNC_IMV_Action_Recommendation *rec,
TNC_IMV_Evaluation_Result *eval);
/**
* Destroys an imv_t object.
*/
void (*destroy)(recommendations_t *this);
};
#endif /** IMV_RECOMMENDATIONS_H_ @}*/
-14
View File
@@ -63,18 +63,4 @@ typedef void (*tnccs_send_message_t)(tnccs_t* tncss,
TNC_UInt32 message_len,
TNC_MessageType message_type);
/**
* Callback function delivering an IMV Action Recommendation and
* IMV Evaluation Result to the TNCS
*
* @param imv_id ID of the IMV providing the recommendation
* @param recommendation action recommendation
* @param evaluation evaluation result
*/
typedef void (*tnccs_provide_recommendation_t)(tnccs_t* tncss,
TNC_IMVID imv_id,
TNC_IMV_Action_Recommendation recommendation,
TNC_IMV_Evaluation_Result evaluation);
#endif /** TNCCS_H_ @}*/
+40 -15
View File
@@ -15,7 +15,10 @@
#include "tnccs_manager.h"
#include <tnc/imv/imv_recommendations.h>
#include <debug.h>
#include <daemon.h>
#include <utils/linked_list.h>
#include <threading/rwlock.h>
@@ -59,10 +62,10 @@ struct tnccs_connection_entry_t {
*/
tnccs_send_message_t send_message;
/** TNCS provide recommendation function
/** collection of IMV recommendations
*
*/
tnccs_provide_recommendation_t provide_recommendation;
recommendations_t *recs;
};
/**
@@ -164,17 +167,37 @@ METHOD(tnccs_manager_t, create_instance, tnccs_t*,
}
METHOD(tnccs_manager_t, create_connection, TNC_ConnectionID,
private_tnccs_manager_t *this, tnccs_t *tnccs,
tnccs_send_message_t send_message,
tnccs_provide_recommendation_t provide_recommendation)
private_tnccs_manager_t *this, tnccs_t *tnccs,
tnccs_send_message_t send_message, recommendations_t **recs)
{
tnccs_connection_entry_t *entry;
entry = malloc_thing(tnccs_connection_entry_t);
entry->tnccs = tnccs;
entry->send_message = send_message;
entry->provide_recommendation = provide_recommendation;
if (recs)
{
/* we assume a TNC Server needing recommendations from IMVs */
if (!charon->imvs)
{
DBG1(DBG_TNC, "no IMV manager available!");
free(entry);
return 0;
}
entry->recs = charon->imvs->create_recommendations(charon->imvs);
*recs = entry->recs;
}
else
{
/* we assume a TNC Client */
if (!charon->imcs)
{
DBG1(DBG_TNC, "no IMC manager available!");
free(entry);
return 0;
}
entry->recs = NULL;
}
this->connection_lock->write_lock(this->connection_lock);
entry->id = ++this->connection_id;
this->connections->insert_last(this->connections, entry);
@@ -197,6 +220,10 @@ METHOD(tnccs_manager_t, remove_connection, void,
if (id == entry->id)
{
this->connections->remove_at(this->connections, enumerator);
if (entry->recs)
{
entry->recs->destroy(entry->recs);
}
free(entry);
DBG1(DBG_TNC, "removed TNCCS Connection ID %u", id);
}
@@ -241,13 +268,12 @@ METHOD(tnccs_manager_t, send_message, TNC_Result,
METHOD(tnccs_manager_t, provide_recommendation, TNC_Result,
private_tnccs_manager_t *this, TNC_IMVID imv_id,
TNC_ConnectionID id,
TNC_IMV_Action_Recommendation recommendation,
TNC_IMV_Evaluation_Result evaluation)
TNC_IMV_Action_Recommendation rec,
TNC_IMV_Evaluation_Result eval)
{
enumerator_t *enumerator;
tnccs_connection_entry_t *entry;
tnccs_provide_recommendation_t provide_recommendation = NULL;
tnccs_t *tnccs = NULL;
recommendations_t *recs = NULL;
this->connection_lock->read_lock(this->connection_lock);
enumerator = this->connections->create_enumerator(this->connections);
@@ -255,17 +281,16 @@ METHOD(tnccs_manager_t, provide_recommendation, TNC_Result,
{
if (id == entry->id)
{
tnccs = entry->tnccs;
provide_recommendation = entry->provide_recommendation;
recs = entry->recs;
break;
}
}
enumerator->destroy(enumerator);
this->connection_lock->unlock(this->connection_lock);
if (tnccs && provide_recommendation)
if (recs)
{
provide_recommendation(tnccs, imv_id, recommendation, evaluation);
recs->provide_recommendation(recs, imv_id, rec, eval);
return TNC_RESULT_SUCCESS;
}
return TNC_RESULT_FATAL;
+8 -6
View File
@@ -23,6 +23,8 @@
#include "tnccs.h"
#include <tnc/imv/imv_recommendations.h>
typedef struct tnccs_manager_t tnccs_manager_t;
/**
@@ -61,18 +63,18 @@ struct tnccs_manager_t {
bool is_server);
/**
* Create a TNCCS connection and assign a unique connection ID as well as
* callback functions for adding a message to a TNCCS batch and delivering
* an IMV recommendation, respectively
* Create a TNCCS connection and assign a unique connection ID as well a
* callback function for adding a message to a TNCCS batch and create
* an empty set for collecting IMV recommendations
*
* @param tnccs TNCCS connection instance
* @param send_message TNCCS callback function
* @param provide_recommendation TNCS callback function
* @param recs pointer to IMV recommendation set
* @return assigned connection ID
*/
TNC_ConnectionID (*create_connection)(tnccs_manager_t *this, tnccs_t *tnccs,
tnccs_send_message_t send_message,
tnccs_provide_recommendation_t provide_recommendation);
tnccs_send_message_t send_message,
recommendations_t **recs);
/**
* Remove a TNCCS connection using its connection ID.