重构代码目录,改用cmake编译。

This commit is contained in:
zhengchao
2018-09-23 14:30:45 +08:00
parent 9dd63f3dec
commit ef6c330f69
43 changed files with 82 additions and 1004 deletions

View File

@@ -0,0 +1,513 @@
#ifndef H_MAAT_RULE_INTERNAL_H_INCLUDE
#define H_MAAT_RULE_INTERNAL_H_INCLUDE
#include "Maat_rule.h"
#include "Maat_command.h"
#include <MESA/MESA_htable.h>
#include <MESA/MESA_list_queue.h>
#include <MESA/field_stat2.h>
#include "dynamic_array.h"
#include "UniversalBoolMatch.h"
#include "rulescan.h"
#include "hiredis.h"
#include "stream_fuzzy_hash.h"
#include "gram_index_engine.h"
#include "aligment_int64.h"
#include <pthread.h>
#include <iconv.h>
extern const char *maat_module;
#if(__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ >= 411)
#define atomic_inc(x) __sync_add_and_fetch((x),1)
#define atomic_dec(x) __sync_sub_and_fetch((x),1)
#define atomic_add(x,y) __sync_add_and_fetch((x),(y))
#define atomic_sub(x,y) __sync_sub_and_fetch((x),(y))
typedef int atomic_t;
#define ATOMIC_INIT(i) { (i) }
#define atomic_read(x) __sync_add_and_fetch((x),0)
#define atomic_set(x,y) __sync_lock_test_and_set((x),y)
#else
#include <alsa/iatomic.h>
#endif
#define TRUE 1
#define FALSE 0
#define MAX_TABLE_NUM 256
#define MAX_CONJUNCTION_TABLE_NUM 8
#define MAX_CHARSET_NUM 16
#define MAX_TABLE_NAME_LEN 256
#define MAX_TABLE_LINE_SIZE (1024*16)
#define MAX_EXPR_KEYLEN 1024
#define MAX_DISTRICT_LEN 64
#define MAX_PLUGING_NUM 32
#define MAX_SCANNER_HIT_NUM 64
#define MAX_GROUP_CACHE 128
#define MAX_FAILED_NUM 128
#define MAX_MAAT_STAT_NUM 64
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#ifndef container_of
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
typedef void* rule_scanner_t;
enum MAAT_TABLE_TYPE
{
TABLE_TYPE_EXPR=0,
TABLE_TYPE_IP,
TABLE_TYPE_INTERVAL,
TABLE_TYPE_DIGEST,
TABLE_TYPE_EXPR_PLUS,
TABLE_TYPE_SIMILARITY,
TABLE_TYPE_GROUP,
TABLE_TYPE_COMPILE,
TABLE_TYPE_PLUGIN
};
struct db_str_rule_t
{
int region_id;
int group_id;
char keywords[MAX_EXPR_KEYLEN];
char district[MAX_DISTRICT_LEN];
enum MAAT_EXPR_TYPE expr_type;
enum MAAT_MATCH_METHOD match_method;
int is_hexbin;
int is_case_sensitive;
int is_valid;
};
struct db_ip_rule_t
{
int region_id;
int group_id;
int addr_type;
union
{
//ip address use network order
//port use host order
ipv4_rule_t ipv4_rule;
ipv6_rule_t ipv6_rule;
};
int is_valid;
};
struct db_intval_rule_t
{
int region_id;
int group_id;
interval_rule_t intval;
int is_valid;
};
struct db_digest_rule_t
{
int region_id;
int group_id;
unsigned long long orgin_len;
char* digest_string;
short confidence_degree;
int is_valid;
};
struct _head_Maat_rule_t
{
int config_id;
int service_id;
char do_log;
char do_blacklist;
char action;
char resevered;
int serv_def_len;
};
struct db_compile_rule_t
{
struct _head_Maat_rule_t m_rule_head;// fix len of Maat_rule_t
char* service_defined;
long long effective_range;
int is_valid;
int declare_grp_num;
};
struct db_group_rule_t
{
int group_id;
int compile_id;
int is_valid;
};
struct op_expr_t
{
boolean_expr_t* p_expr;
scan_rule_t* p_rules[MAAT_MAX_EXPR_ITEM_NUM];
int convert_failed;
int no_effect_convert_cnt;
int table_id;
int rule_type;
};
struct _Maat_region_inner_t
{
int region_id;
int district_id;
int table_id;
int expr_id_cnt;
int expr_id_lb;
int expr_id_ub;
enum MAAT_TABLE_TYPE table_type;
};
struct _Maat_group_inner_t
{
int group_id;
int table_id;
int region_boundary;
int region_cnt;
int ref_cnt;
char* group_name;
dynamic_array_t *regions;
void* compile_shortcut;
pthread_mutex_t mutex;
};
struct _Maat_compile_inner_t
{
struct db_compile_rule_t *db_c_rule;
dynamic_array_t *groups;
int compile_id;//equal to db_c_rule->m_rule.config_id
int table_id;
int group_boundary;
int group_cnt;
pthread_rwlock_t rwlock;//reading compile rule is safe in update thread, rwlock lock called when delete or scan thread read
};
struct _compile_result_t
{
int compile_id;
universal_bool_expr_t group_set;
};
struct _callback_plugin
{
Maat_start_callback_t *start;
Maat_update_callback_t *update;
Maat_finish_callback_t *finish;
void* u_para;
};
struct _plugin_table_info
{
int cb_plug_cnt;
struct _callback_plugin cb_plug[MAX_PLUGING_NUM];
dynamic_array_t *cache_lines;
int cache_line_num;
int acc_line_num;
int update_type;
long cache_size;
};
struct _region_stat_t
{
int cfg_num;
union
{
int expr_rule_cnt; //expr_type=0,1,3
int ipv4_rule_cnt;
};
union
{
int regex_rule_cnt; //expr_type=2
int ipv6_rule_cnt;
};
};
#define USER_REGION_ENCODE_NONE 0
#define USER_REGION_ENCODE_ESCAPE 1
#define USER_REGION_ENCODE_BASE64 2
struct _Maat_table_info_t
{
unsigned short table_id;
unsigned short conj_cnt;
unsigned short updating_name;
char table_name[MAX_CONJUNCTION_TABLE_NUM][MAX_TABLE_NAME_LEN];
enum MAAT_TABLE_TYPE table_type;
enum MAAT_CHARSET src_charset;
enum MAAT_CHARSET dst_charset[MAX_CHARSET_NUM];
int src_charset_in_dst;
int do_charset_merge;
int cfg_num;
int cross_cache_size;
int quick_expr_switch;
union
{
int expr_rule_cnt; //expr_type=0,1,3
int ipv4_rule_cnt;
};
union
{
int regex_rule_cnt; //expr_type=2
int ipv6_rule_cnt;
};
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;
mcore_long_t scan_cpu_time; //nano
mcore_long_t input_bytes;
mcore_long_t stream_num;
mcore_long_t hit_cnt;
};
struct _INNER_scan_status_t
{
int cur_hit_cnt;
int hit_group_cnt;
int hit_group_size;
unsigned int cur_hit_id[MAX_SCANNER_HIT_NUM];
unsigned int *hitted_group_id;
};
struct _OUTER_scan_status_t
{
struct _Maat_feather_t* feather;
unsigned short thread_num;
unsigned char is_set_district;
unsigned char is_last_region;
int district_id;
struct _INNER_scan_status_t* inner;
};
enum maat_garbage_type
{
GARBAGE_SCANNER=0,
GARBAGE_GROUP_RULE,
GARBAGE_COMPILE_RULE,
GARBAGE_BOOL_MATCHER,
GARBAGE_MAP_STR2INT
};
struct iconv_handle_t
{
int is_initialized;
iconv_t cd;
};
struct _stream_para_t
{
struct _Maat_feather_t* feather;
int version;
int thread_num;
int max_cross_size;
int caching_size;
unsigned short table_id;
char do_merge;
char do_expr:4;
char do_regex:4;
char* last_cache;
char* scan_buff;
void* rs_stream_para;
long process_offset;
unsigned long long total_len;
sfh_instance_t *fuzzy_hash_handle;
pthread_mutex_t fuzzy_mutex;
unsigned char query_point[8];
};
struct GIE_aux_t
{
enum MAAT_TABLE_TYPE table_type;
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;
time_t last_update_time;
long long *ref_cnt; //optimized for cache_alignment 64
rule_scanner_t region;
long gie_total_q_size;
struct GIE_aux_t gie_aux[MAX_TABLE_NUM];
MESA_htable_handle region_hash;
MESA_htable_handle group_hash;
MESA_htable_handle compile_hash;
MESA_htable_handle district_map;
MESA_htable_handle tmp_district_map;
unsigned int district_num;
unsigned int cfg_num;
unsigned int exprid_generator;
unsigned int dedup_expr_num;
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
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]
};
struct _Maat_feather_t
{
struct _Maat_scanner_t *scanner;
struct _Maat_scanner_t *update_tmp_scanner;
MESA_lqueue_head garbage_q;
int table_cnt;
int DEFERRED_LOAD_ON;
int GROUP_MODE_ON;
int REDIS_MODE_ON;
int still_working;
int scan_interval_ms;
int effect_interval_ms;
int cumulative_update_off;
int stat_on;
int perf_on;
struct _Maat_table_info_t *p_table_info[MAX_TABLE_NUM];
MESA_htable_handle map_tablename2id;
void* logger;
long long maat_version;
long long last_full_version;
int scan_thread_num;
int rule_scan_type;
char inc_dir[MAX_TABLE_NAME_LEN];
char full_dir[MAX_TABLE_NAME_LEN];
char stat_file[MAX_TABLE_NAME_LEN];
char instance_name[MAX_TABLE_NAME_LEN];
char table_info_fn[MAX_TABLE_NAME_LEN];
char compile_tn[MAX_TABLE_NAME_LEN];
char group_tn[MAX_TABLE_NAME_LEN];
pthread_mutex_t backgroud_update_mutex;
unsigned char decrypt_key[MAX_TABLE_NAME_LEN];
char redis_ip[MAX_TABLE_NAME_LEN];
int redis_port;
int redis_index;
int AUTO_NUMBERING_ON;
struct timeval connect_timeout;
redisContext *redis_read_ctx;
redisContext *redis_write_ctx; // not thread safe.
int on_redis_writing;
int cmd_q_cnt;
struct _Maat_cmd_inner_t* cmd_qhead, *cmd_qtail;
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;
int is_last_plugin_table_updating;
//for stat>>>>
int backgroud_update_enabled;
screen_stat_handle_t stat_handle;
int total_stat_id;
int fs_status_id[MAX_MAAT_STAT_NUM];
int fs_column_id[MAX_MAAT_STAT_NUM];
mcore_long_t outer_mid_cnt;
mcore_long_t inner_mid_cnt;
mcore_long_t hit_cnt;
mcore_long_t thread_call_cnt;//size indicate by scan_thread_num,
mcore_long_t orphan_group_saving;
mcore_long_t last_region_saving;
long long total_scan_bytes;
long long total_scan_cnt;
long long update_err_cnt;//sum of the same name variable in each table
long long iconv_err_cnt;//sum of the same name variable in each table
long long scan_err_cnt;
long long zombie_rs_stream;
long long postpone_q_size;
long long compile_rule_num;
long long cmd_acc_num;
long long line_cmd_acc_num;
};
struct _maat_garbage_t
{
enum maat_garbage_type type;
time_t create_time;
int ok_times;
union
{
struct _Maat_scanner_t* scanner;
struct _Maat_group_inner_t* group_rule;
struct _Maat_compile_inner_t* compile_rule;
void* bool_matcher;
void * raw;
MESA_htable_handle str2int_map;
};
};
struct serial_rule_t //rm= Redis Maat
{
enum MAAT_OPERATION op;//0: delete, 1: add.
int rule_id;
int label_id;
long long timeout; // absolute unix time.
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);
int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char* table_info_path,int max_thread_num,void* logger);
void maat_start_cb(long long new_version,int update_type,void*u_para);
int maat_update_cb(const char* table_name,const char* line,void *u_para);
void maat_finish_cb(void* u_para);
void *thread_rule_monitor(void *arg);
unsigned int make_sub_type(unsigned short table_id,enum MAAT_CHARSET charset,int do_charset_merge);
inline void ipv6_ntoh(unsigned int *v6_addr)
{
unsigned int i=0;
for(i=0;i<4;i++)
{
v6_addr[i]=ntohl(v6_addr[i]);
}
return;
}
void * HASH_fetch_by_id(MESA_htable_handle hash,int id);
int HASH_add_by_id(MESA_htable_handle hash,int id,void*data);
int HASH_delete_by_id(MESA_htable_handle hash,int id);
void maat_read_full_config(_Maat_feather_t* _feather);
void maat_stat_init(struct _Maat_feather_t* feather);
void maat_stat_table(struct _Maat_table_info_t* p_table,int scan_len,struct timespec* start, struct timespec* end,int thread_num);
void maat_stat_output(struct _Maat_feather_t* feather);
char* _maat_strdup(const char* s);
char* str_unescape(char* s);
redisReply *_wrap_redisCommand(redisContext *c, const char *format, ...);
int get_rm_key_list(redisContext *c, long long instance_version, long long desired_version, long long* new_version, struct serial_rule_t** list,int *update_type, void* logger, int cumulative_off);
int get_maat_redis_value(redisContext *c,struct serial_rule_t* rule_list,int rule_num,void* logger,int print_process);
void set_serial_rule(struct serial_rule_t* rule,enum MAAT_OPERATION op,int rule_id,int label_id,const char* table_name,const char* line, long long timeout);
void empty_serial_rules(struct serial_rule_t* rule);
int exec_serial_rule(redisContext* ctx,struct serial_rule_t* s_rule,int serial_rule_num, long long server_time, void* logger);
long long redis_server_time(redisContext* ctx);
void redis_monitor_traverse(long long version,redisContext *c,
void (*start)(long long,int ,void*),//vesion,CM_UPDATE_TYPE_*,u_para
int (*update)(const char* ,const char*,void* ),//table name ,line ,u_para
void (*finish)(void*),//u_para
void* u_para,
const unsigned char* dec_key,
_Maat_feather_t* feather);
const char* module_name_str(const char*name);
#define maat_module (module_name_str("MAAT_Frame"))
#endif

