TSG-13421: 不再处理UNCATEGORIZED=8000的识别结果,保证Application Full Path填充为空,增加gtest测试用例

This commit is contained in:
刘学利
2023-02-07 09:33:49 +00:00
parent ccf02881fa
commit 6756fcdf7a
7 changed files with 83 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
#TYPE1:UCHAR,2:USHORT,3:USTRING,4:ULOG,5:USTRING,6:FILE,7:UBASE64,8:PACKET #TYPE1:UCHAR,2:USHORT,3:USTRING,4:ULOG,5:USTRING,6:FILE,7:UBASE64,8:PACKET
#TYPE FIELD VALUE #TYPE FIELD VALUE
STRING UNCATEGORIZED 8000 #STRING UNCATEGORIZED 8000
#STRING UNCATEGORIZED 8001 #STRING UNCATEGORIZED 8001
#STRING UNKNOWN_OTHER 8002 #STRING UNKNOWN_OTHER 8002
STRING DNS 32 STRING DNS 32

View File

@@ -1236,7 +1236,7 @@ static int set_l7_protocol_label(const struct streaminfo *a_stream, tsg_protocol
int app_id=tsg_l7_protocol_name2id(g_tsg_proto_name2id[protocol].name); int app_id=tsg_l7_protocol_name2id(g_tsg_proto_name2id[protocol].name);
if(app_id>0) if(app_id>0)
{ {
gather_result[ORIGIN_BASIC_PROTOCOL].app_num=1; gather_result[ORIGIN_BASIC_PROTOCOL].app_num=1;
gather_result[ORIGIN_BASIC_PROTOCOL].origin=ORIGIN_BASIC_PROTOCOL; gather_result[ORIGIN_BASIC_PROTOCOL].origin=ORIGIN_BASIC_PROTOCOL;
gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].app_id=app_id; gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].app_id=app_id;
gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].surrogate_id=0; gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].surrogate_id=0;
@@ -2190,7 +2190,7 @@ static int app_identify_result_cb(const struct streaminfo *a_stream, int bridge_
) )
{ {
is_parent_ssl=1; is_parent_ssl=1;
} }
break; break;
case ORIGIN_UNKNOWN: case ORIGIN_UNKNOWN:
context->is_app_link=FLAG_TRUE; context->is_app_link=FLAG_TRUE;
@@ -2354,13 +2354,13 @@ static unsigned char tsg_master_data_entry(const struct streaminfo *a_stream, vo
state=master_deal_scan_result(a_stream, context, scan_result, hit_num, a_packet); state=master_deal_scan_result(a_stream, context, scan_result, hit_num, a_packet);
context->deal_pkt_num++; context->deal_pkt_num++;
break; break;
case OP_STATE_DATA: case OP_STATE_DATA:
if(context->is_app_link==FLAG_FALSE && (context->deal_pkt_num++) == (g_tsg_para.identify_app_max_pkt_num+1)) if(context->is_app_link==FLAG_FALSE && (context->deal_pkt_num++) == (g_tsg_para.identify_app_max_pkt_num+1))
{ {
unknown_result.app_id_num=1; unknown_result.app_id_num=1;
unknown_result.surrogate_id[0]=0; unknown_result.surrogate_id[0]=0;
unknown_result.origin=ORIGIN_UNKNOWN; unknown_result.origin=ORIGIN_UNKNOWN;
unknown_result.app_id[0]=g_tsg_para.unknown_app_id; unknown_result.app_id[0]=g_tsg_para.unknown_app_id;
app_identify_result_cb(a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_APP_IDENTIFY_RESULT], (void *)&unknown_result); app_identify_result_cb(a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_APP_IDENTIFY_RESULT], (void *)&unknown_result);
} }
@@ -2786,21 +2786,21 @@ extern "C" int TSG_MASTER_INIT()
g_tsg_para.context_project_id=project_producer_register("TSG_MASTER_CONTEXT", PROJECT_VAL_TYPE_STRUCT, free_context_label); g_tsg_para.context_project_id=project_producer_register("TSG_MASTER_CONTEXT", PROJECT_VAL_TYPE_STRUCT, free_context_label);
if(g_tsg_para.context_project_id<0) if(g_tsg_para.context_project_id<0)
{ {
MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "CONTEXT_LABEL", "project_customer_register is error, context label: %s","TSG_MASTER_CONTEXT"); MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "CONTEXT_LABEL", "project_producer_register is error, context label: %s","TSG_MASTER_CONTEXT");
return -1; return -1;
} }
g_tsg_para.tcpall_project_id=project_producer_register("TSG_TCPALL_CONTEXT", PROJECT_VAL_TYPE_STRUCT, free_tcpall_label); g_tsg_para.tcpall_project_id=project_producer_register("TSG_TCPALL_CONTEXT", PROJECT_VAL_TYPE_STRUCT, free_tcpall_label);
if(g_tsg_para.tcpall_project_id<0) if(g_tsg_para.tcpall_project_id<0)
{ {
MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "CONTEXT_LABEL", "project_customer_register is error, context label: %s","TSG_TCPALL_CONTEXT"); MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "CONTEXT_LABEL", "project_producer_register is error, context label: %s","TSG_TCPALL_CONTEXT");
return -1; return -1;
} }
g_tsg_para.gather_app_project_id=project_producer_register("APP_IDENTIFY_RESULT", PROJECT_VAL_TYPE_STRUCT, free_gather_app_result); g_tsg_para.gather_app_project_id=project_producer_register("APP_IDENTIFY_RESULT", PROJECT_VAL_TYPE_STRUCT, free_gather_app_result);
if(g_tsg_para.gather_app_project_id<0) if(g_tsg_para.gather_app_project_id<0)
{ {
MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "APP_IDENTIFY_RESULT", "project_customer_register is error, context label: %s","APP_IDENTIFY_RESULT"); MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "APP_IDENTIFY_RESULT", "project_producer_register is error, context label: %s","APP_IDENTIFY_RESULT");
return -1; return -1;
} }

