Add features support to tnccs plugins

This commit is contained in:
Andreas Steffen 2011-10-20 14:05:59 +02:00
parent 039a976745
commit e50c853597
5 changed files with 107 additions and 23 deletions

View File

@ -24,11 +24,22 @@ METHOD(plugin_t, get_name, char*,
return "tnccs-11";
}
METHOD(plugin_t, get_features, int,
tnccs_11_plugin_t *this, plugin_feature_t *features[])
{
static plugin_feature_t f[] = {
PLUGIN_CALLBACK(tnccs_method_register, tnccs_11_create),
PLUGIN_PROVIDE(CUSTOM, "tnccs-1.1"),
PLUGIN_DEPENDS(EAP_SERVER, EAP_TNC),
PLUGIN_DEPENDS(EAP_PEER, EAP_TNC),
};
*features = f;
return countof(f);
}
METHOD(plugin_t, destroy, void,
tnccs_11_plugin_t *this)
{
charon->tnccs->remove_method(charon->tnccs,
(tnccs_constructor_t)tnccs_11_create);
free(this);
}
@ -42,14 +53,11 @@ plugin_t *tnccs_11_plugin_create()
INIT(this,
.plugin = {
.get_name = _get_name,
.reload = (void*)return_false,
.get_features = _get_features,
.destroy = _destroy,
},
);
charon->tnccs->add_method(charon->tnccs, TNCCS_1_1,
(tnccs_constructor_t)tnccs_11_create);
return &this->plugin;
}

View File

@ -24,11 +24,22 @@ METHOD(plugin_t, get_name, char*,
return "tnccs-20";
}
METHOD(plugin_t, get_features, int,
tnccs_20_plugin_t *this, plugin_feature_t *features[])
{
static plugin_feature_t f[] = {
PLUGIN_CALLBACK(tnccs_method_register, tnccs_20_create),
PLUGIN_PROVIDE(CUSTOM, "tnccs-2.0"),
PLUGIN_DEPENDS(EAP_SERVER, EAP_TNC),
PLUGIN_DEPENDS(EAP_PEER, EAP_TNC),
};
*features = f;
return countof(f);
}
METHOD(plugin_t, destroy, void,
tnccs_20_plugin_t *this)
{
charon->tnccs->remove_method(charon->tnccs,
(tnccs_constructor_t)tnccs_20_create);
free(this);
}
@ -42,14 +53,11 @@ plugin_t *tnccs_20_plugin_create()
INIT(this,
.plugin = {
.get_name = _get_name,
.reload = (void*)return_false,
.get_features = _get_features,
.destroy = _destroy,
},
);
charon->tnccs->add_method(charon->tnccs, TNCCS_2_0,
(tnccs_constructor_t)tnccs_20_create);
return &this->plugin;
}

View File

@ -24,11 +24,24 @@ METHOD(plugin_t, get_name, char*,
return "tnccs-dynamic";
}
METHOD(plugin_t, get_features, int,
tnccs_dynamic_plugin_t *this, plugin_feature_t *features[])
{
static plugin_feature_t f[] = {
PLUGIN_CALLBACK(tnccs_method_register, tnccs_dynamic_create),
PLUGIN_PROVIDE(CUSTOM, "tnccs-dynamic"),
PLUGIN_DEPENDS(CUSTOM, "tnccs-1.1"),
PLUGIN_DEPENDS(CUSTOM, "tnccs-2.0"),
PLUGIN_DEPENDS(EAP_SERVER, EAP_TNC),
PLUGIN_DEPENDS(EAP_PEER, EAP_TNC),
};
*features = f;
return countof(f);
}
METHOD(plugin_t, destroy, void,
tnccs_dynamic_plugin_t *this)
{
charon->tnccs->remove_method(charon->tnccs,
(tnccs_constructor_t)tnccs_dynamic_create);
free(this);
}
@ -42,14 +55,11 @@ plugin_t *tnccs_dynamic_plugin_create()
INIT(this,
.plugin = {
.get_name = _get_name,
.reload = (void*)return_false,
.get_features = _get_features,
.destroy = _destroy,
},
);
charon->tnccs->add_method(charon->tnccs, TNCCS_DYNAMIC,
(tnccs_constructor_t)tnccs_dynamic_create);
return &this->plugin;
}

View File

@ -13,11 +13,55 @@
* for more details.
*/
#define USE_TNC
#include "tnccs.h"
#include <daemon.h>
ENUM(tnccs_type_names, TNCCS_UNKNOWN, TNCCS_2_0,
"unknown TNCCS",
"TNCCS 1.1",
"TNCCS SOH",
"TNCCS 2.0",
);
/**
* See header
*/
bool tnccs_method_register(plugin_t *plugin, plugin_feature_t *feature,
bool reg, void *data)
{
if (reg)
{
if (feature->type == FEATURE_CUSTOM)
{
tnccs_type_t type = TNCCS_UNKNOWN;
if (streq(feature->arg.custom, "tnccs-2.0"))
{
type = TNCCS_2_0;
}
else if (streq(feature->arg.custom, "tnccs-1.1"))
{
type = TNCCS_1_1;
}
else if (streq(feature->arg.custom, "tnccs-dynamic"))
{
type = TNCCS_DYNAMIC;
}
else
{
return FALSE;
}
charon->tnccs->add_method(charon->tnccs, type,
(tnccs_constructor_t)data);
}
}
else
{
charon->tnccs->remove_method(charon->tnccs, (tnccs_constructor_t)data);
}
return TRUE;
}

View File

@ -24,13 +24,15 @@
#ifndef TNCCS_H_
#define TNCCS_H_
typedef struct tnccs_t tnccs_t;
typedef enum tnccs_type_t tnccs_type_t;
#include <tncif.h>
#include <tncifimc.h>
#include <tncifimv.h>
#include <library.h>
typedef enum tnccs_type_t tnccs_type_t;
#include <plugins/plugin.h>
/**
* Type of TNC Client/Server protocol
@ -48,15 +50,27 @@ enum tnccs_type_t {
*/
extern enum_name_t *tnccs_type_names;
typedef struct tnccs_t tnccs_t;
/**
* Constructor definition for a pluggable TNCCS protocol implementation.
*
* @param is_server TRUE if TNC Server, FALSE if TNC Client
* @return implementation of the tnccs_t interface
*/
typedef tnccs_t* (*tnccs_constructor_t)(bool is_server);
typedef tnccs_t *(*tnccs_constructor_t)(bool is_server);
/**
* Helper function to (un-)register TNCCS methods from plugin features.
*
* This function is a plugin_feature_callback_t and can be used with the
* PLUGIN_CALLBACK macro to register a TNCCS method constructor.
*
* @param plugin plugin registering the TNCCS method constructor
* @param feature associated plugin feature
* @param reg TRUE to register, FALSE to unregister.
* @param data data passed to callback, a tnccs_constructor_t
*/
bool tnccs_method_register(plugin_t *plugin, plugin_feature_t *feature,
bool reg, void *data);
/**
* Callback function adding a message to a TNCCS batch