Work on cs_MsgSet

FossilOrigin-Name: 22ea5e3947fb5fa1b70d9384d7120ff5ae65eeb8924b724afebc0170a8f4fe3f
This commit is contained in:
7u83@mail.ru 2018-02-24 22:58:31 +00:00
parent f4723a33da
commit 8ec78cea1b
19 changed files with 169 additions and 87 deletions

View File

@ -21,7 +21,6 @@
<File Name="src/ac/ac.h"/>
<File Name="src/ac/dataman.h"/>
<File Name="src/ac/socklist.h"/>
<File Name="src/mod/capwap/capwap_actions_ac.c"/>
</VirtualDirectory>
</VirtualDirectory>
<Description/>

View File

@ -17,6 +17,7 @@
<File Name="src/mod/capwap/capwap_in_session_id.c"/>
<File Name="src/mod/capwap/capwap_out_get_session_id.c"/>
<File Name="src/mod/capwap/capwap_out_get_idle_timeout.c"/>
<File Name="src/mod/capwap/capwap_actions_ac.c"/>
</VirtualDirectory>
</VirtualDirectory>
</VirtualDirectory>

View File

@ -242,7 +242,11 @@
#define CW_ELEM_RETURNED_MESSAGE_ELEMENT 34
#define CW_ELEM_SESSION_ID 35
#define CW_ELEM_STATISTICS_TIMER 36
#define CW_ELEM_VENDOR_SPECIFIC_PAYLOAD 37
/**
* The Vendor Specific Payload allows tronasport of
* vebdor defined data.*/
#define CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD 37
#define CAPWAP_ELEM_WTP_BOARD_DATA 38
/**
* The WTP Descriptor message element conteins information

View File

@ -43,7 +43,7 @@ struct cw_strlist_elem capwap_strings_elem[] = {
{CW_ELEM_RETURNED_MESSAGE_ELEMENT, "Returned Message Element"},
{CW_ELEM_SESSION_ID, "Session ID"},
{CW_ELEM_STATISTICS_TIMER, "Statistics Timer"},
{CW_ELEM_VENDOR_SPECIFIC_PAYLOAD, "Vendor Specific Payload"},
{CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, "Vendor Specific Payload"},
{CAPWAP_ELEM_WTP_BOARD_DATA, "WTP Board Data"},
{CAPWAP_ELEM_WTP_DESCRIPTOR, "WTP Descriptor"},
{CW_ELEM_WTP_FALLBACK, "WTP Fallback"},

View File

@ -104,36 +104,34 @@
typedef struct{
int proto;
int vendor;
int id;
int mand;
}cw_messagedef_t;
typedef struct {
int type;
int * states;
cw_messagedef_t * elements;
const char * name;
}cw_message_t;
typedef struct {
int proto;
int vendor;
int id;
int min_len;
int max_len;
const char * name;
}cw_message_element_t;
}cw_msgelemdef_t;
typedef struct {
mavl_t messages;
mavl_t all_elems;
}cw_message_set_t;
typedef struct{
cw_msgelemdef_t * elem;
int mand;
}cw_msgelemprops_t;
typedef struct {
int type;
int * states;
cw_msgelemprops_t * elements;
const char * name;
}cw_msgdef_t;
/**
* Get length wireless specific data
@ -390,7 +388,7 @@ static inline int cw_put_elem_vendor_hdr(uint8_t * dst, uint32_t vendorid,
uint16_t elemid, uint16_t len)
{
cw_put_elem_hdr(dst, CW_ELEM_VENDOR_SPECIFIC_PAYLOAD, len + 6);
cw_put_elem_hdr(dst, CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, len + 6);
cw_put_dword(dst + 4, vendorid);
cw_put_word(dst + 8, elemid);
return 10;

View File

@ -42,7 +42,7 @@ int cw_addelem_vendor_specific_payload(uint8_t * dst, uint32_t vendor_id,
d += cw_put_data(d, data, len);
int l = d - dst;
cw_put_elem_hdr(dst, CW_ELEM_VENDOR_SPECIFIC_PAYLOAD, l - 4);
cw_put_elem_hdr(dst, CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, l - 4);
return l;
}

View File

@ -53,7 +53,7 @@ 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));
mlist_t m = cw_actionlist_out_get(conn->actions->out,cw_get_msg_type(msgptr));
if (!m){
cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.",
@ -69,7 +69,7 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
int len = 0;
for (e=m->list; e; e=e->next) {
for (e=m->first; e; e=e->next) {
cw_action_out_t *ae=(cw_action_out_t*)e->data;
//printf("Put %d %i %s\n",ae->msg_id,ae->elem_id,ae->item_id);

View File

@ -549,7 +549,7 @@ void cw_dbg_elem_colored(int level, struct conn *conn, int msg, int msgelem,
char vendor_details[265];
*vendor_details = 0;
if (msgelem == CW_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
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);

View File

@ -1,6 +1,7 @@
#include "cw.h"
#include "mavl.h"
#include "cw/dbg.h"
#include "message_set.h"
@ -12,9 +13,9 @@ typedef struct {
mlist_t elements_list;
}message2_t;
static inline int cmp_cw_message_element(const void *elem1, const void *elem2){
cw_message_element_t * e1 = (cw_message_element_t*)elem1;
cw_message_element_t * e2 = (cw_message_element_t*)elem2;
static inline int cmp_cw_msgelemprops(const void *elem1, const void *elem2){
cw_msgelemdef_t * e1 = ((cw_msgelemprops_t*)elem1)->elem;
cw_msgelemdef_t * e2 = ((cw_msgelemprops_t*)elem2)->elem;
int r;
r = e1->id - e2->id;
if (r!=0)
@ -58,7 +59,7 @@ cw_message_set_t * cw_message_set_create(){
memset(set,0,sizeof(cw_message_set_t));
/* create mavl for all_elems */
set->all_elems = mavl_create(cmp_cw_message_element,NULL);
set->all_elems = mavl_create(cmp_cw_msgelemprops,NULL);
if (set->all_elems==NULL){
cw_message_set_destroy(set);
return NULL;
@ -76,25 +77,85 @@ cw_message_set_t * cw_message_set_create(){
}
static void update_message(message2_t * msg, cw_msgdef_t * src, cw_message_set_t * set){
void cw_message_set_add(cw_message_set_t * set,
cw_message_t messages[],
cw_message_element_t elements[]){
cw_msgelemprops_t *md;
cw_message_element_t * e;
for (e=elements; e->id!=0; e++){
mavl_replace(set->all_elems, e);
}
cw_message_t * m;
for (m=messages; m->type !=0; m++){
printf("MESS: %d %s",m->type, m->name);
for (md = src->elements; md->elem!=0; md++){
cw_dbg(DBG_INFO," add element %d - %s, %d",md->elem->id, md->elem->name, md->mand);
mavl_add(msg->elements_tree,md);
mavl_add(set->all_elems,md);
mlist_append(msg->elements_list,md);
mlist_replace(msg->elements_list,NULL,md);
}
}
cw_message_element_t * cw_message_set_find_element(
void cw_message_set_add(cw_message_set_t * set,
cw_msgdef_t messages[]){
cw_msgdef_t * m;
for (m=messages; m->type !=0; m++){
message2_t search, *next;
search.type = m->type;
cw_dbg(DBG_INFO,"Add message: Type:%d - %s",m->type,m->name);
next = mavl_find(set->messages,&search);
/** message not already in memory,
* create a new one */
if (next == NULL){
next = malloc (sizeof(message2_t));
if (next == NULL)
return;
next->elements_tree = mavl_create(cmp_cw_msgelemprops,NULL);
if (next->elements_tree==NULL){
free(next);
return;
}
next->elements_list = mlist_create(cmp_cw_msgelemprops);
if (next->elements_list == NULL){
mavl_destroy(next->elements_tree);
free(next);
return;
}
next->type=m->type;
mavl_add(set->messages,next);
}
/* massage is alreaddy in there */
if (m->name)
next->name=m->name;
if (m->states)
next->states=m->states;
update_message(next,m, set);
}
}
cw_msgelemdef_t * cw_message_set_find_element(
cw_message_set_t * set,
cw_message_element_t * element){
cw_msgelemdef_t * element){
return mavl_find(set->all_elems,element);
}
mlist_t cw_msgset_get_msg(cw_message_set_t * set, int type){
message2_t search;
search.type = type;
message2_t * result = mavl_find(set->messages,&search);
if (!result){
printf ("no result\n");
return NULL;
}
return result->elements_list;
}

View File

@ -6,6 +6,6 @@
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,
cw_message_t messages[],
cw_message_element_t elements[]);
cw_msgdef_t messages[]);
mlist_t cw_msgset_get_msg(cw_message_set_t * set, int type);
#endif

View File

@ -1,22 +1,22 @@
#include <stdlib.h>
#include <string.h>
#include "mlist.h"
mlist_t *mlist_create(int (*cmp) (void *v1, void *v2))
mlist_t mlist_create(int (*cmp) (const void *v1, const void *v2))
{
mlist_t *l = malloc(sizeof(mlist_t));
struct mlist * l = malloc(sizeof(struct mlist));
if (!l)
return NULL;
memset(l, 0, sizeof(mlist_t));
memset(l, 0, sizeof(struct mlist));
l->cmp = cmp;
return l;
}
struct mlist_elem *mlist_append(mlist_t * l, void *data)
struct mlist_elem * mlist_append(mlist_t l, void *data)
{
struct mlist_elem **n = &l->list;
struct mlist_elem **n = &l->first;
while (*n != NULL)
n = &(*n)->next;
*n = malloc(sizeof(struct mlist_elem));
@ -29,13 +29,13 @@ struct mlist_elem *mlist_append(mlist_t * l, void *data)
return *n;
}
struct mlist_elem *mlist_find(mlist_t * l, struct mlist_elem *start, void *data)
struct mlist_elem *mlist_find(mlist_t l, struct mlist_elem *start, void *data)
{
struct mlist_elem *e;
if (start)
e = start;
else
e = l->list;
e = l->first;
while (e) {
if (l->cmp(e->data, data) == 0)
@ -47,13 +47,13 @@ struct mlist_elem *mlist_find(mlist_t * l, struct mlist_elem *start, void *data)
}
struct mlist_elem *mlist_replace(mlist_t *l, struct mlist_elem *start, void *data)
struct mlist_elem * mlist_replace(mlist_t l, struct mlist_elem *start, void *data)
{
struct mlist_elem *e;
if (start)
e = start;
else
e = l->list;
e = l->first;
struct mlist_elem * f = mlist_find(l,e,data);
if (!f)

View File

@ -46,22 +46,23 @@ struct mlist_elem {
struct mlist {
void *data;
int (*cmp) (void *d1, void *d2);
struct mlist_elem *list;
int (*cmp) (const void *d1, const void *d2);
struct mlist_elem *first;
};
typedef struct mlist mlist_t;
typedef struct mlist * mlist_t;
/**
* defgroup MLIST_FUNCTIONS
* @{
*/
extern mlist_t *mlist_create(int (*cmp) (void *v1, void *v2));
extern struct mlist_elem *mlist_append(mlist_t * l, void *data);
extern struct mlist_elem *mlist_find(mlist_t * l, struct mlist_elem *start, void *data);
extern struct mlist_elem *mlist_replace(mlist_t *l, struct mlist_elem *start, void *data);
extern mlist_t mlist_create(int (*cmp) (const void *v1, const void *v2));
extern struct mlist_elem *mlist_append(mlist_t l, void *data);
extern struct mlist_elem *mlist_find(mlist_t l, struct mlist_elem *start, void *data);
extern struct mlist_elem *mlist_replace(mlist_t l, struct mlist_elem *start, void *data);
#define mlist_add mlist_append
/**
* @}
*/
@ -70,7 +71,7 @@ extern struct mlist_elem *mlist_replace(mlist_t *l, struct mlist_elem *start, vo
#define mlist_foreach(i,l)\
for (i=l->data; i; i=i->next)
for (i=l->first; i; i=i->next)

View File

@ -29,7 +29,7 @@
#include "mod_capwap.h"
static cw_message_element_t _DISCOVERY_TYPE = {
static cw_msgelemdef_t _DISCOVERY_TYPE = {
.name = "Discovery Type",
.id = CAPWAP_ELEM_DISCOVERY_TYPE,
//.start = cw_in_generic2,
@ -37,21 +37,21 @@ static cw_message_element_t _DISCOVERY_TYPE = {
.min_len = 1,
.max_len = 1
};
static cw_message_element_t _WTP_BOARD_DATA = {
static cw_msgelemdef_t _WTP_BOARD_DATA = {
.name = "WTP Board Data",
.id = CAPWAP_ELEM_WTP_BOARD_DATA,
// .start = cw_in_wtp_board_data,
// .item_id = CW_ITEM_WTP_BOARD_DATA,
};
static cw_message_element_t _WTP_DESCRIPTOR = {
static cw_msgelemdef_t _WTP_DESCRIPTOR = {
.id = CAPWAP_ELEM_WTP_DESCRIPTOR,
.name = "WTP Descriptor",
//.start = capwap_in_wtp_descriptor,
//.item_id = "wtp_descriptor",
};
static cw_message_element_t _WTP_FRAME_TUNNEL_MODE = {
static cw_msgelemdef_t _WTP_FRAME_TUNNEL_MODE = {
.id = CAPWAP_ELEM_WTP_FRAME_TUNNEL_MODE,
.name = "WTP Frame Tunnel Mode",
// .start = cw_in_generic2,
@ -60,7 +60,7 @@ static cw_message_element_t _WTP_FRAME_TUNNEL_MODE = {
.max_len = 1
};
static cw_message_element_t _WTP_MAC_TYPE = {
static cw_msgelemdef_t _WTP_MAC_TYPE = {
.id = CAPWAP_ELEM_WTP_MAC_TYPE,
.name = "WTP Mac Type",
// .start = cw_in_generic2,
@ -70,13 +70,13 @@ static cw_message_element_t _WTP_MAC_TYPE = {
};
/* MTU Discovery Padding */
static cw_message_element_t _MTU_DISCOVERY_PADDING = {
static cw_msgelemdef_t _MTU_DISCOVERY_PADDING = {
.id = CW_ELEM_MTU_DISCOVERY_PADDING,
.name = "MTU Discovery Padding"
// .start = cw_in_mtu_discovery_padding,
};
static cw_message_element_t _VENDOR_SPECIFIC_PAYLOAD = {
static cw_msgelemdef_t _VENDOR_SPECIFIC_PAYLOAD = {
.name = "Vendor Specific Payload",
.id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD,
@ -85,7 +85,7 @@ static cw_message_element_t _VENDOR_SPECIFIC_PAYLOAD = {
};
/* AC Descriptor - Discovery Response */
static cw_message_element_t _AC_DESCRIPTOR = {
static cw_msgelemdef_t _AC_DESCRIPTOR = {
.name = "AC Descriptor",
.id = CAPWAP_ELEM_AC_DESCRIPTOR,
//.item_id = CW_ITEM_AC_DESCRIPTOR,
@ -96,14 +96,14 @@ static cw_message_element_t _AC_DESCRIPTOR = {
static cw_message_t messages[] = {
static cw_msgdef_t messages[] = {
/* Discovery Request Message*/
{
.name = "Discovery Request",
.type = CAPWAP_MSG_DISCOVERY_REQUEST,
.states = (int[]){CAPWAP_STATE_DISCOVERY,0},
.elements = (cw_messagedef_t []){
.elements = (cw_msgelemprops_t []){
{&_DISCOVERY_TYPE,1},
{&_WTP_BOARD_DATA,1},
{&_WTP_DESCRIPTOR,1},
@ -119,7 +119,7 @@ static cw_message_t messages[] = {
.name = "Discovery Response",
.type = CAPWAP_MSG_DISCOVERY_RESPONSE,
.states = (int[]){CAPWAP_STATE_DISCOVERY,0},
.elements = (cw_messagedef_t[]){
.elements = (cw_msgelemprops_t[]){
{&_AC_DESCRIPTOR,1},
{0,0},
}
@ -137,22 +137,40 @@ void test_sets(){
cw_message_set_add(set,messages);
cw_message_element_t el, *result;
cw_msgelemdef_t el;
memset(&el,0,sizeof(el));
el.id=CAPWAP_ELEM_DISCOVERY_TYPE;
result = mavl_find(set->all_elems,&el);
cw_msgelemprops_t search, *result;;
search.elem = &el;
result = mavl_find(set->all_elems,&search);
if (result!=NULL){
printf("Found: %d %s\n",
result->id,
result->name
printf("Found: %d %s %d\n",
result->elem->id,
result->elem->name,
result->mand
);
}
else{
printf("not found\n");
}
mlist_t m;
m = cw_msgset_get_msg(set,CAPWAP_MSG_DISCOVERY_REQUEST);
printf("Hey: %p\n",m);
struct mlist_elem * i;
mlist_foreach(i,m){
cw_msgelemprops_t * le = i->data;
printf("Element: %d %s\n",le->elem->id, le->elem->name, le->mand);
}
}

View File

@ -73,7 +73,7 @@ static cw_action_in_t actions_in[] = {
{
.capwap_state = CAPWAP_STATE_DISCOVERY,
.msg_id = CAPWAP_MSG_DISCOVERY_RESPONSE,
.elem_id = CW_ELEM_VENDOR_SPECIFIC_PAYLOAD,
.elem_id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD,
.start = cw_in_vendor_specific_payload
}
,
@ -299,7 +299,7 @@ static cw_action_in_t actions_in[] = {
{
.capwap_state = CW_STATE_CONFIGURE,
.msg_id = CW_MSG_CONFIGURATION_STATUS_RESPONSE,
.elem_id = CW_ELEM_VENDOR_SPECIFIC_PAYLOAD,
.elem_id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD,
.start = cw_in_vendor_specific_payload
}
,
@ -370,7 +370,7 @@ static cw_action_in_t actions_in[] = {
{
.capwap_state = CW_STATE_RUN,
.msg_id = CW_MSG_ECHO_RESPONSE,
.elem_id = CW_ELEM_VENDOR_SPECIFIC_PAYLOAD,
.elem_id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD,
.start = cw_in_vendor_specific_payload
}
,
@ -435,7 +435,7 @@ static cw_action_in_t actions_in[] = {
{
.capwap_state = CW_STATE_RUN,
.msg_id = CW_MSG_CONFIGURATION_UPDATE_REQUEST,
.elem_id = CW_ELEM_VENDOR_SPECIFIC_PAYLOAD,
.elem_id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD,
.start = cw_in_vendor_specific_payload
}
,

View File

@ -140,7 +140,7 @@ static int detect(struct conn *conn, const uint8_t * rawmsg, int rawlen, int ele
* specific payload Cisco identifier */
cw_foreach_elem(elem, elems_ptr, elems_len) {
int id = cw_get_elem_id(elem);
if (id == CW_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
if (id == CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
uint32_t vendor_id = cw_get_dword(cw_get_elem_data(elem));
if (vendor_id == CW_VENDOR_ID_CISCO) {
// conn->actions = &actions;

View File

@ -127,7 +127,7 @@ static int detect(struct conn *conn, const uint8_t * rawmsg, int rawlen, int ele
* specific payload Cisco identifier */
cw_foreach_elem(elem, elems_ptr, elems_len) {
int id = cw_get_elem_id(elem);
if (id == CW_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
if (id == CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
uint32_t vendor_id = cw_get_dword(cw_get_elem_data(elem));
if (vendor_id == CW_VENDOR_ID_CISCO) {
// conn->actions = &actions;

View File

@ -39,7 +39,7 @@ static cw_action_in_t actions_in[] = {
/* Message Discovery Request */
{
.capwap_state = CW_STATE_DISCOVERY,
.capwap_state = CAPWAP_STATE_DISCOVERY,
.msg_id = CAPWAP_MSG_DISCOVERY_REQUEST,
.end = cw_in_check_disc_req
}
@ -47,7 +47,7 @@ static cw_action_in_t actions_in[] = {
#if 0
/* Element WTP Descriptor */
{
.capwap_state = CW_STATE_DISCOVERY,
.capwap_state = CAPWAP_STATE_DISCOVERY,
.msg_id = CAPWAP_MSG_DISCOVERY_REQUEST,
.elem_id = CW_ELEM_WTP_DESCRIPTOR,
.start = cisco_in_wtp_descriptor,
@ -58,7 +58,7 @@ static cw_action_in_t actions_in[] = {
/* Element Cisco RAD Name */
{
.capwap_state = CW_STATE_DISCOVERY,
.capwap_state = CAPWAP_STATE_DISCOVERY,
.msg_id = CAPWAP_MSG_DISCOVERY_REQUEST,
.vendor_id = CW_VENDOR_ID_CISCO,
.elem_id = CW_CISCO_RAD_NAME,
@ -249,7 +249,7 @@ static cw_action_in_t actions80211_in[] = {
/* Cisco doe't sned this message element in discovery request,
so make it non-mandatory */
.capwap_state = CW_STATE_DISCOVERY,
.capwap_state = CAPWAP_STATE_DISCOVERY,
.msg_id = CAPWAP_MSG_DISCOVERY_REQUEST,
.elem_id = CW_ELEM80211_WTP_RADIO_INFORMATION,
.item_id = "radio_information",

View File

@ -81,7 +81,7 @@ static int detect(struct conn *conn, const uint8_t * rawmsg, int rawlen, int ele
* specific payload Fortinet identifier */
cw_foreach_elem(elem, elems_ptr, elems_len) {
int id = cw_get_elem_id(elem);
if (id == CW_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
if (id == CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
uint32_t vendor_id = cw_get_dword(cw_get_elem_data(elem));
if (vendor_id == CW_VENDOR_ID_FORTINET) {
// conn->actions = &actions;

View File

@ -126,7 +126,7 @@ static int detect(struct conn *conn, const uint8_t * rawmsg, int rawlen, int ele
* specific payload Fortinet identifier */
cw_foreach_elem(elem, elems_ptr, elems_len) {
int id = cw_get_elem_id(elem);
if (id == CW_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
if (id == CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
uint32_t vendor_id = cw_get_dword(cw_get_elem_data(elem));
if (vendor_id == CW_VENDOR_ID_FORTINET) {
// conn->actions = &actions;