View File

@@ -0,0 +1,46 @@
/*
*
* Copyright (c) 2014
* String Algorithms Research Group
* Institute of Information Engineering, Chinese Academy of Sciences (IIE-CAS)
* National Engineering Laboratory for Information Security Technologies (NELIST)
* All rights reserved
*
* Written by: LIU YANBING (liuyanbing@iie.ac.cn)
* Last modification: 2014-12-09
*
* This code is the exclusive and proprietary property of IIE-CAS and NELIST.
* Usage for direct or indirect commercial advantage is not allowed without
* written permission from the authors.
*
*/
#ifndef H_UNIVERSAL_BOOL_MATCH_H
#define H_UNIVERSAL_BOOL_MATCH_H
#ifdef __cplusplus
extern "C"
{
#endif
#define MAX_ITEMS_PER_BOOL_EXPR 8
typedef struct _universal_bool_expr_t
{
void * bool_expr_id;
unsigned int bool_item_num;
unsigned int bool_item_ids[MAX_ITEMS_PER_BOOL_EXPR];
}universal_bool_expr_t;
/*ע<><EFBFBD><E2A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ûύ<C3BB><E1BDBB>bool_exprs<72><73>Ԫ<EFBFBD>ص<EFBFBD>λ<EFBFBD><CEBB>*/
void * boolexpr_initialize(universal_bool_expr_t * bool_exprs, unsigned int bool_expr_num, unsigned int max_thread_num, unsigned int * mem_size);
int boolexpr_match(void * instance, unsigned int thread_id, unsigned int * item_ids, unsigned int item_num, void ** result, unsigned int size);
void boolexpr_destroy(void * instance);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,52 @@
#ifndef H_ALIGMENT_INT64_H_INCLUDE
#define H_ALIGMENT_INT64_H_INCLUDE
#include <stdlib.h>
#define CPU_CACHE_ALIGMENT 64
typedef long long* mcore_long_t;
inline long long *aligment_int64_array_alloc(int size)
{
long long *ret=NULL;
ret=(long long*)calloc(CPU_CACHE_ALIGMENT,size);
return ret;
}
inline long long aligment_int64_array_sum(mcore_long_t array,int size)
{
long long sum=0;
int offset=0,i=0;
for(i=0;i<size;i++)
{
offset=(CPU_CACHE_ALIGMENT/sizeof(long long))*i;
sum+=array[offset];
}
return sum;
}
inline long long aligment_int64_array_add(mcore_long_t array,int offset,long long op_val)
{
int idx=(CPU_CACHE_ALIGMENT/sizeof(long long))*offset;
array[idx]+=op_val;
return array[idx];
}
inline long long aligment_int64_array_cnt(mcore_long_t array,int size)
{
int offset=0,i=0;
int cnt=0;
for(i=0;i<size;i++)
{
offset=(CPU_CACHE_ALIGMENT/sizeof(long long))*i;
if(array[offset]>0)
{
cnt++;
}
}
return cnt;
}
inline void aligment_int64_array_free(mcore_long_t array)
{
free(array);
}
#endif

143
src/inc_internal/cJSON.h Normal file
View File

@@ -0,0 +1,143 @@
/*
Copyright (c) 2009 Dave Gamble
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE EXPR_TYPE_AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef cJSON__h
#define cJSON__h
#ifdef __cplusplus
extern "C"
{
#endif
/* cJSON Types: */
#define cJSON_False 0
#define cJSON_True 1
#define cJSON_NULL 2
#define cJSON_Number 3
#define cJSON_String 4
#define cJSON_Array 5
#define cJSON_Object 6
#define cJSON_IsReference 256
/* The cJSON structure: */
typedef struct cJSON {
struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
int type; /* The type of the item, as above. */
char *valuestring; /* The item's string, if type==cJSON_String */
int valueint; /* The item's number, if type==cJSON_Number */
double valuedouble; /* The item's number, if type==cJSON_Number */
char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
} cJSON;
typedef struct cJSON_Hooks {
void *(*malloc_fn)(size_t sz);
void (*free_fn)(void *ptr);
} cJSON_Hooks;
/* Supply malloc, realloc and free functions to cJSON */
extern void cJSON_InitHooks(cJSON_Hooks* hooks);
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
extern cJSON *cJSON_Parse(const char *value);
/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
extern char *cJSON_Print(cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
extern char *cJSON_PrintUnformatted(cJSON *item);
/* Delete a cJSON entity and all subentities. */
extern void cJSON_Delete(cJSON *c);
/* Returns the number of items in an array (or object). */
extern int cJSON_GetArraySize(cJSON *array);
/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
extern cJSON *cJSON_GetArrayItem(cJSON *array,int item);
/* Get item "string" from object. Case insensitive. */
extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
extern const char *cJSON_GetErrorPtr(void);
/* These calls create a cJSON item of the appropriate type. */
extern cJSON *cJSON_CreateNull(void);
extern cJSON *cJSON_CreateTrue(void);
extern cJSON *cJSON_CreateFalse(void);
extern cJSON *cJSON_CreateBool(int b);
extern cJSON *cJSON_CreateNumber(double num);
extern cJSON *cJSON_CreateString(const char *string);
extern cJSON *cJSON_CreateArray(void);
extern cJSON *cJSON_CreateObject(void);
/* These utilities create an Array of count items. */
extern cJSON *cJSON_CreateIntArray(const int *numbers,int count);
extern cJSON *cJSON_CreateFloatArray(const float *numbers,int count);
extern cJSON *cJSON_CreateDoubleArray(const double *numbers,int count);
extern cJSON *cJSON_CreateStringArray(const char **strings,int count);
/* Append item to the specified array/object. */
extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
/* Remove/Detatch items from Arrays/Objects. */
extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which);
extern void cJSON_DeleteItemFromArray(cJSON *array,int which);
extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string);
extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string);
/* Update array items. */
extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);
extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
/* Duplicate a cJSON item */
extern cJSON *cJSON_Duplicate(cJSON *item,int recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
need to be released. With recurse!=0, it will duplicate any children connected to the item.
The item->next and ->prev pointers are always zero on return from Duplicate. */
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int require_null_terminated);
extern void cJSON_Minify(char *json);
/* Macros for creating things quickly. */
#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b))
#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val))
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,15 @@
#ifndef __CONFIG_MONITOR_H_INCLUDE_
#define __CONFIG_MONITOR_H_INCLUDE_
#define CM_UPDATE_TYPE_FULL 1
#define CM_UPDATE_TYPE_INC 2
void config_monitor_traverse(long long version,const char*idx_dir,
void (*start)(long long, int, void*),//vesion,CM_UPDATE_TYPE_*,u_para
int (*update)(const char*, const char*, void*),//table name ,line ,u_para
void (*finish)(void*),//u_para
void* u_para,
const unsigned char* dec_key,
void* logger);
#endif

