From 895344d7d2f616b8c18dfc34138abe2c02692756 Mon Sep 17 00:00:00 2001 From: zhengchao Date: Tue, 4 Dec 2018 13:38:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84table=5Finfo=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=93=E6=9E=84=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/Maat_rule.h | 15 ++++ src/entry/Maat_api.cpp | 13 +++- src/entry/Maat_rule.cpp | 6 +- src/inc_internal/Maat_rule_internal.h | 102 +++++++++++++++++++++----- 4 files changed, 112 insertions(+), 24 deletions(-) diff --git a/inc/Maat_rule.h b/inc/Maat_rule.h index bea7e76..2e956a5 100644 --- a/inc/Maat_rule.h +++ b/inc/Maat_rule.h @@ -257,6 +257,21 @@ int Maat_rule_get_ex_new_index(Maat_feather_t feather, const char* compile_table //returned data is duplicated by dup_func of Maat_rule_get_ex_new_index, caller is responsible to free the data. MAAT_RULE_EX_DATA Maat_rule_get_ex_data(Maat_feather_t feather, const struct Maat_rule_t* rule, int idx); +//Following functions are similar to Maat_rule_get_ex_data, except they are effective on plugin table. +typedef void* MAAT_PLUGIN_EX_DATA; +typedef void Maat_plugin_EX_new_func_t(int table_id, const char* key, const char* table_line, MAAT_PLUGIN_EX_DATA* ad, long argl, void *argp); +typedef void Maat_plugin_EX_free_func_t(int table_id, const char* key, const char* table_line, MAAT_PLUGIN_EX_DATA* ad, long argl, void *argp); +typedef void Maat_plugin_EX_dup_func_t(int table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DATA *from, long argl, void *argp); +typedef int Maat_plugin_EX_key2index_func_t(const char* key); + +int Maat_plugin_EX_register(Maat_feather_t feather, int table_id, + Maat_plugin_EX_new_func_t* new_func, + Maat_plugin_EX_free_func_t* free_func, + Maat_plugin_EX_dup_func_t* dup_func, + Maat_plugin_EX_key2index_func_t* key2index_func, + long argl, void *argp); +//Data is duplicated by dup_func of Maat_plugin_EX_register, caller is responsible to free the data. +MAAT_PLUGIN_EX_DATA Maat_plugin_get_EX_data(Maat_feather_t feather, int table_id, const char* key, int thread_num); enum MAAT_RULE_OPT { diff --git a/src/entry/Maat_api.cpp b/src/entry/Maat_api.cpp index b353063..e42c2e6 100644 --- a/src/entry/Maat_api.cpp +++ b/src/entry/Maat_api.cpp @@ -113,7 +113,7 @@ int region_compile(_Maat_feather_t*feather,struct _INNER_scan_status_t *_mid,int int ret=0,i=0; int r_in_c_cnt=0; int shortcut_avilable_cnt=0; - void* bool_matcher=feather->scanner->expr_compiler; + void* bool_matcher=feather->scanner->bool_macher_expr_compiler; struct _Maat_group_inner_t* group_rule=NULL; struct _Maat_compile_inner_t* array_mi_rule[MAX_SCANNER_HIT_NUM]; struct _Maat_compile_inner_t* _mi_rule=NULL; @@ -1046,6 +1046,17 @@ MAAT_RULE_EX_DATA Maat_rule_get_ex_data(Maat_feather_t feather, const struct Maa pthread_rwlock_unlock(&(compile_inner->rwlock)); return ad; } +int Maat_plugin_EX_register(Maat_feather_t feather, int table_id, + Maat_plugin_EX_new_func_t* new_func, + Maat_plugin_EX_free_func_t* free_func, + Maat_plugin_EX_dup_func_t* dup_func, + Maat_plugin_EX_key2index_func_t* key2index_func, + long argl, void *argp) + +{ + +} + int Maat_full_scan_string_detail(Maat_feather_t feather,int table_id ,enum MAAT_CHARSET charset,const char* data,int data_len ,struct Maat_rule_t*result,int rule_num,struct Maat_hit_detail_t *hit_detail,int detail_num diff --git a/src/entry/Maat_rule.cpp b/src/entry/Maat_rule.cpp index 26e1171..f06d60a 100644 --- a/src/entry/Maat_rule.cpp +++ b/src/entry/Maat_rule.cpp @@ -1306,7 +1306,7 @@ void destroy_maat_scanner(struct _Maat_scanner_t*scanner) map_destroy(scanner->district_map); scanner->district_map=NULL; assert(scanner->tmp_district_map==NULL); - destroy_bool_matcher((void*)scanner->expr_compiler); + destroy_bool_matcher((void*)scanner->bool_macher_expr_compiler); q_cnt=MESA_lqueue_get_count(scanner->region_update_q); for(i=0;icompile_hash, scan_thread_num, logger); - tmp2=scanner->expr_compiler; + tmp2=scanner->bool_macher_expr_compiler; //assume pinter = operation is thread safe - scanner->expr_compiler=tmp1; + scanner->bool_macher_expr_compiler=tmp1; if(tmp2!=NULL) { garbage_bagging(GARBAGE_BOOL_MATCHER, tmp2, garbage_q); diff --git a/src/inc_internal/Maat_rule_internal.h b/src/inc_internal/Maat_rule_internal.h index 475eb7d..42cdb28 100644 --- a/src/inc_internal/Maat_rule_internal.h +++ b/src/inc_internal/Maat_rule_internal.h @@ -101,6 +101,69 @@ struct compile_ex_data_idx int idx; int table_id; }; +struct compile_table_descr +{ + enum USER_REGION_ENCODE user_region_encoding; + int ex_data_num; + struct compile_ex_data_idx ex_desc[MAX_COMPILE_EX_DATA_NUM]; +}; + +struct plugin_table_callback_desc +{ + Maat_start_callback_t *start; + Maat_update_callback_t *update; + Maat_finish_callback_t *finish; + void* u_para; +}; +struct plugin_table_ex_data_desc +{ + Maat_plugin_EX_new_func_t* new_func; + Maat_plugin_EX_free_func_t* free_func; + Maat_plugin_EX_dup_func_t* dup_func; + Maat_plugin_EX_key2index_func_t* key2index_func; + long argl; + void *argp; +}; +struct _plugin_table_info +{ + int cb_plug_cnt; + struct plugin_table_callback_desc cb_plug[MAX_PLUGIN_PER_TABLE]; + dynamic_array_t *cache_lines; + int cache_line_num; + int acc_line_num; + int update_type; + long cache_size; +}; + +struct plugin_table_descr +{ + int key_column; + int valid_flag_column; + int rule_tag_column; + int n_foreign; + int foreign_columns[MAX_FOREIGN_CLMN_NUM]; + int cb_plug_cnt; + struct plugin_table_callback_desc cb_plug[MAX_PLUGIN_PER_TABLE]; + struct plugin_table_ex_data_desc ex_desc; + int acc_line_num; +}; +struct expr_table_descr +{ + enum MAAT_CHARSET src_charset; + enum MAAT_CHARSET dst_charset[MAX_CHARSET_NUM]; + int src_charset_in_dst; + int do_charset_merge; + int cross_cache_size; + int quick_expr_switch; + int expr_rule_cnt; //expr_type=0,1,3 + int regex_rule_cnt; //expr_type=2 +}; +struct ip_table_descr +{ + int ipv4_rule_cnt; + int ipv6_rule_cnt; +}; + struct _Maat_table_info_t { unsigned short table_id; @@ -108,6 +171,14 @@ struct _Maat_table_info_t unsigned short updating_name; char table_name[MAX_CONJUNCTION_TABLE_NUM][MAX_TABLE_NAME_LEN]; enum MAAT_TABLE_TYPE table_type; + union + { + struct compile_table_descr compile; + struct expr_table_descr expr; + struct ip_table_descr ip; + struct plugin_table_descr plugin; + void* others;//group, interval and digest don't have sperate description info. + }; enum MAAT_CHARSET src_charset; enum MAAT_CHARSET dst_charset[MAX_CHARSET_NUM]; int src_charset_in_dst; @@ -263,24 +334,7 @@ struct _compile_result_t int compile_id; universal_bool_expr_t group_set; }; -struct _callback_plugin -{ - Maat_start_callback_t *start; - Maat_update_callback_t *update; - Maat_finish_callback_t *finish; - void* u_para; -}; -struct _plugin_table_info -{ - int cb_plug_cnt; - struct _callback_plugin cb_plug[MAX_PLUGIN_PER_TABLE]; - dynamic_array_t *cache_lines; - int cache_line_num; - int acc_line_num; - int update_type; - long cache_size; -}; struct _region_stat_t { int cfg_num; @@ -349,12 +403,19 @@ struct _stream_para_t pthread_mutex_t fuzzy_mutex; unsigned char query_point[8]; }; -struct GIE_aux_t +struct digest_engine { enum MAAT_TABLE_TYPE table_type; GIE_handle_t* gie_handle; MESA_lqueue_head update_q; }; +struct plugin_engine +{ + dynamic_array_t *cache_lines; + int cache_line_num; + long cache_size; +}; + struct rule_tag { char* tag_name; @@ -367,7 +428,8 @@ struct _Maat_scanner_t long long *ref_cnt; //optimized for cache_alignment 64 rule_scanner_t region; long gie_total_q_size; - struct GIE_aux_t gie_aux[MAX_TABLE_NUM]; + struct digest_engine gie_aux[MAX_TABLE_NUM]; + struct plugin_engine plugin_aux[MAX_TABLE_NUM]; MESA_htable_handle region_hash; MESA_htable_handle group_hash; MESA_htable_handle compile_hash; @@ -378,7 +440,7 @@ struct _Maat_scanner_t unsigned int exprid_generator; unsigned int dedup_expr_num; MESA_lqueue_head region_update_q; - void * expr_compiler; + void * bool_macher_expr_compiler; scan_result_t *region_rslt_buff; MESA_lqueue_head tomb_ref;//reference of g_feather->garbage_q struct _region_stat_t region_counter[MAX_TABLE_NUM];