mtu discovery padding added

FossilOrigin-Name: 391a17b2ab460b54a220c3e128578a37610e71f524b3d127316f201bf4dfd4af
This commit is contained in:
7u83@mail.ru 2018-03-11 09:34:20 +00:00
parent 4171d208d0
commit 41688c4e60
28 changed files with 352 additions and 276 deletions

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<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="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="Yes"/>
<Project Name="mod_cisco" Path="mod_cisco.project" Active="No"/>
<Project Name="libcw" Path="libcw.project" Active="No"/>
<Project Name="mod_capwap80211" Path="mod_capwap80211.project" Active="No"/>

View File

@ -93,7 +93,6 @@
<File Name="src/cw/cw_in_wtp_reboot_statistics.c"/>
<File Name="src/cw/mlist.c"/>
<File Name="src/cw/netconn.c"/>
<File Name="src/cw/mavl_create_conststr.c"/>
<File Name="src/cw/cw_in_capwap_local_ipv6_address.c"/>
<File Name="src/cw/cw_out_capwap_local_ip_address.c"/>
<File Name="src/cw/cw_out_wtp_descriptor.c"/>
@ -257,7 +256,6 @@
<File Name="src/cw/lw_put_80211_wtp_wlan_radio_configuration.c"/>
<File Name="src/cw/cw_put_image_data.c"/>
<File Name="src/cw/cw_util.c"/>
<File Name="src/cw/cw_in_mtu_discovery_padding.c"/>
<File Name="src/cw/conn_create_noq.c"/>
<File Name="src/cw/cw_addelem_cisco_wtp_radio_cfg.c"/>
<File Name="src/cw/mavl_del.c"/>
@ -322,10 +320,14 @@
<File Name="src/cw/msget.h"/>
<File Name="src/cw/mavl_replace.c"/>
<File Name="src/cw/cw_kvt_add.c"/>
<File Name="src/cw/mlist_create.c"/>
<File Name="src/cw/mlist_append.c"/>
</VirtualDirectory>
</VirtualDirectory>
<Description/>
<Dependencies/>
<Dependencies Name="Debug"/>
<Dependencies Name="Release"/>
<Settings Type="Static Library">
<GlobalSettings>
<Compiler Options="" C_Options="" Assembler="">
@ -342,7 +344,7 @@
</Compiler>
<Linker Options="" Required="yes"/>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="" IntermediateDirectory="./Debug" Command="" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<General OutputFile="" IntermediateDirectory="./Debug" Command="$(WorkspacePath)/src/ac/actube" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
@ -413,6 +415,4 @@
</Completion>
</Configuration>
</Settings>
<Dependencies Name="Debug"/>
<Dependencies Name="Release"/>
</CodeLite_Project>

View File

@ -19,6 +19,7 @@
<File Name="src/mod/capwap/capwap_out_get_idle_timeout.c"/>
<File Name="src/mod/capwap/capwap_actions_ac.c"/>
<File Name="src/mod/capwap/capwap_in_vendor_specific_payload.c"/>
<File Name="src/mod/capwap/capwap_in_mtu_discovery_padding.c"/>
</VirtualDirectory>
</VirtualDirectory>
</VirtualDirectory>

View File