View File

@@ -847,7 +847,7 @@ int set_app_info(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_han
return 1; return 1;
} }
static int set_app_id(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, struct streaminfo *a_stream) int set_app_id(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, struct streaminfo *a_stream)
{ {
char app_name[512]={0}; char app_name[512]={0};
@@ -886,7 +886,6 @@ static int set_app_id(struct tsg_log_instance_t *_instance, struct TLD_handle_t
TLD_append(_handle, _instance->id2field[LOG_COMMON_APP_ID].name, &app_id_object, TLD_TYPE_OBJECT); TLD_append(_handle, _instance->id2field[LOG_COMMON_APP_ID].name, &app_id_object, TLD_TYPE_OBJECT);
} }
return 1; return 1;
} }

View File

@@ -43,6 +43,7 @@
"table_name": "APP_ID_DICT", "table_name": "APP_ID_DICT",
"table_content": [ "table_content": [
"4\tunknown\t0\tnull\tcategory\tsubcategory\ttechnology\trisk\tcharacteristics\tnull\tnull\t1\t0\t3600\t3600\t1800\t1800\t1", "4\tunknown\t0\tnull\tcategory\tsubcategory\ttechnology\trisk\tcharacteristics\tnull\tnull\t1\t0\t3600\t3600\t1800\t1800\t1",
"67\thttp\t0\tnull\tcategory\tsubcategory\ttechnology\trisk\tcharacteristics\tnull\tnull\t1\t0\t3600\t3600\t1800\t1800\t1",
"156\tqq\t0\tnull\tcategory\tsubcategory\ttechnology\trisk\tcharacteristics\tnull\tnull\t1\t0\t3600\t3600\t1800\t1800\t1", "156\tqq\t0\tnull\tcategory\tsubcategory\ttechnology\trisk\tcharacteristics\tnull\tnull\t1\t0\t3600\t3600\t1800\t1800\t1",
"336\tOPENVPN\t0\tnull\tcategory\tsubcategory\ttechnology\trisk\tcharacteristics\tnull\tnull\t1\t0\t3600\t3600\t1800\t1800\t1", "336\tOPENVPN\t0\tnull\tcategory\tsubcategory\ttechnology\trisk\tcharacteristics\tnull\tnull\t1\t0\t3600\t3600\t1800\t1800\t1",
"199\tSSL\t0\tnull\tcategory\tsubcategory\ttechnology\trisk\tcharacteristics\tnull\tnull\t1\t0\t3600\t3600\t1800\t1800\t1", "199\tSSL\t0\tnull\tcategory\tsubcategory\ttechnology\trisk\tcharacteristics\tnull\tnull\t1\t0\t3600\t3600\t1800\t1800\t1",

View File

@@ -144,24 +144,50 @@ int stream_bridge_build(const char * bridge_name, const char * rw_mode)
return bridge_id++; return bridge_id++;
} }
#define MAX_PROJECT_NUM 16
static int project_id=0;
const void *g_project_data[MAX_PROJECT_NUM]={0};
project_req_free_t *g_project_free[MAX_PROJECT_NUM]={0};
char g_project_label[MAX_PROJECT_NUM][32]={0};
int project_req_add_struct(struct streaminfo *stream, int project_req_id, const void *project_req_value) int project_req_add_struct(struct streaminfo *stream, int project_req_id, const void *project_req_value)
{ {
g_project_data[project_req_id]=project_req_value;
return 0; return 0;
} }
const void *project_req_get_struct(const struct streaminfo *stream, int project_req_id) const void *project_req_get_struct(const struct streaminfo *stream, int project_req_id)
{ {
return NULL; return g_project_data[project_req_id];
} }
int project_customer_register(const char * project_req_name, const char * project_req_val_type) int project_customer_register(const char * project_req_name, const char * project_req_val_type)
{ {
return 0; for(int i=0; i<project_id; i++)
{
if(memcmp(g_project_label[i], project_req_name, strlen(project_req_name))==0)
{
return i;
}
}
return -1;
} }
int project_producer_register(const char * project_req_name, const char * project_req_val_type, project_req_free_t * free_cb) int project_producer_register(const char * project_req_name, const char * project_req_val_type, project_req_free_t * free_cb)
{ {
return 0; assert(project_id<MAX_PROJECT_NUM);
for(int i=0; i<project_id; i++)
{
if(memcmp(g_project_label[i], project_req_name, strlen(project_req_name))==0)
{
return project_id;
}
}
g_project_free[project_id]=free_cb;
memcpy(g_project_label[project_id], project_req_name, strlen(project_req_name));
return project_id++;
} }
extern "C" void *http_field_parser(const char* buf, unsigned int buflen, int http_dir) extern "C" void *http_field_parser(const char* buf, unsigned int buflen, int http_dir)

