[OPTIMIZE]reduce adapter_hs_scan cpu usage

This commit is contained in:
刘文坛
2023-06-20 07:00:49 +00:00
parent d3aed20bfa
commit 8ad355d5d7
31 changed files with 664 additions and 618 deletions

View File

@@ -55,9 +55,6 @@ struct ex_data_runtime *bool_plugin_runtime_get_ex_data_rt(void *bool_plugin_run
int bool_plugin_runtime_get_ex_data(void *bool_plugin_runtime, unsigned long long *item_ids,
size_t n_item, void **ex_data_array, size_t n_ex_data);
void bool_plugin_runtime_perf_stat(void *bool_plugin_runtime, struct timespec *start,
struct timespec *end, int thread_id);
long long bool_plugin_runtime_scan_count(void *bool_plugin_runtime);
long long bool_plugin_runtime_scan_cpu_time(void *bool_plugin_runtime);

View File

@@ -97,8 +97,6 @@ long long maat_cmd_read_redis_integer(const redisReply *reply);
int maat_cmd_get_valid_flag_offset(const char *line, int column_seq);
const char *maat_cmd_find_Nth_column(const char *line, int Nth, int *column_len);
int maat_cmd_write_rule(redisContext *c, struct serial_rule *s_rule,
size_t serial_rule_num, long long server_time,
struct log_handle *logger);

View File

@@ -22,8 +22,8 @@ extern "C"
void config_monitor_traverse(long long version, const char *idx_dir,
void (*start_fn)(long long, int, void *),
int (*update_fn)(const char *, const char *, void *),
void (*finish_fn)(void *), void *u_param, const char *dec_key,
struct log_handle *logger);
void (*finish_fn)(void *), void *u_param,
const char *dec_key, struct log_handle *logger);
int load_maat_json_file(struct maat *maat_instance, const char *json_filename,
char *err_str, size_t err_str_sz);

View File

