仅支持4级及以上IP归属地

This commit is contained in:
liuxueli
2023-06-18 15:57:17 +08:00
parent a9bf36ac67
commit 9b78e751c1
6 changed files with 21 additions and 31 deletions

View File

@@ -105,7 +105,6 @@ struct maat_runtime_para
{ {
int level; int level;
int default_compile_id; int default_compile_id;
int location_field_num;
int session_record_switch; int session_record_switch;
char data_center[MAX_STRING_LEN128]; char data_center[MAX_STRING_LEN128];
char device_tag[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_data_center_get(void);
char *tsg_device_tag_get(void); char *tsg_device_tag_get(void);
int tsg_location_type_get(void);
int tsg_session_record_switch_get(void); int tsg_session_record_switch_get(void);
int tsg_domain_table_idx_get(enum TSG_PROTOCOL proto); int tsg_domain_table_idx_get(enum TSG_PROTOCOL proto);
int tsg_fqdn_category_table_idx_get(enum TSG_PROTOCOL proto); int tsg_fqdn_category_table_idx_get(enum TSG_PROTOCOL proto);

View File

@@ -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) 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; return 0;
} }
int len=0; char location[1024]={0};
char buff[1024]={0};
int buff_len=sizeof(buff); memcpy(location, location_info->full_location, MIN((int)sizeof(location), location_info->full_location_len-1));
int location_type=tsg_location_type_get(); TLD_append(_handle, field_name, (void *)location, TLD_TYPE_STRING);
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);
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; return 1;
} }

View File

@@ -1153,7 +1153,7 @@
"table_content": { "table_content": {
"format": "uncase plain", "format": "uncase plain",
"match_method": "complete", "match_method": "complete",
"keywords": "country_full_test..city_full_test.", "keywords": "country_full_test..city_full_test..",
"expr_type": "none" "expr_type": "none"
} }
} }
@@ -1184,7 +1184,7 @@
"table_content": { "table_content": {
"format": "uncase plain", "format": "uncase plain",
"match_method": "complete", "match_method": "complete",
"keywords": "country_full_test..city_full_test.", "keywords": "country_full_test..city_full_test..",
"expr_type": "none" "expr_type": "none"
} }
} }

View File

@@ -707,6 +707,7 @@ TEST(TSGBridge, SessionSessionRuntimeAttributeTSG15457)
srt_attribute->client_location->province_full=(char *)"beijing"; srt_attribute->client_location->province_full=(char *)"beijing";
srt_attribute->client_location->city_full=(char *)"west"; srt_attribute->client_location->city_full=(char *)"west";
srt_attribute->client_location->subdivision_addr=(char *)"yuming road"; 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=(struct location_info *)dictator_malloc(0, sizeof(struct location_info));
srt_attribute->server_location->ref_cnt=1; 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->province_full=(char *)"shanghai";
srt_attribute->server_location->city_full=(char *)"east"; srt_attribute->server_location->city_full=(char *)"east";
srt_attribute->server_location->subdivision_addr=(char *)"zhongshan road"; 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=(struct subscribe_id_info *)dictator_malloc(0, sizeof(struct subscribe_id_info));
srt_attribute->client_subscribe_id->ref_cnt=1; 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("beijing", srt_attribute_out->client_location->province_full);
EXPECT_STREQ("west", srt_attribute_out->client_location->city_full); EXPECT_STREQ("west", srt_attribute_out->client_location->city_full);
EXPECT_STREQ("yuming road", srt_attribute_out->client_location->subdivision_addr); 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); 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); EXPECT_NE(nullptr, c_location);
@@ -815,6 +818,7 @@ TEST(TSGBridge, SessionSessionRuntimeAttributeTSG15457)
EXPECT_STREQ("beijing", c_location->province_full); EXPECT_STREQ("beijing", c_location->province_full);
EXPECT_STREQ("west", c_location->city_full); EXPECT_STREQ("west", c_location->city_full);
EXPECT_STREQ("yuming road", c_location->subdivision_addr); 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_NE(nullptr, srt_attribute_out->server_location);
EXPECT_EQ(1, srt_attribute_out->server_location->ref_cnt); 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("shanghai", srt_attribute_out->server_location->province_full);
EXPECT_STREQ("east", srt_attribute_out->server_location->city_full); EXPECT_STREQ("east", srt_attribute_out->server_location->city_full);
EXPECT_STREQ("zhongshan road", srt_attribute_out->server_location->subdivision_addr); 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); 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); EXPECT_NE(nullptr, s_location);
@@ -830,6 +835,7 @@ TEST(TSGBridge, SessionSessionRuntimeAttributeTSG15457)
EXPECT_STREQ("shanghai", s_location->province_full); EXPECT_STREQ("shanghai", s_location->province_full);
EXPECT_STREQ("east", s_location->city_full); EXPECT_STREQ("east", s_location->city_full);
EXPECT_STREQ("zhongshan road", s_location->subdivision_addr); 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_NE(nullptr, srt_attribute_out->client_subscribe_id);
EXPECT_EQ(1, srt_attribute_out->client_subscribe_id->ref_cnt); EXPECT_EQ(1, srt_attribute_out->client_subscribe_id->ref_cnt);