View File

@@ -0,0 +1,13 @@
#ifndef _DYNAMIC_ARRAY_H_INCLUDE_
#define _DYNAMIC_ARRAY_H_INCLUDE_
struct dynamic_array_t
{
void ** array;
int size;
int enlarge_step;
};
struct dynamic_array_t* dynamic_array_create(int size,int step);
void dynamic_array_destroy(struct dynamic_array_t* d_array,void (* free_data)(void *));
void* dynamic_array_read(struct dynamic_array_t* d_array,int i);
void dynamic_array_write(struct dynamic_array_t* d_array,int i,void* data);
#endif //_DYNAMIC_ARRAY_H_INCLUDE_

View File

@@ -0,0 +1,313 @@
/************************************************************************
* InterVal Index interface
* NOTE that:
* (1) There are no overlapping intervals in InterVal Index;
* (2) Each interval is closed;
* (3) The interval supports rollback.
*
* author: zhengchao@iie.ac.cn tangqi@iie.ac.cn
* last modify time: 2015-12-04
*************************************************************************/
#ifndef _INTERVAL_INDEX_H_
#define _INTERVAL_INDEX_H_
#ifdef __cplusplus
extern "C"{
#endif
#define SIZE_8
#ifdef SIZE_8
typedef unsigned long long OFFSET_TYPE;
typedef signed long long S_OFFSET_TYPE;
#else
typedef unsigned int OFFSET_TYPE;
typedef signed int S_OFFSET_TYPE;
#endif
typedef struct{
}IVI_t;
/**
* structure of segment
**/
typedef struct __IVI_seg_t{
OFFSET_TYPE left;
OFFSET_TYPE right;
void * data;
}IVI_seg_t;
typedef void IVI_callback_t(IVI_seg_t * seg, void * usr_para);
/**
* Deal with rollback
* Refering to the approach of Linux's kernel to solute tcp seq rollback
**/
static inline int before(OFFSET_TYPE off1, OFFSET_TYPE off2)
{
return (S_OFFSET_TYPE)(off1 - off2) < 0;
}
#define after(off2, off1) before(off1, off2)
static inline int continuous(OFFSET_TYPE prev, OFFSET_TYPE next)
{
return ((next - prev) == 1);
}
IVI_seg_t * IVI_first_seg(IVI_t * handler);
IVI_seg_t * IVI_last_seg(IVI_t * handler);
IVI_seg_t * IVI_prev_seg(IVI_seg_t * seg);
IVI_seg_t * IVI_next_seg(IVI_seg_t * seg);
IVI_seg_t * IVI_prev_continuous_seg(IVI_seg_t * seg);
IVI_seg_t * IVI_next_continuous_seg(IVI_seg_t * seg);
/**
* Relation of two segments
**/
typedef enum __Relation_t{
LEFT_NO_OVERLAP = 1, // |___A___|
// |___B___|
LEFT_OVERLAP, // |___A___|
// |___B___|
CONTAINED, // |___A___|
// |_____B_____|
CONTAIN, // |_____A_____|
// |___B___|
RIGHT_OVERLAP, // |___A___|
// |___B___|
RIGHT_NO_OVERLAP, // |___A___|
// |___B___|
ERROR
}Relation_t;
/**
* Name:
* IVI_relative_position
* Description:
* Get relative position of given two interval segments
* Params:
* seg1: Subject of relation
* seg2: Object of relation
* Relation:
* On success, return the relation of two segments with enum;
* Else, return ERROR in enum;
**/
Relation_t IVI_relative_position(IVI_seg_t * seg1, IVI_seg_t * seg2);
/**
* Name:
* IVI_create
* Description:
* Create an InterVal Index
* Params:
* void
* Return:
* Return a handler of this InterVal Index
**/
IVI_t * IVI_create(void);
/**
* Name:
* IVI_destroy
* Description:
* Destroy a given InterVal Index's handler
* Params:
* handler: The InterVal Index you want to destroy
* cb: Callback function for user to free data in segement
* usr_para: User parameter
* Return:
* void
**/
void IVI_destroy(IVI_t * handler, IVI_callback_t cb, void * usr_para);
/**
* Name:
* IVI_seg_malloc
* Description:
* Malloc a segment with given parameters
* Params:
* left: Left point of segment
* right: Right point of segment
* data: User data
* Return:
* Return a pointer of segment structure.
**/
IVI_seg_t * IVI_seg_malloc(OFFSET_TYPE left, OFFSET_TYPE right, void * data);
/**
* Name:
* IVI_seg_free
* Description:
* Free the memory of given segment
* Params:
* seg: The segment that you want to free
* cb: Callback function for user to free *data in seg
* usr_para: User parameter for cb
* Return:
* void
**/
void IVI_seg_free(IVI_seg_t * seg, IVI_callback_t cb, void * usr_para);
/**
* Name:
* IVI_insert
* Description:
* Insert a segment to an InterVal Index handler,and the segment
* MUST not be overlapped with others in handler.
* Params:
* handler: The handler of InterVal Index created by IVI_create
* seg: A segment that user wants to add. It MUST be created
* by IVI_seg_malloc.
* Return:
* On success, 0 is returned;
* Else when overlapp occures or error occures, -1 is returned.
**/
int IVI_insert(IVI_t * handler, IVI_seg_t * seg);
/**
* Name:
* IVI_remove
* Description:
* Remove a given segment from given InterVal Index handler.
* Params:
* handler: The handler of InterVal Index created by IVI_create
* seg: A segment that user wants to delete. It MUST be created
* by IVI_seg_malloc.
* Return:
* On success, 0 is returned;
* Else when overlapp occures, -1 is returned.
**/
int IVI_remove(IVI_t * handler, IVI_seg_t * seg);
/**
* Name:
* IVI_query
* Description:
* Query from given InterVal Index and get the number of segments
* which are overlapped with given interval, and store those segments
* in the last parameter.
* Params:
* handler: The handler of interval index created by IVI_create
* left: Left point of given interval
* right: Right point of given interval
* segs: An address of a segment pointer array to store those segments which
* are overlapped with given interval. NOTE that user should not malloc
* the array, and segs need to be freed by user. The element of *segs
* MUST not be freed by user.
* Return:
* Return the number of segments which are overlapped with given interval
**/
int IVI_query(IVI_t * handler, OFFSET_TYPE left, OFFSET_TYPE right, IVI_seg_t *** segs);
/**
* Name:
* IVI_query_continuous
* Description:
* Query from interval index handler and get the number of continous segments
* which are overlapped with given interval.
* Params:
* handler: The handler of InterVal Index created by IVI_create.
* left: Left point of given interval
* right: Right point of given interval
* segs: An address of a segment pointer array to store those segments which
* are overlapped with given interval. NOTE that user should not malloc
* the array, and segs need to be freed by user. The element of *segs
* MUST not be freed by user.
* Return:
* Return the number of continous segments which are overlapped with given interval
**/
int IVI_query_continuous(IVI_t * handler, OFFSET_TYPE left, OFFSET_TYPE right, IVI_seg_t *** segs);
/**
* Name:
* IVI_seg_cnt
* Description:
* Get the count of segments in given interval index handler
* Params:
* handler: The handler of InterVal Index created by IVI_create.
* Return:
* Return the count of segments in given interval index handler
**/
int IVI_seg_cnt(IVI_t * handler);
/**
* Name:
* IVI_seg_len
* Description:
* Get the length of whole segments in given interval index handler
* Params:
* handler: The handler of InterVal Index created by IVI_create.
* Return:
* Return the length of whole segments in given interval index handler
**/
OFFSET_TYPE IVI_seg_length(IVI_t * handler);
/**
* Name:
* IVI_mem_occupy
* Description:
* Get the memory occupy of given interval index handler
* Params:
* handler: The handler of InterVal Index created by IVI_create.
* Return:
* Return the memory occupy of given interval index handler
**/
unsigned long long IVI_mem_occupy(IVI_t * handler);
/**
* Name:
* IVI_traverse
* Description:
* Traverse given InterVal Index and execute given callback function
* one time for each seg in InterVal Index.
* Params:
* handler: The handler of InterVal Index created by IVI_create.
* IVI_callback_t: Callback function for user to define.
* usr_para: Parameter user want to pass to callback function.
* Return:
* void
**/
void IVI_traverse(IVI_t * handler, IVI_callback_t cb, void * usr_para);
#ifdef __cplusplus
}
#endif
#endif /* _INTERVAL_INDEX_H_ */

