refactor hierarchy and maat_table
This commit is contained in:
@@ -25,7 +25,7 @@ struct maat_options {
|
||||
char instance_name[NAME_MAX];
|
||||
size_t nr_worker_threads;
|
||||
|
||||
const char *accept_tags;
|
||||
char *accept_tags;
|
||||
|
||||
int rule_effect_interval_ms;
|
||||
int rule_update_checking_interval_ms;
|
||||
|
||||
@@ -18,7 +18,7 @@ extern "C"
|
||||
|
||||
#include "log/log.h"
|
||||
#include "cJSON/cJSON.h"
|
||||
#include "maat.h"
|
||||
#include "maat/maat.h"
|
||||
#include "maat_kv.h"
|
||||
#include "maat_rule.h"
|
||||
|
||||
@@ -38,6 +38,7 @@ void compile_schema_free(void *compile_schema);
|
||||
|
||||
void *group2compile_schema_new(cJSON *json, const char *table_name, struct log_handle *logger);
|
||||
void group2compile_schema_free(void *g2c_schema);
|
||||
int group2compile_associated_compile_table_id(void *g2c_schema);
|
||||
|
||||
int compile_table_set_rule_ex_data_schema(struct compile_schema *compile_schema, int table_id,
|
||||
maat_rule_ex_new_func_t *new_func,
|
||||
@@ -51,7 +52,7 @@ compile_table_get_rule_ex_data_schema(struct compile_schema *compile_schema, siz
|
||||
size_t compile_table_rule_ex_data_schema_count(struct compile_schema *compile_schema);
|
||||
|
||||
/* compile runtime API */
|
||||
void *compile_runtime_new(void *compile_schema, struct maat_garbage_bin *garbage_bin,
|
||||
void *compile_runtime_new(void *compile_schema, int max_thread_num, struct maat_garbage_bin *garbage_bin,
|
||||
struct log_handle *logger);
|
||||
void compile_runtime_free(void *compile_runtime);
|
||||
|
||||
@@ -60,14 +61,15 @@ int compile_runtime_update(void *compile_runtime, void *compile_schema, const ch
|
||||
int compile_runtime_commit(void *compile_runtime);
|
||||
|
||||
int compile_runtime_match(struct compile_runtime *compile_rt, int *group_ids, size_t n_group_ids,
|
||||
int *compile_ids, size_t compile_ids_size, struct maat_state *state);
|
||||
int vt_id, int *compile_ids, size_t compile_ids_size, struct maat_state *state);
|
||||
|
||||
size_t compile_runtime_get_hit_paths(struct compile_runtime *compile_rt, struct maat_group_topology *group_topo,
|
||||
struct maat_compile_state *compile_state,
|
||||
size_t compile_runtime_get_hit_paths(struct compile_runtime *compile_rt, struct group2group_runtime *g2g_rt,
|
||||
struct maat_compile_state *compile_state,
|
||||
struct maat_hit_path *hit_paths, size_t hit_path_siz);
|
||||
/* group2compile runtime API */
|
||||
void *group2compile_runtime_new(void *g2c_schema, struct maat_garbage_bin *garbage_bin,
|
||||
void *group2compile_runtime_new(void *g2c_schema, int max_thread_num, struct maat_garbage_bin *garbage_bin,
|
||||
struct log_handle *logger);
|
||||
void group2compile_runtime_init(void *g2c_runtime, void *compile_runtime, void *g2g_runtime);
|
||||
void group2compile_runtime_free(void *g2c_runtime);
|
||||
|
||||
int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema, const char *line,
|
||||
@@ -79,7 +81,7 @@ struct maat_compile_state *maat_compile_state_new(int thread_id);
|
||||
void maat_compile_state_free(struct maat_compile_state *compile_state);
|
||||
void maat_compile_state_update_hit_path(struct maat_compile_state *compile_state, int item_id, int group_id, int virtual_table_id,
|
||||
int Nth_scan, int Nth_item_result);
|
||||
void maat_compile_state_update_hit_clause(struct maat_compile_state *compile_state, struct maat_compile **compile_hash,
|
||||
void maat_compile_state_update_hit_clause(struct maat_compile_state *compile_state, void *compile_runtime,
|
||||
int group_id, int virtual_table_id);
|
||||
int maat_compile_state_has_NOT_clause(struct maat_compile_state *compile_state);
|
||||
|
||||
|
||||
@@ -33,7 +33,8 @@ struct ex_container_ctx {
|
||||
struct ex_data_runtime;
|
||||
|
||||
/* ex_data_runtime API */
|
||||
struct ex_data_runtime *ex_data_runtime_new(int table_id, rcu_hash_data_free_fn *data_free_fn);
|
||||
struct ex_data_runtime *ex_data_runtime_new(int table_id, rcu_hash_data_free_fn *data_free_fn,
|
||||
struct log_handle *logger);
|
||||
|
||||
void ex_data_runtime_free(struct ex_data_runtime *ex_data_rt);
|
||||
|
||||
|
||||
@@ -25,10 +25,11 @@ void *expr_schema_new(cJSON *json, const char *table_name, struct log_handle *lo
|
||||
void expr_schema_free(void *expr_schema);
|
||||
|
||||
/* expr runtime API */
|
||||
void *expr_runtime_new(void *expr_schema, struct maat_garbage_bin *garbage_bin, struct log_handle *logger);
|
||||
void *expr_runtime_new(void *expr_schema, int max_thread_num, struct maat_garbage_bin *garbage_bin,
|
||||
struct log_handle *logger);
|
||||
void expr_runtime_free(void *expr_runtime);
|
||||
|
||||
int expr_runtime_updating_flag(struct expr_runtime *expr_rt);
|
||||
int expr_runtime_updating_flag(void *expr_runtime);
|
||||
int expr_runtime_update(void *expr_runtime, void *expr_schema, const char *line, int valid_column);
|
||||
int expr_runtime_commit(void *expr_runtime);
|
||||
|
||||
@@ -38,7 +39,7 @@ int expr_runtime_commit(void *expr_runtime);
|
||||
*
|
||||
* @retval the num of hit group_id
|
||||
*/
|
||||
int expr_runtime_scan_string(struct expr_runtime *expr_rt, int thread_id,
|
||||
int expr_runtime_scan_string(struct expr_runtime *expr_runtime, int thread_id,
|
||||
const char *data, size_t data_len, int group_ids[],
|
||||
size_t max_hit_num, int virtual_table_id,
|
||||
struct maat_state *state);
|
||||
|
||||
@@ -20,17 +20,17 @@ extern "C"
|
||||
|
||||
struct maat_garbage_bin;
|
||||
|
||||
struct maat_garbage_bin* maat_garbage_bin_new(int default_timeout);
|
||||
struct maat_garbage_bin *maat_garbage_bin_new(int default_timeout);
|
||||
|
||||
void maat_garbage_bin_free(struct maat_garbage_bin* bin);
|
||||
void maat_garbage_bin_free(struct maat_garbage_bin *bin);
|
||||
|
||||
void maat_garbage_bagging(struct maat_garbage_bin* bin, void* garbage, void (* func)(void *));
|
||||
void maat_garbage_bagging(struct maat_garbage_bin *bin, void *garbage, void (* func)(void *));
|
||||
|
||||
void maat_garbage_collect_routine(struct maat_garbage_bin* bin);
|
||||
void maat_garbage_collect_routine(struct maat_garbage_bin *bin);
|
||||
|
||||
size_t maat_garbage_bin_get_size(struct maat_garbage_bin* bin);
|
||||
size_t maat_garbage_bin_get_size(struct maat_garbage_bin *bin);
|
||||
|
||||
void maat_garbage_collect_by_force(struct maat_garbage_bin* bin);
|
||||
void maat_garbage_collect_by_force(struct maat_garbage_bin *bin);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
@@ -37,22 +37,20 @@ struct maat_group {
|
||||
|
||||
/* maat group topology API */
|
||||
struct maat_group_topology;
|
||||
struct maat_group_topology *maat_group_topology_new(struct log_handle *logger);
|
||||
void maat_group_topology_free(struct maat_group_topology *group_topo);
|
||||
|
||||
struct maat_group *maat_group_topology_add_group(struct maat_group_topology *group_topo, int group_id);
|
||||
void maat_group_topology_remove_group(struct maat_group_topology *group_topo, struct maat_group *group);
|
||||
|
||||
/**
|
||||
* @retval if not found, return NULL
|
||||
*/
|
||||
struct maat_group *maat_group_topology_find_group(struct maat_group_topology *group_topo, int group_id);
|
||||
|
||||
int maat_group_topology_add_group_to_group(struct maat_group_topology *group_topo, int group_id, int superior_group_id);
|
||||
int maat_group_topology_remove_group_from_group(struct maat_group_topology *group_topo, int group_id, int superior_group_id);
|
||||
|
||||
//struct maat_group *maat_group_topology_add_group(struct maat_group_topology *group_topo, int group_id);
|
||||
//struct maat_group *maat_group_topology_find_group(struct maat_group_topology *group_topo, int group_id);
|
||||
//void maat_group_topology_remove_group(struct maat_group_topology *group_topo, struct maat_group *group);
|
||||
//int maat_group_topology_add_group_to_group(struct maat_group_topology *group_topo, int group_id, int superior_group_id);
|
||||
//int maat_group_topology_remove_group_from_group(struct maat_group_topology *group_topo, int group_id, int superior_group_id);
|
||||
|
||||
/* build top groups */
|
||||
int maat_group_topology_build_top_groups(struct maat_group_topology *group_topo);
|
||||
//int maat_group_topology_build_top_groups(struct maat_group_topology *group_topo);
|
||||
|
||||
|
||||
/* group2group schema API */
|
||||
@@ -60,15 +58,24 @@ void *group2group_schema_new(cJSON *json, const char *table_name, struct log_han
|
||||
void group2group_schema_free(void *g2g_schema);
|
||||
|
||||
/* group2group runtime API */
|
||||
struct group2group_runtime *
|
||||
group2group_runtime_new(void *ip_plus_schema, struct maat_garbage_bin *garbage_bin,
|
||||
struct log_handle *logger);
|
||||
void *group2group_runtime_new(void *ip_plus_schema, int max_thread_num, struct maat_garbage_bin *garbage_bin,
|
||||
struct log_handle *logger);
|
||||
void group2group_runtime_free(void *g2g_runtime);
|
||||
|
||||
struct maat_group *group2group_runtime_add_group(void *g2g_runtime, int group_id);
|
||||
void group2group_runtime_remove_group(void *g2g_runtime, struct maat_group *group);
|
||||
struct maat_group *group2group_runtime_find_group(void *g2g_runtime, int group_id);
|
||||
|
||||
int group2group_runtime_add_group_to_group(void *g2g_runtime, int group_id, int superior_group_id);
|
||||
int group2group_runtime_remove_group_from_group(void *g2g_runtime, int group_id, int superior_group_id);
|
||||
|
||||
int group2group_runtime_build_top_groups(void *g2g_runtime);
|
||||
|
||||
|
||||
int group2group_runtime_update(void *g2g_runtime, void *g2g_schema, const char *line, int valid_column);
|
||||
int group2group_runtime_commit(void *g2g_runtime);
|
||||
|
||||
int group2group_runtime_get_top_groups(struct group2group_runtime *g2g_rt, int *group_ids, size_t n_group_ids,
|
||||
int group2group_runtime_get_top_groups(void *g2g_runtime, int *group_ids, size_t n_group_ids,
|
||||
int *top_group_ids);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
|
||||
@@ -22,18 +22,21 @@ void *ip_plus_schema_new(cJSON *json, const char *table_name, struct log_handle
|
||||
void ip_plus_schema_free(void *ip_plus_schema);
|
||||
|
||||
/* ip plus runtime API */
|
||||
void *ip_plus_runtime_new(void *ip_plus_schema, struct maat_garbage_bin *garbage_bin, struct log_handle *logger);
|
||||
void *ip_plus_runtime_new(void *ip_plus_schema, int max_thread_num, struct maat_garbage_bin *garbage_bin,
|
||||
struct log_handle *logger);
|
||||
void ip_plus_runtime_free(void *ip_plus_runtime);
|
||||
|
||||
int ip_plus_runtime_update(void *ip_plus_runtime, void *ip_plus_schema, const char *line);
|
||||
int ip_plus_runtime_updating_flag(void *ip_plus_runtime);
|
||||
int ip_plus_runtime_update(void *ip_plus_runtime, void *ip_plus_schema, const char *line,
|
||||
int valid_column);
|
||||
int ip_plus_runtime_commit(void *ip_plus_runtime);
|
||||
|
||||
struct ex_data_runtime *ip_plus_runtime_get_ex_data_rt(struct ip_plus_runtime *ip_plus_rt);
|
||||
|
||||
/* ip runtime scan API */
|
||||
int ip_runtime_scan_ip(struct ip_runtime *ip_rt, int thread_id, struct ip_addr *data,
|
||||
int *group_id_array, size_t n_group_id_array, int virtual_table_id,
|
||||
struct maat_state *state);
|
||||
int ip_plus_runtime_scan_ipv4(struct ip_plus_runtime *ip_plus_rt, int thread_id, uint32_t ip_addr,
|
||||
int *group_id_array, size_t n_group_id_array, int virtual_table_id,
|
||||
struct maat_state *state);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "log/log.h"
|
||||
#include "maat/maat.h"
|
||||
#include "cJSON/cJSON.h"
|
||||
|
||||
struct ip_plugin_runtime;
|
||||
|
||||
/* ip plugin schema API */
|
||||
@@ -29,15 +33,17 @@ int ip_plugin_table_set_ex_data_schema(void *ip_plugin_schema,
|
||||
maat_plugin_ex_new_func_t *new_func,
|
||||
maat_plugin_ex_free_func_t *free_func,
|
||||
maat_plugin_ex_dup_func_t *dup_func,
|
||||
long argl, void *argp);
|
||||
long argl, void *argp,
|
||||
struct log_handle *logger);
|
||||
|
||||
/* ip plugin runtime API */
|
||||
void *ip_plugin_runtime_new(void *ip_plugin_schema, struct maat_garbage_bin *garbage_bin,
|
||||
void *ip_plugin_runtime_new(void *ip_plugin_schema, int max_thread_num, struct maat_garbage_bin *garbage_bin,
|
||||
struct log_handle *logger);
|
||||
void ip_plugin_runtime_free(void *ip_plugin_runtime);
|
||||
|
||||
int ip_plugin_runtime_updating_flag(struct ip_plugin_runtime *ip_plugin_rt);
|
||||
int ip_plugin_runtime_update(void *ip_plugin_runtime, void *ip_plugin_schema, const char *line);
|
||||
int ip_plugin_runtime_updating_flag(void *ip_plugin_runtime);
|
||||
int ip_plugin_runtime_update(void *ip_plugin_runtime, void *ip_plugin_schema, const char *line,
|
||||
int valid_column);
|
||||
int ip_plugin_runtime_commit(void *ip_plugin_runtime);
|
||||
|
||||
struct ex_data_runtime *ip_plugin_runtime_get_ex_data_rt(void *ip_plugin_runtime);
|
||||
|
||||
@@ -16,6 +16,8 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "maat/maat.h"
|
||||
|
||||
#define MAX_FOREIGN_CLMN_NUM 8
|
||||
|
||||
/* plugin schema API */
|
||||
@@ -40,19 +42,23 @@ int plugin_table_set_ex_data_schema(void *custom_schema,
|
||||
maat_plugin_ex_new_func_t *new_func,
|
||||
maat_plugin_ex_free_func_t *free_func,
|
||||
maat_plugin_ex_dup_func_t *dup_func,
|
||||
long argl, void *argp);
|
||||
long argl, void *argp,
|
||||
struct log_handle *logger);
|
||||
struct ex_data_schema *plugin_table_get_ex_data_schema(void *custom_schema);
|
||||
|
||||
/* plugin runtime API */
|
||||
struct ex_data_runtime *plugin_runtime_get_ex_data_rt(void *plugin_runtime);
|
||||
void *plugin_runtime_new(void *plugin_schema, int max_thread_num, struct maat_garbage_bin *garbage_bin,
|
||||
struct log_handle *logger);
|
||||
void plugin_runtime_free(void *plugin_runtime);
|
||||
|
||||
int plugin_runtime_updating_flag(struct plugin_runtime *plugin_rt);
|
||||
int plugin_runtime_updating_flag(void *plugin_runtime);
|
||||
|
||||
int plugin_runtime_update(struct plugin_runtime *plugin_rt, struct plugin_item *plugin_item,
|
||||
struct plugin_schema *plugin_schema, const char *row,
|
||||
struct log_handle *logger);
|
||||
int plugin_runtime_update(void *plugin_runtime, void *plugin_schema, const char *line,
|
||||
int valid_column);
|
||||
int plugin_runtime_commit(void *plugin_runtime);
|
||||
|
||||
struct ex_data_runtime *plugin_runtime_get_ex_data_rt(void *plugin_runtime);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -80,7 +80,6 @@ struct compile_rule {
|
||||
int compile_id;
|
||||
struct maat_rule_head head;// fix len of Maat_rule_t
|
||||
char *service_defined;
|
||||
int is_valid;
|
||||
int declared_clause_num;
|
||||
double evaluation_order;
|
||||
struct compile_schema *ref_table;
|
||||
@@ -88,20 +87,9 @@ struct compile_rule {
|
||||
pthread_rwlock_t rwlock;
|
||||
};
|
||||
|
||||
struct group2compile_rule {
|
||||
int group_id;
|
||||
int compile_id;
|
||||
int is_valid;
|
||||
int not_flag;
|
||||
int vt_id; //virtual_table_id
|
||||
int clause_index;
|
||||
int associated_compile_table_id;
|
||||
};
|
||||
|
||||
struct group2group_rule {
|
||||
int group_id;
|
||||
int superior_group_id;
|
||||
int is_valid;
|
||||
};
|
||||
|
||||
struct maat_runtime {
|
||||
@@ -114,7 +102,6 @@ struct maat_runtime {
|
||||
struct table_manager *ref_tbl_mgr; //share with maat instance
|
||||
size_t max_table_num;
|
||||
|
||||
size_t max_thread_num;
|
||||
uint32_t rule_num;
|
||||
|
||||
struct maat_garbage_bin *ref_garbage_bin;
|
||||
@@ -254,9 +241,9 @@ struct maat_state {
|
||||
struct maat_compile_state *compile_mid;
|
||||
};
|
||||
|
||||
int parse_accept_tag(const char *value, struct rule_tag **result, void *logger);
|
||||
size_t parse_accept_tag(const char *value, struct rule_tag **result, struct log_handle *logger);
|
||||
|
||||
int compare_accept_tag(const char *value, const struct rule_tag *accept_tags, int n_tag);
|
||||
int compare_accept_tag(const char *value, const struct rule_tag *accept_tags, size_t n_accept_tag);
|
||||
|
||||
struct maat_item *maat_item_new(int item_id, int group_id, void *user_data);
|
||||
|
||||
@@ -264,7 +251,7 @@ void maat_item_free(struct maat_item *item, void (* item_user_data_free)(void *)
|
||||
|
||||
struct maat_item_inner *maat_item_inner_new(int group_id, int item_id, int district_id);
|
||||
|
||||
void maat_item_inner_free(struct maat_item_inner *item);
|
||||
void maat_item_inner_free(void *item_inner);
|
||||
|
||||
void maat_start_cb(long long new_version, int update_type, void *u_para);
|
||||
|
||||
@@ -297,7 +284,7 @@ int maat_cmd_write_rule(redisContext *c, struct serial_rule *s_rule, size_t seri
|
||||
void maat_cmd_clear_rule_cache(struct serial_rule *s_rule);
|
||||
|
||||
int maat_cmd_get_rm_key_list(redisContext *c, long long instance_version, long long desired_version,
|
||||
long long *new_version, struct table_schema_manager* table_schema_mgr,
|
||||
long long *new_version, struct table_manager* tbl_mgr,
|
||||
struct serial_rule **list, int *update_type, int cumulative_off,
|
||||
struct log_handle *logger);
|
||||
|
||||
|
||||
@@ -45,20 +45,23 @@ struct table_manager;
|
||||
|
||||
struct table_manager *table_manager_create(const char *table_info_path, const char *accept_tags,
|
||||
struct log_handle *logger);
|
||||
int table_manager_init(struct table_manager *tbl_mgr, struct maat_garbage_bin *garbage_bin);
|
||||
int table_manager_deinit(struct table_manager *tbl_mgr);
|
||||
int table_manager_runtime_create(struct table_manager *tbl_mgr, int max_thread_num,
|
||||
struct maat_garbage_bin *garbage_bin);
|
||||
void table_manager_runtime_destroy(struct table_manager *tbl_mgr);
|
||||
void table_manager_destroy(struct table_manager *tbl_mgr);
|
||||
|
||||
size_t table_manager_table_count(struct table_manager *tbl_mgr);
|
||||
int table_manager_get_table_id(struct table_manager *tbl_mgr, const char *name);
|
||||
enum table_type table_manager_get_table_type(struct table_manager *tbl_mgr, int table_id);
|
||||
int table_manager_get_defaut_compile_table_id(struct table_manager *tbl_mgr);
|
||||
int table_manager_get_valid_column(struct table_manager *tbl_mgr, int table_id);
|
||||
int table_manager_accept_tags_match(const char *tags);
|
||||
int table_manager_accept_tags_match(struct table_manager *tbl_mgr, const char *tags);
|
||||
|
||||
void *table_manager_get_schema(struct table_manager *tbl_mgr, int table_id);
|
||||
|
||||
void *table_manager_get_runtime(struct table_manager *tbl_mgr, int table_id);
|
||||
void table_manager_update_runtime(struct table_manager *tbl_mgr, int table_id, const char *line);
|
||||
int table_manager_runtime_updating_flag(struct table_manager *tbl_mgr, int table_id);
|
||||
int table_manager_update_runtime(struct table_manager *tbl_mgr, int table_id, const char *line);
|
||||
void table_manager_commit_runtime(struct table_manager *tbl_mgr, int table_id);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
|
||||
@@ -31,6 +31,8 @@ enum scan_type {
|
||||
|
||||
void *virtual_schema_new(cJSON *json, const char *table_name, struct log_handle *logger);
|
||||
|
||||
void virtual_schema_free(void *virtual_schema);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user