[PATCH]delete useless code

This commit is contained in:
liuwentan
2024-04-03 16:47:30 +08:00
parent cbabcbd6b0
commit 7e25f48fdd
21 changed files with 3147 additions and 5266 deletions

View File

@@ -92,9 +92,9 @@ struct translate_command {
int default_int;
};
static struct iris_table *query_table_info(struct iris_description *p_iris,
const char *table_name,
enum table_type table_type)
static struct iris_table *
query_table_info(struct iris_description *p_iris, const char *table_name,
enum table_type table_type)
{
if (NULL == p_iris || NULL == table_name ||
table_type == TABLE_TYPE_INVALID) {
@@ -127,11 +127,12 @@ static void free_iris_table_info(void *p)
FREE(table);
}
static int set_iris_descriptor(const char *json_file, cJSON *json,
const char *encrypt_key, const char *encrypt_algo,
const char *compile_tn, const char *group2compile_tn,
const char* group2group_tn, redisContext *redis_write_ctx,
struct iris_description *iris_cfg)
static int
set_iris_descriptor(const char *json_file, cJSON *json,
const char *encrypt_key, const char *encrypt_algo,
const char *compile_tn, const char *group2compile_tn,
const char* group2group_tn, redisContext *redis_write_ctx,
struct iris_description *iris_cfg)
{
memset(iris_cfg, 0, sizeof(struct iris_description));
snprintf(iris_cfg->tmp_iris_dir, sizeof(iris_cfg->tmp_iris_dir),
@@ -251,9 +252,10 @@ static int create_tmp_dir(struct iris_description *p)
return 0;
}
static int write_plugin_line(cJSON *plug_table_json, int sequence,
struct iris_description *p_iris,
struct log_handle *logger)
static int
write_plugin_line(cJSON *plug_table_json, int sequence,
struct iris_description *p_iris,
struct log_handle *logger)
{
cJSON *item = cJSON_GetObjectItem(plug_table_json, "table_name");
if (NULL == item || item->type != cJSON_String) {
@@ -345,9 +347,10 @@ static int get_region_seq(struct iris_description *iris_cfg)
return sequence;
}
static int direct_write_rule(cJSON *json, struct maat_kv_store *str2int,
struct translate_command *cmd, int cmd_cnt,
struct iris_table *table, struct log_handle *logger)
static int
direct_write_rule(cJSON *json, struct maat_kv_store *str2int,
struct translate_command *cmd, int cmd_cnt,
struct iris_table *table, struct log_handle *logger)
{
int i = 0;
int ret = -1;
@@ -404,9 +407,11 @@ static int direct_write_rule(cJSON *json, struct maat_kv_store *str2int,
for (i = 0; i < cmd_cnt; i++) {
table->write_pos += memcat(&(table->buff), table->write_pos, &table->buff_sz,
cmd[i].json_value, strlen(cmd[i].json_value));
table->write_pos += memcat(&(table->buff), table->write_pos, &table->buff_sz, "\t", 1);
table->write_pos += memcat(&(table->buff), table->write_pos,
&table->buff_sz, "\t", 1);
}
table->write_pos += memcat(&(table->buff), table->write_pos, &table->buff_sz, "\n", 1);
table->write_pos += memcat(&(table->buff), table->write_pos,
&table->buff_sz, "\n", 1);
table->line_count++;
ret = 0;
error_out:
@@ -418,8 +423,9 @@ error_out:
return ret;
}
static int write_flag_line(cJSON *region_json, struct iris_description *p_iris,
struct iris_table *table, struct log_handle *logger)
static int
write_flag_line(cJSON *region_json, struct iris_description *p_iris,
struct iris_table *table, struct log_handle *logger)
{
struct translate_command json_cmd[MAX_COLUMN_NUM];
int cmd_cnt = 0;
@@ -455,8 +461,9 @@ static int write_flag_line(cJSON *region_json, struct iris_description *p_iris,
json_cmd, cmd_cnt, table, logger);
}
static int write_expr_line(cJSON *region_json, struct iris_description *p_iris,
struct iris_table *table, struct log_handle *logger)
static int
write_expr_line(cJSON *region_json, struct iris_description *p_iris,
struct iris_table *table, struct log_handle *logger)
{
struct translate_command json_cmd[MAX_COLUMN_NUM];
int cmd_cnt = 0;
@@ -503,8 +510,9 @@ static int write_expr_line(cJSON *region_json, struct iris_description *p_iris,
json_cmd, cmd_cnt, table, logger);
}
static int write_ip_line(cJSON *region_json, struct iris_description *p_iris,
struct iris_table *table, struct log_handle *logger)
static int
write_ip_line(cJSON *region_json, struct iris_description *p_iris,
struct iris_table *table, struct log_handle *logger)
{
struct translate_command json_cmd[MAX_COLUMN_NUM];
int cmd_cnt = 0;
@@ -555,8 +563,9 @@ static int write_ip_line(cJSON *region_json, struct iris_description *p_iris,
json_cmd, cmd_cnt, table, logger);
}
static int write_interval_line(cJSON *region_json, struct iris_description *p_iris,
struct iris_table *table, struct log_handle *logger)
static int
write_interval_line(cJSON *region_json, struct iris_description *p_iris,
struct iris_table *table, struct log_handle *logger)
{
struct translate_command json_cmd[MAX_COLUMN_NUM];
int cmd_cnt = 0;
@@ -592,8 +601,9 @@ static int write_interval_line(cJSON *region_json, struct iris_description *p_ir
json_cmd, cmd_cnt, table, logger);
}
static int write_region_rule(cJSON *region_json, int compile_id, int group_id,
struct iris_description *p_iris, struct log_handle *logger)
static int
write_region_rule(cJSON *region_json, int compile_id, int group_id,
struct iris_description *p_iris, struct log_handle *logger)
{
cJSON *item = cJSON_GetObjectItem(region_json, "table_name");
if (NULL == item || item->type != cJSON_String) {
@@ -662,11 +672,12 @@ static int write_region_rule(cJSON *region_json, int compile_id, int group_id,
return ret;
}
static int write_group2compile_line(int *group_ids, size_t n_group_id,
int compile_id, int group_not_flag,
int clause_index, const char *vtable,
struct iris_description *p_iris,
struct iris_table *g2c_table)
static int
write_group2compile_line(int *group_ids, size_t n_group_id,
int compile_id, int group_not_flag,
int clause_index, const char *vtable,
struct iris_description *p_iris,
struct iris_table *g2c_table)
{
char buff[4096] = {0};
struct iris_table *table = NULL;
@@ -689,23 +700,24 @@ static int write_group2compile_line(int *group_ids, size_t n_group_id,
strcat(group_id_str, tmp_str);
}
group_id_str[strlen(group_id_str) - 1] = '\0';
snprintf(buff, sizeof(buff), "%s\t%d\t%d\t%s\t%d\t1\n", group_id_str, compile_id,
group_not_flag, vtable, clause_index);
snprintf(buff, sizeof(buff), "%s\t%d\t%d\t%s\t%d\t1\n", group_id_str,
compile_id, group_not_flag, vtable, clause_index);
} else {
snprintf(buff, sizeof(buff), "%d\t%d\t%d\t%s\t%d\t1\n", group_ids[0], compile_id,
group_not_flag, vtable, clause_index);
snprintf(buff, sizeof(buff), "%d\t%d\t%d\t%s\t%d\t1\n", group_ids[0],
compile_id, group_not_flag, vtable, clause_index);
}
table->write_pos += memcat(&(table->buff), table->write_pos, &(table->buff_sz),
buff, strlen(buff));
table->write_pos += memcat(&(table->buff), table->write_pos,
&(table->buff_sz), buff, strlen(buff));
table->line_count++;
return 0;
}
static int write_group2group_line(int group_id, UT_array *incl_sub_group_ids,
UT_array *excl_sub_group_ids,
struct iris_description *p_iris)
static int
write_group2group_line(int group_id, UT_array *incl_sub_group_ids,
UT_array *excl_sub_group_ids,
struct iris_description *p_iris)
{
char buff[MAX_BUFF_LEN*4] = {0};
struct iris_table *table = p_iris->group2group_table;
@@ -765,10 +777,11 @@ static int write_group2group_line(int group_id, UT_array *incl_sub_group_ids,
return 0;
}
static int write_group_rule(cJSON *group_json, int parent_id,
int parent_type, int tracking_compile_id,
int Nth_group, struct iris_description *p_iris,
struct log_handle *logger)
static int
write_group_rule(cJSON *group_json, int parent_id,
int parent_type, int tracking_compile_id,
int Nth_group, struct iris_description *p_iris,
struct log_handle *logger)
{
int ret = 0;
int group_not_flag = 0;
@@ -839,11 +852,12 @@ static int write_group_rule(cJSON *group_json, int parent_id,
if (group_name_cnt > 0) {
int group_ids[group_name_cnt];
for (size_t i = 0; i < group_name_cnt; i++) {
struct group_info *group_info = group_info_read(p_iris->group_name_map,
group_name_array[i]);
struct group_info *group_info =
group_info_read(p_iris->group_name_map, group_name_array[i]);
if (NULL == group_info) {
log_fatal(logger, MODULE_JSON2IRIS, "[%s:%d] group_name:%s has no group_id",
__FUNCTION__, __LINE__, group_name_array[i]);
log_fatal(logger, MODULE_JSON2IRIS, "[%s:%d] group_name:%s"
" has no group_id", __FUNCTION__, __LINE__,
group_name_array[i]);
return -1;
}
group_ids[i] = group_info->group_id;
@@ -854,7 +868,8 @@ static int write_group_rule(cJSON *group_json, int parent_id,
virtual_table, p_iris, g2c_table);
} else {
struct group_info *group_info = group_info_read(p_iris->group_name_map, group_name);
struct group_info *group_info =
group_info_read(p_iris->group_name_map, group_name);
// exist group name, regions and sub groups will be ommit.
if (NULL == group_info) {
if (0 == strncasecmp(group_name, untitled_group_name,
@@ -864,8 +879,8 @@ static int write_group_rule(cJSON *group_json, int parent_id,
if (-1 == group_id) {
log_fatal(logger, MODULE_JSON2IRIS,
"[%s:%d] group_name:<%s> has no group_id", __FUNCTION__,
__LINE__, group_name);
"[%s:%d] group_name:<%s> has no group_id",
__FUNCTION__, __LINE__, group_name);
return -1;
}
@@ -924,13 +939,15 @@ static int write_group_rule(cJSON *group_json, int parent_id,
return 0;
}
static int write_compile_line(cJSON *compile, struct iris_description *p_iris,
struct log_handle *logger)
static int
write_compile_line(cJSON *compile, struct iris_description *p_iris,
struct log_handle *logger)
{
cJSON *item=cJSON_GetObjectItem(compile, "compile_id");
if (item->type != cJSON_Number) {
log_fatal(logger, MODULE_JSON2IRIS,
"[%s:%d] compile_id format not number", __FUNCTION__, __LINE__);
"[%s:%d] compile_id format not number",
__FUNCTION__, __LINE__);
return -1;
}
int compile_id = item->valueint;
@@ -1021,8 +1038,8 @@ static int write_compile_line(cJSON *compile, struct iris_description *p_iris,
table_info = query_table_info(p_iris, item->valuestring, TABLE_TYPE_COMPILE);
}
int ret = direct_write_rule(compile, p_iris->str2int_map, compile_cmd, cmd_cnt,
table_info, logger);
int ret = direct_write_rule(compile, p_iris->str2int_map, compile_cmd,
cmd_cnt, table_info, logger);
if (ret < 0) {
return -1;
}
@@ -1073,7 +1090,8 @@ static int write_index_file(struct iris_description *p_iris,
if (NULL == p_iris->idx_fp) {
log_fatal(logger, MODULE_JSON2IRIS,
"[%s:%d] index file %s fopen error %s",
__FUNCTION__, __LINE__, p_iris->index_path, strerror(errno));
__FUNCTION__, __LINE__, p_iris->index_path,
strerror(errno));
return -1;
}
@@ -1165,8 +1183,10 @@ static int write_group2group_rule(struct iris_description *p_iris,
struct group_info *group_info = NULL, *tmp_group_info = NULL;
HASH_ITER(hh, p_iris->group_name_map, group_info, tmp_group_info) {
ret = write_group2group_line(group_info->group_id, group_info->incl_sub_group_ids,
group_info->excl_sub_group_ids, p_iris);
ret = write_group2group_line(group_info->group_id,
group_info->incl_sub_group_ids,
group_info->excl_sub_group_ids,
p_iris);
if (ret < 0) {
log_fatal(logger, MODULE_JSON2IRIS,
"[%s:%d] write group2group line failed for super_group:%d",

View File

@@ -90,7 +90,8 @@ void maat_options_free(struct maat_options *opts)
FREE(opts);
}
int maat_options_set_caller_thread_number(struct maat_options *opts, size_t n_thread)
int maat_options_set_caller_thread_number(struct maat_options *opts,
size_t n_thread)
{
if (NULL == opts) {
return -1;
@@ -100,7 +101,8 @@ int maat_options_set_caller_thread_number(struct maat_options *opts, size_t n_th
return 0;
}
int maat_options_set_accept_tags(struct maat_options *opts, const char *accept_tags)
int maat_options_set_accept_tags(struct maat_options *opts,
const char *accept_tags)
{
if (NULL == opts || NULL == accept_tags) {
return -1;
@@ -110,7 +112,8 @@ int maat_options_set_accept_tags(struct maat_options *opts, const char *accept_t
return 0;
}
int maat_options_set_rule_update_checking_interval_ms(struct maat_options *opts, int interval_ms)
int maat_options_set_rule_update_checking_interval_ms(struct maat_options *opts,
int interval_ms)
{
if (NULL == opts || interval_ms < 0) {
return -1;
@@ -130,7 +133,8 @@ int maat_options_set_gc_timeout_ms(struct maat_options *opts, int interval_ms)
return 0;
}
int maat_options_set_instance_name(struct maat_options *opts, const char *instance_name)
int maat_options_set_instance_name(struct maat_options *opts,
const char *instance_name)
{
if (NULL == opts || NULL == instance_name ||
strlen(instance_name) > MAX_INSTANCE_NAME_LEN) {
@@ -171,7 +175,8 @@ int maat_options_set_perf_on(struct maat_options *opts)
return 0;
}
int maat_options_set_foreign_cont_dir(struct maat_options *opts, const char *dir)
int maat_options_set_foreign_cont_dir(struct maat_options *opts,
const char *dir)
{
if (NULL == opts || NULL == dir || strlen(dir) >= NAME_MAX) {
return -1;
@@ -181,7 +186,8 @@ int maat_options_set_foreign_cont_dir(struct maat_options *opts, const char *dir
return 0;
}
int maat_options_set_iris(struct maat_options *opts, const char *full_directory,
int maat_options_set_iris(struct maat_options *opts,
const char *full_directory,
const char *increment_directory)
{
if (NULL == opts || strlen(full_directory) >= NAME_MAX ||
@@ -189,16 +195,20 @@ int maat_options_set_iris(struct maat_options *opts, const char *full_directory,
return -1;
}
memcpy(opts->iris_ctx.full_idx_dir, full_directory, strlen(full_directory));
memcpy(opts->iris_ctx.inc_idx_dir, increment_directory, strlen(increment_directory));
memcpy(opts->iris_ctx.full_idx_dir, full_directory,
strlen(full_directory));
memcpy(opts->iris_ctx.inc_idx_dir, increment_directory,
strlen(increment_directory));
opts->input_mode = DATA_SOURCE_IRIS_FILE;
return 0;
}
int maat_options_set_json_file(struct maat_options *opts, const char *json_filename)
int maat_options_set_json_file(struct maat_options *opts,
const char *json_filename)
{
strncpy(opts->json_ctx.json_file, json_filename, sizeof(opts->json_ctx.json_file));
strncpy(opts->json_ctx.json_file, json_filename,
sizeof(opts->json_ctx.json_file));
opts->input_mode = DATA_SOURCE_JSON_FILE;
return 0;
@@ -240,7 +250,8 @@ int maat_options_set_redis(struct maat_options *opts, const char *redis_ip,
return 0;
}
int maat_options_set_stat_file(struct maat_options *opts, const char *stat_filename)
int maat_options_set_stat_file(struct maat_options *opts,
const char *stat_filename)
{
size_t str_len = MIN(sizeof(opts->stat_file), strlen(stat_filename));
@@ -347,9 +358,10 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
} else {
char log_path[MAX_NAME_STR_LEN] = {0};
if (strlen(maat_inst->opts.inst_name) > 0) {
snprintf(log_path, sizeof(log_path), "%s.log", maat_inst->opts.inst_name);
snprintf(log_path, sizeof(log_path), "%s.log",
maat_inst->opts.inst_name);
} else {
snprintf(log_path, sizeof(log_path), "maat.log");
snprintf(log_path, sizeof(log_path), "./maat.log");
}
maat_inst->logger = log_handle_create(log_path, maat_inst->opts.log_level);
}
@@ -360,17 +372,20 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
}
if (0 == strlen(maat_inst->opts.foreign_cont_dir)) {
snprintf(maat_inst->opts.foreign_cont_dir, sizeof(maat_inst->opts.foreign_cont_dir),
snprintf(maat_inst->opts.foreign_cont_dir,
sizeof(maat_inst->opts.foreign_cont_dir),
"%s_files", table_info_path);
}
system_cmd_mkdir(maat_inst->opts.foreign_cont_dir);
if (0 == strlen(maat_inst->opts.stat_file)) {
snprintf(maat_inst->opts.stat_file, sizeof(maat_inst->opts.stat_file), "maat_stat.fs");
snprintf(maat_inst->opts.stat_file, sizeof(maat_inst->opts.stat_file),
"maat_stat.fs");
}
snprintf(maat_inst->opts.decrypt_algo, sizeof(maat_inst->opts.decrypt_algo), "aes-256-cbc");
snprintf(maat_inst->opts.decrypt_algo, sizeof(maat_inst->opts.decrypt_algo),
"aes-256-cbc");
maat_inst->is_running = 0;
maat_inst->maat_version = 0;
@@ -394,9 +409,10 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
pthread_mutex_init(&(maat_inst->background_update_mutex), NULL);
maat_inst->tbl_mgr = table_manager_create(table_info_path, maat_inst->opts.accept_tags,
maat_inst->opts.expr_engine, maat_inst->garbage_bin,
maat_inst->logger);
maat_inst->tbl_mgr =
table_manager_create(table_info_path, maat_inst->opts.accept_tags,
maat_inst->opts.expr_engine, maat_inst->garbage_bin,
maat_inst->logger);
if (NULL == maat_inst->tbl_mgr) {
goto failed;
}
@@ -406,7 +422,8 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
}
if (1 == maat_inst->opts.stat_on) {
int ret = maat_stat_init(maat_inst->stat, maat_inst->tbl_mgr, maat_inst->garbage_bin);
int ret = maat_stat_init(maat_inst->stat, maat_inst->tbl_mgr,
maat_inst->garbage_bin);
if (ret < 0) {
log_fatal(maat_inst->logger, MODULE_MAAT_API,
"[%s:%d] maat_stat_init failed.", __FUNCTION__, __LINE__);
@@ -414,7 +431,8 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
}
}
pthread_create(&(maat_inst->cfg_mon_thread), NULL, rule_monitor_loop, (void *)maat_inst);
pthread_create(&(maat_inst->cfg_mon_thread), NULL, rule_monitor_loop,
(void *)maat_inst);
return maat_inst;
@@ -488,7 +506,8 @@ int maat_get_table_id(struct maat *maat_inst, const char *table_name)
return table_manager_get_table_id(table_mgr, table_name);
}
const char *maat_get_table_schema_tag(struct maat *maat_inst, int table_id)
const char *
maat_get_table_schema_tag(struct maat *maat_inst, int table_id)
{
if (NULL == maat_inst || table_id < 0) {
return NULL;
@@ -498,18 +517,20 @@ const char *maat_get_table_schema_tag(struct maat *maat_inst, int table_id)
return table_manager_get_table_schema_tag(table_mgr, table_id);
}
static inline void maat_runtime_ref_inc(struct maat_runtime *maat_rt, int thread_id)
static inline void
maat_runtime_ref_inc(struct maat_runtime *maat_rt, int thread_id)
{
if (NULL == maat_rt) {
if (NULL == maat_rt || thread_id < 0) {
return;
}
alignment_int64_array_add(maat_rt->ref_cnt, thread_id, 1);
}
static inline void maat_runtime_ref_dec(struct maat_runtime *maat_rt, int thread_id)
static inline void
maat_runtime_ref_dec(struct maat_runtime *maat_rt, int thread_id)
{
if (NULL == maat_rt) {
if (NULL == maat_rt || thread_id < 0) {
return;
}
@@ -530,8 +551,9 @@ int maat_table_callback_register(struct maat *maat_inst, int table_id,
if (NULL == schema) {
pthread_mutex_unlock(&(maat_inst->background_update_mutex));
log_fatal(maat_inst->logger, MODULE_MAAT_API,
"[%s:%d] table(table_id:%d) schema is NULL, register callback failed",
__FUNCTION__, __LINE__, table_id);
"[%s:%d] table(table_id:%d) schema is NULL, "
"register callback failed", __FUNCTION__,
__LINE__, table_id);
return -1;
}
@@ -549,7 +571,8 @@ int maat_table_callback_register(struct maat *maat_inst, int table_id,
void *runtime = table_manager_get_runtime(maat_inst->tbl_mgr, table_id);
enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id);
enum table_type table_type =
table_manager_get_table_type(maat_inst->tbl_mgr, table_id);
if (table_type != TABLE_TYPE_PLUGIN) {
pthread_mutex_unlock(&(maat_inst->background_update_mutex));
log_fatal(maat_inst->logger, MODULE_MAAT_API,
@@ -583,12 +606,13 @@ int maat_table_callback_register(struct maat *maat_inst, int table_id,
return 0;
}
static int generic_plugin_table_set_ex_schema(struct table_manager *tbl_mgr, int table_id,
maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func,
long argl, void *argp,
struct log_handle *logger)
static int
generic_plugin_table_set_ex_schema(struct table_manager *tbl_mgr, int table_id,
maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func,
long argl, void *argp,
struct log_handle *logger)
{
void *schema = table_manager_get_schema(tbl_mgr, table_id);
if (NULL == schema) {
@@ -1447,9 +1471,9 @@ int maat_scan_integer(struct maat *maat_inst, int table_id,
}
}
int maat_scan_ipv4_port(struct maat *maat_inst, int table_id, uint32_t ip_addr, int port,
long long *results, size_t n_result, size_t *n_hit_result,
struct maat_state *state)
int maat_scan_ipv4_port(struct maat *maat_inst, int table_id, uint32_t ip_addr,
int port, long long *results, size_t n_result,
size_t *n_hit_result, struct maat_state *state)
{
if ((NULL == maat_inst) || table_id < 0 || table_id >= MAX_TABLE_NUM ||
(NULL == results) || (0 == n_result) || (NULL == n_hit_result) ||
@@ -1532,9 +1556,9 @@ int maat_scan_ipv4_port(struct maat *maat_inst, int table_id, uint32_t ip_addr,
}
}
int maat_scan_ipv6_port(struct maat *maat_inst, int table_id, uint8_t *ip_addr, int port,
long long *results, size_t n_result, size_t *n_hit_result,
struct maat_state *state)
int maat_scan_ipv6_port(struct maat *maat_inst, int table_id, uint8_t *ip_addr,
int port, long long *results, size_t n_result,
size_t *n_hit_result, struct maat_state *state)
{
if ((NULL == maat_inst) || table_id < 0 || table_id >= MAX_TABLE_NUM ||
(NULL == ip_addr) || (NULL == results) || (0 == n_result) ||
@@ -1616,6 +1640,7 @@ int maat_scan_ipv6_port(struct maat *maat_inst, int table_id, uint8_t *ip_addr,
return MAAT_SCAN_OK;
}
}
#define PORT_IGNORED -1
inline int maat_scan_ipv6(struct maat *instance, int table_id, uint8_t *ip_addr,
long long *results, size_t n_result, size_t *n_hit_result,
@@ -1624,6 +1649,7 @@ inline int maat_scan_ipv6(struct maat *instance, int table_id, uint8_t *ip_addr,
return maat_scan_ipv6_port(instance, table_id, ip_addr, PORT_IGNORED,
results, n_result, n_hit_result, state);
}
inline int maat_scan_ipv4(struct maat *instance, int table_id, uint32_t ip_addr,
long long *results, size_t n_result, size_t *n_hit_result,
struct maat_state *state)
@@ -1631,6 +1657,7 @@ inline int maat_scan_ipv4(struct maat *instance, int table_id, uint32_t ip_addr,
return maat_scan_ipv4_port(instance, table_id, ip_addr, PORT_IGNORED,
results, n_result, n_hit_result, state);
}
int maat_scan_string(struct maat *maat_inst, int table_id,
const char *data, size_t data_len,
long long *results, size_t n_result,

View File

@@ -603,7 +603,9 @@ void compile_runtime_init(void *compile_runtime, struct maat_runtime *maat_rt)
return;
}
struct compile_runtime *compile_rt = (struct compile_runtime *)compile_runtime;
struct compile_runtime *compile_rt =
(struct compile_runtime *)compile_runtime;
compile_rt->ref_maat_rt = maat_rt;
}
@@ -615,7 +617,9 @@ void *group2compile_runtime_new(void *g2c_schema, size_t max_thread_num,
return NULL;
}
struct group2compile_runtime *g2c_rt = ALLOC(struct group2compile_runtime, 1);
struct group2compile_runtime *g2c_rt =
ALLOC(struct group2compile_runtime, 1);
g2c_rt->tbl_not_clause_hash = NULL;
return g2c_rt;
@@ -623,7 +627,8 @@ void *group2compile_runtime_new(void *g2c_schema, size_t max_thread_num,
void group2compile_runtime_init(void *g2c_runtime, void *compile_runtime)
{
struct group2compile_runtime *g2c_rt = (struct group2compile_runtime *)g2c_runtime;
struct group2compile_runtime *g2c_rt =
(struct group2compile_runtime *)g2c_runtime;
g2c_rt->ref_compile_rt = (struct compile_runtime *)compile_runtime;
}
@@ -634,7 +639,9 @@ void group2compile_runtime_free(void *g2c_runtime)
return;
}
struct group2compile_runtime *g2c_rt = (struct group2compile_runtime *)g2c_runtime;
struct group2compile_runtime *g2c_rt =
(struct group2compile_runtime *)g2c_runtime;
if (g2c_rt->tbl_not_clause_hash != NULL) {
struct table_clause *not_clause = NULL, *tmp_not_clause = NULL;
HASH_ITER(hh, g2c_rt->tbl_not_clause_hash, not_clause, tmp_not_clause) {
@@ -886,7 +893,8 @@ static void maat_compile_clause_remove_literal(struct maat_compile *compile,
}
static struct bool_matcher *
maat_compile_bool_matcher_new(struct compile_runtime *compile_rt, size_t *compile_cnt)
maat_compile_bool_matcher_new(struct compile_runtime *compile_rt,
size_t *compile_cnt)
{
if (NULL == compile_rt) {
return NULL;
@@ -912,7 +920,8 @@ maat_compile_bool_matcher_new(struct compile_runtime *compile_rt, size_t *compil
has_clause_num++;
if (0 == clause->clause_id) {
clause->clause_id = maat_runtime_get_sequence(compile_rt->ref_maat_rt, "clause_id");
clause->clause_id =
maat_runtime_get_sequence(compile_rt->ref_maat_rt, "clause_id");
}
}
assert(has_clause_num == iter_compile->actual_clause_num);
@@ -1063,19 +1072,24 @@ build_clause_id_kv_hash(struct compile_runtime *compile_rt, int not_flag)
struct clause_literal *tmp_cl = NULL;
for (size_t j = 0; j < utarray_len(clause->literals); j++) {
tmp_cl = (struct clause_literal *)utarray_eltptr(clause->literals, j);
for (size_t k = 0; k < tmp_cl->group_cnt; k++) {
struct clause_query_key key = {tmp_cl->group_ids[k], tmp_cl->vtable_id, clause->not_flag};
struct clause_query_key key =
{tmp_cl->group_ids[k], tmp_cl->vtable_id, clause->not_flag};
struct clause_id_kv *clause_id_kv = NULL;
HASH_FIND(hh, clause_id_kv_hash, &key, sizeof(struct clause_query_key), clause_id_kv);
HASH_FIND(hh, clause_id_kv_hash, &key, sizeof(struct clause_query_key),
clause_id_kv);
if (NULL == clause_id_kv) {
clause_id_kv = ALLOC(struct clause_id_kv, 1);
clause_id_kv->key = key;
utarray_new(clause_id_kv->clause_ids, &ut_clause_id_icd);
HASH_ADD_KEYPTR(hh, clause_id_kv_hash, &clause_id_kv->key, sizeof(clause_id_kv->key), clause_id_kv);
HASH_ADD_KEYPTR(hh, clause_id_kv_hash, &clause_id_kv->key,
sizeof(clause_id_kv->key), clause_id_kv);
}
if (utarray_find(clause_id_kv->clause_ids, &(clause->clause_id), compare_clause_id)) {
if (utarray_find(clause_id_kv->clause_ids, &(clause->clause_id),
compare_clause_id)) {
continue;
}
utarray_push_back(clause_id_kv->clause_ids, &(clause->clause_id));
@@ -1089,7 +1103,8 @@ build_clause_id_kv_hash(struct compile_runtime *compile_rt, int not_flag)
return clause_id_kv_hash;
}
static int maat_compile_has_clause(struct maat_compile *compile, long long clause_id)
static int
maat_compile_has_clause(struct maat_compile *compile, long long clause_id)
{
struct compile_clause *clause = NULL;
@@ -1107,8 +1122,9 @@ static int maat_compile_has_clause(struct maat_compile *compile, long long claus
return 0;
}
static size_t compile_state_if_new_hit_compile(struct compile_state *compile_state,
struct maat_compile *compile)
static size_t
compile_state_if_new_hit_compile(struct compile_state *compile_state,
struct maat_compile *compile)
{
size_t i = 0;
size_t r_in_c_cnt = 0;
@@ -1117,7 +1133,8 @@ static size_t compile_state_if_new_hit_compile(struct compile_state *compile_sta
long long new_hit_clause_id = 0;
if (0 == compile_state->this_scan_not_logic) {
for (i = 0; i < utarray_len(compile_state->this_scan_hit_clauses); i++) {
new_hit_clause_id = *(long long*)utarray_eltptr(compile_state->this_scan_hit_clauses, i);
new_hit_clause_id =
*(long long*)utarray_eltptr(compile_state->this_scan_hit_clauses, i);
ret = maat_compile_has_clause(compile, new_hit_clause_id);
if (ret) {
r_in_c_cnt++;
@@ -1125,7 +1142,8 @@ static size_t compile_state_if_new_hit_compile(struct compile_state *compile_sta
}
} else {
for (i = 0; i < utarray_len(compile_state->this_scan_hit_not_clauses); i++) {
new_hit_clause_id = *(long long*)utarray_eltptr(compile_state->this_scan_hit_not_clauses, i);
new_hit_clause_id =
*(long long*)utarray_eltptr(compile_state->this_scan_hit_not_clauses, i);
ret = maat_compile_has_clause(compile, new_hit_clause_id);
if (ret) {
r_in_c_cnt++;
@@ -1136,20 +1154,23 @@ static size_t compile_state_if_new_hit_compile(struct compile_state *compile_sta
return r_in_c_cnt;
}
static void compile_state_update_hit_compile_table_id(struct compile_state *compile_state,
long long compile_id, int table_id)
static void
compile_state_update_hit_compile_table_id(struct compile_state *compile_state,
long long compile_id, int table_id)
{
if (!utarray_find(compile_state->hit_compile_table_ids, &compile_id, compare_compile_id)) {
if (!utarray_find(compile_state->hit_compile_table_ids, &compile_id,
compare_compile_id)) {
struct compile2table_id compile_table_id = {compile_id, table_id};
utarray_push_back(compile_state->hit_compile_table_ids, &compile_table_id);
utarray_sort(compile_state->hit_compile_table_ids, compare_compile_id);
}
}
static size_t maat_compile_bool_matcher_match(struct compile_runtime *compile_rt,
struct compile_state *compile_state,
int thread_id, void **user_data_array,
size_t ud_array_size)
static size_t
maat_compile_bool_matcher_match(struct compile_runtime *compile_rt,
struct compile_state *compile_state,
int thread_id, void **user_data_array,
size_t ud_array_size)
{
size_t ud_result_cnt = 0;
struct maat_compile *compile = NULL;
@@ -1161,8 +1182,9 @@ static size_t maat_compile_bool_matcher_match(struct compile_runtime *compile_rt
compile_state->compile_rt_version = compile_rt->version;
}
if (NULL == compile_rt->bm || 0 == utarray_len(compile_state->all_hit_clauses)
|| compile_state->compile_rt_version != compile_rt->version) {
if (NULL == compile_rt->bm ||
0 == utarray_len(compile_state->all_hit_clauses) ||
compile_state->compile_rt_version != compile_rt->version) {
return 0;
}
@@ -1175,10 +1197,11 @@ static size_t maat_compile_bool_matcher_match(struct compile_runtime *compile_rt
}
#endif
int bool_match_ret = bool_matcher_match(compile_rt->bm,
(unsigned long long *)utarray_eltptr(compile_state->all_hit_clauses, 0),
utarray_len(compile_state->all_hit_clauses),
expr_match, MAX_HIT_COMPILE_NUM);
int bool_match_ret =
bool_matcher_match(compile_rt->bm,
(unsigned long long *)utarray_eltptr(compile_state->all_hit_clauses, 0),
utarray_len(compile_state->all_hit_clauses),
expr_match, MAX_HIT_COMPILE_NUM);
for (int i = 0; i < bool_match_ret && ud_result_cnt < ud_array_size; i++) {
compile = (struct maat_compile *)expr_match[i].user_tag;
assert(compile->magic_num == MAAT_COMPILE_MAGIC);
@@ -1187,7 +1210,8 @@ static size_t maat_compile_bool_matcher_match(struct compile_runtime *compile_rt
continue;
}
size_t n_new_hit_compile = compile_state_if_new_hit_compile(compile_state, compile);
size_t n_new_hit_compile =
compile_state_if_new_hit_compile(compile_state, compile);
if (compile->user_data != NULL && n_new_hit_compile > 0) {
user_data_array[ud_result_cnt] = compile->user_data;
@@ -1223,7 +1247,8 @@ maat_compile_clone(struct maat_compile *compile, int deep_copy)
new_compile->actual_clause_num = compile->actual_clause_num;
new_compile->declared_clause_num = compile->declared_clause_num;
if (1 == deep_copy && compile->user_data != NULL) {
new_compile->user_data = compile_item_clone((struct compile_item *)compile->user_data);
new_compile->user_data =
compile_item_clone((struct compile_item *)compile->user_data);
}
struct clause_literal *tmp_literal = NULL;
@@ -1233,7 +1258,8 @@ maat_compile_clone(struct maat_compile *compile, int deep_copy)
new_compile->clauses[i].not_flag = compile->clauses[i].not_flag;
utarray_new(new_compile->clauses[i].literals, &ut_clause_literal_icd);
for (size_t j = 0; j < utarray_len(compile->clauses[i].literals); j++) {
tmp_literal = (struct clause_literal *)utarray_eltptr(compile->clauses[i].literals, j);
tmp_literal =
(struct clause_literal *)utarray_eltptr(compile->clauses[i].literals, j);
utarray_push_back(new_compile->clauses[i].literals, tmp_literal);
}
}
@@ -1411,7 +1437,8 @@ struct compile_state *compile_state_new(void)
return compile_state;
}
static long long compile_state_hit_not_tbl_groups_free(struct compile_state *compile_state)
static long long
compile_state_hit_not_tbl_groups_free(struct compile_state *compile_state)
{
if (NULL == compile_state) {
return 0;
@@ -1420,7 +1447,8 @@ static long long compile_state_hit_not_tbl_groups_free(struct compile_state *com
long long free_bytes = 0;
struct table_group *tbl_group = NULL, *tmp_tbl_group = NULL;
HASH_ITER(hh, compile_state->hit_not_tbl_groups, tbl_group, tmp_tbl_group) {
free_bytes += (sizeof(tbl_group) + utarray_len(tbl_group->group_ids) * sizeof(long long));
free_bytes +=
(sizeof(tbl_group) + utarray_len(tbl_group->group_ids) * sizeof(long long));
HASH_DEL(compile_state->hit_not_tbl_groups, tbl_group);
if (tbl_group->group_ids != NULL) {
utarray_free(tbl_group->group_ids);
@@ -1474,49 +1502,57 @@ void compile_state_free(struct compile_state *compile_state,
}
if (compile_state->all_hit_clauses != NULL) {
free_bytes += utarray_size(compile_state->all_hit_clauses) * sizeof(long long);
free_bytes += utarray_size(compile_state->all_hit_clauses) *
sizeof(long long);
utarray_free(compile_state->all_hit_clauses);
compile_state->all_hit_clauses = NULL;
}
if (compile_state->this_scan_hit_clauses != NULL) {
free_bytes += utarray_size(compile_state->this_scan_hit_clauses) * sizeof(long long);
free_bytes += utarray_size(compile_state->this_scan_hit_clauses) *
sizeof(long long);
utarray_free(compile_state->this_scan_hit_clauses);
compile_state->this_scan_hit_clauses = NULL;
}
if (compile_state->this_scan_hit_not_clauses != NULL) {
free_bytes += utarray_size(compile_state->this_scan_hit_not_clauses) * sizeof(long long);
free_bytes += utarray_size(compile_state->this_scan_hit_not_clauses) *
sizeof(long long);
utarray_free(compile_state->this_scan_hit_not_clauses);
compile_state->this_scan_hit_not_clauses = NULL;
}
if (compile_state->exclude_not_clauses != NULL) {
free_bytes += utarray_size(compile_state->exclude_not_clauses) * sizeof(long long);
free_bytes += utarray_size(compile_state->exclude_not_clauses) *
sizeof(long long);
utarray_free(compile_state->exclude_not_clauses);
compile_state->exclude_not_clauses = NULL;
}
if (compile_state->direct_hit_groups != NULL) {
free_bytes += utarray_size(compile_state->direct_hit_groups) * sizeof(struct maat_hit_group);
free_bytes += utarray_size(compile_state->direct_hit_groups) *
sizeof(struct maat_hit_group);
utarray_free(compile_state->direct_hit_groups);
compile_state->direct_hit_groups = NULL;
}
if (compile_state->indirect_hit_groups != NULL) {
free_bytes += utarray_size(compile_state->indirect_hit_groups) * sizeof(struct maat_hit_group);
free_bytes += utarray_size(compile_state->indirect_hit_groups) *
sizeof(struct maat_hit_group);
utarray_free(compile_state->indirect_hit_groups);
compile_state->indirect_hit_groups = NULL;
}
if (compile_state->last_hit_groups != NULL) {
free_bytes += utarray_size(compile_state->last_hit_groups) * sizeof(struct maat_hit_group);
free_bytes += utarray_size(compile_state->last_hit_groups) *
sizeof(struct maat_hit_group);
utarray_free(compile_state->last_hit_groups);
compile_state->last_hit_groups = NULL;
}
if (compile_state->hit_compile_table_ids != NULL) {
free_bytes += utarray_size(compile_state->hit_compile_table_ids) * sizeof(struct compile2table_id);
free_bytes += utarray_size(compile_state->hit_compile_table_ids) *
sizeof(struct compile2table_id);
utarray_free(compile_state->hit_compile_table_ids);
compile_state->hit_compile_table_ids = NULL;
}
@@ -1530,9 +1566,10 @@ void compile_state_free(struct compile_state *compile_state,
thread_id, free_bytes);
}
static void compile_state_add_internal_hit_path(struct compile_state *compile_state,
long long item_id, long long group_id,
int vtable_id, int NOT_flag, int Nth_scan)
static void
compile_state_add_internal_hit_path(struct compile_state *compile_state,
long long item_id, long long group_id,
int vtable_id, int NOT_flag, int Nth_scan)
{
if (NULL == compile_state) {
return;
@@ -1580,9 +1617,10 @@ static int maat_compile_has_clause_query_key(struct maat_compile *compile,
return 0;
}
static size_t maat_compile_get_hit_clause_index(struct maat_compile *compile,
int vtable_id, long long hit_group_id,
int *clause_idx_array, size_t array_size)
static size_t
maat_compile_get_hit_clause_index(struct maat_compile *compile,
int vtable_id, long long hit_group_id,
int *clause_idx_array, size_t array_size)
{
size_t hit_clause_cnt = 0;
struct compile_clause *tmp_clause = NULL;
@@ -1613,8 +1651,9 @@ static size_t maat_compile_get_hit_clause_index(struct maat_compile *compile,
return hit_clause_cnt;
}
static int maat_compile_is_hit_path_existed(const struct maat_hit_path *hit_paths,
size_t n_path, const struct maat_hit_path *find)
static int
maat_compile_is_hit_path_existed(const struct maat_hit_path *hit_paths,
size_t n_path, const struct maat_hit_path *find)
{
for (size_t i = 0; i < n_path; i++) {
if (0 == memcmp(hit_paths + i, find, sizeof(*find))) {
@@ -1627,7 +1666,8 @@ static int maat_compile_is_hit_path_existed(const struct maat_hit_path *hit_path
void populate_hit_path_with_compile(struct maat_hit_path *hit_path_array,
size_t array_idx, size_t n_hit_path,
size_t *n_new_hit_path, struct maat_compile *compile)
size_t *n_new_hit_path,
struct maat_compile *compile)
{
size_t i = 0;
size_t idx = array_idx;
@@ -1643,9 +1683,11 @@ void populate_hit_path_with_compile(struct maat_hit_path *hit_path_array,
if (hit_path_array[idx].compile_id < 0) {
hit_path_array[idx].compile_id = compile->compile_id;
// find out which clause in compile hit
n_clause_index = maat_compile_get_hit_clause_index(compile, hit_path_array[idx].vtable_id,
hit_path_array[idx].top_group_id, clause_index_array,
MAX_ITEMS_PER_BOOL_EXPR);
n_clause_index =
maat_compile_get_hit_clause_index(compile, hit_path_array[idx].vtable_id,
hit_path_array[idx].top_group_id,
clause_index_array,
MAX_ITEMS_PER_BOOL_EXPR);
hit_path_array[idx].clause_index = clause_index_array[0];
if (n_clause_index > 1) {
for (i = 1; i < n_clause_index; i++) {
@@ -1662,8 +1704,9 @@ void populate_hit_path_with_compile(struct maat_hit_path *hit_path_array,
if (!maat_compile_is_hit_path_existed(hit_path_array, n_hit_path + new_hit_path_cnt, &tmp_path)) {
hit_path_array[n_hit_path + new_hit_path_cnt] = tmp_path;
new_hit_path_cnt++;
n_clause_index = maat_compile_get_hit_clause_index(compile, tmp_path.vtable_id, tmp_path.top_group_id,
clause_index_array, MAX_ITEMS_PER_BOOL_EXPR);
n_clause_index =
maat_compile_get_hit_clause_index(compile, tmp_path.vtable_id, tmp_path.top_group_id,
clause_index_array, MAX_ITEMS_PER_BOOL_EXPR);
hit_path_array[n_hit_path + new_hit_path_cnt - 1].clause_index = clause_index_array[0];
if (n_clause_index > 1) {
for (i = 1; i < n_clause_index; i++) {
@@ -1696,9 +1739,10 @@ size_t compile_runtime_get_hit_paths(struct compile_runtime *compile_rt, int thr
return 0;
}
int bool_match_ret = bool_matcher_match(compile_rt->bm,
(unsigned long long *)utarray_eltptr(compile_state->all_hit_clauses, 0),
utarray_len(compile_state->all_hit_clauses), expr_match, MAX_HIT_COMPILE_NUM);
int bool_match_ret =
bool_matcher_match(compile_rt->bm,
(unsigned long long *)utarray_eltptr(compile_state->all_hit_clauses, 0),
utarray_len(compile_state->all_hit_clauses), expr_match, MAX_HIT_COMPILE_NUM);
for (int idx = 0; idx < bool_match_ret; idx++) {
compile = (struct maat_compile *)expr_match[idx].user_tag;
@@ -1718,7 +1762,8 @@ size_t compile_runtime_get_hit_paths(struct compile_runtime *compile_rt, int thr
key.vtable_id = hit_path_array[j].vtable_id;
key.not_flag = hit_path_array[j].NOT_flag;
if (maat_compile_has_clause_query_key(compile, &key)) {
populate_hit_path_with_compile(hit_path_array, j, n_hit_path, &n_new_hit_path, compile);
populate_hit_path_with_compile(hit_path_array, j, n_hit_path,
&n_new_hit_path, compile);
}
}
}
@@ -1726,9 +1771,10 @@ size_t compile_runtime_get_hit_paths(struct compile_runtime *compile_rt, int thr
return (n_hit_path + n_new_hit_path);
}
static void compile_state_add_direct_hit_groups(struct compile_state *compile_state,
struct maat_item *hit_items,
size_t n_hit_items, int vtable_id)
static void
compile_state_add_direct_hit_groups(struct compile_state *compile_state,
struct maat_item *hit_items,
size_t n_hit_items, int vtable_id)
{
if (NULL == compile_state || NULL == hit_items) {
return;
@@ -1743,9 +1789,10 @@ static void compile_state_add_direct_hit_groups(struct compile_state *compile_st
}
}
static void compile_state_add_indirect_hit_groups(struct compile_state *compile_state,
long long *group_ids,
size_t n_group_ids, int vtable_id)
static void
compile_state_add_indirect_hit_groups(struct compile_state *compile_state,
long long *group_ids,
size_t n_group_ids, int vtable_id)
{
if (NULL == compile_state || NULL == group_ids) {
return;
@@ -1760,8 +1807,9 @@ static void compile_state_add_indirect_hit_groups(struct compile_state *compile_
}
}
static void compile_state_add_hit_clauses(struct compile_state *compile_state,
UT_array *clause_id_array)
static void
compile_state_add_hit_clauses(struct compile_state *compile_state,
UT_array *clause_id_array)
{
size_t i = 0;
long long *clause_id = NULL;
@@ -1787,12 +1835,14 @@ static void compile_state_add_hit_clauses(struct compile_state *compile_state,
}
}
static void compile_state_add_exclude_not_clauses(struct compile_state *compile_state,
UT_array *clause_id_array)
static void
compile_state_add_exclude_not_clauses(struct compile_state *compile_state,
UT_array *clause_id_array)
{
for (size_t i = 0; i < utarray_len(clause_id_array); i++) {
long long *clause_id = (long long *)utarray_eltptr(clause_id_array, i);
if (utarray_find(compile_state->exclude_not_clauses, clause_id, compare_clause_id)) {
if (utarray_find(compile_state->exclude_not_clauses, clause_id,
compare_clause_id)) {
continue;
}
utarray_push_back(compile_state->exclude_not_clauses, clause_id);
@@ -1800,8 +1850,9 @@ static void compile_state_add_exclude_not_clauses(struct compile_state *compile_
utarray_sort(compile_state->exclude_not_clauses, compare_clause_id);
}
static void compile_state_add_hit_not_clauses(struct compile_state *compile_state,
UT_array *clause_id_array)
static void
compile_state_add_hit_not_clauses(struct compile_state *compile_state,
UT_array *clause_id_array)
{
size_t i = 0;
long long *clause_id = NULL;
@@ -1832,9 +1883,10 @@ static void compile_state_add_hit_not_clauses(struct compile_state *compile_stat
}
}
static void compile_state_update_hit_clauses(struct compile_state *compile_state,
struct compile_runtime *compile_rt,
long long group_id, int vtable_id)
static void
compile_state_update_hit_clauses(struct compile_state *compile_state,
struct compile_runtime *compile_rt,
long long group_id, int vtable_id)
{
if (NULL == compile_state || NULL == compile_rt) {
return;
@@ -1855,10 +1907,11 @@ static void compile_state_update_hit_clauses(struct compile_state *compile_state
}
}
static void compile_state_cache_hit_not_groups(struct compile_state *compile_state,
struct compile_runtime *compile_rt,
long long *hit_group_ids,
size_t n_hit_group_id, int vtable_id)
static void
compile_state_cache_hit_not_groups(struct compile_state *compile_state,
struct compile_runtime *compile_rt,
long long *hit_group_ids,
size_t n_hit_group_id, int vtable_id)
{
if (NULL == compile_state || NULL == compile_rt) {
return;
@@ -1889,8 +1942,9 @@ static void compile_state_cache_hit_not_groups(struct compile_state *compile_sta
continue;
}
long long *tmp_group_id = bsearch(&(clause_id_kv->key.group_id), hit_group_ids,
n_hit_group_id, sizeof(long long), compare_group_id);
long long *tmp_group_id =
bsearch(&(clause_id_kv->key.group_id), hit_group_ids,
n_hit_group_id, sizeof(long long), compare_group_id);
if (tmp_group_id != NULL) {
continue;
}
@@ -1902,7 +1956,8 @@ static void compile_state_cache_hit_not_groups(struct compile_state *compile_sta
HASH_ADD_INT(compile_state->hit_not_tbl_groups, vtable_id, tbl_group);
}
if (!utarray_find(tbl_group->group_ids, &(clause_id_kv->key.group_id), compare_group_id)) {
if (!utarray_find(tbl_group->group_ids, &(clause_id_kv->key.group_id),
compare_group_id)) {
utarray_push_back(tbl_group->group_ids, &(clause_id_kv->key.group_id));
}
}
@@ -1926,10 +1981,11 @@ int compile_state_get_compile_table_id(struct compile_state *compile_state,
return tmp->table_id;
}
static int compile_runtime_add_compile(struct compile_runtime *compile_rt,
struct compile_schema *schema,
long long compile_id, const char *table_name,
const char *line, struct log_handle *logger)
static int
compile_runtime_add_compile(struct compile_runtime *compile_rt,
struct compile_schema *schema,
long long compile_id, const char *table_name,
const char *line, struct log_handle *logger)
{
struct maat_compile *compile = NULL;
struct compile_item *compile_item = compile_item_new(line, schema, table_name,
@@ -1941,8 +1997,8 @@ static int compile_runtime_add_compile(struct compile_runtime *compile_rt,
int table_id = table_manager_get_table_id(schema->ref_tbl_mgr, table_name);
if (table_id < 0) {
log_fatal(logger, MODULE_COMPILE,
"[%s:%d]table_name:%s has invalid table_id:%d, drop line:%s", __FUNCTION__,
__LINE__, table_name, table_id, line);
"[%s:%d]table_name:%s has invalid table_id:%d, drop line:%s",
__FUNCTION__, __LINE__, table_name, table_id, line);
return -1;
}
@@ -2173,8 +2229,8 @@ int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
}
int ret = -1;
struct group2compile_item *g2c_item = group2compile_item_new(line, schema, table_name,
compile_rt->logger);
struct group2compile_item *g2c_item =
group2compile_item_new(line, schema, table_name, compile_rt->logger);
if (NULL == g2c_item) {
g2c_rt->update_err_cnt++;
return -1;
@@ -2229,7 +2285,9 @@ long long group2compile_runtime_not_clause_count(void *g2c_runtime)
return 0;
}
struct group2compile_runtime *g2c_rt = (struct group2compile_runtime *)g2c_runtime;
struct group2compile_runtime *g2c_rt =
(struct group2compile_runtime *)g2c_runtime;
return g2c_rt->not_clause_cnt;
}
@@ -2239,7 +2297,9 @@ long long group2compile_runtime_rule_count(void *g2c_runtime)
return 0;
}
struct group2compile_runtime *g2c_rt = (struct group2compile_runtime *)g2c_runtime;
struct group2compile_runtime *g2c_rt =
(struct group2compile_runtime *)g2c_runtime;
return g2c_rt->rule_num;
}
@@ -2249,7 +2309,9 @@ long long group2compile_runtime_update_err_count(void *g2c_runtime)
return 0;
}
struct group2compile_runtime *g2c_rt = (struct group2compile_runtime *)g2c_runtime;
struct group2compile_runtime *g2c_rt =
(struct group2compile_runtime *)g2c_runtime;
return g2c_rt->update_err_cnt;
}
@@ -2260,7 +2322,8 @@ int compile_runtime_commit(void *compile_runtime, const char *table_name,
return -1;
}
struct compile_runtime *compile_rt = (struct compile_runtime *)compile_runtime;
struct compile_runtime *compile_rt =
(struct compile_runtime *)compile_runtime;
int updating_flag = rcu_hash_is_updating(compile_rt->cfg_hash);
if (0 == updating_flag) {
@@ -2341,7 +2404,9 @@ long long compile_runtime_rule_count(void *compile_runtime)
return 0;
}
struct compile_runtime *compile_rt = (struct compile_runtime *)compile_runtime;
struct compile_runtime *compile_rt =
(struct compile_runtime *)compile_runtime;
return compile_rt->rule_num;
}
@@ -2351,7 +2416,9 @@ long long compile_runtime_update_err_count(void *compile_runtime)
return 0;
}
struct compile_runtime *compile_rt = (struct compile_runtime *)compile_runtime;
struct compile_runtime *compile_rt =
(struct compile_runtime *)compile_runtime;
return compile_rt->update_err_cnt;
}
@@ -2392,10 +2459,11 @@ int compile_runtime_match(struct compile_runtime *compile_rt, long long *compile
struct compile_item *compile_items[compile_ids_size];
// all hit clause_id -> compile_id
size_t bool_match_ret = maat_compile_bool_matcher_match(compile_rt, compile_state,
state->thread_id,
(void **)compile_items,
compile_ids_size);
size_t bool_match_ret =
maat_compile_bool_matcher_match(compile_rt, compile_state,
state->thread_id,
(void **)compile_items,
compile_ids_size);
if (bool_match_ret > 0) {
qsort(compile_items, bool_match_ret, sizeof(struct compile_item *),
compare_compile_item);
@@ -2528,7 +2596,8 @@ size_t compile_state_get_indirect_hit_groups(struct compile_state *compile_state
size_t i = 0;
struct maat_hit_group *hit_group = NULL;
for (i = 0; i < utarray_len(compile_state->indirect_hit_groups) && i < array_size; i++) {
hit_group = (struct maat_hit_group *)utarray_eltptr(compile_state->indirect_hit_groups, i);
hit_group =
(struct maat_hit_group *)utarray_eltptr(compile_state->indirect_hit_groups, i);
group_array[i].item_id = hit_group->item_id;
group_array[i].group_id = hit_group->group_id;
group_array[i].vtable_id = hit_group->vtable_id;
@@ -2551,7 +2620,8 @@ size_t compile_state_get_last_hit_groups(struct compile_state *compile_state,
size_t i = 0;
for (i = 0; i < utarray_len(compile_state->last_hit_groups) && i < array_size; i++) {
group_array[i] = *(struct maat_hit_group *)utarray_eltptr(compile_state->last_hit_groups, i);
group_array[i] =
*(struct maat_hit_group *)utarray_eltptr(compile_state->last_hit_groups, i);
}
return i;
@@ -2597,7 +2667,8 @@ size_t compile_state_get_internal_hit_paths(struct compile_state *compile_state,
struct internal_hit_path *internal_path = NULL;
for (int i = 0; i < utarray_len(compile_state->internal_hit_paths); i++) {
internal_path = (struct internal_hit_path *)utarray_eltptr(compile_state->internal_hit_paths, i);
internal_path =
(struct internal_hit_path *)utarray_eltptr(compile_state->internal_hit_paths, i);
/*
NOTE: maybe one item has been deleted, but it's item_id still exist in internal_hit_paths
*/
@@ -2605,8 +2676,9 @@ size_t compile_state_get_internal_hit_paths(struct compile_state *compile_state,
UT_array *valid_super_group_ids;
utarray_new(valid_super_group_ids, &ut_compile_group_id_icd);
size_t super_group_cnt = group2group_runtime_get_super_groups(g2g_rt, &(internal_path->group_id), 1,
super_group_ids, MAX_HIT_GROUP_NUM);
size_t super_group_cnt =
group2group_runtime_get_super_groups(g2g_rt, &(internal_path->group_id), 1,
super_group_ids, MAX_HIT_GROUP_NUM);
for (size_t idx = 0; idx < super_group_cnt; idx++) {
utarray_push_back(valid_super_group_ids, &super_group_ids[idx]);
}
@@ -2623,7 +2695,8 @@ size_t compile_state_get_internal_hit_paths(struct compile_state *compile_state,
long long *p = NULL;
struct maat_hit_path tmp_path;
for (p = utarray_front(valid_super_group_ids); p != NULL && hit_path_cnt < array_size;
for (p = utarray_front(valid_super_group_ids);
p != NULL && hit_path_cnt < array_size;
p = utarray_next(valid_super_group_ids, p)) {
memset(&tmp_path, 0, sizeof(tmp_path));
tmp_path.Nth_scan = internal_path->Nth_scan;
@@ -2638,7 +2711,8 @@ size_t compile_state_get_internal_hit_paths(struct compile_state *compile_state,
/* check if internal_path is duplicated from hit_path_array[]
* element */
if (hit_path_cnt > 0) {
if (maat_compile_is_hit_path_existed(hit_path_array, hit_path_cnt, &tmp_path)) {
if (maat_compile_is_hit_path_existed(hit_path_array, hit_path_cnt,
&tmp_path)) {
continue;
}
}

View File

@@ -39,7 +39,6 @@ struct plugin_runtime {
struct log_handle *logger;
long long rule_num;
long long acc_line_num;
long long update_err_cnt;
long long *scan_times;
};
@@ -372,7 +371,6 @@ static int plugin_runtime_update_row(struct plugin_runtime *plugin_rt,
ex_container_free(plugin_rt->ex_data_rt, ex_container);
return -1;
}
plugin_rt->acc_line_num++;
}
}

View File

@@ -528,7 +528,6 @@ void *rule_monitor_loop(void *arg)
pthread_mutex_unlock(&(maat_inst->background_update_mutex));
maat_garbage_collect_routine(maat_inst->garbage_bin);
maat_plugin_table_garbage_collect_routine(maat_inst->tbl_mgr);