Feature 4 layer location
This commit is contained in:
@@ -51,8 +51,8 @@
|
|||||||
39 TSG_PROFILE_RESPONSE_PAGES plugin {"key":1,"foreign":"4","valid":5} --
|
39 TSG_PROFILE_RESPONSE_PAGES plugin {"key":1,"foreign":"4","valid":5} --
|
||||||
40 TSG_IP_ASN_BUILT_IN ip_plugin {"row_id":1,"ip_type":2,"start_ip":3,"end_ip":4,"valid":7,"estimate_size":4194304}
|
40 TSG_IP_ASN_BUILT_IN ip_plugin {"row_id":1,"ip_type":2,"start_ip":3,"end_ip":4,"valid":7,"estimate_size":4194304}
|
||||||
41 TSG_IP_ASN_USER_DEFINED ip_plugin {"row_id":1,"ip_type":2,"start_ip":3,"end_ip":4,"valid":7,"estimate_size":4194304}
|
41 TSG_IP_ASN_USER_DEFINED ip_plugin {"row_id":1,"ip_type":2,"start_ip":3,"end_ip":4,"valid":7,"estimate_size":4194304}
|
||||||
42 TSG_IP_LOCATION_BUILT_IN ip_plugin {"row_id":1,"ip_type":3,"start_ip":4,"end_ip":5,"valid":18,"estimate_size":4194304}
|
42 TSG_IP_LOCATION_BUILT_IN ip_plugin {"row_id":1,"ip_type":3,"start_ip":4,"end_ip":5,"valid":19,"estimate_size":4194304}
|
||||||
43 TSG_IP_LOCATION_USER_DEFINED ip_plugin {"row_id":1,"ip_type":3,"start_ip":4,"end_ip":5,"valid":18,"estimate_size":4194304}
|
43 TSG_IP_LOCATION_USER_DEFINED ip_plugin {"row_id":1,"ip_type":3,"start_ip":4,"end_ip":5,"valid":19,"estimate_size":4194304}
|
||||||
44 TSG_OBJ_AS_NUMBER expr UTF8 UTF8/GBK yes 0
|
44 TSG_OBJ_AS_NUMBER expr UTF8 UTF8/GBK yes 0
|
||||||
45 TSG_SECURITY_SOURCE_ASN virtual TSG_OBJ_AS_NUMBER --
|
45 TSG_SECURITY_SOURCE_ASN virtual TSG_OBJ_AS_NUMBER --
|
||||||
46 TSG_SECURITY_DESTINATION_ASN virtual TSG_OBJ_AS_NUMBER --
|
46 TSG_SECURITY_DESTINATION_ASN virtual TSG_OBJ_AS_NUMBER --
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ struct location_info
|
|||||||
char *country_full;
|
char *country_full;
|
||||||
char *province_full;
|
char *province_full;
|
||||||
char *city_full;
|
char *city_full;
|
||||||
|
char *subdivision_addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct subscribe_id_info
|
struct subscribe_id_info
|
||||||
|
|||||||
@@ -263,6 +263,7 @@ typedef struct tsg_para
|
|||||||
short mirror_switch;
|
short mirror_switch;
|
||||||
unsigned short timeout;
|
unsigned short timeout;
|
||||||
int dynamic_maat_switch;
|
int dynamic_maat_switch;
|
||||||
|
int location_field_num;
|
||||||
int app_dict_field_num;
|
int app_dict_field_num;
|
||||||
int device_seq_in_dc;
|
int device_seq_in_dc;
|
||||||
int datacenter_id;
|
int datacenter_id;
|
||||||
|
|||||||
@@ -425,24 +425,22 @@ void location_dup_data(int table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DAT
|
|||||||
|
|
||||||
void location_new_data(int table_id, const char* key, const char* table_line, MAAT_PLUGIN_EX_DATA* ad, long argl, void* argp)
|
void location_new_data(int table_id, const char* key, const char* table_line, MAAT_PLUGIN_EX_DATA* ad, long argl, void* argp)
|
||||||
{
|
{
|
||||||
int country_full=13,province_full=15,city_full=16;
|
int country_full=13,province_full=15,city_full=16,subdivision_addr=17;
|
||||||
struct location_info *location=(struct location_info *)calloc(1, sizeof(struct location_info));
|
struct location_info *location=(struct location_info *)calloc(1, sizeof(struct location_info));
|
||||||
|
|
||||||
location->country_full=tsg_get_column_string_value(table_line, country_full);
|
location->country_full=tsg_get_column_string_value(table_line, country_full);
|
||||||
location->province_full=tsg_get_column_string_value(table_line, province_full);
|
location->province_full=tsg_get_column_string_value(table_line, province_full);
|
||||||
location->city_full=tsg_get_column_string_value(table_line, city_full);
|
location->city_full=tsg_get_column_string_value(table_line, city_full);
|
||||||
|
|
||||||
if(location->country_full==NULL && location->province_full==NULL && location->city_full==NULL)
|
|
||||||
{
|
|
||||||
_free_field((char *)location);
|
|
||||||
location=NULL;
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
str_unescape(location->country_full);
|
str_unescape(location->country_full);
|
||||||
str_unescape(location->province_full);
|
str_unescape(location->province_full);
|
||||||
str_unescape(location->city_full);
|
str_unescape(location->city_full);
|
||||||
|
|
||||||
|
if(g_tsg_para.location_field_num==19)
|
||||||
|
{
|
||||||
|
location->subdivision_addr=tsg_get_column_string_value(table_line, subdivision_addr);
|
||||||
|
str_unescape(location->subdivision_addr);
|
||||||
|
}
|
||||||
|
|
||||||
atomic_inc(&location->ref_cnt);
|
atomic_inc(&location->ref_cnt);
|
||||||
*ad=(MAAT_PLUGIN_EX_DATA)location;
|
*ad=(MAAT_PLUGIN_EX_DATA)location;
|
||||||
|
|
||||||
@@ -459,6 +457,8 @@ void location_free_data(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, void*
|
|||||||
_free_field(location->country_full);
|
_free_field(location->country_full);
|
||||||
_free_field(location->province_full);
|
_free_field(location->province_full);
|
||||||
_free_field(location->city_full);
|
_free_field(location->city_full);
|
||||||
|
_free_field(location->subdivision_addr);
|
||||||
|
|
||||||
_free_field((char *)(*ad));
|
_free_field((char *)(*ad));
|
||||||
*ad=NULL;
|
*ad=NULL;
|
||||||
}
|
}
|
||||||
@@ -1694,6 +1694,7 @@ int tsg_rule_init(const char* conffile, void *logger)
|
|||||||
char cb_subscriber_ip_table[32]={0};
|
char cb_subscriber_ip_table[32]={0};
|
||||||
|
|
||||||
MESA_load_profile_int_def(conffile, "MAAT","APP_ID_TABLE_TYPE", &g_tsg_para.app_dict_field_num, 18);
|
MESA_load_profile_int_def(conffile, "MAAT","APP_ID_TABLE_TYPE", &g_tsg_para.app_dict_field_num, 18);
|
||||||
|
MESA_load_profile_int_def(conffile, "MAAT","LOCATION_TABLE_TYPE", &g_tsg_para.location_field_num, 18);
|
||||||
|
|
||||||
MESA_load_profile_string_def(conffile, "MAAT", "PROFILE", maat_conffile, sizeof(maat_conffile), "./tsgconf/maat.conf");
|
MESA_load_profile_string_def(conffile, "MAAT", "PROFILE", maat_conffile, sizeof(maat_conffile), "./tsgconf/maat.conf");
|
||||||
MESA_load_profile_string_def(conffile, "MAAT", "SECURITY_COMPILE", g_tsg_para.table_name[TABLE_SECURITY_COMPILE], _MAX_TABLE_NAME_LEN, "TSG_SECURITY_COMPILE");
|
MESA_load_profile_string_def(conffile, "MAAT", "SECURITY_COMPILE", g_tsg_para.table_name[TABLE_SECURITY_COMPILE], _MAX_TABLE_NAME_LEN, "TSG_SECURITY_COMPILE");
|
||||||
@@ -2143,22 +2144,36 @@ int tsg_scan_ip_asn(Maat_feather_t maat_feather, const struct streaminfo *a_stre
|
|||||||
int tsg_scan_ip_location(Maat_feather_t maat_feather, const struct streaminfo *a_stream, struct location_info *location, enum MASTER_TABLE idx, scan_status_t *mid, Maat_rule_t*result, int result_num)
|
int tsg_scan_ip_location(Maat_feather_t maat_feather, const struct streaminfo *a_stream, struct location_info *location, enum MASTER_TABLE idx, scan_status_t *mid, Maat_rule_t*result, int result_num)
|
||||||
{
|
{
|
||||||
int ret=0;
|
int ret=0;
|
||||||
char buff[1024]={0};
|
char full_address[1024]={0};
|
||||||
|
|
||||||
if(location==NULL || location->country_full==NULL || location->city_full==NULL || result==NULL || result_num==0)
|
if(location==NULL || result==NULL || result_num==0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buff, sizeof(buff), "%s.%s.", location->country_full, location->city_full);
|
if(g_tsg_para.location_field_num==19)
|
||||||
ret=Maat_full_scan_string(maat_feather, g_tsg_para.table_id[idx], CHARSET_GBK, buff, strlen(buff), result, NULL, result_num, mid, a_stream->threadnum);
|
{
|
||||||
|
snprintf(full_address,
|
||||||
|
sizeof(full_address),
|
||||||
|
"%s.%s.%s.%s.",
|
||||||
|
location->country_full,
|
||||||
|
location->province_full,
|
||||||
|
location->city_full,
|
||||||
|
location->subdivision_addr==NULL ? "" : location->subdivision_addr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(full_address, sizeof(full_address), "%s.%s.", location->country_full, location->city_full);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret=Maat_full_scan_string(maat_feather, g_tsg_para.table_id[idx], CHARSET_GBK, full_address, strlen(full_address), result, NULL, result_num, mid, a_stream->threadnum);
|
||||||
if(ret > 0)
|
if(ret > 0)
|
||||||
{
|
{
|
||||||
MESA_handle_runtime_log(g_tsg_para.logger,
|
MESA_handle_runtime_log(g_tsg_para.logger,
|
||||||
RLOG_LV_DEBUG,
|
RLOG_LV_DEBUG,
|
||||||
"SCAN_IP_LOCATION",
|
"SCAN_IP_LOCATION",
|
||||||
"Hit IP_LOCATION: %s scan ret: %d table_name: %s policy_id: %d service: %d action: %d addr: %s",
|
"Hit IP_LOCATION: %s scan ret: %d table_name: %s policy_id: %d service: %d action: %d addr: %s",
|
||||||
buff,
|
full_address,
|
||||||
ret,
|
ret,
|
||||||
g_tsg_para.table_name[idx],
|
g_tsg_para.table_name[idx],
|
||||||
result[0].config_id,
|
result[0].config_id,
|
||||||
@@ -2173,7 +2188,7 @@ int tsg_scan_ip_location(Maat_feather_t maat_feather, const struct streaminfo *a
|
|||||||
RLOG_LV_DEBUG,
|
RLOG_LV_DEBUG,
|
||||||
"SCAN_IP_LOCATION",
|
"SCAN_IP_LOCATION",
|
||||||
"No hit IP_LOCATION: %s scan ret: %d table_name: %s addr: %s",
|
"No hit IP_LOCATION: %s scan ret: %d table_name: %s addr: %s",
|
||||||
buff,
|
full_address,
|
||||||
ret,
|
ret,
|
||||||
g_tsg_para.table_name[idx],
|
g_tsg_para.table_name[idx],
|
||||||
PRINTADDR(a_stream, g_tsg_para.level)
|
PRINTADDR(a_stream, g_tsg_para.level)
|
||||||
|
|||||||
@@ -233,17 +233,25 @@ static int set_location(struct TLD_handle_t *_handle, struct streaminfo *a_strea
|
|||||||
char buff[1024]={0};
|
char buff[1024]={0};
|
||||||
int buff_len=sizeof(buff);
|
int buff_len=sizeof(buff);
|
||||||
|
|
||||||
if(location_info!=NULL)
|
if(location_info==NULL)
|
||||||
{
|
{
|
||||||
len+=string_cat(buff+len, buff_len-len, location_info->city_full);
|
return 0;
|
||||||
buff[len++]=',';
|
|
||||||
len+=string_cat(buff+len, buff_len-len, location_info->province_full);
|
|
||||||
buff[len++]=',';
|
|
||||||
len+=string_cat(buff+len, buff_len-len, location_info->country_full);
|
|
||||||
|
|
||||||
TLD_append(_handle, field_name, (void *)buff, TLD_TYPE_STRING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
len+=string_cat(buff+len, buff_len-len, location_info->country_full);
|
||||||
|
buff[len++]='.';
|
||||||
|
len+=string_cat(buff+len, buff_len-len, location_info->province_full);
|
||||||
|
buff[len++]='.';
|
||||||
|
len+=string_cat(buff+len, buff_len-len, location_info->city_full);
|
||||||
|
|
||||||
|
if(location_info->subdivision_addr!=NULL)
|
||||||
|
{
|
||||||
|
buff[len++]='.';
|
||||||
|
len+=string_cat(buff+len, buff_len-len, location_info->subdivision_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
TLD_append(_handle, field_name, (void *)buff, TLD_TYPE_STRING);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user