diff --git a/src/eap.c b/src/eap.c index 1c86046f..7ff87aa3 100644 --- a/src/eap.c +++ b/src/eap.c @@ -412,15 +412,54 @@ int eap_unregister_method(struct eap_method *method) return -ENOENT; } -void eap_init(void) { - eap_methods = l_queue_new(); +static void __eap_method_enable(struct eap_method_desc *start, + struct eap_method_desc *stop) +{ + struct eap_method_desc *desc; - eap_register_method(&eap_md5); - eap_register_method(&eap_tls); - eap_register_method(&eap_ttls); + l_debug(""); + + if (start == NULL || stop == NULL) + return; + + for (desc = start; desc < stop; desc++) { + if (!desc->init) + continue; + + desc->init(); + } } -void eap_exit(void) { +static void __eap_method_disable(struct eap_method_desc *start, + struct eap_method_desc *stop) +{ + struct eap_method_desc *desc; + + l_debug(""); + + if (start == NULL || stop == NULL) + return; + + for (desc = start; desc < stop; desc++) { + if (!desc->exit) + continue; + + desc->exit(); + } +} + +extern struct eap_method_desc __start___eap[]; +extern struct eap_method_desc __stop___eap[]; + +void eap_init(void) +{ + eap_methods = l_queue_new(); + __eap_method_enable(__start___eap, __stop___eap); +} + +void eap_exit(void) +{ + __eap_method_disable(__start___eap, __stop___eap); l_queue_destroy(eap_methods, NULL); } diff --git a/src/eap.h b/src/eap.h index 75a9525a..a8bb52ab 100644 --- a/src/eap.h +++ b/src/eap.h @@ -95,6 +95,18 @@ struct eap_method { const uint8_t *pkt, size_t len); }; +struct eap_method_desc { + const char *name; + int (*init)(void); + void (*exit)(void); +} __attribute__((aligned(8))); + +#define EAP_METHOD_BUILTIN(name, init, exit) \ + static struct eap_method_desc __eap_builtin_ ## name \ + __attribute__((used, section("__eap"), aligned(8))) = { \ + #name, init, exit \ + }; \ + int eap_register_method(struct eap_method *method); int eap_unregister_method(struct eap_method *method); @@ -117,7 +129,3 @@ void eap_method_error(struct eap_state *eap); void eap_save_last_id(struct eap_state *eap, uint8_t *last_id); void eap_restore_last_id(struct eap_state *eap, uint8_t last_id); - -extern struct eap_method eap_md5; -extern struct eap_method eap_tls; -extern struct eap_method eap_ttls;