TSG Master 共享部分扫描结果给 TFE
* TSG-2847 - TFE 新增 cmsg 共享 TSG Master 的扫描结果 * TSG-2851 - Pangu 从 cmsg 获取 TSG Master 的扫描结果 * TSG-2852 - DOH 从 cmsg 获取 TSG Master 的扫描结果 * TSG-2849 - TFE DOH 功能支持 SUBID * 合并 pangu/doh 的 maat scan 的代码为 tfe_scan
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
#include <tfe_utils.h>
|
||||
#include <tfe_resource.h>
|
||||
#include <tfe_proxy.h>
|
||||
#include <tfe_kafka_logger.h>
|
||||
#include <cjson/cJSON.h>
|
||||
#include <MESA/Maat_rule.h>
|
||||
#include <MESA/MESA_prof_load.h>
|
||||
#include <MESA/Maat_rule.h>
|
||||
#include <cjson/cJSON.h>
|
||||
#include <tfe_kafka_logger.h>
|
||||
#include <tfe_proxy.h>
|
||||
#include <tfe_resource.h>
|
||||
|
||||
#define MAAT_INPUT_JSON 0
|
||||
#define MAAT_INPUT_REDIS 1
|
||||
@@ -13,13 +12,12 @@
|
||||
struct maat_table_info
|
||||
{
|
||||
int id;
|
||||
char *name;
|
||||
const char *name;
|
||||
Maat_plugin_EX_new_func_t *new_func;
|
||||
Maat_plugin_EX_dup_func_t *dup_func;
|
||||
Maat_plugin_EX_free_func_t *free_func;
|
||||
};
|
||||
static Maat_feather_t static_maat = NULL;
|
||||
static Maat_feather_t dynamic_maat = NULL;
|
||||
static tfe_kafka_logger_t *kafka_logger = NULL;
|
||||
static char *device_id = NULL;
|
||||
|
||||
@@ -32,7 +30,7 @@ static Maat_feather_t create_maat_feather(const char *instance_name, const char
|
||||
char redis_server[TFE_STRING_MAX] = {0};
|
||||
char redis_port_range[TFE_STRING_MAX] = {0};
|
||||
char accept_tags[TFE_STRING_MAX] = {0};
|
||||
char accept_path[TFE_PATH_MAX]={0};
|
||||
char accept_path[TFE_PATH_MAX] = {0};
|
||||
int redis_port_begin = 0, redis_port_end = 0;
|
||||
int redis_port_select = 0;
|
||||
int redis_db_idx = 0;
|
||||
@@ -135,9 +133,9 @@ static Maat_feather_t create_maat_feather(const char *instance_name, const char
|
||||
Maat_set_feather_opt(target, MAAT_OPT_SCAN_DETAIL, &scan_detail, sizeof(scan_detail));
|
||||
if (strlen(accept_path) > 0)
|
||||
{
|
||||
MESA_load_profile_string_def(accept_path, "maat", "ACCEPT_TAGS", accept_tags, sizeof(accept_tags), "{\"tags\":[{\"tag\":\"device_id\",\"value\":\"device_1\"}]}");
|
||||
MESA_load_profile_string_def(accept_path, "maat", "ACCEPT_TAGS", accept_tags, sizeof(accept_tags), "{\"tags\":[{\"tag\":\"device_id\",\"value\":\"device_1\"}]}");
|
||||
Maat_set_feather_opt(target, MAAT_OPT_ACCEPT_TAGS, &accept_tags, sizeof(accept_tags));
|
||||
TFE_LOG_INFO(logger, "tfe accept tags : %s", accept_tags);
|
||||
TFE_LOG_INFO(logger, "tfe accept tags : %s", accept_tags);
|
||||
}
|
||||
|
||||
ret = Maat_initiate_feather(target);
|
||||
@@ -233,129 +231,7 @@ finish:
|
||||
return (char *)device_def_id;
|
||||
}
|
||||
|
||||
static void ip_asn_table_new_cb(int table_id, const char *key, const char *table_line, MAAT_PLUGIN_EX_DATA *ad, long argl, void *argp)
|
||||
{
|
||||
int addr_type;
|
||||
int ret = 0, profile_id = 0, is_valid = 0;
|
||||
char start_ip[40], end_ip[40], asn[40] = {0};
|
||||
char organization[TFE_PATH_MAX];
|
||||
|
||||
ret = sscanf(table_line, "%d\t%d\t%s\t%s\t%s\t%s\t%d", &profile_id, &addr_type, start_ip, end_ip, asn, organization, &is_valid);
|
||||
if (ret != 7)
|
||||
{
|
||||
TFE_LOG_ERROR(g_default_logger, "Policy table parse ip ASN failed, ret:%d, %s", ret, table_line);
|
||||
return;
|
||||
}
|
||||
tfe_unescape(organization);
|
||||
|
||||
struct ip_data_table *ip_asn = ALLOC(struct ip_data_table, 1);
|
||||
memset(ip_asn, 0, sizeof(struct ip_data_table));
|
||||
ip_asn->profile_id = profile_id;
|
||||
ip_asn->asn = tfe_strdup(asn);
|
||||
ip_asn->organization = tfe_strdup(organization);
|
||||
ip_asn->ref_cnt = 1;
|
||||
pthread_mutex_init(&(ip_asn->lock), NULL);
|
||||
|
||||
TFE_LOG_INFO(g_default_logger, "Policy table add success %d", profile_id);
|
||||
|
||||
*ad = ip_asn;
|
||||
}
|
||||
|
||||
static void ip_location_table_new_cb(int table_id, const char *key, const char *table_line, MAAT_PLUGIN_EX_DATA *ad, long argl, void *argp)
|
||||
{
|
||||
int ret = 0, profile_id = 0, is_valid = 0;
|
||||
int geoname_id = 0, addr_type = 0;
|
||||
double latitude, longitude, coords;
|
||||
char language[40], start_ip[40], end_ip[40];
|
||||
char continent_abbr[TFE_PATH_MAX], continent_full[TFE_PATH_MAX];
|
||||
char country_abbr[TFE_PATH_MAX], province_abbr[TFE_PATH_MAX], time_zone[TFE_PATH_MAX];
|
||||
char country_full[TFE_PATH_MAX], province_full[TFE_PATH_MAX], city_full[TFE_PATH_MAX];
|
||||
|
||||
ret = sscanf(table_line, "%d\t%d\t%d\t%s\t%s\t%lf\t%lf\t%lf\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d", &profile_id, &geoname_id,
|
||||
&addr_type, start_ip, end_ip, &latitude, &longitude, &coords, language,
|
||||
continent_abbr, continent_full, country_abbr, country_full, province_abbr, province_full,
|
||||
city_full, time_zone, &is_valid);
|
||||
|
||||
if (ret != 18)
|
||||
{
|
||||
TFE_LOG_ERROR(g_default_logger, "Policy table parse ip location failed, ret:%d, %s", ret, table_line);
|
||||
return;
|
||||
}
|
||||
tfe_unescape(continent_full);
|
||||
tfe_unescape(country_full);
|
||||
tfe_unescape(province_full);
|
||||
tfe_unescape(city_full);
|
||||
|
||||
struct ip_data_table *ip_asn = ALLOC(struct ip_data_table, 1);
|
||||
memset(ip_asn, 0, sizeof(struct ip_data_table));
|
||||
ip_asn->profile_id = profile_id;
|
||||
ip_asn->country_full = tfe_strdup(country_full);
|
||||
ip_asn->province_full = tfe_strdup(province_full);
|
||||
ip_asn->city_full = tfe_strdup(city_full);
|
||||
ip_asn->ref_cnt = 1;
|
||||
pthread_mutex_init(&(ip_asn->lock), NULL);
|
||||
|
||||
TFE_LOG_INFO(g_default_logger, "Policy table add success %d", profile_id);
|
||||
|
||||
*ad = ip_asn;
|
||||
}
|
||||
|
||||
static void ip_table_dup_cb(int table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DATA *from, long argl, void *argp)
|
||||
{
|
||||
struct ip_data_table *ip_asn = (struct ip_data_table *)(*from);
|
||||
pthread_mutex_lock(&(ip_asn->lock));
|
||||
ip_asn->ref_cnt++;
|
||||
pthread_mutex_unlock(&(ip_asn->lock));
|
||||
*to = ip_asn;
|
||||
}
|
||||
|
||||
static void ip_table_free_cb(int table_id, MAAT_PLUGIN_EX_DATA *ad, long argl, void *argp)
|
||||
{
|
||||
if (*ad == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
struct ip_data_table *ip_asn = (struct ip_data_table *)(*ad);
|
||||
pthread_mutex_lock(&(ip_asn->lock));
|
||||
ip_asn->ref_cnt--;
|
||||
if (ip_asn->ref_cnt > 0)
|
||||
{
|
||||
pthread_mutex_unlock(&(ip_asn->lock));
|
||||
return;
|
||||
}
|
||||
pthread_mutex_unlock(&(ip_asn->lock));
|
||||
pthread_mutex_destroy(&(ip_asn->lock));
|
||||
|
||||
if (ip_asn->asn)
|
||||
FREE(&ip_asn->asn);
|
||||
if (ip_asn->organization)
|
||||
FREE(&ip_asn->organization);
|
||||
if (ip_asn->country_full)
|
||||
FREE(&ip_asn->country_full);
|
||||
if (ip_asn->province_full)
|
||||
FREE(&ip_asn->province_full);
|
||||
if (ip_asn->city_full)
|
||||
FREE(&ip_asn->city_full);
|
||||
|
||||
FREE(&ip_asn);
|
||||
*ad = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
void ip_table_free(struct ip_data_table *ip_asn)
|
||||
{
|
||||
ip_table_free_cb(0, (void **)&ip_asn, 0, NULL);
|
||||
}
|
||||
|
||||
static struct maat_table_info maat_pub_tables[TABLE_TYPE_MAX] = {
|
||||
// TABLE_IP_ASN_USER_DEFINED
|
||||
{0, "TSG_IP_ASN_USER_DEFINED", ip_asn_table_new_cb, ip_table_dup_cb, ip_table_free_cb},
|
||||
// TABLE_IP_ASN_BUILT_IN
|
||||
{0, "TSG_IP_ASN_BUILT_IN", ip_asn_table_new_cb, ip_table_dup_cb, ip_table_free_cb},
|
||||
// TABLE_IP_LOCATION_USER_DEFINED
|
||||
{0, "TSG_IP_LOCATION_USER_DEFINED", ip_location_table_new_cb, ip_table_dup_cb, ip_table_free_cb},
|
||||
// TABLE_IP_LOCATION_BUILT_IN
|
||||
{0, "TSG_IP_LOCATION_BUILT_IN", ip_location_table_new_cb, ip_table_dup_cb, ip_table_free_cb},
|
||||
// TABLE_SECURITY_SOURCE_ASN
|
||||
{0, "TSG_SECURITY_SOURCE_ASN", NULL, NULL, NULL},
|
||||
// TABLE_SECURITY_DESTINATION_ASN
|
||||
@@ -363,8 +239,9 @@ static struct maat_table_info maat_pub_tables[TABLE_TYPE_MAX] = {
|
||||
// TABLE_SECURITY_SOURCE_LOCATION
|
||||
{0, "TSG_SECURITY_SOURCE_LOCATION", NULL, NULL, NULL},
|
||||
// TABLE_SECURITY_DESTINATION_LOCATION
|
||||
{0, "TSG_SECURITY_DESTINATION_LOCATION", NULL, NULL, NULL}
|
||||
};
|
||||
{0, "TSG_SECURITY_DESTINATION_LOCATION", NULL, NULL, NULL},
|
||||
// TABLE_OBJ_SUBSCRIBER_ID
|
||||
{0, "TSG_OBJ_SUBSCRIBER_ID", NULL, NULL, NULL}};
|
||||
|
||||
static int register_maat_table()
|
||||
{
|
||||
@@ -397,12 +274,6 @@ int tfe_bussiness_resouce_init()
|
||||
return -1;
|
||||
}
|
||||
|
||||
dynamic_maat = create_maat_feather("dyn", profile_path, "DYNAMIC_MAAT", thread_num, g_default_logger);
|
||||
if (!dynamic_maat)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
kafka_logger = create_kafka_logger(profile_path, "kafka", g_default_logger);
|
||||
if (!kafka_logger)
|
||||
{
|
||||
@@ -425,8 +296,6 @@ void *tfe_bussiness_resouce_get(enum RESOURCE_TYPE type)
|
||||
{
|
||||
case STATIC_MAAT:
|
||||
return static_maat;
|
||||
case DYNAMINC_MAAT:
|
||||
return dynamic_maat;
|
||||
case KAFKA_LOGGER:
|
||||
return kafka_logger;
|
||||
case DEVICE_ID:
|
||||
|
||||
Reference in New Issue
Block a user