统一发送session flags和l4 protocol label

This commit is contained in:
liuxueli
2023-06-25 14:50:42 +08:00
parent d3096ccbfd
commit 57e9ec9a61
7 changed files with 64 additions and 22 deletions

View File

@@ -769,6 +769,16 @@ char srt_action_context_get_direction(const struct session_runtime_action_contex
return -1;
}
char *srt_action_context_get_l4_protocol(const struct session_runtime_action_context *srt_action_context)
{
if(srt_action_context!=NULL)
{
return srt_action_context->l4_protocol;
}
return NULL;
}
enum TSG_METHOD_TYPE srt_action_context_get_method_type(const struct session_runtime_action_context *srt_action_context)
{
if(srt_action_context!=NULL)

View File

@@ -213,6 +213,7 @@ int srt_action_context_set_hitted_app_id(const struct streaminfo * a_stream, int
const struct session_runtime_action_context *session_runtime_action_context_get(const struct streaminfo *a_stream);
char srt_action_context_get_direction(const struct session_runtime_action_context *srt_action_context);
enum TSG_METHOD_TYPE srt_action_context_get_method_type(const struct session_runtime_action_context *srt_action_context);
char *srt_action_context_get_l4_protocol(const struct session_runtime_action_context *srt_action_context);
const struct session_runtime_process_context *session_runtime_process_context_new(const struct streaminfo * a_stream);

View File

@@ -749,11 +749,11 @@ static const char *session_addr_type_string_convert(UCHAR addrtype)
}
#define MAX_L4_PROTOCOL_STR_LEN 512
char *session_l4_protocol_label_update(const struct streaminfo *a_stream, char **l4_protocol)
char *session_l4_protocol_label_update(const struct streaminfo *a_stream)
{
if(*l4_protocol!=NULL || a_stream == NULL)
if(a_stream==NULL)
{
return *l4_protocol;
return NULL;
}
const char *l4_protocol_str = NULL;
@@ -804,13 +804,15 @@ char *session_l4_protocol_label_update(const struct streaminfo *a_stream, char *
continue;
}
int n_l4_protocol_str = strlen(l4_protocol_str);
if (n_l4_protocol_str!=0)
if(l4_protocol_str!=NULL)
{
int n_l4_protocol_str = strlen(l4_protocol_str);
if (combined_l4_protocol_offset - n_l4_protocol_str < 0)
{
break;
}
memcpy(combined_l4_protocol_str+combined_l4_protocol_offset-n_l4_protocol_str, l4_protocol_str, n_l4_protocol_str);
combined_l4_protocol_offset-=n_l4_protocol_str;
l4_protocol_str=NULL;
@@ -822,12 +824,14 @@ char *session_l4_protocol_label_update(const struct streaminfo *a_stream, char *
if(combined_l4_protocol_offset>0 && combined_l4_protocol_offset<MAX_L4_PROTOCOL_STR_LEN)
{
int l4_protocol_len=MAX_L4_PROTOCOL_STR_LEN-combined_l4_protocol_offset-1;
*l4_protocol=(char *)malloc(l4_protocol_len+1);
memcpy(*l4_protocol, combined_l4_protocol_str+combined_l4_protocol_offset+1, l4_protocol_len); // +1 for del "."
(*l4_protocol)[l4_protocol_len]='\0';
char *l4_protocol=(char *)dictator_malloc(a_stream->threadnum, l4_protocol_len+1);
memcpy(l4_protocol, combined_l4_protocol_str+combined_l4_protocol_offset+1, l4_protocol_len); // +1 for del "."
l4_protocol[l4_protocol_len]='\0';
return l4_protocol;
}
return *l4_protocol;
return NULL;
}
@@ -942,11 +946,15 @@ int session_application_metrics_update(const struct streaminfo *a_stream, struct
char app_full_path[256]={0};
struct traffic_packet_info current_traffic_statis={0},increase_traffic_statis={0};
session_application_full_path_update(a_stream, app_full_path, sizeof(app_full_path));
char *l4_protocol_string=session_l4_protocol_label_update(a_stream, &srt_action_context->l4_protocol);
if(srt_action_context->l4_protocol==NULL)
{
srt_action_context->l4_protocol=session_l4_protocol_label_update(a_stream);
}
session_current_traffic_statis_update(a_stream, &current_traffic_statis, thread_seq);
session_increase_traffic_statis_update(&current_traffic_statis, srt_action_context->last_traffic_statis, &increase_traffic_statis);
tsg_set_application_metrics(a_stream, l4_protocol_string, app_full_path, &increase_traffic_statis, thread_seq);
tsg_set_application_metrics(a_stream, srt_action_context->l4_protocol, app_full_path, &increase_traffic_statis, thread_seq);
if(a_stream->opstate==OP_STATE_CLOSE || a_stream->pktstate==OP_STATE_CLOSE)
{

View File

@@ -175,5 +175,6 @@ void tsg_metric_destroy(void);
int tsg_gtp_signaling_hash_init(const char* conffile, void *logger);
char *session_l4_protocol_label_update(const struct streaminfo *a_stream);
int session_application_full_path_update(const struct streaminfo *a_stream, char *app_full_path, int app_full_path_len);

View File

@@ -1030,8 +1030,6 @@ struct TLD_handle_t *TLD_create(int thread_id)
_handle->document = new Document(_handle->valueAllocator);
_handle->document->SetObject();
return _handle;
}
@@ -1180,24 +1178,36 @@ struct session_marker_notify_ctx
int set_session_flags(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, const struct streaminfo *a_stream)
{
struct session_marker_notify_ctx *sm_notify=(struct session_marker_notify_ctx *)session_session_flags_get(a_stream);
if(sm_notify==NULL)
{
return 0;
}
if(!TLD_search(_handle, _instance->id2field[LOG_COMMON_FLAGS].name))
if(sm_notify!=NULL)
{
TLD_append(_handle, _instance->id2field[LOG_COMMON_FLAGS].name, (void *)(long)(sm_notify->flags), TLD_TYPE_LONG);
}
if(!TLD_search(_handle, _instance->id2field[LOG_COMMON_FLAGS_IDENTIFY_INFO].name))
{
TLD_append(_handle, _instance->id2field[LOG_COMMON_FLAGS_IDENTIFY_INFO].name, (void *)(long)(sm_notify->identify_str), TLD_TYPE_STRING);
return 1;
}
return 0;
}
int set_l4_protocol(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, const struct streaminfo *a_stream)
{
const struct session_runtime_action_context *srt_action_context=session_runtime_action_context_get(a_stream);
if(srt_action_context==NULL)
{
return 0;
}
char *l4_protocol=srt_action_context_get_l4_protocol(srt_action_context);
if(l4_protocol==NULL)
{
l4_protocol=session_l4_protocol_label_update(a_stream);
}
TLD_append(_handle, _instance->id2field[LOG_COMMON_L4_PROTOCOL_LABEL].name, (void *) l4_protocol, TLD_TYPE_STRING);
return 1;
}
int set_sce_profile_ids(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, const struct streaminfo *a_stream)
{
struct sce_log_update *sce = (struct sce_log_update *)session_log_update_data_get(a_stream, TSG_SERVICE_CHAINING);
@@ -1643,6 +1653,7 @@ int TLD_append_streaminfo(struct tsg_log_instance_t *instance, struct TLD_handle
set_lua_scripts_result(_instance, _handle, a_stream);
set_session_flags(_instance, _handle, a_stream);
set_l4_protocol(_instance, _handle, a_stream);
if(is_tunnels(a_stream))
{

View File

@@ -149,6 +149,7 @@ enum LOG_FIELD_ID
LOG_COMMON_SSL_PASSTHROUGHT_REASON,
LOG_COMMON_SCE_PROFILE_IDS,
LOG_COMMON_SHAPING_PROFILE_IDS,
LOG_COMMON_L4_PROTOCOL_LABEL,
LOG_COMMON_MAX
};

View File

@@ -130,6 +130,11 @@ int tsg_get_app_name_by_id(struct maat *feahter, int app_id, char * app_name, in
return 0;
}
char *srt_action_context_get_l4_protocol(const struct session_runtime_action_context * srt_action_context)
{
return NULL;
}
const struct session_runtime_attribute *session_runtime_attribute_get(const struct streaminfo * a_stream)
{
return NULL;
@@ -154,6 +159,11 @@ int session_application_full_path_update(const struct streaminfo * a_stream, cha
return 0;
}
char *session_l4_protocol_label_update(const struct streaminfo * a_stream)
{
return NULL;
}
TEST(Master, SendInterimRecord)
{
struct streaminfo a_stream={0};