diff options
| author | luwenpeng <[email protected]> | 2024-07-19 18:20:04 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2024-07-19 18:57:57 +0800 |
| commit | 2045d517cabbf7559e18367fa33b3a170143ef79 (patch) | |
| tree | 15c70ad522c455c6b51622181442e12cea75f3e7 /common | |
| parent | 88a7a8c5c48f681cdd0478a809652ac94c2647ee (diff) | |
featureļ¼ TSG-21853 Refactoring TFE Kafka infrastructure
Diffstat (limited to 'common')
| -rw-r--r-- | common/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | common/include/kafka.h | 31 | ||||
| -rw-r--r-- | common/include/tfe_kafka_logger.h | 44 | ||||
| -rw-r--r-- | common/include/tfe_resource.h | 24 | ||||
| -rw-r--r-- | common/include/tfe_utils.h | 9 | ||||
| -rw-r--r-- | common/src/intercept_policy.cpp | 2 | ||||
| -rw-r--r-- | common/src/kafka.cpp | 251 | ||||
| -rw-r--r-- | common/src/tfe_kafka_logger.cpp | 212 | ||||
| -rw-r--r-- | common/src/tfe_resource.cpp | 277 | ||||
| -rw-r--r-- | common/src/tfe_scan.cpp | 58 |
10 files changed, 426 insertions, 484 deletions
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 35a8c40..0aa8dfc 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,6 +1,6 @@ add_library( common src/tfe_utils.cpp src/tfe_types.cpp src/tfe_future.cpp src/tfe_http.cpp src/tfe_plugin.cpp - src/tfe_rpc.cpp src/tfe_cmsg.cpp src/tfe_kafka_logger.cpp src/tfe_resource.cpp src/tfe_scan.cpp + src/tfe_rpc.cpp src/tfe_cmsg.cpp src/kafka.cpp src/tfe_resource.cpp src/tfe_scan.cpp src/tfe_pkt_util.cpp src/tfe_tcp_restore.cpp src/packet_construct.cpp src/tap.cpp src/io_uring.cpp src/intercept_policy.cpp src/tfe_fieldstat.cpp src/tuple.cpp src/tfe_packet_io.cpp src/tfe_session_table.cpp diff --git a/common/include/kafka.h b/common/include/kafka.h new file mode 100644 index 0000000..4a242ed --- /dev/null +++ b/common/include/kafka.h @@ -0,0 +1,31 @@ +#ifndef _KAFKA_H +#define _KAFKA_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +enum topic_idx +{ + TOPIC_RULE_HITS, + TOPIC_PROXY_EVENT, + TOPIC_FILE_STREAM, + TOPIC_EXCH_CERT, + + // add more topic here + + MAX_TOPIC_NUM, +}; + +struct kafka *kafka_create(const char *profile); +void kafka_destroy(struct kafka *handle); +// return 0: if success +// return -1: if failed +int kafka_send(struct kafka *handle, enum topic_idx idx, const char *data, int len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/common/include/tfe_kafka_logger.h b/common/include/tfe_kafka_logger.h deleted file mode 100644 index 0ea0d20..0000000 --- a/common/include/tfe_kafka_logger.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _TFE_KAFKA_LOGGER_H -#define _TFE_KAFKA_LOGGER_H - -#ifdef __cpluscplus -extern "C" -{ -#endif - -#include <tfe_utils.h> -#include <librdkafka/rdkafka.h> - -enum kafka_topic_type -{ - TOPIC_LOGGER, - TOPIC_BUCKET, - TOPIC_MC_CACHE, - TOPIC_MAX -}; - -typedef struct tfe_kafka_logger_s -{ - int enable; - int t_vsys_id; - - unsigned int local_ip_num; - char local_ip_str[TFE_SYMBOL_MAX]; - - char topic_name[TOPIC_MAX][TFE_STRING_MAX]; - char broker_list[TFE_STRING_MAX]; - - rd_kafka_t *kafka_handle[TOPIC_MAX]; - rd_kafka_topic_t *kafka_topic[TOPIC_MAX]; -} tfe_kafka_logger_t; - -tfe_kafka_logger_t *tfe_kafka_logger_create(int enable, const char *nic_name, const char *brokerlist, void *local_logger); -int tfe_logger_create_kafka_topic(tfe_kafka_logger_t *logger, const char *sasl_username, const char *sasl_passwd, const char *topic_name, int topic_id, void *local_logger); -void tfe_kafka_logger_destroy(tfe_kafka_logger_t *logger); -int tfe_kafka_logger_send(tfe_kafka_logger_t *logger, int topic_id, const char *data, int len); - -#ifdef __cpluscplus -} -#endif - -#endif diff --git a/common/include/tfe_resource.h b/common/include/tfe_resource.h index 8597770..a2f321e 100644 --- a/common/include/tfe_resource.h +++ b/common/include/tfe_resource.h @@ -11,15 +11,6 @@ struct app_id_dict void app_id_dict_free(struct app_id_dict *app_dict); -enum RESOURCE_TYPE -{ - STATIC_MAAT, - KAFKA_LOGGER, - DEVICE_ID, - EFFECTIVE_DEVICE_TAG, - DYNAMIC_FIELDSTAT, -}; - enum scan_common_table { PXY_CTRL_SOURCE_IP, @@ -46,6 +37,15 @@ enum scan_common_table __SCAN_COMMON_TABLE_MAX }; -int tfe_bussiness_resouce_init(); -void *tfe_bussiness_resouce_get(enum RESOURCE_TYPE type); -int tfe_bussiness_tableid_get(enum scan_common_table type);
\ No newline at end of file +int tfe_env_init(); +int tfe_bussiness_tableid_get(enum scan_common_table type); + +int tfe_get_vsys_id(); +const char *tfe_get_device_id(); +const char *tfe_get_data_center(); +const char *tfe_get_device_group(); +const char *tfe_get_device_tag(); +const char *tfe_get_sled_ip(); +struct kafka *tfe_get_kafka_handle(); +struct maat *tfe_get_maat_handle(); +struct tfe_fieldstat_metric_t *tfe_get_fieldstat_handle();
\ No newline at end of file diff --git a/common/include/tfe_utils.h b/common/include/tfe_utils.h index bda4958..a8b37a3 100644 --- a/common/include/tfe_utils.h +++ b/common/include/tfe_utils.h @@ -9,18 +9,11 @@ #include <time.h> #include <dirent.h> //scan_dir #include <stdbool.h> +#include "kafka.h" -#define LOG_TAG_POLICY "POLICY" -#define LOG_TAG_UTILS "UTILS" -#define LOG_TAG_RAWPKT "RAW_PACKET" #define LOG_TAG_CTRLPKT "CTRL_PACKET" #define LOG_TAG_STABLE "SESSION_TABLE" #define LOG_TAG_PKTIO "PACKET_IO" -#define LOG_TAG_METRICS "G_METRICS" -#define LOG_TAG_SF_METRICS "SF_METRICS" -#define LOG_TAG_SF_STATUS "SF_STATUS" -#define LOG_TAG_SCE "SCE" -#define LOG_TAG_TIMESTAMP "TIMESTAMP" #define TFE_STRING_MAX 2048 #define TFE_PATH_MAX 256 diff --git a/common/src/intercept_policy.cpp b/common/src/intercept_policy.cpp index 47c9607..d8f57cb 100644 --- a/common/src/intercept_policy.cpp +++ b/common/src/intercept_policy.cpp @@ -217,7 +217,7 @@ struct intercept_policy_enforcer *intercept_policy_enforcer_create(void *logger) { int ret = 0; struct intercept_policy_enforcer *enforcer = ALLOC(struct intercept_policy_enforcer, 1); - enforcer->maat = (struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT); + enforcer->maat = tfe_get_maat_handle(); enforcer->logger = logger; enforcer->table_id = maat_get_table_id(enforcer->maat, "PXY_INTERCEPT_COMPILE"); diff --git a/common/src/kafka.cpp b/common/src/kafka.cpp new file mode 100644 index 0000000..a82c641 --- /dev/null +++ b/common/src/kafka.cpp @@ -0,0 +1,251 @@ +#include <stdlib.h> +#include <string.h> + +#include "kafka.h" +#include "tfe_utils.h" +#include <MESA/MESA_prof_load.h> +#include <librdkafka/rdkafka.h> + +#define MAX_SYMBOL_LEN 128 + +struct config +{ + char brokerlist[MAX_SYMBOL_LEN]; + char sasl_username[MAX_SYMBOL_LEN]; + char sasl_passwd[MAX_SYMBOL_LEN]; + char topic_name[MAX_TOPIC_NUM][MAX_SYMBOL_LEN]; +}; + +struct per_producer_per_topic +{ + rd_kafka_t *producer; + rd_kafka_topic_t *topic; +}; + +struct kafka +{ + struct config cfg; + struct per_producer_per_topic *pppt[MAX_TOPIC_NUM]; +}; + +/****************************************************************************** + * Private API + ******************************************************************************/ + +static void per_producer_per_topic_free(struct per_producer_per_topic *pppt) +{ + if (pppt) + { + if (pppt->topic) + { + rd_kafka_topic_destroy(pppt->topic); + pppt->topic = NULL; + } + + if (pppt->producer) + { + rd_kafka_destroy(pppt->producer); + pppt->producer = NULL; + } + + free(pppt); + pppt = NULL; + } +} + +static struct per_producer_per_topic *per_producer_per_topic_new(const char *brokerlist, const char *sasl_username, const char *sasl_passwd, const char *topic_name) +{ + char err_str[1024] = {0}; + struct per_producer_per_topic *pppt = (struct per_producer_per_topic *)calloc(1, sizeof(struct per_producer_per_topic)); + if (!pppt) + { + return NULL; + } + + rd_kafka_conf_t *conf = rd_kafka_conf_new(); + if (!conf) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: failed to create kafka conf"); + goto error_out; + } + if (rd_kafka_conf_set(conf, "queue.buffering.max.messages", "1000000", err_str, sizeof(err_str)) != RD_KAFKA_CONF_OK) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: failed to set kafka queue.buffering.max.messages, %s", err_str); + goto error_out; + } + if (rd_kafka_conf_set(conf, "topic.metadata.refresh.interval.ms", "600000", err_str, sizeof(err_str)) != RD_KAFKA_CONF_OK) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: failed to set kafka topic.metadata.refresh.interval.ms, %s", err_str); + goto error_out; + } + if (rd_kafka_conf_set(conf, "client.id", topic_name, err_str, sizeof(err_str)) != RD_KAFKA_CONF_OK) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: failed to set kafka client.id, %s", err_str); + goto error_out; + } + if (strlen(sasl_username) > 0 && strlen(sasl_passwd) > 0) + { + if (rd_kafka_conf_set(conf, "security.protocol", "sasl_plaintext", err_str, sizeof(err_str)) != RD_KAFKA_CONF_OK) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: failed to set kafka security.protocol, %s", err_str); + goto error_out; + } + if (rd_kafka_conf_set(conf, "sasl.mechanisms", "PLAIN", err_str, sizeof(err_str)) != RD_KAFKA_CONF_OK) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: failed to set kafka sasl.mechanisms, %s", err_str); + goto error_out; + } + if (rd_kafka_conf_set(conf, "sasl.username", sasl_username, err_str, sizeof(err_str)) != RD_KAFKA_CONF_OK) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: failed to set kafka sasl.username, %s", err_str); + goto error_out; + } + if (rd_kafka_conf_set(conf, "sasl.password", sasl_passwd, err_str, sizeof(err_str)) != RD_KAFKA_CONF_OK) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: failed to set kafka sasl.password, %s", err_str); + goto error_out; + } + } + else + { + if (rd_kafka_conf_set(conf, "security.protocol", "plaintext", err_str, sizeof(err_str)) != RD_KAFKA_CONF_OK) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: failed to set kafka security.protocol, %s", err_str); + goto error_out; + } + } + + // The conf object is freed by this function and must not be used or destroyed by the application sub-sequently. + pppt->producer = rd_kafka_new(RD_KAFKA_PRODUCER, conf, err_str, sizeof(err_str)); + conf = NULL; + if (pppt->producer == NULL) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: failed to create kafka producer, %s", err_str); + goto error_out; + } + + if (rd_kafka_brokers_add(pppt->producer, brokerlist) == 0) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: failed to add kafka brokers"); + goto error_out; + } + + pppt->topic = rd_kafka_topic_new(pppt->producer, topic_name, NULL); + if (pppt->topic == NULL) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: failed to create kafka topic: %s", topic_name); + goto error_out; + } + + return pppt; + +error_out: + if (conf) + { + rd_kafka_conf_destroy(conf); + } + + per_producer_per_topic_free(pppt); + return NULL; +} + +/****************************************************************************** + * Public API -- Kafka + ******************************************************************************/ + +// due to limit by client.id, need per producer per topic +struct kafka *kafka_create(const char *profile) +{ + struct kafka *handle = (struct kafka *)calloc(1, sizeof(struct kafka)); + if (!handle) + { + return NULL; + } + + MESA_load_profile_string_def(profile, "kafka", "brokerlist", handle->cfg.brokerlist, sizeof(handle->cfg.brokerlist), ""); + MESA_load_profile_string_def(profile, "kafka", "sasl_username", handle->cfg.sasl_username, sizeof(handle->cfg.sasl_username), ""); + MESA_load_profile_string_def(profile, "kafka", "sasl_passwd", handle->cfg.sasl_passwd, sizeof(handle->cfg.sasl_passwd), ""); + MESA_load_profile_string_def(profile, "kafka", "rule_hits_topic", handle->cfg.topic_name[TOPIC_RULE_HITS], sizeof(handle->cfg.topic_name[TOPIC_RULE_HITS]), ""); + MESA_load_profile_string_def(profile, "kafka", "proxy_event_topic", handle->cfg.topic_name[TOPIC_PROXY_EVENT], sizeof(handle->cfg.topic_name[TOPIC_PROXY_EVENT]), ""); + MESA_load_profile_string_def(profile, "kafka", "file_stream_topic", handle->cfg.topic_name[TOPIC_FILE_STREAM], sizeof(handle->cfg.topic_name[TOPIC_FILE_STREAM]), ""); + MESA_load_profile_string_def(profile, "kafka", "exch_cert_topic", handle->cfg.topic_name[TOPIC_EXCH_CERT], sizeof(handle->cfg.topic_name[TOPIC_EXCH_CERT]), ""); + + if (strlen(handle->cfg.brokerlist) == 0) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: brokerlist is empty"); + goto error_out; + } + + for (int i = 0; i < MAX_TOPIC_NUM; i++) + { + if (strlen(handle->cfg.topic_name[i]) == 0) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: topic_name[%d] is empty", i); + goto error_out; + } + } + + for (int i = 0; i < MAX_TOPIC_NUM; i++) + { + handle->pppt[i] = per_producer_per_topic_new(handle->cfg.brokerlist, handle->cfg.sasl_username, handle->cfg.sasl_passwd, handle->cfg.topic_name[i]); + if (!handle->pppt[i]) + { + goto error_out; + } + } + + return handle; + +error_out: + kafka_destroy(handle); + return NULL; +} + +void kafka_destroy(struct kafka *handle) +{ + if (handle) + { + for (int i = 0; i < MAX_TOPIC_NUM; i++) + { + per_producer_per_topic_free(handle->pppt[i]); + handle->pppt[i] = NULL; + } + + free(handle); + handle = NULL; + } +} + +int kafka_send(struct kafka *handle, enum topic_idx idx, const char *data, int len) +{ + if (!handle) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: handle is NULL"); + return -1; + } + + if (idx < 0 || idx >= MAX_TOPIC_NUM) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: invalid topic index: %d", idx); + return -1; + } + + if (handle->pppt[idx]) + { + if (rd_kafka_produce(handle->pppt[idx]->topic, RD_KAFKA_PARTITION_UA, RD_KAFKA_MSG_F_COPY, (void *)data, len, NULL, 0, NULL) == -1) + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: failed to produce message with topic [%d], %s", idx, rd_kafka_err2str(rd_kafka_last_error())); + return -1; + } + else + { + TFE_LOG_DEBUG(g_default_logger, "KAFKA: success to produce message with topic [%d], %s", idx, data); + return 0; + } + } + else + { + TFE_LOG_ERROR(g_default_logger, "KAFKA: topic %d not initialized", idx); + return -1; + } +}
\ No newline at end of file diff --git a/common/src/tfe_kafka_logger.cpp b/common/src/tfe_kafka_logger.cpp deleted file mode 100644 index 28f4ce8..0000000 --- a/common/src/tfe_kafka_logger.cpp +++ /dev/null @@ -1,212 +0,0 @@ -#include <sys/ioctl.h> -#include <unistd.h> -#include <arpa/inet.h> -#include <net/if.h> - -#include <tfe_kafka_logger.h> - -// return INADDR_NONE if error occur -static unsigned int get_ip_by_eth_name(const char *ifname) -{ - int sockfd = -1; - struct ifreq ifr; - unsigned int ip; - - sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (-1 == sockfd) - { - goto error; - } - - strcpy(ifr.ifr_name, ifname); - if (ioctl(sockfd, SIOCGIFADDR, &ifr) == -1) - { - goto error; - } - close(sockfd); - - ip = ((struct sockaddr_in *)&(ifr.ifr_addr))->sin_addr.s_addr; - return ip; - -error: - if (sockfd > 0) - close(sockfd); - return INADDR_NONE; -} - -static rd_kafka_t *create_kafka_handle(const char *brokerlist, const char *sasl_username, const char *sasl_passwd, const char *topic_name, void *local_logger) -{ - int ret; - char kafka_errstr[1024] = {0}; - rd_kafka_t *handle = NULL; - rd_kafka_conf_t *rconf = NULL; - - rconf = rd_kafka_conf_new(); - - ret = rd_kafka_conf_set(rconf, "queue.buffering.max.messages", "1000000", kafka_errstr, sizeof(kafka_errstr)); - if (ret != RD_KAFKA_CONF_OK) - { - TFE_LOG_ERROR(local_logger, "Error to set kafka \"queue.buffering.max.messages\", %s.", kafka_errstr); - rd_kafka_conf_destroy(rconf); - return NULL; - } - ret = rd_kafka_conf_set(rconf, "topic.metadata.refresh.interval.ms", "600000", kafka_errstr, sizeof(kafka_errstr)); - if (ret != RD_KAFKA_CONF_OK) - { - TFE_LOG_ERROR(local_logger, "Error to set kafka \"topic.metadata.refresh.interval.ms\", %s.", kafka_errstr); - rd_kafka_conf_destroy(rconf); - return NULL; - } - ret = rd_kafka_conf_set(rconf, "security.protocol", "plaintext", kafka_errstr, sizeof(kafka_errstr)); - if (ret != RD_KAFKA_CONF_OK) - { - TFE_LOG_ERROR(local_logger, "Error to set kafka \"security.protocol\", %s.", kafka_errstr); - rd_kafka_conf_destroy(rconf); - return NULL; - } - ret = rd_kafka_conf_set(rconf, "client.id", topic_name, kafka_errstr, sizeof(kafka_errstr)); - if (ret != RD_KAFKA_CONF_OK) - { - TFE_LOG_ERROR(local_logger, "Error to set kafka \"client.id\", %s.", kafka_errstr); - rd_kafka_conf_destroy(rconf); - return NULL; - } - - if (strlen(sasl_username) > 0 && strlen(sasl_passwd) > 0) - { - rd_kafka_conf_set(rconf, "security.protocol", "sasl_plaintext", kafka_errstr, sizeof(kafka_errstr)); - rd_kafka_conf_set(rconf, "sasl.mechanisms", "PLAIN", kafka_errstr, sizeof(kafka_errstr)); - ret = rd_kafka_conf_set(rconf, "sasl.username", sasl_username, kafka_errstr, sizeof(kafka_errstr)); - if (ret != RD_KAFKA_CONF_OK) - { - TFE_LOG_ERROR(local_logger, "Error to set kafka \"sasl.username\", %s.", kafka_errstr); - rd_kafka_conf_destroy(rconf); - return NULL; - } - ret = rd_kafka_conf_set(rconf, "sasl.password", sasl_passwd, kafka_errstr, sizeof(kafka_errstr)); - if (ret != RD_KAFKA_CONF_OK) - { - TFE_LOG_ERROR(local_logger, "Error to set kafka \"sasl.password\", %s.", kafka_errstr); - rd_kafka_conf_destroy(rconf); - return NULL; - } - } - - //The conf object is freed by this function and must not be used or destroyed by the application sub-sequently. - handle = rd_kafka_new(RD_KAFKA_PRODUCER, rconf, kafka_errstr, sizeof(kafka_errstr)); - rconf = NULL; - if (handle == NULL) - { - TFE_LOG_ERROR(local_logger, "Error to new kafka, %s.", kafka_errstr); - return NULL; - } - - if (rd_kafka_brokers_add(handle, brokerlist) == 0) - { - TFE_LOG_ERROR(local_logger, "Error to add kakfa bokers."); - rd_kafka_destroy(handle); - return NULL; - } - - return handle; -} - -int tfe_kafka_logger_topic_new(tfe_kafka_logger_t *logger, const char *topic_name, int topic_id, void *local_logger) -{ - if(logger && logger->enable) - { - strncpy(logger->topic_name[topic_id], topic_name, sizeof(logger->topic_name[topic_id])-1); - logger->kafka_topic[topic_id] = rd_kafka_topic_new(logger->kafka_handle[topic_id], topic_name, NULL); - if (logger->kafka_topic[topic_id] == NULL) - { - TFE_LOG_ERROR(local_logger, "Error to creat kafka topic: %s.", topic_name); - rd_kafka_destroy(logger->kafka_handle[topic_id]); - free(logger); - return -1; - } - } - return 0; -} - -tfe_kafka_logger_t *tfe_kafka_logger_create(int enable, const char *nic_name, const char *brokerlist, void *local_logger) -{ - char *override_sled_ip=NULL; - - tfe_kafka_logger_t *logger = (tfe_kafka_logger_t *)calloc(1, sizeof(tfe_kafka_logger_t)); - if (!logger) - { - return NULL; - } - - logger->enable = enable; - if (!logger->enable) - { - return logger; - } - - override_sled_ip = getenv("OVERRIDE_SLED_IP"); - if(override_sled_ip != NULL) - { - strncpy(logger->local_ip_str, override_sled_ip, sizeof(logger->local_ip_str)-1); - goto finish; - } - - logger->local_ip_num = get_ip_by_eth_name(nic_name); - if (logger->local_ip_num == INADDR_NONE) - { - TFE_LOG_ERROR(local_logger, "Error to get NIC_NAME: %s.", nic_name); - free(logger); - return NULL; - } - inet_ntop(AF_INET, &(logger->local_ip_num), logger->local_ip_str, sizeof(logger->local_ip_str)); -finish: - strncpy(logger->broker_list, brokerlist, sizeof(logger->broker_list)-1); - return logger; -} - -int tfe_logger_create_kafka_topic(tfe_kafka_logger_t *logger, const char *sasl_username, const char *sasl_passwd, const char *topic_name, int topic_id, void *local_logger) -{ - if(!logger->enable) - { - return 0; - } - - logger->kafka_handle[topic_id] = create_kafka_handle(logger->broker_list, sasl_username, sasl_passwd, topic_name, local_logger); - if (logger->kafka_handle[topic_id] == NULL) - { - TFE_LOG_ERROR(local_logger, "Error to creat kafka handler with brokerlist: %s.", logger->broker_list); - free(logger); - return -1; - } - tfe_kafka_logger_topic_new(logger, topic_name, topic_id, logger); - return 0; -} - -void tfe_kafka_logger_destroy(tfe_kafka_logger_t *logger) -{ - if (logger) - { - for(int i=0; i<TOPIC_MAX; i++) - { - if(logger->kafka_topic[i]) - { - rd_kafka_topic_destroy(logger->kafka_topic[i]); - } - - if(logger->kafka_handle[i]) - { - rd_kafka_destroy(logger->kafka_handle[i]); - } - } - free(logger); - logger = NULL; - } -} - -int tfe_kafka_logger_send(tfe_kafka_logger_t *logger, int topic_id, const char *data, int len) -{ - if (logger && logger->enable) - return rd_kafka_produce(logger->kafka_topic[topic_id], RD_KAFKA_PARTITION_UA, RD_KAFKA_MSG_F_COPY, (void *)data, len, NULL, 0, NULL); - else - return 0; -} diff --git a/common/src/tfe_resource.cpp b/common/src/tfe_resource.cpp index c0c4e6d..8379a65 100644 --- a/common/src/tfe_resource.cpp +++ b/common/src/tfe_resource.cpp @@ -1,21 +1,73 @@ #include <MESA/MESA_prof_load.h> #include <MESA/maat.h> #include <cjson/cJSON.h> -#include <tfe_kafka_logger.h> #include <tfe_fieldstat.h> #include <tfe_proxy.h> #include <tfe_resource.h> +#include "kafka.h" #define MAAT_INPUT_JSON 0 #define MAAT_INPUT_REDIS 1 #define MAAT_INPUT_FILE 2 static int scan_table_id[__SCAN_COMMON_TABLE_MAX]; -static struct maat *static_maat = NULL; -static tfe_kafka_logger_t *kafka_logger = NULL; static struct tfe_fieldstat_metric_t *dynamic_fieldstat = NULL; -static char *device_id = NULL; -static char *effective_device_tag=NULL; +static char *device_tag=NULL; + +struct tfe_fieldstat_metric_t *fieldstat_handle = NULL; +struct kafka *kafka_handle = NULL; +struct maat *maat_handle = NULL; + +static int vsys_id = 0; +static char data_center[1024] = {0}; +static char device_group[1024] = {0}; +static char device_id[1024] = {0}; +static char sled_ip[1024] = {0}; + +int tfe_get_vsys_id() +{ + return vsys_id; +} + +const char *tfe_get_device_id() +{ + return device_id; +} + +const char *tfe_get_data_center() +{ + return data_center; +} + +const char *tfe_get_device_group() +{ + return device_group; +} + +const char *tfe_get_device_tag() +{ + return device_tag; +} + +const char *tfe_get_sled_ip() +{ + return sled_ip; +} + +struct kafka *tfe_get_kafka_handle() +{ + return kafka_handle; +} + +struct maat *tfe_get_maat_handle() +{ + return maat_handle; +} + +struct tfe_fieldstat_metric_t *tfe_get_fieldstat_handle() +{ + return fieldstat_handle; +} static struct tfe_fieldstat_metric_t *create_fieldstat_instance(const char *profile, const char *section, int max_thread, void *logger) { @@ -173,129 +225,9 @@ error_out: return NULL; } -static tfe_kafka_logger_t *create_kafka_logger(const char *profile, const char *section, void *logger) -{ - int ret=0, enable=0, vsystem_id=0; - char nic_name[TFE_SYMBOL_MAX] = {0}; - char brokerlist[TFE_STRING_MAX] = {0}; - char logger_topic[TFE_STRING_MAX] = {0}; - char bucket_topic[TFE_STRING_MAX] = {0}; - char sasl_username[TFE_STRING_MAX] = {0}; - char sasl_passwd[TFE_STRING_MAX] = {0}; - tfe_kafka_logger_t *kafka_logger = NULL; - - MESA_load_profile_int_def(profile, section, "enable", &enable, 1); - MESA_load_profile_int_def(profile, section, "VSYSTEM_ID", &vsystem_id, 1); - MESA_load_profile_string_def(profile, section, "NIC_NAME", nic_name, sizeof(nic_name), "eth0"); - MESA_load_profile_string_def(profile, section, "KAFKA_BROKERLIST", brokerlist, sizeof(brokerlist), ""); - MESA_load_profile_string_def(profile, section, "LOGGER_SEND_TOPIC", logger_topic, sizeof(logger_topic), "PROXY-EVENT"); - MESA_load_profile_string_def(profile, section, "FILE_BUCKET_TOPIC", bucket_topic, sizeof(bucket_topic), "TRAFFIC-FILE-STREAM-RECORD"); - MESA_load_profile_string_def(profile, section, "SASL_USERNAME", sasl_username, sizeof(sasl_username), ""); - MESA_load_profile_string_def(profile, section, "SASL_PASSWD", sasl_passwd, sizeof(sasl_passwd), ""); - - if (!strlen(brokerlist)) - { - TFE_LOG_ERROR(logger, "tfe kafka init failed, no brokerlist in profile %s section %s.", profile, section); - return NULL; - } - - kafka_logger = tfe_kafka_logger_create(enable, nic_name, brokerlist, logger); - if (kafka_logger == NULL) - { - TFE_LOG_ERROR(logger, "tfe kafka init failed, error to create kafka logger."); - return NULL; - } - - ret = tfe_logger_create_kafka_topic(kafka_logger, sasl_username, sasl_passwd, logger_topic, TOPIC_LOGGER, logger); - if(ret < 0) - { - TFE_LOG_ERROR(logger, "tfe kafka init failed, error to create %s topic.", logger_topic); - return NULL; - } - - ret = tfe_logger_create_kafka_topic(kafka_logger, sasl_username, sasl_passwd, bucket_topic, TOPIC_BUCKET, logger); - if(ret < 0) - { - TFE_LOG_ERROR(logger, "tfe kafka init failed, error to create %s topic.", bucket_topic); - return NULL; - } - kafka_logger->t_vsys_id=vsystem_id; - - TFE_LOG_INFO(logger, "tfe kafka logger : %s", enable ? "ENABLE" : "DISABLE"); - TFE_LOG_INFO(logger, "tfe kafka vsystem id : %d", vsystem_id); - TFE_LOG_INFO(logger, "tfe logger kafka topic : %s", logger_topic); - TFE_LOG_INFO(logger, "tfe bucket kafka topic : %s", bucket_topic); - TFE_LOG_INFO(logger, "tfe kafka brokerlist : %s", brokerlist); - - if (strlen(sasl_username) > 0 && strlen(sasl_passwd) > 0) - { - TFE_LOG_INFO(logger, "tfe kafka sasl_username : %s", sasl_username); - TFE_LOG_INFO(logger, "tfe kafka sasl_passwd : %s", sasl_passwd); - } - - return kafka_logger; -} - -static char *cerate_device_id(const char *profile, const char *section, void *logger) +static char* create_device_tag(const char *profile, const char *section, void *logger) { - int ret = -1; - size_t device_id_size = 0; - char *tsg_sn_file = NULL, *device_id; - - const char *device_def_id = "DFT2201925000001"; - cJSON *json = NULL, *item = NULL; - char device_id_filepath[TFE_STRING_MAX] = {0}; - - ret = MESA_load_profile_string_def(profile, section, "device_id_filepath", device_id_filepath, sizeof(device_id_filepath), NULL); - if (ret < 0) - { - TFE_LOG_ERROR(logger, "Invalid device parameter: device_id_filepath not existed in profile %s section %s.", profile, section); - goto finish; - } - tsg_sn_file = tfe_read_file(device_id_filepath, &device_id_size); - if (tsg_sn_file == NULL) - { - TFE_LOG_ERROR(logger, "Invalid device parameter: device sn file not existed."); - goto finish; - } - json = cJSON_Parse(tsg_sn_file); - if (json == NULL) - { - TFE_LOG_ERROR(logger, "Invalid device parameter: %s invalid json format", tsg_sn_file); - goto finish; - } - item = cJSON_GetObjectItem(json, "sn"); - if (unlikely(!item || !cJSON_IsString(item))) - { - TFE_LOG_ERROR(logger, "Invalid device parameter: %s invalid json format", tsg_sn_file); - goto finish; - } - device_id = tfe_strdup(item->valuestring); - - if(tsg_sn_file) - { - FREE(&tsg_sn_file); - } - cJSON_Delete(json); - TFE_LOG_INFO(logger, "tfe device id : %s", device_id); - - return device_id; -finish: - TFE_LOG_INFO(logger, "tfe use default device id : %s", device_def_id); - if (json) - { - cJSON_Delete(json); - } - if(tsg_sn_file) - { - FREE(&tsg_sn_file); - } - return (char *)device_def_id; -} - -static char* create_effective_device_tag(const char *profile, const char *section, void *logger) -{ - char *effective_device_tag=NULL; + char *c=NULL; char accept_path[TFE_PATH_MAX] = {0}, accept_tags[TFE_STRING_MAX] = {0}; MESA_load_profile_string_def(profile, section, "accept_path", accept_path, sizeof(accept_path), ""); @@ -307,10 +239,10 @@ static char* create_effective_device_tag(const char *profile, const char *sectio { return NULL; } - effective_device_tag = tfe_strdup(accept_tags); - TFE_LOG_INFO(logger, "tfe device tag : %s", effective_device_tag); + device_tag = tfe_strdup(accept_tags); + TFE_LOG_INFO(logger, "tfe device tag : %s", device_tag); - return effective_device_tag; + return device_tag; } void app_dict_table_new_cb(const char *table_name, int table_id, const char* key, const char* table_line, void **ad, long argl, void* argp) @@ -410,71 +342,62 @@ static int maat_common_table_init() for (int i = 0; i < __SCAN_COMMON_TABLE_MAX; i++) { - scan_table_id[i] = maat_get_table_id(static_maat, table_name[i]); + scan_table_id[i] = maat_get_table_id(maat_handle, table_name[i]); if (scan_table_id[i] < 0) { TFE_LOG_ERROR(g_default_logger, "Maat table %s register failed.", table_name[i]); return -1; } } - maat_plugin_table_ex_schema_register(static_maat, "APP_ID_DICT", app_dict_table_new_cb, app_dict_table_free_cb, app_dict_table_dup_cb, 0, NULL); + maat_plugin_table_ex_schema_register(maat_handle, "APP_ID_DICT", app_dict_table_new_cb, app_dict_table_free_cb, app_dict_table_dup_cb, 0, NULL); return 0; } -int tfe_bussiness_resouce_init() +int tfe_env_init() { - const char *profile_path = "./conf/tfe/tfe.conf"; - unsigned int thread_num = tfe_proxy_get_work_thread_count(); - static_maat = create_maat_feather("static", profile_path, "MAAT", thread_num, g_default_logger); - if (!static_maat) - { - return -1; - } + const char *profile_path = "./conf/tfe/tfe.conf"; - kafka_logger = create_kafka_logger(profile_path, "kafka", g_default_logger); - if (!kafka_logger) - { - return -1; - } + MESA_load_profile_int_def(profile_path, "public", "vsys_id", &vsys_id, 0); + MESA_load_profile_string_def(profile_path, "public", "data_center", data_center, sizeof(data_center), ""); + MESA_load_profile_string_def(profile_path, "public", "device_group", device_group, sizeof(device_group), ""); + MESA_load_profile_string_def(profile_path, "public", "device_id", device_id, sizeof(device_id), ""); - dynamic_fieldstat = create_fieldstat_instance(profile_path, "proxy_hits", thread_num, g_default_logger); - if(!dynamic_fieldstat) - { - return -1; - } + char *ptr = getenv("OVERRIDE_SLED_IP"); + if (ptr == NULL) + { + return -1; + } + strncpy(sled_ip, ptr, strlen(ptr)); - device_id = cerate_device_id(profile_path, "kafka", g_default_logger); - - effective_device_tag = create_effective_device_tag(profile_path, "MAAT", g_default_logger); + kafka_handle = kafka_create(profile_path); + if (!kafka_handle) + { + return -1; + } - if (maat_common_table_init()) - { - return -1; - } + unsigned int thread_num = tfe_proxy_get_work_thread_count(); + maat_handle = create_maat_feather("static", profile_path, "MAAT", thread_num, g_default_logger); + if (!maat_handle) + { + return -1; + } - return 0; -} + dynamic_fieldstat = create_fieldstat_instance(profile_path, "proxy_hits", thread_num, g_default_logger); + if (!dynamic_fieldstat) + { + return -1; + } -void *tfe_bussiness_resouce_get(enum RESOURCE_TYPE type) -{ - switch (type) - { - case STATIC_MAAT: - return static_maat; - case KAFKA_LOGGER: - return kafka_logger; - case DEVICE_ID: - return device_id; - case EFFECTIVE_DEVICE_TAG: - return effective_device_tag; - case DYNAMIC_FIELDSTAT: - return dynamic_fieldstat; - default: - return NULL; - } + device_tag = create_device_tag(profile_path, "MAAT", g_default_logger); + if (maat_common_table_init()) + { + return -1; + } + + return 0; } int tfe_bussiness_tableid_get(enum scan_common_table type) { - return scan_table_id[type]; + return scan_table_id[type]; }
\ No newline at end of file diff --git a/common/src/tfe_scan.cpp b/common/src/tfe_scan.cpp index fe77194..a886e68 100644 --- a/common/src/tfe_scan.cpp +++ b/common/src/tfe_scan.cpp @@ -30,7 +30,7 @@ int tfe_scan_subscribe_id(const struct tfe_stream *stream, long long *result, st if (strlen(source_subscribe_id)) { - scan_ret = maat_scan_string((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_SUBSCRIBER_ID), + scan_ret = maat_scan_string(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_SUBSCRIBER_ID), source_subscribe_id, strlen(source_subscribe_id),result + hit_cnt + hit_cnt_ip, MAX_SCAN_RESULT - hit_cnt - hit_cnt_ip, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) @@ -44,7 +44,7 @@ int tfe_scan_subscribe_id(const struct tfe_stream *stream, long long *result, st TFE_LOG_INFO(logger, "Scan src TSG_OBJ_SUBSCRIBER_ID, NO hit subid: %s scan ret: %d addr: %s", source_subscribe_id, scan_ret, stream->str_stream_info); } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_SUBSCRIBER_ID), + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_SUBSCRIBER_ID), result + hit_cnt + hit_cnt_ip, MAX_SCAN_RESULT - hit_cnt - hit_cnt_ip, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { @@ -54,7 +54,7 @@ int tfe_scan_subscribe_id(const struct tfe_stream *stream, long long *result, st if (strlen(dest_subscribe_id)) { - scan_ret = maat_scan_string((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_SUBSCRIBER_ID), + scan_ret = maat_scan_string(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_SUBSCRIBER_ID), dest_subscribe_id, strlen(dest_subscribe_id),result + hit_cnt + hit_cnt_ip, MAX_SCAN_RESULT - hit_cnt - hit_cnt_ip,&n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) @@ -68,7 +68,7 @@ int tfe_scan_subscribe_id(const struct tfe_stream *stream, long long *result, st TFE_LOG_INFO(logger, "Scan dst TSG_OBJ_SUBSCRIBER_ID, NO hit subid: %s scan ret: %d addr: %s", dest_subscribe_id, scan_ret, stream->str_stream_info); } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_SUBSCRIBER_ID), + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_SUBSCRIBER_ID), result + hit_cnt + hit_cnt_ip, MAX_SCAN_RESULT - hit_cnt - hit_cnt_ip, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { @@ -84,13 +84,13 @@ static int scan_group(struct maat_hit_group hit_group, long long *result, struct size_t n_hit_result=0; int scan_ret=0, hit_cnt_group=0; - scan_ret = maat_scan_group((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), table_id, &hit_group, 1, + scan_ret = maat_scan_group(tfe_get_maat_handle(), table_id, &hit_group, 1, result+hit_cnt+hit_cnt_group, MAX_SCAN_RESULT-hit_cnt-hit_cnt_group, &n_hit_result, scan_mid); if(scan_ret == MAAT_SCAN_HIT) { hit_cnt_group+=n_hit_result; } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), table_id, result+hit_cnt+hit_cnt_group, + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), table_id, result+hit_cnt+hit_cnt_group, MAX_SCAN_RESULT-hit_cnt-hit_cnt_group, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { @@ -242,19 +242,19 @@ int tfe_scan_app_id(long long *result, struct maat_state *scan_mid, int hit_cnt, size_t n_hit_result = 0; struct maat_hit_group hit_group; - struct app_id_dict *app_dict = (struct app_id_dict*)maat_plugin_table_get_ex_data((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_APP_ID_DICT), + struct app_id_dict *app_dict = (struct app_id_dict*)maat_plugin_table_get_ex_data(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_APP_ID_DICT), (const char *)&app_id, sizeof(long long)); if(app_dict!=NULL) { memset(&hit_group, 0, sizeof(hit_group)); hit_group.group_id=app_dict->group_id; - scan_ret = maat_scan_group((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), table_id, &hit_group, 1, result+hit_cnt+hit_app_id, + scan_ret = maat_scan_group(tfe_get_maat_handle(), table_id, &hit_group, 1, result+hit_cnt+hit_app_id, MAX_SCAN_RESULT-hit_cnt-hit_app_id, &n_hit_result, scan_mid); if(scan_ret==MAAT_SCAN_HIT) { hit_app_id += n_hit_result; } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), table_id, result+hit_cnt+hit_app_id, MAX_SCAN_RESULT-hit_cnt-hit_app_id, &n_hit_result, scan_mid); + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), table_id, result+hit_cnt+hit_app_id, MAX_SCAN_RESULT-hit_cnt-hit_app_id, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { hit_app_id += n_hit_result; @@ -298,13 +298,13 @@ int tfe_scan_internal_exteral_addr(const struct tfe_stream *stream, long long *r if(n_last_hit_group > 0) { maat_state_get_last_hit_groups(scan_mid, last_hit_groups, array_size); - scan_ret = maat_scan_group((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), table_id, last_hit_groups, array_size, result+hit_cnt+hit_cnt_ip, + scan_ret = maat_scan_group(tfe_get_maat_handle(), table_id, last_hit_groups, array_size, result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if(scan_ret == MAAT_SCAN_HIT) { hit_cnt_ip += n_hit_result; } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), table_id, + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), table_id, result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { @@ -332,13 +332,13 @@ int tfe_scan_internal_exteral_port(const struct tfe_stream *stream, long long *r if(n_last_hit_group > 0) { maat_state_get_last_hit_groups(scan_mid, last_hit_groups, array_size); - scan_ret = maat_scan_group((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), table_id, last_hit_groups, array_size, result+hit_cnt+hit_cnt_port, + scan_ret = maat_scan_group(tfe_get_maat_handle(), table_id, last_hit_groups, array_size, result+hit_cnt+hit_cnt_port, MAX_SCAN_RESULT-hit_cnt-hit_cnt_port, &n_hit_result, scan_mid); if(scan_ret == MAAT_SCAN_HIT) { hit_cnt_port += n_hit_result; } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), table_id, + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), table_id, result+hit_cnt+hit_cnt_port, MAX_SCAN_RESULT-hit_cnt-hit_cnt_port, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { @@ -354,7 +354,7 @@ int tfe_scan_port(const struct tfe_stream *stream, long long *result, struct maa int hit_cnt_port = 0; size_t n_hit_result = 0; - scan_ret=maat_scan_integer((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_SOURCE_PORT), ntohs(source), + scan_ret=maat_scan_integer(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_SOURCE_PORT), ntohs(source), result+hit_cnt+hit_cnt_port, MAX_SCAN_RESULT-hit_cnt-hit_cnt_port, &n_hit_result, scan_mid); if(scan_ret == MAAT_SCAN_HIT) { @@ -365,14 +365,14 @@ int tfe_scan_port(const struct tfe_stream *stream, long long *result, struct maa { hit_cnt_port+=scan_ret; } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_SOURCE_PORT), + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_SOURCE_PORT), result+hit_cnt+hit_cnt_port, MAX_SCAN_RESULT-hit_cnt-hit_cnt_port, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { hit_cnt_port+=n_hit_result; } - scan_ret=maat_scan_integer((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_DESTINATION_PORT), ntohs(dest), + scan_ret=maat_scan_integer(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_DESTINATION_PORT), ntohs(dest), result+hit_cnt+hit_cnt_port, MAX_SCAN_RESULT-hit_cnt-hit_cnt_port, &n_hit_result, scan_mid); if(scan_ret == MAAT_SCAN_HIT) { @@ -383,7 +383,7 @@ int tfe_scan_port(const struct tfe_stream *stream, long long *result, struct maa { hit_cnt_port+=scan_ret; } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_DESTINATION_PORT), + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_DESTINATION_PORT), result+hit_cnt+hit_cnt_port, MAX_SCAN_RESULT-hit_cnt-hit_cnt_port, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { @@ -403,20 +403,20 @@ int tfe_scan_ipv4_addr(const struct tfe_stream *stream, long long *result, struc memset(&hit_group, 0, sizeof(hit_group)); hit_group.group_id=PROTOCOL_TCP_GROUP_ID; - scan_ret = maat_scan_group((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_IP_PROTOCOL), &hit_group, 1, + scan_ret = maat_scan_group(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_IP_PROTOCOL), &hit_group, 1, result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if(scan_ret==MAAT_SCAN_HIT) { hit_cnt_ip += n_hit_result; } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_IP_PROTOCOL), + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_IP_PROTOCOL), result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { hit_cnt_ip += n_hit_result; } - scan_ret = maat_scan_ipv4_port((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_SOURCE_IP), sapp_addr.v4->saddr, ntohs(sapp_addr.v4->source), + scan_ret = maat_scan_ipv4_port(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_SOURCE_IP), sapp_addr.v4->saddr, ntohs(sapp_addr.v4->source), result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { @@ -427,14 +427,14 @@ int tfe_scan_ipv4_addr(const struct tfe_stream *stream, long long *result, struc { hit_cnt_ip += scan_ret; } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_SOURCE_IP), + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_SOURCE_IP), result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { hit_cnt_ip += n_hit_result; } - scan_ret = maat_scan_ipv4_port((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_DESTINATION_IP), sapp_addr.v4->daddr, ntohs(sapp_addr.v4->dest), + scan_ret = maat_scan_ipv4_port(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_DESTINATION_IP), sapp_addr.v4->daddr, ntohs(sapp_addr.v4->dest), result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if(scan_ret == MAAT_SCAN_HIT) { @@ -445,7 +445,7 @@ int tfe_scan_ipv4_addr(const struct tfe_stream *stream, long long *result, struc { hit_cnt_ip += scan_ret; } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_DESTINATION_IP), + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_DESTINATION_IP), result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { @@ -464,19 +464,19 @@ int tfe_scan_ipv6_addr(const struct tfe_stream *stream, long long *result, struc memset(&hit_group, 0, sizeof(hit_group)); hit_group.group_id=PROTOCOL_TCP_GROUP_ID; - scan_ret = maat_scan_group((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_IP_PROTOCOL), &hit_group, 1, + scan_ret = maat_scan_group(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_IP_PROTOCOL), &hit_group, 1, result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if(scan_ret==MAAT_SCAN_HIT) { hit_cnt_ip += n_hit_result; } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_IP_PROTOCOL), + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_IP_PROTOCOL), result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { hit_cnt_ip += n_hit_result; } - scan_ret = maat_scan_ipv6_port((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_SOURCE_IP), sapp_addr.v6->saddr, ntohs(sapp_addr.v6->source), + scan_ret = maat_scan_ipv6_port(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_SOURCE_IP), sapp_addr.v6->saddr, ntohs(sapp_addr.v6->source), result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { @@ -487,14 +487,14 @@ int tfe_scan_ipv6_addr(const struct tfe_stream *stream, long long *result, struc { hit_cnt_ip += scan_ret; } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_SOURCE_IP), + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_SOURCE_IP), result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { hit_cnt_ip += n_hit_result; } - scan_ret = maat_scan_ipv6_port((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_DESTINATION_IP), sapp_addr.v6->daddr, ntohs(sapp_addr.v6->dest), + scan_ret = maat_scan_ipv6_port(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_DESTINATION_IP), sapp_addr.v6->daddr, ntohs(sapp_addr.v6->dest), result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { @@ -505,7 +505,7 @@ int tfe_scan_ipv6_addr(const struct tfe_stream *stream, long long *result, struc { hit_cnt_ip += scan_ret; } - scan_ret = maat_scan_not_logic((struct maat *)tfe_bussiness_resouce_get(STATIC_MAAT), tfe_bussiness_tableid_get(PXY_CTRL_DESTINATION_IP), + scan_ret = maat_scan_not_logic(tfe_get_maat_handle(), tfe_bussiness_tableid_get(PXY_CTRL_DESTINATION_IP), result+hit_cnt+hit_cnt_ip, MAX_SCAN_RESULT-hit_cnt-hit_cnt_ip, &n_hit_result, scan_mid); if (scan_ret == MAAT_SCAN_HIT) { |
