Debugging colored, cool
FossilOrigin-Name: b62ab94004ae914a6c042383ef399141a1a82e49408b6ae3b1422ba3c72733b1
This commit is contained in:
parent
7832ca1336
commit
34646183a1
@ -3,9 +3,9 @@
|
||||
<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="Yes"/>
|
||||
<Project Name="libcw" Path="libcw.project" Active="No"/>
|
||||
<Project Name="mod_capwap80211" Path="mod_capwap80211.project" Active="No"/>
|
||||
<Project Name="mod_fortinet" Path="mod_fortinet.project" Active="No"/>
|
||||
<BuildMatrix>
|
||||
|
@ -43,7 +43,6 @@
|
||||
<File Name="src/cw/radioinfo.h"/>
|
||||
<File Name="src/cw/capwap80211.h"/>
|
||||
<File Name="src/cw/conn_init.c"/>
|
||||
<File Name="src/cw/item_strings.c"/>
|
||||
<File Name="src/cw/strheap.h"/>
|
||||
<File Name="src/cw/cw_in_check_join_req.c"/>
|
||||
<File Name="src/cw/cw_put_radio_operational_states.c"/>
|
||||
@ -236,7 +235,6 @@
|
||||
<File Name="src/cw/timer.h"/>
|
||||
<File Name="src/cw/mavl_foreach.c"/>
|
||||
<File Name="src/cw/lwapp_cisco.h"/>
|
||||
<File Name="src/cw/hdr_print.c"/>
|
||||
<File Name="src/cw/cw_init_data_keep_alive_msg.c"/>
|
||||
<File Name="src/cw/capwap_strings_item.c"/>
|
||||
<File Name="src/cw/cw_out_ac_name_with_priority.c"/>
|
||||
@ -299,6 +297,7 @@
|
||||
<File Name="src/cw/cw_dbg_set_level.c"/>
|
||||
<File Name="src/cw/cw_dbg_set_level_from_str.c"/>
|
||||
<File Name="src/cw/ansi_colors.h"/>
|
||||
<File Name="src/cw/cw_clock_lap.c"/>
|
||||
</VirtualDirectory>
|
||||
</VirtualDirectory>
|
||||
<Description/>
|
||||
|
@ -227,7 +227,7 @@ int main (int argc, char *argv[])
|
||||
|
||||
fclose(file);
|
||||
|
||||
cw_ktv_dump(global_cfg,DBG_INFO,NULL,"CFG:",NULL);
|
||||
cw_dbg_ktv_dump(global_cfg,DBG_INFO,NULL,"CFG:",NULL);
|
||||
actube_global_cfg = global_cfg;
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
#define ANSI_YELLOW "\x1b[33m"
|
||||
#define ANSI_BLUE "\x1b[34m"
|
||||
#define ANSI_MAGENTA "\x1b[35m"
|
||||
#define ANSI_CYAN "\x1b[35m"
|
||||
#define ANSI_CYAN "\x1b[36m"
|
||||
#define ANSI_WHITE "\x1b[37m"
|
||||
|
||||
#define ANSI_BBLACK "\x1b[90m"
|
||||
@ -19,7 +19,7 @@
|
||||
#define ANSI_BYELLOW "\x1b[93m"
|
||||
#define ANSI_BBLUE "\x1b[94m"
|
||||
#define ANSI_BMAGENTA "\x1b[95m"
|
||||
#define ANSI_BCYAN "\x1b[95m"
|
||||
#define ANSI_BCYAN "\x1b[96m"
|
||||
#define ANSI_BWHITE "\x1b[97m"
|
||||
|
||||
#define ANSI_ITALIC "\x1b[3m"
|
||||
|
@ -355,7 +355,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
mand_found = mavl_create_conststr();
|
||||
unrecognized = mlist_create(NULL,NULL,sizeof(uint8_t*));
|
||||
|
||||
cw_dbg(DBG_MSG_PARSING ,"*** parsing message elemtns in %d - (%s) ***",
|
||||
cw_dbg(DBG_MSG_PARSING ,"*** Parsing message of type %d - (%s) ***",
|
||||
message->type,message->name);
|
||||
/* iterate through message elements */
|
||||
cw_foreach_elem(elem, elems_ptr, elems_len) {
|
||||
@ -394,6 +394,10 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
mlist_append(unrecognized,&elem);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (rc < 0 ){
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -403,32 +407,16 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
|
||||
cw_check_missing_mand(message,mand_found);
|
||||
|
||||
cw_dbg(DBG_MSG_PARSING," *** done parsing message elements in %d (%s) ***",
|
||||
cw_dbg(DBG_MSG_PARSING," *** Done parsing message of type %d (%s) ***",
|
||||
message->type,message->name);
|
||||
|
||||
mavl_destroy(mand_found);
|
||||
|
||||
cw_dbg_ktv_dump(conn->remote_cfg,DBG_CFG_DMP,
|
||||
" *** Remote CFG dump ***", "CFG:", " *** End of remote CFG dump");
|
||||
|
||||
{
|
||||
|
||||
mavliter_t it;
|
||||
const struct cw_Type * type;
|
||||
cw_dbg (DBG_INFO, "********** THE REMOTE CFG **************\n");
|
||||
mavliter_init(&it,conn->remote_cfg);
|
||||
|
||||
|
||||
mavliter_foreach(&it){
|
||||
char value[500];
|
||||
struct cw_KTV * data;
|
||||
data = mavliter_get(&it);
|
||||
type = data->type;
|
||||
type->to_str(data,value,0);
|
||||
|
||||
cw_dbg(DBG_INFO,"RMTCFG: %s (%s): %s",data->key,type->name, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
mlistelem_t *e;
|
||||
mlist_foreach(e,unrecognized){
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
uint8_t * conn_q_get_packet(struct conn * conn)
|
||||
{
|
||||
int qrpos;
|
||||
struct timespec timespec;
|
||||
clock_gettime(CLOCK_REALTIME,×pec);
|
||||
timespec.tv_sec++;
|
||||
@ -30,7 +31,7 @@ uint8_t * conn_q_get_packet(struct conn * conn)
|
||||
return NULL;
|
||||
};
|
||||
|
||||
int qrpos = conn->qrpos+1;
|
||||
qrpos = conn->qrpos+1;
|
||||
if (qrpos==conn->qsize)
|
||||
qrpos=0;
|
||||
conn->qrpos=qrpos;
|
||||
|
@ -11,5 +11,3 @@ double cw_clock_lap(struct timeval *tv)
|
||||
gettimeofday(&lap, NULL);
|
||||
return (cw_timevaltodouble(&lap) - cw_timevaltodouble(tv)) / 1000000.0;
|
||||
}
|
||||
|
||||
|
@ -1,26 +1,23 @@
|
||||
|
||||
#include "capwap.h"
|
||||
#include "msgset.h"
|
||||
#include "ktv.h"
|
||||
#include "log.h"
|
||||
|
||||
int cw_in_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
|
||||
uint8_t * elem_data, int elem_len){
|
||||
/* mavldata_t data, *result;
|
||||
char str[30];
|
||||
*/
|
||||
uint8_t * elem_data, int elem_len)
|
||||
{
|
||||
cw_KTV_t * result;
|
||||
|
||||
if (!handler->type){
|
||||
cw_log(LOG_ERR,"Can't handle element: %s, no type defined",handler->name);
|
||||
return 0;
|
||||
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
|
||||
}
|
||||
cw_ktv_add(params->conn->remote_cfg, handler->key, handler->type, elem_data,elem_len);
|
||||
|
||||
result = cw_ktv_add(params->conn->remote_cfg, handler->key,
|
||||
handler->type, elem_data,elem_len);
|
||||
|
||||
/*
|
||||
result = handler->type->get(&data,elem_data,elem_len);
|
||||
result->kv.key = strdup(handler->key);
|
||||
params->elem=result;
|
||||
|
||||
handler->type->to_str(result,str,30);
|
||||
mavl_add(conn->remote_cfg, result);
|
||||
*/
|
||||
return 0;
|
||||
return CAPWAP_RESULT_SUCCESS;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "log.h"
|
||||
#include "dbg.h"
|
||||
|
||||
const char * cw_ktv_add(mavl_t kvtstore, const char *key, const struct cw_Type *type,
|
||||
cw_KTV_t * cw_ktv_add(mavl_t kvtstore, const char *key, const struct cw_Type *type,
|
||||
const uint8_t * data, int len)
|
||||
{
|
||||
cw_KTV_t mdata, *mresult;
|
||||
@ -15,7 +15,7 @@ const char * cw_ktv_add(mavl_t kvtstore, const char *key, const struct cw_Type *
|
||||
*/
|
||||
mdata.key=cw_strdup(key);
|
||||
if (!mdata.key){
|
||||
cw_log(LOG_ERR, "Can't allocate memory for key %s: %s",
|
||||
cw_log(LOG_ERR, "Can't allocate memory for KTV key %s: %s",
|
||||
key,strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
@ -35,8 +35,8 @@ const char * cw_ktv_add(mavl_t kvtstore, const char *key, const struct cw_Type *
|
||||
free(mdata.key);
|
||||
if (type->del)
|
||||
type->del(&mdata);
|
||||
return key;
|
||||
return mresult;
|
||||
}
|
||||
|
||||
return mdata.key;
|
||||
return mresult;
|
||||
}
|
||||
|
@ -1,30 +1,3 @@
|
||||
#include "ktv.h"
|
||||
#include "dbg.h"
|
||||
|
||||
|
||||
void cw_ktv_dump(mavl_t ktv, uint32_t dbglevel,
|
||||
const char *header, const char *prefix, const char *footer )
|
||||
{
|
||||
char value[500];
|
||||
struct cw_KTV * data;
|
||||
mavliter_t it;
|
||||
const struct cw_Type * type;
|
||||
|
||||
if (header != NULL)
|
||||
cw_dbg (dbglevel, header);
|
||||
|
||||
mavliter_init(&it,ktv);
|
||||
|
||||
mavliter_foreach(&it){
|
||||
|
||||
data = mavliter_get(&it);
|
||||
type = data->type;
|
||||
type->to_str(data,value,0);
|
||||
|
||||
cw_dbg(dbglevel,"%s%s (%s): %s",prefix,data->key,type->name, value);
|
||||
}
|
||||
|
||||
if (footer != NULL)
|
||||
cw_dbg (dbglevel, footer);
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,9 @@ int cw_process_element(struct cw_ElemHandlerParams *params, int proto, int vendo
|
||||
|
||||
struct cw_ElemHandler * handler;
|
||||
struct cw_ElemData * elem_data, elem_data_search;
|
||||
int rc;
|
||||
|
||||
params->elem=NULL;
|
||||
|
||||
/* try to retrieve a handler for this message element */
|
||||
handler = cw_msgset_get_elemhandler(params->conn->msgset,proto, vendor, elem_id);
|
||||
@ -37,10 +40,6 @@ 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,
|
||||
@ -49,6 +48,13 @@ int cw_process_element(struct cw_ElemHandlerParams *params, int proto, int vendo
|
||||
handler->min_len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (elem_data->mand){
|
||||
mavl_add_str(params->mand_found,handler->key);
|
||||
}
|
||||
|
||||
|
||||
if (len > handler->max_len && handler->max_len) {
|
||||
cw_dbg(DBG_ELEM_ERR,
|
||||
"%d (%s) message element too big, len=%d, max len=%d", handler->id,
|
||||
@ -57,8 +63,11 @@ int cw_process_element(struct cw_ElemHandlerParams *params, int proto, int vendo
|
||||
return -1;
|
||||
}
|
||||
|
||||
cw_dbg_elem(DBG_ELEM_IN, params->conn, params->msgdata->type, handler, params,
|
||||
cw_dbg_elem(DBG_ELEM_IN, params->conn, params->msgdata->type, handler,
|
||||
data,len);
|
||||
|
||||
return handler->get(handler, params, data, len);
|
||||
rc = handler->get(handler, params, data, len);
|
||||
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
|
||||
l = handler->put(handler,¶ms,dst+len);
|
||||
|
||||
if(l>0)
|
||||
cw_dbg_elem(DBG_ELEM_OUT,conn,type,handler,¶ms,dst+len,l);
|
||||
cw_dbg_elem(DBG_ELEM_OUT,conn,type,handler,dst+len,l);
|
||||
len += l;
|
||||
}
|
||||
|
||||
|
45
src/cw/dbg.c
45
src/cw/dbg.c
@ -90,6 +90,7 @@ static struct cw_StrListElem color_on[] = {
|
||||
{DBG_X, "\x1b[31m"},
|
||||
{DBG_WARN, ANSI_CYAN},
|
||||
{DBG_MOD, ANSI_WHITE},
|
||||
{DBG_CFG_DMP, ANSI_BCYAN },
|
||||
|
||||
|
||||
{CW_STR_STOP, ""}
|
||||
@ -129,6 +130,7 @@ static struct cw_StrListElem prefix[] = {
|
||||
{DBG_DTLS_DETAIL, " DTLS - "},
|
||||
{DBG_WARN, " Warning - "},
|
||||
{DBG_MOD, " Mod - "},
|
||||
|
||||
{DBG_X, "XXXXX - "},
|
||||
|
||||
{CW_STR_STOP, ""}
|
||||
@ -466,9 +468,7 @@ void cw_dbg(int level, const char *format, ...){
|
||||
|
||||
|
||||
void cw_dbg_elem(int level, struct conn *conn, int msg,
|
||||
struct cw_ElemHandler * handler,
|
||||
struct cw_ElemHandlerParams *params,
|
||||
const uint8_t * msgbuf, int len)
|
||||
struct cw_ElemHandler * handler, const uint8_t * msgbuf, int len)
|
||||
{
|
||||
char vendorname[256];
|
||||
char vendor_details[265];
|
||||
@ -486,17 +486,9 @@ void cw_dbg_elem(int level, struct conn *conn, int msg,
|
||||
sprintf(vendorname,"");
|
||||
}
|
||||
|
||||
if (params->elem == NULL) {
|
||||
cw_dbg(level,"%s %d (%s), len=%d ",vendorname,handler->id,
|
||||
|
||||
cw_dbg(level,"%s %d (%s), len=%d ",vendorname,handler->id,
|
||||
handler->name,len);
|
||||
}else {
|
||||
char str[512];
|
||||
params->elem->type->to_str(params->elem,str,512);
|
||||
cw_dbg(level,"%s %d (%s), len=%d, val=%s ",vendorname,handler->id,
|
||||
handler->name,len, str);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (cw_dbg_is_level(DBG_ELEM_DMP)) {
|
||||
/*dmp = cw_format_dump(msgbuf,len,NULL);*/
|
||||
@ -510,6 +502,33 @@ void cw_dbg_elem(int level, struct conn *conn, int msg,
|
||||
|
||||
|
||||
|
||||
void cw_dbg_ktv_dump(mavl_t ktv, uint32_t dbglevel,
|
||||
const char *header, const char *prefix, const char *footer )
|
||||
{
|
||||
char value[500];
|
||||
struct cw_KTV * data;
|
||||
mavliter_t it;
|
||||
const struct cw_Type * type;
|
||||
|
||||
if (header != NULL)
|
||||
cw_dbg (dbglevel, header);
|
||||
|
||||
mavliter_init(&it,ktv);
|
||||
|
||||
mavliter_foreach(&it){
|
||||
|
||||
data = mavliter_get(&it);
|
||||
type = data->type;
|
||||
type->to_str(data,value,0);
|
||||
|
||||
cw_dbg(dbglevel,"%s%s (%s): %s",prefix,data->key,type->name, value);
|
||||
}
|
||||
|
||||
if (footer != NULL)
|
||||
cw_dbg (dbglevel, footer);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
16
src/cw/dbg.h
16
src/cw/dbg.h
@ -112,6 +112,8 @@ enum cw_dbg_levels{
|
||||
|
||||
/** Show DTLS Details */
|
||||
DBG_DTLS_DETAIL,
|
||||
|
||||
DBG_CFG_DMP,
|
||||
|
||||
/** Debug Mods */
|
||||
DBG_MOD,
|
||||
@ -133,17 +135,18 @@ enum cw_dbg_levels{
|
||||
|
||||
#define DBG_LN __FILE__,__LINE__
|
||||
|
||||
|
||||
/*
|
||||
struct dbg_Context{
|
||||
int level;
|
||||
};
|
||||
*/
|
||||
|
||||
void cw_dbg_set_level (int level, int on);
|
||||
int cw_dbg_set_level_from_str(const char *level);
|
||||
|
||||
|
||||
/*
|
||||
void cw_dbg_elem_(struct conn * conn, int msg, int msgelem, const uint8_t * msgbuf, int len);
|
||||
|
||||
*/
|
||||
/*
|
||||
void cw_dbg_missing_mand(int level,struct conn *conn,cw_action_in_t ** ml,int n,cw_action_in_t *a);
|
||||
*/
|
||||
@ -195,9 +198,7 @@ void cw_dbg_dmp_(int level, const uint8_t * data, int len, const char *format, .
|
||||
|
||||
|
||||
void cw_dbg_elem(int level, struct conn *conn, int msg,
|
||||
struct cw_ElemHandler * handler, struct
|
||||
cw_ElemHandlerParams * params,
|
||||
const uint8_t * msgbuf, int len);
|
||||
struct cw_ElemHandler * handler, const uint8_t * msgbuf, int len);
|
||||
|
||||
|
||||
void cw_dbg_pkt_nc(int level,struct netconn *nc, uint8_t * packet, int len,struct sockaddr *from);
|
||||
@ -206,7 +207,8 @@ void cw_dbg_msg(int level,struct conn *conn, uint8_t * packet, int len,struct so
|
||||
char * cw_dbg_mkdmp(const uint8_t * data, int len);
|
||||
void cw_dbg_version_subelem(int level, const char *context, int subtype,
|
||||
uint32_t vendor_id, const uint8_t * vstr, int len);
|
||||
|
||||
void cw_dbg_ktv_dump(mavl_t ktv, uint32_t dbglevel,
|
||||
const char *header, const char *prefix, const char *footer );
|
||||
|
||||
/**
|
||||
* Set debug level
|
||||
|
@ -63,6 +63,8 @@ struct cw_StrListElem cw_dbg_strings[] = {
|
||||
{ DBG_DTLS_BIO_DMP, "dtls_bio_dmp"},
|
||||
{ DBG_DTLS_DETAIL, "dtls_detail"},
|
||||
|
||||
{DBG_CFG_DMP, "cfg_dmp" },
|
||||
|
||||
{ DBG_WARN, "warn" },
|
||||
|
||||
{ DBG_MOD,"mod"},
|
||||
|
@ -48,8 +48,8 @@ static const char * ssl_version2str(int version)
|
||||
return "TLSv1";
|
||||
case DTLS1_VERSION:
|
||||
return "DTLSv1";
|
||||
// case DTLS1_2_VERSION:
|
||||
// return "DTLSv1.2";
|
||||
/* case DTLS1_2_VERSION:
|
||||
return "DTLSv1.2"; */
|
||||
}
|
||||
return "Version unknown";
|
||||
}
|
||||
@ -65,7 +65,7 @@ static void dtls_debug_cb(int write_p,int version,int type, const void * buf,siz
|
||||
s += sprintf(s,"SSL msg in: ");
|
||||
|
||||
s+=sprintf(s,"type = %d (0x%02X), %s (%08x), len = %d",type,type,ssl_version2str(version),version,(int)len);
|
||||
// cw_dbg(DBG_DTLS_DETAIL,buffer);
|
||||
/* cw_dbg(DBG_DTLS_DETAIL,buffer); */
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -121,7 +121,7 @@ int pem_passwd_cb(char *buf, int size, int rwflag, void *password)
|
||||
if (rsa_1024)
|
||||
rsa_tmp=rsa_1024;
|
||||
else
|
||||
exit(0); //should_not_happen_in_this_example();
|
||||
exit(0); /* should_not_happen_in_this_example(); */
|
||||
break;
|
||||
default:
|
||||
/* Generating a key on the fly is very costly, so use what is there */
|
||||
@ -139,9 +139,10 @@ int pem_passwd_cb(char *buf, int size, int rwflag, void *password)
|
||||
|
||||
int dtls_openssl_init()
|
||||
{
|
||||
int rc;
|
||||
const char * version = SSLeay_version(SSLEAY_VERSION);
|
||||
cw_dbg(DBG_INFO,"Init SSL library - %s",version);
|
||||
int rc = SSL_library_init();
|
||||
rc = SSL_library_init();
|
||||
ERR_clear_error();
|
||||
SSL_load_error_strings();
|
||||
OpenSSL_add_all_algorithms();
|
||||
@ -151,11 +152,12 @@ int dtls_openssl_init()
|
||||
|
||||
int dtls_openssl_log_error_queue(const char *txt)
|
||||
{
|
||||
char errstr[256];
|
||||
|
||||
int e = ERR_get_error();
|
||||
if (e==0)
|
||||
return 0;
|
||||
|
||||
char errstr[256];
|
||||
while (e!=0){
|
||||
ERR_error_string(e,errstr);
|
||||
cw_log(LOG_ERR,"%s - %s",txt,errstr);
|
||||
@ -166,16 +168,18 @@ int dtls_openssl_log_error_queue(const char *txt)
|
||||
|
||||
int dtls_openssl_log_error(SSL * ssl, int rc, const char *txt)
|
||||
{
|
||||
char errstr[256];
|
||||
int e;
|
||||
int en = errno; /* save errno */
|
||||
|
||||
if (!ssl){
|
||||
return dtls_openssl_log_error_queue(txt);
|
||||
}
|
||||
|
||||
int e;
|
||||
|
||||
e = SSL_get_error(ssl,rc);
|
||||
|
||||
char errstr[256];
|
||||
|
||||
ERR_error_string(e,errstr);
|
||||
cw_log(LOG_ERR,"%s - %s","SSSSS",errstr);
|
||||
|
||||
@ -254,10 +258,8 @@ int generate_session_id(const SSL *ssl, unsigned char * id, unsigned int *id_len
|
||||
/* BIO * b = SSL_get_rbio(ssl);
|
||||
struct conn * conn = b->ptr;
|
||||
*/
|
||||
|
||||
|
||||
printf ("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMaking session id\n");
|
||||
const char * sessid = "9123456789";
|
||||
/* printf ("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMaking session id\n");*/
|
||||
memcpy(id,sessid,strlen(sessid));
|
||||
*id_len=strlen(sessid);
|
||||
return 1;
|
||||
@ -267,11 +269,11 @@ int generate_session_id(const SSL *ssl, unsigned char * id, unsigned int *id_len
|
||||
|
||||
static int dtls_verify_peer_callback (int ok, X509_STORE_CTX *ctx)
|
||||
{
|
||||
printf ("Verify callback called with ok = %d\n",ok);
|
||||
/* printf ("Verify callback called with ok = %d\n",ok);*/
|
||||
|
||||
// SSL *ssl;
|
||||
/*// SSL *ssl;
|
||||
// ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
|
||||
|
||||
*/
|
||||
char buf[1024];
|
||||
X509 *err_cert;
|
||||
|
||||
@ -304,6 +306,7 @@ static unsigned int psk_server_cb(SSL *ssl,const char *identity, unsigned char *
|
||||
|
||||
struct dtls_openssl_data * dtls_openssl_data_create(struct conn * conn, const SSL_METHOD * method, BIO_METHOD * bio)
|
||||
{
|
||||
int rc;
|
||||
struct dtls_openssl_data * d = malloc(sizeof(struct dtls_openssl_data));
|
||||
if (!d)
|
||||
return NULL;
|
||||
@ -317,7 +320,7 @@ struct dtls_openssl_data * dtls_openssl_data_create(struct conn * conn, const SS
|
||||
}
|
||||
|
||||
|
||||
int rc = SSL_CTX_set_cipher_list(d->ctx, conn->dtls_cipher);
|
||||
rc = SSL_CTX_set_cipher_list(d->ctx, conn->dtls_cipher);
|
||||
if (!rc){
|
||||
dtls_openssl_log_error(0,rc,"DTLS setup cipher error:");
|
||||
dtls_openssl_data_destroy(d);
|
||||
@ -372,28 +375,29 @@ struct dtls_openssl_data * dtls_openssl_data_create(struct conn * conn, const SS
|
||||
|
||||
|
||||
|
||||
// SSL_CTX_set_session_cache_mode(d->ctx, SSL_SESS_CACHE_BOTH);
|
||||
/*// SSL_CTX_set_session_cache_mode(d->ctx, SSL_SESS_CACHE_BOTH);*/
|
||||
SSL_CTX_set_options(d->ctx, SSL_OP_NO_SSLv2 |SSL_OP_NO_SSLv3 );
|
||||
// SSL_CTX_set_generate_session_id(d->ctx,generate_session_id);
|
||||
/*// SSL_CTX_set_generate_session_id(d->ctx,generate_session_id);*/
|
||||
|
||||
|
||||
SSL_CTX_set_timeout(d->ctx,30);
|
||||
|
||||
/*
|
||||
// rc =SSL_CTX_set_max_proto_version (d->ctx,DTLS1_VERSION);
|
||||
// printf("MAXMAMX = %d\n",rc);
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
// SSL_CTX_set_verify(d->ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, dtls_verify_callback);
|
||||
// SSL_CTX_set_verify(d->ctx, SSL_VERIFY_PEER, dtls_verify_callback);
|
||||
|
||||
// SSL_CTX_set_tmp_rsa_callback(d->ctx,tmp_rsa_callback);
|
||||
|
||||
// SSL_CTX_set_mode(d->ctx,SSL_MODE_SEND_SERVERHELLO_TIME);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
// rsa_512 = RSA_generate_key(512,RSA_F4,NULL,NULL);
|
||||
// if (rsa_512 == NULL)
|
||||
// evaluate_error_queue();
|
||||
@ -404,7 +408,7 @@ struct dtls_openssl_data * dtls_openssl_data_create(struct conn * conn, const SS
|
||||
|
||||
|
||||
// printf ("Ver cookie rc %d\n",rc);
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
if (conn->dtls_key_file && conn->dtls_cert_file){
|
||||
@ -489,15 +493,17 @@ out_err:
|
||||
|
||||
|
||||
#include <arpa/inet.h>
|
||||
//#include <socket.h>
|
||||
/*//#include <socket.h>*/
|
||||
#include <netinet/in.h>
|
||||
|
||||
int dtls_openssl_shutdown(struct conn *conn)
|
||||
{
|
||||
struct dtls_openssl_data * d ;
|
||||
|
||||
conn->write = conn->send_packet;
|
||||
conn->read = conn->recv_packet;
|
||||
|
||||
struct dtls_openssl_data * d = (struct dtls_openssl_data*)conn->dtls_data;
|
||||
d = (struct dtls_openssl_data*)conn->dtls_data;
|
||||
if (!d)
|
||||
return 0;
|
||||
|
||||
@ -525,13 +531,14 @@ int dtls_openssl_shutdown(struct conn *conn)
|
||||
|
||||
|
||||
|
||||
//int cookie_initialized=0;
|
||||
/*//int cookie_initialized=0;
|
||||
//#define COOKIE_SECRET_LENGTH 16
|
||||
//unsigned char cookie_secret[COOKIE_SECRET_LENGTH];
|
||||
|
||||
*/
|
||||
int dtls_openssl_generate_cookie(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
char sock_buf2[SOCK_ADDR_BUFSIZE];
|
||||
|
||||
BIO * b = SSL_get_rbio(ssl);
|
||||
struct conn * conn = b->ptr;
|
||||
@ -540,7 +547,7 @@ int dtls_openssl_generate_cookie(SSL *ssl, unsigned char *cookie, unsigned int *
|
||||
|
||||
/* we "missuse" sockaddr2str to convert our cookie to a hex str */
|
||||
cw_dbg(DBG_DTLS,"DTLS session cookie for %s generated: %s",
|
||||
sock_addr2str(&conn->addr,sock_buf), sock_hwaddr2idstr(conn->dtls_cookie,sizeof(conn->dtls_cookie)));
|
||||
sock_addr2str(&conn->addr,sock_buf), sock_hwaddr2idstr(conn->dtls_cookie,sizeof(conn->dtls_cookie),sock_buf2));
|
||||
|
||||
memcpy(cookie,conn->dtls_cookie,sizeof(conn->dtls_cookie));
|
||||
*cookie_len=sizeof(conn->dtls_cookie);
|
||||
@ -548,17 +555,15 @@ int dtls_openssl_generate_cookie(SSL *ssl, unsigned char *cookie, unsigned int *
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int dtls_openssl_verify_cookie(SSL *ssl, unsigned char *cookie, unsigned int len)
|
||||
{
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
char sock_buf2[SOCK_ADDR_BUFSIZE];
|
||||
BIO * b = SSL_get_rbio(ssl);
|
||||
struct conn * conn = b->ptr;
|
||||
|
||||
cw_dbg(DBG_DTLS,"Verifying DTLS cookie from %s: %s",
|
||||
sock_addr2str(&conn->addr,sock_buf),sock_hwaddr2idstr(conn->dtls_cookie,len));
|
||||
sock_addr2str(&conn->addr,sock_buf),sock_hwaddr2idstr(conn->dtls_cookie,len,sock_buf2));
|
||||
|
||||
if (len != sizeof(conn->dtls_cookie)){
|
||||
return 0;
|
||||
|
@ -1,123 +0,0 @@
|
||||
/*
|
||||
This file is part of libcapwap.
|
||||
|
||||
libcapwap 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/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "capwap.h"
|
||||
#include "sock.h"
|
||||
|
||||
/*
|
||||
|
||||
int hdr_print(char *str, uint8_t *packet, int len)
|
||||
{
|
||||
|
||||
|
||||
char *s = str;
|
||||
|
||||
|
||||
if (len<1){
|
||||
s+=sprintf(s,"\tNo info available.");
|
||||
return s-str;
|
||||
}
|
||||
|
||||
int preamble = cw_get_hdr_preamble(packet); //CWTH_GET_PREAMBLE(packet);
|
||||
|
||||
if (preamble==01){
|
||||
s+=sprintf(s,"\tEncrypted data.");
|
||||
return s-str;
|
||||
}
|
||||
|
||||
if (preamble!=00){
|
||||
s+=sprintf(s,"\tWrong CAPWAP version or encryption type.");
|
||||
return s-str;
|
||||
}
|
||||
|
||||
|
||||
if (len < 4){
|
||||
s+=sprintf(s,"\tNo more data. Packet too short.");
|
||||
return s-str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int hlen = cw_get_hdr_hlen(packet); //CWTH_GET_HLEN(packet);
|
||||
int rid = cw_get_hdr_rid(packet);
|
||||
int wbid = cw_get_hdr_wbid(packet);
|
||||
s+=sprintf(s,"\tHLEN: %d, RID: %02X, WBID %02X",hlen,rid,wbid);
|
||||
|
||||
|
||||
|
||||
s+=sprintf(s," Flags: (T=%d,F=%d,L=%d,W=%d,M=%d,K=%d)\n",
|
||||
cw_get_hdr_flag_t(packet),
|
||||
cw_get_hdr_flag_f(packet),
|
||||
cw_get_hdr_flag_l(packet),
|
||||
cw_get_hdr_flag_w(packet),
|
||||
cw_get_hdr_flag_m(packet),
|
||||
cw_get_hdr_flag_k(packet)
|
||||
);
|
||||
if (cw_get_hdr_flag_m(packet)){
|
||||
uint8_t * rmac = cw_get_hdr_rmac(packet);
|
||||
s+=sprintf(s,"\tRadio MAC: %s\n",sock_hwaddr2str(bstr_data(rmac),
|
||||
bstr_len(rmac)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (len < 8){
|
||||
s+=sprintf(s,"\tNo more data. Packet too short.");
|
||||
return s-str;
|
||||
}
|
||||
|
||||
int frag_id = cw_get_hdr_fragid(packet);
|
||||
int frag_offs = cw_get_hdr_fragoffset(packet);
|
||||
s+=sprintf(s,"\tFrag Id: %d, Frag Offs:: %d\n",frag_id,frag_offs);
|
||||
|
||||
|
||||
int bhlen = 4*hlen;
|
||||
if (cw_get_hdr_flag_f(packet) && frag_offs!=0){
|
||||
s+=sprintf(s,"\tFragment data ...");
|
||||
return s-str;
|
||||
}
|
||||
|
||||
|
||||
if (len<bhlen+4){
|
||||
s+=sprintf(s,"\tNo more data. Packet too short.");
|
||||
return s-str;
|
||||
}
|
||||
|
||||
|
||||
int msgtype = ntohl(*((uint32_t*)(packet+bhlen)));
|
||||
s+=sprintf(s,"\tMsgType: %d",msgtype);
|
||||
|
||||
if (len<bhlen+8){
|
||||
s+=sprintf(s,"\n\tNo more data. Packet too short.");
|
||||
return s-str;
|
||||
}
|
||||
|
||||
int seqnum = (ntohl(*((uint32_t*)(packet+bhlen+4))))>>24;
|
||||
int msgelemlen = 0xFF & ((ntohl(*((uint32_t*)(packet+bhlen+4))))>>8);
|
||||
|
||||
s+=sprintf(s,", SeqNum: %d, MsgelemLen:%d",seqnum,msgelemlen);
|
||||
|
||||
|
||||
return s-str;
|
||||
}
|
||||
|
||||
*/
|
41
src/cw/ktv.h
41
src/cw/ktv.h
@ -6,6 +6,18 @@
|
||||
|
||||
#include "mavl.h"
|
||||
|
||||
|
||||
/**
|
||||
* @addtogroup DATAMGMT Data Structures & Algos
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup KTV Key-Type-Value-Store
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define CW_KTV_MAX_KEY_LEN 1024
|
||||
|
||||
struct cw_KTV {
|
||||
@ -21,7 +33,12 @@ struct cw_KTV {
|
||||
};
|
||||
typedef struct cw_KTV cw_KTV_t;
|
||||
|
||||
|
||||
/**
|
||||
* @class cw_Type
|
||||
* @author 7u83
|
||||
* @file ktv.h
|
||||
* @brief Representation of a cw_Type objetc
|
||||
*/
|
||||
struct cw_Type {
|
||||
/** A human readable name for this type */
|
||||
const char *name;
|
||||
@ -36,8 +53,13 @@ struct cw_Type {
|
||||
struct cw_KTV *(*get) (struct cw_KTV * data, const uint8_t * src, int len);
|
||||
|
||||
/** A pointer to a function to convert elements of this type to a string.
|
||||
This function is mainly used to store elements to an SQL database
|
||||
or to json strings */
|
||||
* This function is mainly used to store elements to an SQL database
|
||||
* or to json strings
|
||||
* @param data pointer to KTV object
|
||||
* @param dst buffer where to put the string in
|
||||
* @param max_len maximum length of buffer
|
||||
* @return The number of bytes written to dst
|
||||
*/
|
||||
int (*to_str) (const struct cw_KTV * data, char *dst, int max_len);
|
||||
|
||||
/** Cereate an item of this type from a string, which was previously
|
||||
@ -63,7 +85,7 @@ extern const struct cw_Type cw_type_bstr16;
|
||||
/*
|
||||
void cw_kvstore_mavl_delete(const void *data);
|
||||
*/
|
||||
const char *cw_ktv_add(mavl_t kvstore, const char *key, const struct cw_Type *type,
|
||||
cw_KTV_t *cw_ktv_add(mavl_t kvstore, const char *key, const struct cw_Type *type,
|
||||
const uint8_t * data, int len);
|
||||
|
||||
const char * cw_ktv_add_from_str(mavl_t kvtstore, const char *key, const struct cw_Type *type,
|
||||
@ -74,6 +96,10 @@ int cw_ktv_mavlcmp_type_by_name(const void *v1,const void *v2);
|
||||
|
||||
void cw_ktv_mavldel(void *data);
|
||||
|
||||
/**
|
||||
* Create a KTV store
|
||||
* @return a #mavl_t object representing the KTV store
|
||||
*/
|
||||
#define cw_ktv_create()\
|
||||
mavl_create(cw_ktv_mavlcmp, cw_ktv_mavldel, sizeof(cw_KTV_t))
|
||||
|
||||
@ -85,12 +111,13 @@ int cw_ktv_read_file(FILE * file, mavl_t ktv, mavl_t types);
|
||||
cw_KTV_t * cw_ktv_get(mavl_t ktv, const char *key, const cw_Type_t * type);
|
||||
uint8_t cw_ktv_get_byte(mavl_t ktv,const char *key, uint8_t def);
|
||||
uint16_t cw_ktv_get_word(mavl_t ktv,const char *key, uint16_t def);
|
||||
|
||||
void cw_ktv_dump(mavl_t ktv, uint32_t dbglevel,
|
||||
const char *header, const char *prefix, const char *footer );
|
||||
|
||||
extern const cw_Type_t * cw_ktv_std_types[];
|
||||
#define CW_KTV_STD_TYPES cw_ktv_std_types
|
||||
|
||||
/**
|
||||
* @} KTV
|
||||
* @} DATAMGMT
|
||||
*/
|
||||
|
||||
#endif /* __KVT_H */
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*@file
|
||||
*@brief Definitions for logging and debugging.
|
||||
|
@ -157,8 +157,11 @@ void *mavl_replace_data ( struct mavl *t, void *data, int len );
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* An alias gor #mavl_get
|
||||
*/
|
||||
#define mavl_find(t,d) mavl_get(t,d)
|
||||
|
||||
#define mavl_find_ptr(tree,search_ptr) mavl_get_ptr(tree,search_ptr)
|
||||
#define mavl_insert(t,d) mavl_add(t,d)
|
||||
|
||||
|
@ -182,13 +182,14 @@ static int mavl_add0 ( struct mavl *t, struct mavlnode **parent, const void ** d
|
||||
* Add an element to an AVL tree
|
||||
*
|
||||
* @param t mavl
|
||||
* @param data pointer to element
|
||||
*
|
||||
* @return A pointer to the element in the tree. If teh returned pointer
|
||||
* equals to the pointer given in the data argument, the element has already
|
||||
* been in the tree. If the function returns NULL, there was en error, e.g.
|
||||
* no memory left. Consult therefore errno.
|
||||
*
|
||||
* @param data pointer to the element to add
|
||||
* @param exists pointer to an interger vairable which wil be set to 1, if
|
||||
* the element to add already exists in the tree. If the element did't
|
||||
* exist, the variable ist to 0.
|
||||
* @return A pointer to the element in the tree. If the element was added,
|
||||
* it the pointer to newly created element. If the element had already existed,
|
||||
* the pointer points to the existing element. mavl_add returns thero, if
|
||||
* something else went wrong. Therefore consult errno.
|
||||
* @example mavl_add_example.c
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,12 @@
|
||||
#include "mlist.h"
|
||||
|
||||
/**
|
||||
* @brief Create a mlist object
|
||||
* @param v1
|
||||
* @param v2
|
||||
* @param data_size
|
||||
* @return a pointer to the created object or NULL if something
|
||||
* wnet wrong.
|
||||
*/
|
||||
mlist_t mlist_create(int (*cmp) (const void *v1, const void *v2),
|
||||
void (*del)(void*),
|
||||
size_t data_size)
|
||||
|
@ -167,8 +167,8 @@ static int update_msgdata(struct cw_MsgSet *set, struct cw_MsgData *msgdata,
|
||||
elemdef->vendor, elemdef->id);
|
||||
/* check if a handler for our element already exists */
|
||||
if (!handler) {
|
||||
cw_log(LOG_ERR, "No handler for message element: %d %d %d",
|
||||
elemdef->proto, elemdef->vendor, elemdef->id);
|
||||
cw_log(LOG_ERR, "Creating message set: No handler for message element: %d %d %d [%s]",
|
||||
elemdef->proto, elemdef->vendor, elemdef->id, cw_strelem(elemdef->id));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,10 @@ char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen, int addp
|
||||
|
||||
#define SOCK_ADDR_BUFSIZE 64
|
||||
|
||||
/*
|
||||
#define SOCK_ADDR_BUF_DEFINE char __sock_buf__[SOCK_ADDR_BUFSIZE]
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Convert a sockaddr structure to a human readable string
|
||||
@ -113,8 +116,8 @@ char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen, int addp
|
||||
|
||||
|
||||
|
||||
#define sock_hwaddr2str(s,l) ( sock_hwaddrtostr( s,l, (char[64]){0}, ":" ) )
|
||||
#define sock_hwaddr2idstr(s,l) ( sock_hwaddrtostr( s,l, (char[64]){0}, "" ) )
|
||||
#define sock_hwaddr2str(s,l,buf) ( sock_hwaddrtostr( s,l, buf, ":" ) )
|
||||
#define sock_hwaddr2idstr(s,l,buf) ( sock_hwaddrtostr( s,l, buf, "" ) )
|
||||
|
||||
/*
|
||||
//#define sock_addrtostr(s,str,n) sock_addrtostr(s,str,n,1)
|
||||
|
@ -42,7 +42,7 @@ typedef time_t cw_timer_t;
|
||||
* @code
|
||||
* cw_timer_t timer = cw_timer_start(60);
|
||||
* while (!cw_timer_timeout(timer)){
|
||||
* // Do something for max. 60 seconds ...
|
||||
* @startcomment Do something for max. 60 seconds ... @endcomment
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
@ -78,7 +78,7 @@ typedef time_t cw_timer_t;
|
||||
* @code
|
||||
* CW_CLOCK_DEFINE(clk);
|
||||
* cw_clock_start(clk);
|
||||
* // do something ...
|
||||
* @startcomment do something ... @endcomment
|
||||
* int t = cw_clock_lap(clk);
|
||||
* printf("Caclulation took %d seconds\n",t);
|
||||
* @endcode
|
||||
|
@ -54,7 +54,7 @@ static struct cw_ElemHandler handlers[] = {
|
||||
"WTP Board Data", /* name */
|
||||
CAPWAP_ELEM_WTP_BOARD_DATA, /* Element ID */
|
||||
0,0, /* Vendor / Proto */
|
||||
4,128, /* min/max length */
|
||||
14,1024, /* min/max length */
|
||||
NULL, /* type */
|
||||
CW_KEY_WTP_BOARD_DATA, /* Key */
|
||||
capwap_in_wtp_board_data, /* get */
|
||||
@ -65,7 +65,7 @@ static struct cw_ElemHandler handlers[] = {
|
||||
"WTP Descriptor", /* name */
|
||||
CAPWAP_ELEM_WTP_DESCRIPTOR, /* Element ID */
|
||||
0,0, /* Vendor / Proto */
|
||||
4,128, /* min/max length */
|
||||
33,1024, /* min/max length */
|
||||
NULL, /* type */
|
||||
CW_KEY_WTP_DESCRIPTOR, /* Key */
|
||||
capwap_in_wtp_descriptor, /* get */
|
||||
|
@ -55,7 +55,7 @@ static void readsubelems_wtp_board_data(mavl_t cfg, uint8_t * msgelem,
|
||||
return;
|
||||
}
|
||||
|
||||
cw_dbg(DBG_SUBELEM, "Reading WTP board data sub-element, type=%d, len=%d",
|
||||
cw_dbg(DBG_SUBELEM, "WTP board data sub-element, type=%d, len=%d",
|
||||
subtype, sublen);
|
||||
|
||||
switch (subtype) {
|
||||
|
@ -108,7 +108,7 @@ int main (int argc, char **argv)
|
||||
cw_ktv_read_file(file,global_cfg,types_tree);
|
||||
|
||||
|
||||
cw_ktv_dump(global_cfg,DBG_INFO,"----- global cfg start -----","","----- global cfg end -----");
|
||||
cw_dbg_ktv_dump(global_cfg,DBG_CFG_DMP,"----- global cfg start -----","","----- global cfg end -----");
|
||||
|
||||
|
||||
mod = cw_mod_load(bootcfg.modname, global_cfg, CW_ROLE_WTP);
|
||||
|
Loading…
Reference in New Issue
Block a user