summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorroot <[email protected]>2024-09-20 11:20:21 +0000
committerroot <[email protected]>2024-09-20 11:20:21 +0000
commitfc99675b403baffc08da5c5ba357d58d9064427c (patch)
tree2888da8cda7ccae003a650648ed08246b2560115 /src
parent20de47c873c226ffa1717e5d6ad47ac4ce4c8d1b (diff)
change type of rule_id, object_id, item_id from (long long) to (uuid_t)
just compile libmaatframe.so, without modifing about test case
Diffstat (limited to 'src')
-rw-r--r--src/inc_internal/maat_core.h4
-rw-r--r--src/inc_internal/maat_object.h22
-rw-r--r--src/inc_internal/maat_rule.h4
-rw-r--r--src/maat_api.c32
-rw-r--r--src/maat_bool_plugin.c2
-rw-r--r--src/maat_config_monitor.c4
-rw-r--r--src/maat_expr.c74
-rw-r--r--src/maat_flag.c38
-rw-r--r--src/maat_fqdn_plugin.c2
-rw-r--r--src/maat_interval.c40
-rw-r--r--src/maat_ip.c39
-rw-r--r--src/maat_ip_plugin.c2
-rw-r--r--src/maat_ipport_plugin.c6
-rw-r--r--src/maat_object.c791
-rw-r--r--src/maat_rule.c343
-rw-r--r--src/maat_stat.c8
-rw-r--r--src/maat_table.c12
17 files changed, 726 insertions, 697 deletions
diff --git a/src/inc_internal/maat_core.h b/src/inc_internal/maat_core.h
index f861ee6..c138362 100644
--- a/src/inc_internal/maat_core.h
+++ b/src/inc_internal/maat_core.h
@@ -53,8 +53,8 @@ enum tag_match {
};
struct maat_item {
- long long item_id;
- long long object_id;
+ uuid_t item_uuid;
+ uuid_t object_uuid;
};
struct maat_runtime {
diff --git a/src/inc_internal/maat_object.h b/src/inc_internal/maat_object.h
index 5cdf824..6d13e46 100644
--- a/src/inc_internal/maat_object.h
+++ b/src/inc_internal/maat_object.h
@@ -28,28 +28,28 @@ struct object2object_runtime;
/* object2object schema API */
void *object2object_schema_new(cJSON *json, struct table_manager *tbl_mgr,
const char *table_name, struct log_handle *logger);
-void object2object_schema_free(void *g2g_schema);
+void object2object_schema_free(void *o2o_schema);
/* object2object runtime API */
-void *object2object_runtime_new(void *g2g_schema, size_t max_thread_num,
+void *object2object_runtime_new(void *o2o_schema, size_t max_thread_num,
struct maat_garbage_bin *garbage_bin,
struct log_handle *logger);
-void object2object_runtime_free(void *g2g_runtime);
+void object2object_runtime_free(void *o2o_runtime);
-int object2object_runtime_update(void *g2g_runtime, void *g2g_schema, const char *table_name,
+int object2object_runtime_update(void *o2o_runtime, void *o2o_schema, const char *table_name,
const char *line, enum maat_operation op);
-int object2object_runtime_commit(void *g2g_runtime, const char *table_name, long long maat_rt_version);
+int object2object_runtime_commit(void *o2o_runtime, const char *table_name, long long maat_rt_version);
-size_t object2object_runtime_get_super_objects(void *g2g_runtime, long long *object_ids,
- size_t n_object_ids, long long *super_object_ids,
- size_t super_object_ids_size);
+size_t object2object_runtime_get_super_objects(void *o2o_runtime, uuid_t *object_uuids,
+ size_t n_object_uuids, uuid_t *super_object_uuids,
+ size_t super_object_uuids_size);
-long long object2object_runtime_rule_count(void *g2g_runtime);
+long long object2object_runtime_rule_count(void *o2o_runtime);
-long long object2object_runtime_exclude_rule_count(void *g2g_runtime);
+long long object2object_runtime_exclude_rule_count(void *o2o_runtime);
-long long object2object_runtime_update_err_count(void *g2g_runtime);
+long long object2object_runtime_update_err_count(void *o2o_runtime);
#ifdef __cplusplus
}
diff --git a/src/inc_internal/maat_rule.h b/src/inc_internal/maat_rule.h
index b2c3083..3b8008e 100644
--- a/src/inc_internal/maat_rule.h
+++ b/src/inc_internal/maat_rule.h
@@ -51,7 +51,7 @@ long long rule_runtime_rule_count(void *rule_runtime);
long long rule_runtime_update_err_count(void *rule_runtime);
-int rule_runtime_match(struct rule_runtime *rule_rt, long long *rule_ids,
+int rule_runtime_match(struct rule_runtime *rule_rt, uuid_t *rule_uuids,
size_t rule_ids_size, struct maat_state *state);
size_t rule_runtime_get_hit_paths(struct rule_runtime *rule_rt, int thread_id,
@@ -81,7 +81,7 @@ void rule_compile_state_not_logic_update(struct rule_compile_state *rule_compile
size_t rule_compile_state_get_internal_hit_paths(struct rule_compile_state *rule_compile_state,
struct rule_runtime *rule_rt,
- struct object2object_runtime *g2g_rt,
+ struct object2object_runtime *o2o_rt,
struct maat_hit_path *hit_path_array,
size_t array_size);
diff --git a/src/maat_api.c b/src/maat_api.c
index 04f5be5..8db25ac 100644
--- a/src/maat_api.c
+++ b/src/maat_api.c
@@ -1184,7 +1184,7 @@ string_scan(struct table_manager *tbl_mgr, int thread_id,
}
static size_t
-object_to_rule(struct maat *maat_inst, long long *results, size_t n_result,
+object_to_rule(struct maat *maat_inst, uuid_t *results, size_t n_result,
struct maat_state *state)
{
int rule_table_id =
@@ -1205,7 +1205,7 @@ object_to_rule(struct maat *maat_inst, long long *results, size_t n_result,
}
int maat_scan_flag(struct maat *maat_inst, int attribute_id,
- long long flag, long long *results, size_t n_result,
+ long long flag, uuid_t *results, size_t n_result,
size_t *n_hit_result, struct maat_state *state)
{
if ((NULL == maat_inst) || attribute_id < 0 || attribute_id >= MAX_ATTRIBUTE_NUM ||
@@ -1284,7 +1284,7 @@ int maat_scan_flag(struct maat *maat_inst, int attribute_id,
}
int maat_scan_integer(struct maat *maat_inst, int attribute_id,
- long long integer, long long *results, size_t n_result,
+ long long integer, uuid_t *results, size_t n_result,
size_t *n_hit_result, struct maat_state *state)
{
if ((NULL == maat_inst) || attribute_id < 0 || attribute_id >= MAX_ATTRIBUTE_NUM ||
@@ -1364,7 +1364,7 @@ int maat_scan_integer(struct maat *maat_inst, int attribute_id,
}
int maat_scan_ipv4_port(struct maat *maat_inst, int attribute_id, uint32_t ip_addr,
- int port, long long *results, size_t n_result,
+ int port, uuid_t *results, size_t n_result,
size_t *n_hit_result, struct maat_state *state)
{
if ((NULL == maat_inst) || attribute_id < 0 || attribute_id >= MAX_ATTRIBUTE_NUM ||
@@ -1443,7 +1443,7 @@ int maat_scan_ipv4_port(struct maat *maat_inst, int attribute_id, uint32_t ip_ad
}
int maat_scan_ipv6_port(struct maat *maat_inst, int attribute_id, uint8_t *ip_addr,
- int port, long long *results, size_t n_result,
+ int port, uuid_t *results, size_t n_result,
size_t *n_hit_result, struct maat_state *state)
{
if ((NULL == maat_inst) || attribute_id < 0 || attribute_id >= MAX_ATTRIBUTE_NUM ||
@@ -1523,7 +1523,7 @@ int maat_scan_ipv6_port(struct maat *maat_inst, int attribute_id, uint8_t *ip_ad
#define PORT_IGNORED -1
inline int maat_scan_ipv6(struct maat *instance, int attribute_id, uint8_t *ip_addr,
- long long *results, size_t n_result, size_t *n_hit_result,
+ uuid_t *results, size_t n_result, size_t *n_hit_result,
struct maat_state *state)
{
return maat_scan_ipv6_port(instance, attribute_id, ip_addr, PORT_IGNORED,
@@ -1531,7 +1531,7 @@ inline int maat_scan_ipv6(struct maat *instance, int attribute_id, uint8_t *ip_a
}
inline int maat_scan_ipv4(struct maat *instance, int attribute_id, uint32_t ip_addr,
- long long *results, size_t n_result, size_t *n_hit_result,
+ uuid_t *results, size_t n_result, size_t *n_hit_result,
struct maat_state *state)
{
return maat_scan_ipv4_port(instance, attribute_id, ip_addr, PORT_IGNORED,
@@ -1540,7 +1540,7 @@ inline int maat_scan_ipv4(struct maat *instance, int attribute_id, uint32_t ip_a
int maat_scan_string(struct maat *maat_inst, int attribute_id,
const char *data, size_t data_len,
- long long *results, size_t n_result,
+ uuid_t *results, size_t n_result,
size_t *n_hit_result, struct maat_state *state)
{
if ((NULL == maat_inst) || attribute_id < 0 || attribute_id >= MAX_ATTRIBUTE_NUM ||
@@ -1642,8 +1642,8 @@ static void maat_state_add_hit_object(struct maat_state *state, int attribute_id
struct maat_item hit_items[n_hit_item];
for (size_t i = 0; i < n_hit_item; i++) {
- hit_items[i].item_id = objects[i].item_id;
- hit_items[i].object_id = objects[i].object_id;
+ uuid_copy(hit_items[i].item_uuid, objects[i].item_uuid);
+ uuid_copy(hit_items[i].object_uuid, objects[i].object_uuid);
}
rule_compile_state_update(state->rule_compile_state, maat_inst, attribute_id,
@@ -1682,7 +1682,7 @@ maat_state_activate_hit_not_object(struct maat_state *state, int attribute_id)
int maat_scan_object(struct maat *maat_inst, int attribute_id,
struct maat_hit_object *objects, size_t n_object,
- long long *results, size_t n_result,
+ uuid_t *results, size_t n_result,
size_t *n_hit_result, struct maat_state *state)
{
if ((NULL == maat_inst) || attribute_id < 0 || attribute_id >= MAX_ATTRIBUTE_NUM ||
@@ -1724,7 +1724,7 @@ int maat_scan_object(struct maat *maat_inst, int attribute_id,
}
int maat_scan_not_logic(struct maat *maat_inst, int attribute_id,
- long long *results, size_t n_result,
+ uuid_t *results, size_t n_result,
size_t *n_hit_result, struct maat_state *state)
{
if ((NULL == maat_inst) || attribute_id < 0 || attribute_id >= MAX_ATTRIBUTE_NUM ||
@@ -1848,7 +1848,7 @@ static int expr_stream_scan(struct maat_stream *stream, const char *data,
}
int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data_len,
- long long *results, size_t n_result, size_t *n_hit_result,
+ uuid_t *results, size_t n_result, size_t *n_hit_result,
struct maat_state *state)
{
if ((NULL == maat_stream) || (NULL == data) || (0 == data_len)
@@ -2135,13 +2135,13 @@ int maat_state_get_hit_paths(struct maat_state *state, struct maat_hit_path *pat
return -1;
}
- int g2g_table_id = table_manager_get_object2object_table_id(maat_inst->tbl_mgr);
- void *g2g_runtime = table_manager_get_runtime(maat_inst->tbl_mgr, g2g_table_id);
+ int o2o_table_id = table_manager_get_object2object_table_id(maat_inst->tbl_mgr);
+ void *o2o_runtime = table_manager_get_runtime(maat_inst->tbl_mgr, o2o_table_id);
size_t hit_path_cnt =
rule_compile_state_get_internal_hit_paths(state->rule_compile_state,
(struct rule_runtime *)rule_rt,
- (struct object2object_runtime *)g2g_runtime,
+ (struct object2object_runtime *)o2o_runtime,
path_array, array_size);
return rule_runtime_get_hit_paths((struct rule_runtime *)rule_rt,
diff --git a/src/maat_bool_plugin.c b/src/maat_bool_plugin.c
index 1751073..eac5433 100644
--- a/src/maat_bool_plugin.c
+++ b/src/maat_bool_plugin.c
@@ -314,7 +314,7 @@ bool_plugin_expr_new(struct bool_plugin_schema *schema, const char *table_name,
__LINE__, table_name, schema->key_name, cJSON_Print(json));
goto error;
}
- bool_expr->expr_id = atoll(tmp_obj->valuestring);
+ uuid_parse(tmp_obj->valuestring, bool_expr->expr_uuid);
tmp_obj = cJSON_GetObjectItem(json, "bool_expr");
if (NULL == tmp_obj || tmp_obj->type != cJSON_String) {
diff --git a/src/maat_config_monitor.c b/src/maat_config_monitor.c
index 6e091a7..6ecdeb9 100644
--- a/src/maat_config_monitor.c
+++ b/src/maat_config_monitor.c
@@ -153,7 +153,9 @@ void config_monitor_traverse(long long current_version, const cJSON *json_root,
}
}
- config_load_json_content(json_root, object2object_table->valuestring, "object_groups", u_param, update_fn);
+ if (object2object_table) {
+ config_load_json_content(json_root, object2object_table->valuestring, "object_groups", u_param, update_fn);
+ }
config_load_json_content(json_root, rule_table->valuestring, "rules", u_param, update_fn);
if (finish_fn != NULL) {
diff --git a/src/maat_expr.c b/src/maat_expr.c
index 5d76522..4fbef51 100644
--- a/src/maat_expr.c
+++ b/src/maat_expr.c
@@ -57,8 +57,8 @@ enum match_method {
};
struct expr_item {
- long long item_id;
- long long object_id;
+ uuid_t item_uuid;
+ uuid_t object_uuid;
char keywords[MAX_KEYWORDS_STR_LEN + 1];
enum expr_type expr_type;
void *user_data;
@@ -152,7 +152,7 @@ int expr_runtime_set_scan_district(struct expr_runtime *expr_rt, const char *dis
static struct expr_item *
expr_item_new(struct expr_schema *expr_schema, const char *table_name,
- const cJSON *json, struct expr_runtime *expr_rt, long long item_id)
+ const cJSON *json, struct expr_runtime *expr_rt, uuid_t item_uuid)
{
int expr_type = -1;
enum table_type table_type = TABLE_TYPE_INVALID;
@@ -161,18 +161,16 @@ expr_item_new(struct expr_schema *expr_schema, const char *table_name,
size_t len = 0;
int ret;
- expr_item->item_id = item_id;
+ uuid_copy(expr_item->item_uuid, item_uuid);
- tmp_obj = cJSON_GetObjectItem(json, "object_id");
- if (tmp_obj != NULL && tmp_obj->type == cJSON_String) {
- expr_item->object_id = tmp_obj->valueint;
- } else {
+ tmp_obj = cJSON_GetObjectItem(json, "object_uuid");
+ if (tmp_obj == NULL && tmp_obj->type != cJSON_String) {
log_fatal(expr_rt->logger, MODULE_EXPR,
"[%s:%d] expr table:<%s> has no object_id in line:%s",
__FUNCTION__, __LINE__, table_name, cJSON_Print(json));
goto error;
}
- expr_item->object_id = atoll(tmp_obj->valuestring);
+ uuid_parse(tmp_obj->valuestring, expr_item->object_uuid);
tmp_obj = cJSON_GetObjectItem(json, "keywords");
if (tmp_obj == NULL || tmp_obj->type != cJSON_String) {
@@ -209,10 +207,12 @@ expr_item_new(struct expr_schema *expr_schema, const char *table_name,
} else if (expr_item->expr_type == EXPR_TYPE_REGEX) {
ret = expr_matcher_verify_regex_expression(expr_item->keywords, expr_rt->logger);
if (0 == ret) {
+ char uuid_str[UUID_STR_LEN] = {0};
+ uuid_unparse(item_uuid, uuid_str);
log_fatal(expr_rt->logger, MODULE_EXPR,
- "[%s:%d] expr table:<%s> regex expression(item_id:%lld):%s illegal,"
+ "[%s:%d] expr table:<%s> regex expression(item_id:%s):%s illegal,"
" will be dropped", __FUNCTION__, __LINE__, table_name,
- expr_item->item_id, expr_item->keywords);
+ uuid_str, expr_item->keywords);
goto error;
}
}
@@ -432,9 +432,11 @@ static int expr_runtime_update_row(struct expr_runtime *expr_rt, char *key,
//add
ret = rcu_hash_add(expr_rt->item_hash, key, key_len, (void *)item);
if (ret < 0) {
+ char uuid_str[UUID_STR_LEN] = {0};
+ uuid_unparse(item->item_uuid, uuid_str);
log_debug(expr_rt->logger, MODULE_EXPR,
- "[%s:%d] expr item(item_id:%lld) add to item_hash failed",
- __FUNCTION__, __LINE__, item->item_id);
+ "[%s:%d] expr item(item_id:%s) add to item_hash failed",
+ __FUNCTION__, __LINE__, uuid_str);
return -1;
}
}
@@ -602,6 +604,9 @@ static int expr_item_to_expr_rule(struct expr_item *expr_item,
char *tmp = NULL;
char *saveptr = NULL;
char tmp_keywords[MAX_KEYWORDS_STR_LEN + 1];
+ char uuid_str[UUID_STR_LEN] = {0};
+
+ uuid_unparse(expr_item->item_uuid, uuid_str);
memcpy(tmp_keywords, expr_item->keywords, MAX_KEYWORDS_STR_LEN + 1);
@@ -615,17 +620,17 @@ static int expr_item_to_expr_rule(struct expr_item *expr_item,
if (i >= MAAT_MAX_EXPR_ITEM_NUM) {
log_fatal(logger, MODULE_EXPR,
- "[%s:%d]abandon config expr_item(item_id:%d) "
+ "[%s:%d]abandon config expr_item(item_id:%s) "
"too many patterns", __FUNCTION__, __LINE__,
- expr_item->item_id);
+ uuid_str);
return -1;
}
if (expr_keywords_to_expr_pattern(tmp, &expr_rule->patterns[i], logger) < 0) {
log_fatal(logger, MODULE_EXPR,
- "[%s:%d]abandon config expr_item(item_id:%d) "
+ "[%s:%d]abandon config expr_item(item_id:%s) "
"has invalid pattern %s", __FUNCTION__, __LINE__,
- expr_item->item_id, tmp);
+ uuid_str, tmp);
return -1;
}
expr_rule->patterns[i].type = EXPR_PATTERN_TYPE_STR;
@@ -646,13 +651,13 @@ static int expr_item_to_expr_rule(struct expr_item *expr_item,
break;
default:
log_fatal(logger, MODULE_EXPR,
- "[%s:%d]abandon config expr_item(item_id:%lld) has "
+ "[%s:%d]abandon config expr_item(item_id:%s) has "
"invalid expr type=%d", __FUNCTION__, __LINE__,
- expr_item->item_id, expr_item->expr_type);
+ uuid_str, expr_item->expr_type);
return -1;
}
- expr_rule->expr_id = expr_item->item_id;
+ uuid_copy(expr_rule->expr_uuid, expr_item->item_uuid);
expr_rule->tag = expr_item->user_data;
expr_rule->n_patterns = sub_expr_cnt;
@@ -681,7 +686,7 @@ int expr_runtime_update(void *expr_runtime, void *expr_schema,
return -1;
}
- tmp_obj = cJSON_GetObjectItem(json, "item_id");
+ tmp_obj = cJSON_GetObjectItem(json, "uuid");
if (tmp_obj == NULL || tmp_obj->type != cJSON_String) {
log_fatal(expr_rt->logger, MODULE_EXPR,
"[%s:%d] expr table:<%s> has no item_id in line:%s",
@@ -690,8 +695,9 @@ int expr_runtime_update(void *expr_runtime, void *expr_schema,
goto ERROR;
}
- long long item_id = atoll(tmp_obj->valuestring);
- if (item_id < 0) {
+ uuid_t item_uuid;
+ uuid_parse(tmp_obj->valuestring, item_uuid);
+ if (uuid_is_null(item_uuid)) {
log_fatal(expr_rt->logger, MODULE_EXPR,
"[%s:%d] expr table:<%s> item_id wrong"
" in table_line:%s", __FUNCTION__, __LINE__, table_name,
@@ -703,7 +709,7 @@ int expr_runtime_update(void *expr_runtime, void *expr_schema,
struct expr_item *expr_item = NULL;
if (MAAT_OP_ADD == op) {
//add
- expr_item = expr_item_new(schema, table_name, json, expr_rt, item_id);
+ expr_item = expr_item_new(schema, table_name, json, expr_rt, item_uuid);
if (NULL == expr_item) {
expr_rt->update_err_cnt++;
goto ERROR;
@@ -715,7 +721,7 @@ int expr_runtime_update(void *expr_runtime, void *expr_schema,
expr_item->user_data = item_district_id;
}
- int ret = expr_runtime_update_row(expr_rt, (char *)&item_id, sizeof(long long),
+ int ret = expr_runtime_update_row(expr_rt, (char *)&item_uuid, sizeof(item_uuid),
expr_item, op);
if (ret < 0) {
if (expr_item != NULL) {
@@ -939,17 +945,16 @@ int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id,
for (size_t i = 0; i < n_hit_item; i++) {
int tag_district_id = *(int *)(hit_results[i].user_tag);
if (tag_district_id == state->district_id || tag_district_id == DISTRICT_ANY) {
- long long item_id = hit_results[i].rule_id;
struct expr_item *expr_item = (struct expr_item *)rcu_hash_find(expr_rt->item_hash,
- (char *)&item_id,
- sizeof(long long));
+ (char *)&hit_results[i].rule_uuid,
+ sizeof(uuid_t));
if (!expr_item) {
// item config has been deleted
continue;
}
- hit_maat_items[real_hit_item_num].item_id = item_id;
- hit_maat_items[real_hit_item_num].object_id = expr_item->object_id;
+ uuid_copy(hit_maat_items[real_hit_item_num].item_uuid, expr_item->item_uuid);
+ uuid_copy(hit_maat_items[real_hit_item_num].object_uuid, expr_item->object_uuid);
real_hit_item_num++;
}
}
@@ -1034,17 +1039,16 @@ int expr_runtime_stream_scan(struct expr_runtime_stream *expr_rt_stream,
}
for (size_t i = 0; i < n_hit_item; i++) {
- long long item_id = hit_results[i].rule_id;
expr_item = (struct expr_item *)rcu_hash_find(expr_rt->item_hash,
- (char *)&item_id,
- sizeof(long long));
+ (char *)&hit_results[i].rule_uuid,
+ sizeof(uuid_t));
if (!expr_item) {
// item config has been deleted
continue;
}
- hit_maat_items[real_hit_item_cnt].item_id = item_id;
- hit_maat_items[real_hit_item_cnt].object_id = expr_item->object_id;
+ uuid_copy(hit_maat_items[real_hit_item_cnt].item_uuid, expr_item->item_uuid);
+ uuid_copy(hit_maat_items[real_hit_item_cnt].object_uuid, expr_item->object_uuid);
real_hit_item_cnt++;
}
diff --git a/src/maat_flag.c b/src/maat_flag.c
index 43cb2c2..dbc7458 100644
--- a/src/maat_flag.c
+++ b/src/maat_flag.c
@@ -30,8 +30,8 @@ struct flag_schema {
};
struct flag_item {
- long long item_id;
- long long object_id;
+ uuid_t item_uuid;
+ uuid_t object_uuid;
long long flag;
long long flag_mask;
void *user_data;
@@ -197,9 +197,11 @@ static int flag_runtime_update_row(struct flag_runtime *flag_rt, char *key,
//add
ret = rcu_hash_add(flag_rt->item_hash, key, key_len, (void *)item);
if (ret < 0) {
+ char uuid_str[UUID_STR_LEN] = {0};
+ uuid_unparse(item->item_uuid, uuid_str);
log_debug(flag_rt->logger, MODULE_FLAG,
- "[%s:%d] flag item(item_id:%lld) add to item_hash failed",
- __FUNCTION__, __LINE__, item->item_id);
+ "[%s:%d] flag item(item_uuid:%s) add to item_hash failed",
+ __FUNCTION__, __LINE__, uuid_str);
return -1;
}
}
@@ -242,22 +244,22 @@ int flag_runtime_set_scan_district(struct flag_runtime *flag_rt, const char *dis
static struct flag_item *
flag_item_new(struct flag_schema *schema, const char *table_name,
- const cJSON *json, struct flag_runtime *flag_rt, long long item_id)
+ const cJSON *json, struct flag_runtime *flag_rt, uuid_t item_uuid)
{
cJSON *tmp_obj = NULL;
enum table_type table_type = TABLE_TYPE_INVALID;
struct flag_item *item = ALLOC(struct flag_item, 1);
- item->item_id = item_id;
+ uuid_copy(item->item_uuid, item_uuid);
- tmp_obj = cJSON_GetObjectItem(json, "object_id");
+ tmp_obj = cJSON_GetObjectItem(json, "object_uuid");
if (tmp_obj == NULL || tmp_obj->type != cJSON_String) {
log_fatal(flag_rt->logger, MODULE_FLAG,
"[%s:%d] flag table:<%s> has no object_id in json:%s",
__FUNCTION__, __LINE__, table_name, cJSON_Print(json));
goto error;
}
- item->object_id = atoll(tmp_obj->valuestring);
+ uuid_parse(tmp_obj->valuestring, item->object_uuid);
table_type = table_manager_get_table_type(schema->ref_tbl_mgr, schema->table_id);
if (table_type == TABLE_TYPE_INTERVAL_PLUS) {
@@ -316,7 +318,7 @@ static struct flag_rule flag_item_to_flag_rule(struct flag_item *item)
{
struct flag_rule rule;
- rule.rule_id = item->item_id;
+ uuid_copy(rule.rule_uuid, item->item_uuid);
rule.flag = item->flag;
rule.mask = item->flag_mask;
rule.user_tag = item->user_data;
@@ -344,7 +346,7 @@ int flag_runtime_update(void *flag_runtime, void *flag_schema,
return -1;
}
- cJSON *item = cJSON_GetObjectItem(json, "item_id");
+ cJSON *item = cJSON_GetObjectItem(json, "uuid");
if (NULL == item || item->type != cJSON_String) {
log_fatal(flag_rt->logger, MODULE_FLAG,
"[%s:%d] flag table:<%s> line:%s has no item_id",
@@ -352,11 +354,12 @@ int flag_runtime_update(void *flag_runtime, void *flag_schema,
goto ERROR;
}
- long long item_id = atoll(item->valuestring);
+ uuid_t item_uuid;
+ uuid_parse(item->valuestring, item_uuid);
struct flag_item *flag_item = NULL;
if (MAAT_OP_ADD == op) {
- flag_item = flag_item_new(schema, table_name, json, flag_rt, item_id);
+ flag_item = flag_item_new(schema, table_name, json, flag_rt, item_uuid);
if (NULL == flag_item) {
flag_rt->update_err_cnt++;
goto ERROR;
@@ -368,7 +371,7 @@ int flag_runtime_update(void *flag_runtime, void *flag_schema,
flag_item->user_data = item_district_id;
}
- int ret = flag_runtime_update_row(flag_rt, (char *)&item_id, sizeof(long long),
+ int ret = flag_runtime_update_row(flag_rt, (char *)&item_uuid, sizeof(item_uuid),
flag_item, op);
if (ret < 0) {
if (flag_item != NULL) {
@@ -520,18 +523,17 @@ int flag_runtime_scan(struct flag_runtime *flag_rt, int thread_id,
int tag_district_id = *(int *)(hit_results[i].user_tag);
if (tag_district_id == state->district_id ||
tag_district_id == DISTRICT_ANY) {
- long long item_id = hit_results[i].rule_id;
struct flag_item *flag_item =
(struct flag_item *)rcu_hash_find(flag_rt->item_hash,
- (char *)&item_id,
- sizeof(long long));
+ (char *)&hit_results[i].rule_uuid,
+ sizeof(hit_results[i].rule_uuid));
if (!flag_item) {
// item config has been deleted
continue;
}
- hit_maat_items[real_hit_item_cnt].item_id = item_id;
- hit_maat_items[real_hit_item_cnt].object_id = flag_item->object_id;
+ uuid_copy(hit_maat_items[real_hit_item_cnt].item_uuid, hit_results[i].rule_uuid);
+ uuid_copy(hit_maat_items[real_hit_item_cnt].object_uuid, flag_item->object_uuid);
real_hit_item_cnt++;
}
}
diff --git a/src/maat_fqdn_plugin.c b/src/maat_fqdn_plugin.c
index 0fb2034..6083439 100644
--- a/src/maat_fqdn_plugin.c
+++ b/src/maat_fqdn_plugin.c
@@ -265,7 +265,7 @@ fqdn_plugin_rule_new(const cJSON *json, struct fqdn_plugin_schema *schema,
__FUNCTION__, __LINE__, table_name, cJSON_Print(json));
goto error;
}
- fqdn_plugin_rule->id = atoi(tmp_obj->valuestring);
+ uuid_parse(tmp_obj->valuestring, fqdn_plugin_rule->uuid);
tmp_obj = cJSON_GetObjectItem(json, "fqdn");
if (NULL == tmp_obj || tmp_obj->type != cJSON_String) {
diff --git a/src/maat_interval.c b/src/maat_interval.c
index a52a336..8eb9311 100644
--- a/src/maat_interval.c
+++ b/src/maat_interval.c
@@ -27,8 +27,8 @@ struct interval_schema {
};
struct interval_item {
- long long item_id;
- long long object_id;
+ uuid_t item_uuid;
+ uuid_t object_uuid;
int low_boundary;
int up_boundary;
void *user_data;
@@ -215,23 +215,23 @@ int interval_runtime_set_scan_district(struct interval_runtime *interval_rt,
static struct interval_item *
interval_item_new(struct interval_schema *schema, const char *table_name,
- const cJSON *json, struct interval_runtime *interval_rt, long long item_id)
+ const cJSON *json, struct interval_runtime *interval_rt, uuid_t item_uuid)
{
enum table_type table_type = TABLE_TYPE_INVALID;
char port_str[16] = {0};
struct interval_item *item = ALLOC(struct interval_item, 1);
cJSON *tmp_obj = NULL;
- item->item_id = item_id;
+ uuid_copy(item->item_uuid, item_uuid);
- tmp_obj = cJSON_GetObjectItem(json, "object_id");
+ tmp_obj = cJSON_GetObjectItem(json, "object_uuid");
if (NULL == tmp_obj || tmp_obj->type != cJSON_String) {
log_fatal(interval_rt->logger, MODULE_INTERVAL,
"[%s:%d] interval table:<%s> has no object_id in line:%s",
__FUNCTION__, __LINE__, table_name, cJSON_Print(json));
goto error;
}
- item->object_id = atoll(tmp_obj->valuestring);
+ uuid_parse(tmp_obj->valuestring, item->object_uuid);
table_type = table_manager_get_table_type(schema->ref_tbl_mgr, schema->table_id);
if (table_type == TABLE_TYPE_INTERVAL_PLUS) {
@@ -289,7 +289,7 @@ interval_item_to_interval_rule(struct interval_item *item)
rule.start = item->low_boundary;
rule.end = item->up_boundary;
- rule.result.rule_id = item->item_id;
+ uuid_copy(rule.result.rule_uuid, item->item_uuid);
rule.result.user_tag = item->user_data;
return rule;
@@ -308,10 +308,12 @@ static int interval_runtime_update_row(struct interval_runtime *interval_rt,
//add
ret = rcu_hash_add(interval_rt->item_hash, key, key_len, (void *)item);
if (ret < 0) {
+ char uuid_str[UUID_STR_LEN] = {0};
+ uuid_unparse(item->item_uuid, uuid_str);
log_debug(interval_rt->logger, MODULE_INTERVAL,
- "[%s:%d] interval item(item_id:%lld) add to "
+ "[%s:%d] interval item(item_id:%s) add to "
"interavl_item_hash failed", __FUNCTION__, __LINE__,
- item->item_id);
+ uuid_str);
return -1;
}
}
@@ -342,7 +344,7 @@ int interval_runtime_update(void *interval_runtime, void *interval_schema,
goto ERROR;
}
- tmp_obj = cJSON_GetObjectItem(json, "item_id");
+ tmp_obj = cJSON_GetObjectItem(json, "uuid");
if (NULL == tmp_obj || tmp_obj->type != cJSON_String) {
log_fatal(interval_rt->logger, MODULE_INTERVAL,
"[%s:%d] interval table:<%s> has no item_id in line:%s",
@@ -351,8 +353,9 @@ int interval_runtime_update(void *interval_runtime, void *interval_schema,
goto ERROR;
}
- long long item_id = atoll(tmp_obj->valuestring);
- if (item_id < 0) {
+ uuid_t item_uuid;
+ uuid_parse(tmp_obj->valuestring, item_uuid);
+ if (uuid_is_null(item_uuid)) {
log_fatal(interval_rt->logger, MODULE_INTERVAL,
"[%s:%d] interval table:<%s> item_id wrong"
" in table_line:%s", __FUNCTION__, __LINE__, table_name,
@@ -364,7 +367,7 @@ int interval_runtime_update(void *interval_runtime, void *interval_schema,
struct interval_item *interval_item = NULL;
if (MAAT_OP_ADD == op) {
//add
- interval_item = interval_item_new(schema, table_name, json, interval_rt, item_id);
+ interval_item = interval_item_new(schema, table_name, json, interval_rt, item_uuid);
if (NULL == interval_item) {
interval_rt->update_err_cnt++;
goto ERROR;
@@ -376,7 +379,7 @@ int interval_runtime_update(void *interval_runtime, void *interval_schema,
interval_item->user_data = item_district_id;
}
- int ret = interval_runtime_update_row(interval_rt, (char *)&item_id, sizeof(long long),
+ int ret = interval_runtime_update_row(interval_rt, (char *)&item_uuid, sizeof(uuid_t),
interval_item, op);
if (ret < 0) {
if (interval_item != NULL) {
@@ -531,18 +534,17 @@ int interval_runtime_scan(struct interval_runtime *interval_rt, int thread_id,
int tag_district_id = *(int *)(hit_results[i].user_tag);
if (tag_district_id == state->district_id ||
tag_district_id == DISTRICT_ANY) {
- long long item_id = hit_results[i].rule_id;
struct interval_item *int_item =
(struct interval_item *)rcu_hash_find(interval_rt->item_hash,
- (char *)&item_id,
- sizeof(long long));
+ (char *)&hit_results[i].rule_uuid,
+ sizeof(uuid_t));
if (!int_item) {
// item config has been deleted
continue;
}
- hit_maat_items[real_hit_item_cnt].item_id = item_id;
- hit_maat_items[real_hit_item_cnt].object_id = int_item->object_id;
+ uuid_copy(hit_maat_items[real_hit_item_cnt].item_uuid, int_item->item_uuid);
+ uuid_copy(hit_maat_items[real_hit_item_cnt].object_uuid, int_item->object_uuid);
real_hit_item_cnt++;
}
}
diff --git a/src/maat_ip.c b/src/maat_ip.c
index aa98c41..1597e34 100644
--- a/src/maat_ip.c
+++ b/src/maat_ip.c
@@ -39,8 +39,8 @@ struct ipv6_item_rule {
};
struct ip_item {
- long long item_id;
- long long object_id;
+ uuid_t item_uuid;
+ uuid_t object_uuid;
int addr_type;
union {
struct ipv4_item_rule ipv4;
@@ -98,23 +98,23 @@ void ip_schema_free(void *ip_schema)
static struct ip_item *
ip_item_new(struct ip_schema *ip_schema, const char *table_name,
- const cJSON *json, struct log_handle *logger, long long item_id)
+ const cJSON *json, struct log_handle *logger, uuid_t item_uuid)
{
char ip_str[128] = {0};
struct ip_item *ip_item = ALLOC(struct ip_item, 1);
cJSON *tmp_obj = NULL;
int ret = 0;
- ip_item->item_id = item_id;
+ uuid_copy(ip_item->item_uuid, item_uuid);
- tmp_obj = cJSON_GetObjectItem(json, "object_id");
+ tmp_obj = cJSON_GetObjectItem(json, "object_uuid");
if (NULL == tmp_obj || tmp_obj->type != cJSON_String) {
log_fatal(logger, MODULE_IP,
"[%s:%d] ip table:<%s> has no object_id in line:%s",
__FUNCTION__, __LINE__, table_name, cJSON_Print(json));
goto error;
}
- ip_item->object_id = atoll(tmp_obj->valuestring);
+ uuid_parse(tmp_obj->valuestring, ip_item->object_uuid);
tmp_obj = cJSON_GetObjectItem(json, "ip");
if (NULL == tmp_obj || tmp_obj->type != cJSON_String) {
@@ -268,7 +268,7 @@ static void ip_item_to_ip_rule(struct ip_item *item, struct ip_rule *rule)
memcpy(rule->ipv6_rule.end_ip, item->ipv6.max_ip,
sizeof(item->ipv6.max_ip));
}
- rule->rule_id = item->item_id;
+ uuid_copy(rule->rule_uuid, item->item_uuid);
}
static int ip_runtime_update_row(struct ip_runtime *ip_rt, char *key, size_t key_len,
@@ -283,9 +283,11 @@ static int ip_runtime_update_row(struct ip_runtime *ip_rt, char *key, size_t key
// add
ret = rcu_hash_add(ip_rt->item_hash, key, key_len, (void *)item);
if (ret < 0) {
+ char uuid_str[37] = {0};
+ uuid_unparse(item->item_uuid, uuid_str);
log_debug(ip_rt->logger, MODULE_IP,
- "[%s:%d] ip item(item_id:%lld) add to ip runtime htable failed",
- __FUNCTION__, __LINE__, item->item_id);
+ "[%s:%d] ip item(item_id:%s) add to ip runtime htable failed",
+ __FUNCTION__, __LINE__, uuid_str);
return -1;
}
}
@@ -315,7 +317,7 @@ int ip_runtime_update(void *ip_runtime, void *ip_schema,
goto ERROR;
}
- tmp_obj = cJSON_GetObjectItem(json, "item_id");
+ tmp_obj = cJSON_GetObjectItem(json, "uuid");
if (NULL == tmp_obj || tmp_obj->type != cJSON_String) {
log_fatal(ip_rt->logger, MODULE_IP,
"[%s:%d] ip table:<%s> has no item_id in line:%s",
@@ -323,19 +325,21 @@ int ip_runtime_update(void *ip_runtime, void *ip_schema,
ip_rt->update_err_cnt++;
goto ERROR;
}
- long long item_id = atoll(tmp_obj->valuestring);
+
+ uuid_t item_uuid;
+ uuid_parse(tmp_obj->valuestring, item_uuid);
struct ip_item *ip_item = NULL;
if (MAAT_OP_ADD == op) {
//add
- ip_item = ip_item_new(schema, table_name, json, ip_rt->logger, item_id);
+ ip_item = ip_item_new(schema, table_name, json, ip_rt->logger, item_uuid);
if (NULL == ip_item) {
ip_rt->update_err_cnt++;
goto ERROR;
}
}
- int ret = ip_runtime_update_row(ip_rt, (char *)&item_id, sizeof(long long),
+ int ret = ip_runtime_update_row(ip_rt, (char *)&item_uuid, sizeof(uuid_t),
ip_item, op);
if (ret < 0) {
if (ip_item != NULL) {
@@ -505,10 +509,9 @@ int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
}
for (size_t i = 0; i < n_hit_ip_item; i++) {
- long long item_id = ip_results[i].rule_id;
struct ip_item *ip_item = (struct ip_item *)rcu_hash_find(ip_rt->item_hash,
- (char *)&item_id,
- sizeof(long long));
+ (char *)&ip_results[i].rule_uuid,
+ sizeof(uuid_t));
if (!ip_item) {
// item config has been deleted
continue;
@@ -524,8 +527,8 @@ int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
continue;
}
- hit_maat_items[real_hit_item_cnt].item_id = ip_results[i].rule_id;
- hit_maat_items[real_hit_item_cnt].object_id = ip_item->object_id;
+ uuid_copy(hit_maat_items[real_hit_item_cnt].item_uuid, ip_item->item_uuid);
+ uuid_copy(hit_maat_items[real_hit_item_cnt].object_uuid, ip_item->object_uuid);
real_hit_item_cnt++;
}
diff --git a/src/maat_ip_plugin.c b/src/maat_ip_plugin.c
index 9881c54..1419d12 100644
--- a/src/maat_ip_plugin.c
+++ b/src/maat_ip_plugin.c
@@ -159,7 +159,7 @@ ip_plugin_rule_new(struct ip_plugin_schema *schema, const char *table_name,
__FUNCTION__, __LINE__, table_name, schema->key_name, cJSON_Print(json));
goto error;
}
- ip_plugin_rule->rule_id = atoll(tmp_obj->valuestring);
+ uuid_parse(tmp_obj->valuestring, ip_plugin_rule->rule_uuid);
tmp_obj = cJSON_GetObjectItem(json, "ip");
if (NULL == tmp_obj || tmp_obj->type != cJSON_String) {
diff --git a/src/maat_ipport_plugin.c b/src/maat_ipport_plugin.c
index d26e5bd..bb735a7 100644
--- a/src/maat_ipport_plugin.c
+++ b/src/maat_ipport_plugin.c
@@ -42,7 +42,7 @@ struct ipv6_item {
};
struct ipport_item {
- long long item_id;
+ uuid_t item_uuid;
int ip_type; //IPV4 or IPV6
union {
struct ipv4_item ipv4;
@@ -237,7 +237,7 @@ ipport_item_new(struct ipport_plugin_schema *schema, const char *table_name,
__FUNCTION__, __LINE__, table_name, cJSON_Print(json));
goto error;
}
- ipport_item->item_id = atoll(tmp_obj->valuestring);
+ uuid_parse(tmp_obj->valuestring, ipport_item->item_uuid);
tmp_obj = cJSON_GetObjectItem(json, "ip");
if (NULL == tmp_obj || tmp_obj->type != cJSON_String) {
@@ -442,7 +442,7 @@ ipport_item_to_ipport_rule(struct ipport_item *item, struct ipport_rule *rule)
rule->min_port = item->min_port;
rule->max_port = item->max_port;
}
- rule->rule_id = item->item_id;
+ uuid_copy(rule->rule_uuid, item->item_uuid);
}
static void
diff --git a/src/maat_object.c b/src/maat_object.c
index 9b1d4f5..3222718 100644
--- a/src/maat_object.c
+++ b/src/maat_object.c
@@ -23,9 +23,9 @@
#define MODULE_OBJECT module_name_str("maat.object")
struct object2object_item {
- long long object_id;
- UT_array *incl_sub_object_ids;
- UT_array *excl_sub_object_ids;
+ uuid_t object_uuid;
+ UT_array *incl_sub_object_uuids;
+ UT_array *excl_sub_object_uuids;
};
struct object2object_schema {
@@ -35,22 +35,22 @@ struct object2object_schema {
struct maat_object {
igraph_integer_t vertex_id;
- long long object_id;
+ uuid_t object_uuid;
int ref_by_super_object_cnt;
int ref_by_sub_object_cnt;
- UT_array *incl_super_object_ids;
- UT_array *excl_super_object_ids;
- UT_array *incl_sub_object_ids;
- UT_array *excl_sub_object_ids;
+ UT_array *incl_super_object_uuids;
+ UT_array *excl_super_object_uuids;
+ UT_array *incl_sub_object_uuids;
+ UT_array *excl_sub_object_uuids;
- UT_hash_handle hh_object_id;
+ UT_hash_handle hh_object_uuid;
UT_hash_handle hh_vertex_id;
};
struct maat_object_topology {
- struct maat_object *hash_by_object_id; //key: object_id, value: struct maat_object *.
+ struct maat_object *hash_by_object_uuid; //key: object_id, value: struct maat_object *.
struct maat_object *hash_by_vertex_id; //key: vetex_id, value: struct maat_object *.
igraph_t object_graph;
igraph_integer_t grp_vertex_id_generator;
@@ -61,7 +61,7 @@ struct object2object_runtime {
struct maat_object_topology *object_topo;
struct maat_object_topology *updating_object_topo;
long long rule_num;
- long long excl_rule_num; //exclude g2g rule num
+ long long excl_rule_num; //exclude o2o rule num
long long update_err_cnt;
int updating_flag;
@@ -69,46 +69,38 @@ struct object2object_runtime {
struct log_handle *logger;
};
-UT_icd ut_object_id_icd = {sizeof(long long), NULL, NULL, NULL};
+UT_icd ut_object_uuid_icd = {sizeof(uuid_t), NULL, NULL, NULL};
-static inline int compare_object_id(const void *a, const void *b)
+static inline int compare_object_uuid(const void *a, const void *b)
{
- long long ret = *(const long long *)a - *(const long long *)b;
-
- if (0 == ret) {
- return 0;
- } else if(ret < 0) {
- return -1;
- } else {
- return 1;
- }
+ return uuid_compare(*(uuid_t *)a, *(uuid_t *)b);
}
void *object2object_schema_new(cJSON *json, struct table_manager *tbl_mgr,
const char *table_name, struct log_handle *logger)
{
- struct object2object_schema *g2g_schema = ALLOC(struct object2object_schema, 1);
+ struct object2object_schema *o2o_schema = ALLOC(struct object2object_schema, 1);
cJSON *item = cJSON_GetObjectItem(json, "table_id");
if (item != NULL && item->type == cJSON_Number) {
- g2g_schema->table_id = item->valueint;
+ o2o_schema->table_id = item->valueint;
} else {
log_fatal(logger, MODULE_OBJECT,
- "[%s:%d] g2g table:<%s> schema has no table_id column",
+ "[%s:%d] o2o table:<%s> schema has no table_id column",
__FUNCTION__, __LINE__, table_name);
goto error;
}
- g2g_schema->ref_tbl_mgr = tbl_mgr;
- return g2g_schema;
+ o2o_schema->ref_tbl_mgr = tbl_mgr;
+ return o2o_schema;
error:
- FREE(g2g_schema);
+ FREE(o2o_schema);
return NULL;
}
-void object2object_schema_free(void *g2g_schema)
+void object2object_schema_free(void *o2o_schema)
{
- FREE(g2g_schema);
+ FREE(o2o_schema);
}
static void object_vertex_free(struct maat_object *object)
@@ -117,24 +109,24 @@ static void object_vertex_free(struct maat_object *object)
return;
}
- if (object->incl_super_object_ids != NULL) {
- utarray_free(object->incl_super_object_ids);
- object->incl_super_object_ids = NULL;
+ if (object->incl_super_object_uuids != NULL) {
+ utarray_free(object->incl_super_object_uuids);
+ object->incl_super_object_uuids = NULL;
}
- if (object->excl_super_object_ids != NULL) {
- utarray_free(object->excl_super_object_ids);
- object->excl_super_object_ids = NULL;
+ if (object->excl_super_object_uuids != NULL) {
+ utarray_free(object->excl_super_object_uuids);
+ object->excl_super_object_uuids = NULL;
}
- if (object->incl_sub_object_ids != NULL) {
- utarray_free(object->incl_sub_object_ids);
- object->incl_sub_object_ids = NULL;
+ if (object->incl_sub_object_uuids != NULL) {
+ utarray_free(object->incl_sub_object_uuids);
+ object->incl_sub_object_uuids = NULL;
}
- if (object->excl_sub_object_ids != NULL) {
- utarray_free(object->excl_sub_object_ids);
- object->excl_sub_object_ids = NULL;
+ if (object->excl_sub_object_uuids != NULL) {
+ utarray_free(object->excl_sub_object_uuids);
+ object->excl_sub_object_uuids = NULL;
}
FREE(object);
@@ -146,7 +138,7 @@ maat_object_topology_new(struct log_handle *logger)
struct maat_object_topology *object_topo = ALLOC(struct maat_object_topology, 1);
UNUSED int ret = 0;
- object_topo->hash_by_object_id = NULL;
+ object_topo->hash_by_object_uuid = NULL;
object_topo->hash_by_vertex_id = NULL;
ret = igraph_empty(&(object_topo->object_graph), 0, IGRAPH_DIRECTED);
@@ -166,11 +158,11 @@ static void maat_object_topology_free(struct maat_object_topology *object_topo)
struct maat_object *object = NULL, *tmp_object = NULL;
HASH_CLEAR(hh_vertex_id, object_topo->hash_by_vertex_id);//No need object memory clean up.
- HASH_ITER(hh_object_id, object_topo->hash_by_object_id, object, tmp_object) {
- HASH_DELETE(hh_object_id, object_topo->hash_by_object_id, object);
+ HASH_ITER(hh_object_uuid, object_topo->hash_by_object_uuid, object, tmp_object) {
+ HASH_DELETE(hh_object_uuid, object_topo->hash_by_object_uuid, object);
object_vertex_free(object);
}
- assert(object_topo->hash_by_object_id == NULL);
+ assert(object_topo->hash_by_object_uuid == NULL);
igraph_destroy(&object_topo->object_graph);
FREE(object_topo);
@@ -180,34 +172,34 @@ static struct maat_object *maat_object_clone(struct maat_object *object)
{
struct maat_object *object_copy = ALLOC(struct maat_object, 1);
- object_copy->object_id = object->object_id;
+ uuid_copy(object_copy->object_uuid, object->object_uuid);
object_copy->vertex_id = object->vertex_id;
object_copy->ref_by_sub_object_cnt = object->ref_by_sub_object_cnt;
object_copy->ref_by_super_object_cnt = object->ref_by_super_object_cnt;
- utarray_new(object_copy->incl_super_object_ids, &ut_object_id_icd);
- utarray_new(object_copy->excl_super_object_ids, &ut_object_id_icd);
- utarray_new(object_copy->incl_sub_object_ids, &ut_object_id_icd);
- utarray_new(object_copy->excl_sub_object_ids, &ut_object_id_icd);
+ utarray_new(object_copy->incl_super_object_uuids, &ut_object_uuid_icd);
+ utarray_new(object_copy->excl_super_object_uuids, &ut_object_uuid_icd);
+ utarray_new(object_copy->incl_sub_object_uuids, &ut_object_uuid_icd);
+ utarray_new(object_copy->excl_sub_object_uuids, &ut_object_uuid_icd);
- long long *p = NULL;
- for (p = (long long *)utarray_front(object->incl_super_object_ids); p != NULL;
- p = (long long *)utarray_next(object->incl_super_object_ids, p)) {
- utarray_push_back(object_copy->incl_super_object_ids, p);
+ uuid_t *p = NULL;
+ for (p = (uuid_t *)utarray_front(object->incl_super_object_uuids); p != NULL;
+ p = (uuid_t *)utarray_next(object->incl_super_object_uuids, p)) {
+ utarray_push_back(object_copy->incl_super_object_uuids, p);
}
- for (p = (long long *)utarray_front(object->excl_super_object_ids); p != NULL;
- p = (long long *)utarray_next(object->excl_super_object_ids, p)) {
- utarray_push_back(object_copy->excl_super_object_ids, p);
+ for (p = (uuid_t *)utarray_front(object->excl_super_object_uuids); p != NULL;
+ p = (uuid_t *)utarray_next(object->excl_super_object_uuids, p)) {
+ utarray_push_back(object_copy->excl_super_object_uuids, p);
}
- for (p = (long long *)utarray_front(object->incl_sub_object_ids); p != NULL;
- p = (long long *)utarray_next(object->incl_sub_object_ids, p)) {
- utarray_push_back(object_copy->incl_sub_object_ids, p);
+ for (p = (uuid_t *)utarray_front(object->incl_sub_object_uuids); p != NULL;
+ p = (uuid_t *)utarray_next(object->incl_sub_object_uuids, p)) {
+ utarray_push_back(object_copy->incl_sub_object_uuids, p);
}
- for (p = (long long *)utarray_front(object->excl_sub_object_ids); p != NULL;
- p = (long long *)utarray_next(object->excl_sub_object_ids, p)) {
- utarray_push_back(object_copy->excl_sub_object_ids, p);
+ for (p = (uuid_t *)utarray_front(object->excl_sub_object_uuids); p != NULL;
+ p = (uuid_t *)utarray_next(object->excl_sub_object_uuids, p)) {
+ utarray_push_back(object_copy->excl_sub_object_uuids, p);
}
return object_copy;
@@ -223,11 +215,11 @@ maat_object_topology_clone(struct maat_object_topology *object_topo)
struct maat_object_topology *object_topo_copy = ALLOC(struct maat_object_topology, 1);
struct maat_object *object = NULL, *tmp_object = NULL;
- HASH_ITER(hh_object_id, object_topo->hash_by_object_id, object, tmp_object) {
+ HASH_ITER(hh_object_uuid, object_topo->hash_by_object_uuid, object, tmp_object) {
struct maat_object *object_copy = maat_object_clone(object);
- HASH_ADD(hh_object_id, object_topo_copy->hash_by_object_id, object_id,
- sizeof(object_copy->object_id), object_copy);
+ HASH_ADD(hh_object_uuid, object_topo_copy->hash_by_object_uuid, object_uuid,
+ sizeof(object_copy->object_uuid), object_copy);
HASH_ADD(hh_vertex_id, object_topo_copy->hash_by_vertex_id, vertex_id,
sizeof(object_copy->vertex_id), object_copy);
}
@@ -239,46 +231,46 @@ maat_object_topology_clone(struct maat_object_topology *object_topo)
return object_topo_copy;
}
-void *object2object_runtime_new(void *g2g_schema, size_t max_thread_num,
+void *object2object_runtime_new(void *o2o_schema, size_t max_thread_num,
struct maat_garbage_bin *garbage_bin,
struct log_handle *logger)
{
- if (NULL == g2g_schema) {
+ if (NULL == o2o_schema) {
return NULL;
}
- struct object2object_runtime *g2g_rt = ALLOC(struct object2object_runtime, 1);
+ struct object2object_runtime *o2o_rt = ALLOC(struct object2object_runtime, 1);
- g2g_rt->object_topo = maat_object_topology_new(logger);
- g2g_rt->ref_garbage_bin = garbage_bin;
- g2g_rt->logger = logger;
+ o2o_rt->object_topo = maat_object_topology_new(logger);
+ o2o_rt->ref_garbage_bin = garbage_bin;
+ o2o_rt->logger = logger;
- return g2g_rt;
+ return o2o_rt;
}
-void object2object_runtime_free(void *g2g_runtime)
+void object2object_runtime_free(void *o2o_runtime)
{
- if (NULL == g2g_runtime) {
+ if (NULL == o2o_runtime) {
return;
}
- struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
+ struct object2object_runtime *o2o_rt = (struct object2object_runtime *)o2o_runtime;
- if (g2g_rt->object_topo != NULL) {
- maat_object_topology_free(g2g_rt->object_topo);
- g2g_rt->object_topo = NULL;
+ if (o2o_rt->object_topo != NULL) {
+ maat_object_topology_free(o2o_rt->object_topo);
+ o2o_rt->object_topo = NULL;
}
- if (g2g_rt->updating_object_topo != NULL) {
- maat_object_topology_free(g2g_rt->updating_object_topo);
- g2g_rt->updating_object_topo = NULL;
+ if (o2o_rt->updating_object_topo != NULL) {
+ maat_object_topology_free(o2o_rt->updating_object_topo);
+ o2o_rt->updating_object_topo = NULL;
}
- FREE(g2g_rt);
+ FREE(o2o_rt);
}
static struct object2object_item *
-object2object_item_new(const char *line, struct object2object_schema *g2g_schema,
+object2object_item_new(const char *line, struct object2object_schema *o2o_schema,
const char *table_name, struct log_handle *logger)
{
cJSON *tmp_obj = NULL;
@@ -286,28 +278,28 @@ object2object_item_new(const char *line, struct object2object_schema *g2g_schema
if (json == NULL) {
log_fatal(logger, MODULE_OBJECT,
- "[%s:%d] g2g table:<%s> line:<%s> parse json failed",
+ "[%s:%d] o2o table:<%s> line:<%s> parse json failed",
__FUNCTION__, __LINE__, table_name, line);
return NULL;
}
- struct object2object_item *g2g_item = ALLOC(struct object2object_item, 1);
- utarray_new(g2g_item->incl_sub_object_ids, &ut_object_id_icd);
- utarray_new(g2g_item->excl_sub_object_ids, &ut_object_id_icd);
+ struct object2object_item *o2o_item = ALLOC(struct object2object_item, 1);
+ utarray_new(o2o_item->incl_sub_object_uuids, &ut_object_uuid_icd);
+ utarray_new(o2o_item->excl_sub_object_uuids, &ut_object_uuid_icd);
- tmp_obj = cJSON_GetObjectItem(json, "object_id");
+ tmp_obj = cJSON_GetObjectItem(json, "object_uuid");
if (tmp_obj == NULL || tmp_obj->type != cJSON_String) {
log_fatal(logger, MODULE_OBJECT,
- "[%s:%d] g2g table:<%s> has no object_id or format is not string in line:%s",
+ "[%s:%d] o2o table:<%s> has no object_id or format is not string in line:%s",
__FUNCTION__, __LINE__, table_name, line);
goto error;
}
- g2g_item->object_id = atoll(tmp_obj->valuestring);
+ uuid_parse(tmp_obj->valuestring, o2o_item->object_uuid);
- tmp_obj = cJSON_GetObjectItem(json, "include_object_ids");
+ tmp_obj = cJSON_GetObjectItem(json, "include_object_uuids");
if (tmp_obj == NULL || tmp_obj->type != cJSON_Array) {
log_fatal(logger, MODULE_OBJECT,
- "[%s:%d] g2g table:<%s> has no included_sub_object_ids or format is not array in line:%s",
+ "[%s:%d] o2o table:<%s> has no included_sub_object_ids or format is not array in line:%s",
__FUNCTION__, __LINE__, table_name, line);
goto error;
}
@@ -316,25 +308,26 @@ object2object_item_new(const char *line, struct object2object_schema *g2g_schema
cJSON *item = cJSON_GetArrayItem(tmp_obj, i);
if (item == NULL || item->type != cJSON_String) {
log_fatal(logger, MODULE_OBJECT,
- "[%s:%d] g2g table:<%s> included_sub_object_ids format error in line:%s",
+ "[%s:%d] o2o table:<%s> included_sub_object_ids format error in line:%s",
__FUNCTION__, __LINE__, table_name, line);
goto error;
}
- long long object_id = atoll(item->valuestring);
- utarray_push_back(g2g_item->incl_sub_object_ids, &object_id);
+ uuid_t object_uuid;
+ uuid_parse(item->valuestring, object_uuid);
+ utarray_push_back(o2o_item->incl_sub_object_uuids, &object_uuid);
}
- if (utarray_len(g2g_item->incl_sub_object_ids) > MAX_OBJECT_CNT) {
+ if (utarray_len(o2o_item->incl_sub_object_uuids) > MAX_OBJECT_CNT) {
log_fatal(logger, MODULE_OBJECT,
- "[%s:%d] g2c table:<%s> included_sub_object_ids exceed maximum:%d in line:%s",
+ "[%s:%d] o2r table:<%s> included_sub_object_ids exceed maximum:%d in line:%s",
__FUNCTION__, __LINE__, table_name, MAX_OBJECT_CNT, line);
goto error;
}
- tmp_obj = cJSON_GetObjectItem(json, "exclude_object_ids");
+ tmp_obj = cJSON_GetObjectItem(json, "exclude_object_uuids");
if (tmp_obj == NULL || tmp_obj->type != cJSON_Array) {
log_fatal(logger, MODULE_OBJECT,
- "[%s:%d] g2g table:<%s> has no excluded_sub_object_ids or format is not array in line:%s",
+ "[%s:%d] o2o table:<%s> has no excluded_sub_object_ids or format is not array in line:%s",
__FUNCTION__, __LINE__, table_name, line);
goto error;
}
@@ -343,44 +336,45 @@ object2object_item_new(const char *line, struct object2object_schema *g2g_schema
cJSON *item = cJSON_GetArrayItem(tmp_obj, i);
if (item == NULL || item->type != cJSON_String) {
log_fatal(logger, MODULE_OBJECT,
- "[%s:%d] g2g table:<%s> excluded_sub_object_ids format error in line:%s",
+ "[%s:%d] o2o table:<%s> excluded_sub_object_ids format error in line:%s",
__FUNCTION__, __LINE__, table_name, line);
goto error;
}
- long long object_id = atoll(item->valuestring);
- utarray_push_back(g2g_item->excl_sub_object_ids, &object_id);
+ uuid_t object_uuid;
+ uuid_parse(item->valuestring, object_uuid);
+ utarray_push_back(o2o_item->excl_sub_object_uuids, &object_uuid);
}
- if (utarray_len(g2g_item->excl_sub_object_ids) > MAX_OBJECT_CNT) {
+ if (utarray_len(o2o_item->excl_sub_object_uuids) > MAX_OBJECT_CNT) {
log_fatal(logger, MODULE_OBJECT,
- "[%s:%d] g2c table:<%s> excluded_sub_object_ids exceed maximum:%d in line:%s",
+ "[%s:%d] o2r table:<%s> excluded_sub_object_ids exceed maximum:%d in line:%s",
__FUNCTION__, __LINE__, table_name, MAX_OBJECT_CNT, line);
goto error;
}
- return g2g_item;
+ return o2o_item;
error:
- FREE(g2g_item);
+ FREE(o2o_item);
return NULL;
}
-static void object2object_item_free(struct object2object_item *g2g_item)
+static void object2object_item_free(struct object2object_item *o2o_item)
{
- if (NULL == g2g_item) {
+ if (NULL == o2o_item) {
return;
}
- if (g2g_item->incl_sub_object_ids != NULL) {
- utarray_free(g2g_item->incl_sub_object_ids);
- g2g_item->incl_sub_object_ids = NULL;
+ if (o2o_item->incl_sub_object_uuids != NULL) {
+ utarray_free(o2o_item->incl_sub_object_uuids);
+ o2o_item->incl_sub_object_uuids = NULL;
}
- if (g2g_item->excl_sub_object_ids != NULL) {
- utarray_free(g2g_item->excl_sub_object_ids);
- g2g_item->excl_sub_object_ids = NULL;
+ if (o2o_item->excl_sub_object_uuids != NULL) {
+ utarray_free(o2o_item->excl_sub_object_uuids);
+ o2o_item->excl_sub_object_uuids = NULL;
}
- FREE(g2g_item);
+ FREE(o2o_item);
}
static size_t print_igraph_vector(igraph_vector_t *v, char *buff, size_t sz) {
@@ -396,23 +390,23 @@ static size_t print_igraph_vector(igraph_vector_t *v, char *buff, size_t sz) {
}
static struct maat_object *
-object_topology_add_object(struct maat_object_topology *object_topo, long long object_id)
+object_topology_add_object(struct maat_object_topology *object_topo, uuid_t object_uuid)
{
assert(object_topo != NULL);
struct maat_object *object = ALLOC(struct maat_object, 1);
- object->object_id = object_id;
+ uuid_copy(object->object_uuid, object_uuid);
object->vertex_id = object_topo->grp_vertex_id_generator++;
- utarray_new(object->incl_super_object_ids, &ut_object_id_icd);
- utarray_new(object->excl_super_object_ids, &ut_object_id_icd);
- utarray_new(object->incl_sub_object_ids, &ut_object_id_icd);
- utarray_new(object->excl_sub_object_ids, &ut_object_id_icd);
+ utarray_new(object->incl_super_object_uuids, &ut_object_uuid_icd);
+ utarray_new(object->excl_super_object_uuids, &ut_object_uuid_icd);
+ utarray_new(object->incl_sub_object_uuids, &ut_object_uuid_icd);
+ utarray_new(object->excl_sub_object_uuids, &ut_object_uuid_icd);
assert(igraph_vcount(&object_topo->object_graph)==object->vertex_id);
igraph_add_vertices(&object_topo->object_graph, 1, NULL); //Add 1 vertice.
- HASH_ADD(hh_object_id, object_topo->hash_by_object_id, object_id,
- sizeof(object->object_id), object);
+ HASH_ADD(hh_object_uuid, object_topo->hash_by_object_uuid, object_uuid,
+ sizeof(object->object_uuid), object);
HASH_ADD(hh_vertex_id, object_topo->hash_by_vertex_id, vertex_id,
sizeof(object->vertex_id), object);
@@ -444,152 +438,152 @@ static void object_topology_del_object(struct maat_object_topology *object_topo,
//We should not call igraph_delete_vertices, because this is function changes the ids of the vertices.
- HASH_DELETE(hh_object_id, object_topo->hash_by_object_id, object);
+ HASH_DELETE(hh_object_uuid, object_topo->hash_by_object_uuid, object);
HASH_DELETE(hh_vertex_id, object_topo->hash_by_vertex_id, object);
object_vertex_free(object);
}
static struct maat_object *
-object_topology_find_object(struct maat_object_topology *object_topo, long long object_id)
+object_topology_find_object(struct maat_object_topology *object_topo, uuid_t object_uuid)
{
- if (NULL == object_topo || object_id < 0) {
+ if (NULL == object_topo || uuid_is_null(object_uuid)) {
return NULL;
}
struct maat_object *object = NULL;
- HASH_FIND(hh_object_id, object_topo->hash_by_object_id, &object_id, sizeof(object_id), object);
+ HASH_FIND(hh_object_uuid, object_topo->hash_by_object_uuid, (char*)&object_uuid, sizeof(uuid_t), object);
return object;
}
static void maat_object_reference_super_object(struct maat_object *object,
- long long super_object_id,
+ uuid_t super_object_uuid,
int is_exclude)
{
- if (NULL == object || super_object_id < 0) {
+ if (NULL == object || uuid_is_null(super_object_uuid)) {
return;
}
if (0 == is_exclude) {
//include superior object
- if (!utarray_find(object->incl_super_object_ids, &super_object_id,
- compare_object_id)) {
- utarray_push_back(object->incl_super_object_ids, &super_object_id);
- utarray_sort(object->incl_super_object_ids, compare_object_id);
+ if (!utarray_find(object->incl_super_object_uuids, &super_object_uuid,
+ compare_object_uuid)) {
+ utarray_push_back(object->incl_super_object_uuids, &super_object_uuid);
+ utarray_sort(object->incl_super_object_uuids, compare_object_uuid);
}
} else {
//exclude superior object
- if (!utarray_find(object->excl_super_object_ids, &super_object_id,
- compare_object_id)) {
- utarray_push_back(object->excl_super_object_ids, &super_object_id);
- utarray_sort(object->excl_super_object_ids, compare_object_id);
+ if (!utarray_find(object->excl_super_object_uuids, &super_object_uuid,
+ compare_object_uuid)) {
+ utarray_push_back(object->excl_super_object_uuids, &super_object_uuid);
+ utarray_sort(object->excl_super_object_uuids, compare_object_uuid);
}
}
}
static void maat_object_reference_sub_object(struct maat_object *object,
- long long sub_object_id,
+ uuid_t sub_object_uuid,
int is_exclude)
{
- if (NULL == object || sub_object_id < 0) {
+ if (NULL == object || uuid_is_null(sub_object_uuid)) {
return;
}
if (0 == is_exclude) {
//include sub object
- if (!utarray_find(object->incl_sub_object_ids, &sub_object_id,
- compare_object_id)) {
- utarray_push_back(object->incl_sub_object_ids, &sub_object_id);
- utarray_sort(object->incl_sub_object_ids, compare_object_id);
+ if (!utarray_find(object->incl_sub_object_uuids, &sub_object_uuid,
+ compare_object_uuid)) {
+ utarray_push_back(object->incl_sub_object_uuids, &sub_object_uuid);
+ utarray_sort(object->incl_sub_object_uuids, compare_object_uuid);
}
} else {
//exclude sub object
- if (!utarray_find(object->excl_sub_object_ids, &sub_object_id,
- compare_object_id)) {
- utarray_push_back(object->excl_sub_object_ids, &sub_object_id);
- utarray_sort(object->excl_sub_object_ids, compare_object_id);
+ if (!utarray_find(object->excl_sub_object_uuids, &sub_object_uuid,
+ compare_object_uuid)) {
+ utarray_push_back(object->excl_sub_object_uuids, &sub_object_uuid);
+ utarray_sort(object->excl_sub_object_uuids, compare_object_uuid);
}
}
}
static void maat_object_dereference_super_object(struct maat_object *object,
- long long super_object_id,
+ uuid_t super_object_uuid,
int is_exclude)
{
- if (NULL == object || super_object_id < 0) {
+ if (NULL == object || uuid_is_null(super_object_uuid)) {
return;
}
size_t remove_idx = 0;
- long long *tmp_id = NULL;
+ uuid_t *tmp_uuid = NULL;
if (0 == is_exclude) {
//include superior object
- tmp_id = utarray_find(object->incl_super_object_ids, &super_object_id,
- compare_object_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(object->incl_super_object_ids, tmp_id);
- utarray_erase(object->incl_super_object_ids, remove_idx, 1);
+ tmp_uuid = utarray_find(object->incl_super_object_uuids, &super_object_uuid,
+ compare_object_uuid);
+ if (tmp_uuid != NULL) {
+ remove_idx = utarray_eltidx(object->incl_super_object_uuids, tmp_uuid);
+ utarray_erase(object->incl_super_object_uuids, remove_idx, 1);
}
} else {
//exclude superior object
- tmp_id = utarray_find(object->excl_super_object_ids, &super_object_id,
- compare_object_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(object->excl_super_object_ids, tmp_id);
- utarray_erase(object->excl_super_object_ids, remove_idx, 1);
+ tmp_uuid = utarray_find(object->excl_super_object_uuids, &super_object_uuid,
+ compare_object_uuid);
+ if (tmp_uuid != NULL) {
+ remove_idx = utarray_eltidx(object->excl_super_object_uuids, tmp_uuid);
+ utarray_erase(object->excl_super_object_uuids, remove_idx, 1);
}
}
}
static void maat_object_dereference_sub_object(struct maat_object *object,
- long long sub_object_id,
+ uuid_t sub_object_uuid,
int is_exclude)
{
- if (NULL == object || sub_object_id < 0) {
+ if (NULL == object || uuid_is_null(sub_object_uuid)) {
return;
}
size_t remove_idx = 0;
- long long *tmp_id = NULL;
+ uuid_t *tmp_uuid = NULL;
if (0 == is_exclude) {
//include superior object
- tmp_id = utarray_find(object->incl_sub_object_ids, &sub_object_id,
- compare_object_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(object->incl_sub_object_ids, tmp_id);
- utarray_erase(object->incl_sub_object_ids, remove_idx, 1);
+ tmp_uuid = utarray_find(object->incl_sub_object_uuids, &sub_object_uuid,
+ compare_object_uuid);
+ if (tmp_uuid != NULL) {
+ remove_idx = utarray_eltidx(object->incl_sub_object_uuids, tmp_uuid);
+ utarray_erase(object->incl_sub_object_uuids, remove_idx, 1);
}
} else {
//exclude superior object
- tmp_id = utarray_find(object->excl_sub_object_ids, &sub_object_id,
- compare_object_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(object->excl_sub_object_ids, tmp_id);
- utarray_erase(object->excl_sub_object_ids, remove_idx, 1);
+ tmp_uuid = utarray_find(object->excl_sub_object_uuids, &sub_object_uuid,
+ compare_object_uuid);
+ if (tmp_uuid != NULL) {
+ remove_idx = utarray_eltidx(object->excl_sub_object_uuids, tmp_uuid);
+ utarray_erase(object->excl_sub_object_uuids, remove_idx, 1);
}
}
}
static int object_topology_add_object_to_object(struct maat_object_topology *object_topo,
- long long object_id, long long sub_object_id,
+ uuid_t object_uuid, uuid_t sub_object_uuid,
int is_exclude)
{
if (NULL == object_topo) {
return -1;
}
- struct maat_object *sub_object = object_topology_find_object(object_topo, sub_object_id);
+ struct maat_object *sub_object = object_topology_find_object(object_topo, sub_object_uuid);
if (NULL == sub_object) {
- sub_object = object_topology_add_object(object_topo, sub_object_id);
+ sub_object = object_topology_add_object(object_topo, sub_object_uuid);
}
- struct maat_object *object = object_topology_find_object(object_topo, object_id);
+ struct maat_object *object = object_topology_find_object(object_topo, object_uuid);
if (NULL == object) {
- object = object_topology_add_object(object_topo, object_id);
+ object = object_topology_add_object(object_topo, object_uuid);
}
- maat_object_reference_super_object(sub_object, object_id, is_exclude);
- maat_object_reference_sub_object(object, sub_object_id, is_exclude);
+ maat_object_reference_super_object(sub_object, object_uuid, is_exclude);
+ maat_object_reference_sub_object(object, sub_object_uuid, is_exclude);
igraph_integer_t edge_id;
int ret = igraph_get_eid(&object_topo->object_graph, &edge_id, sub_object->vertex_id,
@@ -597,9 +591,13 @@ static int object_topology_add_object_to_object(struct maat_object_topology *obj
//No duplicated edges between two objects.
if (edge_id > 0) {
+ char object_uuid_str[37] = {0};
+ char sub_object_uuid_str[37] = {0};
+ uuid_unparse(object_uuid, object_uuid_str);
+ uuid_unparse(sub_object_uuid, sub_object_uuid_str);
log_fatal(object_topo->logger, MODULE_OBJECT,
- "[%s:%d] Add object %d to object %d failed, relation already existed.",
- __FUNCTION__, __LINE__, sub_object->object_id, object->object_id);
+ "[%s:%d] Add object %s to object %s failed, relation already existed.",
+ __FUNCTION__, __LINE__, sub_object_uuid_str, object_uuid_str);
ret = -1;
} else {
igraph_add_edge(&object_topo->object_graph, sub_object->vertex_id,
@@ -612,9 +610,13 @@ static int object_topology_add_object_to_object(struct maat_object_topology *obj
igraph_bool_t is_dag;
igraph_is_dag(&(object_topo->object_graph), &is_dag);
if (!is_dag) {
+ char object_uuid_str[37] = {0};
+ char sub_object_uuid_str[37] = {0};
+ uuid_unparse(object_uuid, object_uuid_str);
+ uuid_unparse(sub_object_uuid, sub_object_uuid_str);
log_fatal(object_topo->logger, MODULE_OBJECT,
- "[%s:%d] Sub object cycle detected, sub_object_id:%lld, object_id:%lld!",
- __FUNCTION__, __LINE__, sub_object_id, object_id);
+ "[%s:%d] Sub object cycle detected, sub_object_id:%s, object_id:%s!",
+ __FUNCTION__, __LINE__, sub_object_uuid_str, object_uuid_str);
return -1;
}
@@ -622,7 +624,7 @@ static int object_topology_add_object_to_object(struct maat_object_topology *obj
}
static int object_topology_del_object_from_object(struct maat_object_topology *object_topo,
- long long object_id, long long sub_object_id,
+ uuid_t object_uuid, uuid_t sub_object_uuid,
int is_exclude)
{
if (NULL == object_topo) {
@@ -630,24 +632,32 @@ static int object_topology_del_object_from_object(struct maat_object_topology *o
}
//No hash write operation, LOCK protection is unnecessary.
- struct maat_object *sub_object = object_topology_find_object(object_topo, sub_object_id);
+ struct maat_object *sub_object = object_topology_find_object(object_topo, sub_object_uuid);
if (NULL == sub_object) {
+ char object_uuid_str[37] = {0};
+ char sub_object_uuid_str[37] = {0};
+ uuid_unparse(object_uuid, object_uuid_str);
+ uuid_unparse(sub_object_uuid, sub_object_uuid_str);
log_fatal(object_topo->logger, MODULE_OBJECT,
- "[%s:%d] Del object %d from object %d failed, object %d not existed.",
- __FUNCTION__, __LINE__, sub_object_id, object_id, sub_object_id);
+ "[%s:%d] Del object %s from object %s failed, object %s not existed.",
+ __FUNCTION__, __LINE__, sub_object_uuid_str, object_uuid_str, sub_object_uuid_str);
return -1;
}
- struct maat_object *object = object_topology_find_object(object_topo, object_id);
+ struct maat_object *object = object_topology_find_object(object_topo, object_uuid);
if (NULL == object) {
+ char object_uuid_str[37] = {0};
+ char sub_object_uuid_str[37] = {0};
+ uuid_unparse(object_uuid, object_uuid_str);
+ uuid_unparse(sub_object_uuid, sub_object_uuid_str);
log_fatal(object_topo->logger, MODULE_OBJECT,
- "[%s:%d] Del object %d from object %d failed, object %d not existed.",
- __FUNCTION__, __LINE__, sub_object_id, object_id, object_id);
+ "[%s:%d] Del object %s from object %s failed, object %s not existed.",
+ __FUNCTION__, __LINE__, sub_object_uuid_str, object_uuid_str, object_uuid_str);
return -1;
}
- maat_object_dereference_super_object(sub_object, object_id, is_exclude);
- maat_object_dereference_sub_object(object, sub_object_id, is_exclude);
+ maat_object_dereference_super_object(sub_object, object_uuid, is_exclude);
+ maat_object_dereference_sub_object(object, sub_object_uuid, is_exclude);
igraph_es_t es;
igraph_integer_t edge_num_before = 0, edge_num_after = 0;
@@ -694,7 +704,7 @@ static int object_topology_build_super_objects(struct maat_object_topology *obje
}
struct maat_object *object = NULL, *tmp_object = NULL;
- HASH_ITER (hh_object_id, object_topo->hash_by_object_id, object, tmp_object) {
+ HASH_ITER (hh_object_uuid, object_topo->hash_by_object_uuid, object, tmp_object) {
//Orphan, Not reference by any one, free it.
if (0 == object->ref_by_super_object_cnt
&& 0 == object->ref_by_sub_object_cnt) {
@@ -706,93 +716,93 @@ static int object_topology_build_super_objects(struct maat_object_topology *obje
return 0;
}
-int object2object_runtime_update(void *g2g_runtime, void *g2g_schema,
+int object2object_runtime_update(void *o2o_runtime, void *o2o_schema,
const char *table_name, const char *line,
enum maat_operation op)
{
- if (NULL == g2g_runtime || NULL == g2g_schema ||
+ if (NULL == o2o_runtime || NULL == o2o_schema ||
NULL == line) {
return -1;
}
- struct object2object_schema *schema = (struct object2object_schema *)g2g_schema;
- struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
+ struct object2object_schema *schema = (struct object2object_schema *)o2o_schema;
+ struct object2object_runtime *o2o_rt = (struct object2object_runtime *)o2o_runtime;
- struct object2object_item *g2g_item = object2object_item_new(line, schema, table_name,
- g2g_rt->logger);
- if (NULL == g2g_item) {
- g2g_rt->update_err_cnt++;
+ struct object2object_item *o2o_item = object2object_item_new(line, schema, table_name,
+ o2o_rt->logger);
+ if (NULL == o2o_item) {
+ o2o_rt->update_err_cnt++;
return -1;
}
- if (0 == g2g_rt->updating_flag) {
- assert(g2g_rt->updating_object_topo == NULL);
- g2g_rt->updating_object_topo = maat_object_topology_clone(g2g_rt->object_topo);
- g2g_rt->updating_flag = 1;
+ if (0 == o2o_rt->updating_flag) {
+ assert(o2o_rt->updating_object_topo == NULL);
+ o2o_rt->updating_object_topo = maat_object_topology_clone(o2o_rt->object_topo);
+ o2o_rt->updating_flag = 1;
}
int ret = 0;
size_t i = 0;
int err_flag = 0;
- long long *sub_object_id = NULL;
+ uuid_t *sub_object_uuid = NULL;
if (MAAT_OP_DEL == op) {
//delete
- for (i = 0; i < utarray_len(g2g_item->incl_sub_object_ids); i++) {
- sub_object_id = (long long *)utarray_eltptr(g2g_item->incl_sub_object_ids, i);
- ret = object_topology_del_object_from_object(g2g_rt->updating_object_topo,
- g2g_item->object_id, *sub_object_id, 0);
+ for (i = 0; i < utarray_len(o2o_item->incl_sub_object_uuids); i++) {
+ sub_object_uuid = (uuid_t *)utarray_eltptr(o2o_item->incl_sub_object_uuids, i);
+ ret = object_topology_del_object_from_object(o2o_rt->updating_object_topo,
+ o2o_item->object_uuid, *sub_object_uuid, 0);
if (ret != 0) {
err_flag = 1;
}
}
- for (i = 0; i < utarray_len(g2g_item->excl_sub_object_ids); i++) {
- sub_object_id = (long long *)utarray_eltptr(g2g_item->excl_sub_object_ids, i);
- ret = object_topology_del_object_from_object(g2g_rt->updating_object_topo,
- g2g_item->object_id, *sub_object_id, 1);
+ for (i = 0; i < utarray_len(o2o_item->excl_sub_object_uuids); i++) {
+ sub_object_uuid = (uuid_t *)utarray_eltptr(o2o_item->excl_sub_object_uuids, i);
+ ret = object_topology_del_object_from_object(o2o_rt->updating_object_topo,
+ o2o_item->object_uuid, *sub_object_uuid, 1);
if (ret != 0) {
err_flag = 1;
}
}
if (1 == err_flag) {
- g2g_rt->update_err_cnt++;
+ o2o_rt->update_err_cnt++;
} else {
- if (utarray_len(g2g_item->excl_sub_object_ids) > 0) {
- g2g_rt->excl_rule_num--;
+ if (utarray_len(o2o_item->excl_sub_object_uuids) > 0) {
+ o2o_rt->excl_rule_num--;
}
- g2g_rt->rule_num--;
+ o2o_rt->rule_num--;
}
} else {
//add
- for (i = 0; i < utarray_len(g2g_item->incl_sub_object_ids); i++) {
- sub_object_id = (long long *)utarray_eltptr(g2g_item->incl_sub_object_ids, i);
- ret = object_topology_add_object_to_object(g2g_rt->updating_object_topo,
- g2g_item->object_id, *sub_object_id, 0);
+ for (i = 0; i < utarray_len(o2o_item->incl_sub_object_uuids); i++) {
+ sub_object_uuid = (uuid_t *)utarray_eltptr(o2o_item->incl_sub_object_uuids, i);
+ ret = object_topology_add_object_to_object(o2o_rt->updating_object_topo,
+ o2o_item->object_uuid, *sub_object_uuid, 0);
if (ret != 0) {
err_flag = 1;
}
}
- for (i = 0; i < utarray_len(g2g_item->excl_sub_object_ids); i++) {
- sub_object_id = (long long *)utarray_eltptr(g2g_item->excl_sub_object_ids, i);
- ret = object_topology_add_object_to_object(g2g_rt->updating_object_topo,
- g2g_item->object_id, *sub_object_id, 1);
+ for (i = 0; i < utarray_len(o2o_item->excl_sub_object_uuids); i++) {
+ sub_object_uuid = (uuid_t *)utarray_eltptr(o2o_item->excl_sub_object_uuids, i);
+ ret = object_topology_add_object_to_object(o2o_rt->updating_object_topo,
+ o2o_item->object_uuid, *sub_object_uuid, 1);
if (ret != 0) {
err_flag = 1;
}
}
if (1 == err_flag) {
- g2g_rt->update_err_cnt++;
+ o2o_rt->update_err_cnt++;
} else {
- if (utarray_len(g2g_item->excl_sub_object_ids) > 0) {
- g2g_rt->excl_rule_num++;
+ if (utarray_len(o2o_item->excl_sub_object_uuids) > 0) {
+ o2o_rt->excl_rule_num++;
}
- g2g_rt->rule_num++;
+ o2o_rt->rule_num++;
}
}
- object2object_item_free(g2g_item);
+ object2object_item_free(o2o_item);
return ret;
}
@@ -803,43 +813,43 @@ static void garbage_maat_object_topology_free(void *data, void *arg)
maat_object_topology_free(object_topo);
}
-int object2object_runtime_commit(void *g2g_runtime, const char *table_name,
+int object2object_runtime_commit(void *o2o_runtime, const char *table_name,
long long maat_rt_version)
{
- if (NULL == g2g_runtime) {
+ if (NULL == o2o_runtime) {
return -1;
}
- struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
- if (0 == g2g_rt->updating_flag) {
+ struct object2object_runtime *o2o_rt = (struct object2object_runtime *)o2o_runtime;
+ if (0 == o2o_rt->updating_flag) {
return 0;
}
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
- int ret = object_topology_build_super_objects(g2g_rt->updating_object_topo);
+ int ret = object_topology_build_super_objects(o2o_rt->updating_object_topo);
clock_gettime(CLOCK_MONOTONIC, &end);
long long time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 +
(end.tv_nsec - start.tv_nsec) / 1000000;
if (ret < 0) {
- log_fatal(g2g_rt->logger, MODULE_OBJECT,
+ log_fatal(o2o_rt->logger, MODULE_OBJECT,
"[%s:%d] table[%s] object2object runtime commit failed",
__FUNCTION__, __LINE__, table_name);
return -1;
}
- struct maat_object_topology *old_object_topo = g2g_rt->object_topo;
- g2g_rt->object_topo = g2g_rt->updating_object_topo;
- g2g_rt->updating_object_topo = NULL;
- g2g_rt->updating_flag = 0;
+ struct maat_object_topology *old_object_topo = o2o_rt->object_topo;
+ o2o_rt->object_topo = o2o_rt->updating_object_topo;
+ o2o_rt->updating_object_topo = NULL;
+ o2o_rt->updating_flag = 0;
- maat_garbage_bagging(g2g_rt->ref_garbage_bin, old_object_topo, NULL,
+ maat_garbage_bagging(o2o_rt->ref_garbage_bin, old_object_topo, NULL,
garbage_maat_object_topology_free);
- log_info(g2g_rt->logger, MODULE_OBJECT,
- "table[%s] commit %zu g2g rules and rebuild super_objects completed,"
- " version:%lld, consume:%lldms", table_name, g2g_rt->rule_num,
+ log_info(o2o_rt->logger, MODULE_OBJECT,
+ "table[%s] commit %zu o2o rules and rebuild super_objects completed,"
+ " version:%lld, consume:%lldms", table_name, o2o_rt->rule_num,
maat_rt_version, time_elapse_ms);
return 0;
@@ -847,78 +857,78 @@ int object2object_runtime_commit(void *g2g_runtime, const char *table_name,
#define MAX_RECURSION_DEPTH 5
static void get_candidate_super_object_ids(struct maat_object_topology *object_topo,
- UT_array *hit_object_ids,
- UT_array *super_object_ids)
+ UT_array *hit_object_uuids,
+ UT_array *super_object_uuids)
{
- long long *p = NULL;
+ uuid_t *p = NULL;
//Find super candidates
- for (p = (long long *)utarray_front(hit_object_ids); p != NULL;
- p = (long long *)utarray_next(hit_object_ids, p)) {
+ for (p = (uuid_t *)utarray_front(hit_object_uuids); p != NULL;
+ p = (uuid_t *)utarray_next(hit_object_uuids, p)) {
struct maat_object *object = object_topology_find_object(object_topo, *p);
if (NULL == object) {
//object_id not in object2object table
continue;
}
- for (int i = 0; i < utarray_len(object->incl_super_object_ids); i++) {
- long long *tmp = (long long *)utarray_eltptr(object->incl_super_object_ids, i);
- utarray_push_back(super_object_ids, tmp);
+ for (int i = 0; i < utarray_len(object->incl_super_object_uuids); i++) {
+ uuid_t *tmp = (uuid_t *)utarray_eltptr(object->incl_super_object_uuids, i);
+ utarray_push_back(super_object_uuids, tmp);
}
}
}
static void verify_object_by_sub_include_objects(struct maat_object *object,
- UT_array *candidate_object_ids,
- UT_array *kept_super_object_ids,
- UT_array *all_hit_object_ids)
+ UT_array *candidate_object_uuids,
+ UT_array *kept_super_object_uuids,
+ UT_array *all_hit_object_uuids)
{
size_t remove_idx = 0;
- long long *tmp_id = NULL;
+ uuid_t *tmp_uuid = NULL;
// delete objects whose all incl sub not in all_hit_object_ids
- if (utarray_len(object->incl_sub_object_ids) != 0) {
+ if (utarray_len(object->incl_sub_object_uuids) != 0) {
int sub_incl_flag = 0;
- for (tmp_id = (long long *)utarray_front(object->incl_sub_object_ids); tmp_id != NULL;
- tmp_id = (long long *)utarray_next(object->incl_sub_object_ids, tmp_id)) {
- if (utarray_find(candidate_object_ids, tmp_id, compare_object_id)) {
+ for (tmp_uuid = (uuid_t *)utarray_front(object->incl_sub_object_uuids); tmp_uuid != NULL;
+ tmp_uuid = (uuid_t *)utarray_next(object->incl_sub_object_uuids, tmp_uuid)) {
+ if (utarray_find(candidate_object_uuids, tmp_uuid, compare_object_uuid)) {
sub_incl_flag = 1;
break;
}
}
if (0 == sub_incl_flag) {
- tmp_id = utarray_find(all_hit_object_ids, &(object->object_id), compare_object_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(all_hit_object_ids, tmp_id);
- utarray_erase(all_hit_object_ids, remove_idx, 1);
+ tmp_uuid = utarray_find(all_hit_object_uuids, &(object->object_uuid), compare_object_uuid);
+ if (tmp_uuid != NULL) {
+ remove_idx = utarray_eltidx(all_hit_object_uuids, tmp_uuid);
+ utarray_erase(all_hit_object_uuids, remove_idx, 1);
}
- tmp_id = utarray_find(kept_super_object_ids, &(object->object_id), compare_object_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(kept_super_object_ids, tmp_id);
- utarray_erase(kept_super_object_ids, remove_idx, 1);
+ tmp_uuid = utarray_find(kept_super_object_uuids, &(object->object_uuid), compare_object_uuid);
+ if (tmp_uuid != NULL) {
+ remove_idx = utarray_eltidx(kept_super_object_uuids, tmp_uuid);
+ utarray_erase(kept_super_object_uuids, remove_idx, 1);
}
}
}
}
static void verify_object_by_sub_exclude_objects(struct maat_object *object,
- UT_array *candidate_object_ids,
- UT_array *kept_super_object_ids,
- UT_array *all_hit_object_ids)
+ UT_array *candidate_object_uuids,
+ UT_array *kept_super_object_uuids,
+ UT_array *all_hit_object_uuids)
{
- if (0 == utarray_len(object->excl_sub_object_ids)) {
+ if (0 == utarray_len(object->excl_sub_object_uuids)) {
return;
}
// delete objects whose excl sub in all_hit_object_ids
int sub_excl_flag = 0;
- long long *tmp_id = NULL;
- for (tmp_id = (long long *)utarray_front(object->excl_sub_object_ids); tmp_id != NULL;
- tmp_id = (long long *)utarray_next(object->excl_sub_object_ids, tmp_id)) {
- if (utarray_find(candidate_object_ids, tmp_id, compare_object_id)) {
+ uuid_t *tmp_uuid = NULL;
+ for (tmp_uuid = (uuid_t *)utarray_front(object->excl_sub_object_uuids); tmp_uuid != NULL;
+ tmp_uuid = (uuid_t *)utarray_next(object->excl_sub_object_uuids, tmp_uuid)) {
+ if (utarray_find(candidate_object_uuids, tmp_uuid, compare_object_uuid)) {
sub_excl_flag = 1;
break;
}
@@ -926,54 +936,55 @@ static void verify_object_by_sub_exclude_objects(struct maat_object *object,
if (1 == sub_excl_flag) {
size_t remove_idx = 0;
- tmp_id = utarray_find(all_hit_object_ids, &(object->object_id), compare_object_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(all_hit_object_ids, tmp_id);
- utarray_erase(all_hit_object_ids, remove_idx, 1);
+ tmp_uuid = utarray_find(all_hit_object_uuids, &(object->object_uuid), compare_object_uuid);
+ if (tmp_uuid != NULL) {
+ remove_idx = utarray_eltidx(all_hit_object_uuids, tmp_uuid);
+ utarray_erase(all_hit_object_uuids, remove_idx, 1);
}
- tmp_id = utarray_find(kept_super_object_ids, &(object->object_id), compare_object_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(kept_super_object_ids, tmp_id);
- utarray_erase(kept_super_object_ids, remove_idx, 1);
+ tmp_uuid = utarray_find(kept_super_object_uuids, &(object->object_uuid), compare_object_uuid);
+ if (tmp_uuid != NULL) {
+ remove_idx = utarray_eltidx(kept_super_object_uuids, tmp_uuid);
+ utarray_erase(kept_super_object_uuids, remove_idx, 1);
}
}
}
static void verify_candidate_super_object_ids(struct maat_object_topology *object_topo,
- UT_array *candidate_super_object_ids,
- UT_array *all_hit_object_ids,
- UT_array *kept_super_object_ids)
+ UT_array *candidate_super_object_uuids,
+ UT_array *all_hit_object_uuids,
+ UT_array *kept_super_object_uuids)
{
- long long *p = NULL;
- UT_array *candidate_object_ids;
+ uuid_t *p = NULL;
+ UT_array *candidate_object_uuids;
- utarray_new(candidate_object_ids, &ut_object_id_icd);
+ utarray_new(candidate_object_uuids, &ut_object_uuid_icd);
/* merge this round of candidate super objects with hit objects from the previous round */
- for (p = (long long *)utarray_front(candidate_super_object_ids); p != NULL;
- p = (long long *)utarray_next(candidate_super_object_ids, p)) {
- utarray_push_back(candidate_object_ids, p);
+ for (p = (uuid_t *)utarray_front(candidate_super_object_uuids); p != NULL;
+ p = (uuid_t *)utarray_next(candidate_super_object_uuids, p)) {
+ utarray_push_back(candidate_object_uuids, p);
}
- for (p = (long long *)utarray_front(all_hit_object_ids); p != NULL;
- p = (long long *)utarray_next(all_hit_object_ids, p)) {
- utarray_push_back(candidate_object_ids, p);
+ for (p = (uuid_t *)utarray_front(all_hit_object_uuids); p != NULL;
+ p = (uuid_t *)utarray_next(all_hit_object_uuids, p)) {
+ utarray_push_back(candidate_object_uuids, p);
}
- utarray_sort(candidate_object_ids, compare_object_id);
+ utarray_sort(candidate_object_uuids, compare_object_uuid);
/**
* verify sub exclude for candidate_super_object_ids
*/
- long long prev_object_id = -1;
- for (p = (long long *)utarray_front(candidate_super_object_ids); p != NULL;
- p = (long long *)utarray_next(candidate_super_object_ids, p)) {
+ uuid_t prev_object_uuid;
+ uuid_clear(prev_object_uuid);
+ for (p = (uuid_t *)utarray_front(candidate_super_object_uuids); p != NULL;
+ p = (uuid_t *)utarray_next(candidate_super_object_uuids, p)) {
//filter duplicated object id
- if (*p == prev_object_id) {
+ if (uuid_compare(*p, prev_object_uuid) == 0) {
continue;
}
- prev_object_id = *p;
+ uuid_copy(prev_object_uuid, *p);
struct maat_object *object = object_topology_find_object(object_topo, *p);
if (NULL == object) {
@@ -982,10 +993,10 @@ static void verify_candidate_super_object_ids(struct maat_object_topology *objec
//if object's sub excl in candidate_object_ids
int sub_excl_flag = 0;
- long long *tmp_id = NULL;
- for (tmp_id = (long long *)utarray_front(object->excl_sub_object_ids); tmp_id != NULL;
- tmp_id = (long long *)utarray_next(object->excl_sub_object_ids, tmp_id)) {
- if (utarray_find(candidate_object_ids, tmp_id, compare_object_id)) {
+ uuid_t *tmp_uuid = NULL;
+ for (tmp_uuid = (uuid_t *)utarray_front(object->excl_sub_object_uuids); tmp_uuid != NULL;
+ tmp_uuid = (uuid_t *)utarray_next(object->excl_sub_object_uuids, tmp_uuid)) {
+ if (utarray_find(candidate_object_uuids, tmp_uuid, compare_object_uuid)) {
sub_excl_flag = 1;
break;
}
@@ -996,64 +1007,66 @@ static void verify_candidate_super_object_ids(struct maat_object_topology *objec
continue;
}
- utarray_push_back(kept_super_object_ids, p);
- utarray_push_back(all_hit_object_ids, p);
+ utarray_push_back(kept_super_object_uuids, p);
+ utarray_push_back(all_hit_object_uuids, p);
}
- utarray_sort(all_hit_object_ids, compare_object_id);
- utarray_sort(kept_super_object_ids, compare_object_id);
+ utarray_sort(all_hit_object_uuids, compare_object_uuid);
+ utarray_sort(kept_super_object_uuids, compare_object_uuid);
/**
* candidate_object_ids clone all_hit_object_ids
*/
- utarray_clear(candidate_object_ids);
- for (p = (long long *)utarray_front(all_hit_object_ids); p != NULL;
- p = (long long *)utarray_next(all_hit_object_ids, p)) {
- utarray_push_back(candidate_object_ids, p);
+ utarray_clear(candidate_object_uuids);
+ for (p = (uuid_t *)utarray_front(all_hit_object_uuids); p != NULL;
+ p = (uuid_t *)utarray_next(all_hit_object_uuids, p)) {
+ utarray_push_back(candidate_object_uuids, p);
}
/**
* 1. delete objects whose excl sub in all_hit_object_ids
* 2. delete objects whose all incl sub is non-exist in all_hit_object_ids
*/
- for (p = (long long *)utarray_front(candidate_object_ids); p != NULL;
- p = (long long *)utarray_next(candidate_object_ids, p)) {
+ for (p = (uuid_t *)utarray_front(candidate_object_uuids); p != NULL;
+ p = (uuid_t *)utarray_next(candidate_object_uuids, p)) {
struct maat_object *object = object_topology_find_object(object_topo, *p);
if (NULL == object) {
continue;
}
- verify_object_by_sub_exclude_objects(object, candidate_object_ids,
- kept_super_object_ids, all_hit_object_ids);
- verify_object_by_sub_include_objects(object, candidate_object_ids,
- kept_super_object_ids, all_hit_object_ids);
+ verify_object_by_sub_exclude_objects(object, candidate_object_uuids,
+ kept_super_object_uuids, all_hit_object_uuids);
+ verify_object_by_sub_include_objects(object, candidate_object_uuids,
+ kept_super_object_uuids, all_hit_object_uuids);
}
- utarray_free(candidate_object_ids);
+ utarray_free(candidate_object_uuids);
}
static void get_super_object_ids(struct maat_object_topology *object_topo,
- UT_array *hit_object_ids, UT_array *all_hit_object_ids,
+ UT_array *hit_object_uuids, UT_array *all_hit_object_uuids,
size_t depth)
{
- UT_array *candidate_super_object_ids;
- UT_array *kept_super_object_ids;
+ UT_array *candidate_super_object_uuids;
+ UT_array *kept_super_object_uuids;
if (depth >= MAX_RECURSION_DEPTH) {
log_error(object_topo->logger, MODULE_OBJECT,
"[%s:%d]exceed max recursion depth(5)",
__FUNCTION__, __LINE__);
- for (int i = 0; i < utarray_len(hit_object_ids); i++) {
- long long *p = (long long *)utarray_eltptr(hit_object_ids, i);
+ for (int i = 0; i < utarray_len(hit_object_uuids); i++) {
+ uuid_t *p = (uuid_t *)utarray_eltptr(hit_object_uuids, i);
+ char uuid_str[UUID_STR_LEN] = {0};
+ uuid_unparse(*p, uuid_str);
log_error(object_topo->logger, MODULE_OBJECT,
- "[%s:%d]object_id:%lld can't recursively get super object_id",
- __FUNCTION__, __LINE__, *p);
+ "[%s:%d]object_id:%s can't recursively get super object_id",
+ __FUNCTION__, __LINE__, uuid_str);
}
return;
}
- utarray_new(kept_super_object_ids, &ut_object_id_icd);
- utarray_new(candidate_super_object_ids, &ut_object_id_icd);
+ utarray_new(kept_super_object_uuids, &ut_object_uuid_icd);
+ utarray_new(candidate_super_object_uuids, &ut_object_uuid_icd);
/**
candidate super objects means all hit objects' super include object,
@@ -1065,9 +1078,9 @@ static void get_super_object_ids(struct maat_object_topology *object_topo,
candidate super objects = {g7, g8, g12}
*/
- get_candidate_super_object_ids(object_topo, hit_object_ids, candidate_super_object_ids);
+ get_candidate_super_object_ids(object_topo, hit_object_uuids, candidate_super_object_uuids);
- if (0 == utarray_len(candidate_super_object_ids)) {
+ if (0 == utarray_len(candidate_super_object_uuids)) {
goto next;
}
@@ -1095,114 +1108,114 @@ static void get_super_object_ids(struct maat_object_topology *object_topo,
after verify candidates, kept super objects = {g7, g8},
all hit objects = {g4, g11, g7, g8}
*/
- verify_candidate_super_object_ids(object_topo, candidate_super_object_ids, all_hit_object_ids,
- kept_super_object_ids);
+ verify_candidate_super_object_ids(object_topo, candidate_super_object_uuids, all_hit_object_uuids,
+ kept_super_object_uuids);
depth++;
- get_super_object_ids(object_topo, kept_super_object_ids, all_hit_object_ids, depth);
+ get_super_object_ids(object_topo, kept_super_object_uuids, all_hit_object_uuids, depth);
next:
- utarray_free(candidate_super_object_ids);
- utarray_free(kept_super_object_ids);
+ utarray_free(candidate_super_object_uuids);
+ utarray_free(kept_super_object_uuids);
}
static size_t object_topology_get_super_objects(struct maat_object_topology *object_topo,
- long long *object_ids, size_t n_object_ids,
- long long *super_object_ids,
- size_t super_object_ids_size)
+ uuid_t *object_uuids, size_t n_object_uuids,
+ uuid_t *super_object_uuids,
+ size_t super_object_uuids_size)
{
size_t i = 0, idx = 0;
- UT_array *all_hit_object_ids;
- UT_array *candidate_object_ids;
+ UT_array *all_hit_object_uuids;
+ UT_array *candidate_object_uuids;
- utarray_new(all_hit_object_ids, &ut_object_id_icd);
- utarray_new(candidate_object_ids, &ut_object_id_icd);
+ utarray_new(all_hit_object_uuids, &ut_object_uuid_icd);
+ utarray_new(candidate_object_uuids, &ut_object_uuid_icd);
- for (i = 0; i < n_object_ids; i++) {
- utarray_push_back(all_hit_object_ids, &(object_ids[i]));
- utarray_push_back(candidate_object_ids, &(object_ids[i]));
+ for (i = 0; i < n_object_uuids; i++) {
+ utarray_push_back(all_hit_object_uuids, &(object_uuids[i]));
+ utarray_push_back(candidate_object_uuids, &(object_uuids[i]));
}
- get_super_object_ids(object_topo, candidate_object_ids, all_hit_object_ids, 0);
+ get_super_object_ids(object_topo, candidate_object_uuids, all_hit_object_uuids, 0);
- for (i = 0; i < n_object_ids; i++) {
- long long *tmp_id = utarray_find(all_hit_object_ids, &(object_ids[i]),
- compare_object_id);
+ for (i = 0; i < n_object_uuids; i++) {
+ uuid_t *tmp_id = utarray_find(all_hit_object_uuids, &(object_uuids[i]),
+ compare_object_uuid);
if (tmp_id != NULL) {
- size_t remove_idx = utarray_eltidx(all_hit_object_ids, tmp_id);
- utarray_erase(all_hit_object_ids, remove_idx, 1);
+ size_t remove_idx = utarray_eltidx(all_hit_object_uuids, tmp_id);
+ utarray_erase(all_hit_object_uuids, remove_idx, 1);
}
}
- long long *p = NULL;
- for (p = (long long *)utarray_front(all_hit_object_ids); p != NULL;
- p = (long long *)utarray_next(all_hit_object_ids, p)) {
- if (idx >= super_object_ids_size) {
+ uuid_t *p = NULL;
+ for (p = (uuid_t *)utarray_front(all_hit_object_uuids); p != NULL;
+ p = (uuid_t *)utarray_next(all_hit_object_uuids, p)) {
+ if (idx >= super_object_uuids_size) {
break;
}
- super_object_ids[idx++] = *p;
+ uuid_copy(super_object_uuids[idx++], *p);
}
- utarray_free(all_hit_object_ids);
- utarray_free(candidate_object_ids);
+ utarray_free(all_hit_object_uuids);
+ utarray_free(candidate_object_uuids);
return idx;
}
-size_t object2object_runtime_get_super_objects(void *g2g_runtime, long long *object_ids,
- size_t n_object_ids, long long *super_object_ids,
- size_t super_object_ids_size)
+size_t object2object_runtime_get_super_objects(void *o2o_runtime, uuid_t *object_uuids,
+ size_t n_object_uuids, uuid_t *super_object_uuids,
+ size_t super_object_uuids_size)
{
- if (NULL == g2g_runtime || NULL == object_ids || 0 == n_object_ids) {
+ if (NULL == o2o_runtime || NULL == object_uuids || 0 == n_object_uuids) {
return 0;
}
- struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
- long long g2g_object_ids[n_object_ids];
- size_t g2g_object_ids_cnt = 0;
+ struct object2object_runtime *o2o_rt = (struct object2object_runtime *)o2o_runtime;
+ uuid_t o2o_object_uuids[n_object_uuids];
+ size_t o2o_object_uuids_cnt = 0;
- for (size_t i = 0; i < n_object_ids; i++) {
- struct maat_object *object = object_topology_find_object(g2g_rt->object_topo, object_ids[i]);
+ for (size_t i = 0; i < n_object_uuids; i++) {
+ struct maat_object *object = object_topology_find_object(o2o_rt->object_topo, object_uuids[i]);
if (NULL == object) {
continue;
}
- g2g_object_ids[g2g_object_ids_cnt++] = object_ids[i];
+ uuid_copy(o2o_object_uuids[o2o_object_uuids_cnt++], object_uuids[i]);
}
- if (0 == g2g_object_ids_cnt) {
+ if (0 == o2o_object_uuids_cnt) {
return 0;
}
- return object_topology_get_super_objects(g2g_rt->object_topo, g2g_object_ids, g2g_object_ids_cnt,
- super_object_ids, super_object_ids_size);
+ return object_topology_get_super_objects(o2o_rt->object_topo, o2o_object_uuids, o2o_object_uuids_cnt,
+ super_object_uuids, super_object_uuids_size);
}
-long long object2object_runtime_rule_count(void *g2g_runtime)
+long long object2object_runtime_rule_count(void *o2o_runtime)
{
- if (NULL == g2g_runtime) {
+ if (NULL == o2o_runtime) {
return 0;
}
- struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
- return g2g_rt->rule_num;
+ struct object2object_runtime *o2o_rt = (struct object2object_runtime *)o2o_runtime;
+ return o2o_rt->rule_num;
}
-long long object2object_runtime_exclude_rule_count(void *g2g_runtime)
+long long object2object_runtime_exclude_rule_count(void *o2o_runtime)
{
- if (NULL == g2g_runtime) {
+ if (NULL == o2o_runtime) {
return 0;
}
- struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
- return g2g_rt->excl_rule_num;
+ struct object2object_runtime *o2o_rt = (struct object2object_runtime *)o2o_runtime;
+ return o2o_rt->excl_rule_num;
}
-long long object2object_runtime_update_err_count(void *g2g_runtime)
+long long object2object_runtime_update_err_count(void *o2o_runtime)
{
- if (NULL == g2g_runtime) {
+ if (NULL == o2o_runtime) {
return 0;
}
- struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
- return g2g_rt->update_err_cnt;
+ struct object2object_runtime *o2o_rt = (struct object2object_runtime *)o2o_runtime;
+ return o2o_rt->update_err_cnt;
} \ No newline at end of file
diff --git a/src/maat_rule.c b/src/maat_rule.c
index 4409148..a53d5d3 100644
--- a/src/maat_rule.c
+++ b/src/maat_rule.c
@@ -43,13 +43,13 @@ struct rule_schema {
struct rule_item {
int condition_num;
- long long rule_id;
+ uuid_t rule_uuid;
char *table_line;
size_t table_line_len;
};
struct condition_query_key {
- long long object_id;
+ uuid_t object_uuid;
int attribute_id;
int negate_option;
};
@@ -70,7 +70,7 @@ struct table_condition {
struct table_object {
int attribute_id;
- UT_array *object_ids;
+ UT_array *object_uuids;
UT_hash_handle hh;
};
@@ -99,7 +99,7 @@ struct condition_literal {
struct rule_condition {
long long condition_id;
- long long object_ids[MAX_OBJECT_CNT];
+ uuid_t object_uuids[MAX_OBJECT_CNT];
int object_cnt;
int attribute_id;
char negate_option; // 1 byte
@@ -109,7 +109,7 @@ struct rule_condition {
struct rule_sort_para {
int condition_num;
- long long rule_id;
+ uuid_t rule_uuid;
};
#define MAAT_RULE_MAGIC 0x4a5b6c7d
@@ -117,21 +117,21 @@ struct maat_rule {
uint32_t magic_num;
int condition_num;
int table_id;
- long long rule_id;
+ uuid_t rule_uuid;
void *user_data; // rule_item
struct rule_condition conditions[MAX_ITEMS_PER_BOOL_EXPR];
};
struct internal_hit_path {
- long long item_id;
- long long object_id;
+ uuid_t item_uuid;
+ uuid_t object_uuid;
int Nth_scan;
int attribute_id;
int negate_option; // 1 means negate condition
};
struct rule2table_id {
- long long rule_id;
+ uuid_t rule_uuid;
int table_id;
};
@@ -153,7 +153,7 @@ struct rule_compile_state {
};
UT_icd ut_condition_id_icd = {sizeof(long long), NULL, NULL, NULL};
-UT_icd ut_rule_object_id_icd = {sizeof(long long), NULL, NULL, NULL};
+UT_icd ut_rule_object_uuid_icd = {sizeof(uuid_t), NULL, NULL, NULL};
UT_icd ut_maat_hit_object_icd = {sizeof(struct maat_hit_object), NULL, NULL, NULL};
UT_icd ut_hit_path_icd = {sizeof(struct internal_hit_path), NULL, NULL, NULL};
UT_icd ut_hit_rule_table_id_icd = {sizeof(struct rule2table_id), NULL, NULL, NULL};
@@ -226,7 +226,7 @@ static int validate_table_not_condition(struct rule_runtime *rule_rt,
}
static struct maat_rule *maat_rule_new(struct rule_runtime *rule_rt, struct rule_schema *schema,
- const char *table_name, long long rule_id,
+ const char *table_name, uuid_t rule_uuid,
const char *table_line, struct rule_item *rule_item)
{
struct maat_rule *rule = ALLOC(struct maat_rule, 1);
@@ -235,7 +235,7 @@ static struct maat_rule *maat_rule_new(struct rule_runtime *rule_rt, struct rule
cJSON *table_json = cJSON_Parse(table_line);
rule->magic_num = MAAT_RULE_MAGIC;
- rule->rule_id = rule_id;
+ uuid_copy(rule->rule_uuid, rule_uuid);
for(int i = 0; i < MAX_ITEMS_PER_BOOL_EXPR; i++) {
rule->conditions[i].in_use = 0;
@@ -309,7 +309,7 @@ static struct maat_rule *maat_rule_new(struct rule_runtime *rule_rt, struct rule
}
}
- tmp_obj = cJSON_GetObjectItem(condition_obj, "object_ids");
+ tmp_obj = cJSON_GetObjectItem(condition_obj, "object_uuids");
if (tmp_obj && tmp_obj->type == cJSON_Array) {
int n_object_ids = cJSON_GetArraySize(tmp_obj);
@@ -318,8 +318,7 @@ static struct maat_rule *maat_rule_new(struct rule_runtime *rule_rt, struct rule
for (int j = 0; j < n_object_ids; j++) {
cJSON *object_id_obj = cJSON_GetArrayItem(tmp_obj, j);
if (object_id_obj && object_id_obj->type == cJSON_String) {
- long long object_id = atoll(object_id_obj->valuestring);
- condition->object_ids[j] = object_id;
+ uuid_parse(object_id_obj->valuestring, condition->object_uuids[j]);
}
}
}
@@ -383,14 +382,14 @@ rule_item_new(const char *table_line, struct rule_schema *schema,
struct rule_item *rule_item = ALLOC(struct rule_item, 1);
cJSON *table_json = cJSON_Parse(table_line);
- tmp_obj = cJSON_GetObjectItem(table_json, "rule_id");
+ tmp_obj = cJSON_GetObjectItem(table_json, "uuid");
if (tmp_obj == NULL && tmp_obj->type != cJSON_String) {
log_fatal(logger, MODULE_RULE,
"[%s:%d] table: <%s> has no rule_id or not string format in line:%s",
__FUNCTION__, __LINE__, table_name, cJSON_Print(table_json));
goto error;
}
- rule_item->rule_id = atoll(tmp_obj->valuestring);
+ uuid_parse(tmp_obj->valuestring, rule_item->rule_uuid);
rule_item->table_line_len = strlen(table_line);
rule_item->table_line = ALLOC(char, rule_item->table_line_len + 1);
@@ -529,17 +528,9 @@ void rule_runtime_init(void *rule_runtime, struct maat_runtime *maat_rt)
rule_rt->ref_maat_rt = maat_rt;
}
-static inline int compare_object_id(const void *a, const void *b)
+static inline int compare_object_uuid(const void *a, const void *b)
{
- long long ret = *(const long long *)a - *(const long long *)b;
-
- if (0 == ret) {
- return 0;
- } else if(ret < 0) {
- return -1;
- } else {
- return 1;
- }
+ return uuid_compare(*(uuid_t *)a, *(uuid_t *)b);
}
static struct bool_matcher *
@@ -588,7 +579,7 @@ maat_rule_bool_matcher_new(struct rule_runtime *rule_rt,
// some rule may have zero objects, e.g. default policy.
if (j == (size_t)iter_rule->condition_num && j > 0) {
- bool_expr_array[expr_cnt].expr_id = iter_rule->rule_id;
+ uuid_copy(bool_expr_array[expr_cnt].expr_uuid, iter_rule->rule_uuid);
bool_expr_array[expr_cnt].user_tag = iter_rule;
bool_expr_array[expr_cnt].item_num = j;
expr_cnt++;
@@ -634,17 +625,9 @@ static inline int compare_condition_id(const void *a, const void *b)
}
}
-static inline int compare_rule_id(const void *a, const void *b)
+static inline int compare_rule_uuid(const void *a, const void *b)
{
- long long ret = *(const long long *)a - *(const long long *)b;
-
- if (0 == ret) {
- return 0;
- } else if (ret < 0) {
- return -1;
- } else {
- return 1;
- }
+ return uuid_compare(*(uuid_t *)a, *(uuid_t *)b);
}
/**
@@ -687,9 +670,12 @@ build_condition_id_kv_hash(struct rule_runtime *rule_rt, int negate_option)
}
for (size_t k = 0; k < condition->object_cnt; k++) {
- struct condition_query_key key =
- {condition->object_ids[k], condition->attribute_id, condition->negate_option};
+ struct condition_query_key key;
struct condition_id_kv *condition_id_kv = NULL;
+
+ key.attribute_id = condition->attribute_id;
+ key.negate_option = condition->negate_option;
+ uuid_copy(key.object_uuid, condition->object_uuids[k]);
HASH_FIND(hh, condition_id_kv_hash, &key, sizeof(struct condition_query_key),
condition_id_kv);
@@ -768,13 +754,16 @@ rule_compile_state_if_new_hit_rule(struct rule_compile_state *rule_compile_state
static void
rule_compile_state_update_hit_rule_table_id(struct rule_compile_state *rule_compile_state,
- long long rule_id, int table_id)
+ uuid_t rule_uuid, int table_id)
{
- if (!utarray_find(rule_compile_state->hit_rule_table_ids, &rule_id,
- compare_rule_id)) {
- struct rule2table_id rule_table_id = {rule_id, table_id};
+ if (!utarray_find(rule_compile_state->hit_rule_table_ids, &rule_uuid,
+ compare_rule_uuid)) {
+ struct rule2table_id rule_table_id;
+ rule_table_id.table_id = table_id;
+ uuid_copy(rule_table_id.rule_uuid, rule_uuid);
+
utarray_push_back(rule_compile_state->hit_rule_table_ids, &rule_table_id);
- utarray_sort(rule_compile_state->hit_rule_table_ids, compare_rule_id);
+ utarray_sort(rule_compile_state->hit_rule_table_ids, compare_rule_uuid);
}
}
@@ -808,7 +797,8 @@ maat_rule_bool_matcher_match(struct rule_runtime *rule_rt,
for (int i = 0; i < bool_match_ret && ud_result_cnt < ud_array_size; i++) {
rule = (struct maat_rule *)expr_match[i].user_tag;
assert(rule->magic_num == MAAT_RULE_MAGIC);
- assert((unsigned long long)rule->rule_id == expr_match[i].expr_id);
+ assert(uuid_compare(rule->rule_uuid, expr_match[i].expr_uuid) == 0);
+
if (0 == rule->condition_num) {
continue;
}
@@ -819,7 +809,7 @@ maat_rule_bool_matcher_match(struct rule_runtime *rule_rt,
if (rule->user_data != NULL && n_new_hit_rule > 0) {
user_data_array[ud_result_cnt] = rule->user_data;
ud_result_cnt++;
- rule_compile_state_update_hit_rule_table_id(rule_compile_state, rule->rule_id,
+ rule_compile_state_update_hit_rule_table_id(rule_compile_state, rule->rule_uuid,
rule->table_id);
}
}
@@ -856,11 +846,11 @@ rule_compile_state_hit_not_tbl_objects_free(struct rule_compile_state *rule_comp
struct table_object *tbl_object = NULL, *tmp_tbl_object = NULL;
HASH_ITER(hh, rule_compile_state->hit_not_tbl_objects, tbl_object, tmp_tbl_object) {
free_bytes +=
- (sizeof(tbl_object) + utarray_len(tbl_object->object_ids) * sizeof(long long));
+ (sizeof(tbl_object) + utarray_len(tbl_object->object_uuids) * sizeof(uuid_t));
HASH_DEL(rule_compile_state->hit_not_tbl_objects, tbl_object);
- if (tbl_object->object_ids != NULL) {
- utarray_free(tbl_object->object_ids);
- tbl_object->object_ids = NULL;
+ if (tbl_object->object_uuids != NULL) {
+ utarray_free(tbl_object->object_uuids);
+ tbl_object->object_uuids = NULL;
}
FREE(tbl_object);
}
@@ -890,7 +880,7 @@ void rule_compile_state_reset(struct rule_compile_state *rule_compile_state)
struct table_object *tbl_object = NULL, *tmp_tbl_object = NULL;
HASH_ITER(hh, rule_compile_state->hit_not_tbl_objects, tbl_object, tmp_tbl_object) {
- utarray_clear(tbl_object->object_ids);
+ utarray_clear(tbl_object->object_uuids);
}
}
@@ -976,7 +966,7 @@ void rule_compile_state_free(struct rule_compile_state *rule_compile_state,
static void
rule_compile_state_add_internal_hit_path(struct rule_compile_state *rule_compile_state,
- long long item_id, long long object_id,
+ uuid_t item_uuid, uuid_t object_uuid,
int attribute_id, int negate_option, int Nth_scan)
{
if (NULL == rule_compile_state) {
@@ -984,9 +974,9 @@ rule_compile_state_add_internal_hit_path(struct rule_compile_state *rule_compile
}
struct internal_hit_path new_path;
- new_path.item_id = item_id;
+ uuid_copy(new_path.item_uuid, item_uuid);
new_path.Nth_scan = Nth_scan;
- new_path.object_id = object_id;
+ uuid_copy(new_path.object_uuid, object_uuid);
new_path.attribute_id = attribute_id;
new_path.negate_option = negate_option;
@@ -1011,10 +1001,10 @@ static int maat_rule_has_condition_query_key(struct maat_rule *rule,
continue;
}
- long long *tmp_object_id = bsearch(&(key->object_id), condition->object_ids,
- condition->object_cnt, sizeof(long long),
- compare_object_id);
- if (tmp_object_id != NULL) {
+ uuid_t *tmp_object_uuid = bsearch(&(key->object_uuid), condition->object_uuids,
+ condition->object_cnt, sizeof(uuid_t),
+ compare_object_uuid);
+ if (tmp_object_uuid != NULL) {
return 1;
}
}
@@ -1024,7 +1014,7 @@ static int maat_rule_has_condition_query_key(struct maat_rule *rule,
static size_t
maat_rule_get_hit_condition_index(struct maat_rule *rule,
- int attribute_id, long long hit_object_id,
+ int attribute_id, uuid_t hit_object_uuid,
int *condition_idx_array, size_t array_size)
{
size_t hit_condition_cnt = 0;
@@ -1041,10 +1031,10 @@ maat_rule_get_hit_condition_index(struct maat_rule *rule,
continue;
}
- long long *tmp_object_id = bsearch(&hit_object_id, tmp_condition->object_ids,
- tmp_condition->object_cnt, sizeof(long long),
- compare_object_id);
- if (tmp_object_id != NULL) {
+ uuid_t *tmp_object_uuid = bsearch(&hit_object_uuid, tmp_condition->object_uuids,
+ tmp_condition->object_cnt, sizeof(uuid_t),
+ compare_object_uuid);
+ if (tmp_object_uuid != NULL) {
condition_idx_array[hit_condition_cnt++] = i;
break;
}
@@ -1077,17 +1067,17 @@ void populate_hit_path_with_rule(struct maat_hit_path *hit_path_array,
size_t new_hit_path_cnt = *n_new_hit_path;
int condition_index_array[MAX_ITEMS_PER_BOOL_EXPR] = {0};
- if (hit_path_array[idx].top_object_id < 0) {
- hit_path_array[idx].top_object_id = hit_path_array[idx].sub_object_id;
+ if (uuid_is_null(hit_path_array[idx].top_object_uuid)) {
+ uuid_copy(hit_path_array[idx].top_object_uuid, hit_path_array[idx].sub_object_uuid);
}
struct maat_hit_path tmp_path;
- if (hit_path_array[idx].rule_id < 0) {
- hit_path_array[idx].rule_id = rule->rule_id;
+ if (uuid_is_null(hit_path_array[idx].rule_uuid)) {
+ uuid_copy(hit_path_array[idx].rule_uuid, rule->rule_uuid);
// find out which condition in rule hit
n_condition_index =
maat_rule_get_hit_condition_index(rule, hit_path_array[idx].attribute_id,
- hit_path_array[idx].top_object_id,
+ hit_path_array[idx].top_object_uuid,
condition_index_array,
MAX_ITEMS_PER_BOOL_EXPR);
hit_path_array[idx].condition_index = condition_index_array[0];
@@ -1102,12 +1092,12 @@ void populate_hit_path_with_rule(struct maat_hit_path *hit_path_array,
} else {
// means same condition_query_id hit more than one rule_id
tmp_path = hit_path_array[idx];
- tmp_path.rule_id = rule->rule_id;
+ uuid_copy(tmp_path.rule_uuid, rule->rule_uuid);
if (!maat_rule_is_hit_path_existed(hit_path_array, n_hit_path + new_hit_path_cnt, &tmp_path)) {
hit_path_array[n_hit_path + new_hit_path_cnt] = tmp_path;
new_hit_path_cnt++;
n_condition_index =
- maat_rule_get_hit_condition_index(rule, tmp_path.attribute_id, tmp_path.top_object_id,
+ maat_rule_get_hit_condition_index(rule, tmp_path.attribute_id, tmp_path.top_object_uuid,
condition_index_array, MAX_ITEMS_PER_BOOL_EXPR);
hit_path_array[n_hit_path + new_hit_path_cnt - 1].condition_index = condition_index_array[0];
if (n_condition_index > 1) {
@@ -1132,7 +1122,7 @@ size_t rule_runtime_get_hit_paths(struct rule_runtime *rule_rt, int thread_id,
/* assign hit_path_array[].rule_id */
size_t n_new_hit_path = 0;
struct maat_rule *rule = NULL;
- struct condition_query_key key = {0, 0, 0};
+ struct condition_query_key key;
struct bool_expr_match *expr_match = rule_rt->expr_match_buff +
(thread_id * MAX_HIT_RULE_NUM);
assert(thread_id >= 0);
@@ -1149,16 +1139,16 @@ size_t rule_runtime_get_hit_paths(struct rule_runtime *rule_rt, int thread_id,
for (int idx = 0; idx < bool_match_ret; idx++) {
rule = (struct maat_rule *)expr_match[idx].user_tag;
assert(rule->magic_num == MAAT_RULE_MAGIC);
- assert((unsigned long long)rule->rule_id == expr_match[idx].expr_id);
+ assert(uuid_compare(rule->rule_uuid, expr_match[idx].expr_uuid) == 0);
if (0 == rule->condition_num || NULL == rule->user_data) {
continue;
}
for (size_t j = 0; j < n_hit_path && (n_hit_path + n_new_hit_path) < array_size; j++) {
- if (hit_path_array[j].top_object_id < 0) {
- key.object_id = hit_path_array[j].sub_object_id;
+ if (uuid_is_null(hit_path_array[j].top_object_uuid)) {
+ uuid_copy(key.object_uuid, hit_path_array[j].sub_object_uuid);
} else {
- key.object_id = hit_path_array[j].top_object_id;
+ uuid_copy(key.object_uuid, hit_path_array[j].top_object_uuid);
}
key.attribute_id = hit_path_array[j].attribute_id;
@@ -1184,8 +1174,8 @@ rule_compile_state_add_direct_hit_objects(struct rule_compile_state *rule_compil
struct maat_hit_object hit_object;
for (size_t i = 0; i < n_hit_items; i++) {
- hit_object.item_id = hit_items[i].item_id;
- hit_object.object_id = hit_items[i].object_id;
+ uuid_copy(hit_object.item_uuid, hit_items[i].item_uuid);
+ uuid_copy(hit_object.object_uuid, hit_items[i].object_uuid);
hit_object.attribute_id = attribute_id;
utarray_push_back(rule_compile_state->direct_hit_objects, &hit_object);
}
@@ -1193,17 +1183,17 @@ rule_compile_state_add_direct_hit_objects(struct rule_compile_state *rule_compil
static void
rule_compile_state_add_indirect_hit_objects(struct rule_compile_state *rule_compile_state,
- long long *object_ids,
- size_t n_object_ids, int attribute_id)
+ uuid_t *object_uuids,
+ size_t n_object_uuids, int attribute_id)
{
- if (NULL == rule_compile_state || NULL == object_ids) {
+ if (NULL == rule_compile_state || NULL == object_uuids) {
return;
}
struct maat_hit_object hit_object;
- for (size_t i = 0; i < n_object_ids; i++) {
- hit_object.item_id = 0;
- hit_object.object_id = object_ids[i];
+ for (size_t i = 0; i < n_object_uuids; i++) {
+ uuid_clear(hit_object.item_uuid);
+ uuid_copy(hit_object.object_uuid, object_uuids[i]);
hit_object.attribute_id = attribute_id;
utarray_push_back(rule_compile_state->indirect_hit_objects, &hit_object);
}
@@ -1288,15 +1278,19 @@ rule_compile_state_add_hit_not_conditions(struct rule_compile_state *rule_compil
static void
rule_compile_state_update_hit_conditions(struct rule_compile_state *rule_compile_state,
struct rule_runtime *rule_rt,
- long long object_id, int attribute_id)
+ uuid_t object_uuid, int attribute_id)
{
if (NULL == rule_compile_state || NULL == rule_rt) {
return;
}
- struct condition_query_key key = {object_id, attribute_id, 0};
+ struct condition_query_key key;
struct condition_id_kv *condition_id_kv = NULL;
+ key.negate_option = 0;
+ key.attribute_id = attribute_id;
+ uuid_copy(key.object_uuid, object_uuid);
+
HASH_FIND(hh, rule_rt->condition_id_kv_hash, &key, sizeof(key), condition_id_kv);
if (condition_id_kv != NULL) {
rule_compile_state_add_hit_conditions(rule_compile_state, condition_id_kv->condition_ids);
@@ -1312,29 +1306,29 @@ rule_compile_state_update_hit_conditions(struct rule_compile_state *rule_compile
static void
rule_compile_state_cache_hit_not_objects(struct rule_compile_state *rule_compile_state,
struct rule_runtime *rule_rt,
- long long *hit_object_ids,
- size_t n_hit_object_id, int attribute_id)
+ uuid_t *hit_object_uuids,
+ size_t n_hit_object_uuid, int attribute_id)
{
if (NULL == rule_compile_state || NULL == rule_rt) {
return;
}
- if (n_hit_object_id != 0) {
- qsort(hit_object_ids, n_hit_object_id, sizeof(long long), compare_object_id);
+ if (n_hit_object_uuid != 0) {
+ qsort(hit_object_uuids, n_hit_object_uuid, sizeof(uuid_t), compare_object_uuid);
}
struct table_object *tbl_object = NULL;
HASH_FIND(hh, rule_compile_state->hit_not_tbl_objects, &attribute_id, sizeof(int), tbl_object);
if (tbl_object != NULL) {
- for (size_t i = 0; i < n_hit_object_id; i++) {
- long long *object_id = (long long *)utarray_find(tbl_object->object_ids,
- &hit_object_ids[i],
- compare_object_id);
- if (NULL == object_id) {
+ for (size_t i = 0; i < n_hit_object_uuid; i++) {
+ uuid_t *object_uuid = (uuid_t *)utarray_find(tbl_object->object_uuids,
+ &hit_object_uuids[i],
+ compare_object_uuid);
+ if (NULL == object_uuid) {
continue;
}
- size_t remove_idx = utarray_eltidx(tbl_object->object_ids, object_id);
- utarray_erase(tbl_object->object_ids, remove_idx, 1);
+ size_t remove_idx = utarray_eltidx(tbl_object->object_uuids, object_uuid);
+ utarray_erase(tbl_object->object_uuids, remove_idx, 1);
}
}
@@ -1344,28 +1338,28 @@ rule_compile_state_cache_hit_not_objects(struct rule_compile_state *rule_compile
continue;
}
- long long *tmp_object_id =
- bsearch(&(condition_id_kv->key.object_id), hit_object_ids,
- n_hit_object_id, sizeof(long long), compare_object_id);
- if (tmp_object_id != NULL) {
+ uuid_t *tmp_object_uuid =
+ bsearch(&(condition_id_kv->key.object_uuid), hit_object_uuids,
+ n_hit_object_uuid, sizeof(uuid_t), compare_object_uuid);
+ if (tmp_object_uuid != NULL) {
continue;
}
if (NULL == tbl_object) {
tbl_object = ALLOC(struct table_object, 1);
tbl_object->attribute_id = attribute_id;
- utarray_new(tbl_object->object_ids, &ut_rule_object_id_icd);
+ utarray_new(tbl_object->object_uuids, &ut_rule_object_uuid_icd);
HASH_ADD_INT(rule_compile_state->hit_not_tbl_objects, attribute_id, tbl_object);
}
- if (!utarray_find(tbl_object->object_ids, &(condition_id_kv->key.object_id),
- compare_object_id)) {
- utarray_push_back(tbl_object->object_ids, &(condition_id_kv->key.object_id));
+ if (!utarray_find(tbl_object->object_uuids, &(condition_id_kv->key.object_uuid),
+ compare_object_uuid)) {
+ utarray_push_back(tbl_object->object_uuids, &(condition_id_kv->key.object_uuid));
}
}
if (tbl_object != NULL) {
- utarray_sort(tbl_object->object_ids, compare_object_id);
+ utarray_sort(tbl_object->object_uuids, compare_object_uuid);
}
}
@@ -1375,7 +1369,7 @@ int rule_compile_state_get_rule_table_id(struct rule_compile_state *rule_compile
struct rule2table_id *tmp = NULL;
tmp = utarray_find(rule_compile_state->hit_rule_table_ids, &rule_id,
- compare_rule_id);
+ compare_rule_uuid);
if (NULL == tmp) {
return -1;
}
@@ -1386,7 +1380,7 @@ int rule_compile_state_get_rule_table_id(struct rule_compile_state *rule_compile
static int
rule_runtime_add_rule(struct rule_runtime *rule_rt,
struct rule_schema *schema,
- long long rule_id, const char *table_name,
+ uuid_t rule_uuid, const char *table_name,
const char *line, struct log_handle *logger)
{
struct maat_rule *rule = NULL;
@@ -1407,18 +1401,20 @@ rule_runtime_add_rule(struct rule_runtime *rule_rt,
int updating_flag = rcu_hash_is_updating(rule_rt->cfg_hash);
if (1 == updating_flag) {
- rule = rcu_updating_hash_find(rule_rt->cfg_hash, (char *)&rule_id,
- sizeof(long long));
+ rule = rcu_updating_hash_find(rule_rt->cfg_hash, (char *)&rule_uuid,
+ sizeof(uuid_t));
} else {
- rule = rcu_hash_find(rule_rt->cfg_hash, (char *)&rule_id, sizeof(long long));
+ rule = rcu_hash_find(rule_rt->cfg_hash, (char *)&rule_uuid, sizeof(uuid_t));
}
if (rule != NULL) {
+ char rule_uuid_str[UUID_STR_LEN] = {0};
+ uuid_unparse(rule_uuid, rule_uuid_str);
log_fatal(logger, MODULE_RULE,
- "[%s:%d]rule_id:%lld already existed in rule table, drop line:%s",
- __FUNCTION__, __LINE__, rule_id, line);
+ "[%s:%d]rule_id:%s already existed in rule table, drop line:%s",
+ __FUNCTION__, __LINE__, rule_uuid_str, line);
}
- rule = maat_rule_new(rule_rt, schema, table_name, rule_id, line, rule_item);
+ rule = maat_rule_new(rule_rt, schema, table_name, rule_uuid, line, rule_item);
if (NULL == rule) {
log_fatal(logger, MODULE_RULE,
"[%s:%d]maat_rule_new failed, drop line:%s",
@@ -1426,14 +1422,14 @@ rule_runtime_add_rule(struct rule_runtime *rule_rt,
return -1;
}
- rcu_hash_add(rule_rt->cfg_hash, (char *)&rule_id, sizeof(long long), rule);
+ rcu_hash_add(rule_rt->cfg_hash, (char *)&rule_uuid, sizeof(uuid_t), rule);
return 0;
}
static void rule_runtime_del_rule(struct rule_runtime *rule_rt,
struct rule_schema *schema,
- long long rule_id,
+ uuid_t rule_uuid,
struct log_handle *logger)
{
struct maat_rule *rule = NULL;
@@ -1441,11 +1437,11 @@ static void rule_runtime_del_rule(struct rule_runtime *rule_rt,
int updating_flag = rcu_hash_is_updating(rule_rt->cfg_hash);
if (1 == updating_flag) {
// find in updating hash
- rule = rcu_updating_hash_find(rule_rt->cfg_hash, (char *)&rule_id,
- sizeof(long long));
+ rule = rcu_updating_hash_find(rule_rt->cfg_hash, (char *)&rule_uuid,
+ sizeof(uuid_t));
} else {
// find in effective hash
- rule = rcu_hash_find(rule_rt->cfg_hash, (char *)&rule_id, sizeof(long long));
+ rule = rcu_hash_find(rule_rt->cfg_hash, (char *)&rule_uuid, sizeof(uuid_t));
}
if (rule != NULL) {
@@ -1456,7 +1452,7 @@ static void rule_runtime_del_rule(struct rule_runtime *rule_rt,
}
}
- rcu_hash_del(rule_rt->cfg_hash, (char *)&rule_id, sizeof(long long));
+ rcu_hash_del(rule_rt->cfg_hash, (char *)&rule_uuid, sizeof(uuid_t));
}
}
@@ -1480,7 +1476,7 @@ int rule_runtime_update(void *rule_runtime, void *rule_schema,
return -1;
}
- tmp_obj = cJSON_GetObjectItem(json, "rule_id");
+ tmp_obj = cJSON_GetObjectItem(json, "uuid");
if (NULL == tmp_obj || tmp_obj->type != cJSON_String) {
log_fatal(rule_rt->logger, MODULE_RULE,
"[%s:%d] rule table:<%s> has no rule_id or not string format in table_line:%s",
@@ -1489,14 +1485,15 @@ int rule_runtime_update(void *rule_runtime, void *rule_schema,
cJSON_Delete(json);
return -1;
}
- long long rule_id = atoll(tmp_obj->valuestring);
+ uuid_t rule_uuid;
+ uuid_parse(tmp_obj->valuestring, rule_uuid);
if (MAAT_OP_DEL == op) {
// delete
- rule_runtime_del_rule(rule_rt, schema, rule_id, rule_rt->logger);
+ rule_runtime_del_rule(rule_rt, schema, rule_uuid, rule_rt->logger);
} else {
// add
- int ret = rule_runtime_add_rule(rule_rt, schema, rule_id,
+ int ret = rule_runtime_add_rule(rule_rt, schema, rule_uuid,
table_name, line, rule_rt->logger);
if (ret < 0) {
rule_rt->update_err_cnt++;
@@ -1621,14 +1618,14 @@ static int rule_sort_para_compare(const struct rule_sort_para *a,
if (a->condition_num != b->condition_num) {
return (a->condition_num - b->condition_num);
} else {
- return (b->rule_id - a->rule_id);
+ return uuid_compare(a->rule_uuid, b->rule_uuid);
}
}
static void rule_sort_para_set(struct rule_sort_para *para,
const struct rule_item *item)
{
- para->rule_id = item->rule_id;
+ uuid_copy(para->rule_uuid, item->rule_uuid);
para->condition_num = item->condition_num;
}
@@ -1644,7 +1641,7 @@ static int compare_rule_item(const void *a, const void *b)
return rule_sort_para_compare(&sa, &sb);
}
-int rule_runtime_match(struct rule_runtime *rule_rt, long long *rule_ids,
+int rule_runtime_match(struct rule_runtime *rule_rt, uuid_t *rule_uuids,
size_t rule_ids_size, struct maat_state *state)
{
struct rule_compile_state *rule_compile_state = state->rule_compile_state;
@@ -1662,7 +1659,7 @@ int rule_runtime_match(struct rule_runtime *rule_rt, long long *rule_ids,
}
for (size_t i = 0; i < bool_match_ret; i++) {
- rule_ids[i] = rule_items[i]->rule_id;
+ uuid_copy(rule_uuids[i], rule_items[i]->rule_uuid);
}
return MIN(bool_match_ret, rule_ids_size);
@@ -1674,7 +1671,7 @@ int rule_compile_state_update(struct rule_compile_state *rule_compile_state, str
{
size_t i = 0, j = 0;
size_t hit_cnt = n_hit_item;
- long long hit_object_ids[MAX_HIT_OBJECT_NUM];
+ uuid_t hit_object_uuids[MAX_HIT_OBJECT_NUM];
struct maat_hit_object hit_object;
utarray_clear(rule_compile_state->this_scan_hit_conditions);
@@ -1682,38 +1679,38 @@ int rule_compile_state_update(struct rule_compile_state *rule_compile_state, str
rule_compile_state->Nth_scan = Nth_scan;
for (i = 0; i < hit_cnt; i++) {
- hit_object_ids[i] = hit_items[i].object_id;
+ uuid_copy(hit_object_uuids[i], hit_items[i].object_uuid);
- hit_object.item_id = hit_items[i].item_id;
- hit_object.object_id = hit_items[i].object_id;
+ uuid_copy(hit_object.item_uuid, hit_items[i].item_uuid);
+ uuid_copy(hit_object.object_uuid, hit_items[i].object_uuid);
hit_object.attribute_id = attribute_id;
utarray_push_back(rule_compile_state->last_hit_objects, &hit_object);
}
- int g2g_table_id = table_manager_get_object2object_table_id(maat_inst->tbl_mgr);
- void *g2g_rt = table_manager_get_runtime(maat_inst->tbl_mgr, g2g_table_id);
+ int o2o_table_id = table_manager_get_object2object_table_id(maat_inst->tbl_mgr);
+ void *o2o_rt = table_manager_get_runtime(maat_inst->tbl_mgr, o2o_table_id);
- long long super_object_ids[MAX_HIT_OBJECT_NUM];
- size_t super_object_cnt = object2object_runtime_get_super_objects(g2g_rt, hit_object_ids,
- hit_cnt, super_object_ids,
+ uuid_t super_object_uuids[MAX_HIT_OBJECT_NUM];
+ size_t super_object_cnt = object2object_runtime_get_super_objects(o2o_rt, hit_object_uuids,
+ hit_cnt, super_object_uuids,
MAX_HIT_OBJECT_NUM);
for (i = 0; i < super_object_cnt; i++) {
- hit_object.item_id = 0;
- hit_object.object_id = super_object_ids[i];
+ uuid_clear(hit_object.item_uuid);
+ uuid_copy(hit_object.object_uuid, super_object_uuids[i]);
hit_object.attribute_id = attribute_id;
utarray_push_back(rule_compile_state->last_hit_objects, &hit_object);
}
if (1 == maat_inst->opts.hit_path_on && hit_cnt > 0) {
for (i = 0; i < hit_cnt; i++) {
- rule_compile_state_add_internal_hit_path(rule_compile_state, hit_items[i].item_id,
- hit_items[i].object_id, attribute_id, 0, Nth_scan);
+ rule_compile_state_add_internal_hit_path(rule_compile_state, hit_items[i].item_uuid,
+ hit_items[i].object_uuid, attribute_id, 0, Nth_scan);
}
}
if (1 == maat_inst->opts.hit_object_on) {
rule_compile_state_add_direct_hit_objects(rule_compile_state, hit_items, hit_cnt, attribute_id);
- rule_compile_state_add_indirect_hit_objects(rule_compile_state, super_object_ids,
+ rule_compile_state_add_indirect_hit_objects(rule_compile_state, super_object_uuids,
super_object_cnt, attribute_id);
}
@@ -1730,15 +1727,15 @@ int rule_compile_state_update(struct rule_compile_state *rule_compile_state, str
}
for (j = 0; j < super_object_cnt && hit_cnt < MAX_HIT_OBJECT_NUM; j++) {
- hit_object_ids[hit_cnt++] = super_object_ids[j];
+ uuid_copy(hit_object_uuids[hit_cnt++], super_object_uuids[j]);
}
for (i = 0; i < hit_cnt; i++) {
rule_compile_state_update_hit_conditions(rule_compile_state, rule_rt,
- hit_object_ids[i], attribute_id);
+ hit_object_uuids[i], attribute_id);
}
- rule_compile_state_cache_hit_not_objects(rule_compile_state, rule_rt, hit_object_ids,
+ rule_compile_state_cache_hit_not_objects(rule_compile_state, rule_rt, hit_object_uuids,
hit_cnt, attribute_id);
return hit_cnt;
}
@@ -1772,9 +1769,12 @@ void rule_compile_state_not_logic_update(struct rule_compile_state *rule_compile
}
struct condition_id_kv *condition_id_kv = NULL;
- for (size_t i = 0; i < utarray_len(tbl_object->object_ids); i++) {
- long long *object_id = utarray_eltptr(tbl_object->object_ids, i);
- struct condition_query_key key = {*object_id, attribute_id, 1};
+ for (size_t i = 0; i < utarray_len(tbl_object->object_uuids); i++) {
+ uuid_t *object_uuid = utarray_eltptr(tbl_object->object_uuids, i);
+ struct condition_query_key key;
+ key.attribute_id = attribute_id;
+ key.negate_option = 1;
+ uuid_copy(key.object_uuid, *object_uuid);
HASH_FIND(hh, rule_rt->not_condition_id_kv_hash, &key, sizeof(key), condition_id_kv);
if (NULL == condition_id_kv) {
@@ -1783,7 +1783,9 @@ void rule_compile_state_not_logic_update(struct rule_compile_state *rule_compile
rule_compile_state_add_hit_not_conditions(rule_compile_state, condition_id_kv->condition_ids);
if (1 == maat_inst->opts.hit_path_on) {
- rule_compile_state_add_internal_hit_path(rule_compile_state, -1, *object_id,
+ uuid_t null_uuid;
+ uuid_clear(null_uuid);
+ rule_compile_state_add_internal_hit_path(rule_compile_state, null_uuid, *object_uuid,
attribute_id, 1, Nth_scan);
}
}
@@ -1798,8 +1800,8 @@ size_t rule_compile_state_get_indirect_hit_objects(struct rule_compile_state *ru
for (i = 0; i < utarray_len(rule_compile_state->indirect_hit_objects) && i < array_size; i++) {
hit_object =
(struct maat_hit_object *)utarray_eltptr(rule_compile_state->indirect_hit_objects, i);
- object_array[i].item_id = hit_object->item_id;
- object_array[i].object_id = hit_object->object_id;
+ uuid_copy(object_array[i].item_uuid, hit_object->item_uuid);
+ uuid_copy(object_array[i].object_uuid, hit_object->object_uuid);
object_array[i].attribute_id = hit_object->attribute_id;
}
@@ -1842,8 +1844,8 @@ size_t rule_compile_state_get_direct_hit_objects(struct rule_compile_state *rule
struct maat_hit_object *object = NULL;
for (i = 0; i < utarray_len(direct_hit_object) && i < array_size; i++) {
object = (struct maat_hit_object *)utarray_eltptr(direct_hit_object, i);
- object_array[i].item_id = object->item_id;
- object_array[i].object_id = object->object_id;
+ uuid_copy(object_array[i].item_uuid, object->item_uuid);
+ uuid_copy(object_array[i].object_uuid, object->object_uuid);
object_array[i].attribute_id = object->attribute_id;
}
@@ -1859,7 +1861,7 @@ size_t rule_compile_state_get_direct_hit_object_cnt(struct rule_compile_state *r
size_t rule_compile_state_get_internal_hit_paths(struct rule_compile_state *rule_compile_state,
struct rule_runtime *rule_rt,
- struct object2object_runtime *g2g_rt,
+ struct object2object_runtime *o2o_rt,
struct maat_hit_path *hit_path_array,
size_t array_size)
{
@@ -1872,15 +1874,15 @@ size_t rule_compile_state_get_internal_hit_paths(struct rule_compile_state *rule
/*
NOTE: maybe one item has been deleted, but it's item_id still exist in internal_hit_paths
*/
- long long super_object_ids[MAX_HIT_OBJECT_NUM];
- UT_array *valid_super_object_ids;
- utarray_new(valid_super_object_ids, &ut_rule_object_id_icd);
+ uuid_t super_object_uuids[MAX_HIT_OBJECT_NUM];
+ UT_array *valid_super_object_uuids;
+ utarray_new(valid_super_object_uuids, &ut_rule_object_uuid_icd);
size_t super_object_cnt =
- object2object_runtime_get_super_objects(g2g_rt, &(internal_path->object_id), 1,
- super_object_ids, MAX_HIT_OBJECT_NUM);
+ object2object_runtime_get_super_objects(o2o_rt, &(internal_path->object_uuid), 1,
+ super_object_uuids, MAX_HIT_OBJECT_NUM);
for (size_t idx = 0; idx < super_object_cnt; idx++) {
- utarray_push_back(valid_super_object_ids, &super_object_ids[idx]);
+ utarray_push_back(valid_super_object_uuids, &super_object_uuids[idx]);
}
/*
@@ -1889,24 +1891,25 @@ size_t rule_compile_state_get_internal_hit_paths(struct rule_compile_state *rule
------------------------------------------------------------------------------
NOTE: Add the hit path as long as the item is hit
*/
- long long super_object_id = -1;
- utarray_push_back(valid_super_object_ids, &super_object_id);
+ uuid_t super_object_uuid;
+ uuid_clear(super_object_uuid);
+ utarray_push_back(valid_super_object_uuids, &super_object_uuid);
- long long *p = NULL;
+ uuid_t *p = NULL;
struct maat_hit_path tmp_path;
- for (p = utarray_front(valid_super_object_ids);
+ for (p = utarray_front(valid_super_object_uuids);
p != NULL && hit_path_cnt < array_size;
- p = utarray_next(valid_super_object_ids, p)) {
+ p = utarray_next(valid_super_object_uuids, p)) {
memset(&tmp_path, 0, sizeof(tmp_path));
tmp_path.Nth_scan = internal_path->Nth_scan;
- tmp_path.item_id = internal_path->item_id;
- tmp_path.sub_object_id = internal_path->object_id;
- tmp_path.top_object_id = *p;
+ uuid_copy(tmp_path.item_uuid, internal_path->item_uuid);
+ uuid_copy(tmp_path.sub_object_uuid, internal_path->object_uuid);
+ uuid_copy(tmp_path.top_object_uuid, *p);
tmp_path.attribute_id = internal_path->attribute_id;
tmp_path.negate_option = internal_path->negate_option;
tmp_path.condition_index = -1;
- tmp_path.rule_id = -1;
+ uuid_clear(tmp_path.rule_uuid);
/* check if internal_path is duplicated from hit_path_array[]
* element */
@@ -1920,7 +1923,7 @@ size_t rule_compile_state_get_internal_hit_paths(struct rule_compile_state *rule
hit_path_array[hit_path_cnt] = tmp_path;
hit_path_cnt++;
}
- utarray_free(valid_super_object_ids);
+ utarray_free(valid_super_object_uuids);
}
return hit_path_cnt;
diff --git a/src/maat_stat.c b/src/maat_stat.c
index 3b5c578..7132d31 100644
--- a/src/maat_stat.c
+++ b/src/maat_stat.c
@@ -244,7 +244,7 @@ static void fs_table_row_refresh(struct maat_stat *stat, int perf_on)
long long total_rule_num = 0, total_scan_bytes = 0, total_update_err = 0;
long long total_scan_times = 0, total_hit_times = 0, total_scan_cpu_time = 0;
long long total_regv6_num = 0, total_hit_item_num = 0, total_hit_pattern_num = 0;
- long long g2c_not_condition_num = 0, g2g_excl_rule_num = 0;
+ long long o2r_not_condition_num = 0, o2o_excl_rule_num = 0;
struct field cell_tag = {
.key = "TBL",
.type = FIELD_VALUE_CSTRING
@@ -273,7 +273,7 @@ static void fs_table_row_refresh(struct maat_stat *stat, int perf_on)
plugin_rule_num += plugin_runtime_rule_count(runtime);
break;
case TABLE_TYPE_OBJECT2OBJECT:
- g2g_excl_rule_num += object2object_runtime_exclude_rule_count(runtime);
+ o2o_excl_rule_num += object2object_runtime_exclude_rule_count(runtime);
break;
case TABLE_TYPE_EXPR:
case TABLE_TYPE_EXPR_PLUS:
@@ -412,11 +412,11 @@ static void fs_table_row_refresh(struct maat_stat *stat, int perf_on)
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->g_metric_id[STATUS_CONDITION_REF_NOT_NUM],
- NULL, 0, g2c_not_condition_num);
+ NULL, 0, o2r_not_condition_num);
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->g_metric_id[STATUS_OBJECT_REF_EXCL_NUM],
- NULL, 0, g2g_excl_rule_num);
+ NULL, 0, o2o_excl_rule_num);
}
diff --git a/src/maat_table.c b/src/maat_table.c
index 2ecc143..f264319 100644
--- a/src/maat_table.c
+++ b/src/maat_table.c
@@ -59,7 +59,7 @@ struct table_manager {
enum expr_engine_type engine_type;
int default_rule_table_id;
- int g2g_table_id;
+ int o2o_table_id;
struct maat_kv_store *tbl_name2id_map;
struct maat_kv_store *conj_tbl_name2id_map;
struct maat_kv_store *attr_name2id_map;
@@ -929,7 +929,7 @@ table_manager_create(const char *table_info_path, const char *accept_tags,
}
int default_rule_table_id = -1;
- int g2g_table_id = -1;
+ int o2o_table_id = -1;
struct maat_kv_store *reserved_word_map = maat_kv_store_new();
register_reserved_word(reserved_word_map);
@@ -967,7 +967,7 @@ table_manager_create(const char *table_info_path, const char *accept_tags,
}
if (maat_tbl->table_type == TABLE_TYPE_OBJECT2OBJECT) {
- g2g_table_id = maat_tbl->table_id;
+ o2o_table_id = maat_tbl->table_id;
}
if (maat_tbl->table_type >= TABLE_TYPE_FLAG && maat_tbl->table_type <= TABLE_TYPE_INTERVAL_PLUS) {
@@ -984,10 +984,10 @@ table_manager_create(const char *table_info_path, const char *accept_tags,
}
tbl_mgr->default_rule_table_id = default_rule_table_id;
- tbl_mgr->g2g_table_id = g2g_table_id;
+ tbl_mgr->o2o_table_id = o2o_table_id;
log_info(logger, MODULE_TABLE, "default rule table id: %d", default_rule_table_id);
- log_info(logger, MODULE_TABLE, "object2object table id: %d", g2g_table_id);
+ log_info(logger, MODULE_TABLE, "object2object table id: %d", o2o_table_id);
next:
FREE(json_buff);
maat_kv_store_free(reserved_word_map);
@@ -1241,7 +1241,7 @@ int table_manager_get_object2object_table_id(struct table_manager *tbl_mgr)
return -1;
}
- return tbl_mgr->g2g_table_id;
+ return tbl_mgr->o2o_table_id;
}
void *table_manager_get_schema(struct table_manager *tbl_mgr, int table_id)