@ -153,11 +153,48 @@ int stcmp (const void * sa1, const void *sa2)
int main (int argc, char *argv[])
{
mavl_t tree;
/* mavl_t tree;
int i;
mavliter_t it;
mlist_t list;
struct mlistelem * elem;
int x;
list = mlist_create(NULL,sizeof(int));
x=8;
mlist_append(list,&x);
x=13;
mlist_append(list,&x);
x=11;
mlist_append(list,&x);
for(i=0; i<100000000; i++){
int val;
val = i;
mlistelem_t * result;
result = mlist_append(list,&val);
if (result == NULL){
printf("error\n");
}
}
printf("Count %d\n",list->count);
mlist_foreach(elem,list){
int * data = mlistelem_dataptr(elem);
printf("Here is %d\n",*data);
}
exit(0);
*/
/*tree = mavl_create_ptr( (int(*)(const void*,const void*))strcmp,free);
*/

View File

@ -307,7 +307,7 @@ errX:
}
// TODO XXXX
mavl_conststr_t db_get_update_tasks(struct conn * conn,const char * wtpid)
mavl_t db_get_update_tasks(struct conn * conn,const char * wtpid)
{
/*
sqlite3_reset(get_tasks_stmt);
@ -391,7 +391,7 @@ errX:
mavl_conststr_t db_get_radio_tasks(struct conn * conn,const char * wtpid)
mavl_t db_get_radio_tasks(struct conn * conn,const char * wtpid)
{
/*
//cw_dbg(DBG_X,"Get Radio Tasks for %s",wtpid);

View File

@ -10,10 +10,10 @@ extern int db_init();
int db_start();
int db_get_tasks(struct conn * conn,const char * wtpid);
void db_put_wtp_prop(const char *wtp_id,const char * id,const char *sub_id,const char * val);
mavl_conststr_t db_get_update_tasks(struct conn * conn,const char * wtpid);
mavl_t db_get_update_tasks(struct conn * conn,const char * wtpid);
void db_put_radio_prop(const char *wtp_id,const char *rid, const char * key,const char *sub_key,const char * val);
extern mavl_conststr_t db_get_radio_tasks(struct conn * conn,const char * wtpid);
extern mavl_t db_get_radio_tasks(struct conn * conn,const char * wtpid);
#endif

View File

@ -598,7 +598,7 @@ static void wtpman_run(void *arg)
mavl_conststr_t r;
mavl_t r;
r = db_get_update_tasks(conn, sock_addr2str(&conn->addr,sock_buf));
if (r) {

View File

@ -168,7 +168,7 @@ static int mout_cmp(void *elem1,void *elem2)
struct outelem * cw_actionlist_mout_create(int msg_id)
{
struct outelem * o = malloc(sizeof(struct outelem));
/* struct outelem * o = malloc(sizeof(struct outelem));
if (!o)
return NULL;
@ -179,6 +179,7 @@ struct outelem * cw_actionlist_mout_create(int msg_id)
}
o->msg_id=msg_id;
return o;
*/
}
static struct outelem * cw_actionlist_out_get_outelem(cw_actionlist_out_t t, int msg_id)
@ -220,7 +221,7 @@ cw_action_out_t *cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_o
mavl_add(t,o,NULL);
}
struct mlist_elem * e = mlist_replace(o->mlist,NULL,a);
struct mlistelem * e = mlist_replace(o->mlist,NULL,a);
if (!e)
e = mlist_append(o->mlist,a);

View File

@ -238,7 +238,7 @@
#define CW_ELEM_INITIATE_DOWNLOAD 27
#define CW_ELEM_LOCATION_DATA 28
#define CW_ELEM_MAXIMUM_MESSAGE_LENGTH 29
#define CW_ELEM_MTU_DISCOVERY_PADDING 52
#define CAPWAP_ELEM_MTU_DISCOVERY_PADDING 52
#define CW_ELEM_RADIO_ADMINISTRATIVE_STATE 31
#define CW_ELEM_RADIO_OPERATIONAL_STATE 32
#define CW_ELEM_RESULT_CODE 33
@ -469,7 +469,7 @@ extern int cw_readelem_statistics_timer(uint16_t * timer, int type, uint8_t * ms
int len);
extern int cw_readelem_result_code(uint32_t * result_code, int type, uint8_t * msgelem,
int len);
extern int cw_readelem_mtu_discovery_padding(int type, uint8_t * msgelem, int len);
extern int cw_readelem_vendor_specific_payload(void *data, int msgtype, int elemtype,
uint8_t * msgelem, int len);

View File

