From 22cc098e1add9fd0de70c20499b5e29c00dda826 Mon Sep 17 00:00:00 2001 From: jixinyi Date: Thu, 29 Nov 2018 17:44:31 +0800 Subject: IPReuse/mctrl --- src/ir_mctrl.cpp | 590 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 590 insertions(+) create mode 100644 src/ir_mctrl.cpp (limited to 'src/ir_mctrl.cpp') diff --git a/src/ir_mctrl.cpp b/src/ir_mctrl.cpp new file mode 100644 index 0000000..a23cdd8 --- /dev/null +++ b/src/ir_mctrl.cpp @@ -0,0 +1,590 @@ +#include +#include +#include +#include +#include +#include "MESA_prof_load.h" +#include "MESA_handle_logger.h" +#include "Maat_rule.h" +#include "Maat_command.h" +#include "ir_mctrl.h" +#include "MESA_htable.h" + +void *logger_handle; +Maat_feather_t mctrl_d_feather; +Maat_feather_t mctrl_s_feather; +MESA_htable_handle s_and_d_nominee_htable; + + +void Maat_start_cb(int update_type,void* u_para) +{ + if(update_type==MAAT_RULE_UPDATE_TYPE_FULL) + { + MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is full",u_para); + } + else + { + MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is inc",u_para); + } + return; +} + +void get_cur_time(char *date) +{ + time_t t; + struct tm *lt; + time(&t); + lt = localtime(&t); + snprintf(date, MAX_TIME_LEN,"%d/%d/%d/%d:%d:%d",lt->tm_year+1900, lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec); +} + + +int set_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *table_line,int rule_id) +{ + const struct Maat_line_t *p_line; + struct Maat_line_t line_rule; + int ret = 0; + char m_table_line[HTABLE_DATA_LEN]; + struct IR_MCTRL_INFO nom_info; + memset(&line_rule, 0,sizeof(line_rule)); + + line_rule.label_id=0; + line_rule.rule_id=rule_id; + line_rule.table_name=ir_table_name; + + sscanf(table_line, "%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s", + &nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, + nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, + nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.is_valid, + &nom_info.action,&nom_info.service,&nom_info.addr_pool_id,nom_info.op_time); + + get_cur_time(nom_info.op_time); + + if(memcmp(ir_table_name,INTERCEPT_IP,strlen(INTERCEPT_IP))) + { + snprintf(m_table_line,sizeof(m_table_line),"%d\t%d\t%d\t%s\t%d\t%s", + rule_id,nom_info.addr_pool_id,nom_info.addr_type,nom_info.src_ip,nom_info.is_valid,nom_info.op_time); + } + else + { + snprintf(m_table_line,sizeof(m_table_line),"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%s", + rule_id,nom_info.group_id,nom_info.addr_type, + nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, + nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction, + nom_info.is_valid,nom_info.action,nom_info.service,nom_info.op_time); + } + + line_rule.table_line=m_table_line; + line_rule.expire_after=0; + p_line=&line_rule; + + ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_ADD); + + MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"maat_update", "set_table_line:%s",m_table_line); + + if(ret==-1) + { + MESA_handle_runtime_log(logger_handle, RLOG_LV_INFO, (char*)"SET_LINE","%s:set redis line error",ir_table_name); + } + else + { + MESA_handle_runtime_log(logger_handle, RLOG_LV_INFO, (char*)"SET_LINE","%s:set redis line success",ir_table_name); + } + return ret; +} + + +int del_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *table_line,int rule_id) +{ + int ret=0; + + const struct Maat_line_t *p_line; + struct Maat_line_t line_rule; + memset(&line_rule,0,sizeof(line_rule)); + + line_rule.label_id=0; + line_rule.rule_id=rule_id; + line_rule.table_name=ir_table_name; + if(!memcmp(ir_table_name,INTERCEPT_IP,strlen(INTERCEPT_IP))) + { + line_rule.table_line=table_line; + line_rule.expire_after=TIME_OUT; + p_line=&line_rule; + ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_RENEW_TIMEOUT); + } + else + { + line_rule.table_line=NULL; + line_rule.expire_after=0; + p_line=&line_rule; + ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_DEL); + } + + MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"maat_update", "del_table_line:%s",table_line); + + + if(ret==-1) + { + MESA_handle_runtime_log(logger_handle, RLOG_LV_INFO, (char*)"DEL_LINE","%s:del redis line error",ir_table_name); + } + else if(ret==1) + { + MESA_handle_runtime_log(logger_handle, RLOG_LV_INFO, (char*)"DEL_LINE","%s:del redis line success",ir_table_name); + } + else + { + MESA_handle_runtime_log(logger_handle, RLOG_LV_INFO, (char*)"DEL_LINE","%s:del redis line not sure",ir_table_name); + } + return ret; + +} + + +long htable_write_search(void *data, const uchar *key, uint size, void *user_arg) +{ + int htable_flag=0; + char *htable_data=(char*)data; + if(htable_data!=NULL) + { + sscanf(htable_data,"%d\t",&htable_flag); + MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"htable_write_search","get htable flag:%d!",htable_flag); + } + return htable_flag; +} + +long htable_read_search(void *data, const uchar *key, uint size, void *user_arg) +{ + int htable_flag=0; + struct IR_MCTRL_INFO nom_info; + char *htable_data=(char*)data; + + if(htable_data!=NULL) + { + sscanf((char*)data, "%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s", + &htable_flag,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, + nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, + nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.is_valid, + &nom_info.action,&nom_info.service,&nom_info.addr_pool_id,nom_info.op_time); + + if(!memcmp(user_arg,INTERCEPT_IP,strlen(INTERCEPT_IP))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_C_FLAG|| + htable_flag==O_AND_N_FLAG||htable_flag==O_AND_C_AND_N_FLAG)) + { + htable_flag+=INTERCEPT_FLAG; + } + else if(!memcmp(user_arg,NOMINEE_IP,strlen(NOMINEE_IP))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_C_FLAG|| + htable_flag==O_AND_I_FLAG||htable_flag==O_AND_C_AND_I_FLAG)) + { + htable_flag+=NOMINEE_FLAG; + } + else if(!memcmp(user_arg,CANDIDATE_IP,strlen(CANDIDATE_IP))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_N_FLAG|| + htable_flag==O_AND_I_FLAG||htable_flag==O_AND_I_AND_N_FLAG)) + { + htable_flag+=CANDIDATE_FLAG; + } + else + { + MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"htable_read_search","htable flag is:%d",htable_flag); + } + + snprintf(htable_data,sizeof(HTABLE_DATA_LEN), "%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s", + htable_flag,nom_info.region_id,nom_info.group_id,nom_info.addr_type, + nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, + nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.is_valid, + nom_info.action,nom_info.service,nom_info.addr_pool_id,nom_info.op_time); + + MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"htable_read_search","htable flag change:%d",htable_flag); + } + + return htable_flag; +} + + +void read_table_update_cb(int table_id,const char* table_line,void* u_para) +{ + int rule_id=0; + void *htable_data=NULL; + int is_valid=-1; + long search_ret=0; + + if(!memcmp(u_para,INTERCEPT_IP,strlen(INTERCEPT_IP))) + { + sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*d\t%*d\t%d\t%*d\t%*d\t%*s",&rule_id,&is_valid); + } + else if(!memcmp(u_para,NOMINEE_IP,strlen(NOMINEE_IP))) + { + sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%d\t%*s",&rule_id,&is_valid); + } + else + { + sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%*d\t%*s\t%*d\t%*d\t%*d\t%*d\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%d",&rule_id,&is_valid); + } + + unsigned char *key_id=(unsigned char*)&rule_id; + + if(is_valid==0) + { + MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"READ_TABLE_UPDATA","table_name:%s del redis is_valid==0",u_para); + return; + } + + htable_data=MESA_htable_search_cb(s_and_d_nominee_htable,key_id,sizeof(rule_id), htable_read_search,u_para,&search_ret); + + if(htable_data==NULL) + { + del_ir_line(mctrl_d_feather,(char*)u_para,table_line,rule_id); + } + else + { + MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"READ_TABLE_UPDATA","already exist!"); + } + return; +} + +void htable_data_free(void *data) +{ + if(data!=NULL) + { + MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"DATA_FREE","htable_data_free!"); + free(data); + data=NULL; + } + return; +} + +void write_table_update_cb(int table_id,const char* table_line,void* u_para) +{ + int add_ret=0; + struct IR_MCTRL_INFO nom_info; + nom_info.htable_flag=S_OR_D_ORIGIN_FLAG; + int rule_id=0; + int del_ret=0; + long cb_ret=0; + + if(!memcmp(u_para,DYNAMIC_NOMINEE_IP,strlen(DYNAMIC_NOMINEE_IP))) + { + sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%d\t%*s\t%*d\t%d\t%s", + &nom_info.region_id,&nom_info.addr_type,&nom_info.procotol,nom_info.src_ip,nom_info.src_port, + &nom_info.direction,&nom_info.is_valid,nom_info.op_time); + nom_info.region_id+=1000000000; + nom_info.addr_pool_id=0; + nom_info.group_id=nom_info.region_id; + memcpy(nom_info.mask_src_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(nom_info.mask_src_port,"0",sizeof("0")); + memcpy(nom_info.dst_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(nom_info.mask_dst_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(nom_info.dst_port,"0",sizeof("0")); + memcpy(nom_info.mask_dst_port,"0",sizeof("0")); + nom_info.action=0x60; + nom_info.service=19; + } + else + { + sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s", + &nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, + nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, + nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.is_valid, + &nom_info.action,&nom_info.service,&nom_info.addr_pool_id,nom_info.op_time); + } + + unsigned char *key_id=(unsigned char*)&nom_info.region_id; + rule_id=nom_info.region_id; + + if(nom_info.is_valid==1) + { + char *htable_data=(char*)malloc(HTABLE_DATA_LEN); + snprintf(htable_data,HTABLE_DATA_LEN,"%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s", + nom_info.htable_flag,nom_info.region_id,nom_info.group_id,nom_info.addr_type, + nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, + nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.is_valid, + nom_info.action,nom_info.service,nom_info.addr_pool_id,nom_info.op_time); + + add_ret=MESA_htable_add(s_and_d_nominee_htable,key_id,sizeof(int),htable_data); + + if(add_ret<0) + { + MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"ADD_S_AND_D_NOMINEE_HASH","add htable error:%d",add_ret); + } + else + { + MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"ADD_S_AND_D_NOMINEE_HASH","add htable succeed:%d",add_ret); + } + + } + else + { + assert(nom_info.is_valid<=1); + } + + MESA_htable_search_cb(s_and_d_nominee_htable,key_id,sizeof(rule_id),htable_write_search,NULL,&cb_ret); + + switch(nom_info.is_valid) + { + case 0: + del_ir_line(mctrl_d_feather,(char*)CANDIDATE_IP,table_line,rule_id); + del_ir_line(mctrl_d_feather,(char*)INTERCEPT_IP,table_line,rule_id); + del_ir_line(mctrl_d_feather,(char*)NOMINEE_IP,table_line,rule_id); + del_ret=MESA_htable_del(s_and_d_nominee_htable,key_id,sizeof(rule_id),htable_data_free); + + if(del_ret<0) + { + MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"DEL_S_AND_D_NOMINEE","del htable error:%d",del_ret); + } + break; + + case 1: + if(cb_ret==S_OR_D_ORIGIN_FLAG||cb_ret==O_AND_C_FLAG) + { + set_ir_line(mctrl_d_feather, (char*)INTERCEPT_IP,table_line,rule_id); + set_ir_line(mctrl_d_feather,(char*)NOMINEE_IP,table_line,rule_id); + } + else if(cb_ret==O_AND_N_FLAG||cb_ret==O_AND_C_AND_N_FLAG) + { + set_ir_line(mctrl_d_feather, (char*)INTERCEPT_IP,table_line,rule_id); + } + else if(cb_ret==O_AND_I_FLAG||cb_ret==O_AND_C_AND_I_FLAG) + { + set_ir_line(mctrl_d_feather,(char*)NOMINEE_IP,table_line,rule_id); + } + else + { + MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"write_update", "exist already !! htable_flag is:%d",cb_ret); + assert(cb_ret<=ALL_EXIST_FLAG); + } + break; + + default: + MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"write_update", "is_valid default !!!"); + assert(0); + break; + } + + return; +} + +void Maat_finish_cb(void* u_para) +{ + MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,finish succeed",u_para); + return; +} + + +int read_plugin_table(Maat_feather_t feather,const char* table_name, + Maat_start_callback_t *start,Maat_update_callback_t *update,Maat_finish_callback_t *finish, + void *u_para,void* logger,int table_id) +{ + int ret=0; + + ret=Maat_table_callback_register(feather, table_id, + start, + update, + finish, + u_para); + if(ret<0) + { + MESA_handle_runtime_log(logger_handle,RLOG_LV_FATAL, (char*)"REGISTER_TABLE", "Maat callback register table %s error.\n",table_name); + assert(0); + } + + return ret; +} + +void htable_iterate(const uchar * key, uint size, void * data, void * user) +{ + int htable_flag=0; + int rule_id=0; + char table_line[HTABLE_DATA_LEN]; + struct IR_MCTRL_INFO nom_info; + + sscanf((char*)data,"%d\t%d",&htable_flag,&rule_id); + + if(htable_flag=14: %d!",htable_flag); + assert(htable_flag>=S_OR_D_ORIGIN_FLAG); + } + } + else + { + MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"htable_iterate", "already exist,htable flag is:%d!",htable_flag); + assert(htable_flag<=ALL_EXIST_FLAG); + } + + return; +} + +void Maat_init() +{ +// load conf + const char *section_d = "Mctrl"; + const char *section_s = "Mctrl_S"; + char table_info_path[MAX_PATH_LEN]; + char logger_path[MAX_PATH_LEN]; + int max_thread_num=0; + char Maat_redis_ip[MAX_IP4_LEN]; + int Maat_redis_port=0; + char Maat_redis_ip_s[MAX_IP4_LEN]; + int Maat_redis_port_s=0; + char stat_file_path[MAX_PATH_LEN]; + int logger_level=0; + +//dynamic server conf + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_d, "table_info_path", table_info_path, sizeof(table_info_path), "./conf/table_info.conf"); + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_d, "logger_path", logger_path, sizeof(logger_path), "./log/ir.log"); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d, "max_thread_num", &max_thread_num, 1); + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_d, "Maat_redis_ip", Maat_redis_ip, sizeof(Maat_redis_ip), "127.0.0.1"); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d, "Maat_redis_port", &Maat_redis_port,6379); + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_d, "stat_file_path", stat_file_path, sizeof(stat_file_path), "./log/Maat_stat.log"); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d, "logger_level", &logger_level,RLOG_LV_DEBUG); +//static server conf + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_s, "Maat_redis_ip", Maat_redis_ip_s, sizeof(Maat_redis_ip), "127.0.0.1"); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_s, "Maat_redis_port", &Maat_redis_port_s,6379); + + +//log + logger_handle=MESA_create_runtime_log_handle(logger_path,logger_level); + if(logger_handle == NULL) + { + printf("IR MESA_create_runtime_log_handle() error!\n"); + assert(0); + } + +//redis + mctrl_d_feather = Maat_feather(max_thread_num, table_info_path,logger_handle); + mctrl_s_feather = Maat_feather(max_thread_num, table_info_path,logger_handle); + if(mctrl_d_feather==NULL||mctrl_s_feather==NULL) + { + MESA_handle_runtime_log(logger_handle,RLOG_LV_FATAL,(char*)"MAAT","IR maat_feather error!"); + assert(0); + } + + Maat_set_feather_opt(mctrl_d_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip,MAX_IP4_LEN); + Maat_set_feather_opt(mctrl_d_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port,sizeof(Maat_redis_port)); + Maat_set_feather_opt(mctrl_s_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_s,MAX_IP4_LEN); + Maat_set_feather_opt(mctrl_s_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_s,sizeof(Maat_redis_port)); + +} + + +int htable_init() +{ + int htable_ret; + s_and_d_nominee_htable = MESA_htable_born(); + if(s_and_d_nominee_htable == NULL) + { + MESA_handle_runtime_log(logger_handle,RLOG_LV_FATAL,(char*)"htable","htable born failed"); + assert(0); + return -1; + } + + htable_ret = MESA_htable_mature(s_and_d_nominee_htable); + + if(0 == htable_ret) + { + MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO,(char*)"htable","htable mature succ"); + return 0; + } + else + { + MESA_handle_runtime_log(logger_handle,RLOG_LV_FATAL,(char*)"htable","htable mature failed"); + assert(0); + return -1; + } +} + +int main(int argc, char * argv [ ]) +{ + + Maat_init(); + + Maat_set_feather_opt(mctrl_d_feather, MAAT_OPT_INSTANCE_NAME, DYNAMIC_NOMINEE_IP, strlen(DYNAMIC_NOMINEE_IP)+1); + Maat_set_feather_opt(mctrl_d_feather, MAAT_OPT_INSTANCE_NAME, INTERCEPT_IP, strlen(INTERCEPT_IP)+1); + Maat_set_feather_opt(mctrl_d_feather, MAAT_OPT_INSTANCE_NAME, NOMINEE_IP, strlen(NOMINEE_IP)+1); + Maat_set_feather_opt(mctrl_d_feather, MAAT_OPT_INSTANCE_NAME, CANDIDATE_IP, strlen(CANDIDATE_IP)+1); + + Maat_set_feather_opt(mctrl_s_feather, MAAT_OPT_INSTANCE_NAME, STATIC_NOMINEE_IP, strlen(STATIC_NOMINEE_IP)+1); + + Maat_initiate_feather(mctrl_d_feather); + Maat_initiate_feather(mctrl_s_feather); + + htable_init(); + + char static_nominee[]=STATIC_NOMINEE_IP; + char dynamic_nominee[]=DYNAMIC_NOMINEE_IP; + char nominee[]=NOMINEE_IP; + char candidate[]=CANDIDATE_IP; + char intercept[]=INTERCEPT_IP; + + int static_id=-1; + int dynamic_id=-1; + int nominee_id=-1; + int candidate_id=-1; + int intercept_id=-1; + + static_id=Maat_table_register(mctrl_s_feather,static_nominee); + dynamic_id=Maat_table_register(mctrl_d_feather,dynamic_nominee); + nominee_id=Maat_table_register(mctrl_d_feather,nominee); + candidate_id=Maat_table_register(mctrl_d_feather,candidate); + intercept_id=Maat_table_register(mctrl_d_feather, intercept); + + if(static_id==-1||dynamic_id==-1||nominee_id==-1||candidate_id==-1||intercept_id==-1) + { + MESA_handle_runtime_log(logger_handle,RLOG_LV_FATAL,(char*)"REGISTER_TABLE","Database table register failed\n"); + } + + read_plugin_table(mctrl_s_feather,STATIC_NOMINEE_IP,Maat_start_cb,write_table_update_cb,Maat_finish_cb, + static_nominee,logger_handle,static_id); + read_plugin_table(mctrl_d_feather,DYNAMIC_NOMINEE_IP,Maat_start_cb,write_table_update_cb,Maat_finish_cb, + dynamic_nominee,logger_handle,dynamic_id); + + read_plugin_table(mctrl_d_feather,INTERCEPT_IP,Maat_start_cb,read_table_update_cb,Maat_finish_cb, + intercept,logger_handle,intercept_id); + read_plugin_table(mctrl_d_feather,NOMINEE_IP,Maat_start_cb,read_table_update_cb,Maat_finish_cb, + nominee,logger_handle,nominee_id); + read_plugin_table(mctrl_d_feather,CANDIDATE_IP,Maat_start_cb,read_table_update_cb,Maat_finish_cb, + candidate,logger_handle,candidate_id); + + + while(1) + { + MESA_htable_iterate(s_and_d_nominee_htable, htable_iterate, NULL); + sleep(3600); + } + + Maat_burn_feather(mctrl_d_feather); + Maat_burn_feather(mctrl_s_feather); + MESA_destroy_runtime_log_handle(logger_handle); + MESA_htable_destroy(s_and_d_nominee_htable,htable_data_free); + return 0; + +} + + -- cgit v1.2.3 From 067beb9caaa641fdee10b0bb9d27b9affcb9f530 Mon Sep 17 00:00:00 2001 From: jixinyi Date: Tue, 4 Dec 2018 10:31:57 +0800 Subject: 2018.12.03 --- conf/redis.conf | 25 ++++- conf/table_info.conf | 27 ++++- include/ir_mctrl.h | 22 ++-- src/ir_mctrl.cpp | 279 +++++++++++++++++++++++++++++---------------------- 4 files changed, 214 insertions(+), 139 deletions(-) (limited to 'src/ir_mctrl.cpp') diff --git a/conf/redis.conf b/conf/redis.conf index 9a7d540..5dc1221 100644 --- a/conf/redis.conf +++ b/conf/redis.conf @@ -1,8 +1,23 @@ -[Mctrl] +[Mctrl_D] table_info_path=./conf/table_info.conf -Maat_redis_ip=192.168.10.180 -Maat_redis_port=26379 +Maat_redis_ip=192.168.11.243 +Maat_redis_port=6800 +Maat_redis_index=1 +logger_level=10 +stat_file_path=./log/Maat_stat.log +logger_path=./log/ir_mctrl.log [Mctrl_S] -Maat_redis_ip=127.0.0.1 -Maat_redis_port=6379 \ No newline at end of file +Maat_redis_ip=192.168.11.243 +Maat_redis_port=6379 +Maat_redis_index=6 + +[Mctrl_I] +Maat_redis_ip=192.168.11.243 +Maat_redis_port=6800 +Maat_redis_index=1 + +[Mctrl_N] +Maat_redis_ip=192.168.11.243 +Maat_redis_port=6800 +Maat_redis_index=5 \ No newline at end of file diff --git a/conf/table_info.conf b/conf/table_info.conf index e2ffe36..03e0579 100644 --- a/conf/table_info.conf +++ b/conf/table_info.conf @@ -1,5 +1,22 @@ -1 IR_NOMINEE_IP plugin {"valid":5} -2 IR_INTERCEPT_IP plugin {"valid":14} -3 IR_STATIC_NOMINEE_IP plugin {"valid":14} -4 IR_DYNAMIC_NOMINEE_IP plugin {"valid":14} -5 IR_CANDIDATE_IP plugin {"valid":19} \ No newline at end of file +#each collumn seperate with '\t' +#id (0~65535) +#name string +#type one of ip,expr,expr_plus,digest,intval,compile or plugin +#src_charset one of GBK,BIG5,UNICODE,UTF8 +#dst_charset combined by GBK,BIG5,UNICODE,UTF8,seperate with '/' +#do_merege [yes/no] +#cross cache [number] +#quick mode [quickon/quickoff], default [quickoff] +#For ip/intval/digest/compile/group +#id name type +# +#For plugin table +#id name type valid_column +# +#For expr/expr_plus Table +#id name type src_charset dst_charset do_merge cross_cache quick_mode +0 IR_STATIC_NOMINEE_IP plugin 15 -- +1 IR_DYNAMIC_NOMINEE_IP plugin 9 -- +2 IR_NOMINEE_IP plugin 5 -- +3 IR_CANDIDATE_IP plugin 19 -- +4 IR_INTERCEPT_IP plugin 14 -- diff --git a/include/ir_mctrl.h b/include/ir_mctrl.h index 97822e6..1fceab6 100644 --- a/include/ir_mctrl.h +++ b/include/ir_mctrl.h @@ -1,26 +1,24 @@ #ifndef IR_MCTRL_H #define IR_MCTRL_H -#define MAX_IP4_LEN 64 -#define MAX_THREAD_NUM 1 +#define MAX_STRING_LEN 64 #define MAX_PORT_LEN 6 #define MAX_PATH_LEN 64 #define MAX_TABLE_NAME_LEN 64 -#define MAX_TIME_LEN 50 -#define HTABLE_DATA_LEN 400 +#define MAX_TIME_LEN 50 +#define HTABLE_DATA_LEN 512 #define MCTRL_CONF_FILE "./conf/redis.conf" //table name -#define NOMINEE_IP "IR_MCTRL_INFO" +#define NOMINEE_IP "IR_NOMINEE_IP" #define INTERCEPT_IP "IR_INTERCEPT_IP" #define STATIC_NOMINEE_IP "IR_STATIC_NOMINEE_IP" #define DYNAMIC_NOMINEE_IP "IR_DYNAMIC_NOMINEE_IP" #define CANDIDATE_IP "IR_CANDIDATE_IP" - -unsigned int set_line_num=1; #define TIME_OUT 30 +#define MAX_THREAD_NUM 1 //htable flag @@ -42,12 +40,12 @@ struct IR_MCTRL_INFO int region_id; int group_id; int addr_type; - char src_ip[MAX_IP4_LEN]; - char mask_src_ip[MAX_IP4_LEN]; + char src_ip[MAX_STRING_LEN]; + char mask_src_ip[MAX_STRING_LEN]; char src_port[MAX_PORT_LEN]; char mask_src_port[MAX_PORT_LEN]; - char dst_ip[MAX_IP4_LEN]; - char mask_dst_ip[MAX_IP4_LEN]; + char dst_ip[MAX_STRING_LEN]; + char mask_dst_ip[MAX_STRING_LEN]; char dst_port[MAX_PORT_LEN]; char mask_dst_port[MAX_PORT_LEN]; int procotol; @@ -56,6 +54,8 @@ struct IR_MCTRL_INFO int action; int service; int addr_pool_id; + char effective_range[MAX_STRING_LEN]; + char user_region[MAX_STRING_LEN]; char op_time[MAX_TIME_LEN]; int htable_flag; diff --git a/src/ir_mctrl.cpp b/src/ir_mctrl.cpp index a23cdd8..f861755 100644 --- a/src/ir_mctrl.cpp +++ b/src/ir_mctrl.cpp @@ -13,6 +13,8 @@ void *logger_handle; Maat_feather_t mctrl_d_feather; Maat_feather_t mctrl_s_feather; +Maat_feather_t mctrl_n_feather; +Maat_feather_t mctrl_i_feather; MESA_htable_handle s_and_d_nominee_htable; @@ -52,26 +54,26 @@ int set_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab line_rule.rule_id=rule_id; line_rule.table_name=ir_table_name; - sscanf(table_line, "%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s", + sscanf(table_line, "%*d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", &nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.is_valid, - &nom_info.action,&nom_info.service,&nom_info.addr_pool_id,nom_info.op_time); + nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, + &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); get_cur_time(nom_info.op_time); if(memcmp(ir_table_name,INTERCEPT_IP,strlen(INTERCEPT_IP))) { - snprintf(m_table_line,sizeof(m_table_line),"%d\t%d\t%d\t%s\t%d\t%s", - rule_id,nom_info.addr_pool_id,nom_info.addr_type,nom_info.src_ip,nom_info.is_valid,nom_info.op_time); + snprintf(m_table_line,sizeof(m_table_line),"%d\t%d\t%d\t%s\t%d\t%s\t%s", + rule_id,nom_info.addr_pool_id,nom_info.addr_type,nom_info.src_ip,nom_info.is_valid,nom_info.effective_range,nom_info.op_time); } else { - snprintf(m_table_line,sizeof(m_table_line),"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%s", + snprintf(m_table_line,sizeof(m_table_line),"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", rule_id,nom_info.group_id,nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction, - nom_info.is_valid,nom_info.action,nom_info.service,nom_info.op_time); + nom_info.is_valid,nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); } line_rule.table_line=m_table_line; @@ -80,7 +82,7 @@ int set_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_ADD); - MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"maat_update", "set_table_line:%s",m_table_line); + MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"maat_update", "set_table_name:%s set_table_line:%s",ir_table_name,m_table_line); if(ret==-1) { @@ -105,22 +107,21 @@ int del_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab line_rule.label_id=0; line_rule.rule_id=rule_id; line_rule.table_name=ir_table_name; + line_rule.table_line=NULL; if(!memcmp(ir_table_name,INTERCEPT_IP,strlen(INTERCEPT_IP))) { - line_rule.table_line=table_line; line_rule.expire_after=TIME_OUT; p_line=&line_rule; ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_RENEW_TIMEOUT); } else { - line_rule.table_line=NULL; line_rule.expire_after=0; p_line=&line_rule; ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_DEL); } - MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"maat_update", "del_table_line:%s",table_line); + MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"maat_update", "del_table_name:%s del_table_line:%s",ir_table_name,table_line); if(ret==-1) @@ -160,11 +161,11 @@ long htable_read_search(void *data, const uchar *key, uint size, void *user_arg) if(htable_data!=NULL) { - sscanf((char*)data, "%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s", + sscanf((char*)data, "%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", &htable_flag,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.is_valid, - &nom_info.action,&nom_info.service,&nom_info.addr_pool_id,nom_info.op_time); + nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, + &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); if(!memcmp(user_arg,INTERCEPT_IP,strlen(INTERCEPT_IP))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_C_FLAG|| htable_flag==O_AND_N_FLAG||htable_flag==O_AND_C_AND_N_FLAG)) @@ -186,11 +187,11 @@ long htable_read_search(void *data, const uchar *key, uint size, void *user_arg) MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"htable_read_search","htable flag is:%d",htable_flag); } - snprintf(htable_data,sizeof(HTABLE_DATA_LEN), "%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s", + snprintf(htable_data,sizeof(HTABLE_DATA_LEN), "%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", htable_flag,nom_info.region_id,nom_info.group_id,nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.is_valid, - nom_info.action,nom_info.service,nom_info.addr_pool_id,nom_info.op_time); + nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, + nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"htable_read_search","htable flag change:%d",htable_flag); } @@ -208,11 +209,11 @@ void read_table_update_cb(int table_id,const char* table_line,void* u_para) if(!memcmp(u_para,INTERCEPT_IP,strlen(INTERCEPT_IP))) { - sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*d\t%*d\t%d\t%*d\t%*d\t%*s",&rule_id,&is_valid); + sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*d\t%*d\t%d",&rule_id,&is_valid); } else if(!memcmp(u_para,NOMINEE_IP,strlen(NOMINEE_IP))) { - sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%d\t%*s",&rule_id,&is_valid); + sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%d",&rule_id,&is_valid); } else { @@ -231,7 +232,15 @@ void read_table_update_cb(int table_id,const char* table_line,void* u_para) if(htable_data==NULL) { - del_ir_line(mctrl_d_feather,(char*)u_para,table_line,rule_id); + if(!memcmp(u_para,INTERCEPT_IP,strlen(INTERCEPT_IP))) + { + del_ir_line(mctrl_i_feather,(char*)u_para,table_line,rule_id); + } + else + { + del_ir_line(mctrl_n_feather,(char*)u_para,table_line,rule_id); + } + } else { @@ -255,16 +264,19 @@ void write_table_update_cb(int table_id,const char* table_line,void* u_para) { int add_ret=0; struct IR_MCTRL_INFO nom_info; + char *htable_data=NULL; nom_info.htable_flag=S_OR_D_ORIGIN_FLAG; int rule_id=0; int del_ret=0; long cb_ret=0; +// MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"write_update","table_name!!!!!!!!!!!!:%s", u_para); + if(!memcmp(u_para,DYNAMIC_NOMINEE_IP,strlen(DYNAMIC_NOMINEE_IP))) { - sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%d\t%*s\t%*d\t%d\t%s", + sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%d\t%s\t%*d\t%d\t%d\t%*d\t%s\t%s", &nom_info.region_id,&nom_info.addr_type,&nom_info.procotol,nom_info.src_ip,nom_info.src_port, - &nom_info.direction,&nom_info.is_valid,nom_info.op_time); + &nom_info.direction,nom_info.user_region,&nom_info.is_valid,&nom_info.service,nom_info.effective_range,nom_info.op_time); nom_info.region_id+=1000000000; nom_info.addr_pool_id=0; nom_info.group_id=nom_info.region_id; @@ -274,16 +286,16 @@ void write_table_update_cb(int table_id,const char* table_line,void* u_para) memcpy(nom_info.mask_dst_ip,"0.0.0.0",sizeof("0.0.0.0")); memcpy(nom_info.dst_port,"0",sizeof("0")); memcpy(nom_info.mask_dst_port,"0",sizeof("0")); - nom_info.action=0x60; - nom_info.service=19; + nom_info.action=96; } else { - sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s", + sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s", &nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.is_valid, - &nom_info.action,&nom_info.service,&nom_info.addr_pool_id,nom_info.op_time); + nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, + &nom_info.action,&nom_info.service,nom_info.effective_range,nom_info.op_time); + memcpy(nom_info.user_region,"0",sizeof("0")); } unsigned char *key_id=(unsigned char*)&nom_info.region_id; @@ -291,12 +303,12 @@ void write_table_update_cb(int table_id,const char* table_line,void* u_para) if(nom_info.is_valid==1) { - char *htable_data=(char*)malloc(HTABLE_DATA_LEN); - snprintf(htable_data,HTABLE_DATA_LEN,"%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s", + htable_data=(char*)malloc(HTABLE_DATA_LEN); + snprintf(htable_data,HTABLE_DATA_LEN,"%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", nom_info.htable_flag,nom_info.region_id,nom_info.group_id,nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.is_valid, - nom_info.action,nom_info.service,nom_info.addr_pool_id,nom_info.op_time); + nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, + nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); add_ret=MESA_htable_add(s_and_d_nominee_htable,key_id,sizeof(int),htable_data); @@ -308,54 +320,46 @@ void write_table_update_cb(int table_id,const char* table_line,void* u_para) { MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"ADD_S_AND_D_NOMINEE_HASH","add htable succeed:%d",add_ret); } + + + MESA_htable_search_cb(s_and_d_nominee_htable,key_id,sizeof(rule_id),htable_write_search,NULL,&cb_ret); + + if(cb_ret==S_OR_D_ORIGIN_FLAG||cb_ret==O_AND_C_FLAG) + { + set_ir_line(mctrl_i_feather, (char*)INTERCEPT_IP,htable_data,rule_id); + set_ir_line(mctrl_n_feather,(char*)NOMINEE_IP,htable_data,rule_id); + } + else if(cb_ret==O_AND_N_FLAG||cb_ret==O_AND_C_AND_N_FLAG) + { + set_ir_line(mctrl_i_feather, (char*)INTERCEPT_IP,htable_data,rule_id); + } + else if(cb_ret==O_AND_I_FLAG||cb_ret==O_AND_C_AND_I_FLAG) + { + set_ir_line(mctrl_n_feather,(char*)NOMINEE_IP,htable_data,rule_id); + } + else + { + MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"write_update", "exist already !! htable_flag is:%d",cb_ret); + assert(cb_ret<=ALL_EXIST_FLAG); + } } - else + else if(nom_info.is_valid==0) { - assert(nom_info.is_valid<=1); + del_ir_line(mctrl_i_feather,(char*)INTERCEPT_IP,table_line,rule_id); + del_ir_line(mctrl_n_feather,(char*)NOMINEE_IP,table_line,rule_id); + del_ir_line(mctrl_n_feather,(char*)CANDIDATE_IP,table_line,rule_id); + del_ret=MESA_htable_del(s_and_d_nominee_htable,key_id,sizeof(rule_id),htable_data_free); + + if(del_ret<0) + { + MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"DEL_S_AND_D_NOMINEE","del htable error:%d",del_ret); + } } - - MESA_htable_search_cb(s_and_d_nominee_htable,key_id,sizeof(rule_id),htable_write_search,NULL,&cb_ret); - - switch(nom_info.is_valid) + else { - case 0: - del_ir_line(mctrl_d_feather,(char*)CANDIDATE_IP,table_line,rule_id); - del_ir_line(mctrl_d_feather,(char*)INTERCEPT_IP,table_line,rule_id); - del_ir_line(mctrl_d_feather,(char*)NOMINEE_IP,table_line,rule_id); - del_ret=MESA_htable_del(s_and_d_nominee_htable,key_id,sizeof(rule_id),htable_data_free); - - if(del_ret<0) - { - MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"DEL_S_AND_D_NOMINEE","del htable error:%d",del_ret); - } - break; - - case 1: - if(cb_ret==S_OR_D_ORIGIN_FLAG||cb_ret==O_AND_C_FLAG) - { - set_ir_line(mctrl_d_feather, (char*)INTERCEPT_IP,table_line,rule_id); - set_ir_line(mctrl_d_feather,(char*)NOMINEE_IP,table_line,rule_id); - } - else if(cb_ret==O_AND_N_FLAG||cb_ret==O_AND_C_AND_N_FLAG) - { - set_ir_line(mctrl_d_feather, (char*)INTERCEPT_IP,table_line,rule_id); - } - else if(cb_ret==O_AND_I_FLAG||cb_ret==O_AND_C_AND_I_FLAG) - { - set_ir_line(mctrl_d_feather,(char*)NOMINEE_IP,table_line,rule_id); - } - else - { - MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"write_update", "exist already !! htable_flag is:%d",cb_ret); - assert(cb_ret<=ALL_EXIST_FLAG); - } - break; - - default: - MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"write_update", "is_valid default !!!"); - assert(0); - break; + MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"write_update", "is_valid default !!!"); + assert(0); } return; @@ -399,32 +403,32 @@ void htable_iterate(const uchar * key, uint size, void * data, void * user) if(htable_flag Date: Sun, 9 Dec 2018 22:04:54 +0800 Subject: 整理目录结构 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 22 -- bin/conf/mctrl.conf | 25 ++ bin/conf/table_info.conf | 22 ++ conf/mctrl.conf | 25 -- conf/redis.conf | 23 -- conf/table_info.conf | 22 -- include/ir_mctrl.h | 65 ----- ir_mctrl.cpp | 732 ----------------------------------------------- ir_mctrl.h | 89 ------ src/Makefile | 22 ++ src/ir_mctrl.cpp | 411 ++++++++++++++++---------- src/ir_mctrl.h | 89 ++++++ 12 files changed, 413 insertions(+), 1134 deletions(-) delete mode 100644 Makefile create mode 100644 bin/conf/mctrl.conf create mode 100644 bin/conf/table_info.conf delete mode 100644 conf/mctrl.conf delete mode 100644 conf/redis.conf delete mode 100644 conf/table_info.conf delete mode 100644 include/ir_mctrl.h delete mode 100644 ir_mctrl.cpp delete mode 100644 ir_mctrl.h create mode 100644 src/Makefile create mode 100644 src/ir_mctrl.h (limited to 'src/ir_mctrl.cpp') diff --git a/Makefile b/Makefile deleted file mode 100644 index 22edc9d..0000000 --- a/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -CC = gcc -CCC = g++ -CFLAGS = -Wall -g -fPIC -#INC = -I./inc/ -#1INC += /usr/include/MESA -LDFLAGS = -L./lib/ -LIBS = -lMESA_handle_logger -lMESA_prof_load -lMESA_htable -lmaatframe -OBJ =ir_mctrl.o -TARGET =ir_mctrl - -.cpp.o: - $(CCC) -c $(CFLAGS) $(INC) $< - -all: $(TARGET) - -$(TARGET): $(OBJ) - $(CCC) -o $@ $(OBJ) $(LDFLAGS) $(LIBS) - -clean: - -rm -rf $(OBJ) $(TARGET) - -.PHONY:clean diff --git a/bin/conf/mctrl.conf b/bin/conf/mctrl.conf new file mode 100644 index 0000000..3a5d955 --- /dev/null +++ b/bin/conf/mctrl.conf @@ -0,0 +1,25 @@ +[Mctrl] +table_info_path=./conf/table_info.conf +max_thread_num=1 +logger_level=30 +logger_path=./log/ir_mctrl.log + +[Mctrl_D] +Maat_redis_ip=192.168.11.243 +Maat_redis_port=6800 +Maat_redis_index=1 + +[Mctrl_S] +Maat_redis_ip=192.168.11.243 +Maat_redis_port=6379 +Maat_redis_index=6 + +[Mctrl_I] +Maat_redis_ip=192.168.11.243 +Maat_redis_port=6800 +Maat_redis_index=1 + +[Mctrl_N] +Maat_redis_ip=192.168.11.243 +Maat_redis_port=6800 +Maat_redis_index=5 diff --git a/bin/conf/table_info.conf b/bin/conf/table_info.conf new file mode 100644 index 0000000..03e0579 --- /dev/null +++ b/bin/conf/table_info.conf @@ -0,0 +1,22 @@ +#each collumn seperate with '\t' +#id (0~65535) +#name string +#type one of ip,expr,expr_plus,digest,intval,compile or plugin +#src_charset one of GBK,BIG5,UNICODE,UTF8 +#dst_charset combined by GBK,BIG5,UNICODE,UTF8,seperate with '/' +#do_merege [yes/no] +#cross cache [number] +#quick mode [quickon/quickoff], default [quickoff] +#For ip/intval/digest/compile/group +#id name type +# +#For plugin table +#id name type valid_column +# +#For expr/expr_plus Table +#id name type src_charset dst_charset do_merge cross_cache quick_mode +0 IR_STATIC_NOMINEE_IP plugin 15 -- +1 IR_DYNAMIC_NOMINEE_IP plugin 9 -- +2 IR_NOMINEE_IP plugin 5 -- +3 IR_CANDIDATE_IP plugin 19 -- +4 IR_INTERCEPT_IP plugin 14 -- diff --git a/conf/mctrl.conf b/conf/mctrl.conf deleted file mode 100644 index 3a5d955..0000000 --- a/conf/mctrl.conf +++ /dev/null @@ -1,25 +0,0 @@ -[Mctrl] -table_info_path=./conf/table_info.conf -max_thread_num=1 -logger_level=30 -logger_path=./log/ir_mctrl.log - -[Mctrl_D] -Maat_redis_ip=192.168.11.243 -Maat_redis_port=6800 -Maat_redis_index=1 - -[Mctrl_S] -Maat_redis_ip=192.168.11.243 -Maat_redis_port=6379 -Maat_redis_index=6 - -[Mctrl_I] -Maat_redis_ip=192.168.11.243 -Maat_redis_port=6800 -Maat_redis_index=1 - -[Mctrl_N] -Maat_redis_ip=192.168.11.243 -Maat_redis_port=6800 -Maat_redis_index=5 diff --git a/conf/redis.conf b/conf/redis.conf deleted file mode 100644 index 5dc1221..0000000 --- a/conf/redis.conf +++ /dev/null @@ -1,23 +0,0 @@ -[Mctrl_D] -table_info_path=./conf/table_info.conf -Maat_redis_ip=192.168.11.243 -Maat_redis_port=6800 -Maat_redis_index=1 -logger_level=10 -stat_file_path=./log/Maat_stat.log -logger_path=./log/ir_mctrl.log - -[Mctrl_S] -Maat_redis_ip=192.168.11.243 -Maat_redis_port=6379 -Maat_redis_index=6 - -[Mctrl_I] -Maat_redis_ip=192.168.11.243 -Maat_redis_port=6800 -Maat_redis_index=1 - -[Mctrl_N] -Maat_redis_ip=192.168.11.243 -Maat_redis_port=6800 -Maat_redis_index=5 \ No newline at end of file diff --git a/conf/table_info.conf b/conf/table_info.conf deleted file mode 100644 index 03e0579..0000000 --- a/conf/table_info.conf +++ /dev/null @@ -1,22 +0,0 @@ -#each collumn seperate with '\t' -#id (0~65535) -#name string -#type one of ip,expr,expr_plus,digest,intval,compile or plugin -#src_charset one of GBK,BIG5,UNICODE,UTF8 -#dst_charset combined by GBK,BIG5,UNICODE,UTF8,seperate with '/' -#do_merege [yes/no] -#cross cache [number] -#quick mode [quickon/quickoff], default [quickoff] -#For ip/intval/digest/compile/group -#id name type -# -#For plugin table -#id name type valid_column -# -#For expr/expr_plus Table -#id name type src_charset dst_charset do_merge cross_cache quick_mode -0 IR_STATIC_NOMINEE_IP plugin 15 -- -1 IR_DYNAMIC_NOMINEE_IP plugin 9 -- -2 IR_NOMINEE_IP plugin 5 -- -3 IR_CANDIDATE_IP plugin 19 -- -4 IR_INTERCEPT_IP plugin 14 -- diff --git a/include/ir_mctrl.h b/include/ir_mctrl.h deleted file mode 100644 index 1fceab6..0000000 --- a/include/ir_mctrl.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef IR_MCTRL_H -#define IR_MCTRL_H - -#define MAX_STRING_LEN 64 -#define MAX_PORT_LEN 6 -#define MAX_PATH_LEN 64 -#define MAX_TABLE_NAME_LEN 64 -#define MAX_TIME_LEN 50 -#define HTABLE_DATA_LEN 512 - -#define MCTRL_CONF_FILE "./conf/redis.conf" - -//table name -#define NOMINEE_IP "IR_NOMINEE_IP" -#define INTERCEPT_IP "IR_INTERCEPT_IP" -#define STATIC_NOMINEE_IP "IR_STATIC_NOMINEE_IP" -#define DYNAMIC_NOMINEE_IP "IR_DYNAMIC_NOMINEE_IP" -#define CANDIDATE_IP "IR_CANDIDATE_IP" - -#define TIME_OUT 30 -#define MAX_THREAD_NUM 1 - - -//htable flag -#define S_OR_D_ORIGIN_FLAG 8 -#define INTERCEPT_FLAG 4 -#define NOMINEE_FLAG 2 -#define CANDIDATE_FLAG 1 - -#define O_AND_C_FLAG 9 -#define O_AND_N_FLAG 10 -#define O_AND_C_AND_N_FLAG 11 -#define O_AND_I_FLAG 12 -#define O_AND_C_AND_I_FLAG 13 -#define O_AND_I_AND_N_FLAG 14 -#define ALL_EXIST_FLAG 15 - -struct IR_MCTRL_INFO -{ - int region_id; - int group_id; - int addr_type; - char src_ip[MAX_STRING_LEN]; - char mask_src_ip[MAX_STRING_LEN]; - char src_port[MAX_PORT_LEN]; - char mask_src_port[MAX_PORT_LEN]; - char dst_ip[MAX_STRING_LEN]; - char mask_dst_ip[MAX_STRING_LEN]; - char dst_port[MAX_PORT_LEN]; - char mask_dst_port[MAX_PORT_LEN]; - int procotol; - int direction; - int is_valid; - int action; - int service; - int addr_pool_id; - char effective_range[MAX_STRING_LEN]; - char user_region[MAX_STRING_LEN]; - char op_time[MAX_TIME_LEN]; - int htable_flag; - -}; - -#endif - diff --git a/ir_mctrl.cpp b/ir_mctrl.cpp deleted file mode 100644 index 9ba3f0f..0000000 --- a/ir_mctrl.cpp +++ /dev/null @@ -1,732 +0,0 @@ -#include -#include -#include -#include -#include -#include "MESA_prof_load.h" -#include "MESA_handle_logger.h" -#include "Maat_rule.h" -#include "Maat_command.h" -#include "ir_mctrl.h" -#include "MESA_htable.h" - -struct mctrl_glocal_info mctrl_g; - - -void s_d_start_cb(int update_type,void* u_para) -{ - if(update_type==MAAT_RULE_UPDATE_TYPE_FULL) - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is full",u_para); - if(!memcmp(u_para,DYNAMIC_NOMINEE_IP,strlen(DYNAMIC_NOMINEE_IP))) - { - mctrl_g.update_type_d=MAAT_RULE_UPDATE_TYPE_FULL; - mctrl_g.version_d++; - - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,version:%d",u_para,mctrl_g.version_d); - } - else - { - mctrl_g.update_type_s=MAAT_RULE_UPDATE_TYPE_FULL; - mctrl_g.version_s++; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,version:%d",u_para,mctrl_g.version_s); - } - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is inc",u_para); - } - return; -} - - -void Maat_start_cb(int update_type,void* u_para) -{ - if(update_type==MAAT_RULE_UPDATE_TYPE_FULL) - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is full",u_para); - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is inc",u_para); - } - return; -} - -void get_cur_time(char *date) -{ - time_t t; - struct tm *lt; - time(&t); - lt = localtime(&t); - snprintf(date, MAX_TIME_LEN,"%d/%d/%d/%d:%d:%d",lt->tm_year+1900, lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec); -} - - -int set_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *table_line,int rule_id) -{ - const struct Maat_line_t *p_line; - struct Maat_line_t line_rule; - int ret = 0; - char m_table_line[HTABLE_DATA_LEN]; - struct IR_MCTRL_INFO nom_info; - memset(&nom_info,0,sizeof(nom_info)); - memset(&line_rule, 0,sizeof(line_rule)); - - line_rule.label_id=0; - line_rule.rule_id=rule_id; - line_rule.table_name=ir_table_name; - - sscanf(table_line, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &nom_info.htable_flag,&nom_info.nominee_type,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, - &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - - get_cur_time(nom_info.op_time); - - if(memcmp(ir_table_name,INTERCEPT_IP,strlen(INTERCEPT_IP))) - { - snprintf(m_table_line,sizeof(m_table_line),"%d\t%d\t%d\t%s\t%d\t%s\t%s", - rule_id,nom_info.addr_pool_id,nom_info.addr_type,nom_info.src_ip,nom_info.is_valid,nom_info.effective_range,nom_info.op_time); - } - else - { - snprintf(m_table_line,sizeof(m_table_line),"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - rule_id,nom_info.group_id,nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction, - nom_info.is_valid,nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - } - - line_rule.table_line=m_table_line; - line_rule.expire_after=0; - p_line=&line_rule; - - ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_ADD); - - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"maat_update", "set_table_name:%s set_table_line:%s",ir_table_name,m_table_line); - - if(ret==-1) - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"SET_LINE","%s:set redis line error",ir_table_name); - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"SET_LINE","%s:set redis line success",ir_table_name); - } - return ret; -} - - -int del_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *table_line,int rule_id) -{ - int ret=0; - - const struct Maat_line_t *p_line; - struct Maat_line_t line_rule; - memset(&line_rule,0,sizeof(line_rule)); - - line_rule.label_id=0; - line_rule.rule_id=rule_id; - line_rule.table_name=ir_table_name; - line_rule.table_line=NULL; - if(!memcmp(ir_table_name,INTERCEPT_IP,strlen(INTERCEPT_IP))) - { - line_rule.expire_after=TIME_OUT; - p_line=&line_rule; - ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_RENEW_TIMEOUT); - } - else - { - line_rule.expire_after=0; - p_line=&line_rule; - ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_DEL); - } - - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"maat_update", "del_table_name:%s del_table_line:%s",ir_table_name,table_line); - - - if(ret==-1) - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"DEL_LINE","%s:del redis line error",ir_table_name); - } - else if(ret==1) - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"DEL_LINE","%s:del redis line success",ir_table_name); - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"DEL_LINE","%s:del redis line not sure",ir_table_name); - } - return ret; - -} - - -long htable_s_d_update_search(void *data, const uchar *key, uint size, void *user_arg) -{ - struct IR_MCTRL_INFO nom_info; - char *htable_data=(char*)data; - if(htable_data!=NULL) - { - sscanf(htable_data,"%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &nom_info.htable_flag,&nom_info.nominee_type,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, - &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - - if(nom_info.nominee_type==DYNAMIC_NOMINEE) - { - nom_info.version=mctrl_g.version_d; - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_s_d_update_search","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); - } - else if(nom_info.nominee_type==STATIC_NOMINEE) - { - nom_info.version=mctrl_g.version_s; - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_s_d_update_search","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_s_d_update_search","get htable flag:%d!",nom_info.htable_flag); - } - - snprintf(htable_data,HTABLE_DATA_LEN, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - nom_info.htable_flag,nom_info.nominee_type,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, - nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - - } - return nom_info.htable_flag; -} - -long htable_n_i_search(void *data, const uchar *key, uint size, void *user_arg) -{ - int htable_flag=0; - struct IR_MCTRL_INFO nom_info; - char *htable_data=(char*)data; - - if(htable_data!=NULL) - { - sscanf((char*)data, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &htable_flag,&nom_info.nominee_type,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, - &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - - if(!memcmp(user_arg,INTERCEPT_IP,strlen(INTERCEPT_IP))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_C_FLAG|| - htable_flag==O_AND_N_FLAG||htable_flag==O_AND_C_AND_N_FLAG)) - { - htable_flag+=INTERCEPT_FLAG; - } - else if(!memcmp(user_arg,NOMINEE_IP,strlen(NOMINEE_IP))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_C_FLAG|| - htable_flag==O_AND_I_FLAG||htable_flag==O_AND_C_AND_I_FLAG)) - { - htable_flag+=NOMINEE_FLAG; - } - else if(!memcmp(user_arg,CANDIDATE_IP,strlen(CANDIDATE_IP))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_N_FLAG|| - htable_flag==O_AND_I_FLAG||htable_flag==O_AND_I_AND_N_FLAG)) - { - htable_flag+=CANDIDATE_FLAG; - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_n_i_search","htable flag is:%d",htable_flag); - } - - snprintf(htable_data,HTABLE_DATA_LEN, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - htable_flag,nom_info.nominee_type,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, - nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_n_i_search","htable flag change:%d",htable_flag); - } - - return htable_flag; -} - - -void n_i_table_update_cb(int table_id,const char* table_line,void* u_para) -{ - int rule_id=0; - void *htable_data=NULL; - int is_valid=-1; - long search_ret=0; - - if(!memcmp(u_para,INTERCEPT_IP,strlen(INTERCEPT_IP))) - { - sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*d\t%*d\t%d",&rule_id,&is_valid); - } - else if(!memcmp(u_para,NOMINEE_IP,strlen(NOMINEE_IP))) - { - sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%d",&rule_id,&is_valid); - } - else - { - sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%*d\t%*s\t%*d\t%*d\t%*d\t%*d\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%d",&rule_id,&is_valid); - } - - unsigned char *key_id=(unsigned char*)&rule_id; - - if(is_valid==0) - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"READ_TABLE_UPDATA","table_name:%s del redis is_valid==0",u_para); - return; - } - - htable_data=MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id), htable_n_i_search,u_para,&search_ret); - - if(htable_data==NULL) - { - if(!memcmp(u_para,INTERCEPT_IP,strlen(INTERCEPT_IP))) - { - del_ir_line(mctrl_g.i_feather,(char*)u_para,table_line,rule_id); - } - else - { - del_ir_line(mctrl_g.n_feather,(char*)u_para,table_line,rule_id); - } - - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"READ_TABLE_UPDATA","already exist!"); - } - return; -} - -void htable_data_free(void *data) -{ - if(data!=NULL) - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"DATA_FREE","htable_data_free!"); - free(data); - data=NULL; - } - return; -} - -void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) -{ - int add_ret=0; - struct IR_MCTRL_INFO nom_info; - memset(&nom_info,0,sizeof(nom_info)); - char *htable_data=NULL; - nom_info.htable_flag=S_OR_D_ORIGIN_FLAG; - int rule_id=0; - int del_ret=0; - long cb_ret=0; - - if(!memcmp(u_para,DYNAMIC_NOMINEE_IP,strlen(DYNAMIC_NOMINEE_IP))) - { - sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%d\t%s\t%*d\t%d\t%d\t%*d\t%s\t%s", - &nom_info.region_id,&nom_info.addr_type,&nom_info.procotol,nom_info.src_ip,nom_info.src_port, - &nom_info.direction,nom_info.user_region,&nom_info.is_valid,&nom_info.service,nom_info.effective_range,nom_info.op_time); - nom_info.region_id+=1000000000; - nom_info.addr_pool_id=0; - nom_info.group_id=nom_info.region_id; - memcpy(nom_info.src_port,"0",sizeof("0")); - memcpy(nom_info.mask_src_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.mask_src_port,"0",sizeof("0")); - memcpy(nom_info.dst_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.mask_dst_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.dst_port,"0",sizeof("0")); - memcpy(nom_info.mask_dst_port,"0",sizeof("0")); - memcpy(nom_info.effective_range,"{}",sizeof("{}")); - nom_info.action=96; - nom_info.service=832; - nom_info.nominee_type=DYNAMIC_NOMINEE; - - } - else - { - sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s", - &nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, - &nom_info.action,&nom_info.service,nom_info.effective_range,nom_info.op_time); - memcpy(nom_info.effective_range,"{}",sizeof("{}")); - memcpy(nom_info.user_region,"0",sizeof("0")); - nom_info.service=832; - nom_info.nominee_type=STATIC_NOMINEE; - } - - unsigned char *key_id=(unsigned char*)&nom_info.region_id; - rule_id=nom_info.region_id; - - if(nom_info.is_valid==1) - { - htable_data=(char*)malloc(HTABLE_DATA_LEN); - snprintf(htable_data,HTABLE_DATA_LEN,"%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - nom_info.htable_flag,nom_info.nominee_type,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, - nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - - add_ret=MESA_htable_add(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_data); - - if(add_ret<0) - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"ADD_S_AND_D_NOMINEE_HASH","add htable error:%d",add_ret); - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"ADD_S_AND_D_NOMINEE_HASH","add htable succeed:%d",add_ret); - } - - - MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_s_d_update_search,NULL,&cb_ret); - - if(cb_ret==S_OR_D_ORIGIN_FLAG||cb_ret==O_AND_C_FLAG) - { - set_ir_line(mctrl_g.i_feather, (char*)INTERCEPT_IP,htable_data,rule_id); - set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,htable_data,rule_id); - } - else if(cb_ret==O_AND_N_FLAG||cb_ret==O_AND_C_AND_N_FLAG) - { - set_ir_line(mctrl_g.i_feather, (char*)INTERCEPT_IP,htable_data,rule_id); - } - else if(cb_ret==O_AND_I_FLAG||cb_ret==O_AND_C_AND_I_FLAG) - { - set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,htable_data,rule_id); - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"write_update", "exist already !! htable_flag is:%d",cb_ret); - assert(cb_ret<=ALL_EXIST_FLAG); - } - - } - else if(nom_info.is_valid==0) - { - del_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_IP,table_line,rule_id); - del_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,table_line,rule_id); - del_ir_line(mctrl_g.n_feather,(char*)CANDIDATE_IP,table_line,rule_id); - del_ret=MESA_htable_del(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_data_free); - - if(del_ret<0) - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"DEL_S_AND_D_NOMINEE","del htable error:%d",del_ret); - } - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"write_update", "is_valid default !!!"); - assert(0); - } - - return; -} - -void s_d_htable_iterate(const uchar * key, uint size, void * data, void * user) -{ - struct IR_MCTRL_INFO nom_info; - memset(&nom_info,0,sizeof(nom_info)); - char *htable_data=(char*)data; - int del_ret=0; - if(htable_data==NULL) - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"search_s_d_htable","htable is null"); - return; - } - - sscanf(htable_data, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &nom_info.htable_flag,&nom_info.nominee_type,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, - &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - if((mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==STATIC_NOMINEE&&nom_info.version!=mctrl_g.version_s)|| - (mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==DYNAMIC_NOMINEE&&nom_info.version!=mctrl_g.version_d)) - - { - unsigned char *key_id=(unsigned char*)&nom_info.region_id; - del_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_IP,(char*)data,nom_info.region_id); - del_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,(char*)data,nom_info.region_id); - del_ir_line(mctrl_g.n_feather,(char*)CANDIDATE_IP,(char*)data,nom_info.region_id); - del_ret=MESA_htable_del(mctrl_g.s_d_htable,key_id,sizeof(int),htable_data_free); - - if(del_ret<0) - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"DEL_S_AND_D_NOMINEE","del htable error:%d",del_ret); - } - } - return; -} - - -void s_d_finish_cb(void* u_para) -{ - if((!memcmp(u_para,DYNAMIC_NOMINEE_IP,strlen(DYNAMIC_NOMINEE_IP)))&&mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL) - { - MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_iterate,NULL); - mctrl_g.update_type_d=MAAT_RULE_UPDATE_TYPE_INC; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,update_type:%d,finish succeed",u_para,mctrl_g.update_type_d); - } - else if((!memcmp(u_para,STATIC_NOMINEE_IP,strlen(STATIC_NOMINEE_IP)))&&mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL) - { - MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_iterate,NULL); - mctrl_g.update_type_s=MAAT_RULE_UPDATE_TYPE_INC; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,update_type:%d,finish succeed",u_para,mctrl_g.update_type_s); - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,finish succeed",u_para); - } - return; -} - - -void Maat_finish_cb(void* u_para) -{ - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,finish succeed",u_para); - return; -} - - -int read_plugin_table(Maat_feather_t feather,const char* table_name, - Maat_start_callback_t *start,Maat_update_callback_t *update,Maat_finish_callback_t *finish, - void *u_para,void* logger,int table_id) -{ - int ret=0; - - ret=Maat_table_callback_register(feather, table_id, - start, - update, - finish, - u_para); - if(ret<0) - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"REGISTER_TABLE", "Maat callback register table %s error.\n",table_name); - assert(0); - } - - return ret; -} - - -void htable_iterate(const uchar * key, uint size, void * data, void * user) -{ - int htable_flag=0; - int rule_id=0; - char *table_line=(char*)data; - - sscanf(table_line,"%d\t%*d\t%*d\t%d",&htable_flag,&rule_id); - - if(htable_flag=14: %d!",htable_flag); - assert(htable_flag>=S_OR_D_ORIGIN_FLAG); - } - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"htable_iterate", "already exist,htable flag is:%d!",htable_flag); - assert(htable_flag<=ALL_EXIST_FLAG); - } - - return; -} - -void Maat_init() -{ -// load conf - const char *section = "Mctrl"; - const char *section_d = "Mctrl_D"; - const char *section_s = "Mctrl_S"; - const char *section_i = "Mctrl_I"; - const char *section_n = "Mctrl_N"; - char table_info_path[MAX_PATH_LEN]; - char logger_path[MAX_PATH_LEN]; - int max_thread_num=0; - char Maat_redis_ip_d[MAX_STRING_LEN]; - int Maat_redis_port_d=0; - int Maat_redis_index_d=0; - - char Maat_redis_ip_s[MAX_STRING_LEN]; - int Maat_redis_port_s=0; - int Maat_redis_index_s=0; - - char Maat_redis_ip_i[MAX_STRING_LEN]; - int Maat_redis_port_i=0; - int Maat_redis_index_i=0; - - char Maat_redis_ip_n[MAX_STRING_LEN]; - int Maat_redis_port_n=0; - int Maat_redis_index_n=0; - - int logger_level=0; - -//dynamic server conf - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section,"table_info_path", table_info_path, sizeof(table_info_path), "./conf/table_info.conf"); - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section,"logger_path", logger_path, sizeof(logger_path), "./log/ir_mctrl.log"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section,"max_thread_num", &max_thread_num, 1); - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_ip", Maat_redis_ip_d, sizeof(Maat_redis_ip_d), "127.0.0.1"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_port", &Maat_redis_port_d,6379); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_index", &Maat_redis_index_d,1); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section,"logger_level", &logger_level,RLOG_LV_FATAL); -//static server conf - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_s, "Maat_redis_ip", Maat_redis_ip_s, sizeof(Maat_redis_ip_s), "127.0.0.1"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_s,"Maat_redis_port", &Maat_redis_port_s,6379); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_s,"Maat_redis_index", &Maat_redis_index_s,0); -//nominee and candate conf - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_n,"Maat_redis_ip", Maat_redis_ip_n, sizeof(Maat_redis_ip_n), "127.0.0.1"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_n,"Maat_redis_port", &Maat_redis_port_n,6379); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_n,"Maat_redis_index", &Maat_redis_index_n,0); -//intercept conf - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_i,"Maat_redis_ip", Maat_redis_ip_i, sizeof(Maat_redis_ip_i), "127.0.0.1"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_i,"Maat_redis_port", &Maat_redis_port_i,6379); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_i,"Maat_redis_index", &Maat_redis_index_i,0); - -//log - mctrl_g.logger_handle=MESA_create_runtime_log_handle(logger_path,logger_level); - if(mctrl_g.logger_handle == NULL) - { - printf("IR MESA_create_runtime_log_handle() error!\n"); - assert(0); - } - -//redis - mctrl_g.d_feather = Maat_feather(max_thread_num, table_info_path,mctrl_g.logger_handle); - mctrl_g.s_feather = Maat_feather(max_thread_num, table_info_path,mctrl_g.logger_handle); - mctrl_g.n_feather = Maat_feather(max_thread_num, table_info_path,mctrl_g.logger_handle); - mctrl_g.i_feather = Maat_feather(max_thread_num, table_info_path,mctrl_g.logger_handle); - - if(mctrl_g.d_feather==NULL||mctrl_g.s_feather==NULL||mctrl_g.n_feather==NULL||mctrl_g.i_feather==NULL) - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"MAAT","IR maat_feather error!"); - assert(0); - } - - Maat_set_feather_opt(mctrl_g.d_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_d,MAX_STRING_LEN); - Maat_set_feather_opt(mctrl_g.d_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_d,sizeof(Maat_redis_port_d)); - Maat_set_feather_opt(mctrl_g.d_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_d,sizeof(Maat_redis_index_d)); - Maat_set_feather_opt(mctrl_g.d_feather, MAAT_OPT_INSTANCE_NAME, DYNAMIC_NOMINEE_IP, strlen(DYNAMIC_NOMINEE_IP)+1); - - Maat_set_feather_opt(mctrl_g.s_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_s,MAX_STRING_LEN); - Maat_set_feather_opt(mctrl_g.s_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_s,sizeof(Maat_redis_port_s)); - Maat_set_feather_opt(mctrl_g.s_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_s,sizeof(Maat_redis_index_s)); - Maat_set_feather_opt(mctrl_g.s_feather, MAAT_OPT_INSTANCE_NAME, STATIC_NOMINEE_IP, strlen(STATIC_NOMINEE_IP)+1); - - Maat_set_feather_opt(mctrl_g.i_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_i,MAX_STRING_LEN); - Maat_set_feather_opt(mctrl_g.i_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_i,sizeof(Maat_redis_port_i)); - Maat_set_feather_opt(mctrl_g.i_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_i,sizeof(Maat_redis_index_i)); - Maat_set_feather_opt(mctrl_g.i_feather, MAAT_OPT_INSTANCE_NAME, INTERCEPT_IP, strlen(INTERCEPT_IP)+1); - - Maat_set_feather_opt(mctrl_g.n_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_n,MAX_STRING_LEN); - Maat_set_feather_opt(mctrl_g.n_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_n,sizeof(Maat_redis_port_n)); - Maat_set_feather_opt(mctrl_g.n_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_n,sizeof(Maat_redis_index_n)); - Maat_set_feather_opt(mctrl_g.n_feather, MAAT_OPT_INSTANCE_NAME, NOMINEE_IP, strlen(NOMINEE_IP)+1); - Maat_set_feather_opt(mctrl_g.n_feather, MAAT_OPT_INSTANCE_NAME, CANDIDATE_IP, strlen(CANDIDATE_IP)+1); - - Maat_initiate_feather(mctrl_g.d_feather); - Maat_initiate_feather(mctrl_g.s_feather); - Maat_initiate_feather(mctrl_g.i_feather); - Maat_initiate_feather(mctrl_g.n_feather); - -} - - -int htable_init() -{ - int htable_ret=0; - mctrl_g.s_d_htable = MESA_htable_born(); - if(mctrl_g.s_d_htable == NULL) - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"htable","htable born failed"); - assert(0); - return -1; - } - - htable_ret = MESA_htable_mature(mctrl_g.s_d_htable); - - if(0 == htable_ret) - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"htable","htable mature succ"); - return 0; - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"htable","htable mature failed"); - assert(0); - return -1; - } -} - -int main(int argc, char * argv [ ]) -{ - - Maat_init(); - htable_init(); - - char static_nominee[]=STATIC_NOMINEE_IP; - char dynamic_nominee[]=DYNAMIC_NOMINEE_IP; - char nominee[]=NOMINEE_IP; - char candidate[]=CANDIDATE_IP; - char intercept[]=INTERCEPT_IP; - - int static_id=-1; - int dynamic_id=-1; - int nominee_id=-1; - int candidate_id=-1; - int intercept_id=-1; - - static_id=Maat_table_register(mctrl_g.s_feather,static_nominee); - dynamic_id=Maat_table_register(mctrl_g.d_feather,dynamic_nominee); - nominee_id=Maat_table_register(mctrl_g.n_feather,nominee); - candidate_id=Maat_table_register(mctrl_g.n_feather,candidate); - intercept_id=Maat_table_register(mctrl_g.i_feather, intercept); - - if(static_id==-1||dynamic_id==-1||nominee_id==-1||candidate_id==-1||intercept_id==-1) - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"REGISTER_TABLE","Database table register failed\n"); - assert(0); - } - - read_plugin_table(mctrl_g.s_feather,STATIC_NOMINEE_IP,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, - static_nominee,mctrl_g.logger_handle,static_id); - read_plugin_table(mctrl_g.d_feather,DYNAMIC_NOMINEE_IP,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, - dynamic_nominee,mctrl_g.logger_handle,dynamic_id); - - read_plugin_table(mctrl_g.i_feather,INTERCEPT_IP,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, - intercept,mctrl_g.logger_handle,intercept_id); - read_plugin_table(mctrl_g.n_feather,NOMINEE_IP,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, - nominee,mctrl_g.logger_handle,nominee_id); - read_plugin_table(mctrl_g.n_feather,CANDIDATE_IP,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, - candidate,mctrl_g.logger_handle,candidate_id); - - - while(1) - { - MESA_htable_iterate(mctrl_g.s_d_htable, htable_iterate, NULL); - sleep(3600); - } - - Maat_burn_feather(mctrl_g.d_feather); - Maat_burn_feather(mctrl_g.s_feather); - Maat_burn_feather(mctrl_g.i_feather); - Maat_burn_feather(mctrl_g.n_feather); - MESA_destroy_runtime_log_handle(mctrl_g.logger_handle); - MESA_htable_destroy(mctrl_g.s_d_htable,htable_data_free); - return 0; - -} - - diff --git a/ir_mctrl.h b/ir_mctrl.h deleted file mode 100644 index 2e58d2b..0000000 --- a/ir_mctrl.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef IR_MCTRL_H -#define IR_MCTRL_H - -#include "MESA_handle_logger.h" -#include "Maat_rule.h" -#include "Maat_command.h" -#include "MESA_htable.h" - -#define MAX_STRING_LEN 64 -#define MAX_PORT_LEN 6 -#define MAX_PATH_LEN 64 -#define MAX_TABLE_NAME_LEN 64 -#define MAX_TIME_LEN 50 -#define HTABLE_DATA_LEN 512 - -#define MCTRL_CONF_FILE "./conf/mctrl.conf" - -//table name -#define NOMINEE_IP "IR_NOMINEE_IP" -#define INTERCEPT_IP "IR_INTERCEPT_IP" -#define STATIC_NOMINEE_IP "IR_STATIC_NOMINEE_IP" -#define DYNAMIC_NOMINEE_IP "IR_DYNAMIC_NOMINEE_IP" -#define CANDIDATE_IP "IR_CANDIDATE_IP" - -#define TIME_OUT 1800 -#define MAX_THREAD_NUM 1 - -//nominee_type -#define STATIC_NOMINEE 1 -#define DYNAMIC_NOMINEE 2 - -//htable flag -#define S_OR_D_ORIGIN_FLAG 8 -#define INTERCEPT_FLAG 4 -#define NOMINEE_FLAG 2 -#define CANDIDATE_FLAG 1 - -#define O_AND_C_FLAG 9 -#define O_AND_N_FLAG 10 -#define O_AND_C_AND_N_FLAG 11 -#define O_AND_I_FLAG 12 -#define O_AND_C_AND_I_FLAG 13 -#define O_AND_I_AND_N_FLAG 14 -#define ALL_EXIST_FLAG 15 - -struct IR_MCTRL_INFO -{ - int region_id; - int group_id; - int addr_type; - char src_ip[MAX_STRING_LEN]; - char mask_src_ip[MAX_STRING_LEN]; - char src_port[MAX_PORT_LEN]; - char mask_src_port[MAX_PORT_LEN]; - char dst_ip[MAX_STRING_LEN]; - char mask_dst_ip[MAX_STRING_LEN]; - char dst_port[MAX_PORT_LEN]; - char mask_dst_port[MAX_PORT_LEN]; - int procotol; - int direction; - int is_valid; - int action; - int service; - int addr_pool_id; - char effective_range[MAX_STRING_LEN]; - char user_region[MAX_STRING_LEN]; - char op_time[MAX_TIME_LEN]; - int htable_flag; - int nominee_type; - int version; -}; - -struct mctrl_glocal_info -{ - void *logger_handle; - Maat_feather_t d_feather; - Maat_feather_t s_feather; - Maat_feather_t n_feather; - Maat_feather_t i_feather; - MESA_htable_handle s_d_htable; - int update_type_s; - int update_type_d; - int version_s; - int version_d; -}; - - -#endif - diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..22edc9d --- /dev/null +++ b/src/Makefile @@ -0,0 +1,22 @@ +CC = gcc +CCC = g++ +CFLAGS = -Wall -g -fPIC +#INC = -I./inc/ +#1INC += /usr/include/MESA +LDFLAGS = -L./lib/ +LIBS = -lMESA_handle_logger -lMESA_prof_load -lMESA_htable -lmaatframe +OBJ =ir_mctrl.o +TARGET =ir_mctrl + +.cpp.o: + $(CCC) -c $(CFLAGS) $(INC) $< + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CCC) -o $@ $(OBJ) $(LDFLAGS) $(LIBS) + +clean: + -rm -rf $(OBJ) $(TARGET) + +.PHONY:clean diff --git a/src/ir_mctrl.cpp b/src/ir_mctrl.cpp index f861755..9ba3f0f 100644 --- a/src/ir_mctrl.cpp +++ b/src/ir_mctrl.cpp @@ -10,23 +10,45 @@ #include "ir_mctrl.h" #include "MESA_htable.h" -void *logger_handle; -Maat_feather_t mctrl_d_feather; -Maat_feather_t mctrl_s_feather; -Maat_feather_t mctrl_n_feather; -Maat_feather_t mctrl_i_feather; -MESA_htable_handle s_and_d_nominee_htable; +struct mctrl_glocal_info mctrl_g; + + +void s_d_start_cb(int update_type,void* u_para) +{ + if(update_type==MAAT_RULE_UPDATE_TYPE_FULL) + { + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is full",u_para); + if(!memcmp(u_para,DYNAMIC_NOMINEE_IP,strlen(DYNAMIC_NOMINEE_IP))) + { + mctrl_g.update_type_d=MAAT_RULE_UPDATE_TYPE_FULL; + mctrl_g.version_d++; + + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,version:%d",u_para,mctrl_g.version_d); + } + else + { + mctrl_g.update_type_s=MAAT_RULE_UPDATE_TYPE_FULL; + mctrl_g.version_s++; + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,version:%d",u_para,mctrl_g.version_s); + } + } + else + { + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is inc",u_para); + } + return; +} void Maat_start_cb(int update_type,void* u_para) { if(update_type==MAAT_RULE_UPDATE_TYPE_FULL) { - MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is full",u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is full",u_para); } else { - MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is inc",u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is inc",u_para); } return; } @@ -48,14 +70,15 @@ int set_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab int ret = 0; char m_table_line[HTABLE_DATA_LEN]; struct IR_MCTRL_INFO nom_info; + memset(&nom_info,0,sizeof(nom_info)); memset(&line_rule, 0,sizeof(line_rule)); line_rule.label_id=0; line_rule.rule_id=rule_id; line_rule.table_name=ir_table_name; - sscanf(table_line, "%*d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, + sscanf(table_line, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + &nom_info.htable_flag,&nom_info.nominee_type,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); @@ -82,15 +105,15 @@ int set_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_ADD); - MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"maat_update", "set_table_name:%s set_table_line:%s",ir_table_name,m_table_line); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"maat_update", "set_table_name:%s set_table_line:%s",ir_table_name,m_table_line); if(ret==-1) { - MESA_handle_runtime_log(logger_handle, RLOG_LV_INFO, (char*)"SET_LINE","%s:set redis line error",ir_table_name); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"SET_LINE","%s:set redis line error",ir_table_name); } else { - MESA_handle_runtime_log(logger_handle, RLOG_LV_INFO, (char*)"SET_LINE","%s:set redis line success",ir_table_name); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"SET_LINE","%s:set redis line success",ir_table_name); } return ret; } @@ -121,39 +144,64 @@ int del_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_DEL); } - MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"maat_update", "del_table_name:%s del_table_line:%s",ir_table_name,table_line); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"maat_update", "del_table_name:%s del_table_line:%s",ir_table_name,table_line); if(ret==-1) { - MESA_handle_runtime_log(logger_handle, RLOG_LV_INFO, (char*)"DEL_LINE","%s:del redis line error",ir_table_name); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"DEL_LINE","%s:del redis line error",ir_table_name); } else if(ret==1) { - MESA_handle_runtime_log(logger_handle, RLOG_LV_INFO, (char*)"DEL_LINE","%s:del redis line success",ir_table_name); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"DEL_LINE","%s:del redis line success",ir_table_name); } else { - MESA_handle_runtime_log(logger_handle, RLOG_LV_INFO, (char*)"DEL_LINE","%s:del redis line not sure",ir_table_name); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"DEL_LINE","%s:del redis line not sure",ir_table_name); } return ret; } -long htable_write_search(void *data, const uchar *key, uint size, void *user_arg) +long htable_s_d_update_search(void *data, const uchar *key, uint size, void *user_arg) { - int htable_flag=0; + struct IR_MCTRL_INFO nom_info; char *htable_data=(char*)data; if(htable_data!=NULL) { - sscanf(htable_data,"%d\t",&htable_flag); - MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"htable_write_search","get htable flag:%d!",htable_flag); + sscanf(htable_data,"%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + &nom_info.htable_flag,&nom_info.nominee_type,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, + nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, + nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, + &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); + + if(nom_info.nominee_type==DYNAMIC_NOMINEE) + { + nom_info.version=mctrl_g.version_d; + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_s_d_update_search","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); + } + else if(nom_info.nominee_type==STATIC_NOMINEE) + { + nom_info.version=mctrl_g.version_s; + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_s_d_update_search","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); + } + else + { + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_s_d_update_search","get htable flag:%d!",nom_info.htable_flag); + } + + snprintf(htable_data,HTABLE_DATA_LEN, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + nom_info.htable_flag,nom_info.nominee_type,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, + nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, + nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, + nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); + } - return htable_flag; + return nom_info.htable_flag; } -long htable_read_search(void *data, const uchar *key, uint size, void *user_arg) +long htable_n_i_search(void *data, const uchar *key, uint size, void *user_arg) { int htable_flag=0; struct IR_MCTRL_INFO nom_info; @@ -161,8 +209,8 @@ long htable_read_search(void *data, const uchar *key, uint size, void *user_arg) if(htable_data!=NULL) { - sscanf((char*)data, "%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &htable_flag,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, + sscanf((char*)data, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + &htable_flag,&nom_info.nominee_type,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); @@ -184,23 +232,23 @@ long htable_read_search(void *data, const uchar *key, uint size, void *user_arg) } else { - MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"htable_read_search","htable flag is:%d",htable_flag); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_n_i_search","htable flag is:%d",htable_flag); } - snprintf(htable_data,sizeof(HTABLE_DATA_LEN), "%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - htable_flag,nom_info.region_id,nom_info.group_id,nom_info.addr_type, + snprintf(htable_data,HTABLE_DATA_LEN, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + htable_flag,nom_info.nominee_type,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"htable_read_search","htable flag change:%d",htable_flag); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_n_i_search","htable flag change:%d",htable_flag); } return htable_flag; } -void read_table_update_cb(int table_id,const char* table_line,void* u_para) +void n_i_table_update_cb(int table_id,const char* table_line,void* u_para) { int rule_id=0; void *htable_data=NULL; @@ -224,27 +272,27 @@ void read_table_update_cb(int table_id,const char* table_line,void* u_para) if(is_valid==0) { - MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"READ_TABLE_UPDATA","table_name:%s del redis is_valid==0",u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"READ_TABLE_UPDATA","table_name:%s del redis is_valid==0",u_para); return; } - htable_data=MESA_htable_search_cb(s_and_d_nominee_htable,key_id,sizeof(rule_id), htable_read_search,u_para,&search_ret); + htable_data=MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id), htable_n_i_search,u_para,&search_ret); if(htable_data==NULL) { if(!memcmp(u_para,INTERCEPT_IP,strlen(INTERCEPT_IP))) { - del_ir_line(mctrl_i_feather,(char*)u_para,table_line,rule_id); + del_ir_line(mctrl_g.i_feather,(char*)u_para,table_line,rule_id); } else { - del_ir_line(mctrl_n_feather,(char*)u_para,table_line,rule_id); + del_ir_line(mctrl_g.n_feather,(char*)u_para,table_line,rule_id); } } else { - MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"READ_TABLE_UPDATA","already exist!"); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"READ_TABLE_UPDATA","already exist!"); } return; } @@ -253,25 +301,24 @@ void htable_data_free(void *data) { if(data!=NULL) { - MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"DATA_FREE","htable_data_free!"); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"DATA_FREE","htable_data_free!"); free(data); data=NULL; } return; } -void write_table_update_cb(int table_id,const char* table_line,void* u_para) +void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) { int add_ret=0; struct IR_MCTRL_INFO nom_info; + memset(&nom_info,0,sizeof(nom_info)); char *htable_data=NULL; nom_info.htable_flag=S_OR_D_ORIGIN_FLAG; int rule_id=0; int del_ret=0; long cb_ret=0; -// MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"write_update","table_name!!!!!!!!!!!!:%s", u_para); - if(!memcmp(u_para,DYNAMIC_NOMINEE_IP,strlen(DYNAMIC_NOMINEE_IP))) { sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%d\t%s\t%*d\t%d\t%d\t%*d\t%s\t%s", @@ -280,13 +327,18 @@ void write_table_update_cb(int table_id,const char* table_line,void* u_para) nom_info.region_id+=1000000000; nom_info.addr_pool_id=0; nom_info.group_id=nom_info.region_id; + memcpy(nom_info.src_port,"0",sizeof("0")); memcpy(nom_info.mask_src_ip,"0.0.0.0",sizeof("0.0.0.0")); memcpy(nom_info.mask_src_port,"0",sizeof("0")); memcpy(nom_info.dst_ip,"0.0.0.0",sizeof("0.0.0.0")); memcpy(nom_info.mask_dst_ip,"0.0.0.0",sizeof("0.0.0.0")); memcpy(nom_info.dst_port,"0",sizeof("0")); memcpy(nom_info.mask_dst_port,"0",sizeof("0")); + memcpy(nom_info.effective_range,"{}",sizeof("{}")); nom_info.action=96; + nom_info.service=832; + nom_info.nominee_type=DYNAMIC_NOMINEE; + } else { @@ -295,7 +347,10 @@ void write_table_update_cb(int table_id,const char* table_line,void* u_para) nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, &nom_info.action,&nom_info.service,nom_info.effective_range,nom_info.op_time); + memcpy(nom_info.effective_range,"{}",sizeof("{}")); memcpy(nom_info.user_region,"0",sizeof("0")); + nom_info.service=832; + nom_info.nominee_type=STATIC_NOMINEE; } unsigned char *key_id=(unsigned char*)&nom_info.region_id; @@ -304,70 +359,128 @@ void write_table_update_cb(int table_id,const char* table_line,void* u_para) if(nom_info.is_valid==1) { htable_data=(char*)malloc(HTABLE_DATA_LEN); - snprintf(htable_data,HTABLE_DATA_LEN,"%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - nom_info.htable_flag,nom_info.region_id,nom_info.group_id,nom_info.addr_type, + snprintf(htable_data,HTABLE_DATA_LEN,"%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + nom_info.htable_flag,nom_info.nominee_type,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - add_ret=MESA_htable_add(s_and_d_nominee_htable,key_id,sizeof(int),htable_data); + add_ret=MESA_htable_add(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_data); if(add_ret<0) { - MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"ADD_S_AND_D_NOMINEE_HASH","add htable error:%d",add_ret); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"ADD_S_AND_D_NOMINEE_HASH","add htable error:%d",add_ret); } else { - MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"ADD_S_AND_D_NOMINEE_HASH","add htable succeed:%d",add_ret); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"ADD_S_AND_D_NOMINEE_HASH","add htable succeed:%d",add_ret); } - MESA_htable_search_cb(s_and_d_nominee_htable,key_id,sizeof(rule_id),htable_write_search,NULL,&cb_ret); + MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_s_d_update_search,NULL,&cb_ret); if(cb_ret==S_OR_D_ORIGIN_FLAG||cb_ret==O_AND_C_FLAG) { - set_ir_line(mctrl_i_feather, (char*)INTERCEPT_IP,htable_data,rule_id); - set_ir_line(mctrl_n_feather,(char*)NOMINEE_IP,htable_data,rule_id); + set_ir_line(mctrl_g.i_feather, (char*)INTERCEPT_IP,htable_data,rule_id); + set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,htable_data,rule_id); } else if(cb_ret==O_AND_N_FLAG||cb_ret==O_AND_C_AND_N_FLAG) { - set_ir_line(mctrl_i_feather, (char*)INTERCEPT_IP,htable_data,rule_id); + set_ir_line(mctrl_g.i_feather, (char*)INTERCEPT_IP,htable_data,rule_id); } else if(cb_ret==O_AND_I_FLAG||cb_ret==O_AND_C_AND_I_FLAG) { - set_ir_line(mctrl_n_feather,(char*)NOMINEE_IP,htable_data,rule_id); + set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,htable_data,rule_id); } else { - MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"write_update", "exist already !! htable_flag is:%d",cb_ret); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"write_update", "exist already !! htable_flag is:%d",cb_ret); assert(cb_ret<=ALL_EXIST_FLAG); } } else if(nom_info.is_valid==0) { - del_ir_line(mctrl_i_feather,(char*)INTERCEPT_IP,table_line,rule_id); - del_ir_line(mctrl_n_feather,(char*)NOMINEE_IP,table_line,rule_id); - del_ir_line(mctrl_n_feather,(char*)CANDIDATE_IP,table_line,rule_id); - del_ret=MESA_htable_del(s_and_d_nominee_htable,key_id,sizeof(rule_id),htable_data_free); + del_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_IP,table_line,rule_id); + del_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,table_line,rule_id); + del_ir_line(mctrl_g.n_feather,(char*)CANDIDATE_IP,table_line,rule_id); + del_ret=MESA_htable_del(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_data_free); if(del_ret<0) { - MESA_handle_runtime_log(logger_handle, RLOG_LV_DEBUG, (char*)"DEL_S_AND_D_NOMINEE","del htable error:%d",del_ret); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"DEL_S_AND_D_NOMINEE","del htable error:%d",del_ret); } } else { - MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"write_update", "is_valid default !!!"); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"write_update", "is_valid default !!!"); assert(0); } return; } +void s_d_htable_iterate(const uchar * key, uint size, void * data, void * user) +{ + struct IR_MCTRL_INFO nom_info; + memset(&nom_info,0,sizeof(nom_info)); + char *htable_data=(char*)data; + int del_ret=0; + if(htable_data==NULL) + { + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"search_s_d_htable","htable is null"); + return; + } + + sscanf(htable_data, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + &nom_info.htable_flag,&nom_info.nominee_type,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, + nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, + nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, + &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); + if((mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==STATIC_NOMINEE&&nom_info.version!=mctrl_g.version_s)|| + (mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==DYNAMIC_NOMINEE&&nom_info.version!=mctrl_g.version_d)) + + { + unsigned char *key_id=(unsigned char*)&nom_info.region_id; + del_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_IP,(char*)data,nom_info.region_id); + del_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,(char*)data,nom_info.region_id); + del_ir_line(mctrl_g.n_feather,(char*)CANDIDATE_IP,(char*)data,nom_info.region_id); + del_ret=MESA_htable_del(mctrl_g.s_d_htable,key_id,sizeof(int),htable_data_free); + + if(del_ret<0) + { + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"DEL_S_AND_D_NOMINEE","del htable error:%d",del_ret); + } + } + return; +} + + +void s_d_finish_cb(void* u_para) +{ + if((!memcmp(u_para,DYNAMIC_NOMINEE_IP,strlen(DYNAMIC_NOMINEE_IP)))&&mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL) + { + MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_iterate,NULL); + mctrl_g.update_type_d=MAAT_RULE_UPDATE_TYPE_INC; + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,update_type:%d,finish succeed",u_para,mctrl_g.update_type_d); + } + else if((!memcmp(u_para,STATIC_NOMINEE_IP,strlen(STATIC_NOMINEE_IP)))&&mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL) + { + MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_iterate,NULL); + mctrl_g.update_type_s=MAAT_RULE_UPDATE_TYPE_INC; + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,update_type:%d,finish succeed",u_para,mctrl_g.update_type_s); + } + else + { + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,finish succeed",u_para); + } + return; +} + + void Maat_finish_cb(void* u_para) { - MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,finish succeed",u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,finish succeed",u_para); return; } @@ -385,60 +498,47 @@ int read_plugin_table(Maat_feather_t feather,const char* table_name, u_para); if(ret<0) { - MESA_handle_runtime_log(logger_handle,RLOG_LV_FATAL, (char*)"REGISTER_TABLE", "Maat callback register table %s error.\n",table_name); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"REGISTER_TABLE", "Maat callback register table %s error.\n",table_name); assert(0); } return ret; } + void htable_iterate(const uchar * key, uint size, void * data, void * user) { int htable_flag=0; int rule_id=0; - char table_line[HTABLE_DATA_LEN]; - struct IR_MCTRL_INFO nom_info; + char *table_line=(char*)data; - sscanf((char*)data,"%d\t%d",&htable_flag,&rule_id); + sscanf(table_line,"%d\t%*d\t%*d\t%d",&htable_flag,&rule_id); if(htable_flag=14: %d!",htable_flag); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"htable_iterate", "htable flag >=14: %d!",htable_flag); assert(htable_flag>=S_OR_D_ORIGIN_FLAG); } } else { - MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"htable_iterate", "already exist,htable flag is:%d!",htable_flag); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"htable_iterate", "already exist,htable flag is:%d!",htable_flag); assert(htable_flag<=ALL_EXIST_FLAG); } @@ -448,6 +548,7 @@ void htable_iterate(const uchar * key, uint size, void * data, void * user) void Maat_init() { // load conf + const char *section = "Mctrl"; const char *section_d = "Mctrl_D"; const char *section_s = "Mctrl_S"; const char *section_i = "Mctrl_I"; @@ -471,76 +572,74 @@ void Maat_init() int Maat_redis_port_n=0; int Maat_redis_index_n=0; - char stat_file_path[MAX_PATH_LEN]; int logger_level=0; //dynamic server conf - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_d, "table_info_path", table_info_path, sizeof(table_info_path), "./conf/table_info.conf"); - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_d, "logger_path", logger_path, sizeof(logger_path), "./log/ir_mctrl.log"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d, "max_thread_num", &max_thread_num, 1); - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_d, "Maat_redis_ip", Maat_redis_ip_d, sizeof(Maat_redis_ip_d), "127.0.0.1"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d, "Maat_redis_port", &Maat_redis_port_d,6379); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d, "Maat_redis_index", &Maat_redis_index_d,1); - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_d, "stat_file_path", stat_file_path, sizeof(stat_file_path), "./log/Maat_stat.log"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d, "logger_level", &logger_level,RLOG_LV_DEBUG); + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section,"table_info_path", table_info_path, sizeof(table_info_path), "./conf/table_info.conf"); + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section,"logger_path", logger_path, sizeof(logger_path), "./log/ir_mctrl.log"); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section,"max_thread_num", &max_thread_num, 1); + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_ip", Maat_redis_ip_d, sizeof(Maat_redis_ip_d), "127.0.0.1"); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_port", &Maat_redis_port_d,6379); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_index", &Maat_redis_index_d,1); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section,"logger_level", &logger_level,RLOG_LV_FATAL); //static server conf MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_s, "Maat_redis_ip", Maat_redis_ip_s, sizeof(Maat_redis_ip_s), "127.0.0.1"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_s, "Maat_redis_port", &Maat_redis_port_s,6379); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_s, "Maat_redis_index", &Maat_redis_index_s,0); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_s,"Maat_redis_port", &Maat_redis_port_s,6379); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_s,"Maat_redis_index", &Maat_redis_index_s,0); //nominee and candate conf - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_n, "Maat_redis_ip", Maat_redis_ip_n, sizeof(Maat_redis_ip_n), "127.0.0.1"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_n, "Maat_redis_port", &Maat_redis_port_n,6379); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_n, "Maat_redis_index", &Maat_redis_index_n,0); + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_n,"Maat_redis_ip", Maat_redis_ip_n, sizeof(Maat_redis_ip_n), "127.0.0.1"); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_n,"Maat_redis_port", &Maat_redis_port_n,6379); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_n,"Maat_redis_index", &Maat_redis_index_n,0); //intercept conf - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_i, "Maat_redis_ip", Maat_redis_ip_i, sizeof(Maat_redis_ip_i), "127.0.0.1"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_i, "Maat_redis_port", &Maat_redis_port_i,6379); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_i, "Maat_redis_index", &Maat_redis_index_i,0); + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_i,"Maat_redis_ip", Maat_redis_ip_i, sizeof(Maat_redis_ip_i), "127.0.0.1"); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_i,"Maat_redis_port", &Maat_redis_port_i,6379); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_i,"Maat_redis_index", &Maat_redis_index_i,0); //log - logger_handle=MESA_create_runtime_log_handle(logger_path,logger_level); - if(logger_handle == NULL) + mctrl_g.logger_handle=MESA_create_runtime_log_handle(logger_path,logger_level); + if(mctrl_g.logger_handle == NULL) { printf("IR MESA_create_runtime_log_handle() error!\n"); assert(0); } //redis - mctrl_d_feather = Maat_feather(max_thread_num, table_info_path,logger_handle); - mctrl_s_feather = Maat_feather(max_thread_num, table_info_path,logger_handle); - mctrl_n_feather = Maat_feather(max_thread_num, table_info_path,logger_handle); - mctrl_i_feather = Maat_feather(max_thread_num, table_info_path,logger_handle); + mctrl_g.d_feather = Maat_feather(max_thread_num, table_info_path,mctrl_g.logger_handle); + mctrl_g.s_feather = Maat_feather(max_thread_num, table_info_path,mctrl_g.logger_handle); + mctrl_g.n_feather = Maat_feather(max_thread_num, table_info_path,mctrl_g.logger_handle); + mctrl_g.i_feather = Maat_feather(max_thread_num, table_info_path,mctrl_g.logger_handle); - if(mctrl_d_feather==NULL||mctrl_s_feather==NULL||mctrl_n_feather==NULL||mctrl_i_feather==NULL) + if(mctrl_g.d_feather==NULL||mctrl_g.s_feather==NULL||mctrl_g.n_feather==NULL||mctrl_g.i_feather==NULL) { - MESA_handle_runtime_log(logger_handle,RLOG_LV_FATAL,(char*)"MAAT","IR maat_feather error!"); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"MAAT","IR maat_feather error!"); assert(0); } - Maat_set_feather_opt(mctrl_d_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_d,MAX_STRING_LEN); - Maat_set_feather_opt(mctrl_d_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_d,sizeof(Maat_redis_port_d)); - Maat_set_feather_opt(mctrl_d_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_d,sizeof(Maat_redis_index_d)); - Maat_set_feather_opt(mctrl_d_feather, MAAT_OPT_INSTANCE_NAME, DYNAMIC_NOMINEE_IP, strlen(DYNAMIC_NOMINEE_IP)+1); + Maat_set_feather_opt(mctrl_g.d_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_d,MAX_STRING_LEN); + Maat_set_feather_opt(mctrl_g.d_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_d,sizeof(Maat_redis_port_d)); + Maat_set_feather_opt(mctrl_g.d_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_d,sizeof(Maat_redis_index_d)); + Maat_set_feather_opt(mctrl_g.d_feather, MAAT_OPT_INSTANCE_NAME, DYNAMIC_NOMINEE_IP, strlen(DYNAMIC_NOMINEE_IP)+1); - Maat_set_feather_opt(mctrl_s_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_s,MAX_STRING_LEN); - Maat_set_feather_opt(mctrl_s_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_s,sizeof(Maat_redis_port_s)); - Maat_set_feather_opt(mctrl_s_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_s,sizeof(Maat_redis_index_s)); - Maat_set_feather_opt(mctrl_s_feather, MAAT_OPT_INSTANCE_NAME, STATIC_NOMINEE_IP, strlen(STATIC_NOMINEE_IP)+1); + Maat_set_feather_opt(mctrl_g.s_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_s,MAX_STRING_LEN); + Maat_set_feather_opt(mctrl_g.s_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_s,sizeof(Maat_redis_port_s)); + Maat_set_feather_opt(mctrl_g.s_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_s,sizeof(Maat_redis_index_s)); + Maat_set_feather_opt(mctrl_g.s_feather, MAAT_OPT_INSTANCE_NAME, STATIC_NOMINEE_IP, strlen(STATIC_NOMINEE_IP)+1); - Maat_set_feather_opt(mctrl_i_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_i,MAX_STRING_LEN); - Maat_set_feather_opt(mctrl_i_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_i,sizeof(Maat_redis_port_i)); - Maat_set_feather_opt(mctrl_i_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_i,sizeof(Maat_redis_index_i)); - Maat_set_feather_opt(mctrl_i_feather, MAAT_OPT_INSTANCE_NAME, INTERCEPT_IP, strlen(INTERCEPT_IP)+1); - - Maat_set_feather_opt(mctrl_n_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_n,MAX_STRING_LEN); - Maat_set_feather_opt(mctrl_n_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_n,sizeof(Maat_redis_port_n)); - Maat_set_feather_opt(mctrl_n_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_n,sizeof(Maat_redis_index_n)); - Maat_set_feather_opt(mctrl_n_feather, MAAT_OPT_INSTANCE_NAME, NOMINEE_IP, strlen(NOMINEE_IP)+1); - Maat_set_feather_opt(mctrl_n_feather, MAAT_OPT_INSTANCE_NAME, CANDIDATE_IP, strlen(CANDIDATE_IP)+1); + Maat_set_feather_opt(mctrl_g.i_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_i,MAX_STRING_LEN); + Maat_set_feather_opt(mctrl_g.i_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_i,sizeof(Maat_redis_port_i)); + Maat_set_feather_opt(mctrl_g.i_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_i,sizeof(Maat_redis_index_i)); + Maat_set_feather_opt(mctrl_g.i_feather, MAAT_OPT_INSTANCE_NAME, INTERCEPT_IP, strlen(INTERCEPT_IP)+1); + + Maat_set_feather_opt(mctrl_g.n_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_n,MAX_STRING_LEN); + Maat_set_feather_opt(mctrl_g.n_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_n,sizeof(Maat_redis_port_n)); + Maat_set_feather_opt(mctrl_g.n_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_n,sizeof(Maat_redis_index_n)); + Maat_set_feather_opt(mctrl_g.n_feather, MAAT_OPT_INSTANCE_NAME, NOMINEE_IP, strlen(NOMINEE_IP)+1); + Maat_set_feather_opt(mctrl_g.n_feather, MAAT_OPT_INSTANCE_NAME, CANDIDATE_IP, strlen(CANDIDATE_IP)+1); - Maat_initiate_feather(mctrl_d_feather); - Maat_initiate_feather(mctrl_s_feather); - Maat_initiate_feather(mctrl_i_feather); - Maat_initiate_feather(mctrl_n_feather); + Maat_initiate_feather(mctrl_g.d_feather); + Maat_initiate_feather(mctrl_g.s_feather); + Maat_initiate_feather(mctrl_g.i_feather); + Maat_initiate_feather(mctrl_g.n_feather); } @@ -548,24 +647,24 @@ void Maat_init() int htable_init() { int htable_ret=0; - s_and_d_nominee_htable = MESA_htable_born(); - if(s_and_d_nominee_htable == NULL) + mctrl_g.s_d_htable = MESA_htable_born(); + if(mctrl_g.s_d_htable == NULL) { - MESA_handle_runtime_log(logger_handle,RLOG_LV_FATAL,(char*)"htable","htable born failed"); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"htable","htable born failed"); assert(0); return -1; } - htable_ret = MESA_htable_mature(s_and_d_nominee_htable); + htable_ret = MESA_htable_mature(mctrl_g.s_d_htable); if(0 == htable_ret) { - MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO,(char*)"htable","htable mature succ"); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"htable","htable mature succ"); return 0; } else { - MESA_handle_runtime_log(logger_handle,RLOG_LV_FATAL,(char*)"htable","htable mature failed"); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"htable","htable mature failed"); assert(0); return -1; } @@ -589,43 +688,43 @@ int main(int argc, char * argv [ ]) int candidate_id=-1; int intercept_id=-1; - static_id=Maat_table_register(mctrl_s_feather,static_nominee); - dynamic_id=Maat_table_register(mctrl_d_feather,dynamic_nominee); - nominee_id=Maat_table_register(mctrl_n_feather,nominee); - candidate_id=Maat_table_register(mctrl_n_feather,candidate); - intercept_id=Maat_table_register(mctrl_i_feather, intercept); + static_id=Maat_table_register(mctrl_g.s_feather,static_nominee); + dynamic_id=Maat_table_register(mctrl_g.d_feather,dynamic_nominee); + nominee_id=Maat_table_register(mctrl_g.n_feather,nominee); + candidate_id=Maat_table_register(mctrl_g.n_feather,candidate); + intercept_id=Maat_table_register(mctrl_g.i_feather, intercept); if(static_id==-1||dynamic_id==-1||nominee_id==-1||candidate_id==-1||intercept_id==-1) { - MESA_handle_runtime_log(logger_handle,RLOG_LV_FATAL,(char*)"REGISTER_TABLE","Database table register failed\n"); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"REGISTER_TABLE","Database table register failed\n"); assert(0); } - read_plugin_table(mctrl_s_feather,STATIC_NOMINEE_IP,Maat_start_cb,write_table_update_cb,Maat_finish_cb, - static_nominee,logger_handle,static_id); - read_plugin_table(mctrl_d_feather,DYNAMIC_NOMINEE_IP,Maat_start_cb,write_table_update_cb,Maat_finish_cb, - dynamic_nominee,logger_handle,dynamic_id); + read_plugin_table(mctrl_g.s_feather,STATIC_NOMINEE_IP,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, + static_nominee,mctrl_g.logger_handle,static_id); + read_plugin_table(mctrl_g.d_feather,DYNAMIC_NOMINEE_IP,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, + dynamic_nominee,mctrl_g.logger_handle,dynamic_id); - read_plugin_table(mctrl_i_feather,INTERCEPT_IP,Maat_start_cb,read_table_update_cb,Maat_finish_cb, - intercept,logger_handle,intercept_id); - read_plugin_table(mctrl_n_feather,NOMINEE_IP,Maat_start_cb,read_table_update_cb,Maat_finish_cb, - nominee,logger_handle,nominee_id); - read_plugin_table(mctrl_n_feather,CANDIDATE_IP,Maat_start_cb,read_table_update_cb,Maat_finish_cb, - candidate,logger_handle,candidate_id); + read_plugin_table(mctrl_g.i_feather,INTERCEPT_IP,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, + intercept,mctrl_g.logger_handle,intercept_id); + read_plugin_table(mctrl_g.n_feather,NOMINEE_IP,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, + nominee,mctrl_g.logger_handle,nominee_id); + read_plugin_table(mctrl_g.n_feather,CANDIDATE_IP,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, + candidate,mctrl_g.logger_handle,candidate_id); while(1) { - MESA_htable_iterate(s_and_d_nominee_htable, htable_iterate, NULL); + MESA_htable_iterate(mctrl_g.s_d_htable, htable_iterate, NULL); sleep(3600); } - Maat_burn_feather(mctrl_d_feather); - Maat_burn_feather(mctrl_s_feather); - Maat_burn_feather(mctrl_i_feather); - Maat_burn_feather(mctrl_n_feather); - MESA_destroy_runtime_log_handle(logger_handle); - MESA_htable_destroy(s_and_d_nominee_htable,htable_data_free); + Maat_burn_feather(mctrl_g.d_feather); + Maat_burn_feather(mctrl_g.s_feather); + Maat_burn_feather(mctrl_g.i_feather); + Maat_burn_feather(mctrl_g.n_feather); + MESA_destroy_runtime_log_handle(mctrl_g.logger_handle); + MESA_htable_destroy(mctrl_g.s_d_htable,htable_data_free); return 0; } diff --git a/src/ir_mctrl.h b/src/ir_mctrl.h new file mode 100644 index 0000000..2e58d2b --- /dev/null +++ b/src/ir_mctrl.h @@ -0,0 +1,89 @@ +#ifndef IR_MCTRL_H +#define IR_MCTRL_H + +#include "MESA_handle_logger.h" +#include "Maat_rule.h" +#include "Maat_command.h" +#include "MESA_htable.h" + +#define MAX_STRING_LEN 64 +#define MAX_PORT_LEN 6 +#define MAX_PATH_LEN 64 +#define MAX_TABLE_NAME_LEN 64 +#define MAX_TIME_LEN 50 +#define HTABLE_DATA_LEN 512 + +#define MCTRL_CONF_FILE "./conf/mctrl.conf" + +//table name +#define NOMINEE_IP "IR_NOMINEE_IP" +#define INTERCEPT_IP "IR_INTERCEPT_IP" +#define STATIC_NOMINEE_IP "IR_STATIC_NOMINEE_IP" +#define DYNAMIC_NOMINEE_IP "IR_DYNAMIC_NOMINEE_IP" +#define CANDIDATE_IP "IR_CANDIDATE_IP" + +#define TIME_OUT 1800 +#define MAX_THREAD_NUM 1 + +//nominee_type +#define STATIC_NOMINEE 1 +#define DYNAMIC_NOMINEE 2 + +//htable flag +#define S_OR_D_ORIGIN_FLAG 8 +#define INTERCEPT_FLAG 4 +#define NOMINEE_FLAG 2 +#define CANDIDATE_FLAG 1 + +#define O_AND_C_FLAG 9 +#define O_AND_N_FLAG 10 +#define O_AND_C_AND_N_FLAG 11 +#define O_AND_I_FLAG 12 +#define O_AND_C_AND_I_FLAG 13 +#define O_AND_I_AND_N_FLAG 14 +#define ALL_EXIST_FLAG 15 + +struct IR_MCTRL_INFO +{ + int region_id; + int group_id; + int addr_type; + char src_ip[MAX_STRING_LEN]; + char mask_src_ip[MAX_STRING_LEN]; + char src_port[MAX_PORT_LEN]; + char mask_src_port[MAX_PORT_LEN]; + char dst_ip[MAX_STRING_LEN]; + char mask_dst_ip[MAX_STRING_LEN]; + char dst_port[MAX_PORT_LEN]; + char mask_dst_port[MAX_PORT_LEN]; + int procotol; + int direction; + int is_valid; + int action; + int service; + int addr_pool_id; + char effective_range[MAX_STRING_LEN]; + char user_region[MAX_STRING_LEN]; + char op_time[MAX_TIME_LEN]; + int htable_flag; + int nominee_type; + int version; +}; + +struct mctrl_glocal_info +{ + void *logger_handle; + Maat_feather_t d_feather; + Maat_feather_t s_feather; + Maat_feather_t n_feather; + Maat_feather_t i_feather; + MESA_htable_handle s_d_htable; + int update_type_s; + int update_type_d; + int version_s; + int version_d; +}; + + +#endif + -- cgit v1.2.3 From 9da93fd8ffe3126deb4356ff4da9d552b4b9e0fd Mon Sep 17 00:00:00 2001 From: jixinyi Date: Mon, 10 Dec 2018 15:03:22 +0800 Subject: 修复全量调用关联删除失败bug,详细说明文档,修改遍历时间 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...57\264\346\230\216\346\226\207\346\241\243.docx" | Bin 28172 -> 28705 bytes src/ir_mctrl.cpp | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ir_mctrl.cpp') diff --git "a/doc/IP\345\244\215\347\224\250\351\241\271\347\233\256mctrl\350\257\264\346\230\216\346\226\207\346\241\243.docx" "b/doc/IP\345\244\215\347\224\250\351\241\271\347\233\256mctrl\350\257\264\346\230\216\346\226\207\346\241\243.docx" index c865897..f59a0ee 100644 Binary files "a/doc/IP\345\244\215\347\224\250\351\241\271\347\233\256mctrl\350\257\264\346\230\216\346\226\207\346\241\243.docx" and "b/doc/IP\345\244\215\347\224\250\351\241\271\347\233\256mctrl\350\257\264\346\230\216\346\226\207\346\241\243.docx" differ diff --git a/src/ir_mctrl.cpp b/src/ir_mctrl.cpp index 9ba3f0f..d0ea89f 100644 --- a/src/ir_mctrl.cpp +++ b/src/ir_mctrl.cpp @@ -716,7 +716,7 @@ int main(int argc, char * argv [ ]) while(1) { MESA_htable_iterate(mctrl_g.s_d_htable, htable_iterate, NULL); - sleep(3600); + sleep(86400); } Maat_burn_feather(mctrl_g.d_feather); -- cgit v1.2.3 From 6882ea29c596796fa16e703ddba95e687cbc14f5 Mon Sep 17 00:00:00 2001 From: jixinyi Date: Tue, 11 Dec 2018 20:55:42 +0800 Subject: 加入DNAT_POLICY表处理逻辑,修改CANDIDATE处理 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/conf/table_info.conf | 4 +- bin/ir_mctrl | Bin 47048 -> 47800 bytes src/ir_mctrl.cpp | 249 +++++++++++++++++++++++++++++++++-------------- src/ir_mctrl.h | 22 +++-- 4 files changed, 195 insertions(+), 80 deletions(-) (limited to 'src/ir_mctrl.cpp') diff --git a/bin/conf/table_info.conf b/bin/conf/table_info.conf index 03e0579..c66db3a 100644 --- a/bin/conf/table_info.conf +++ b/bin/conf/table_info.conf @@ -18,5 +18,7 @@ 0 IR_STATIC_NOMINEE_IP plugin 15 -- 1 IR_DYNAMIC_NOMINEE_IP plugin 9 -- 2 IR_NOMINEE_IP plugin 5 -- -3 IR_CANDIDATE_IP plugin 19 -- +3 IR_CANDIDATE_IP plugin 6 -- 4 IR_INTERCEPT_IP plugin 14 -- +5 IR_DNAT_POLICY plugin 11 -- + diff --git a/bin/ir_mctrl b/bin/ir_mctrl index a4ac21c..05deeea 100644 Binary files a/bin/ir_mctrl and b/bin/ir_mctrl differ diff --git a/src/ir_mctrl.cpp b/src/ir_mctrl.cpp index d0ea89f..7f5c330 100644 --- a/src/ir_mctrl.cpp +++ b/src/ir_mctrl.cpp @@ -18,19 +18,24 @@ void s_d_start_cb(int update_type,void* u_para) if(update_type==MAAT_RULE_UPDATE_TYPE_FULL) { MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is full",u_para); - if(!memcmp(u_para,DYNAMIC_NOMINEE_IP,strlen(DYNAMIC_NOMINEE_IP))) + if(!memcmp(u_para,DYNAMIC_NOMINEE_TABLE,strlen(DYNAMIC_NOMINEE_TABLE))) { mctrl_g.update_type_d=MAAT_RULE_UPDATE_TYPE_FULL; mctrl_g.version_d++; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,version:%d",u_para,mctrl_g.version_d); } - else + else if(!memcmp(u_para,STATIC_NOMINEE_TABLE,strlen(STATIC_NOMINEE_TABLE))) { mctrl_g.update_type_s=MAAT_RULE_UPDATE_TYPE_FULL; mctrl_g.version_s++; MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,version:%d",u_para,mctrl_g.version_s); } + else + { + mctrl_g.update_type_dp=MAAT_RULE_UPDATE_TYPE_FULL; + mctrl_g.version_dp++; + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,version:%d",u_para,mctrl_g.version_dp); + } } else { @@ -85,12 +90,12 @@ int set_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab get_cur_time(nom_info.op_time); - if(memcmp(ir_table_name,INTERCEPT_IP,strlen(INTERCEPT_IP))) + if(!memcmp(ir_table_name,NOMINEE_TABLE,strlen(NOMINEE_TABLE))) { snprintf(m_table_line,sizeof(m_table_line),"%d\t%d\t%d\t%s\t%d\t%s\t%s", rule_id,nom_info.addr_pool_id,nom_info.addr_type,nom_info.src_ip,nom_info.is_valid,nom_info.effective_range,nom_info.op_time); } - else + else { snprintf(m_table_line,sizeof(m_table_line),"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", rule_id,nom_info.group_id,nom_info.addr_type, @@ -131,7 +136,7 @@ int del_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab line_rule.rule_id=rule_id; line_rule.table_name=ir_table_name; line_rule.table_line=NULL; - if(!memcmp(ir_table_name,INTERCEPT_IP,strlen(INTERCEPT_IP))) + if(!memcmp(ir_table_name,INTERCEPT_TABLE,strlen(INTERCEPT_TABLE))) { line_rule.expire_after=TIME_OUT; p_line=&line_rule; @@ -163,11 +168,23 @@ int del_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab } +long htable_del_update_search(void *data, const uchar *key, uint size, void *user_arg) +{ + int htable_flag=0; + char *htable_data=(char*)data; + if(htable_data!=NULL) + { + sscanf(htable_data,"%d\t",&htable_flag); + } + return htable_flag; +} + -long htable_s_d_update_search(void *data, const uchar *key, uint size, void *user_arg) +long htable_set_update_search(void *data, const uchar *key, uint size, void *user_arg) { struct IR_MCTRL_INFO nom_info; char *htable_data=(char*)data; + if(htable_data!=NULL) { sscanf(htable_data,"%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", @@ -176,19 +193,24 @@ long htable_s_d_update_search(void *data, const uchar *key, uint size, void *use nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - if(nom_info.nominee_type==DYNAMIC_NOMINEE) + if(nom_info.nominee_type==DYNAMIC_NOMINEE_INFO) { nom_info.version=mctrl_g.version_d; - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_s_d_update_search","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_set_update_search","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); } - else if(nom_info.nominee_type==STATIC_NOMINEE) + else if(nom_info.nominee_type==STATIC_NOMINEE_INFO) { nom_info.version=mctrl_g.version_s; - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_s_d_update_search","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_set_update_search","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); + } + else if(nom_info.nominee_type==D_POLICY_INFO) + { + nom_info.version=mctrl_g.version_dp; + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_set_update_search","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); } else { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_s_d_update_search","get htable flag:%d!",nom_info.htable_flag); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_set_update_search","get htable flag:%d!",nom_info.htable_flag); } snprintf(htable_data,HTABLE_DATA_LEN, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", @@ -196,7 +218,10 @@ long htable_s_d_update_search(void *data, const uchar *key, uint size, void *use nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - + } + else + { + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"htable_set_update_search","htable info not exist!!!"); } return nom_info.htable_flag; } @@ -215,17 +240,17 @@ long htable_n_i_search(void *data, const uchar *key, uint size, void *user_arg) nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - if(!memcmp(user_arg,INTERCEPT_IP,strlen(INTERCEPT_IP))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_C_FLAG|| - htable_flag==O_AND_N_FLAG||htable_flag==O_AND_C_AND_N_FLAG)) + if(!memcmp(user_arg,INTERCEPT_TABLE,strlen(INTERCEPT_TABLE))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_C_FLAG|| + htable_flag==O_AND_N_FLAG||htable_flag==O_AND_C_AND_N_FLAG||htable_flag==D_POLICY_FLAG)) { htable_flag+=INTERCEPT_FLAG; } - else if(!memcmp(user_arg,NOMINEE_IP,strlen(NOMINEE_IP))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_C_FLAG|| + else if(!memcmp(user_arg,NOMINEE_TABLE,strlen(NOMINEE_TABLE))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_C_FLAG|| htable_flag==O_AND_I_FLAG||htable_flag==O_AND_C_AND_I_FLAG)) { htable_flag+=NOMINEE_FLAG; } - else if(!memcmp(user_arg,CANDIDATE_IP,strlen(CANDIDATE_IP))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_N_FLAG|| + else if(!memcmp(user_arg,CANDIDATE_TABLE,strlen(CANDIDATE_TABLE))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_N_FLAG|| htable_flag==O_AND_I_FLAG||htable_flag==O_AND_I_AND_N_FLAG)) { htable_flag+=CANDIDATE_FLAG; @@ -255,17 +280,17 @@ void n_i_table_update_cb(int table_id,const char* table_line,void* u_para) int is_valid=-1; long search_ret=0; - if(!memcmp(u_para,INTERCEPT_IP,strlen(INTERCEPT_IP))) + if(!memcmp(u_para,INTERCEPT_TABLE,strlen(INTERCEPT_TABLE))) { sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*d\t%*d\t%d",&rule_id,&is_valid); } - else if(!memcmp(u_para,NOMINEE_IP,strlen(NOMINEE_IP))) + else if(!memcmp(u_para,NOMINEE_TABLE,strlen(NOMINEE_TABLE))) { sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%d",&rule_id,&is_valid); } else { - sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%*d\t%*s\t%*d\t%*d\t%*d\t%*d\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%d",&rule_id,&is_valid); + sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%*d\t%d",&rule_id,&is_valid); } unsigned char *key_id=(unsigned char*)&rule_id; @@ -280,7 +305,7 @@ void n_i_table_update_cb(int table_id,const char* table_line,void* u_para) if(htable_data==NULL) { - if(!memcmp(u_para,INTERCEPT_IP,strlen(INTERCEPT_IP))) + if(!memcmp(u_para,INTERCEPT_TABLE,strlen(INTERCEPT_TABLE))) { del_ir_line(mctrl_g.i_feather,(char*)u_para,table_line,rule_id); } @@ -308,18 +333,55 @@ void htable_data_free(void *data) return; } +void del_redis_info(int flag,const char* table_line,int rule_id) +{ + switch(flag) + { + case ALL_EXIST_FLAG: + del_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_TABLE,table_line,rule_id); + del_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE,table_line,rule_id); + del_ir_line(mctrl_g.n_feather,(char*)CANDIDATE_TABLE,table_line,rule_id); + break; + case O_AND_I_AND_N_FLAG: + del_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_TABLE,table_line,rule_id); + del_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE,table_line,rule_id); + break; + case O_AND_C_AND_I_FLAG: + del_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_TABLE,table_line,rule_id); + del_ir_line(mctrl_g.n_feather,(char*)CANDIDATE_TABLE,table_line,rule_id); + break; + case O_AND_C_AND_N_FLAG: + del_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE,table_line,rule_id); + del_ir_line(mctrl_g.n_feather,(char*)CANDIDATE_TABLE,table_line,rule_id); + break; + case O_AND_I_FLAG: + case DP_AND_I_FLAG: + del_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_TABLE,table_line,rule_id); + break; + case O_AND_C_FLAG: + del_ir_line(mctrl_g.n_feather,(char*)CANDIDATE_TABLE,table_line,rule_id); + break; + case O_AND_N_FLAG: + del_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE,table_line,rule_id); + break; + default: + break; + } + return; +} + void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) { int add_ret=0; struct IR_MCTRL_INFO nom_info; memset(&nom_info,0,sizeof(nom_info)); char *htable_data=NULL; - nom_info.htable_flag=S_OR_D_ORIGIN_FLAG; + void *search_result=NULL; int rule_id=0; int del_ret=0; long cb_ret=0; - if(!memcmp(u_para,DYNAMIC_NOMINEE_IP,strlen(DYNAMIC_NOMINEE_IP))) + if(!memcmp(u_para,DYNAMIC_NOMINEE_TABLE,strlen(DYNAMIC_NOMINEE_TABLE))) { sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%d\t%s\t%*d\t%d\t%d\t%*d\t%s\t%s", &nom_info.region_id,&nom_info.addr_type,&nom_info.procotol,nom_info.src_ip,nom_info.src_port, @@ -337,20 +399,44 @@ void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) memcpy(nom_info.effective_range,"{}",sizeof("{}")); nom_info.action=96; nom_info.service=832; - nom_info.nominee_type=DYNAMIC_NOMINEE; + nom_info.htable_flag=S_OR_D_ORIGIN_FLAG; + nom_info.nominee_type=DYNAMIC_NOMINEE_INFO; } - else + else if(!memcmp(u_para,STATIC_NOMINEE_TABLE,strlen(STATIC_NOMINEE_TABLE))) { sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s", &nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, &nom_info.action,&nom_info.service,nom_info.effective_range,nom_info.op_time); + nom_info.region_id+=500000000; + memcpy(nom_info.user_region,"0",sizeof("0")); memcpy(nom_info.effective_range,"{}",sizeof("{}")); + nom_info.service=832; + nom_info.htable_flag=S_OR_D_ORIGIN_FLAG; + nom_info.nominee_type=STATIC_NOMINEE_INFO; + } + else + { + sscanf(table_line,"%d\t%d\t%s\t%s\t%d\t%*s\t%*s\t%d\t%d\t%d\t%d\t%s\t%s", + &nom_info.region_id,&nom_info.addr_type,nom_info.dst_ip,nom_info.dst_port,&nom_info.procotol, + &nom_info.do_log,&nom_info.action,&nom_info.service,&nom_info.is_valid, + nom_info.effective_range,nom_info.op_time); + nom_info.group_id=nom_info.region_id; + memcpy(nom_info.src_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(nom_info.src_port,"0",sizeof("0")); + memcpy(nom_info.mask_src_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(nom_info.mask_src_port,"0",sizeof("0")); + memcpy(nom_info.mask_dst_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(nom_info.mask_dst_port,"0",sizeof("0")); memcpy(nom_info.user_region,"0",sizeof("0")); + memcpy(nom_info.effective_range,"{}",sizeof("{}")); + nom_info.direction=0; + nom_info.action=96; nom_info.service=832; - nom_info.nominee_type=STATIC_NOMINEE; + nom_info.htable_flag=D_POLICY_FLAG; + nom_info.nominee_type=D_POLICY_INFO; } unsigned char *key_id=(unsigned char*)&nom_info.region_id; @@ -377,20 +463,20 @@ void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) } - MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_s_d_update_search,NULL,&cb_ret); + MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_set_update_search,NULL,&cb_ret); if(cb_ret==S_OR_D_ORIGIN_FLAG||cb_ret==O_AND_C_FLAG) { - set_ir_line(mctrl_g.i_feather, (char*)INTERCEPT_IP,htable_data,rule_id); - set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,htable_data,rule_id); + set_ir_line(mctrl_g.i_feather, (char*)INTERCEPT_TABLE,htable_data,rule_id); + set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE,htable_data,rule_id); } - else if(cb_ret==O_AND_N_FLAG||cb_ret==O_AND_C_AND_N_FLAG) + else if(cb_ret==O_AND_N_FLAG||cb_ret==O_AND_C_AND_N_FLAG||cb_ret==D_POLICY_FLAG) { - set_ir_line(mctrl_g.i_feather, (char*)INTERCEPT_IP,htable_data,rule_id); + set_ir_line(mctrl_g.i_feather, (char*)INTERCEPT_TABLE,htable_data,rule_id); } else if(cb_ret==O_AND_I_FLAG||cb_ret==O_AND_C_AND_I_FLAG) { - set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,htable_data,rule_id); + set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE,htable_data,rule_id); } else { @@ -401,9 +487,16 @@ void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) } else if(nom_info.is_valid==0) { - del_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_IP,table_line,rule_id); - del_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,table_line,rule_id); - del_ir_line(mctrl_g.n_feather,(char*)CANDIDATE_IP,table_line,rule_id); + search_result=MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_del_update_search,NULL,&cb_ret); + + if(search_result==NULL) + { + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"write_update", "already del!!!"); + return; + } + + del_redis_info(cb_ret,table_line,rule_id); + del_ret=MESA_htable_del(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_data_free); if(del_ret<0) @@ -437,14 +530,15 @@ void s_d_htable_iterate(const uchar * key, uint size, void * data, void * user) nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - if((mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==STATIC_NOMINEE&&nom_info.version!=mctrl_g.version_s)|| - (mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==DYNAMIC_NOMINEE&&nom_info.version!=mctrl_g.version_d)) + if((mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==STATIC_NOMINEE_INFO&&nom_info.version!=mctrl_g.version_s)|| + (mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==DYNAMIC_NOMINEE_INFO&&nom_info.version!=mctrl_g.version_d)|| + (mctrl_g.update_type_dp==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==D_POLICY_INFO&&nom_info.version!=mctrl_g.version_dp)) { + del_redis_info(nom_info.htable_flag,(char*)data,nom_info.region_id); + unsigned char *key_id=(unsigned char*)&nom_info.region_id; - del_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_IP,(char*)data,nom_info.region_id); - del_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,(char*)data,nom_info.region_id); - del_ir_line(mctrl_g.n_feather,(char*)CANDIDATE_IP,(char*)data,nom_info.region_id); + del_ret=MESA_htable_del(mctrl_g.s_d_htable,key_id,sizeof(int),htable_data_free); if(del_ret<0) @@ -458,20 +552,27 @@ void s_d_htable_iterate(const uchar * key, uint size, void * data, void * user) void s_d_finish_cb(void* u_para) { - if((!memcmp(u_para,DYNAMIC_NOMINEE_IP,strlen(DYNAMIC_NOMINEE_IP)))&&mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL) + if((!memcmp(u_para,DYNAMIC_NOMINEE_TABLE,strlen(DYNAMIC_NOMINEE_TABLE)))&&mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL) { MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_iterate,NULL); mctrl_g.update_type_d=MAAT_RULE_UPDATE_TYPE_INC; MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,update_type:%d,finish succeed",u_para,mctrl_g.update_type_d); } - else if((!memcmp(u_para,STATIC_NOMINEE_IP,strlen(STATIC_NOMINEE_IP)))&&mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL) + else if((!memcmp(u_para,STATIC_NOMINEE_TABLE,strlen(STATIC_NOMINEE_TABLE)))&&mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL) { MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_iterate,NULL); mctrl_g.update_type_s=MAAT_RULE_UPDATE_TYPE_INC; MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,update_type:%d,finish succeed",u_para,mctrl_g.update_type_s); } + else if((!memcmp(u_para,DNAT_POLICY_TABLE,strlen(DNAT_POLICY_TABLE)))&&mctrl_g.update_type_dp==MAAT_RULE_UPDATE_TYPE_FULL) + { + + MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_iterate,NULL); + mctrl_g.update_type_dp=MAAT_RULE_UPDATE_TYPE_INC; + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,update_type:%d,finish succeed",u_para,mctrl_g.update_type_dp); + } else - { + { MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,finish succeed",u_para); } return; @@ -519,21 +620,21 @@ void htable_iterate(const uchar * key, uint size, void * data, void * user) if(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_C_FLAG) { - set_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_IP,table_line,rule_id); - set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,table_line,rule_id); + set_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_TABLE,table_line,rule_id); + set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE,table_line,rule_id); } - else if(htable_flag==O_AND_N_FLAG||htable_flag==O_AND_C_AND_N_FLAG) + else if(htable_flag==O_AND_N_FLAG||htable_flag==O_AND_C_AND_N_FLAG||htable_flag==D_POLICY_FLAG) { - set_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_IP,table_line,rule_id); + set_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_TABLE,table_line,rule_id); } else if(htable_flag==O_AND_I_FLAG||htable_flag==O_AND_C_AND_I_FLAG) { - set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,table_line,rule_id); + set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE,table_line,rule_id); } else { MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"htable_iterate", "htable flag >=14: %d!",htable_flag); - assert(htable_flag>=S_OR_D_ORIGIN_FLAG); + assert(htable_flag>=D_POLICY_FLAG); } } else @@ -556,6 +657,8 @@ void Maat_init() char table_info_path[MAX_PATH_LEN]; char logger_path[MAX_PATH_LEN]; int max_thread_num=0; + int logger_level=0; + char Maat_redis_ip_d[MAX_STRING_LEN]; int Maat_redis_port_d=0; int Maat_redis_index_d=0; @@ -571,17 +674,15 @@ void Maat_init() char Maat_redis_ip_n[MAX_STRING_LEN]; int Maat_redis_port_n=0; int Maat_redis_index_n=0; - - int logger_level=0; - -//dynamic server conf + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section,"table_info_path", table_info_path, sizeof(table_info_path), "./conf/table_info.conf"); MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section,"logger_path", logger_path, sizeof(logger_path), "./log/ir_mctrl.log"); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section,"logger_level", &logger_level,RLOG_LV_FATAL); MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section,"max_thread_num", &max_thread_num, 1); +//dynamic server conf MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_ip", Maat_redis_ip_d, sizeof(Maat_redis_ip_d), "127.0.0.1"); MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_port", &Maat_redis_port_d,6379); MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_index", &Maat_redis_index_d,1); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section,"logger_level", &logger_level,RLOG_LV_FATAL); //static server conf MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_s, "Maat_redis_ip", Maat_redis_ip_s, sizeof(Maat_redis_ip_s), "127.0.0.1"); MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_s,"Maat_redis_port", &Maat_redis_port_s,6379); @@ -618,23 +719,23 @@ void Maat_init() Maat_set_feather_opt(mctrl_g.d_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_d,MAX_STRING_LEN); Maat_set_feather_opt(mctrl_g.d_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_d,sizeof(Maat_redis_port_d)); Maat_set_feather_opt(mctrl_g.d_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_d,sizeof(Maat_redis_index_d)); - Maat_set_feather_opt(mctrl_g.d_feather, MAAT_OPT_INSTANCE_NAME, DYNAMIC_NOMINEE_IP, strlen(DYNAMIC_NOMINEE_IP)+1); + Maat_set_feather_opt(mctrl_g.d_feather, MAAT_OPT_INSTANCE_NAME, DYNAMIC_NOMINEE_TABLE, strlen(DYNAMIC_NOMINEE_TABLE)+1); Maat_set_feather_opt(mctrl_g.s_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_s,MAX_STRING_LEN); Maat_set_feather_opt(mctrl_g.s_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_s,sizeof(Maat_redis_port_s)); Maat_set_feather_opt(mctrl_g.s_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_s,sizeof(Maat_redis_index_s)); - Maat_set_feather_opt(mctrl_g.s_feather, MAAT_OPT_INSTANCE_NAME, STATIC_NOMINEE_IP, strlen(STATIC_NOMINEE_IP)+1); + Maat_set_feather_opt(mctrl_g.s_feather, MAAT_OPT_INSTANCE_NAME, STATIC_NOMINEE_TABLE, strlen(STATIC_NOMINEE_TABLE)+1); Maat_set_feather_opt(mctrl_g.i_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_i,MAX_STRING_LEN); Maat_set_feather_opt(mctrl_g.i_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_i,sizeof(Maat_redis_port_i)); Maat_set_feather_opt(mctrl_g.i_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_i,sizeof(Maat_redis_index_i)); - Maat_set_feather_opt(mctrl_g.i_feather, MAAT_OPT_INSTANCE_NAME, INTERCEPT_IP, strlen(INTERCEPT_IP)+1); + Maat_set_feather_opt(mctrl_g.i_feather, MAAT_OPT_INSTANCE_NAME, INTERCEPT_TABLE, strlen(INTERCEPT_TABLE)+1); Maat_set_feather_opt(mctrl_g.n_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_n,MAX_STRING_LEN); Maat_set_feather_opt(mctrl_g.n_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_n,sizeof(Maat_redis_port_n)); Maat_set_feather_opt(mctrl_g.n_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_n,sizeof(Maat_redis_index_n)); - Maat_set_feather_opt(mctrl_g.n_feather, MAAT_OPT_INSTANCE_NAME, NOMINEE_IP, strlen(NOMINEE_IP)+1); - Maat_set_feather_opt(mctrl_g.n_feather, MAAT_OPT_INSTANCE_NAME, CANDIDATE_IP, strlen(CANDIDATE_IP)+1); + Maat_set_feather_opt(mctrl_g.n_feather, MAAT_OPT_INSTANCE_NAME, NOMINEE_TABLE, strlen(NOMINEE_TABLE)+1); + Maat_set_feather_opt(mctrl_g.n_feather, MAAT_OPT_INSTANCE_NAME, CANDIDATE_TABLE, strlen(CANDIDATE_TABLE)+1); Maat_initiate_feather(mctrl_g.d_feather); Maat_initiate_feather(mctrl_g.s_feather); @@ -676,47 +777,51 @@ int main(int argc, char * argv [ ]) Maat_init(); htable_init(); - char static_nominee[]=STATIC_NOMINEE_IP; - char dynamic_nominee[]=DYNAMIC_NOMINEE_IP; - char nominee[]=NOMINEE_IP; - char candidate[]=CANDIDATE_IP; - char intercept[]=INTERCEPT_IP; + char static_nominee[]=STATIC_NOMINEE_TABLE; + char dynamic_nominee[]=DYNAMIC_NOMINEE_TABLE; + char nominee[]=NOMINEE_TABLE; + char candidate[]=CANDIDATE_TABLE; + char intercept[]=INTERCEPT_TABLE; + char d_policy[]=DNAT_POLICY_TABLE; int static_id=-1; int dynamic_id=-1; int nominee_id=-1; int candidate_id=-1; int intercept_id=-1; + int d_policy_id=-1; static_id=Maat_table_register(mctrl_g.s_feather,static_nominee); dynamic_id=Maat_table_register(mctrl_g.d_feather,dynamic_nominee); nominee_id=Maat_table_register(mctrl_g.n_feather,nominee); candidate_id=Maat_table_register(mctrl_g.n_feather,candidate); intercept_id=Maat_table_register(mctrl_g.i_feather, intercept); + d_policy_id=Maat_table_register(mctrl_g.s_feather,d_policy); - if(static_id==-1||dynamic_id==-1||nominee_id==-1||candidate_id==-1||intercept_id==-1) + if(static_id==-1||dynamic_id==-1||nominee_id==-1||candidate_id==-1||intercept_id==-1||d_policy_id==-1) { MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"REGISTER_TABLE","Database table register failed\n"); assert(0); } - read_plugin_table(mctrl_g.s_feather,STATIC_NOMINEE_IP,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, + read_plugin_table(mctrl_g.s_feather,STATIC_NOMINEE_TABLE,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, static_nominee,mctrl_g.logger_handle,static_id); - read_plugin_table(mctrl_g.d_feather,DYNAMIC_NOMINEE_IP,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, + read_plugin_table(mctrl_g.d_feather,DYNAMIC_NOMINEE_TABLE,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, dynamic_nominee,mctrl_g.logger_handle,dynamic_id); + read_plugin_table(mctrl_g.s_feather,DNAT_POLICY_TABLE,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, + d_policy,mctrl_g.logger_handle,d_policy_id); - read_plugin_table(mctrl_g.i_feather,INTERCEPT_IP,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, + read_plugin_table(mctrl_g.i_feather,INTERCEPT_TABLE,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, intercept,mctrl_g.logger_handle,intercept_id); - read_plugin_table(mctrl_g.n_feather,NOMINEE_IP,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, + read_plugin_table(mctrl_g.n_feather,NOMINEE_TABLE,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, nominee,mctrl_g.logger_handle,nominee_id); - read_plugin_table(mctrl_g.n_feather,CANDIDATE_IP,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, + read_plugin_table(mctrl_g.n_feather,CANDIDATE_TABLE,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, candidate,mctrl_g.logger_handle,candidate_id); - while(1) { MESA_htable_iterate(mctrl_g.s_d_htable, htable_iterate, NULL); - sleep(86400); + sleep(SLEEP_TIME); } Maat_burn_feather(mctrl_g.d_feather); diff --git a/src/ir_mctrl.h b/src/ir_mctrl.h index 2e58d2b..16e07a8 100644 --- a/src/ir_mctrl.h +++ b/src/ir_mctrl.h @@ -16,25 +16,30 @@ #define MCTRL_CONF_FILE "./conf/mctrl.conf" //table name -#define NOMINEE_IP "IR_NOMINEE_IP" -#define INTERCEPT_IP "IR_INTERCEPT_IP" -#define STATIC_NOMINEE_IP "IR_STATIC_NOMINEE_IP" -#define DYNAMIC_NOMINEE_IP "IR_DYNAMIC_NOMINEE_IP" -#define CANDIDATE_IP "IR_CANDIDATE_IP" +#define NOMINEE_TABLE "IR_NOMINEE_IP" +#define INTERCEPT_TABLE "IR_INTERCEPT_IP" +#define STATIC_NOMINEE_TABLE "IR_STATIC_NOMINEE_IP" +#define DYNAMIC_NOMINEE_TABLE "IR_DYNAMIC_NOMINEE_IP" +#define CANDIDATE_TABLE "IR_CANDIDATE_IP" +#define DNAT_POLICY_TABLE "IR_DNAT_POLICY" +#define SLEEP_TIME 86400 #define TIME_OUT 1800 #define MAX_THREAD_NUM 1 //nominee_type -#define STATIC_NOMINEE 1 -#define DYNAMIC_NOMINEE 2 +#define STATIC_NOMINEE_INFO 1 +#define DYNAMIC_NOMINEE_INFO 2 +#define D_POLICY_INFO 3 //htable flag #define S_OR_D_ORIGIN_FLAG 8 #define INTERCEPT_FLAG 4 #define NOMINEE_FLAG 2 #define CANDIDATE_FLAG 1 +#define D_POLICY_FLAG 3 +#define DP_AND_I_FLAG 7 #define O_AND_C_FLAG 9 #define O_AND_N_FLAG 10 #define O_AND_C_AND_N_FLAG 11 @@ -65,6 +70,7 @@ struct IR_MCTRL_INFO char effective_range[MAX_STRING_LEN]; char user_region[MAX_STRING_LEN]; char op_time[MAX_TIME_LEN]; + int do_log; int htable_flag; int nominee_type; int version; @@ -80,8 +86,10 @@ struct mctrl_glocal_info MESA_htable_handle s_d_htable; int update_type_s; int update_type_d; + int update_type_dp; int version_s; int version_d; + int version_dp; }; -- cgit v1.2.3 From 0e930e6b50916ee73641dfb0e27bbaa893fd005f Mon Sep 17 00:00:00 2001 From: jixinyi Date: Thu, 13 Dec 2018 15:05:46 +0800 Subject: 修改rule_id分段模式,修复溢出bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/ir_mctrl | Bin 47800 -> 47928 bytes src/ir_mctrl.cpp | 14 ++++++++------ src/ir_mctrl.h | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src/ir_mctrl.cpp') diff --git a/bin/ir_mctrl b/bin/ir_mctrl index 05deeea..660ee8a 100644 Binary files a/bin/ir_mctrl and b/bin/ir_mctrl differ diff --git a/src/ir_mctrl.cpp b/src/ir_mctrl.cpp index 7f5c330..f5607f9 100644 --- a/src/ir_mctrl.cpp +++ b/src/ir_mctrl.cpp @@ -64,7 +64,7 @@ void get_cur_time(char *date) struct tm *lt; time(&t); lt = localtime(&t); - snprintf(date, MAX_TIME_LEN,"%d/%d/%d/%d:%d:%d",lt->tm_year+1900, lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec); + snprintf(date, MAX_TIME_LEN,"%d/%d/%d/%d:%d:%d",lt->tm_year+1900, lt->tm_mon+1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec); } @@ -221,7 +221,8 @@ long htable_set_update_search(void *data, const uchar *key, uint size, void *use } else { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"htable_set_update_search","htable info not exist!!!"); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"htable_set_update_search","htable info not exist!,set error!!!"); + assert(0); } return nom_info.htable_flag; } @@ -297,7 +298,7 @@ void n_i_table_update_cb(int table_id,const char* table_line,void* u_para) if(is_valid==0) { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"READ_TABLE_UPDATA","table_name:%s del redis is_valid==0",u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"READ_TABLE_UPDATA"," del table_name:%s,data:%s is_valid==0",u_para,table_line); return; } @@ -326,7 +327,7 @@ void htable_data_free(void *data) { if(data!=NULL) { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"DATA_FREE","htable_data_free!"); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"DATA_FREE","htable_data_free!"); free(data); data=NULL; } @@ -386,7 +387,7 @@ void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%d\t%s\t%*d\t%d\t%d\t%*d\t%s\t%s", &nom_info.region_id,&nom_info.addr_type,&nom_info.procotol,nom_info.src_ip,nom_info.src_port, &nom_info.direction,nom_info.user_region,&nom_info.is_valid,&nom_info.service,nom_info.effective_range,nom_info.op_time); - nom_info.region_id+=1000000000; + nom_info.region_id=(nom_info.region_id%1000000000)+1000000000; nom_info.addr_pool_id=0; nom_info.group_id=nom_info.region_id; memcpy(nom_info.src_port,"0",sizeof("0")); @@ -410,7 +411,7 @@ void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, &nom_info.action,&nom_info.service,nom_info.effective_range,nom_info.op_time); - nom_info.region_id+=500000000; + nom_info.region_id=(nom_info.region_id%500000000)+500000000; memcpy(nom_info.user_region,"0",sizeof("0")); memcpy(nom_info.effective_range,"{}",sizeof("{}")); nom_info.service=832; @@ -432,6 +433,7 @@ void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) memcpy(nom_info.mask_dst_port,"0",sizeof("0")); memcpy(nom_info.user_region,"0",sizeof("0")); memcpy(nom_info.effective_range,"{}",sizeof("{}")); + nom_info.region_id=nom_info.region_id%500000000; nom_info.direction=0; nom_info.action=96; nom_info.service=832; diff --git a/src/ir_mctrl.h b/src/ir_mctrl.h index 16e07a8..3c1a25c 100644 --- a/src/ir_mctrl.h +++ b/src/ir_mctrl.h @@ -23,7 +23,7 @@ #define CANDIDATE_TABLE "IR_CANDIDATE_IP" #define DNAT_POLICY_TABLE "IR_DNAT_POLICY" -#define SLEEP_TIME 86400 +#define SLEEP_TIME 43200 #define TIME_OUT 1800 #define MAX_THREAD_NUM 1 -- cgit v1.2.3 From 1a058c1e2bcf4d86ba46eedb433dd97f975bb49c Mon Sep 17 00:00:00 2001 From: jixinyi Date: Fri, 4 Jan 2019 09:33:23 +0800 Subject: 整理SNAT和DNAT代码 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ir_mctrl.cpp | 159 ++++++++++++++++++++++++++----------------------------- src/ir_mctrl.h | 11 ++-- 2 files changed, 82 insertions(+), 88 deletions(-) (limited to 'src/ir_mctrl.cpp') diff --git a/src/ir_mctrl.cpp b/src/ir_mctrl.cpp index f5607f9..3663216 100644 --- a/src/ir_mctrl.cpp +++ b/src/ir_mctrl.cpp @@ -12,7 +12,6 @@ struct mctrl_glocal_info mctrl_g; - void s_d_start_cb(int update_type,void* u_para) { if(update_type==MAAT_RULE_UPDATE_TYPE_FULL) @@ -45,7 +44,7 @@ void s_d_start_cb(int update_type,void* u_para) } -void Maat_start_cb(int update_type,void* u_para) +void n_i_c_start_cb(int update_type,void* u_para) { if(update_type==MAAT_RULE_UPDATE_TYPE_FULL) { @@ -168,7 +167,7 @@ int del_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab } -long htable_del_update_search(void *data, const uchar *key, uint size, void *user_arg) +long del_update_search_htable_cb(void *data, const uchar *key, uint size, void *user_arg) { int htable_flag=0; char *htable_data=(char*)data; @@ -179,8 +178,7 @@ long htable_del_update_search(void *data, const uchar *key, uint size, void *use return htable_flag; } - -long htable_set_update_search(void *data, const uchar *key, uint size, void *user_arg) +long set_update_search_htable_cb(void *data, const uchar *key, uint size, void *user_arg) { struct IR_MCTRL_INFO nom_info; char *htable_data=(char*)data; @@ -196,21 +194,21 @@ long htable_set_update_search(void *data, const uchar *key, uint size, void *use if(nom_info.nominee_type==DYNAMIC_NOMINEE_INFO) { nom_info.version=mctrl_g.version_d; - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_set_update_search","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); } else if(nom_info.nominee_type==STATIC_NOMINEE_INFO) { nom_info.version=mctrl_g.version_s; - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_set_update_search","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); } - else if(nom_info.nominee_type==D_POLICY_INFO) + else if(nom_info.nominee_type==DNAT_POLICY_INFO) { nom_info.version=mctrl_g.version_dp; - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_set_update_search","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); } else { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_set_update_search","get htable flag:%d!",nom_info.htable_flag); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d!",nom_info.htable_flag); } snprintf(htable_data,HTABLE_DATA_LEN, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", @@ -221,13 +219,14 @@ long htable_set_update_search(void *data, const uchar *key, uint size, void *use } else { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"htable_set_update_search","htable info not exist!,set error!!!"); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"set_update_search_htable_cb","htable info not exist!,set error!!!"); assert(0); } return nom_info.htable_flag; } -long htable_n_i_search(void *data, const uchar *key, uint size, void *user_arg) + +long n_i_c_update_search_htable_cb(void *data, const uchar *key, uint size, void *user_arg) { int htable_flag=0; struct IR_MCTRL_INFO nom_info; @@ -258,7 +257,7 @@ long htable_n_i_search(void *data, const uchar *key, uint size, void *user_arg) } else { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_n_i_search","htable flag is:%d",htable_flag); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"n_i_c_update_search_htable_cb","htable flag is:%d",htable_flag); } snprintf(htable_data,HTABLE_DATA_LEN, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", @@ -267,14 +266,14 @@ long htable_n_i_search(void *data, const uchar *key, uint size, void *user_arg) nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"htable_n_i_search","htable flag change:%d",htable_flag); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"n_i_c_update_search_htable_cb","htable flag change:%d",htable_flag); } return htable_flag; } -void n_i_table_update_cb(int table_id,const char* table_line,void* u_para) +void n_i_c_table_update_cb(int table_id,const char* table_line,void* u_para) { int rule_id=0; void *htable_data=NULL; @@ -298,11 +297,11 @@ void n_i_table_update_cb(int table_id,const char* table_line,void* u_para) if(is_valid==0) { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"READ_TABLE_UPDATA"," del table_name:%s,data:%s is_valid==0",u_para,table_line); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"READ_TABLE_UPDATA"," del table_name:%s,data:%s is_valid==0,del succeed",u_para,table_line); return; } - htable_data=MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id), htable_n_i_search,u_para,&search_ret); + htable_data=MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id), n_i_c_update_search_htable_cb,u_para,&search_ret); if(htable_data==NULL) { @@ -313,8 +312,7 @@ void n_i_table_update_cb(int table_id,const char* table_line,void* u_para) else { del_ir_line(mctrl_g.n_feather,(char*)u_para,table_line,rule_id); - } - + } } else { @@ -366,6 +364,34 @@ void del_redis_info(int flag,const char* table_line,int rule_id) del_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE,table_line,rule_id); break; default: + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"del_update", "already del! htable_flag is:%d",flag); + break; + } + return; +} + +void set_redis_info(int flag,const char* table_line,int rule_id) +{ + switch(flag) + { + case S_OR_D_ORIGIN_FLAG: + case O_AND_C_FLAG: + set_ir_line(mctrl_g.i_feather, (char*)INTERCEPT_TABLE,table_line,rule_id); + set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE,table_line,rule_id); + break; + case O_AND_N_FLAG: + case O_AND_C_AND_N_FLAG: + case D_POLICY_FLAG: + set_ir_line(mctrl_g.i_feather, (char*)INTERCEPT_TABLE,table_line,rule_id); + break; + case O_AND_I_FLAG: + case O_AND_C_AND_I_FLAG: + set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE,table_line,rule_id); + break; + default: + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"write_update", "exist already ! htable_flag is:%d",flag); + assert(flag<=ALL_EXIST_FLAG); + assert(flag>=D_POLICY_FLAG); break; } return; @@ -381,12 +407,13 @@ void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) int rule_id=0; int del_ret=0; long cb_ret=0; - + if(!memcmp(u_para,DYNAMIC_NOMINEE_TABLE,strlen(DYNAMIC_NOMINEE_TABLE))) { sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%d\t%s\t%*d\t%d\t%d\t%*d\t%s\t%s", &nom_info.region_id,&nom_info.addr_type,&nom_info.procotol,nom_info.src_ip,nom_info.src_port, &nom_info.direction,nom_info.user_region,&nom_info.is_valid,&nom_info.service,nom_info.effective_range,nom_info.op_time); + nom_info.region_id=(nom_info.region_id%1000000000)+1000000000; nom_info.addr_pool_id=0; nom_info.group_id=nom_info.region_id; @@ -438,7 +465,7 @@ void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) nom_info.action=96; nom_info.service=832; nom_info.htable_flag=D_POLICY_FLAG; - nom_info.nominee_type=D_POLICY_INFO; + nom_info.nominee_type=DNAT_POLICY_INFO; } unsigned char *key_id=(unsigned char*)&nom_info.region_id; @@ -465,31 +492,14 @@ void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) } - MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_set_update_search,NULL,&cb_ret); + MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id),set_update_search_htable_cb,NULL,&cb_ret); - if(cb_ret==S_OR_D_ORIGIN_FLAG||cb_ret==O_AND_C_FLAG) - { - set_ir_line(mctrl_g.i_feather, (char*)INTERCEPT_TABLE,htable_data,rule_id); - set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE,htable_data,rule_id); - } - else if(cb_ret==O_AND_N_FLAG||cb_ret==O_AND_C_AND_N_FLAG||cb_ret==D_POLICY_FLAG) - { - set_ir_line(mctrl_g.i_feather, (char*)INTERCEPT_TABLE,htable_data,rule_id); - } - else if(cb_ret==O_AND_I_FLAG||cb_ret==O_AND_C_AND_I_FLAG) - { - set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE,htable_data,rule_id); - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"write_update", "exist already !! htable_flag is:%d",cb_ret); - assert(cb_ret<=ALL_EXIST_FLAG); - } + set_redis_info(cb_ret,htable_data,rule_id); } else if(nom_info.is_valid==0) { - search_result=MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_del_update_search,NULL,&cb_ret); + search_result=MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id),del_update_search_htable_cb,NULL,&cb_ret); if(search_result==NULL) { @@ -515,7 +525,7 @@ void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) return; } -void s_d_htable_iterate(const uchar * key, uint size, void * data, void * user) +void s_d_htable_full_iterate(const uchar * key, uint size, void * data, void * user) { struct IR_MCTRL_INFO nom_info; memset(&nom_info,0,sizeof(nom_info)); @@ -534,7 +544,7 @@ void s_d_htable_iterate(const uchar * key, uint size, void * data, void * user) &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); if((mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==STATIC_NOMINEE_INFO&&nom_info.version!=mctrl_g.version_s)|| (mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==DYNAMIC_NOMINEE_INFO&&nom_info.version!=mctrl_g.version_d)|| - (mctrl_g.update_type_dp==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==D_POLICY_INFO&&nom_info.version!=mctrl_g.version_dp)) + (mctrl_g.update_type_dp==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==DNAT_POLICY_INFO&&nom_info.version!=mctrl_g.version_dp)) { del_redis_info(nom_info.htable_flag,(char*)data,nom_info.region_id); @@ -556,20 +566,20 @@ void s_d_finish_cb(void* u_para) { if((!memcmp(u_para,DYNAMIC_NOMINEE_TABLE,strlen(DYNAMIC_NOMINEE_TABLE)))&&mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL) { - MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_iterate,NULL); + MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_full_iterate,NULL); mctrl_g.update_type_d=MAAT_RULE_UPDATE_TYPE_INC; MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,update_type:%d,finish succeed",u_para,mctrl_g.update_type_d); } else if((!memcmp(u_para,STATIC_NOMINEE_TABLE,strlen(STATIC_NOMINEE_TABLE)))&&mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL) { - MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_iterate,NULL); + MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_full_iterate,NULL); mctrl_g.update_type_s=MAAT_RULE_UPDATE_TYPE_INC; MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,update_type:%d,finish succeed",u_para,mctrl_g.update_type_s); } else if((!memcmp(u_para,DNAT_POLICY_TABLE,strlen(DNAT_POLICY_TABLE)))&&mctrl_g.update_type_dp==MAAT_RULE_UPDATE_TYPE_FULL) { - MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_iterate,NULL); + MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_full_iterate,NULL); mctrl_g.update_type_dp=MAAT_RULE_UPDATE_TYPE_INC; MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,update_type:%d,finish succeed",u_para,mctrl_g.update_type_dp); } @@ -581,7 +591,7 @@ void s_d_finish_cb(void* u_para) } -void Maat_finish_cb(void* u_para) +void n_i_c_finish_cb(void* u_para) { MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,finish succeed",u_para); return; @@ -616,35 +626,9 @@ void htable_iterate(const uchar * key, uint size, void * data, void * user) char *table_line=(char*)data; sscanf(table_line,"%d\t%*d\t%*d\t%d",&htable_flag,&rule_id); - - if(htable_flag=14: %d!",htable_flag); - assert(htable_flag>=D_POLICY_FLAG); - } - } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"htable_iterate", "already exist,htable flag is:%d!",htable_flag); - assert(htable_flag<=ALL_EXIST_FLAG); - } + set_redis_info(htable_flag,table_line,rule_id); + return; } @@ -795,14 +779,11 @@ int main(int argc, char * argv [ ]) static_id=Maat_table_register(mctrl_g.s_feather,static_nominee); dynamic_id=Maat_table_register(mctrl_g.d_feather,dynamic_nominee); - nominee_id=Maat_table_register(mctrl_g.n_feather,nominee); - candidate_id=Maat_table_register(mctrl_g.n_feather,candidate); - intercept_id=Maat_table_register(mctrl_g.i_feather, intercept); d_policy_id=Maat_table_register(mctrl_g.s_feather,d_policy); - if(static_id==-1||dynamic_id==-1||nominee_id==-1||candidate_id==-1||intercept_id==-1||d_policy_id==-1) + if(static_id==-1||dynamic_id==-1||d_policy_id==-1) { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"REGISTER_TABLE","Database table register failed\n"); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"REGISTER_TABLE","S_D_DP Database table register failed\n"); assert(0); } @@ -812,12 +793,22 @@ int main(int argc, char * argv [ ]) dynamic_nominee,mctrl_g.logger_handle,dynamic_id); read_plugin_table(mctrl_g.s_feather,DNAT_POLICY_TABLE,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, d_policy,mctrl_g.logger_handle,d_policy_id); - - read_plugin_table(mctrl_g.i_feather,INTERCEPT_TABLE,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, + + nominee_id=Maat_table_register(mctrl_g.n_feather,nominee); + candidate_id=Maat_table_register(mctrl_g.n_feather,candidate); + intercept_id=Maat_table_register(mctrl_g.i_feather, intercept); + + if(nominee_id==-1||candidate_id==-1||intercept_id==-1) + { + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"REGISTER_TABLE","N_C_I Database table register failed\n"); + assert(0); + } + + read_plugin_table(mctrl_g.i_feather,INTERCEPT_TABLE,n_i_c_start_cb,n_i_c_table_update_cb,n_i_c_finish_cb, intercept,mctrl_g.logger_handle,intercept_id); - read_plugin_table(mctrl_g.n_feather,NOMINEE_TABLE,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, + read_plugin_table(mctrl_g.n_feather,NOMINEE_TABLE,n_i_c_start_cb,n_i_c_table_update_cb,n_i_c_finish_cb, nominee,mctrl_g.logger_handle,nominee_id); - read_plugin_table(mctrl_g.n_feather,CANDIDATE_TABLE,Maat_start_cb,n_i_table_update_cb,Maat_finish_cb, + read_plugin_table(mctrl_g.n_feather,CANDIDATE_TABLE,n_i_c_start_cb,n_i_c_table_update_cb,n_i_c_finish_cb, candidate,mctrl_g.logger_handle,candidate_id); while(1) diff --git a/src/ir_mctrl.h b/src/ir_mctrl.h index 3c1a25c..d409d51 100644 --- a/src/ir_mctrl.h +++ b/src/ir_mctrl.h @@ -10,7 +10,7 @@ #define MAX_PORT_LEN 6 #define MAX_PATH_LEN 64 #define MAX_TABLE_NAME_LEN 64 -#define MAX_TIME_LEN 50 +#define MAX_TIME_LEN 30 #define HTABLE_DATA_LEN 512 #define MCTRL_CONF_FILE "./conf/mctrl.conf" @@ -24,13 +24,16 @@ #define DNAT_POLICY_TABLE "IR_DNAT_POLICY" #define SLEEP_TIME 43200 -#define TIME_OUT 1800 -#define MAX_THREAD_NUM 1 +#define TIME_OUT 30 +#define MAX_THREAD_NUM 1 //nominee_type #define STATIC_NOMINEE_INFO 1 #define DYNAMIC_NOMINEE_INFO 2 -#define D_POLICY_INFO 3 +#define DNAT_POLICY_INFO 3 +#define NOMINEE_INFO 4 +#define INTERCEPT_INFO 5 +#define CANDIDATE_INFO 6 //htable flag #define S_OR_D_ORIGIN_FLAG 8 -- cgit v1.2.3 From 151c370a35604426d2c19aa1c84a63bcc706c22c Mon Sep 17 00:00:00 2001 From: jixinyi Date: Fri, 4 Jan 2019 18:56:03 +0800 Subject: 整理SNAT和DNAT代码 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ir_mctrl.cpp | 495 ++++++++++++++++++++++++++----------------------------- src/ir_mctrl.h | 45 ++--- 2 files changed, 250 insertions(+), 290 deletions(-) (limited to 'src/ir_mctrl.cpp') diff --git a/src/ir_mctrl.cpp b/src/ir_mctrl.cpp index 3663216..050f941 100644 --- a/src/ir_mctrl.cpp +++ b/src/ir_mctrl.cpp @@ -16,29 +16,33 @@ void s_d_start_cb(int update_type,void* u_para) { if(update_type==MAAT_RULE_UPDATE_TYPE_FULL) { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is full",u_para); - if(!memcmp(u_para,DYNAMIC_NOMINEE_TABLE,strlen(DYNAMIC_NOMINEE_TABLE))) + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,Maat rule type is full",*(int*)u_para); + switch(*(int*)u_para) { - mctrl_g.update_type_d=MAAT_RULE_UPDATE_TYPE_FULL; - mctrl_g.version_d++; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,version:%d",u_para,mctrl_g.version_d); - } - else if(!memcmp(u_para,STATIC_NOMINEE_TABLE,strlen(STATIC_NOMINEE_TABLE))) - { - mctrl_g.update_type_s=MAAT_RULE_UPDATE_TYPE_FULL; - mctrl_g.version_s++; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,version:%d",u_para,mctrl_g.version_s); - } - else - { - mctrl_g.update_type_dp=MAAT_RULE_UPDATE_TYPE_FULL; - mctrl_g.version_dp++; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,version:%d",u_para,mctrl_g.version_dp); + case DYNAMIC_NOMINEE_FLAG: + mctrl_g.update_type_d=MAAT_RULE_UPDATE_TYPE_FULL; + mctrl_g.version_d++; + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,version:%d",*(int*)u_para,mctrl_g.version_d); + break; + case STATIC_NOMINEE_FLAG: + mctrl_g.update_type_s=MAAT_RULE_UPDATE_TYPE_FULL; + mctrl_g.version_s++; + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,version:%d",*(int*)u_para,mctrl_g.version_s); + break; + case DNAT_POLICY_FLAG: + mctrl_g.update_type_dp=MAAT_RULE_UPDATE_TYPE_FULL; + mctrl_g.version_dp++; + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,version:%d",*(int*)u_para,mctrl_g.version_dp); + break; + default: + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_start_cb", "maat_start_cb table name error!!!"); + assert(0); + break; } } else { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is inc",u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,Maat rule type is inc",*(int*)u_para); } return; } @@ -48,16 +52,16 @@ void n_i_c_start_cb(int update_type,void* u_para) { if(update_type==MAAT_RULE_UPDATE_TYPE_FULL) { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is full",u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,Maat rule type is full",*(int*)u_para); } else { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%s,Maat rule type is inc",u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,Maat rule type is inc",*(int*)u_para); } return; } -void get_cur_time(char *date) +void mctrl_get_cur_time(char *date) { time_t t; struct tm *lt; @@ -81,15 +85,15 @@ int set_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab line_rule.rule_id=rule_id; line_rule.table_name=ir_table_name; - sscanf(table_line, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &nom_info.htable_flag,&nom_info.nominee_type,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, + sscanf(table_line, "%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + &nom_info.htable_flag,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - get_cur_time(nom_info.op_time); + mctrl_get_cur_time(nom_info.op_time); - if(!memcmp(ir_table_name,NOMINEE_TABLE,strlen(NOMINEE_TABLE))) + if(!memcmp(ir_table_name,NOMINEE_TABLE_NAME,strlen(NOMINEE_TABLE_NAME))) { snprintf(m_table_line,sizeof(m_table_line),"%d\t%d\t%d\t%s\t%d\t%s\t%s", rule_id,nom_info.addr_pool_id,nom_info.addr_type,nom_info.src_ip,nom_info.is_valid,nom_info.effective_range,nom_info.op_time); @@ -135,33 +139,28 @@ int del_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab line_rule.rule_id=rule_id; line_rule.table_name=ir_table_name; line_rule.table_line=NULL; - if(!memcmp(ir_table_name,INTERCEPT_TABLE,strlen(INTERCEPT_TABLE))) + if(!memcmp(ir_table_name,NOMINEE_TABLE_NAME,strlen(NOMINEE_TABLE_NAME))) { - line_rule.expire_after=TIME_OUT; + line_rule.expire_after=0; p_line=&line_rule; - ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_RENEW_TIMEOUT); + ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_DEL); } else { - line_rule.expire_after=0; + line_rule.expire_after=TIME_OUT; p_line=&line_rule; - ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_DEL); + ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_RENEW_TIMEOUT); } MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"maat_update", "del_table_name:%s del_table_line:%s",ir_table_name,table_line); - if(ret==-1) { MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"DEL_LINE","%s:del redis line error",ir_table_name); } - else if(ret==1) - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"DEL_LINE","%s:del redis line success",ir_table_name); - } else { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"DEL_LINE","%s:del redis line not sure",ir_table_name); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"DEL_LINE","%s:del redis line success",ir_table_name); } return ret; @@ -185,23 +184,23 @@ long set_update_search_htable_cb(void *data, const uchar *key, uint size, void * if(htable_data!=NULL) { - sscanf(htable_data,"%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &nom_info.htable_flag,&nom_info.nominee_type,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, + sscanf(htable_data,"%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + &nom_info.htable_flag,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - if(nom_info.nominee_type==DYNAMIC_NOMINEE_INFO) + if(nom_info.htable_flag & DYNAMIC_NOMINEE_FLAG) { - nom_info.version=mctrl_g.version_d; + nom_info.version=mctrl_g.version_d; MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); } - else if(nom_info.nominee_type==STATIC_NOMINEE_INFO) + else if(nom_info.htable_flag & STATIC_NOMINEE_FLAG) { - nom_info.version=mctrl_g.version_s; + nom_info.version=mctrl_g.version_s; MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); } - else if(nom_info.nominee_type==DNAT_POLICY_INFO) + else if(nom_info.htable_flag & DNAT_POLICY_FLAG) { nom_info.version=mctrl_g.version_dp; MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); @@ -210,9 +209,9 @@ long set_update_search_htable_cb(void *data, const uchar *key, uint size, void * { MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d!",nom_info.htable_flag); } - - snprintf(htable_data,HTABLE_DATA_LEN, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - nom_info.htable_flag,nom_info.nominee_type,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, + + snprintf(htable_data,HTABLE_DATA_LEN, "%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + nom_info.htable_flag,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); @@ -232,46 +231,74 @@ long n_i_c_update_search_htable_cb(void *data, const uchar *key, uint size, void struct IR_MCTRL_INFO nom_info; char *htable_data=(char*)data; - if(htable_data!=NULL) + if(htable_data==NULL) { - sscanf((char*)data, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &htable_flag,&nom_info.nominee_type,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, - &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - - if(!memcmp(user_arg,INTERCEPT_TABLE,strlen(INTERCEPT_TABLE))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_C_FLAG|| - htable_flag==O_AND_N_FLAG||htable_flag==O_AND_C_AND_N_FLAG||htable_flag==D_POLICY_FLAG)) - { - htable_flag+=INTERCEPT_FLAG; - } - else if(!memcmp(user_arg,NOMINEE_TABLE,strlen(NOMINEE_TABLE))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_C_FLAG|| - htable_flag==O_AND_I_FLAG||htable_flag==O_AND_C_AND_I_FLAG)) - { - htable_flag+=NOMINEE_FLAG; - } - else if(!memcmp(user_arg,CANDIDATE_TABLE,strlen(CANDIDATE_TABLE))&&(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_N_FLAG|| - htable_flag==O_AND_I_FLAG||htable_flag==O_AND_I_AND_N_FLAG)) - { - htable_flag+=CANDIDATE_FLAG; - } - else - { + return htable_flag; + } + + sscanf((char*)data, "%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + &htable_flag,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, + nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, + nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, + &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); + + switch(*(int*)user_arg) + { + case INTERCEPT_FLAG: + if(!(htable_flag & INTERCEPT_FLAG)) + { + htable_flag+=INTERCEPT_FLAG; + } + break; + case NOMINEE_FLAG: + if(!(htable_flag & NOMINEE_FLAG)) + { + htable_flag+=NOMINEE_FLAG; + } + break; + case CANDIDATE_FLAG: + if(!(htable_flag & CANDIDATE_FLAG)) + { + htable_flag+=CANDIDATE_FLAG; + } + break; + default: MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"n_i_c_update_search_htable_cb","htable flag is:%d",htable_flag); - } - - snprintf(htable_data,HTABLE_DATA_LEN, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - htable_flag,nom_info.nominee_type,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, - nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"n_i_c_update_search_htable_cb","htable flag change:%d",htable_flag); + break; } + snprintf(htable_data,HTABLE_DATA_LEN, "%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + htable_flag,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, + nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, + nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, + nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); + + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"n_i_c_update_search_htable_cb","htable flag change:%d",htable_flag); + + return htable_flag; } +void del_redis_info(int flag,const char* table_line,int rule_id) +{ + + if(flag & INTERCEPT_FLAG) + { + del_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_TABLE_NAME,table_line,rule_id); + } + + if(flag & NOMINEE_FLAG) + { + del_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE_NAME,table_line,rule_id); + } + + if(flag & CANDIDATE_FLAG) + { + del_ir_line(mctrl_g.n_feather,(char*)CANDIDATE_TABLE_NAME,table_line,rule_id); + } + + return; +} void n_i_c_table_update_cb(int table_id,const char* table_line,void* u_para) { @@ -280,24 +307,32 @@ void n_i_c_table_update_cb(int table_id,const char* table_line,void* u_para) int is_valid=-1; long search_ret=0; - if(!memcmp(u_para,INTERCEPT_TABLE,strlen(INTERCEPT_TABLE))) - { - sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*s\t%*d\t%*d\t%d",&rule_id,&is_valid); - } - else if(!memcmp(u_para,NOMINEE_TABLE,strlen(NOMINEE_TABLE))) + switch(*(int*)u_para) { - sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%d",&rule_id,&is_valid); - } - else - { - sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%*d\t%d",&rule_id,&is_valid); + case NOMINEE_FLAG: + sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%d",&rule_id,&is_valid); + if(rule_id=D_POLICY_FLAG); - break; + set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_TABLE_NAME,table_line,rule_id); } + return; } @@ -407,65 +385,62 @@ void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) int rule_id=0; int del_ret=0; long cb_ret=0; - - if(!memcmp(u_para,DYNAMIC_NOMINEE_TABLE,strlen(DYNAMIC_NOMINEE_TABLE))) - { - sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%d\t%s\t%*d\t%d\t%d\t%*d\t%s\t%s", - &nom_info.region_id,&nom_info.addr_type,&nom_info.procotol,nom_info.src_ip,nom_info.src_port, - &nom_info.direction,nom_info.user_region,&nom_info.is_valid,&nom_info.service,nom_info.effective_range,nom_info.op_time); - - nom_info.region_id=(nom_info.region_id%1000000000)+1000000000; - nom_info.addr_pool_id=0; - nom_info.group_id=nom_info.region_id; - memcpy(nom_info.src_port,"0",sizeof("0")); - memcpy(nom_info.mask_src_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.mask_src_port,"0",sizeof("0")); - memcpy(nom_info.dst_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.mask_dst_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.dst_port,"0",sizeof("0")); - memcpy(nom_info.mask_dst_port,"0",sizeof("0")); - memcpy(nom_info.effective_range,"{}",sizeof("{}")); - nom_info.action=96; - nom_info.service=832; - nom_info.htable_flag=S_OR_D_ORIGIN_FLAG; - nom_info.nominee_type=DYNAMIC_NOMINEE_INFO; - - } - else if(!memcmp(u_para,STATIC_NOMINEE_TABLE,strlen(STATIC_NOMINEE_TABLE))) - { - sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s", - &nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, - &nom_info.action,&nom_info.service,nom_info.effective_range,nom_info.op_time); - nom_info.region_id=(nom_info.region_id%500000000)+500000000; - memcpy(nom_info.user_region,"0",sizeof("0")); - memcpy(nom_info.effective_range,"{}",sizeof("{}")); - nom_info.service=832; - nom_info.htable_flag=S_OR_D_ORIGIN_FLAG; - nom_info.nominee_type=STATIC_NOMINEE_INFO; - } - else - { - sscanf(table_line,"%d\t%d\t%s\t%s\t%d\t%*s\t%*s\t%d\t%d\t%d\t%d\t%s\t%s", - &nom_info.region_id,&nom_info.addr_type,nom_info.dst_ip,nom_info.dst_port,&nom_info.procotol, - &nom_info.do_log,&nom_info.action,&nom_info.service,&nom_info.is_valid, - nom_info.effective_range,nom_info.op_time); - nom_info.group_id=nom_info.region_id; - memcpy(nom_info.src_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.src_port,"0",sizeof("0")); - memcpy(nom_info.mask_src_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.mask_src_port,"0",sizeof("0")); - memcpy(nom_info.mask_dst_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.mask_dst_port,"0",sizeof("0")); - memcpy(nom_info.user_region,"0",sizeof("0")); - memcpy(nom_info.effective_range,"{}",sizeof("{}")); - nom_info.region_id=nom_info.region_id%500000000; - nom_info.direction=0; - nom_info.action=96; - nom_info.service=832; - nom_info.htable_flag=D_POLICY_FLAG; - nom_info.nominee_type=DNAT_POLICY_INFO; + switch(*(int*)u_para) + { + case DYNAMIC_NOMINEE_FLAG: + nom_info.addr_pool_id=0; + nom_info.group_id=nom_info.region_id; + memcpy(nom_info.src_port,"0",sizeof("0")); + memcpy(nom_info.mask_src_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(nom_info.mask_src_port,"0",sizeof("0")); + memcpy(nom_info.dst_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(nom_info.mask_dst_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(nom_info.dst_port,"0",sizeof("0")); + memcpy(nom_info.mask_dst_port,"0",sizeof("0")); + memcpy(nom_info.effective_range,"{}",sizeof("{}")); + nom_info.action=96; + nom_info.service=832; + nom_info.htable_flag=DYNAMIC_NOMINEE_FLAG; + sscanf(table_line,"%d\t%d\t%d\t%s\t%*s\t%d\t%s\t%*d\t%d\t%d\t%*d\t%*s\t%*s", + &nom_info.region_id,&nom_info.addr_type,&nom_info.procotol,nom_info.src_ip, + &nom_info.direction,nom_info.user_region,&nom_info.is_valid,&nom_info.service); + nom_info.region_id=(nom_info.region_id%SNAT_DYNAMIC_NUMBER)+SNAT_DYNAMIC_NUMBER; + break; + case STATIC_NOMINEE_FLAG: + memcpy(nom_info.user_region,"0",sizeof("0")); + memcpy(nom_info.effective_range,"{}",sizeof("{}")); + nom_info.service=832; + nom_info.htable_flag=STATIC_NOMINEE_FLAG; + sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%*d\t%*s\t%*s", + &nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, + nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, + nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, + &nom_info.action); + nom_info.region_id=(nom_info.region_id%DNAT_NUMBER)+DNAT_NUMBER; + break; + case DNAT_POLICY_FLAG: + memcpy(nom_info.src_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(nom_info.src_port,"0",sizeof("0")); + memcpy(nom_info.mask_src_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(nom_info.mask_src_port,"0",sizeof("0")); + memcpy(nom_info.mask_dst_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(nom_info.mask_dst_port,"0",sizeof("0")); + memcpy(nom_info.user_region,"0",sizeof("0")); + memcpy(nom_info.effective_range,"{}",sizeof("{}")); + nom_info.direction=0; + nom_info.action=96; + nom_info.service=832; + nom_info.htable_flag=DNAT_POLICY_FLAG; + sscanf(table_line,"%d\t%d\t%s\t%s\t%d\t%*s\t%*s\t%d\t%*d\t%*d\t%d\t%*s\t%*s", + &nom_info.region_id,&nom_info.addr_type,nom_info.dst_ip,nom_info.dst_port,&nom_info.procotol, + &nom_info.do_log,&nom_info.is_valid); + nom_info.group_id=nom_info.region_id; + nom_info.region_id=nom_info.region_id%DNAT_NUMBER; + break; + default: + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"read_snat_dnat","read_snat_or_dnat table error!!"); + assert(0); + break; } unsigned char *key_id=(unsigned char*)&nom_info.region_id; @@ -474,8 +449,8 @@ void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) if(nom_info.is_valid==1) { htable_data=(char*)malloc(HTABLE_DATA_LEN); - snprintf(htable_data,HTABLE_DATA_LEN,"%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - nom_info.htable_flag,nom_info.nominee_type,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, + snprintf(htable_data,HTABLE_DATA_LEN,"%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + nom_info.htable_flag,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); @@ -537,14 +512,14 @@ void s_d_htable_full_iterate(const uchar * key, uint size, void * data, void * u return; } - sscanf(htable_data, "%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &nom_info.htable_flag,&nom_info.nominee_type,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, + sscanf(htable_data, "%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + &nom_info.htable_flag,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - if((mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==STATIC_NOMINEE_INFO&&nom_info.version!=mctrl_g.version_s)|| - (mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==DYNAMIC_NOMINEE_INFO&&nom_info.version!=mctrl_g.version_d)|| - (mctrl_g.update_type_dp==MAAT_RULE_UPDATE_TYPE_FULL&&nom_info.nominee_type==DNAT_POLICY_INFO&&nom_info.version!=mctrl_g.version_dp)) + if((mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL&&(nom_info.htable_flag & STATIC_NOMINEE_FLAG)&&nom_info.version!=mctrl_g.version_s)|| + (mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL&&(nom_info.htable_flag & DYNAMIC_NOMINEE_FLAG)&&nom_info.version!=mctrl_g.version_d)|| + (mctrl_g.update_type_dp==MAAT_RULE_UPDATE_TYPE_FULL&&(nom_info.htable_flag & DNAT_POLICY_FLAG)&&nom_info.version!=mctrl_g.version_dp)) { del_redis_info(nom_info.htable_flag,(char*)data,nom_info.region_id); @@ -564,28 +539,28 @@ void s_d_htable_full_iterate(const uchar * key, uint size, void * data, void * u void s_d_finish_cb(void* u_para) { - if((!memcmp(u_para,DYNAMIC_NOMINEE_TABLE,strlen(DYNAMIC_NOMINEE_TABLE)))&&mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL) + if((*(int*)u_para==DYNAMIC_NOMINEE_FLAG)&&mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL) { MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_full_iterate,NULL); mctrl_g.update_type_d=MAAT_RULE_UPDATE_TYPE_INC; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,update_type:%d,finish succeed",u_para,mctrl_g.update_type_d); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%d,update_type:%d,finish succeed",*(int*)u_para,mctrl_g.update_type_d); } - else if((!memcmp(u_para,STATIC_NOMINEE_TABLE,strlen(STATIC_NOMINEE_TABLE)))&&mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL) + else if((*(int*)u_para==STATIC_NOMINEE_FLAG)&&mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL) { MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_full_iterate,NULL); mctrl_g.update_type_s=MAAT_RULE_UPDATE_TYPE_INC; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,update_type:%d,finish succeed",u_para,mctrl_g.update_type_s); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%d,update_type:%d,finish succeed",*(int*)u_para,mctrl_g.update_type_s); } - else if((!memcmp(u_para,DNAT_POLICY_TABLE,strlen(DNAT_POLICY_TABLE)))&&mctrl_g.update_type_dp==MAAT_RULE_UPDATE_TYPE_FULL) + else if((*(int*)u_para==DNAT_POLICY_FLAG)&&mctrl_g.update_type_dp==MAAT_RULE_UPDATE_TYPE_FULL) { MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_full_iterate,NULL); mctrl_g.update_type_dp=MAAT_RULE_UPDATE_TYPE_INC; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,update_type:%d,finish succeed",u_para,mctrl_g.update_type_dp); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%d,update_type:%d,finish succeed",*(int*)u_para,mctrl_g.update_type_dp); } else { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,finish succeed",u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%d,finish succeed",*(int*)u_para); } return; } @@ -593,7 +568,7 @@ void s_d_finish_cb(void* u_para) void n_i_c_finish_cb(void* u_para) { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%s,finish succeed",u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%d,finish succeed",*(int*)u_para); return; } @@ -625,7 +600,7 @@ void htable_iterate(const uchar * key, uint size, void * data, void * user) int rule_id=0; char *table_line=(char*)data; - sscanf(table_line,"%d\t%*d\t%*d\t%d",&htable_flag,&rule_id); + sscanf(table_line,"%d\t%*d\t%d",&htable_flag,&rule_id); set_redis_info(htable_flag,table_line,rule_id); @@ -705,23 +680,23 @@ void Maat_init() Maat_set_feather_opt(mctrl_g.d_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_d,MAX_STRING_LEN); Maat_set_feather_opt(mctrl_g.d_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_d,sizeof(Maat_redis_port_d)); Maat_set_feather_opt(mctrl_g.d_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_d,sizeof(Maat_redis_index_d)); - Maat_set_feather_opt(mctrl_g.d_feather, MAAT_OPT_INSTANCE_NAME, DYNAMIC_NOMINEE_TABLE, strlen(DYNAMIC_NOMINEE_TABLE)+1); + Maat_set_feather_opt(mctrl_g.d_feather, MAAT_OPT_INSTANCE_NAME, DYNAMIC_NOMINEE_TABLE_NAME, strlen(DYNAMIC_NOMINEE_TABLE_NAME)+1); Maat_set_feather_opt(mctrl_g.s_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_s,MAX_STRING_LEN); Maat_set_feather_opt(mctrl_g.s_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_s,sizeof(Maat_redis_port_s)); Maat_set_feather_opt(mctrl_g.s_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_s,sizeof(Maat_redis_index_s)); - Maat_set_feather_opt(mctrl_g.s_feather, MAAT_OPT_INSTANCE_NAME, STATIC_NOMINEE_TABLE, strlen(STATIC_NOMINEE_TABLE)+1); + Maat_set_feather_opt(mctrl_g.s_feather, MAAT_OPT_INSTANCE_NAME, STATIC_NOMINEE_TABLE_NAME, strlen(STATIC_NOMINEE_TABLE_NAME)+1); Maat_set_feather_opt(mctrl_g.i_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_i,MAX_STRING_LEN); Maat_set_feather_opt(mctrl_g.i_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_i,sizeof(Maat_redis_port_i)); Maat_set_feather_opt(mctrl_g.i_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_i,sizeof(Maat_redis_index_i)); - Maat_set_feather_opt(mctrl_g.i_feather, MAAT_OPT_INSTANCE_NAME, INTERCEPT_TABLE, strlen(INTERCEPT_TABLE)+1); + Maat_set_feather_opt(mctrl_g.i_feather, MAAT_OPT_INSTANCE_NAME, INTERCEPT_TABLE_NAME, strlen(INTERCEPT_TABLE_NAME)+1); Maat_set_feather_opt(mctrl_g.n_feather,MAAT_OPT_REDIS_IP,Maat_redis_ip_n,MAX_STRING_LEN); Maat_set_feather_opt(mctrl_g.n_feather,MAAT_OPT_REDIS_PORT,&Maat_redis_port_n,sizeof(Maat_redis_port_n)); Maat_set_feather_opt(mctrl_g.n_feather,MAAT_OPT_REDIS_INDEX,&Maat_redis_index_n,sizeof(Maat_redis_index_n)); - Maat_set_feather_opt(mctrl_g.n_feather, MAAT_OPT_INSTANCE_NAME, NOMINEE_TABLE, strlen(NOMINEE_TABLE)+1); - Maat_set_feather_opt(mctrl_g.n_feather, MAAT_OPT_INSTANCE_NAME, CANDIDATE_TABLE, strlen(CANDIDATE_TABLE)+1); + Maat_set_feather_opt(mctrl_g.n_feather, MAAT_OPT_INSTANCE_NAME, NOMINEE_TABLE_NAME, strlen(NOMINEE_TABLE_NAME)+1); + Maat_set_feather_opt(mctrl_g.n_feather, MAAT_OPT_INSTANCE_NAME, CANDIDATE_TABLE_NAME, strlen(CANDIDATE_TABLE_NAME)+1); Maat_initiate_feather(mctrl_g.d_feather); Maat_initiate_feather(mctrl_g.s_feather); @@ -763,40 +738,40 @@ int main(int argc, char * argv [ ]) Maat_init(); htable_init(); - char static_nominee[]=STATIC_NOMINEE_TABLE; - char dynamic_nominee[]=DYNAMIC_NOMINEE_TABLE; - char nominee[]=NOMINEE_TABLE; - char candidate[]=CANDIDATE_TABLE; - char intercept[]=INTERCEPT_TABLE; - char d_policy[]=DNAT_POLICY_TABLE; + int static_flag=STATIC_NOMINEE_FLAG; + int dynamic_flag=DYNAMIC_NOMINEE_FLAG; + int dnat_policy_flag=DNAT_POLICY_FLAG; + int nominee_flag=NOMINEE_FLAG; + int candidate_flag=CANDIDATE_FLAG; + int intercept_flag=INTERCEPT_FLAG; int static_id=-1; int dynamic_id=-1; + int dnat_policy_id=-1; int nominee_id=-1; int candidate_id=-1; int intercept_id=-1; - int d_policy_id=-1; - static_id=Maat_table_register(mctrl_g.s_feather,static_nominee); - dynamic_id=Maat_table_register(mctrl_g.d_feather,dynamic_nominee); - d_policy_id=Maat_table_register(mctrl_g.s_feather,d_policy); + static_id=Maat_table_register(mctrl_g.s_feather,STATIC_NOMINEE_TABLE_NAME); + dynamic_id=Maat_table_register(mctrl_g.d_feather,DYNAMIC_NOMINEE_TABLE_NAME); + dnat_policy_id=Maat_table_register(mctrl_g.s_feather,DNAT_POLICY_TABLE_NAME); - if(static_id==-1||dynamic_id==-1||d_policy_id==-1) + if(static_id==-1||dynamic_id==-1||dnat_policy_id==-1) { MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"REGISTER_TABLE","S_D_DP Database table register failed\n"); assert(0); } - read_plugin_table(mctrl_g.s_feather,STATIC_NOMINEE_TABLE,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, - static_nominee,mctrl_g.logger_handle,static_id); - read_plugin_table(mctrl_g.d_feather,DYNAMIC_NOMINEE_TABLE,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, - dynamic_nominee,mctrl_g.logger_handle,dynamic_id); - read_plugin_table(mctrl_g.s_feather,DNAT_POLICY_TABLE,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, - d_policy,mctrl_g.logger_handle,d_policy_id); + read_plugin_table(mctrl_g.s_feather,STATIC_NOMINEE_TABLE_NAME,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, + &static_flag,mctrl_g.logger_handle,static_id); + read_plugin_table(mctrl_g.d_feather,DYNAMIC_NOMINEE_TABLE_NAME,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, + &dynamic_flag,mctrl_g.logger_handle,dynamic_id); + read_plugin_table(mctrl_g.s_feather,DNAT_POLICY_TABLE_NAME,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, + &dnat_policy_flag,mctrl_g.logger_handle,dnat_policy_id); - nominee_id=Maat_table_register(mctrl_g.n_feather,nominee); - candidate_id=Maat_table_register(mctrl_g.n_feather,candidate); - intercept_id=Maat_table_register(mctrl_g.i_feather, intercept); + nominee_id=Maat_table_register(mctrl_g.n_feather,NOMINEE_TABLE_NAME); + candidate_id=Maat_table_register(mctrl_g.n_feather,CANDIDATE_TABLE_NAME); + intercept_id=Maat_table_register(mctrl_g.i_feather,INTERCEPT_TABLE_NAME); if(nominee_id==-1||candidate_id==-1||intercept_id==-1) { @@ -804,12 +779,12 @@ int main(int argc, char * argv [ ]) assert(0); } - read_plugin_table(mctrl_g.i_feather,INTERCEPT_TABLE,n_i_c_start_cb,n_i_c_table_update_cb,n_i_c_finish_cb, - intercept,mctrl_g.logger_handle,intercept_id); - read_plugin_table(mctrl_g.n_feather,NOMINEE_TABLE,n_i_c_start_cb,n_i_c_table_update_cb,n_i_c_finish_cb, - nominee,mctrl_g.logger_handle,nominee_id); - read_plugin_table(mctrl_g.n_feather,CANDIDATE_TABLE,n_i_c_start_cb,n_i_c_table_update_cb,n_i_c_finish_cb, - candidate,mctrl_g.logger_handle,candidate_id); + read_plugin_table(mctrl_g.i_feather,INTERCEPT_TABLE_NAME,n_i_c_start_cb,n_i_c_table_update_cb,n_i_c_finish_cb, + &intercept_flag,mctrl_g.logger_handle,intercept_id); + read_plugin_table(mctrl_g.n_feather,NOMINEE_TABLE_NAME,n_i_c_start_cb,n_i_c_table_update_cb,n_i_c_finish_cb, + &nominee_flag,mctrl_g.logger_handle,nominee_id); + read_plugin_table(mctrl_g.n_feather,CANDIDATE_TABLE_NAME,n_i_c_start_cb,n_i_c_table_update_cb,n_i_c_finish_cb, + &candidate_flag,mctrl_g.logger_handle,candidate_id); while(1) { diff --git a/src/ir_mctrl.h b/src/ir_mctrl.h index d409d51..ac60fcc 100644 --- a/src/ir_mctrl.h +++ b/src/ir_mctrl.h @@ -16,40 +16,26 @@ #define MCTRL_CONF_FILE "./conf/mctrl.conf" //table name -#define NOMINEE_TABLE "IR_NOMINEE_IP" -#define INTERCEPT_TABLE "IR_INTERCEPT_IP" -#define STATIC_NOMINEE_TABLE "IR_STATIC_NOMINEE_IP" -#define DYNAMIC_NOMINEE_TABLE "IR_DYNAMIC_NOMINEE_IP" -#define CANDIDATE_TABLE "IR_CANDIDATE_IP" -#define DNAT_POLICY_TABLE "IR_DNAT_POLICY" +#define STATIC_NOMINEE_TABLE_NAME "IR_STATIC_NOMINEE_IP" +#define DYNAMIC_NOMINEE_TABLE_NAME "IR_DYNAMIC_NOMINEE_IP" +#define DNAT_POLICY_TABLE_NAME "IR_DNAT_POLICY" +#define NOMINEE_TABLE_NAME "IR_NOMINEE_IP" +#define INTERCEPT_TABLE_NAME "IR_INTERCEPT_IP" +#define CANDIDATE_TABLE_NAME "IR_CANDIDATE_IP" #define SLEEP_TIME 43200 #define TIME_OUT 30 #define MAX_THREAD_NUM 1 -//nominee_type -#define STATIC_NOMINEE_INFO 1 -#define DYNAMIC_NOMINEE_INFO 2 -#define DNAT_POLICY_INFO 3 -#define NOMINEE_INFO 4 -#define INTERCEPT_INFO 5 -#define CANDIDATE_INFO 6 - -//htable flag -#define S_OR_D_ORIGIN_FLAG 8 -#define INTERCEPT_FLAG 4 -#define NOMINEE_FLAG 2 -#define CANDIDATE_FLAG 1 -#define D_POLICY_FLAG 3 - -#define DP_AND_I_FLAG 7 -#define O_AND_C_FLAG 9 -#define O_AND_N_FLAG 10 -#define O_AND_C_AND_N_FLAG 11 -#define O_AND_I_FLAG 12 -#define O_AND_C_AND_I_FLAG 13 -#define O_AND_I_AND_N_FLAG 14 -#define ALL_EXIST_FLAG 15 +#define DNAT_NUMBER 500000000 +#define SNAT_DYNAMIC_NUMBER 1000000000 +//table flag +#define STATIC_NOMINEE_FLAG 1 +#define DYNAMIC_NOMINEE_FLAG 2 +#define DNAT_POLICY_FLAG 4 +#define NOMINEE_FLAG 8 +#define INTERCEPT_FLAG 16 +#define CANDIDATE_FLAG 32 struct IR_MCTRL_INFO { @@ -75,7 +61,6 @@ struct IR_MCTRL_INFO char op_time[MAX_TIME_LEN]; int do_log; int htable_flag; - int nominee_type; int version; }; -- cgit v1.2.3 From cdc88d025275a3f0a2e4ff8450c79e1d9123284b Mon Sep 17 00:00:00 2001 From: jixinyi Date: Tue, 8 Jan 2019 15:52:58 +0800 Subject: 更新说明文档,完善日志和名称 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/ir_mctrl | Bin 48128 -> 48952 bytes ...7\264\346\230\216\346\226\207\346\241\243.docx" | Bin 28705 -> 28840 bytes src/ir_mctrl.cpp | 394 +++++++++++---------- src/ir_mctrl.h | 11 +- 4 files changed, 205 insertions(+), 200 deletions(-) (limited to 'src/ir_mctrl.cpp') diff --git a/bin/ir_mctrl b/bin/ir_mctrl index af26605..28851e5 100644 Binary files a/bin/ir_mctrl and b/bin/ir_mctrl differ diff --git "a/doc/IP\345\244\215\347\224\250\351\241\271\347\233\256mctrl\350\257\264\346\230\216\346\226\207\346\241\243.docx" "b/doc/IP\345\244\215\347\224\250\351\241\271\347\233\256mctrl\350\257\264\346\230\216\346\226\207\346\241\243.docx" index f59a0ee..7695387 100644 Binary files "a/doc/IP\345\244\215\347\224\250\351\241\271\347\233\256mctrl\350\257\264\346\230\216\346\226\207\346\241\243.docx" and "b/doc/IP\345\244\215\347\224\250\351\241\271\347\233\256mctrl\350\257\264\346\230\216\346\226\207\346\241\243.docx" differ diff --git a/src/ir_mctrl.cpp b/src/ir_mctrl.cpp index 050f941..57faac1 100644 --- a/src/ir_mctrl.cpp +++ b/src/ir_mctrl.cpp @@ -10,53 +10,53 @@ #include "ir_mctrl.h" #include "MESA_htable.h" -struct mctrl_glocal_info mctrl_g; +struct MCTRL_GLOCAL_INFO mctrl_g; -void s_d_start_cb(int update_type,void* u_para) +void sta_dyn_policy_maat_start_cb(int update_type,void* u_para) { if(update_type==MAAT_RULE_UPDATE_TYPE_FULL) { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,Maat rule type is full",*(int*)u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"sta_dyn_policy_maat_start_cb", "table_id:%d,Maat rule type is full",*(int*)u_para); switch(*(int*)u_para) { case DYNAMIC_NOMINEE_FLAG: mctrl_g.update_type_d=MAAT_RULE_UPDATE_TYPE_FULL; mctrl_g.version_d++; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,version:%d",*(int*)u_para,mctrl_g.version_d); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_DEBUG,(char*)"sta_dyn_policy_maat_start_cb", "table_id:%d,version:%d",*(int*)u_para,mctrl_g.version_d); break; case STATIC_NOMINEE_FLAG: mctrl_g.update_type_s=MAAT_RULE_UPDATE_TYPE_FULL; mctrl_g.version_s++; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,version:%d",*(int*)u_para,mctrl_g.version_s); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_DEBUG,(char*)"sta_dyn_policy_maat_start_cb", "table_id:%d,version:%d",*(int*)u_para,mctrl_g.version_s); break; case DNAT_POLICY_FLAG: mctrl_g.update_type_dp=MAAT_RULE_UPDATE_TYPE_FULL; mctrl_g.version_dp++; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,version:%d",*(int*)u_para,mctrl_g.version_dp); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_DEBUG,(char*)"sta_dyn_policy_maat_start_cb", "table_id:%d,version:%d",*(int*)u_para,mctrl_g.version_dp); break; default: - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_start_cb", "maat_start_cb table name error!!!"); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_DEBUG,(char*)"sta_dyn_policy_maat_start_cb", "maat_start_cb table id error!!!"); assert(0); break; } } else { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,Maat rule type is inc",*(int*)u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"sta_dyn_policy_maat_start_cb", "table_id:%d,Maat rule type is inc",*(int*)u_para); } return; } -void n_i_c_start_cb(int update_type,void* u_para) +void nominee_intercept_candidate_maat_start_cb(int update_type,void* u_para) { if(update_type==MAAT_RULE_UPDATE_TYPE_FULL) { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,Maat rule type is full",*(int*)u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"nominee_intercept_candidate_maat_start_cb", "table_id:%d,Maat rule type is full",*(int*)u_para); } else { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"maat_rule_type", "table_name:%d,Maat rule type is inc",*(int*)u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO,(char*)"nominee_intercept_candidate_maat_start_cb", "table_id:%d,Maat rule type is inc",*(int*)u_para); } return; } @@ -77,8 +77,8 @@ int set_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab struct Maat_line_t line_rule; int ret = 0; char m_table_line[HTABLE_DATA_LEN]; - struct IR_MCTRL_INFO nom_info; - memset(&nom_info,0,sizeof(nom_info)); + struct IR_MCTRL_INFO mctrl_info; + memset(&mctrl_info,0,sizeof(mctrl_info)); memset(&line_rule, 0,sizeof(line_rule)); line_rule.label_id=0; @@ -86,25 +86,25 @@ int set_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab line_rule.table_name=ir_table_name; sscanf(table_line, "%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &nom_info.htable_flag,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, - &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); + &mctrl_info.htable_flag,&mctrl_info.version,&mctrl_info.region_id,&mctrl_info.group_id,&mctrl_info.addr_type, + mctrl_info.src_ip,mctrl_info.mask_src_ip,mctrl_info.src_port,mctrl_info.mask_src_port,mctrl_info.dst_ip,mctrl_info.mask_dst_ip, + mctrl_info.dst_port,mctrl_info.mask_dst_port,&mctrl_info.procotol,&mctrl_info.direction,&mctrl_info.addr_pool_id,&mctrl_info.is_valid, + &mctrl_info.action,&mctrl_info.service,mctrl_info.user_region,mctrl_info.effective_range,mctrl_info.op_time); - mctrl_get_cur_time(nom_info.op_time); + mctrl_get_cur_time(mctrl_info.op_time); if(!memcmp(ir_table_name,NOMINEE_TABLE_NAME,strlen(NOMINEE_TABLE_NAME))) { snprintf(m_table_line,sizeof(m_table_line),"%d\t%d\t%d\t%s\t%d\t%s\t%s", - rule_id,nom_info.addr_pool_id,nom_info.addr_type,nom_info.src_ip,nom_info.is_valid,nom_info.effective_range,nom_info.op_time); + rule_id,mctrl_info.addr_pool_id,mctrl_info.addr_type,mctrl_info.src_ip,mctrl_info.is_valid,mctrl_info.effective_range,mctrl_info.op_time); } else { snprintf(m_table_line,sizeof(m_table_line),"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - rule_id,nom_info.group_id,nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction, - nom_info.is_valid,nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); + rule_id,mctrl_info.group_id,mctrl_info.addr_type, + mctrl_info.src_ip,mctrl_info.mask_src_ip,mctrl_info.src_port,mctrl_info.mask_src_port,mctrl_info.dst_ip,mctrl_info.mask_dst_ip, + mctrl_info.dst_port,mctrl_info.mask_dst_port,mctrl_info.procotol,mctrl_info.direction, + mctrl_info.is_valid,mctrl_info.action,mctrl_info.service,mctrl_info.user_region,mctrl_info.effective_range,mctrl_info.op_time); } line_rule.table_line=m_table_line; @@ -113,15 +113,15 @@ int set_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_ADD); - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"maat_update", "set_table_name:%s set_table_line:%s",ir_table_name,m_table_line); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"set_ir_line", "set_table_name:%s set_table_line:%s",ir_table_name,m_table_line); if(ret==-1) { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"SET_LINE","%s:set redis line error",ir_table_name); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"set_ir_line","%s:set rule_id is %d redis line error",ir_table_name,rule_id); } else { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"SET_LINE","%s:set redis line success",ir_table_name); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"set_ir_line","%s:set rule_id is %d redis line success",ir_table_name,rule_id); } return ret; } @@ -139,28 +139,28 @@ int del_ir_line(Maat_feather_t feather,const char *ir_table_name,const char *tab line_rule.rule_id=rule_id; line_rule.table_name=ir_table_name; line_rule.table_line=NULL; - if(!memcmp(ir_table_name,NOMINEE_TABLE_NAME,strlen(NOMINEE_TABLE_NAME))) + if(!memcmp(ir_table_name,INTERCEPT_TABLE_NAME,strlen(NOMINEE_TABLE_NAME))) { - line_rule.expire_after=0; + line_rule.expire_after=TIME_OUT; p_line=&line_rule; - ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_DEL); + ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_RENEW_TIMEOUT); } else { - line_rule.expire_after=TIME_OUT; + line_rule.expire_after=0; p_line=&line_rule; - ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_RENEW_TIMEOUT); + ret=Maat_cmd_set_line(feather, p_line, MAAT_OP_DEL); } - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"maat_update", "del_table_name:%s del_table_line:%s",ir_table_name,table_line); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"del_ir_line", "del_table_name:%s del_table_line:%s",ir_table_name,table_line); if(ret==-1) { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"DEL_LINE","%s:del redis line error",ir_table_name); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"del_ir_line","%s:del rule_id is %d redis line error",ir_table_name,rule_id); } else { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"DEL_LINE","%s:del redis line success",ir_table_name); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"del_ir_line","%s:del rule_id is %d redis line success",ir_table_name,rule_id); } return ret; @@ -179,56 +179,58 @@ long del_update_search_htable_cb(void *data, const uchar *key, uint size, void * long set_update_search_htable_cb(void *data, const uchar *key, uint size, void *user_arg) { - struct IR_MCTRL_INFO nom_info; + struct IR_MCTRL_INFO mctrl_info; + memset(&mctrl_info,0,sizeof(mctrl_info)); char *htable_data=(char*)data; if(htable_data!=NULL) { sscanf(htable_data,"%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &nom_info.htable_flag,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, - &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); + &mctrl_info.htable_flag,&mctrl_info.version,&mctrl_info.region_id,&mctrl_info.group_id,&mctrl_info.addr_type, + mctrl_info.src_ip,mctrl_info.mask_src_ip,mctrl_info.src_port,mctrl_info.mask_src_port,mctrl_info.dst_ip,mctrl_info.mask_dst_ip, + mctrl_info.dst_port,mctrl_info.mask_dst_port,&mctrl_info.procotol,&mctrl_info.direction,&mctrl_info.addr_pool_id,&mctrl_info.is_valid, + &mctrl_info.action,&mctrl_info.service,mctrl_info.user_region,mctrl_info.effective_range,mctrl_info.op_time); - if(nom_info.htable_flag & DYNAMIC_NOMINEE_FLAG) + if(mctrl_info.htable_flag & DYNAMIC_NOMINEE_FLAG) { - nom_info.version=mctrl_g.version_d; - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); + mctrl_info.version=mctrl_g.version_d; + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d! version:%d!",mctrl_info.htable_flag,mctrl_info.version); } - else if(nom_info.htable_flag & STATIC_NOMINEE_FLAG) + else if(mctrl_info.htable_flag & STATIC_NOMINEE_FLAG) { - nom_info.version=mctrl_g.version_s; - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); + mctrl_info.version=mctrl_g.version_s; + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d! version:%d!",mctrl_info.htable_flag,mctrl_info.version); } - else if(nom_info.htable_flag & DNAT_POLICY_FLAG) + else if(mctrl_info.htable_flag & DNAT_POLICY_FLAG) { - nom_info.version=mctrl_g.version_dp; - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d! version:%d!",nom_info.htable_flag,nom_info.version); + mctrl_info.version=mctrl_g.version_dp; + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d! version:%d!",mctrl_info.htable_flag,mctrl_info.version); } else { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d!",nom_info.htable_flag); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"set_update_search_htable_cb","get htable flag:%d!",mctrl_info.htable_flag); } snprintf(htable_data,HTABLE_DATA_LEN, "%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - nom_info.htable_flag,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, - nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); + mctrl_info.htable_flag,mctrl_info.version,mctrl_info.region_id,mctrl_info.group_id,mctrl_info.addr_type, + mctrl_info.src_ip,mctrl_info.mask_src_ip,mctrl_info.src_port,mctrl_info.mask_src_port,mctrl_info.dst_ip,mctrl_info.mask_dst_ip, + mctrl_info.dst_port,mctrl_info.mask_dst_port,mctrl_info.procotol,mctrl_info.direction,mctrl_info.addr_pool_id,mctrl_info.is_valid, + mctrl_info.action,mctrl_info.service,mctrl_info.user_region,mctrl_info.effective_range,mctrl_info.op_time); } else { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"set_update_search_htable_cb","htable info not exist!,set error!!!"); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"set_update_search_htable_cb","htable info not exist!,add htable data error!!!"); assert(0); } - return nom_info.htable_flag; + return mctrl_info.htable_flag; } -long n_i_c_update_search_htable_cb(void *data, const uchar *key, uint size, void *user_arg) +long nominee_intercept_candidate_search_htable_cb(void *data, const uchar *key, uint size, void *user_arg) { int htable_flag=0; - struct IR_MCTRL_INFO nom_info; + struct IR_MCTRL_INFO mctrl_info; + memset(&mctrl_info,0,sizeof(mctrl_info)); char *htable_data=(char*)data; if(htable_data==NULL) @@ -236,11 +238,11 @@ long n_i_c_update_search_htable_cb(void *data, const uchar *key, uint size, void return htable_flag; } - sscanf((char*)data, "%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &htable_flag,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, - &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); + sscanf(htable_data, "%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", + &htable_flag,&mctrl_info.version,&mctrl_info.region_id,&mctrl_info.group_id,&mctrl_info.addr_type, + mctrl_info.src_ip,mctrl_info.mask_src_ip,mctrl_info.src_port,mctrl_info.mask_src_port,mctrl_info.dst_ip,mctrl_info.mask_dst_ip, + mctrl_info.dst_port,mctrl_info.mask_dst_port,&mctrl_info.procotol,&mctrl_info.direction,&mctrl_info.addr_pool_id,&mctrl_info.is_valid, + &mctrl_info.action,&mctrl_info.service,mctrl_info.user_region,mctrl_info.effective_range,mctrl_info.op_time); switch(*(int*)user_arg) { @@ -263,23 +265,23 @@ long n_i_c_update_search_htable_cb(void *data, const uchar *key, uint size, void } break; default: - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"n_i_c_update_search_htable_cb","htable flag is:%d",htable_flag); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"nominee_intercept_candidate_search_htable_cb","read nom_intercept_candidate_table error!!!"); + assert(0); break; } snprintf(htable_data,HTABLE_DATA_LEN, "%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - htable_flag,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, - nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); + htable_flag,mctrl_info.version,mctrl_info.region_id,mctrl_info.group_id,mctrl_info.addr_type, + mctrl_info.src_ip,mctrl_info.mask_src_ip,mctrl_info.src_port,mctrl_info.mask_src_port,mctrl_info.dst_ip,mctrl_info.mask_dst_ip, + mctrl_info.dst_port,mctrl_info.mask_dst_port,mctrl_info.procotol,mctrl_info.direction,mctrl_info.addr_pool_id,mctrl_info.is_valid, + mctrl_info.action,mctrl_info.service,mctrl_info.user_region,mctrl_info.effective_range,mctrl_info.op_time); - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"n_i_c_update_search_htable_cb","htable flag change:%d",htable_flag); - - + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"nominee_intercept_candidate_search_htable_cb","Data rule id is:%d htable flag is:%d",mctrl_info.region_id, htable_flag); + return htable_flag; } -void del_redis_info(int flag,const char* table_line,int rule_id) +void del_ir_redis_info(int flag,const char* table_line,int rule_id) { if(flag & INTERCEPT_FLAG) @@ -300,7 +302,7 @@ void del_redis_info(int flag,const char* table_line,int rule_id) return; } -void n_i_c_table_update_cb(int table_id,const char* table_line,void* u_para) +void nominee_intercept_candidate_maat_update_cb(int table_id,const char* table_line,void* u_para) { int rule_id=0; void *htable_data=NULL; @@ -323,7 +325,7 @@ void n_i_c_table_update_cb(int table_id,const char* table_line,void* u_para) sscanf(table_line,"%d\t%*d\t%*d\t%*s\t%*d\t%d",&rule_id,&is_valid); break; default: - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"READ_TABLE_UPDATA","read n_i_c_table error!!!"); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"nominee_intercept_candidate_maat_update_cb","read nom_intercept_candidate_table flag error!!!"); assert(0); break; } @@ -332,19 +334,20 @@ void n_i_c_table_update_cb(int table_id,const char* table_line,void* u_para) if(is_valid==0) { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"READ_TABLE_UPDATA"," del table_name:%d,data:%s is_valid==0,del succeed",*(int*)u_para,table_line); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"nominee_intercept_candidate_maat_update_cb"," del table_id:%d,data:%s is_valid==0,del succeed",*(int*)u_para,table_line); return; } - htable_data=MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id), n_i_c_update_search_htable_cb,u_para,&search_ret); + htable_data=MESA_htable_search_cb(mctrl_g.mctrl_htable_handle,key_id,sizeof(rule_id), nominee_intercept_candidate_search_htable_cb,u_para,&search_ret); if(htable_data==NULL) { - del_redis_info(*(int*)u_para,table_line,rule_id); + del_ir_redis_info(*(int*)u_para,table_line,rule_id); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"nominee_intercept_candidate_maat_update_cb","htable data not exist,del it!"); } else { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"READ_TABLE_UPDATA","already exist!"); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"nominee_intercept_candidate_maat_update_cb","htable data exist!"); } return; } @@ -353,14 +356,14 @@ void htable_data_free(void *data) { if(data!=NULL) { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"DATA_FREE","htable_data_free!"); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"htable_data_free","htable_data_free!"); free(data); data=NULL; } return; } -void set_redis_info(int flag,const char* table_line,int rule_id) +void set_ir_redis_info(int flag,const char* table_line,int rule_id) { if(!(flag & INTERCEPT_FLAG)) { @@ -375,11 +378,11 @@ void set_redis_info(int flag,const char* table_line,int rule_id) return; } -void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) +void sta_dyn_policy_maat_update_cb(int table_id,const char* table_line,void* u_para) { int add_ret=0; - struct IR_MCTRL_INFO nom_info; - memset(&nom_info,0,sizeof(nom_info)); + struct IR_MCTRL_INFO mctrl_info; + memset(&mctrl_info,0,sizeof(mctrl_info)); char *htable_data=NULL; void *search_result=NULL; int rule_id=0; @@ -388,192 +391,193 @@ void s_d_table_update_cb(int table_id,const char* table_line,void* u_para) switch(*(int*)u_para) { case DYNAMIC_NOMINEE_FLAG: - nom_info.addr_pool_id=0; - nom_info.group_id=nom_info.region_id; - memcpy(nom_info.src_port,"0",sizeof("0")); - memcpy(nom_info.mask_src_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.mask_src_port,"0",sizeof("0")); - memcpy(nom_info.dst_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.mask_dst_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.dst_port,"0",sizeof("0")); - memcpy(nom_info.mask_dst_port,"0",sizeof("0")); - memcpy(nom_info.effective_range,"{}",sizeof("{}")); - nom_info.action=96; - nom_info.service=832; - nom_info.htable_flag=DYNAMIC_NOMINEE_FLAG; + mctrl_info.addr_pool_id=0; + memcpy(mctrl_info.src_port,"0",sizeof("0")); + memcpy(mctrl_info.mask_src_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(mctrl_info.mask_src_port,"0",sizeof("0")); + memcpy(mctrl_info.dst_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(mctrl_info.mask_dst_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(mctrl_info.dst_port,"0",sizeof("0")); + memcpy(mctrl_info.mask_dst_port,"0",sizeof("0")); + memcpy(mctrl_info.effective_range,"{}",sizeof("{}")); + mctrl_info.action=96; + mctrl_info.service=832; + mctrl_info.htable_flag=DYNAMIC_NOMINEE_FLAG; sscanf(table_line,"%d\t%d\t%d\t%s\t%*s\t%d\t%s\t%*d\t%d\t%d\t%*d\t%*s\t%*s", - &nom_info.region_id,&nom_info.addr_type,&nom_info.procotol,nom_info.src_ip, - &nom_info.direction,nom_info.user_region,&nom_info.is_valid,&nom_info.service); - nom_info.region_id=(nom_info.region_id%SNAT_DYNAMIC_NUMBER)+SNAT_DYNAMIC_NUMBER; + &mctrl_info.region_id,&mctrl_info.addr_type,&mctrl_info.procotol,mctrl_info.src_ip, + &mctrl_info.direction,mctrl_info.user_region,&mctrl_info.is_valid,&mctrl_info.service); + mctrl_info.region_id=(mctrl_info.region_id%SNAT_DYNAMIC_NUMBER)+SNAT_DYNAMIC_NUMBER; + mctrl_info.group_id=mctrl_info.region_id; break; case STATIC_NOMINEE_FLAG: - memcpy(nom_info.user_region,"0",sizeof("0")); - memcpy(nom_info.effective_range,"{}",sizeof("{}")); - nom_info.service=832; - nom_info.htable_flag=STATIC_NOMINEE_FLAG; + memcpy(mctrl_info.user_region,"0",sizeof("0")); + memcpy(mctrl_info.effective_range,"{}",sizeof("{}")); + mctrl_info.service=832; + mctrl_info.htable_flag=STATIC_NOMINEE_FLAG; sscanf(table_line,"%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%*d\t%*s\t%*s", - &nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, - &nom_info.action); - nom_info.region_id=(nom_info.region_id%DNAT_NUMBER)+DNAT_NUMBER; + &mctrl_info.region_id,&mctrl_info.group_id,&mctrl_info.addr_type, + mctrl_info.src_ip,mctrl_info.mask_src_ip,mctrl_info.src_port,mctrl_info.mask_src_port,mctrl_info.dst_ip,mctrl_info.mask_dst_ip, + mctrl_info.dst_port,mctrl_info.mask_dst_port,&mctrl_info.procotol,&mctrl_info.direction,&mctrl_info.addr_pool_id,&mctrl_info.is_valid, + &mctrl_info.action); + mctrl_info.region_id=(mctrl_info.region_id%DNAT_NUMBER)+DNAT_NUMBER; break; case DNAT_POLICY_FLAG: - memcpy(nom_info.src_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.src_port,"0",sizeof("0")); - memcpy(nom_info.mask_src_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.mask_src_port,"0",sizeof("0")); - memcpy(nom_info.mask_dst_ip,"0.0.0.0",sizeof("0.0.0.0")); - memcpy(nom_info.mask_dst_port,"0",sizeof("0")); - memcpy(nom_info.user_region,"0",sizeof("0")); - memcpy(nom_info.effective_range,"{}",sizeof("{}")); - nom_info.direction=0; - nom_info.action=96; - nom_info.service=832; - nom_info.htable_flag=DNAT_POLICY_FLAG; + memcpy(mctrl_info.src_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(mctrl_info.src_port,"0",sizeof("0")); + memcpy(mctrl_info.mask_src_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(mctrl_info.mask_src_port,"0",sizeof("0")); + memcpy(mctrl_info.mask_dst_ip,"0.0.0.0",sizeof("0.0.0.0")); + memcpy(mctrl_info.mask_dst_port,"0",sizeof("0")); + memcpy(mctrl_info.user_region,"0",sizeof("0")); + memcpy(mctrl_info.effective_range,"{}",sizeof("{}")); + mctrl_info.direction=0; + mctrl_info.action=96; + mctrl_info.service=832; + mctrl_info.htable_flag=DNAT_POLICY_FLAG; sscanf(table_line,"%d\t%d\t%s\t%s\t%d\t%*s\t%*s\t%d\t%*d\t%*d\t%d\t%*s\t%*s", - &nom_info.region_id,&nom_info.addr_type,nom_info.dst_ip,nom_info.dst_port,&nom_info.procotol, - &nom_info.do_log,&nom_info.is_valid); - nom_info.group_id=nom_info.region_id; - nom_info.region_id=nom_info.region_id%DNAT_NUMBER; + &mctrl_info.region_id,&mctrl_info.addr_type,mctrl_info.dst_ip,mctrl_info.dst_port,&mctrl_info.procotol, + &mctrl_info.do_log,&mctrl_info.is_valid); + mctrl_info.group_id=mctrl_info.region_id; + mctrl_info.region_id=mctrl_info.region_id%DNAT_NUMBER; break; default: - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"read_snat_dnat","read_snat_or_dnat table error!!"); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"sta_dyn_policy_maat_update_cb","read_snat_or_dnat table flag error!!"); assert(0); break; } - unsigned char *key_id=(unsigned char*)&nom_info.region_id; - rule_id=nom_info.region_id; + unsigned char *key_id=(unsigned char*)&mctrl_info.region_id; + rule_id=mctrl_info.region_id; - if(nom_info.is_valid==1) + if(mctrl_info.is_valid==1) { htable_data=(char*)malloc(HTABLE_DATA_LEN); snprintf(htable_data,HTABLE_DATA_LEN,"%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - nom_info.htable_flag,nom_info.version,nom_info.region_id,nom_info.group_id,nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,nom_info.procotol,nom_info.direction,nom_info.addr_pool_id,nom_info.is_valid, - nom_info.action,nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); + mctrl_info.htable_flag,mctrl_info.version,mctrl_info.region_id,mctrl_info.group_id,mctrl_info.addr_type, + mctrl_info.src_ip,mctrl_info.mask_src_ip,mctrl_info.src_port,mctrl_info.mask_src_port,mctrl_info.dst_ip,mctrl_info.mask_dst_ip, + mctrl_info.dst_port,mctrl_info.mask_dst_port,mctrl_info.procotol,mctrl_info.direction,mctrl_info.addr_pool_id,mctrl_info.is_valid, + mctrl_info.action,mctrl_info.service,mctrl_info.user_region,mctrl_info.effective_range,mctrl_info.op_time); - add_ret=MESA_htable_add(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_data); + add_ret=MESA_htable_add(mctrl_g.mctrl_htable_handle,key_id,sizeof(rule_id),htable_data); if(add_ret<0) { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"ADD_S_AND_D_NOMINEE_HASH","add htable error:%d",add_ret); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"sta_dyn_policy_maat_update_cb","add htable error:%d",add_ret); } else { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"ADD_S_AND_D_NOMINEE_HASH","add htable succeed:%d",add_ret); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"sta_dyn_policy_maat_update_cb","add htable succeed:%d",add_ret); } - - MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id),set_update_search_htable_cb,NULL,&cb_ret); + MESA_htable_search_cb(mctrl_g.mctrl_htable_handle,key_id,sizeof(rule_id),set_update_search_htable_cb,NULL,&cb_ret); - set_redis_info(cb_ret,htable_data,rule_id); + set_ir_redis_info(cb_ret,htable_data,rule_id); } - else if(nom_info.is_valid==0) + else if(mctrl_info.is_valid==0) { - search_result=MESA_htable_search_cb(mctrl_g.s_d_htable,key_id,sizeof(rule_id),del_update_search_htable_cb,NULL,&cb_ret); + search_result=MESA_htable_search_cb(mctrl_g.mctrl_htable_handle,key_id,sizeof(rule_id),del_update_search_htable_cb,NULL,&cb_ret); if(search_result==NULL) { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"write_update", "already del!!!"); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"sta_dyn_policy_maat_update_cb", "already del!!!"); return; } - del_redis_info(cb_ret,table_line,rule_id); + del_ir_redis_info(cb_ret,table_line,rule_id); - del_ret=MESA_htable_del(mctrl_g.s_d_htable,key_id,sizeof(rule_id),htable_data_free); + del_ret=MESA_htable_del(mctrl_g.mctrl_htable_handle,key_id,sizeof(rule_id),htable_data_free); if(del_ret<0) { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"DEL_S_AND_D_NOMINEE","del htable error:%d",del_ret); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"sta_dyn_policy_maat_update_cb","del htable error:%d",del_ret); + assert(0); } } else { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"write_update", "is_valid default !!!"); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"sta_dyn_policy_maat_update_cb", "is_valid default !!!"); assert(0); } return; } -void s_d_htable_full_iterate(const uchar * key, uint size, void * data, void * user) +void sta_dyn_policy_htable_full_iterate(const uchar * key, uint size, void * data, void * user) { - struct IR_MCTRL_INFO nom_info; - memset(&nom_info,0,sizeof(nom_info)); + struct IR_MCTRL_INFO mctrl_info; + memset(&mctrl_info,0,sizeof(mctrl_info)); char *htable_data=(char*)data; int del_ret=0; if(htable_data==NULL) { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"search_s_d_htable","htable is null"); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"sta_dyn_policy_htable_full_iterate","htable is null"); return; } sscanf(htable_data, "%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", - &nom_info.htable_flag,&nom_info.version,&nom_info.region_id,&nom_info.group_id,&nom_info.addr_type, - nom_info.src_ip,nom_info.mask_src_ip,nom_info.src_port,nom_info.mask_src_port,nom_info.dst_ip,nom_info.mask_dst_ip, - nom_info.dst_port,nom_info.mask_dst_port,&nom_info.procotol,&nom_info.direction,&nom_info.addr_pool_id,&nom_info.is_valid, - &nom_info.action,&nom_info.service,nom_info.user_region,nom_info.effective_range,nom_info.op_time); - if((mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL&&(nom_info.htable_flag & STATIC_NOMINEE_FLAG)&&nom_info.version!=mctrl_g.version_s)|| - (mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL&&(nom_info.htable_flag & DYNAMIC_NOMINEE_FLAG)&&nom_info.version!=mctrl_g.version_d)|| - (mctrl_g.update_type_dp==MAAT_RULE_UPDATE_TYPE_FULL&&(nom_info.htable_flag & DNAT_POLICY_FLAG)&&nom_info.version!=mctrl_g.version_dp)) + &mctrl_info.htable_flag,&mctrl_info.version,&mctrl_info.region_id,&mctrl_info.group_id,&mctrl_info.addr_type, + mctrl_info.src_ip,mctrl_info.mask_src_ip,mctrl_info.src_port,mctrl_info.mask_src_port,mctrl_info.dst_ip,mctrl_info.mask_dst_ip, + mctrl_info.dst_port,mctrl_info.mask_dst_port,&mctrl_info.procotol,&mctrl_info.direction,&mctrl_info.addr_pool_id,&mctrl_info.is_valid, + &mctrl_info.action,&mctrl_info.service,mctrl_info.user_region,mctrl_info.effective_range,mctrl_info.op_time); + if((mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL&&(mctrl_info.htable_flag & STATIC_NOMINEE_FLAG)&&mctrl_info.version!=mctrl_g.version_s)|| + (mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL&&(mctrl_info.htable_flag & DYNAMIC_NOMINEE_FLAG)&&mctrl_info.version!=mctrl_g.version_d)|| + (mctrl_g.update_type_dp==MAAT_RULE_UPDATE_TYPE_FULL&&(mctrl_info.htable_flag & DNAT_POLICY_FLAG)&&mctrl_info.version!=mctrl_g.version_dp)) { - del_redis_info(nom_info.htable_flag,(char*)data,nom_info.region_id); + del_ir_redis_info(mctrl_info.htable_flag,(char*)data,mctrl_info.region_id); - unsigned char *key_id=(unsigned char*)&nom_info.region_id; + unsigned char *key_id=(unsigned char*)&mctrl_info.region_id; - del_ret=MESA_htable_del(mctrl_g.s_d_htable,key_id,sizeof(int),htable_data_free); + del_ret=MESA_htable_del(mctrl_g.mctrl_htable_handle,key_id,sizeof(int),htable_data_free); if(del_ret<0) { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"DEL_S_AND_D_NOMINEE","del htable error:%d",del_ret); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"sta_dyn_policy_htable_full_iterate","del htable error:%d",del_ret); + assert(0); } } return; } -void s_d_finish_cb(void* u_para) +void sta_dyn_policy_maat_finish_cb(void* u_para) { if((*(int*)u_para==DYNAMIC_NOMINEE_FLAG)&&mctrl_g.update_type_d==MAAT_RULE_UPDATE_TYPE_FULL) { - MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_full_iterate,NULL); + MESA_htable_iterate(mctrl_g.mctrl_htable_handle, sta_dyn_policy_htable_full_iterate,NULL); mctrl_g.update_type_d=MAAT_RULE_UPDATE_TYPE_INC; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%d,update_type:%d,finish succeed",*(int*)u_para,mctrl_g.update_type_d); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_DEBUG, (char*)"sta_dyn_policy_maat_finish_cb", "table_id:%d,update_type:%d,finish succeed",*(int*)u_para,mctrl_g.update_type_d); } else if((*(int*)u_para==STATIC_NOMINEE_FLAG)&&mctrl_g.update_type_s==MAAT_RULE_UPDATE_TYPE_FULL) { - MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_full_iterate,NULL); + MESA_htable_iterate(mctrl_g.mctrl_htable_handle, sta_dyn_policy_htable_full_iterate,NULL); mctrl_g.update_type_s=MAAT_RULE_UPDATE_TYPE_INC; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%d,update_type:%d,finish succeed",*(int*)u_para,mctrl_g.update_type_s); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_DEBUG, (char*)"sta_dyn_policy_maat_finish_cb", "table_id:%d,update_type:%d,finish succeed",*(int*)u_para,mctrl_g.update_type_s); } else if((*(int*)u_para==DNAT_POLICY_FLAG)&&mctrl_g.update_type_dp==MAAT_RULE_UPDATE_TYPE_FULL) { - MESA_htable_iterate(mctrl_g.s_d_htable, s_d_htable_full_iterate,NULL); + MESA_htable_iterate(mctrl_g.mctrl_htable_handle, sta_dyn_policy_htable_full_iterate,NULL); mctrl_g.update_type_dp=MAAT_RULE_UPDATE_TYPE_INC; - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%d,update_type:%d,finish succeed",*(int*)u_para,mctrl_g.update_type_dp); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_DEBUG, (char*)"sta_dyn_policy_maat_finish_cb", "table_id:%d,update_type:%d,finish succeed",*(int*)u_para,mctrl_g.update_type_dp); } else { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%d,finish succeed",*(int*)u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"sta_dyn_policy_maat_finish_cb", "table_id:%d,finish succeed",*(int*)u_para); } return; } -void n_i_c_finish_cb(void* u_para) +void nominee_intercept_candidate_maat_finish_cb(void* u_para) { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"maat_finish", "table_name:%d,finish succeed",*(int*)u_para); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_INFO, (char*)"nominee_intercept_candidate_maat_finish_cb", "table_id:%d,finish succeed",*(int*)u_para); return; } -int read_plugin_table(Maat_feather_t feather,const char* table_name, +int register_plugin_table(Maat_feather_t feather,const char* table_name, Maat_start_callback_t *start,Maat_update_callback_t *update,Maat_finish_callback_t *finish, void *u_para,void* logger,int table_id) { @@ -586,7 +590,7 @@ int read_plugin_table(Maat_feather_t feather,const char* table_name, u_para); if(ret<0) { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"REGISTER_TABLE", "Maat callback register table %s error.\n",table_name); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL, (char*)"register_plugin_table", "Maat callback register table %s error.\n",table_name); assert(0); } @@ -602,7 +606,7 @@ void htable_iterate(const uchar * key, uint size, void * data, void * user) sscanf(table_line,"%d\t%*d\t%d",&htable_flag,&rule_id); - set_redis_info(htable_flag,table_line,rule_id); + set_ir_redis_info(htable_flag,table_line,rule_id); return; } @@ -641,21 +645,21 @@ void Maat_init() MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section,"logger_level", &logger_level,RLOG_LV_FATAL); MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section,"max_thread_num", &max_thread_num, 1); //dynamic server conf - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_ip", Maat_redis_ip_d, sizeof(Maat_redis_ip_d), "127.0.0.1"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_port", &Maat_redis_port_d,6379); + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_ip", Maat_redis_ip_d, sizeof(Maat_redis_ip_d), "192.168.11.243"); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_port", &Maat_redis_port_d,6800); MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_d,"Maat_redis_index", &Maat_redis_index_d,1); //static server conf - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_s, "Maat_redis_ip", Maat_redis_ip_s, sizeof(Maat_redis_ip_s), "127.0.0.1"); + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_s, "Maat_redis_ip", Maat_redis_ip_s, sizeof(Maat_redis_ip_s), "192.168.11.243"); MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_s,"Maat_redis_port", &Maat_redis_port_s,6379); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_s,"Maat_redis_index", &Maat_redis_index_s,0); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_s,"Maat_redis_index", &Maat_redis_index_s,6); //nominee and candate conf - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_n,"Maat_redis_ip", Maat_redis_ip_n, sizeof(Maat_redis_ip_n), "127.0.0.1"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_n,"Maat_redis_port", &Maat_redis_port_n,6379); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_n,"Maat_redis_index", &Maat_redis_index_n,0); + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_n,"Maat_redis_ip", Maat_redis_ip_n, sizeof(Maat_redis_ip_n), "192.168.11.243"); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_n,"Maat_redis_port", &Maat_redis_port_n,6800); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_n,"Maat_redis_index", &Maat_redis_index_n,5); //intercept conf - MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_i,"Maat_redis_ip", Maat_redis_ip_i, sizeof(Maat_redis_ip_i), "127.0.0.1"); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_i,"Maat_redis_port", &Maat_redis_port_i,6379); - MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_i,"Maat_redis_index", &Maat_redis_index_i,0); + MESA_load_profile_string_def((char*)MCTRL_CONF_FILE, section_i,"Maat_redis_ip", Maat_redis_ip_i, sizeof(Maat_redis_ip_i), "192.168.11.243"); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_i,"Maat_redis_port", &Maat_redis_port_i,6800); + MESA_load_profile_int_def((char*)MCTRL_CONF_FILE, section_i,"Maat_redis_index", &Maat_redis_index_i,1); //log mctrl_g.logger_handle=MESA_create_runtime_log_handle(logger_path,logger_level); @@ -709,15 +713,15 @@ void Maat_init() int htable_init() { int htable_ret=0; - mctrl_g.s_d_htable = MESA_htable_born(); - if(mctrl_g.s_d_htable == NULL) + mctrl_g.mctrl_htable_handle = MESA_htable_born(); + if(mctrl_g.mctrl_htable_handle == NULL) { MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"htable","htable born failed"); assert(0); return -1; } - htable_ret = MESA_htable_mature(mctrl_g.s_d_htable); + htable_ret = MESA_htable_mature(mctrl_g.mctrl_htable_handle); if(0 == htable_ret) { @@ -758,15 +762,15 @@ int main(int argc, char * argv [ ]) if(static_id==-1||dynamic_id==-1||dnat_policy_id==-1) { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"REGISTER_TABLE","S_D_DP Database table register failed\n"); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"main","Sta_Dyn_policy Database table register failed\n"); assert(0); } - read_plugin_table(mctrl_g.s_feather,STATIC_NOMINEE_TABLE_NAME,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, + register_plugin_table(mctrl_g.s_feather,STATIC_NOMINEE_TABLE_NAME,sta_dyn_policy_maat_start_cb,sta_dyn_policy_maat_update_cb,sta_dyn_policy_maat_finish_cb, &static_flag,mctrl_g.logger_handle,static_id); - read_plugin_table(mctrl_g.d_feather,DYNAMIC_NOMINEE_TABLE_NAME,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, + register_plugin_table(mctrl_g.d_feather,DYNAMIC_NOMINEE_TABLE_NAME,sta_dyn_policy_maat_start_cb,sta_dyn_policy_maat_update_cb,sta_dyn_policy_maat_finish_cb, &dynamic_flag,mctrl_g.logger_handle,dynamic_id); - read_plugin_table(mctrl_g.s_feather,DNAT_POLICY_TABLE_NAME,s_d_start_cb,s_d_table_update_cb,s_d_finish_cb, + register_plugin_table(mctrl_g.s_feather,DNAT_POLICY_TABLE_NAME,sta_dyn_policy_maat_start_cb,sta_dyn_policy_maat_update_cb,sta_dyn_policy_maat_finish_cb, &dnat_policy_flag,mctrl_g.logger_handle,dnat_policy_id); nominee_id=Maat_table_register(mctrl_g.n_feather,NOMINEE_TABLE_NAME); @@ -775,20 +779,20 @@ int main(int argc, char * argv [ ]) if(nominee_id==-1||candidate_id==-1||intercept_id==-1) { - MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"REGISTER_TABLE","N_C_I Database table register failed\n"); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"main","Nom_Candidate_Intercept Database table register failed\n"); assert(0); } - read_plugin_table(mctrl_g.i_feather,INTERCEPT_TABLE_NAME,n_i_c_start_cb,n_i_c_table_update_cb,n_i_c_finish_cb, + register_plugin_table(mctrl_g.i_feather,INTERCEPT_TABLE_NAME,nominee_intercept_candidate_maat_start_cb,nominee_intercept_candidate_maat_update_cb,nominee_intercept_candidate_maat_finish_cb, &intercept_flag,mctrl_g.logger_handle,intercept_id); - read_plugin_table(mctrl_g.n_feather,NOMINEE_TABLE_NAME,n_i_c_start_cb,n_i_c_table_update_cb,n_i_c_finish_cb, + register_plugin_table(mctrl_g.n_feather,NOMINEE_TABLE_NAME,nominee_intercept_candidate_maat_start_cb,nominee_intercept_candidate_maat_update_cb,nominee_intercept_candidate_maat_finish_cb, &nominee_flag,mctrl_g.logger_handle,nominee_id); - read_plugin_table(mctrl_g.n_feather,CANDIDATE_TABLE_NAME,n_i_c_start_cb,n_i_c_table_update_cb,n_i_c_finish_cb, + register_plugin_table(mctrl_g.n_feather,CANDIDATE_TABLE_NAME,nominee_intercept_candidate_maat_start_cb,nominee_intercept_candidate_maat_update_cb,nominee_intercept_candidate_maat_finish_cb, &candidate_flag,mctrl_g.logger_handle,candidate_id); while(1) { - MESA_htable_iterate(mctrl_g.s_d_htable, htable_iterate, NULL); + MESA_htable_iterate(mctrl_g.mctrl_htable_handle, htable_iterate, NULL); sleep(SLEEP_TIME); } @@ -797,7 +801,7 @@ int main(int argc, char * argv [ ]) Maat_burn_feather(mctrl_g.i_feather); Maat_burn_feather(mctrl_g.n_feather); MESA_destroy_runtime_log_handle(mctrl_g.logger_handle); - MESA_htable_destroy(mctrl_g.s_d_htable,htable_data_free); + MESA_htable_destroy(mctrl_g.mctrl_htable_handle,htable_data_free); return 0; } diff --git a/src/ir_mctrl.h b/src/ir_mctrl.h index ac60fcc..6a42a98 100644 --- a/src/ir_mctrl.h +++ b/src/ir_mctrl.h @@ -10,7 +10,7 @@ #define MAX_PORT_LEN 6 #define MAX_PATH_LEN 64 #define MAX_TABLE_NAME_LEN 64 -#define MAX_TIME_LEN 30 +#define MAX_TIME_LEN 40 #define HTABLE_DATA_LEN 512 #define MCTRL_CONF_FILE "./conf/mctrl.conf" @@ -24,11 +24,12 @@ #define CANDIDATE_TABLE_NAME "IR_CANDIDATE_IP" #define SLEEP_TIME 43200 -#define TIME_OUT 30 -#define MAX_THREAD_NUM 1 +#define TIME_OUT 1800 +#define MAX_THREAD_NUM 1 #define DNAT_NUMBER 500000000 #define SNAT_DYNAMIC_NUMBER 1000000000 + //table flag #define STATIC_NOMINEE_FLAG 1 #define DYNAMIC_NOMINEE_FLAG 2 @@ -64,14 +65,14 @@ struct IR_MCTRL_INFO int version; }; -struct mctrl_glocal_info +struct MCTRL_GLOCAL_INFO { void *logger_handle; Maat_feather_t d_feather; Maat_feather_t s_feather; Maat_feather_t n_feather; Maat_feather_t i_feather; - MESA_htable_handle s_d_htable; + MESA_htable_handle mctrl_htable_handle; int update_type_s; int update_type_d; int update_type_dp; -- cgit v1.2.3 From 81457afe6bba22c1cc6c90c0067915e2379746f1 Mon Sep 17 00:00:00 2001 From: jixinyi Date: Mon, 14 Jan 2019 10:55:21 +0800 Subject: 适应修改后DNAT_POLICY库表 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/conf/table_info.conf | 10 ++++++---- bin/ir_mctrl | Bin 48952 -> 48952 bytes src/ir_mctrl.cpp | 5 ++++- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src/ir_mctrl.cpp') diff --git a/bin/conf/table_info.conf b/bin/conf/table_info.conf index c66db3a..3a13540 100644 --- a/bin/conf/table_info.conf +++ b/bin/conf/table_info.conf @@ -17,8 +17,10 @@ #id name type src_charset dst_charset do_merge cross_cache quick_mode 0 IR_STATIC_NOMINEE_IP plugin 15 -- 1 IR_DYNAMIC_NOMINEE_IP plugin 9 -- -2 IR_NOMINEE_IP plugin 5 -- -3 IR_CANDIDATE_IP plugin 6 -- -4 IR_INTERCEPT_IP plugin 14 -- -5 IR_DNAT_POLICY plugin 11 -- +2 IR_DNAT_POLICY plugin 12 -- +3 IR_INTERCEPT_IP plugin 14 -- +4 IR_NOMINEE_IP plugin 5 -- +5 IR_CANDIDATE_IP plugin 6 -- + + diff --git a/bin/ir_mctrl b/bin/ir_mctrl index 28851e5..39db09f 100644 Binary files a/bin/ir_mctrl and b/bin/ir_mctrl differ diff --git a/src/ir_mctrl.cpp b/src/ir_mctrl.cpp index 57faac1..2c1fc96 100644 --- a/src/ir_mctrl.cpp +++ b/src/ir_mctrl.cpp @@ -434,7 +434,7 @@ void sta_dyn_policy_maat_update_cb(int table_id,const char* table_line,void* u_p mctrl_info.action=96; mctrl_info.service=832; mctrl_info.htable_flag=DNAT_POLICY_FLAG; - sscanf(table_line,"%d\t%d\t%s\t%s\t%d\t%*s\t%*s\t%d\t%*d\t%*d\t%d\t%*s\t%*s", + sscanf(table_line,"%d\t%d\t%s\t%s\t%d\t%*s\t%*s\t%*s\t%d\t%*d\t%*d\t%d\t%*s\t%*s", &mctrl_info.region_id,&mctrl_info.addr_type,mctrl_info.dst_ip,mctrl_info.dst_port,&mctrl_info.procotol, &mctrl_info.do_log,&mctrl_info.is_valid); mctrl_info.group_id=mctrl_info.region_id; @@ -777,6 +777,9 @@ int main(int argc, char * argv [ ]) candidate_id=Maat_table_register(mctrl_g.n_feather,CANDIDATE_TABLE_NAME); intercept_id=Maat_table_register(mctrl_g.i_feather,INTERCEPT_TABLE_NAME); + MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"main","static table_id is:%d,dy_id is:%d,dp_id is:%d,nominee_table_id is:%d,intercept_table_id is:%d,candidate_table_id is:%d", + static_id,dynamic_id,dnat_policy_id,nominee_id,intercept_id,candidate_id); + if(nominee_id==-1||candidate_id==-1||intercept_id==-1) { MESA_handle_runtime_log(mctrl_g.logger_handle,RLOG_LV_FATAL,(char*)"main","Nom_Candidate_Intercept Database table register failed\n"); -- cgit v1.2.3 From 263cdc86b5b2f58bd3003f0af3234bc4ea4690a4 Mon Sep 17 00:00:00 2001 From: jixinyi Date: Thu, 17 Jan 2019 17:55:21 +0800 Subject: 适应修改后DNAT_POLICY库表 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/ir_mctrl | Bin 48952 -> 48888 bytes src/ir_mctrl.cpp | 42 ++++++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 20 deletions(-) (limited to 'src/ir_mctrl.cpp') diff --git a/bin/ir_mctrl b/bin/ir_mctrl index 39db09f..24c655c 100644 Binary files a/bin/ir_mctrl and b/bin/ir_mctrl differ diff --git a/src/ir_mctrl.cpp b/src/ir_mctrl.cpp index 2c1fc96..83f7820 100644 --- a/src/ir_mctrl.cpp +++ b/src/ir_mctrl.cpp @@ -217,11 +217,6 @@ long set_update_search_htable_cb(void *data, const uchar *key, uint size, void * mctrl_info.dst_port,mctrl_info.mask_dst_port,mctrl_info.procotol,mctrl_info.direction,mctrl_info.addr_pool_id,mctrl_info.is_valid, mctrl_info.action,mctrl_info.service,mctrl_info.user_region,mctrl_info.effective_range,mctrl_info.op_time); } - else - { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"set_update_search_htable_cb","htable info not exist!,add htable data error!!!"); - assert(0); - } return mctrl_info.htable_flag; } @@ -343,11 +338,11 @@ void nominee_intercept_candidate_maat_update_cb(int table_id,const char* table_l if(htable_data==NULL) { del_ir_redis_info(*(int*)u_para,table_line,rule_id); - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"nominee_intercept_candidate_maat_update_cb","htable data not exist,del it!"); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"nominee_intercept_candidate_maat_update_cb","htable data not exist,del it! rule_id is:%d",rule_id); } else { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"nominee_intercept_candidate_maat_update_cb","htable data exist!"); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"nominee_intercept_candidate_maat_update_cb","htable data exist! rule_id is:%d",rule_id); } return; } @@ -356,7 +351,9 @@ void htable_data_free(void *data) { if(data!=NULL) { - MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"htable_data_free","htable_data_free!"); + int rule_id=0; + sscanf((char*)data,"%*d\t%d",&rule_id); + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_INFO, (char*)"htable_data_free","rule_id is:%d",rule_id); free(data); data=NULL; } @@ -451,15 +448,19 @@ void sta_dyn_policy_maat_update_cb(int table_id,const char* table_line,void* u_p if(mctrl_info.is_valid==1) { + htable_data=(char*)malloc(HTABLE_DATA_LEN); + if(htable_data==NULL) + { + MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_FATAL, (char*)"sta_dyn_policy_maat_update_cb","malloc htable_data error!!"); + exit(1); + } snprintf(htable_data,HTABLE_DATA_LEN,"%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s", mctrl_info.htable_flag,mctrl_info.version,mctrl_info.region_id,mctrl_info.group_id,mctrl_info.addr_type, mctrl_info.src_ip,mctrl_info.mask_src_ip,mctrl_info.src_port,mctrl_info.mask_src_port,mctrl_info.dst_ip,mctrl_info.mask_dst_ip, mctrl_info.dst_port,mctrl_info.mask_dst_port,mctrl_info.procotol,mctrl_info.direction,mctrl_info.addr_pool_id,mctrl_info.is_valid, mctrl_info.action,mctrl_info.service,mctrl_info.user_region,mctrl_info.effective_range,mctrl_info.op_time); - add_ret=MESA_htable_add(mctrl_g.mctrl_htable_handle,key_id,sizeof(rule_id),htable_data); - if(add_ret<0) { MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"sta_dyn_policy_maat_update_cb","add htable error:%d",add_ret); @@ -468,12 +469,13 @@ void sta_dyn_policy_maat_update_cb(int table_id,const char* table_line,void* u_p { MESA_handle_runtime_log(mctrl_g.logger_handle, RLOG_LV_DEBUG, (char*)"sta_dyn_policy_maat_update_cb","add htable succeed:%d",add_ret); } - + MESA_htable_search_cb(mctrl_g.mctrl_htable_handle,key_id,sizeof(rule_id),set_update_search_htable_cb,NULL,&cb_ret); - - set_ir_redis_info(cb_ret,htable_data,rule_id); + set_ir_redis_info(cb_ret,htable_data,rule_id); + } + else if(mctrl_info.is_valid==0) { search_result=MESA_htable_search_cb(mctrl_g.mctrl_htable_handle,key_id,sizeof(rule_id),del_update_search_htable_cb,NULL,&cb_ret); @@ -579,7 +581,7 @@ void nominee_intercept_candidate_maat_finish_cb(void* u_para) int register_plugin_table(Maat_feather_t feather,const char* table_name, Maat_start_callback_t *start,Maat_update_callback_t *update,Maat_finish_callback_t *finish, - void *u_para,void* logger,int table_id) + void *u_para,int table_id) { int ret=0; @@ -767,11 +769,11 @@ int main(int argc, char * argv [ ]) } register_plugin_table(mctrl_g.s_feather,STATIC_NOMINEE_TABLE_NAME,sta_dyn_policy_maat_start_cb,sta_dyn_policy_maat_update_cb,sta_dyn_policy_maat_finish_cb, - &static_flag,mctrl_g.logger_handle,static_id); + &static_flag,static_id); register_plugin_table(mctrl_g.d_feather,DYNAMIC_NOMINEE_TABLE_NAME,sta_dyn_policy_maat_start_cb,sta_dyn_policy_maat_update_cb,sta_dyn_policy_maat_finish_cb, - &dynamic_flag,mctrl_g.logger_handle,dynamic_id); + &dynamic_flag,dynamic_id); register_plugin_table(mctrl_g.s_feather,DNAT_POLICY_TABLE_NAME,sta_dyn_policy_maat_start_cb,sta_dyn_policy_maat_update_cb,sta_dyn_policy_maat_finish_cb, - &dnat_policy_flag,mctrl_g.logger_handle,dnat_policy_id); + &dnat_policy_flag,dnat_policy_id); nominee_id=Maat_table_register(mctrl_g.n_feather,NOMINEE_TABLE_NAME); candidate_id=Maat_table_register(mctrl_g.n_feather,CANDIDATE_TABLE_NAME); @@ -787,11 +789,11 @@ int main(int argc, char * argv [ ]) } register_plugin_table(mctrl_g.i_feather,INTERCEPT_TABLE_NAME,nominee_intercept_candidate_maat_start_cb,nominee_intercept_candidate_maat_update_cb,nominee_intercept_candidate_maat_finish_cb, - &intercept_flag,mctrl_g.logger_handle,intercept_id); + &intercept_flag,intercept_id); register_plugin_table(mctrl_g.n_feather,NOMINEE_TABLE_NAME,nominee_intercept_candidate_maat_start_cb,nominee_intercept_candidate_maat_update_cb,nominee_intercept_candidate_maat_finish_cb, - &nominee_flag,mctrl_g.logger_handle,nominee_id); + &nominee_flag,nominee_id); register_plugin_table(mctrl_g.n_feather,CANDIDATE_TABLE_NAME,nominee_intercept_candidate_maat_start_cb,nominee_intercept_candidate_maat_update_cb,nominee_intercept_candidate_maat_finish_cb, - &candidate_flag,mctrl_g.logger_handle,candidate_id); + &candidate_flag,candidate_id); while(1) { -- cgit v1.2.3