TSG-19631 SCE Support Datapath Packet Trace
This commit is contained in:
@@ -8,6 +8,35 @@
|
||||
#include "utils.h"
|
||||
#include "control_packet.h"
|
||||
|
||||
const char *control_packte_state_to_string(enum control_packet_state state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case CTRL_PKT_SUCCESS:
|
||||
return "success";
|
||||
case CTRL_PKT_INVALID_FORMAT:
|
||||
return "failure (invalid format)";
|
||||
case CTRL_PKT_INVALID_TSYNC:
|
||||
return "failure (invalid tsync)";
|
||||
case CTRL_PKT_INVALID_SESSION_ID:
|
||||
return "failure (invalid session id)";
|
||||
case CTRL_PKT_INVALID_STATE:
|
||||
return "failure (invalid state)";
|
||||
case CTRL_PKT_INVALID_METHOD:
|
||||
return "failure (invalid method)";
|
||||
case CTRL_PKT_INVALID_POLICY_UPDATE:
|
||||
return "failure (invalid policy update)";
|
||||
case CTRL_PKT_INVALID_PARAMS:
|
||||
return "failure (invalid params)";
|
||||
case CTRL_PKT_INVALID_APP:
|
||||
return "failure (invalid app)";
|
||||
case CTRL_PKT_INVALID_RULE_IDS:
|
||||
return "failure (invalid rule ids)";
|
||||
default:
|
||||
return "failure (unknown)";
|
||||
}
|
||||
}
|
||||
|
||||
const char *session_state_to_string(enum session_state state)
|
||||
{
|
||||
switch (state)
|
||||
@@ -25,9 +54,7 @@ const char *session_state_to_string(enum session_state state)
|
||||
}
|
||||
}
|
||||
|
||||
// return 0 : success
|
||||
// return -1 : error
|
||||
int control_packet_parse(struct control_packet *handler, const char *data, size_t length)
|
||||
enum control_packet_state control_packet_parse(struct control_packet *handler, const char *data, size_t length)
|
||||
{
|
||||
memset(handler, 0, sizeof(struct control_packet));
|
||||
|
||||
@@ -37,6 +64,7 @@ int control_packet_parse(struct control_packet *handler, const char *data, size_
|
||||
mpack_node_t item;
|
||||
mpack_error_t ret;
|
||||
char buffer[16];
|
||||
enum control_packet_state state = CTRL_PKT_SUCCESS;
|
||||
|
||||
mpack_tree_init_data(&tree, data, length);
|
||||
mpack_tree_parse(&tree);
|
||||
@@ -44,6 +72,7 @@ int control_packet_parse(struct control_packet *handler, const char *data, size_
|
||||
if (mpack_node_is_nil(root))
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet: (invalid mpack format)", LOG_TAG_CTRLPKT);
|
||||
state = CTRL_PKT_INVALID_FORMAT;
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
@@ -52,12 +81,14 @@ int control_packet_parse(struct control_packet *handler, const char *data, size_
|
||||
if (mpack_node_is_nil(temp))
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet: (tsync no found)", LOG_TAG_CTRLPKT);
|
||||
state = CTRL_PKT_INVALID_TSYNC;
|
||||
goto error_out;
|
||||
}
|
||||
mpack_node_copy_cstr(temp, handler->tsync, sizeof(handler->tsync));
|
||||
if (strcasecmp(handler->tsync, "2.0") != 0)
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet: (invalid tsync value) %s", LOG_TAG_CTRLPKT, handler->tsync);
|
||||
state = CTRL_PKT_INVALID_TSYNC;
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
@@ -66,6 +97,7 @@ int control_packet_parse(struct control_packet *handler, const char *data, size_
|
||||
if (mpack_node_is_nil(temp))
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet: (session_id no found)", LOG_TAG_CTRLPKT);
|
||||
state = CTRL_PKT_INVALID_SESSION_ID;
|
||||
goto error_out;
|
||||
}
|
||||
handler->session_id = mpack_node_u64(temp);
|
||||
@@ -83,6 +115,7 @@ int control_packet_parse(struct control_packet *handler, const char *data, size_
|
||||
if (mpack_node_is_nil(temp))
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet: (state no found)", LOG_TAG_CTRLPKT);
|
||||
state = CTRL_PKT_INVALID_STATE;
|
||||
goto error_out;
|
||||
}
|
||||
mpack_node_copy_cstr(temp, buffer, sizeof(buffer));
|
||||
@@ -105,6 +138,7 @@ int control_packet_parse(struct control_packet *handler, const char *data, size_
|
||||
else
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet: (invalid state value) %s", LOG_TAG_CTRLPKT, buffer);
|
||||
state = CTRL_PKT_INVALID_STATE;
|
||||
goto error_out;
|
||||
}
|
||||
if (handler->state != SESSION_STATE_ACTIVE)
|
||||
@@ -117,12 +151,14 @@ int control_packet_parse(struct control_packet *handler, const char *data, size_
|
||||
if (mpack_node_is_nil(temp))
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet: (method no found)", LOG_TAG_CTRLPKT);
|
||||
state = CTRL_PKT_INVALID_METHOD;
|
||||
goto error_out;
|
||||
}
|
||||
mpack_node_copy_cstr(temp, handler->method, sizeof(handler->method));
|
||||
if (strcasecmp(handler->method, "policy_update") != 0)
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet: (invalid method value) %s", LOG_TAG_CTRLPKT, handler->method);
|
||||
state = CTRL_PKT_INVALID_POLICY_UPDATE;
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
@@ -131,6 +167,7 @@ int control_packet_parse(struct control_packet *handler, const char *data, size_
|
||||
if (mpack_node_is_nil(temp))
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet: (params no found)", LOG_TAG_CTRLPKT);
|
||||
state = CTRL_PKT_INVALID_PARAMS;
|
||||
goto error_out;
|
||||
}
|
||||
// params->sce
|
||||
@@ -138,6 +175,7 @@ int control_packet_parse(struct control_packet *handler, const char *data, size_
|
||||
if (mpack_node_is_nil(temp))
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet: (sce no found)", LOG_TAG_CTRLPKT);
|
||||
state = CTRL_PKT_INVALID_APP;
|
||||
goto error_out;
|
||||
}
|
||||
// params->sce->rule_ids
|
||||
@@ -145,12 +183,14 @@ int control_packet_parse(struct control_packet *handler, const char *data, size_
|
||||
if (mpack_node_is_nil(temp))
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet: (rule_ids no found)", LOG_TAG_CTRLPKT);
|
||||
state = CTRL_PKT_INVALID_RULE_IDS;
|
||||
goto error_out;
|
||||
}
|
||||
handler->rule_id_num = MIN(mpack_node_array_length(temp), (int)(sizeof(handler->rule_ids) / sizeof(handler->rule_ids[0])));
|
||||
if (handler->rule_id_num <= 0)
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet: (invalid rule id num) %ld", LOG_TAG_CTRLPKT, mpack_node_array_length(temp));
|
||||
state = CTRL_PKT_INVALID_RULE_IDS;
|
||||
goto error_out;
|
||||
}
|
||||
for (int i = 0; i < handler->rule_id_num; i++)
|
||||
@@ -164,14 +204,15 @@ success_out:
|
||||
if (ret != mpack_ok)
|
||||
{
|
||||
LOG_ERROR("%s: unexpected control packet: (mpack return error) %d", LOG_TAG_CTRLPKT, ret);
|
||||
return -1;
|
||||
state = CTRL_PKT_INVALID_FORMAT;
|
||||
return state;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return state;
|
||||
|
||||
error_out:
|
||||
mpack_tree_destroy(&tree);
|
||||
return -1;
|
||||
return state;
|
||||
}
|
||||
|
||||
void control_packet_dump(struct control_packet *handler)
|
||||
|
||||
Reference in New Issue
Block a user