Improved debugging

This commit is contained in:
2022-08-20 21:00:46 +02:00
parent 6405a937d2
commit ee16f3794f
12 changed files with 157 additions and 147 deletions

View File

@ -32,7 +32,7 @@ struct cw_StrListElem capwap_strings_elem[] = {
{CAPWAP_ELEM_ECN_SUPPORT, "ECN Support"},
{CAPWAP_ELEM_IDLE_TIMEOUT, "Idle Timeout"},
{CW_ELEM_IMAGE_DATA, "Image Data"},
{CW_ELEM_IMAGE_IDENTIFIER, "Image Identifier"},
{CAPWAP_ELEM_IMAGE_IDENTIFIER, "Image Identifier"},
{CW_ELEM_IMAGE_INFORMATION, "Image Information"},
{CW_ELEM_INITIATE_DOWNLOAD, "Initiate Download"},
{CAPWAP_ELEM_LOCATION_DATA, "Location Data"},

View File

@ -474,9 +474,10 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len,
elems_ptr = cw_get_msg_elems_ptr(msg_ptr);
cw_dbg(DBG_MSG_PARSING, "*** Parsing message of type %d - (%s) ***",
message->type, message->name);
/* if (cw_dbg_is_level(DBG_ELEM_IN)){
cw_dbg(DBG_MSG_PARSING, "Parsing message of type %d - (%s)",
message->type, message->name);
}*/
memset(&params,0,sizeof(struct cw_ElemHandlerParams));
@ -493,6 +494,7 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len,
params.msgdata = message;
params.msgset=conn->msgset;
params.conn = conn;
params.dbg_level = DBG_ELEM_IN;
cw_decode_elements(&params,elems_ptr, elems_len);
@ -502,8 +504,8 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len,
if (params.mand_found)
cw_check_missing_mand(message, params.mand_found,conn->msgset->handlers_by_key);
cw_dbg(DBG_MSG_PARSING, "*** End parsing message of type %d (%s) ***",
message->type, message->name);
// cw_dbg(DBG_MSG_PARSING, "*** End parsing message of type %d (%s) ***",
// message->type, message->name);
if (params.mand_found)
mavl_destroy(params.mand_found);

View File

@ -14,6 +14,41 @@ int conn_send_msg(struct cw_Conn * conn, uint8_t *rawmsg)
packetlen = cw_get_hdr_msg_total_len(rawmsg);
cw_dbg_msg(DBG_MSG_OUT, conn,rawmsg, packetlen,(struct sockaddr*)&conn->addr);
{
int type;
uint8_t *msgptr;
msgptr = rawmsg + cw_get_hdr_msg_offset(rawmsg);
struct cw_MsgData * msg;
type = cw_get_msg_type(msgptr);
msg = cw_msgset_get_msgdata(conn->msgset,type);
uint8_t *elems_ptr;
int offset = cw_get_hdr_msg_offset(rawmsg);
uint8_t *msg_ptr = rawmsg + offset;
int elems_len = cw_get_msg_elems_len(msg_ptr);
elems_ptr = cw_get_msg_elems_ptr(msg_ptr);
cw_Cfg_t * cfg = cw_cfg_create();
struct cw_ElemHandlerParams params;
memset(&params,0,sizeof(struct cw_ElemHandlerParams));
params.cfg=cfg;
params.msgset=conn->msgset;
params.msgdata=msg;
params.mand_found = mavl_create_conststr();
params.dbg_level = DBG_ELEM_OUT;
cw_decode_elements( &params, elems_ptr,elems_len);
cw_cfg_destroy(cfg);
if (params.mand_found){
cw_check_missing_mand(msg, params.mand_found,conn->msgset->handlers_by_key);
mavl_destroy(params.mand_found);
}
}
/* Zyxel doesn't count msg element length from

View File

@ -18,9 +18,9 @@ void cw_dbg_set_level (int level, int on)
break;
default:
if (on)
cw_dbg_opt_level |= (1 << (level));
cw_dbg_opt_level |= (level);
else
cw_dbg_opt_level &= (0xffffffff) ^ (1 << (level));
cw_dbg_opt_level &= (0xffffffff) ^ (level);
}
}

View File

@ -79,7 +79,7 @@ static struct cw_StrListElem theme0[] = {
{DBG_PKT_ERR, ANSI_RED},
{DBG_ELEM_ERR, ANSI_RED},
{DBG_SUBELEM, ANSI_BBLACK},
// {DBG_SUBELEM, ANSI_BBLACK},
{DBG_DTLS, ANSI_MAGENTA ANSI_BOLD},
{DBG_DTLS_DETAIL, ANSI_MAGENTA},
{DBG_DTLS_BIO, ANSI_BMAGENTA},
@ -94,7 +94,7 @@ static struct cw_StrListElem theme0[] = {
{DBG_MOD, ANSI_WHITE},
{DBG_CFG_DMP, ANSI_BCYAN },
{CW_STR_STOP, ""}
};
@ -117,22 +117,22 @@ static struct cw_StrListElem color_off[] = {
*/
static struct cw_StrListElem prefix[] = {
{DBG_INFO, " Info -"},
{DBG_PKT_IN, " Pkt IN -"},
{DBG_PKT_OUT, " Pkt Out -"},
{DBG_MSG_IN, " Msg IN -"},
{DBG_MSG_OUT, " Msg Out -"},
{DBG_INFO, "Info -"},
{DBG_PKT_IN, "Pkt IN -"},
{DBG_PKT_OUT, "Pkt Out -"},
{DBG_MSG_IN, "Msg In - "},
{DBG_MSG_OUT, "Msg Out - "},
{DBG_ELEM_IN, " Msg Element -"},
{DBG_ELEM_OUT, " Msg Element -"},
{DBG_MSG_PARSING, "" },
{DBG_ELEM_IN, " Msg Element -"},
{DBG_ELEM_OUT, " Msg Element -"},
{DBG_MSG_ERR, " Msg Error -"},
{DBG_PKT_ERR, " Pkt Error -"},
{DBG_ELEM_ERR, " Elem Error -"},
{DBG_RFC, " RFC -"},
{DBG_SUBELEM, " Sub-Element - "},
{DBG_DTLS, " DTLS - "},
{DBG_DTLS_DETAIL, " DTLS - "},
{DBG_MSG_ERR, " Msg Error -"},
{DBG_PKT_ERR, " Pkt Error -"},
{DBG_ELEM_ERR, " Elem Error -"},
{DBG_RFC, " RFC -"},
{DBG_DTLS, "DTLS - "},
{DBG_DTLS_DETAIL, "DTLS - "},
{DBG_WARN, " Warning - "},
{DBG_MOD, " Mod - "},
{DBG_STATE, " STATEMACHINE - "},
@ -142,6 +142,7 @@ static struct cw_StrListElem prefix[] = {
{DBG_X, "XXXXX - "},
{CW_STR_STOP, ""}
};
@ -183,10 +184,13 @@ const char *get_dbg_color_ontext(int level)
int cw_dbg_is_level(int level)
{
if (level >= DBG_ALL ){
if (level > 1 && (level &1))
return 1;
}
return (cw_dbg_opt_level & (1<<level));
/* if (level >= DBG_ALL ){
return 1;
}*/
return (cw_dbg_opt_level & (level));
}
@ -197,11 +201,11 @@ static void cw_dbg_vlog_line(struct cw_LogWriter * writer,
char fbuf[512];
if ( writer->colored){
sprintf(fbuf,"DBG: %s%s %s%s%s",
sprintf(fbuf,"DBG: %s%s%s%s%s",
prefix_color,prefix,textcolor,format,DBG_CLR_OFF);
}
else{
sprintf(fbuf,"DBG: %s %s",
sprintf(fbuf,"DBG: %s%s",
prefix,format);
}
@ -421,38 +425,6 @@ void cw_dbg_elem(int level, struct cw_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_Val * 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->get_type_name(data), value);
}
if (footer != NULL)
cw_dbg (dbglevel, footer);
}

View File

@ -47,93 +47,88 @@
* Debug levels
*/
enum cw_dbg_levels{
/** Show headers of incomming CAPWAP packets */
DBG_PKT_IN=0,
/** Show headers of outgoing CAPWAP packets */
DBG_PKT_OUT,
/** Show headers of incomming/outgoing CAPWAP packets */
DBG_PKT_IN = (1<<0),
DBG_PKT_OUT = (1<<1),
/** Incomming CAPWAP packets with errors, wich would
usually silently discarded */
DBG_PKT_ERR,
DBG_PKT_ERR = (1<<2),
/** Dump content of incomming packets */
DBG_PKT_DMP,
/** Dump content of packets */
DBG_PKT_DMP = (1<<3),
/** Display incomming CAPWAP/LWAPP messages */
DBG_MSG_IN,
/** Display incomming/outgoing CAPWAP/LWAPP messages */
DBG_MSG_IN = (1<<4),
DBG_MSG_OUT = (1<<5),
/** Display outgoing CAPWAP/LWAPP messages */
DBG_MSG_OUT,
DBG_MSG_DMP,
/** Show hex-dump of messages */
DBG_MSG_DMP = (1<<6),
/** Message errors */
DBG_MSG_ERR,
DBG_MSG_ERR = (1<<7),
/** Show message elements in incomming messages */
DBG_ELEM_IN,
/** Show message elements assembled for outgoing messages */
DBG_ELEM_OUT,
/** Show message elements in incomming/outgoing messages */
DBG_ELEM_IN = (1<<8),
DBG_ELEM_OUT = (1<<9),
/** Show message element details */
DBG_ELEM_DETAIL,
DBG_ELEM_DETAIL = (1<<10),
/** Error in msg elements */
DBG_ELEM_ERR,
/** Show subelements */
DBG_SUBELEM,
/** Show dump of subelements */
DBG_SUBELEM_DMP,
DBG_ELEM_ERR = (1<<11),
/** hex dump elements */
DBG_ELEM_DMP,
DBG_ELEM_DMP = (1<<12),
/** General infos, like CAPWAP state */
DBG_INFO,
DBG_INFO = (1<<13),
/** Misc. warnings */
DBG_WARN,
DBG_WARN = (1<<14),
/** RFC related */
DBG_RFC,
DBG_RFC = (1<<15),
/** DTLS related messages */
DBG_DTLS,
DBG_DTLS = (1<<16),
/** DTLS BIOs in/out */
DBG_DTLS_BIO,
DBG_DTLS_BIO = (1<<17),
/** Dump DTLS BIO i/o */
DBG_DTLS_BIO_DMP,
DBG_DTLS_BIO_DMP = (1<<18),
/** Show DTLS Details */
DBG_DTLS_DETAIL,
DBG_DTLS_DETAIL = (1<<19),
DBG_CFG_DMP,
DBG_CFG_DMP = (1<<20),
DBG_CFG_SET,
DBG_CFG_SET = (1<<21),
/** Debug Mods */
DBG_MOD,
DBG_MOD = (1<<22),
DBG_STATE, /**<Debug State machine */
/**Debug State machine */
DBG_STATE = (1<<23),
DBG_ALL,
DBG_PKT_DMP_OUT,
DBG_PKT_DMP_IN,
DBG_PKT_DMP_OUT = (1<<24),
DBG_PKT_DMP_IN = (1<<25),
DBG_MSG_IN_DMP,
DBG_MSG_OUT_DMP,
DBG_MSG_ASSEMBLY,
DBG_MSG_PARSING,
DBG_MSG_ASSEMBLY = (1<<26),
DBG_MSG_IN_DMP = (1<<27),
DBG_MSG_OUT_DMP = (1<<29),
DBG_X
DBG_X = (1<<29),
DBG_ALL = (0xffffffff),
DBG_MSG_PARSING = 3,
DBG_MSG_COMPOSING = 5,
};

View File

@ -51,10 +51,10 @@ struct cw_StrListElem cw_dbg_strings[] = {
{ DBG_ELEM_OUT, "elem_out"},
{ DBG_ELEM_DMP, "elem_dmp"},
{ DBG_SUBELEM, "subelem"},
{ DBG_SUBELEM_DMP, "subelem_dmp" },
// { DBG_SUBELEM, "subelem"},
// { DBG_SUBELEM_DMP, "subelem_dmp" },
{ DBG_ELEM_DETAIL, "elem_detail"},
// { DBG_ELEM_DETAIL, "elem_detail"},
{ DBG_ELEM_ERR, "elem_err" },
@ -72,7 +72,13 @@ struct cw_StrListElem cw_dbg_strings[] = {
{ DBG_MOD,"mod"},
{ DBG_STATE, "state" },
{ (DBG_MSG_IN | DBG_MSG_OUT), "msg" },
{ (DBG_MSG_IN | DBG_MSG_OUT | DBG_ELEM_IN | DBG_ELEM_OUT ), "std" },
{ DBG_ALL, "all"},
{ CW_STR_STOP, NULL }
};

View File

@ -159,8 +159,8 @@ int cw_compose_message(struct cw_Conn *conn, uint8_t * rawout)
{
printf ("----------------------------------- redecode -----------------------------\n");
uint8_t *elems_ptr;
// printf ("----------------------------------- redecode -----------------------------\n");
/* uint8_t *elems_ptr;
int offset = cw_get_hdr_msg_offset(rawout);
@ -176,7 +176,7 @@ int cw_compose_message(struct cw_Conn *conn, uint8_t * rawout)
params.msgset=conn->msgset;
params.msgdata=msg;
params.mand_found = mavl_create_conststr();
params.dbg_level = DBG_ELEM_OUT;
cw_decode_elements( &params, elems_ptr,elems_len);
cw_cfg_destroy(cfg);
@ -184,8 +184,8 @@ int cw_compose_message(struct cw_Conn *conn, uint8_t * rawout)
cw_check_missing_mand(msg, params.mand_found,conn->msgset->handlers_by_key);
mavl_destroy(params.mand_found);
}
printf ("----------------------------------- end redecode -----------------------------\n");
*/
// printf ("----------------------------------- end redecode -----------------------------\n");
}
@ -249,8 +249,9 @@ int cw_decode_element(struct cw_ElemHandlerParams *params, int proto,
return -1;
}
cw_dbg_elem(DBG_ELEM_IN, NULL, params->msgdata->type, handler,
data, len);
if (!handler->flags)
cw_dbg_elem(params->dbg_level, NULL, params->msgdata->type, handler,
data, len);
if (handler->get == NULL) {
cw_log(LOG_ERR, "No get method defined for %d %s", handler->id,

View File

@ -33,6 +33,7 @@ struct cw_ElemHandlerParams {
mlist_t unrecognized;
// cw_Val_t * elem;
char * debug_details;
uint32_t dbg_level;
cw_Cfg_t * cfg;
cw_Cfg_t * cfg_list[10];
};
@ -57,7 +58,7 @@ struct cw_ElemHandler {
int (*mkkey)(const char *pkey, uint8_t*data, int len, char *dst);
int (*patch)(uint8_t *dst, void *data );
void * param;
uint8_t flags;
};