View File

@@ -6,5 +6,7 @@ extern "C" int TSG_MASTER_INIT();
void free_shaping_result(const struct streaminfo *stream, int bridge_id, void *data); void free_shaping_result(const struct streaminfo *stream, int bridge_id, void *data);
int TLD_convert_json(struct TLD_handle_t *_handle, char *buff, unsigned int buff_len); int TLD_convert_json(struct TLD_handle_t *_handle, char *buff, unsigned int buff_len);
int set_app_id(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, struct streaminfo *a_stream);
int set_shaping_rule_ids(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, struct streaminfo *a_stream); int set_shaping_rule_ids(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, struct streaminfo *a_stream);

View File

@@ -7,6 +7,48 @@
#include "tsg_entry.h" #include "tsg_entry.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
TEST(TSGMaster, SetAPPIDHttp)
{
struct streaminfo a_stream={0};
struct gather_app_result gather_result[ORIGIN_MAX]={0};
gather_result[ORIGIN_BASIC_PROTOCOL].app_num=1;
gather_result[ORIGIN_BASIC_PROTOCOL].origin=ORIGIN_BASIC_PROTOCOL;
gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].app_id=67; //HTTP
project_req_add_struct(&a_stream, g_tsg_para.gather_app_project_id, (const void *)gather_result);
struct gather_app_result *get_result=(struct gather_app_result *)project_req_get_struct(&a_stream, g_tsg_para.gather_app_project_id);
EXPECT_NE(nullptr, get_result);
EXPECT_EQ(1, get_result[ORIGIN_BASIC_PROTOCOL].app_num);
EXPECT_EQ(67, get_result[ORIGIN_BASIC_PROTOCOL].attributes[0].app_id);
EXPECT_EQ(0, get_result[ORIGIN_BASIC_PROTOCOL].attributes[0].packet_sequence);
EXPECT_EQ(0, get_result[ORIGIN_BASIC_PROTOCOL].attributes[0].surrogate_id);
EXPECT_EQ(ORIGIN_BASIC_PROTOCOL, get_result[ORIGIN_BASIC_PROTOCOL].origin);
struct TLD_handle_t *handle=TLD_create(0);
set_app_id(g_tsg_log_instance, handle, (struct streaminfo *)&a_stream);
char app_ids[256]={0};
TLD_convert_json(handle, app_ids, sizeof(app_ids));
EXPECT_STREQ("{\"common_app_full_path\":\"http\",\"common_app_label\":\"http\"}", app_ids);
project_req_add_struct(&a_stream, g_tsg_para.gather_app_project_id, NULL);
get_result=(struct gather_app_result *)project_req_get_struct(&a_stream, g_tsg_para.gather_app_project_id);
EXPECT_EQ(nullptr, get_result);
}
TEST(TSGMaster, SetAPPIDUnknown)
{
struct streaminfo a_stream={0};
struct TLD_handle_t *handle=TLD_create(0);
set_app_id(g_tsg_log_instance, handle, (struct streaminfo *)&a_stream);
char app_ids[256]={0};
TLD_convert_json(handle, app_ids, sizeof(app_ids));
EXPECT_STREQ("{\"common_app_full_path\":\"unknown\",\"common_app_label\":\"unknown\"}", app_ids);
}
TEST(TSGMaster, ShapingSetRuleIds) TEST(TSGMaster, ShapingSetRuleIds)
{ {
const struct streaminfo a_stream={0}; const struct streaminfo a_stream={0};