View File

@@ -0,0 +1,6 @@
#ifndef H_MAAT_JSON2IRIS_H_INCLUDE
#define H_MAAT_JSON2IRIS_H_INCLUDE
int json2iris(const char* json_file,const char*compile_tn,const char* group_tn,redisContext *redis_write_ctx,char* iris_dir_buf,int buf_len,void* logger);
int set_file_rulenum(const char* path,int rulenum,void* logger);
#endif

View File

@@ -0,0 +1,11 @@
#ifndef __MAP_STR2INT_H_INCLUDE_
#define __MAP_STR2INT_H_INCLUDE_
#include <MESA/MESA_htable.h>
MESA_htable_handle map_create(void);
void map_destroy(MESA_htable_handle p);
int map_register(MESA_htable_handle handle,const char* string,int value);
int map_str2int(MESA_htable_handle handle,const char* string,int* value);
int map_unNullstr2int(MESA_htable_handle handle,const char* string,int size,int* value);
MESA_htable_handle map_duplicate(MESA_htable_handle origin_map);
#endif

118
src/inc_internal/rbtree.h Normal file
View File

@@ -0,0 +1,118 @@
/*
Red Black Trees
(C) 1999 Andrea Arcangeli <andrea@suse.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
linux/include/linux/rbtree.h
To use rbtrees you'll have to implement your own insert and search cores.
This will avoid us to use callbacks and to drop drammatically performances.
I know it's not the cleaner way, but in C (not in C++) to get
performances and genericity...
See Documentation/rbtree.txt for documentation and samples.
*/
#ifndef _LINUX_RBTREE_H
#define _LINUX_RBTREE_H
#include <stdio.h>
struct rb_node {
unsigned long __rb_parent_color;
struct rb_node *rb_right;
struct rb_node *rb_left;
} __attribute__((aligned(sizeof(long))));
/* The alignment might seem pointless, but allegedly CRIS needs it */
struct rb_root {
struct rb_node *rb_node;
};
#define rb_parent(r) ((struct rb_node *)((r)->__rb_parent_color & ~3))
#define RB_ROOT (struct rb_root) { NULL, }
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#ifndef container_of
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type, member) );})
#endif
#define rb_entry(ptr, type, member) container_of(ptr, type, member)
#define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL)
/* 'empty' nodes are nodes that are known not to be inserted in an rbtree */
#define RB_EMPTY_NODE(node) \
((node)->__rb_parent_color == (unsigned long)(node))
#define RB_CLEAR_NODE(node) \
((node)->__rb_parent_color = (unsigned long)(node))
extern void rb_insert_color(struct rb_node *, struct rb_root *);
extern void rb_erase(struct rb_node *, struct rb_root *);
/* Find logical next and previous nodes in a tree */
extern struct rb_node *rb_next(const struct rb_node *);
extern struct rb_node *rb_prev(const struct rb_node *);
extern struct rb_node *rb_first(const struct rb_root *);
extern struct rb_node *rb_last(const struct rb_root *);
/* Postorder iteration - always visit the parent after its children */
extern struct rb_node *rb_first_postorder(const struct rb_root *);
extern struct rb_node *rb_next_postorder(const struct rb_node *);
/* Fast replacement of a single node without remove/rebalance/add/rebalance */
extern void rb_replace_node(struct rb_node *victim, struct rb_node *new,
struct rb_root *root);
static inline void rb_link_node(struct rb_node * node, struct rb_node * parent,
struct rb_node ** rb_link)
{
node->__rb_parent_color = (unsigned long)parent;
node->rb_left = node->rb_right = NULL;
*rb_link = node;
}
#define rb_entry_safe(ptr, type, member) \
({ typeof(ptr) ____ptr = (ptr); \
____ptr ? rb_entry(____ptr, type, member) : NULL; \
})
/**
* rbtree_postorder_for_each_entry_safe - iterate over rb_root in post order of
* given type safe against removal of rb_node entry
*
* @pos: the 'type *' to use as a loop cursor.
* @n: another 'type *' to use as temporary storage
* @root: 'rb_root *' of the rbtree.
* @field: the name of the rb_node field within 'type'.
*/
#define rbtree_postorder_for_each_entry_safe(pos, n, root, field) \
for (pos = rb_entry_safe(rb_first_postorder(root), typeof(*pos), field); \
pos && ({ n = rb_entry_safe(rb_next_postorder(&pos->field), \
typeof(*pos), field); 1; }); \
pos = n)
#endif /* _LINUX_RBTREE_H */

