summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile22
-rw-r--r--src/ir_mctrl.cpp411
-rw-r--r--src/ir_mctrl.h89
3 files changed, 366 insertions, 156 deletions
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<O_AND_I_AND_N_FLAG)
{
- 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",
- &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.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);
-
- snprintf(table_line,sizeof(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.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.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(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==O_AND_C_FLAG)
{
- set_ir_line(mctrl_i_feather, (char*)INTERCEPT_IP,table_line,rule_id);
- set_ir_line(mctrl_n_feather,(char*)NOMINEE_IP,table_line,rule_id);
+ 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);
}
else if(htable_flag==O_AND_N_FLAG||htable_flag==O_AND_C_AND_N_FLAG)
{
- set_ir_line(mctrl_i_feather, (char*)INTERCEPT_IP,table_line,rule_id);
+ set_ir_line(mctrl_g.i_feather,(char*)INTERCEPT_IP,table_line,rule_id);
}
else if(htable_flag==O_AND_I_FLAG||htable_flag==O_AND_C_AND_I_FLAG)
{
- set_ir_line(mctrl_n_feather,(char*)NOMINEE_IP,table_line,rule_id);
+ set_ir_line(mctrl_g.n_feather,(char*)NOMINEE_IP,table_line,rule_id);
}
else
{
- MESA_handle_runtime_log(logger_handle,RLOG_LV_INFO, (char*)"htable_iterate", "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
+