View File

@@ -206,7 +206,8 @@ TEST(TM, ExDataLocationBuiltIn)
EXPECT_STREQ("Other", location->city_full); EXPECT_STREQ("Other", location->city_full);
EXPECT_STREQ("Hong Kong", location->country_full); EXPECT_STREQ("Hong Kong", location->country_full);
EXPECT_STREQ("Other", location->province_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); EXPECT_EQ(2, location->ref_cnt);
temp_addr.ipv4 = inet_addr("192.168.50.2"); 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("Xin Xi Gang", location->city_full);
EXPECT_STREQ("China", location->country_full); EXPECT_STREQ("China", location->country_full);
EXPECT_STREQ("Beijing", location->province_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); EXPECT_EQ(2, location->ref_cnt);
location = NULL; location = NULL;
@@ -240,7 +242,8 @@ TEST(TM, ExDataLocationUserDefine)
EXPECT_STREQ("Hua Yan Bei Li", location->city_full); EXPECT_STREQ("Hua Yan Bei Li", location->city_full);
EXPECT_STREQ("China", location->country_full); EXPECT_STREQ("China", location->country_full);
EXPECT_STREQ("Beijing", location->province_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); EXPECT_EQ(2, location->ref_cnt);
location = NULL; location = NULL;

View File

@@ -757,7 +757,7 @@ TEST(TSG_Table, TSG_SECURITY_SOURCE_LOCATION)
struct location_info location = {0}; struct location_info location = {0};
location.country_full = (char *)"country_full_test"; location.country_full = (char *)"country_full_test";
location.city_full = (char *)"city_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); location.full_location_len=strlen(location.full_location);
struct maat_state *mid = maat_state_new(g_tsg_maat_feather, a_stream.threadnum); struct maat_state *mid = maat_state_new(g_tsg_maat_feather, a_stream.threadnum);
struct maat_rule results[MAX_RESULT_NUM] = {0}; struct maat_rule results[MAX_RESULT_NUM] = {0};
@@ -774,7 +774,7 @@ TEST(TSG_Table, TSG_SECURITY_DESTINATION_LOCATION)
struct location_info location = {0}; struct location_info location = {0};
location.country_full = (char *)"country_full_test"; location.country_full = (char *)"country_full_test";
location.city_full = (char *)"city_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); location.full_location_len=strlen(location.full_location);
struct maat_state *mid = maat_state_new(g_tsg_maat_feather, a_stream.threadnum); struct maat_state *mid = maat_state_new(g_tsg_maat_feather, a_stream.threadnum);
struct maat_rule results[MAX_RESULT_NUM] = {0}; struct maat_rule results[MAX_RESULT_NUM] = {0};