View File

@@ -0,0 +1,241 @@
/*
Red Black Trees
(C) 1999 Andrea Arcangeli <andrea@suse.de>
(C) 2002 David Woodhouse <dwmw2@infradead.org>
(C) 2012 Michel Lespinasse <walken@google.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
linux/include/linux/rbtree_augmented.h
*/
#ifndef _LINUX_RBTREE_AUGMENTED_H
#define _LINUX_RBTREE_AUGMENTED_H
#include "rbtree.h"
/*
* Please note - only struct rb_augment_callbacks and the prototypes for
* rb_insert_augmented() and rb_erase_augmented() are intended to be public.
* The rest are implementation details you are not expected to depend on.
*
* See Documentation/rbtree.txt for documentation and samples.
*/
struct rb_augment_callbacks {
void (*propagate)(struct rb_node *node, struct rb_node *stop);
void (*copy)(struct rb_node *old, struct rb_node *new);
void (*rotate)(struct rb_node *old, struct rb_node *new);
};
extern void __rb_insert_augmented(struct rb_node *node, struct rb_root *root,
void (*augment_rotate)(struct rb_node *old, struct rb_node *new));
/*
* Fixup the rbtree and update the augmented information when rebalancing.
*
* On insertion, the user must update the augmented information on the path
* leading to the inserted node, then call rb_link_node() as usual and
* rb_augment_inserted() instead of the usual rb_insert_color() call.
* If rb_augment_inserted() rebalances the rbtree, it will callback into
* a user provided function to update the augmented information on the
* affected subtrees.
*/
static inline void
rb_insert_augmented(struct rb_node *node, struct rb_root *root,
const struct rb_augment_callbacks *augment)
{
__rb_insert_augmented(node, root, augment->rotate);
}
#define RB_DECLARE_CALLBACKS(rbstatic, rbname, rbstruct, rbfield, \
rbtype, rbaugmented, rbcompute) \
static inline void \
rbname ## _propagate(struct rb_node *rb, struct rb_node *stop) \
{ \
while (rb != stop) { \
rbstruct *node = rb_entry(rb, rbstruct, rbfield); \
rbtype augmented = rbcompute(node); \
if (node->rbaugmented == augmented) \
break; \
node->rbaugmented = augmented; \
rb = rb_parent(&node->rbfield); \
} \
} \
static inline void \
rbname ## _copy(struct rb_node *rb_old, struct rb_node *rb_new) \
{ \
rbstruct *old = rb_entry(rb_old, rbstruct, rbfield); \
rbstruct *new = rb_entry(rb_new, rbstruct, rbfield); \
new->rbaugmented = old->rbaugmented; \
} \
static void \
rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
{ \
rbstruct *old = rb_entry(rb_old, rbstruct, rbfield); \
rbstruct *new = rb_entry(rb_new, rbstruct, rbfield); \
new->rbaugmented = old->rbaugmented; \
old->rbaugmented = rbcompute(old); \
} \
rbstatic const struct rb_augment_callbacks rbname = { \
rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
};
#define RB_RED 0
#define RB_BLACK 1
#define __rb_parent(pc) ((struct rb_node *)(pc & ~3))
#define __rb_color(pc) ((pc) & 1)
#define __rb_is_black(pc) __rb_color(pc)
#define __rb_is_red(pc) (!__rb_color(pc))
#define rb_color(rb) __rb_color((rb)->__rb_parent_color)
#define rb_is_red(rb) __rb_is_red((rb)->__rb_parent_color)
#define rb_is_black(rb) __rb_is_black((rb)->__rb_parent_color)
static inline void rb_set_parent(struct rb_node *rb, struct rb_node *p)
{
rb->__rb_parent_color = rb_color(rb) | (unsigned long)p;
}
static inline void rb_set_parent_color(struct rb_node *rb,
struct rb_node *p, int color)
{
rb->__rb_parent_color = (unsigned long)p | color;
}
static inline void
__rb_change_child(struct rb_node *old, struct rb_node *new,
struct rb_node *parent, struct rb_root *root)
{
if (parent) {
if (parent->rb_left == old)
parent->rb_left = new;
else
parent->rb_right = new;
} else
root->rb_node = new;
}
extern void __rb_erase_color(struct rb_node *parent, struct rb_root *root,
void (*augment_rotate)(struct rb_node *old, struct rb_node *new));
static __always_inline struct rb_node *
__rb_erase_augmented(struct rb_node *node, struct rb_root *root,
const struct rb_augment_callbacks *augment)
{
struct rb_node *child = node->rb_right, *tmp = node->rb_left;
struct rb_node *parent, *rebalance;
unsigned long pc;
if (!tmp) {
/*
* Case 1: node to erase has no more than 1 child (easy!)
*
* Note that if there is one child it must be red due to 5)
* and node must be black due to 4). We adjust colors locally
* so as to bypass __rb_erase_color() later on.
*/
pc = node->__rb_parent_color;
parent = __rb_parent(pc);
__rb_change_child(node, child, parent, root);
if (child) {
child->__rb_parent_color = pc;
rebalance = NULL;
} else
rebalance = __rb_is_black(pc) ? parent : NULL;
tmp = parent;
} else if (!child) {
/* Still case 1, but this time the child is node->rb_left */
tmp->__rb_parent_color = pc = node->__rb_parent_color;
parent = __rb_parent(pc);
__rb_change_child(node, tmp, parent, root);
rebalance = NULL;
tmp = parent;
} else {
struct rb_node *successor = child, *child2;
tmp = child->rb_left;
if (!tmp) {
/*
* Case 2: node's successor is its right child
*
* (n) (s)
* / \ / \
* (x) (s) -> (x) (c)
* \
* (c)
*/
parent = successor;
child2 = successor->rb_right;
augment->copy(node, successor);
} else {
/*
* Case 3: node's successor is leftmost under
* node's right child subtree
*
* (n) (s)
* / \ / \
* (x) (y) -> (x) (y)
* / /
* (p) (p)
* / /
* (s) (c)
* \
* (c)
*/
do {
parent = successor;
successor = tmp;
tmp = tmp->rb_left;
} while (tmp);
parent->rb_left = child2 = successor->rb_right;
successor->rb_right = child;
rb_set_parent(child, successor);
augment->copy(node, successor);
augment->propagate(parent, successor);
}
successor->rb_left = tmp = node->rb_left;
rb_set_parent(tmp, successor);
pc = node->__rb_parent_color;
tmp = __rb_parent(pc);
__rb_change_child(node, successor, tmp, root);
if (child2) {
successor->__rb_parent_color = pc;
rb_set_parent_color(child2, parent, RB_BLACK);
rebalance = NULL;
} else {
unsigned long pc2 = successor->__rb_parent_color;
successor->__rb_parent_color = pc;
rebalance = __rb_is_black(pc2) ? parent : NULL;
}
tmp = successor;
}
augment->propagate(tmp, NULL);
return rebalance;
}
static __always_inline void
rb_erase_augmented(struct rb_node *node, struct rb_root *root,
const struct rb_augment_callbacks *augment)
{
struct rb_node *rebalance = __rb_erase_augmented(node, root, augment);
if (rebalance)
__rb_erase_color(rebalance, root, augment->rotate);
}
#endif /* _LINUX_RBTREE_AUGMENTED_H */

