diff options
| author | 刘文坛 <[email protected]> | 2023-05-15 07:24:36 +0000 |
|---|---|---|
| committer | 刘文坛 <[email protected]> | 2023-05-15 07:24:36 +0000 |
| commit | 683096608453f06300cf9e390bd997f65e1dd76b (patch) | |
| tree | fe45fad941345432292ca97b1e41aa97659e7871 | |
| parent | 1a7ec28c4f8f90f712ad36e7e56961b55fad7c41 (diff) | |
[BUGFIX]fix group_exclude miss hit groupsv4.0.17
29 files changed, 409 insertions, 184 deletions
diff --git a/src/alignment.c b/src/alignment.c index c6106ba..6c6af77 100644 --- a/src/alignment.c +++ b/src/alignment.c @@ -4,7 +4,7 @@ * Description: * Authors: Zheng Chao <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/inc_internal/alignment.h b/src/inc_internal/alignment.h index fb8083e..6f77d1e 100644 --- a/src/inc_internal/alignment.h +++ b/src/inc_internal/alignment.h @@ -4,7 +4,7 @@ * Description: alignment statistics * Authors: Zheng Chao <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/inc_internal/maat_command.h b/src/inc_internal/maat_command.h index d1d50e3..52882a7 100644 --- a/src/inc_internal/maat_command.h +++ b/src/inc_internal/maat_command.h @@ -4,7 +4,7 @@ * Description: * Authors: Liu WenTan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/inc_internal/maat_config_monitor.h b/src/inc_internal/maat_config_monitor.h index c54f4d9..2dd406b 100644 --- a/src/inc_internal/maat_config_monitor.h +++ b/src/inc_internal/maat_config_monitor.h @@ -4,7 +4,7 @@ * Description: maat config monitor api * Authors: Liu WenTan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/inc_internal/maat_ip.h b/src/inc_internal/maat_ip.h index 857d5c8..725e393 100644 --- a/src/inc_internal/maat_ip.h +++ b/src/inc_internal/maat_ip.h @@ -4,7 +4,7 @@ * Description: * Authors: Liu WenTan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/inc_internal/maat_ip_plugin.h b/src/inc_internal/maat_ip_plugin.h index af25384..a218261 100644 --- a/src/inc_internal/maat_ip_plugin.h +++ b/src/inc_internal/maat_ip_plugin.h @@ -4,7 +4,7 @@ * Description: * Authors: Liu WenTan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/inc_internal/maat_limits.h b/src/inc_internal/maat_limits.h index 6040f37..cc16ac7 100644 --- a/src/inc_internal/maat_limits.h +++ b/src/inc_internal/maat_limits.h @@ -4,7 +4,7 @@ * Description: * Authors: Liu WenTan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/inc_internal/maat_plugin.h b/src/inc_internal/maat_plugin.h index d1adef4..ee1be29 100644 --- a/src/inc_internal/maat_plugin.h +++ b/src/inc_internal/maat_plugin.h @@ -4,7 +4,7 @@ * Description: * Authors: Liu WenTan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/inc_internal/maat_rule.h b/src/inc_internal/maat_rule.h index 38e056d..0eabb23 100644 --- a/src/inc_internal/maat_rule.h +++ b/src/inc_internal/maat_rule.h @@ -4,7 +4,7 @@ * Description: maat rule entry * Authors: Liu WenTan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/inc_internal/maat_stat.h b/src/inc_internal/maat_stat.h index 76999e4..02e0404 100644 --- a/src/inc_internal/maat_stat.h +++ b/src/inc_internal/maat_stat.h @@ -4,7 +4,7 @@ * Description: maat statistics * Authors: Liu WenTan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/inc_internal/maat_table.h b/src/inc_internal/maat_table.h index 148e2ff..8ed7041 100644 --- a/src/inc_internal/maat_table.h +++ b/src/inc_internal/maat_table.h @@ -4,7 +4,7 @@ * Description: maat table schema and runtime * Authors: Liu WenTan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/json2iris.c b/src/json2iris.c index 7af5da6..84aa1c1 100644 --- a/src/json2iris.c +++ b/src/json2iris.c @@ -4,7 +4,7 @@ * Description: rule for transform json2iris * Authors: Zheng Chao <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/maat_api.c b/src/maat_api.c index e5226db..d30c59e 100644 --- a/src/maat_api.c +++ b/src/maat_api.c @@ -1,10 +1,10 @@ /* ********************************************************************************************** -* File: maat_api.cpp +* File: maat_api.c * Description: maat api entry * Authors: Liu WenTan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/maat_bool_plugin.c b/src/maat_bool_plugin.c index b8cf39a..9b8d156 100644 --- a/src/maat_bool_plugin.c +++ b/src/maat_bool_plugin.c @@ -1,10 +1,10 @@ /* ********************************************************************************************** -* File: maat_bool_plugin.cpp +* File: maat_bool_plugin.c * Description: * Authors: Liu wentan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/maat_config_monitor.c b/src/maat_config_monitor.c index bed0a3b..16607f8 100644 --- a/src/maat_config_monitor.c +++ b/src/maat_config_monitor.c @@ -1,10 +1,10 @@ /* ********************************************************************************************** -* File: maat_config_monitor.h +* File: maat_config_monitor.c * Description: maat config monitor api * Authors: Liu WenTan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/maat_ex_data.c b/src/maat_ex_data.c index 55d78ef..8ebe9ee 100644 --- a/src/maat_ex_data.c +++ b/src/maat_ex_data.c @@ -1,10 +1,10 @@ /* ********************************************************************************************** -* File: maat_ex_data.cpp +* File: maat_ex_data.c * Description: ex data * Authors: Liu WenTan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/maat_flag.c b/src/maat_flag.c index eba1be6..e156e2f 100644 --- a/src/maat_flag.c +++ b/src/maat_flag.c @@ -1,10 +1,10 @@ /* ********************************************************************************************** -* File: maat_flag.cpp +* File: maat_flag.c * Description: * Authors: Liu WenTan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/maat_fqdn_plugin.c b/src/maat_fqdn_plugin.c index 71e0225..ca3990e 100644 --- a/src/maat_fqdn_plugin.c +++ b/src/maat_fqdn_plugin.c @@ -1,10 +1,10 @@ /* ********************************************************************************************** -* File: maat_fqdn_plugin.cpp +* File: maat_fqdn_plugin.c * Description: * Authors: Liu wentan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/maat_garbage_collection.c b/src/maat_garbage_collection.c index 39599cd..65fe619 100644 --- a/src/maat_garbage_collection.c +++ b/src/maat_garbage_collection.c @@ -1,10 +1,10 @@ /* ********************************************************************************************** -* File: maat_garbage_collection.h +* File: maat_garbage_collection.c * Description: * Authors: Zhengchao <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/maat_group.c b/src/maat_group.c index 74bdec4..cdc8b5a 100644 --- a/src/maat_group.c +++ b/src/maat_group.c @@ -1,10 +1,10 @@ /* ********************************************************************************************** -* File: maat_group.cpp +* File: maat_group.c * Description: * Authors: Liu wentan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ @@ -315,7 +315,8 @@ group2group_item_new(const char *line, struct group2group_schema *g2g_schema, size_t column_len = 0; struct group2group_item *g2g_item = ALLOC(struct group2group_item, 1); - int ret = get_column_pos(line, g2g_schema->group_id_column, &column_offset, &column_len); + int ret = get_column_pos(line, g2g_schema->group_id_column, + &column_offset, &column_len); if (ret < 0) { log_error(logger, MODULE_GROUP, "[%s:%d] group2group table:%s line:%s has no group_id", @@ -360,13 +361,14 @@ size_t print_igraph_vector(igraph_vector_t *v, char *buff, size_t sz) { int printed = 0; for (i = 0; i < igraph_vector_size(v); i++) { - printed += snprintf(buff + printed, sz - printed, " %li", (long int) VECTOR(*v)[i]); + printed += snprintf(buff + printed, sz - printed, " %li", + (long int) VECTOR(*v)[i]); } return printed; } -struct maat_group *group_topology_add_group(struct maat_group_topology *group_topo, +struct maat_group *group_topology_add_group(struct maat_group_topology *group_topo, long long group_id) { assert(group_topo != NULL); @@ -382,8 +384,10 @@ struct maat_group *group_topology_add_group(struct maat_group_topology *group_to assert(igraph_vcount(&group_topo->group_graph)==group->vertex_id); igraph_add_vertices(&group_topo->group_graph, 1, NULL); //Add 1 vertice. - HASH_ADD(hh_group_id, group_topo->hash_by_group_id, group_id, sizeof(group->group_id), group); - HASH_ADD(hh_vertex_id, group_topo->hash_by_vertex_id, vertex_id, sizeof(group->vertex_id), group); + HASH_ADD(hh_group_id, group_topo->hash_by_group_id, group_id, + sizeof(group->group_id), group); + HASH_ADD(hh_vertex_id, group_topo->hash_by_vertex_id, vertex_id, + sizeof(group->vertex_id), group); return group; } @@ -494,7 +498,6 @@ void maat_group_dereference_super_group(struct maat_group *group, long long supe if (tmp_id != NULL) { remove_idx = utarray_eltidx(group->incl_super_group_ids, tmp_id); utarray_erase(group->incl_super_group_ids, remove_idx, 1); - utarray_sort(group->incl_super_group_ids, compare_group_id); } } else { //exclude superior group @@ -502,7 +505,6 @@ void maat_group_dereference_super_group(struct maat_group *group, long long supe if (tmp_id != NULL) { remove_idx = utarray_eltidx(group->excl_super_group_ids, tmp_id); utarray_erase(group->excl_super_group_ids, remove_idx, 1); - utarray_sort(group->excl_super_group_ids, compare_group_id); } } } @@ -522,7 +524,6 @@ void maat_group_dereference_sub_group(struct maat_group *group, long long sub_gr if (tmp_id != NULL) { remove_idx = utarray_eltidx(group->incl_sub_group_ids, tmp_id); utarray_erase(group->incl_sub_group_ids, remove_idx, 1); - utarray_sort(group->incl_sub_group_ids, compare_group_id); } } else { //exclude superior group @@ -530,7 +531,6 @@ void maat_group_dereference_sub_group(struct maat_group *group, long long sub_gr if (tmp_id != NULL) { remove_idx = utarray_eltidx(group->excl_sub_group_ids, tmp_id); utarray_erase(group->excl_sub_group_ids, remove_idx, 1); - utarray_sort(group->excl_sub_group_ids, compare_group_id); } } } @@ -680,7 +680,7 @@ int group2group_runtime_update(void *g2g_runtime, void *g2g_schema, return -1; } - struct group2group_item *g2g_item = group2group_item_new(line, schema, table_name, + struct group2group_item *g2g_item = group2group_item_new(line, schema, table_name, g2g_rt->logger); if (NULL == g2g_item) { g2g_rt->update_err_cnt++; @@ -695,8 +695,10 @@ int group2group_runtime_update(void *g2g_runtime, void *g2g_schema, if (0 == is_valid) { //delete - ret = group_topology_del_group_from_group(g2g_rt->updating_group_topo, g2g_item->group_id, - g2g_item->super_group_id, g2g_item->is_exclude); + ret = group_topology_del_group_from_group(g2g_rt->updating_group_topo, + g2g_item->group_id, + g2g_item->super_group_id, + g2g_item->is_exclude); if (0 == ret) { g2g_rt->rule_num--; } else { @@ -704,8 +706,10 @@ int group2group_runtime_update(void *g2g_runtime, void *g2g_schema, } } else { //add - ret = group_topology_add_group_to_group(g2g_rt->updating_group_topo, g2g_item->group_id, - g2g_item->super_group_id, g2g_item->is_exclude); + ret = group_topology_add_group_to_group(g2g_rt->updating_group_topo, + g2g_item->group_id, + g2g_item->super_group_id, + g2g_item->is_exclude); if (0 == ret) { g2g_rt->rule_num++; } else { @@ -723,7 +727,8 @@ void garbage_maat_group_topology_free(void *data, void *arg) maat_group_topology_free(group_topo); } -int group2group_runtime_commit(void *g2g_runtime, const char *table_name, long long maat_rt_version) +int group2group_runtime_commit(void *g2g_runtime, const char *table_name, + long long maat_rt_version) { if (NULL == g2g_runtime) { return -1; @@ -759,21 +764,13 @@ int group2group_runtime_commit(void *g2g_runtime, const char *table_name, long l } #define MAX_RECURSION_DEPTH 5 -void get_candidate_super_group_ids(struct maat_group_topology *group_topo, UT_array *hit_group_ids, - UT_array *candidate_group_ids, size_t depth) +void get_candidate_super_group_ids(struct maat_group_topology *group_topo, + UT_array *hit_group_ids, + UT_array *super_group_ids) { long long *p = NULL; - UT_array *one_round_hit_group_ids; - - if (depth >= MAX_RECURSION_DEPTH) { - log_error(group_topo->logger, MODULE_GROUP, "[%s:%d] recursive depth:%zu exceed maxium:%d", - __FUNCTION__, __LINE__, depth, MAX_RECURSION_DEPTH); - return; - } - - utarray_new(one_round_hit_group_ids, &ut_group_id_icd); - //Find super candidates + //Find super candidates for (p = (long long *)utarray_front(hit_group_ids); p != NULL; p = (long long *)utarray_next(hit_group_ids, p)) { struct maat_group *group = group_topology_find_group(group_topo, *p); @@ -782,135 +779,149 @@ void get_candidate_super_group_ids(struct maat_group_topology *group_topo, UT_ar continue; } - if ((0 == utarray_len(group->incl_sub_group_ids)) && - (0 == utarray_len(group->excl_sub_group_ids))) { - if (!utarray_find(candidate_group_ids, p, compare_group_id)) { - utarray_push_back(candidate_group_ids, p); - utarray_sort(candidate_group_ids, compare_group_id); - } - } - long long *tmp = NULL; for (tmp = (long long *)utarray_front(group->incl_super_group_ids); tmp != NULL; tmp = (long long *)utarray_next(group->incl_super_group_ids, tmp)) { - if (utarray_find(candidate_group_ids, tmp, compare_group_id)) { + if (utarray_find(super_group_ids, tmp, compare_group_id)) { continue; } - utarray_push_back(candidate_group_ids, tmp); - utarray_sort(candidate_group_ids, compare_group_id); - utarray_push_back(one_round_hit_group_ids, tmp); + utarray_push_back(super_group_ids, tmp); + utarray_sort(super_group_ids, compare_group_id); } } - - if (utarray_len(one_round_hit_group_ids) == 0) { - goto next; - } - - depth++; - get_candidate_super_group_ids(group_topo, one_round_hit_group_ids, candidate_group_ids, depth); -next: - utarray_free(one_round_hit_group_ids); } -void verify_candidate_super_group_ids(struct maat_group_topology *group_topo, UT_array *candidate_group_ids, - UT_array *all_hit_group_ids, size_t depth) +void verify_candidate_super_group_ids(struct maat_group_topology *group_topo, + UT_array *candidate_super_group_ids, + UT_array *all_hit_group_ids, + UT_array *kept_super_group_ids) { long long *p = NULL; - UT_array *kept_group_ids; + UT_array *candidate_group_ids; - if (depth >= MAX_RECURSION_DEPTH) { - log_error(group_topo->logger, MODULE_GROUP, "[%s:%d] recursive depth:%zu exceed maxium:%d", - __FUNCTION__, __LINE__, depth, MAX_RECURSION_DEPTH); - return; + utarray_new(candidate_group_ids, &ut_group_id_icd); + + for (p = (long long *)utarray_front(candidate_super_group_ids); p != NULL; + p = (long long *)utarray_next(candidate_super_group_ids, p)) { + utarray_push_back(candidate_group_ids, p); } - utarray_new(kept_group_ids, &ut_group_id_icd); - - for (p = (long long *)utarray_front(candidate_group_ids); p != NULL; - p = (long long *)utarray_next(candidate_group_ids, p)) { + for (p = (long long *)utarray_front(all_hit_group_ids); p != NULL; + p = (long long *)utarray_next(all_hit_group_ids, p)) { + utarray_push_back(candidate_group_ids, p); + } + utarray_sort(candidate_group_ids, compare_group_id); + + /** + * verify sub exclude for candidate_super_group_ids + */ + for (p = (long long *)utarray_front(candidate_super_group_ids); p != NULL; + p = (long long *)utarray_next(candidate_super_group_ids, p)) { struct maat_group *group = group_topology_find_group(group_topo, *p); assert(group != NULL); - if ((0 == utarray_len(group->incl_sub_group_ids)) && - (0 == utarray_len(group->excl_sub_group_ids))) { - if (!utarray_find(kept_group_ids, p, compare_group_id)) { - utarray_push_back(kept_group_ids, p); + //if group's sub excl in candidate_group_ids + int sub_excl_flag = 0; + long long *tmp_id = NULL; + for (tmp_id = (long long *)utarray_front(group->excl_sub_group_ids); tmp_id != NULL; + tmp_id = (long long *)utarray_next(group->excl_sub_group_ids, tmp_id)) { + if (utarray_find(candidate_group_ids, tmp_id, compare_group_id)) { + sub_excl_flag = 1; + break; } - + } + + //delete group_id from kept_group_ids + if (1 == sub_excl_flag) { continue; } + utarray_push_back(kept_super_group_ids, p); + utarray_sort(kept_super_group_ids, compare_group_id); - long long *tmp = NULL; - int kept_flag = 1; - // group's sub_exclude in candidates, it should not be kept - for (tmp = (long long *)utarray_front(group->excl_sub_group_ids); tmp != NULL; - tmp = (long long *)utarray_next(group->excl_sub_group_ids, tmp)) { - if (utarray_find(candidate_group_ids, tmp, compare_group_id)) { - //if group's sub exclude in candidate, it should not be kept - kept_flag = 0; - break; - } + if (!utarray_find(all_hit_group_ids, p, compare_group_id)) { + utarray_push_back(all_hit_group_ids, p); + utarray_sort(all_hit_group_ids, compare_group_id); } + } - // group's all sub_include not in candidates, it should not be kept - for (tmp = (long long *)utarray_front(group->incl_sub_group_ids); tmp != NULL; - tmp = (long long *)utarray_next(group->incl_sub_group_ids, tmp)) { - if (!utarray_find(candidate_group_ids, tmp, compare_group_id)) { - kept_flag = 0; - break; - } + /** + * candidate_group_ids clone all_hit_group_ids + */ + utarray_clear(candidate_group_ids); + for (p = (long long *)utarray_front(all_hit_group_ids); p != NULL; + p = (long long *)utarray_next(all_hit_group_ids, p)) { + utarray_push_back(candidate_group_ids, p); + } + + /** + * delete groups whose all incl sub is non-exist in all_hit_group_ids + */ + for (p = (long long *)utarray_front(candidate_group_ids); p != NULL; + p = (long long *)utarray_next(candidate_group_ids, p)) { + struct maat_group *group = group_topology_find_group(group_topo, *p); + if (NULL == group) { + continue; } - if (1 == kept_flag) { - utarray_push_back(kept_group_ids, p); + if (0 == utarray_len(group->incl_sub_group_ids)) { + continue; } - } - if (utarray_len(kept_group_ids) == utarray_len(candidate_group_ids)) { - for (p = (long long *)utarray_front(candidate_group_ids); p != NULL; - p = (long long *)utarray_next(candidate_group_ids, p)) { - utarray_push_back(all_hit_group_ids, p); + int sub_incl_flag = 0; + long long *tmp_id = NULL; + for (tmp_id = (long long *)utarray_front(group->incl_sub_group_ids); tmp_id != NULL; + tmp_id = (long long *)utarray_next(group->incl_sub_group_ids, tmp_id)) { + if (utarray_find(candidate_group_ids, tmp_id, compare_group_id)) { + sub_incl_flag = 1; + break; + } } - goto next; + if (0 == sub_incl_flag) { + tmp_id = utarray_find(all_hit_group_ids, p, compare_group_id); + assert(tmp_id != NULL); + size_t remove_idx = utarray_eltidx(all_hit_group_ids, tmp_id); + utarray_erase(all_hit_group_ids, remove_idx, 1); + + tmp_id = utarray_find(kept_super_group_ids, p, compare_group_id); + if (tmp_id != NULL) { + remove_idx = utarray_eltidx(kept_super_group_ids, tmp_id); + utarray_erase(kept_super_group_ids, remove_idx, 1); + } + } } - depth++; - verify_candidate_super_group_ids(group_topo, kept_group_ids, all_hit_group_ids, depth); -next: - utarray_free(kept_group_ids); + utarray_free(candidate_group_ids); } -size_t group_topology_get_super_groups(struct maat_group_topology *group_topo, - long long *group_ids, size_t n_group_ids, - long long *super_group_ids, - size_t super_group_ids_size) +#define MAX_RECURSION_DEPTH 5 +void get_super_group_ids(struct maat_group_topology *group_topo, UT_array *hit_group_ids, + UT_array *all_hit_group_ids, size_t depth) { - size_t i = 0, idx = 0, depth = 0; - UT_array *one_round_hit_group_ids; - UT_array *candidate_group_ids; - UT_array *all_hit_group_ids; - - utarray_new(one_round_hit_group_ids, &ut_group_id_icd); - utarray_new(candidate_group_ids, &ut_group_id_icd); - utarray_new(all_hit_group_ids, &ut_group_id_icd); + UT_array *candidate_super_group_ids; + UT_array *kept_super_group_ids; - for (i = 0; i < n_group_ids; i++) { - utarray_push_back(one_round_hit_group_ids, &(group_ids[i])); + if (depth >= MAX_RECURSION_DEPTH) { + return; } + utarray_new(kept_super_group_ids, &ut_group_id_icd); + utarray_new(candidate_super_group_ids, &ut_group_id_icd); + /** - candidates means all hit groups' super include group, no need to consider super exclude groups + candidate super groups means all hit groups' super include group, + no need to consider super exclude groups for example: hit_groups = {g4, g11} g4's super include groups = {g7, g8} g11's super include groups = {g12} - candidates = {g7, g8, g12} + candidate super groups = {g7, g8, g12} */ - get_candidate_super_group_ids(group_topo, one_round_hit_group_ids, candidate_group_ids, depth); - if (0 == utarray_len(candidate_group_ids)) { + get_candidate_super_group_ids(group_topo, hit_group_ids, candidate_super_group_ids); + + if (0 == utarray_len(candidate_super_group_ids)) { goto next; } @@ -932,17 +943,43 @@ size_t group_topology_get_super_groups(struct maat_group_topology *group_topo, g3 g4 g5 g11 candidates = {g4, g11, g7, g8, g12} g12's sub_exclude g8 in candidates, so g12 should be dropped - after verify candidates, all hit super groups = {g7, g8}, all hit groups = {g4, g11, g7, g8} + after verify candidates, all hit super groups = {g7, g8}, + all hit groups = {g4, g11, g7, g8} */ - verify_candidate_super_group_ids(group_topo, candidate_group_ids, all_hit_group_ids, depth); - if (0 == utarray_len(all_hit_group_ids)) { - goto next; + verify_candidate_super_group_ids(group_topo, candidate_super_group_ids, all_hit_group_ids, + kept_super_group_ids); + + depth++; + get_super_group_ids(group_topo, kept_super_group_ids, all_hit_group_ids, depth); +next: + utarray_free(candidate_super_group_ids); + utarray_free(kept_super_group_ids); +} + +size_t group_topology_get_super_groups(struct maat_group_topology *group_topo, + long long *group_ids, size_t n_group_ids, + long long *super_group_ids, + size_t super_group_ids_size) +{ + size_t i = 0, idx = 0; + UT_array *all_hit_group_ids; + UT_array *candidate_group_ids; + + utarray_new(all_hit_group_ids, &ut_group_id_icd); + utarray_new(candidate_group_ids, &ut_group_id_icd); + + for (i = 0; i < n_group_ids; i++) { + utarray_push_back(candidate_group_ids, &(group_ids[i])); + utarray_push_back(all_hit_group_ids, &(group_ids[i])); } + utarray_sort(candidate_group_ids, compare_group_id); + utarray_sort(all_hit_group_ids, compare_group_id); + + get_super_group_ids(group_topo, candidate_group_ids, all_hit_group_ids, 0); - // delete group_ids from all_hit_group_ids, just keep all hit super groups for (i = 0; i < n_group_ids; i++) { - long long *tmp_id = NULL; - tmp_id = utarray_find(all_hit_group_ids, &group_ids[i], compare_group_id); + long long *tmp_id = utarray_find(all_hit_group_ids, &(group_ids[i]), + compare_group_id); if (tmp_id != NULL) { size_t remove_idx = utarray_eltidx(all_hit_group_ids, tmp_id); utarray_erase(all_hit_group_ids, remove_idx, 1); @@ -952,17 +989,11 @@ size_t group_topology_get_super_groups(struct maat_group_topology *group_topo, long long *p = NULL; for (p = (long long *)utarray_front(all_hit_group_ids); p != NULL; p = (long long *)utarray_next(all_hit_group_ids, p)) { - if (idx >= super_group_ids_size) { - break; - } - super_group_ids[idx++] = *p; } -next: - utarray_free(one_round_hit_group_ids); - utarray_free(candidate_group_ids); utarray_free(all_hit_group_ids); + utarray_free(candidate_group_ids); return idx; } diff --git a/src/maat_ip_plugin.c b/src/maat_ip_plugin.c index 4294d60..d471ad2 100644 --- a/src/maat_ip_plugin.c +++ b/src/maat_ip_plugin.c @@ -1,10 +1,10 @@ /* ********************************************************************************************** -* File: maat_ip_plugin.cpp +* File: maat_ip_plugin.c * Description: * Authors: Liu wentan <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/src/maat_kv.c b/src/maat_kv.c index 990407c..ee282de 100644 --- a/src/maat_kv.c +++ b/src/maat_kv.c @@ -1,10 +1,10 @@ /* ********************************************************************************************** -* File: maat_kv_map.cpp +* File: maat_kv.c * Description: * Authors: Zheng chao <[email protected]> * Date: 2022-10-31 -* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved. +* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. *********************************************************************************************** */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index edbf951..9c459d4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,9 +6,6 @@ include_directories(${PROJECT_SOURCE_DIR}/scanner) include_directories(${PROJECT_SOURCE_DIR}/scanner/adapter_hs) include_directories(${PROJECT_SOURCE_DIR}/scanner/ip_matcher) -add_executable(maat_api_gtest maat_api_gtest.cpp) -target_link_libraries(maat_api_gtest maat_frame_shared gtest_static) - add_executable(rcu_hash_gtest rcu_hash_gtest.cpp) target_link_libraries(rcu_hash_gtest maat_frame_static gtest_static) @@ -27,6 +24,8 @@ target_link_libraries(adapter_hs_gtest maat_frame_static gtest_static) add_executable(maat_ex_data_gtest maat_ex_data_gtest.cpp) target_link_libraries(maat_ex_data_gtest maat_frame_static gtest_static) +add_subdirectory(group_exclude) + file(COPY table_info.conf DESTINATION ./) file(COPY file_test_tableinfo.conf DESTINATION ./) file(COPY literal_expr.conf DESTINATION ./) @@ -37,6 +36,7 @@ file(COPY ntcrule DESTINATION ./) file(COPY testdata DESTINATION ./) file(COPY test_streamfiles DESTINATION ./) file(COPY json_update DESTINATION ./) +file(COPY group_exclude DESTINATION ./) include(GoogleTest) gtest_discover_tests(maat_framework_gtest)
\ No newline at end of file diff --git a/test/group_exclude/CMakeLists.txt b/test/group_exclude/CMakeLists.txt new file mode 100644 index 0000000..cd25a1c --- /dev/null +++ b/test/group_exclude/CMakeLists.txt @@ -0,0 +1,4 @@ +include_directories(${PROJECT_SOURCE_DIR}/src/inc_internal) + +add_executable(group_exclude_gtest group_exclude_gtest.cpp) +target_link_libraries(group_exclude_gtest maat_frame_static gtest_static)
\ No newline at end of file diff --git a/test/group_exclude/group_exclude_L3.conf b/test/group_exclude/group_exclude_L3.conf index 176999f..dbbe13e 100644 --- a/test/group_exclude/group_exclude_L3.conf +++ b/test/group_exclude/group_exclude_L3.conf @@ -79,20 +79,10 @@ "group_id": 11, "super_group_id": 13, "is_exclude": 1 - }, - { - "group_id": 8, - "super_group_id": 7, - "is_exclude": 1 } ], "del_items": [ { - "group_id": 8, - "super_group_id": 7, - "is_exclude": 1 - }, - { "group_id": 11, "super_group_id": 13, "is_exclude": 1 diff --git a/test/group_exclude/group_exclude_gtest.cpp b/test/group_exclude/group_exclude_gtest.cpp new file mode 100644 index 0000000..8c6822d --- /dev/null +++ b/test/group_exclude/group_exclude_gtest.cpp @@ -0,0 +1,202 @@ +#include "maat.h" +#include "log/log.h" +#include "cJSON/cJSON.h" +#include "maat_rule.h" +#include "maat_utils.h" +#include "maat_command.h" +#include "maat_group.h" +#include <gtest/gtest.h> + +#define MODULE_GROUP_EXCLUDE_GTEST module_name_str("maat.group_exclude_gtest") + +#define MAX_ITEM_NUM 64 +#define WAIT_FOR_EFFECTIVE_S 2 + +const char *table_info_path = "./table_info.conf"; + +struct group_item { + long long group_id; + long long super_group_id; + int is_exclude; +}; + +struct group2group_rule { + size_t n_add_item; + size_t n_del_item; + struct group_item add_items[MAX_ITEM_NUM]; + struct group_item del_items[MAX_ITEM_NUM]; +}; + +static int parse_config_file(const char *filename, struct group2group_rule *rules) +{ + unsigned char *json_buff = NULL; + size_t json_buff_size = 0; + + int ret = load_file_to_memory(filename, &json_buff, &json_buff_size); + if (ret < 0) { + printf("load file:%s to memory failed.\n", filename); + return -1; + } + + size_t rule_cnt = 0; + cJSON *items_array = NULL; + cJSON *root = cJSON_Parse((const char *)json_buff); + if (NULL == root) { + printf("Error before: %-200.200s\n", cJSON_GetErrorPtr()); + ret = -1; + goto next; + } + + items_array = cJSON_GetObjectItem(root, "add_items"); + if (NULL == items_array) { + printf("Error before: %-200.200s\n", cJSON_GetErrorPtr()); + ret = -1; + goto next; + } + + rule_cnt = cJSON_GetArraySize(items_array); + for (size_t i = 0; i < rule_cnt; i++) { + cJSON *item_obj = cJSON_GetArrayItem(items_array, i); + cJSON *tmp_item = cJSON_GetObjectItem(item_obj, "group_id"); + if (tmp_item != NULL && tmp_item->type == cJSON_Number) { + rules->add_items[i].group_id = tmp_item->valueint; + } + + tmp_item = cJSON_GetObjectItem(item_obj, "super_group_id"); + if (tmp_item != NULL && tmp_item->type == cJSON_Number) { + rules->add_items[i].super_group_id = tmp_item->valueint; + } + + tmp_item = cJSON_GetObjectItem(item_obj, "is_exclude"); + if (tmp_item != NULL && tmp_item->type == cJSON_Number) { + rules->add_items[i].is_exclude = tmp_item->valueint; + } + } + rules->n_add_item = rule_cnt; + + items_array = cJSON_GetObjectItem(root, "del_items"); + if (NULL == items_array) { + printf("Error before: %-200.200s\n", cJSON_GetErrorPtr()); + ret = -1; + goto next; + } + + rule_cnt = cJSON_GetArraySize(items_array); + for (size_t i = 0; i < rule_cnt; i++) { + cJSON *item_obj = cJSON_GetArrayItem(items_array, i); + cJSON *tmp_item = cJSON_GetObjectItem(item_obj, "group_id"); + if (tmp_item != NULL && tmp_item->type == cJSON_Number) { + rules->del_items[i].group_id = tmp_item->valueint; + } + + tmp_item = cJSON_GetObjectItem(item_obj, "super_group_id"); + if (tmp_item != NULL && tmp_item->type == cJSON_Number) { + rules->del_items[i].super_group_id = tmp_item->valueint; + } + + tmp_item = cJSON_GetObjectItem(item_obj, "is_exclude"); + if (tmp_item != NULL && tmp_item->type == cJSON_Number) { + rules->del_items[i].is_exclude = tmp_item->valueint; + } + } + rules->n_del_item = rule_cnt; + +next: + cJSON_Delete(root); + FREE(json_buff); + return ret; +} + +class MaatGroupExclude : public testing::Test +{ +protected: + static void SetUpTestCase() { + unsigned char *json_buff = NULL; + size_t json_buff_size = 0; + + logger = log_handle_create("./group_exclude_gtest.log", 0); + garbage_bin = maat_garbage_bin_new(60); + + int ret = load_file_to_memory("./group_exclude_table_info.conf", + &json_buff, &json_buff_size); + if (ret < 0) { + log_error(logger, MODULE_GROUP_EXCLUDE_GTEST, "load_file_to_memory failed."); + assert(0); + } + + cJSON *root = cJSON_Parse((const char *)json_buff); + if (!root) { + log_error(logger, MODULE_GROUP_EXCLUDE_GTEST, "cJSON_Parse failed."); + assert(0); + } + + g2g_schema = group2group_schema_new(root, NULL, "EXCLUDE_GROUP2GROUP", logger); + FREE(json_buff); + cJSON_Delete(root); + + if (NULL == g2g_schema) { + log_error(logger, MODULE_GROUP_EXCLUDE_GTEST, "group2group_schema_new failed."); + assert(0); + } + + g2g_runtime = group2group_runtime_new(g2g_schema, 1, garbage_bin, logger); + if (NULL == g2g_runtime) { + log_error(logger, MODULE_GROUP_EXCLUDE_GTEST, "group2group_runtime_new failed."); + assert(0); + } + + } + + static void TearDownTestCase() { + log_handle_destroy(logger); + maat_garbage_bin_free(garbage_bin); + group2group_runtime_free(g2g_runtime); + group2group_schema_free(g2g_schema); + } + + static void *g2g_schema; + static void *g2g_runtime; + static struct log_handle *logger; + static struct maat_garbage_bin *garbage_bin; +}; + +void *MaatGroupExclude::g2g_schema; +void *MaatGroupExclude::g2g_runtime; +struct log_handle *MaatGroupExclude::logger; +struct maat_garbage_bin *MaatGroupExclude::garbage_bin; + +TEST_F(MaatGroupExclude, level_3_basic) { + char table_line[1024]; + struct group2group_rule rules; + const char *table_name = "EXCLUDE_GROUP2GROUP"; + //struct log_handle *logger = MaatGroupExclude::logger; + + int ret = parse_config_file("group_exclude_L3.conf", &rules); + EXPECT_EQ(ret, 0); + + for (size_t i = 0; i < rules.n_add_item; i++) { + memset(table_line, 0, sizeof(table_line)); + + sprintf(table_line, "%lld\t%lld\t%d\t%d", rules.add_items[i].group_id, + rules.add_items[i].super_group_id, rules.add_items[i].is_exclude, 1); + group2group_runtime_update(g2g_runtime, g2g_schema, table_name, table_line, 4); + } + + group2group_runtime_commit(g2g_runtime, table_name, 1); + + long long hit_group_ids[2] = {11, 4}; + long long super_group_ids[MAX_ITEM_NUM]; + size_t super_group_cnt = group2group_runtime_get_super_groups(g2g_runtime, hit_group_ids, 2, + super_group_ids, MAX_ITEM_NUM); + for (size_t i = 0; i < super_group_cnt; i++) { + printf("super_group_ids[%zu]:%lld\n", i, super_group_ids[i]); + } +} + +int main(int argc, char ** argv) +{ + int ret=0; + ::testing::InitGoogleTest(&argc, argv); + ret=RUN_ALL_TESTS(); + return ret; +} diff --git a/test/group_exclude/group_exclude_table_info.conf b/test/group_exclude/group_exclude_table_info.conf new file mode 100644 index 0000000..f938a4e --- /dev/null +++ b/test/group_exclude/group_exclude_table_info.conf @@ -0,0 +1,11 @@ +{ + "table_id":1, + "table_name":"EXCLUDE_GROUP2GROUP", + "table_type":"group2group", + "valid_column":4, + "custom": { + "group_id":1, + "super_group_id":2, + "is_exclude":3 + } +}
\ No newline at end of file diff --git a/test/maat_api_gtest.cpp b/test/maat_api_gtest.cpp deleted file mode 100644 index df9911d..0000000 --- a/test/maat_api_gtest.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "maat.h" -#include "maat_rule.h" -#include <gtest/gtest.h> - - -int main(int argc, char ** argv) -{ - int ret=0; - ::testing::InitGoogleTest(&argc, argv); - ret=RUN_ALL_TESTS(); - return ret; -} diff --git a/test/maat_framework_gtest.cpp b/test/maat_framework_gtest.cpp index 9eb9f43..798a8ef 100644 --- a/test/maat_framework_gtest.cpp +++ b/test/maat_framework_gtest.cpp @@ -775,7 +775,7 @@ TEST_F(MaatFlagScan, FlagPlus) { maat_state_free(state); state = NULL; } -#if 1 + class MaatStringScan : public testing::Test { protected: @@ -6160,7 +6160,6 @@ TEST_F(MaatRollbackTest, FullConfigRollback) { maat_state_free(state); state = NULL; } -#endif int main(int argc, char ** argv) { |
