Mods are detected

FossilOrigin-Name: a2bfbb518739fcc8f547950c91afbff7569cc820dea93d70654c0d313e0ec810
This commit is contained in:
7u83@mail.ru 2018-02-26 19:18:53 +00:00
parent 6ebf54dbbd
commit d53346d250
9 changed files with 66 additions and 25 deletions

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Workspace Name="actube" Database=""> <CodeLite_Workspace Name="actube" Database="">
<Project Name="ac" Path="ac.project" Active="Yes"/> <Project Name="ac" Path="ac.project" Active="No"/>
<Project Name="wtp" Path="wtp.project" Active="No"/> <Project Name="wtp" Path="wtp.project" Active="No"/>
<Project Name="mod_cipwap" Path="mod_cipwap.project" Active="No"/> <Project Name="mod_cipwap" Path="mod_cipwap.project" Active="No"/>
<Project Name="mod_capwap" Path="mod_capwap.project" Active="No"/> <Project Name="mod_capwap" Path="mod_capwap.project" Active="No"/>
<Project Name="mod_cisco" Path="mod_cisco.project" Active="No"/> <Project Name="mod_cisco" Path="mod_cisco.project" Active="Yes"/>
<Project Name="libcw" Path="libcw.project" Active="No"/> <Project Name="libcw" Path="libcw.project" Active="No"/>
<Project Name="mod_capwap80211" Path="mod_capwap80211.project" Active="No"/> <Project Name="mod_capwap80211" Path="mod_capwap80211.project" Active="No"/>
<Project Name="mod_fortinet" Path="mod_fortinet.project" Active="No"/> <Project Name="mod_fortinet" Path="mod_fortinet.project" Active="No"/>

View File

@ -32,7 +32,7 @@
#include "stravltree.h" #include "stravltree.h"
#include "mod.h" #include "mod.h"
#include "message_set.h"
int conn_send_msg(struct conn *conn, uint8_t * rawmsg); int conn_send_msg(struct conn *conn, uint8_t * rawmsg);
@ -189,6 +189,7 @@ static struct cw_MsgSet *load_msg_set(struct conn *conn, uint8_t * rawmsg, int l
// struct cw_actiondef *ad = mod_cache_add(conn,cmod, bmod); // struct cw_actiondef *ad = mod_cache_add(conn,cmod, bmod);
struct cw_MsgSet * set = cw_mod_get_msg_set(conn,cmod,bmod); struct cw_MsgSet * set = cw_mod_get_msg_set(conn,cmod,bmod);
return set; return set;
@ -253,6 +254,8 @@ 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_MsgSet *set = load_msg_set(conn, rawmsg, len, elems_len, from); struct cw_MsgSet *set = load_msg_set(conn, rawmsg, len, elems_len, from);
if (!set) { if (!set) {
//cw_log(LOG_ERR, "Error"); //cw_log(LOG_ERR, "Error");
errno = EAGAIN; errno = EAGAIN;
@ -264,13 +267,25 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
conn->detected = 1; conn->detected = 1;
} }
printf("We have loaded the message set\n");
cw_dbg_msg(DBG_MSG_IN, conn, rawmsg, len, from);
/* prepare struct for search operation */ /* prepare struct for search operation */
struct cw_MsgData search;
search.type = cw_get_msg_id(msg_ptr);
struct cw_MsgData * message;
message = mavl_get(conn->msgset->messages,&search);
printf("Got Message %d (%s)\n", message->type, message->name);
exit(0);
/*
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);
as.vendor_id = 0; as.vendor_id = 0;
as.elem_id = 0; as.elem_id = 0;
as.proto = 0; as.proto = 0;
*/
/* 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);
@ -346,7 +361,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
"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;
} }
@ -454,7 +469,6 @@ int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
{ {
uint8_t *msgptr = rawmsg + cw_get_hdr_msg_offset(rawmsg); uint8_t *msgptr = rawmsg + cw_get_hdr_msg_offset(rawmsg);
@ -596,7 +610,7 @@ int conn_process_packet2(struct conn *conn, uint8_t * packet, int len,
cw_dbg_pkt(DBG_PKT_IN, conn, f + 4, *(uint32_t *) f, from); cw_dbg_pkt(DBG_PKT_IN, conn, f + 4, *(uint32_t *) f, from);
cw_dbg_msg(DBG_MSG_IN, conn, f + 4, *(uint32_t *) f, from); // cw_dbg_msg(DBG_MSG_IN, conn, f + 4, *(uint32_t *) f, from);
// XXX: Modify fragman to not throw away CAPWAP headers // XXX: Modify fragman to not throw away CAPWAP headers
@ -607,7 +621,7 @@ int conn_process_packet2(struct conn *conn, uint8_t * packet, int len,
} }
/* not fragmented, we have a complete message */ /* not fragmented, we have a complete message */
cw_dbg_msg(DBG_MSG_IN, conn, packet, len, from); // cw_dbg_msg(DBG_MSG_IN, conn, packet, len, from);
return conn->process_message(conn, packet, len, from); return conn->process_message(conn, packet, len, from);
} }

View File

