summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conf/redis.conf25
-rw-r--r--conf/table_info.conf27
-rw-r--r--include/ir_mctrl.h22
-rw-r--r--src/ir_mctrl.cpp279
4 files changed, 214 insertions, 139 deletions
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<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",
- &nom_info.region_id,&nom_info.group_id,&nom_info.addr_type,
+ 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.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);
- snprintf(table_line,sizeof(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,
+ 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.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(htable_flag==S_OR_D_ORIGIN_FLAG||htable_flag==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);
+ 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);
}
else if(htable_flag==O_AND_N_FLAG||htable_flag==O_AND_C_AND_N_FLAG)
{
- set_ir_line(mctrl_d_feather, (char*)INTERCEPT_IP,table_line,rule_id);
+ set_ir_line(mctrl_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_d_feather,(char*)NOMINEE_IP,table_line,rule_id);
+ set_ir_line(mctrl_n_feather,(char*)NOMINEE_IP,table_line,rule_id);
}
else
{
@@ -444,30 +448,53 @@ void htable_iterate(const uchar * key, uint size, void * data, void * user)
void Maat_init()
{
// load conf
- const char *section_d = "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[MAX_IP4_LEN];
- int Maat_redis_port=0;
- char Maat_redis_ip_s[MAX_IP4_LEN];
+ 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;
+
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_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, 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, "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);
//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_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
logger_handle=MESA_create_runtime_log_handle(logger_path,logger_level);
@@ -480,23 +507,47 @@ void Maat_init()
//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)
+ 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);
+
+ if(mctrl_d_feather==NULL||mctrl_s_feather==NULL||mctrl_n_feather==NULL||mctrl_i_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));
+ 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_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_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_initiate_feather(mctrl_d_feather);
+ Maat_initiate_feather(mctrl_s_feather);
+ Maat_initiate_feather(mctrl_i_feather);
+ Maat_initiate_feather(mctrl_n_feather);
}
int htable_init()
{
- int htable_ret;
+ int htable_ret=0;
s_and_d_nominee_htable = MESA_htable_born();
if(s_and_d_nominee_htable == NULL)
{
@@ -524,17 +575,6 @@ 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;
@@ -551,13 +591,14 @@ int main(int argc, char * argv [ ])
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);
+ 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);
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");
+ assert(0);
}
read_plugin_table(mctrl_s_feather,STATIC_NOMINEE_IP,Maat_start_cb,write_table_update_cb,Maat_finish_cb,
@@ -565,11 +606,11 @@ int main(int argc, char * argv [ ])
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,
+ 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_d_feather,NOMINEE_IP,Maat_start_cb,read_table_update_cb,Maat_finish_cb,
+ 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_d_feather,CANDIDATE_IP,Maat_start_cb,read_table_update_cb,Maat_finish_cb,
+ read_plugin_table(mctrl_n_feather,CANDIDATE_IP,Maat_start_cb,read_table_update_cb,Maat_finish_cb,
candidate,logger_handle,candidate_id);
@@ -581,6 +622,8 @@ int main(int argc, char * argv [ ])
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);
return 0;