View File

@@ -0,0 +1,108 @@
#include "zt_hash.h"
#include "interval_index.h"
#include "stream_fuzzy_hash.h"
#ifndef __SFH_INTERNAL_H_INCLUDE_
#define __SFH_INTERNAL_H_INCLUDE_
#define ROLLING_WINDOW 7
#define BLOCKSIZE_MIN 3
#define HASH_PRIME 0x01000193
#define HASH_INIT 0x28021967
#define CALCULATE 0
#define MODIFY 1
#define EXPECT_SIGNATURE_LEN 64
#define MEMORY_OCCUPY 3
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef container_of
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
#define DEBUG (0)
//int count = 0;
struct roll_state_t
{
unsigned char window[ROLLING_WINDOW];
unsigned char pad[1];
unsigned int h1, h2, h3;
unsigned int n;
};
typedef struct
{
char mbuf[ROLLING_WINDOW-1];
char pad[8-ROLLING_WINDOW+1];
int slice_num;
unsigned int msize;
struct zt_state_t p_state; //partial strong hash value
struct zt_state_t s_state; //strong hash state
struct roll_state_t r_state;
unsigned long long left_offset;
unsigned long long right_offset;
unsigned int * r_array; //array to store rolling hash value
unsigned int r_cnt;
unsigned int r_size;
struct zt_state_t * s_array; //array to store strong(Tillichi-Zemor) hash value
unsigned int s_cnt; //always point to the next available position
unsigned int s_size;
}sfh_seg_t;
typedef struct
{
unsigned long long orilen;
IVI_t * ivi; //ÿһ<C3BF><D2BB>handle<6C><65><EFBFBD><EFBFBD><E6B1A3>һ<EFBFBD><D2BB>IVIָ<49>һ<EBA3AC><D2BB>IVI<56><49><EFBFBD><EFBFBD><E6B1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Ƭ
unsigned long long effective_length;
unsigned long long blocksize;
unsigned long long fuzzy_node_memory;
unsigned long long IVI_memory;
unsigned long long length_increase;
int s_state_cnt;
unsigned int sim_tuned_rs_cnt;//rolling state count after a tune simulation
int do_tune;
}fuzzy_handle_inner_t;
typedef struct
{
char * hash_b1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>char<61><72><EFBFBD><EFBFBD>
char * hash_b2;
unsigned int size_b1,size_b2;
unsigned int offset_b1,offset_b2; //<2F><><EFBFBD><EFBFBD><E9B3A4>
unsigned long long first_ZTH_offset;
unsigned long long last_ZTH_offset;
char last_char_b1, last_char_b2;
unsigned long long b1,b2;
}sfh_output_t;
typedef struct
{
unsigned long long first_ZTH_offset;
unsigned long long last_ZTH_offset;
unsigned long long hash_length;
}final_length;
int destroy_sfh_seg(sfh_seg_t*p);
unsigned long long get_blocksize(unsigned long long orilen);
int sfh_merge_seg(fuzzy_handle_inner_t * _handle,sfh_seg_t * seg, sfh_seg_t * next_seg, unsigned long long blocksize);
int sfh_update_seg(fuzzy_handle_inner_t * _handle,sfh_seg_t * p, const char * data, unsigned long data_size, unsigned long long blocksize);
unsigned int segment_overlap(fuzzy_handle_inner_t * handle, unsigned int size, unsigned long long offset, const char * data);
void sfh_tune_callback(IVI_seg_t * seg, void * user_para);
void sfh_output_callback(IVI_seg_t * seg, void * user_para);
void fuzzy_hash_length(IVI_seg_t * seg, void * user_para);
#endif

View File

@@ -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

View File

@@ -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><><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

234
src/inc_internal/zt_hash.h Normal file

File diff suppressed because one or more lines are too long