From 57e9ec9a61f311d91e1e3c8779bbefbccaa63c3c Mon Sep 17 00:00:00 2001 From: liuxueli Date: Sun, 25 Jun 2023 14:50:42 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=8F=91=E9=80=81session=20f?= =?UTF-8?q?lags=E5=92=8Cl4=20protocol=20label?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tsg_bridge.cpp | 10 ++++++++++ src/tsg_bridge.h | 1 + src/tsg_entry.cpp | 30 +++++++++++++++++++----------- src/tsg_entry.h | 1 + src/tsg_send_log.cpp | 33 ++++++++++++++++++++++----------- src/tsg_send_log_internal.h | 1 + test/src/gtest_sendlog.cpp | 10 ++++++++++ 7 files changed, 64 insertions(+), 22 deletions(-) diff --git a/src/tsg_bridge.cpp b/src/tsg_bridge.cpp index c287d6d..1c3c8d3 100644 --- a/src/tsg_bridge.cpp +++ b/src/tsg_bridge.cpp @@ -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) diff --git a/src/tsg_bridge.h b/src/tsg_bridge.h index 231be3a..c389b62 100644 --- a/src/tsg_bridge.h +++ b/src/tsg_bridge.h @@ -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); diff --git a/src/tsg_entry.cpp b/src/tsg_entry.cpp index 02877ac..2ef42f7 100644 --- a/src/tsg_entry.cpp +++ b/src/tsg_entry.cpp @@ -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_offsetthreadnum, 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, ¤t_traffic_statis, thread_seq); session_increase_traffic_statis_update(¤t_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) { diff --git a/src/tsg_entry.h b/src/tsg_entry.h index 9e3ea15..03780c8 100644 --- a/src/tsg_entry.h +++ b/src/tsg_entry.h @@ -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); diff --git a/src/tsg_send_log.cpp b/src/tsg_send_log.cpp index c78098f..6e3e65f 100644 --- a/src/tsg_send_log.cpp +++ b/src/tsg_send_log.cpp @@ -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,22 +1178,34 @@ 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) + if(sm_notify!=NULL) + { + TLD_append(_handle, _instance->id2field[LOG_COMMON_FLAGS].name, (void *)(long)(sm_notify->flags), TLD_TYPE_LONG); + 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; } - if(!TLD_search(_handle, _instance->id2field[LOG_COMMON_FLAGS].name)) + char *l4_protocol=srt_action_context_get_l4_protocol(srt_action_context); + if(l4_protocol==NULL) { - TLD_append(_handle, _instance->id2field[LOG_COMMON_FLAGS].name, (void *)(long)(sm_notify->flags), TLD_TYPE_LONG); + 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); - 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 0; + return 1; } int set_sce_profile_ids(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, const struct streaminfo *a_stream) @@ -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)) { diff --git a/src/tsg_send_log_internal.h b/src/tsg_send_log_internal.h index cd0fb6b..beae77e 100644 --- a/src/tsg_send_log_internal.h +++ b/src/tsg_send_log_internal.h @@ -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 }; diff --git a/test/src/gtest_sendlog.cpp b/test/src/gtest_sendlog.cpp index 3d6cde2..9f3da60 100644 --- a/test/src/gtest_sendlog.cpp +++ b/test/src/gtest_sendlog.cpp @@ -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};