From e122469706989c4ea1bd3db2a259ee7cb0c8dee9 Mon Sep 17 00:00:00 2001 From: liuxueli Date: Mon, 23 Mar 2020 11:41:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BC=9A=E8=AF=9D=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=BB=B6=E8=BF=9F=E6=97=B6=E9=97=B4=E7=9A=84=E6=B5=81?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=20=E5=A2=9E=E5=8A=A0mail=E7=9A=84=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE=E8=AF=86=E5=88=AB=20=E4=BF=AE=E6=AD=A3=E9=A2=84?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=AE=89=E8=A3=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- preinstall/install.sh | 4 +++ preinstall/uninstall.sh | 1 + src/tsg_entry.cpp | 65 +++++++++++++++++++++++++++++++++++++++-- src/tsg_entry.h | 3 ++ 4 files changed, 71 insertions(+), 2 deletions(-) diff --git a/preinstall/install.sh b/preinstall/install.sh index 7cd45f4..74b193c 100644 --- a/preinstall/install.sh +++ b/preinstall/install.sh @@ -9,6 +9,10 @@ if [[ -z `grep -rn 'POLICY_PRIORITY' ${DST}/etc/project_list.conf` ]];then echo 'POLICY_PRIORITY struct' >> ${DST}/etc/project_list.conf fi +if [[ -z `grep -rn 'ESTABLISH_LATENCY' ${DST}/etc/project_list.conf` ]];then +echo 'ESTABLISH_LATENCY long' >> ${DST}/etc/project_list.conf +fi + if [[ -z `grep -rn 'tsg_master.inf' ${DST}/plug/conflist.inf` ]];then sed -i '/\[platform\]/a\./plug/platform/tsg_master/tsg_master.inf' ${DST}/plug/conflist.inf fi diff --git a/preinstall/uninstall.sh b/preinstall/uninstall.sh index 14e1334..e6a6e10 100644 --- a/preinstall/uninstall.sh +++ b/preinstall/uninstall.sh @@ -3,3 +3,4 @@ DST=${RPM_INSTALL_PREFIX} mkdir -p ${DST}/plug/platform/ sed -i '/tsg_master.inf/d' ${DST}/plug/conflist.inf sed -i '/POLICY_PRIORITY/d' ${DST}/etc/project_list.conf +sed -i '/ESTABLISH_LATENCY/d' ${DST}/etc/project_list.conf diff --git a/src/tsg_entry.cpp b/src/tsg_entry.cpp index 0306e2d..f708993 100644 --- a/src/tsg_entry.cpp +++ b/src/tsg_entry.cpp @@ -2,10 +2,12 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -39,7 +41,7 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL; #endif -char TSG_MASTER_VERSION_20200119=0; +char TSG_MASTER_VERSION_20200322=0; const char *tsg_conffile="tsgconf/main.conf"; g_tsg_para_t g_tsg_para; @@ -402,6 +404,13 @@ static int identify_application_protocol(struct streaminfo *a_stream, struct _id } //mail + + ret=mail_protocol_identify(a_stream); + if(ret>=SMTP_PROTOCOL&& ret<=IMAP_PROTOCOL) + { + identify_info->proto=PROTO_MAIL; + return 1; + } return ret; } @@ -425,6 +434,34 @@ 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); + if(identify_info.proto==PROTO_HTTP) + { + struct timeval tv; + long establish_latency_ms=0; + gettimeofday(&tv, NULL); + establish_latency_ms=(tv.tv_sec-a_tcp->ptcpdetail->createtime)*1000+tv.tv_usec/1000; + ret=project_req_add_long(a_tcp, g_tsg_para.establish_latency_project_id, establish_latency_ms); + 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=tsg_scan_nesting_addr(g_tsg_maat_feather, a_tcp, identify_info.proto, &mid, all_result+hit_num, MAX_RESULT_NUM-hit_num); if(ret>0) @@ -500,11 +537,23 @@ extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int t if(q_result!=NULL && (p_result==q_result)) { init_context(pme, identify_info.proto, p_result, thread_seq); + if(identify_info.proto>PROTO_UNKONWN && identify_info.protodomain, identify_info.domain, identify_info.domain_len); + _context->domain_len=identify_info.domain_len; + } state=APP_STATE_GIVEME; } break; case TSG_ACTION_BYPASS: init_context(pme, identify_info.proto, p_result, thread_seq); + if(identify_info.proto>PROTO_UNKONWN && identify_info.protodomain, identify_info.domain, identify_info.domain_len); + _context->domain_len=identify_info.domain_len; + } state=APP_STATE_GIVEME|APP_STATE_KILL_OTHER; FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_BYPASS], 0, FS_OP_ADD, 1); break; @@ -563,7 +612,11 @@ extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int t { memset(&identify_info, 0, sizeof(identify_info)); identify_info.proto=_context->proto; - + if(_context->domain_len>0) + { + memcpy(identify_info.domain, _context->domain, _context->domain_len); + identify_info.domain_len=_context->domain_len; + } master_send_log(a_tcp, _context->result, _context->hit_cnt, &identify_info, thread_seq); free_context(pme, thread_seq); } @@ -683,6 +736,14 @@ extern "C" int TSG_MASTER_INIT() return -1; } + MESA_load_profile_string_def(tsg_conffile, "SYSTEM", "ESTABLISH_LATENCY_LABEL", label_buff, sizeof(label_buff), "ESTABLISH_LATENCY"); + g_tsg_para.establish_latency_project_id=project_producer_register(label_buff, PROJECT_VAL_TYPE_LONG, NULL); + if(g_tsg_para.establish_latency_project_id<0) + { + MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "PROJECT_REGISTER", "Register %s failed ...", label_buff); + return -1; + } + ret=tsg_rule_init(tsg_conffile, g_tsg_para.logger); if(ret<0) { diff --git a/src/tsg_entry.h b/src/tsg_entry.h index 8daf3ac..7492468 100644 --- a/src/tsg_entry.h +++ b/src/tsg_entry.h @@ -53,6 +53,8 @@ struct _master_context { tsg_protocol_t proto; int hit_cnt; + int domain_len; + char domain[MAX_DOAMIN_LEN]; struct Maat_rule_t *result; }; @@ -64,6 +66,7 @@ typedef struct _tsg_para int table_id[TABLE_MAX]; int dyn_subscribe_ip_table_id; //TSG_DYN_SUBSCRIBER_IP int priority_project_id; + int establish_latency_project_id; int fs2_field_id[TSG_FS2_MAX]; char table_name[TABLE_MAX][_MAX_TABLE_NAME_LEN]; void *logger;