fix group_exclude logic miss & add some corner case
This commit is contained in:
@@ -283,7 +283,6 @@ void _maat_free(struct maat *maat_instance)
|
||||
|
||||
if (maat_instance->opts.accept_tags != NULL) {
|
||||
FREE(maat_instance->opts.accept_tags);
|
||||
maat_instance->opts.accept_tags = NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&(maat_instance->background_update_mutex));
|
||||
@@ -529,20 +528,21 @@ 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, argl, argp);
|
||||
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,
|
||||
@@ -720,18 +720,19 @@ int maat_plugin_table_ex_schema_register(struct maat *maat_instance,
|
||||
int ret = -1;
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr, table_id);
|
||||
if (TABLE_TYPE_COMPILE == table_type) {
|
||||
ret = compile_table_ex_schema_register(maat_instance, table_id,
|
||||
new_func, free_func, dup_func, argl, argp);
|
||||
ret = compile_table_ex_schema_register(maat_instance, table_id, new_func, free_func,
|
||||
dup_func, argl, argp);
|
||||
} else {
|
||||
ret = generic_plugin_table_ex_schema_register(maat_instance, table_name, table_id,
|
||||
new_func, free_func, dup_func, argl, argp);
|
||||
ret = generic_plugin_table_ex_schema_register(maat_instance, table_name, table_id, new_func,
|
||||
free_func, dup_func, argl, argp);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&(maat_instance->background_update_mutex));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *maat_plugin_table_get_ex_data(struct maat *maat_instance, int table_id, const char *key)
|
||||
void *maat_plugin_table_get_ex_data(struct maat *maat_instance, int table_id,
|
||||
const char *key)
|
||||
{
|
||||
|
||||
if (NULL == maat_instance || table_id < 0 || table_id >= MAX_TABLE_NUM
|
||||
@@ -768,7 +769,7 @@ void *maat_plugin_table_get_ex_data(struct maat *maat_instance, int table_id, co
|
||||
}
|
||||
|
||||
int maat_ip_plugin_table_get_ex_data(struct maat *maat_instance, int table_id,
|
||||
const struct ip_addr *ip_addr, void **ex_data_array,
|
||||
const struct ip_addr *ip_addr, void **ex_data_array,
|
||||
size_t n_ex_data)
|
||||
{
|
||||
if (NULL == maat_instance || table_id < 0 || table_id >= MAX_TABLE_NUM
|
||||
|
||||
@@ -56,7 +56,7 @@ void *bool_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
schema->table_id = item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_BOOL_PLUGIN,
|
||||
"[%s:%d] table %s has no table_id column",
|
||||
"[%s:%d] table: <%s> schema has no table_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ void *bool_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
item = cJSON_GetObjectItem(json, "custom");
|
||||
if (NULL == item || item->type != cJSON_Object) {
|
||||
log_error(logger, MODULE_BOOL_PLUGIN,
|
||||
"[%s:%d] table %s has no custom column",
|
||||
"[%s:%d] table: <%s> schema has no custom column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ void *bool_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
schema->item_id_column = custom_item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_BOOL_PLUGIN,
|
||||
"[%s:%d] table %s has no item_id column",
|
||||
"[%s:%d] table: <%s> schema has no item_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ void *bool_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
schema->bool_expr_column = custom_item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_BOOL_PLUGIN,
|
||||
"[%s:%d] table %s has no bool_expr column",
|
||||
"[%s:%d] table: <%s> schema has no bool_expr column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -185,7 +185,8 @@ void *bool_plugin_runtime_new(void *bool_plugin_schema, size_t max_thread_num,
|
||||
|
||||
bool_plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id, logger);
|
||||
if (1 == schema->container_schema.set_flag) {
|
||||
ex_data_runtime_set_ex_container_schema(bool_plugin_rt->ex_data_rt, &(schema->container_schema));
|
||||
ex_data_runtime_set_ex_container_schema(bool_plugin_rt->ex_data_rt,
|
||||
&(schema->container_schema));
|
||||
}
|
||||
|
||||
bool_plugin_rt->n_worker_thread = max_thread_num;
|
||||
@@ -254,8 +255,8 @@ int bool_plugin_runtime_update_row(struct bool_plugin_runtime *bool_plugin_rt,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bool_plugin_accept_tag_match(struct bool_plugin_schema *schema, const char *line,
|
||||
struct log_handle *logger)
|
||||
int bool_plugin_accept_tag_match(struct bool_plugin_schema *schema, const char *table_name,
|
||||
const char *line, struct log_handle *logger)
|
||||
{
|
||||
size_t column_offset = 0;
|
||||
size_t column_len = 0;
|
||||
@@ -266,8 +267,8 @@ int bool_plugin_accept_tag_match(struct bool_plugin_schema *schema, const char *
|
||||
&column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_BOOL_PLUGIN,
|
||||
"[%s:%d] bool_plugin table(table_id:%d) has no rule_tag, line:%s",
|
||||
__FUNCTION__, __LINE__, schema->table_id, line);
|
||||
"[%s:%d] table: <%s> has no rule_tag in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_ERR;
|
||||
}
|
||||
|
||||
@@ -278,12 +279,15 @@ int bool_plugin_accept_tag_match(struct bool_plugin_schema *schema, const char *
|
||||
FREE(tag_str);
|
||||
if (TAG_MATCH_ERR == ret) {
|
||||
log_error(logger, MODULE_BOOL_PLUGIN,
|
||||
"[%s:%d] bool_plugin table(table_id:%d) has invalid tag format, line:%s",
|
||||
__FUNCTION__, __LINE__, schema->table_id, line);
|
||||
"[%s:%d] table: <%s> has invalid tag format in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_ERR;
|
||||
}
|
||||
|
||||
if (TAG_MATCH_UNMATCHED == ret) {
|
||||
log_error(logger, MODULE_BOOL_PLUGIN,
|
||||
"[%s:%d] table: <%s> has unmatched tag in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_UNMATCHED;
|
||||
}
|
||||
}
|
||||
@@ -296,7 +300,7 @@ struct bool_expr *
|
||||
bool_plugin_expr_new(const char *line, struct bool_plugin_schema *schema,
|
||||
const char *table_name, struct log_handle *logger)
|
||||
{
|
||||
int ret = bool_plugin_accept_tag_match(schema, line, logger);
|
||||
int ret = bool_plugin_accept_tag_match(schema, table_name, line, logger);
|
||||
if (ret == TAG_MATCH_UNMATCHED) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -312,7 +316,7 @@ bool_plugin_expr_new(const char *line, struct bool_plugin_schema *schema,
|
||||
ret = get_column_pos(line, schema->item_id_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_BOOL_PLUGIN,
|
||||
"[%s:%d] bool_plugin table:%s line:%s has no item_id column",
|
||||
"[%s:%d] table: <%s> has no item_id in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -321,7 +325,7 @@ bool_plugin_expr_new(const char *line, struct bool_plugin_schema *schema,
|
||||
ret = get_column_pos(line, schema->bool_expr_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_BOOL_PLUGIN,
|
||||
"[%s:%d] bool_plugin table:%s line:%s has no bool_expr column",
|
||||
"[%s:%d] table: <%s> has no bool_expr in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -337,7 +341,7 @@ bool_plugin_expr_new(const char *line, struct bool_plugin_schema *schema,
|
||||
n_item++;
|
||||
if (ret != 1 || n_item > MAX_ITEMS_PER_BOOL_EXPR) {
|
||||
log_error(logger, MODULE_BOOL_PLUGIN,
|
||||
"[%s:%d] bool_plugin table:%s line:%s has invalid format of bool_expr column",
|
||||
"[%s:%d] table: <%s> has invalid format of bool_expr in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,6 @@ struct compile_runtime {
|
||||
|
||||
struct group2compile_runtime {
|
||||
long long not_flag_group;
|
||||
long long version;
|
||||
long long rule_num;
|
||||
long long update_err_cnt;
|
||||
struct compile_runtime *ref_compile_rt;
|
||||
@@ -229,7 +228,7 @@ void maat_compile_free(struct maat_compile *compile)
|
||||
clause_state->in_use = 0;
|
||||
}
|
||||
compile->magic = 0;
|
||||
free(compile);
|
||||
FREE(compile);
|
||||
}
|
||||
|
||||
void rcu_maat_compile_free(void *user_ctx, void *data)
|
||||
@@ -328,14 +327,15 @@ void *compile_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
compile_schema->table_id = item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] table %s has no table_id column", table_name);
|
||||
"[%s:%d] table: <%s> schema has no table_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
item = cJSON_GetObjectItem(json, "custom");
|
||||
if (item == NULL || item->type != cJSON_Object) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] table %s has no custom column",
|
||||
"[%s:%d] table: <%s> schema has no custom column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -345,7 +345,8 @@ void *compile_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
compile_schema->compile_id_column = custom_item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] table %s has no compile_id column", table_name);
|
||||
"[%s:%d] table: <%s> schema has no compile_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -359,7 +360,8 @@ void *compile_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
compile_schema->declared_clause_num_column = custom_item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] table %s has no clause_num column", table_name);
|
||||
"[%s:%d] table: <%s> schema has no clause_num column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -386,7 +388,7 @@ void *group2compile_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
g2c_schema->table_id = item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] table %s has no table_id column",
|
||||
"[%s:%d] table: <%s> schema has no table_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -396,7 +398,7 @@ void *group2compile_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
g2c_schema->associated_compile_table_id = item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] table %s has no associated_compile_table_id column",
|
||||
"[%s:%d] table: <%s> schema has no associated_compile_table_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -404,7 +406,7 @@ void *group2compile_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
item = cJSON_GetObjectItem(json, "custom");
|
||||
if (item == NULL || item->type != cJSON_Object) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] table %s has no custom column",
|
||||
"[%s:%d] table: <%s> schema has no custom column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -414,7 +416,7 @@ void *group2compile_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
g2c_schema->group_id_column = custom_item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] table %s has no group_id column",
|
||||
"[%s:%d] table: <%s> schema has no group_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -424,7 +426,7 @@ void *group2compile_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
g2c_schema->compile_id_column = custom_item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] table %s has no compile_id column",
|
||||
"[%s:%d] table: <%s> schema has no compile_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -434,7 +436,7 @@ void *group2compile_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
g2c_schema->not_flag_column = custom_item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] table %s has no not_flag column",
|
||||
"[%s:%d] table: <%s> schema has no not_flag column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -444,7 +446,7 @@ void *group2compile_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
g2c_schema->vtable_name_column = custom_item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] table %s has no virtual_table_name column",
|
||||
"[%s:%d] table: <%s> schema has no virtual_table_name column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -454,7 +456,7 @@ void *group2compile_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
g2c_schema->clause_index_column = custom_item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] table %s has no clause_index column",
|
||||
"[%s:%d] table: <%s> schema has no clause_index column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -490,7 +492,7 @@ int compile_accept_tag_match(struct compile_schema *schema, const char *line,
|
||||
&column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] compile table:%s has no rule_tag in line:%s",
|
||||
"[%s:%d] table: <%s> has no rule_tag in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_ERR;
|
||||
}
|
||||
@@ -502,12 +504,15 @@ int compile_accept_tag_match(struct compile_schema *schema, const char *line,
|
||||
FREE(tag_str);
|
||||
if (TAG_MATCH_ERR == ret) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] compile table:%s has invalid tag format in line:%s",
|
||||
"[%s:%d] table: <%s> has invalid tag format in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_ERR;
|
||||
}
|
||||
|
||||
if (TAG_MATCH_UNMATCHED == ret) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] table: <%s> has unmatched tag in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_UNMATCHED;
|
||||
}
|
||||
}
|
||||
@@ -522,9 +527,6 @@ compile_item_new(const char *line, struct compile_schema *compile_schema,
|
||||
{
|
||||
int ret = compile_accept_tag_match(compile_schema, line, table_name, logger);
|
||||
if (ret == TAG_MATCH_UNMATCHED) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] compile table:%s accept tag unmatched in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -536,7 +538,7 @@ compile_item_new(const char *line, struct compile_schema *compile_schema,
|
||||
&column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] compile table:%s has no compile_id in line:%s",
|
||||
"[%s:%d] table: <%s> has no compile_id in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -546,7 +548,7 @@ compile_item_new(const char *line, struct compile_schema *compile_schema,
|
||||
&column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] compile table:%s has no clause_num in line:%s",
|
||||
"[%s:%d] table: <%s> has no clause_num in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -577,7 +579,8 @@ void *compile_runtime_new(void *compile_schema, size_t max_thread_num,
|
||||
|
||||
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->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_tbl = rcu_hash_new(rcu_maat_compile_free, NULL);
|
||||
compile_rt->clause_by_literals_hash = NULL;
|
||||
@@ -746,7 +749,7 @@ group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema
|
||||
int ret = get_column_pos(line, g2c_schema->group_id_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] group2compile table:%s line:%s has no group_id",
|
||||
"[%s:%d] table: <%s> has no group_id in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -755,7 +758,7 @@ group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema
|
||||
ret = get_column_pos(line, g2c_schema->compile_id_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] group2compile table:%s line:%s has no compile_id",
|
||||
"[%s:%d] table: <%s> has no compile_id in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -764,7 +767,7 @@ group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema
|
||||
ret = get_column_pos(line, g2c_schema->not_flag_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] group2compile table:%s line:%s has no NOT_flag",
|
||||
"[%s:%d] table: <%s> has no NOT_flag in line:%s ",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -773,14 +776,14 @@ group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema
|
||||
ret = get_column_pos(line, g2c_schema->vtable_name_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] group2compile table:%s line:%s has no virtual_table_name",
|
||||
"[%s:%d] table: <%s> has no virtual_table_name in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (column_len > NAME_MAX) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] group2compile table:%s line:%s virtual_table_name length too long",
|
||||
"[%s:%d] table: <%s> virtual_table_name length too long in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -791,8 +794,8 @@ group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema
|
||||
g2c_item->vtable_id = table_manager_get_table_id(g2c_schema->ref_tbl_mgr, vtable_name);
|
||||
if (g2c_item->vtable_id < 0) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] group2compile table:%s line:%s unknown virtual table:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line, vtable_name);
|
||||
"[%s:%d] table: <%s> has unknown virtual table:%s in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, vtable_name, line);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@@ -800,7 +803,7 @@ group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema
|
||||
ret = get_column_pos(line, g2c_schema->clause_index_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] group2compile table:%s line:%s has no clause_index",
|
||||
"[%s:%d] table: <%s> has no clause_index in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -960,7 +963,7 @@ struct bool_matcher *maat_compile_bool_matcher_new(struct compile_runtime *compi
|
||||
#if 0
|
||||
struct maat_literal_id *p = NULL;
|
||||
for(p = (struct maat_literal_id *)utarray_front(iter_compile->clause_states[i].ut_literal_ids); p!=NULL;
|
||||
p=(struct maat_literal_id *)utarray_next(iter_compile->clause_states[i].ut_literal_ids,p)) {
|
||||
p = (struct maat_literal_id *)utarray_next(iter_compile->clause_states[i].ut_literal_ids, p)) {
|
||||
printf("<before bool_matcher_new> compile_rt:%p compile_id:%lld, clause_id:%llu, literal{%lld: %lld}\n",
|
||||
compile_rt, iter_compile->compile_id, iter_compile->clause_states[i].clause_id, p->group_id, p->vtable_id);
|
||||
}
|
||||
@@ -986,8 +989,8 @@ struct bool_matcher *maat_compile_bool_matcher_new(struct compile_runtime *compi
|
||||
// STEP 3, build bool matcher
|
||||
size_t mem_size = 0;
|
||||
if (0 == expr_cnt) {
|
||||
log_error(compile_rt->logger, MODULE_COMPILE, "[%s:%d] No bool expression to build bool matcher.",
|
||||
__FUNCTION__, __LINE__);
|
||||
log_error(compile_rt->logger, MODULE_COMPILE,
|
||||
"[%s:%d] No bool expression to build bool matcher.", __FUNCTION__, __LINE__);
|
||||
FREE(bool_expr_array);
|
||||
return NULL;
|
||||
}
|
||||
@@ -995,7 +998,8 @@ struct bool_matcher *maat_compile_bool_matcher_new(struct compile_runtime *compi
|
||||
struct bool_matcher *bm = bool_matcher_new(bool_expr_array, expr_cnt, &mem_size);
|
||||
if (bm != NULL) {
|
||||
log_info(compile_rt->logger, MODULE_COMPILE,
|
||||
"Build bool matcher of %zu expressions with %zu bytes memory.", expr_cnt, mem_size);
|
||||
"Build bool matcher of %zu expressions with %zu bytes memory.",
|
||||
expr_cnt, mem_size);
|
||||
} else {
|
||||
log_error(compile_rt->logger, MODULE_COMPILE, "[%s:%d] Build bool matcher failed!",
|
||||
__FUNCTION__, __LINE__);
|
||||
@@ -1215,14 +1219,21 @@ void compile_rule_free(struct compile_rule *compile_rule)
|
||||
struct compile_schema *schema = compile_rule->ref_schema;
|
||||
assert(compile_rule->magic_num == COMPILE_RULE_MAGIC);
|
||||
|
||||
if (1 == schema->set_flag)
|
||||
{
|
||||
if (1 == schema->set_flag) {
|
||||
rule_ex_data_free(schema->table_id, compile_rule->ex_data, &(schema->ex_schema));
|
||||
*compile_rule->ex_data = NULL;
|
||||
}
|
||||
FREE(compile_rule->ex_data);
|
||||
|
||||
if (compile_rule->ex_data != NULL) {
|
||||
FREE(compile_rule->ex_data);
|
||||
}
|
||||
|
||||
compile_rule->declared_clause_num = -1;
|
||||
FREE(compile_rule->table_line);
|
||||
|
||||
if (compile_rule->table_line != NULL) {
|
||||
FREE(compile_rule->table_line);
|
||||
}
|
||||
|
||||
FREE(compile_rule);
|
||||
}
|
||||
|
||||
@@ -1468,7 +1479,7 @@ void maat_compile_state_free(struct maat_compile_state *compile_state)
|
||||
compile_state->this_scan_hit_clauses = NULL;
|
||||
}
|
||||
|
||||
free(compile_state);
|
||||
FREE(compile_state);
|
||||
}
|
||||
|
||||
static int maat_compile_hit_path_add(UT_array *hit_paths, long long item_id, long long group_id,
|
||||
@@ -1533,7 +1544,8 @@ size_t compile_runtime_get_hit_paths(struct compile_runtime *compile_rt,
|
||||
size_t new_hit_path_cnt = 0;
|
||||
struct maat_compile *compile = NULL;
|
||||
struct maat_literal_id literal_id = {0, 0};
|
||||
struct bool_expr_match *expr_match = compile_rt->expr_match_buff + compile_state->thread_id * MAX_SCANNER_HIT_COMPILE_NUM;
|
||||
struct bool_expr_match *expr_match = compile_rt->expr_match_buff +
|
||||
(compile_state->thread_id * MAX_SCANNER_HIT_COMPILE_NUM);
|
||||
assert(compile_state->thread_id >= 0);
|
||||
|
||||
if (compile_state->compile_rt_version != compile_rt->version) {
|
||||
@@ -1910,7 +1922,7 @@ int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
|
||||
group_ref = ALLOC(struct group_reference, 1);
|
||||
group_ref->group_id = g2c_item->group_id;
|
||||
HASH_ADD_KEYPTR(hh, compile_rt->group_ref_hash, (char *)&(group_ref->group_id),
|
||||
sizeof(long long), group_ref);
|
||||
sizeof(long long), group_ref);
|
||||
}
|
||||
group_ref->ref_by_compile_cnt++;
|
||||
pthread_mutex_unlock(&(compile_rt->mutex));
|
||||
@@ -1933,6 +1945,7 @@ int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
|
||||
int group_referenced_by_compile(struct compile_runtime *compile_rt, long long group_id)
|
||||
{
|
||||
struct group_reference *group_ref = NULL;
|
||||
|
||||
pthread_mutex_lock(&(compile_rt->mutex));
|
||||
HASH_FIND(hh, compile_rt->group_ref_hash, (char *)&group_id, sizeof(long long), group_ref);
|
||||
if (group_ref != NULL) {
|
||||
|
||||
@@ -444,6 +444,10 @@ void expr_rule_reset(struct expr_rule *rule)
|
||||
|
||||
void expr_item_free(struct expr_item *item)
|
||||
{
|
||||
if (NULL == item) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item->user_data != NULL &&
|
||||
item->user_data_free != NULL) {
|
||||
item->user_data_free(item->user_data);
|
||||
@@ -737,15 +741,6 @@ int expr_item_to_expr_rule(struct expr_item *expr_item, struct expr_rule *expr_r
|
||||
expr_rule->user_tag = expr_item->user_data;
|
||||
expr_rule->n_patterns = sub_expr_cnt;
|
||||
|
||||
//mytest
|
||||
// printf("expr_rule->expr_id:%u\n", expr_rule->expr_id);
|
||||
// printf("expr_rule->n_patterns:%zu\n", expr_rule->n_patterns);
|
||||
// for (size_t i = 0; i < expr_rule->n_patterns; i++) {
|
||||
// printf("expr_rule->patterns[%zu].pat:%s\n", i, expr_rule->patterns[i].pat);
|
||||
// printf("expr_rule->patterns[%zu].pat_len:%zu\n", i, expr_rule->patterns[i].pat_len);
|
||||
// printf("expr_rule->patterns[%zu].l_offset:%d\n", i, expr_rule->patterns[i].l_offset);
|
||||
// printf("expr_rule->patterns[%zu].r_offset:%d\n", i, expr_rule->patterns[i].r_offset);
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -876,8 +871,8 @@ int expr_runtime_commit(void *expr_runtime, const char *table_name, long long ma
|
||||
expr_rt->version = maat_rt_version;
|
||||
|
||||
log_info(expr_rt->logger, MODULE_EXPR,
|
||||
"table[%s] commit %zu expr rules and rebuild adapter_hs completed, version:%lld",
|
||||
table_name, rule_cnt, expr_rt->version);
|
||||
"table[%s] has %zu rules, commit %zu expr rules and rebuild adapter_hs completed, version:%lld",
|
||||
table_name, rule_cnt, real_rule_cnt, expr_rt->version);
|
||||
|
||||
if (rules != NULL) {
|
||||
for (i = 0; i < rule_cnt; i++) {
|
||||
|
||||
@@ -425,7 +425,6 @@ int flag_runtime_update(void *flag_runtime, void *flag_schema, const char *table
|
||||
if (ret < 0) {
|
||||
if (flag_item != NULL) {
|
||||
flag_item_free(flag_item);
|
||||
flag_item = NULL;
|
||||
}
|
||||
flag_rt->update_err_cnt++;
|
||||
return -1;
|
||||
|
||||
@@ -56,7 +56,7 @@ void *fqdn_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
schema->table_id = item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_FQDN_PLUGIN,
|
||||
"[%s:%d] table %s has no table_id column",
|
||||
"[%s:%d] table: <%s> schema has no table_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ void *fqdn_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
item = cJSON_GetObjectItem(json, "custom");
|
||||
if (NULL == item || item->type != cJSON_Object) {
|
||||
log_error(logger, MODULE_FQDN_PLUGIN,
|
||||
"[%s:%d] table %s has no custom column",
|
||||
"[%s:%d] table: <%s> schema has no custom column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ void *fqdn_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
schema->item_id_column = custom_item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_FQDN_PLUGIN,
|
||||
"[%s:%d] table %s has no item_id column",
|
||||
"[%s:%d] table: <%s> schema has no item_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ void *fqdn_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
schema->suffix_flag_column = custom_item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_FQDN_PLUGIN,
|
||||
"[%s:%d] table %s has no suffix_match_method column",
|
||||
"[%s:%d] table: <%s> schema has no suffix_match_method column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -95,7 +95,7 @@ void *fqdn_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
schema->fqdn_column = custom_item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_FQDN_PLUGIN,
|
||||
"[%s:%d] table %s has no fqdn column",
|
||||
"[%s:%d] table: <%s> schema has no fqdn column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -159,9 +159,15 @@ struct ex_container_schema *fqdn_plugin_table_get_ex_container_schema(void *fqdn
|
||||
|
||||
void fqdn_rule_free(struct FQDN_rule *fqdn_rule)
|
||||
{
|
||||
if (NULL == fqdn_rule) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(fqdn_rule->user_tag == NULL);
|
||||
free(fqdn_rule->FQDN);
|
||||
fqdn_rule->FQDN = NULL;
|
||||
if (fqdn_rule->FQDN != NULL) {
|
||||
FREE(fqdn_rule->FQDN);
|
||||
}
|
||||
|
||||
free(fqdn_rule);
|
||||
}
|
||||
|
||||
@@ -220,8 +226,8 @@ void fqdn_plugin_runtime_free(void *fqdn_plugin_runtime)
|
||||
FREE(fqdn_plugin_rt);
|
||||
}
|
||||
|
||||
int fqdn_plugin_accept_tag_match(struct fqdn_plugin_schema *schema, const char *line,
|
||||
struct log_handle *logger)
|
||||
int fqdn_plugin_accept_tag_match(struct fqdn_plugin_schema *schema, const char *table_name,
|
||||
const char *line, struct log_handle *logger)
|
||||
{
|
||||
size_t column_offset = 0;
|
||||
size_t column_len = 0;
|
||||
@@ -232,8 +238,8 @@ int fqdn_plugin_accept_tag_match(struct fqdn_plugin_schema *schema, const char *
|
||||
&column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_FQDN_PLUGIN,
|
||||
"[%s:%d] fqdn_plugin table(table_id:%d) has no rule_tag, line:%s",
|
||||
__FUNCTION__, __LINE__, schema->table_id, line);
|
||||
"[%s:%d] table: <%s> has no rule_tag in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_ERR;
|
||||
}
|
||||
|
||||
@@ -244,12 +250,15 @@ int fqdn_plugin_accept_tag_match(struct fqdn_plugin_schema *schema, const char *
|
||||
FREE(tag_str);
|
||||
if (TAG_MATCH_ERR == ret) {
|
||||
log_error(logger, MODULE_FQDN_PLUGIN,
|
||||
"[%s:%d] fqdn_plugin table(table_id:%d) has invalid tag format, line:%s",
|
||||
__FUNCTION__, __LINE__, schema->table_id, line);
|
||||
"[%s:%d] table: <%s> has invalid tag format in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_ERR;
|
||||
}
|
||||
|
||||
if (TAG_MATCH_UNMATCHED == ret) {
|
||||
log_error(logger, MODULE_FQDN_PLUGIN,
|
||||
"[%s:%d] table: <%s> has unmatched tag in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_UNMATCHED;
|
||||
}
|
||||
}
|
||||
@@ -262,7 +271,7 @@ struct FQDN_rule *
|
||||
fqdn_plugin_rule_new(const char *line, struct fqdn_plugin_schema *schema,
|
||||
const char *table_name, struct log_handle *logger)
|
||||
{
|
||||
int ret = fqdn_plugin_accept_tag_match(schema, line, logger);
|
||||
int ret = fqdn_plugin_accept_tag_match(schema, table_name, line, logger);
|
||||
if (ret == TAG_MATCH_UNMATCHED) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -276,7 +285,7 @@ fqdn_plugin_rule_new(const char *line, struct fqdn_plugin_schema *schema,
|
||||
ret = get_column_pos(line, schema->item_id_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_FQDN_PLUGIN,
|
||||
"[%s:%d] fqdn_plugin table:%s line:%s has no item_id column",
|
||||
"[%s:%d] table: <%s> has no item_id in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -285,7 +294,7 @@ fqdn_plugin_rule_new(const char *line, struct fqdn_plugin_schema *schema,
|
||||
ret = get_column_pos(line, schema->suffix_flag_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_FQDN_PLUGIN,
|
||||
"[%s:%d] fqdn_plugin table:%s line:%s has no suffix_match_method column",
|
||||
"[%s:%d] table: <%s> has no suffix_match_method in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -294,7 +303,7 @@ fqdn_plugin_rule_new(const char *line, struct fqdn_plugin_schema *schema,
|
||||
ret = get_column_pos(line, schema->fqdn_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_FQDN_PLUGIN,
|
||||
"[%s:%d] fqdn_plugin table:%s line:%s has no fqdn column",
|
||||
"[%s:%d] table: <%s> has no fqdn in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -323,6 +332,10 @@ error:
|
||||
|
||||
void fqdn_plugin_rule_free(struct FQDN_rule *rule)
|
||||
{
|
||||
if (NULL == rule) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (rule->FQDN != NULL) {
|
||||
FREE(rule->FQDN);
|
||||
}
|
||||
@@ -386,7 +399,8 @@ int fqdn_plugin_runtime_update(void *fqdn_plugin_runtime, void *fqdn_plugin_sche
|
||||
if (1 == schema->container_schema.set_flag) {
|
||||
if (1 == is_valid) {
|
||||
// add
|
||||
fqdn_plugin_rule = fqdn_plugin_rule_new(line, schema, table_name, fqdn_plugin_rt->logger);
|
||||
fqdn_plugin_rule = fqdn_plugin_rule_new(line, schema, table_name,
|
||||
fqdn_plugin_rt->logger);
|
||||
if (NULL == fqdn_plugin_rule) {
|
||||
fqdn_plugin_rt->update_err_cnt++;
|
||||
return -1;
|
||||
@@ -396,7 +410,7 @@ int fqdn_plugin_runtime_update(void *fqdn_plugin_runtime, void *fqdn_plugin_sche
|
||||
const char *key = line + item_id_offset;
|
||||
size_t key_len = item_id_len;
|
||||
ret = fqdn_plugin_runtime_update_row(fqdn_plugin_rt, table_name, line, key, key_len,
|
||||
fqdn_plugin_rule, is_valid);
|
||||
fqdn_plugin_rule, is_valid);
|
||||
if (ret < 0) {
|
||||
if (fqdn_plugin_rule != NULL) {
|
||||
fqdn_plugin_rule_free(fqdn_plugin_rule);
|
||||
@@ -419,7 +433,8 @@ void garbage_fqdn_engine_free(void *fqdn_engine, void *arg)
|
||||
FQDN_engine_free(engine);
|
||||
}
|
||||
|
||||
int fqdn_plugin_runtime_commit(void *fqdn_plugin_runtime, const char *table_name, long long maat_rt_version)
|
||||
int fqdn_plugin_runtime_commit(void *fqdn_plugin_runtime, const char *table_name,
|
||||
long long maat_rt_version)
|
||||
{
|
||||
if (NULL == fqdn_plugin_runtime) {
|
||||
return -1;
|
||||
|
||||
@@ -42,8 +42,12 @@ struct maat_garbage_bin *maat_garbage_bin_new(int default_timeout)
|
||||
return bin;
|
||||
}
|
||||
|
||||
void maat_garbage_bin_free(struct maat_garbage_bin* bin)
|
||||
void maat_garbage_bin_free(struct maat_garbage_bin *bin)
|
||||
{
|
||||
if (NULL == bin) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct maat_garbage_bag *p = NULL;
|
||||
|
||||
while ((p = TAILQ_FIRST(&bin->garbage_q)) != NULL) {
|
||||
@@ -51,6 +55,7 @@ void maat_garbage_bin_free(struct maat_garbage_bin* bin)
|
||||
if (p->arg != NULL) {
|
||||
FREE(p->arg);
|
||||
}
|
||||
|
||||
TAILQ_REMOVE(&bin->garbage_q, p, entries);
|
||||
FREE(p);
|
||||
bin->bag_cnt--;
|
||||
@@ -59,12 +64,16 @@ void maat_garbage_bin_free(struct maat_garbage_bin* bin)
|
||||
FREE(bin);
|
||||
}
|
||||
|
||||
size_t maat_garbage_bin_get_size(struct maat_garbage_bin* bin)
|
||||
size_t maat_garbage_bin_get_size(struct maat_garbage_bin *bin)
|
||||
{
|
||||
if (NULL == bin) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return bin->bag_cnt;
|
||||
}
|
||||
|
||||
void maat_garbage_bagging(struct maat_garbage_bin* bin, void* garbage, void *arg,
|
||||
void maat_garbage_bagging(struct maat_garbage_bin *bin, void *garbage, void *arg,
|
||||
void (* func)(void *, void *))
|
||||
{
|
||||
struct maat_garbage_bag *bag = ALLOC(struct maat_garbage_bag, 1);
|
||||
@@ -77,7 +86,8 @@ void maat_garbage_bagging(struct maat_garbage_bin* bin, void* garbage, void *arg
|
||||
TAILQ_INSERT_TAIL(&bin->garbage_q, bag, entries);
|
||||
bin->bag_cnt++;
|
||||
}
|
||||
void maat_garbage_collect_routine(struct maat_garbage_bin* bin)
|
||||
|
||||
void maat_garbage_collect_routine(struct maat_garbage_bin *bin)
|
||||
{
|
||||
struct maat_garbage_bag *p = NULL, *tmp = NULL;
|
||||
size_t n_clollected = 0, n_bag = 0;
|
||||
@@ -101,9 +111,10 @@ void maat_garbage_collect_routine(struct maat_garbage_bin* bin)
|
||||
bin->bag_cnt -= n_clollected;
|
||||
}
|
||||
|
||||
void maat_garbage_collect_by_force(struct maat_garbage_bin* bin)
|
||||
void maat_garbage_collect_by_force(struct maat_garbage_bin *bin)
|
||||
{
|
||||
struct maat_garbage_bag *p = NULL;
|
||||
|
||||
while ((p = TAILQ_FIRST(&bin->garbage_q)) != NULL) {
|
||||
p->garbage_free(p->garbage, p->arg);
|
||||
if (p->arg != NULL) {
|
||||
|
||||
129
src/maat_group.c
129
src/maat_group.c
@@ -153,6 +153,10 @@ void group2group_schema_free(void *g2g_schema)
|
||||
|
||||
void group_vertex_free(struct maat_group *group)
|
||||
{
|
||||
if (NULL == group) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (group->incl_super_group_ids != NULL) {
|
||||
utarray_free(group->incl_super_group_ids);
|
||||
group->incl_super_group_ids = NULL;
|
||||
@@ -194,6 +198,10 @@ struct maat_group_topology *maat_group_topology_new(struct log_handle *logger)
|
||||
|
||||
void maat_group_topology_free(struct maat_group_topology *group_topo)
|
||||
{
|
||||
if (NULL == group_topo) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct maat_group *group = NULL, *tmp_group = NULL;
|
||||
|
||||
HASH_CLEAR(hh_vertex_id, group_topo->hash_by_vertex_id);//No need group memory clean up.
|
||||
@@ -770,7 +778,7 @@ void get_candidate_super_group_ids(struct maat_group_topology *group_topo,
|
||||
{
|
||||
long long *p = NULL;
|
||||
|
||||
//Find super candidates
|
||||
//Find super candidates
|
||||
for (p = (long long *)utarray_front(hit_group_ids); p != NULL;
|
||||
p = (long long *)utarray_next(hit_group_ids, p)) {
|
||||
struct maat_group *group = group_topology_find_group(group_topo, *p);
|
||||
@@ -792,6 +800,74 @@ void get_candidate_super_group_ids(struct maat_group_topology *group_topo,
|
||||
}
|
||||
}
|
||||
|
||||
void verify_group_by_sub_include_groups(struct maat_group *group, UT_array *candidate_group_ids,
|
||||
UT_array *kept_super_group_ids, UT_array *all_hit_group_ids)
|
||||
{
|
||||
size_t remove_idx = 0;
|
||||
long long *tmp_id = NULL;
|
||||
|
||||
// delete groups whose all incl sub not in all_hit_group_ids
|
||||
if (utarray_len(group->incl_sub_group_ids) != 0) {
|
||||
int sub_incl_flag = 0;
|
||||
|
||||
for (tmp_id = (long long *)utarray_front(group->incl_sub_group_ids); tmp_id != NULL;
|
||||
tmp_id = (long long *)utarray_next(group->incl_sub_group_ids, tmp_id)) {
|
||||
if (utarray_find(candidate_group_ids, tmp_id, compare_group_id)) {
|
||||
sub_incl_flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == sub_incl_flag) {
|
||||
tmp_id = utarray_find(all_hit_group_ids, &(group->group_id), compare_group_id);
|
||||
if (tmp_id != NULL) {
|
||||
remove_idx = utarray_eltidx(all_hit_group_ids, tmp_id);
|
||||
utarray_erase(all_hit_group_ids, remove_idx, 1);
|
||||
}
|
||||
|
||||
tmp_id = utarray_find(kept_super_group_ids, &(group->group_id), compare_group_id);
|
||||
if (tmp_id != NULL) {
|
||||
remove_idx = utarray_eltidx(kept_super_group_ids, tmp_id);
|
||||
utarray_erase(kept_super_group_ids, remove_idx, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void verify_group_by_sub_exclude_groups(struct maat_group *group, UT_array *candidate_group_ids,
|
||||
UT_array *kept_super_group_ids, UT_array *all_hit_group_ids)
|
||||
{
|
||||
if (0 == utarray_len(group->excl_sub_group_ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// delete groups whose excl sub in all_hit_group_ids
|
||||
int sub_excl_flag = 0;
|
||||
long long *tmp_id = NULL;
|
||||
for (tmp_id = (long long *)utarray_front(group->excl_sub_group_ids); tmp_id != NULL;
|
||||
tmp_id = (long long *)utarray_next(group->excl_sub_group_ids, tmp_id)) {
|
||||
if (utarray_find(candidate_group_ids, tmp_id, compare_group_id)) {
|
||||
sub_excl_flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (1 == sub_excl_flag) {
|
||||
size_t remove_idx = 0;
|
||||
tmp_id = utarray_find(all_hit_group_ids, &(group->group_id), compare_group_id);
|
||||
if (tmp_id != NULL) {
|
||||
remove_idx = utarray_eltidx(all_hit_group_ids, tmp_id);
|
||||
utarray_erase(all_hit_group_ids, remove_idx, 1);
|
||||
}
|
||||
|
||||
tmp_id = utarray_find(kept_super_group_ids, &(group->group_id), compare_group_id);
|
||||
if (tmp_id != NULL) {
|
||||
remove_idx = utarray_eltidx(kept_super_group_ids, tmp_id);
|
||||
utarray_erase(kept_super_group_ids, remove_idx, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void verify_candidate_super_group_ids(struct maat_group_topology *group_topo,
|
||||
UT_array *candidate_super_group_ids,
|
||||
UT_array *all_hit_group_ids,
|
||||
@@ -802,6 +878,7 @@ void verify_candidate_super_group_ids(struct maat_group_topology *group_topo,
|
||||
|
||||
utarray_new(candidate_group_ids, &ut_group_id_icd);
|
||||
|
||||
/* merge this round of candidate super groups with hit groups from the previous round */
|
||||
for (p = (long long *)utarray_front(candidate_super_group_ids); p != NULL;
|
||||
p = (long long *)utarray_next(candidate_super_group_ids, p)) {
|
||||
utarray_push_back(candidate_group_ids, p);
|
||||
@@ -832,10 +909,11 @@ void verify_candidate_super_group_ids(struct maat_group_topology *group_topo,
|
||||
}
|
||||
}
|
||||
|
||||
//delete group_id from kept_group_ids
|
||||
//kept super groups should not store this group
|
||||
if (1 == sub_excl_flag) {
|
||||
continue;
|
||||
}
|
||||
|
||||
utarray_push_back(kept_super_group_ids, p);
|
||||
utarray_sort(kept_super_group_ids, compare_group_id);
|
||||
|
||||
@@ -855,7 +933,8 @@ void verify_candidate_super_group_ids(struct maat_group_topology *group_topo,
|
||||
}
|
||||
|
||||
/**
|
||||
* delete groups whose all incl sub is non-exist in all_hit_group_ids
|
||||
* 1. delete groups whose excl sub in all_hit_group_ids
|
||||
* 2. delete groups whose all incl sub is non-exist in all_hit_group_ids
|
||||
*/
|
||||
for (p = (long long *)utarray_front(candidate_group_ids); p != NULL;
|
||||
p = (long long *)utarray_next(candidate_group_ids, p)) {
|
||||
@@ -864,38 +943,15 @@ void verify_candidate_super_group_ids(struct maat_group_topology *group_topo,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (0 == utarray_len(group->incl_sub_group_ids)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int sub_incl_flag = 0;
|
||||
long long *tmp_id = NULL;
|
||||
for (tmp_id = (long long *)utarray_front(group->incl_sub_group_ids); tmp_id != NULL;
|
||||
tmp_id = (long long *)utarray_next(group->incl_sub_group_ids, tmp_id)) {
|
||||
if (utarray_find(candidate_group_ids, tmp_id, compare_group_id)) {
|
||||
sub_incl_flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == sub_incl_flag) {
|
||||
tmp_id = utarray_find(all_hit_group_ids, p, compare_group_id);
|
||||
assert(tmp_id != NULL);
|
||||
size_t remove_idx = utarray_eltidx(all_hit_group_ids, tmp_id);
|
||||
utarray_erase(all_hit_group_ids, remove_idx, 1);
|
||||
|
||||
tmp_id = utarray_find(kept_super_group_ids, p, compare_group_id);
|
||||
if (tmp_id != NULL) {
|
||||
remove_idx = utarray_eltidx(kept_super_group_ids, tmp_id);
|
||||
utarray_erase(kept_super_group_ids, remove_idx, 1);
|
||||
}
|
||||
}
|
||||
verify_group_by_sub_exclude_groups(group, candidate_group_ids,
|
||||
kept_super_group_ids, all_hit_group_ids);
|
||||
verify_group_by_sub_include_groups(group, candidate_group_ids,
|
||||
kept_super_group_ids, all_hit_group_ids);
|
||||
}
|
||||
|
||||
utarray_free(candidate_group_ids);
|
||||
}
|
||||
|
||||
#define MAX_RECURSION_DEPTH 5
|
||||
void get_super_group_ids(struct maat_group_topology *group_topo, UT_array *hit_group_ids,
|
||||
UT_array *all_hit_group_ids, size_t depth)
|
||||
{
|
||||
@@ -903,6 +959,8 @@ void get_super_group_ids(struct maat_group_topology *group_topo, UT_array *hit_g
|
||||
UT_array *kept_super_group_ids;
|
||||
|
||||
if (depth >= MAX_RECURSION_DEPTH) {
|
||||
log_error(group_topo->logger, MODULE_GROUP,
|
||||
"[%s:%d]exceed max recursion depth(5)", __FUNCTION__, __LINE__);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -911,7 +969,7 @@ void get_super_group_ids(struct maat_group_topology *group_topo, UT_array *hit_g
|
||||
|
||||
/**
|
||||
candidate super groups means all hit groups' super include group,
|
||||
no need to consider super exclude groups
|
||||
don't consider super exclude groups
|
||||
for example:
|
||||
hit_groups = {g4, g11}
|
||||
g4's super include groups = {g7, g8}
|
||||
@@ -941,9 +999,12 @@ void get_super_group_ids(struct maat_group_topology *group_topo, UT_array *hit_g
|
||||
x \ / \ \
|
||||
x \/ \ \
|
||||
g3 g4 g5 g11
|
||||
candidates = {g4, g11, g7, g8, g12}
|
||||
g12's sub_exclude g8 in candidates, so g12 should be dropped
|
||||
after verify candidates, all hit super groups = {g7, g8},
|
||||
candidate super groups = {g7, g8, g12}
|
||||
verify logic:
|
||||
1. g12's sub_exclude g8 in candidates, so g12 should be dropped
|
||||
2. g7 & g8, their sub_include in hit groups, so kept them
|
||||
if their all sub_include not exist in hit groups, they should be dropped
|
||||
after verify candidates, kept super groups = {g7, g8},
|
||||
all hit groups = {g4, g11, g7, g8}
|
||||
*/
|
||||
verify_candidate_super_group_ids(group_topo, candidate_super_group_ids, all_hit_group_ids,
|
||||
|
||||
@@ -423,7 +423,6 @@ int interval_runtime_update(void *interval_runtime, void *interval_schema,
|
||||
if (ret < 0) {
|
||||
if (interval_item != NULL) {
|
||||
interval_item_free(interval_item);
|
||||
interval_item = NULL;
|
||||
}
|
||||
interval_rt->update_err_cnt++;
|
||||
return -1;
|
||||
|
||||
@@ -535,7 +535,6 @@ int ip_runtime_update(void *ip_runtime, void *ip_schema,
|
||||
if (ret < 0) {
|
||||
if (ip_item != NULL) {
|
||||
ip_item_free(ip_item);
|
||||
ip_item = NULL;
|
||||
}
|
||||
ip_rt->update_err_cnt++;
|
||||
return -1;
|
||||
|
||||
@@ -51,7 +51,6 @@ struct ip_plugin_runtime {
|
||||
void *ip_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
const char *table_name, struct log_handle *logger)
|
||||
{
|
||||
size_t read_cnt = 0;
|
||||
struct ip_plugin_schema *schema = ALLOC(struct ip_plugin_schema, 1);
|
||||
schema->logger = logger;
|
||||
|
||||
@@ -59,13 +58,17 @@ void *ip_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
cJSON *item = cJSON_GetObjectItem(json, "table_id");
|
||||
if (item != NULL && item->type == cJSON_Number) {
|
||||
schema->table_id = item->valueint;
|
||||
read_cnt++;
|
||||
} else {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] table: <%s> schema has no table_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
item = cJSON_GetObjectItem(json, "custom");
|
||||
if (NULL == item || item->type != cJSON_Object) {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] table %s has no custom column",
|
||||
"[%s:%d] table: <%s> schema has no custom column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -73,33 +76,54 @@ void *ip_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
custom_item = cJSON_GetObjectItem(item, "item_id");
|
||||
if (custom_item != NULL && custom_item->type == cJSON_Number) {
|
||||
schema->item_id_column = custom_item->valueint;
|
||||
read_cnt++;
|
||||
} else {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] table: <%s> schema has no item_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
custom_item = cJSON_GetObjectItem(item, "ip_type");
|
||||
if (custom_item != NULL && custom_item->type == cJSON_Number) {
|
||||
schema->ip_type_column = custom_item->valueint;
|
||||
read_cnt++;
|
||||
} else {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] table: <%s> schema has no ip_type column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
custom_item = cJSON_GetObjectItem(item, "start_ip");
|
||||
if (custom_item != NULL && custom_item->type == cJSON_Number) {
|
||||
schema->start_ip_column = custom_item->valueint;
|
||||
read_cnt++;
|
||||
} else {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] table: <%s> schema has no start_ip column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
custom_item = cJSON_GetObjectItem(item, "end_ip");
|
||||
if (custom_item != NULL && custom_item->type == cJSON_Number) {
|
||||
schema->end_ip_column = custom_item->valueint;
|
||||
read_cnt++;
|
||||
} else {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] table: <%s> schema has no end_ip column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
custom_item = cJSON_GetObjectItem(item, "addr_format");
|
||||
if (custom_item != NULL && custom_item->type == cJSON_Number) {
|
||||
schema->addr_format_column = custom_item->valueint;
|
||||
//TODO: just because test table not add this column
|
||||
//read_cnt++;
|
||||
}
|
||||
}
|
||||
//TODO: just because test table has no addr_format
|
||||
// else {
|
||||
// log_error(logger, MODULE_IP_PLUGIN,
|
||||
// "[%s:%d] table: <%s> schema has no addr_format column",
|
||||
// __FUNCTION__, __LINE__, table_name);
|
||||
// goto error;
|
||||
// }
|
||||
|
||||
// rule_tag is optional
|
||||
custom_item = cJSON_GetObjectItem(item, "rule_tag");
|
||||
@@ -108,10 +132,6 @@ void *ip_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
}
|
||||
|
||||
schema->ref_tbl_mgr = tbl_mgr;
|
||||
|
||||
if (read_cnt < 5) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
return schema;
|
||||
error:
|
||||
@@ -128,8 +148,8 @@ void ip_plugin_schema_free(void *ip_plugin_schema)
|
||||
FREE(ip_plugin_schema);
|
||||
}
|
||||
|
||||
int ip_plugin_accept_tag_match(struct ip_plugin_schema *schema, const char *line,
|
||||
struct log_handle *logger)
|
||||
int ip_plugin_accept_tag_match(struct ip_plugin_schema *schema, const char *table_name,
|
||||
const char *line, struct log_handle *logger)
|
||||
{
|
||||
size_t column_offset = 0;
|
||||
size_t column_len = 0;
|
||||
@@ -140,8 +160,8 @@ int ip_plugin_accept_tag_match(struct ip_plugin_schema *schema, const char *line
|
||||
&column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] ip_plugin table(table_id:%d) has no rule_tag, line:%s",
|
||||
__FUNCTION__, __LINE__, schema->table_id, line);
|
||||
"[%s:%d] table: <%s> has no rule_tag in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_ERR;
|
||||
}
|
||||
|
||||
@@ -152,12 +172,15 @@ int ip_plugin_accept_tag_match(struct ip_plugin_schema *schema, const char *line
|
||||
FREE(tag_str);
|
||||
if (TAG_MATCH_ERR == ret) {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] ip_plugin table(table_id:%d) has invalid tag format, line:%s",
|
||||
__FUNCTION__, __LINE__, schema->table_id, line);
|
||||
"[%s:%d] table: <%s> has invalid tag format in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_ERR;
|
||||
}
|
||||
|
||||
if (TAG_MATCH_UNMATCHED == ret) {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] table: <%s> has unmatched tag in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_UNMATCHED;
|
||||
}
|
||||
}
|
||||
@@ -170,7 +193,7 @@ struct ip_rule *
|
||||
ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
|
||||
const char *table_name, struct log_handle *logger)
|
||||
{
|
||||
int ret = ip_plugin_accept_tag_match(schema, line, logger);
|
||||
int ret = ip_plugin_accept_tag_match(schema, table_name, line, logger);
|
||||
if (ret == TAG_MATCH_UNMATCHED) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -185,7 +208,7 @@ ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
|
||||
ret = get_column_pos(line, schema->item_id_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] ip plugin table:%s line:%s has no item_id",
|
||||
"[%s:%d] table: <%s> has no item_id in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -194,15 +217,15 @@ ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
|
||||
ret = get_column_pos(line, schema->ip_type_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] ip plugin table:%s line:%s has no ip_type",
|
||||
"[%s:%d] table: <%s> has no ip_type in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
ip_plugin_rule->type = atoi(line + column_offset);
|
||||
if (ip_plugin_rule->type != IPv4 && ip_plugin_rule->type != IPv6) {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] ip_plugin table:%s line:%s ip_type[%d] invalid",
|
||||
__FUNCTION__, __LINE__, table_name, line, ip_plugin_rule->type);
|
||||
"[%s:%d] table: <%s> ip_type[%d] invalid in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, ip_plugin_rule->type, line);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -230,7 +253,7 @@ ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
|
||||
ret = get_column_pos(line, schema->start_ip_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] ip_plugin table:%s line:%s has no start_ip",
|
||||
"[%s:%d] table: <%s> has no start_ip in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -239,7 +262,7 @@ ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
|
||||
ret = get_column_pos(line, schema->end_ip_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] ip_plugin table:%s line:%s has no end_ip",
|
||||
"[%s:%d] table: <%s> has no end_ip in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -252,7 +275,7 @@ ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
|
||||
&ip_plugin_rule->ipv4_rule.end_ip);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] ip_plugin table:%s line:%s ip_format2range(ip4) failed",
|
||||
"[%s:%d] table: <%s> ip_format2range(ip4) failed in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -264,7 +287,7 @@ ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
|
||||
ip_plugin_rule->ipv6_rule.end_ip);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_IP_PLUGIN,
|
||||
"[%s:%d] ip_plugin table:%s line:%s ip_format2range(ip6) failed",
|
||||
"[%s:%d] table: <%s> ip_format2range(ip6) failed in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
@@ -359,7 +382,8 @@ void *ip_plugin_runtime_new(void *ip_plugin_schema, size_t max_thread_num,
|
||||
|
||||
ip_plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id, logger);
|
||||
if (1 == schema->container_schema.set_flag) {
|
||||
ex_data_runtime_set_ex_container_schema(ip_plugin_rt->ex_data_rt, &(schema->container_schema));
|
||||
ex_data_runtime_set_ex_container_schema(ip_plugin_rt->ex_data_rt,
|
||||
&(schema->container_schema));
|
||||
}
|
||||
|
||||
ip_plugin_rt->n_worker_thread = max_thread_num;
|
||||
@@ -458,7 +482,8 @@ int ip_plugin_runtime_update(void *ip_plugin_runtime, void *ip_plugin_schema,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ip_plugin_runtime_commit(void *ip_plugin_runtime, const char *table_name, long long maat_rt_version)
|
||||
int ip_plugin_runtime_commit(void *ip_plugin_runtime, const char *table_name,
|
||||
long long maat_rt_version)
|
||||
{
|
||||
if (NULL == ip_plugin_runtime) {
|
||||
return -1;
|
||||
|
||||
@@ -48,10 +48,15 @@ struct maat_kv_pair* maat_kv_pair_new(const char* key, size_t keylen, long long
|
||||
return kv;
|
||||
}
|
||||
|
||||
void maat_kv_pair_free(struct maat_kv_pair* kv)
|
||||
void maat_kv_pair_free(struct maat_kv_pair *kv)
|
||||
{
|
||||
FREE(kv->key);
|
||||
kv->key = NULL;
|
||||
if (NULL == kv) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (kv->key != NULL) {
|
||||
FREE(kv->key);
|
||||
}
|
||||
|
||||
FREE(kv);
|
||||
}
|
||||
@@ -62,7 +67,7 @@ struct maat_kv_store* maat_kv_store_new(void)
|
||||
return store;
|
||||
}
|
||||
|
||||
void maat_kv_store_free(struct maat_kv_store* store)
|
||||
void maat_kv_store_free(struct maat_kv_store *store)
|
||||
{
|
||||
if (NULL == store) {
|
||||
return;
|
||||
@@ -79,7 +84,7 @@ void maat_kv_store_free(struct maat_kv_store* store)
|
||||
FREE(store);
|
||||
}
|
||||
|
||||
int maat_kv_register_unNull(struct maat_kv_store* store, const char *key, size_t keylen, long long value)
|
||||
int maat_kv_register_unNull(struct maat_kv_store *store, const char *key, size_t keylen, long long value)
|
||||
{
|
||||
if (keylen > MAAT_KV_MAX_KEY_LEN) {
|
||||
return -1;
|
||||
|
||||
@@ -87,7 +87,7 @@ void *plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
cJSON *item = cJSON_GetObjectItem(json, "table_id");
|
||||
if (NULL == item || item->type != cJSON_Number) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table %s has no table_id column",
|
||||
"[%s:%d] table: <%s> schema has no table_id column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -99,7 +99,7 @@ void *plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
custom_item = cJSON_GetObjectItem(item, "key");
|
||||
if (NULL == custom_item || custom_item->type != cJSON_Number) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table: %s has no key column",
|
||||
"[%s:%d] table: <%s> schema has no key column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ void *plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
custom_item = cJSON_GetObjectItem(item, "key_type");
|
||||
if (NULL == custom_item || custom_item->type != cJSON_String) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table: %s has no key_type column",
|
||||
"[%s:%d] table: <%s> schema has no key_type column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -119,9 +119,8 @@ void *plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
schema->key_type = PLUGIN_KEY_TYPE_INTEGER;
|
||||
} else {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table: %s key_type:%s illegal",
|
||||
__FUNCTION__, __LINE__, table_name,
|
||||
custom_item->valuestring);
|
||||
"[%s:%d] table: <%s> schema key_type:%s is illegal, just allow {pointer} or {integer}",
|
||||
__FUNCTION__, __LINE__, table_name, custom_item->valuestring);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -274,7 +273,8 @@ void *plugin_runtime_new(void *plugin_schema, size_t max_thread_num,
|
||||
|
||||
plugin_rt->ex_data_rt = ex_data_runtime_new(schema->table_id, logger);
|
||||
if (1 == schema->container_schema.set_flag) {
|
||||
ex_data_runtime_set_ex_container_schema(plugin_rt->ex_data_rt, &(schema->container_schema));
|
||||
ex_data_runtime_set_ex_container_schema(plugin_rt->ex_data_rt,
|
||||
&(schema->container_schema));
|
||||
}
|
||||
|
||||
plugin_rt->ref_garbage_bin = garbage_bin;
|
||||
@@ -319,7 +319,8 @@ int plugin_runtime_update_row(struct plugin_runtime *plugin_rt,
|
||||
void *ex_data = ex_data_runtime_row2ex_data(plugin_rt->ex_data_rt, table_name,
|
||||
row, key, key_len);
|
||||
struct ex_container *ex_container = ex_container_new(ex_data, NULL);
|
||||
ret = ex_data_runtime_add_ex_container(plugin_rt->ex_data_rt, key, key_len, ex_container);
|
||||
ret = ex_data_runtime_add_ex_container(plugin_rt->ex_data_rt, key, key_len,
|
||||
ex_container);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -353,7 +354,7 @@ int plugin_accept_tag_match(struct plugin_schema *schema, const char *table_name
|
||||
int ret = get_column_pos(line, schema->rule_tag_column, &column_offset, &column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table:%s has no rule_tag, line:%s",
|
||||
"[%s:%d] table: <%s> has no rule_tag in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_ERR;
|
||||
}
|
||||
@@ -365,12 +366,15 @@ int plugin_accept_tag_match(struct plugin_schema *schema, const char *table_name
|
||||
FREE(tag_str);
|
||||
if (TAG_MATCH_ERR == ret) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table:%s has invalid tag format, line:%s",
|
||||
"[%s:%d] table: <%s> has invalid tag format in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_ERR;
|
||||
}
|
||||
|
||||
if (TAG_MATCH_UNMATCHED == ret) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] table: <%s> has unmatched tag in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
return TAG_MATCH_UNMATCHED;
|
||||
}
|
||||
}
|
||||
@@ -427,7 +431,8 @@ int plugin_runtime_update(void *plugin_runtime, void *plugin_schema,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int plugin_runtime_commit(void *plugin_runtime, const char *table_name, long long maat_rt_version)
|
||||
int plugin_runtime_commit(void *plugin_runtime, const char *table_name,
|
||||
long long maat_rt_version)
|
||||
{
|
||||
if (NULL == plugin_runtime) {
|
||||
return -1;
|
||||
|
||||
@@ -411,16 +411,28 @@ int get_inc_key_list(long long instance_version, long long target_version,
|
||||
|
||||
void serial_rule_free(struct serial_rule *s_rule)
|
||||
{
|
||||
if (NULL == s_rule) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s_rule->table_line != NULL) {
|
||||
FREE(s_rule->table_line);
|
||||
}
|
||||
|
||||
if (s_rule->n_foreign > 0) {
|
||||
for (int i = 0; i < s_rule->n_foreign; i++) {
|
||||
FREE(s_rule->f_keys[i].filename);
|
||||
FREE(s_rule->f_keys[i].key);
|
||||
if (s_rule->f_keys[i].filename != NULL) {
|
||||
FREE(s_rule->f_keys[i].filename);
|
||||
}
|
||||
|
||||
if (s_rule->f_keys[i].key != NULL) {
|
||||
FREE(s_rule->f_keys[i].key);
|
||||
}
|
||||
}
|
||||
FREE(s_rule->f_keys);
|
||||
|
||||
if (s_rule->f_keys != NULL) {
|
||||
FREE(s_rule->f_keys);
|
||||
}
|
||||
}
|
||||
|
||||
FREE(s_rule);
|
||||
|
||||
@@ -55,7 +55,7 @@ void maat_item_inner_free(void *item_inner)
|
||||
assert(item->magic_num == ITEM_RULE_MAGIC);
|
||||
item->magic_num = 0;
|
||||
|
||||
free(item);
|
||||
FREE(item);
|
||||
}
|
||||
|
||||
struct maat_runtime* maat_runtime_create(long long version, struct maat *maat_instance)
|
||||
|
||||
@@ -185,7 +185,7 @@ void maat_stat_free(struct maat_stat *stat)
|
||||
stat->fs_handle = NULL;
|
||||
}
|
||||
|
||||
free(stat);
|
||||
FREE(stat);
|
||||
}
|
||||
|
||||
int maat_stat_init(struct maat_stat *stat, struct table_manager *tbl_mgr,
|
||||
@@ -287,8 +287,7 @@ void maat_fieldstat_table_row_output(struct maat_stat *stat, int perf_on)
|
||||
break;
|
||||
}
|
||||
|
||||
if (table_type == TABLE_TYPE_PLUGIN || table_type == TABLE_TYPE_COMPILE ||
|
||||
table_type == TABLE_TYPE_GROUP2COMPILE || table_type == TABLE_TYPE_GROUP2GROUP) {
|
||||
if (table_type == TABLE_TYPE_PLUGIN ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user