Merge branch 'feature-rule-tags' into 'develop'
Feature rule tags See merge request MESA_framework/maat!1
This commit is contained in:
12
CMakeLists.txt
Normal file
12
CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
cmake_minimum_required (VERSION 3.5)
|
||||
project (maatframe)
|
||||
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -Wall)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/inc/)
|
||||
include_directories(/opt/MESA/include/MESA/)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_subdirectory (vendor)
|
||||
add_subdirectory (src)
|
||||
add_subdirectory (test)
|
||||
add_subdirectory (tools)
|
||||
53
Makefile
53
Makefile
@@ -1,16 +1,41 @@
|
||||
#opt: OPTFLAGS = -O2
|
||||
#export OPTFLAGS
|
||||
BUILD_DIR = $(CURDIR)/build
|
||||
LOCAL_DIR = $(CURDIR)
|
||||
DEBUG_FLAGS = -DCMAKE_BUILD_TYPE=Debug
|
||||
REL_FLAGS = -DCMAKE_BUILD_TYPE=RelWithDebInfo
|
||||
|
||||
.PHONY: all clean opt
|
||||
ifneq ($(INSTALL_PREFIX),)
|
||||
DEBUG_FLAGS += -DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX)
|
||||
REL_FLAGS += -DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX)
|
||||
endif
|
||||
|
||||
all:
|
||||
cd src/entry/ && $(MAKE)
|
||||
cd test && $(MAKE)
|
||||
cd tools && $(MAKE)
|
||||
clean:
|
||||
cd src/entry/ && $(MAKE) clean
|
||||
cd test && $(MAKE) clean
|
||||
cd tools && $(MAKE) clean
|
||||
|
||||
opt:
|
||||
$(MAKE) all
|
||||
all: _make_build_dir _compile_rel
|
||||
|
||||
PHONY: all _make_build_dir _compile_debug _compile_rel _install \
|
||||
build_release build_debug install
|
||||
|
||||
_make_build_dir:
|
||||
mkdir -p $(BUILD_DIR)
|
||||
|
||||
_compile_debug:
|
||||
cd $(BUILD_DIR) && cmake $(LOCAL_DIR) $(DEBUG_FLAGS) && make
|
||||
|
||||
_compile_rel:
|
||||
cd $(BUILD_DIR) && cmake $(LOCAL_DIR) $(REL_FLAGS) && make
|
||||
|
||||
_install:
|
||||
cd $(BUILD_DIR) && make install
|
||||
_package:
|
||||
cd $(BUILD_DIR) && make package
|
||||
_clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
||||
# Release Version, No Debug Symbol and Optimized with -O2
|
||||
release: _make_build_dir _compile_rel
|
||||
# Debug Version, Optimized with -O0
|
||||
debug: _make_build_dir _compile_debug
|
||||
# Install
|
||||
install: _install
|
||||
# Package
|
||||
package: _package
|
||||
# Clean
|
||||
clean: _clean
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* to reside in the heart) of the departed would reach the paradise of afterlife
|
||||
* successfully.
|
||||
* Author: zhengchao@iie.ac.cn,MESA
|
||||
* Version 2018-07-27 huge service_define
|
||||
* Version 2018-09-21 rule tags
|
||||
* NOTE: MUST compile with G++
|
||||
* All right reserved by Institute of Infomation Engineering,Chinese Academic of Science 2014~2018
|
||||
*********************************************************
|
||||
@@ -156,7 +156,8 @@ enum MAAT_INIT_OPT
|
||||
MAAT_OPT_CUMULATIVE_UPDATE_OFF, //VALUE is NULL,SIZE is 0. Default: CUMMULATIVE UPDATE ON.
|
||||
MAAT_OPT_LOAD_VERSION_FROM, //VALUE is a long long, SIZE=sizeof(long long). Default: Load the Latest. Only valid in redis mode, and maybe failed for too old.
|
||||
//This option also disables background update.
|
||||
MAAT_OPT_ENABLE_UPDATE //VALUE is interger, SIZE=sizeof(int). 1: Enabled, 0:Disabled. DEFAULT: Backgroud update is enabled. Runtime setting is allowed.
|
||||
MAAT_OPT_ENABLE_UPDATE, //VALUE is interger, SIZE=sizeof(int). 1: Enabled, 0:Disabled. DEFAULT: Backgroud update is enabled. Runtime setting is allowed.
|
||||
MAAT_OPT_ACCEPT_TAGS //VALUE is a const char*, MUST end with '\0', SIZE= strlen(string+'\0')+1. Format is a JSON, e.g.{"tags":[{"tag":"location","value":"Beijing/ChaoYang/Huayan/22A"},{"tag":"isp","value":"telecom"}]}
|
||||
};
|
||||
//return -1 if failed, return 0 on success;
|
||||
int Maat_set_feather_opt(Maat_feather_t feather,enum MAAT_INIT_OPT type,const void* value,int size);
|
||||
|
||||
36
src/CMakeLists.txt
Normal file
36
src/CMakeLists.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
project(maatframe)
|
||||
|
||||
set(MAAT_FRAME_MAJOR_VERSION 2)
|
||||
set(MAAT_FRAME_MINOR_VERSION 2)
|
||||
set(MAAT_FRAME_PATCH_VERSION 20180923)
|
||||
set(MAAT_FRAME_VERSION ${MAAT_FRAME_MAJOR_VERSION}.${MAAT_FRAME_MINOR_VERSION}.${MAAT_FRAME_PATCH_VERSION})
|
||||
|
||||
message(STATUS "Maat Frame, Version: ${MAAT_FRAME_VERSION}")
|
||||
|
||||
add_definitions(-fPIC)
|
||||
set(MAAT_SRC entry/cJSON.c entry/config_monitor.cpp entry/dynamic_array.cpp entry/gram_index_engine.c entry/interval_index.c entry/json2iris.cpp entry/Maat_api.cpp entry/Maat_command.cpp entry/Maat_rule.cpp entry/Maat_stat.cpp entry/map_str2int.cpp entry/rbtree.c entry/stream_fuzzy_hash.c entry/UniversalBoolMatch.cpp)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../inc/)
|
||||
include_directories(/opt/MESA/include/MESA/)
|
||||
|
||||
# Static Library Output
|
||||
add_library(maat_frame_static STATIC ${MAAT_SRC})
|
||||
set_target_properties(maat_frame_static PROPERTIES LINKER_LANGUAGE CXX)
|
||||
set_target_properties(maat_frame_static PROPERTIES OUTPUT_NAME maatframe)
|
||||
set_target_properties(maat_frame_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
target_include_directories(maat_frame_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inc_internal/)
|
||||
target_include_directories(maat_frame_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inc_internal/hiredis)
|
||||
|
||||
# Shared Library Output
|
||||
add_library(maat_frame_shared SHARED ${MAAT_SRC})
|
||||
set_target_properties(maat_frame_shared PROPERTIES LINKER_LANGUAGE CXX)
|
||||
set_target_properties(maat_frame_shared PROPERTIES OUTPUT_NAME maatframe)
|
||||
set_target_properties(maat_frame_shared PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
set_target_properties(maat_frame_shared PROPERTIES VERSION ${MAAT_FRAME_MAJOR_VERSION}.${MAAT_FRAME_MINOR_VERSION})
|
||||
set_target_properties(maat_frame_shared PROPERTIES SOVERSION ${MAAT_FRAME_MAJOR_VERSION})
|
||||
target_include_directories(maat_frame_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inc_internal/)
|
||||
target_include_directories(maat_frame_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inc_internal/hiredis)
|
||||
target_link_libraries(maat_frame_shared MESA_handle_logger MESA_htable pcre rulescan pthread m pcre MESA_field_stat2 crypto hiredis_vip)
|
||||
|
||||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/inc/ DESTINATION /opt/MESA/include/MESA/ FILES_MATCHING PATTERN "*.h")
|
||||
install(TARGETS maat_frame_shared DESTINATION /opt/MESA/lib/)
|
||||
@@ -666,6 +666,13 @@ int Maat_set_feather_opt(Maat_feather_t feather,enum MAAT_INIT_OPT type,const vo
|
||||
"Maat load version from %lld, stops backgroud update."
|
||||
,_feather->load_version_from);
|
||||
break;
|
||||
case MAAT_OPT_ACCEPT_TAGS:
|
||||
_feather->n_tags=parse_accept_tag((const char*) value, &_feather->accept_tags, _feather->logger);
|
||||
if(_feather->n_tags==0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@@ -1219,20 +1226,20 @@ int Maat_scan_proto_addr(Maat_feather_t feather,int table_id
|
||||
switch(addr->addrtype)
|
||||
{
|
||||
case ADDR_TYPE_IPV4:
|
||||
ip_scan_data.ipv4_data.saddr=ntohl(addr->paddr.v4->saddr);
|
||||
ip_scan_data.ipv4_data.daddr=ntohl(addr->paddr.v4->daddr);
|
||||
ip_scan_data.ipv4_data.sport=ntohs(addr->paddr.v4->source);
|
||||
ip_scan_data.ipv4_data.dport=ntohs(addr->paddr.v4->dest);
|
||||
ip_scan_data.ipv4_data.saddr=ntohl(addr->v4->saddr);
|
||||
ip_scan_data.ipv4_data.daddr=ntohl(addr->v4->daddr);
|
||||
ip_scan_data.ipv4_data.sport=ntohs(addr->v4->source);
|
||||
ip_scan_data.ipv4_data.dport=ntohs(addr->v4->dest);
|
||||
ip_scan_data.ipv4_data.proto=proto;
|
||||
break;
|
||||
case ADDR_TYPE_IPV6:
|
||||
ip_scan_data.rule_type=RULETYPE_IPv6;
|
||||
memcpy(ip_scan_data.ipv6_data.saddr,addr->paddr.v6->saddr,sizeof(ip_scan_data.ipv6_data.saddr));
|
||||
memcpy(ip_scan_data.ipv6_data.saddr,addr->v6->saddr,sizeof(ip_scan_data.ipv6_data.saddr));
|
||||
ipv6_ntoh(ip_scan_data.ipv6_data.saddr);
|
||||
memcpy(ip_scan_data.ipv6_data.daddr,addr->paddr.v6->daddr,sizeof(ip_scan_data.ipv6_data.daddr));
|
||||
memcpy(ip_scan_data.ipv6_data.daddr,addr->v6->daddr,sizeof(ip_scan_data.ipv6_data.daddr));
|
||||
ipv6_ntoh(ip_scan_data.ipv6_data.daddr);
|
||||
ip_scan_data.ipv6_data.sport=ntohs(addr->paddr.v6->source);
|
||||
ip_scan_data.ipv6_data.dport=ntohs(addr->paddr.v6->dest);
|
||||
ip_scan_data.ipv6_data.sport=ntohs(addr->v6->source);
|
||||
ip_scan_data.ipv6_data.dport=ntohs(addr->v6->dest);
|
||||
ip_scan_data.ipv6_data.proto=proto;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -695,7 +695,7 @@ int _get_maat_redis_value(redisContext *c,struct serial_rule_t* rule_list,int ru
|
||||
{
|
||||
rule_list[idx].table_line=_maat_strdup(reply->str);
|
||||
}
|
||||
else if(reply->type==REDIS_REPLY_ERROR)//Handle: "Loading Redis is loading the database in memory"
|
||||
else if(reply->type==REDIS_REPLY_ERROR)//Deal with Redis response: "Loading Redis is loading the database in memory"
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_redis_monitor
|
||||
,"Redis cmd=%s Error, Reply type=%d, str=%s",redis_cmd, reply->type, reply->str);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "Maat_rule.h"
|
||||
#include "Maat_rule_internal.h"
|
||||
#include "json2iris.h"
|
||||
#include "cJSON.h"
|
||||
#include "dynamic_array.h"
|
||||
#include "aligment_int64.h"
|
||||
#include "config_monitor.h"
|
||||
@@ -30,7 +31,7 @@
|
||||
#include "stream_fuzzy_hash.h"
|
||||
#include "gram_index_engine.h"
|
||||
|
||||
int MAAT_FRAME_VERSION_2_2_20180808=1;
|
||||
int MAAT_FRAME_VERSION_2_2_20180921=1;
|
||||
|
||||
const char* CHARSET_STRING[]={"NONE","gbk","big5","unicode","utf8","bin",
|
||||
"unicode_ascii_esc","unicode_ascii_aligned","unicode_ncr_dec","unicode_ncr_hex","url_encode_gb2312","url_encode_utf8",""};
|
||||
@@ -319,7 +320,7 @@ error_out:
|
||||
|
||||
return ret;
|
||||
}
|
||||
char* strlwr(char* string)
|
||||
char* str_tolower(char* string)
|
||||
{
|
||||
int i=0;
|
||||
for(i=0;i<(int)strlen(string);i++)
|
||||
@@ -473,7 +474,166 @@ int cnt_maskbits(struct in6_addr mask)
|
||||
}
|
||||
return bits_cnt;
|
||||
}
|
||||
//@param value is a JSON, like {"tags":[{"tag":"location","value":"北京/朝阳/华严北里/甲22号},{"tag":"isp","value":"电信"}]}
|
||||
int parse_accept_tag(const char* value, struct rule_tag** result, void* logger)
|
||||
{
|
||||
cJSON* json=NULL, *array=NULL,*tag=NULL, *tmp=NULL;
|
||||
struct rule_tag* p=NULL;
|
||||
int n_tags=0;
|
||||
json=cJSON_Parse(value);
|
||||
if(!json)
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module,
|
||||
"MAAT_OPT_ACCEPT_TAGS Error before: %-200.200s",cJSON_GetErrorPtr());
|
||||
return 0;
|
||||
}
|
||||
array=cJSON_GetObjectItem(json, "tags");
|
||||
n_tags=cJSON_GetArraySize(array);
|
||||
p=(struct rule_tag*)calloc(sizeof(struct rule_tag), n_tags);
|
||||
for(int i=0;i<n_tags;i++)
|
||||
{
|
||||
tag=cJSON_GetArrayItem(array, i);
|
||||
tmp=cJSON_GetObjectItem(tag, "tag");
|
||||
p[i].tag_name=_maat_strdup(tmp->valuestring);
|
||||
tmp=cJSON_GetObjectItem(tag, "value");
|
||||
p[i].tag_val=_maat_strdup(tmp->valuestring);
|
||||
}
|
||||
cJSON_Delete(json);
|
||||
*result=p;
|
||||
return n_tags;
|
||||
}
|
||||
static int compare_each_tag(cJSON* tag_obj, const struct rule_tag* accept_tags, int n_accept)
|
||||
{
|
||||
const char* tag_name;
|
||||
const char* tag_val;
|
||||
int n_val;
|
||||
cJSON *tab_name_obj=NULL, *tag_vals_array=NULL, *tag_val_obj=NULL;
|
||||
|
||||
int i=0, j=0, name_matched=0;
|
||||
tab_name_obj=cJSON_GetObjectItem(tag_obj,"tag");
|
||||
if(!tab_name_obj||tab_name_obj->type!=cJSON_String)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
tag_name=tab_name_obj->valuestring;
|
||||
tag_vals_array=cJSON_GetObjectItem(tag_obj,"value");
|
||||
if(!tag_vals_array||tag_vals_array->type!=cJSON_Array)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
n_val=cJSON_GetArraySize(tag_vals_array);
|
||||
for(i=0;i<n_accept;i++)
|
||||
{
|
||||
if(0!=strcmp(accept_tags[i].tag_name, tag_name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
name_matched++;
|
||||
|
||||
for(j=0; j<n_val; j++)
|
||||
{
|
||||
tag_val_obj=cJSON_GetArrayItem(tag_vals_array, j);
|
||||
if(!tag_val_obj||tag_val_obj->type!=cJSON_String)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
tag_val=tag_val_obj->valuestring;
|
||||
// compare a/b/c with a/b/c/d is a miss.
|
||||
if(strlen(accept_tags[i].tag_val)<strlen(tag_val))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// compare a1a2/b1/c1 with a1a2/b/ is a miss.
|
||||
//make sure the overlap is ended with a '/'
|
||||
if(0==strncmp(accept_tags[i].tag_val, tag_val, strlen(tag_val))&&
|
||||
(strlen(accept_tags[i].tag_val)==strlen(tag_val)||accept_tags[i].tag_val[strlen(tag_val)]=='/'))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
//no matched name is considered as a
|
||||
if(name_matched>0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
error_out:
|
||||
return -1;
|
||||
|
||||
}
|
||||
//@param tag_set likes [{"tag":"location","value":["北京/朝阳/华严北里","上海/浦东/陆家嘴"]},{"tag":"isp","value":["电信","移动"]}]
|
||||
static int compare_each_tag_set(cJSON* tag_set, const struct rule_tag* accept_tags, int n_accept)
|
||||
{
|
||||
cJSON *tag_obj=NULL;
|
||||
int n_tag=0, ret=0, matched=0;
|
||||
n_tag=cJSON_GetArraySize(tag_set);
|
||||
for(int i=0; i<n_tag; i++)
|
||||
{
|
||||
tag_obj=cJSON_GetArrayItem(tag_set, i);
|
||||
if(!tag_obj||tag_obj->type!=cJSON_Object)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
ret=compare_each_tag(tag_obj, accept_tags, n_accept);
|
||||
if(ret<0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(ret==1)
|
||||
{
|
||||
matched++;
|
||||
}
|
||||
}
|
||||
if(matched==n_tag)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
error_out:
|
||||
return -1;
|
||||
}
|
||||
//@param value {"tag_sets":[[{"tag":"location","value":["北京/朝阳/华严北里","上海/浦东/陆家嘴"]},{"tag":"isp","value":["电信","移动"]}],[{"tag":"location","value":["北京"]},{"tag":"isp","value":["联通"]}]]}
|
||||
//@return 1 on match, 0 on not match, -1 on error.
|
||||
static int compare_accept_tag(const char* value,const struct rule_tag* accept_tags, int n_tags)
|
||||
{
|
||||
cJSON *json=NULL;
|
||||
cJSON *tag_set_array=NULL, *tag_set=NULL;
|
||||
int ret=-1, n_set=0;
|
||||
json=cJSON_Parse(value);
|
||||
if(!json)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
tag_set_array=cJSON_GetObjectItem(json, "tag_sets");
|
||||
if(!tag_set_array||tag_set_array->type!=cJSON_Array)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
n_set=cJSON_GetArraySize(tag_set_array);
|
||||
for(int i=0; i<n_set; i++)
|
||||
{
|
||||
tag_set=cJSON_GetArrayItem(tag_set_array,i);
|
||||
if(!tag_set||tag_set->type!=cJSON_Array)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
ret=compare_each_tag_set(tag_set, accept_tags, n_tags);
|
||||
if(ret!=0)//match or error occurs.
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
error_out:
|
||||
cJSON_Delete(json);
|
||||
return ret;
|
||||
}
|
||||
int lqueue_destroy_cb(void *data, long data_len, void *arg)
|
||||
{
|
||||
assert(0);
|
||||
@@ -544,12 +704,12 @@ int read_expr_table_info(const char* line,int line_num,struct _Maat_table_info_t
|
||||
,&(p->cross_cache_size)
|
||||
,quick_str_scan);
|
||||
memset(ret,0,sizeof(ret));
|
||||
ret[0]=map_str2int(string2int_map,strlwr(table_type),(int*)&(p->table_type));
|
||||
ret[1]=map_str2int(string2int_map,strlwr(src_charset),(int*)&(p->src_charset));
|
||||
ret[2]=map_str2int(string2int_map,strlwr(merge),&(p->do_charset_merge));
|
||||
ret[0]=map_str2int(string2int_map,str_tolower(table_type),(int*)&(p->table_type));
|
||||
ret[1]=map_str2int(string2int_map,str_tolower(src_charset),(int*)&(p->src_charset));
|
||||
ret[2]=map_str2int(string2int_map,str_tolower(merge),&(p->do_charset_merge));
|
||||
if(strlen(quick_str_scan)>0)
|
||||
{
|
||||
ret[3]=map_str2int(string2int_map,strlwr(quick_str_scan),&(p->quick_expr_switch));
|
||||
ret[3]=map_str2int(string2int_map,str_tolower(quick_str_scan),&(p->quick_expr_switch));
|
||||
}
|
||||
memset(quick_str_scan,0,sizeof(quick_str_scan));
|
||||
|
||||
@@ -566,7 +726,7 @@ int read_expr_table_info(const char* line,int line_num,struct _Maat_table_info_t
|
||||
sub_token= strtok_r(token,"/", &saveptr);
|
||||
if (sub_token == NULL)
|
||||
break;
|
||||
ret[3]=map_str2int(string2int_map,strlwr(sub_token),(int*)&(p->dst_charset[j]));
|
||||
ret[3]=map_str2int(string2int_map,str_tolower(sub_token),(int*)&(p->dst_charset[j]));
|
||||
if(ret[3]>0)
|
||||
{
|
||||
if(p->dst_charset[j]==p->src_charset)
|
||||
@@ -588,7 +748,7 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char*
|
||||
FILE*fp=NULL;
|
||||
char line[MAX_TABLE_LINE_SIZE];
|
||||
int i=0,ret=0,table_cnt=0;
|
||||
char table_type_str[16],not_care[1024], user_region_encoding[32];
|
||||
char table_type_str[16],not_care[1024], tmp_str[32];
|
||||
MESA_htable_handle string2int_map=map_create();
|
||||
struct _Maat_table_info_t*p=NULL;
|
||||
struct _Maat_table_info_t*conj_table=NULL;
|
||||
@@ -640,7 +800,7 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char*
|
||||
}
|
||||
p=create_table_info(max_thread_num);
|
||||
|
||||
ret=sscanf(line,"%hu\t%s\t%s\t%s",&(p->table_id)
|
||||
ret=sscanf(line,"%hu\t%s\t%s\t%[a-z0-9\t ]",&(p->table_id)
|
||||
,p->table_name[0]
|
||||
,table_type_str
|
||||
,not_care);
|
||||
@@ -650,7 +810,7 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char*
|
||||
"Maat read table info %s line %d error: not enough column.",table_info_path,i);
|
||||
continue;
|
||||
}
|
||||
ret=map_str2int(string2int_map,strlwr(table_type_str),(int*)&(p->table_type));
|
||||
ret=map_str2int(string2int_map,str_tolower(table_type_str),(int*)&(p->table_type));
|
||||
if(ret<0)
|
||||
{
|
||||
MESA_handle_runtime_log(logger, RLOG_LV_FATAL,maat_module,
|
||||
@@ -673,17 +833,17 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char*
|
||||
case TABLE_TYPE_PLUGIN:
|
||||
p->cb_info=(struct _plugin_table_info*)calloc(sizeof(struct _plugin_table_info),1);
|
||||
p->cb_info->cache_lines=dynamic_array_create(1024,1024);
|
||||
ret=sscanf(not_care,"%d",&(p->valid_flag_column));
|
||||
ret=sscanf(not_care,"%d\t%d\t%[0-9,]",&(p->valid_flag_column), &p->rule_tag_column, tmp_str);
|
||||
if(ret==0||ret==EOF)
|
||||
{
|
||||
p->valid_flag_column=-1;
|
||||
}
|
||||
break;
|
||||
case TABLE_TYPE_COMPILE:
|
||||
ret=sscanf(not_care,"%[a-z0-9]",user_region_encoding);
|
||||
ret=sscanf(not_care,"%[a-z0-9]",tmp_str);
|
||||
if(ret>0)
|
||||
{
|
||||
ret=map_str2int(string2int_map,strlwr(user_region_encoding),(int*)&(p->user_region_encoding));
|
||||
ret=map_str2int(string2int_map,str_tolower(tmp_str),(int*)&(p->user_region_encoding));
|
||||
}
|
||||
if(ret!=1)
|
||||
{
|
||||
@@ -2657,19 +2817,20 @@ error_out:
|
||||
intval_rule=NULL;
|
||||
}
|
||||
|
||||
void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line,struct _Maat_scanner_t *scanner,void* logger)
|
||||
void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line,struct _Maat_scanner_t *scanner, const struct rule_tag* tags, int n_tags,void* logger)
|
||||
{
|
||||
struct db_compile_rule_t *p_compile=(struct db_compile_rule_t*)calloc(sizeof(struct db_compile_rule_t ),1);
|
||||
struct _head_Maat_rule_t* p_m_rule=&(p_compile->m_rule_head);
|
||||
char user_region[MAX_TABLE_LINE_SIZE]={0};
|
||||
char tag_str[MAX_TABLE_LINE_SIZE]={0};
|
||||
int ret=0;
|
||||
p_compile->declare_grp_num=0;
|
||||
ret=sscanf(table_line,"%d\t%d\t%hhd\t%hhd\t%hhd\t%lld\t%s\t%d\t%d",&(p_m_rule->config_id)
|
||||
ret=sscanf(table_line,"%d\t%d\t%hhd\t%hhd\t%hhd\t%s\t%s\t%d\t%d",&(p_m_rule->config_id)
|
||||
,&(p_m_rule->service_id)
|
||||
,&(p_m_rule->action)
|
||||
,&(p_m_rule->do_blacklist)
|
||||
,&(p_m_rule->do_log)
|
||||
,&(p_compile->effective_range)
|
||||
,tag_str
|
||||
,user_region
|
||||
,&(p_compile->is_valid)
|
||||
,&(p_compile->declare_grp_num));
|
||||
@@ -2677,11 +2838,26 @@ void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module ,
|
||||
"update error,invalid format of compile table %s:%s"
|
||||
,table->table_name[table->updating_name],table_line);
|
||||
free(p_compile);
|
||||
p_compile=NULL;
|
||||
,table->table_name[table->updating_name],table_line);
|
||||
table->udpate_err_cnt++;
|
||||
return;
|
||||
goto no_save;
|
||||
}
|
||||
if(n_tags>0&&strlen(tag_str)>2)
|
||||
{
|
||||
ret=compare_accept_tag(tag_str, tags, n_tags);
|
||||
if(ret<0)
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module ,
|
||||
"update error,invalid tag format of compile table %s:%s"
|
||||
,table->table_name[table->updating_name],table_line);
|
||||
table->udpate_err_cnt++;
|
||||
goto no_save;
|
||||
}
|
||||
if(ret==0)
|
||||
{
|
||||
table->unmatch_tag_cnt++;
|
||||
goto no_save;
|
||||
}
|
||||
}
|
||||
switch(table->user_region_encoding)
|
||||
{
|
||||
@@ -2702,10 +2878,7 @@ void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line
|
||||
{
|
||||
table->cfg_num--;
|
||||
}
|
||||
free(p_compile->service_defined);
|
||||
p_compile->service_defined=NULL;
|
||||
free(p_compile);
|
||||
p_compile=NULL;
|
||||
goto no_save;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2714,13 +2887,9 @@ void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_INFO,maat_module ,
|
||||
"duplicate config of compile table %s config_id=%d"
|
||||
,table->table_name[table->updating_name],p_m_rule->config_id);
|
||||
free(p_compile->service_defined);
|
||||
p_compile->service_defined=NULL;
|
||||
free(p_compile);
|
||||
p_compile=NULL;
|
||||
,table->table_name[table->updating_name],p_m_rule->config_id);
|
||||
table->udpate_err_cnt++;
|
||||
|
||||
goto no_save;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2728,7 +2897,13 @@ void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line
|
||||
table->cfg_num++;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
no_save:
|
||||
free(p_compile->service_defined);
|
||||
p_compile->service_defined=NULL;
|
||||
free(p_compile);
|
||||
p_compile=NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2901,13 +3076,49 @@ void garbage_bury(MESA_lqueue_head garbage_q,int timeout,void *logger)
|
||||
q_cnt,bury_cnt);
|
||||
}
|
||||
}
|
||||
void plugin_table_callback(struct _Maat_table_info_t* table,const char* table_line,void* logger)
|
||||
void update_plugin_table(struct _Maat_table_info_t* table,const char* table_line, const struct rule_tag* tags, int n_tags, void* logger)
|
||||
{
|
||||
int i=0;
|
||||
int i=0, ret=1;
|
||||
unsigned int len=strlen(table_line)+1;
|
||||
struct _plugin_table_info* p_table_cb=table->cb_info;
|
||||
char *p=NULL;
|
||||
char* copy=NULL;
|
||||
|
||||
char *token=NULL,*sub_token=NULL,*saveptr;
|
||||
if(table->rule_tag_column>0&&n_tags>0)
|
||||
{
|
||||
copy=_maat_strdup(table_line);
|
||||
for (token = copy, i=0; i<table->rule_tag_column ; token= NULL, i++)
|
||||
{
|
||||
sub_token= strtok_r(token,"\t", &saveptr);
|
||||
if (sub_token == NULL)
|
||||
break;
|
||||
}
|
||||
if(i==table->rule_tag_column&&strlen(sub_token)>2)
|
||||
{
|
||||
ret=compare_accept_tag(sub_token, tags, n_tags);
|
||||
if(ret<0)
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module ,
|
||||
"update error,invalid tag format of plugin table %s:%s"
|
||||
,table->table_name[table->updating_name],table_line);
|
||||
table->udpate_err_cnt++;
|
||||
}
|
||||
if(ret==0)
|
||||
{
|
||||
table->unmatch_tag_cnt++;
|
||||
}
|
||||
}
|
||||
free(copy);
|
||||
copy=NULL;
|
||||
if(ret!=1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
p_table_cb->acc_line_num++;
|
||||
|
||||
if(p_table_cb->cb_plug_cnt>0)
|
||||
{
|
||||
for(i=0;i<p_table_cb->cb_plug_cnt;i++)
|
||||
@@ -3202,13 +3413,13 @@ int maat_update_cb(const char* table_name,const char* line,void *u_para)
|
||||
update_digest_rule(feather->p_table_info[table_id], line, scanner,feather->logger,feather->GROUP_MODE_ON);
|
||||
break;
|
||||
case TABLE_TYPE_COMPILE:
|
||||
update_compile_rule(feather->p_table_info[table_id], line, scanner,feather->logger);
|
||||
update_compile_rule(feather->p_table_info[table_id], line, scanner, feather->accept_tags, feather->n_tags, feather->logger);
|
||||
break;
|
||||
case TABLE_TYPE_GROUP:
|
||||
update_group_rule(feather->p_table_info[table_id], line, scanner,feather->logger);
|
||||
break;
|
||||
case TABLE_TYPE_PLUGIN:
|
||||
plugin_table_callback(feather->p_table_info[table_id], line,feather->logger);
|
||||
update_plugin_table(feather->p_table_info[table_id], line, feather->accept_tags, feather->n_tags, feather->logger);
|
||||
default:
|
||||
break;
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
#opt: OPTFLAGS = -O2
|
||||
#export OPTFLAGS
|
||||
|
||||
CC = gcc
|
||||
CCC = g++
|
||||
CFLAGS = -Wall -g -fPIC
|
||||
#GCOV_FLAGS = -fprofile-arcs -ftest-coverage
|
||||
CFLAGS += $(OPTFLAGS)
|
||||
#CFLAGS += $(GCOV_FLAGS)
|
||||
LDDICTATOR = -Wl,-wrap,malloc -Wl,-wrap,calloc -Wl,-wrap,free -Wl,-wrap,realloc
|
||||
LDFLAGS = -lMESA_handle_logger -lMESA_htable -lpthread -lrt -lm -lrulescan -lpcre -lMESA_field_stat2 -lcrypto -lhiredis_vip
|
||||
#LDFLAGS += $(LDDICTATOR)
|
||||
LDFLAGS += $(GCOV_FLAGS)
|
||||
MAILLIB = ../lib
|
||||
|
||||
G_H_DIR =../inc_internal
|
||||
H_DIR =-I$(G_H_DIR) -I../../inc
|
||||
LIBMAAT = libmaatframe.a
|
||||
LIBMAAT_SO = libmaatframe.so
|
||||
|
||||
OBJS=config_monitor.o Maat_rule.o Maat_api.o Maat_command.o Maat_stat.o UniversalBoolMatch.o dynamic_array.o\
|
||||
cJSON.o json2iris.o map_str2int.o interval_index.o gram_index_engine.o stream_fuzzy_hash.o rbtree.o
|
||||
.c.o:
|
||||
$(CC) -c $(CFLAGS) -I. $(H_DIR) $<
|
||||
|
||||
.cpp.o:
|
||||
$(CCC) -c $(CFLAGS) -I. $(H_DIR) $<
|
||||
|
||||
all: $(LIBMAAT) $(LIBMAAT_SO)
|
||||
|
||||
$(LIBMAAT_SO): $(OBJS)
|
||||
$(CCC) -o $(LIBMAAT_SO) -shared $(OBJS) $(LDFLAGS)
|
||||
cp $(LIBMAAT_SO) ../../lib/
|
||||
$(LIBMAAT): $(OBJS)
|
||||
echo making dynamic lib ...
|
||||
ar cqs $(LIBMAAT) $(OBJS)
|
||||
cp $(LIBMAAT) ../../lib/
|
||||
|
||||
clean:
|
||||
rm -rf *.o *.gcov *.gcno $(LIBMAAT) *~
|
||||
|
||||
opt:
|
||||
$(MAKE) all
|
||||
@@ -715,10 +715,11 @@ int write_compile_rule(cJSON *compile,struct iris_description_t *p_iris,void * l
|
||||
compile_cmd[cmd_cnt].json_type=cJSON_Number;
|
||||
cmd_cnt++;
|
||||
|
||||
compile_cmd[cmd_cnt].json_string="effective_range";
|
||||
compile_cmd[cmd_cnt].json_type=cJSON_Number;
|
||||
|
||||
compile_cmd[cmd_cnt].json_string="tags";
|
||||
compile_cmd[cmd_cnt].json_type=cJSON_String;
|
||||
compile_cmd[cmd_cnt].empty_allowed=1;
|
||||
compile_cmd[cmd_cnt].default_int=0;
|
||||
compile_cmd[cmd_cnt].default_string="0";
|
||||
cmd_cnt++;
|
||||
|
||||
compile_cmd[cmd_cnt].json_string="user_region";
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <sfh_internal.h>
|
||||
#include "sfh_internal.h"
|
||||
#include "stream_fuzzy_hash.h"
|
||||
#include "interval_index.h"
|
||||
//#define DEBUG_PRINT
|
||||
|
||||
@@ -261,9 +261,11 @@ struct _Maat_table_info_t
|
||||
};
|
||||
struct _plugin_table_info *cb_info;
|
||||
int valid_flag_column; //for plugin table
|
||||
int rule_tag_column; //for plugin table;
|
||||
int user_region_encoding; //for compile table, USER_REGION_ENCODE_xx
|
||||
//for stat>>>>>>>>
|
||||
unsigned long long udpate_err_cnt;
|
||||
unsigned long long unmatch_tag_cnt;
|
||||
unsigned long long iconv_err_cnt;
|
||||
int stat_line_id;
|
||||
mcore_long_t scan_cnt;
|
||||
@@ -329,6 +331,11 @@ struct GIE_aux_t
|
||||
GIE_handle_t* gie_handle;
|
||||
MESA_lqueue_head update_q;
|
||||
};
|
||||
struct rule_tag
|
||||
{
|
||||
char* tag_name;
|
||||
char* tag_val;
|
||||
};
|
||||
struct _Maat_scanner_t
|
||||
{
|
||||
long long version;
|
||||
@@ -349,7 +356,7 @@ struct _Maat_scanner_t
|
||||
MESA_lqueue_head region_update_q;
|
||||
void * expr_compiler;
|
||||
scan_result_t *region_rslt_buff;
|
||||
MESA_lqueue_head tomb_ref;//reference of feather->garbage_q
|
||||
MESA_lqueue_head tomb_ref;//reference of g_feather->garbage_q
|
||||
struct _region_stat_t region_counter[MAX_TABLE_NUM];
|
||||
int max_thread_num;
|
||||
iconv_t iconv_handle[MAX_CHARSET_NUM][MAX_CHARSET_NUM];//iconv_handle[to][from]
|
||||
@@ -399,6 +406,9 @@ struct _Maat_feather_t
|
||||
pthread_mutex_t redis_write_lock; //protect redis_write_ctx
|
||||
long long base_rgn_seq,base_grp_seq,server_time;
|
||||
long long load_version_from;
|
||||
|
||||
struct rule_tag *accept_tags;
|
||||
int n_tags;
|
||||
//internal states
|
||||
long long new_version;
|
||||
int active_plugin_table_num;
|
||||
@@ -451,6 +461,7 @@ struct serial_rule_t //rm= Redis Maat
|
||||
char table_name[256];
|
||||
char* table_line;
|
||||
};
|
||||
int parse_accept_tag(const char* value, struct rule_tag** result, void* logger);
|
||||
void garbage_bagging(enum maat_garbage_type type,void *p,MESA_lqueue_head garbage_q);
|
||||
void garbage_bury(MESA_lqueue_head garbage_q,void *logger);
|
||||
void make_group_set(const struct _Maat_compile_inner_t* compile_rule,universal_bool_expr_t* a_set);
|
||||
@@ -1,562 +0,0 @@
|
||||
#ifndef _APP_STREAM_H_
|
||||
#define _APP_STREAM_H_
|
||||
|
||||
/*************************************************************************************
|
||||
Update Log:
|
||||
2014-09-17 LiJia:
|
||||
(1)<29><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>struct ipaddr<64>ṹ<EFBFBD><E1B9B9>, <20><><EFBFBD><EFBFBD>ƽ̨<C6BD>ṹstruct layer_addr<64><72><EFBFBD>ڴ<EFBFBD><DAB4>ֲ<EFBFBD><D6B2>ϼ<EFBFBD><CFBC><EFBFBD>;
|
||||
(2)<29><><EFBFBD><EFBFBD><EFBFBD>½ӿ<C2BD>:
|
||||
int MESA_kill_tcp_synack(struct streaminfo *stream, const void *raw_pkt);
|
||||
<09><><EFBFBD><EFBFBD>HMDģʽ<C4A3>µ<EFBFBD>FD.
|
||||
|
||||
2014-09-10 LiJia:
|
||||
(1)<29><><EFBFBD><EFBFBD><EFBFBD>½ӿ<C2BD>:
|
||||
int MESA_inject_pkt(struct streaminfo *stream, const char *payload,
|
||||
int payload_len, const void *raw_pkt, UCHAR snd_routedir);
|
||||
<09><><EFBFBD><EFBFBD>Ӧ<EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><>ԭ<EFBFBD><D4AD>MESA_fakepacket_send_tcp()<29><><EFBFBD><EFBFBD><EFBFBD>˺ܶ<CBBA><DCB6><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>.
|
||||
**************************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip6.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define USE_MESA_STREAM_HASH (1) /* ʹ<>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3>µ<EFBFBD>HASH<53><48> */
|
||||
|
||||
extern int MESA_PLATFORM_VERSION_20140917; /* ƽ̨<C6BD>汾<EFBFBD><E6B1BE> */
|
||||
|
||||
#define ADDR_UNSYMMETRY (0) /* 2014-04-25, <20><><EFBFBD>Դ<EFBFBD>XinJing<6E><67><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD>, <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>VLAN<41><4E>ַ<EFBFBD><D6B7><EFBFBD>Գ<EFBFBD><D4B3><EFBFBD><EFBFBD><EFBFBD>, <20>˺겻Ӧ<EAB2BB><D3A6><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD> */
|
||||
|
||||
#if 0
|
||||
#define FOR_863 (0) /* for 863<36><33>Ŀ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>ǩģ<C7A9><C4A3> */
|
||||
#define FOR_108 (0)
|
||||
#define RAW_IP_FRAG_PKT (0) /* 2013-08-21 LiJia add, <20><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB>ԭʼIP<49><50>Ƭ<EFBFBD><C6AC> */
|
||||
#endif
|
||||
|
||||
#ifndef UINT8
|
||||
typedef unsigned char UINT8;
|
||||
#endif
|
||||
#ifndef UCHAR
|
||||
typedef unsigned char UCHAR;
|
||||
#endif
|
||||
#ifndef UINT16
|
||||
typedef unsigned short UINT16;
|
||||
#endif
|
||||
#ifndef UINT32
|
||||
typedef unsigned int UINT32;
|
||||
#endif
|
||||
#ifndef UINT64
|
||||
typedef unsigned long long UINT64;
|
||||
#endif
|
||||
|
||||
//<2F><><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define DIR_C2S 0x01
|
||||
#define DIR_S2C 0x02
|
||||
#define DIR_DOUBLE 0x03
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define DIR_ROUTE_UP 0x00
|
||||
#define DIR_ROUTE_DOWN 0x01
|
||||
|
||||
//<2F><>ַ<EFBFBD><D6B7><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
|
||||
enum addr_type_t{
|
||||
__ADDR_TYPE_INIT = 0,
|
||||
ADDR_TYPE_IPV4, /* 1, <20><><EFBFBD><EFBFBD>IPv4<76><34>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>Ϣ */
|
||||
ADDR_TYPE_IPV6, /* 2, <20><><EFBFBD><EFBFBD>IPv6<76><36>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>Ϣ */
|
||||
ADDR_TYPE_VLAN, /* 3 */
|
||||
ADDR_TYPE_MAC, /* 4 */
|
||||
ADDR_TYPE_ARP = 5, /* 5 */
|
||||
ADDR_TYPE_GRE, /* 6 */
|
||||
ADDR_TYPE_MPLS, /* 7 */
|
||||
ADDR_TYPE_PPPOE_SES, /* 8 */
|
||||
ADDR_TYPE_TCP, /* 9 */
|
||||
ADDR_TYPE_UDP = 10, /* 10 */
|
||||
ADDR_TYPE_L2TP, /* 11 */
|
||||
//ADDR_TYPE_STREAM_TUPLE4_V4, /* 12, <20><><EFBFBD>ϵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>IPv4<76><34>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>Ϣ */
|
||||
//ADDR_TYPE_STREAM_TUPLE4_V6, /* 13, <20><><EFBFBD>ϵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>IPv6<76><36>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>Ϣ */
|
||||
__ADDR_TYPE_IP_PAIR_V4, /* 14, <20><>IPv4<76><34>ַ<EFBFBD><D6B7> */
|
||||
__ADDR_TYPE_IP_PAIR_V6, /* 15, <20><>IPv6<76><36>ַ<EFBFBD><D6B7> */
|
||||
__ADDR_TYPE_MAX, /* 16 */
|
||||
};
|
||||
|
||||
|
||||
#define TCP_TAKEOVER_STATE_FLAG_OFF 0
|
||||
#define TCP_TAKEOVER_STATE_FLAG_ON 1
|
||||
|
||||
//Ӧ<>ò㿴<C3B2><E3BFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
|
||||
#define OP_STATE_PENDING 0
|
||||
#define OP_STATE_REMOVE_ME 1
|
||||
#define OP_STATE_CLOSE 2
|
||||
#define OP_STATE_DATA 3
|
||||
|
||||
//Ӧ<>ò㷵<C3B2>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define APP_STATE_GIVEME 0x00
|
||||
#define APP_STATE_DROPME 0x01
|
||||
#define APP_STATE_FAWPKT 0x00
|
||||
#define APP_STATE_DROPPKT 0x10
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
|
||||
enum stream_type_t{
|
||||
STREAM_TYPE_NON = 0, /* <20><><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>, <20><>VLAN, IP<49><50><EFBFBD><EFBFBD> */
|
||||
STREAM_TYPE_TCP,
|
||||
STREAM_TYPE_UDP,
|
||||
STREAM_TYPE_SOCKS4,
|
||||
STREAM_TYPE_SOCKS5,
|
||||
STREAM_TYPE_HTTP_PROXY,
|
||||
STREAM_TYPE_PPPOE,
|
||||
};
|
||||
|
||||
#define PROXY_STATE_SEL 0
|
||||
#define PROXY_STATE_LINK_IN 1
|
||||
|
||||
|
||||
/* ԭʼ<D4AD><CABC><EFBFBD>ṹ */
|
||||
typedef struct {
|
||||
enum addr_type_t low_layer_type; /* ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MAC(pcap<61><70><EFBFBD><EFBFBD>), Ҳ<><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IPv4(pag<61><67><EFBFBD><EFBFBD>) */
|
||||
int raw_pkt_len; /* ԭʼ<D4AD><CABC><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD> */
|
||||
const void *raw_pkt_data; /* ԭʼ<D4AD><CABC>ͷָ<CDB7><D6B8>, <20><><EFBFBD><EFBFBD>low_layer_type<70>ж<EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
struct timeval raw_pkt_ts; /* ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>ȫΪ0<CEAA><30><EFBFBD><EFBFBD>֧<EFBFBD>ִ˹<D6B4><CBB9><EFBFBD>(<28><>pagģʽ) */
|
||||
}raw_pkt_t;
|
||||
|
||||
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
struct proxy_node
|
||||
{
|
||||
UINT16 iType; // <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 0 <20><>ʾ<EFBFBD><CABE>Ч
|
||||
UINT16 uiPort; // <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>
|
||||
UINT16 uiUserLen;
|
||||
UINT16 uiPwdLen;
|
||||
UINT16 uiApendLen;
|
||||
|
||||
UCHAR opstate; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
UCHAR dealstate; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
UINT32 uiIP; // <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<49><50>ַv4, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
||||
UCHAR *pIpv6; // <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<49><50>ַ, v6<76><36>ַ
|
||||
UCHAR *pUser; // <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>
|
||||
UCHAR *pPwd; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
UCHAR *append; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>url
|
||||
|
||||
void *apme; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>url
|
||||
struct proxy_node *pnext;
|
||||
} ;
|
||||
|
||||
|
||||
typedef struct raw_ipfrag_list{
|
||||
void *frag_packet;
|
||||
int pkt_len;
|
||||
int type; /* IPv4 or IPv6 */
|
||||
struct raw_ipfrag_list *next;
|
||||
}raw_ipfrag_list_t;
|
||||
|
||||
|
||||
struct buf_unorder
|
||||
{
|
||||
struct buf_unorder *next;
|
||||
struct buf_unorder *prev;
|
||||
void *data;
|
||||
UINT32 len;
|
||||
UINT32 tcpdatalen;
|
||||
UINT32 urg_ptr;
|
||||
char fin;
|
||||
char urg;
|
||||
char rst;
|
||||
unsigned char pad;
|
||||
UINT32 seq;
|
||||
UINT32 ack;
|
||||
raw_ipfrag_list_t *ipfrag_list;
|
||||
raw_pkt_t raw_pkt; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>洢ԭʼ<D4AD><CABC> */
|
||||
};
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD>嶨<EFBFBD>壺*/
|
||||
struct half_tcpstream
|
||||
{
|
||||
UCHAR *data;
|
||||
UINT32 offset; /*data<74>е<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>TCP<43><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>*/
|
||||
UINT32 count; /*<2A><><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊֹ<CEAA><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>*/
|
||||
UINT32 count_new; /*<2A><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>*/
|
||||
UINT32 count_ideal; /*<2A><><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊֹ<CEAA><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>*/
|
||||
UINT32 pktcout; /*<2A><><EFBFBD><EFBFBD><EFBFBD>ۼƵ<DBBC><C6B5><EFBFBD><EFBFBD>İ<EFBFBD><C4B0><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
UINT32 totallost; /*<2A><><EFBFBD><EFBFBD><EFBFBD>ۼƶ<DBBC><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
UINT32 seq; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>seq<65><71><EFBFBD><EFBFBD>*/
|
||||
UINT32 first_data_seq; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ĵ<EFBFBD>seq<65><71><EFBFBD><EFBFBD>*/
|
||||
UINT32 ack_seq; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>*/
|
||||
UINT16 window; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>С*/
|
||||
UCHAR maxunorder; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ*/
|
||||
UCHAR finstate; /*fin״̬*/
|
||||
UINT32 pktcout_new; /*<2A><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD>İ<EFBFBD><C4B0><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
UINT32 unorder_cnt;
|
||||
struct buf_unorder *unorderlist; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
struct buf_unorder *unorderlisttail; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><CEB2>ָ<EFBFBD><D6B8>*/
|
||||
|
||||
};
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>papp */
|
||||
struct tuple4 {
|
||||
u_int saddr;
|
||||
u_int daddr;
|
||||
u_short source;
|
||||
u_short dest;
|
||||
};
|
||||
|
||||
struct tuple6
|
||||
{
|
||||
UCHAR saddr[16] ;
|
||||
UCHAR daddr[16] ;
|
||||
UINT16 source;
|
||||
UINT16 dest;
|
||||
};
|
||||
|
||||
/* network-order */
|
||||
struct stream_tuple4_v4{
|
||||
UINT32 saddr; /* network order */
|
||||
UINT32 daddr; /* network order */
|
||||
UINT16 source; /* network order */
|
||||
UINT16 dest; /* network order */
|
||||
};
|
||||
|
||||
|
||||
#ifndef IPV6_ADDR_LEN
|
||||
#define IPV6_ADDR_LEN (sizeof(struct in6_addr))
|
||||
#endif
|
||||
|
||||
struct stream_tuple4_v6
|
||||
{
|
||||
UCHAR saddr[IPV6_ADDR_LEN] ;
|
||||
UCHAR daddr[IPV6_ADDR_LEN] ;
|
||||
UINT16 source; /* network order */
|
||||
UINT16 dest; /* network order */
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define GRE_TAG_LEN (4)
|
||||
struct layer_addr_gre
|
||||
{
|
||||
UINT16 gre_id;
|
||||
};
|
||||
|
||||
|
||||
#define VLAN_ID_MASK (0x0FFF)
|
||||
#define VLAN_TAG_LEN (4)
|
||||
struct layer_addr_vlan
|
||||
{
|
||||
UINT16 vlan_id; /* network order */
|
||||
};
|
||||
|
||||
struct layer_addr_pppoe_session
|
||||
{
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
unsigned int ver:4;
|
||||
unsigned int type:4;
|
||||
#endif
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
unsigned int type:4;
|
||||
unsigned int ver:4;
|
||||
#endif
|
||||
unsigned char code;
|
||||
unsigned short session_id;
|
||||
};
|
||||
|
||||
#ifndef MAC_ADDR_LEN
|
||||
#define MAC_ADDR_LEN (6)
|
||||
#endif
|
||||
|
||||
struct layer_addr_mac
|
||||
{
|
||||
UCHAR src_mac[MAC_ADDR_LEN]; /* network order */
|
||||
UCHAR dst_mac[MAC_ADDR_LEN]; /* network order */
|
||||
};
|
||||
|
||||
struct layer_addr_ipv4
|
||||
{
|
||||
UINT32 saddr; /* network order */
|
||||
UINT32 daddr; /* network order */
|
||||
/* 2014-04-21 lijia add,
|
||||
Ϊ<>˿ռ䡢<D5BC><E4A1A2><EFBFBD><EFBFBD><EFBFBD>ԡ<EFBFBD><D4A1><EFBFBD>Ч<EFBFBD><D0A7>, <20><>ǿ<EFBFBD>ư<EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>,
|
||||
IP<49><50><EFBFBD>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>Ϣ, TCP<43><50>ֻ<EFBFBD><D6BB>ָ<EFBFBD><D6B8>ָ<EFBFBD><D6B8><EFBFBD>˿<EFBFBD><CBBF>ڴ<EFBFBD>,
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>Ԫ<EFBFBD><D4AA>ʱ, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫget_tuple4()<29><><EFBFBD><EFBFBD>.
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP, <20>˿<EFBFBD><CBBF><EFBFBD>ϢΪ0;
|
||||
*/
|
||||
UINT16 source; /* network order */
|
||||
UINT16 dest; /* network order */
|
||||
};
|
||||
|
||||
struct layer_addr_ipv6
|
||||
{
|
||||
UCHAR saddr[IPV6_ADDR_LEN] ; /* network order */
|
||||
UCHAR daddr[IPV6_ADDR_LEN] ; /* network order */
|
||||
/* 2014-04-21 lijia add,
|
||||
Ϊ<>˿ռ䡢<D5BC><E4A1A2><EFBFBD><EFBFBD><EFBFBD>ԡ<EFBFBD><D4A1><EFBFBD>Ч<EFBFBD><D0A7>, <20><>ǿ<EFBFBD>ư<EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>,
|
||||
IP<49><50><EFBFBD>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>Ϣ, TCP<43><50>ֻ<EFBFBD><D6BB>ָ<EFBFBD><D6B8>ָ<EFBFBD><D6B8><EFBFBD>˿<EFBFBD><CBBF>ڴ<EFBFBD>,
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>Ԫ<EFBFBD><D4AA>ʱ, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫget_tuple4()<29><><EFBFBD><EFBFBD>.
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP, <20>˿<EFBFBD><CBBF><EFBFBD>ϢΪ0;
|
||||
*/
|
||||
UINT16 source;/* network order */
|
||||
UINT16 dest;/* network order */
|
||||
};
|
||||
|
||||
struct layer_addr_tcp
|
||||
{
|
||||
UINT16 source; /* network order */
|
||||
UINT16 dest; /* network order */
|
||||
};
|
||||
|
||||
struct layer_addr_udp
|
||||
{
|
||||
UINT16 source; /* network order */
|
||||
UINT16 dest; /* network order */
|
||||
};
|
||||
|
||||
struct layer_addr_l2tp
|
||||
{
|
||||
UINT32 tunnelid; /* network order */
|
||||
UINT32 sessionid; /* network order */
|
||||
};
|
||||
|
||||
struct layer_addr
|
||||
{
|
||||
UCHAR addrtype; /* <20><>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> enum addr_type_t */
|
||||
/* Ϊ<>˷<EFBFBD><CBB7><EFBFBD>Ӧ<EFBFBD>ò<EFBFBD><C3B2><EFBFBD>ȡ<EFBFBD><C8A1>ַ, <20>˴<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ʡȥָ<C8A5><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
union
|
||||
{
|
||||
struct stream_tuple4_v4 *tuple4_v4;
|
||||
struct stream_tuple4_v6 *tuple4_v6;
|
||||
struct layer_addr_ipv4 *ipv4;
|
||||
struct layer_addr_ipv6 *ipv6;
|
||||
struct layer_addr_vlan *vlan;
|
||||
struct layer_addr_mac *mac;
|
||||
struct layer_addr_gre *gre;
|
||||
struct layer_addr_tcp *tcp;
|
||||
struct layer_addr_udp *udp;
|
||||
struct layer_addr_pppoe_session *pppoe_ses;
|
||||
struct layer_addr_l2tp *l2tp;
|
||||
void *paddr;
|
||||
};
|
||||
UCHAR addrlen; /* <20><>ַ<EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD> */
|
||||
};
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD>˽ṹ<CBBD><E1B9B9><EFBFBD>ں<EFBFBD>papp<70><70><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>ʱ, <20><><EFBFBD><EFBFBD>struct layer_addrǿת. */
|
||||
struct ipaddr
|
||||
{
|
||||
UCHAR addrtype;
|
||||
union
|
||||
{
|
||||
struct stream_tuple4_v4 *v4;
|
||||
struct stream_tuple4_v6 *v6;
|
||||
}paddr;
|
||||
// struct tuple4 *paddr;
|
||||
};
|
||||
|
||||
|
||||
/* to do:
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲻ<EFBFBD>ɼ<EFBFBD>, <20><>stream.h<><68><EFBFBD><EFBFBD>, <20>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>stream.h<>IJ<EFBFBD><C4B2><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>ͼ;
|
||||
*/
|
||||
struct streaminfo
|
||||
{
|
||||
struct layer_addr addr; //<2F><><EFBFBD><EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>Ϣ
|
||||
struct streaminfo *pfather;//<2F>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||||
UCHAR type; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
UCHAR threadnum; // <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
UCHAR dir:2; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч, <20><><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>˫<EFBFBD><CBAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0x01:c-->s; 0x02:s-->c; 0x03 c<-->s; */
|
||||
UCHAR curdir:2; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч, <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD>, 0x01:c-->s; 0x02:s-->c */
|
||||
UCHAR layer_dir:2; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч, <20><>ǰ<EFBFBD><C7B0><EFBFBD>ĵ<EFBFBD>ַ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ĭ<EFBFBD>Ϲ<EFBFBD><CFB9><EFBFBD>"<22><><EFBFBD>˿<EFBFBD><CBBF>ǿͻ<C7BF><CDBB><EFBFBD>"<22><>ͬ */
|
||||
UCHAR stream_dir:2; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч, <20><><EFBFBD>Ĵ洢<C4B4>ĵ<EFBFBD>ַ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ĭ<EFBFBD>Ϲ<EFBFBD><CFB9><EFBFBD>"<22><><EFBFBD>˿<EFBFBD><CBBF>ǿͻ<C7BF><CDBB><EFBFBD>"<22><>ͬ */
|
||||
UCHAR dirreverse; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ip<69><70>ַ<EFBFBD><D6B7>ת, <20><><EFBFBD><EFBFBD>"<22><><EFBFBD>˿<EFBFBD><CBBF>ǿͻ<C7BF><CDBB><EFBFBD>"<22><><EFBFBD><EFBFBD><EFBFBD>෴ */
|
||||
UCHAR opstate; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
UCHAR pktstate; //<2F><><EFBFBD>ӵİ<D3B5><C4B0><EFBFBD><EFBFBD><EFBFBD>
|
||||
UCHAR routedir; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч, <20><><EFBFBD>˹<EFBFBD>ָ<EFBFBD><D6B8>, <20><><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ͬ, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 0:<3A><><EFBFBD><EFBFBD>; 1:<3A><><EFBFBD><EFBFBD> */
|
||||
UCHAR addr_use_as_hash; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>addr<64>Ƿ<EFBFBD><C7B7><EFBFBD>ΪHASH<53><48><EFBFBD><EFBFBD><EFBFBD>ͱȽϵIJ<CFB5><C4B2><EFBFBD>, <20><>:MAC<41><43>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
|
||||
UCHAR stream_killed_flag; /* 2014-08-22 lijia add, <20><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>, <20>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Kill, ֮<><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>Drop<6F><70>Kill, <20><><EFBFBD><EFBFBD><EFBFBD>ٸ<EFBFBD><D9B8>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD> */
|
||||
UCHAR __pad__[7]; //<2F><><EFBFBD><EFBFBD>8<EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD>
|
||||
void *pproject; //ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD>̿<EFBFBD><CCBF><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ʹ<EFBFBD>ã<EFBFBD>
|
||||
void *pdetail; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8>Ϣ
|
||||
const void *p_layer_header; /* ָ<><EFBFBD><F2B1BEB2><EFBFBD>ͷ<EFBFBD><CDB7>ָ<EFBFBD><D6B8>, <20><><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ȡ<EFBFBD><C8A1><EFBFBD>ز<EFBFBD><D8B2><EFBFBD> */
|
||||
|
||||
#if 0 //FOR_108, ->pproject
|
||||
unsigned long stream_id;
|
||||
#endif
|
||||
|
||||
#if 0 //RAW_IP_FRAG_PKT, ->pproject
|
||||
raw_ipfrag_list_t *ipfrag_list; /* 2013-08-21 LiJia add, ԭʼ<D4AD><CABC>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
#endif
|
||||
|
||||
#if 0 //FOR_863, ->pproject
|
||||
char terminal_tag[40]; /* <20>û<EFBFBD><C3BB><EFBFBD>ǩ */
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
struct tcpdetail
|
||||
{
|
||||
|
||||
void *pdata; //<2F><><EFBFBD><EFBFBD>
|
||||
UINT32 datalen; //<2F><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
UINT32 lostlen;
|
||||
UCHAR multisynflag:4; // multi syn
|
||||
UCHAR needackflag:2; //<2F><>Ҫ<EFBFBD>ϴ<EFBFBD>ack<63><6B><EFBFBD><EFBFBD>
|
||||
UCHAR takeoverflag:2;
|
||||
UCHAR tcpstateflag; // <20><><EFBFBD>ڼ<EFBFBD>¼tcp<63>ĻỰSYN<59><4E><EFBFBD><EFBFBD>״̬
|
||||
UCHAR link_state; // <20><><EFBFBD>ӵ<EFBFBD>״̬
|
||||
UCHAR creat_mod;
|
||||
UINT32 regionid; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
|
||||
struct half_tcpstream *pclient; //<2F><>client<6E><74>TCP<43><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
struct half_tcpstream *pserver; //<2F><> server<65><72>TCP<43><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
UINT32 serverpkt;
|
||||
UINT32 clientpkt;
|
||||
UINT32 servercount;
|
||||
UINT32 clientcount;
|
||||
UINT64 creattime;
|
||||
UINT64 lastmtime;
|
||||
|
||||
UINT32 iserverseq; //<2F><><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD>洢seq
|
||||
UINT32 iclientseq; //<2F><><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD>洢seq
|
||||
void *apme; //Ӧ<>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void *pAllpktpme; //<2F><>״̬<D7B4><CCAC>tcp<63><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
struct proxy_node *pproxylist; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>鸺<EFBFBD><E9B8BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>
|
||||
|
||||
};
|
||||
struct udpdetail
|
||||
{
|
||||
void *pdata; //<2F><><EFBFBD><EFBFBD>
|
||||
UINT32 datalen; //<2F><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
UINT32 regionid; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
UINT32 serverpkt;
|
||||
UINT32 clientpkt;
|
||||
UINT32 servercount;
|
||||
UINT32 clientcount;
|
||||
UINT64 creattime;
|
||||
UINT64 lastmtime;
|
||||
void *apme; //Ӧ<>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
};
|
||||
|
||||
|
||||
//ҵ<><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD>ʱsession_state״̬
|
||||
#define SESSION_STATE_PENDING 0x01
|
||||
#define SESSION_STATE_DATA 0x02
|
||||
#define SESSION_STATE_CLOSE 0x04
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD>ʱ<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>ֵ<EFBFBD><D6B5>
|
||||
#define PROT_STATE_GIVEME 0x01
|
||||
#define PROT_STATE_DROPME 0x02
|
||||
#define PROT_STATE_KILLME 0x04
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
typedef struct _plugin_session_info
|
||||
{
|
||||
unsigned short plugid; //plugid<69><64>ƽ̨<C6BD><CCA8><EFBFBD><EFBFBD>
|
||||
char session_state; //<2F>Ự״̬<D7B4><CCAC>PENDING,DATA,CLOSE
|
||||
char _pad_; //<2F><><EFBFBD><EFBFBD>
|
||||
int buflen; //<2F><>ǰ<EFBFBD>ֶγ<D6B6><CEB3><EFBFBD>
|
||||
long long prot_flag; //<2F><>ǰ<EFBFBD>ֶε<D6B6>flagֵ
|
||||
void *buf; //<2F><>ǰ<EFBFBD>ֶ<EFBFBD>
|
||||
void* app_info; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
}stSessionInfo;
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
args:
|
||||
[IN]:
|
||||
stream:<3A><><EFBFBD>ṹ<EFBFBD><E1B9B9>ָ<EFBFBD><D6B8>;
|
||||
[OUT]
|
||||
addr_type:<3A><>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ADDR_TYPE_IPV4 or ADDR_TYPE_IPV6;
|
||||
|
||||
return value:
|
||||
NULL : error;
|
||||
NON-NULL : ָ<><D6B8><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>;
|
||||
*/
|
||||
struct layer_addr *get_stream_tuple4(struct streaminfo *this_stream);
|
||||
int get_thread_count(void);
|
||||
|
||||
typedef char (*STREAM_CB_FUN_T)(struct streaminfo *pstream,void **pme, int thread_seq,const void *raw_pkt);
|
||||
typedef char (*IPv4_CB_FUN_T)(struct streaminfo *pstream,unsigned char routedir,int thread_seq, const void *raw_pkt);
|
||||
typedef char (*IPv6_CB_FUN_T)(struct streaminfo *pstream,unsigned char routedir,int thread_seq, const void *raw_pkt);
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
a_*<2A><> <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ;
|
||||
f_*: <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD>Ϣ;
|
||||
raw_pkt: ԭʼ<D4AD><CABC>ָ<EFBFBD><D6B8>, ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ'raw_pkt_t';
|
||||
pme: ˽<><CBBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD>ʱΪNULL;
|
||||
thread_seq<65><71><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD>;
|
||||
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
APP_STATE_GIVEME<4D><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2B1BEBA><EFBFBD><EFBFBD>Ͱ<EFBFBD><CDB0><EFBFBD>
|
||||
APP_STATE_DROPME<4D><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2B1BEBA><EFBFBD><EFBFBD>Ͱ<EFBFBD><CDB0><EFBFBD>
|
||||
APP_STATE_FAWPKT<4B><54><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>
|
||||
APP_STATE_DROPPKT<4B><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>
|
||||
*/
|
||||
char IPv4_ENTRY_EXAMPLE( struct streaminfo *f_stream,unsigned char routedir,int thread_seq, const void *raw_pkt);
|
||||
char IPv6_ENTRY_EXAMPLE( struct streaminfo *f_stream,unsigned char routedir,int thread_seq,const void *raw_pkt);
|
||||
char TCP_ENTRY_EXAMPLE(struct streaminfo *a_tcp, void **pme, int thread_seq,const void *raw_pkt);
|
||||
char UDP_ENTRY_EXAMPLE(struct streaminfo *a_udp, void **pme, int thread_seq,const void *raw_pkt);
|
||||
|
||||
int stream_register_tcp_allpkt (STREAM_CB_FUN_T fun);
|
||||
int stream_register_tcp_takeover (STREAM_CB_FUN_T fun);
|
||||
|
||||
int stream_register_tcp (STREAM_CB_FUN_T fun);
|
||||
int stream_register_udp (STREAM_CB_FUN_T fun);
|
||||
int stream_register_ip (IPv4_CB_FUN_T fun);
|
||||
int stream_register_ipv6 (IPv6_CB_FUN_T fun);
|
||||
|
||||
|
||||
void *dictator_malloc(int thread_seq,size_t size);
|
||||
void dictator_free(int thread_seq,void *pbuf);
|
||||
void *dictator_realloc(int thread_seq, void* pbuf, size_t size);
|
||||
|
||||
char PROT_PROCESS(stSessionInfo* session_info, void **pme, int thread_seq,struct streaminfo *a_stream,void *a_packet);
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>Ӧ<EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ǩ */
|
||||
//int terminal_tag_probe(struct streaminfo *stream, struct mesa_tcp_hdr *this_tcphdr,void *rawippkt);
|
||||
const unsigned char *get_terminal_tag(struct streaminfo *stream);
|
||||
//int MESA_kill_tcp(struct streaminfo *stream, struct ip *a_packet);
|
||||
int MESA_kill_tcp(struct streaminfo *stream, const void *raw_pkt);
|
||||
int MESA_kill_tcp_synack(struct streaminfo *stream, const void *raw_pkt);
|
||||
|
||||
/*
|
||||
ARG:
|
||||
stream: <20><><EFBFBD>ṹ<EFBFBD><E1B9B9>ָ<EFBFBD><D6B8>;
|
||||
payload: Ҫ<><D2AA><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>;
|
||||
payload_len: Ҫ<><D2AA><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݸ<EFBFBD><DDB8>س<EFBFBD><D8B3><EFBFBD>;
|
||||
raw_pkt: ԭʼ<D4AD><CABC>ָ<EFBFBD><D6B8>;
|
||||
snd_routedir: Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵķ<DDB5><C4B7><EFBFBD>, ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ:stream->routedir ,
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭʼ<D4AD><CABC>ͬ<EFBFBD><CDAC>, snd_dir = stream->routedir,
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, snd_dir = stream->routedir ^ 3(<28><>1<--->2, 2<--->1<><31><EFBFBD><EFBFBD>ѧת<D1A7><D7AA>);
|
||||
return value:
|
||||
-1: error.
|
||||
>0: <20><><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݰ<EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>(payload_len + <20>ײ<EFBFBD><D7B2><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>);
|
||||
*/
|
||||
int MESA_inject_pkt(struct streaminfo *stream, const char *payload, int payload_len, const void *raw_pkt, UCHAR snd_routedir);
|
||||
|
||||
/* 2014-07-31 LiJia add, for set one stream unorder number */
|
||||
int tcp_set_single_stream_max_unorder(struct streaminfo *stream, UCHAR dir, UCHAR unorder_num);
|
||||
|
||||
raw_ipfrag_list_t *get_raw_frag_list(struct streaminfo *stream);
|
||||
//void frags_list_free_one(raw_ipfrag_list_t *frags_list, int);
|
||||
//raw_ipfrag_list_t *frags_list_merge(raw_ipfrag_list_t *new_merge_list, raw_ipfrag_list_t *old_list);
|
||||
//raw_ipfrag_list_t *raw_ip_frag_list_attach(int thread_num);
|
||||
//void raw_ip_frag_list_detach(int thread_num);
|
||||
|
||||
|
||||
unsigned long get_stream_id(struct streaminfo *stream);
|
||||
|
||||
void MESA_stream_list_free(struct streaminfo *heap_stream);
|
||||
struct streaminfo *MESA_stream_list_dup(struct streaminfo *stack_stream, int reverse);
|
||||
int MESA_stream_list_cmp(struct streaminfo *stream1, struct streaminfo *stream2);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,336 +0,0 @@
|
||||
#ifndef _APP_STREAM_H_
|
||||
#define _APP_STREAM_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip6.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define FOR_863 (0) /* for 863<36><33>Ŀ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>ǩģ<C7A9><C4A3> */
|
||||
#define FOR_108 (0)
|
||||
#define RAW_IP_FRAG_PKT (0) /* 2013-08-21 LiJia add, <20><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB>ԭʼIP<49><50>Ƭ<EFBFBD><C6AC> */
|
||||
|
||||
typedef unsigned char UINT8;
|
||||
typedef unsigned long long UINT64;
|
||||
typedef unsigned int UINT32;
|
||||
typedef unsigned short UINT16;
|
||||
typedef unsigned char UCHAR;
|
||||
|
||||
//<2F><><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define DIR_C2S 0x01
|
||||
#define DIR_S2C 0x02
|
||||
#define DIR_DOUBLE 0x03
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define DIR_ROUTE_UP 0x00
|
||||
#define DIR_ROUTE_DOWN 0x01
|
||||
|
||||
//<2F><>ַ<EFBFBD><D6B7><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
|
||||
#define ADDR_TYPE_IPV4 1
|
||||
#define ADDR_TYPE_IPV6 2
|
||||
#define ADDR_TYPE_VLAN 3
|
||||
|
||||
#define TCP_TAKEOVER_STATE_FLAG_OFF 0
|
||||
#define TCP_TAKEOVER_STATE_FLAG_ON 1
|
||||
|
||||
//Ӧ<>ò㿴<C3B2><E3BFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
|
||||
#define OP_STATE_PENDING 0
|
||||
#define OP_STATE_REMOVE_ME 1
|
||||
#define OP_STATE_CLOSE 2
|
||||
#define OP_STATE_DATA 3
|
||||
|
||||
//Ӧ<>ò㷵<C3B2>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define APP_STATE_GIVEME 0x00
|
||||
#define APP_STATE_DROPME 0x01
|
||||
#define APP_STATE_FAWPKT 0x00
|
||||
#define APP_STATE_DROPPKT 0x10
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
|
||||
#define STREAM_TYPE_TCP 1
|
||||
#define STREAM_TYPE_UDP 2
|
||||
#define STREAM_TYPE_VLAN 3
|
||||
#define STREAM_TYPE_SOCKS4 4
|
||||
#define STREAM_TYPE_SOCKS5 5
|
||||
#define STREAM_TYPE_HTTP_PROXY 6
|
||||
|
||||
#define STREAM_TYPE_MPLS 7
|
||||
|
||||
#define PROXY_STATE_SEL 0
|
||||
#define PROXY_STATE_LINK_IN 1
|
||||
|
||||
|
||||
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
struct proxy_node
|
||||
{
|
||||
UINT16 iType; // <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 0 <20><>ʾ<EFBFBD><CABE>Ч
|
||||
UINT16 uiPort; // <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>
|
||||
UINT16 uiUserLen;
|
||||
UINT16 uiPwdLen;
|
||||
UINT16 uiApendLen;
|
||||
|
||||
UCHAR opstate; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
UCHAR dealstate; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
UINT32 uiIP; // <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<49><50>ַv4, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
||||
UCHAR *pIpv6; // <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<49><50>ַ, v6<76><36>ַ
|
||||
UCHAR *pUser; // <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>
|
||||
UCHAR *pPwd; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
UCHAR *append; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>url
|
||||
|
||||
void *apme; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>url
|
||||
struct proxy_node *pnext;
|
||||
} ;
|
||||
|
||||
|
||||
#if RAW_IP_FRAG_PKT
|
||||
typedef struct raw_ipfrag_list{
|
||||
void *frag_packet;
|
||||
int pkt_len;
|
||||
int type; /* IPv4 or IPv6 */
|
||||
struct raw_ipfrag_list *next;
|
||||
}raw_ipfrag_list_t;
|
||||
#endif
|
||||
|
||||
struct buf_unorder
|
||||
{
|
||||
struct buf_unorder *next;
|
||||
struct buf_unorder *prev;
|
||||
void *data;
|
||||
UINT32 len;
|
||||
UINT32 tcpdatalen;
|
||||
UINT32 urg_ptr;
|
||||
char fin;
|
||||
char urg;
|
||||
char rst;
|
||||
unsigned char pad;
|
||||
UINT32 seq;
|
||||
UINT32 ack;
|
||||
#if RAW_IP_FRAG_PKT
|
||||
raw_ipfrag_list_t *ipfrag_list;
|
||||
#endif
|
||||
};
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD>嶨<EFBFBD>壺*/
|
||||
struct half_tcpstream
|
||||
{
|
||||
UCHAR *data;
|
||||
UINT32 offset; /*data<74>е<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>TCP<43><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>*/
|
||||
UINT32 count; /*<2A><><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊֹ<CEAA><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>*/
|
||||
UINT32 count_new; /*<2A><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>*/
|
||||
UINT32 count_ideal; /*<2A><><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊֹ<CEAA><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>*/
|
||||
UINT32 pktcout; /*<2A><><EFBFBD><EFBFBD><EFBFBD>ۼƵ<DBBC><C6B5><EFBFBD><EFBFBD>İ<EFBFBD><C4B0><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
UINT32 totallost; /*<2A><><EFBFBD><EFBFBD><EFBFBD>ۼƶ<DBBC><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
UINT32 seq; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>seq<65><71><EFBFBD><EFBFBD>*/
|
||||
UINT32 first_data_seq; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ĵ<EFBFBD>seq<65><71><EFBFBD><EFBFBD>*/
|
||||
UINT32 ack_seq; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>*/
|
||||
UINT16 window; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>С*/
|
||||
UCHAR maxunorder; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ*/
|
||||
UCHAR finstate; /*fin״̬*/
|
||||
UINT32 pktcout_new; /*<2A><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD>İ<EFBFBD><C4B0><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
UINT32 unorder_cnt;
|
||||
struct buf_unorder *unorderlist; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
struct buf_unorder *unorderlisttail; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><CEB2>ָ<EFBFBD><D6B8>*/
|
||||
|
||||
};
|
||||
|
||||
#ifndef STRUCT_TUPLE4_DEFINED
|
||||
#define STRUCT_TUPLE4_DEFINED (1)
|
||||
struct tuple4 {
|
||||
UINT32 saddr;
|
||||
UINT32 daddr;
|
||||
UINT16 source;
|
||||
UINT16 dest;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct tuple6
|
||||
{
|
||||
UCHAR saddr[16] ;
|
||||
UCHAR daddr[16] ;
|
||||
UINT16 source;
|
||||
UINT16 dest;
|
||||
};
|
||||
|
||||
#define VLAN_ID_LEN 4
|
||||
struct tuplevlan
|
||||
{
|
||||
UCHAR vlan_id[VLAN_ID_LEN];
|
||||
};
|
||||
|
||||
struct tupell2tp
|
||||
{
|
||||
UINT32 tunnelid;
|
||||
UINT32 sessionid;
|
||||
};
|
||||
struct ipaddr
|
||||
{
|
||||
UCHAR addrtype; //<2F><>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD> ipv6 or ipv4
|
||||
union
|
||||
{
|
||||
struct tuple4 *v4;
|
||||
struct tuple6 *v6;
|
||||
}paddr;
|
||||
// struct tuple4 *paddr;
|
||||
};
|
||||
|
||||
struct streaminfo
|
||||
{
|
||||
struct ipaddr addr; //ip<69>˿<EFBFBD><CBBF><EFBFBD>Ϣ
|
||||
struct streaminfo *pfather;//<2F>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||||
UCHAR type; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
UCHAR threadnum; // <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
UCHAR dir:2; // <20><><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0x01 c-->s 0x02 s-->c 0x03 c<-->s
|
||||
UCHAR curdir:2; // <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>0x01 c-->s 0x02 s-->c
|
||||
UCHAR dirreverse:4; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ip<69><70>ַ<EFBFBD><D6B7>ת
|
||||
UCHAR opstate; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
UCHAR pktstate; //<2F><><EFBFBD>ӵİ<D3B5><C4B0><EFBFBD><EFBFBD><EFBFBD>
|
||||
UCHAR routedir; //<2F><><EFBFBD><EFBFBD>λΪ1<CEAA><31>ʾ<EFBFBD><CABE><EFBFBD>У<EFBFBD>Ϊ0<CEAA><30>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>; <20>ڴ<EFBFBD><DAB4><EFBFBD>ģʽ<C4A3><CABD>,<2C><>7λ<37><CEBB>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>豸ID
|
||||
UCHAR __pad__[2]; //<2F><><EFBFBD><EFBFBD>8<EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD>
|
||||
void *pproject; //ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD>̿<EFBFBD><CCBF><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ʹ<EFBFBD>ã<EFBFBD>
|
||||
void *pdetail; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8>Ϣ
|
||||
#if FOR_108
|
||||
unsigned long stream_id;
|
||||
#endif
|
||||
#if RAW_IP_FRAG_PKT
|
||||
raw_ipfrag_list_t *ipfrag_list; /* 2013-08-21 LiJia add, ԭʼ<D4AD><CABC>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
#endif
|
||||
|
||||
#if FOR_863
|
||||
char terminal_tag[40]; /* <20>û<EFBFBD><C3BB><EFBFBD>ǩ */
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
struct tcpdetail
|
||||
{
|
||||
|
||||
void *pdata; //<2F><><EFBFBD><EFBFBD>
|
||||
UINT32 datalen; //<2F><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
UINT32 lostlen; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
|
||||
UCHAR multisynflag:4; // multi syn
|
||||
UCHAR needackflag:2; //<2F><>Ҫ<EFBFBD>ϴ<EFBFBD>ack<63><6B><EFBFBD><EFBFBD>
|
||||
UCHAR takeoverflag:2;
|
||||
UCHAR tcpstateflag; // <20><><EFBFBD>ڼ<EFBFBD>¼tcp<63>ĻỰSYN<59><4E><EFBFBD><EFBFBD>״̬
|
||||
UCHAR link_state; // <20><><EFBFBD>ӵ<EFBFBD>״̬
|
||||
UCHAR pad[5];
|
||||
|
||||
struct half_tcpstream *pclient; //<2F><>client<6E><74>TCP<43><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
struct half_tcpstream *pserver; //<2F><> server<65><72>TCP<43><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
UINT32 serverpkt;
|
||||
UINT32 clientpkt;
|
||||
UINT32 servercount;
|
||||
UINT32 clientcount;
|
||||
UINT64 creattime;
|
||||
UINT64 lastmtime;
|
||||
|
||||
UINT32 iserverseq; //<2F><><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD>洢seq
|
||||
UINT32 iclientseq; //<2F><><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD>洢seq
|
||||
void *apme; //Ӧ<>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void *pAllpktpme; //<2F><>״̬<D7B4><CCAC>tcp<63><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
struct proxy_node *pproxylist; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>鸺<EFBFBD><E9B8BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>
|
||||
|
||||
};
|
||||
struct udpdetail
|
||||
{
|
||||
void *pdata; //<2F><><EFBFBD><EFBFBD>
|
||||
UINT32 datalen; //<2F><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
UINT32 pad;
|
||||
UINT32 serverpkt;
|
||||
UINT32 clientpkt;
|
||||
UINT32 servercount;
|
||||
UINT32 clientcount;
|
||||
UINT64 creattime;
|
||||
UINT64 lastmtime;
|
||||
void *apme; //Ӧ<>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
};
|
||||
|
||||
|
||||
//ҵ<><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD>ʱsession_state״̬
|
||||
#define SESSION_STATE_PENDING 0x01
|
||||
#define SESSION_STATE_DATA 0x02
|
||||
#define SESSION_STATE_CLOSE 0x04
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD>ʱ<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>ֵ<EFBFBD><D6B5>
|
||||
#define PROT_STATE_GIVEME 0x01
|
||||
#define PROT_STATE_DROPME 0x02
|
||||
#define PROT_STATE_KILLME 0x04
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
typedef struct _plugin_session_info
|
||||
{
|
||||
unsigned short plugid; //plugid<69><64>ƽ̨<C6BD><CCA8><EFBFBD><EFBFBD>
|
||||
char session_state; //<2F>Ự״̬<D7B4><CCAC>PENDING,DATA,CLOSE
|
||||
char _pad_; //<2F><><EFBFBD><EFBFBD>
|
||||
int buflen; //<2F><>ǰ<EFBFBD>ֶγ<D6B6><CEB3><EFBFBD>
|
||||
long long prot_flag; //<2F><>ǰ<EFBFBD>ֶε<D6B6>flagֵ
|
||||
void *buf; //<2F><>ǰ<EFBFBD>ֶ<EFBFBD>
|
||||
void* app_info; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
}stSessionInfo;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
a_*<2A><> <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
|
||||
f_*: <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
|
||||
a_packet: ԭʼip<69><70><EFBFBD><EFBFBD>
|
||||
pme: ˽<><CBBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD>ʱΪNULL
|
||||
thread_seq<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
APP_STATE_GIVEME<4D><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2B1BEBA><EFBFBD><EFBFBD>Ͱ<EFBFBD><CDB0><EFBFBD>
|
||||
APP_STATE_DROPME<4D><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2B1BEBA><EFBFBD><EFBFBD>Ͱ<EFBFBD><CDB0><EFBFBD>
|
||||
APP_STATE_FAWPKT<4B><54><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>
|
||||
APP_STATE_DROPPKT<4B><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>
|
||||
*/
|
||||
char IP_ENTRY( struct streaminfo *f_stream,unsigned char routedir,int thread_seq,struct ip * a_packet);
|
||||
char IPv6_ENTRY( struct streaminfo *f_stream,unsigned char routedir,int thread_seq,struct ip6_hdr *a_packet);
|
||||
char TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a_packet);
|
||||
char UDP_ENTRY(struct streaminfo *a_udp, void **pme, int thread_seq,void *a_packet);
|
||||
|
||||
int stream_register_tcp_allpkt (char (*x)(struct streaminfo *pstream,void **pme, int thread_seq,void *a_packet));
|
||||
int stream_register_tcp_takeover (char (*x)(struct streaminfo *pstream,void **pme, int thread_seq,void *a_packet));
|
||||
|
||||
int stream_register_tcp (char (*x)(struct streaminfo *pstream,void **pme, int thread_seq,void *a_packet));
|
||||
int stream_register_udp (char (*x)(struct streaminfo *pstream,void **pme, int thread_seq,void *a_packet));
|
||||
//int stream_register_ip (char (*x)(struct streaminfo *pstream,void **pme, int thread_seq,void *a_packet));
|
||||
int stream_register_ip (char (*x)(struct streaminfo *f_stream,unsigned char routedir,int thread_seq,struct ip * a_packet));
|
||||
int stream_register_ipv6 (char (*x)(struct streaminfo *f_stream,unsigned char routedir,int thread_seq,struct ip6_hdr *a_packet));
|
||||
|
||||
char * printaddr (struct ipaddr *paddrinfo,int threadindex);
|
||||
|
||||
|
||||
void *dictator_malloc(int thread_seq,int size);
|
||||
void dictator_free(int thread_seq,void *pbuf);
|
||||
|
||||
char PROT_PROCESS(stSessionInfo* session_info, void **pme, int thread_seq,struct streaminfo *a_stream,void *a_packet);
|
||||
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>Ӧ<EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ǩ */
|
||||
int terminal_tag_probe(struct streaminfo *stream, struct tcphdr *this_tcphdr,void *rawippkt);
|
||||
const unsigned char *get_terminal_tag(struct streaminfo *stream);
|
||||
int MESA_kill_tcp(struct streaminfo *stream, struct ip *a_packet);
|
||||
|
||||
#if RAW_IP_FRAG_PKT
|
||||
extern raw_ipfrag_list_t **G_IP_FRAG_LIST;
|
||||
void frags_list_free(raw_ipfrag_list_t *frags_list);
|
||||
raw_ipfrag_list_t *frags_list_merge(raw_ipfrag_list_t *new_merge_list, raw_ipfrag_list_t *old_list);
|
||||
#endif
|
||||
|
||||
#if FOR_108
|
||||
unsigned long papp_get_streamid();
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
16
test/CMakeLists.txt
Normal file
16
test/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
add_executable(maat_demo maat_demo.cpp)
|
||||
target_link_libraries(maat_demo maat_frame_shared)
|
||||
|
||||
add_executable(test_maatframe test_maatframe.cpp)
|
||||
target_link_libraries(test_maatframe maat_frame_shared gtest)
|
||||
|
||||
configure_file(table_info.conf table_info.conf COPYONLY)
|
||||
configure_file(maat_json.json maat_json.json COPYONLY)
|
||||
configure_file(reset_redis4maat.sh reset_redis4maat.sh COPYONLY)
|
||||
file(COPY conf DESTINATION ./)
|
||||
file(COPY rule DESTINATION ./)
|
||||
file(COPY testdata DESTINATION ./)
|
||||
file(COPY testdata_uni2ascii DESTINATION ./)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(test_maatframe)
|
||||
@@ -1,6 +0,0 @@
|
||||
LIBS=../lib/libmaatframe.so
|
||||
INC=-I../inc/ -I/usr/include/MESA/
|
||||
all:
|
||||
g++ -o maat_test -g -Wall maat_test.cpp $(INC) $(LIBS) -lMESA_handle_logger
|
||||
clean:
|
||||
rm maat_test test.log* -f
|
||||
@@ -558,7 +558,74 @@ void test_offset_str_scan(Maat_feather_t feather,const char* table_name)
|
||||
test_offset_str_scan_with_chunk(feather,table_name,1460);
|
||||
return;
|
||||
}
|
||||
void test_compile_accept_tags(Maat_feather_t feather)
|
||||
{
|
||||
int ret1=0, ret2=0;
|
||||
int table_id=0;
|
||||
scan_status_t mid=NULL;
|
||||
struct Maat_rule_t result[4];
|
||||
const char* should_hit="string bbb should hit";
|
||||
const char* should_not_hit="string aaa should not hit";
|
||||
const char* table_name="HTTP_URL";
|
||||
table_id=Maat_table_register(feather,table_name);
|
||||
if(table_id==-1)
|
||||
{
|
||||
printf("Database table %s register failed.\n",table_name);
|
||||
return;
|
||||
}
|
||||
|
||||
ret1=Maat_full_scan_string(feather, table_id,CHARSET_GBK, should_not_hit, strlen(should_not_hit),
|
||||
result,NULL, 4,
|
||||
&mid, 0);
|
||||
ret2=Maat_full_scan_string(feather, table_id,CHARSET_GBK, should_hit, strlen(should_hit),
|
||||
result,NULL, 4,
|
||||
&mid, 0);
|
||||
if(ret1<=0&&ret2>0)
|
||||
{
|
||||
printf("Test compile accept tags success.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Test compile accept tags failed.\n");
|
||||
}
|
||||
Maat_clean_status(&mid);
|
||||
return;
|
||||
}
|
||||
|
||||
void accept_tags_entry_cb(int table_id,const char* table_line,void* u_para)
|
||||
{
|
||||
char status[32]={0};
|
||||
int entry_id=-1,seq=-1;
|
||||
int is_valid=0;
|
||||
sscanf(table_line,"%d\t%s\t%d\t%d",&seq,status,&entry_id,&is_valid);
|
||||
printf("Test plugin accept tags loading %d %s.\n",seq, status);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void test_plugin_accept_tags(Maat_feather_t feather)
|
||||
{
|
||||
int table_id=0,ret=0;
|
||||
const char* table_name="TEST_EFFECTIVE_RANGE_TABLE";
|
||||
table_id=Maat_table_register(feather,table_name);
|
||||
if(table_id==-1)
|
||||
{
|
||||
printf("Database table %s register failed.\n",table_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret=Maat_table_callback_register(feather, table_id,
|
||||
NULL,
|
||||
accept_tags_entry_cb,
|
||||
NULL,
|
||||
NULL);
|
||||
if(ret<0)
|
||||
{
|
||||
printf("Maat callback register table %s error.\n",table_name);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
void test_longer_service_define(Maat_feather_t feather, struct Maat_rule_t* rule)
|
||||
{
|
||||
int ret=0;
|
||||
@@ -990,12 +1057,12 @@ void maat_test_print_usage(void)
|
||||
{
|
||||
printf("Maat Test Usage:\n");
|
||||
printf("\tSource:\n");
|
||||
printf("\t\t-j Test updating from %s.\n",json_path);
|
||||
printf("\t\t-j Test updating from %s. https://www.sojson.com/yasuo.html\n",json_path);
|
||||
printf("\t\t-u Load config from %s, and monitor %s. Need manually move inc index.\n",ful_cfg_dir,inc_cfg_dir);
|
||||
printf("\t\t-r Read config redis %s:%u db0.\n",test_maat_redis_ip,test_maat_redis_port);
|
||||
printf("\tOption:\n");
|
||||
printf("\t\t-d Deferred Loading config.\n");
|
||||
printf("example: ./maat_test -j -d\n");
|
||||
printf("example: ./maat_demo -j -d\n");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1009,6 +1076,7 @@ int main(int argc,char* argv[])
|
||||
const char* stat_file="./scan_staus.log";
|
||||
const char* decrypt_key="mesa2017wy";
|
||||
const char* test_digest_file="./testdata/digest_test.data";
|
||||
const char* accept_tags="{\"tags\":[{\"tag\":\"location\",\"value\":\"北京/朝阳/华严北里/甲22号\"},{\"tag\":\"isp\",\"value\":\"移动\"}]}";
|
||||
int scan_interval_ms=1;
|
||||
int effective_interval_ms=0;
|
||||
|
||||
@@ -1065,13 +1133,11 @@ int main(int argc,char* argv[])
|
||||
Maat_set_feather_opt(feather, MAAT_OPT_STAT_ON, NULL, 0);
|
||||
Maat_set_feather_opt(feather, MAAT_OPT_PERF_ON, NULL, 0);
|
||||
Maat_set_feather_opt(feather, MAAT_OPT_SCAN_DETAIL, &scan_detail, sizeof(scan_detail));
|
||||
Maat_set_feather_opt(feather, MAAT_OPT_ACCEPT_TAGS, accept_tags, strlen(accept_tags)+1);
|
||||
Maat_initiate_feather(feather);
|
||||
|
||||
if(feather==NULL)
|
||||
{
|
||||
printf("Maat initial error, see %s\n",log_file);
|
||||
return -1;
|
||||
}
|
||||
printf("Maat initiating, see %s\n",log_file);
|
||||
|
||||
if(deferred_load_on==1)
|
||||
{
|
||||
printf("Deferred Load ON, Waiting...\n");
|
||||
@@ -1122,6 +1188,10 @@ int main(int argc,char* argv[])
|
||||
Maat_clean_status(&mid);
|
||||
|
||||
test_offset_str_scan(feather,"IMAGE_FP");
|
||||
|
||||
test_plugin_accept_tags(feather);
|
||||
test_compile_accept_tags(feather);
|
||||
|
||||
int value=0;
|
||||
if(1==using_redis)
|
||||
{
|
||||
File diff suppressed because one or more lines are too long
@@ -1,5 +0,0 @@
|
||||
0000000004
|
||||
123 1 1 1 1 0 anything 1
|
||||
124 1 1 1 1 0 anything 1
|
||||
125 1 1 1 1 0 anything 1
|
||||
126 1 1 1 1 0 anything 1
|
||||
@@ -1,3 +0,0 @@
|
||||
0000000002
|
||||
3 2 100 500 1
|
||||
6 5 2014 2016 1
|
||||
@@ -1,8 +0,0 @@
|
||||
0000000007
|
||||
0 123 1
|
||||
1 123 1
|
||||
0 124 1
|
||||
2 124 1
|
||||
3 125 1
|
||||
4 126 1
|
||||
5 126 1
|
||||
@@ -1,4 +0,0 @@
|
||||
0000000003
|
||||
2 1 abckkk&123 1 0 0 1
|
||||
4 3 action=search\&query=(.*) 2 0 0 1
|
||||
5 4 should_not_hit_any_rule 0 0 0 1
|
||||
@@ -1,3 +0,0 @@
|
||||
0000000002
|
||||
0 0 4 10.0.6.201 255.255.0.0 0 65535 0.0.0.0 255.255.255.255 0 65535 6 0 1
|
||||
1 0 4 192.168.0.1 255.255.255.255 0 65535 0.0.0.0 255.255.255.255 0 65535 6 0 1
|
||||
@@ -1,4 +0,0 @@
|
||||
0000000003
|
||||
1 192.168.0.1 101
|
||||
2 192.168.0.2 101
|
||||
3 192.168.1.1 102
|
||||
@@ -1,4 +0,0 @@
|
||||
0000000003
|
||||
1 3388 99 1
|
||||
2 3355 66 1
|
||||
3 cccc 11 1
|
||||
@@ -1,4 +0,0 @@
|
||||
0000000003
|
||||
1 plugname1 1
|
||||
2 plugname2 1
|
||||
3 plugname3 1
|
||||
@@ -1 +0,0 @@
|
||||
0000000000
|
||||
@@ -1,7 +0,0 @@
|
||||
COMPILE 4 ./maat_json.json_iris_tmp/COMPILE.local
|
||||
GROUP 7 ./maat_json.json_iris_tmp/GROUP.local
|
||||
TEST_PLUGIN_TABLE 3 ./maat_json.json_iris_tmp/TEST_PLUGIN_TABLE.local
|
||||
IP_CONFIG 2 ./maat_json.json_iris_tmp/IP_CONFIG.local
|
||||
CONTENT_SIZE 2 ./maat_json.json_iris_tmp/CONTENT_SIZE.local
|
||||
HTTP_URL 3 ./maat_json.json_iris_tmp/HTTP_URL.local
|
||||
QD_ENTRY_INFO 3 ./maat_json.json_iris_tmp/QD_ENTRY_INFO.local
|
||||
@@ -11,7 +11,7 @@
|
||||
#id name type
|
||||
#
|
||||
#For plugin table
|
||||
#id name type valid_column
|
||||
#id name type valid_column tag_column
|
||||
#
|
||||
#For expr/expr_plus Table
|
||||
#id name type src_charset dst_charset do_merge cross_cache quick_mode
|
||||
@@ -22,8 +22,9 @@
|
||||
3 KEYWORDS_TABLE expr UTF8 GBK/BIG5/UNICODE/UTF8/unicode_ascii_esc/unicode_ascii_aligned/unicode_ncr_dec/unicode_ncr_hex yes 0
|
||||
4 IP_CONFIG ip --
|
||||
5 CONTENT_SIZE intval --
|
||||
6 QD_ENTRY_INFO plugin 4
|
||||
6 QD_ENTRY_INFO plugin 4 --
|
||||
7 FILE_DIGEST digest --
|
||||
8 HTTP_REGION expr_plus GBK GBK no 0
|
||||
9 SIM_URL similar --
|
||||
10 IMAGE_FP expr UTF8 UTF8 yes 128 quickoff
|
||||
11 TEST_EFFECTIVE_RANGE_TABLE plugin 4 5 --
|
||||
996
test/test_maatframe.cpp
Normal file
996
test/test_maatframe.cpp
Normal file
@@ -0,0 +1,996 @@
|
||||
#include "Maat_rule.h"
|
||||
#include "stream_fuzzy_hash.h"
|
||||
#include "Maat_command.h"
|
||||
#include <MESA/MESA_handle_logger.h>
|
||||
#include <dlfcn.h>
|
||||
#include <assert.h>
|
||||
#include <sys/socket.h>//inet_addr
|
||||
#include <netinet/in.h>//inet_addr
|
||||
#include <arpa/inet.h>//inet_addr
|
||||
#include <net/if.h>
|
||||
#include <sys/types.h>//fstat
|
||||
#include <sys/ioctl.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <MESA/stream.h>
|
||||
#include <sys/types.h>//fstat
|
||||
#include <sys/stat.h>//fstat
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
const char* test_maat_redis_ip="127.0.0.1";
|
||||
unsigned short test_maat_redis_port=6379;
|
||||
const char* json_path="./maat_json.json";
|
||||
const char* ful_cfg_dir="./rule/full/index/";
|
||||
const char* inc_cfg_dir="./rule/inc/index/";
|
||||
#define WAIT_FOR_EFFECTIVE_US 1000*1000
|
||||
extern int my_scandir(const char *dir, struct dirent ***namelist,
|
||||
int(*filter)(const struct dirent *),
|
||||
int(*compar)(const void *, const void *));
|
||||
|
||||
|
||||
Maat_feather_t g_feather=NULL;
|
||||
void *logger=NULL;
|
||||
int g_iThreadNum=4;
|
||||
const char* table_info_path="./table_info.conf";
|
||||
int scan_interval_ms=1;
|
||||
int effective_interval_ms=0;
|
||||
|
||||
void Maat_read_entry_start_cb(int update_type,void* u_para)
|
||||
{
|
||||
return;
|
||||
}
|
||||
void Maat_read_entry_cb(int table_id,const char* table_line,void* u_para)
|
||||
{
|
||||
char ip_str[16]={0};
|
||||
int entry_id=-1,seq=-1;
|
||||
unsigned int ip_uint=0;
|
||||
int is_valid=0;
|
||||
unsigned int local_ip_nr=16820416;//192.168.0.1
|
||||
sscanf(table_line,"%d\t%s\t%d\t%d",&seq,ip_str,&entry_id,&is_valid);
|
||||
inet_pton(AF_INET,ip_str,&ip_uint);
|
||||
if(local_ip_nr==ip_uint)
|
||||
{
|
||||
if(is_valid==1)
|
||||
{
|
||||
//printf("Load entry id %d success.\n",entry_id);
|
||||
EXPECT_EQ(entry_id, 101);
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("Offload entry id %d success.\n",entry_id);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
void Maat_read_entry_finish_cb(void* u_para)
|
||||
{
|
||||
Maat_feather_t feather=u_para;
|
||||
long long version=0;
|
||||
int ret=0,is_last_updating_table=0;
|
||||
ret=Maat_read_state(feather,MAAT_STATE_VERSION, &version, sizeof(version));
|
||||
EXPECT_EQ(ret, 0);
|
||||
ret=Maat_read_state(feather,MAAT_STATE_LAST_UPDATING_TABLE, &is_last_updating_table, sizeof(is_last_updating_table));
|
||||
EXPECT_EQ(ret, 0);
|
||||
//printf("Maat Version %lld at plugin finish callback, is_last_update=%d.\n",version,is_last_updating_table);
|
||||
|
||||
return;
|
||||
}
|
||||
void test_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=0,ret=0;
|
||||
table_id=Maat_table_register(feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
ret=Maat_table_callback_register(feather, table_id,
|
||||
start,
|
||||
update,
|
||||
finish,
|
||||
u_para);
|
||||
|
||||
ASSERT_GT(ret, 0);
|
||||
|
||||
}
|
||||
|
||||
TEST(PluginTable, Callback)
|
||||
{
|
||||
test_plugin_table(g_feather, "QD_ENTRY_INFO",
|
||||
Maat_read_entry_start_cb,
|
||||
Maat_read_entry_cb,
|
||||
Maat_read_entry_finish_cb,
|
||||
g_feather,
|
||||
logger);
|
||||
|
||||
}
|
||||
TEST(StringScan, Full)
|
||||
{
|
||||
int ret=0;
|
||||
int table_id=0;
|
||||
struct Maat_rule_t result[4];
|
||||
int found_pos[4];
|
||||
const char* table_name="HTTP_URL";
|
||||
scan_status_t mid=NULL;
|
||||
const char* scan_data="http://www.cyberessays.com/search_results.php?action=search&query=yulingjing,abckkk,1234567";
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
ret=Maat_full_scan_string(g_feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
|
||||
result,found_pos, 4, &mid, 0);
|
||||
|
||||
EXPECT_GE(ret, 1);
|
||||
Maat_clean_status(&mid);
|
||||
}
|
||||
|
||||
TEST(IPScan, IPv4)
|
||||
{
|
||||
int table_id=0,ret=0;
|
||||
const char* table_name="IP_CONFIG";
|
||||
struct Maat_rule_t result[4];
|
||||
scan_status_t mid=NULL;
|
||||
struct ipaddr ipv4_addr;
|
||||
struct stream_tuple4_v4 v4_addr;
|
||||
ipv4_addr.addrtype=ADDR_TYPE_IPV4;
|
||||
inet_pton(AF_INET,"10.0.6.205",&(v4_addr.saddr));
|
||||
v4_addr.source=htons(50001);
|
||||
inet_pton(AF_INET,"10.0.6.201",&(v4_addr.daddr));
|
||||
v4_addr.dest=htons(80);
|
||||
ipv4_addr.v4=&v4_addr;
|
||||
|
||||
const char* scan_data="http://www.cyberessays.com/search_results.php?action=search&query=yulingjing,abckkk,1234567";
|
||||
table_id=Maat_table_register(g_feather,"HTTP_URL");
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
ret=Maat_full_scan_string(g_feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
|
||||
result,NULL, 4, &mid, 0);
|
||||
EXPECT_GE(ret, 1);
|
||||
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
|
||||
EXPECT_GT(table_id, 0);
|
||||
|
||||
ret=Maat_scan_proto_addr(g_feather,table_id,&ipv4_addr,6,result,4, &mid,0);
|
||||
|
||||
EXPECT_GT(ret, 0);
|
||||
Maat_clean_status(&mid);
|
||||
return;
|
||||
}
|
||||
TEST(IPScan, IPv6)
|
||||
|
||||
{
|
||||
int table_id=0,ret=0;
|
||||
struct Maat_rule_t result[4];
|
||||
struct ipaddr ipv6_addr;
|
||||
struct stream_tuple4_v6 v6_addr;
|
||||
scan_status_t mid=NULL;
|
||||
|
||||
ipv6_addr.addrtype=ADDR_TYPE_IPV6;
|
||||
inet_pton(AF_INET6,"2001:da8:205:1::101",&(v6_addr.saddr));
|
||||
v6_addr.source=htons(50001);
|
||||
inet_pton(AF_INET6,"2001:da8:205:1::102",&(v6_addr.daddr));
|
||||
v6_addr.dest=htons(80);
|
||||
ipv6_addr.v6=&v6_addr;
|
||||
const char* table_name="IP_CONFIG";
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
EXPECT_GT(table_id, 0);
|
||||
|
||||
//for improving performance.
|
||||
Maat_set_scan_status(g_feather, &mid, MAAT_SET_SCAN_LAST_REGION,NULL, 0);
|
||||
ret=Maat_scan_proto_addr(g_feather,table_id,&ipv6_addr,6,result,4, &mid,0);
|
||||
EXPECT_EQ(ret, -2);
|
||||
Maat_clean_status(&mid);
|
||||
return;
|
||||
}
|
||||
|
||||
TEST(IntervalScan, Pure)
|
||||
{
|
||||
int table_id=0,ret=0;
|
||||
int scan_val=2015;
|
||||
struct Maat_rule_t result[4];
|
||||
const char* table_name="CONTENT_SIZE";
|
||||
scan_status_t mid=NULL;
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
ret=Maat_scan_intval(g_feather, table_id, scan_val, result,4, &mid, 0);
|
||||
EXPECT_EQ(ret, -2);
|
||||
Maat_clean_status(&mid);
|
||||
return;
|
||||
}
|
||||
TEST(DigestScan, Pure)
|
||||
{
|
||||
int table_id=0,ret=0,hit_cnt=0;
|
||||
struct stat digest_fstat;
|
||||
unsigned long long read_size=0,scan_offset=0;
|
||||
char digest_test_buff[4096]={0};
|
||||
const char* file_name="./testdata/digest_test.data";
|
||||
const char* table_name="FILE_DIGEST";
|
||||
struct Maat_rule_t result[4];
|
||||
stream_para_t sp=NULL;
|
||||
scan_status_t mid=NULL;
|
||||
table_id=Maat_table_register(g_feather, table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
ret=stat(file_name,&digest_fstat);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
FILE* fp=fopen(file_name,"r");
|
||||
ASSERT_FALSE(fp==NULL);
|
||||
|
||||
sp=Maat_stream_scan_digest_start(g_feather, table_id, digest_fstat.st_size, 0);
|
||||
while(0==feof(fp))
|
||||
{
|
||||
read_size=fread(digest_test_buff,1,sizeof(digest_test_buff),fp);
|
||||
ret=Maat_stream_scan_digest(&sp, digest_test_buff, read_size, scan_offset, result,4, &mid);
|
||||
scan_offset+=read_size;
|
||||
if(ret>0)
|
||||
{
|
||||
hit_cnt++;
|
||||
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
Maat_stream_scan_string_end(&sp);
|
||||
EXPECT_GE(hit_cnt, 1);
|
||||
Maat_clean_status(&mid);
|
||||
return;
|
||||
}
|
||||
TEST(StringScan, EncodedURL)
|
||||
{
|
||||
const char* url_utf8="www.google.com/?q=C%23%E4%B8%AD%E5%9B%BD";
|
||||
const char* url_gb2312="www.baidu.com/?wd=C%23%D6%D0%B9%FA";
|
||||
int table_id=0,ret=0;
|
||||
struct Maat_rule_t result[4];
|
||||
int found_pos[4];
|
||||
|
||||
const char* table_name="HTTP_URL";
|
||||
scan_status_t mid=NULL;
|
||||
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
ret=Maat_full_scan_string(g_feather, table_id,CHARSET_GBK, url_utf8, strlen(url_utf8),
|
||||
result,found_pos, 4,
|
||||
&mid, 0);
|
||||
EXPECT_GE(ret, 1);
|
||||
Maat_clean_status(&mid);
|
||||
|
||||
ret=Maat_full_scan_string(g_feather, table_id,CHARSET_GBK, url_gb2312, strlen(url_gb2312),
|
||||
result,found_pos, 4,
|
||||
&mid, 0);
|
||||
EXPECT_GE(ret, 1);
|
||||
Maat_clean_status(&mid);
|
||||
return;
|
||||
}
|
||||
TEST(StringScan, UnicodeEscape)
|
||||
{
|
||||
const char* test_data_dir="./testdata_uni2ascii";
|
||||
struct dirent **namelist;
|
||||
FILE* fp=NULL;
|
||||
char file_path[256]={0};
|
||||
char buff[4096];
|
||||
size_t read_len=0;
|
||||
int table_id=0,ret=0;
|
||||
struct Maat_rule_t result[4];
|
||||
stream_para_t sp=NULL;
|
||||
int n=0,i=0, hit_cnt=0;
|
||||
const char* table_name="KEYWORDS_TABLE";
|
||||
scan_status_t mid=NULL;
|
||||
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
n = my_scandir(test_data_dir, &namelist, NULL, (int (*)(const void*, const void*))alphasort);
|
||||
ASSERT_GT(n, 0);
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
if((strcmp(namelist[i]->d_name, ".") == 0) || (strcmp(namelist[i]->d_name, "..") == 0))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
snprintf(file_path,sizeof(file_path),"%s/%s",test_data_dir,namelist[i]->d_name);
|
||||
fp=fopen(file_path,"rb");
|
||||
|
||||
if(fp==NULL)
|
||||
{
|
||||
printf("fopen %s error.\n",file_path);;
|
||||
continue;
|
||||
}
|
||||
sp=Maat_stream_scan_string_start(g_feather,table_id,0);
|
||||
ASSERT_FALSE(sp==NULL);
|
||||
|
||||
read_len=fread(buff,1,sizeof(buff),fp);
|
||||
while(read_len>0)
|
||||
{
|
||||
|
||||
ret=Maat_stream_scan_string(&sp,CHARSET_NONE,buff,read_len
|
||||
,result, NULL, 4, &mid);
|
||||
read_len=fread(buff,1,sizeof(buff),fp);
|
||||
if(ret>0)
|
||||
{
|
||||
hit_cnt++;
|
||||
}
|
||||
}
|
||||
Maat_stream_scan_string_end(&sp);
|
||||
fclose(fp);
|
||||
EXPECT_GT(hit_cnt, 0);
|
||||
EXPECT_GE(result[0].config_id, 130);//130, 131
|
||||
Maat_clean_status(&mid);
|
||||
}
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
free(namelist[i]);
|
||||
}
|
||||
free(namelist);
|
||||
return;
|
||||
}
|
||||
TEST(StringScan, MaatUnescape)
|
||||
{
|
||||
int ret=0;
|
||||
int table_id=0;
|
||||
struct Maat_rule_t result[4];
|
||||
const char* scan_data="Batman\\:Take me Home.Superman/:Fine,stay with me.";
|
||||
const char* table_name="KEYWORDS_TABLE";
|
||||
scan_status_t mid=NULL;
|
||||
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
ret=Maat_full_scan_string(g_feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
|
||||
result, NULL, 4,
|
||||
&mid, 0);
|
||||
EXPECT_EQ(ret, 1);
|
||||
EXPECT_EQ(result[0].config_id, 132);
|
||||
Maat_clean_status(&mid);
|
||||
|
||||
return;
|
||||
}
|
||||
TEST(StringScan, StreamInput)
|
||||
{
|
||||
int table_id=0,ret=0;
|
||||
struct Maat_rule_t result[4];
|
||||
const char* scan_data="http://www.cyberessays.com/search_results.php?action=search&query=yulingjing,abckkk,1234567";
|
||||
const char* table_name="HTTP_URL";
|
||||
scan_status_t mid=NULL;
|
||||
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
struct Maat_hit_detail_t *hit_detail=(struct Maat_hit_detail_t *)malloc(sizeof(struct Maat_hit_detail_t)*10);
|
||||
stream_para_t sp=Maat_stream_scan_string_start(g_feather,table_id,0);
|
||||
ASSERT_FALSE(sp==NULL);
|
||||
int detail_ret=0;
|
||||
|
||||
ret=Maat_stream_scan_string_detail(&sp,CHARSET_NONE,"www.cyberessays.com", strlen("www.cyberessays.com")
|
||||
,result,4,hit_detail,10
|
||||
,&detail_ret, &mid);
|
||||
EXPECT_EQ(ret, 0);
|
||||
ret=Maat_stream_scan_string_detail(&sp,CHARSET_NONE,scan_data, strlen(scan_data)
|
||||
,result,4,hit_detail,10
|
||||
,&detail_ret, &mid);
|
||||
Maat_stream_scan_string_end(&sp);
|
||||
free(hit_detail);
|
||||
EXPECT_EQ(ret, 1);
|
||||
EXPECT_EQ(result[0].config_id, 125);
|
||||
Maat_clean_status(&mid);
|
||||
return;
|
||||
}
|
||||
TEST(SimilarScan, Pure)
|
||||
{
|
||||
int ret=0;
|
||||
int table_id=0;
|
||||
struct Maat_rule_t result[4];
|
||||
const char* scan_data="mwss.xiu.youku.com/live/hls/v1/0000000000000000000000001526a0a8/714.ts?&token=98765";
|
||||
const char* table_name="SIM_URL";
|
||||
scan_status_t mid=NULL;
|
||||
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
|
||||
ret=Maat_similar_scan_string(g_feather, table_id, scan_data, strlen(scan_data),
|
||||
result, 4,
|
||||
&mid, 0);
|
||||
EXPECT_EQ(ret, 1);
|
||||
EXPECT_EQ(result[0].config_id, 135);
|
||||
Maat_clean_status(&mid);
|
||||
return;
|
||||
}
|
||||
TEST(TableInfo, Conjunction)
|
||||
{
|
||||
int ret=0;
|
||||
int table_id=0,conj_table_id=0;
|
||||
struct Maat_rule_t result[4];
|
||||
int found_pos[4];
|
||||
const char* scan_data="soq is using table conjunction function.http://www.3300av.com/novel/27122.txt";
|
||||
const char* table_name="HTTP_URL", *conj_table_name="HTTP_HOST";
|
||||
scan_status_t mid=NULL;
|
||||
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
conj_table_id=Maat_table_register(g_feather,conj_table_name);
|
||||
ASSERT_EQ(conj_table_id, table_id);
|
||||
|
||||
ret=Maat_full_scan_string(g_feather, conj_table_id,CHARSET_GBK, scan_data, strlen(scan_data),
|
||||
result,found_pos, 4,
|
||||
&mid, 0);
|
||||
EXPECT_EQ(ret, 2);
|
||||
EXPECT_EQ(result[0].config_id, 134);
|
||||
EXPECT_EQ(result[1].config_id, 133);
|
||||
|
||||
Maat_clean_status(&mid);
|
||||
return;
|
||||
}
|
||||
void test_offset_str_scan_with_chunk(int chunk_size)
|
||||
{
|
||||
int table_id=0,ret=0;
|
||||
int read_size=0,pass_flag=0;
|
||||
struct Maat_rule_t result[4];
|
||||
scan_status_t mid=NULL;
|
||||
//const char* fn="./testdata/mesa_logo.jpg";
|
||||
const char* table_name="IMAGE_FP";
|
||||
const char* fn="./testdata/mesa_logo.jpg";
|
||||
FILE* fp=fopen(fn,"r");
|
||||
ASSERT_FALSE(fp==NULL);
|
||||
|
||||
char scan_data[chunk_size];
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
|
||||
struct Maat_hit_detail_t *hit_detail=(struct Maat_hit_detail_t *)malloc(sizeof(struct Maat_hit_detail_t)*10);
|
||||
stream_para_t sp=Maat_stream_scan_string_start(g_feather,table_id,0);
|
||||
int detail_ret=0;
|
||||
|
||||
ASSERT_FALSE(sp==NULL);
|
||||
|
||||
while(0==feof(fp))
|
||||
{
|
||||
read_size=fread(scan_data,1,sizeof(scan_data),fp);
|
||||
ret=Maat_stream_scan_string_detail(&sp,CHARSET_NONE,scan_data,read_size
|
||||
,result,4,hit_detail,10
|
||||
,&detail_ret,&mid);
|
||||
if(ret>0)
|
||||
{
|
||||
pass_flag=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(pass_flag, 1);
|
||||
EXPECT_EQ(result[0].config_id, 136);
|
||||
|
||||
Maat_stream_scan_string_end(&sp);
|
||||
free(hit_detail);
|
||||
fclose(fp);
|
||||
Maat_clean_status(&mid);
|
||||
return;
|
||||
}
|
||||
|
||||
TEST(StringScan, OffsetChunk64)
|
||||
{
|
||||
test_offset_str_scan_with_chunk(64);
|
||||
return;
|
||||
}
|
||||
TEST(StringScan, OffsetChunk1460)
|
||||
{
|
||||
|
||||
test_offset_str_scan_with_chunk(1460);
|
||||
return;
|
||||
}
|
||||
void accept_tags_entry_cb(int table_id,const char* table_line,void* u_para)
|
||||
{
|
||||
char status[32]={0};
|
||||
int entry_id=-1,seq=-1;
|
||||
int is_valid=0;
|
||||
sscanf(table_line,"%d\t%s\t%d\t%d",&seq,status,&entry_id,&is_valid);
|
||||
EXPECT_STREQ(status ,"SUCCESS");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
TEST(RuleTags, Plugin)
|
||||
{
|
||||
int table_id=0,ret=0;
|
||||
const char* table_name="TEST_EFFECTIVE_RANGE_TABLE";
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
ret=Maat_table_callback_register(g_feather, table_id,
|
||||
NULL,
|
||||
accept_tags_entry_cb,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
ASSERT_GE(ret, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
TEST(RuleTags, Compile)
|
||||
{
|
||||
int ret=0;
|
||||
int table_id=0;
|
||||
scan_status_t mid=NULL;
|
||||
struct Maat_rule_t result[4];
|
||||
const char* should_hit="string bbb should hit";
|
||||
const char* should_not_hit="string aaa should not hit";
|
||||
const char* table_name="HTTP_URL";
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
ret=Maat_full_scan_string(g_feather, table_id,CHARSET_GBK, should_not_hit, strlen(should_not_hit),
|
||||
result,NULL, 4,
|
||||
&mid, 0);
|
||||
|
||||
EXPECT_LE(ret, 0);
|
||||
|
||||
ret=Maat_full_scan_string(g_feather, table_id,CHARSET_GBK, should_hit, strlen(should_hit),
|
||||
result,NULL, 4,
|
||||
&mid, 0);
|
||||
EXPECT_EQ(ret, 1);
|
||||
Maat_clean_status(&mid);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
TEST(StreamFuzzyHash, Pure)
|
||||
{
|
||||
const size_t FILE_CHUNK_SIZE=4096;
|
||||
char * file_buff=NULL,*sfh_ordered=NULL,*sfh_unorder=NULL;
|
||||
int read_size=0,ret=0,chunk_num=0,i=0,idx=0;
|
||||
unsigned long long *offset=NULL;
|
||||
unsigned long long file_size=0,tmp=0,hash_length=0;
|
||||
const char* filename="./testdata/digest_test.data";
|
||||
|
||||
FILE* fp=fopen(filename,"r");
|
||||
sfh_instance_t * fhandle = NULL;
|
||||
struct stat file_info;
|
||||
ret=stat(filename, &file_info);
|
||||
ASSERT_TRUE(ret==0);
|
||||
|
||||
file_size=file_info.st_size;
|
||||
file_buff=(char*)malloc(file_size);
|
||||
ret=fread(file_buff,1,file_size,fp);
|
||||
ASSERT_TRUE((unsigned long long)ret==file_size);
|
||||
|
||||
chunk_num=file_size/FILE_CHUNK_SIZE;
|
||||
if(file_size%FILE_CHUNK_SIZE==0)
|
||||
{
|
||||
chunk_num=file_size/FILE_CHUNK_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
chunk_num=file_size/FILE_CHUNK_SIZE+1;
|
||||
}
|
||||
offset=(unsigned long long*)malloc(sizeof(unsigned long long)*chunk_num);
|
||||
for(i=0;i<chunk_num;i++)
|
||||
{
|
||||
offset[i]=FILE_CHUNK_SIZE*i;
|
||||
}
|
||||
fhandle=SFH_instance(0);
|
||||
SFH_feed(fhandle,file_buff,file_size,0);
|
||||
hash_length = SFH_status(fhandle, HASH_LENGTH);
|
||||
sfh_ordered=(char*)malloc(hash_length);
|
||||
SFH_digest(fhandle, sfh_ordered, hash_length);
|
||||
SFH_release(fhandle);
|
||||
fhandle=NULL;
|
||||
|
||||
//shuffle file offsets
|
||||
srand(5210);
|
||||
for(i=0;i<chunk_num;i++)
|
||||
{
|
||||
idx=rand()%chunk_num;
|
||||
tmp=offset[i];
|
||||
offset[i]=offset[idx];
|
||||
offset[idx]=tmp;
|
||||
}
|
||||
fhandle=SFH_instance(0);
|
||||
for(i=0;i<chunk_num;i++)
|
||||
{
|
||||
if(offset[i]+FILE_CHUNK_SIZE>file_size)
|
||||
{
|
||||
read_size=file_size-offset[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
read_size=FILE_CHUNK_SIZE;
|
||||
}
|
||||
SFH_feed(fhandle,file_buff+offset[i],read_size,offset[i]);
|
||||
}
|
||||
hash_length = SFH_status(fhandle, HASH_LENGTH);
|
||||
sfh_unorder=(char*)malloc(hash_length);
|
||||
SFH_digest(fhandle, sfh_unorder, hash_length);
|
||||
//printf("%s %u %lf %s\n",path,digest_fstat.st_size,file_entropy,digest_result_buff);
|
||||
SFH_release(fhandle);
|
||||
EXPECT_STREQ(sfh_ordered, sfh_unorder);
|
||||
|
||||
fclose(fp);
|
||||
free(file_buff);
|
||||
free(sfh_ordered);
|
||||
free(sfh_unorder);
|
||||
free(offset);
|
||||
return;
|
||||
}
|
||||
TEST(ScanResult, LongerServiceDefine)
|
||||
{
|
||||
int ret=0;
|
||||
int table_id=0;
|
||||
scan_status_t mid=NULL;
|
||||
|
||||
struct Maat_rule_t result[4];
|
||||
const char* scan_data="soq is using table conjunction function.http://www.3300av.com/novel/27122.txt";
|
||||
const char* table_name="HTTP_URL";
|
||||
|
||||
table_id=Maat_table_register(g_feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
ret=Maat_full_scan_string(g_feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
|
||||
result, NULL, 4,
|
||||
&mid, 0);
|
||||
EXPECT_EQ(ret, 2);
|
||||
EXPECT_EQ(result[1].config_id, 133);
|
||||
EXPECT_GT(result[1].serv_def_len, 128);
|
||||
|
||||
char* buff=(char*)malloc(sizeof(char)*result[1].serv_def_len);
|
||||
ret=Maat_read_rule(g_feather, result+1, MAAT_RULE_SERV_DEFINE, buff, result[1].serv_def_len);
|
||||
EXPECT_EQ(ret, result[1].serv_def_len);
|
||||
Maat_clean_status(&mid);
|
||||
free(buff);
|
||||
return;
|
||||
}
|
||||
class MaatCmdTest : public testing::Test
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
void *logger=NULL;
|
||||
logger=MESA_create_runtime_log_handle("test_maat_redis.log",0);
|
||||
|
||||
_shared_feather=Maat_feather(g_iThreadNum, table_info_path, logger);
|
||||
Maat_set_feather_opt(_shared_feather,MAAT_OPT_INSTANCE_NAME,"redis", strlen("redis")+1);
|
||||
Maat_set_feather_opt(_shared_feather, MAAT_OPT_REDIS_IP, test_maat_redis_ip, strlen(test_maat_redis_ip)+1);
|
||||
Maat_set_feather_opt(_shared_feather, MAAT_OPT_REDIS_PORT, &test_maat_redis_port, sizeof(test_maat_redis_port));
|
||||
Maat_set_feather_opt(_shared_feather, MAAT_OPT_SCANDIR_INTERVAL_MS,&scan_interval_ms, sizeof(scan_interval_ms));
|
||||
//Set a short intevral for testing.
|
||||
Maat_set_feather_opt(_shared_feather, MAAT_OPT_EFFECT_INVERVAL_MS,&effective_interval_ms, sizeof(effective_interval_ms));
|
||||
Maat_initiate_feather(_shared_feather);
|
||||
Maat_cmd_flushDB(_shared_feather);
|
||||
}
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
Maat_burn_feather(_shared_feather);
|
||||
|
||||
}
|
||||
// Some expensive resource shared by all tests.
|
||||
static Maat_feather_t _shared_feather;
|
||||
};
|
||||
Maat_feather_t MaatCmdTest::_shared_feather;
|
||||
|
||||
int test_add_expr_command(Maat_feather_t feather,const char* region_table,int config_id, int timeout,int label_id, const char* keywords)
|
||||
{
|
||||
struct Maat_cmd_t* cmd=NULL;
|
||||
struct Maat_rule_t rule;
|
||||
char huge_serv_def[1024*2];
|
||||
memset(huge_serv_def,'s',sizeof(huge_serv_def));
|
||||
struct Maat_region_t region;
|
||||
int group_num=1,ret=0;
|
||||
memset(&rule,0,sizeof(rule));
|
||||
rule.config_id=config_id;
|
||||
|
||||
strcpy(rule.service_defined,"maat_command");
|
||||
//MUST acqire by function, because Maat_cmd_t has some hidden members.
|
||||
cmd=Maat_create_cmd(&rule, group_num);
|
||||
cmd->expire_after=timeout;
|
||||
cmd->label_id=label_id;
|
||||
memset(®ion,0,sizeof(region));
|
||||
region.region_type=REGION_EXPR;
|
||||
region.table_name=region_table;
|
||||
region.expr_rule.district=NULL;
|
||||
region.expr_rule.keywords=keywords;
|
||||
region.expr_rule.expr_type=EXPR_TYPE_AND;
|
||||
region.expr_rule.match_method=MATCH_METHOD_SUB;
|
||||
region.expr_rule.hex_bin=UNCASE_PLAIN;
|
||||
Maat_cmd_set_opt(cmd, MAAT_RULE_SERV_DEFINE, huge_serv_def, sizeof(huge_serv_def));
|
||||
Maat_add_region2cmd(cmd, 0, ®ion);
|
||||
//use pipeline model.
|
||||
ret=Maat_cmd_append(feather, cmd, MAAT_OP_ADD);
|
||||
if(ret<0)
|
||||
{
|
||||
printf("Add Maat command %d failed.\n",rule.config_id);
|
||||
Maat_free_cmd(cmd);
|
||||
return 0;
|
||||
}
|
||||
//cmd has been saved in feather, so free cmd before commit is allowed.
|
||||
Maat_free_cmd(cmd);
|
||||
ret=Maat_cmd_commit(feather);
|
||||
if(ret<0)
|
||||
{
|
||||
printf("Commit Maat command %d failed.\n",rule.config_id);
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
int del_command(Maat_feather_t feather,int config_id)
|
||||
{
|
||||
struct Maat_cmd_t* cmd=NULL;
|
||||
struct Maat_rule_t rule;
|
||||
int ret=0;
|
||||
memset(&rule,0,sizeof(rule));
|
||||
rule.config_id=config_id;
|
||||
cmd=Maat_create_cmd(&rule, 0);
|
||||
ret=Maat_cmd(feather, cmd, MAAT_OP_DEL);
|
||||
if(ret<0)
|
||||
{
|
||||
printf("Delete Maat command %d failed.\n",rule.config_id);
|
||||
}
|
||||
Maat_free_cmd(cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST_F(MaatCmdTest, Expr)
|
||||
{
|
||||
const char* scan_data="Hiredis is a minimalistic C client library for the Redis database.\r\n";
|
||||
const char* table_name="HTTP_URL";
|
||||
|
||||
const char* keywords1="Hiredis";
|
||||
const char* keywords2="C Client";
|
||||
char escape_buff1[256],escape_buff2[256];
|
||||
char keywords[256];
|
||||
scan_status_t mid=NULL;
|
||||
int config_id=-1, table_id=0, ret=0;
|
||||
int output_ids[4];
|
||||
int output_id_cnt=0;
|
||||
struct Maat_rule_t result;
|
||||
int timeout=0;//seconds
|
||||
int label_id=5210;
|
||||
long long version_before=0,version_after=0;
|
||||
Maat_feather_t feather=MaatCmdTest::_shared_feather;
|
||||
|
||||
Maat_str_escape(escape_buff1, sizeof(escape_buff1),keywords1);
|
||||
Maat_str_escape(escape_buff2, sizeof(escape_buff2),keywords2);
|
||||
snprintf(keywords,sizeof(keywords),"%s&%s",escape_buff1,escape_buff2);
|
||||
config_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", 1);
|
||||
|
||||
ret=Maat_read_state(feather,MAAT_STATE_VERSION, &version_before, sizeof(version_before));
|
||||
test_add_expr_command(feather,table_name,config_id, 0, label_id, keywords);
|
||||
usleep(WAIT_FOR_EFFECTIVE_US);//waiting for commands go into effect
|
||||
|
||||
ret=Maat_read_state(feather,MAAT_STATE_VERSION, &version_after, sizeof(version_after));
|
||||
EXPECT_EQ(ret, 0);
|
||||
table_id=Maat_table_register(feather,table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
ret=Maat_full_scan_string(feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
|
||||
&result,NULL, 1,
|
||||
&mid, 0);
|
||||
EXPECT_GT(ret, 0);
|
||||
EXPECT_EQ(result.config_id, config_id);
|
||||
|
||||
Maat_clean_status(&mid);
|
||||
output_id_cnt=Maat_cmd_select(feather,label_id, output_ids, 4);
|
||||
EXPECT_EQ(output_id_cnt, 1);
|
||||
EXPECT_EQ(output_ids[0], config_id);
|
||||
|
||||
|
||||
del_command(feather, config_id);
|
||||
usleep(WAIT_FOR_EFFECTIVE_US);//waiting for commands go into effect
|
||||
ret=Maat_full_scan_string(feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
|
||||
&result,NULL, 1,
|
||||
&mid, 0);
|
||||
EXPECT_EQ(ret, 0);
|
||||
Maat_clean_status(&mid);
|
||||
|
||||
timeout=1;
|
||||
config_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", 1);
|
||||
test_add_expr_command(feather,table_name,config_id, timeout, label_id, keywords);
|
||||
usleep(timeout*1000*1000+WAIT_FOR_EFFECTIVE_US);
|
||||
ret=Maat_full_scan_string(feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
|
||||
&result,NULL, 1,
|
||||
&mid, 0);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
TEST_F(MaatCmdTest, Lines)
|
||||
{
|
||||
const int TEST_CMD_LINE_NUM=4;
|
||||
const struct Maat_line_t *p_line[TEST_CMD_LINE_NUM];
|
||||
struct Maat_line_t line_rule[TEST_CMD_LINE_NUM];
|
||||
char table_line[TEST_CMD_LINE_NUM][128];
|
||||
int ret=0,i=0;
|
||||
Maat_feather_t feather=MaatCmdTest::_shared_feather;
|
||||
memset(&line_rule,0,sizeof(line_rule));
|
||||
for(i=0;i<TEST_CMD_LINE_NUM;i++)
|
||||
{
|
||||
line_rule[i].label_id=0;
|
||||
line_rule[i].rule_id=(int)Maat_cmd_incrby(feather,"TEST_PLUG_SEQ", 1);
|
||||
line_rule[i].table_name="QD_ENTRY_INFO";
|
||||
snprintf(table_line[i],sizeof(table_line[i]),"1\t192.168.0.1\t%d\t1",100+i);
|
||||
line_rule[i].table_line=table_line[i];
|
||||
line_rule[i].expire_after=0;
|
||||
p_line[i]=line_rule+i;
|
||||
}
|
||||
|
||||
|
||||
ret=Maat_cmd_set_lines(feather, p_line,TEST_CMD_LINE_NUM, MAAT_OP_ADD);
|
||||
EXPECT_GT(ret, 0);
|
||||
|
||||
usleep(WAIT_FOR_EFFECTIVE_US);
|
||||
|
||||
for(i=0;i<TEST_CMD_LINE_NUM;i++)
|
||||
{
|
||||
line_rule[i].table_line=NULL;
|
||||
}
|
||||
ret=Maat_cmd_set_lines(feather, p_line,TEST_CMD_LINE_NUM, MAAT_OP_DEL);
|
||||
EXPECT_GT(ret, 0);
|
||||
|
||||
return;
|
||||
}
|
||||
TEST_F(MaatCmdTest, IP)
|
||||
{
|
||||
struct Maat_cmd_t* cmd=NULL;
|
||||
struct Maat_rule_t rule;
|
||||
int config_id=0,timeout=4;
|
||||
long long version_before=0,version_after=0;
|
||||
const char* region_table="IP_CONFIG";
|
||||
struct Maat_region_t region;
|
||||
int group_num=1,ret=0;
|
||||
memset(&rule,0,sizeof(rule));
|
||||
Maat_feather_t feather=MaatCmdTest::_shared_feather;
|
||||
|
||||
//MUST acquire by Maat_cmd_incrby to guarantee a unique compile ID.
|
||||
config_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", 1);
|
||||
rule.config_id=config_id;
|
||||
|
||||
strcpy(rule.service_defined,"maat_command");
|
||||
//MUST acqire by function, because Maat_cmd_t has some hidden members.
|
||||
cmd=Maat_create_cmd(&rule, group_num);
|
||||
cmd->expire_after=timeout;
|
||||
cmd->label_id=0; //no lable
|
||||
memset(®ion,0,sizeof(region));
|
||||
region.region_type=REGION_IP;
|
||||
region.table_name=region_table;
|
||||
region.ip_rule.addr_type=ADDR_TYPE_IPv4;
|
||||
region.ip_rule.direction=ADDR_DIR_DOUBLE;
|
||||
region.ip_rule.src_ip="172.0.0.1";
|
||||
region.ip_rule.mask_src_ip="255.255.255.255";
|
||||
region.ip_rule.src_port=53331;
|
||||
region.ip_rule.mask_src_port=0;//means any port should hit.
|
||||
|
||||
region.ip_rule.dst_ip="172.0.0.2";
|
||||
region.ip_rule.mask_dst_ip="255.255.255.255";
|
||||
region.ip_rule.dst_port=80;
|
||||
region.ip_rule.mask_dst_port=65535;
|
||||
region.ip_rule.protocol=0;//means any protocol should hit.
|
||||
Maat_add_region2cmd(cmd, 0, ®ion);
|
||||
|
||||
ret=Maat_read_state(feather,MAAT_STATE_VERSION, &version_before, sizeof(version_before));
|
||||
EXPECT_EQ(ret, 0);
|
||||
ret=Maat_cmd(feather, cmd, MAAT_OP_ADD);
|
||||
EXPECT_GE(ret, 0);
|
||||
Maat_free_cmd(cmd);
|
||||
cmd=NULL;
|
||||
|
||||
//TEST if the command go into effective.
|
||||
usleep(WAIT_FOR_EFFECTIVE_US); //waiting for commands go into effect
|
||||
|
||||
ret=Maat_read_state(feather,MAAT_STATE_VERSION, &version_after, sizeof(version_after));
|
||||
|
||||
struct ipaddr ipv4_addr;
|
||||
struct stream_tuple4_v4 v4_addr;
|
||||
ipv4_addr.addrtype=ADDR_TYPE_IPV4;
|
||||
inet_pton(AF_INET,region.ip_rule.src_ip,&(v4_addr.saddr));
|
||||
v4_addr.source=htons(region.ip_rule.src_port+1);//Not use the exactly port for testing port mask.
|
||||
inet_pton(AF_INET,region.ip_rule.dst_ip,&(v4_addr.daddr));
|
||||
v4_addr.dest=htons(region.ip_rule.dst_port);
|
||||
ipv4_addr.v4=&v4_addr;
|
||||
|
||||
int table_id=0;
|
||||
struct Maat_rule_t result;
|
||||
scan_status_t mid=NULL;
|
||||
table_id=Maat_table_register(feather,region_table);
|
||||
ASSERT_GE(table_id, 0);
|
||||
|
||||
ret=Maat_scan_proto_addr(feather,table_id,&ipv4_addr,6,&result,1, &mid,0);
|
||||
EXPECT_EQ(ret, 1);
|
||||
EXPECT_EQ(result.config_id, config_id);
|
||||
|
||||
Maat_clean_status(&mid);
|
||||
//reset timeout.
|
||||
cmd=Maat_create_cmd(&rule, 0);
|
||||
cmd->expire_after=10;
|
||||
ret=Maat_cmd(feather, cmd, MAAT_OP_RENEW_TIMEOUT);
|
||||
EXPECT_EQ(ret ,1);
|
||||
|
||||
usleep(2*1000*1000+WAIT_FOR_EFFECTIVE_US);//wait for commands expired.
|
||||
Maat_free_cmd(cmd);
|
||||
cmd=NULL;
|
||||
|
||||
ret=Maat_scan_proto_addr(feather,table_id,&ipv4_addr,6,&result,1, &mid,0);
|
||||
EXPECT_EQ(ret, 1);
|
||||
|
||||
Maat_clean_status(&mid);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
int g_test_update_paused=0;
|
||||
void pause_update_test_entry_cb(int table_id,const char* table_line,void* u_para)
|
||||
{
|
||||
char status[32]={0};
|
||||
int entry_id=-1,seq=-1;
|
||||
int is_valid=0;
|
||||
sscanf(table_line,"%d\t%s\t%d\t%d",&seq,status,&entry_id,&is_valid);
|
||||
EXPECT_EQ(g_test_update_paused, 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
TEST_F(MaatCmdTest, PauseUpdate)
|
||||
{
|
||||
Maat_feather_t feather=MaatCmdTest::_shared_feather;
|
||||
int value=0, ret=0, table_id=0;
|
||||
struct Maat_line_t line_rule;
|
||||
char* line=NULL;
|
||||
const char* table_name="QD_ENTRY_INFO";
|
||||
table_id=Maat_table_register(feather, table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
ret=Maat_table_callback_register(g_feather, table_id,
|
||||
NULL,
|
||||
pause_update_test_entry_cb,
|
||||
NULL,
|
||||
NULL);
|
||||
Maat_set_feather_opt(feather, MAAT_OPT_ENABLE_UPDATE, &value, sizeof(value));
|
||||
g_test_update_paused=1;
|
||||
line_rule.label_id=0;
|
||||
line_rule.rule_id=(int)Maat_cmd_incrby(feather,"TEST_PLUG_SEQ", 1);
|
||||
line_rule.table_name=table_name;
|
||||
asprintf(&line,"1\t192.168.0.1\t101\t1");
|
||||
line_rule.table_line=line;
|
||||
line_rule.expire_after=0;
|
||||
ret=Maat_cmd_set_line(feather, &line_rule, MAAT_OP_ADD);
|
||||
EXPECT_EQ(ret, 1);
|
||||
free(line);
|
||||
value=1;
|
||||
g_test_update_paused=0;
|
||||
Maat_set_feather_opt(feather, MAAT_OPT_ENABLE_UPDATE, &value, sizeof(value));
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
|
||||
const char* log_file="./test.log";
|
||||
const char* stat_file="./scan_staus.log";
|
||||
const char* decrypt_key="mesa2017wy";
|
||||
const char* accept_tags="{\"tags\":[{\"tag\":\"location\",\"value\":\"北京/朝阳/华严北里/甲22号\"},{\"tag\":\"isp\",\"value\":\"移动\"}]}";
|
||||
|
||||
int scan_detail=0;
|
||||
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
logger=MESA_create_runtime_log_handle(log_file,0);
|
||||
|
||||
g_feather=Maat_feather(g_iThreadNum, table_info_path, logger);
|
||||
Maat_set_feather_opt(g_feather,MAAT_OPT_INSTANCE_NAME,"demo", strlen("demo")+1);
|
||||
Maat_set_feather_opt(g_feather,MAAT_OPT_DECRYPT_KEY,decrypt_key, strlen(decrypt_key)+1);
|
||||
Maat_set_feather_opt(g_feather, MAAT_OPT_JSON_FILE_PATH, json_path, strlen(json_path)+1);
|
||||
|
||||
Maat_set_feather_opt(g_feather, MAAT_OPT_SCANDIR_INTERVAL_MS,&scan_interval_ms, sizeof(scan_interval_ms));
|
||||
//Set a short intevral for testing.
|
||||
Maat_set_feather_opt(g_feather, MAAT_OPT_EFFECT_INVERVAL_MS,&effective_interval_ms, sizeof(effective_interval_ms));
|
||||
|
||||
Maat_set_feather_opt(g_feather, MAAT_OPT_STAT_FILE_PATH, stat_file, strlen(stat_file)+1);
|
||||
Maat_set_feather_opt(g_feather, MAAT_OPT_STAT_ON, NULL, 0);
|
||||
Maat_set_feather_opt(g_feather, MAAT_OPT_PERF_ON, NULL, 0);
|
||||
Maat_set_feather_opt(g_feather, MAAT_OPT_SCAN_DETAIL, &scan_detail, sizeof(scan_detail));
|
||||
Maat_set_feather_opt(g_feather, MAAT_OPT_ACCEPT_TAGS, accept_tags, strlen(accept_tags)+1);
|
||||
Maat_initiate_feather(g_feather);
|
||||
printf("Maat initiating, see %s\n",log_file);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
11
tools/CMakeLists.txt
Normal file
11
tools/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
add_executable(digest_gen digest_gen.c)
|
||||
add_dependencies(digest_gen maat_frame_shared)
|
||||
target_link_libraries(digest_gen maat_frame_shared)
|
||||
|
||||
add_executable(maat_redis_tool maat_redis_tool.cpp)
|
||||
add_dependencies(maat_redis_tool maat_frame_shared)
|
||||
target_link_libraries(maat_redis_tool maat_frame_shared)
|
||||
target_include_directories(maat_redis_tool PRIVATE ${PROJECT_SOURCE_DIR}/src/inc_internal/)
|
||||
target_include_directories(maat_redis_tool PRIVATE ${PROJECT_SOURCE_DIR}/src/inc_internal/hiredis)
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
LIBS= -lmaatframe -lhiredis_vip
|
||||
INC=-I../inc/ -I ../src/entry/ -I../src/inc_internal/ -I/usr/include/MESA/
|
||||
all:
|
||||
g++ -o maat_redis_tool.o -c -g -Wall maat_redis_tool.cpp $(INC)
|
||||
g++ -o maat_redis_tool maat_redis_tool.o $(LIBS)
|
||||
g++ -o digest_gen -g digest_gen.c $(INC) $(LIBS)
|
||||
clean:
|
||||
rm *.o
|
||||
16
vendor/CMakeLists.txt
vendored
Normal file
16
vendor/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
# CMakeFiles for 3rd vendor library
|
||||
|
||||
include(ExternalProject)
|
||||
#### GoogleTest
|
||||
ExternalProject_Add(googletest PREFIX googletest
|
||||
URL ${CMAKE_CURRENT_SOURCE_DIR}/googletest-release-1.8.0.tar.gz
|
||||
URL_MD5 16877098823401d1bf2ed7891d7dce36
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
|
||||
|
||||
ExternalProject_Get_Property(googletest INSTALL_DIR)
|
||||
file(MAKE_DIRECTORY ${INSTALL_DIR}/include)
|
||||
|
||||
add_library(gtest STATIC IMPORTED GLOBAL)
|
||||
set_property(TARGET gtest PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/lib/libgtest.a)
|
||||
set_property(TARGET gtest PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)
|
||||
set_property(TARGET gtest PROPERTY INTERFACE_LINK_LIBRARIES pthread)
|
||||
Reference in New Issue
Block a user