diff --git a/bin/tsg_log_field.conf b/bin/tsg_log_field.conf index b1561b1..fac4bee 100644 --- a/bin/tsg_log_field.conf +++ b/bin/tsg_log_field.conf @@ -47,5 +47,6 @@ STRING common_clinet_asn 39 STRING common_server_asn 40 STRING common_clinet_location 41 STRING common_server_location 42 -STRING quic_sni 43 -STRING ssl_ja3_fingerprint 44 +STRING quic_sni 43 +STRING ssl_ja3_fingerprint 44 +STRING common_data_center 45 \ No newline at end of file diff --git a/src/tsg_entry.h b/src/tsg_entry.h index bc613e8..e756f6f 100644 --- a/src/tsg_entry.h +++ b/src/tsg_entry.h @@ -97,6 +97,7 @@ typedef struct _tsg_para int proto_flag; //tsg_protocol_t int fs2_field_id[TSG_FS2_MAX]; char device_sn[MAX_DOAMIN_LEN/8]; + char data_center[_MAX_TABLE_NAME_LEN]; char table_name[TABLE_MAX][_MAX_TABLE_NAME_LEN]; void *logger; screen_stat_handle_t fs2_handle; diff --git a/src/tsg_rule.cpp b/src/tsg_rule.cpp index 8d34bd8..bdb0d24 100644 --- a/src/tsg_rule.cpp +++ b/src/tsg_rule.cpp @@ -6,7 +6,7 @@ #include #include #include - +#include "MESA/cJSON.h" #include "MESA/MESA_handle_logger.h" #include "Maat_rule.h" #include "Maat_command.h" @@ -124,6 +124,39 @@ static int proto_str2id(tsg_protocol_t proto) return 0; } +static int get_data_center(char *accept_tag, char *data_center, int data_center_len) +{ + int i=0,len; + cJSON *object=cJSON_Parse(accept_tag); + if(object!=NULL) + { + cJSON *array=cJSON_GetObjectItem(object, "tags"); + if(array!=NULL) + { + for(i=0; ivaluestring!=NULL && (memcmp("device_id", tag_item->valuestring, strlen("device_id")))==0) + { + cJSON *v_item=cJSON_GetObjectItem(item, "value"); + if(v_item!=NULL && v_item->valuestring!=NULL) + { + len=strlen(v_item->valuestring); + memcpy(data_center, v_item->valuestring, (len>data_center_len-1 ? data_center_len-1 : len)); + } + return 1; + } + } + } + } + } + + return 0; +} + static void eliminate_default_value(char *value) { if(value!=NULL && (memcmp(value, "null", 4))==0) @@ -419,8 +452,22 @@ static Maat_feather_t init_maat_feather(const char* conffile, char* instance_nam memset(effective_flag, 0, sizeof(effective_flag)); MESA_load_profile_string_def(conffile, module, "EFFECTIVE_RANGE_FILE", effective_range_filename, sizeof(effective_range_filename),"./tsgconf/maat.conf"); - MESA_load_profile_string_def(conffile, "MAAT", "ACCEPT_TAGS", effective_flag, sizeof(effective_flag),""); + if(strlen(effective_range_filename)>0) + { + MESA_load_profile_string_def(effective_range_filename, "MAAT", "ACCEPT_TAGS", effective_flag, sizeof(effective_flag),""); + } + + if(strlen(effective_flag)==0) + { + MESA_load_profile_string_def(conffile, "MAAT", "ACCEPT_TAGS", effective_flag, sizeof(effective_flag),""); + } + + if(strlen(g_tsg_para.data_center)==0 && strlen(effective_flag)>0) + { + get_data_center(effective_flag, g_tsg_para.data_center, sizeof(g_tsg_para.data_center)); + } + MESA_load_profile_int_def(conffile, module,"MAAT_MODE", &(maat_mode),0); MESA_load_profile_int_def(conffile, module,"STAT_SWITCH", &(maat_stat_on),1); MESA_load_profile_int_def(conffile, module,"PERF_SWITCH", &(maat_perf_on),1); @@ -515,7 +562,7 @@ int tsg_rule_init(const char* conffile, void *logger) MESA_load_profile_int_def(conffile, "MAAT","APP_ID_TABLE_TYPE", &g_tsg_para.app_id_table_type, 1); - MESA_load_profile_string_def(conffile, "MAAT", "PROFILE", maat_conffile, sizeof(maat_conffile), "./tsgconf/maat_profile.conf"); + MESA_load_profile_string_def(conffile, "MAAT", "PROFILE", maat_conffile, sizeof(maat_conffile), "./tsgconf/maat.conf"); MESA_load_profile_string_def(conffile, "MAAT", "IP_ADDR_TABLE", g_tsg_para.table_name[TABLE_IP_ADDR], _MAX_TABLE_NAME_LEN, "TSG_SECURITY_ADDR"); MESA_load_profile_string_def(conffile, "MAAT", "SUBSCRIBER_ID_TABLE", g_tsg_para.table_name[TABLE_SUBSCRIBER_ID], _MAX_TABLE_NAME_LEN, "TSG_OBJ_SUBSCRIBER_ID"); MESA_load_profile_string_def(conffile, "MAAT", "APP_ID_TABLE", g_tsg_para.table_name[TABLE_APP_ID], _MAX_TABLE_NAME_LEN, "TSG_OBJ_APP_ID"); diff --git a/src/tsg_send_log.cpp b/src/tsg_send_log.cpp index eabb1d2..42e1312 100644 --- a/src/tsg_send_log.cpp +++ b/src/tsg_send_log.cpp @@ -614,8 +614,16 @@ int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handl TLD_append_streaminfo(instance, handle, log_msg->a_stream); TLD_append(_handle, _instance->id2field[LOG_COMMON_SLED_IP].name, (void *)(_instance->local_ip_str), TLD_TYPE_STRING); - TLD_append(_handle, _instance->id2field[LOG_COMMON_DEVICE_ID].name, (void *)(g_tsg_para.device_sn), TLD_TYPE_STRING); + if(strlen(g_tsg_para.device_sn)>0) + { + TLD_append(_handle, _instance->id2field[LOG_COMMON_DEVICE_ID].name, (void *)(g_tsg_para.device_sn), TLD_TYPE_STRING); + } + if(strlen(g_tsg_para.data_center)>0) + { + TLD_append(_handle, _instance->id2field[LOG_COMMON_DATA_CENTER].name, (void *)(g_tsg_para.data_center), TLD_TYPE_STRING); + } + for(i=0;iresult_num; i++) { if(is_multi_hit_same_policy(&(log_msg->result[i]), policy_id, &repeat_cnt)) diff --git a/src/tsg_send_log_internal.h b/src/tsg_send_log_internal.h index e66fc68..9310d6d 100644 --- a/src/tsg_send_log_internal.h +++ b/src/tsg_send_log_internal.h @@ -69,6 +69,7 @@ typedef enum _tsg_log_field_id LOG_COMMON_SERVER_LOCATION, LOG_QUIC_SNI, LOG_SSL_JA3_FINGERPRINT, + LOG_COMMON_DATA_CENTER, LOG_COMMON_MAX }tsg_log_field_id_t;