diff options
-rw-r--r-- | src/libcharon/plugins/tnccs_11/tnccs_11_plugin.c | 20 | ||||
-rw-r--r-- | src/libcharon/plugins/tnccs_20/tnccs_20_plugin.c | 20 | ||||
-rw-r--r-- | src/libcharon/plugins/tnccs_dynamic/tnccs_dynamic_plugin.c | 22 | ||||
-rw-r--r-- | src/libcharon/tnc/tnccs/tnccs.c | 44 | ||||
-rw-r--r-- | src/libcharon/tnc/tnccs/tnccs.h | 24 |
5 files changed, 107 insertions, 23 deletions
diff --git a/src/libcharon/plugins/tnccs_11/tnccs_11_plugin.c b/src/libcharon/plugins/tnccs_11/tnccs_11_plugin.c index 9ec91f006..9d227f017 100644 --- a/src/libcharon/plugins/tnccs_11/tnccs_11_plugin.c +++ b/src/libcharon/plugins/tnccs_11/tnccs_11_plugin.c @@ -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; } diff --git a/src/libcharon/plugins/tnccs_20/tnccs_20_plugin.c b/src/libcharon/plugins/tnccs_20/tnccs_20_plugin.c index e6dc699e6..a44c614d5 100644 --- a/src/libcharon/plugins/tnccs_20/tnccs_20_plugin.c +++ b/src/libcharon/plugins/tnccs_20/tnccs_20_plugin.c @@ -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; } diff --git a/src/libcharon/plugins/tnccs_dynamic/tnccs_dynamic_plugin.c b/src/libcharon/plugins/tnccs_dynamic/tnccs_dynamic_plugin.c index 089a3ed57..8a6298a57 100644 --- a/src/libcharon/plugins/tnccs_dynamic/tnccs_dynamic_plugin.c +++ b/src/libcharon/plugins/tnccs_dynamic/tnccs_dynamic_plugin.c @@ -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; } diff --git a/src/libcharon/tnc/tnccs/tnccs.c b/src/libcharon/tnc/tnccs/tnccs.c index 575b850f5..5a6d5a4b8 100644 --- a/src/libcharon/tnc/tnccs/tnccs.c +++ b/src/libcharon/tnc/tnccs/tnccs.c @@ -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; +} diff --git a/src/libcharon/tnc/tnccs/tnccs.h b/src/libcharon/tnc/tnccs/tnccs.h index dc8a422f7..7145c6ad3 100644 --- a/src/libcharon/tnc/tnccs/tnccs.h +++ b/src/libcharon/tnc/tnccs/tnccs.h @@ -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 |