Got rid of conn->actions

But there are now a lot of TODO XXX

FossilOrigin-Name: 48a574ca77230265480a3054d8f6009d6074a476dd0d39c8544f5fb972ecb615
This commit is contained in:
7u83@mail.ru 2018-02-26 17:28:12 +00:00
parent 33cc9e3af9
commit 6ebf54dbbd
23 changed files with 166 additions and 142 deletions

View File

@ -305,10 +305,10 @@ errX:
} }
// TODO XXXX
mavl_conststr_t db_get_update_tasks(struct conn * conn,const char * wtpid) mavl_conststr_t db_get_update_tasks(struct conn * conn,const char * wtpid)
{ {
/*
sqlite3_reset(get_tasks_stmt); sqlite3_reset(get_tasks_stmt);
sqlite3_clear_bindings(get_tasks_stmt); sqlite3_clear_bindings(get_tasks_stmt);
@ -385,14 +385,14 @@ errX:
return NULL; return NULL;
*/
} }
mavl_conststr_t db_get_radio_tasks(struct conn * conn,const char * wtpid) mavl_conststr_t db_get_radio_tasks(struct conn * conn,const char * wtpid)
{ {
/*
//cw_dbg(DBG_X,"Get Radio Tasks for %s",wtpid); //cw_dbg(DBG_X,"Get Radio Tasks for %s",wtpid);
sqlite3_reset(stmt_get_radio_tasks); sqlite3_reset(stmt_get_radio_tasks);
@ -479,7 +479,7 @@ errX:
return NULL; return NULL;
*/
} }

View File

@ -91,7 +91,7 @@ static void wtpman_run_discovery(void *arg)
extern cw_actionlist_in_t the_tree; extern cw_actionlist_in_t the_tree;
wtpman->conn->capwap_state = CAPWAP_STATE_DISCOVERY; wtpman->conn->capwap_state = CAPWAP_STATE_DISCOVERY;
wtpman->conn->actions = &capwap_actions; // wtpman->conn->actions = &capwap_actions;
wtpman->conn->outgoing = mbag_create(); wtpman->conn->outgoing = mbag_create();
wtpman->conn->incomming = mbag_create(); wtpman->conn->incomming = mbag_create();
@ -276,8 +276,12 @@ static void wtpman_image_data(struct wtpman *wtpman)
} }
// TODO XXXX
void props_to_sql(struct conn *conn, mbag_t mb, const char *mid) void props_to_sql(struct conn *conn, mbag_t mb, const char *mid)
{ {
/*
// XXX for the now we use just the IP adress as ID // XXX for the now we use just the IP adress as ID
char *wtp_id = sock_addr2str(&conn->addr); char *wtp_id = sock_addr2str(&conn->addr);
@ -327,6 +331,7 @@ void props_to_sql(struct conn *conn, mbag_t mb, const char *mid)
} }
} }
*/
} }
@ -334,6 +339,8 @@ void props_to_sql(struct conn *conn, mbag_t mb, const char *mid)
void config_to_sql(struct conn *conn) void config_to_sql(struct conn *conn)
{ {
/*
// XXX for the moment we use just the IP adress as ID // XXX for the moment we use just the IP adress as ID
char *wtp_id = sock_addr2str(&conn->addr); char *wtp_id = sock_addr2str(&conn->addr);
@ -370,10 +377,13 @@ void config_to_sql(struct conn *conn)
} }
} }
*/
} }
void radio_to_sql(struct conn *conn, char *wtp_id, int rid, mbag_t radio) void radio_to_sql(struct conn *conn, char *wtp_id, int rid, mbag_t radio)
{ {
/*
MAVLITER_DEFINE(it, radio); MAVLITER_DEFINE(it, radio);
mavliter_foreach(&it) { mavliter_foreach(&it) {
mbag_item_t *i = mavliter_get(&it); mbag_item_t *i = mavliter_get(&it);
@ -408,7 +418,7 @@ void radio_to_sql(struct conn *conn, char *wtp_id, int rid, mbag_t radio)
// int rid = ((struct mbag_item*)mavliter_get(&it))->iid; // int rid = ((struct mbag_item*)mavliter_get(&it))->iid;
*/
} }

View File