@ -37,7 +37,7 @@ struct cw_strlist_elem capwap_strings_elem[] = {
{CW_ELEM_INITIATE_DOWNLOAD, "Initiate Download"},
{CW_ELEM_LOCATION_DATA, "Location Data"},
{CW_ELEM_MAXIMUM_MESSAGE_LENGTH, "Maximum Message Length"},
{CW_ELEM_MTU_DISCOVERY_PADDING, "MTU Discovery Padding"},
{CAPWAP_ELEM_MTU_DISCOVERY_PADDING, "MTU Discovery Padding"},
{CW_ELEM_RADIO_ADMINISTRATIVE_STATE, "Radio Administrative State"},
{CW_ELEM_RADIO_OPERATIONAL_STATE, "Radio Operational State"},
{CW_ELEM_RESULT_CODE, "Result Code"},

View File

@ -233,6 +233,10 @@ void cw_read_elem(struct cw_ElemHandler * handler, struct conn * conn,
static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
struct sockaddr *from)
{
mavl_t mand_found;
mlist_t unrecognized;
char sock_buf[SOCK_ADDR_BUFSIZE]; /**< to hold str from sockaddr2str */
struct cw_action_in as, *af, *afm;
@ -365,9 +369,10 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
uint8_t *elem;
/* Create an avltree to catch the found mandatory elements */
conn->mand = stravltree_create();
//conn->mand = stravltree_create();
mand_found = mavl_create_conststr();
unrecognized = mlist_create(NULL,NULL,sizeof(uint8_t*));
/* iterate through message elements */
cw_foreach_elem(elem, elems_ptr, elems_len) {
@ -393,6 +398,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
params.conn=conn;
params.from=from;
params.msgdata=message;
params.mand_found=mand_found;
result_code = cw_process_element(&params,0,0,elem_id,elem_data,elem_len);
@ -400,7 +406,10 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
if (cw_result_is_ok(result_code))
continue;
if (result_code == CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT){
mlist_append(unrecognized,&elem);
}
/*
@ -517,12 +526,27 @@ exit(0);
}
mavliter_init(&it,mand_found);
mavliter_foreach(&it){
printf("MAnd found: %s\n", mavliter_get_str(&it));
}
{
mlistelem_t *e;
mlist_foreach(e,unrecognized){
uint8_t * elem = *(uint8_t**)mlistelem_dataptr(e);
int elem_len = cw_get_elem_len(elem);
//int elem_data=cw_get_elem_data(elem);
int elem_id = cw_get_elem_id(elem);
printf("Unrecognized: %d %d\n",elem_id,elem_len);
}
}
mavl_destroy(mand_found);
}
//int result_code = 0;
int unrecognized =3;
//int unrecognized =3;
int rct = cw_in_check_generic(conn, afm, rawmsg, len, from);

View File

@ -341,9 +341,6 @@ extern int cw_in_check_generic_resp(struct conn *conn, struct cw_action_in *a,
extern int cw_in_check_generic_req(struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len, struct sockaddr *from);
extern int cw_in_mtu_discovery_padding(struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len, struct sockaddr *from);
/**

View File

@ -37,6 +37,10 @@ int cw_process_element(struct cw_ElemHandlerParams *params, int proto, int vendo
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
}
if (elem_data->mand){
mavl_add_str(params->mand_found,handler->key);
}
/* check the length of the message */
if (len < handler->min_len) {
cw_dbg(DBG_ELEM_ERR,

View File

@ -68,12 +68,12 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
}
struct mlist_elem *e;
struct mlistelem *e;
int len = 0;
for (e=m->first; e; e=e->next) {
cw_action_out_t *ae=(cw_action_out_t*)e->data;
cw_action_out_t *ae=(cw_action_out_t*)e;
//printf("Put %d %i %s\n",ae->msg_id,ae->elem_id,ae->item_id);
if ( ae->item_id ) {
@ -123,17 +123,21 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
* alread initilaized in buffer
* Message alements are taken fom actiondef in #conn->action
*/
int cw_put_custom_msg(struct conn *conn, uint8_t * rawout, mavl_conststr_t elems)
int cw_put_custom_msg(struct conn *conn, uint8_t * rawout, /*mavl_conststr_t elems*/ t)
{
/* rawout is already initialized, so we can get
msg type from buffer */
/*
// rawout is already initialized, so we can get
//msg type from buffer
uint8_t *msgptr = rawout + cw_get_hdr_msg_offset(rawout);
int msg_id = cw_get_msg_type(msgptr);
MAVLITER_DEFINE(it,elems);
mavliter_foreach(&it){
const char *i= mavliter_get(&it);
/* preapare action search */
// preapare action search
cw_action_out_t as;
as.msg_id=msg_id;
as.item_id=i;
@ -147,7 +151,7 @@ int cw_put_custom_msg(struct conn *conn, uint8_t * rawout, mavl_conststr_t elems
/* create search paramaters */
cw_action_out_t as;
as.item_id = CW_ITEM_NONE;
@ -182,7 +186,7 @@ MAVLITER_DEFINE(i,0);
}
if (ae->msg_id != as.msg_id) {
/* Element is from next msg, close action */
// Element is from next msg, close action
break;
}
int l=0;
@ -206,15 +210,15 @@ MAVLITER_DEFINE(i,0);
cw_set_msg_elems_len(msgptr, len);
if (as.msg_id & 1) {
/* It's a request, so we have to set seqnum */
/// It's a request, so we have to set seqnum
int s = conn_get_next_seqnum(conn);
cw_set_msg_seqnum(msgptr,s);
// printf("Set seqnum to : %d\n",s);
}
*/
return len;
return 0; //len
}

View File

@ -34,7 +34,7 @@ printf("MTU discovery len %d %d and pos %d:\n",conn->mtu,len,msg->pos);
if (len < 0 )
return;
uint32_t val = CW_ELEM_MTU_DISCOVERY_PADDING<<16|len;
uint32_t val = CAPWAP_ELEM_MTU_DISCOVERY_PADDING<<16|len;
*((uint32_t*)(msg->msgelems+msg->pos))=htonl(val);
memset(msg->msgelems+4+msg->pos,0xff,len);
msg->pos+=4+len;

View File

@ -241,8 +241,10 @@ extern union mavldata * mavliter_seek ( mavliter_t *i, void *d );
*/
#define mavl_get_count(m) (m->count)
typedef mavl_t mavl_conststr_t;
extern mavl_conststr_t mavl_create_conststr();
/*
#typedef mavl_t mavl_conststr_t;
#extern mavl_conststr_t mavl_create_conststr();
*/
/*
//int mavl_cmp_str ( const union mavldata *e1, const union mavldata *e2 );
@ -276,6 +278,7 @@ void mavl_freeptr(void *ptr);
mavl_create(cmp,del,sizeof(void*))
int mavl_cmpstr(const void *p1, const void *p2);
#define mavl_create_str() mavl_create_ptr(mavl_cmpstr,mavl_freeptr)
#define mavl_create_conststr() mavl_create_ptr(mavl_cmpstr,NULL)
void * mavl_get_ptr ( mavl_t tree, void * search );
void * mavl_add_ptr ( mavl_t tree, void *ptr );

View File

@ -1,43 +0,0 @@
/*
This file is part of actube.
actube is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file
* @brief Implementation of mavl_create_conststr
*/
#include "mavl.h"
static int cmp(const void *v1,const void*v2)
{
return strcmp( (char*)v1,(char*)v2);
}
/**
* Create a mavl object which holds pointers to strings.
* These strings have to be constant. So there is no
* free method called, when the mavl object is destroyed
* @return The created mavl object or NULL if an error
* has occured.
*/
mavl_conststr_t mavl_create_conststr()
{
return mavl_create(cmp,NULL,1312);
}

View File

@ -3,42 +3,19 @@
#include "mlist.h"
mlist_t mlist_create(int (*cmp) (const void *v1, const void *v2))
{
struct mlist * l = malloc(sizeof(struct mlist));
if (!l)
return NULL;
memset(l, 0, sizeof(struct mlist));
l->cmp = cmp;
return l;
}
struct mlist_elem * mlist_append(mlist_t l, void *data)
{
struct mlist_elem **n = &l->first;
while (*n != NULL)
n = &(*n)->next;
*n = malloc(sizeof(struct mlist_elem));
if (!*n)
return NULL;
(*n)->data = data;
(*n)->next = NULL;
return *n;
}
struct mlist_elem * mlist_prepend(mlist_t l, void *data){
struct mlistelem * mlist_prepend(mlist_t l, void *data){
}
struct mlist_elem *mlist_find(mlist_t l, struct mlist_elem *start, void *data)
struct mlistelem *mlist_find(mlist_t l, struct mlistelem *start, void *data)
{
struct mlist_elem *e;
/*
struct mlistelem *e;
if (start)
e = start;
else
@ -51,22 +28,24 @@ struct mlist_elem *mlist_find(mlist_t l, struct mlist_elem *start, void *data)
}
return NULL;
*/
}
struct mlist_elem * mlist_replace(mlist_t l, struct mlist_elem *start, void *data)
struct mlistelem * mlist_replace(mlist_t l, struct mlistelem *start, void *data)
{
struct mlist_elem *e;
/*
struct mlistelem *e;
if (start)
e = start;
else
e = l->first;
struct mlist_elem * f = mlist_find(l,e,data);
struct mlistelem * f = mlist_find(l,e,data);
if (!f)
return NULL;
f->data = data;
return f;
*/
}

View File

@ -24,6 +24,10 @@
* @brief Mlist Mini list
*/
#include <stdlib.h>
#include <stdint.h>
/**
* @defgroup MLIST MLIST
* @{
@ -34,51 +38,43 @@
* It's a simple connected list, just with pone connection to the
* next element.
*/
struct mlist_elem {
/** Pointer to data */
void *data;
/**
* Pointer to next element
* The last element is determined by a NULL pointer
* */
struct mlist_elem *next;
struct mlist_elem *prev;
struct mlistelem {
struct mlistelem *next;
struct mlistelem *prev;
};
typedef struct mlistelem mlistelem_t;
struct mlist {
void *data;
/* void *data;*/
int (*cmp) (const void *d1, const void *d2);
struct mlist_elem *first;
struct mlist_elem *last;
void (*del) (void *data);
struct mlistelem *first;
struct mlistelem *last;
int count;
/* //size_t elem_size;*/
size_t data_size;
};
typedef struct mlist * mlist_t;
#define mlistelem_dataptr(elem) ((void*)(((uint8_t*)(elem))+sizeof(struct mlistelem)))
/**
* defgroup MLIST_FUNCTIONS
* @{
*/
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);
mlist_t mlist_create(int (*cmp) (const void *v1, const void *v2), void (*del)(void *), size_t data_size);
struct mlistelem *mlist_append(mlist_t l, void *data);
extern struct mlistelem *mlist_find(mlist_t l, struct mlistelem *start, void *data);
extern struct mlistelem *mlist_replace(mlist_t l, struct mlistelem *start, void *data);
#define mlist_add mlist_append
/**
* @}
*/
#define mlist_foreach(i,l)\
for (i=l->first; i; i=i->next)
#define mlist_foreach(elem,list)\
for (elem=list->first; elem; elem=elem->next)
/**
* @}

31
src/cw/mlist_append.c Normal file
View File

@ -0,0 +1,31 @@
#include <string.h>
#include "mlist.h"
struct mlistelem *mlist_append(mlist_t l, void *data)
{
struct mlistelem *e;
e = malloc(sizeof(struct mlistelem) + l->data_size);
if (e == NULL)
return NULL;
memcpy(mlistelem_dataptr(e), data, l->data_size);
if (l->first == NULL) {
l->first = e;
l->last = e;
e->prev=NULL;
e->next=NULL;
l->count++;
return e;
}
l->last->next=e;
e->prev=l->last;
e->next=NULL;
l->last=e;
l->count++;
return e;
}

18
src/cw/mlist_create.c Normal file
View File

@ -0,0 +1,18 @@
#include "mlist.h"
mlist_t mlist_create(int (*cmp) (const void *v1, const void *v2),
void (*del)(void*),
size_t data_size)
{
struct mlist * l = malloc(sizeof(struct mlist));
if (!l)
return NULL;
/*memset(l, 0, sizeof(struct mlist));*/
l->cmp = cmp;
l->data_size=data_size;
l->first=NULL;
l->last=NULL;
l->count=0;
return l;
}

View File

@ -264,18 +264,25 @@ errX:
}
static struct mlist * mods_list = NULL;
struct cw_Mod * cw_mod_add_to_list(struct cw_Mod * mod ){
mlistelem_t *elem;
if (!mods_list){
mods_list = mlist_create(mod_cmp_mlist);
mods_list = mlist_create(mod_cmp_mlist,NULL,sizeof(struct cw_Mod *));
if (!mods_list){
cw_log(LOG_ERROR,"Can't init mods_list");
return 0;
}
}
return mlist_append(mods_list,mod)->data;
elem = mlist_append(mods_list,&mod);
printf("Append mod %p\n",mod);
if (elem == NULL)
return NULL;
return mlistelem_dataptr(elem);
/*return mlist_append(mods_list,mod)->data;*/
}
struct cw_Mod * cw_mod_detect(struct conn *conn,
@ -283,16 +290,18 @@ struct cw_Mod * cw_mod_detect(struct conn *conn,
int elems_len, struct sockaddr *from,
int mode){
struct mlist_elem * e;
struct mlistelem * e;
if (mods_list==NULL)
return MOD_NULL;
mlist_foreach(e,mods_list){
struct cw_Mod * mod = e->data;
/// 1312
struct cw_Mod * mod = *(struct cw_Mod**)(mlistelem_dataptr(e)); /* = e->data;*/
cw_dbg(DBG_MOD,"Checking mod: %s",mod->name);
printf("Got the mod %p\n",mod);
/* if there is no detect method, skip */
if (!mod->detect)
continue;

View File

@ -32,6 +32,7 @@ struct cw_ElemHandlerParams {
struct conn * conn;
struct cw_MsgData * msgdata;
struct sockaddr *from;
mavl_t mand_found;
};
struct cw_ElemHandler {

View File

@ -8,66 +8,70 @@
#include "msget.h"
static int cmp_cw_elemhandler_by_id(const void * elem1, const void *elem2){
const struct cw_ElemHandler * e1 = elem1;
const struct cw_ElemHandler * e2 = elem2;
static int cmp_cw_elemhandler_by_id(const void *elem1, const void *elem2)
{
const struct cw_ElemHandler *e1 = elem1;
const struct cw_ElemHandler *e2 = elem2;
int r;
r = e1->id - e2->id;
if (r!=0)
if (r != 0)
return r;
r = e1->vendor - e2->vendor;
if (r!=0)
if (r != 0)
return r;
r = e1->proto - e2->proto;
if (r != 0)
return r;
r = e1->proto - e2->proto;
if (r != 0)
return r;
return 0;
}
static int cmp_cw_elemhandler_by_key(const void *elem1, const void *elem2){
const struct cw_ElemHandler * e1 = elem1;
const struct cw_ElemHandler * e2 = elem2;
return strcmp(e1->key,e2->key);
static int cmp_cw_elemhandler_by_key(const void *elem1, const void *elem2)
{
const struct cw_ElemHandler *e1 = elem1;
const struct cw_ElemHandler *e2 = elem2;
return strcmp(e1->key, e2->key);
}
static int cmp_msgdata(const void * elem1, const void *elem2)
{
const struct cw_MsgData * e1 = elem1;
const struct cw_MsgData * e2 = elem2;
static int cmp_msgdata(const void *elem1, const void *elem2)
{
const struct cw_MsgData *e1 = elem1;
const struct cw_MsgData *e2 = elem2;
return e1->type - e2->type;
}
static int cmp_elemdata(const void * elem1, const void *elem2)
static int cmp_elemdata(const void *elem1, const void *elem2)
{
const struct cw_ElemData * e1 = elem1;
const struct cw_ElemData * e2 = elem2;
const struct cw_ElemData *e1 = elem1;
const struct cw_ElemData *e2 = elem2;
int r;
r = e1->id - e2->id;
if (r!=0)
if (r != 0)
return r;
r = e1->vendor - e2->vendor;
if (r!=0)
if (r != 0)
return r;
r = e1->proto - e2->proto;
if (r != 0)
return r;
r = e1->proto - e2->proto;
if (r != 0)
return r;
return 0;
}
static void msgdata_destroy(struct cw_MsgData *data){
static void msgdata_destroy(struct cw_MsgData *data)
{
if (!data)
return;
/* if (data->elements_list)
mlist_destroy(data->elements_list);
*/
if (data->elements_tree)
mavl_destroy( data->elements_tree );
mavl_destroy(data->elements_tree);
free(data);
}
static void del_mavl_msdgdata( void * d ){
static void del_mavl_msdgdata(void *d)
{
msgdata_destroy(d);
}
@ -76,7 +80,8 @@ static void del_mavl_msdgdata( void * d ){
* @brief Destroy a message set
* @param set Message set to destroy
*/
void cw_msgset_destroy(struct cw_MsgSet * set){
void cw_msgset_destroy(struct cw_MsgSet *set)
{
if (set->msgdata)
mavl_destroy(set->msgdata);
if (set->handlers_by_id)
@ -91,35 +96,36 @@ void cw_msgset_destroy(struct cw_MsgSet * set){
* @brief Create a message set
* @return Message set create, NULL if an error has occured
*/
struct cw_MsgSet * cw_msgset_create(){
struct cw_MsgSet *cw_msgset_create()
{
/* allocate memory for a message_set */
struct cw_MsgSet * set = malloc(sizeof(struct cw_MsgSet ));
if (set==NULL)
struct cw_MsgSet *set = malloc(sizeof(struct cw_MsgSet));
if (set == NULL)
return NULL;
memset(set,0,sizeof(struct cw_MsgSet));
memset(set, 0, sizeof(struct cw_MsgSet));
/* create mavl for all_elems by id */
set->handlers_by_id = mavl_create(cmp_cw_elemhandler_by_id,NULL,
sizeof(struct cw_ElemHandler));
if (set->handlers_by_id==NULL){
set->handlers_by_id = mavl_create(cmp_cw_elemhandler_by_id, NULL,
sizeof(struct cw_ElemHandler));
if (set->handlers_by_id == NULL) {
cw_msgset_destroy(set);
return NULL;
}
/* create mavl for all_elems by key */
set->handlers_by_key = mavl_create(cmp_cw_elemhandler_by_key,NULL,
sizeof(struct cw_ElemHandler));
if (set->handlers_by_key==NULL){
set->handlers_by_key = mavl_create(cmp_cw_elemhandler_by_key, NULL,
sizeof(struct cw_ElemHandler));
if (set->handlers_by_key == NULL) {
cw_msgset_destroy(set);
return NULL;
}
/* create mavl for messages */
set->msgdata = mavl_create(cmp_msgdata,del_mavl_msdgdata,
sizeof(struct cw_MsgData));
if (set->msgdata==NULL){
set->msgdata = mavl_create(cmp_msgdata, del_mavl_msdgdata,
sizeof(struct cw_MsgData));
if (set->msgdata == NULL) {
cw_msgset_destroy(set);
return NULL;
}
@ -127,120 +133,107 @@ struct cw_MsgSet * cw_msgset_create(){
return set;
}
struct cw_ElemHandler * cw_msgset_get_elemhandler(struct cw_MsgSet * set,
int proto, int vendor, int id)
struct cw_ElemHandler *cw_msgset_get_elemhandler(struct cw_MsgSet *set,
int proto, int vendor, int id)
{
struct cw_ElemHandler search;
search.proto=proto;
search.vendor=vendor;
search.id=id;
return mavl_find(set->handlers_by_id,&search);
search.proto = proto;
search.vendor = vendor;
search.id = id;
return mavl_find(set->handlers_by_id, &search);
}
static int update_msgdata(struct cw_MsgSet * set, struct cw_MsgData * msgdata,
struct cw_MsgDef * msgdef)
static int update_msgdata(struct cw_MsgSet *set, struct cw_MsgData *msgdata,
struct cw_MsgDef *msgdef)
{
struct cw_ElemDef * elemdef;
struct cw_ElemDef *elemdef;
struct cw_ElemData ed, *result;
/* iterate through all defined elements */
for(elemdef = msgdef->elements; elemdef->id; elemdef++){
struct cw_ElemHandler * handler;
for (elemdef = msgdef->elements; elemdef->id; elemdef++) {
struct cw_ElemHandler *handler;
int replaced;
handler = cw_msgset_get_elemhandler(set,
elemdef->proto,
elemdef->vendor,
elemdef->id);
elemdef->proto,
elemdef->vendor, elemdef->id);
/* check if a handler for our element already exists */
if (!handler){
if (!handler) {
cw_log(LOG_ERR, "No handler for message element: %d %d %d",
elemdef->proto,
elemdef->vendor,
elemdef->id);
elemdef->proto, elemdef->vendor, elemdef->id);
continue;
}
ed.id=elemdef->id;
ed.proto=elemdef->proto;
ed.vendor=elemdef->vendor;
ed.mand=elemdef->mand;
result = mavl_replace(msgdata->elements_tree, &ed, &replaced);
if (!replaced){
cw_dbg(DBG_MOD, " adding message element %d %d %d - %s",
elemdef->proto,
elemdef->vendor,
elemdef->id,
handler->name);
}
else{
cw_dbg(DBG_MOD, " replacing message element %d %d %d - %s",
elemdef->proto,
elemdef->vendor,
elemdef->id,
handler->name);
}
ed.id = elemdef->id;
ed.proto = elemdef->proto;
ed.vendor = elemdef->vendor;
ed.mand = elemdef->mand;
result = mavl_replace(msgdata->elements_tree, &ed, &replaced);
if (!replaced) {
cw_dbg(DBG_MOD, " adding message element %d %d %d - %s",
elemdef->proto,
elemdef->vendor, elemdef->id, handler->name);
} else {
cw_dbg(DBG_MOD, " replacing message element %d %d %d - %s",
elemdef->proto,
elemdef->vendor, elemdef->id, handler->name);
}
}
return 0;
}
int cw_msgset_add(struct cw_MsgSet * set,
struct cw_MsgDef messages[],
struct cw_ElemHandler handlers[]
){
int cw_msgset_add(struct cw_MsgSet *set,
struct cw_MsgDef messages[], struct cw_ElemHandler handlers[]
)
{
struct cw_ElemHandler * handler;
struct cw_MsgDef * msgdef;
struct cw_ElemHandler *handler;
struct cw_MsgDef *msgdef;
/* Create mavl for all handlers */
for(handler = handlers; handler->id; handler++){
cw_dbg(DBG_MOD,"Adding handler for element %d - %s - with key: %s",
handler->id,
handler->name,
handler->key);
mavl_replace(set->handlers_by_id,handler,NULL);
mavl_replace(set->handlers_by_key,handler,NULL);
for (handler = handlers; handler->id; handler++) {
cw_dbg(DBG_MOD, "Adding handler for element %d - %s - with key: %s",
handler->id, handler->name, handler->key);
mavl_replace(set->handlers_by_id, handler, NULL);
mavl_replace(set->handlers_by_key, handler, NULL);
}
for (msgdef=messages; msgdef->type !=0; msgdef++){
for (msgdef = messages; msgdef->type != 0; msgdef++) {
struct cw_MsgData search;
struct cw_MsgData *msg;
int exists;
/* Look if message already exists */
search.type=msgdef->type;
msg = mavl_add(set->msgdata,&search,&exists);
if (msg == NULL){
cw_log(LOG_ERR,"Can't create messae");
return 0;
/* Look if message already exists */
search.type = msgdef->type;
msg = mavl_add(set->msgdata, &search, &exists);
if (msg == NULL) {
cw_log(LOG_ERR, "Can't create messae");
return 0;
}
if (!exists){
msg->elements_tree = mavl_create(cmp_elemdata,NULL,
sizeof(struct cw_ElemData));
if (!exists) {
msg->elements_tree = mavl_create(cmp_elemdata, NULL,
sizeof(struct cw_ElemData));
}
/* Overwrite the found message */
if (msgdef->name)
msg->name=msgdef->name;
msg->name = msgdef->name;
if (msgdef->states)
msg->states=msgdef->states;
msg->receiver=msgdef->receiver;
msg->states = msgdef->states;
msg->receiver = msgdef->receiver;
cw_dbg(DBG_MOD, "Add message Type:%d - %s ",msgdef->type,msgdef->name);
cw_dbg(DBG_MOD, "Add message Type:%d - %s ", msgdef->type, msgdef->name);
update_msgdata(set,msg,msgdef);
update_msgdata(set, msg, msgdef);
}
return 0;
@ -252,8 +245,9 @@ int cw_msgset_add(struct cw_MsgSet * set,
* @param type message type to search for
* @return message data or NULL if not found
*/
struct cw_MsgData * cw_msgset_get_msgdata(struct cw_MsgSet *set,int type){
struct cw_MsgData *cw_msgset_get_msgdata(struct cw_MsgSet *set, int type)
{
struct cw_MsgData search;
search.type=type;
return mavl_find_ptr(set->msgdata,&search);
search.type = type;
return mavl_find_ptr(set->msgdata, &search);
}

View File

@ -16,6 +16,7 @@ OBJS=\
capwap_out_ac_ip_list.o \
capwap_in_session_id.o \
capwap_in_vendor_specific_payload.o \
capwap_in_mtu_discovery_padding.o
LIBDIR := ../../../lib

View File

@ -88,6 +88,18 @@ static struct cw_ElemHandler handlers[] = {
capwap_in_vendor_specific_payload /* get */
}
,
{
"MTU Discovery Padding", /* name */
CAPWAP_ELEM_MTU_DISCOVERY_PADDING, /* Element ID */
0,0, /* Vendor / Proto */
0,0, /* min/max length */
NULL, /* type */
NULL, /* Key */
capwap_in_mtu_discovery_padding /* get */
}
,
{0,0,0,0,0,0,0,0}
@ -97,10 +109,11 @@ static struct cw_ElemHandler handlers[] = {
static int discovery_request_states[] = {CAPWAP_STATE_DISCOVERY,0};
static struct cw_ElemDef discovery_request_elements[] ={
{0,0,CAPWAP_ELEM_DISCOVERY_TYPE, 1, 0},
{0,0,CAPWAP_ELEM_WTP_MAC_TYPE, 1, 0},
{0,0,CAPWAP_ELEM_WTP_BOARD_DATA, 1, 0},
{0,0,CAPWAP_ELEM_WTP_DESCRIPTOR, 1, 0},
{0,0,CAPWAP_ELEM_WTP_DESCRIPTOR, 1, 0},
{0,0,CAPWAP_ELEM_WTP_FRAME_TUNNEL_MODE, 1, 0},
{0,0,CAPWAP_ELEM_WTP_MAC_TYPE, 1, 0},
{0,0,CAPWAP_ELEM_MTU_DISCOVERY_PADDING, 0, 0},
{0,0,CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, 0, 0},
{0,0,0,0,0}

View File

@ -16,16 +16,18 @@
*/
#include "cw.h"
#include "dbg.h"
#include "cw/capwap.h"
#include "cw/msget.h"
#include "cw/dbg.h"
int cw_in_mtu_discovery_padding(struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len,struct sockaddr *from)
int capwap_in_mtu_discovery_padding(struct cw_ElemHandler *eh,
struct cw_ElemHandlerParams *params, uint8_t * data,
int len)
{
int i, n = 0;
int i, n;
n = 0;
for (i = 0; i < len; i++) {
if (data[i] != 0xff)
n++;
@ -34,8 +36,8 @@ int cw_in_mtu_discovery_padding(struct conn *conn, struct cw_action_in *a,
cw_dbg(DBG_RFC,
"MTU discovery padding msg elem contains %d non-0xFF byte(s) out of %d, See RFC 5415.",
n, len);
if (conn->strict_capwap)
return 0;
if (params->conn->strict_capwap)
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
}
return 1;
return CAPWAP_RESULT_SUCCESS;
}

View File

@ -25,6 +25,10 @@ int capwap_in_vendor_specific_payload(struct cw_ElemHandler *handler,
struct cw_ElemHandlerParams *params,
uint8_t * data, int len);
int capwap_in_mtu_discovery_padding(struct cw_ElemHandler *eh,
struct cw_ElemHandlerParams *params, uint8_t * data,
int len);
/*
extern int capwap_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a,
uint8_t * dst);