@ -133,12 +133,13 @@ typedef struct{
int op; int op;
}cw_msgelemprops_t; }cw_msgelemprops_t;
typedef struct { struct cw_MsgDef{
int type; int type;
int * states; int * states;
cw_msgelemprops_t * elements; cw_msgelemprops_t * elements;
const char * name; const char * name;
}cw_msgdef_t; };
typedef struct cw_MsgDef cw_msgdef_t;
/** /**
* Get length wireless specific data * Get length wireless specific data

View File

@ -36,6 +36,8 @@
#include "capwap.h" #include "capwap.h"
#include "capwap_cisco.h" #include "capwap_cisco.h"
#include "lwapp_cisco.h" #include "lwapp_cisco.h"
#include "cw.h"
#include "message_set.h"
/** /**
*@addtogroup DBG *@addtogroup DBG
@ -485,7 +487,15 @@ void cw_dbg_msg(int level, struct conn *conn, uint8_t * packet, int len,
// int pplen = len - (msgptr-packet); // int pplen = len - (msgptr-packet);
int msg_id = cw_get_msg_id(msgptr); int msg_id = cw_get_msg_id(msgptr);
s += sprintf(s, "%s Message (type=%d) ", cw_strmsg(msg_id), msg_id);
struct cw_MsgData search;
search.type = msg_id;
struct cw_MsgData * message;
message = mavl_get(conn->msgset->messages,&search);
s += sprintf(s, "%s Message (type=%d) ", message->name /*cw_strmsg(msg_id)*/, msg_id);
if (level == DBG_MSG_IN) if (level == DBG_MSG_IN)
s += sprintf(s, "from %s ", sock_addr2str(from)); s += sprintf(s, "from %s ", sock_addr2str(from));
else else

View File

@ -5,6 +5,7 @@
#include "message_set.h" #include "message_set.h"
/*
typedef struct { typedef struct {
int type; int type;
const char * name; const char * name;
@ -12,6 +13,7 @@ typedef struct {
mavl_t elements_tree; mavl_t elements_tree;
mlist_t elements_list; mlist_t elements_list;
}message2_t; }message2_t;
*/
static inline int cmp_cw_msgelemprops(const void *elem1, const void *elem2){ static inline int cmp_cw_msgelemprops(const void *elem1, const void *elem2){
cw_elem_handler_t * e1 = ((cw_msgelemprops_t*)elem1)->elem; cw_elem_handler_t * e1 = ((cw_msgelemprops_t*)elem1)->elem;
@ -98,13 +100,13 @@ static void update_message(message2_t * msg, cw_msgdef_t * src, cw_MsgSet_t * se
void cw_msgset_add(cw_MsgSet_t * set, void cw_msgset_add(cw_MsgSet_t * set,
cw_msgdef_t messages[]){ cw_msgdef_t messages[]){
cw_msgdef_t * m; cw_msgdef_t * message;
for (m=messages; m->type !=0; m++){ for (message=messages; message->type !=0; message++){
message2_t search, *next; message2_t search, *next;
search.type = m->type; search.type = message->type;
cw_dbg(DBG_INFO,"Add message: Type:%d - %s",m->type,m->name); cw_dbg(DBG_INFO,"Add message: Type:%d - %s",message->type,message->name);
next = mavl_find(set->messages,&search); next = mavl_find(set->messages,&search);
@ -125,17 +127,17 @@ void cw_msgset_add(cw_MsgSet_t * set,
free(next); free(next);
return; return;
} }
next->type=m->type; next->type=message->type;
mavl_add(set->messages,next); mavl_add(set->messages,next);
} }
/* massage is alreaddy in there */ /* massage is alreaddy in there */
if (m->name) if (message->name)
next->name=m->name; next->name=message->name;
if (m->states) if (message->states)
next->states=m->states; next->states=message->states;
update_message(next,m, set); update_message(next,message, set);
} }
} }

View File

@ -8,4 +8,17 @@ extern cw_MsgSet_t * cw_message_set_create();
extern void cw_msgset_add(cw_MsgSet_t * set, extern void cw_msgset_add(cw_MsgSet_t * set,
cw_msgdef_t messages[]); cw_msgdef_t messages[]);
mlist_t cw_msgset_get_msg(cw_MsgSet_t * set, int type); mlist_t cw_msgset_get_msg(cw_MsgSet_t * set, int type);
typedef struct cw_MsgData{
int type;
const char * name;
int * states;
mavl_t elements_tree;
mlist_t elements_list;
};
typedef struct cw_MsgData message2_t;
#endif #endif

View File

@ -97,6 +97,8 @@ 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);
struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
struct cw_Mod * capwap_mod, struct cw_Mod *bindings_mod);
#define CW_MOD_MAX_MOD_NAME_LEN 128 #define CW_MOD_MAX_MOD_NAME_LEN 128
#define CW_MOD_INTERFACE_FUNCTION_NAME_SUFFIX "_get_interface" #define CW_MOD_INTERFACE_FUNCTION_NAME_SUFFIX "_get_interface"

View File

@ -133,12 +133,10 @@ static cw_msgdef_t messages[] = {
struct cw_MsgSet * capwap_register_msg_set(struct cw_MsgSet * set, int mode){ 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) if (mode != CW_MOD_MODE_CAPWAP)
return NULL; return NULL;
cw_msgset_add(set,messages); cw_msgset_add(set,messages);
printf("Done Addin gmessages"); return set;
exit(0);
} }
void test_sets(){ void test_sets(){

View File

@ -171,7 +171,8 @@ static struct cw_Mod capwap_ac = {
.name = "cisco", .name = "cisco",
.init = init, .init = init,
.detect = detect, .detect = detect,
.register_actions = register_actions, // .register_actions = register_actions,
}; };
struct cw_Mod *mod_cisco_ac() struct cw_Mod *mod_cisco_ac()