plugin-feature: Add vendor specific EAP method registration macros
authorTobias Brunner <tobias@strongswan.org>
Thu, 25 Jun 2015 15:41:09 +0000 (17:41 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 17 Aug 2015 09:28:08 +0000 (11:28 +0200)
Vendor specific EAP methods may be registered with:

    PLUGIN_CALLBACK(eap_method_register, <constructor>),
        PLUGIN_PROVIDE(EAP_SERVER_VENDOR, <type>, <vendor>),

Same for client implementations via EAP_PEER_VENDOR.

References #969.

src/libcharon/sa/eap/eap_method.c
src/libstrongswan/plugins/plugin_feature.c
src/libstrongswan/plugins/plugin_feature.h

index a05e8c5..9ce6ecf 100644 (file)
@@ -30,7 +30,8 @@ bool eap_method_register(plugin_t *plugin, plugin_feature_t *feature,
 {
        if (reg)
        {
-               charon->eap->add_method(charon->eap, feature->arg.eap, 0,
+               charon->eap->add_method(charon->eap, feature->arg.eap.type,
+                                       feature->arg.eap.vendor,
                                        feature->type == FEATURE_EAP_SERVER ? EAP_SERVER : EAP_PEER,
                                        (eap_constructor_t)data);
        }
index e909f4a..0ea5eea 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2013 Tobias Brunner
+ * Copyright (C) 2012-2015 Tobias Brunner
  * Hochschule fuer Technik Rapperswil
  *
  * Copyright (C) 2011 Martin Willi
@@ -185,7 +185,8 @@ bool plugin_feature_matches(plugin_feature_t *a, plugin_feature_t *b)
                                return a->arg.container == b->arg.container;
                        case FEATURE_EAP_SERVER:
                        case FEATURE_EAP_PEER:
-                               return a->arg.eap == b->arg.eap;
+                               return a->arg.eap.vendor == b->arg.eap.vendor &&
+                                          a->arg.eap.type == b->arg.eap.type;
                        case FEATURE_DATABASE:
                                return a->arg.database == DB_ANY ||
                                           a->arg.database == b->arg.database;
@@ -368,8 +369,15 @@ char* plugin_feature_get_string(plugin_feature_t *feature)
                        break;
                case FEATURE_EAP_SERVER:
                case FEATURE_EAP_PEER:
-                       if (asprintf(&str, "%N:%N", plugin_feature_names, feature->type,
-                                       eap_type_short_names, feature->arg.eap) > 0)
+                       if (feature->arg.eap.vendor &&
+                               asprintf(&str, "%N:%d-%d", plugin_feature_names, feature->type,
+                                       feature->arg.eap.type, feature->arg.eap.vendor) > 0)
+                       {
+                               return str;
+                       }
+                       else if (!feature->arg.eap.vendor &&
+                               asprintf(&str, "%N:%N", plugin_feature_names, feature->type,
+                                       eap_type_short_names, feature->arg.eap.type) > 0)
                        {
                                return str;
                        }
index ea23f76..03f1ba8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2013 Tobias Brunner
+ * Copyright (C) 2012-2015 Tobias Brunner
  * Hochschule fuer Technik Rapperswil
  *
  * Copyright (C) 2011 Martin Willi
@@ -196,7 +196,7 @@ struct plugin_feature_t {
                /** FEATURE_CONTAINER_DECODE/ENCODE */
                container_type_t container;
                /** FEATURE_EAP_SERVER/CLIENT */
-               eap_type_t eap;
+               eap_vendor_type_t eap;
                /** FEATURE_DATABASE */
                db_driver_t database;
                /** FEATURE_FETCHER */
@@ -292,8 +292,10 @@ struct plugin_feature_t {
 #define _PLUGIN_FEATURE_CERT_ENCODE(kind, type)                                __PLUGIN_FEATURE(kind, CERT_ENCODE, .cert = type)
 #define _PLUGIN_FEATURE_CONTAINER_DECODE(kind, type)           __PLUGIN_FEATURE(kind, CONTAINER_DECODE, .container = type)
 #define _PLUGIN_FEATURE_CONTAINER_ENCODE(kind, type)           __PLUGIN_FEATURE(kind, CONTAINER_ENCODE, .container = type)
-#define _PLUGIN_FEATURE_EAP_SERVER(kind, type)                         __PLUGIN_FEATURE(kind, EAP_SERVER, .eap = type)
-#define _PLUGIN_FEATURE_EAP_PEER(kind, type)                           __PLUGIN_FEATURE(kind, EAP_PEER, .eap = type)
+#define _PLUGIN_FEATURE_EAP_SERVER(kind, type)                         _PLUGIN_FEATURE_EAP_SERVER_VENDOR(kind, type, 0)
+#define _PLUGIN_FEATURE_EAP_PEER(kind, type)                           _PLUGIN_FEATURE_EAP_PEER_VENDOR(kind, type, 0)
+#define _PLUGIN_FEATURE_EAP_SERVER_VENDOR(kind, type, vendor)__PLUGIN_FEATURE(kind, EAP_SERVER, .eap = { type, vendor })
+#define _PLUGIN_FEATURE_EAP_PEER_VENDOR(kind, type, vendor)    __PLUGIN_FEATURE(kind, EAP_PEER, .eap = { type, vendor })
 #define _PLUGIN_FEATURE_DATABASE(kind, type)                           __PLUGIN_FEATURE(kind, DATABASE, .database = type)
 #define _PLUGIN_FEATURE_FETCHER(kind, type)                                    __PLUGIN_FEATURE(kind, FETCHER, .fetcher = type)
 #define _PLUGIN_FEATURE_RESOLVER(kind, ...)                                    __PLUGIN_FEATURE(kind, RESOLVER, .custom = NULL)