From cf3ec4e15c4f33ce8d5d92db132e057633dc5d32 Mon Sep 17 00:00:00 2001 From: liuxueli Date: Tue, 9 Jun 2020 10:20:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=B4=E9=9C=B2TSG=5FMASTER=5FINTERNAL=5FLAB?= =?UTF-8?q?EL=E6=B5=81=E6=A0=87=E7=AD=BE=EF=BC=8C=E4=BE=9B=E5=A4=96?= =?UTF-8?q?=E9=83=A8=E6=8F=92=E4=BB=B6=E4=BD=BF=E7=94=A8=EF=BC=8C=E7=9B=B8?= =?UTF-8?q?=E5=BA=94=E7=BB=93=E6=9E=84=E4=BD=93=20struct=20=5Finternal=5Fl?= =?UTF-8?q?abel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/tsg_rule.h | 13 ++++++++ src/tsg_entry.cpp | 84 ++++++++++++++++++++++++++++++++--------------- src/tsg_entry.h | 13 -------- 3 files changed, 70 insertions(+), 40 deletions(-) diff --git a/inc/tsg_rule.h b/inc/tsg_rule.h index 302f1eb..eb76c2a 100644 --- a/inc/tsg_rule.h +++ b/inc/tsg_rule.h @@ -53,6 +53,19 @@ struct _identify_info char domain[MAX_DOAMIN_LEN]; }; +struct _internal_label +{ + tsg_protocol_t proto; + long establish_latency_ms; + struct _asn_info *client_asn; + struct _asn_info *server_asn; + struct _location_info *client_location; + struct _location_info *server_location; + struct _subscribe_id_info *client_subscribe_id; + struct _subscribe_id_info *server_subscribe_id; +}; + + typedef enum _PULL_RESULT_TYPE { PULL_KNI_RESULT, diff --git a/src/tsg_entry.cpp b/src/tsg_entry.cpp index 7524f7b..b92da1b 100644 --- a/src/tsg_entry.cpp +++ b/src/tsg_entry.cpp @@ -42,7 +42,7 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL; #endif -char TSG_MASTER_VERSION_20200608=0; +char TSG_MASTER_VERSION_20200609=0; const char *tsg_conffile="tsgconf/main.conf"; g_tsg_para_t g_tsg_para; @@ -524,7 +524,6 @@ extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int t { int ret=0,hit_num=0; struct timespec tv; - long establish_latency_ms=0; int state=APP_STATE_GIVEME; scan_status_t mid=NULL; Maat_rule_t *p_result=NULL; @@ -541,35 +540,39 @@ extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int t memset(&identify_info, 0, sizeof(identify_info)); identify_application_protocol(a_tcp, &identify_info, a_packet); + + internal_label=(struct _internal_label *)dictator_malloc(1, sizeof(struct _internal_label)); + memset(internal_label, 0, sizeof(struct _internal_label)); + internal_label->proto=identify_info.proto; + if(identify_info.proto==PROTO_HTTP) { - internal_label=(struct _internal_label *)dictator_malloc(1, sizeof(struct _internal_label)); - memset(internal_label, 0, sizeof(struct _internal_label)); - clock_gettime(CLOCK_REALTIME, &tv); internal_label->establish_latency_ms=(tv.tv_sec-a_tcp->ptcpdetail->createtime)*1000+tv.tv_nsec/1000/1000; - - ret=project_req_add_struct(a_tcp, g_tsg_para.internal_project_id, (const void *)internal_label); - if(ret<0) - { - MESA_handle_runtime_log(g_tsg_para.logger, - RLOG_LV_FATAL, - "PROJECT_ADD", - "Add policy_priority_label failed, establish latency ms: %llu addr: %s", - establish_latency_ms, - printaddr(&a_tcp->addr, thread_seq) - ); - } - else - { - MESA_handle_runtime_log(g_tsg_para.logger, - RLOG_LV_DEBUG, - "PROJECT_ADD", - "Add policy_priority_label successfully, establish latency ms: %llu addr: %s", - establish_latency_ms, - printaddr(&a_tcp->addr, thread_seq) - ); - } + } + + ret=project_req_add_struct(a_tcp, g_tsg_para.internal_project_id, (const void *)internal_label); + if(ret<0) + { + MESA_handle_runtime_log(g_tsg_para.logger, + RLOG_LV_FATAL, + "PROJECT_ADD", + "Add internal_label failed, establish latency ms: %llu proto: %d addr: %s", + internal_label->establish_latency_ms, + internal_label->proto, + printaddr(&a_tcp->addr, thread_seq) + ); + } + else + { + MESA_handle_runtime_log(g_tsg_para.logger, + RLOG_LV_DEBUG, + "PROJECT_ADD", + "Add internal_label successfully, establish latency ms: %llu proto: %d addr: %s", + internal_label->establish_latency_ms, + internal_label->proto, + printaddr(&a_tcp->addr, thread_seq) + ); } ret=tsg_scan_nesting_addr(g_tsg_maat_feather, a_tcp, identify_info.proto, &mid, all_result+hit_num, MAX_RESULT_NUM-hit_num); @@ -729,6 +732,7 @@ extern "C" char TSG_MASTER_UDP_ENTRY(struct streaminfo *a_udp, void **pme, int t Maat_rule_t result[MAX_RESULT_NUM]={0}; struct _identify_info identify_info; struct _master_context *_context=(struct _master_context *)*pme; + struct _internal_label *internal_label=NULL; switch(a_udp->opstate) { @@ -736,6 +740,32 @@ extern "C" char TSG_MASTER_UDP_ENTRY(struct streaminfo *a_udp, void **pme, int t memset(&identify_info, 0, sizeof(identify_info)); identify_application_protocol(a_udp, &identify_info, a_packet); + internal_label=(struct _internal_label *)dictator_malloc(1, sizeof(struct _internal_label)); + memset(internal_label, 0, sizeof(struct _internal_label)); + internal_label->proto=identify_info.proto; + + ret=project_req_add_struct(a_udp, g_tsg_para.internal_project_id, (const void *)internal_label); + if(ret<0) + { + MESA_handle_runtime_log(g_tsg_para.logger, + RLOG_LV_FATAL, + "PROJECT_ADD", + "Add internal_label failed, proto: %d addr: %s", + internal_label->proto, + printaddr(&a_udp->addr, thread_seq) + ); + } + else + { + MESA_handle_runtime_log(g_tsg_para.logger, + RLOG_LV_DEBUG, + "PROJECT_ADD", + "Add internal_label successfully, proto: %d addr: %s", + internal_label->proto, + printaddr(&a_udp->addr, thread_seq) + ); + } + ret=tsg_scan_nesting_addr(g_tsg_maat_feather, a_udp, identify_info.proto, &mid, result, MAX_RESULT_NUM); if(ret>0) { diff --git a/src/tsg_entry.h b/src/tsg_entry.h index 2cc2040..f91b987 100644 --- a/src/tsg_entry.h +++ b/src/tsg_entry.h @@ -101,19 +101,6 @@ struct _subscribe_id_info char subscribe_id[256]; }; - -struct _internal_label -{ - long establish_latency_ms; - struct _asn_info *client_asn; - struct _asn_info *server_asn; - struct _location_info *client_location; - struct _location_info *server_location; - struct _subscribe_id_info *client_subscribe_id; - struct _subscribe_id_info *server_subscribe_id; -}; - - typedef struct _policy_priority_label { tsg_protocol_t proto; //enum _tsg_protocol (tsg_types.h)