From 291c05ea79fe3eda8fdef68079808e321cf2d1f5 Mon Sep 17 00:00:00 2001 From: liuxueli Date: Wed, 20 Nov 2019 16:40:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E6=B5=81ID=E7=9A=84=E6=8E=A5=E5=8F=A3=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=80=BB=E6=8E=A7=E6=B3=A8=E5=86=8C=E4=B8=BATCP?= =?UTF-8?q?=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/tsg_send_log.h | 2 ++ src/tsg_entry.cpp | 45 +++++++++++++++++++------------------------- src/tsg_entry.h | 1 + src/tsg_send_log.cpp | 23 +++++++++++++++++++++- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/inc/tsg_send_log.h b/inc/tsg_send_log.h index 0115f46..b3a4b5c 100644 --- a/inc/tsg_send_log.h +++ b/inc/tsg_send_log.h @@ -32,5 +32,7 @@ int TLD_cancel(TLD_handle_t handle); int tsg_send_log(tsg_log_instance_t instance, TLD_handle_t handle, tsg_log_t *log_msg, int thread_id); +unsigned long long tsg_get_stream_id(struct streaminfo *a_stream); + #endif diff --git a/src/tsg_entry.cpp b/src/tsg_entry.cpp index b985fd5..51c6592 100644 --- a/src/tsg_entry.cpp +++ b/src/tsg_entry.cpp @@ -110,7 +110,7 @@ static Maat_rule_t *tsg_policy_decision_criteria(Maat_rule_t *result, int result return p_result; } -extern "C" char TSG_MASTER_TCPALL_ENTRY(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a_packet) +extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a_packet) { int send_log=0,identify_flag=0; int ret=0,hit_num=0,ip_policy=0; @@ -126,15 +126,10 @@ extern "C" char TSG_MASTER_TCPALL_ENTRY(struct streaminfo *a_tcp, void **pme, in Maat_rule_t all_result[MAX_RESULT_NUM]; policy_priority_label_t *priority_label=NULL; - switch(a_tcp->pktstate) + switch(a_tcp->opstate) { case OP_STATE_PENDING: FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_LINKS], 0, FS_OP_ADD, 1); - case OP_STATE_DATA: - if((a_tcp->ptcpdetail->pdata==NULL) || (a_tcp->ptcpdetail->datalen<=0) || (a_tcp->dir==DIR_DOUBLE && a_tcp->curdir==DIR_S2C)) - { - return APP_STATE_GIVEME; - } ret=tsg_scan_nesting_addr(g_tsg_maat_feather, a_tcp, PROTO_MAX, &mid, all_result+hit_num, MAX_RESULT_NUM-hit_num); if(ret>0) @@ -144,26 +139,22 @@ extern "C" char TSG_MASTER_TCPALL_ENTRY(struct streaminfo *a_tcp, void **pme, in FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_HIT_ADDR], 0, FS_OP_ADD, 1); } - - if(a_tcp->curdir==DIR_C2S) + memset(&identify_info, 0, sizeof(identify_info)); + + ret=tsg_scan_shared_policy(g_tsg_maat_feather, + a_tcp->ptcpdetail->pdata, + a_tcp->ptcpdetail->datalen, + all_result+hit_num, + MAX_RESULT_NUM-hit_num, + &identify_info, + &mid, + g_tsg_para.logger, + thread_seq); + if(ret>0) { - memset(&identify_info, 0, sizeof(identify_info)); - - ret=tsg_scan_shared_policy(g_tsg_maat_feather, - a_tcp->ptcpdetail->pdata, - a_tcp->ptcpdetail->datalen, - all_result+hit_num, - MAX_RESULT_NUM-hit_num, - &identify_info, - &mid, - g_tsg_para.logger, - thread_seq); - if(ret>0) - { - hit_num+=ret; - identify_flag=1; - FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_HIT_SHARE], 0, FS_OP_ADD, 1); - } + hit_num+=ret; + identify_flag=1; + FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_HIT_SHARE], 0, FS_OP_ADD, 1); } p_result=tsg_policy_decision_criteria(all_result, hit_num); @@ -239,6 +230,7 @@ extern "C" char TSG_MASTER_TCPALL_ENTRY(struct streaminfo *a_tcp, void **pme, in } } break; + case OP_STATE_DATA: case OP_STATE_CLOSE: default: break; @@ -272,6 +264,7 @@ extern "C" int TSG_MASTER_INIT() return -1; } + MESA_load_profile_int_def(tsg_conffile, "SYSTEM", "DEVICE_ID", &g_tsg_para.device_id, 0); MESA_load_profile_string_def(tsg_conffile, "SYSTEM", "POLICY_PRIORITY_LABEL", label_buff, sizeof(label_buff), "POLICY_PRIORITY"); g_tsg_para.priority_project_id=project_producer_register(label_buff, PROJECT_VAL_TYPE_STRUCT, free_policy_label); diff --git a/src/tsg_entry.h b/src/tsg_entry.h index fdd873b..5f5b5c1 100644 --- a/src/tsg_entry.h +++ b/src/tsg_entry.h @@ -35,6 +35,7 @@ typedef struct _policy_priority_label typedef struct _tsg_para { + int device_id; int ip_addr_table_id; int subscribe_id_table_id; int priority_project_id; diff --git a/src/tsg_send_log.cpp b/src/tsg_send_log.cpp index 20744cd..4f8cbe3 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_20191119=0; +char TSG_SEND_LOG_VERSION_20191120=0; tsg_log_instance_t g_tsg_log_instance; const id2field_t tld_type[TLD_TYPE_MAX]={{TLD_TYPE_UNKNOWN, TLD_TYPE_UNKNOWN, "UNKOWN"}, @@ -30,6 +30,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); + +unsigned long long tsg_get_stream_id(struct streaminfo * a_stream) +{ + int ret=0; + int device_id_size=sizeof(unsigned long long); + unsigned long long device_id=(unsigned long long)g_tsg_para.device_id; + + ret=MESA_get_stream_opt(a_stream, MSO_GLOBAL_STREAM_ID, (void *)device_id, &device_id_size); + if(ret==0) + { + return device_id; + } + + return -1; +} + int TLD_cancel(TLD_handle_t handle) { int thread_id=0; @@ -159,6 +175,11 @@ int TLD_append_streaminfo(struct _tsg_log_instance *_instance, struct _tld_handl TLD_append((TLD_handle_t)_handle, _instance->id2field[LOG_COMMON_STREAM_DIR].name, (void *)(long)a_stream->dir, TLD_TYPE_LONG); TLD_append((TLD_handle_t)_handle, _instance->id2field[LOG_COMMON_ADDRESS_TYPE].name, (void *)(long)addr_type, TLD_TYPE_LONG); + + TLD_append((TLD_handle_t)_handle, _instance->id2field[LOG_COMMON_C2S_PKT_NUM].name, (void *)(long)a_stream->ptcpdetail->clientpktnum, TLD_TYPE_LONG); + TLD_append((TLD_handle_t)_handle, _instance->id2field[LOG_COMMON_C2S_BYTE_NUM].name, (void *)(long)a_stream->ptcpdetail->clientbytes, TLD_TYPE_LONG); + TLD_append((TLD_handle_t)_handle, _instance->id2field[LOG_COMMON_S2C_PKT_NUM].name, (void *)(long)a_stream->ptcpdetail->serverpktnum, TLD_TYPE_LONG); + TLD_append((TLD_handle_t)_handle, _instance->id2field[LOG_COMMON_S2C_BYTE_NUM].name, (void *)(long)a_stream->ptcpdetail->serverbytes, TLD_TYPE_LONG); addr_proto=(char *)layer_addr_prefix_ntop(a_stream);