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)
{
/*
sqlite3_reset(get_tasks_stmt);
sqlite3_clear_bindings(get_tasks_stmt);
@ -385,14 +385,14 @@ errX:
return NULL;
*/
}
mavl_conststr_t db_get_radio_tasks(struct conn * conn,const char * wtpid)
{
/*
//cw_dbg(DBG_X,"Get Radio Tasks for %s",wtpid);
sqlite3_reset(stmt_get_radio_tasks);
@ -479,7 +479,7 @@ errX:
return NULL;
*/
}

View File

@ -91,7 +91,7 @@ static void wtpman_run_discovery(void *arg)
extern cw_actionlist_in_t the_tree;
wtpman->conn->capwap_state = CAPWAP_STATE_DISCOVERY;
wtpman->conn->actions = &capwap_actions;
// wtpman->conn->actions = &capwap_actions;
wtpman->conn->outgoing = 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)
{
/*
// XXX for the now we use just the IP adress as ID
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)
{
/*
// XXX for the moment we use just the IP adress as ID
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)
{
/*
MAVLITER_DEFINE(it, radio);
mavliter_foreach(&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;
*/
}

View File

@ -328,7 +328,7 @@ OBJS:=$(patsubst %.o,$(OBJDIR)/%.o,$(OBJS))
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) \
-DWITH_CW_LOG \

View File

@ -96,7 +96,9 @@ struct conn {
/** Actionsdefs - this defines the possible actions for
this conn object, so in the end this is the specification
of the protocoll */
struct cw_actiondef *actions;
// struct cw_actiondef *actions;
struct cw_MsgSet * msgset;
/** 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)
return 1;
if (len < a->min_len) {
/* if (len < a->min_len) {
cw_dbg(DBG_ELEM_ERR,
"%d (%s) message element too short, len=%d, min len=%d",
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);
return 0;
}
*/
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)
{
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) {
cw_dbg(DBG_MSG_ERR,
"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 =
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);
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);
/*
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;
*/
return set;
}
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) {
//struct mod_ac *mod;
struct cw_actiondef *ad = load_mods(conn, rawmsg, len, elems_len, from);
if (!ad) {
struct cw_MsgSet *set = load_msg_set(conn, rawmsg, len, elems_len, from);
if (!set) {
//cw_log(LOG_ERR, "Error");
errno = EAGAIN;
return -1;
}
conn->actions = ad;
conn->msgset= set;
// conn->actions = ad;
conn->detected = 1;
}
/* prepare struct for search operation */
as.capwap_state = conn->capwap_state;
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 */
afm = cw_actionlist_in_get(conn->actions->in, &as);
// afm = cw_actionlist_in_get(conn->actions->in, &as);
if (!afm) {
/* 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
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;
if (str) {
/* 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);
int elem_len = cw_get_elem_len(elem);
af = cw_actionlist_in_get(conn->actions->in, &as);
// TODO XXX
// af = cw_actionlist_in_get(conn->actions->in, &as);
af = 0;
if (!af) {
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.",
as.elem_id, cw_strelemp(conn->actions, as.elem_id),
as.msg_id, cw_strmsg(as.msg_id));
/* *
continue;
}
@ -416,7 +372,8 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
}
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 "mavl.h"
#include "pthread.h"
struct connlist {
/* struct conn ** connlist; */

View File

@ -124,6 +124,7 @@ struct cw_MsgSet {
mavl_t messages;
mavl_t all_elems;
};
typedef struct cw_MsgSet cw_MsgSet_t;
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.elem_id = 0;
as.proto=0;
/// TODO XXXX
/*
DEFINE_AVLITER(it,conn->actions->in);
int n=0;
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 "cw.h"
/// TODO XXXX
int static check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from)
{
/*
if (len < a->min_len) {
cw_dbg(DBG_ELEM_ERR,
"%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);
return 0;
}
*/
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,
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) {
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 len, struct sockaddr *from)
{
const cw_itemdef_t * idef = cw_itemdef_get(conn->actions->radioitems,a->item_id,CW_ITEM_NONE);
// TODO XXXX
// 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){
cw_log(LOG_ERR,"No definition found for %s",a->item_id);
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.elem_id = cw_get_word(data + 4);
af = cw_actionlist_in_get(conn->actions->in, &as);
// TODO XXXX
// af = cw_actionlist_in_get(conn->actions->in, &as);
af = 0;
if (!af) {
cw_dbg(DBG_WARN,
"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;
}

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);
}
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.",
vendor,
a->elem_id, cw_strelemp(conn->actions, a->elem_id)
, cw_strmsg(a->msg_id)
, a->item_id
);
}
*/ }
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,
a->elem_id, cw_strelemp(conn->actions, a->elem_id)
, cw_strmsg(a->msg_id),a->item_id);
*/
}
return 0;
} else {

View File

@ -53,7 +53,9 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
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){
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;
DEFINE_AVLITER(i,conn->actions->out);
/// TODO XXXX
// DEFINE_AVLITER(i,conn->actions->out);
DEFINE_AVLITER(i,0);
cw_action_out_t *am;
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;
int i;
char *delim = "";
// TODO XXXX
for (i = 0; i < n; i++) {
p += sprintf(p, "%s", delim);
/* p += sprintf(p, "%s", delim);
delim = ", ";
p += sprintf(p, "%s", cw_strelemp(conn->actions, ml[i]->elem_id));
*/
}
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 vendor_details[265];
*vendor_details = 0;
/// TODO XXXX
if (msgelem == CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
uint32_t vendor_id = ntohl(*((uint32_t *) msgbuf));
int type = ntohs(*((uint16_t *) (msgbuf + 4)));
cw_format_vendor(vendor_details, vendor_id, type, msgbuf);
sprintf(vendorname, "%s/%s/%s",
/* sprintf(vendorname, "%s/%s/%s",
cw_strelemp(conn->actions, msgelem),
(char *) cw_strvendor(vendor_id), vendor_details);
*/
elemname = vendorname;
} 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 <time.h>
#include <unistd.h>
#ifndef FRAG_MAXSIZE
/** 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.proto = CW_ACTION_PROTO_LWAPP;
af = cw_actionlist_in_get(conn->actions->in, &as);
// TODO XXXX
//af = cw_actionlist_in_get(conn->actions->in, &as);
af = 0;
if (!af) {
cw_dbg(DBG_WARN,

View File

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

View File

@ -123,13 +123,22 @@ static cw_msgdef_t messages[] = {
{&_AC_DESCRIPTOR,1},
{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(){

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);
struct cw_MsgSet * capwap_register_msg_set(struct cw_MsgSet * set, int mode);
#endif

View File

@ -18,8 +18,6 @@ extern int capwap_register_actions_ac(struct cw_actiondef *def);
static int init()
{
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;
}
@ -46,7 +44,8 @@ static struct cw_Mod capwap_ac = {
.name = "capwap",
.init = init,
.detect = detect,
.register_actions = register_actions
.register_actions = register_actions,
.register_messages = capwap_register_msg_set
};
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)
return 0;
conn->detected = 1;
conn->actions = &actions;
//conn->actions = &actions;
return 1;
}