rename mod_wtp and mod_ac to cw_Mod
FossilOrigin-Name: 4a8f9578a5fc384f0dad291114ac9470ea8561817e87760946277ec9ddd0db79
This commit is contained in:
@ -333,7 +333,7 @@ OBJS:=$(patsubst %.o,$(ARCH)/%.o,$(OBJS))
|
||||
|
||||
|
||||
|
||||
CFLAGS = -Wall -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include -I../
|
||||
CFLAGS = -Wall -fPIC -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include -I../
|
||||
#CFLAGS = -Wall -Os -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I/usr/local/include
|
||||
|
||||
CFLAGS += $(GNUTLS_CFLAGS) \
|
||||
|
@ -168,23 +168,21 @@ static int check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct mod_ac *detect_mod(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
static struct cw_Mod *detect_mod(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
int elems_len, struct sockaddr *from, int mode)
|
||||
{
|
||||
if (conn->mods) {
|
||||
struct mod_ac **mods = (struct mod_ac **) conn->mods;
|
||||
int i;
|
||||
for (i = 0; mods[i]; i++) {
|
||||
if (mods[i]->detect) {
|
||||
if (mods[i]->detect
|
||||
(conn, rawmsg, len, elems_len, from, mode)) {
|
||||
return mods[i];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!conn->mods)
|
||||
return MOD_NULL;
|
||||
|
||||
struct cw_Mod **mods = (struct cw_Mod **) conn->mods;
|
||||
int i;
|
||||
for (i = 0; mods[i]; i++) {
|
||||
if (!mods[i]->detect)
|
||||
continue;
|
||||
if (mods[i]->detect (conn, rawmsg, len, elems_len, from, mode))
|
||||
return mods[i];
|
||||
}
|
||||
|
||||
|
||||
return MOD_NULL;
|
||||
}
|
||||
|
||||
@ -192,16 +190,16 @@ static struct cw_actiondef *load_mods(struct conn *conn, uint8_t * rawmsg, int l
|
||||
int elems_len, struct sockaddr *from)
|
||||
{
|
||||
|
||||
struct mod_ac *cmod =
|
||||
struct cw_Mod *cmod =
|
||||
detect_mod(conn, rawmsg, len, elems_len, from, MOD_MODE_CAPWAP);
|
||||
if (cmod == MOD_NULL) {
|
||||
cw_dbg(DBG_MSG_ERR,
|
||||
"Can't find mod to handle connection from %s , discarding message",
|
||||
"Can't find mod to handle connection from %s, discarding message",
|
||||
sock_addr2str_p(from));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mod_ac *bmod =
|
||||
struct cw_Mod *bmod =
|
||||
detect_mod(conn, rawmsg, len, elems_len, from, MOD_MODE_BINDINGS);
|
||||
|
||||
cw_dbg(DBG_INFO, "Mods deteced: %s,%s", cmod->name, bmod->name);
|
||||
|
@ -120,10 +120,11 @@ typedef struct {
|
||||
|
||||
}cw_elem_handler_t;
|
||||
|
||||
typedef struct {
|
||||
struct cw_MsgSet {
|
||||
mavl_t messages;
|
||||
mavl_t all_elems;
|
||||
}cw_message_set_t;
|
||||
};
|
||||
typedef struct cw_MsgSet cw_MsgSet_t;
|
||||
|
||||
typedef struct{
|
||||
cw_elem_handler_t * elem;
|
||||
|
@ -7,15 +7,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
struct mod_ac *(*mods_ac[])() = MODS_AC;
|
||||
struct cw_Mod *(*mods_ac[])() = MODS_AC;
|
||||
|
||||
|
||||
struct mod_ac * cw_get_mod_ac(const char *name)
|
||||
struct cw_Mod * cw_get_mod_ac(const char *name)
|
||||
{
|
||||
int i;
|
||||
for (i=0; mods_ac[i];i++){
|
||||
|
||||
struct mod_ac * m = mods_ac[i]();
|
||||
struct cw_Mod * m = mods_ac[i]();
|
||||
if (strcmp(m->name,name)==0)
|
||||
return m;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ static inline int msg_cmp(const void *elem1, const void *elem2)
|
||||
}
|
||||
|
||||
|
||||
void cw_message_set_destroy(cw_message_set_t * set){
|
||||
void cw_message_set_destroy(cw_MsgSet_t * set){
|
||||
if (set->messages){
|
||||
mavl_destroy(set->messages);
|
||||
}
|
||||
@ -49,14 +49,14 @@ void cw_message_set_destroy(cw_message_set_t * set){
|
||||
free(set);
|
||||
}
|
||||
|
||||
cw_message_set_t * cw_message_set_create(){
|
||||
cw_MsgSet_t * cw_message_set_create(){
|
||||
|
||||
/* allocate memory for a message_set */
|
||||
cw_message_set_t * set = malloc(sizeof(cw_message_set_t));
|
||||
cw_MsgSet_t * set = malloc(sizeof(cw_MsgSet_t));
|
||||
if (set==NULL)
|
||||
return NULL;
|
||||
|
||||
memset(set,0,sizeof(cw_message_set_t));
|
||||
memset(set,0,sizeof(cw_MsgSet_t));
|
||||
|
||||
/* create mavl for all_elems */
|
||||
set->all_elems = mavl_create(cmp_cw_msgelemprops,NULL);
|
||||
@ -77,7 +77,7 @@ cw_message_set_t * cw_message_set_create(){
|
||||
}
|
||||
|
||||
|
||||
static void update_message(message2_t * msg, cw_msgdef_t * src, cw_message_set_t * set){
|
||||
static void update_message(message2_t * msg, cw_msgdef_t * src, cw_MsgSet_t * set){
|
||||
|
||||
cw_msgelemprops_t *md;
|
||||
|
||||
@ -95,7 +95,7 @@ static void update_message(message2_t * msg, cw_msgdef_t * src, cw_message_set_t
|
||||
|
||||
|
||||
|
||||
void cw_message_set_add(cw_message_set_t * set,
|
||||
void cw_msgset_add(cw_MsgSet_t * set,
|
||||
cw_msgdef_t messages[]){
|
||||
|
||||
cw_msgdef_t * m;
|
||||
@ -136,19 +136,17 @@ void cw_message_set_add(cw_message_set_t * set,
|
||||
next->states=m->states;
|
||||
|
||||
update_message(next,m, set);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cw_elem_handler_t * cw_message_set_find_element(
|
||||
cw_message_set_t * set,
|
||||
cw_MsgSet_t * set,
|
||||
cw_elem_handler_t * element){
|
||||
return mavl_find(set->all_elems,element);
|
||||
}
|
||||
|
||||
|
||||
mlist_t cw_msgset_get_msg(cw_message_set_t * set, int type){
|
||||
mlist_t cw_msgset_get_msg(cw_MsgSet_t * set, int type){
|
||||
message2_t search;
|
||||
search.type = type;
|
||||
message2_t * result = mavl_find(set->messages,&search);
|
||||
|
@ -3,9 +3,9 @@
|
||||
|
||||
#include "cw.h"
|
||||
|
||||
extern void cw_message_set_destroy(cw_message_set_t * set);
|
||||
extern cw_message_set_t * cw_message_set_create();
|
||||
extern void cw_message_set_add(cw_message_set_t * set,
|
||||
extern void cw_message_set_destroy(cw_MsgSet_t * set);
|
||||
extern cw_MsgSet_t * cw_message_set_create();
|
||||
extern void cw_msgset_add(cw_MsgSet_t * set,
|
||||
cw_msgdef_t messages[]);
|
||||
mlist_t cw_msgset_get_msg(cw_message_set_t * set, int type);
|
||||
mlist_t cw_msgset_get_msg(cw_MsgSet_t * set, int type);
|
||||
#endif
|
78
src/cw/mod.c
78
src/cw/mod.c
@ -18,11 +18,12 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Functions for mods
|
||||
* @brief Functions for modules (mods) management.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
|
||||
#include "action.h"
|
||||
@ -31,15 +32,16 @@
|
||||
#include "log.h"
|
||||
|
||||
|
||||
static void (*actions_registered_cb) (struct mod_ac * capwap, struct mod_ac * bindings,
|
||||
static void (*actions_registered_cb) (struct cw_Mod * capwap, struct cw_Mod * bindings,
|
||||
struct cw_actiondef * actions) = NULL;
|
||||
|
||||
|
||||
|
||||
int mod_caching = 1;
|
||||
|
||||
|
||||
void mod_set_actions_registered_cb(void (*fun)
|
||||
(struct mod_ac *, struct mod_ac *, struct cw_actiondef *))
|
||||
(struct cw_Mod *, struct cw_Mod *,
|
||||
struct cw_actiondef *))
|
||||
{
|
||||
actions_registered_cb = fun;
|
||||
}
|
||||
@ -49,7 +51,7 @@ struct cache_item {
|
||||
const char *capwap;
|
||||
const char *bindings;
|
||||
struct cw_actiondef actions;
|
||||
|
||||
struct cw_MsgSet * msgset;
|
||||
};
|
||||
|
||||
static struct mavl *cache = NULL;
|
||||
@ -62,9 +64,10 @@ static int mod_null_register_actions(struct cw_actiondef *def, int mode)
|
||||
/**
|
||||
* mod_null is a dummy mod
|
||||
*/
|
||||
struct mod_ac mod_null = {
|
||||
struct cw_Mod mod_null = {
|
||||
.name = "none",
|
||||
.register_actions = mod_null_register_actions
|
||||
.register_actions = mod_null_register_actions,
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -89,7 +92,7 @@ struct cw_actiondef *mod_cache_get(const char *capwap, const char *bindings)
|
||||
}
|
||||
|
||||
|
||||
struct cw_actiondef *mod_cache_add(struct conn *conn, struct mod_ac *c, struct mod_ac *b)
|
||||
struct cw_actiondef *mod_cache_add(struct conn *conn, struct cw_Mod *c, struct cw_Mod *b)
|
||||
{
|
||||
if (!cache) {
|
||||
cache = mavl_create(cmp, NULL);
|
||||
@ -130,8 +133,65 @@ struct cw_actiondef *mod_cache_add(struct conn *conn, struct mod_ac *c, struct m
|
||||
}
|
||||
|
||||
if (actions_registered_cb)
|
||||
actions_registered_cb(c,b,&(i->actions));
|
||||
actions_registered_cb(c, b, &(i->actions));
|
||||
|
||||
mavl_add(cache, i);
|
||||
return &(i->actions);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* static mavl to store modules */
|
||||
static struct mavl * modlist = NULL;
|
||||
static int mod_cmp(const void *e1, const void *e2){
|
||||
struct cw_Mod * (*m1fn)() = e1;
|
||||
struct cw_Mod * (*m2fn)() = e2;
|
||||
return strcmp(m1fn()->name,m2fn()->name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Load a module
|
||||
* @param name Name of the module
|
||||
* @return pointer to the module structure or NULL if the
|
||||
* module cannot be loaded.
|
||||
*/
|
||||
struct cw_Mod * cw_mod_get(const char *name)
|
||||
{
|
||||
|
||||
/*int i;
|
||||
for (i=0; modlist[i];i++){
|
||||
|
||||
struct cw_Mod * m = modlist[i]();
|
||||
if (strcmp(m->name,name)==0)
|
||||
return m;
|
||||
}
|
||||
return NULL;
|
||||
*/
|
||||
}
|
||||
|
||||
int cw_mod_add(struct cw_Mod * (*modfn)() ){
|
||||
if (modlist == NULL){
|
||||
modlist = mavl_create(mod_cmp,NULL);
|
||||
if (modlist==NULL){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
mavl_add(modlist,modfn);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int cw_mod_add_dynamic(const char * filename){
|
||||
void * handle;
|
||||
handle = dlopen(filename,RTLD_NOW);
|
||||
if (!handle){
|
||||
printf("Error: %s",dlerror());
|
||||
}
|
||||
|
||||
printf("Load DLL %p\n",handle);
|
||||
|
||||
void * ifu = dlsym(handle,"bstr_create");
|
||||
|
||||
printf("IFU DLL %p\n",ifu);
|
||||
}
|
31
src/cw/mod.h
31
src/cw/mod.h
@ -16,6 +16,11 @@
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief module definitions
|
||||
*/
|
||||
|
||||
#ifndef __MOD_H
|
||||
#define __MOD_H
|
||||
|
||||
@ -28,15 +33,14 @@
|
||||
|
||||
struct cw_actiondef;
|
||||
|
||||
#define MOD_MAXMODS 8
|
||||
|
||||
enum {
|
||||
MOD_MODE_CAPWAP,
|
||||
MOD_MODE_BINDINGS
|
||||
};
|
||||
|
||||
struct mod_ac {
|
||||
/** Name of the mod */
|
||||
struct cw_Mod {
|
||||
/** Name of the module */
|
||||
const char *name;
|
||||
/** Initializion method */
|
||||
int (*init) ();
|
||||
@ -45,8 +49,10 @@ struct mod_ac {
|
||||
int (*init_config) (mbag_t config);
|
||||
|
||||
/** Detect capwap
|
||||
This function is called after receiving and disassembling a complete
|
||||
CAPWAP message. Either on Discovery Request or Join Request
|
||||
* This function is called after receiving and disassembling a complete
|
||||
* CAPWAP message. Either on Discovery Request or Join Request.
|
||||
* @param conn current connection
|
||||
* @return 0 if notdetected
|
||||
**/
|
||||
int (*detect) (struct conn * conn, const uint8_t * rawmsg, int rawlen,
|
||||
int elems_len, struct sockaddr * from, int mode);
|
||||
@ -56,31 +62,28 @@ struct mod_ac {
|
||||
|
||||
/** Register actions */
|
||||
int (*register_actions) (struct cw_actiondef * def,int mode);
|
||||
|
||||
struct cw_MsgSet * (*register_messages)(struct cw_MsgSet set, int mode);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* We define here struct mod_wtp in case we need
|
||||
* different methods for WTP and AC later
|
||||
*/
|
||||
#define mod_wtp mod_ac
|
||||
|
||||
extern struct mod_ac mod_null;
|
||||
extern struct cw_Mod mod_null;
|
||||
|
||||
|
||||
#define MOD_NULL (&mod_null)
|
||||
|
||||
struct cw_actiondef * mod_cache_add(struct conn *conn,struct mod_ac *c, struct mod_ac *b);
|
||||
struct cw_actiondef * mod_cache_add(struct conn *conn,struct cw_Mod *c, struct cw_Mod *b);
|
||||
|
||||
|
||||
#define mod_init_config(mod,cfg) (mod->init_config ? mod->init_config(cfg):1)
|
||||
|
||||
void mod_set_actions_registered_cb(void (*fun) (struct mod_ac *, struct mod_ac *, struct cw_actiondef *));
|
||||
void mod_set_actions_registered_cb(void (*fun) (struct cw_Mod *, struct cw_Mod *, struct cw_actiondef *));
|
||||
|
||||
extern int mod_caching;
|
||||
|
||||
#define mod_set_caching(var) (mod_caching=var)
|
||||
#define mod_get_caching() (mod_caching)
|
||||
|
||||
extern int cw_mod_add_dynamic(const char * filename);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user