From f0e838de0abd6f57e36af65e7981cfb41c9dec96 Mon Sep 17 00:00:00 2001
From: "7u83@mail.ru" <7u83@mail.ru@noemail.net>
Date: Mon, 26 Feb 2018 22:14:32 +0000
Subject: [PATCH] Can handle unknown messages
FossilOrigin-Name: 189731bb4dae23486840ea02ba738a3eb8bad3dd58b184a89e9d3a5fbef3ff00
---
actube.workspace | 4 ++--
src/cw/conn_process_packet.c | 19 ++++++++++++++-----
src/cw/dbg.c | 8 ++++++--
src/mod/capwap/capwap_actions_ac.c | 5 +++--
4 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/actube.workspace b/actube.workspace
index c63c2d68..e0162c79 100644
--- a/actube.workspace
+++ b/actube.workspace
@@ -4,8 +4,8 @@
-
-
+
+
diff --git a/src/cw/conn_process_packet.c b/src/cw/conn_process_packet.c
index 7045fd22..1d039ca8 100644
--- a/src/cw/conn_process_packet.c
+++ b/src/cw/conn_process_packet.c
@@ -267,8 +267,6 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
conn->detected = 1;
}
-printf("We have loaded the message set\n");
-
cw_dbg_msg(DBG_MSG_IN, conn, rawmsg, len, from);
/* prepare struct for search operation */
@@ -277,7 +275,18 @@ printf("We have loaded the message set\n");
struct cw_MsgData * message;
/* Search for message combination */
message = mavl_get(conn->msgset->messages,&search);
-
+
+ int result_code = 0;
+ if (!message){
+ /* Message is unknown */
+ cw_dbg(DBG_MSG_ERR, "Message type %d (%s) unknown.",
+ search.type, cw_strmsg(search.type),
+ cw_strstate(conn->capwap_state));
+ result_code = CW_RESULT_MSG_UNRECOGNIZED;
+ cw_send_error_response(conn, rawmsg, result_code);
+ errno = EAGAIN;
+ return -1;
+ }
// afm = cw_actionlist_in_get(conn->actions->in, &as);
@@ -304,7 +313,7 @@ printf("We have loaded the message set\n");
cw_dbg(DBG_MSG_ERR,
"Message type %d (%s) not allowed in %s State.", as.msg_id,
cw_strmsg(as.msg_id), cw_strstate(as.capwap_state));
- result_code = CW_RESULT_MSG_INVALID_IN_CURRENT_STATE;
+ result_code = CAPWAP_RESULT_MSG_INVALID_IN_CURRENT_STATE;
} else {
/* Message is unknown */
cw_dbg(DBG_MSG_ERR, "Message type %d (%s) unknown.",
@@ -388,7 +397,7 @@ printf("We have loaded the message set\n");
/* all message elements are processed, do now after processing
by calling the "end" function for the message */
- int result_code = 0;
+ //int result_code = 0;
diff --git a/src/cw/dbg.c b/src/cw/dbg.c
index b59aea36..f58884a8 100644
--- a/src/cw/dbg.c
+++ b/src/cw/dbg.c
@@ -492,10 +492,14 @@ void cw_dbg_msg(int level, struct conn *conn, uint8_t * packet, int len,
search.type = msg_id;
struct cw_MsgData * message;
message = mavl_get(conn->msgset->messages,&search);
-
+ char * msname;
+ if (!message)
+ msname="Unknown";
+ else
+ msname = message->name;
- s += sprintf(s, "%s Message (type=%d) ", message->name /*cw_strmsg(msg_id)*/, msg_id);
+ s += sprintf(s, "%s Message (type=%d) ", msname /*cw_strmsg(msg_id)*/, msg_id);
if (level == DBG_MSG_IN)
s += sprintf(s, "from %s ", sock_addr2str(from));
else
diff --git a/src/mod/capwap/capwap_actions_ac.c b/src/mod/capwap/capwap_actions_ac.c
index 233f071b..4031c04c 100644
--- a/src/mod/capwap/capwap_actions_ac.c
+++ b/src/mod/capwap/capwap_actions_ac.c
@@ -101,7 +101,8 @@ static cw_msgdef_t messages[] = {
/* Discovery Request Message*/
{
.name = "Discovery Request",
- .type = CAPWAP_MSG_DISCOVERY_REQUEST,
+ // .type = CAPWAP_MSG_DISCOVERY_REQUEST,
+ .type = 7,
.states = (int[]){CAPWAP_STATE_DISCOVERY,0},
.elements = (cw_msgelemprops_t []){
{&_DISCOVERY_TYPE,1},
@@ -132,7 +133,7 @@ static cw_msgdef_t messages[] = {
-struct cw_MsgSet * cisco_register_msg_set(struct cw_MsgSet * set, int mode){
+struct cw_MsgSet * capwap_register_msg_set(struct cw_MsgSet * set, int mode){
if (mode != CW_MOD_MODE_CAPWAP)
return NULL;
cw_msgset_add(set,messages);