From 9b78e751c1e482c034e39bcc48aa1648501ee09f Mon Sep 17 00:00:00 2001 From: liuxueli Date: Sun, 18 Jun 2023 15:57:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=85=E6=94=AF=E6=8C=814=E7=BA=A7=E5=8F=8A?= =?UTF-8?q?=E4=BB=A5=E4=B8=8AIP=E5=BD=92=E5=B1=9E=E5=9C=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tsg_rule_internal.h | 2 -- src/tsg_send_log.cpp | 27 +++++---------------------- test/bin/gtest_maat.json | 4 ++-- test/src/gtest_bridge.cpp | 6 ++++++ test/src/gtest_rule.cpp | 9 ++++++--- test/src/gtest_tableinfo.cpp | 4 ++-- 6 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/tsg_rule_internal.h b/src/tsg_rule_internal.h index c173bc0..0b609d7 100644 --- a/src/tsg_rule_internal.h +++ b/src/tsg_rule_internal.h @@ -105,7 +105,6 @@ struct maat_runtime_para { int level; int default_compile_id; - int location_field_num; int session_record_switch; char data_center[MAX_STRING_LEN128]; char device_tag[MAX_STRING_LEN128]; @@ -149,7 +148,6 @@ void *matched_rule_cites_dns_profile_record(struct maat *feather, long long prof char *tsg_data_center_get(void); char *tsg_device_tag_get(void); -int tsg_location_type_get(void); int tsg_session_record_switch_get(void); int tsg_domain_table_idx_get(enum TSG_PROTOCOL proto); int tsg_fqdn_category_table_idx_get(enum TSG_PROTOCOL proto); diff --git a/src/tsg_send_log.cpp b/src/tsg_send_log.cpp index e0dc307..82fd20b 100644 --- a/src/tsg_send_log.cpp +++ b/src/tsg_send_log.cpp @@ -317,33 +317,16 @@ static int set_asn(struct TLD_handle_t *_handle, const struct streaminfo *a_stre static int set_location(struct TLD_handle_t *_handle, const struct streaminfo *a_stream, char *field_name, struct location_info *location_info) { - if(location_info==NULL) + if(location_info==NULL || location_info->full_location==NULL || location_info->full_location_len<=0) { return 0; } - int len=0; - char buff[1024]={0}; - int buff_len=sizeof(buff); - int location_type=tsg_location_type_get(); - switch(location_type) - { - case 18: - len+=string_cat(buff+len, buff_len-len, location_info->city_full); - buff[len++]=','; - len+=string_cat(buff+len, buff_len-len, location_info->province_full); - buff[len++]=','; - string_cat(buff+len, buff_len-len, location_info->country_full); + char location[1024]={0}; + + memcpy(location, location_info->full_location, MIN((int)sizeof(location), location_info->full_location_len-1)); + TLD_append(_handle, field_name, (void *)location, TLD_TYPE_STRING); - TLD_append(_handle, field_name, (void *)buff, TLD_TYPE_STRING); - break; - case 19: - TLD_append(_handle, field_name, (void *)location_info->full_location, TLD_TYPE_STRING); - break; - default: - return 0; - } - return 1; } diff --git a/test/bin/gtest_maat.json b/test/bin/gtest_maat.json index 0fc10df..b92c120 100644 --- a/test/bin/gtest_maat.json +++ b/test/bin/gtest_maat.json @@ -1153,7 +1153,7 @@ "table_content": { "format": "uncase plain", "match_method": "complete", - "keywords": "country_full_test..city_full_test.", + "keywords": "country_full_test..city_full_test..", "expr_type": "none" } } @@ -1184,7 +1184,7 @@ "table_content": { "format": "uncase plain", "match_method": "complete", - "keywords": "country_full_test..city_full_test.", + "keywords": "country_full_test..city_full_test..", "expr_type": "none" } } diff --git a/test/src/gtest_bridge.cpp b/test/src/gtest_bridge.cpp index 562d172..209ff3c 100644 --- a/test/src/gtest_bridge.cpp +++ b/test/src/gtest_bridge.cpp @@ -707,6 +707,7 @@ TEST(TSGBridge, SessionSessionRuntimeAttributeTSG15457) srt_attribute->client_location->province_full=(char *)"beijing"; srt_attribute->client_location->city_full=(char *)"west"; srt_attribute->client_location->subdivision_addr=(char *)"yuming road"; + srt_attribute->client_location->full_location=(char *)"china.beijing.west.yuming road."; srt_attribute->server_location=(struct location_info *)dictator_malloc(0, sizeof(struct location_info)); srt_attribute->server_location->ref_cnt=1; @@ -714,6 +715,7 @@ TEST(TSGBridge, SessionSessionRuntimeAttributeTSG15457) srt_attribute->server_location->province_full=(char *)"shanghai"; srt_attribute->server_location->city_full=(char *)"east"; srt_attribute->server_location->subdivision_addr=(char *)"zhongshan road"; + srt_attribute->server_location->full_location=(char *)"china.shanghai.east.zhongshan road."; srt_attribute->client_subscribe_id=(struct subscribe_id_info *)dictator_malloc(0, sizeof(struct subscribe_id_info)); srt_attribute->client_subscribe_id->ref_cnt=1; @@ -807,6 +809,7 @@ TEST(TSGBridge, SessionSessionRuntimeAttributeTSG15457) EXPECT_STREQ("beijing", srt_attribute_out->client_location->province_full); EXPECT_STREQ("west", srt_attribute_out->client_location->city_full); EXPECT_STREQ("yuming road", srt_attribute_out->client_location->subdivision_addr); + EXPECT_STREQ("china.beijing.west.yuming road.", srt_attribute_out->client_location->full_location); const struct location_info *c_location=srt_attribute_get_client_ip_location((const struct session_runtime_attribute *)srt_attribute_out); EXPECT_NE(nullptr, c_location); @@ -815,6 +818,7 @@ TEST(TSGBridge, SessionSessionRuntimeAttributeTSG15457) EXPECT_STREQ("beijing", c_location->province_full); EXPECT_STREQ("west", c_location->city_full); EXPECT_STREQ("yuming road", c_location->subdivision_addr); + EXPECT_STREQ("china.beijing.west.yuming road.", c_location->full_location); EXPECT_NE(nullptr, srt_attribute_out->server_location); EXPECT_EQ(1, srt_attribute_out->server_location->ref_cnt); @@ -822,6 +826,7 @@ TEST(TSGBridge, SessionSessionRuntimeAttributeTSG15457) EXPECT_STREQ("shanghai", srt_attribute_out->server_location->province_full); EXPECT_STREQ("east", srt_attribute_out->server_location->city_full); EXPECT_STREQ("zhongshan road", srt_attribute_out->server_location->subdivision_addr); + EXPECT_STREQ("china.shanghai.east.zhongshan road.", srt_attribute_out->server_location->full_location); const struct location_info *s_location=srt_attribute_get_server_ip_location((const struct session_runtime_attribute *)srt_attribute_out); EXPECT_NE(nullptr, s_location); @@ -830,6 +835,7 @@ TEST(TSGBridge, SessionSessionRuntimeAttributeTSG15457) EXPECT_STREQ("shanghai", s_location->province_full); EXPECT_STREQ("east", s_location->city_full); EXPECT_STREQ("zhongshan road", s_location->subdivision_addr); + EXPECT_STREQ("china.shanghai.east.zhongshan road.", s_location->full_location); EXPECT_NE(nullptr, srt_attribute_out->client_subscribe_id); EXPECT_EQ(1, srt_attribute_out->client_subscribe_id->ref_cnt); diff --git a/test/src/gtest_rule.cpp b/test/src/gtest_rule.cpp index a3082af..012f0ea 100644 --- a/test/src/gtest_rule.cpp +++ b/test/src/gtest_rule.cpp @@ -206,7 +206,8 @@ TEST(TM, ExDataLocationBuiltIn) EXPECT_STREQ("Other", location->city_full); EXPECT_STREQ("Hong Kong", location->country_full); EXPECT_STREQ("Other", location->province_full); - EXPECT_STREQ(NULL, location->subdivision_addr); + EXPECT_STREQ("Road1", location->subdivision_addr); + EXPECT_STREQ("Hong Kong.Other.Other.Road1.", location->full_location); EXPECT_EQ(2, location->ref_cnt); temp_addr.ipv4 = inet_addr("192.168.50.2"); @@ -215,7 +216,8 @@ TEST(TM, ExDataLocationBuiltIn) EXPECT_STREQ("Xin Xi Gang", location->city_full); EXPECT_STREQ("China", location->country_full); EXPECT_STREQ("Beijing", location->province_full); - EXPECT_STREQ(NULL, location->subdivision_addr); // location_field_num == 18; not 19 + EXPECT_STREQ("Road1", location->subdivision_addr); + EXPECT_STREQ("China.Beijing.Xin Xi Gang.Road1.", location->full_location); EXPECT_EQ(2, location->ref_cnt); location = NULL; @@ -240,7 +242,8 @@ TEST(TM, ExDataLocationUserDefine) EXPECT_STREQ("Hua Yan Bei Li", location->city_full); EXPECT_STREQ("China", location->country_full); EXPECT_STREQ("Beijing", location->province_full); - EXPECT_STREQ(NULL, location->subdivision_addr); // location_field_num == 18; not 19 + EXPECT_STREQ("Road1", location->subdivision_addr); + EXPECT_STREQ("China.Beijing.Hua Yan Bei Li.Road1.", location->full_location); EXPECT_EQ(2, location->ref_cnt); location = NULL; diff --git a/test/src/gtest_tableinfo.cpp b/test/src/gtest_tableinfo.cpp index 43d10b4..1492536 100644 --- a/test/src/gtest_tableinfo.cpp +++ b/test/src/gtest_tableinfo.cpp @@ -757,7 +757,7 @@ TEST(TSG_Table, TSG_SECURITY_SOURCE_LOCATION) struct location_info location = {0}; location.country_full = (char *)"country_full_test"; location.city_full = (char *)"city_full_test"; - location.full_location=(char *)"country_full_test..city_full_test."; + location.full_location=(char *)"country_full_test..city_full_test.."; location.full_location_len=strlen(location.full_location); struct maat_state *mid = maat_state_new(g_tsg_maat_feather, a_stream.threadnum); struct maat_rule results[MAX_RESULT_NUM] = {0}; @@ -774,7 +774,7 @@ TEST(TSG_Table, TSG_SECURITY_DESTINATION_LOCATION) struct location_info location = {0}; location.country_full = (char *)"country_full_test"; location.city_full = (char *)"city_full_test"; - location.full_location=(char *)"country_full_test..city_full_test."; + location.full_location=(char *)"country_full_test..city_full_test.."; location.full_location_len=strlen(location.full_location); struct maat_state *mid = maat_state_new(g_tsg_maat_feather, a_stream.threadnum); struct maat_rule results[MAX_RESULT_NUM] = {0};