diff --git a/include/maat.h b/include/maat.h index 09d1799..3533ff5 100644 --- a/include/maat.h +++ b/include/maat.h @@ -171,10 +171,18 @@ int maat_plugin_table_ex_schema_register(struct maat *instance, const char *tabl maat_ex_dup_func_t *dup_func, long argl, void *argp); /** - * returned data is duplicated by dup_func of maat_plugin_table_ex_schema_register, - * caller is responsible to free the data. - * NOTE: support three key type(integer, pointer, ip_addr) specified in table_info.conf - * if use ip_addr key type, then key should be ip address in network order. + * xx_plugin_table_get_ex_data + * returned data is duplicated by dup_func of maat_plugin_table_ex_schema_register, + * caller is responsible to free the data. + * + * free_func support gargbage collection(gc), gc timeout(default 0) can be configured + * in table_info which means maat will not call free_func until the timeout expires + */ + +/** + * NOTE: only plugin table support three key type(integer, pointer, ip_addr) + * specified in table_info.conf. If use ip_addr key type, then key should be + * ip address in network order. */ void *maat_plugin_table_get_ex_data(struct maat *instance, int table_id, const char *key, size_t key_len); diff --git a/src/inc_internal/maat_ex_data.h b/src/inc_internal/maat_ex_data.h index 736805f..4592831 100644 --- a/src/inc_internal/maat_ex_data.h +++ b/src/inc_internal/maat_ex_data.h @@ -43,8 +43,11 @@ struct ex_container_schema { struct ex_data_runtime; /* ex_data_runtime API */ -struct ex_data_runtime *ex_data_runtime_new(int table_id, struct log_handle *logger); +struct ex_data_runtime * +ex_data_runtime_new(int table_id, int gc_timeout_s, struct log_handle *logger); + void ex_data_runtime_free(struct ex_data_runtime *ex_data_rt); + void ex_data_runtime_commit(struct ex_data_runtime *ex_data_rt); /* ex_data_runtime cache row API */ @@ -90,6 +93,8 @@ void *ex_data_runtime_get_ex_data_by_container(struct ex_data_runtime *ex_data_r 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 } #endif diff --git a/src/inc_internal/rcu_hash.h b/src/inc_internal/rcu_hash.h index 3dfb6ec..90d8855 100644 --- a/src/inc_internal/rcu_hash.h +++ b/src/inc_internal/rcu_hash.h @@ -23,7 +23,8 @@ typedef void data_free_fn(void *user_ctx, void *data); /* rcu hash table */ struct rcu_hash_table; -struct rcu_hash_table *rcu_hash_new(data_free_fn *free_fn, void *arg); +struct rcu_hash_table * +rcu_hash_new(data_free_fn *free_fn, void *user_ctx, int gc_timeout_s); void rcu_hash_free(struct rcu_hash_table *htable); @@ -75,6 +76,8 @@ int rcu_hash_is_updating(struct rcu_hash_table *htable); */ void rcu_hash_commit(struct rcu_hash_table *htable); +void rcu_hash_garbage_collect_routine(struct rcu_hash_table *htable); + #ifdef __cplusplus } #endif diff --git a/src/maat_api.c b/src/maat_api.c index fa9fb8b..d613bf7 100644 --- a/src/maat_api.c +++ b/src/maat_api.c @@ -57,7 +57,7 @@ struct maat_stream { struct log_handle *logger; int thread_id; int vtable_id; - int physical_table_id; + int phy_table_id; }; struct maat_options* maat_options_new(void) @@ -219,7 +219,8 @@ int maat_options_set_json_file_gzip_flag(struct maat_options *opts, int flag) return 0; } -int maat_options_set_json_file_decrypt_key(struct maat_options *opts, const char *decrypt_key) +int maat_options_set_json_file_decrypt_key(struct maat_options *opts, + const char *decrypt_key) { if (NULL == opts || NULL == decrypt_key) { return -1; @@ -253,7 +254,8 @@ int maat_options_set_stat_file(struct maat_options *opts, const char *stat_filen return 0; } -int maat_options_set_logger(struct maat_options *opts, const char *log_path, enum log_level level) +int maat_options_set_logger(struct maat_options *opts, const char *log_path, + enum log_level level) { if (NULL == opts || NULL == log_path || strlen(log_path) >= PATH_MAX) { return -1; @@ -348,13 +350,14 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path) } maat_inst->garbage_bin = maat_garbage_bin_new(garbage_gc_timeout_s); - maat_inst->stat = maat_stat_new(maat_inst->opts.stat_file, maat_inst->opts.nr_worker_thread, - maat_inst->logger); + maat_inst->stat = maat_stat_new(maat_inst->opts.stat_file, + maat_inst->opts.nr_worker_thread, + maat_inst->logger); pthread_mutex_init(&(maat_inst->background_update_mutex), NULL); maat_inst->tbl_mgr = table_manager_create(table_info_path, maat_inst->opts.accept_tags, - maat_inst->garbage_bin, maat_inst->logger); + maat_inst->garbage_bin, maat_inst->logger); if (NULL == maat_inst->tbl_mgr) { goto failed; } @@ -536,8 +539,8 @@ int generic_plugin_table_set_ex_schema(struct table_manager *tbl_mgr, int table_ void *schema = table_manager_get_schema(tbl_mgr, table_id); if (NULL == schema) { log_error(logger, MODULE_MAAT_API, - "[%s:%d], table(table_id:%d) is not registered, can't register ex_container_schema", - __FUNCTION__, __LINE__, table_id); + "[%s:%d], table(table_id:%d) is not registered, can't " + "register ex_container_schema", __FUNCTION__, __LINE__, table_id); return -1; } @@ -545,21 +548,25 @@ int generic_plugin_table_set_ex_schema(struct table_manager *tbl_mgr, int table_ enum table_type table_type = table_manager_get_table_type(tbl_mgr, table_id); switch (table_type) { case TABLE_TYPE_PLUGIN: - ret = plugin_table_set_ex_container_schema(schema, table_id, new_func, free_func, - dup_func, free, argl, argp); + ret = plugin_table_set_ex_container_schema(schema, table_id, + new_func, free_func, dup_func, + free, argl, argp); break; case TABLE_TYPE_IP_PLUGIN: - ret = ip_plugin_table_set_ex_container_schema(schema, table_id, new_func, free_func, - dup_func, free, argl, argp); + ret = ip_plugin_table_set_ex_container_schema(schema, table_id, + new_func, free_func, dup_func, + free, argl, argp); break; case TABLE_TYPE_FQDN_PLUGIN: - ret = fqdn_plugin_table_set_ex_container_schema(schema, table_id, new_func, free_func, - dup_func, (void (*)(void *))fqdn_rule_free, + ret = fqdn_plugin_table_set_ex_container_schema(schema, table_id, + new_func, free_func, dup_func, + (void (*)(void *))fqdn_rule_free, argl, argp); break; case TABLE_TYPE_BOOL_PLUGIN: - ret = bool_plugin_table_set_ex_container_schema(schema, table_id, new_func, free_func, - dup_func, free, argl, argp); + ret = bool_plugin_table_set_ex_container_schema(schema, table_id, + new_func, free_func, dup_func, + free, argl, argp); break; default: log_error(logger, MODULE_MAAT_API, @@ -571,11 +578,15 @@ 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, +void plugin_runtime_commit_ex_schema(void *runtime, void *schema, + const char *table_name, int valid_column) { - struct ex_container_schema *container_schema = plugin_table_get_ex_container_schema(schema); - struct ex_data_runtime *ex_data_rt = plugin_runtime_get_ex_data_rt(runtime); + struct ex_container_schema *container_schema = NULL; + struct ex_data_runtime *ex_data_rt = NULL; + + container_schema = plugin_table_get_ex_container_schema(schema); + ex_data_rt = plugin_runtime_get_ex_data_rt(runtime); ex_data_runtime_set_ex_container_schema(ex_data_rt, container_schema); size_t n_cached_row = ex_data_runtime_cached_row_count(ex_data_rt); @@ -588,11 +599,15 @@ void plugin_runtime_commit_ex_schema(void *runtime, void *schema, const char *ta plugin_runtime_commit(runtime, table_name, 0); } -void ip_plugin_runtime_commit_ex_schema(void *runtime, void *schema, const char *table_name, +void ip_plugin_runtime_commit_ex_schema(void *runtime, void *schema, + const char *table_name, int valid_column) { - struct ex_container_schema *container_schema = ip_plugin_table_get_ex_container_schema(schema); - struct ex_data_runtime *ex_data_rt = ip_plugin_runtime_get_ex_data_rt(runtime); + struct ex_container_schema *container_schema = NULL; + struct ex_data_runtime *ex_data_rt = NULL; + + container_schema = ip_plugin_table_get_ex_container_schema(schema); + ex_data_rt = ip_plugin_runtime_get_ex_data_rt(runtime); ex_data_runtime_set_ex_container_schema(ex_data_rt, container_schema); size_t n_cached_row = ex_data_runtime_cached_row_count(ex_data_rt); @@ -605,11 +620,15 @@ void ip_plugin_runtime_commit_ex_schema(void *runtime, void *schema, const char ip_plugin_runtime_commit(runtime, table_name, 0); } -void fqdn_plugin_runtime_commit_ex_schema(void *runtime, void *schema, const char *table_name, +void fqdn_plugin_runtime_commit_ex_schema(void *runtime, void *schema, + const char *table_name, int valid_column) { - struct ex_container_schema *container_schema = fqdn_plugin_table_get_ex_container_schema(schema); - struct ex_data_runtime *ex_data_rt = fqdn_plugin_runtime_get_ex_data_rt(runtime); + struct ex_container_schema *container_schema = NULL; + struct ex_data_runtime *ex_data_rt = NULL; + + container_schema = fqdn_plugin_table_get_ex_container_schema(schema); + ex_data_rt = fqdn_plugin_runtime_get_ex_data_rt(runtime); ex_data_runtime_set_ex_container_schema(ex_data_rt, container_schema); size_t n_cached_row = ex_data_runtime_cached_row_count(ex_data_rt); @@ -622,11 +641,15 @@ void fqdn_plugin_runtime_commit_ex_schema(void *runtime, void *schema, const cha fqdn_plugin_runtime_commit(runtime, table_name, 0); } -void bool_plugin_runtime_commit_ex_schema(void *runtime, void *schema, const char *table_name, +void bool_plugin_runtime_commit_ex_schema(void *runtime, void *schema, + const char *table_name, int valid_column) { - struct ex_container_schema *container_schema = bool_plugin_table_get_ex_container_schema(schema); - struct ex_data_runtime *ex_data_rt = bool_plugin_runtime_get_ex_data_rt(runtime); + struct ex_container_schema *container_schema = NULL; + struct ex_data_runtime *ex_data_rt = NULL; + + container_schema = bool_plugin_table_get_ex_container_schema(schema); + ex_data_rt = bool_plugin_runtime_get_ex_data_rt(runtime); ex_data_runtime_set_ex_container_schema(ex_data_rt, container_schema); size_t n_cached_row = ex_data_runtime_cached_row_count(ex_data_rt); @@ -789,8 +812,8 @@ void *maat_plugin_table_get_ex_data(struct maat *maat_inst, int table_id, } int maat_ip_plugin_table_get_ex_data(struct maat *maat_inst, int table_id, - const struct ip_addr *ip_addr, void **ex_data_array, - size_t n_ex_data) + const struct ip_addr *ip_addr, + void **ex_data_array, size_t n_ex_data) { if (NULL == maat_inst || table_id < 0 || table_id >= MAX_TABLE_NUM || NULL == ip_addr || NULL == ex_data_array || 0 == n_ex_data) { @@ -891,9 +914,9 @@ size_t hit_group_to_compile(void *compile_runtime, long long *compile_ids, } int flag_scan(struct table_manager *tbl_mgr, int thread_id, long long flag, - int physical_table_id, int vtable_id, struct maat_state *state) + int phy_table_id, int vtable_id, struct maat_state *state) { - enum table_type table_type = table_manager_get_table_type(tbl_mgr, physical_table_id); + enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id); if (table_type == TABLE_TYPE_FLAG_PLUS && DISTRICT_FLAG_UNSET == state->is_set_district) { return -1; @@ -903,7 +926,7 @@ int flag_scan(struct table_manager *tbl_mgr, int thread_id, long long flag, return -1; } - void *flag_rt = table_manager_get_runtime(tbl_mgr, physical_table_id); + void *flag_rt = table_manager_get_runtime(tbl_mgr, phy_table_id); if (NULL == flag_rt) { return -1; } @@ -920,10 +943,10 @@ int flag_scan(struct table_manager *tbl_mgr, int thread_id, long long flag, } int interval_scan(struct table_manager *tbl_mgr, int thread_id, long long integer, - int physical_table_id, int vtable_id, struct maat_state *state) + int phy_table_id, int vtable_id, struct maat_state *state) { - enum table_type table_type = table_manager_get_table_type(tbl_mgr, physical_table_id); + enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id); if (table_type == TABLE_TYPE_INTERVAL_PLUS && DISTRICT_FLAG_UNSET == state->is_set_district) { return -1; @@ -933,7 +956,7 @@ int interval_scan(struct table_manager *tbl_mgr, int thread_id, long long intege return -1; } - void *interval_rt = table_manager_get_runtime(tbl_mgr, physical_table_id); + void *interval_rt = table_manager_get_runtime(tbl_mgr, phy_table_id); if (NULL == interval_rt) { return -1; } @@ -950,16 +973,16 @@ int interval_scan(struct table_manager *tbl_mgr, int thread_id, long long intege } int ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_addr, - uint16_t port, int proto, int physical_table_id, int vtable_id, + 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, physical_table_id); + enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id); if (table_type != TABLE_TYPE_IP_PLUS) { return -1; } - void *ip_rt = table_manager_get_runtime(tbl_mgr, physical_table_id); + void *ip_rt = table_manager_get_runtime(tbl_mgr, phy_table_id); if (NULL == ip_rt) { return -1; } @@ -976,17 +999,17 @@ 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 physical_table_id, int vtable_id, - struct maat_state *state) +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, physical_table_id); + enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id); if (table_type != TABLE_TYPE_IP_PLUS) { return -1; } - void *ip_rt = table_manager_get_runtime(tbl_mgr, physical_table_id); + void *ip_rt = table_manager_get_runtime(tbl_mgr, phy_table_id); if (NULL == ip_rt) { return -1; } @@ -1002,10 +1025,11 @@ int ipv6_scan(struct table_manager *tbl_mgr, int thread_id, uint8_t *ip_addr, return group_hit_cnt; } -int string_scan(struct table_manager *tbl_mgr, int thread_id, const char *data, size_t data_len, - int physical_table_id, int vtable_id, struct maat_state *state) +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, physical_table_id); + enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id); if (table_type == TABLE_TYPE_EXPR_PLUS && DISTRICT_FLAG_UNSET == state->is_set_district) { return -1; @@ -1015,7 +1039,7 @@ int string_scan(struct table_manager *tbl_mgr, int thread_id, const char *data, return -1; } - void *expr_rt = table_manager_get_runtime(tbl_mgr, physical_table_id); + void *expr_rt = table_manager_get_runtime(tbl_mgr, phy_table_id); if (NULL == expr_rt) { return -1; } @@ -1032,15 +1056,16 @@ int string_scan(struct table_manager *tbl_mgr, int thread_id, const char *data, return group_hit_cnt; } -int expr_stream_scan(struct maat_stream *stream, const char *data, size_t data_len, - struct maat_state *state) +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; } + enum table_type table_type = TABLE_TYPE_INVALID; struct table_manager *tbl_mgr = stream->ref_maat_inst->tbl_mgr; - enum table_type table_type = table_manager_get_table_type(tbl_mgr, stream->physical_table_id); + table_type = table_manager_get_table_type(tbl_mgr, stream->phy_table_id); if (table_type == TABLE_TYPE_EXPR_PLUS && DISTRICT_FLAG_UNSET == state->is_set_district) { return -1; @@ -1050,13 +1075,14 @@ int expr_stream_scan(struct maat_stream *stream, const char *data, size_t data_l return -1; } - void *expr_rt = table_manager_get_runtime(tbl_mgr, stream->physical_table_id); + void *expr_rt = table_manager_get_runtime(tbl_mgr, stream->phy_table_id); if (NULL == expr_rt) { return -1; } - int group_hit_cnt = expr_runtime_stream_scan((struct expr_runtime *)expr_rt, stream->handle, - data, data_len, stream->vtable_id, state); + int group_hit_cnt = expr_runtime_stream_scan((struct expr_runtime *)expr_rt, + stream->handle, data, data_len, + stream->vtable_id, state); if (group_hit_cnt <= 0) { return group_hit_cnt; } @@ -1069,13 +1095,11 @@ int expr_stream_scan(struct maat_stream *stream, const char *data, size_t data_l size_t group_to_compile(struct maat *maat_inst, long long *results, size_t n_result, struct maat_state *state) { - int compile_table_id = -1; + int compile_table_id = table_manager_get_default_compile_table_id(maat_inst->tbl_mgr); if (state->compile_table_id > 0) { compile_table_id = state->compile_table_id; - } else { - compile_table_id = table_manager_get_default_compile_table_id(maat_inst->tbl_mgr); - } + } void *compile_rt = table_manager_get_runtime(maat_inst->tbl_mgr, compile_table_id); if (NULL == compile_rt) { @@ -1114,21 +1138,21 @@ int maat_scan_flag(struct maat *maat_inst, int table_id, } int vtable_id = 0; - int physical_table_id = -1; - enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id); + int phy_table_id = table_id; + enum table_type table_type = TABLE_TYPE_INVALID; + + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id); if (table_type == TABLE_TYPE_VIRTUAL) { - physical_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, table_id); + phy_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, table_id); vtable_id = table_id; - } else { - physical_table_id = table_id; } - if (physical_table_id < 0) { + if (phy_table_id < 0) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; } - table_type = table_manager_get_table_type(maat_inst->tbl_mgr, physical_table_id); + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, phy_table_id); if (table_type != TABLE_TYPE_FLAG && table_type != TABLE_TYPE_FLAG_PLUS) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; @@ -1138,7 +1162,7 @@ int maat_scan_flag(struct maat *maat_inst, int table_id, alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1); int hit_group_cnt = flag_scan(maat_inst->tbl_mgr, state->thread_id, flag, - physical_table_id, vtable_id, state); + phy_table_id, vtable_id, state); if (hit_group_cnt < 0) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; @@ -1159,7 +1183,7 @@ int maat_scan_flag(struct maat *maat_inst, int table_id, } } - void *flag_rt = table_manager_get_runtime(maat_inst->tbl_mgr, physical_table_id); + void *flag_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id); assert(flag_rt != NULL); if (1 == maat_inst->opts.perf_on) { @@ -1202,23 +1226,21 @@ int maat_scan_integer(struct maat *maat_inst, int table_id, } int vtable_id = 0; - int physical_table_id = -1; - enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr, - table_id); + int phy_table_id = table_id; + enum table_type table_type = TABLE_TYPE_INVALID; + + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id); if (table_type == TABLE_TYPE_VIRTUAL) { - physical_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, - table_id); + phy_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, table_id); vtable_id = table_id; - } else { - physical_table_id = table_id; } - if (physical_table_id < 0) { + if (phy_table_id < 0) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; } - table_type = table_manager_get_table_type(maat_inst->tbl_mgr, physical_table_id); + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, phy_table_id); if (table_type != TABLE_TYPE_INTERVAL && table_type != TABLE_TYPE_INTERVAL_PLUS) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; @@ -1228,7 +1250,7 @@ int maat_scan_integer(struct maat *maat_inst, int table_id, alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1); int hit_group_cnt = interval_scan(maat_inst->tbl_mgr, state->thread_id, integer, - physical_table_id, vtable_id, state); + phy_table_id, vtable_id, state); if (hit_group_cnt < 0) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; @@ -1249,8 +1271,7 @@ int maat_scan_integer(struct maat *maat_inst, int table_id, } } - void *interval_rt = table_manager_get_runtime(maat_inst->tbl_mgr, - physical_table_id); + void *interval_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id); assert(interval_rt != NULL); if (1 == maat_inst->opts.perf_on) { @@ -1293,23 +1314,21 @@ int maat_scan_ipv4(struct maat *maat_inst, int table_id, uint32_t ip_addr, } int vtable_id = 0; - int physical_table_id = -1; - enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr, - table_id); + int phy_table_id = table_id; + enum table_type table_type = TABLE_TYPE_INVALID; + + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id); if (table_type == TABLE_TYPE_VIRTUAL) { - physical_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, - table_id); + phy_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, table_id); vtable_id = table_id; - } else { - physical_table_id = table_id; } - if (physical_table_id < 0) { + if (phy_table_id < 0) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; } - table_type = table_manager_get_table_type(maat_inst->tbl_mgr, physical_table_id); + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, phy_table_id); if (table_type != TABLE_TYPE_IP_PLUS) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; @@ -1319,7 +1338,7 @@ int maat_scan_ipv4(struct maat *maat_inst, int table_id, uint32_t ip_addr, alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1); int hit_group_cnt = ipv4_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr, - port, protocol, physical_table_id, vtable_id, state); + port, protocol, phy_table_id, vtable_id, state); if (hit_group_cnt < 0) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; @@ -1340,7 +1359,7 @@ int maat_scan_ipv4(struct maat *maat_inst, int table_id, uint32_t ip_addr, } } - void *ip_rt = table_manager_get_runtime(maat_inst->tbl_mgr, physical_table_id); + void *ip_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id); assert(ip_rt != NULL); if (1 == maat_inst->opts.perf_on) { @@ -1384,23 +1403,21 @@ int maat_scan_ipv6(struct maat *maat_inst, int table_id, } int vtable_id = 0; - int physical_table_id = -1; - enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr, - table_id); + int phy_table_id = table_id; + enum table_type table_type = TABLE_TYPE_INVALID; + + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id); if (table_type == TABLE_TYPE_VIRTUAL) { - physical_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, - table_id); + phy_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, table_id); vtable_id = table_id; - } else { - physical_table_id = table_id; } - if (physical_table_id < 0) { + if (phy_table_id < 0) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; } - table_type = table_manager_get_table_type(maat_inst->tbl_mgr, physical_table_id); + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, phy_table_id); if (table_type != TABLE_TYPE_IP_PLUS) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; @@ -1410,7 +1427,7 @@ int maat_scan_ipv6(struct maat *maat_inst, int table_id, alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1); int hit_group_cnt = ipv6_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr, - port, protocol, physical_table_id, vtable_id, state); + port, protocol, phy_table_id, vtable_id, state); if (hit_group_cnt < 0) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; @@ -1431,7 +1448,7 @@ int maat_scan_ipv6(struct maat *maat_inst, int table_id, } } - void *ip_rt = table_manager_get_runtime(maat_inst->tbl_mgr, physical_table_id); + void *ip_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id); assert(ip_rt != NULL); if (1 == maat_inst->opts.perf_on) { @@ -1474,23 +1491,21 @@ int maat_scan_string(struct maat *maat_inst, int table_id, const char *data, } int vtable_id = 0; - int physical_table_id = -1; - enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr, - table_id); + int phy_table_id = table_id; + enum table_type table_type = TABLE_TYPE_INVALID; + + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id); if (table_type == TABLE_TYPE_VIRTUAL) { - physical_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, - table_id); + phy_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, table_id); vtable_id = table_id; - } else { - physical_table_id = table_id; } - if (physical_table_id < 0) { + if (phy_table_id < 0) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; } - table_type = table_manager_get_table_type(maat_inst->tbl_mgr, physical_table_id); + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, phy_table_id); if (table_type != TABLE_TYPE_EXPR && table_type != TABLE_TYPE_EXPR_PLUS) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; @@ -1499,8 +1514,8 @@ int maat_scan_string(struct maat *maat_inst, int table_id, const char *data, maat_runtime_ref_inc(maat_inst->maat_rt, state->thread_id); alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1); - int hit_group_cnt = string_scan(maat_inst->tbl_mgr, state->thread_id, data, data_len, - physical_table_id, vtable_id, state); + int hit_group_cnt = string_scan(maat_inst->tbl_mgr, state->thread_id, data, + data_len, phy_table_id, vtable_id, state); if (hit_group_cnt < 0) { maat_inst->stat->scan_err_cnt++; return MAAT_SCAN_ERR; @@ -1521,7 +1536,7 @@ int maat_scan_string(struct maat *maat_inst, int table_id, const char *data, } } - void *expr_rt = table_manager_get_runtime(maat_inst->tbl_mgr, physical_table_id); + void *expr_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id); assert(expr_rt != NULL); if (1 == maat_inst->opts.perf_on) { @@ -1554,31 +1569,28 @@ struct maat_stream *maat_stream_new(struct maat *maat_inst, int table_id, stream->ref_maat_inst = maat_inst; stream->last_full_version = maat_inst->last_full_version; stream->thread_id = state->thread_id; + stream->phy_table_id = table_id; stream->logger = maat_inst->logger; - enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr, - table_id); + enum table_type table_type = TABLE_TYPE_INVALID; + + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id); if (table_type == TABLE_TYPE_VIRTUAL) { - stream->physical_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, - table_id); + stream->phy_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, table_id); stream->vtable_id = table_id; - } else { - stream->physical_table_id = table_id; - stream->vtable_id = 0; } - if (stream->physical_table_id < 0) { + if (stream->phy_table_id < 0) { return NULL; } - table_type = table_manager_get_table_type(maat_inst->tbl_mgr, - stream->physical_table_id); + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, stream->phy_table_id); if (table_type != TABLE_TYPE_EXPR && table_type != TABLE_TYPE_EXPR_PLUS) { return NULL; } void *expr_rt = table_manager_get_runtime(stream->ref_maat_inst->tbl_mgr, - stream->physical_table_id); + stream->phy_table_id); assert(expr_rt != NULL); stream->expr_rt_version = expr_runtime_get_version(expr_rt); @@ -1619,7 +1631,7 @@ int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data } void *expr_rt = table_manager_get_runtime(maat_inst->tbl_mgr, - maat_stream->physical_table_id); + maat_stream->phy_table_id); assert(expr_rt != NULL); long long cur_expr_rt_version = expr_runtime_get_version(expr_rt); @@ -1675,7 +1687,7 @@ void maat_stream_free(struct maat_stream *maat_stream) struct maat *maat_inst = maat_stream->ref_maat_inst; void *expr_rt = table_manager_get_runtime(maat_inst->tbl_mgr, - maat_stream->physical_table_id); + maat_stream->phy_table_id); assert(expr_rt != NULL); long long cur_expr_rt_version = expr_runtime_get_version(expr_rt); @@ -1756,7 +1768,7 @@ void maat_state_free(struct maat_state *state) thread_id, sizeof(struct maat_state)); } -int maat_state_set_scan_district(struct maat_state *state, int vtable_id, +int maat_state_set_scan_district(struct maat_state *state, int table_id, const char *district, size_t district_len) { if (NULL == state || NULL == district || 0 == district_len) { @@ -1772,8 +1784,8 @@ int maat_state_set_scan_district(struct maat_state *state, int vtable_id, return -1; } - enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr, - vtable_id); + enum table_type table_type = TABLE_TYPE_INVALID; + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id); if (table_type != TABLE_TYPE_FLAG_PLUS && table_type != TABLE_TYPE_EXPR_PLUS && table_type != TABLE_TYPE_INTERVAL_PLUS && table_type != TABLE_TYPE_VIRTUAL) { log_error(maat_inst->logger, MODULE_MAAT_API, @@ -1781,18 +1793,16 @@ int maat_state_set_scan_district(struct maat_state *state, int vtable_id, return -1; } - int physical_table_id = vtable_id; + int phy_table_id = table_id; if (table_type == TABLE_TYPE_VIRTUAL) { - physical_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, - vtable_id); + phy_table_id = vtable_get_physical_table_id(maat_inst->tbl_mgr, table_id); } int ret = -1; long long district_id; - table_type = table_manager_get_table_type(maat_inst->tbl_mgr, - physical_table_id); - void *runtime = table_manager_get_runtime(maat_inst->tbl_mgr, - physical_table_id); + + table_type = table_manager_get_table_type(maat_inst->tbl_mgr, phy_table_id); + void *runtime = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id); assert(runtime != NULL); switch (table_type) { @@ -1877,15 +1887,12 @@ int maat_state_get_hit_paths(struct maat_state *state, struct maat_hit_path *pat return -1; } - int compile_table_id = -1; + int compile_table_id = table_manager_get_default_compile_table_id(maat_inst->tbl_mgr); if (state->compile_table_id > 0) { compile_table_id = state->compile_table_id; - } else { - compile_table_id = table_manager_get_default_compile_table_id(maat_inst->tbl_mgr); } - void *compile_rt = table_manager_get_runtime(maat_inst->tbl_mgr, - compile_table_id); + void *compile_rt = table_manager_get_runtime(maat_inst->tbl_mgr, compile_table_id); if (NULL == compile_rt) { return -1; } diff --git a/src/maat_bool_plugin.c b/src/maat_bool_plugin.c index 696134a..426e4df 100644 --- a/src/maat_bool_plugin.c +++ b/src/maat_bool_plugin.c @@ -23,6 +23,7 @@ struct bool_plugin_schema { int item_id_column; int bool_expr_column; int rule_tag_column; + int gc_timeout_s; struct ex_container_schema container_schema; int table_id; struct table_manager *ref_tbl_mgr; @@ -94,6 +95,12 @@ void *bool_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr, schema->rule_tag_column = custom_item->valueint; } + //gc_timeout_s is optional + custom_item = cJSON_GetObjectItem(item, "gc_timeout_s"); + if (custom_item != NULL && custom_item->type == cJSON_Number) { + schema->gc_timeout_s = custom_item->valueint; + } + schema->ref_tbl_mgr = tbl_mgr; return schema; error: @@ -183,7 +190,8 @@ void *bool_plugin_runtime_new(void *bool_plugin_schema, size_t max_thread_num, struct bool_plugin_schema *schema = (struct bool_plugin_schema *)bool_plugin_schema; struct bool_plugin_runtime *bool_plugin_rt = ALLOC(struct bool_plugin_runtime, 1); - bool_plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id, logger); + bool_plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id, schema->gc_timeout_s, + logger); if (1 == schema->container_schema.set_flag) { ex_data_runtime_set_ex_container_schema(bool_plugin_rt->ex_data_rt, &(schema->container_schema)); diff --git a/src/maat_compile.c b/src/maat_compile.c index 94744fc..151750a 100644 --- a/src/maat_compile.c +++ b/src/maat_compile.c @@ -33,10 +33,11 @@ struct compile_schema { int rule_tag_column; int declared_clause_num_column; int set_flag; + int gc_timeout_s; + int table_id; //ugly struct ex_data_schema ex_schema; struct table_manager *ref_tbl_mgr; struct log_handle *logger; - int table_id; //ugly }; struct group2compile_schema { @@ -308,13 +309,13 @@ void *compile_schema_new(cJSON *json, struct table_manager *tbl_mgr, const char *table_name, struct log_handle *logger) { - struct compile_schema *compile_schema = ALLOC(struct compile_schema, 1); - compile_schema->logger = logger; + struct compile_schema *schema = ALLOC(struct compile_schema, 1); + schema->logger = logger; cJSON *custom_item = NULL; cJSON *item = cJSON_GetObjectItem(json, "table_id"); if (item != NULL && item->type == cJSON_Number) { - compile_schema->table_id = item->valueint; + schema->table_id = item->valueint; } else { log_error(logger, MODULE_COMPILE, "[%s:%d] table: <%s> schema has no table_id column", @@ -332,7 +333,7 @@ void *compile_schema_new(cJSON *json, struct table_manager *tbl_mgr, custom_item = cJSON_GetObjectItem(item, "compile_id"); if (custom_item != NULL && custom_item->type == cJSON_Number) { - compile_schema->compile_id_column = custom_item->valueint; + schema->compile_id_column = custom_item->valueint; } else { log_error(logger, MODULE_COMPILE, "[%s:%d] table: <%s> schema has no compile_id column", @@ -342,12 +343,12 @@ void *compile_schema_new(cJSON *json, struct table_manager *tbl_mgr, custom_item = cJSON_GetObjectItem(item, "tags"); if (custom_item != NULL && custom_item->type == cJSON_Number) { - compile_schema->rule_tag_column = custom_item->valueint; + schema->rule_tag_column = custom_item->valueint; } custom_item = cJSON_GetObjectItem(item, "clause_num"); if (custom_item != NULL && custom_item->type == cJSON_Number) { - compile_schema->declared_clause_num_column = custom_item->valueint; + schema->declared_clause_num_column = custom_item->valueint; } else { log_error(logger, MODULE_COMPILE, "[%s:%d] table: <%s> schema has no clause_num column", @@ -355,10 +356,16 @@ void *compile_schema_new(cJSON *json, struct table_manager *tbl_mgr, goto error; } - compile_schema->ref_tbl_mgr = tbl_mgr; - return compile_schema; + //gc_timeout_s is optional + custom_item = cJSON_GetObjectItem(item, "gc_timeout_s"); + if (custom_item != NULL && custom_item->type == cJSON_Number) { + schema->gc_timeout_s = custom_item->valueint; + } + + schema->ref_tbl_mgr = tbl_mgr; + return schema; error: - FREE(compile_schema); + FREE(schema); return NULL; } @@ -567,12 +574,14 @@ void *compile_runtime_new(void *compile_schema, size_t max_thread_num, return NULL; } + struct compile_schema *schema = (struct compile_schema *)compile_schema; struct compile_runtime *compile_rt = ALLOC(struct compile_runtime, 1); compile_rt->expr_match_buff = ALLOC(struct bool_expr_match, max_thread_num * MAX_SCANNER_HIT_COMPILE_NUM); compile_rt->version = time(NULL); - compile_rt->cfg_hash = rcu_hash_new(rcu_compile_cfg_free, NULL); + compile_rt->cfg_hash = rcu_hash_new(rcu_compile_cfg_free, NULL, + schema->gc_timeout_s); compile_rt->clause_by_literals_hash = NULL; compile_rt->literal2clause_hash = NULL; compile_rt->logger = logger; @@ -2111,11 +2120,9 @@ void maat_compile_state_update(int vtable_id, struct maat_item *hit_items, } /* update hit clause */ - int compile_table_id = -1; + int compile_table_id = table_manager_get_default_compile_table_id(maat_inst->tbl_mgr); if (state->compile_table_id > 0) { compile_table_id = state->compile_table_id; - } else { - compile_table_id = table_manager_get_default_compile_table_id(maat_inst->tbl_mgr); } struct compile_runtime *compile_rt = table_manager_get_runtime(maat_inst->tbl_mgr, diff --git a/src/maat_ex_data.c b/src/maat_ex_data.c index 8ebe9ee..5f8027f 100644 --- a/src/maat_ex_data.c +++ b/src/maat_ex_data.c @@ -27,6 +27,7 @@ struct ex_data_runtime { struct rcu_hash_table *htable; // store ex_container struct ex_container_schema *ref_container_schema; + int gc_timeout_s; int table_id; struct log_handle *logger; @@ -40,7 +41,7 @@ void cache_row_free(void *p) UT_icd ut_cache_row_icd = {sizeof(char*), NULL, NULL, cache_row_free}; struct ex_data_runtime * -ex_data_runtime_new(int table_id, struct log_handle *logger) +ex_data_runtime_new(int table_id, int gc_timeout_s, struct log_handle *logger) { if (table_id < 0 || NULL == logger) { return NULL; @@ -50,6 +51,7 @@ ex_data_runtime_new(int table_id, struct log_handle *logger) utarray_new(ex_data_rt->cache_rows, &ut_cache_row_icd); ex_data_rt->htable = NULL; + ex_data_rt->gc_timeout_s = gc_timeout_s; ex_data_rt->table_id = table_id; ex_data_rt->logger = logger; @@ -181,7 +183,8 @@ void ex_container_free(void *user_ctx, void *data) /* free ex_container->ex_data */ if (container->ex_data != NULL && container_schema->ex_schema.free_func != NULL) { - container_schema->ex_schema.free_func(container_schema->table_id, &(container->ex_data), + container_schema->ex_schema.free_func(container_schema->table_id, + &(container->ex_data), container_schema->ex_schema.argl, container_schema->ex_schema.argp); container->ex_data = NULL; @@ -202,7 +205,9 @@ int ex_data_runtime_add_ex_container(struct ex_data_runtime *ex_data_rt, if (NULL == ex_data_rt->htable) { /* ex_data_rt->ref_container_schema has been set */ assert(ex_data_rt->ref_container_schema != NULL); - ex_data_rt->htable = rcu_hash_new(ex_container_free, ex_data_rt->ref_container_schema); + ex_data_rt->htable = rcu_hash_new(ex_container_free, + ex_data_rt->ref_container_schema, + ex_data_rt->gc_timeout_s); } return rcu_hash_add(ex_data_rt->htable, key, key_len, ex_container); @@ -292,4 +297,15 @@ size_t ex_data_runtime_list_ex_container(struct ex_data_runtime *ex_data_rt, struct ex_container ***ex_container) { return rcu_hash_list(ex_data_rt->htable, (void ***)ex_container); +} + +void ex_data_runtime_garbage_collect_routine(struct ex_data_runtime *ex_data_rt) +{ + if (NULL == ex_data_rt) { + return; + } + + if (ex_data_rt->htable != NULL) { + rcu_hash_garbage_collect_routine(ex_data_rt->htable); + } } \ No newline at end of file diff --git a/src/maat_expr.c b/src/maat_expr.c index d010019..fefe24b 100644 --- a/src/maat_expr.c +++ b/src/maat_expr.c @@ -476,7 +476,7 @@ void *expr_runtime_new(void *expr_schema, size_t max_thread_num, struct expr_runtime *expr_rt = ALLOC(struct expr_runtime, 1); - expr_rt->item_hash = rcu_hash_new(expr_item_free_cb, NULL); + expr_rt->item_hash = rcu_hash_new(expr_item_free_cb, NULL, 0); expr_rt->n_worker_thread = max_thread_num; expr_rt->ref_garbage_bin = garbage_bin; expr_rt->logger = logger; diff --git a/src/maat_flag.c b/src/maat_flag.c index b49c898..782cfbe 100644 --- a/src/maat_flag.c +++ b/src/maat_flag.c @@ -188,7 +188,7 @@ void *flag_runtime_new(void *flag_schema, size_t max_thread_num, struct flag_runtime *flag_rt = ALLOC(struct flag_runtime, 1); - flag_rt->item_hash = rcu_hash_new(flag_item_free_cb, NULL); + flag_rt->item_hash = rcu_hash_new(flag_item_free_cb, NULL, 0); flag_rt->n_worker_thread = max_thread_num; flag_rt->ref_garbage_bin = garbage_bin; flag_rt->logger = logger; diff --git a/src/maat_fqdn_plugin.c b/src/maat_fqdn_plugin.c index 10b36fc..c3e7c41 100644 --- a/src/maat_fqdn_plugin.c +++ b/src/maat_fqdn_plugin.c @@ -24,8 +24,9 @@ struct fqdn_plugin_schema { int suffix_flag_column; int fqdn_column; int rule_tag_column; - struct ex_container_schema container_schema; + int gc_timeout_s; int table_id; + struct ex_container_schema container_schema; struct table_manager *ref_tbl_mgr; struct log_handle *logger; }; @@ -105,6 +106,12 @@ void *fqdn_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr, schema->rule_tag_column = custom_item->valueint; } + //gc_timeout_s is optional + custom_item = cJSON_GetObjectItem(item, "gc_timeout_s"); + if (custom_item != NULL && custom_item->type == cJSON_Number) { + schema->gc_timeout_s = custom_item->valueint; + } + schema->ref_tbl_mgr = tbl_mgr; return schema; error: @@ -182,7 +189,8 @@ void *fqdn_plugin_runtime_new(void *fqdn_plugin_schema, size_t max_thread_num, struct fqdn_plugin_schema *schema = (struct fqdn_plugin_schema *)fqdn_plugin_schema; struct fqdn_plugin_runtime *fqdn_plugin_rt = ALLOC(struct fqdn_plugin_runtime, 1); - fqdn_plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id, logger); + fqdn_plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id, schema->gc_timeout_s, + logger); if (1 == schema->container_schema.set_flag) { ex_data_runtime_set_ex_container_schema(fqdn_plugin_rt->ex_data_rt, &(schema->container_schema)); diff --git a/src/maat_interval.c b/src/maat_interval.c index 5771a86..0e3718f 100644 --- a/src/maat_interval.c +++ b/src/maat_interval.c @@ -184,7 +184,7 @@ void *interval_runtime_new(void *interval_schema, size_t max_thread_num, struct interval_runtime *interval_rt = ALLOC(struct interval_runtime, 1); - interval_rt->item_hash = rcu_hash_new(interval_item_free_cb, NULL); + interval_rt->item_hash = rcu_hash_new(interval_item_free_cb, NULL, 0); interval_rt->n_worker_thread = max_thread_num; interval_rt->ref_garbage_bin = garbage_bin; interval_rt->logger = logger; diff --git a/src/maat_ip.c b/src/maat_ip.c index 16dc19c..f9e7143 100644 --- a/src/maat_ip.c +++ b/src/maat_ip.c @@ -403,7 +403,7 @@ void *ip_runtime_new(void *ip_schema, size_t max_thread_num, struct ip_runtime *ip_rt = ALLOC(struct ip_runtime, 1); - ip_rt->item_hash = rcu_hash_new(ip_item_free_cb, NULL); + ip_rt->item_hash = rcu_hash_new(ip_item_free_cb, NULL, 0); ip_rt->n_worker_thread = max_thread_num; ip_rt->ref_garbage_bin = garbage_bin; ip_rt->logger = logger; diff --git a/src/maat_ip_plugin.c b/src/maat_ip_plugin.c index beee297..08b5690 100644 --- a/src/maat_ip_plugin.c +++ b/src/maat_ip_plugin.c @@ -28,8 +28,9 @@ struct ip_plugin_schema { int end_ip_column; int addr_format_column; int rule_tag_column; - struct ex_container_schema container_schema; + int gc_timeout_s; int table_id; //ugly + struct ex_container_schema container_schema; struct table_manager *ref_tbl_mgr; struct log_handle *logger; }; @@ -130,6 +131,12 @@ void *ip_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr, schema->rule_tag_column = custom_item->valueint; } + //gc_timeout_s is optional + custom_item = cJSON_GetObjectItem(item, "gc_timeout_s"); + if (custom_item != NULL && custom_item->type == cJSON_Number) { + schema->gc_timeout_s = custom_item->valueint; + } + schema->ref_tbl_mgr = tbl_mgr; return schema; @@ -379,7 +386,8 @@ void *ip_plugin_runtime_new(void *ip_plugin_schema, size_t max_thread_num, struct ip_plugin_schema *schema = (struct ip_plugin_schema *)ip_plugin_schema; struct ip_plugin_runtime *ip_plugin_rt = ALLOC(struct ip_plugin_runtime, 1); - ip_plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id, logger); + ip_plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id, schema->gc_timeout_s, + logger); if (1 == schema->container_schema.set_flag) { ex_data_runtime_set_ex_container_schema(ip_plugin_rt->ex_data_rt, &(schema->container_schema)); diff --git a/src/maat_plugin.c b/src/maat_plugin.c index 52b1c71..7c6d035 100644 --- a/src/maat_plugin.c +++ b/src/maat_plugin.c @@ -20,6 +20,7 @@ #include "maat_table.h" #define MODULE_PLUGIN module_name_str("maat.plugin") + #define IPV4 4 #define IPV6 6 @@ -53,6 +54,7 @@ struct plugin_schema { int key_column; int addr_type_column; int rule_tag_column; + int gc_timeout_s; int n_foreign; int foreign_columns[MAX_FOREIGN_CLMN_NUM]; size_t cb_cnt; @@ -169,6 +171,11 @@ void *plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr, } } } + + custom_item = cJSON_GetObjectItem(item, "gc_timeout_s"); + if (custom_item != NULL && custom_item->type == cJSON_Number) { + schema->gc_timeout_s = custom_item->valueint; + } } schema->ref_tbl_mgr = tbl_mgr; @@ -298,7 +305,9 @@ void *plugin_runtime_new(void *plugin_schema, size_t max_thread_num, struct plugin_schema *schema = (struct plugin_schema *)plugin_schema; struct plugin_runtime *plugin_rt = ALLOC(struct plugin_runtime, 1); - plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id, logger); + plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id, + schema->gc_timeout_s, + logger); if (1 == schema->container_schema.set_flag) { ex_data_runtime_set_ex_container_schema(plugin_rt->ex_data_rt, &(schema->container_schema)); diff --git a/src/maat_rule.c b/src/maat_rule.c index 82d0d90..92bbf52 100644 --- a/src/maat_rule.c +++ b/src/maat_rule.c @@ -166,6 +166,23 @@ void maat_plugin_table_all_callback_finish(struct table_manager *tbl_mgr) } } +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; + + for (size_t i = 0; i < max_table_cnt; i++) { + table_type = table_manager_get_table_type(tbl_mgr, i); + if (table_type != TABLE_TYPE_PLUGIN) { + continue; + } + + void *plugin_runtime = table_manager_get_runtime(tbl_mgr, i); + struct ex_data_runtime *ex_data_rt = plugin_runtime_get_ex_data_rt(plugin_runtime); + ex_data_runtime_garbage_collect_routine(ex_data_rt); + } +} + void maat_finish_cb(void *u_param) { struct maat *maat_inst = (struct maat *)u_param; @@ -449,6 +466,8 @@ void *rule_monitor_loop(void *arg) } maat_garbage_collect_routine(maat_inst->garbage_bin); + maat_plugin_table_garbage_collect_routine(maat_inst->tbl_mgr); + if ((1 == maat_inst->opts.stat_on) && (time(NULL) % 2 == 0)) { maat_stat_output(maat_inst->stat, maat_inst->maat_version, maat_inst->opts.perf_on); } diff --git a/src/rcu_hash.c b/src/rcu_hash.c index fe15130..1b954c0 100644 --- a/src/rcu_hash.c +++ b/src/rcu_hash.c @@ -18,6 +18,7 @@ #include "maat_utils.h" struct rcu_hash_garbage_bag { + time_t create_time; void *garbage; void (* garbage_free)(void *garbage); TAILQ_ENTRY(rcu_hash_garbage_bag) entries; @@ -37,6 +38,7 @@ struct rcu_hash_table { struct rcu_hash_garbage_q garbage_q; size_t garbage_q_len; + int gc_timeout_s; pthread_mutex_t update_mutex; }; @@ -53,7 +55,7 @@ struct rcu_hash_node { UT_hash_handle hh_b; }; -void rcu_hash_garbage_queue_free(struct rcu_hash_garbage_q *garbage_q) +void rcu_hash_garbage_collect_force(struct rcu_hash_garbage_q *garbage_q) { struct rcu_hash_garbage_bag *p = NULL; @@ -64,11 +66,28 @@ void rcu_hash_garbage_queue_free(struct rcu_hash_garbage_q *garbage_q) } } -void rcu_hash_garbage_bagging(struct rcu_hash_garbage_q* garbage_q, - void* garbage, void (* func)(void *)) +void rcu_hash_garbage_collect_routine(struct rcu_hash_table *htable) +{ + struct rcu_hash_garbage_bag *p = NULL, *tmp = NULL; + time_t now = time(NULL); + + for (p = TAILQ_FIRST(&(htable->garbage_q)); p != NULL; p = tmp) { + tmp = TAILQ_NEXT(p, entries); + 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); + FREE(p); + } + } +} + +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); + bag->create_time = time(NULL); bag->garbage = garbage; bag->garbage_free = func; TAILQ_INSERT_TAIL(garbage_q, bag, entries); @@ -90,7 +109,8 @@ void rcu_hash_node_free(struct rcu_hash_node *node) FREE(node); } -struct rcu_hash_table *rcu_hash_new(data_free_fn *free_fn, void *user_ctx) +struct rcu_hash_table * +rcu_hash_new(data_free_fn *free_fn, void *user_ctx, int gc_timeout_s) { if (NULL == free_fn) { return NULL; @@ -102,6 +122,7 @@ struct rcu_hash_table *rcu_hash_new(data_free_fn *free_fn, void *user_ctx) htable->effective_hash = 'a'; TAILQ_INIT(&htable->garbage_q); htable->garbage_q_len = 0; + htable->gc_timeout_s = gc_timeout_s; htable->data_free_fn = free_fn; htable->user_ctx = user_ctx; pthread_mutex_init(&htable->update_mutex, NULL); @@ -129,7 +150,7 @@ void rcu_hash_free(struct rcu_hash_table *htable) } } - rcu_hash_garbage_queue_free(&(htable->garbage_q)); + rcu_hash_garbage_collect_force(&(htable->garbage_q)); pthread_mutex_destroy(&htable->update_mutex); FREE(htable); @@ -322,7 +343,7 @@ void rcu_hash_commit(struct rcu_hash_table *htable) } htable->is_updating = 0; - rcu_hash_garbage_queue_free(&(htable->garbage_q)); + rcu_hash_garbage_collect_routine(htable); htable->garbage_q_len = 0; pthread_mutex_unlock(&htable->update_mutex); diff --git a/test/maat_ex_data_gtest.cpp b/test/maat_ex_data_gtest.cpp index 6ae78cc..84e2848 100644 --- a/test/maat_ex_data_gtest.cpp +++ b/test/maat_ex_data_gtest.cpp @@ -15,10 +15,9 @@ struct log_handle *g_logger = NULL; struct maat *g_maat_inst = NULL; struct user_info { - char name[256]; + char name[16]; char ip_addr[32]; int id; - int ref_cnt; }; void ex_data_new_cb(const char *table_name, int table_id, const char *key, const char *table_line, @@ -26,10 +25,10 @@ void ex_data_new_cb(const char *table_name, int table_id, const char *key, const { int *counter = (int *)argp; struct user_info *u = ALLOC(struct user_info, 1); - int valid = 0, tag = 0; - int ret = sscanf(table_line, "%d\t%s\t%s%d\t%d", &(u->id), u->ip_addr, u->name, &valid, &tag); - EXPECT_EQ(ret, 5); - u->ref_cnt = 0; + + int ret = sscanf(table_line, "%d\t%s\t%s", &(u->id), u->ip_addr, u->name); + EXPECT_EQ(ret, 3); + *ad = u; (*counter)++; } @@ -37,19 +36,15 @@ void ex_data_new_cb(const char *table_name, int table_id, const char *key, const void ex_data_free_cb(int table_id, void **ad, long argl, void *argp) { struct user_info *u = (struct user_info *)(*ad); - if ((__sync_sub_and_fetch(&u->ref_cnt, 1) == 0)) { - printf("yes, free(u)\n"); - free(u); - *ad = NULL; - } else { - printf("u->ref_cnt:%d\n", u->ref_cnt); - } + + memset(u, 0, sizeof(struct user_info)); + free(u); + *ad = NULL; } void ex_data_dup_cb(int table_id, void **to, void **from, long argl, void *argp) { struct user_info *u = (struct user_info *)(*from); - __sync_add_and_fetch(&(u->ref_cnt), 1); *to = u; } @@ -59,7 +54,7 @@ TEST(EXDataRuntime, Update) { ASSERT_GT(table_id, 0); int ex_data_counter = 0; - struct ex_data_runtime *ex_data_rt = ex_data_runtime_new(table_id, g_logger); + struct ex_data_runtime *ex_data_rt = ex_data_runtime_new(table_id, 3, g_logger); struct ex_container_schema *container_schema = ALLOC(struct ex_container_schema, 1); container_schema->custom_data_free = NULL; container_schema->table_id = table_id; @@ -72,7 +67,7 @@ TEST(EXDataRuntime, Update) { ex_data_runtime_set_ex_container_schema(ex_data_rt, container_schema); - const char *row1 = "1\t192.168.0.1\tmahuateng\t1\t0"; + const char *row1 = "101\t192.168.0.1\tmahuateng"; const char *key1 = "192.168.0.1"; size_t key1_len = strlen(key1); void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, table_name, row1, key1, key1_len); @@ -82,7 +77,7 @@ TEST(EXDataRuntime, Update) { int ret = ex_data_runtime_add_ex_container(ex_data_rt, key1, key1_len, ex_container); EXPECT_EQ(ret, 0); - const char *row2 = "2\t192.168.0.2\tliyanhong\t1\t0"; + const char *row2 = "102\t192.168.0.2\tliyanhong"; const char *key2 = "192.168.0.2"; size_t key2_len = strlen(key2); ex_data = ex_data_runtime_row2ex_data(ex_data_rt, table_name, row2, key2, key2_len); @@ -92,22 +87,35 @@ TEST(EXDataRuntime, Update) { ex_data_runtime_commit(ex_data_rt); - void *res_data1 = ex_data_runtime_get_ex_data_by_key(ex_data_rt, "192.168.0.1", 11); + void *res_data1 = ex_data_runtime_get_ex_data_by_key(ex_data_rt, key1, key1_len); EXPECT_TRUE(res_data1 != NULL); - struct user_info *info = (struct user_info *)res_data1; - EXPECT_EQ(0, strcmp(info->name, "mahuateng")); - EXPECT_EQ(info->id, 1); - ex_data_free_cb(table_id, (void **)&res_data1, 0, NULL); + struct user_info *info1 = (struct user_info *)res_data1; + EXPECT_EQ(0, strcmp(info1->name, "mahuateng")); + EXPECT_EQ(info1->id, 101); ex_container = NULL; - void *res_data2 = ex_data_runtime_get_ex_data_by_key(ex_data_rt, "192.168.0.2", 11); + void *res_data2 = ex_data_runtime_get_ex_data_by_key(ex_data_rt, key2, key2_len); EXPECT_TRUE(res_data2 != NULL); - info = (struct user_info *)res_data2; - EXPECT_EQ(0, strcmp(info->name, "liyanhong")); - EXPECT_EQ(info->id, 2); - ex_data_free_cb(table_id, (void **)&res_data2, 0, NULL); + struct user_info *info2 = (struct user_info *)res_data2; + EXPECT_EQ(0, strcmp(info2->name, "liyanhong")); + EXPECT_EQ(info2->id, 102); + + ex_data_runtime_del_ex_container(ex_data_rt, key1, key1_len); + ex_data_runtime_commit(ex_data_rt); + + EXPECT_EQ(0, strcmp(info1->name, "mahuateng")); + EXPECT_EQ(info1->id, 101); + + sleep(5); + ex_data_runtime_garbage_collect_routine(ex_data_rt); + + EXPECT_EQ(0, strcmp(info2->name, "liyanhong")); + EXPECT_EQ(info2->id, 102); + + EXPECT_NE(0, strcmp(info1->name, "mahuateng")); + EXPECT_NE(info1->id, 101); ex_data_runtime_free(ex_data_rt); FREE(container_schema); diff --git a/test/maat_framework_gtest.cpp b/test/maat_framework_gtest.cpp index efb5567..d2c0ee5 100644 --- a/test/maat_framework_gtest.cpp +++ b/test/maat_framework_gtest.cpp @@ -2445,7 +2445,6 @@ TEST_F(ExcludeLogic, ScanNotIP) { void maat_read_entry_start_cb(int update_type, void *u_para) { - } void maat_read_entry_cb(int table_id, const char *table_line, void *u_para) @@ -2459,25 +2458,13 @@ void maat_read_entry_cb(int table_id, const char *table_line, void *u_para) sscanf(table_line, "%d\t%s\t%d\t%d", &seq,ip_str, &entry_id, &is_valid); inet_pton(AF_INET, ip_str, &ip_uint); if (local_ip_nr == ip_uint) { - if (is_valid == 1) { - //printf("Load entry id %d success.\n",entry_id); - EXPECT_EQ(entry_id, 101); - } else { - //printf("Offload entry id %d success.\n",entry_id); - } + EXPECT_EQ(is_valid, 1); + EXPECT_EQ(entry_id, 101); } } void maat_read_entry_finish_cb(void *u_para) { - //Maat_feather_t feather=u_para; - // long long version=0; - // int ret=0,is_last_updating_table=0; - // ret=Maat_read_state(feather,MAAT_STATE_VERSION, &version, sizeof(version)); - // EXPECT_EQ(ret, 0); - // ret=Maat_read_state(feather,MAAT_STATE_LAST_UPDATING_TABLE, &is_last_updating_table, sizeof(is_last_updating_table)); - // EXPECT_EQ(ret, 0); - //printf("Maat Version %lld at plugin finish callback, is_last_update=%d.\n",version,is_last_updating_table); } class PluginTable : public testing::Test @@ -2537,10 +2524,9 @@ TEST_F(PluginTable, Callback) { } struct plugin_ud { - char key[256]; - char value[256]; + char key[32]; + char value[32]; int id; - int ref_cnt; }; void plugin_EX_new_cb(const char *table_name, int table_id, const char *key, @@ -2552,7 +2538,7 @@ void plugin_EX_new_cb(const char *table_name, int table_id, const char *key, int ret = sscanf(table_line, "%d\t%s\t%s\t%d\t%d", &(ud->id), ud->key, ud->value, &valid, &tag); EXPECT_EQ(ret, 5); - ud->ref_cnt = 1; + *ad = ud; (*counter)++; } @@ -2560,16 +2546,16 @@ void plugin_EX_new_cb(const char *table_name, int table_id, const char *key, void plugin_EX_free_cb(int table_id, void **ad, long argl, void *argp) { struct plugin_ud *ud = (struct plugin_ud *)(*ad); - if ((__sync_sub_and_fetch(&ud->ref_cnt, 1) == 0)) { - free(ud); - *ad = NULL; - } + + memset(ud, 0, sizeof(struct plugin_ud)); + free(ud); + *ad = NULL; } void plugin_EX_dup_cb(int table_id, void **to, void **from, long argl, void *argp) { struct plugin_ud *ud = (struct plugin_ud *)(*from); - __sync_add_and_fetch(&(ud->ref_cnt), 1); + *to = ud; } @@ -2596,7 +2582,6 @@ TEST_F(PluginTable, EX_DATA) { ASSERT_TRUE(ud != NULL); EXPECT_STREQ(ud->value, "Shijiazhuang"); EXPECT_EQ(ud->id, 1); - plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL); const char *key2 = "ShanDong"; ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_inst, table_id, @@ -2604,7 +2589,6 @@ TEST_F(PluginTable, EX_DATA) { ASSERT_TRUE(ud != NULL); EXPECT_STREQ(ud->value, "Jinan"); EXPECT_EQ(ud->id, 3); - plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL); } TEST_F(PluginTable, LONG_KEY_TYPE) { @@ -2630,7 +2614,6 @@ TEST_F(PluginTable, LONG_KEY_TYPE) { ASSERT_TRUE(ud != NULL); EXPECT_STREQ(ud->value, "Shijiazhuang"); EXPECT_EQ(ud->id, 1); - plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL); long long key2 = 33333333; ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_inst, table_id, @@ -2638,7 +2621,6 @@ TEST_F(PluginTable, LONG_KEY_TYPE) { ASSERT_TRUE(ud != NULL); EXPECT_STREQ(ud->value, "Jinan"); EXPECT_EQ(ud->id, 3); - plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL); int key3 = 22222222; ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_inst, table_id, @@ -2669,7 +2651,6 @@ TEST_F(PluginTable, INT_KEY_TYPE) { ASSERT_TRUE(ud != NULL); EXPECT_STREQ(ud->value, "China"); EXPECT_EQ(ud->id, 1); - plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL); int key2 = 102; ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_inst, table_id, @@ -2677,7 +2658,6 @@ TEST_F(PluginTable, INT_KEY_TYPE) { ASSERT_TRUE(ud != NULL); EXPECT_STREQ(ud->value, "America"); EXPECT_EQ(ud->id, 2); - plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL); long long key3 = 103; ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_inst, table_id, @@ -2711,7 +2691,6 @@ TEST_F(PluginTable, IP_KEY_TYPE) { ASSERT_TRUE(ud != NULL); EXPECT_STREQ(ud->value, "XiZang"); EXPECT_EQ(ud->id, 4); - plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL); uint32_t ipv4_addr2; ret = inet_pton(AF_INET, "100.64.1.2", &ipv4_addr2); @@ -2722,7 +2701,6 @@ TEST_F(PluginTable, IP_KEY_TYPE) { ASSERT_TRUE(ud != NULL); EXPECT_STREQ(ud->value, "XinJiang"); EXPECT_EQ(ud->id, 4); - plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL); uint8_t ipv6_addr1[16]; ret = inet_pton(AF_INET6, "2001:da8:205:1::101", ipv6_addr1); @@ -2733,7 +2711,6 @@ TEST_F(PluginTable, IP_KEY_TYPE) { ASSERT_TRUE(ud != NULL); EXPECT_STREQ(ud->value, "GuiZhou"); EXPECT_EQ(ud->id, 6); - plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL); uint8_t ipv6_addr2[16]; ret = inet_pton(AF_INET6, "1001:da8:205:1::101", ipv6_addr2); @@ -2744,7 +2721,6 @@ TEST_F(PluginTable, IP_KEY_TYPE) { ASSERT_TRUE(ud != NULL); EXPECT_STREQ(ud->value, "SiChuan"); EXPECT_EQ(ud->id, 6); - plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL); } class IPPluginTable : public testing::Test @@ -2793,7 +2769,7 @@ struct log_handle *IPPluginTable::logger; struct ip_plugin_ud { long long rule_id; char *buffer; - int ref_cnt; + size_t buf_len; }; void ip_plugin_ex_new_cb(const char *table_name, int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp) @@ -2812,7 +2788,8 @@ void ip_plugin_ex_new_cb(const char *table_name, int table_id, const char *key, ud->buffer = ALLOC(char, column_len + 1); strncpy(ud->buffer, table_line + column_offset, column_len); - ud->ref_cnt = 1; + + ud->buf_len = column_len + 1; *ad = ud; (*counter)++; } @@ -2820,17 +2797,17 @@ void ip_plugin_ex_new_cb(const char *table_name, int table_id, const char *key, void ip_plugin_ex_free_cb(int table_id, void **ad, long argl, void *argp) { struct ip_plugin_ud *ud = (struct ip_plugin_ud *)(*ad); - if ((__sync_sub_and_fetch(&ud->ref_cnt, 1) == 0)) { - free(ud->buffer); - free(ud); - *ad = NULL; - } + + memset(ud->buffer, 0, ud->buf_len); + free(ud->buffer); + free(ud); + *ad = NULL; } void ip_plugin_ex_dup_cb(int table_id, void **to, void **from, long argl, void *argp) { struct ip_plugin_ud *ud = (struct ip_plugin_ud *)(*from); - __sync_add_and_fetch(&(ud->ref_cnt), 1); + *to = ud; } @@ -2862,11 +2839,6 @@ TEST_F(IPPluginTable, EX_DATA) { EXPECT_EQ(results[0]->rule_id, 101); EXPECT_EQ(results[1]->rule_id, 102); - int i = 0; - for (i = 0; i < ret; i++) { - ip_plugin_ex_free_cb(0, (void**)&(results[i]), 0, NULL); - } - struct ip_addr ipv6; ipv6.ip_type = IPv6; inet_pton(AF_INET6, "2001:db8:1234::5210", &(ipv6.ipv6)); @@ -2878,10 +2850,6 @@ TEST_F(IPPluginTable, EX_DATA) { EXPECT_EQ(results[0]->rule_id, 104); EXPECT_EQ(results[1]->rule_id, 103); - for (i = 0; i < ret; i++) { - ip_plugin_ex_free_cb(0, (void**)&(results[i]), 0, NULL); - } - //Reproduce BugReport-Liumengyan-20210515 inet_pton(AF_INET6, "240e:97c:4010:104::17", &(ipv6.ipv6)); ret = maat_ip_plugin_table_get_ex_data(maat_inst, table_id, &ipv6, @@ -2937,7 +2905,6 @@ struct fqdn_plugin_ud { int rule_id; int catid; - int ref_cnt; }; void fqdn_plugin_ex_new_cb(const char *table_name, int table_id, const char *key, @@ -2955,7 +2922,7 @@ void fqdn_plugin_ex_new_cb(const char *table_name, int table_id, const char *key EXPECT_EQ(ret, 0); sscanf(table_line + column_offset, "catid=%d", &ud->catid); - ud->ref_cnt = 1; + *ad = ud; (*counter)++; } @@ -2963,16 +2930,15 @@ void fqdn_plugin_ex_new_cb(const char *table_name, int table_id, const char *key void fqdn_plugin_ex_free_cb(int table_id, void **ad, long argl, void *argp) { struct fqdn_plugin_ud *u = (struct fqdn_plugin_ud *)(*ad); - if ((__sync_sub_and_fetch(&u->ref_cnt, 1) == 0)) { - free(u); - *ad = NULL; - } + + free(u); + *ad = NULL; } void fqdn_plugin_ex_dup_cb(int table_id, void **to, void **from, long argl, void *argp) { struct fqdn_plugin_ud *u = (struct fqdn_plugin_ud *)(*from); - __sync_add_and_fetch(&(u->ref_cnt), 1); + *to = u; } @@ -2992,7 +2958,6 @@ TEST_F(FQDNPluginTable, EX_DATA) { ASSERT_TRUE(ret>=0); EXPECT_EQ(fqdn_plugin_ex_data_counter, 5); - int i = 0; struct fqdn_plugin_ud *result[4]; ret = maat_fqdn_plugin_table_get_ex_data(maat_inst, table_id, "www.example1.com", (void**)result, 4); @@ -3000,26 +2965,18 @@ TEST_F(FQDNPluginTable, EX_DATA) { EXPECT_EQ(result[0]->rule_id, 201); EXPECT_EQ(result[1]->rule_id, 202); - for (i = 0; i < ret; i++) { - fqdn_plugin_ex_free_cb(0, (void**)&(result[i]), 0, NULL); - } - ret = maat_fqdn_plugin_table_get_ex_data(maat_inst, table_id, "www.example3.com", (void**)result, 4); EXPECT_EQ(ret, 0); ret = maat_fqdn_plugin_table_get_ex_data(maat_inst, table_id, "r3---sn-i3belne6.example2.com", (void**)result, 4); ASSERT_EQ(ret, 2); EXPECT_TRUE(result[0]->rule_id == 205 || result[0]->rule_id == 204); - - for (i = 0; i < ret; i++) { - fqdn_plugin_ex_free_cb(0, (void**)&(result[i]), 0, NULL); - } } struct bool_plugin_ud { int id; char *name; - int ref_cnt; + size_t name_len; }; void bool_plugin_ex_new_cb(const char *table_name, int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp) @@ -3037,24 +2994,25 @@ void bool_plugin_ex_new_cb(const char *table_name, int table_id, const char *key ud->name = ALLOC(char, column_len+1); memcpy(ud->name, table_line+column_offset, column_len); - ud->ref_cnt = 1; + ud->name_len = column_len + 1; + *ad = ud; (*counter)++; } void bool_plugin_ex_free_cb(int table_id, void **ad, long argl, void *argp) { struct bool_plugin_ud *u = (struct bool_plugin_ud *)(*ad); - if ((__sync_sub_and_fetch(&u->ref_cnt, 1) == 0)) - { - free(u->name); - free(u); - *ad = NULL; - } + + memset(u->name, 0, u->name_len); + free(u->name); + free(u); + *ad = NULL; + } void bool_plugin_ex_dup_cb(int table_id, void **to, void **from, long argl, void *argp) { struct bool_plugin_ud *u = (struct bool_plugin_ud *)(*from); - __sync_add_and_fetch(&(u->ref_cnt), 1); + *to = u; } @@ -3102,7 +3060,7 @@ struct maat *BoolPluginTable::_shared_maat_inst; struct log_handle *BoolPluginTable::logger; TEST_F(BoolPluginTable, EX_DATA) { - int ex_data_counter = 0, i = 0; + int ex_data_counter = 0; const char *table_name = "TEST_BOOL_PLUGIN_WITH_EXDATA"; struct maat *maat_inst = BoolPluginTable::_shared_maat_inst; @@ -3122,26 +3080,17 @@ TEST_F(BoolPluginTable, EX_DATA) { ret = maat_bool_plugin_table_get_ex_data(maat_inst, table_id, items_1, 1, (void**)result, 6); EXPECT_EQ(ret, 0); - for (i = 0; i < ret; i++) { - bool_plugin_ex_free_cb(0, (void**)&(result[i]), 0, NULL); - } unsigned long long items_2[] = {1, 2, 1000}; ret = maat_bool_plugin_table_get_ex_data(maat_inst, table_id, items_2, 3, (void**)result, 6); EXPECT_EQ(ret, 1); EXPECT_EQ(result[0]->id, 301); - for (i = 0; i < ret; i++) { - bool_plugin_ex_free_cb(0, (void**)&(result[i]), 0, NULL); - } unsigned long long items_3[]={101, 102, 1000}; ret = maat_bool_plugin_table_get_ex_data(maat_inst, table_id, items_3, 3, (void**)result, 6); EXPECT_EQ(ret, 4); - for (i = 0; i < ret; i++) { - bool_plugin_ex_free_cb(0, (void**)&(result[i]), 0, NULL); - } unsigned long long items_4[]={7, 0, 1, 2, 3, 4, 5, 6, 7, 7, 7}; ret = maat_bool_plugin_table_get_ex_data(maat_inst, table_id, items_4, @@ -3149,9 +3098,6 @@ TEST_F(BoolPluginTable, EX_DATA) { (void**)result, 6); EXPECT_EQ(ret, 1); EXPECT_EQ(result[0]->id, 305); - for (i = 0; i < ret; i++) { - bool_plugin_ex_free_cb(0, (void**)&(result[i]), 0, NULL); - } } class VirtualTable : public testing::Test @@ -3260,10 +3206,8 @@ struct maat *CompileTable::_shared_maat_inst; struct log_handle *CompileTable::logger; struct rule_ex_param { - int ref_cnt; char name[NAME_MAX]; int id; - pthread_mutex_t lock; }; void compile_ex_param_new(const char *table_name, int table_id, const char *key, @@ -3272,9 +3216,7 @@ void compile_ex_param_new(const char *table_name, int table_id, const char *key, int *counter = (int *)argp; *ad = NULL; - struct rule_ex_param *param = (struct rule_ex_param *)calloc(sizeof(struct rule_ex_param), 1); - param->ref_cnt = 1; - pthread_mutex_init(&(param->lock), NULL); + struct rule_ex_param *param = ALLOC(struct rule_ex_param, 1); int compile_id = 0; int service_id = 0; @@ -3298,21 +3240,14 @@ void compile_ex_param_free(int table_id, void **ad, long argl, void *argp) } struct rule_ex_param *param = (struct rule_ex_param *)*ad; - pthread_mutex_lock(&(param->lock)); - param->ref_cnt--; - if (param->ref_cnt > 0) { - pthread_mutex_unlock(&(param->lock)); - return; - } + free(param); } void compile_ex_param_dup(int table_id, void **to, void **from, long argl, void *argp) { struct rule_ex_param *from_param = *((struct rule_ex_param **)from); - pthread_mutex_lock(&(from_param->lock)); - from_param->ref_cnt++; - pthread_mutex_unlock(&(from_param->lock)); + *((struct rule_ex_param**)to) = from_param; } @@ -3321,11 +3256,13 @@ TEST_F(CompileTable, CompileRuleUpdate) { const char *compile_table_name = "COMPILE"; long long compile_id = maat_cmd_incrby(maat_inst, "TEST_SEQ", 1); - int ret = compile_table_set_line(maat_inst, compile_table_name, MAAT_OP_ADD, compile_id, "null", 1, 0); + int ret = compile_table_set_line(maat_inst, compile_table_name, + MAAT_OP_ADD, compile_id, "null", 1, 0); EXPECT_EQ(ret, 1); sleep(WAIT_FOR_EFFECTIVE_S); - ret = compile_table_set_line(maat_inst, compile_table_name, MAAT_OP_DEL, compile_id, "null", 1, 0); + ret = compile_table_set_line(maat_inst, compile_table_name, + MAAT_OP_DEL, compile_id, "null", 1, 0); EXPECT_EQ(ret, 1); sleep(WAIT_FOR_EFFECTIVE_S); } @@ -3397,7 +3334,8 @@ class Policy : public testing::Test { protected: static void SetUpTestCase() { - const char *accept_tags = "{\"tags\":[{\"tag\":\"location\",\"value\":\"北京/朝阳/华严北里/甲22号\"},{\"tag\":\"isp\",\"value\":\"移动\"},{\"tag\":\"location\",\"value\":\"Astana\"}]}"; + const char *accept_tags = "{\"tags\":[{\"tag\":\"location\",\"value\":\"北京/朝阳/华严北里/甲22号\"}," + "{\"tag\":\"isp\",\"value\":\"移动\"},{\"tag\":\"location\",\"value\":\"Astana\"}]}"; char redis_ip[64] = "127.0.0.1"; int redis_port = 6379; int redis_db = 0; @@ -3554,7 +3492,6 @@ TEST_F(Policy, CompileEXData) { str_unescape(param->name); EXPECT_EQ(strcmp(param->name, expect_name), 0); - compile_ex_param_free(compile_table_id, &ex_data, 0, NULL); maat_state_free(state); state = NULL; @@ -4930,17 +4867,16 @@ struct user_info { char name[256]; char ip_addr[32]; int id; - int ref_cnt; }; void plugin_ex_new_cb(const char *table_name, int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp) { int *counter = (int *)argp; struct user_info *u = ALLOC(struct user_info, 1); - int valid = 0, tag = 0; - int ret = sscanf(table_line, "%d\t%s\t%s%d\t%d", &(u->id), u->ip_addr, u->name, &valid, &tag); - EXPECT_EQ(ret, 5); - u->ref_cnt = 1; + + int ret = sscanf(table_line, "%d\t%s\t%s", &(u->id), u->ip_addr, u->name); + EXPECT_EQ(ret, 3); + *ad = u; (*counter)++; } @@ -4948,16 +4884,16 @@ void plugin_ex_new_cb(const char *table_name, int table_id, const char *key, void plugin_ex_free_cb(int table_id, void **ad, long argl, void *argp) { struct user_info *u = (struct user_info *)(*ad); - if ((__sync_sub_and_fetch(&u->ref_cnt, 1) == 0)) { - free(u); - *ad = NULL; - } + + memset(u, 0, sizeof(struct user_info)); + free(u); + *ad = NULL; } void plugin_ex_dup_cb(int table_id, void **to, void **from, long argl, void *argp) { struct user_info *u = (struct user_info *)(*from); - __sync_add_and_fetch(&(u->ref_cnt), 1); + *to = u; } @@ -4966,15 +4902,19 @@ TEST_F(MaatCmdTest, PluginEXData) { const int TEST_CMD_LINE_NUM = 4; struct maat *maat_inst = MaatCmdTest::_shared_maat_inst; int *ex_data_counter = MaatCmdTest::_ex_data_counter; - const char *table_line_add[TEST_CMD_LINE_NUM] = {"1\t192.168.0.1\tmahuateng\t1\t0", - "2\t192.168.0.2\tliuqiangdong\t1\t0", - "3\t192.168.0.3\tmayun\t1\t0", - "4\t192.168.0.4\tliyanhong\t1\t0"}; + const char *table_line_add[TEST_CMD_LINE_NUM] = { + "1\t192.168.0.1\tmahuateng\t1\t0", + "2\t192.168.0.2\tliuqiangdong\t1\t0", + "3\t192.168.0.3\tmayun\t1\t0", + "4\t192.168.0.4\tliyanhong\t1\t0" + }; - const char *table_line_del[TEST_CMD_LINE_NUM] = {"1\t192.168.0.1\tmahuateng\t0\t0", - "2\t192.168.0.2\tliuqiangdong\t0\t0", - "3\t192.168.0.3\tmayun\t0\t0", - "4\t192.168.0.4\tliyanhong\t0\t0"}; + const char *table_line_del[TEST_CMD_LINE_NUM] = { + "1\t192.168.0.1\tmahuateng\t0\t0", + "2\t192.168.0.2\tliuqiangdong\t0\t0", + "3\t192.168.0.3\tmayun\t0\t0", + "4\t192.168.0.4\tliyanhong\t0\t0" + }; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -4996,6 +4936,7 @@ TEST_F(MaatCmdTest, PluginEXData) { } sleep(WAIT_FOR_EFFECTIVE_S); + *ex_data_counter = 0; ret = maat_plugin_table_ex_schema_register(maat_inst, table_name, plugin_ex_new_cb, @@ -5005,14 +4946,14 @@ TEST_F(MaatCmdTest, PluginEXData) { ASSERT_TRUE(ret >= 0); EXPECT_EQ(*ex_data_counter, TEST_CMD_LINE_NUM); - struct user_info *uinfo = NULL; + struct user_info *uinfo1 = NULL; const char *key1 = "192.168.0.2"; - uinfo = (struct user_info *)maat_plugin_table_get_ex_data(maat_inst, table_id, - key1, strlen(key1)); - ASSERT_TRUE(uinfo != NULL); - EXPECT_EQ(0, strcmp(uinfo->name, "liuqiangdong")); - EXPECT_EQ(uinfo->id, 2); - plugin_ex_free_cb(table_id, (void**)&uinfo, 0, NULL); + + uinfo1 = (struct user_info *)maat_plugin_table_get_ex_data(maat_inst, table_id, + key1, strlen(key1)); + ASSERT_TRUE(uinfo1 != NULL); + EXPECT_EQ(0, strcmp(uinfo1->name, "liuqiangdong")); + EXPECT_EQ(uinfo1->id, 2); memset(&line_rule, 0, sizeof(line_rule)); line_rule.rule_id = rule_id[1]; @@ -5023,11 +4964,19 @@ TEST_F(MaatCmdTest, PluginEXData) { ret = maat_cmd_set_line(maat_inst, &line_rule); EXPECT_GT(ret, 0); - sleep(WAIT_FOR_EFFECTIVE_S); - const char *key2 = "192.168.0.2"; - uinfo = (struct user_info *)maat_plugin_table_get_ex_data(maat_inst, table_id, - key2, strlen(key2)); - ASSERT_TRUE(uinfo == NULL); + sleep(WAIT_FOR_EFFECTIVE_S); //gc_timeout_s == 3 which configured in table_info + + struct user_info *uinfo2 = NULL; + uinfo2 = (struct user_info *)maat_plugin_table_get_ex_data(maat_inst, table_id, + key1, strlen(key1)); + ASSERT_TRUE(uinfo2 == NULL); + + //the data pointed by uinfo1 has in garbage queue, but not be freed yet + EXPECT_EQ(0, strcmp(uinfo1->name, "liuqiangdong")); + EXPECT_EQ(uinfo1->id, 2); + + sleep(WAIT_FOR_EFFECTIVE_S * 2); + //excced gc_timeout_s, the data pointed by uinfo1 has been freed } TEST_F(MaatCmdTest, UpdateIPPlugin) { @@ -5087,9 +5036,6 @@ TEST_F(MaatCmdTest, UpdateIPPlugin) { EXPECT_EQ(ret, 2); EXPECT_EQ(results[0]->rule_id, 101); EXPECT_EQ(results[1]->rule_id, 102); - for (i = 0; i < ret; i++) { - ip_plugin_ex_free_cb(table_id, (void **)&(results[i]), 0, NULL); - } ipv6.ip_type = 6; inet_pton(AF_INET6, "2001:db8:1234::5210", &(ipv6.ipv6)); @@ -5100,9 +5046,6 @@ TEST_F(MaatCmdTest, UpdateIPPlugin) { EXPECT_EQ(ret, 2); EXPECT_EQ(results[0]->rule_id, 104); EXPECT_EQ(results[1]->rule_id, 103); - for (i = 0; i < ret; i++) { - ip_plugin_ex_free_cb(table_id, (void **)&(results[i]), 0, NULL); - } //del lines for (i = 0; i < TEST_CMD_LINE_NUM; i++) { @@ -5179,9 +5122,6 @@ TEST_F(MaatCmdTest, UpdateFQDNPlugin) { "r3---sn-i3belne6.example2.com", (void**)results, ARRAY_SIZE); ASSERT_EQ(ret, 2); - for (i = 0; i < ret; i++) { - fqdn_plugin_ex_free_cb(0, (void**)&(results[i]), 0, NULL); - } //del lines for (i = 3; i < TEST_CMD_LINE_NUM; i++) { @@ -5258,9 +5198,6 @@ TEST_F(MaatCmdTest, UpdateBoolPlugin) { ret = maat_bool_plugin_table_get_ex_data(maat_inst, table_id, items, 3, (void **)results, ARRAY_SIZE); EXPECT_EQ(ret, 4); - for (i = 0; i < ret; i++) { - bool_plugin_ex_free_cb(0, (void**)&(results[i]), 0, NULL); - } for (i = 3; i < TEST_CMD_LINE_NUM; i++) { memset(&line_rule, 0, sizeof(line_rule)); @@ -5278,9 +5215,6 @@ TEST_F(MaatCmdTest, UpdateBoolPlugin) { ret = maat_bool_plugin_table_get_ex_data(maat_inst, table_id, items, 3, (void **)results, ARRAY_SIZE); EXPECT_EQ(ret, 2); - for (i = 0; i < ret; i++) { - bool_plugin_ex_free_cb(0, (void**)&(results[i]), 0, NULL); - } } #define COMPILE_ID_NUMS 1000 diff --git a/test/maat_framework_perf_gtest.cpp b/test/maat_framework_perf_gtest.cpp index 2b3d378..34a2ebd 100644 --- a/test/maat_framework_perf_gtest.cpp +++ b/test/maat_framework_perf_gtest.cpp @@ -804,7 +804,6 @@ struct log_handle *MaatPerfFQDNPluginScan::logger; struct perf_fqdn_plugin_ud { long long rule_id; int catid; - int ref_cnt; }; void perf_fqdn_plugin_EX_new_cb(const char *table_name, int table_id, const char *key, @@ -822,7 +821,7 @@ void perf_fqdn_plugin_EX_new_cb(const char *table_name, int table_id, const char EXPECT_EQ(ret, 0); sscanf(table_line+column_offset, "catid=%d",&ud->catid); - ud->ref_cnt = 1; + *ad = ud; (*counter)++; } @@ -830,16 +829,15 @@ void perf_fqdn_plugin_EX_new_cb(const char *table_name, int table_id, const char void perf_fqdn_plugin_EX_free_cb(int table_id, void **ad, long argl, void *argp) { struct perf_fqdn_plugin_ud *u = (struct perf_fqdn_plugin_ud *)(*ad); - if ((__sync_sub_and_fetch(&u->ref_cnt, 1) == 0)) { - free(u); - *ad = NULL; - } + + free(u); + *ad = NULL; } void perf_fqdn_plugin_EX_dup_cb(int table_id, void **to, void **from, long argl, void *argp) { struct perf_fqdn_plugin_ud *u = (struct perf_fqdn_plugin_ud *)(*from); - __sync_add_and_fetch(&(u->ref_cnt), 1); + *to = u; } @@ -1034,8 +1032,8 @@ struct log_handle *MaatPerfBoolPluginScan::logger; struct bool_plugin_ud { int id; char *name; - int ref_cnt; }; + void perf_bool_plugin_ex_new_cb(const char *table_name, int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp) { @@ -1052,24 +1050,24 @@ void perf_bool_plugin_ex_new_cb(const char *table_name, int table_id, const char ud->name = (char *)malloc(column_len+1); memcpy(ud->name, table_line+column_offset, column_len); - ud->ref_cnt = 1; + *ad = ud; (*counter)++; } + void perf_bool_plugin_ex_free_cb(int table_id, void **ad, long argl, void *argp) { struct bool_plugin_ud *u = (struct bool_plugin_ud *)(*ad); - if ((__sync_sub_and_fetch(&u->ref_cnt, 1) == 0)) - { - free(u->name); - free(u); - *ad = NULL; - } + + free(u->name); + free(u); + *ad = NULL; } + void perf_bool_plugin_ex_dup_cb(int table_id, void **to, void **from, long argl, void *argp) { struct bool_plugin_ud *u = (struct bool_plugin_ud *)(*from); - __sync_add_and_fetch(&(u->ref_cnt), 1); + *to = u; } @@ -1231,7 +1229,6 @@ struct log_handle *MaatPerfFileScan::logger; struct perf_ip_plugin_ud { long long rule_id; - int ref_cnt; }; void perf_ip_plugin_EX_new_cb(const char *table_name, int table_id, const char *key, @@ -1248,7 +1245,6 @@ void perf_ip_plugin_EX_new_cb(const char *table_name, int table_id, const char * ret = maat_helper_read_column(table_line, 5, &column_offset, &column_len); EXPECT_EQ(ret, 0); - ud->ref_cnt = 1; *ad = ud; (*counter)++; } @@ -1256,16 +1252,15 @@ void perf_ip_plugin_EX_new_cb(const char *table_name, int table_id, const char * void perf_ip_plugin_EX_free_cb(int table_id, void **ad, long argl, void *argp) { struct perf_ip_plugin_ud *u = (struct perf_ip_plugin_ud*)(*ad); - if ((__sync_sub_and_fetch(&u->ref_cnt, 1) == 0)) { - free(u); - *ad = NULL; - } + + free(u); + *ad = NULL; } void perf_ip_plugin_EX_dup_cb(int table_id, void **to, void **from, long argl, void *argp) { struct perf_ip_plugin_ud *u = (struct perf_ip_plugin_ud*)(*from); - __sync_add_and_fetch(&(u->ref_cnt), 1); + *to = u; } diff --git a/test/maat_json.json b/test/maat_json.json index 18de689..142487e 100644 --- a/test/maat_json.json +++ b/test/maat_json.json @@ -2949,8 +2949,8 @@ "table_name": "QD_ENTRY_INFO", "table_content": [ "1\t192.168.0.1\t101\t1", - "2\t192.168.0.2\t101\t1", - "3\t192.168.1.1\t102\t1" + "2\t192.168.0.2\t102\t1", + "3\t192.168.1.1\t103\t1" ] }, { diff --git a/test/rcu_hash_gtest.cpp b/test/rcu_hash_gtest.cpp index 96fa7a5..221da3e 100644 --- a/test/rcu_hash_gtest.cpp +++ b/test/rcu_hash_gtest.cpp @@ -16,13 +16,13 @@ void data_free(void *user_ctx, void *data) } TEST(rcu_hash_new, invalid_input_parameter) { - struct rcu_hash_table *htable = rcu_hash_new(NULL, NULL); + struct rcu_hash_table *htable = rcu_hash_new(NULL, NULL, 0); EXPECT_TRUE(htable == NULL); } TEST(rcu_hash_add_one_node, single_thread) { /* add one node to hash */ - struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL); + struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL, 0); EXPECT_TRUE(htable != NULL); struct user_data *data = ALLOC(struct user_data, 1); @@ -69,7 +69,7 @@ TEST(rcu_hash_add_one_node, single_thread) { TEST(rcu_hash_add_multi_node, single_thread) { /* add multi node to hash */ - struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL); + struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL, 0); EXPECT_TRUE(htable != NULL); struct user_data *data0 = ALLOC(struct user_data, 1); @@ -163,7 +163,7 @@ TEST(rcu_hash_add_multi_node, single_thread) { TEST(rcu_hash_del_one_node, single_thread) { /* case1: add and del before commit */ - struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL); + struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL, 0); EXPECT_TRUE(htable != NULL); struct user_data *data = ALLOC(struct user_data, 1); @@ -243,7 +243,7 @@ TEST(rcu_hash_del_one_node, single_thread) { TEST(rcu_hash_del_multi_node, single_thread) { /* case1: add and del before commit */ - struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL); + struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL, 0); EXPECT_TRUE(htable != NULL); struct user_data *data1 = ALLOC(struct user_data, 1); @@ -288,7 +288,7 @@ TEST(rcu_hash_del_multi_node, single_thread) { } TEST(rcu_hash_add_with_same_key, single_thread) { - struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL); + struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL, 0); EXPECT_TRUE(htable != NULL); char key[64] = "http_url"; @@ -327,7 +327,7 @@ TEST(rcu_hash_add_with_same_key, single_thread) { } TEST(rcu_hash_del_with_same_key, single_thread) { - struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL); + struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL, 0); EXPECT_TRUE(htable != NULL); char key[64] = "http_url"; @@ -372,7 +372,7 @@ TEST(rcu_hash_del_with_same_key, single_thread) { } TEST(rcu_hash_modify_with_same_key, single_thread) { - struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL); + struct rcu_hash_table *htable = rcu_hash_new(data_free, NULL, 0); EXPECT_TRUE(htable != NULL); char key[64] = "http_url"; @@ -463,7 +463,7 @@ int main(int argc, char ** argv) int ret=0; ::testing::InitGoogleTest(&argc, argv); - g_htable = rcu_hash_new(data_free, NULL); + g_htable = rcu_hash_new(data_free, NULL, 0); ret=RUN_ALL_TESTS(); diff --git a/test/table_info.conf b/test/table_info.conf index dad4167..e677c10 100644 --- a/test/table_info.conf +++ b/test/table_info.conf @@ -6,6 +6,7 @@ "table_type":"compile", "valid_column":8, "custom": { + "gc_timeout_s": 3, "compile_id":1, "tags":6, "clause_num":9 @@ -32,6 +33,7 @@ "table_type":"compile", "valid_column":8, "custom": { + "gc_timeout_s": 3, "compile_id":1, "tags":6, "clause_num":9 @@ -191,6 +193,7 @@ "table_type":"plugin", "valid_column":4, "custom": { + "gc_timeout_s":3, "key_type":"pointer", "key":2, "tag":5 @@ -300,6 +303,7 @@ "table_type":"ip_plugin", "valid_column":6, "custom": { + "gc_timeout_s": 3, "item_id":1, "ip_type":2, "start_ip":3, @@ -372,6 +376,7 @@ "table_type":"fqdn_plugin", "valid_column":5, "custom": { + "gc_timeout_s": 3, "item_id":1, "suffix_match_method":2, "fqdn":3 @@ -421,6 +426,7 @@ "table_type":"bool_plugin", "valid_column":4, "custom": { + "gc_timeout_s": 3, "item_id":1, "bool_expr":2 }