From b9774d36cad432040b974b4886a679784e8ebc1b Mon Sep 17 00:00:00 2001 From: liuxueli Date: Mon, 20 Jul 2020 15:59:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UDP=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E8=AE=A1=E6=95=B0=20=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E5=A4=9A=E5=91=BD=E4=B8=AD=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=AD=96=E7=95=A5=E4=BB=85=E5=8F=91=E9=80=81=E4=B8=80?= =?UTF-8?q?=E6=9D=A1=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tsg_send_log.cpp | 24 +++++++++++++++++++++++- src/tsg_statistic.cpp | 24 ++++++++++++++++++++---- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/tsg_send_log.cpp b/src/tsg_send_log.cpp index 4e8828c..5af348a 100644 --- a/src/tsg_send_log.cpp +++ b/src/tsg_send_log.cpp @@ -19,7 +19,7 @@ #include "tsg_send_log.h" #include "tsg_send_log_internal.h" -char TSG_SEND_LOG_VERSION_20200617=0; +char TSG_SEND_LOG_VERSION_20200720=0; struct tsg_log_instance_t *g_tsg_log_instance; @@ -32,7 +32,22 @@ const id2field_t tld_type[TLD_TYPE_MAX]={{TLD_TYPE_UNKNOWN, TLD_TYPE_UNKNOWN, " extern "C" int MESA_get_dev_ipv4(const char *device, int *ip_add); +int is_multi_hit_same_policy(struct Maat_rule_t *result, int *policy_id, int *policy_id_num) +{ + int j=0; + + for(j=0;j<*policy_id_num;j++) + { + if(policy_id[j]==result->config_id) + { + return 1; + } + } + policy_id[(*policy_id_num)++]=result->config_id; + + return 0; +} unsigned long long tsg_get_stream_id(struct streaminfo * a_stream) { int ret=0; @@ -509,6 +524,8 @@ int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handl { int i=0,status=0; char *payload=NULL; + int repeat_cnt=0; + int policy_id[MAX_RESULT_NUM]={0}; struct TLD_handle_t *_handle=handle; struct tsg_log_instance_t *_instance=instance; @@ -532,6 +549,11 @@ int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handl for(i=0;iresult_num; i++) { + if(is_multi_hit_same_policy(&(log_msg->result[i]), policy_id, &repeat_cnt)) + { + continue; + } + switch(log_msg->result[i].do_log) { case LOG_ABORT: diff --git a/src/tsg_statistic.cpp b/src/tsg_statistic.cpp index 80349a2..5fb2b22 100644 --- a/src/tsg_statistic.cpp +++ b/src/tsg_statistic.cpp @@ -205,6 +205,7 @@ static int _set_traffic_info(struct _traffic_info *from, struct _traffic_info *t static void *tsg_statistic_thread(void *arg) { long long value=0; + long long total_value=0; int value_len=sizeof(long long); int thread_num=get_thread_count(); struct _traffic_info policy_traffic_info; @@ -225,18 +226,33 @@ static void *tsg_statistic_thread(void *arg) _set_traffic_info(g_tsg_statis_para.traffic_info[TSG_ACTION_INTERCEPT], &policy_traffic_info, TSG_ACTION_INTERCEPT, thread_num); value=0; + total_value=0; sapp_get_platform_opt(SPO_TCP_STREAM_ESTAB, (void *)&value, &value_len); - FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[STATIS_ESTABLISHED_CON_NUM], FS_OP_SET, value); + total_value+=value; + value=0; + sapp_get_platform_opt(SPO_UDP_STREAM_CONCURRENT, (void *)&value, &value_len); + total_value+=value; + FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[STATIS_ESTABLISHED_CON_NUM], FS_OP_SET, total_value); value=0; + total_value=0; sapp_get_platform_opt(SPO_TCP_STREAM_CLOSE, (void *)&value, &value_len); - FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[STATIS_CLOSE_CON_NUM], FS_OP_SET, value); + total_value+=value; + value=0; + sapp_get_platform_opt(SPO_UDP_STREAM_CLOSE, (void *)&value, &value_len); + total_value+=value; + FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[STATIS_CLOSE_CON_NUM], FS_OP_SET, total_value); value=0; + total_value=0; sapp_get_platform_opt(SPO_TCP_STREAM_NEW, (void *)&value, &value_len); - FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[STATIS_NEW_CON_NUM], FS_OP_SET, value); + total_value+=value; + value=0; + sapp_get_platform_opt(SPO_UDP_STREAM_NEW, (void *)&value, &value_len); + total_value+=value; + FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[STATIS_NEW_CON_NUM], FS_OP_SET, total_value); - total_traffic_info.con_num+=value; + total_traffic_info.con_num+=total_value; value_len=sizeof(total_traffic_info.in_bytes); sapp_get_platform_opt(SPO_TOTAL_INBOUND_BYTE, (void *)&total_traffic_info.in_bytes, &value_len);