@ -328,7 +328,7 @@ OBJS:=$(patsubst %.o,$(OBJDIR)/%.o,$(OBJS))
all: $(SNAME) $(DNAME) all: $(SNAME) $(DNAME)
CFLAGS = -W -fPIC -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 += $(GNUTLS_CFLAGS) \ CFLAGS += $(GNUTLS_CFLAGS) \
-DWITH_CW_LOG \ -DWITH_CW_LOG \

View File

@ -96,7 +96,9 @@ struct conn {
/** Actionsdefs - this defines the possible actions for /** Actionsdefs - this defines the possible actions for
this conn object, so in the end this is the specification this conn object, so in the end this is the specification
of the protocoll */ of the protocoll */
struct cw_actiondef *actions; // struct cw_actiondef *actions;
struct cw_MsgSet * msgset;
/** Current CAPWAP state */ /** Current CAPWAP state */

View File

@ -151,7 +151,7 @@ static int check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data,
if (!a->max_len) if (!a->max_len)
return 1; return 1;
if (len < a->min_len) { /* if (len < a->min_len) {
cw_dbg(DBG_ELEM_ERR, cw_dbg(DBG_ELEM_ERR,
"%d (%s) message element too short, len=%d, min len=%d", "%d (%s) message element too short, len=%d, min len=%d",
a->elem_id, cw_strelemp(conn->actions, a->elem_id), len, a->elem_id, cw_strelemp(conn->actions, a->elem_id), len,
@ -164,37 +164,17 @@ static int check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data,
cw_strelemp(conn->actions, a->elem_id), len, a->max_len); cw_strelemp(conn->actions, a->elem_id), len, a->max_len);
return 0; return 0;
} }
*/
return 1; return 1;
} }
static struct cw_Mod *detect_mod(struct conn *conn, uint8_t * rawmsg, int len,
int elems_len, struct sockaddr *from, int mode)
{
cw_mod_detect(conn,rawmsg,len,elems_len,from,mode);
return MOD_NULL;
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;
}
static struct cw_actiondef *load_mods(struct conn *conn, uint8_t * rawmsg, int len, static struct cw_MsgSet *load_msg_set(struct conn *conn, uint8_t * rawmsg, int len,
int elems_len, struct sockaddr *from) int elems_len, struct sockaddr *from)
{ {
struct cw_Mod *cmod = struct cw_Mod *cmod =
detect_mod(conn, rawmsg, len, elems_len, from, CW_MOD_MODE_CAPWAP); cw_mod_detect(conn, rawmsg, len, elems_len, from, CW_MOD_MODE_CAPWAP);
if (cmod == MOD_NULL) { if (cmod == MOD_NULL) {
cw_dbg(DBG_MSG_ERR, 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",
@ -203,43 +183,15 @@ static struct cw_actiondef *load_mods(struct conn *conn, uint8_t * rawmsg, int l
} }
struct cw_Mod *bmod = struct cw_Mod *bmod =
detect_mod(conn, rawmsg, len, elems_len, from, MOD_MODE_BINDINGS); cw_mod_detect(conn, rawmsg, len, elems_len, from, MOD_MODE_BINDINGS);
cw_dbg(DBG_INFO, "Mods deteced: %s,%s", cmod->name, bmod->name); cw_dbg(DBG_INFO, "Mods deteced: %s,%s", cmod->name, bmod->name);
struct cw_actiondef *ad = mod_cache_add(conn,cmod, bmod); // struct cw_actiondef *ad = mod_cache_add(conn,cmod, bmod);
return ad; struct cw_MsgSet * set = cw_mod_get_msg_set(conn,cmod,bmod);
return set;
/*
if (bindins_mod) {
cw_dbg(DBG_INFO, "Using mod '%s' to handle CAWPAP for %s", mod->name,
sock_addr2str_p(from));
conn->detected=1;
}
else{
// errno = EAGAIN;
// return -1;
}
mod = detect_mod(conn, rawmsg, len, elems_len, from, MOD_DETECT_BINDINGS);
if (mod) {
cw_dbg(DBG_INFO, "Using bindings '%s' to handle %s", mod->name,
sock_addr2str_p(from));
conn->detected=1;
}
else{
cw_dbg(DBG_MSG_ERR, "Can't detect bindings ... for %s",
sock_addr2str_p(from));
}
return 0;
*/
} }
int cw_in_check_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int cw_in_check_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data,
@ -296,23 +248,22 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
} }
} }
if (!conn->detected) { if (!conn->detected) {
//struct mod_ac *mod; //struct mod_ac *mod;
struct cw_actiondef *ad = load_mods(conn, rawmsg, len, elems_len, from); struct cw_MsgSet *set = load_msg_set(conn, rawmsg, len, elems_len, from);
if (!ad) { if (!set) {
//cw_log(LOG_ERR, "Error"); //cw_log(LOG_ERR, "Error");
errno = EAGAIN; errno = EAGAIN;
return -1; return -1;
} }
conn->actions = ad;
conn->msgset= set;
// conn->actions = ad;
conn->detected = 1; conn->detected = 1;
} }
/* prepare struct for search operation */ /* prepare struct for search operation */
as.capwap_state = conn->capwap_state; as.capwap_state = conn->capwap_state;
as.msg_id = cw_get_msg_id(msg_ptr); as.msg_id = cw_get_msg_id(msg_ptr);
@ -322,7 +273,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
/* Search for state/message combination */ /* Search for state/message combination */
afm = cw_actionlist_in_get(conn->actions->in, &as); // afm = cw_actionlist_in_get(conn->actions->in, &as);
if (!afm) { if (!afm) {
/* Throw away unexpected response messages */ /* Throw away unexpected response messages */
@ -337,7 +288,9 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
/* Request message not found in current state, check if we know /* Request message not found in current state, check if we know
anything else about this message type */ anything else about this message type */
const char *str = cw_strheap_get(conn->actions->strmsg, as.msg_id); // TODO XXXX
//const char *str = cw_strheap_get(conn->actions->strmsg, as.msg_id);
const char *str = 0;
int result_code = 0; int result_code = 0;
if (str) { if (str) {
/* Message found, but it was in wrong state */ /* Message found, but it was in wrong state */
@ -382,15 +335,18 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
as.elem_id = cw_get_elem_id(elem); as.elem_id = cw_get_elem_id(elem);
int elem_len = cw_get_elem_len(elem); int elem_len = cw_get_elem_len(elem);
// TODO XXX
af = cw_actionlist_in_get(conn->actions->in, &as); // af = cw_actionlist_in_get(conn->actions->in, &as);
af = 0;
if (!af) { if (!af) {
unrecognized++; unrecognized++;
cw_dbg(DBG_ELEM_ERR, // TOOO XXXX
/* cw_dbg(DBG_ELEM_ERR,
"Element %d (%s) not allowed in msg of type %d (%s), ignoring.", "Element %d (%s) not allowed in msg of type %d (%s), ignoring.",
as.elem_id, cw_strelemp(conn->actions, as.elem_id), as.elem_id, cw_strelemp(conn->actions, as.elem_id),
as.msg_id, cw_strmsg(as.msg_id)); as.msg_id, cw_strmsg(as.msg_id));
/* *
continue; continue;
} }
@ -416,7 +372,8 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
} }
if(conn->elem_end){ if(conn->elem_end){
afrc = conn->elem_end(conn,af,afrc,cw_get_elem_data(elem), elem_len,from); // TODO XXXX
// afrc = conn->elem_end(conn,af,afrc,cw_get_elem_data(elem), elem_len,from);
} }
} }

View File

@ -4,6 +4,7 @@
#include "conn.h" #include "conn.h"
#include "mavl.h" #include "mavl.h"
#include "pthread.h"
struct connlist { struct connlist {
/* struct conn ** connlist; */ /* struct conn ** connlist; */

View File

@ -124,6 +124,7 @@ struct cw_MsgSet {
mavl_t messages; mavl_t messages;
mavl_t all_elems; mavl_t all_elems;
}; };
typedef struct cw_MsgSet cw_MsgSet_t; typedef struct cw_MsgSet cw_MsgSet_t;
typedef struct{ typedef struct{

View File

@ -13,7 +13,8 @@ int cw_check_missing_mand(cw_action_in_t ** out, struct conn * conn, cw_action_i
as.vendor_id = 0; as.vendor_id = 0;
as.elem_id = 0; as.elem_id = 0;
as.proto=0; as.proto=0;
/// TODO XXXX
/*
DEFINE_AVLITER(it,conn->actions->in); DEFINE_AVLITER(it,conn->actions->in);
int n=0; int n=0;
avliter_foreach_from(&it,&as) { avliter_foreach_from(&it,&as) {
@ -30,7 +31,8 @@ int cw_check_missing_mand(cw_action_in_t ** out, struct conn * conn, cw_action_i
} }
} }
return n; return n;
*/
} }

View File

@ -5,10 +5,11 @@
#include "mbag.h" #include "mbag.h"
#include "cw.h" #include "cw.h"
/// TODO XXXX
int static check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, int static check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from) struct sockaddr *from)
{ {
/*
if (len < a->min_len) { if (len < a->min_len) {
cw_dbg(DBG_ELEM_ERR, cw_dbg(DBG_ELEM_ERR,
"%d (%s) message element too short, len=%d, min len=%d", "%d (%s) message element too short, len=%d, min len=%d",
@ -22,7 +23,7 @@ int static check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data,
cw_strelemp(conn->actions, a->elem_id), len, a->max_len); cw_strelemp(conn->actions, a->elem_id), len, a->max_len);
return 0; return 0;
} }
*/
return 1; return 1;
} }

View File

@ -98,7 +98,10 @@ int static do_save(mbag_t itemstore, struct conn *conn, struct cw_action_in *a,
int cw_in_generic2(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, int cw_in_generic2(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from) struct sockaddr *from)
{ {
const cw_itemdef_t * idef = cw_itemdef_get(conn->actions->items,a->item_id,CW_ITEM_NONE); /// TODO XXXX
// const cw_itemdef_t * idef = cw_itemdef_get(conn->actions->items,a->item_id,CW_ITEM_NONE);
const cw_itemdef_t * idef=0;
if (!idef) { if (!idef) {
cw_log(LOG_ERR,"No itemdef found for %s",a->item_id); cw_log(LOG_ERR,"No itemdef found for %s",a->item_id);

View File

@ -14,8 +14,10 @@
int cw_in_radio_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int cw_in_radio_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len, struct sockaddr *from) int len, struct sockaddr *from)
{ {
// TODO XXXX
const cw_itemdef_t * idef = cw_itemdef_get(conn->actions->radioitems,a->item_id,CW_ITEM_NONE); // const cw_itemdef_t * idef = cw_itemdef_get(conn->actions->radioitems,a->item_id,CW_ITEM_NONE);
const cw_itemdef_t * idef = 0;
if (!idef){ if (!idef){
cw_log(LOG_ERR,"No definition found for %s",a->item_id); cw_log(LOG_ERR,"No definition found for %s",a->item_id);
return 0; return 0;

View File

@ -22,9 +22,10 @@ int cw_in_vendor_specific_payload(struct conn *conn, struct cw_action_in *a,
as.vendor_id = cw_get_dword(data); as.vendor_id = cw_get_dword(data);
as.elem_id = cw_get_word(data + 4); as.elem_id = cw_get_word(data + 4);
// TODO XXXX
af = cw_actionlist_in_get(conn->actions->in, &as); // af = cw_actionlist_in_get(conn->actions->in, &as);
af = 0;
if (!af) { if (!af) {
cw_dbg(DBG_WARN, cw_dbg(DBG_WARN,
"Can't handle Vendor Specific Payload %s/%d, in msg %d (%s) in %s state.", "Can't handle Vendor Specific Payload %s/%d, in msg %d (%s) in %s state.",
@ -44,4 +45,5 @@ int cw_in_vendor_specific_payload(struct conn *conn, struct cw_action_in *a,
} }
return 1; return 1;
} }

View File

@ -29,20 +29,20 @@ int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
vendor=cw_strvendor(a->vendor_id); vendor=cw_strvendor(a->vendor_id);
} }
if (a->mand) { if (a->mand) {
cw_log(LOG_ERR, /* cw_log(LOG_ERR,
"Can't put mandatory element %s %d - (%s) into %s. No value for '%s' found.", "Can't put mandatory element %s %d - (%s) into %s. No value for '%s' found.",
vendor, vendor,
a->elem_id, cw_strelemp(conn->actions, a->elem_id) a->elem_id, cw_strelemp(conn->actions, a->elem_id)
, cw_strmsg(a->msg_id) , cw_strmsg(a->msg_id)
, a->item_id , a->item_id
); );
} */ }
else{ else{
cw_dbg(DBG_WARN,"No output for element %s%d -(%s) in %s. Item %s not found.", /* cw_dbg(DBG_WARN,"No output for element %s%d -(%s) in %s. Item %s not found.",
vendor, vendor,
a->elem_id, cw_strelemp(conn->actions, a->elem_id) a->elem_id, cw_strelemp(conn->actions, a->elem_id)
, cw_strmsg(a->msg_id),a->item_id); , cw_strmsg(a->msg_id),a->item_id);
*/
} }
return 0; return 0;
} else { } else {

View File

@ -53,7 +53,9 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
uint8_t *dst = msgptr+8; uint8_t *dst = msgptr+8;
mlist_t m = cw_actionlist_out_get(conn->actions->out,cw_get_msg_type(msgptr)); /// TODO XXXX
//mlist_t m = cw_actionlist_out_get(conn->actions->out,cw_get_msg_type(msgptr));
mlist_t m =0;
if (!m){ if (!m){
cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.", cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.",
@ -152,8 +154,9 @@ int cw_put_custom_msg(struct conn *conn, uint8_t * rawout, mavl_conststr_t elems
uint8_t *dst = msgptr+8; uint8_t *dst = msgptr+8;
DEFINE_AVLITER(i,conn->actions->out); /// TODO XXXX
// DEFINE_AVLITER(i,conn->actions->out);
DEFINE_AVLITER(i,0);
cw_action_out_t *am; cw_action_out_t *am;
if (! (am=avliter_seek(&i,&as))){ if (! (am=avliter_seek(&i,&as))){

View File

@ -196,10 +196,12 @@ void cw_dbg_missing_mand(int level, struct conn *conn, cw_action_in_t ** ml, int
char *p = buffer; char *p = buffer;
int i; int i;
char *delim = ""; char *delim = "";
// TODO XXXX
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
p += sprintf(p, "%s", delim); /* p += sprintf(p, "%s", delim);
delim = ", "; delim = ", ";
p += sprintf(p, "%s", cw_strelemp(conn->actions, ml[i]->elem_id)); p += sprintf(p, "%s", cw_strelemp(conn->actions, ml[i]->elem_id));
*/
} }
cw_dbg(level, "Missing mandatory elements: [%s]", buffer); cw_dbg(level, "Missing mandatory elements: [%s]", buffer);
} }
@ -548,18 +550,21 @@ void cw_dbg_elem_colored(int level, struct conn *conn, int msg, int msgelem,
char vendorname[256]; char vendorname[256];
char vendor_details[265]; char vendor_details[265];
*vendor_details = 0; *vendor_details = 0;
/// TODO XXXX
if (msgelem == CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD) { if (msgelem == CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
uint32_t vendor_id = ntohl(*((uint32_t *) msgbuf)); uint32_t vendor_id = ntohl(*((uint32_t *) msgbuf));
int type = ntohs(*((uint16_t *) (msgbuf + 4))); int type = ntohs(*((uint16_t *) (msgbuf + 4)));
cw_format_vendor(vendor_details, vendor_id, type, msgbuf); cw_format_vendor(vendor_details, vendor_id, type, msgbuf);
sprintf(vendorname, "%s/%s/%s", /* sprintf(vendorname, "%s/%s/%s",
cw_strelemp(conn->actions, msgelem), cw_strelemp(conn->actions, msgelem),
(char *) cw_strvendor(vendor_id), vendor_details); (char *) cw_strvendor(vendor_id), vendor_details);
*/
elemname = vendorname; elemname = vendorname;
} else { } else {
elemname = cw_strelemp(conn->actions, msgelem); // elemname = cw_strelemp(conn->actions, msgelem);
elemname=0;
} }

View File

@ -31,6 +31,7 @@
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
#include <unistd.h>
#ifndef FRAG_MAXSIZE #ifndef FRAG_MAXSIZE
/** maximaum size of a fragment */ /** maximaum size of a fragment */

View File

@ -23,8 +23,10 @@ int lw_in_vendor_specific(struct conn *conn, struct cw_action_in *a,
as.elem_id = cw_get_word(data + 4); as.elem_id = cw_get_word(data + 4);
as.proto = CW_ACTION_PROTO_LWAPP; as.proto = CW_ACTION_PROTO_LWAPP;
// TODO XXXX
af = cw_actionlist_in_get(conn->actions->in, &as); //af = cw_actionlist_in_get(conn->actions->in, &as);
af = 0;
if (!af) { if (!af) {
cw_dbg(DBG_WARN, cw_dbg(DBG_WARN,

View File

@ -26,11 +26,13 @@
#include <dlfcn.h> #include <dlfcn.h>
#include "action.h" //#include "action.h"
#include "mavl.h" #include "mavl.h"
#include "dbg.h" #include "dbg.h"
#include "log.h" #include "log.h"
#include "file.h" #include "file.h"
#include "cw.h"
#include "cw/message_set.h"
static void (*actions_registered_cb) (struct cw_Mod * capwap, struct cw_Mod * bindings, static void (*actions_registered_cb) (struct cw_Mod * capwap, struct cw_Mod * bindings,
struct cw_actiondef * actions) = NULL; struct cw_actiondef * actions) = NULL;
@ -50,11 +52,9 @@ void mod_set_actions_registered_cb(void (*fun)
struct cache_item { struct cache_item {
const char *capwap; const char *capwap;
const char *bindings; const char *bindings;
struct cw_actiondef actions;
struct cw_MsgSet * msgset; struct cw_MsgSet * msgset;
}; };
static struct mavl *msgset_cache = NULL;
static struct mavl *cache = NULL;
static int mod_null_register_actions(struct cw_actiondef *def, int mode) static int mod_null_register_actions(struct cw_actiondef *def, int mode)
{ {
@ -92,51 +92,66 @@ struct cw_actiondef *mod_cache_get(const char *capwap, const char *bindings)
} }
struct cw_actiondef *mod_cache_add(struct conn *conn, struct cw_Mod *c, struct cw_Mod *b) struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
struct cw_Mod * capwap_mod, struct cw_Mod *bindings_mod)
{ {
if (!cache) { if (!msgset_cache) {
cache = mavl_create(cmp, NULL); msgset_cache = mavl_create(cmp, NULL);
if (!cache) { if (!msgset_cache) {
cw_log(LOG_ERR, "Can't initialize mod cache: %s", cw_log(LOG_ERR, "Can't initialize msgset cache: %s",
strerror(errno)); strerror(errno));
return NULL; return NULL;
} }
} }
struct cache_item s; struct cache_item search;
s.capwap = c->name; search.capwap = capwap_mod->name;
s.bindings = b->name; search.bindings = bindings_mod->name;
struct cache_item *i = mavl_get(cache, &s); struct cache_item * cached_set = mavl_get(msgset_cache, &search);
if (i) { if (cached_set) {
cw_dbg(DBG_INFO, "Using cached actions for %s,%s", c->name, b->name); cw_dbg(DBG_INFO, "Using cached message set for %s,%s", capwap_mod->name, bindings_mod->name);
return &(i->actions); return cached_set->msgset;
} }
i = malloc(sizeof(struct cache_item)); cached_set = malloc(sizeof(struct cache_item));
if (!i) { if (!cached_set) {
cw_log(LOG_ERR, "Can't allocate memory for mod cache item %s", cw_log(LOG_ERR, "Can't allocate memory for mod cache item %s",
strerror(errno)); strerror(errno));
return NULL; return NULL;
} }
memset(cached_set, 0, sizeof(struct cache_item));
cw_dbg(DBG_INFO, "Loading actions for %s,%s", c->name, b->name);
memset(i, 0, sizeof(struct cache_item)); struct cw_MsgSet * set = cw_message_set_create();
if (c) { if (!set) {
i->capwap = c->name; free(cached_set);
c->register_actions(&(i->actions), CW_MOD_MODE_CAPWAP); cw_log(LOG_ERR, "Can't allocate memory for mod cache item %s",
strerror(errno));
return NULL;
} }
if (b) { cached_set->msgset=set;
i->bindings = b->name;
b->register_actions(&(i->actions), MOD_MODE_BINDINGS);
cw_dbg(DBG_INFO, "Loading message set for %s,%s", capwap_mod->name, bindings_mod->name);
if (capwap_mod) {
cached_set->capwap = capwap_mod->name;
//c->register_actions(&(i->actions), CW_MOD_MODE_CAPWAP);
capwap_mod->register_messages(cached_set->msgset,CW_MOD_MODE_CAPWAP);
}
if (bindings_mod) {
cached_set->bindings = bindings_mod->name;
//b->register_actions(&(i->actions), MOD_MODE_BINDINGS);
} }
if (actions_registered_cb) // if (actions_registered_cb)
actions_registered_cb(c, b, &(i->actions)); // actions_registered_cb(capwap_mod, bindings_mod, &(cached_set->actions));
mavl_add(cache, i); mavl_add(msgset_cache, cached_set);
return &(i->actions); return cached_set->msgset;
} }
@ -246,13 +261,10 @@ struct cw_Mod * cw_mod_add_to_list(struct cw_Mod * mod ){
return mlist_append(mods_list,mod)->data; return mlist_append(mods_list,mod)->data;
} }
struct cw_Mod * cw_mod_detect(struct conn *conn, struct cw_Mod * cw_mod_detect(struct conn *conn,
uint8_t * rawmsg, int len, uint8_t * rawmsg, int len,
int elems_len, struct sockaddr *from, int elems_len, struct sockaddr *from,
int mode){ int mode){
cw_dbg(DBG_MOD, "Try to detect");
if (mods_list==NULL) if (mods_list==NULL)
return MOD_NULL; return MOD_NULL;
@ -260,5 +272,14 @@ struct cw_Mod * cw_mod_detect(struct conn *conn,
mlist_foreach(e,mods_list){ mlist_foreach(e,mods_list){
struct cw_Mod * mod = e->data; struct cw_Mod * mod = e->data;
cw_dbg(DBG_MOD,"Checking mod: %s",mod->name); cw_dbg(DBG_MOD,"Checking mod: %s",mod->name);
/* if there is no detect method, skip */
if (!mod->detect)
continue;
if ( mod->detect(conn,rawmsg,len,elems_len,from,mode) ){
return mod;
}
} }
return MOD_NULL;
} }

View File

@ -63,7 +63,7 @@ struct cw_Mod {
/** Register actions */ /** Register actions */
int (*register_actions) (struct cw_actiondef * def,int mode); int (*register_actions) (struct cw_actiondef * def,int mode);
struct cw_MsgSet * (*register_messages)(struct cw_MsgSet set, int mode); struct cw_MsgSet * (*register_messages)(struct cw_MsgSet * set, int mode);
/** /**
* Handle returned by dlopen, if this module was loaded * Handle returned by dlopen, if this module was loaded

View File

@ -123,13 +123,22 @@ static cw_msgdef_t messages[] = {
{&_AC_DESCRIPTOR,1}, {&_AC_DESCRIPTOR,1},
{0,0}, {0,0},
} }
} },
{0,0,0,0}
}; };
int capwap_register_msg_set(struct cw_MsgSet * set){ struct cw_MsgSet * capwap_register_msg_set(struct cw_MsgSet * set, int mode){
printf("Register Message set %p\n",set);
if (mode != CW_MOD_MODE_CAPWAP)
return NULL;
cw_msgset_add(set,messages);
printf("Done Addin gmessages");
exit(0);
} }
void test_sets(){ void test_sets(){

View File

@ -28,5 +28,8 @@ extern struct mbag_item * capwap_out_get_capwap_timers(struct conn *conn,struct
extern int capwap_out_ac_ip_list(struct conn *conn, struct cw_action_out *a, uint8_t * dst); extern int capwap_out_ac_ip_list(struct conn *conn, struct cw_action_out *a, uint8_t * dst);
struct cw_MsgSet * capwap_register_msg_set(struct cw_MsgSet * set, int mode);
#endif #endif

View File

@ -18,8 +18,6 @@ extern int capwap_register_actions_ac(struct cw_actiondef *def);
static int init() static int init()
{ {
cw_dbg(DBG_MOD, "Initialiazing mod_capwap."); cw_dbg(DBG_MOD, "Initialiazing mod_capwap.");
// int rc = capwap_register_actions_ac(&actions);
// cw_dbg(DBG_INFO, "Initialized mod capwap with %d actions", rc);
return 0; return 0;
} }
@ -46,7 +44,8 @@ static struct cw_Mod capwap_ac = {
.name = "capwap", .name = "capwap",
.init = init, .init = init,
.detect = detect, .detect = detect,
.register_actions = register_actions .register_actions = register_actions,
.register_messages = capwap_register_msg_set
}; };
struct cw_Mod *mod_capwap_ac() struct cw_Mod *mod_capwap_ac()

View File

@ -30,7 +30,7 @@ static int detect(struct conn *conn, const uint8_t * rawmsg, int rawlen, int ele
if (mode != CW_MOD_MODE_CAPWAP) if (mode != CW_MOD_MODE_CAPWAP)
return 0; return 0;
conn->detected = 1; conn->detected = 1;
conn->actions = &actions; //conn->actions = &actions;
return 1; return 1;
} }