[FEATURE]compile/plugin/xx_plugin table support gc

This commit is contained in:
刘文坛
2023-06-19 09:44:25 +00:00
parent 0b73681bd1
commit df36b8987b
22 changed files with 455 additions and 393 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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));

View File

@@ -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,

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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));

View File

@@ -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;

View File

@@ -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;

View File

@@ -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));

View File

@@ -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));

View File

@@ -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);
}

View File

@@ -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);