@@ -90,9 +90,6 @@ void *ex_data_runtime_get_ex_data_by_key(struct ex_data_runtime *ex_data_rt,
void *ex_data_runtime_get_ex_data_by_container(struct ex_data_runtime *ex_data_rt,
struct ex_container *ex_container);
void *ex_data_runtime_get_custom_data(struct ex_data_runtime *ex_data_rt,
const char *key, size_t key_len);
void ex_data_runtime_garbage_collect_routine(struct ex_data_runtime *ex_data_rt);
#ifdef __cplusplus

View File

@@ -59,9 +59,6 @@ int fqdn_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, const char *fqdn,
void fqdn_rule_free(struct FQDN_rule *fqdn_rule);
void fqdn_plugin_runtime_perf_stat(void *fqdn_plugin_runtime, struct timespec *start,
struct timespec *end, int thread_id);
long long fqdn_plugin_runtime_scan_count(void *fqdn_plugin_runtime);
long long fqdn_plugin_runtime_scan_cpu_time(void *fqdn_plugin_runtime);

View File

@@ -55,9 +55,6 @@ struct ex_data_runtime *ip_plugin_runtime_get_ex_data_rt(void *ip_plugin_runtime
int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, const struct ip_addr *ip_addr,
void **ex_data_array, size_t n_ex_data_array);
void ip_plugin_runtime_perf_stat(void *ip_plugin_runtime, struct timespec *start,
struct timespec *end, int thread_id);
long long ip_plugin_runtime_scan_count(void *ip_plugin_runtime);
long long ip_plugin_runtime_scan_cpu_time(void *ip_plugin_runtime);

View File

@@ -86,9 +86,9 @@ struct translate_command {
int default_int;
};
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) {
@@ -112,7 +112,7 @@ struct iris_table *query_table_info(struct iris_description *p_iris,
return table_info;
}
void free_iris_table_info(void *p)
static void free_iris_table_info(void *p)
{
struct iris_table *table = (struct iris_table *)p;
if (table != NULL) {
@@ -121,11 +121,11 @@ void free_iris_table_info(void *p)
FREE(table);
}
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),
@@ -191,7 +191,7 @@ int set_iris_descriptor(const char *json_file, cJSON *json,
return 0;
}
void clear_iris_descriptor(struct iris_description *iris_cfg)
static void clear_iris_descriptor(struct iris_description *iris_cfg)
{
if (iris_cfg->group_name_map != NULL) {
struct group_info *node = NULL;
@@ -218,7 +218,7 @@ void clear_iris_descriptor(struct iris_description *iris_cfg)
return;
}
int create_tmp_dir(struct iris_description *p)
static int create_tmp_dir(struct iris_description *p)
{
if ((access(p->tmp_iris_dir,F_OK)) < 0) {
if ((mkdir(p->tmp_iris_dir, 0777)) < 0) {
@@ -235,9 +235,9 @@ int create_tmp_dir(struct iris_description *p)
return 0;
}
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) {
@@ -347,9 +347,9 @@ static int get_region_seq(struct iris_description *iris_cfg)
return sequence;
}
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;
@@ -420,8 +420,8 @@ error_out:
return ret;
}
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;
@@ -457,8 +457,8 @@ int write_flag_line(cJSON *region_json, struct iris_description *p_iris,
json_cmd, cmd_cnt, table, logger);
}
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;
@@ -505,8 +505,8 @@ int write_expr_line(cJSON *region_json, struct iris_description *p_iris,
json_cmd, cmd_cnt, table, logger);
}
int write_ip_plus_line(cJSON *region_json, struct iris_description *p_iris,
struct iris_table *table, struct log_handle *logger)
static int write_ip_plus_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;
@@ -575,8 +575,8 @@ int write_ip_plus_line(cJSON *region_json, struct iris_description *p_iris,
json_cmd, cmd_cnt, table, logger);
}
int write_intval_line(cJSON *region_json, struct iris_description *p_iris,
struct iris_table *table, struct log_handle *logger)
static int write_intval_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;
@@ -612,8 +612,8 @@ int write_intval_line(cJSON *region_json, struct iris_description *p_iris,
json_cmd, cmd_cnt, table, logger);
}
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) {
@@ -682,10 +682,10 @@ int write_region_rule(cJSON *region_json, int compile_id, int group_id,
return ret;
}
int write_group2compile_line(int 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_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;
@@ -708,8 +708,8 @@ int write_group2compile_line(int group_id, int compile_id, int group_not_flag,
return 0;
}
int write_group2group_line(int group_id, int super_group_id, int is_exclude,
struct iris_description *p_iris)
static int write_group2group_line(int group_id, int super_group_id, int is_exclude,
struct iris_description *p_iris)
{
char buff[4096] = {0};
struct iris_table *table = p_iris->group2group_table;
@@ -726,10 +726,10 @@ int write_group2group_line(int group_id, int super_group_id, int is_exclude,
return 0;
}
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;
@@ -842,8 +842,8 @@ int write_group_rule(cJSON *group_json, int parent_id,
return 0;
}
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) {
@@ -948,7 +948,8 @@ int write_compile_line(cJSON *compile, struct iris_description *p_iris,
return compile_id;
}
void write_table_idx(struct iris_description *p_iris, struct iris_table *table)
static void write_table_idx(struct iris_description *p_iris,
struct iris_table *table)
{
char line_cnt_str[32] = {0};
char err_str[256] = {0};
@@ -966,24 +967,25 @@ void write_table_idx(struct iris_description *p_iris, struct iris_table *table)
unsigned char *encrypt_buff = NULL;
size_t encrypt_buff_sz = 0;
ret = crypt_memory(buff, table_file_sz, &encrypt_buff,
&encrypt_buff_sz, p_iris->encrypt_key,
p_iris->encrypt_algo, 1, err_str, sizeof(err_str));
&encrypt_buff_sz, p_iris->encrypt_key,
p_iris->encrypt_algo, 1, err_str, sizeof(err_str));
assert(ret == 0);
fwrite(encrypt_buff, encrypt_buff_sz, 1, table_fp);
fprintf(p_iris->idx_fp, "%s\t%d\t%s\t%s\n", table->table_name, table->line_count,
table->table_path, p_iris->encrypt_algo);
fprintf(p_iris->idx_fp, "%s\t%d\t%s\t%s\n", table->table_name,
table->line_count, table->table_path, p_iris->encrypt_algo);
FREE(encrypt_buff);
} else {
fwrite(buff, table_file_sz, 1, table_fp);
fprintf(p_iris->idx_fp, "%s\t%d\t%s\n", table->table_name, table->line_count,
table->table_path);
fprintf(p_iris->idx_fp, "%s\t%d\t%s\n", table->table_name,
table->line_count, table->table_path);
}
fclose(table_fp);
FREE(buff);
}
int write_index_file(struct iris_description *p_iris, struct log_handle *logger)
static int write_index_file(struct iris_description *p_iris,
struct log_handle *logger)
{
p_iris->idx_fp = fopen(p_iris->index_path, "w");
if (NULL == p_iris->idx_fp) {
@@ -1005,8 +1007,8 @@ int write_index_file(struct iris_description *p_iris, struct log_handle *logger)
return 0;
}
int write_iris(cJSON *json, struct iris_description *p_iris,
struct log_handle *logger)
static int write_iris(cJSON *json, struct iris_description *p_iris,
struct log_handle *logger)
{
int i=0;
int ret=0;

View File

@@ -267,7 +267,7 @@ int maat_options_set_logger(struct maat_options *opts, const char *log_path,
return 0;
}
void _maat_free(struct maat *maat_inst)
static void _maat_free(struct maat *maat_inst)
{
if (NULL == maat_inst) {
return;
@@ -504,11 +504,11 @@ int maat_table_callback_register(struct maat *maat_inst, int table_id,
return 0;
}
int compile_table_ex_schema_register(struct maat *maat_inst, 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)
static int compile_table_ex_schema_register(struct maat *maat_inst, 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)
{
void *schema = table_manager_get_schema(maat_inst->tbl_mgr, table_id);
assert(schema != NULL);
@@ -530,11 +530,12 @@ int compile_table_ex_schema_register(struct maat *maat_inst, int table_id,
return 0;
}
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) {
@@ -578,9 +579,9 @@ int generic_plugin_table_set_ex_schema(struct table_manager *tbl_mgr, int table_
return ret;
}
void plugin_runtime_commit_ex_schema(void *runtime, void *schema,
const char *table_name,
int valid_column)
static void plugin_runtime_commit_ex_schema(void *runtime, void *schema,
const char *table_name,
int valid_column)
{
struct ex_container_schema *container_schema = NULL;
struct ex_data_runtime *ex_data_rt = NULL;
@@ -599,9 +600,9 @@ void plugin_runtime_commit_ex_schema(void *runtime, void *schema,
plugin_runtime_commit(runtime, table_name, 0);
}
void ip_plugin_runtime_commit_ex_schema(void *runtime, void *schema,
const char *table_name,
int valid_column)
static void ip_plugin_runtime_commit_ex_schema(void *runtime, void *schema,
const char *table_name,
int valid_column)
{
struct ex_container_schema *container_schema = NULL;
struct ex_data_runtime *ex_data_rt = NULL;
@@ -620,9 +621,9 @@ void ip_plugin_runtime_commit_ex_schema(void *runtime, void *schema,
ip_plugin_runtime_commit(runtime, table_name, 0);
}
void fqdn_plugin_runtime_commit_ex_schema(void *runtime, void *schema,
const char *table_name,
int valid_column)
static void fqdn_plugin_runtime_commit_ex_schema(void *runtime, void *schema,
const char *table_name,
int valid_column)
{
struct ex_container_schema *container_schema = NULL;
struct ex_data_runtime *ex_data_rt = NULL;
@@ -641,9 +642,9 @@ void fqdn_plugin_runtime_commit_ex_schema(void *runtime, void *schema,
fqdn_plugin_runtime_commit(runtime, table_name, 0);
}
void bool_plugin_runtime_commit_ex_schema(void *runtime, void *schema,
const char *table_name,
int valid_column)
static void bool_plugin_runtime_commit_ex_schema(void *runtime, void *schema,
const char *table_name,
int valid_column)
{
struct ex_container_schema *container_schema = NULL;
struct ex_data_runtime *ex_data_rt = NULL;
@@ -662,9 +663,11 @@ void bool_plugin_runtime_commit_ex_schema(void *runtime, void *schema,
bool_plugin_runtime_commit(runtime, table_name, 0);
}
int generic_plugin_runtime_commit_ex_schema(void *runtime, void *schema, const char *table_name,
enum table_type table_type, int valid_column,
struct log_handle *logger)
static int generic_plugin_runtime_commit_ex_schema(void *runtime, void *schema,
const char *table_name,
enum table_type table_type,
int valid_column,
struct log_handle *logger)
{
if (NULL == runtime || NULL == schema || valid_column < 0) {
log_error(logger, MODULE_MAAT_API,
@@ -695,12 +698,12 @@ int generic_plugin_runtime_commit_ex_schema(void *runtime, void *schema, const c
return 0;
}
int generic_plugin_table_ex_schema_register(struct maat *maat_inst,
const char *table_name, 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)
static int generic_plugin_table_ex_schema_register(struct maat *maat_inst,
const char *table_name, 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)
{
int ret = generic_plugin_table_set_ex_schema(maat_inst->tbl_mgr, table_id,
new_func, free_func, dup_func,
@@ -905,16 +908,16 @@ static inline int scan_status_should_compile_NOT(struct maat_state *state)
return 0;
}
size_t hit_group_to_compile(void *compile_runtime, long long *compile_ids,
size_t compile_ids_size, struct maat_state *state)
static size_t hit_group_to_compile(void *compile_runtime, long long *compile_ids,
size_t compile_ids_size, struct maat_state *state)
{
size_t n_hit_compile = compile_runtime_match((struct compile_runtime *)compile_runtime,
compile_ids, compile_ids_size, state);
return n_hit_compile;
}
int flag_scan(struct table_manager *tbl_mgr, int thread_id, long long flag,
int phy_table_id, int vtable_id, struct maat_state *state)
static int flag_scan(struct table_manager *tbl_mgr, int thread_id, long long flag,
int phy_table_id, int vtable_id, struct maat_state *state)
{
enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id);
if (table_type == TABLE_TYPE_FLAG_PLUS &&
@@ -942,8 +945,8 @@ int flag_scan(struct table_manager *tbl_mgr, int thread_id, long long flag,
return group_hit_cnt;
}
int interval_scan(struct table_manager *tbl_mgr, int thread_id, long long integer,
int phy_table_id, int vtable_id, struct maat_state *state)
static int interval_scan(struct table_manager *tbl_mgr, int thread_id, long long integer,
int phy_table_id, int vtable_id, struct maat_state *state)
{
enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id);
@@ -972,9 +975,9 @@ int interval_scan(struct table_manager *tbl_mgr, int thread_id, long long intege
return group_hit_cnt;
}
int ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_addr,
uint16_t port, int proto, int phy_table_id, int vtable_id,
struct maat_state *state)
static int ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_addr,
uint16_t port, int proto, int phy_table_id, int vtable_id,
struct maat_state *state)
{
enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id);
@@ -999,9 +1002,9 @@ int ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_addr,
return group_hit_cnt;
}
int ipv6_scan(struct table_manager *tbl_mgr, int thread_id,
uint8_t *ip_addr, uint16_t port, int proto,
int phy_table_id, int vtable_id, struct maat_state *state)
static int ipv6_scan(struct table_manager *tbl_mgr, int thread_id,
uint8_t *ip_addr, uint16_t port, int proto,
int phy_table_id, int vtable_id, struct maat_state *state)
{
enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id);
@@ -1025,9 +1028,9 @@ int ipv6_scan(struct table_manager *tbl_mgr, int thread_id,
return group_hit_cnt;
}
int string_scan(struct table_manager *tbl_mgr, int thread_id,
const char *data, size_t data_len, int phy_table_id,
int vtable_id, struct maat_state *state)
static int string_scan(struct table_manager *tbl_mgr, int thread_id,
const char *data, size_t data_len, int phy_table_id,
int vtable_id, struct maat_state *state)
{
enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id);
if (table_type == TABLE_TYPE_EXPR_PLUS &&
@@ -1056,8 +1059,8 @@ int string_scan(struct table_manager *tbl_mgr, int thread_id,
return group_hit_cnt;
}
int expr_stream_scan(struct maat_stream *stream, const char *data,
size_t data_len, struct maat_state *state)
static int expr_stream_scan(struct maat_stream *stream, const char *data,
size_t data_len, struct maat_state *state)
{
if (NULL == stream || NULL == data) {
return 0;
@@ -1092,8 +1095,8 @@ int expr_stream_scan(struct maat_stream *stream, const char *data,
return group_hit_cnt;
}
size_t group_to_compile(struct maat *maat_inst, long long *results, size_t n_result,
struct maat_state *state)
static size_t group_to_compile(struct maat *maat_inst, long long *results,
size_t n_result, struct maat_state *state)
{
int compile_table_id = table_manager_get_default_compile_table_id(maat_inst->tbl_mgr);

View File

@@ -164,7 +164,7 @@ static int cmp_ull_p(const void *p1, const void *p2)
}
}
size_t ull_dedup(unsigned long long item_ids[], size_t n_item)
static size_t ull_dedup(unsigned long long item_ids[], size_t n_item)
{
size_t index = 0;
@@ -236,10 +236,10 @@ void bool_plugin_runtime_free(void *bool_plugin_runtime)
FREE(bool_plugin_rt);
}
int bool_plugin_runtime_update_row(struct bool_plugin_runtime *bool_plugin_rt,
const char *table_name, const char *row,
const char *key, size_t key_len,
struct bool_expr *expr, int is_valid)
static int bool_plugin_runtime_update_row(struct bool_plugin_runtime *bool_plugin_rt,
const char *table_name, const char *row,
const char *key, size_t key_len,
struct bool_expr *expr, int is_valid)
{
int ret = -1;
struct ex_data_runtime *ex_data_rt = bool_plugin_rt->ex_data_rt;
@@ -264,8 +264,9 @@ int bool_plugin_runtime_update_row(struct bool_plugin_runtime *bool_plugin_rt,
return 0;
}
int bool_plugin_accept_tag_match(struct bool_plugin_schema *schema, const char *table_name,
const char *line, struct log_handle *logger)
static int bool_plugin_accept_tag_match(struct bool_plugin_schema *schema,
const char *table_name, const char *line,
struct log_handle *logger)
{
size_t column_offset = 0;
size_t column_len = 0;
@@ -305,7 +306,7 @@ int bool_plugin_accept_tag_match(struct bool_plugin_schema *schema, const char *
return TAG_MATCH_MATCHED;
}
struct bool_expr *
static struct bool_expr *
bool_plugin_expr_new(struct bool_plugin_schema *schema, const char *table_name,
const char *line, struct log_handle *logger)
{
@@ -370,7 +371,7 @@ error:
return NULL;
}
void bool_plugin_expr_free(struct bool_expr *expr)
static void bool_plugin_expr_free(struct bool_expr *expr)
{
FREE(expr);
}
@@ -563,23 +564,6 @@ int bool_plugin_runtime_get_ex_data(void *bool_plugin_runtime, unsigned long lon
return n_result;
}
void bool_plugin_runtime_perf_stat(void *bool_plugin_runtime, struct timespec *start,
struct timespec *end, int thread_id)
{
if (NULL == bool_plugin_runtime || thread_id < 0) {
return;
}
struct bool_plugin_runtime *bool_plugin_rt = (struct bool_plugin_runtime *)bool_plugin_runtime;
alignment_int64_array_add(bool_plugin_rt->scan_cnt, thread_id, 1);
if (start != NULL && end != NULL) {
long long consume_time = (end->tv_sec - start->tv_sec) * 1000000000 +
(end->tv_nsec - start->tv_nsec);
alignment_int64_array_add(bool_plugin_rt->scan_cpu_time, thread_id, consume_time);
}
}
long long bool_plugin_runtime_scan_count(void *bool_plugin_runtime)
{
if (NULL == bool_plugin_runtime) {

View File

@@ -107,7 +107,8 @@ long long maat_cmd_read_redis_integer(const redisReply *reply)
return 0;
}
int redis_flushDB(redisContext *ctx, int db_index, struct log_handle *logger)
static int redis_flushDB(redisContext *ctx, int db_index,
struct log_handle *logger)
{
long long maat_redis_version = 0;
@@ -184,7 +185,7 @@ static int connect_redis_for_write(struct source_redis_ctx *redis_ctx,
}
}
redisContext *get_redis_ctx_for_write(struct maat *maat_inst)
static redisContext *get_redis_ctx_for_write(struct maat *maat_inst)
{
if (NULL == maat_inst->opts.redis_ctx.write_ctx) {
int ret = connect_redis_for_write(&(maat_inst->opts.redis_ctx),
@@ -276,42 +277,6 @@ long long maat_cmd_redis_server_time_s(redisContext *c)
return server_time;
}
const char *maat_cmd_find_Nth_column(const char *line, int Nth, int *column_len)
{
size_t i = 0;
int j = 0;
size_t start=0, end=0;
size_t line_len = strlen(line);
for (i = 0; i < line_len; i++) {
if (line[i] != ' ' && line[i] != '\t') {
continue;
}
j++;
if (j == Nth - 1) {
start = i + 1;
}
if(j == Nth) {
end = i;
break;
}
}
if (start == end) {
return NULL;
}
if (end == 0) {
end = i;
}
*column_len = end - start;
return line + start;
}
int maat_cmd_wrap_redis_get_reply(redisContext *c, redisReply **reply)
{
return redisGetReply(c, (void **)reply);
@@ -522,4 +487,4 @@ char *maat_cmd_str_escape(char *dst, int size, const char *src)
dst[j] = '\0';
return dst;
}
}

View File

@@ -167,7 +167,7 @@ UT_icd ut_clause_id_icd = {sizeof(long long), NULL, NULL, NULL};
UT_icd ut_hit_group_icd = {sizeof(struct maat_hit_group), NULL, NULL, NULL};
UT_icd ut_hit_path_icd = {sizeof(struct maat_internal_hit_path), NULL, NULL, NULL};
struct maat_compile *maat_compile_new(long long compile_id)
static struct maat_compile *maat_compile_new(long long compile_id)
{
struct maat_compile *compile = ALLOC(struct maat_compile, 1);
@@ -183,9 +183,9 @@ struct maat_compile *maat_compile_new(long long compile_id)
return compile;
}
int maat_compile_set(struct maat_compile *compile, const char *table_name,
int declared_clause_num, void *user_data,
void (*user_data_free)(void *))
static int maat_compile_set(struct maat_compile *compile, const char *table_name,
int declared_clause_num, void *user_data,
void (*user_data_free)(void *))
{
if (user_data != NULL && NULL == user_data_free) {
return -1;
@@ -200,7 +200,7 @@ int maat_compile_set(struct maat_compile *compile, const char *table_name,
return 0;
}
void maat_compile_free(struct maat_compile *compile)
static void maat_compile_free(struct maat_compile *compile)
{
struct maat_clause_state *clause_state = NULL;
if (compile->user_data && compile->user_data_free) {
@@ -222,7 +222,7 @@ void maat_compile_free(struct maat_compile *compile)
FREE(compile);
}
void rcu_compile_cfg_free(void *user_ctx, void *data)
static void rcu_compile_cfg_free(void *user_ctx, void *data)
{
struct maat_compile *compile = (struct maat_compile *)data;
maat_compile_free(compile);
@@ -236,8 +236,8 @@ int compile_table_set_ex_data_schema(struct compile_schema *compile_schema, int
{
if (1 == compile_schema->set_flag) {
log_error(compile_schema->logger, MODULE_COMPILE,
"[%s:%d] compile table(table_id:%d)ex schema has been set already, can't set again",
__FUNCTION__, __LINE__, table_id);
"[%s:%d] compile table(table_id:%d)ex schema has been set already,"
" can't set again", __FUNCTION__, __LINE__, table_id);
return -1;
}
@@ -251,10 +251,12 @@ int compile_table_set_ex_data_schema(struct compile_schema *compile_schema, int
return 0;
}
void *compile_runtime_get_user_data(struct compile_runtime *compile_rt, long long compile_id)
static void *compile_runtime_get_user_data(struct compile_runtime *compile_rt,
long long compile_id)
{
struct maat_compile *compile = rcu_hash_find(compile_rt->cfg_hash,
(char *)&compile_id, sizeof(long long));
(char *)&compile_id,
sizeof(long long));
void *ret = NULL;
if (compile != NULL) {
ret = compile->user_data;
@@ -263,8 +265,9 @@ void *compile_runtime_get_user_data(struct compile_runtime *compile_rt, long lon
return ret;
}
void *rule_ex_data_new(const char *table_name, int table_id, const char *table_line,
struct ex_data_schema *ex_schema)
static void *rule_ex_data_new(const char *table_name, int table_id,
const char *table_line,
struct ex_data_schema *ex_schema)
{
void *ex_data = NULL;
@@ -273,12 +276,14 @@ void *rule_ex_data_new(const char *table_name, int table_id, const char *table_l
return ex_data;
}
void rule_ex_data_free(int table_id, void **ex_data, const struct ex_data_schema *ex_schema)
static void rule_ex_data_free(int table_id, void **ex_data,
const struct ex_data_schema *ex_schema)
{
ex_schema->free_func(table_id, ex_data, ex_schema->argl, ex_schema->argp);
}
void rule_ex_data_new_cb(void *user_data, void *param, const char *table_name, int table_id)
static void rule_ex_data_new_cb(void *user_data, void *param,
const char *table_name, int table_id)
{
struct ex_data_schema *ex_schema = (struct ex_data_schema *)param;
struct compile_rule *compile = (struct compile_rule *)user_data;
@@ -287,9 +292,9 @@ void rule_ex_data_new_cb(void *user_data, void *param, const char *table_name, i
*compile->ex_data = ad;
}
void compile_runtime_user_data_iterate(struct compile_runtime *compile_rt,
void (*callback)(void *user_data, void *param, const char *table_name, int table_id),
void *param, int table_id)
static void compile_runtime_user_data_iterate(struct compile_runtime *compile_rt,
void (*callback)(void *user_data, void *param, const char *table_name, int table_id),
void *param, int table_id)
{
/* I'm in background_update_mutex, config update can't happen, so no need to lock cfg_hash */
void **data_array = NULL;
@@ -477,8 +482,8 @@ int group2compile_associated_compile_table_id(void *g2c_schema)
return schema->asso_compile_table_id;
}
int compile_accept_tag_match(struct compile_schema *schema, const char *line,
const char *table_name, struct log_handle *logger)
static int compile_accept_tag_match(struct compile_schema *schema, const char *line,
const char *table_name, struct log_handle *logger)
{
size_t column_offset = 0;
size_t column_len = 0;
@@ -518,7 +523,7 @@ int compile_accept_tag_match(struct compile_schema *schema, const char *line,
return TAG_MATCH_MATCHED;
}
struct compile_item *
static struct compile_item *
compile_item_new(const char *line, struct compile_schema *compile_schema,
const char *table_name, struct log_handle *logger)
{
@@ -557,7 +562,7 @@ error:
return NULL;
}
void compile_item_free(struct compile_item *compile_item)
static void compile_item_free(struct compile_item *compile_item)
{
if (NULL == compile_item) {
return;
@@ -617,7 +622,7 @@ static void literal2clause_hash_free(struct literal_clause *hash)
assert(hash == NULL);
}
void garbage_literal2clause_hash_free(void *l2c_hash, void *arg)
static void garbage_literal2clause_hash_free(void *l2c_hash, void *arg)
{
literal2clause_hash_free((struct literal_clause *)l2c_hash);
}
@@ -696,7 +701,7 @@ void group2compile_runtime_free(void *g2c_runtime)
FREE(g2c_runtime);
}
int is_valid_table_name(const char *str)
static int is_valid_table_name(const char *str)
{
size_t integer_cnt=0;
for (size_t i = 0; i < strlen(str); i++) {
@@ -713,7 +718,7 @@ int is_valid_table_name(const char *str)
return 1;
}
struct group2compile_item *
static struct group2compile_item *
group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema,
const char *table_name, struct log_handle *logger)
{
@@ -799,7 +804,7 @@ error:
return NULL;
}
void group2compile_item_free(struct group2compile_item *g2c_item)
static void group2compile_item_free(struct group2compile_item *g2c_item)
{
if (NULL == g2c_item) {
return;
@@ -808,7 +813,7 @@ void group2compile_item_free(struct group2compile_item *g2c_item)
FREE(g2c_item);
}
int compare_literal_id(const void *pa, const void *pb)
static int compare_literal_id(const void *pa, const void *pb)
{
struct maat_literal_id *la = (struct maat_literal_id *)pa;
struct maat_literal_id *lb = (struct maat_literal_id *)pb;
@@ -821,9 +826,9 @@ int compare_literal_id(const void *pa, const void *pb)
return ret;
}
int maat_compile_clause_add_literal(struct maat_compile *compile,
struct maat_literal_id *literal_id,
int clause_index, int clause_not_flag)
static int maat_compile_clause_add_literal(struct maat_compile *compile,
struct maat_literal_id *literal_id,
int clause_index, int clause_not_flag)
{
struct maat_clause_state *clause_state = compile->clause_states + clause_index;
@@ -848,9 +853,9 @@ int maat_compile_clause_add_literal(struct maat_compile *compile,
return 0;
}
int maat_compile_clause_remove_literal(struct maat_compile *compile,
struct maat_literal_id *literal_id,
int clause_index)
static int maat_compile_clause_remove_literal(struct maat_compile *compile,
struct maat_literal_id *literal_id,
int clause_index)
{
struct maat_clause_state* clause_state = compile->clause_states + clause_index;
struct maat_literal_id *tmp = NULL;
@@ -896,7 +901,7 @@ maat_clause_hash_fetch_clause(struct compile_runtime *compile_rt,
return clause;
}
struct bool_matcher *
static struct bool_matcher *
maat_compile_bool_matcher_new(struct compile_runtime *compile_rt, size_t *compile_cnt)
{
if (NULL == compile_rt) {
@@ -1020,7 +1025,7 @@ static inline int compare_hit_group(const void *pa, const void *pb)
return ret;
}
struct literal_clause *
static struct literal_clause *
maat_compile_build_literal2clause_hash(struct compile_runtime *compile_rt)
{
if (NULL == compile_rt) {
@@ -1101,9 +1106,10 @@ static size_t compile_state_if_new_hit_compile(struct maat_compile_state *compil
return r_in_c_cnt;
}
size_t maat_compile_bool_matcher_match(struct compile_runtime *compile_rt, int is_last_scan,
struct maat_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,
int is_last_scan, int thread_id,
struct maat_compile_state *compile_state,
void **user_data_array, size_t ud_array_size)
{
size_t ud_result_cnt = 0;
struct maat_compile *compile = NULL;
@@ -1162,10 +1168,9 @@ size_t maat_compile_bool_matcher_match(struct compile_runtime *compile_rt, int i
}
#define COMPILE_RULE_MAGIC 0x1a2b3c4d
struct compile_rule *compile_rule_new(struct compile_item *compile_item,
struct compile_schema *schema,
const char *table_name,
const char *table_line)
static struct compile_rule *
compile_rule_new(struct compile_item *compile_item, struct compile_schema *schema,
const char *table_name, const char *table_line)
{
struct compile_rule *compile_rule = ALLOC(struct compile_rule, 1);
@@ -1190,7 +1195,7 @@ struct compile_rule *compile_rule_new(struct compile_item *compile_item,
return compile_rule;
}
struct compile_rule *compile_rule_clone(struct compile_rule *rule)
static struct compile_rule *compile_rule_clone(struct compile_rule *rule)
{
struct compile_rule *new_rule = ALLOC(struct compile_rule, 1);
@@ -1212,7 +1217,7 @@ struct compile_rule *compile_rule_clone(struct compile_rule *rule)
return new_rule;
}
void compile_rule_free(struct compile_rule *compile_rule)
static void compile_rule_free(struct compile_rule *compile_rule)
{
struct compile_schema *schema = compile_rule->ref_schema;
assert(compile_rule->magic_num == COMPILE_RULE_MAGIC);
@@ -1236,7 +1241,8 @@ void compile_rule_free(struct compile_rule *compile_rule)
FREE(compile_rule);
}
struct maat_compile *maat_compile_clone(struct maat_compile *compile, int deep_copy)
static struct maat_compile *
maat_compile_clone(struct maat_compile *compile, int deep_copy)
{
struct maat_compile *new_compile = ALLOC(struct maat_compile, 1);
@@ -1270,8 +1276,9 @@ struct maat_compile *maat_compile_clone(struct maat_compile *compile, int deep_c
return new_compile;
}
int maat_add_group_to_compile(struct rcu_hash_table *hash_tbl, struct group2compile_item *g2c_item,
struct log_handle *logger)
static int maat_add_group_to_compile(struct rcu_hash_table *hash_tbl,
struct group2compile_item *g2c_item,
struct log_handle *logger)
{
int ret = -1;
long long compile_id = g2c_item->compile_id;
@@ -1351,9 +1358,9 @@ int maat_add_group_to_compile(struct rcu_hash_table *hash_tbl, struct group2comp
return ret;
}
int maat_remove_group_from_compile(struct rcu_hash_table *hash_tbl,
struct group2compile_item *g2c_item,
struct log_handle *logger)
static int maat_remove_group_from_compile(struct rcu_hash_table *hash_tbl,
struct group2compile_item *g2c_item,
struct log_handle *logger)
{
int ret = -1;
long long compile_id = g2c_item->compile_id;
@@ -1605,9 +1612,9 @@ size_t compile_runtime_get_hit_paths(struct compile_runtime *compile_rt, int thr
return (n_internal_hit_path + new_hit_path_cnt);
}
void maat_compile_state_update_hit_path(struct maat_compile_state *compile_state,
long long item_id, long long group_id,
int vtable_id, int Nth_scan, int Nth_item_result)
static void maat_compile_state_update_hit_path(struct maat_compile_state *compile_state,
long long item_id, long long group_id,
int vtable_id, int Nth_scan, int Nth_item_result)
{
if (compile_state->Nth_scan != Nth_scan) {
assert(compile_state->this_scan_hit_item_flag == 0);
@@ -1621,9 +1628,9 @@ void maat_compile_state_update_hit_path(struct maat_compile_state *compile_state
compile_state->this_scan_hit_item_flag = 1;
}
void maat_compile_state_update_hit_clause(struct maat_compile_state *compile_state,
struct compile_runtime *compile_rt,
long long group_id, int vtable_id)
static void maat_compile_state_update_hit_clause(struct maat_compile_state *compile_state,
struct compile_runtime *compile_rt,
long long group_id, int vtable_id)
{
if (NULL == compile_state || NULL == compile_rt) {
return;
@@ -1702,8 +1709,10 @@ void *compile_runtime_get_ex_data(struct compile_runtime *compile_rt,
return ex_data;
}
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)
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 compile_item *compile_item = NULL;
struct maat_compile *compile = NULL;
@@ -1775,7 +1784,8 @@ int compile_runtime_add_compile(struct compile_runtime *compile_rt, struct compi
return 0;
}
void compile_runtime_del_compile(struct compile_runtime *compile_rt, long long compile_id)
static void compile_runtime_del_compile(struct compile_runtime *compile_rt,
long long compile_id)
{
struct maat_compile *compile = NULL;
@@ -2079,7 +2089,7 @@ int compile_runtime_match(struct compile_runtime *compile_rt, long long *compile
// all hit clause_id -> compile_id
size_t bool_match_ret = maat_compile_bool_matcher_match(compile_rt, is_last_scan,
compile_state, state->thread_id,
state->thread_id, compile_state,
(void **)compile_rules,
compile_ids_size);
if (bool_match_ret > 0) {

View File

@@ -33,8 +33,8 @@ struct cm_table_info_t
char encrypt_algo[NAME_MAX];
};
int cm_read_cfg_index_file(const char* path, struct cm_table_info_t* idx, int size,
struct log_handle *logger)
static int cm_read_cfg_index_file(const char *path, struct cm_table_info_t *idx,
int size, struct log_handle *logger)
{
int ret = 0;
int i = 0;
@@ -72,7 +72,7 @@ int cm_read_cfg_index_file(const char* path, struct cm_table_info_t* idx, int si
return i;
}
const char *path2filename(const char *path)
static const char *path2filename(const char *path)
{
int i = 0;
for (i = strlen(path);i > 0;i--) {
@@ -83,8 +83,8 @@ const char *path2filename(const char *path)
return path + i + 1;
}
char *read_nxt_line_from_buff(const char *buff, size_t buff_size,
size_t *offset, char *line, int line_size)
static char *read_nxt_line_from_buff(const char *buff, size_t buff_size,
size_t *offset, char *line, int line_size)
{
int this_offset=0;
const char* p;
@@ -110,9 +110,10 @@ char *read_nxt_line_from_buff(const char *buff, size_t buff_size,
return line;
}
int cm_read_table_file(struct cm_table_info_t *index,
int (*update_fn)(const char *, const char *, void *),
void *u_param, const char *dec_key, struct log_handle *logger)
static int cm_read_table_file(struct cm_table_info_t *index,
int (*update_fn)(const char *, const char *, void *),
void *u_param, const char *dec_key,
struct log_handle *logger)
{
int ret = 0;
size_t file_sz = 0;
@@ -123,7 +124,8 @@ int cm_read_table_file(struct cm_table_info_t *index,
//JSON file has been encrypted
if (NULL == dec_key || 0 == strlen(dec_key)) {
log_error(logger, MODULE_CONFIG_MONITOR,
"update error, no key to decrypt %s.", index->cfg_path);
"update error, no key to decrypt %s.",
index->cfg_path);
return -1;
}
@@ -132,7 +134,8 @@ int cm_read_table_file(struct cm_table_info_t *index,
sizeof(error_string));
if (ret < 0) {
log_error(logger, MODULE_CONFIG_MONITOR,
"update error, decrypt %s failed: %s", index->cfg_path, error_string);
"update error, decrypt %s failed: %s",
index->cfg_path, error_string);
return -1;
}
} else {
@@ -154,7 +157,8 @@ int cm_read_table_file(struct cm_table_info_t *index,
if(cfg_num != index->cfg_num) {
FREE(file_buff);
log_error(logger, MODULE_CONFIG_MONITOR, "[%s:%d] file %s config num not matched",
log_error(logger, MODULE_CONFIG_MONITOR,
"[%s:%d] file %s config num not matched",
__FUNCTION__, __LINE__, index->cfg_path);
return -1;
}
@@ -162,15 +166,18 @@ int cm_read_table_file(struct cm_table_info_t *index,
for (int i = 0; i < cfg_num; i++) {
line[sizeof(line) - 1] = '\0';
char *ret_str = read_nxt_line_from_buff(file_buff, file_sz, &file_offset, line, sizeof(line));
char *ret_str = read_nxt_line_from_buff(file_buff, file_sz, &file_offset,
line, sizeof(line));
if (ret_str == NULL) {
log_error(logger, MODULE_CONFIG_MONITOR, "[%s:%d] file %s line_num %d less than claimed %d",
log_error(logger, MODULE_CONFIG_MONITOR,
"[%s:%d] file %s line_num %d less than claimed %d",
__FUNCTION__, __LINE__, index->cfg_path, i, cfg_num);
break;
}
if(line[sizeof(line) - 1] != '\0') {
log_error(logger, MODULE_CONFIG_MONITOR, "[%s:%d] line size more than %u at of file %s:%d",
log_error(logger, MODULE_CONFIG_MONITOR,
"[%s:%d] line size more than %u at of file %s:%d",
__FUNCTION__, __LINE__, sizeof(line), index->cfg_path, i);
continue;
}
@@ -222,7 +229,8 @@ int my_scandir(const char *dir, struct dirent ***namelist,
n++;
if (n >= DIR_ENT_SIZE) {
DIR_ENT_SIZE += ENLARGE_STEP;
struct dirent **tmp_list = (struct dirent **)realloc((void*)list, DIR_ENT_SIZE * sizeof(struct dirent *));
struct dirent **tmp_list = (struct dirent **)realloc((void*)list,
DIR_ENT_SIZE * sizeof(struct dirent *));
if (tmp_list != NULL) {
list = tmp_list;
} else {
@@ -243,49 +251,57 @@ int my_scandir(const char *dir, struct dirent ***namelist,
return n;
}
int filter_fn(const struct dirent *ent)
static int filter_fn(const struct dirent *ent)
{
return (strncmp(ent->d_name,"full_config_index",strlen("full_config_index")) == 0 ||
strncmp(ent->d_name,"inc_config_index",strlen("inc_config_index")) == 0);
}
int get_new_idx_path(long long current_version, const char *file_dir,
char ***idx_path, size_t *idx_num, struct log_handle *logger)
static int get_new_idx_path(long long current_version, const char *file_dir,
char ***idx_path, size_t *idx_num,
struct log_handle *logger)
{
struct dirent **namelist = NULL;
int update_type = MAAT_UPDATE_TYPE_INVALID;
int n = my_scandir(file_dir, &namelist, filter_fn, (int (*)(const void*, const void*))alphasort);
int n = my_scandir(file_dir, &namelist, filter_fn,
(int (*)(const void*, const void*))alphasort);
if (n < 0) {
log_error(logger, MODULE_CONFIG_MONITOR, "[%s:%d] scan dir error", __FUNCTION__, __LINE__);
log_error(logger, MODULE_CONFIG_MONITOR,
"[%s:%d] scan dir error", __FUNCTION__, __LINE__);
return update_type;
}
long long latest_full_version = 0;
long long latest_inc_version = 0;
int i = 0;
int full_file_idx = 0;
int *inc_file_idx = ALLOC(int, n);
int inc_idx_num = 0;
int i = 0;
long long latest_inc_version = 0;
long long latest_full_version = 0;
for (i = 0; i < n; i++) {
long long config_seq = 0;
char update_str[32] = {0};
if ((strcmp(namelist[i]->d_name, ".") == 0) || (strcmp(namelist[i]->d_name, "..") == 0)) {
if ((strcmp(namelist[i]->d_name, ".") == 0) ||
(strcmp(namelist[i]->d_name, "..") == 0)) {
continue;
}
if (strlen(namelist[i]->d_name) > 42) {
log_error(logger, MODULE_CONFIG_MONITOR,
"[%s:%d] config file %s filename too long, should like full_config_index.000000000001",
__FUNCTION__, __LINE__, namelist[i]->d_name);
"[%s:%d] config file %s filename too long, should like"
" full_config_index.000000000001",
__FUNCTION__, __LINE__, namelist[i]->d_name);
continue;
}
int ret = sscanf(namelist[i]->d_name,"%[a-zA-Z]_config_index.%lld", update_str, &config_seq);
int ret = sscanf(namelist[i]->d_name,"%[a-zA-Z]_config_index.%lld",
update_str, &config_seq);
if (ret != 2) {
log_error(logger, MODULE_CONFIG_MONITOR,
"[%s:%d] config file %s filename error, should like full_config_index.000000000001",
"[%s:%d] config file %s filename error, should like"
" full_config_index.000000000001",
__FUNCTION__, __LINE__, namelist[i]->d_name);
continue;
}
@@ -316,16 +332,20 @@ int get_new_idx_path(long long current_version, const char *file_dir,
*idx_path = (char **)malloc(sizeof(char **));
path_len = strlen(file_dir) + strlen(namelist[full_file_idx]->d_name) + 1 + 1;
(*idx_path)[0] = (char *)malloc(path_len);
snprintf((*idx_path)[0], path_len, "%s/%s", file_dir, namelist[full_file_idx]->d_name);
snprintf((*idx_path)[0], path_len, "%s/%s", file_dir,
namelist[full_file_idx]->d_name);
*idx_num = 1;
update_type = MAAT_UPDATE_TYPE_FULL;
} else if (latest_inc_version > current_version) {
//inc update,it's possible that do inc after full update in this function,but we'll process it at next loop.
/* Inc update, it's possible that do inc after Full update,
but we'll process it at next loop.
*/
*idx_path = (char **)malloc(sizeof(char **) * inc_idx_num);
for (i = 0; i < inc_idx_num; i++) {
path_len = strlen(file_dir) + strlen(namelist[inc_file_idx[i]]->d_name) + 1 + 1;
(*idx_path)[i] = (char *)malloc(path_len);
snprintf((*idx_path)[i], path_len, "%s/%s", file_dir, namelist[inc_file_idx[i]]->d_name);
snprintf((*idx_path)[i], path_len, "%s/%s", file_dir,
namelist[inc_file_idx[i]]->d_name);
}
*idx_num = inc_idx_num;
update_type = MAAT_UPDATE_TYPE_INC;
@@ -345,8 +365,8 @@ int get_new_idx_path(long long current_version, const char *file_dir,
void config_monitor_traverse(long long current_version, const char *idx_dir,
void (*start_fn)(long long, int, void *),
int (*update_fn)(const char *, const char *, void *),
void (*finish_fn)(void *), void *u_param, const char *dec_key,
struct log_handle *logger)
void (*finish_fn)(void *), void *u_param,
const char *dec_key, struct log_handle *logger)
{
size_t i = 0;
long long new_version = 0;
@@ -475,4 +495,4 @@ int load_maat_json_file(struct maat *maat_inst, const char *json_filename,
maat_inst->opts.input_mode = DATA_SOURCE_JSON_FILE;
return 0;
}
}

View File

@@ -270,19 +270,6 @@ void *ex_data_runtime_get_ex_data_by_container(struct ex_data_runtime *ex_data_r
return dup_ex_data;
}
void *ex_data_runtime_get_custom_data(struct ex_data_runtime *ex_data_rt,
const char *key, size_t key_len)
{
struct ex_container *ex_container = NULL;
ex_container = (struct ex_container *)rcu_hash_find(ex_data_rt->htable,
key, key_len);
if (NULL == ex_container) {
return NULL;
}
return ex_container->custom_data;
}
size_t ex_data_runtime_ex_container_count(struct ex_data_runtime *ex_data_rt)
{
return rcu_hash_count(ex_data_rt->htable);

View File

@@ -92,7 +92,7 @@ struct expr_runtime {
long long *scan_bytes;
};
enum expr_type int_to_expr_type(int expr_type)
static enum expr_type int_to_expr_type(int expr_type)
{
enum expr_type type = EXPR_TYPE_INVALID;
@@ -116,7 +116,7 @@ enum expr_type int_to_expr_type(int expr_type)
return type;
}
enum hs_match_mode int_to_match_mode(int match_method)
static enum hs_match_mode int_to_match_mode(int match_method)
{
enum hs_match_mode mode = HS_MATCH_MODE_INVALID;
@@ -140,7 +140,8 @@ enum hs_match_mode int_to_match_mode(int match_method)
return mode;
}
int expr_runtime_get_district_id(struct expr_runtime *expr_rt, const char *district)
static int expr_runtime_get_district_id(struct expr_runtime *expr_rt,
const char *district)
{
long long district_id = DISTRICT_ANY;
@@ -171,8 +172,9 @@ int expr_runtime_set_scan_district(struct expr_runtime *expr_rt, const char *dis
return maat_kv_read_unNull(expr_rt->district_map, district, district_len, district_id);
}
struct expr_item *expr_item_new(struct expr_schema *expr_schema, const char *table_name,
const char *line, struct expr_runtime *expr_rt)
static struct expr_item *
expr_item_new(struct expr_schema *expr_schema, const char *table_name,
const char *line, struct expr_runtime *expr_rt)
{
size_t column_offset = 0;
size_t column_len = 0;
@@ -434,7 +436,7 @@ void expr_schema_free(void *expr_schema)
FREE(expr_schema);
}
void expr_rule_reset(struct expr_rule *rule)
static void expr_rule_reset(struct expr_rule *rule)
{
if (NULL == rule) {
return;
@@ -445,7 +447,7 @@ void expr_rule_reset(struct expr_rule *rule)
}
}
void expr_item_free(struct expr_item *item)
static void expr_item_free(struct expr_item *item)
{
if (NULL == item) {
return;
@@ -460,7 +462,7 @@ void expr_item_free(struct expr_item *item)
FREE(item);
}
void expr_item_free_cb(void *user_ctx, void *data)
static void expr_item_free_cb(void *user_ctx, void *data)
{
struct expr_item *item = (struct expr_item *)data;
expr_item_free(item);
@@ -543,8 +545,9 @@ void expr_runtime_free(void *expr_runtime)
FREE(expr_rt);
}
int expr_runtime_update_row(struct expr_runtime *expr_rt, char *key, size_t key_len,
struct expr_item *item, int is_valid)
static int expr_runtime_update_row(struct expr_runtime *expr_rt, char *key,
size_t key_len, struct expr_item *item,
int is_valid)
{
int ret = -1;
@@ -565,9 +568,9 @@ int expr_runtime_update_row(struct expr_runtime *expr_rt, char *key, size_t key_
return 0;
}
enum hs_pattern_type expr_type2pattern_type(enum expr_type expr_type)
static enum hs_pattern_type expr_type2pattern_type(enum expr_type expr_type)
{
enum hs_pattern_type pattern_type = HS_PATTERN_TYPE_MAX;
enum hs_pattern_type pattern_type;
switch (expr_type) {
case EXPR_TYPE_STRING:
@@ -613,8 +616,9 @@ static size_t hex2bin(char *hex, int hex_len, char *binary, size_t size)
}
#define MAAT_MAX_EXPR_ITEM_NUM 8
int expr_item_to_expr_rule(struct expr_item *expr_item, struct expr_rule *expr_rule,
struct log_handle *logger)
static int expr_item_to_expr_rule(struct expr_item *expr_item,
struct expr_rule *expr_rule,
struct log_handle *logger)
{
size_t i = 0;
size_t sub_expr_cnt = 0;
@@ -817,7 +821,7 @@ int expr_runtime_update(void *expr_runtime, void *expr_schema,
return 0;
}
void garbage_adapter_hs_free(void *adapter_hs, void *arg)
static void garbage_adapter_hs_free(void *adapter_hs, void *arg)
{
struct adapter_hs *hs = (struct adapter_hs *)adapter_hs;
adapter_hs_free(hs);

View File

@@ -157,7 +157,7 @@ void flag_schema_free(void *flag_schema)
FREE(flag_schema);
}
void flag_item_free(struct flag_item *item)
static void flag_item_free(struct flag_item *item)
{
if (NULL == item) {
return;
@@ -171,7 +171,7 @@ void flag_item_free(struct flag_item *item)
FREE(item);
}
void flag_item_free_cb(void *user_ctx, void *data)
static void flag_item_free_cb(void *user_ctx, void *data)
{
struct flag_item *item = (struct flag_item *)data;
@@ -243,8 +243,9 @@ void flag_runtime_free(void *flag_runtime)
FREE(flag_rt);
}
int flag_runtime_update_row(struct flag_runtime *flag_rt, char *key, size_t key_len,
struct flag_item *item, int is_valid)
static int flag_runtime_update_row(struct flag_runtime *flag_rt, char *key,
size_t key_len, struct flag_item *item,
int is_valid)
{
int ret = -1;
@@ -265,7 +266,8 @@ int flag_runtime_update_row(struct flag_runtime *flag_rt, char *key, size_t key_
return 0;
}
int flag_runtime_get_district_id(struct flag_runtime *flag_rt, const char *district)
static int flag_runtime_get_district_id(struct flag_runtime *flag_rt,
const char *district)
{
long long district_id = DISTRICT_ANY;
@@ -296,8 +298,9 @@ int flag_runtime_set_scan_district(struct flag_runtime *flag_rt, const char *dis
return maat_kv_read_unNull(flag_rt->district_map, district, district_len, district_id);
}
struct flag_item *flag_item_new(struct flag_schema *schema, const char *table_name,
const char *line, struct flag_runtime *flag_rt)
static struct flag_item *
flag_item_new(struct flag_schema *schema, const char *table_name,
const char *line, struct flag_runtime *flag_rt)
{
size_t column_offset = 0;
size_t column_len = 0;
@@ -374,7 +377,7 @@ error:
return NULL;
}
struct flag_rule flag_item_to_flag_rule(struct flag_item *item)
static struct flag_rule flag_item_to_flag_rule(struct flag_item *item)
{
struct flag_rule rule;
@@ -386,8 +389,9 @@ struct flag_rule flag_item_to_flag_rule(struct flag_item *item)
return rule;
}
int flag_runtime_update(void *flag_runtime, void *flag_schema, const char *table_name,
const char *line, int valid_column)
int flag_runtime_update(void *flag_runtime, void *flag_schema,
const char *table_name, const char *line,
int valid_column)
{
if (NULL == flag_runtime || NULL == flag_schema ||
NULL == line) {
@@ -444,7 +448,7 @@ int flag_runtime_update(void *flag_runtime, void *flag_schema, const char *table
return 0;
}
void garbage_flag_matcher_free(void *flag_matcher, void *arg)
static void garbage_flag_matcher_free(void *flag_matcher, void *arg)
{
struct flag_matcher *matcher = (struct flag_matcher *)flag_matcher;
flag_matcher_free(matcher);

View File

@@ -235,8 +235,9 @@ void fqdn_plugin_runtime_free(void *fqdn_plugin_runtime)
FREE(fqdn_plugin_rt);
}
int fqdn_plugin_accept_tag_match(struct fqdn_plugin_schema *schema, const char *table_name,
const char *line, struct log_handle *logger)
static int fqdn_plugin_accept_tag_match(struct fqdn_plugin_schema *schema,
const char *table_name, const char *line,
struct log_handle *logger)
{
size_t column_offset = 0;
size_t column_len = 0;
@@ -276,7 +277,7 @@ int fqdn_plugin_accept_tag_match(struct fqdn_plugin_schema *schema, const char *
return TAG_MATCH_MATCHED;
}
struct FQDN_rule *
static struct FQDN_rule *
fqdn_plugin_rule_new(const char *line, struct fqdn_plugin_schema *schema,
const char *table_name, struct log_handle *logger)
{
@@ -339,7 +340,7 @@ error:
return NULL;
}
void fqdn_plugin_rule_free(struct FQDN_rule *rule)
static void fqdn_plugin_rule_free(struct FQDN_rule *rule)
{
if (NULL == rule) {
return;
@@ -352,11 +353,11 @@ void fqdn_plugin_rule_free(struct FQDN_rule *rule)
FREE(rule);
}
int fqdn_plugin_runtime_update_row(struct fqdn_plugin_runtime *fqdn_plugin_rt,
const char *table_name, const char *row,
const char *key, size_t key_len,
struct FQDN_rule *fqdn_plugin_rule,
int is_valid)
static int fqdn_plugin_runtime_update_row(struct fqdn_plugin_runtime *fqdn_plugin_rt,
const char *table_name, const char *row,
const char *key, size_t key_len,
struct FQDN_rule *fqdn_plugin_rule,
int is_valid)
{
int ret = -1;
struct ex_data_runtime *ex_data_rt = fqdn_plugin_rt->ex_data_rt;
@@ -445,7 +446,7 @@ int fqdn_plugin_runtime_update(void *fqdn_plugin_runtime, void *fqdn_plugin_sche
return 0;
}
void garbage_fqdn_engine_free(void *fqdn_engine, void *arg)
static void garbage_fqdn_engine_free(void *fqdn_engine, void *arg)
{
struct FQDN_engine *engine = (struct FQDN_engine *)fqdn_engine;
FQDN_engine_free(engine);
@@ -570,23 +571,6 @@ int fqdn_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, const char *query
return n_result;
}
void fqdn_plugin_runtime_perf_stat(void *fqdn_plugin_runtime, struct timespec *start,
struct timespec *end, int thread_id)
{
if (NULL == fqdn_plugin_runtime || thread_id < 0) {
return;
}
struct fqdn_plugin_runtime *fqdn_plugin_rt = (struct fqdn_plugin_runtime *)fqdn_plugin_runtime;
alignment_int64_array_add(fqdn_plugin_rt->scan_cnt, thread_id, 1);
if (start != NULL && end != NULL) {
long long consume_time = (end->tv_sec - start->tv_sec) * 1000000000 +
(end->tv_nsec - start->tv_nsec);
alignment_int64_array_add(fqdn_plugin_rt->scan_cpu_time, thread_id, consume_time);
}
}
long long fqdn_plugin_runtime_scan_count(void *fqdn_plugin_runtime)
{
if (NULL == fqdn_plugin_runtime) {

View File

@@ -124,4 +124,4 @@ void maat_garbage_collect_by_force(struct maat_garbage_bin *bin)
FREE(p);
bin->bag_cnt--;
}
}
}

View File

@@ -52,8 +52,8 @@ struct maat_group {
};
struct maat_group_topology {
struct maat_group *hash_by_group_id; //key: group_id, value: struct maat_group *.
struct maat_group *hash_by_vertex_id; //key: vetex_id, value: struct maat_group *. Multimap (Items with multiple keys).
struct maat_group *hash_by_group_id; //key: group_id, value: struct maat_group *.
struct maat_group *hash_by_vertex_id; //key: vetex_id, value: struct maat_group *.
igraph_t group_graph;
igraph_integer_t grp_vertex_id_generator;
struct log_handle *logger;
@@ -152,7 +152,7 @@ void group2group_schema_free(void *g2g_schema)
FREE(g2g_schema);
}
void group_vertex_free(struct maat_group *group)
static void group_vertex_free(struct maat_group *group)
{
if (NULL == group) {
return;
@@ -181,7 +181,8 @@ void group_vertex_free(struct maat_group *group)
FREE(group);
}
struct maat_group_topology *maat_group_topology_new(struct log_handle *logger)
static struct maat_group_topology *
maat_group_topology_new(struct log_handle *logger)
{
struct maat_group_topology *group_topo = ALLOC(struct maat_group_topology, 1);
UNUSED int ret = 0;
@@ -197,7 +198,7 @@ struct maat_group_topology *maat_group_topology_new(struct log_handle *logger)
return group_topo;
}
void maat_group_topology_free(struct maat_group_topology *group_topo)
static void maat_group_topology_free(struct maat_group_topology *group_topo)
{
if (NULL == group_topo) {
return;
@@ -216,7 +217,7 @@ void maat_group_topology_free(struct maat_group_topology *group_topo)
FREE(group_topo);
}
struct maat_group *maat_group_clone(struct maat_group *group)
static struct maat_group *maat_group_clone(struct maat_group *group)
{
struct maat_group *group_copy = ALLOC(struct maat_group, 1);
@@ -253,7 +254,8 @@ struct maat_group *maat_group_clone(struct maat_group *group)
return group_copy;
}
struct maat_group_topology *maat_group_topology_clone(struct maat_group_topology *group_topo)
static struct maat_group_topology *
maat_group_topology_clone(struct maat_group_topology *group_topo)
{
if (NULL == group_topo) {
return NULL;
@@ -316,7 +318,7 @@ void group2group_runtime_free(void *g2g_runtime)
FREE(g2g_rt);
}
struct group2group_item *
static struct group2group_item *
group2group_item_new(const char *line, struct group2group_schema *g2g_schema,
const char *table_name, struct log_handle *logger)
{
@@ -360,12 +362,12 @@ error:
return NULL;
}
void group2group_item_free(struct group2group_item *g2g_item)
static void group2group_item_free(struct group2group_item *g2g_item)
{
FREE(g2g_item);
}
size_t print_igraph_vector(igraph_vector_t *v, char *buff, size_t sz) {
static size_t print_igraph_vector(igraph_vector_t *v, char *buff, size_t sz) {
long int i;
int printed = 0;
@@ -377,8 +379,8 @@ size_t print_igraph_vector(igraph_vector_t *v, char *buff, size_t sz) {
return printed;
}
struct maat_group *group_topology_add_group(struct maat_group_topology *group_topo,
long long group_id)
static struct maat_group *
group_topology_add_group(struct maat_group_topology *group_topo, long long group_id)
{
assert(group_topo != NULL);
@@ -401,8 +403,8 @@ struct maat_group *group_topology_add_group(struct maat_group_topology *group_to
return group;
}
void group_topology_del_group(struct maat_group_topology *group_topo,
struct maat_group *group)
static void group_topology_del_group(struct maat_group_topology *group_topo,
struct maat_group *group)
{
if (NULL == group_topo || NULL == group) {
return;
@@ -431,8 +433,8 @@ void group_topology_del_group(struct maat_group_topology *group_topo,
group_vertex_free(group);
}
struct maat_group *group_topology_find_group(struct maat_group_topology *group_topo,
long long group_id)
static struct maat_group *
group_topology_find_group(struct maat_group_topology *group_topo, long long group_id)
{
if (NULL == group_topo || group_id < 0) {
return NULL;
@@ -444,8 +446,9 @@ struct maat_group *group_topology_find_group(struct maat_group_topology *group_t
return group;
}
void maat_group_reference_super_group(struct maat_group *group, long long super_group_id,
int is_exclude)
static void maat_group_reference_super_group(struct maat_group *group,
long long super_group_id,
int is_exclude)
{
if (NULL == group || super_group_id < 0) {
return;
@@ -468,8 +471,9 @@ void maat_group_reference_super_group(struct maat_group *group, long long super_
}
}
void maat_group_reference_sub_group(struct maat_group *group, long long sub_group_id,
int is_exclude)
static void maat_group_reference_sub_group(struct maat_group *group,
long long sub_group_id,
int is_exclude)
{
if (NULL == group || sub_group_id < 0) {
return;
@@ -492,8 +496,9 @@ void maat_group_reference_sub_group(struct maat_group *group, long long sub_grou
}
}
void maat_group_dereference_super_group(struct maat_group *group, long long super_group_id,
int is_exclude)
static void maat_group_dereference_super_group(struct maat_group *group,
long long super_group_id,
int is_exclude)
{
if (NULL == group || super_group_id < 0) {
return;
@@ -503,14 +508,16 @@ void maat_group_dereference_super_group(struct maat_group *group, long long supe
long long *tmp_id = NULL;
if (0 == is_exclude) {
//include superior group
tmp_id = utarray_find(group->incl_super_group_ids, &super_group_id, compare_group_id);
tmp_id = utarray_find(group->incl_super_group_ids, &super_group_id,
compare_group_id);
if (tmp_id != NULL) {
remove_idx = utarray_eltidx(group->incl_super_group_ids, tmp_id);
utarray_erase(group->incl_super_group_ids, remove_idx, 1);
}
} else {
//exclude superior group
tmp_id = utarray_find(group->excl_super_group_ids, &super_group_id, compare_group_id);
tmp_id = utarray_find(group->excl_super_group_ids, &super_group_id,
compare_group_id);
if (tmp_id != NULL) {
remove_idx = utarray_eltidx(group->excl_super_group_ids, tmp_id);
utarray_erase(group->excl_super_group_ids, remove_idx, 1);
@@ -518,8 +525,9 @@ void maat_group_dereference_super_group(struct maat_group *group, long long supe
}
}
void maat_group_dereference_sub_group(struct maat_group *group, long long sub_group_id,
int is_exclude)
static void maat_group_dereference_sub_group(struct maat_group *group,
long long sub_group_id,
int is_exclude)
{
if (NULL == group || sub_group_id < 0) {
return;
@@ -529,14 +537,16 @@ void maat_group_dereference_sub_group(struct maat_group *group, long long sub_gr
long long *tmp_id = NULL;
if (0 == is_exclude) {
//include superior group
tmp_id = utarray_find(group->incl_sub_group_ids, &sub_group_id, compare_group_id);
tmp_id = utarray_find(group->incl_sub_group_ids, &sub_group_id,
compare_group_id);
if (tmp_id != NULL) {
remove_idx = utarray_eltidx(group->incl_sub_group_ids, tmp_id);
utarray_erase(group->incl_sub_group_ids, remove_idx, 1);
}
} else {
//exclude superior group
tmp_id = utarray_find(group->excl_sub_group_ids, &sub_group_id, compare_group_id);
tmp_id = utarray_find(group->excl_sub_group_ids, &sub_group_id,
compare_group_id);
if (tmp_id != NULL) {
remove_idx = utarray_eltidx(group->excl_sub_group_ids, tmp_id);
utarray_erase(group->excl_sub_group_ids, remove_idx, 1);
@@ -544,9 +554,9 @@ void maat_group_dereference_sub_group(struct maat_group *group, long long sub_gr
}
}
int group_topology_add_group_to_group(struct maat_group_topology *group_topo,
long long group_id, long long super_group_id,
int is_exclude)
static int group_topology_add_group_to_group(struct maat_group_topology *group_topo,
long long group_id, long long super_group_id,
int is_exclude)
{
if (NULL == group_topo) {
return -1;
@@ -586,9 +596,9 @@ int group_topology_add_group_to_group(struct maat_group_topology *group_topo,
return ret;
}
int group_topology_del_group_from_group(struct maat_group_topology *group_topo,
long long group_id, long long super_group_id,
int is_exclude)
static int group_topology_del_group_from_group(struct maat_group_topology *group_topo,
long long group_id, long long super_group_id,
int is_exclude)
{
if (NULL == group_topo) {
return -1;
@@ -644,7 +654,7 @@ int group_topology_del_group_from_group(struct maat_group_topology *group_topo,
return 0;
}
int group_topology_build_super_groups(struct maat_group_topology *group_topo)
static int group_topology_build_super_groups(struct maat_group_topology *group_topo)
{
if (NULL == group_topo) {
return -1;
@@ -653,8 +663,8 @@ int group_topology_build_super_groups(struct maat_group_topology *group_topo)
igraph_bool_t is_dag;
igraph_is_dag(&(group_topo->group_graph), &is_dag);
if (!is_dag) {
log_error(group_topo->logger, MODULE_GROUP, "[%s:%d] Sub group cycle detected!",
__FUNCTION__, __LINE__);
log_error(group_topo->logger, MODULE_GROUP,
"[%s:%d] Sub group cycle detected!", __FUNCTION__, __LINE__);
return -1;
}
@@ -740,7 +750,7 @@ int group2group_runtime_update(void *g2g_runtime, void *g2g_schema,
return ret;
}
void garbage_maat_group_topology_free(void *data, void *arg)
static void garbage_maat_group_topology_free(void *data, void *arg)
{
struct maat_group_topology *group_topo = (struct maat_group_topology *)data;
maat_group_topology_free(group_topo);
@@ -782,9 +792,9 @@ int group2group_runtime_commit(void *g2g_runtime, const char *table_name,
}
#define MAX_RECURSION_DEPTH 5
void get_candidate_super_group_ids(struct maat_group_topology *group_topo,
UT_array *hit_group_ids,
UT_array *super_group_ids)
static void get_candidate_super_group_ids(struct maat_group_topology *group_topo,
UT_array *hit_group_ids,
UT_array *super_group_ids)
{
long long *p = NULL;
@@ -810,8 +820,10 @@ void get_candidate_super_group_ids(struct maat_group_topology *group_topo,
}
}
void verify_group_by_sub_include_groups(struct maat_group *group, UT_array *candidate_group_ids,
UT_array *kept_super_group_ids, UT_array *all_hit_group_ids)
static void verify_group_by_sub_include_groups(struct maat_group *group,
UT_array *candidate_group_ids,
UT_array *kept_super_group_ids,
UT_array *all_hit_group_ids)
{
size_t remove_idx = 0;
long long *tmp_id = NULL;
@@ -844,8 +856,10 @@ void verify_group_by_sub_include_groups(struct maat_group *group, UT_array *cand
}
}
void verify_group_by_sub_exclude_groups(struct maat_group *group, UT_array *candidate_group_ids,
UT_array *kept_super_group_ids, UT_array *all_hit_group_ids)
static void verify_group_by_sub_exclude_groups(struct maat_group *group,
UT_array *candidate_group_ids,
UT_array *kept_super_group_ids,
UT_array *all_hit_group_ids)
{
if (0 == utarray_len(group->excl_sub_group_ids)) {
return;
@@ -878,10 +892,10 @@ void verify_group_by_sub_exclude_groups(struct maat_group *group, UT_array *cand
}
}
void verify_candidate_super_group_ids(struct maat_group_topology *group_topo,
UT_array *candidate_super_group_ids,
UT_array *all_hit_group_ids,
UT_array *kept_super_group_ids)
static void verify_candidate_super_group_ids(struct maat_group_topology *group_topo,
UT_array *candidate_super_group_ids,
UT_array *all_hit_group_ids,
UT_array *kept_super_group_ids)
{
long long *p = NULL;
UT_array *candidate_group_ids;
@@ -962,15 +976,17 @@ void verify_candidate_super_group_ids(struct maat_group_topology *group_topo,
utarray_free(candidate_group_ids);
}
void get_super_group_ids(struct maat_group_topology *group_topo, UT_array *hit_group_ids,
UT_array *all_hit_group_ids, size_t depth)
static void get_super_group_ids(struct maat_group_topology *group_topo,
UT_array *hit_group_ids, UT_array *all_hit_group_ids,
size_t depth)
{
UT_array *candidate_super_group_ids;
UT_array *kept_super_group_ids;
if (depth >= MAX_RECURSION_DEPTH) {
log_error(group_topo->logger, MODULE_GROUP,
"[%s:%d]exceed max recursion depth(5)", __FUNCTION__, __LINE__);
"[%s:%d]exceed max recursion depth(5)",
__FUNCTION__, __LINE__);
for (int i = 0; i < utarray_len(hit_group_ids); i++) {
long long *p = (long long *)utarray_eltptr(hit_group_ids, i);
log_error(group_topo->logger, MODULE_GROUP,
@@ -1033,10 +1049,10 @@ next:
utarray_free(kept_super_group_ids);
}
size_t group_topology_get_super_groups(struct maat_group_topology *group_topo,
long long *group_ids, size_t n_group_ids,
long long *super_group_ids,
size_t super_group_ids_size)
static size_t group_topology_get_super_groups(struct maat_group_topology *group_topo,
long long *group_ids, size_t n_group_ids,
long long *super_group_ids,
size_t super_group_ids_size)
{
size_t i = 0, idx = 0;
UT_array *all_hit_group_ids;

View File

@@ -154,7 +154,7 @@ void interval_schema_free(void *interval_schema)
FREE(interval_schema);
}
void interval_item_free(struct interval_item *item)
static void interval_item_free(struct interval_item *item)
{
if (NULL == item) {
return;
@@ -168,7 +168,7 @@ void interval_item_free(struct interval_item *item)
FREE(item);
}
void interval_item_free_cb(void *user_ctx, void *data)
static void interval_item_free_cb(void *user_ctx, void *data)
{
struct interval_item *item = (struct interval_item *)data;
interval_item_free(item);
@@ -239,8 +239,8 @@ void interval_runtime_free(void *interval_runtime)
FREE(interval_rt);
}
int interval_runtime_get_district_id(struct interval_runtime *interval_rt,
const char *district)
static int interval_runtime_get_district_id(struct interval_runtime *interval_rt,
const char *district)
{
long long district_id = DISTRICT_ANY;
@@ -273,7 +273,7 @@ int interval_runtime_set_scan_district(struct interval_runtime *interval_rt,
district_len, district_id);
}
struct interval_item *
static struct interval_item *
interval_item_new(struct interval_schema *schema, const char *table_name,
const char *line, struct interval_runtime *interval_rt)
{
@@ -351,7 +351,8 @@ error:
return NULL;
}
struct interval_rule interval_item_to_interval_rule(struct interval_item *item)
static struct interval_rule
interval_item_to_interval_rule(struct interval_item *item)
{
struct interval_rule rule;
@@ -363,9 +364,9 @@ struct interval_rule interval_item_to_interval_rule(struct interval_item *item)
return rule;
}
int interval_runtime_update_row(struct interval_runtime *interval_rt, char *key,
size_t key_len, struct interval_item *item,
int is_valid)
static int interval_runtime_update_row(struct interval_runtime *interval_rt,
char *key, size_t key_len,
struct interval_item *item, int is_valid)
{
int ret = -1;
@@ -661,4 +662,4 @@ long long interval_runtime_update_err_cnt(void *interval_runtime)
struct interval_runtime *interval_rt = (struct interval_runtime *)interval_runtime;
return interval_rt->update_err_cnt;
}
}

View File

@@ -217,8 +217,9 @@ void ip_schema_free(void *ip_schema)
FREE(ip_schema);
}
struct ip_item *ip_item_new(struct ip_schema *ip_schema, const char *table_name,
const char *line, struct log_handle *logger)
static struct ip_item *
ip_item_new(struct ip_schema *ip_schema, const char *table_name,
const char *line, struct log_handle *logger)
{
size_t column_offset = 0;
size_t column_len = 0;
@@ -378,7 +379,7 @@ error:
return NULL;
}
void ip_item_free(struct ip_item *item)
static void ip_item_free(struct ip_item *item)
{
if (NULL == item) {
return;
@@ -387,7 +388,7 @@ void ip_item_free(struct ip_item *item)
FREE(item);
}
void ip_item_free_cb(void *user_ctx, void *data)
static void ip_item_free_cb(void *user_ctx, void *data)
{
struct ip_item *item = (struct ip_item *)data;
ip_item_free(item);
@@ -455,7 +456,7 @@ void ip_runtime_free(void *ip_runtime)
FREE(ip_rt);
}
void ip_item_to_ip_rule(struct ip_item *item, struct ip_rule *rule)
static void ip_item_to_ip_rule(struct ip_item *item, struct ip_rule *rule)
{
if (IPv4 == item->addr_type) {
rule->type = IPv4;
@@ -471,15 +472,15 @@ void ip_item_to_ip_rule(struct ip_item *item, struct ip_rule *rule)
rule->rule_id = item->item_id;
}
void ip_item_to_port_rule(struct ip_item *item, struct interval_rule *rule)
static void ip_item_to_port_rule(struct ip_item *item, struct interval_rule *rule)
{
rule->start = item->min_port;
rule->end = item->max_port;
rule->result.rule_id = item->item_id;
}
int ip_runtime_update_row(struct ip_runtime *ip_rt, char *key, size_t key_len,
struct ip_item *item, int is_valid)
static int ip_runtime_update_row(struct ip_runtime *ip_rt, char *key, size_t key_len,
struct ip_item *item, int is_valid)
{
int ret = -1;
@@ -680,7 +681,7 @@ long long ip_runtime_ipv6_rule_count(void *ip_runtime)
return ip_rt->ipv6_rule_num;
}
int validate_port(struct ip_item *item, uint16_t port, int proto)
static int validate_port(struct ip_item *item, uint16_t port, int proto)
{
uint16_t host_port = ntohs(port);
@@ -695,7 +696,7 @@ int validate_port(struct ip_item *item, uint16_t port, int proto)
return 0;
}
int validate_proto(struct ip_item *item, int proto)
static int validate_proto(struct ip_item *item, int proto)
{
if (item->proto != -1 && item->proto != proto) {
return -1;

View File

@@ -154,8 +154,9 @@ void ip_plugin_schema_free(void *ip_plugin_schema)
FREE(ip_plugin_schema);
}
int ip_plugin_accept_tag_match(struct ip_plugin_schema *schema, const char *table_name,
const char *line, struct log_handle *logger)
static int ip_plugin_accept_tag_match(struct ip_plugin_schema *schema,
const char *table_name, const char *line,
struct log_handle *logger)
{
size_t column_offset = 0;
size_t column_len = 0;
@@ -195,7 +196,7 @@ int ip_plugin_accept_tag_match(struct ip_plugin_schema *schema, const char *tabl
return TAG_MATCH_MATCHED;
}
struct ip_rule *
static struct ip_rule *
ip_plugin_rule_new(struct ip_plugin_schema *schema, const char *table_name,
const char *line, struct log_handle *logger)
{
@@ -305,7 +306,7 @@ error:
return NULL;
}
void ip_plugin_rule_free(struct ip_rule *rule)
static void ip_plugin_rule_free(struct ip_rule *rule)
{
FREE(rule);
}
@@ -345,10 +346,10 @@ struct ex_container_schema *ip_plugin_table_get_ex_container_schema(void *ip_plu
return &(schema->container_schema);
}
int ip_plugin_runtime_update_row(struct ip_plugin_runtime *ip_plugin_rt,
const char *table_name, const char *row,
const char *key, size_t key_len,
struct ip_rule *ip_plugin_rule, int is_valid)
static int ip_plugin_runtime_update_row(struct ip_plugin_runtime *ip_plugin_rt,
const char *table_name, const char *row,
const char *key, size_t key_len,
struct ip_rule *ip_plugin_rule, int is_valid)
{
int ret = -1;
struct ex_data_runtime *ex_data_rt = ip_plugin_rt->ex_data_rt;
@@ -613,23 +614,6 @@ int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, const struct ip_addr
return n_result;
}
void ip_plugin_runtime_perf_stat(void *ip_plugin_runtime, struct timespec *start,
struct timespec *end, int thread_id)
{
if (NULL == ip_plugin_runtime || thread_id < 0) {
return;
}
struct ip_plugin_runtime *ip_plugin_rt = (struct ip_plugin_runtime *)ip_plugin_runtime;
alignment_int64_array_add(ip_plugin_rt->scan_cnt, thread_id, 1);
if (start != NULL && end != NULL) {
long long consume_time = (end->tv_sec - start->tv_sec) * 1000000000 +
(end->tv_nsec - start->tv_nsec);
alignment_int64_array_add(ip_plugin_rt->scan_cpu_time, thread_id, consume_time);
}
}
long long ip_plugin_runtime_scan_count(void *ip_plugin_runtime)
{
if (NULL == ip_plugin_runtime) {

View File

@@ -28,14 +28,15 @@ struct maat_kv_store
struct maat_kv_pair* hash;
};
void strlowercase(const char* src, size_t src_len, char* dst, size_t dst_sz)
static void strlowercase(const char* src, size_t src_len, char* dst, size_t dst_sz)
{
for (size_t i = 0; i < src_len && i < dst_sz; i++) {
dst[i] = tolower(src[i]);
}
}
struct maat_kv_pair* maat_kv_pair_new(const char* key, size_t keylen, long long value)
static struct maat_kv_pair *
maat_kv_pair_new(const char* key, size_t keylen, long long value)
{
struct maat_kv_pair *kv = ALLOC(struct maat_kv_pair, 1);
@@ -48,7 +49,7 @@ struct maat_kv_pair* maat_kv_pair_new(const char* key, size_t keylen, long long
return kv;
}
void maat_kv_pair_free(struct maat_kv_pair *kv)
static void maat_kv_pair_free(struct maat_kv_pair *kv)
{
if (NULL == kv) {
return;
@@ -84,8 +85,8 @@ void maat_kv_store_free(struct maat_kv_store *store)
FREE(store);
}
int maat_kv_register_unNull(struct maat_kv_store *store, const char *key,
size_t keylen, long long value)
static int maat_kv_register_unNull(struct maat_kv_store *store, const char *key,
size_t keylen, long long value)
{
if (keylen > MAAT_KV_MAX_KEY_LEN) {
return -1;

View File

@@ -334,10 +334,10 @@ void plugin_runtime_free(void *plugin_runtime)
FREE(plugin_rt);
}
int plugin_runtime_update_row(struct plugin_runtime *plugin_rt,
struct plugin_schema *plugin_schema,
const char *table_name, const char *row,
const char *key, size_t key_len, int is_valid)
static int plugin_runtime_update_row(struct plugin_runtime *plugin_rt,
struct plugin_schema *plugin_schema,
const char *table_name, const char *row,
const char *key, size_t key_len, int is_valid)
{
int ret = -1;
struct ex_container_schema *container_schema = &(plugin_schema->container_schema);
@@ -380,8 +380,9 @@ int plugin_runtime_update_row(struct plugin_runtime *plugin_rt,
return 0;
}
int plugin_accept_tag_match(struct plugin_schema *schema, const char *table_name,
const char *line, struct log_handle *logger)
static int plugin_accept_tag_match(struct plugin_schema *schema,
const char *table_name, const char *line,
struct log_handle *logger)
{
size_t column_offset = 0;
size_t column_len = 0;
@@ -422,9 +423,10 @@ int plugin_accept_tag_match(struct plugin_schema *schema, const char *table_name
return TAG_MATCH_MATCHED;
}
int plugin_table_line_get_key(struct plugin_schema *schema, const char *table_name,
const char *line, char *dst_key, size_t *dst_key_len,
struct log_handle *logger)
static int plugin_table_line_get_key(struct plugin_schema *schema,
const char *table_name, const char *line,
char *dst_key, size_t *dst_key_len,
struct log_handle *logger)
{
size_t key_offset = 0, key_len = 0;

View File

@@ -50,8 +50,8 @@ struct expected_reply {
redisReply possible_replies[POSSIBLE_REDIS_REPLY_SIZE];
};
char *get_foreign_cont_filename(const char *table_name, long long rule_id,
const char *foreign_key, const char *dir)
static char *get_foreign_cont_filename(const char *table_name, long long rule_id,
const char *foreign_key, const char *dir)
{
char buffer[512] = {0};
@@ -63,8 +63,44 @@ char *get_foreign_cont_filename(const char *table_name, long long rule_id,
return filename;
}
void _get_foregin_keys(struct serial_rule *p_rule, int *foreign_columns,
int n_foreign, const char *dir, struct log_handle *logger)
static const char *maat_cmd_find_Nth_column(const char *line, int Nth, int *column_len)
{
size_t i = 0;
int j = 0;
size_t start=0, end=0;
size_t line_len = strlen(line);
for (i = 0; i < line_len; i++) {
if (line[i] != ' ' && line[i] != '\t') {
continue;
}
j++;
if (j == Nth - 1) {
start = i + 1;
}
if(j == Nth) {
end = i;
break;
}
}
if (start == end) {
return NULL;
}
if (end == 0) {
end = i;
}
*column_len = end - start;
return line + start;
}
static void _get_foregin_keys(struct serial_rule *p_rule, int *foreign_columns,
int n_foreign, const char *dir, struct log_handle *logger)
{
int foreign_key_size = 0;
p_rule->f_keys = ALLOC(struct foreign_key, n_foreign);
@@ -117,8 +153,8 @@ void _get_foregin_keys(struct serial_rule *p_rule, int *foreign_columns,
}
}
int get_foreign_keys_define(redisContext *ctx, struct serial_rule *rule_list,
int rule_num, struct maat *maat_inst, const char *dir)
static int get_foreign_keys_define(redisContext *ctx, struct serial_rule *rule_list,
int rule_num, struct maat *maat_inst, const char *dir)
{
int rule_with_foreign_key = 0;
@@ -181,14 +217,13 @@ int maat_cmd_get_foreign_keys_by_prefix(redisContext *ctx, struct serial_rule *r
return rule_with_foreign_key;
}
struct foreign_conts_track
{
struct foreign_conts_track {
int rule_idx;
int foreign_idx;
};
int _get_maat_redis_value(redisContext *c, struct serial_rule *rule_list, int rule_num,
struct log_handle *logger)
static int _get_maat_redis_value(redisContext *c, struct serial_rule *rule_list,
int rule_num, struct log_handle *logger)
{
int i = 0;
int failed_cnt = 0;
@@ -317,9 +352,9 @@ int maat_cmd_get_redis_value(redisContext *c, struct serial_rule *rule_list,
return 0;
}
int get_inc_key_list(long long instance_version, long long target_version,
redisContext *c, struct serial_rule **list,
struct log_handle *logger)
static int get_inc_key_list(long long instance_version, long long target_version,
redisContext *c, struct serial_rule **list,
struct log_handle *logger)
{
//Returns all the elements in the sorted set at key with a score that instance_version < score <= redis_version.
//The elements are considered to be ordered from low to high scores(instance_version).
@@ -409,7 +444,7 @@ int get_inc_key_list(long long instance_version, long long target_version,
return rule_num;
}
void serial_rule_free(struct serial_rule *s_rule)
static void serial_rule_free(struct serial_rule *s_rule)
{
if (NULL == s_rule) {
return;
@@ -438,7 +473,7 @@ void serial_rule_free(struct serial_rule *s_rule)
FREE(s_rule);
}
struct serial_rule *serial_rule_clone(const struct serial_rule *s_rule)
static struct serial_rule *serial_rule_clone(const struct serial_rule *s_rule)
{
struct serial_rule *new_rule = ALLOC(struct serial_rule, 1);
@@ -462,9 +497,9 @@ struct serial_rule *serial_rule_clone(const struct serial_rule *s_rule)
return new_rule;
}
int recovery_history_version(const struct serial_rule *current, int current_num,
const struct serial_rule *changed, int changed_num,
struct serial_rule **history_result)
static int recovery_history_version(const struct serial_rule *current, int current_num,
const struct serial_rule *changed, int changed_num,
struct serial_rule **history_result)
{
int i = 0;
int ret = 0;
@@ -739,15 +774,16 @@ FULL_UPDATE:
return rule_num ;
}
void _get_foreign_conts(redisContext *c, struct serial_rule *rule_list,
int rule_num, int print_fn, struct log_handle *logger)
static void _get_foreign_conts(redisContext *c, struct serial_rule *rule_list,
int rule_num, int print_fn, struct log_handle *logger)
{
int i = 0;
int j = 0;
UNUSED int ret = 0;
int key_num = 0;
struct serial_rule *s_rule = NULL;
struct foreign_conts_track *track = ALLOC(struct foreign_conts_track, rule_num * MAX_FOREIGN_CLMN_NUM);
struct foreign_conts_track *track = ALLOC(struct foreign_conts_track,
rule_num * MAX_FOREIGN_CLMN_NUM);
for (i = 0; i < rule_num; i++) {
s_rule = rule_list + i;
@@ -851,7 +887,7 @@ void maat_cmd_get_foreign_conts(redisContext *c, struct serial_rule *rule_list,
}
}
int invalidate_line(char *line, int column_seq)
static int invalidate_line(char *line, int column_seq)
{
if (NULL == line || column_seq < 0) {
return -1;
@@ -898,8 +934,8 @@ void maat_cmd_rewrite_table_line_with_foreign(struct serial_rule *s_rule)
s_rule->table_line = rewrite_line;
}
void expected_reply_add(struct expected_reply* expected, int s_rule_seq,
int type, long long integer)
static void expected_reply_add(struct expected_reply* expected, int s_rule_seq,
int type, long long integer)
{
int i = expected->possible_reply_num;
assert(i < POSSIBLE_REDIS_REPLY_SIZE);
@@ -909,7 +945,8 @@ void expected_reply_add(struct expected_reply* expected, int s_rule_seq,
expected->possible_reply_num++;
}
int redlock_try_lock(redisContext *c, const char *lock_name, long long expire)
static int redlock_try_lock(redisContext *c, const char *lock_name,
long long expire)
{
int ret = 0;
@@ -927,9 +964,9 @@ int redlock_try_lock(redisContext *c, const char *lock_name, long long expire)
return ret;
}
long long exec_serial_rule_begin(redisContext* c, size_t rule_num,
size_t renew_rule_num, int *renew_allowed,
long long *transaction_version)
static long long exec_serial_rule_begin(redisContext* c, size_t rule_num,
size_t renew_rule_num, int *renew_allowed,
long long *transaction_version)
{
int ret = -1;
redisReply *data_reply = NULL;
@@ -961,7 +998,7 @@ long long exec_serial_rule_begin(redisContext* c, size_t rule_num,
return ret;
}
void redlock_unlock(redisContext *c, const char *lock_name)
static void redlock_unlock(redisContext *c, const char *lock_name)
{
redisReply *reply = maat_cmd_wrap_redis_command(c, "DEL %s", lock_name);
freeReplyObject(reply);
@@ -977,9 +1014,9 @@ const char* lua_exec_done=
"redis.call(\'del\', KEYS[4]);"
"redis.call(\'zadd\', KEYS[3], ARGV[1], maat_version);"
"return maat_version;";
redisReply* exec_serial_rule_end(redisContext *c, const char *transaction_list,
long long server_time, int renew_allowed,
struct expected_reply *expect_reply, size_t *cnt)
static redisReply* exec_serial_rule_end(redisContext *c, const char *transaction_list,
long long server_time, int renew_allowed,
struct expected_reply *expect_reply, size_t *cnt)
{
redisReply *data_reply = NULL;
@@ -1007,10 +1044,10 @@ redisReply* exec_serial_rule_end(redisContext *c, const char *transaction_list,
return data_reply;
}
void exec_serial_rule(redisContext *c, const char *transaction_list,
struct serial_rule *s_rule, size_t rule_num,
struct expected_reply *expect_reply, size_t *cnt,
size_t offset, int renew_allowed)
static void exec_serial_rule(redisContext *c, const char *transaction_list,
struct serial_rule *s_rule, size_t rule_num,
struct expected_reply *expect_reply, size_t *cnt,
size_t offset, int renew_allowed)
{
size_t i = 0;
size_t append_cmd_cnt = 0;
@@ -1123,7 +1160,8 @@ void exec_serial_rule(redisContext *c, const char *transaction_list,
}
}
int mr_operation_success(redisReply *actual_reply, struct expected_reply *expected)
static int mr_operation_success(redisReply *actual_reply,
struct expected_reply *expected)
{
if (expected->possible_replies[0].type != actual_reply->type) {
return 0;
@@ -1252,7 +1290,7 @@ error_out:
return success_cnt;
}
void cleanup_update_status(redisContext *c, struct log_handle *logger)
static void cleanup_update_status(redisContext *c, struct log_handle *logger)
{
long long version_upper_bound = 0;
long long version_lower_bound = 0;
@@ -1323,7 +1361,7 @@ error_out:
reply = NULL;
}
void check_maat_expiration(redisContext *c, struct log_handle *logger)
static void check_maat_expiration(redisContext *c, struct log_handle *logger)
{
UNUSED int ret = 0;
@@ -1522,4 +1560,4 @@ clean_up:
}
FREE(rule_list);
}
}

View File

@@ -35,7 +35,8 @@
#define MODULE_MAAT_RULE module_name_str("maat.rule")
struct maat_runtime* maat_runtime_create(long long version, struct maat *maat_inst)
static struct maat_runtime *
maat_runtime_create(long long version, struct maat *maat_inst)
{
struct maat_runtime *maat_rt = ALLOC(struct maat_runtime, 1);
@@ -58,8 +59,27 @@ struct maat_runtime* maat_runtime_create(long long version, struct maat *maat_in
return maat_rt;
}
void maat_runtime_commit(struct maat_runtime *maat_rt, int update_type,
long long maat_rt_version, struct log_handle *logger)
static void maat_runtime_destroy(struct maat_runtime *maat_rt)
{
if (NULL == maat_rt) {
return;
}
if (maat_rt->sequence_map != NULL) {
maat_kv_store_free(maat_rt->sequence_map);
maat_rt->sequence_map = NULL;
}
if (maat_rt->ref_cnt != NULL) {
alignment_int64_array_free(maat_rt->ref_cnt);
maat_rt->ref_cnt = NULL;
}
FREE(maat_rt);
}
static void maat_runtime_commit(struct maat_runtime *maat_rt, int update_type,
long long maat_rt_version, struct log_handle *logger)
{
for (size_t i = 0; i < maat_rt->max_table_num; i++) {
table_manager_commit_runtime(maat_rt->ref_tbl_mgr, i, update_type, maat_rt_version);
@@ -68,7 +88,7 @@ void maat_runtime_commit(struct maat_runtime *maat_rt, int update_type,
maat_rt->last_update_time = time(NULL);
}
void maat_start_cb(long long new_version, int update_type, void *u_param)
static void maat_start_cb(long long new_version, int update_type, void *u_param)
{
size_t i = 0;
enum table_type table_type = TABLE_TYPE_INVALID;
@@ -101,7 +121,7 @@ void maat_start_cb(long long new_version, int update_type, void *u_param)
}
}
int maat_update_cb(const char *table_name, const char *line, void *u_param)
static int maat_update_cb(const char *table_name, const char *line, void *u_param)
{
if (NULL == table_name || NULL == line || NULL == u_param) {
return 0;
@@ -138,7 +158,7 @@ int maat_update_cb(const char *table_name, const char *line, void *u_param)
return 0;
}
long long maat_runtime_rule_num(struct maat_runtime *maat_rt)
static long long maat_runtime_rule_num(struct maat_runtime *maat_rt)
{
long long total = 0;
@@ -146,14 +166,15 @@ long long maat_runtime_rule_num(struct maat_runtime *maat_rt)
long long rule_cnt = table_manager_runtime_rule_count(maat_rt->ref_tbl_mgr, i);
total += rule_cnt;
if (rule_cnt != 0) {
log_info(maat_rt->logger, MODULE_MAAT_RULE, "table:%d rule count:%lld", i, rule_cnt);
log_info(maat_rt->logger, MODULE_MAAT_RULE,
"table:%d rule count:%lld", i, rule_cnt);
}
}
return total;
}
void maat_plugin_table_all_callback_finish(struct table_manager *tbl_mgr)
static void maat_plugin_table_all_callback_finish(struct table_manager *tbl_mgr)
{
size_t max_table_cnt = table_manager_table_size(tbl_mgr);
enum table_type table_type = TABLE_TYPE_INVALID;
@@ -169,7 +190,7 @@ void maat_plugin_table_all_callback_finish(struct table_manager *tbl_mgr)
}
}
void maat_plugin_table_garbage_collect_routine(struct table_manager *tbl_mgr)
static void maat_plugin_table_garbage_collect_routine(struct table_manager *tbl_mgr)
{
size_t max_table_cnt = table_manager_table_size(tbl_mgr);
enum table_type table_type = TABLE_TYPE_INVALID;
@@ -211,7 +232,7 @@ void maat_plugin_table_garbage_collect_routine(struct table_manager *tbl_mgr)
}
}
void maat_finish_cb(void *u_param)
static void maat_finish_cb(void *u_param)
{
struct maat *maat_inst = (struct maat *)u_param;
@@ -338,32 +359,13 @@ long long maat_runtime_get_sequence(struct maat_runtime *maat_rt, const char *ke
return sequence;
}
void maat_runtime_destroy(struct maat_runtime *maat_rt)
{
if (NULL == maat_rt) {
return;
}
if (maat_rt->sequence_map != NULL) {
maat_kv_store_free(maat_rt->sequence_map);
maat_rt->sequence_map = NULL;
}
if (maat_rt->ref_cnt != NULL) {
alignment_int64_array_free(maat_rt->ref_cnt);
maat_rt->ref_cnt = NULL;
}
FREE(maat_rt);
}
void garbage_maat_kv_store_free(void *kv_store, void *arg)
{
struct maat_kv_store *store = (struct maat_kv_store *)kv_store;
maat_kv_store_free(store);
}
void garbage_maat_runtime_destroy(void *maat_runtime, void *arg)
static void garbage_maat_runtime_destroy(void *maat_runtime, void *arg)
{
struct maat_runtime *maat_rt = (struct maat_runtime *)maat_runtime;
maat_runtime_destroy(maat_rt);
@@ -531,4 +533,4 @@ void *rule_monitor_loop(void *arg)
FREE(maat_inst);
return NULL;
}
}

View File

@@ -77,7 +77,7 @@ enum field_type common_column_type[] = {
};
#define MAX_CONJ_NAME_LEN 22
void maat_fieldstat_register(struct maat_stat *stat)
static void maat_fieldstat_register(struct maat_stat *stat)
{
stat->fs_status_id[STATUS_VERSION] = fieldstat_register(stat->fs_handle, FIELD_TYPE_GAUGE,
"version", NULL, 0);
@@ -123,8 +123,9 @@ void maat_fieldstat_register(struct maat_stat *stat)
"line_cmd/s", NULL, 0);
}
int maat_fieldstat_table_row_register(struct maat_stat *stat, struct table_manager *tbl_mgr,
int table_id)
static int maat_fieldstat_table_row_register(struct maat_stat *stat,
struct table_manager *tbl_mgr,
int table_id)
{
size_t max_table_cnt = table_manager_table_size(tbl_mgr);
int ret = fieldstat_register_table_row(stat->fs_handle, table_id, "Sum", NULL, 0,
@@ -331,7 +332,7 @@ int maat_stat_init(struct maat_stat *stat, struct table_manager *tbl_mgr,
return 0;
}
void maat_fieldstat_table_row_output(struct maat_stat *stat, int perf_on)
static void maat_fieldstat_table_row_output(struct maat_stat *stat, int perf_on)
{
long long plugin_cache_num = 0, plugin_rule_num = 0, g2c_not_group_num = 0;
long long compile_rule_num = 0, g2c_rule_num = 0, g2g_rule_num = 0;

View File

@@ -279,7 +279,8 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
};
//@param value is a JSON, like {"tags":[{"tag":"location","value":"北京/朝阳/华严北里/甲22号},{"tag":"isp","value":"电信"}]}
size_t parse_accept_tag(const char *value, struct rule_tag **result, struct log_handle *logger)
static size_t parse_accept_tag(const char *value, struct rule_tag **result,
struct log_handle *logger)
{
if (NULL == value || NULL == result || NULL == logger) {
return 0;
@@ -311,7 +312,8 @@ size_t parse_accept_tag(const char *value, struct rule_tag **result, struct log_
return n_tag;
}
static int compare_each_tag(cJSON *tag_obj, const struct rule_tag *accept_tags, size_t n_accept_tag)
static int compare_each_tag(cJSON *tag_obj, const struct rule_tag *accept_tags,
size_t n_accept_tag)
{
if (NULL == tag_obj || NULL == accept_tags) {
return TAG_MATCH_ERR;
@@ -396,9 +398,11 @@ static int compare_each_tag_set(cJSON *tag_set, const struct rule_tag *accept_ta
}
}
//@param value {"tag_sets":[[{"tag":"location","value":["北京/朝阳/华严北里","上海/浦东/陆家嘴"]},{"tag":"isp","value":["电信","移动"]}],[{"tag":"location","value":["北京"]},{"tag":"isp","value":["联通"]}]]}
//@param value {"tag_sets":[[{"tag":"location","value":["北京/朝阳/华严北里","上海/浦东/陆家嘴"]},
//{"tag":"isp","value":["电信","移动"]}],[{"tag":"location","value":["北京"]},{"tag":"isp","value":["联通"]}]]}
//@return 1 on match, 0 on not match, -1 on error.
static int compare_accept_tag(const char *value, const struct rule_tag *accept_tags, size_t n_accept_tag)
static int compare_accept_tag(const char *value, const struct rule_tag *accept_tags,
size_t n_accept_tag)
{
int ret = TAG_MATCH_ERR;
int n_set = 0;
@@ -434,10 +438,10 @@ error:
return ret;
}
void *maat_table_schema_new(cJSON *json, const char *table_name,
enum table_type table_type,
struct table_manager *tbl_mgr,
struct log_handle *logger)
static void *maat_table_schema_new(cJSON *json, const char *table_name,
enum table_type table_type,
struct table_manager *tbl_mgr,
struct log_handle *logger)
{
void *schema = NULL;
@@ -448,7 +452,7 @@ void *maat_table_schema_new(cJSON *json, const char *table_name,
return schema;
}
void maat_table_schema_free(void *schema, enum table_type table_type)
static void maat_table_schema_free(void *schema, enum table_type table_type)
{
if (NULL == schema) {
return;
@@ -478,8 +482,9 @@ static void register_reserved_word(struct maat_kv_store *reserved_word_map)
maat_kv_register(reserved_word_map, "virtual", TABLE_TYPE_VIRTUAL);
}
struct maat_table *maat_table_new(cJSON *json, struct maat_kv_store *reserved_word_map,
struct log_handle *logger)
static struct maat_table *
maat_table_new(cJSON *json, struct maat_kv_store *reserved_word_map,
struct log_handle *logger)
{
struct maat_table *ptable = ALLOC(struct maat_table, 1);
@@ -501,7 +506,8 @@ struct maat_table *maat_table_new(cJSON *json, struct maat_kv_store *reserved_wo
// already validate in register_tablename2id
if (item->type == cJSON_Array) {
cJSON *tmp_item = cJSON_GetArrayItem(item, 0);
memcpy(ptable->table_name, tmp_item->valuestring, strlen(tmp_item->valuestring));
memcpy(ptable->table_name, tmp_item->valuestring,
strlen(tmp_item->valuestring));
} else {
//cJSON_String
memcpy(ptable->table_name, item->valuestring, strlen(item->valuestring));
@@ -515,11 +521,13 @@ struct maat_table *maat_table_new(cJSON *json, struct maat_kv_store *reserved_wo
goto error;
}
ret = maat_kv_read(reserved_word_map, item->valuestring, (long long *)&(ptable->table_type));
ret = maat_kv_read(reserved_word_map, item->valuestring,
(long long *)&(ptable->table_type));
if (ret < 0) {
log_error(logger, MODULE_TABLE,
"[%s:%d] table:%s table_type %s is illegal",
__FUNCTION__, __LINE__, ptable->table_name, item->valuestring);
__FUNCTION__, __LINE__, ptable->table_name,
item->valuestring);
goto error;
}
@@ -541,7 +549,7 @@ error:
return NULL;
}
void maat_table_runtime_free(void *runtime, enum table_type table_type)
static void maat_table_runtime_free(void *runtime, enum table_type table_type)
{
if (NULL == runtime) {
return;
@@ -552,7 +560,7 @@ void maat_table_runtime_free(void *runtime, enum table_type table_type)
}
}
void maat_table_free(struct maat_table *maat_tbl)
static void maat_table_free(struct maat_table *maat_tbl)
{
if (NULL == maat_tbl) {
return;
@@ -791,8 +799,10 @@ next:
return tbl_mgr;
}
void *maat_table_runtime_new(void *schema, enum table_type table_type, size_t max_thread_num,
struct maat_garbage_bin *garbage_bin, struct log_handle *logger)
static void *maat_table_runtime_new(void *schema, enum table_type table_type,
size_t max_thread_num,
struct maat_garbage_bin *garbage_bin,
struct log_handle *logger)
{
void *runtime = NULL;
@@ -804,7 +814,7 @@ void *maat_table_runtime_new(void *schema, enum table_type table_type, size_t ma
return runtime;
}
void garbage_maat_table_runtime_free(void *runtime, void *arg)
static void garbage_maat_table_runtime_free(void *runtime, void *arg)
{
enum table_type type = *(enum table_type *)arg;
maat_table_runtime_free(runtime, type);

View File

@@ -55,14 +55,15 @@ struct rcu_hash_node {
UT_hash_handle hh_b;
};
void rcu_hash_garbage_collect_force(struct rcu_hash_garbage_q *garbage_q)
static void rcu_hash_garbage_collect_force(struct rcu_hash_table *htable)
{
struct rcu_hash_garbage_bag *p = NULL;
while ((p = TAILQ_FIRST(garbage_q)) != NULL) {
while ((p = TAILQ_FIRST(&(htable->garbage_q))) != NULL) {
p->garbage_free(p->garbage);
TAILQ_REMOVE(garbage_q, p, entries);
TAILQ_REMOVE(&(htable->garbage_q), p, entries);
FREE(p);
htable->garbage_q_len--;
}
}
@@ -76,14 +77,15 @@ void rcu_hash_garbage_collect_routine(struct rcu_hash_table *htable)
if ((now - p->create_time) > htable->gc_timeout_s ||
htable->gc_timeout_s == 0) {
p->garbage_free(p->garbage);
TAILQ_REMOVE(&htable->garbage_q, p, entries);
TAILQ_REMOVE(&(htable->garbage_q), p, entries);
FREE(p);
htable->garbage_q_len--;
}
}
}
void rcu_hash_garbage_bagging(struct rcu_hash_garbage_q *garbage_q,
void *garbage, void (* func)(void *))
static void rcu_hash_garbage_bagging(struct rcu_hash_garbage_q *garbage_q,
void *garbage, void (* func)(void *))
{
struct rcu_hash_garbage_bag *bag = ALLOC(struct rcu_hash_garbage_bag, 1);
@@ -93,7 +95,7 @@ void rcu_hash_garbage_bagging(struct rcu_hash_garbage_q *garbage_q,
TAILQ_INSERT_TAIL(garbage_q, bag, entries);
}
void rcu_hash_node_free(struct rcu_hash_node *node)
static void rcu_hash_node_free(struct rcu_hash_node *node)
{
if (NULL == node) {
return;
@@ -150,13 +152,13 @@ void rcu_hash_free(struct rcu_hash_table *htable)
}
}
rcu_hash_garbage_collect_force(&(htable->garbage_q));
rcu_hash_garbage_collect_force(htable);
pthread_mutex_destroy(&htable->update_mutex);
FREE(htable);
}
void rcu_hash_commit_prepare(struct rcu_hash_table *htable)
static void rcu_hash_commit_prepare(struct rcu_hash_table *htable)
{
struct rcu_hash_node *node = NULL;
struct rcu_hash_node *tmp = NULL;