diff options
| author | yangwei <[email protected]> | 2024-07-12 18:33:09 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2024-07-12 19:24:26 +0800 |
| commit | 22585b931e6fad43a8db300a9359f6e3811ffdf4 (patch) | |
| tree | 1b2e6a934c41a265fd4756aef450bcf717083f81 /src | |
| parent | c27eacce8a0b21b0692774d90edc213dc1dd54ea (diff) | |
🌈 style(header file refomat): remove CN annotationv4.3.61
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/config_parse.cpp | 213 | ||||
| -rw-r--r-- | src/dealpkt/deal_ipv6.c | 127 | ||||
| -rw-r--r-- | src/dealpkt/deal_udp.c | 114 | ||||
| -rw-r--r-- | src/dealpkt/stream_manage.c | 316 | ||||
| -rw-r--r-- | src/plugin/src/plugin_manage.cpp | 78 | ||||
| -rw-r--r-- | src/project/stream_bridge.c | 11 | ||||
| -rw-r--r-- | src/support/cpu_limit/cpu_limit.c | 113 |
7 files changed, 164 insertions, 808 deletions
diff --git a/src/config/config_parse.cpp b/src/config/config_parse.cpp index 9d4230e..c82f8f7 100644 --- a/src/config/config_parse.cpp +++ b/src/config/config_parse.cpp @@ -4,34 +4,30 @@ extern "C" { #endif -#include "sapp_api.h" -#include "sapp_private_api.h" +#include <stddef.h> +#include <sys/sysinfo.h> +#include "MESA_prof_load.h" + #include "support/tomlc99_wrap.h" -#include "field_stat2.h" #include "sapp_declaration.h" +#include "sapp_cla.h" extern int g_overlay_layer_set[__ADDR_TYPE_MAX][SAPP_SUPPORT_LAYER_NUM_MAX]; -/* - ˵��: - _sapp_toml_sample_file_image����, _sapp_toml_sample_file_image_len�����ǿ�����xxd -i �Զ����ɵ�, - �����ڶ�̬�������ļ�sapp.toml.hex.array.c��, - ���ļ��������git�ֿ�. -*/ extern const unsigned char _sapp_toml_sample_file_image[]; extern const int _sapp_toml_sample_file_image_len; #define SAPP_CFG_OBSOLETE_FLAG 99999999 typedef struct __sapp_config_check{ int global_id; - int depend_id; /* 1:����IJ���, ��������������, Ҳ����ȱʧ; 0:��ѡ��, ����û��, ��Ӱ��sapp���幦��; >=1000:����δ����, ȡ�����������ò����Ƿ���, ����transparentģʽ��������packet_io.external.interface */ - int err_log_level; /* 10,20,30, ������־�ȼ� */ + int depend_id; + int err_log_level; const char *section; const char *cfg_key; - const char *depend_cfg_value; /* ����depend_id>1000ʱ��Ч, ��ʾ����������ֵ����Ԥ�ȶ���ʱ, �ż�鵱ǰ�����Ƿ�Ϸ�, ����mirroģʽ�¸�������Ҫ��� packet_io.external.interface */ + const char *depend_cfg_value; int (*cfg_value_check_fun)(const struct __sapp_config_check *sapp_cfg_check_attr, int this_cfg_id, int depend_cfg_id, const char *cfg_value, const void *range_array, int array_num); - char *cfg_value; /* NULL is not found */ - const void *expect_range_array; /* ���ڼ�����ֵ�Ŀ�ѡ��Χ����, �������͵IJ�ͬ������int *, ������char **���� */ + char *cfg_value; + const void *expect_range_array; int expect_array_num; }sapp_config_check_t; @@ -46,7 +42,7 @@ static const char *sapp_cfg_get_value_from_attr_by_id(const sapp_config_check_t static const char *sapp_cfg_get_value_from_attr_by_section_key(const sapp_config_check_t *sapp_cfg_check_attr, const char *section, const char *key); static int cfg_value_check_inject_mode(const sapp_config_check_t *sapp_cfg_check_attr,int this_cfg_id,int depend_cfg_id, const char *raw_cfg_value, const void *expect_range_array, int array_num); -static int g_interger_range_array[65536]; /* һ��int�͵�����, ��ֵ�±����ֵһ��, �� g_interger_range_array[0]=0, g_interger_range_array[1]=1, �����ж���ֵ������Χ�Ϸ��� */ +static int g_interger_range_array[65536]; static int cfg_value_check_integer_range(const sapp_config_check_t *sapp_cfg_check_attr,int this_cfg_id,int depend_cfg_id, const char *raw_cfg_value, const void *expect_range_array, int array_num) @@ -113,8 +109,6 @@ static int cfg_value_check_worker_threads(const sapp_config_check_t *sapp_cfg_ch int cur_sys_cpu_num = get_nprocs(); if(cfg_value_int <= 0 || cur_sys_cpu_num < cfg_value_int){ - //printf("\033[33m[Warning]sapp.toml->CPU.worker_threads=%d more than current available processors:%d\033[0m\n", sapp_global_val->config.cpu.worker_threads, cur_sys_cpu_num); - //sapp_runtime_log(RLOG_LV_INFO, "[Warning]sapp.toml->CPU.worker_threads=%d more than current available processors:%d", sapp_global_val->config.cpu.worker_threads, cur_sys_cpu_num); return -1; } @@ -127,11 +121,9 @@ static int cfg_value_check_bind_mask(const sapp_config_check_t *sapp_cfg_check_a long bind_mask_array[SAPP_MAX_THREADS]; int ret; - /* ��ʱû��ֱ�ӽ���raw_cfg_value�ĺ���, �˴��ٶ�ȡһ�������ļ� */ ret = tomlc99_wrap_load_long_array(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"CPU", (char *)"bind_mask", bind_mask_array, &bind_mask_array_num); if(ret < 0){ unsigned int load_profile_array[SAPP_MAX_THREADS]; - /* ����Χ������, ��1-10,10-20�Ȳ���ʹ��MESA_load_profile_uint_range����, ��ʱҪ���ַ���ģʽ!!! */ ret = MESA_load_profile_uint_range( ABBR_CFG_FILE_MAIN_ENTRY, (char *)"CPU", (char *)"bind_mask", SAPP_MAX_THREADS, (unsigned int *)load_profile_array); @@ -143,7 +135,7 @@ static int cfg_value_check_bind_mask(const sapp_config_check_t *sapp_cfg_check_a } if(0 == bind_mask_array_num){ - return 0; /* ����������, ������CPU,������� */ + return 0; } const char *raw_cfg_worker_threads_value = sapp_cfg_get_value_from_attr_by_id(sapp_cfg_check_attr, depend_cfg_id); @@ -173,7 +165,7 @@ static int cfg_value_check_stream_id_base_time(const sapp_config_check_t *sapp_c struct tm local_tm; if(NULL == raw_cfg_value || strlen(raw_cfg_value) == 0){ - return 0; /* ����ΪNULL,������� */ + return 0; } if(strptime(raw_cfg_value, "%Y-%m-%d %H:%M:%S", &local_tm) == NULL){ @@ -207,7 +199,7 @@ static const sapp_config_check_t g_sapp_cfg_check_attr[] = {2002,0,RLOG_LV_DEBUG, "CPU", "send_only_threads_max", NULL,NULL, NULL, NULL, 0}, {2003,2001,RLOG_LV_FATAL,"CPU", "bind_mask", "",cfg_value_check_bind_mask, NULL, NULL, 0}, - {3001,0, RLOG_LV_INFO,"MEM", "dictator_enable", NULL,cfg_value_check_integer_range, NULL, g_interger_range_array, 2}, /* ֻ����0��1, ���Ծ���ǰ2��Ԫ�� */ + {3001,0, RLOG_LV_INFO,"MEM", "dictator_enable", NULL,cfg_value_check_integer_range, NULL, g_interger_range_array, 2}, {4000,0,RLOG_LV_DEBUG,"PACKET_IO", NULL, NULL, NULL,NULL, NULL, 0}, @@ -351,9 +343,6 @@ static const sapp_config_check_t g_sapp_cfg_check_attr[] = {9201,0,RLOG_LV_INFO, "LIBRARY_LINK", "marsio_library_path", NULL,NULL, NULL, NULL, 0}, - /******************************************************************************************************************/ - /*********** ��������ʷ���������ֹ�������, Ҳ�������,Ҳ���㲻֧��,����澯��Ϣ��ʾ���������� *********************/ - /******************************************************************************************************************/ {SAPP_CFG_OBSOLETE_FLAG,0,RLOG_LV_INFO,"overlay_tunnel_definition","stream_compare_layer_cfg_file",NULL, NULL, NULL,NULL, 0}, {SAPP_CFG_OBSOLETE_FLAG,0,RLOG_LV_INFO,"overlay_tunnel_definition","vlan_flipping_cfg_file",NULL, NULL, NULL,NULL, 0}, {SAPP_CFG_OBSOLETE_FLAG,0,RLOG_LV_INFO,"overlay_tunnel_definition","asymmetric_presence_layer_cfg_file",NULL, NULL, NULL,NULL, 0}, @@ -437,7 +426,6 @@ static int cfg_value_check_inject_mode(const sapp_config_check_t *sapp_cfg_check depend_cfg_index = cfg_get_index_by_depend_id(depend_cfg_id); depend_cfg_value = sapp_cfg_check_attr[depend_cfg_index].cfg_value; - /* raw_cfg_value������NULL, ��ʱӦ�����ж�depend_cfg_value, �������������, ��̫�����ǿ� */ if(strncasecmp(depend_cfg_value, "vxlan_by_inline_device", strlen("vxlan_by_inline_device")) == 0){ expect_cfg_index = cfg_get_index_by_key_name("inject_mode_inline_device_sport"); @@ -526,7 +514,6 @@ static inline int is_file_exist(const char *filename) static void update_overlay_vxlan_layer_set(void); -/* ������ͬ���͵�����, �����в�������, ����sapp.toml�е����� */ void sapp_cla_override_cfg_file(void) { char *cmd_args; @@ -537,7 +524,7 @@ void sapp_cla_override_cfg_file(void) } if (sapp_get_cla_raw("dumpfile", &cmd_args) >= 0) - { /* dumpfileģʽ�Զ�����interface���� */ + { strncpy(pconfig->packet_io.deployment_mode_str, "dumpfile", NAME_MAX); pconfig->packet_io.deployment_mode_bin = DEPLOYMENT_MODE_MIRROR; sapp_global_val->individual_fixed.deployment_mode_private = NET_CONN_PARALLEL; @@ -612,9 +599,6 @@ static int pkt_dump_thread_id_convert(void) return 0; } -/* - C_router_vlan_id I_router_vlan_id mac_flipping_enable -*/ static int parse_vlan_flipping_map_config(void) { FILE *fp; @@ -627,7 +611,6 @@ static int parse_vlan_flipping_map_config(void) fp = fopen(ABBR_VLAN_FLIPPING_CONF_FILE, "r"); if(NULL == fp){ sapp_log(RLOG_LV_INFO, ~0, ~0, "[warning]can't open vlan_flipping_cfg_file:%s", ABBR_VLAN_FLIPPING_CONF_FILE); - /* ��ǰ����, ����ļ�������, ������� */ return 0; } @@ -718,10 +701,6 @@ static int embed_layer_t_pton(char *config_val, embed_layer_t *result) return 0; } -/* - return value pattern: - addr_type_name[layer_index] -*/ static const char *embed_layer_t_ntop(const embed_layer_t *layer_st, char *result, int res_max_len) { char addrtype_name_str[NAME_MAX] = {}; @@ -779,11 +758,6 @@ static int update_asymmetric_presence_layer(enum addr_type_t addrtype, embed_lay return 0; } -/* - #pattern: asymmetric_layer_name[layer index] - ethernet[1] - mpls[*] -*/ static int parse_asymmetric_addr_layer_config(void) { int i, j, ret; @@ -796,7 +770,6 @@ static int parse_asymmetric_addr_layer_config(void) fp = fopen(ABBR_ASYM_LAYER_ADDR_CONF_FILE, "r"); if(NULL == fp){ sapp_log(RLOG_LV_INFO, ~0, ~0, "[Warning]can't open asymmetric_addr_layer_cfg_file:%s", ABBR_ASYM_LAYER_ADDR_CONF_FILE); - /* ��ǰ����, ����ļ�������, ������� */ return 0; } @@ -850,11 +823,6 @@ static int set_default_stream_compare_layer(embed_layer_t *stream_compare_layer_ return 0; } -/* - #pattern: stream_compare_layer_name[layer index] - vlan[1] - mpls[*] -*/ static int parse_stream_compare_layer_config(void) { int i, j, ret; @@ -869,7 +837,6 @@ static int parse_stream_compare_layer_config(void) fp = fopen(ABBR_STREAM_CMP_LAYER_CONF_FILE, "r"); if(NULL == fp){ sapp_log(RLOG_LV_INFO, ~0, ~0, "[Warning]can't open stream compare layer cfg_file:%s", ABBR_STREAM_CMP_LAYER_CONF_FILE); - /* ��ǰ����, ����ļ�������, ������� */ return 0; } @@ -913,7 +880,7 @@ static void update_overlay_vxlan_layer_set(void) g_overlay_layer_set[ADDR_TYPE_MAC][0] = 1; g_overlay_layer_set[ADDR_TYPE_IPV4][1] = 1; g_overlay_layer_set[__ADDR_TYPE_IP_PAIR_V4][1] = 1; - g_overlay_layer_set[ADDR_TYPE_UDP][1] = 1; /* IP��udp�ϲ���Ϊһ��, ���Դ˴�������1 */ + g_overlay_layer_set[ADDR_TYPE_UDP][1] = 1; g_overlay_layer_set[ADDR_TYPE_VXLAN][2] = 1; } @@ -930,18 +897,11 @@ static void update_well_known_port_array(int last_section_proto, unsigned short } } -/* - #pattern: - [TCP] - some ports here - [UDP] - some ports here -*/ static int parse_well_known_port_config(void) { FILE *fp; char line_buf[256]; - int last_section_proto = -1; /* �����ʶ: TCP or UDP */ + int last_section_proto = -1; unsigned short *port_array = NULL; int port_array_num = 0; int tmpnum; @@ -949,7 +909,7 @@ static int parse_well_known_port_config(void) fp = fopen(ABBR_WELL_KNOWN_PORT_CONF_FILE, "r"); if(NULL == fp){ - return 0; /* û�д��ļ�, ������� */ + return 0; } while(fgets(line_buf, sizeof(line_buf), fp)){ @@ -959,9 +919,8 @@ static int parse_well_known_port_config(void) sapp_memmove_for_blank_table(line_buf, sizeof(line_buf)); del_last_rn(line_buf, sizeof(line_buf)); - if('[' == line_buf[0]){ /* [] һ���������ʼ */ + if('[' == line_buf[0]){ if(port_array != NULL){ - /* ��һ������ս��� */ update_well_known_port_array(last_section_proto, port_array, port_array_num); port_array = NULL; port_array_num = 0; @@ -1012,9 +971,6 @@ static int parse_well_known_port_config(void) return 0; } -/* - example: ether[4]:0 -*/ static int parse_extract_linkdir_from_mac_cfg(void) { sapp_config_t *pconfig; @@ -1053,7 +1009,6 @@ static int parse_extract_linkdir_from_mac_cfg(void) return 0; } -/* ���ø�ʽת��, ���ַ�������תΪint����,���ڳ����� */ static int config_expression_convert(void) { sapp_config_t *pconfig; @@ -1072,15 +1027,7 @@ static int config_expression_convert(void) sapp_global_val->individual_fixed.create_stream_mode = TCP_CTEAT_LINK_BYSYN | TCP_CTEAT_LINK_BYDATA; } - /****************************** PACKET_IO *******************************/ - /* - net_connection_mode: - 0: don't send packet, only capture; - 1: parallel mode with single card; - 2: serial mode with two card; - 3: logic serial mode with G device. - */ tmp_str = pconfig->packet_io.deployment_mode_str; if(strncasecmp(tmp_str, "mirror", strlen("mirror")) == 0){ pconfig->packet_io.deployment_mode_bin = DEPLOYMENT_MODE_MIRROR; @@ -1141,7 +1088,6 @@ static int config_expression_convert(void) return- 1; } - //todo, parse prune inject cfg file tmp_str = pconfig->packet_io.internal.interface.type_str; @@ -1211,7 +1157,6 @@ static int config_expression_convert(void) return -1; } - /****************************** STREAM *******************************/ struct tm ttm = {}; if(sapp_global_val->config.stream.stream_id_base_time_str[0] == '\0'){ sapp_log(20, ~0, ~0, "[Warning]sapp.toml->STREAM.stream_id_base_time is not set, use '1970-01-01 00:00:00' as default!"); @@ -1232,7 +1177,6 @@ static int config_expression_convert(void) sapp_global_val->config.stream.stream_id_base_time_t = mktime(&ttm); } - /****************************** TOOLS *******************************/ if(pconfig->tools.pkt_dump.enabled != 0){ if(strncasecmp(pconfig->tools.pkt_dump.mode_str, "storage" ,strlen("storage")) == 0){ pconfig->tools.pkt_dump.mode_bin = PKT_DUMP_LOCAL_FILE; @@ -1251,10 +1195,6 @@ static int config_expression_convert(void) return 0; } -/* - 1: yes, go on! - 0: no, exit. -*/ static int get_user_intention(void) { char input_buf[MAX_INPUT]; @@ -1280,30 +1220,15 @@ static inline void old_config_file_detect(const char *old_filename, const char * sapp_log(RLOG_LV_FATAL, ~0, ~0, "This is sapp v4.0, detect obsolete config file:\"%s\"! please use \"%s\" instead!", old_filename, new_filename); if(is_file_exist(new_filename)){ sapp_log(RLOG_LV_FATAL, ~0, ~0, "You already have new config file:\"%s\", you must rename or delete obsolete file:\"%s\"!", new_filename, old_filename); - //sapp_log(30, ~0, ~0, "Are you sure you are using new config file? 'y' or 'n':"); - //if(0 == get_user_intention()){ exit(1); - //} }else{ - //sapp_log(30, ~0, ~0, "Do you want to continue running, the sapp behavior is unpredictable! 'y' or 'n' : "); - //if(0 == get_user_intention()){ sapp_log(30, ~0, ~0, "You should run ./sapp --sample-config to generate sapp.toml!"); exit(1); - //} } } } -/* - �����ļ��Ϸ��ԡ�����Լ��. - - TODO: ������������ g_sapp_cfg_check_attr[] ���ϲ�, ijЩ�����������ظ���!!! - - return value: - 0: succ; - -1: error, must exit! -*/ static int config_sanity_check(void) { int cur_cpu_num; @@ -1313,7 +1238,7 @@ static int config_sanity_check(void) struct streaminfo_private phony_stream_pr; phony_stream_pr.layer_index = 0xF; - assert(SAPP_SUPPORT_LAYER_NUM_MAX == phony_stream_pr.layer_index); /* �����ж�����������layer_index��SAPP_SUPPORT_LAYER_NUM_MAX, ����������һ�µ���� */ + assert(SAPP_SUPPORT_LAYER_NUM_MAX == phony_stream_pr.layer_index); if(SAPP_SUPPORT_LAYER_NUM_MAX != phony_stream_pr.layer_index){ sapp_log(RLOG_LV_FATAL, ~0, ~0, "SAPP_SUPPORT_LAYER_NUM_MAX is:%d, but streaminfo_private->layer_index max is:%d", SAPP_SUPPORT_LAYER_NUM_MAX, phony_stream_pr.layer_index); return -1; @@ -1335,7 +1260,6 @@ static int config_sanity_check(void) } } - /******************************* CPU ********************************/ cur_cpu_num = get_nprocs(); if(cur_cpu_num < pconfig->cpu.worker_threads){ sapp_log(20, 0, ~0, "[Warning]sapp.toml->CPU.worker_threads=%d more than current available processors:%d", sapp_global_val->config.cpu.worker_threads, cur_cpu_num); @@ -1371,7 +1295,6 @@ static int config_sanity_check(void) } } - /******************************* STREAM ******************************/ if(pconfig->stream.tcp.inject.auto_remedy != 0){ if(pconfig->stream.tcp.inject.rst_num <= 0 || pconfig->stream.tcp.inject.rst_num >= 10){ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->stream.tcp.inject.rst.number=%d, is Illegal!", pconfig->stream.tcp.inject.rst_num); @@ -1379,7 +1302,6 @@ static int config_sanity_check(void) } } - /******************************* Packet IO ******************************/ tmp_str = pconfig->packet_io.deployment_mode_str; if((strncasecmp(tmp_str, "mirror", strlen("mirror")) != 0) @@ -1431,7 +1353,6 @@ static int config_sanity_check(void) } } - /******************************* PKT_DUMP ******************************/ if(pconfig->tools.pkt_dump.enabled != 0){ if(pconfig->tools.pkt_dump.dump_thread_id_array_num > pconfig->cpu.worker_threads){ sapp_log(RLOG_LV_FATAL, ~0, ~0, "TOOLS.PKT_DUMP.dump_thread_id_array items more than CPU.worker_threads!"); @@ -1460,9 +1381,6 @@ static int config_sanity_check(void) -/* - ֧�ֶ�д����ģʽ, ���¸��������ļ�·��, ���������ļ�·��. -*/ int sapp_get_secondary_file_path(void) { char str_tmp[ARG_MAX]; @@ -1498,7 +1416,6 @@ int sapp_get_secondary_file_path(void) pconfig->data_file_path.data_sapp_fs2_process_latency_relative = sapp_strdup(pconfig->profiling.process_latency_local_file); } - /*************************** SECONDARY_CONFIG_LINK *************************/ tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"SECONDARY_CONFIG_LINK", (char *)"cfg_file_sapp_log", str_tmp, ARG_MAX, "etc/sapp_log.conf"); if(str_tmp[0] != '\0'){ if(pconfig->cfg_file_path.cfg_sapp_log_relative){ @@ -1588,7 +1505,6 @@ int sapp_get_secondary_file_path(void) pconfig->cfg_file_path.cfg_file_well_known_port_relative = sapp_strdup(str_tmp); } - /*************************** SECONDARY_DATA_LINK *************************/ tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"SECONDARY_DATA_LINK", (char *)"data_file_sysinfo_log", str_tmp, ARG_MAX, "sysinfo.log"); if(str_tmp[0] != '\0'){ if(pconfig->data_file_path.data_sapp_sysinfo_log_relative){ @@ -1634,7 +1550,6 @@ int sapp_get_secondary_file_path(void) } -/* ��ȡ�����ļ�sapp.toml, ������ֻLoad, ���������ʹ����� */ int sapp_parse_config(void) { int ret; @@ -1653,15 +1568,12 @@ int sapp_parse_config(void) pconfig = &sapp_global_val->config; - /******************************* SYSTEM *********************************/ ret = tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"SYSTEM", (char *)"instance_name", pconfig->system.instance_name, NAME_MAX, "sapp_v4.2"); if(TOMLC99_RET_PATTERN_ERROR == ret){ - /* �״ν����ж������PATTERN_ERROR, ˵��toml��ʽ������, ���ټ������� */ sapp_log(30, ~0, ~0, "parse config file %s error!", ABBR_CFG_FILE_MAIN_ENTRY); exit(1); } - /******************************* PROFILING.LOG ***************************/ MESA_handle_runtime_log_creation(ABBR_SAPP_LOG_CONF_FILE); tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"profiling.log", (char *)"sapp_log_category", pconfig->profiling.log.sapp_log_category, NAME_MAX, "sapp_runtime_log"); @@ -1671,7 +1583,6 @@ int sapp_parse_config(void) sapp_global_val->individual_fixed.plugin_log_handle = MESA_create_runtime_log_handle(sapp_global_val->config.profiling.log.sapp_plugin_log_category, RLOG_LV_INFO); - /******************************* CPU *********************************/ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"CPU", (char *)"worker_threads", (int *)&pconfig->cpu.worker_threads, 1); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"CPU", (char *)"send_only_threads_max", (int *)&pconfig->cpu.send_only_threads_max_num, 0); @@ -1679,7 +1590,6 @@ int sapp_parse_config(void) tomlc99_wrap_load_long_array(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"CPU", (char *)"bind_mask", pconfig->cpu.bind_mask_array, &pconfig->cpu.bind_mask_array_num); - /* ����Χ������, ��1-10,10-20�Ȳ���ʹ��MESA_load_profile_uint_range����, ��ʱҪ���ַ���ģʽ!!! */ int tmp_bind_mask[SAPP_MAX_THREADS] = {}; ret = MESA_load_profile_uint_range( ABBR_CFG_FILE_MAIN_ENTRY, (char *)"CPU", (char *)"bind_mask", @@ -1695,16 +1605,12 @@ int sapp_parse_config(void) - /******************************* PACKET_IO ******************************/ - /******************************* packet_io.overlay_tunnel_definition ******************************/ - //tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"overlay_tunnel_definition", (char *)"l2_l3_tunnel_support", &pconfig->packet_io.packet_io_tunnel.l2_l3_tunnel_support, 1); pconfig->packet_io.packet_io_tunnel.l2_l3_tunnel_support=1; tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"overlay_tunnel_definition", (char *)"overlay_mode", pconfig->packet_io.packet_io_tunnel.overlay_mode_string, NAME_MAX, "none"); - /******************************* packet_io.feature ******************************/ tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.feature", (char *)"BSD_packet_filter", str_tmp, NAME_MAX, ""); if(str_tmp[0] != '\0'){ pconfig->packet_io.input_bpf_filter = sapp_strdup(str_tmp); @@ -1744,15 +1650,13 @@ int sapp_parse_config(void) tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.polling", (char *)"work_percent", &pconfig->packet_io.work_percent, 90); - /** duplicate packet config **/ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.traffic.original", (char *)"kickout_udp_stream_enabled", &pconfig->packet_io.dup_pkt_para.kickout_udp_stream_enabled, 0); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.traffic.original", (char *)"original_ipv4_tcp_enabled", &pconfig->packet_io.dup_pkt_para.dup_pkt_distinguish_ipv4_tcp, 0); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.traffic.original", (char *)"original_ipv4_udp_enabled", &pconfig->packet_io.dup_pkt_para.dup_pkt_distinguish_ipv4_udp, 0); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.traffic.inject", (char *)"inject_all_enabled", &pconfig->packet_io.dup_pkt_para.dup_pkt_distinguish_all_inject, 0); - /******************************* packet_io.under_ddos ******************************/ - tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.under_ddos", (char *)"stream_bypass_enabled", &pconfig->packet_io.under_ddos_config.enabled, 0); //��ǰ����, Ĭ�ϲ����� + tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.under_ddos", (char *)"stream_bypass_enabled", &pconfig->packet_io.under_ddos_config.enabled, 0); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.under_ddos", (char *)"get_cpu_usage_interval", &pconfig->packet_io.under_ddos_config.get_cpu_usage_interval, 500); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.under_ddos", (char *)"smooth_avg_window", &pconfig->packet_io.under_ddos_config.smooth_avg_window, 2); @@ -1767,10 +1671,8 @@ int sapp_parse_config(void) tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.under_ddos", (char *)"recovery_observe_time", &pconfig->packet_io.under_ddos_config.recovery_observe_time, 60); - /******************************* STREAM ******************************/ tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"STREAM", (char *)"stream_id_base_time", pconfig->stream.stream_id_base_time_str, 32, ""); - /******************************* STREAM.TCP ******************************/ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.tcp", (char *)"max", (int *)&pconfig->stream.tcp.max, 50000); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.tcp", (char *)"timeout", (int *)&pconfig->stream.tcp.timeout, 180); @@ -1799,7 +1701,6 @@ int sapp_parse_config(void) tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.tcp.inject.rst", (char *)"remedy_kill_tcp_by_inline_device", &pconfig->stream.tcp.inject.remedy_kill_tcp_by_inline_device, 0); - /******************************* STREAM.UDP ******************************/ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.udp", (char *)"max", (int *)&pconfig->stream.udp.max, 5000); if(pconfig->stream.udp.timeout == 0)pconfig->stream.udp.timeout=MAX_DEFALUT_TIMEOUT_S; tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.udp", (char *)"max_opening", (int *)&pconfig->stream.udp.max_opening, pconfig->stream.udp.max*3); @@ -1811,7 +1712,6 @@ int sapp_parse_config(void) tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.udp", (char *)"max_timeouts_per_sec", (int *)&pconfig->stream.udp.max_timeouts_per_sec, 0); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"stream.udp", (char *)"max_opening_per_sec", (int *)&pconfig->stream.udp.max_opening_per_sec, 0); - /******************************* Bloom parameter ******************************/ int tmp_dm_timeout; tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.parameters", (char *)"bloom_transition_time", &tmp_dm_timeout, 3); pconfig->packet_io.dup_pkt_para.transition_time_ms = (long)tmp_dm_timeout * 1000; @@ -1823,13 +1723,11 @@ int sapp_parse_config(void) tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.parameters", (char *)"bloom_partition_num", (int *)&pconfig->packet_io.dup_pkt_para.bloom_partition_num, 16); pconfig->packet_io.dup_pkt_para.bloom_error_rate = strtod(str_tmp, NULL); - //default capacity = (tcp_stream_num + udp_stream_num)*first_dup_check_packet_num*2 int default_bloom_capacity = ((pconfig->stream.tcp.max*6+pconfig->stream.udp.max+pconfig->stream.udp.max_pair+pconfig->stream.udp.max_opening)*pconfig->packet_io.dup_pkt_para.first_packets)*2; tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.parameters", (char *)"bloom_capacity", &pconfig->packet_io.dup_pkt_para.bloom_capacity, default_bloom_capacity); int default_bloom_timeout=pconfig->stream.udp.timeout; tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.parameters", (char *)"bloom_timeout", &tmp_dm_timeout, default_bloom_timeout); pconfig->packet_io.dup_pkt_para.bloom_timeout_ms = (long)tmp_dm_timeout * 1000; - /******************************* PROFILING.metric.fs2 **********************/ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"profiling.metric.fs2", (char *)"enabled", (int *)&pconfig->profiling.fs2.enabled, 0); if(pconfig->profiling.fs2.enabled) { @@ -1840,7 +1738,6 @@ int sapp_parse_config(void) } tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"profiling.metric.fs3", (char *)"enabled", (int *)&pconfig->profiling.fs3.enabled, 0); - /******************************* PROFILING.metric.fs3 **********************/ if(pconfig->profiling.fs3.enabled) { tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"profiling.metric.fs3", (char *)"prometheus_port", (int *)&pconfig->profiling.fs3.prometheus_service_port, 0); @@ -1849,7 +1746,6 @@ int sapp_parse_config(void) tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"profiling.metric.fs3", (char *)"app_name", pconfig->profiling.fs3.app_name, NAME_MAX, "sapp4"); } - /******************************* PROFILING.process_latency ******************************/ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"profiling.process_latency", (char *)"histogram_enabled", (int *)&pconfig->profiling.histogram_enabled, 0); tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"profiling.process_latency", (char *)"log_category", pconfig->profiling.process_latency_log_category, NAME_MAX, "sapp_process_latency_log"); @@ -1873,13 +1769,11 @@ int sapp_parse_config(void) pconfig->profiling.process_latency_clock_id=6; } - /******************************* PROFILING.sanity_check ******************************/ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"profiling.sanity_check", (char *)"raw_pkt_broken_enabled", (int *)&pconfig->profiling.sanity_check_raw_pkt_broken_enabled, 0); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"profiling.sanity_check", (char *)"symbol_conflict_enabled", (int *)&pconfig->profiling.sanity_check_symbol_conflict_enabled, 0); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"profiling.memory", (char *)"memory_used_stat_interval_s", (int *)&pconfig->profiling.memory_used_stat_interval_s, 10); - /************************ PROTOCOL_FEATURE **********************************/ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"PROTOCOL_FEATURE", (char *)"ipv6_decapsulation_enabled", (int *)&pconfig->protocol_feature.ipv6_decapsulation_enabled, 1); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"PROTOCOL_FEATURE", (char *)"ipv6_send_packet_enabled", (int *)&pconfig->protocol_feature.ipv6_send_packet_enabled, 1); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"PROTOCOL_FEATURE", (char *)"tcp_drop_pure_ack_pkt", (int *)&pconfig->protocol_feature.tcp_drop_pure_ack_pkt, 0); @@ -1893,7 +1787,6 @@ int sapp_parse_config(void) tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"PROTOCOL_FEATURE", (char *)"ipv4_reassembly_enabled", (int *)&pconfig->protocol_feature.ipv4_reassembly_enabled, 1); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"PROTOCOL_FEATURE", (char *)"ipv6_reassembly_enabled", (int *)&pconfig->protocol_feature.ipv6_reassembly_enabled, 1); - /******************************* TOOLS **********************************/ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"tools.signal_handler", (char *)"signal", (int *)&pconfig->tools.signal_handler.signal, 0); tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"tools.pkt_dump", (char *)"enabled", (int *)&pconfig->tools.pkt_dump.enabled, 0); @@ -1933,11 +1826,6 @@ int sapp_parse_config(void) return 0; } -/* - 0: ����ʶ�����ļ��е�key-value; - 1: ʶ�洢�����ļ��е�key-value; - 2: ����ijЩ�Ѿ��������IJ���. -*/ static int sapp_config_check_update_option(sapp_config_check_t *local_cfg_check_attr, const char *section, const char *key, const char *value) { int i; @@ -1945,7 +1833,7 @@ static int sapp_config_check_update_option(sapp_config_check_t *local_cfg_check_ int found_cfg = 0; for(i = 0; local_cfg_check_attr[i].global_id != -1; i++){ - if(NULL == local_cfg_check_attr[i].cfg_key){ /* [PACKET_IO], []DUPLICATE_PKT] ������ֻ�и�section, ����û��key */ + if(NULL == local_cfg_check_attr[i].cfg_key){ continue; } section_max_len = SAPP_MAX(strlen(local_cfg_check_attr[i].section), strlen(section)); @@ -1957,7 +1845,7 @@ static int sapp_config_check_update_option(sapp_config_check_t *local_cfg_check_ return 2; }else{ if(NULL == value){ - local_cfg_check_attr[i].cfg_value = sapp_strdup(""); /* û�����������ֵ, ����bpf��������Ϊ��, ����key�Ǵ��ڵ�, Ҳ�������ҵ��� */ + local_cfg_check_attr[i].cfg_value = sapp_strdup(""); }else{ local_cfg_check_attr[i].cfg_value = sapp_strdup(value); } @@ -1975,9 +1863,6 @@ extern int sapp_del_last_char(char *data, int max_len, char del_char); extern char *sapp_memmove_for_blank_table(char *data, int max_len); -/* - �Ƿ���Ҫ��鵱ǰ���õĺϷ���. -*/ static int cfg_value_need_be_check(const sapp_config_check_t *local_cfg_check_array, const sapp_config_check_t *this_cfg_check_attr) { int depend_cfg_index; @@ -1985,7 +1870,7 @@ static int cfg_value_need_be_check(const sapp_config_check_t *local_cfg_check_ar if(1 == this_cfg_check_attr->depend_id){ return 1; } - if(0 == this_cfg_check_attr->depend_id){ /* ��ѡ������Ҳ��� */ + if(0 == this_cfg_check_attr->depend_id){ return 1; } @@ -2002,13 +1887,6 @@ static int cfg_value_need_be_check(const sapp_config_check_t *local_cfg_check_ar return 0; } -/* - ��ȫ����һ�鵱ǰ��sapp.toml, ����Ƿ��в���ʶ������, �����˵��: - 1)sapp��sapp.toml�İ汾��; - 2)ijЩ��ʷ�ϵIJ����Ѿ�������, ����sapp.toml������; - - �˴�����prof_load����������fgets���ж�ȡ, ��Ϊ���Ȳ�֪��Ҫ��ȡʲô, Ҫ�����е��ж�����һ��. -*/ static int sapp_config_check_unsupport(sapp_config_check_t *local_cfg_check_attr) { int ret, fun_ret = 0; @@ -2017,7 +1895,7 @@ static int sapp_config_check_unsupport(sapp_config_check_t *local_cfg_check_attr char section_string[128] = {}; char *cfg_key; char *cfg_value; - const char *kname_delim = "="; /* ������ֵֻ����=�ָ�, ������key��ֵ��Ŀո�\tɾ��, ����bpf filter */ + const char *kname_delim = "="; const char *section_delim = "[] \t"; char *key_save_ptr, *section_save_ptr; FILE *fp; @@ -2035,12 +1913,12 @@ static int sapp_config_check_unsupport(sapp_config_check_t *local_cfg_check_attr if('#' == raw_config_line[0]){ continue; } - if('\0' == raw_config_line[0]){ /* ������ */ + if('\0' == raw_config_line[0]){ continue; } memcpy(config_line, raw_config_line, sizeof(raw_config_line)); - if('[' == raw_config_line[0]){ /* ��[��ͷ��ʾ��section���俪ʼ */ + if('[' == raw_config_line[0]){ char *pure_sesion_str = strtok_r(config_line, section_delim, §ion_save_ptr); strncpy(section_string, pure_sesion_str, sizeof(section_string)); while(strtok_r(NULL, section_delim, §ion_save_ptr)); @@ -2063,7 +1941,7 @@ static int sapp_config_check_unsupport(sapp_config_check_t *local_cfg_check_attr sapp_memmove_for_blank_table(cfg_value, strlen(cfg_value)); - const char *kkvalue_delim = "\"'"; /* ������ֵ���ܱ�˫���ű�����, ��ʱֻ��ȥ�����ŵ��Dz������ÿո�\t�ָ���, ����bpf_filter */ + const char *kkvalue_delim = "\"'"; char *pure_cfg_value_save_ptr; char *pure_cfg_value = strtok_r(cfg_value, kkvalue_delim, &pure_cfg_value_save_ptr); ret = sapp_config_check_update_option(local_cfg_check_attr, section_string, cfg_key, pure_cfg_value); @@ -2080,10 +1958,6 @@ static int sapp_config_check_unsupport(sapp_config_check_t *local_cfg_check_attr return fun_ret; } -/* - ��������֪�IJ�����sapp.toml���ȡһ��, ����Ƿ��в����ڵ�����, �����: - 1)sapp��sapp.toml�İ汾��; -*/ static int sapp_config_check_missing(sapp_config_check_t *local_cfg_check_attr) { int ret1, ret2, ret3, i; @@ -2092,10 +1966,10 @@ static int sapp_config_check_missing(sapp_config_check_t *local_cfg_check_attr) int fun_ret = 0; for(i = 0; local_cfg_check_attr[i].global_id != -1; i++){ - if(NULL == local_cfg_check_attr[i].cfg_key){ /* [PACKET_IO], []DUPLICATE_PKT] ������ֻ�и�section, ����Ϊ�����ʶ, ����û��key */ + if(NULL == local_cfg_check_attr[i].cfg_key){ continue; } - if(SAPP_CFG_OBSOLETE_FLAG == local_cfg_check_attr[i].global_id){ /* �Ѿ�����������, �����ڼ��missing */ + if(SAPP_CFG_OBSOLETE_FLAG == local_cfg_check_attr[i].global_id){ continue; } if(cfg_value_need_be_check(local_cfg_check_attr, &local_cfg_check_attr[i]) == 0){ @@ -2103,24 +1977,20 @@ static int sapp_config_check_missing(sapp_config_check_t *local_cfg_check_attr) } ret1 = MESA_load_profile_string_nodef(ABBR_CFG_FILE_MAIN_ENTRY, local_cfg_check_attr[i].section, local_cfg_check_attr[i].cfg_key, cfg_value, sizeof(cfg_value)); if(ret1 < 0){ - /* ��profile�ӿڶ�ȡ�����п�����toml��ʽ������, ����toml���鳢�Խ���һ�� */ array_num = 1024; ret2 = tomlc99_wrap_load_int_array(ABBR_CFG_FILE_MAIN_ENTRY, local_cfg_check_attr[i].section, (char *)local_cfg_check_attr[i].cfg_key, cfg_array, &array_num); if(ret2 < 0){ - /* ʹ��toml����Ҳû�ж�ȡ������, ����Ƿ��������������� */ if((local_cfg_check_attr[i].depend_id != 0) && (local_cfg_check_attr[i].cfg_value_check_fun != NULL)){ ret3 = local_cfg_check_attr[i].cfg_value_check_fun(local_cfg_check_attr, local_cfg_check_attr[i].global_id, local_cfg_check_attr[i].depend_id, local_cfg_check_attr[i].cfg_value, local_cfg_check_attr[i].expect_range_array, local_cfg_check_attr[i].expect_array_num); if(ret3 != 0){ fun_ret = SAPP_MAX(local_cfg_check_attr[i].err_log_level, fun_ret); sapp_printf_colorful(fun_ret, "missing sapp.toml config: [%s] -> %s\n", local_cfg_check_attr[i].section, local_cfg_check_attr[i].cfg_key); - /* ע��: �˴���Ҫbreak, ������е������ļ����� */ } }else{ fun_ret = SAPP_MAX(local_cfg_check_attr[i].err_log_level, fun_ret); sapp_printf_colorful(fun_ret, "missing sapp.toml config: [%s] -> %s\n", local_cfg_check_attr[i].section, local_cfg_check_attr[i].cfg_key); - /* ע��: �˴���Ҫbreak, ������е������ļ����� */ } } } @@ -2134,7 +2004,6 @@ static int sapp_config_check_missing_and_unsupport(sapp_config_check_t *local_cf { int ret; - /* ע��: check_unsupport����ǰ��, ��Ϊ���и���������, ���ǰ��������õ�ֵ��ȡ��ȫ�ֱ���: g_sapp_cfg_check_attr ��*/ ret = sapp_config_check_unsupport(local_cfg_check_attr); if(ret != 0){ sapp_printf_colorful(ret, "maybe a typo, maybe some config is obsolete, or sapp is older than sapp.toml version!\n"); @@ -2150,9 +2019,6 @@ static int sapp_config_check_missing_and_unsupport(sapp_config_check_t *local_cf return ret; } -/* - ���ÿ�����������ĺϷ���, ֻ�ǵ�����������ֵ�ϲ��Ϸ�, ���������Լ��. -*/ static int sapp_config_check_single_validity(sapp_config_check_t *local_cfg_check_attr) { int i, ret, fun_ret = 0; @@ -2178,32 +2044,16 @@ static int sapp_config_check_single_validity(sapp_config_check_t *local_cfg_chec return fun_ret; } -/* - ����Ӳ���֮��Ĺ����Լ��, - ��������Ϊtransparentģʽ, ���뿪��packet_io.external.interface; - ���翪����prometheus_enabled, ������prometheus_port��prometheus_url_path; -*/ static int sapp_config_check_sanity(sapp_config_check_t *local_cfg_check_attr) { - /* - TODO: - - */ return 0; } -/* - check_level: - t1: ֻ���֧�ֵIJ����ڲ���, �Ƿ��в�֧�ֵ��²���; - t2: ���ÿ��������ֵ�Ƿ�Ϸ�, ����packet_io.mode ����mirror, inline, tansparent��; - t3: ������鵥������, �����ܵļ�����в������������������, ����transparentģʽû������external����; -*/ int sapp_config_check(void) { int i, ret1, ret2, final_ret = 0; - /* ȫ�ֱ������й̶����������, Ҳ�ж�̬�������ļ���ȡ������, ���Դ˴�copyһ����ʱ���� */ sapp_config_check_t *local_cfg_check_attr = (sapp_config_check_t *)sapp_mem_calloc(SAPP_MEM_FIX_GLOBAL_VAL, MEM_STAT_GLOBAL_THREAD_ID,sizeof(g_sapp_cfg_check_attr)); memcpy(local_cfg_check_attr, g_sapp_cfg_check_attr, sizeof(g_sapp_cfg_check_attr)); @@ -2228,7 +2078,6 @@ int sapp_config_check(void) done: if(final_ret != 0){ - //printf("\033[1;31;40msapp config check fail!\033[0m\n"); sapp_printf_colorful(final_ret, "You should use './sapp -e filename' to generate the latest sample configuration file.\n"); }else{ printf("\033[32msapp config check success!\033[0m\n"); @@ -2254,11 +2103,9 @@ void sapp_log_handle_destroy(void) } -/* init breakpad_mini */ void sapp_init_breakpad_mini(void) { #ifdef GIT_VERSION - //__attribute__((__used__)) const char *sapp_git_ver = GIT_VERSION; const char *sapp_git_ver = GIT_VERSION; #else const char * sapp_git_ver = "sapp_version_unkonw"; diff --git a/src/dealpkt/deal_ipv6.c b/src/dealpkt/deal_ipv6.c index 8a4a8e5..c948cac 100644 --- a/src/dealpkt/deal_ipv6.c +++ b/src/dealpkt/deal_ipv6.c @@ -1,14 +1,4 @@ -/*
- * Description:
- * IPv6 implement.
- *
- * Author: Li Jia<[email protected]>
- * Date: 2012-05-25
- * Version: 0.1
- */
-#include "sapp_api.h"
-#include "sapp_private_api.h"
#include "sapp_declaration.h"
#include "stream_internal.h"
@@ -86,7 +76,6 @@ static uchar * ipv6_frag_key_dup(const uchar *key, uint key_size) raw_frag_key = (struct ipv6_frag_key *)key;
tid = raw_frag_key->pfstream_pr->stream_public.threadnum;
- /* �˺�������ȡ�̺߳�, ����ʹ��malloc, ͬ��������ҲҪʹ��free */
new_frag_key = (struct ipv6_frag_key *)sapp_mem_calloc(SAPP_MEM_DYN_IP_FRAG_PKT, tid, sizeof(struct ipv6_frag_key));
memcpy(&new_frag_key->ip6_src, &raw_frag_key->ip6_src, sizeof(struct in6_addr));
@@ -121,7 +110,6 @@ void ipv6_frag_ipq_free_no_iph(void *data) struct ip_frags *frag, *next;
int thread_num = ipq->thread_num;
- /* Release all fragment data. */
frag = ipq->fragments;
while(frag != NULL)
{
@@ -149,7 +137,6 @@ static void ipv6_frag_ipq_free_all(void *data) {
struct frag_ipq *ipq = (struct frag_ipq *)data;
- /* ���������ɾ��ʱ, Ҫ�ͷ�new_iph�ڴ� */
if(ipq->new_iph){
sapp_mem_free(SAPP_MEM_DYN_IP_FRAG_PKT,ipq->thread_num, ipq->new_iph);
}
@@ -185,7 +172,6 @@ static inline int checkipv6pkt(const struct mesa_ip6_hdr * iph, int payload_len, break;
#endif
case NEXTHDR_FRAGMENT :
- /* NOTE: ��ΪIPv6��Ƭ�����, �ֵݹ������ipv6_entry(), ��ʱ���ܼ�⸺�س��ȴ���raw_pkt_len, ֻ��ԭʼ��Ƭ��������ô��� */
if(payload_len + (int)sizeof(struct mesa_ip6_hdr) > raw_pkt_len){
sapp_runtime_log(20, "ipv6 packet check error: fragement pkt len:%d, raw_pkt len: %d\n", payload_len, raw_pkt_len);
return -1;
@@ -204,7 +190,6 @@ static inline int checkipv6pkt(const struct mesa_ip6_hdr * iph, int payload_len, return 0;
}
-/* 2012-05-25 LiJia add */
int ipv6_packet_check(int threadid, int len, struct simple_ip6_hdr *ip6h)
{
if (len < (int)sizeof (struct ip6_hdr)
@@ -218,7 +203,6 @@ int ipv6_packet_check(int threadid, int len, struct simple_ip6_hdr *ip6h) return 1;
}
-/* to do: ������� */
static int ipv6_attack_detect(struct frag_ipq *ipv6_qp)
{
if(ipv6_qp->attack_flag != 0)
@@ -232,8 +216,6 @@ static int ipv6_attack_detect(struct frag_ipq *ipv6_qp) return IP_FRAG_IGNORE;
}
- // to do: ��������
-
return IP_FRAG_OK;
}
@@ -271,11 +253,6 @@ static unsigned int ipv6_frag_hash_index(void *hash_key) }
#endif
-/*
- return value:
- 0: keyֵ��ͬ
- -1:keyֵ��ͬ
-*/
int ipv6_frag_hash_cmp(void *hash_key1, void *hash_key2)
{
return memcmp(hash_key1, hash_key2, sizeof(struct ipv6_frag_key));
@@ -299,7 +276,7 @@ static struct frag_ipq *ipv6_frag_queue_find(struct streaminfo_private *pstream_ frag_ipq);
if(ret < 0){
- ipv6_frag_ipq_free_all(frag_ipq); /* 2015-12-01 lijia add, for memory leak */
+ ipv6_frag_ipq_free_all(frag_ipq);
return NULL;
}
}
@@ -322,7 +299,6 @@ static struct frag_ipq *ipv6_frag_queue_find(struct streaminfo_private *pstream_ }
#endif
-/* ��IPv4�����£�ͳ�Ƴ����ڴ�ռ�þ���ֵ */
static inline int ip6_buff_size(int tot_len)
{
return tot_len > 2048 ? (tot_len > 10240 ? 65576 : 10240) : 2048;
@@ -330,20 +306,18 @@ static inline int ip6_buff_size(int tot_len) #if (USE_MESA_STREAM_HASH==0)
-/* ���ݳ�ʱ���������ڴ� */
static void ipv6_frag_mem_clean_by_time(struct frag_manage *handle)
{
struct frag_ipq *tmp, *next;
int raw_mem_size = handle->total_mem;
tmp = handle->lru_head;
- while(tmp && (tmp->create_time + (time_t)IPV6_FRAG_TIMEOUT < g_CurrentTime)) /* timeout */
+ while(tmp && (tmp->create_time + (time_t)IPV6_FRAG_TIMEOUT < g_CurrentTime))
{
next = tmp->lru_next;
frag_ipq_kill(handle, tmp);
- /* ÿ��ֻ�ͷ�һ���������ڴ棬���ⳤʱ���ڴ˺������У���������������� */
if(raw_mem_size-handle->total_mem >= IPV6_FRAG_MEM_FREE_ONCE)
{
break;
@@ -354,7 +328,6 @@ static void ipv6_frag_mem_clean_by_time(struct frag_manage *handle) }
-/* ����ռ���ڴ����������ڴ� */
static void ipv6_frag_mem_clean_by_size(struct frag_manage *handle)
{
struct frag_ipq *tmp, *next;
@@ -367,7 +340,6 @@ static void ipv6_frag_mem_clean_by_size(struct frag_manage *handle) frag_ipq_kill(handle, tmp);
- /* ÿ��ֻ�ͷ�һ���������ڴ棬���ⳤʱ���ڴ˺������У���������������� */
if(raw_mem_size-handle->total_mem >= IPV6_FRAG_MEM_FREE_ONCE)
{
break;
@@ -378,7 +350,6 @@ static void ipv6_frag_mem_clean_by_size(struct frag_manage *handle) }
-/* �����ڴ棬��ʱ���ռ���ڴ����� */
static inline void ipv6_frag_mem_clean(struct frag_manage *handle)
{
ipv6_frag_mem_clean_by_time(handle);
@@ -412,16 +383,6 @@ static void *frag_reassemble_v6(struct frag_manage *handle, struct frag_ipq *ipq }
#endif
-/*
- IPv6��Ƭ�������.
- ����˵��:
- pfstream: �ײ�����ָ��.
- thread_num: �߳�ID
- frag_packet: ԭʼIPv6���ݰ�ͷָ��
- ipv6_frag_hdr: IPv6��Ƭͷ��ָ��
- last_hdr_offset: ��Ƭͷ��ǰһ����ͷ��next_hdr�ֶΣ����IPv6ԭʼ��ͷ��ƫ������
- �������֮��������Ƭͷ����Ҫ�ѷ�Ƭͷ��ǰһ����ͷ��next_hdrֵ��Ϊ��Ƭͷ֮���next_hdrֵ.
-*/
static struct mesa_ip6_hdr *ipv6_defrag(struct streaminfo_private *pstream_pr,
int thread_num, const struct mesa_ip6_hdr *frag_packet,
struct ipv6_frag_hdr *ipv6_frag_hdr, int last_hdr_offset, const raw_pkt_t *raw_pkt)
@@ -458,7 +419,6 @@ static struct mesa_ip6_hdr *ipv6_defrag(struct streaminfo_private *pstream_pr, return NULL;
}
- /* ������� */
attack_flag = ipv6_attack_detect(ipv6_qp);
switch(attack_flag)
{
@@ -474,7 +434,7 @@ static struct mesa_ip6_hdr *ipv6_defrag(struct streaminfo_private *pstream_pr, goto discard_fq;
break;
- default: /* go on */
+ default:
break;
}
@@ -484,7 +444,7 @@ static struct mesa_ip6_hdr *ipv6_defrag(struct streaminfo_private *pstream_pr, ipv6_qp->frags_num++;
- if(NULL == ipv6_qp->private_info) /* �յ��ĵ�һ����Ƭ�� */
+ if(NULL == ipv6_qp->private_info)
{
ipv6_qp->private_info = frag_malloc(ip6_frag_handle, sizeof(struct ipv6_frag_private));
ipv6_qp->private_len = sizeof(struct ipv6_frag_private);
@@ -496,7 +456,7 @@ static struct mesa_ip6_hdr *ipv6_defrag(struct streaminfo_private *pstream_pr, offset = ntohs(ipv6_frag_hdr->frag_off) & ~0x7;
end = offset + (ntohs(frag_packet->ip6_payload_len) -
- ((u_int8_t *)(ipv6_frag_hdr + 1) - (u_int8_t *)(frag_packet + 1)));/* lijia comment, ��Ƭͷǰ���п��ܻ���������ͷ��, */
+ ((u_int8_t *)(ipv6_frag_hdr + 1) - (u_int8_t *)(frag_packet + 1)));
if(offset >= end)
{
@@ -507,7 +467,7 @@ static struct mesa_ip6_hdr *ipv6_defrag(struct streaminfo_private *pstream_pr, goto err;
}
- if(!(ipv6_frag_hdr->frag_off & htons(IP6_MF))) /* ���һ����Ƭ�� */
+ if(!(ipv6_frag_hdr->frag_off & htons(IP6_MF)))
{
if (end < ipv6_qp->tot_len||
((ipv6_qp->last_in & IP_FRAG_LAST_IN) && end != ipv6_qp->tot_len))
@@ -519,11 +479,11 @@ static struct mesa_ip6_hdr *ipv6_defrag(struct streaminfo_private *pstream_pr, }
else
{
- if(end & 0x7) /* ����8�������� */
+ if(end & 0x7)
{
goto err;
}
- if(end > ipv6_qp->tot_len) /* ���� */
+ if(end > ipv6_qp->tot_len)
{
if(ipv6_qp->last_in & IP_FRAG_LAST_IN)
{
@@ -533,10 +493,6 @@ static struct mesa_ip6_hdr *ipv6_defrag(struct streaminfo_private *pstream_pr, }
}
- /* Find out which fragments are in front and at the back of us
- * in the chain of fragments so far. We must know where to put
- * this fragment.
- */
prev = ipv6_qp->fragments_tail;
if(!prev || prev->offset < offset)
{
@@ -544,23 +500,23 @@ static struct mesa_ip6_hdr *ipv6_defrag(struct streaminfo_private *pstream_pr, goto found;
}
-#if 0 /* search forward */
+#if 0
prev = NULL;
for(next = ipv6_qp->fragments; next != NULL; next = next->next)
{
if(next->offset >= offset)
{
- break; /* bingo! */
+ break;
}
prev = next;
}
-#else /* search backward, һ�������, offset��ֵ���Ǵ�С����ʱ�临�Ӷ�ΪO(1) */
+#else
next = NULL;
for(prev = ipv6_qp->fragments_tail; prev != NULL; prev = prev->prev)
{
if(prev->offset < offset)
{
- break; /* bingo! */
+ break;
}
next = prev;
}
@@ -568,25 +524,23 @@ static struct mesa_ip6_hdr *ipv6_defrag(struct streaminfo_private *pstream_pr, found:
- /* Check for overlap with preceding fragment. */
if(prev && (prev->end > offset))
{
goto discard_fq;
}
- /* Look for overlap with succeeding segment. */
if(next && (next->offset < end))
{
goto discard_fq;
}
- if(prev && (prev->end == offset)) /* �ϲ����ڷ�Ƭ��Ϣ�������½�frags�ṹ */
+ if(prev && (prev->end == offset))
{
prev->end = end;
goto copy_data;
}
- if(next && (next->offset == end)) /* �ϲ����ڷ�Ƭ��Ϣ�������½�frags�ṹ */
+ if(next && (next->offset == end))
{
next->offset = offset;
goto copy_data;
@@ -594,7 +548,6 @@ found: tmp_fg = frags_create(ip6_frag_handle, offset, end);
- /* Insert this fragment in the chain of fragments. */
tmp_fg->next = next;
tmp_fg->prev = prev;
if(next)
@@ -618,16 +571,15 @@ copy_data: ipv6_qp->meat += (end - offset);
- /* The first fragment. */
if(0 == offset)
{
- int this_pkt_unfragmentable_len = (char *)ipv6_frag_hdr - (char *)frag_packet; /* ��ǰ��ʵ�ʲ��ɷ�Ƭ��ͷ���� */
+ int this_pkt_unfragmentable_len = (char *)ipv6_frag_hdr - (char *)frag_packet;
ipv6_qp->last_in |= IP_FRAG_FIRST_IN;
- if(this_pkt_unfragmentable_len > private_info->unfragmentable_len){ /* ʵ��ͷ���ռ䳬��Ԥ���ռ� */
- if (end + this_pkt_unfragmentable_len > ipv6_qp->buf_size){ /* �Ƿ���Ҫ���仺��ռ� */
+ if(this_pkt_unfragmentable_len > private_info->unfragmentable_len){
+ if (end + this_pkt_unfragmentable_len > ipv6_qp->buf_size){
new_buf_size = ip6_buff_size(end + this_pkt_unfragmentable_len);
new_ip6h = (struct mesa_ip6_hdr *)frag_malloc(ip6_frag_handle, new_buf_size);
- if(ipv6_qp->meat > 0){ /* meat>0, ֮ǰ�Ѿ��洢������, ͨ�������Ƿ�Ƭ����, �����յ������ķ�Ƭ�� */
+ if(ipv6_qp->meat > 0){
memcpy((char *)new_ip6h + this_pkt_unfragmentable_len, (char *)ipv6_qp->new_iph + private_info->unfragmentable_len, ipv6_qp->buf_size);
}
frag_free(ip6_frag_handle, ipv6_qp->new_iph, ipv6_qp->buf_size);
@@ -636,11 +588,10 @@ copy_data: }
}
private_info->unfragmentable_len = this_pkt_unfragmentable_len;
- private_info->raw_next_hdr = ipv6_frag_hdr->nexthdr; /* ��¼��һ����Ƭ����һ��Э������ */
+ private_info->raw_next_hdr = ipv6_frag_hdr->nexthdr;
memcpy(ipv6_qp->new_iph, frag_packet, this_pkt_unfragmentable_len);
}
- /*If ipq buff is not enough to store current fragment piece, get a bigger one*/
if(end + private_info->unfragmentable_len > ipv6_qp->buf_size)
{
new_buf_size = ip6_buff_size(end + private_info->unfragmentable_len);
@@ -663,7 +614,7 @@ copy_data: ipv6_qp->ipfrag_list = NULL;
#endif
- int ip6_payload_len = htons(ipv6_qp->meat); /* ʵ�����ݳ���, ����ͷ�� */
+ int ip6_payload_len = htons(ipv6_qp->meat);
char raw_next_hdr = private_info->raw_next_hdr;
#if USE_MESA_STREAM_HASH
new_ip6h = (struct mesa_ip6_hdr *)frag_reassemble_v6(ip6_frag_handle, ipv6_qp, &ip6_frag_key);
@@ -671,7 +622,7 @@ copy_data: new_ip6h = (struct mesa_ip6_hdr *)frag_reassemble(ip6_frag_handle, ipv6_qp);
#endif
new_ip6h->ip6_payload_len = ip6_payload_len;
- *((char *)new_ip6h + last_hdr_offset) = raw_next_hdr; /* ����Ϊ��һ������nexthdr��Ϣ */
+ *((char *)new_ip6h + last_hdr_offset) = raw_next_hdr;
return new_ip6h;
}
@@ -713,7 +664,6 @@ static void set_ipv6_stream(struct streaminfo_private *pfstream_pr, struct strea ip6_addr->source = 0;
ip6_addr->dest = 0;
- /* LiJia add, ��Ϊ��ij���㷨���ⶨ��һ�������ַ�ķ���, �����ж�memcmp�Ľ�� */
if(memcmp(ip6_addr->saddr, ip6_addr->daddr, IPV6_ADDR_LEN) >= 0){
pstream_pr->layer_dir = 1;
pstream->curdir = DIR_C2S;
@@ -723,7 +673,6 @@ static void set_ipv6_stream(struct streaminfo_private *pfstream_pr, struct strea }
pstream->addr.ipv6 = ip6_addr;
- /* ��IP��������Ϊ__ADDR_TYPE_IP_PAIR_V4, ����ϲ���TCP/UDP, ����������ΪADDR_TYPE_IPV4, �����Ipv6_over_ipv4����, ������IP���ַ���� */
pstream->addr.addrtype = __ADDR_TYPE_IP_PAIR_V6;
pstream->addr.addrlen = sizeof(struct layer_addr_ipv6);
pstream_pr->addr_use_as_hash = 1;
@@ -731,10 +680,10 @@ static void set_ipv6_stream(struct streaminfo_private *pfstream_pr, struct strea //ptmp->stream.p_layer_header = ip6hdr;
// ptmp->stream.offset_to_raw_pkt_hdr = (char *)ip6hdr - (char *)raw_pkt->raw_pkt_data;
pstream_pr->offset_to_raw_pkt_hdr = offset_to_raw_pkt_hdr;
- pstream_pr->raw_pkt = raw_pkt; /* 2014-12-30 lijia add */
+ pstream_pr->raw_pkt = raw_pkt;
if((pfstream_pr != NULL)
- && (g_overlay_layer_set[pfstream_pr->stream_public.addr.addrtype][pfstream_pr->layer_index] != 0)){ /* 2021-01-11 lijia add, overlay���pfather��ΪNULL, ������ɼ� */
+ && (g_overlay_layer_set[pfstream_pr->stream_public.addr.addrtype][pfstream_pr->layer_index] != 0)){
pstream->pfather = NULL;
}else{
pstream->pfather=&pfstream_pr->stream_public;
@@ -752,14 +701,6 @@ static void set_ipv6_stream(struct streaminfo_private *pfstream_pr, struct strea }
-/*
- IPv6���ݰ��������.
- ����˵��:
- pfstream: �ײ�����ָ��.
- a_packet: ԭʼIPv6���ݰ�ͷָ��
- thread_num: �߳�ID
- routedir: �ײ���Ĵ��䷽��
-*/
int ipv6_entry(struct streaminfo_private *pfstream_pr, const void *this_layer_hdr, int thread_num,
unsigned char routedir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr)
{
@@ -793,7 +734,6 @@ if(likely(pfstream_pr != NULL && pfstream_pr->layer_index < SAPP_SUPPORT_LAYER_N return PASS;
}
- /* NOTE: �������·���Ī�������IP��, ��������ѭ��, һ��Ҫ��ͷ���Ϸ��Լ��!! */
if(unlikely(checkipv6pkt(a_packet, (int)payload_len, raw_pkt->raw_pkt_len) < 0)){
local_sys_stat->count[SAPP_STAT_DROP_IPV6]++;
local_sys_stat->length[SAPP_STAT_DROP_IPV6]+=raw_pkt->raw_pkt_len;
@@ -811,7 +751,6 @@ if(likely(pfstream_pr != NULL && pfstream_pr->layer_index < SAPP_SUPPORT_LAYER_N }
if((sapp_global_mthread[thread_num].ipv6_pkt_type_flag & PKT_TYPE_IPREBUILD) == 0){
- /* IP��Ƭ����İ�������ipv6_entry, �����ټ��� */
local_sys_stat->count[SAPP_STAT_RCV_IPV6]++;
local_sys_stat->length[SAPP_STAT_RCV_IPV6]+=payload_len + sizeof(struct mesa_ip6_hdr);
if (routedir == sapp_global_val->config.packet_io.inbound_route_dir)
@@ -828,9 +767,8 @@ if(likely(pfstream_pr != NULL && pfstream_pr->layer_index < SAPP_SUPPORT_LAYER_N set_ipv6_stream(pfstream_pr, &tmp_index, &ip6_addr, a_packet, routedir, thread_num, raw_pkt, offset_to_raw_pkt_hdr);
- plocal_stream->addr.pkttype = sapp_global_mthread[thread_num].ipv6_pkt_type_flag;/* 2014-12-25 lijia add */
+ plocal_stream->addr.pkttype = sapp_global_mthread[thread_num].ipv6_pkt_type_flag;
- /* 2015-02-03 lijia add */
if(PKT_TYPE_NORMAL == plocal_stream->addr.pkttype){
stream_process_ipv6_frag(plocal_stream, (const struct ip6_hdr *)this_layer_hdr,
thread_num, routedir, raw_pkt);
@@ -875,7 +813,6 @@ if(likely(pfstream_pr != NULL && pfstream_pr->layer_index < SAPP_SUPPORT_LAYER_N {
goto done;
}
- /* 2015-02-03 lijia add */
plocal_stream->addr.pktipfragtype = PKT_TYPE_IP_FRAG;
stream_process_ipv6_frag(plocal_stream, (const struct ip6_hdr *)this_layer_hdr,
thread_num, routedir, raw_pkt);
@@ -883,18 +820,16 @@ if(likely(pfstream_pr != NULL && pfstream_pr->layer_index < SAPP_SUPPORT_LAYER_N (struct ipv6_frag_hdr *)next_hdr_ptr, last_hdr-(uchar *)a_packet, raw_pkt);
if(new_ip6h)
{
- //assert(new_ip6h->ip6_nxt_hdr != NEXTHDR_FRAGMENT); /* ǿ��У��, ��Ƭ����İ����������Ƿ�Ƭ, ����ѭ����!! */
+ //assert(new_ip6h->ip6_nxt_hdr != NEXTHDR_FRAGMENT);
if(new_ip6h->ip6_nxt_hdr == NEXTHDR_FRAGMENT)
{
need_free=1;
goto done;
}
- /* ��������IP��ַ��Ϣ */
set_ipv6_stream(pfstream_pr, &(tmp_index), &ip6_addr, new_ip6h, routedir, thread_num, raw_pkt, skip_len+offset_to_raw_pkt_hdr);
- /* �ݹ��������һ��,����IPv6����չͷ��,�����ϲ㴦��ģ�� */
sapp_global_mthread[thread_num].ipv6_pkt_type_flag = PKT_TYPE_IPREBUILD;
action = ipv6_entry(pfstream_pr, (const void *)new_ip6h, thread_num, routedir, raw_pkt,
- skip_len+offset_to_raw_pkt_hdr); /* ��Ƭ����İ��ݹ��������, �������sizeof(struct mesa_ip6_hdr)ͷ */
+ skip_len+offset_to_raw_pkt_hdr);
need_free = 1;
sapp_global_mthread[thread_num].ipv6_pkt_type_flag = PKT_TYPE_NORMAL;
IPV6_PRINT("ipv6_frag_reassemble_num: %u\n", ipv6_frag_reassemble_num++);
@@ -909,7 +844,7 @@ if(likely(pfstream_pr != NULL && pfstream_pr->layer_index < SAPP_SUPPORT_LAYER_N case NEXTHDR_AUTH:
case NEXTHDR_DEST:
//skip_len = *(next_hdr_ptr + 1) + 1;
- skip_len = (*(next_hdr_ptr + 1))*8 + 8; /* ѡ�����8�ֽ�Ϊ��λ */
+ skip_len = (*(next_hdr_ptr + 1))*8 + 8;
break;
case NEXTHDR_NONE:
@@ -938,7 +873,6 @@ if(likely(pfstream_pr != NULL && pfstream_pr->layer_index < SAPP_SUPPORT_LAYER_N if(ret==DROP){
goto prosecc_pkt_drop;
}
- /* 2014-12-10 lijia add */
((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = sizeof(struct mesa_ip6_hdr)+skip_len+offset_to_raw_pkt_hdr;
ret = ipv4_entry(&(tmp_index.stream), (const void *)next_hdr_ptr, thread_num,
routedir, raw_pkt, sizeof(struct mesa_ip6_hdr)+skip_len+offset_to_raw_pkt_hdr);
@@ -1058,8 +992,8 @@ MESA_htable_handle ipv6_frag_htable_create(void) hargs.key2index = ipv6_frag_hash_index;
hargs.data_free = ipv6_frag_ipq_free_all;
hargs.data_expire_with_condition = NULL;
- hargs.complex_key_dup = ipv6_frag_key_dup; /* ���ڸ��ӽṹ��key����, ��copyһ����ַ���� */
- hargs.complex_key_free = ipv6_frag_key_free; /* ɾ��ʱ�ͷ�key���ڴ���Դ */
+ hargs.complex_key_dup = ipv6_frag_key_dup;
+ hargs.complex_key_free = ipv6_frag_key_free;
return MESA_htable_create(&hargs, sizeof(MESA_htable_create_args_t));
}
@@ -1114,5 +1048,4 @@ void ipv6_frag_exit(void) #ifdef __cplusplus
}
-#endif
-
+#endif
\ No newline at end of file diff --git a/src/dealpkt/deal_udp.c b/src/dealpkt/deal_udp.c index 5a3a3e5..917d420 100644 --- a/src/dealpkt/deal_udp.c +++ b/src/dealpkt/deal_udp.c @@ -1,8 +1,3 @@ -/* -20120603 : - -20130530 :����ǿ��udp����̭���ܣ� -*/ #include "sapp_api.h" #include "sapp_pkt_stat.h" #include "sapp_private_api.h" @@ -131,7 +126,6 @@ static void udp_change_stream_state(struct streamindex *pindex, struct mesa_udp_ } #if SAPP_INSECTICIDE -/* 2017-02-09 ��ʱ���Ӵ���, ���߷���Ī������BUG, ���ж�stream->pfatherָ���ҵ�BUG, Ҳ��֪���İ�pfatherд���� */ void iterate_stream_list(const struct streaminfo *stream) { char tmp_buf[8]; @@ -190,15 +184,14 @@ static struct streamindex *udp_add_new_stream(struct streamindex *pindex, iterate_stream_list(pstream_udp); #endif - /* 2016-07-25 lijia add, ��¼��ǰ����ײ���������, ÿ����ֻ�ڴ���ʱ��һ�μ��� */ get_stream_carry_tunnel_type(pstream_udp, NULL, &pstream_udp_pr->stream_low_layer_tunnel_type); if(1 == pstream_udp_pr->layer_dir){ - pstream_udp_pr->stream_dir = 1; /* ��ΪUDP�ǰ�DATA������, ����stream_dir�϶���Ĭ�Ϲ�����ͬ */ + pstream_udp_pr->stream_dir = 1; //((struct streaminfo_private *)(pstream_udp->pfather))->stream_dir = ((struct streaminfo_private *)(pstream_udp->pfather))->layer_dir; //set_stream_addr(pstream_udp, this_udphdr->uh_sport, this_udphdr->uh_dport); }else{ - pstream_udp_pr->stream_dir = 1; /* ��Ϊ��UDP��DATA������, ����stream_dir�϶���Ĭ�Ϲ�����ͬ */ + pstream_udp_pr->stream_dir = 1; //((struct streaminfo_private *)(pstream_udp->pfather))->stream_dir =((struct streaminfo_private *)(pstream_udp->pfather))->layer_dir ^ 1; //set_stream_addr(pstream_udp, this_udphdr->uh_dport, this_udphdr->uh_sport); } @@ -227,18 +220,15 @@ static struct streamindex *udp_add_new_stream(struct streamindex *pindex, pdetail->lastmtime=g_CurrentTime; if(pstream_udp_pr->under_ddos_bypass){ - /* bypass״̬�������κβ��, ������project, bridge,��ʼ��half_stream�Ȳ��������Ժ����� */ sapp_global_val->mthread_volatile[threadnum]->sys_stat.count[SAPP_STAT_UDP_BYPASS_STREAM]++; cycle_pkt_dump_by_classify(threadnum, raw_pkt, PKT_CLASSIFY_BYPASS); sapp_runtime_log(RLOG_LV_INFO, "UDP stream:%s under ddos bypass!", printaddr(&pstream_udp->addr, threadnum)); return pindex_udp; } - /* 2014-03-26 LiJia add, ijЩ��Ŀ����Ӧ�ó�ʼ��, ���ǩ��ԭʼIP��Ƭ�б��� */ pstream_udp_pr->pproject = project_requirement_create(SAPP_MEM_DYN_UDP_PROJECT, threadnum); pstream_udp_pr->stream_bridge = stream_bridge_create_per_stream(SAPP_MEM_DYN_UDP_BRIDGE,threadnum); - /* 2016-07-14 lijia add */ if(G_UDP_FLOW_STAT_PROJECT_ID != -1){ pdetail_pr->flow_stat = (struct udp_flow_stat *)sapp_mem_malloc(SAPP_MEM_DYN_UDP_FLOW_STAT,pstream_udp->threadnum, sizeof(struct udp_flow_stat)); memset(pdetail_pr->flow_stat, 0, sizeof(struct udp_flow_stat)); @@ -315,12 +305,11 @@ void udp_free_stream(struct streamindex *pindex) ((raw_pkt_t *)pstream_pr->raw_pkt)->prepend_list=NULL; } - pstream_pr->raw_pkt = NULL; /* 2015-02-04 lijia add, ������˵��ö�����MESA_kill_xxx */ + pstream_pr->raw_pkt = NULL; if(pdetail_pr->apme!=NULL) { pstream->opstate=OP_STATE_CLOSE; - //udp stream �ص� pstream->pktstate=OP_STATE_CLOSE; // add by lijia 20141202 stream_process_udp(pstream,NULL,NULL,NULL,&(pdetail_pr->apme),&(pstream->opstate)); udp_cleardata(pstream); @@ -352,7 +341,7 @@ void udp_free_stream(struct streamindex *pindex) pstream->pdetail=NULL; - if(pstream_pr->set_special_timeout != 0){ /* ���Ӷ��г�ʱʱ��, ���ټ��� */ + if(pstream_pr->set_special_timeout != 0){ sapp_global_mthread[threadnum].udp_stream_special_timeout_num--; } @@ -378,8 +367,6 @@ void udp_free_stream(struct streamindex *pindex) } //add by lqy 20130530 -// �����趨��ʱ��ǿ����̭���õ���Ԫ����Ϣ -// return 1 ���������ã�0 δ�������� static int udp_reset_stream(struct streamindex *pindex) { struct stream_list *plist; @@ -396,7 +383,6 @@ static int udp_reset_stream(struct streamindex *pindex) threadnum = pstream->threadnum; sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[threadnum]->sys_stat; - // ������ǰ�ĵ�����Ϣ plist = &(G_MESA_GLOBAL_STREAM[threadnum]->udpList[pstream->stream_state]); streamleavlist(pindex, plist); // pstream->stream.opstate=OP_STATE_CLOSE; @@ -437,7 +423,6 @@ static int udp_reset_stream(struct streamindex *pindex) pstream_pr->pproject = project_requirement_create(SAPP_MEM_DYN_UDP_PROJECT, threadnum); pstream_pr->stream_bridge = stream_bridge_create_per_stream(SAPP_MEM_DYN_UDP_BRIDGE, threadnum); - /* 2015-12-28 lijia add, ������, ���������ڴ� */ if (G_UDP_FLOW_STAT_PROJECT_ID != -1) { pdetail_pr->flow_stat = (struct udp_flow_stat *)sapp_mem_malloc(SAPP_MEM_DYN_UDP_FLOW_STAT, threadnum, sizeof(struct udp_flow_stat)); @@ -445,7 +430,6 @@ static int udp_reset_stream(struct streamindex *pindex) project_req_add_struct(pstream, G_UDP_FLOW_STAT_PROJECT_ID, pdetail_pr->flow_stat); } - // ��������״̬ memset(pdetail, 0, sizeof(struct udpdetail)); // pstream->stream.opstate=OP_STATE_PENDING; pstream->opstate = OP_STATE_PENDING; @@ -488,12 +472,10 @@ static int dealipv4udppkt_dup_check(int tid, struct streaminfo_private *pstream_ int is_dup_pkt = 0; int dup_check_enabled = 0; - /* vxlan��ı�����Ϣ����ʶ���ظ���, ��Ϊʵ��ijЩinline device���巢���ı����ȫ��һ����, udp checksum��0, ipidҲ���� */ if(is_overlay_udp_layer){ return 0; } - /* ����Э������UDP��ʶ���ظ����� */ if(STREAM_TUNNLE_NON != pstream_pr->stream_carry_up_layer_tunnel_type){ return 0; } @@ -502,7 +484,6 @@ static int dealipv4udppkt_dup_check(int tid, struct streaminfo_private *pstream_ if(dup_pkt_para->dup_pkt_distinguish_ipv4_udp || dup_pkt_para->dup_pkt_distinguish_all_inject) { - // ����ԭʼ�����, ֻ�ж�ǰN����, ���û�����ظ�����, ����Ϊ�Ժ�Ķ������ظ���! if((0 == pstream_pr->has_duplicate_pkt) && (pdetail_pr->udpdetail_public.clientpktnum+pdetail_pr->udpdetail_public.serverpktnum >= dup_pkt_para->first_packets)){ dup_check_enabled = 0; @@ -533,7 +514,7 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ struct udpdetail_private *pdetail_pr=NULL; struct streaminfo_private *pstream_pr=&(pindex->stream); struct streaminfo *pstream=&(pstream_pr->stream_public); - struct streaminfo_private *stack_stream_pr = &(pindex->stream); /* 2016-11-24 lijia add, �����l2tp, teredo����, ʹ��ջ���ָ�� */ + struct streaminfo_private *stack_stream_pr = &(pindex->stream); int next_layer_offset; void *tmpme=NULL; int hlen=0; @@ -549,12 +530,11 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ udph = (struct mesa_udp_hdr *) ((char*)this_iphdr +hlen ); ulen = ntohs (udph->uh_ulen); - local_sys_stat->count_per_layer[ADDR_TYPE_UDP][pstream_pr->layer_index]++; /* udp��ip����һ�� */ - local_sys_stat->length_per_layer[ADDR_TYPE_UDP][pstream_pr->layer_index] += ulen; /* udp��ip����һ�� */ + local_sys_stat->count_per_layer[ADDR_TYPE_UDP][pstream_pr->layer_index]++; + local_sys_stat->length_per_layer[ADDR_TYPE_UDP][pstream_pr->layer_index] += ulen; if(raw_pkt->is_ctrl_pkt==0) { - /* 2015-12-29 lijia modify, ijЩUDP��û�и�������, û������, ֱ�Ӷ��� */ if(unlikely(iplen - hlen < ulen || ulen <= (int)sizeof (struct mesa_udp_hdr))){ return PASS; } @@ -570,7 +550,7 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ } pstream_pr->offset_to_ip_hdr = (char *)udph - (char *)this_iphdr; - pstream_pr->raw_pkt = raw_pkt; /* 2014-12-30 lijia add */ + pstream_pr->raw_pkt = raw_pkt; //set_stream_addr(pfstream, udph->uh_sport, udph->uh_dport, &ptmp->stream.addr); //pstream->pfather=&pfstream->stream_public; pstream->type=STREAM_TYPE_UDP; @@ -579,7 +559,7 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ is_overlay_udp_layer = sapp_is_overlay_layer(pstream_pr, raw_pkt); - if(0 == is_overlay_udp_layer){ /* ��overlay����ۼ���ز���� */ + if(0 == is_overlay_udp_layer){ local_sys_stat->count[SAPP_STAT_RCV_UDP]++; local_sys_stat->length[SAPP_STAT_RCV_UDP]+=datalen; if (routedir == sapp_global_val->config.packet_io.inbound_route_dir) @@ -604,7 +584,6 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ if(sapp_global_val->config.protocol_feature.skip_gtp_layer==1)return gtp_entry(stack_stream_pr, udph, thread_num, routedir, raw_pkt, next_layer_offset); } //add by lqy 20130530 - // udp�в���������ԭ�Ĺ�������ֱ�Ӱ������������� if(unlikely(0 ==udp_stream_table_size)) { struct udpdetail_private detail_pr; @@ -612,7 +591,6 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ pdetail = (struct udpdetail *)&detail_pr; pstream_pr->offset_to_ip_hdr = (char *)udph - (char *)this_iphdr; - /* ������, �ٶ�Դ�˿ڴ��ΪClient */ //if(memcmp(&udph->uh_sport, &udph->uh_dport, sizeof(short)) >= 0){ if(ntohs(udph->uh_sport) >= ntohs(udph->uh_dport)){ pstream->curdir=DIR_C2S; @@ -676,7 +654,6 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ return PASS; } } - // add by lqy ֻ�е�����δ����ʱ����lru else { if (lrustream(a_index) == 1) @@ -685,10 +662,9 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ } } - /* NOTE: ����pstreamָ��, ָ����д洢���ڴ� */ pstream_pr=&(a_index->stream); pstream=&(pstream_pr->stream_public); - //pstream->addr.pktipfragtype = pstream->stream_public.addr.pktipfragtype; /* 2015-11-04 lijia add, IP��Ƭ������ */ + //pstream->addr.pktipfragtype = pstream->stream_public.addr.pktipfragtype; pdetail_pr=(struct udpdetail_private *)(pstream->pdetail); pstream->pudpdetail->lastmtime=(long)g_CurrentTime; @@ -708,16 +684,14 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ return PASS; } - /* 2014-11-15 lijia add, for udp serial kill udp */ if(unlikely(a_index->stream.stream_killed_flag != 0 && raw_pkt->is_ctrl_pkt==0)){ return DROP; } - if(unlikely(pdetail_pr->drop_stream_flag != 0) && raw_pkt->is_ctrl_pkt==0 ){ /* 2020-06-02 lijia add */ + if(unlikely(pdetail_pr->drop_stream_flag != 0) && raw_pkt->is_ctrl_pkt==0 ){ return DROP; } - // ����kill remedy��drop stream���ظ�������sappֱ�Ӵ��������������ϵ�sid,����ת����service chain����������SF������ if (pstream_pr->sid_append_list != NULL) { ((raw_pkt_t *)raw_pkt)->append_list = pstream_pr->sid_append_list; @@ -734,11 +708,11 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ if(pstream->curdir==DIR_S2C){ - if(pdetail_pr->udpdetail_public.clientpktnum == 0){ /* ��ǰ����ĵ�һ����, ���Ը��µײ������ĵ����ַ��Ϣ(��MPLS, GTP) */ + if(pdetail_pr->udpdetail_public.clientpktnum == 0){ try_to_update_addr_info = 1; } }else{ - if(pdetail_pr->udpdetail_public.serverpktnum == 0){ /* ��ǰ����ĵ�һ����, ���Ը��µײ������ĵ����ַ��Ϣ(��MPLS, GTP) */ + if(pdetail_pr->udpdetail_public.serverpktnum == 0){ try_to_update_addr_info = 1; } } @@ -752,9 +726,8 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ udp_change_stream_state(a_index,udph, raw_pkt, offset_to_raw_pkt_hdr); pstream_pr->packet_process_context=0; pstream_pr->offset_to_ip_hdr = (char *)udph - (char *)this_iphdr; - pstream_pr->raw_pkt = raw_pkt; /* 2014-12-30 lijia add */ + pstream_pr->raw_pkt = raw_pkt; - /* update ip ttl */ if(unlikely(0 == pstream_pr->ip_ttl_c2s) && (DIR_C2S == pstream->curdir)) { pstream_pr->ip_ttl_c2s = this_iphdr->ip_ttl; } @@ -776,12 +749,10 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ ret = vxlan_entry(stack_stream_pr, (char *)udph+sizeof(struct mesa_udp_hdr), thread_num, routedir, raw_pkt, next_layer_offset); udp_cleardata(pstream); pstream_pr->packet_process_context=0; - /* overlay UDP�㲻�ټ���������������� */ return ret; } else { - /* 2022-04-13 liuxueli add, for udp offload stream */ if(pdetail_pr->offload_stream_flag==SMART_OFFLOAD_FLAG_UDP && pstream_pr->stream_carry_up_layer_tunnel_type==STREAM_TUNNLE_NON && DROP!=ret @@ -807,7 +778,7 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ } } - if(unlikely(DROP == ret)){ /* �������DROP���ٽ��к������� */ + if(unlikely(DROP == ret)){ return DROP; } pstream_pr->packet_process_context=1; @@ -858,8 +829,8 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe iplen = ntohs (a_packet->ip6_payload_len); ulen = ntohs (udph->uh_ulen); - local_sys_stat->count_per_layer[ADDR_TYPE_UDP][pstream_pr->layer_index]++; /* udp��ip����һ�� */ - local_sys_stat->length_per_layer[ADDR_TYPE_UDP][pstream_pr->layer_index] += ulen; /* udp��ip����һ�� */ + local_sys_stat->count_per_layer[ADDR_TYPE_UDP][pstream_pr->layer_index]++; + local_sys_stat->length_per_layer[ADDR_TYPE_UDP][pstream_pr->layer_index] += ulen; if(unlikely(iplen < ulen || ulen <= (int)sizeof (struct mesa_udp_hdr))){ return PASS; @@ -881,13 +852,12 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe pstream->addr.addrlen=sizeof(struct layer_addr_udp); pstream_pr->addr_use_as_hash = 0; //ptmp->stream.p_layer_header = udph; -/* IP, UDP��ϲ���, ���ٸ���UDP���offset_to_raw_pkt_hdr */ #if 0 pstream_pr->offset_to_raw_pkt_hdr = offset_to_raw_pkt_hdr; #endif pstream_pr->offset_to_ip_hdr = (char *)udph - (char *)a_packet; - pstream_pr->raw_pkt = raw_pkt; /* 2014-12-30 lijia add */ + pstream_pr->raw_pkt = raw_pkt; //pstream->pfather=pfstream; pstream->type=STREAM_TYPE_UDP; @@ -905,11 +875,9 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe if(sapp_global_val->config.protocol_feature.skip_gtp_layer==1)return gtp_entry(pstream_pr, udph, thread_num, routedir, raw_pkt, next_layer_offset); } //add by lqy 20130530 - // udp�в���������ԭ�Ĺ�������ֱ�Ӱ������������� if(unlikely(0 == udp_stream_table_size)) { - /* ������, �ٶ�Դ�˿ڴ��ΪClient */ if(memcmp(&udph->uh_sport, &udph->uh_dport, sizeof(short)) >= 0){ pstream->curdir=DIR_C2S; pstream_pr->layer_dir = 1; @@ -969,7 +937,6 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe } } - /* NOTE: ����pstreamָ��, ָ����д洢���ڴ� */ pstream_pr=&(a_index->stream); pstream=&(pstream_pr->stream_public); pdetail_pr=(struct udpdetail_private *)(pstream->pdetail); @@ -983,18 +950,6 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe return PASS; } - /* - 2021-05-18 lijia close ipv6 original dup pkt check: - IPv6��Ϊû��Ipid�ֶ�, ������������Ӧ�ò��ش����ظ�����, �����˻ᵼ�¶�������CT, ���Բ�֧��ԭʼ����ʶ��! - - ����IPv6���������: - 1)��������˴�������, �ش�����ʶ������ظ����Ļ�, sapp��ֱ��PASS��, ʵ���Ǹ�������ʵͨ��˫������, û�о���tfe����, ���ܾͶ�����. - 2)���������firewall��drop����, ��һ��drop�ɹ���, ��Ӧ�ò���ش�, �ش�����ʶ������ظ����Ļ�, sapp��ֱ��PASS��, ����CT. - - ����, Ҫ֧��ע������ʶ��!! - - 24.04: ����IPv6��˵, ��Ϊ��֧��ԭʼ�����ظ����, ����ע���ʶ��Ҳ��֧�ֿ���·��. -*/ if((sapp_global_val->config.packet_io.dup_pkt_para.dup_pkt_distinguish_all_inject != 0) && (sapp_dup_pkt_identify(thread_num, pstream_pr, a_packet, udph, 0) != 0)){ local_sys_stat->count[SAPP_STAT_RCV_DUP_UDP]++; @@ -1016,21 +971,20 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe ((raw_pkt_t *)raw_pkt)->stream_trace_id = pstream_pr->stream_trace_id; } - /* 2014-11-15 lijia add, for udp serial kill udp */ if(unlikely(a_index->stream.stream_killed_flag != 0) && raw_pkt->is_ctrl_pkt==0){ return DROP; } - if(unlikely(pdetail_pr->drop_stream_flag != 0) && raw_pkt->is_ctrl_pkt==0){ /* 2020-06-02 lijia add */ + if(unlikely(pdetail_pr->drop_stream_flag != 0) && raw_pkt->is_ctrl_pkt==0){ return DROP; } if(pstream->curdir==DIR_S2C){ - if(pdetail_pr->udpdetail_public.clientpktnum == 0){ /* ��ǰ����ĵ�һ����, ���Ը��µײ������ĵ����ַ��Ϣ(��MPLS, GTP) */ + if(pdetail_pr->udpdetail_public.clientpktnum == 0){ try_to_update_addr_info = 1; } }else{ - if(pdetail_pr->udpdetail_public.serverpktnum == 0){ /* ��ǰ����ĵ�һ����, ���Ը��µײ������ĵ����ַ��Ϣ(��MPLS, GTP) */ + if(pdetail_pr->udpdetail_public.serverpktnum == 0){ try_to_update_addr_info = 1; } } @@ -1041,18 +995,15 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe pstream_pr->packet_process_context=1; udp_change_stream_state(a_index,udph, raw_pkt, offset_to_raw_pkt_hdr); pstream_pr->packet_process_context=0; - /* ����pstreamָ�� */ pstream_pr=&(a_index->stream); pstream=&(pstream_pr->stream_public); update_polling_inject_context(SAPP_MEM_DYN_UDP_POLLING_RAW_PKT, pstream_pr, raw_pkt); -/* IP, UDP��ϲ���, ���ٸ���UDP���offset_to_raw_pkt_hdr */ #if 0 pstream_pr->offset_to_raw_pkt_hdr = offset_to_raw_pkt_hdr; #endif - /* 2022-04-13 liuxueli add, for udp offload stream */ if(pdetail_pr->offload_stream_flag==SMART_OFFLOAD_FLAG_UDP && pstream_pr->stream_carry_up_layer_tunnel_type==STREAM_TUNNLE_NON && DROP!=ret @@ -1066,7 +1017,6 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe return PASS; } - /* update ip ttl */ if(unlikely(0 == pstream_pr->ip_ttl_c2s) && (DIR_C2S == pstream->curdir)) { pstream_pr->ip_ttl_c2s = a_packet->ip6_hop; } @@ -1075,25 +1025,12 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe } pstream_pr->offset_to_ip_hdr = (char *)udph - (char *)a_packet; - pstream_pr->raw_pkt = raw_pkt; /* 2014-12-30 lijia add */ + pstream_pr->raw_pkt = raw_pkt; pdetail_pr=(struct udpdetail_private *)(pstream->pdetail); ret=stream_process_udp(pstream,(const void *)a_packet, (const void *)udph, raw_pkt,&(pdetail_pr->apme),&(pstream->opstate)); udp_cleardata(pstream); } -/* - if(pdetail_pr!=NULL - &&pdetail_pr->offload_stream_flag==SMART_OFFLOAD_FLAG_UDP - && pstream_pr->stream_carry_up_layer_tunnel_type==STREAM_TUNNLE_NON - && DROP!=ret - && (g_CurrentTime > pdetail_pr->offload_stream_timestamp_s)) - { - local_sys_stat->count[SAPP_STAT_UDP_OFFLOAD_STREAM]++; - MESA_send_smart_offload(pstream, (const void *)raw_pkt, pstream->threadnum); - pdetail_pr->offload_stream_timestamp_s = g_CurrentTime; - return PASS; - } -*/ pstream_pr->packet_process_context=1; if(pstream_pr->stream_carry_up_layer_tunnel_type & STREAM_TUNNLE_L2TP){ ret = l2tpv2_entry(pstream_pr, udph, thread_num, routedir, raw_pkt, next_layer_offset); @@ -1106,7 +1043,6 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe ret = gtp_entry(pstream_pr, udph, thread_num, routedir, raw_pkt, next_layer_offset); } - /* TODO 2, ����IPv6��UDP port 1701 L2TPЭ�� */ pstream_pr->packet_process_context=0; if(DROP == ret){ sapp_runtime_log(RLOG_LV_DEBUG, "UDP stream: %s, curdir:%d, return DROP.", printaddr(&pstream->addr, pstream->threadnum), pstream->curdir); @@ -1115,7 +1051,6 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe return ret; } -/* lijia comment: a_packet��������ʵԭʼ��, Ҳ������malloc��IP�����, ��addr.pkttype���� */ int process_ipv4_pkt (struct streamindex *pfindex,const struct mesa_ip4_hdr * a_packet,int thread_num, unsigned char routedir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr) { @@ -1179,7 +1114,7 @@ int process_ipv4_pkt (struct streamindex *pfindex,const struct mesa_ip4_hdr * a_ break; case IPPROTO_ICMP: -#if 0 /* 2017-05-19 lijia modify, GDEV����ת��g_device_plug�����ʵ��, ƽ̨�ڲ����ٴ��� */ +#if 0 ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offest; ret = icmp_entry(pfstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offest); #endif @@ -1206,7 +1141,6 @@ int process_ipv4_pkt (struct streamindex *pfindex,const struct mesa_ip4_hdr * a_ break; default: - /* unknown protocol */ local_sys_stat->count[SAPP_STAT_RCV_UNKNOWN]++; local_sys_stat->length[SAPP_STAT_RCV_UNKNOWN]+= raw_pkt->raw_pkt_len; ((raw_pkt_t *)raw_pkt)->diagnose_error_to_dump = 1; @@ -1230,7 +1164,7 @@ char udp_teredo_identify_entry(const struct streaminfo *pstream, const void *thi pstream_pr->stream_carry_up_layer_tunnel_type |= STREAM_TUNNLE_TEREDO; } - return APP_STATE_DROPME; /* ÿ����ֻ����һ����, �����Ƿ�teredo����, ���������ٴ����� */ + return APP_STATE_DROPME; } diff --git a/src/dealpkt/stream_manage.c b/src/dealpkt/stream_manage.c index 9029652..9041dad 100644 --- a/src/dealpkt/stream_manage.c +++ b/src/dealpkt/stream_manage.c @@ -1,30 +1,4 @@ -/* -********************************************* -1. 20130803 ������ -1) ԭ����������hash����������Ĺ���ͬһkeyֵ�ϣ� - ��Ϊ������Ԫ��Ĵ�С��������hash����ͬһ�������ϣ� -2) ͨ���� findandsethashindex ����ʱԤ��Ҫ������������������ٲ���ʱ�����²�� - - -2 . adjust by lqy 20130917 streamaddlist -1) ��������̭֮����Ҫ���¼���Ҫ�����λ�� -2) ÿ����̭��������ĿΪ��������Ŀ��2% - -3 . adjust by lqy 20140810 -1) ������̭ʱ�������100�� - -4. adjust by lqy 20141203 -1)lruʱ����������һ���Ƿ�ʱ����ʱ������̭ - -5.adjust by lqy 20141212 -1)Ϊÿ��������ȫ��Ψһ����stream_index ����ͨ��������� -2)�Ƿ�֧��ȫ���ӿ��ɿ����趨 -3)ÿ�����Ӿ�����lru -4) fix hash��ͻʱ������������� -*/ -#include "sapp_api.h" -#include "sapp_private_api.h" #include "sapp_declaration.h" #include "stream_inc/stream_base.h" #include "stream_manage.h" @@ -37,9 +11,6 @@ extern "C" { int sapp_version_v4_20191119; -/* - ����İ汾������packet_io_libУ��, ��ֹƽ̨��dl.so��ƥ�䵼�������쳣, ��������BUGδ����. -*/ #if IOMODE_PCAP int sapp_packet_io_v = 20210907; #elif IOMODE_PAG @@ -128,12 +99,10 @@ static int init_stream_detail(struct global_stream *g_stream) g_stream->udpList[i].timeout_ratelimiter = g_stream->udp_timeout_ratelimiter; } - //Ԥ�ȷ���hashָ�� g_stream->tcp_stream_table = (struct streamindex **)sapp_mem_malloc(SAPP_MEM_FIX_GLOBAL_STREAM, -1, tcp_stream_table_size * sizeof(char *)); memset(g_stream->tcp_stream_table, 0, tcp_stream_table_size * sizeof(char *)); g_stream->udp_stream_table = (struct streamindex **)sapp_mem_malloc(SAPP_MEM_FIX_GLOBAL_STREAM, -1, udp_stream_table_size * sizeof(char *)); memset(g_stream->udp_stream_table, 0, udp_stream_table_size * sizeof(char *)); - //��¼hash��״̬ g_stream->tcp_stream_talbe_hash_count = (unsigned short *)sapp_mem_malloc(SAPP_MEM_FIX_GLOBAL_STREAM, -1, tcp_stream_table_size * sizeof(short)); memset(g_stream->tcp_stream_talbe_hash_count, 0, tcp_stream_table_size * sizeof(short)); g_stream->udp_stream_talbe_hash_count = (unsigned short *)sapp_mem_malloc(SAPP_MEM_FIX_GLOBAL_STREAM, -1, udp_stream_table_size * sizeof(short)); @@ -141,7 +110,6 @@ static int init_stream_detail(struct global_stream *g_stream) int max_cnt = tcp_stream_table_size + udp_stream_table_size; - //Ԥ�ȷ���stream_index�� STAILQ_INIT(&g_stream->freeList); g_stream->__freeList_real_head = (struct stream_index_list_item *)sapp_mem_malloc(SAPP_MEM_FIX_GLOBAL_STREAM, -1, (max_cnt) * sizeof(struct stream_index_list_item)); memset(g_stream->__freeList_real_head, 0, (max_cnt) * sizeof(struct stream_index_list_item)); @@ -168,7 +136,6 @@ int tcp_set_creatlink_model(int model) tcp_creatlink_model=model; return 0; } -//�����Ƿ���tcpallģʽ int tcp_set_support_tcpall_model(int model) { tcp_support_all=model; @@ -180,7 +147,7 @@ int tcp_set_default_unorder_num(unsigned short max_unorder) return 0; } -int tcp_set_max_unorder(int max_unorder) //2014-12-25 lijia add, ���ݾ�ƽ̨, xj_fd +int tcp_set_max_unorder(int max_unorder) { tcp_default_unorder=max_unorder; return 0; @@ -228,21 +195,13 @@ static void stream_timeout_shift_lrulist(struct streamindex *pindex, unsigned sh return; } -/* - NOTE: - �����õij�ʱʱ������ȫ�ֱ�timeoutֵ��!! - ��Ϊȫ����������ֻ��һ��LRU_time����, - ������ֵ�ܴ�, ���Խ���ǰ����LRUĩβ�����ʵ�λ��, - �������ǰֵ��ȫ�ֱ�С, ������Ҫ��LRU������tail����ѯ�ܶ���������ҵ��ʵ�λ��, - ���µ�����ʱ̫��. -*/ int stream_set_single_stream_timeout(const struct streaminfo *pstream,unsigned short timeout) { int ret=0; struct streaminfo_private *pstream_pr=(struct streaminfo_private *)pstream; struct streamindex *pindex; - if(OP_STATE_CLOSE == pstream->opstate && OP_STATE_CLOSE == pstream->pktstate){/* ��ǰ���ѽ���, ���賬ʱҲû�������� */ + if(OP_STATE_CLOSE == pstream->opstate && OP_STATE_CLOSE == pstream->pktstate){ return -1; } @@ -251,7 +210,6 @@ int stream_set_single_stream_timeout(const struct streaminfo *pstream,unsigned s { if (pstream_pr->set_special_timeout == 0) { - /* �������������ó�ʱʱ��, ��ǰ����һ�����ó�ʱʱ���¼���� */ sapp_global_mthread[pstream->threadnum].udp_stream_special_timeout_num++; } } @@ -259,13 +217,12 @@ int stream_set_single_stream_timeout(const struct streaminfo *pstream,unsigned s { if (pstream_pr->set_special_timeout == 0) { - /* �������������ó�ʱʱ��, ��ǰ����һ�����ó�ʱʱ���¼���� */ sapp_global_mthread[pstream->threadnum].tcp_stream_special_timeout_num++; } } else { - goto err; /* ��֧��TCP��UDP�� */ + goto err; } if(pstream_pr->plugin_process_context != 0) { @@ -439,8 +396,6 @@ struct streamindex *malloc_and_copy_streamindex(int threadnum, struct streaminde pindex->stream.stream_carry_up_layer_tunnel_type = 0; pindex->stream.stream_low_layer_tunnel_type = 0; - //pindex->stream.global_stream_id = get_global_stream_id(threadnum);//�ƶ���streamaddlist,��Ԫ������ʱ���ᱻ����. - return pindex; } @@ -463,16 +418,7 @@ void free_streamindex(int threadnum,struct streamindex *pindex) extern int call_streamentry(struct streaminfo *a_stream, const void *this_iphdr, const void *transport_hdr, const void *raw_pkt, StreamFunInfo *pFunInfo); //add by lqy 20141203 -//�������β�������һ�������Ƿ�ʱ�������ʱ����̭֮ - -/* 2015-06-10 lijia add arg "current_drive_index", ��ʾ��ǰ���ṹָ�� - return value: - 0: normal; - 1: del self by time. - modify by lqy 20150612 - ��ʱɾ��������ͷ����ʼ��һ��ɾ�� -*/ enum del_stream_by_time_returen_code { @@ -516,10 +462,9 @@ int del_stream_by_time(struct stream_list *plist, const struct streamindex *curr struct streaminfo *pstream = &(pstream_pr->stream_public); if (pindex == current_drive_index) - { /* ��ǰ�����ڵ�����ʱ, ˵��֮ǰ�ܳ�ʱ��û�а�����, ��ʱ����free, ���Ƿ���1, �ٵ���reset */ + { if (STREAM_TYPE_TCP == pstream->type) { - /* 2016-12-15 lijia add, ��ʱreset֮ǰ, ��Ҫ����link_state */ ((struct tcpdetail_private *)(pstream->pdetail))->link_state = STREAM_LINK_TIMEOUT; } ret = DEL_STREAM_BY_TIME_RET_DEL_SELF; @@ -579,11 +524,6 @@ int del_stream_by_time(struct stream_list *plist, const struct streamindex *curr return ret; } -/* - return value: - 0: normal; - 1: del self by timeout, need reset. -*/ int lrustream(struct streamindex *pindex) { struct stream_list *plist=NULL; @@ -633,30 +573,19 @@ int lrustream(struct streamindex *pindex) return 0; } -/* - MPLS���ַ����ipv4,ipv6,tcp,udp����, �յ�����һ���������ƶ���һ��ĵ�ַ, - MPLS��ַ�ǵ����, �������п����Dz��Գƴ��ڵ�, ��һ���ж���һ��û��. - ����, �Ƚϵ�ַ���ַ���. -*/ static int cmpaddr_mpls(const struct layer_addr_mpls *addr_heap, const struct layer_addr_mpls *addr_stack) { int i, ret = 0; int same_dir_diff = 0, reverse_dir_diff = 0; if(0 == addr_stack->c2s_layer_num){ - return 0; /* �����İ�mpls�ǿղ�, ���ñȽ� */ + return 0; } if((addr_heap->c2s_layer_num == 0) || (addr_heap->s2c_layer_num == 0)){ - /* �������ĵ�ַijһ����0, Ҳ���ǵ�����, ����û�յ����Բ�����; - Ҳ����ijһ���ǿղ�, ������û��mpls, - ��ʱû���ж���һ�����Բ����ݰ��״ε���, ���Ǹ�������һ����������һ�������״ε���, - �Ȳ��Ƚϵ�ַ��. - */ return 0; } - /* ����Ƚϵ�ַ */ if(addr_heap->c2s_layer_num != addr_stack->c2s_layer_num){ same_dir_diff = 1; }else{ @@ -668,7 +597,6 @@ static int cmpaddr_mpls(const struct layer_addr_mpls *addr_heap, const struct la } } - /* ����Ƚϵ�ַ */ if(addr_heap->s2c_layer_num != addr_stack->c2s_layer_num){ reverse_dir_diff = 1; }else{ @@ -680,7 +608,7 @@ static int cmpaddr_mpls(const struct layer_addr_mpls *addr_heap, const struct la } } - if(same_dir_diff && reverse_dir_diff){ /* ���������ַ����һ�� */ + if(same_dir_diff && reverse_dir_diff){ return -1; } @@ -689,10 +617,6 @@ static int cmpaddr_mpls(const struct layer_addr_mpls *addr_heap, const struct la static int cmpaddr_gtp(const struct layer_addr_gtp *addr_heap, const struct layer_addr_gtp *addr_stack) { - /* stack �ĵ�ַ�̶��洢��c2s���� - gtp��ַ�Ƚ�ʱ, ���ַ���, �����ⷽ���teid����ͬ, ����Ϊ��һ�������� - ֮ǰ��pcap���з�������ַ��ijһ���teid���仯�����. - */ if(0 != addr_heap->teid_c2s){ if(addr_heap->teid_c2s == addr_stack->teid_c2s){ return 0 ; @@ -715,11 +639,9 @@ static int cmpaddr_positive(void *addr_heap, void *addr_stack, UCHAR addrtype, switch(addrtype){ case ADDR_TYPE_IPV4: { - /* 2015-07-14 lijia modify, ��Ҫ�Ƚ϶˿� */ struct stream_tuple4_v4 *ip4_addr_heap = (struct stream_tuple4_v4 *)addr_heap; struct stream_tuple4_v4 *ip4_addr_stack = (struct stream_tuple4_v4 *)addr_stack; - /* 2015-07-15 lijia modify, ����ܲ�һ���ı���������ǰ��Ƚ� */ ret = (int)ip4_addr_heap->source - (int)ip4_addr_stack->source; if(ret != 0){ return ret; @@ -743,7 +665,6 @@ static int cmpaddr_positive(void *addr_heap, void *addr_stack, UCHAR addrtype, { struct stream_tuple4_v6 *ip6_addr_heap = (struct stream_tuple4_v6 *)addr_heap; struct stream_tuple4_v6 *ip6_addr_stack = (struct stream_tuple4_v6 *)addr_stack; - /* 2015-07-15 lijia modify, ����ܲ�һ���ı���������ǰ��Ƚ� */ ret = (int)ip6_addr_heap->source - (int)ip6_addr_stack->source; if(ret != 0){ return ret; @@ -804,7 +725,6 @@ static int cmpaddr_positive(void *addr_heap, void *addr_stack, UCHAR addrtype, break; default: - /* ������ַ����, ��VLAN, L2TP��, ����������, ����ת��, ֱ�ӱȽϼ��� */ ret = memcmp(addr_heap, addr_stack, addrlen); } @@ -817,11 +737,9 @@ static int cmpaddr_reverse(void *addr_heap, void *addr_stack, UCHAR addrtype, U switch(addrtype){ case ADDR_TYPE_IPV4: { - /* 2015-07-14 lijia modify, ��Ҫ�Ƚ϶˿� */ struct stream_tuple4_v4 *ip4_addr_heap = (struct stream_tuple4_v4 *)addr_heap; struct stream_tuple4_v4 *ip4_addr_stack = (struct stream_tuple4_v4 *)addr_stack; - /* 2015-07-15 lijia modify, ����ܲ�һ���ı���������ǰ��Ƚ� */ ret = (int)ip4_addr_heap->source - (int)ip4_addr_stack->dest; if(ret != 0){ return ret; @@ -845,7 +763,6 @@ static int cmpaddr_reverse(void *addr_heap, void *addr_stack, UCHAR addrtype, U { struct stream_tuple4_v6 *ip6_addr_heap = (struct stream_tuple4_v6 *)addr_heap; struct stream_tuple4_v6 *ip6_addr_stack = (struct stream_tuple4_v6 *)addr_stack; - /* 2015-07-15 lijia modify, ����ܲ�һ���ı���������ǰ��Ƚ� */ ret = (int)ip6_addr_heap->source - (int)ip6_addr_stack->dest; if(ret != 0){ return ret; @@ -906,17 +823,12 @@ static int cmpaddr_reverse(void *addr_heap, void *addr_stack, UCHAR addrtype, U break; default: - /* ������ַ����, ��VLAN, L2TP��, ����������, ����ת�� */ ret = memcmp(addr_heap, addr_stack, addrlen); } return ret; } -/* - pheap_stream_pr : already in stream htable. - pstack_stream_pr: new element recv from network; -*/ static int cmpaddr_new(struct streaminfo_private *pheap_stream_pr, struct streaminfo_private *pstack_stream_pr) { @@ -930,7 +842,6 @@ static int cmpaddr_new(struct streaminfo_private *pheap_stream_pr, ret = cmpaddr_positive(heap_addr->paddr, stack_addr->paddr, heap_addr->addrtype, heap_addr->addrlen); }else{ - /* 2015-03-04 lijia add, �����ַ�Ƚ�, ������COPY.*/ ret = cmpaddr_reverse(heap_addr->paddr, stack_addr->paddr, heap_addr->addrtype, heap_addr->addrlen); } @@ -944,10 +855,6 @@ static int cmpaddr_new(struct streaminfo_private *pheap_stream_pr, } -/* - GTP�Ķ˿ڿ��������һ��, ��asymmetric addr, - �˴����¶˿������һ��ip��teid�ı�İ�Ϊ. -*/ static void update_outer_ipv4addr_for_gtp_tunnel(const struct streaminfo_private *top_stream_pr, struct streaminfo_private *pheap_gtp_stream_pr, struct streaminfo_private *pstack_gtp_stream_pr, struct streaminfo_private *pheap_ip_stream_pr, struct streaminfo_private *pstack_ip_stream_pr, unsigned char cur_pkt_dir) @@ -982,7 +889,6 @@ static void update_outer_ipv4addr_for_gtp_tunnel(const struct streaminfo_private return; } - /******** for debug log, Ҫ���ڵ�ַ���µ�ǰ��, ����ԭʼ��Ϣ�ͱ������� ********/ if(MESA_handle_runtime_log_level_enabled(ABBR_SAPP_LOG_HANDLE, RLOG_LV_DEBUG)){ char ip_before_src_str[INET_ADDRSTRLEN], ip_before_dst_str[INET_ADDRSTRLEN]; char ip_after_src_str[INET_ADDRSTRLEN], ip_after_dst_str[INET_ADDRSTRLEN]; @@ -997,7 +903,7 @@ static void update_outer_ipv4addr_for_gtp_tunnel(const struct streaminfo_private after_teid_c2s = ntohl(pstack_gtp_stream_pr->stream_public.addr.gtp->teid_c2s); after_teid_s2c = before_teid_s2c; }else{ - after_teid_s2c = ntohl(pstack_gtp_stream_pr->stream_public.addr.gtp->teid_c2s); /* �˴����DZ���!! stack����ʱջ�ռ�, teid�̶�����c2s������ */ + after_teid_s2c = ntohl(pstack_gtp_stream_pr->stream_public.addr.gtp->teid_c2s); after_teid_c2s = before_teid_c2s; } @@ -1024,7 +930,7 @@ static void update_outer_ipv4addr_for_gtp_tunnel(const struct streaminfo_private heap_tuple4addr->daddr = stack_tuple4addr->saddr; heap_tuple4addr->source = stack_tuple4addr->dest; heap_tuple4addr->dest = stack_tuple4addr->source; - pheap_gtp_stream_pr->stream_public.addr.gtp->teid_s2c = pstack_gtp_stream_pr->stream_public.addr.gtp->teid_c2s; /* �˴����DZ���!! stack����ʱջ�ռ�, teid�̶�����c2s������ */ + pheap_gtp_stream_pr->stream_public.addr.gtp->teid_s2c = pstack_gtp_stream_pr->stream_public.addr.gtp->teid_c2s; } return; @@ -1064,7 +970,6 @@ static void update_outer_ipv6addr_for_gtp_tunnel(const struct streaminfo_private return; } - /******** for debug log, Ҫ���ڵ�ַ���µ�ǰ��, ����ԭʼ��Ϣ�ͱ������� ********/ if( MESA_handle_runtime_log_level_enabled(ABBR_SAPP_LOG_HANDLE, RLOG_LV_DEBUG)){ char ip_before_src_str[INET_ADDRSTRLEN], ip_before_dst_str[INET_ADDRSTRLEN]; char ip_after_src_str[INET_ADDRSTRLEN], ip_after_dst_str[INET_ADDRSTRLEN]; @@ -1079,7 +984,7 @@ static void update_outer_ipv6addr_for_gtp_tunnel(const struct streaminfo_private after_teid_c2s = ntohl(pstack_gtp_stream_pr->stream_public.addr.gtp->teid_c2s); after_teid_s2c = before_teid_s2c; }else{ - after_teid_s2c = ntohl(pstack_gtp_stream_pr->stream_public.addr.gtp->teid_c2s); /* �˴����DZ���!! stack����ʱջ�ռ�, teid�̶�����c2s������ */ + after_teid_s2c = ntohl(pstack_gtp_stream_pr->stream_public.addr.gtp->teid_c2s); after_teid_c2s = before_teid_c2s; } @@ -1111,17 +1016,12 @@ static void update_outer_ipv6addr_for_gtp_tunnel(const struct streaminfo_private memcpy(heap_tuple6addr->daddr, stack_tuple6addr->saddr, IPV6_ADDR_LEN); heap_tuple6addr->source = stack_tuple6addr->dest; heap_tuple6addr->dest = stack_tuple6addr->source; - pheap_gtp_stream_pr->stream_public.addr.gtp->teid_s2c = pstack_gtp_stream_pr->stream_public.addr.gtp->teid_c2s; /* �˴����DZ���!! stack����ʱջ�ռ�, teid�̶�����c2s������ */ + pheap_gtp_stream_pr->stream_public.addr.gtp->teid_s2c = pstack_gtp_stream_pr->stream_public.addr.gtp->teid_c2s; } return; } -/* - GTP���������IP��Ԫ��, ���վ��Ǩ��, ���IP���ܱ仯. - - pheap_stream_pr, pstack_stream_prָ��GTP��һ���ip/udp��. -*/ static int checkstreamorder_for_gtp_tunnel(const struct streaminfo_private *top_stream_pr, struct streaminfo_private *pheap_gtp_stream_pr, struct streaminfo_private *pstack_gtp_stream_pr, struct streaminfo_private *pheap_ip_stream_pr, struct streaminfo_private *pstack_ip_stream_pr, @@ -1145,9 +1045,6 @@ static int checkstreamorder_for_gtp_tunnel(const struct streaminfo_private *top_ } } - /* ���ip��ַ��仯, ���ĸ�ip�����ܶ���һ��, �����ⷽ���ַ��ͬ, ������Ϊ������ͬһ��GTP���� - TODO, �˴���ҪͬGTP-C���� ?? - */ if (pheap_stream->addr.addrtype == pstack_stream->addr.addrtype && pheap_stream->addr.addrlen == pstack_stream->addr.addrlen) { if (pheap_stream->addr.addrtype == ADDR_TYPE_IPV4) @@ -1214,19 +1111,15 @@ static int checkstreamorder_for_gtp_tunnel(const struct streaminfo_private *top_ pstack_stream->addr.addrlen); } - if(0 == this_layer_is_same){ /* �����ַȫ��һ��, ��Ϊ��������һ������, ֱ�ӷ��ش��� */ + if(0 == this_layer_is_same){ return -1; } - /* �����Ƚ���һ���ַ */ ret=checkstreamorder(top_stream_pr, (struct streaminfo_private *)(pheap_ip_stream_pr->pfather_pr), (struct streaminfo_private *)(pstack_ip_stream_pr->pfather_pr), heap_streaminfo_skip_layer_num, stack_streaminfo_skip_layer_num); if(0 == ret){ - /* ִ�е���, ���е�ַ����ͬ, �����Dz����ڵ�ַ�Ƚ�, ˵����ǰ��pheap_stream_pr,pstack_stream_pr��ͬ����һ���ϲ�TCP/UDP��, - ���Ը�������ipv4/udp����Ϣ. - */ if(pheap_stream->addr.addrtype == ADDR_TYPE_IPV4) { @@ -1242,15 +1135,6 @@ static int checkstreamorder_for_gtp_tunnel(const struct streaminfo_private *top_ } -/*�Ƚ��������ṹ���С */ -//adjust 20140324 �Ƚ��������ṹ�Ƿ���ͬ������pfather �ڵ���ȫ��ͬ, -//�ݹ�Ƚ��������ĸ�������� -/* - return value: - 0 : found, success; - 1 : pst1 > pst2; - -1: pst1 < pst2 -*/ int checkstreamorder(const struct streaminfo_private *top_stream_pr, struct streaminfo_private *pheap_stream_pr, struct streaminfo_private *pstack_stream_pr, int *heap_streaminfo_skip_layer_num, int *stack_streaminfo_skip_layer_num) { @@ -1289,10 +1173,6 @@ int checkstreamorder(const struct streaminfo_private *top_stream_pr, struct stre pstack_stream = &pstack_stream_pr->stream_public; - /* GTP��TEID��仯, ���ܼıȽ�addr����, ���Ա���addr_use_as_hash=0, - ���Ի�����gtp���Ƚ��²��ip/udp, ��������ip�Ͷ˿ڿ��ܻ�Ư��, Ҳ���ܰ����淽ʽ�Ƚ�ip��port, - ����GTP��һ�������. - */ switch(pstack_stream->addr.addrtype){ case ADDR_TYPE_GPRS_TUNNEL: return checkstreamorder_for_gtp_tunnel(top_stream_pr, pheap_stream_pr, pstack_stream_pr, @@ -1324,7 +1204,6 @@ int checkstreamorder(const struct streaminfo_private *top_stream_pr, struct stre if(0 != ret){ return ret; }else{ - /* 2015-03-11 lijia add, ��Ҫ����ǰ��IP��İ���Ϣ���ݵ�����Ϣ */ pheap_stream_pr->stream_public.addr.pktipfragtype = pstack_stream_pr->stream_public.addr.pktipfragtype; } @@ -1340,17 +1219,6 @@ int checkstreamorder(const struct streaminfo_private *top_stream_pr, struct stre return ret; } -/* - ���ڷǶԳ�Э������Ķ�. - - ����: - heap stream : tuple4->eth, - stack stream: tuple4->mpls->eth, - ���������, ������Ϊ�ڲ�tcp��ͬ����һ����. - - ��֮��: - heap stream : tuple4->mpls->eth -*/ static void streaminfo_layer_alignment(const struct streaminfo *top_stream, struct streaminfo_private *heap_stream_pr, struct streaminfo_private *stack_stream_pr) { struct streaminfo_private *new_heap_tmp = NULL; @@ -1365,15 +1233,12 @@ static void streaminfo_layer_alignment(const struct streaminfo *top_stream, stru } if(heap_stream_pr->pfather_pr->stream_public.addr.addrtype != stack_stream_pr->pfather_pr->stream_public.addr.addrtype){ - /* - new_heap_tmp��ʱִ��mpls�� - */ if(STREAM_TYPE_TCP == top_stream->type){ mem_used_type = SAPP_MEM_DYN_TCP_STREAM; }else{ mem_used_type = SAPP_MEM_DYN_UDP_STREAM; } - new_heap_tmp = copy_stream_info_to_heap_single_layer(mem_used_type, stack_stream_pr->pfather_pr, 1); /* ����ʱ, �϶��ǶԲ�����, ����copy, ��Ϊͬ��Ͳ����ڲ�����һ����, reverse�̶�Ϊ1 */ + new_heap_tmp = copy_stream_info_to_heap_single_layer(mem_used_type, stack_stream_pr->pfather_pr, 1); new_heap_tmp->pfather_pr = heap_stream_pr->pfather_pr; new_heap_tmp->stream_public.pfather = &heap_stream_pr->pfather_pr->stream_public; @@ -1387,10 +1252,6 @@ static void streaminfo_layer_alignment(const struct streaminfo *top_stream, stru streaminfo_layer_alignment(top_stream, heap_stream_pr->pfather_pr, stack_stream_pr->pfather_pr); } -/* - plinkhead: �Ѵ���������htable��ij��slot�ĵ�һ���ڵ�; - pinsert : ��ǰ��������ʱջ�ռ�����ַ. -*/ static struct streamindex * findandsethashindex_lru(struct streamindex *plinkhead, struct streamindex *pinsert) { struct streamindex *phead=plinkhead; @@ -1401,12 +1262,11 @@ static struct streamindex * findandsethashindex_lru(struct streamindex *plinkhea unsigned long hash_list_num = 0; UCHAR threadnum = psinsert_pr->stream_public.threadnum; sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[threadnum]->sys_stat; - int stack_streaminfo_skip_layer_num = 0, heap_streaminfo_skip_layer_num = 0; /* ����Ҫ��ַ�Ƚϲ������ */ + int stack_streaminfo_skip_layer_num = 0, heap_streaminfo_skip_layer_num = 0; while(phead!=NULL) { pshead_pr=&(phead->stream); - /* 2015-12-14 lijia add, ��ͨ���ڶ���HASHֵԤ���ж��Ƿ����, ���HASH��ͬ, ��ַ�϶���ͬ */ if(pshead_pr->hash_slave != psinsert_pr->hash_slave){ phead=phead->phashnext; hash_list_num++; @@ -1444,11 +1304,6 @@ static struct streamindex * findandsethashindex_lru(struct streamindex *plinkhea -/* -//�����������˵����� -//1) �ж��Ƿ������ -//2) �������ķ�����Ϣ ,dir ,curdir ,routdir -*/ struct streamindex *findstreamindex(struct streamindex *pindex, const raw_pkt_t *raw_pkt) { struct streamindex **phashstream=NULL; @@ -1495,8 +1350,8 @@ struct streamindex *findstreamindex(struct streamindex *pindex, const raw_pkt_t elemcount=this_thread_stream->tcp_stream_talbe_hash_count[hash_index]; } - if(0 == elemcount){ /* 2015-12-14 lijia add, HASH����ǰSLOT��û����, ֱ�ӷ��� */ - ptmp->hash_index = hash_index; /* �������õ���HASHֵ */ + if(0 == elemcount){ + ptmp->hash_index = hash_index; return NULL; } @@ -1504,15 +1359,6 @@ struct streamindex *findstreamindex(struct streamindex *pindex, const raw_pkt_t if (likely(a_index!=NULL)){ - /* - 2015-12-14 lijia add - NOTE: - �����ǰ������N�ζ�����HASH_SLOT�ĵ�һλ, ���ƶ�����һλ, �ƶ����������, - �´β��ҿ�������, - ͬʱ��ֹ����һ��SLOT�ļ�������Ƶ���а��������, ָ��Ƶ�������ƶ�, ������������. - - Ŀ�����ĸ��������ݰ��϶�, ˭�;�����SLOT��һλ. - */ if((a_index != phashstream[hash_index]) && (a_index->stream.hash_not_head_times++ > 5)){ if(a_index->phashnext){ a_index->phashnext->phashprev = a_index->phashprev; @@ -1582,7 +1428,6 @@ void hash_add_stream(struct streamindex *pindex) } - /* ����HASH-Slot��һ��λ�� */ if(phashstream[hash_index]!=NULL) phashstream[hash_index]->phashprev=pindex; pindex->phashnext=phashstream[hash_index]; @@ -1590,9 +1435,6 @@ void hash_add_stream(struct streamindex *pindex) pelementcount[hash_index]++; - /* TCP, UDP�½���ʱ������ô˺���, ����ddos���ŵ��˴�, - �����мDz�Ҫ�ŵ�streamaddlist()����, ��Ϊͬһ�����л���ͬ״̬ʱ, ���ܻ����streamaddlist()�ü���. - */ if(pindex->stream.create_dir_by_well_known_port != 1) { pindex->stream.under_ddos_bypass = packet_io_under_ddos_should_bypass(threadnum); @@ -1881,7 +1723,6 @@ int addr_dir_relation(void *addr, int addrtype) break; default: - /* ������ַ��������������, Ĭ��Ϊ0 */ relation = 0; break; } @@ -1889,7 +1730,6 @@ int addr_dir_relation(void *addr, int addrtype) return relation; } -/* ��addr��ַ���� */ void reverse_addr(void *addr, int addrtype) { UINT16 tmp_ushort; @@ -1950,17 +1790,14 @@ void reverse_addr(void *addr, int addrtype) } break; - /* TODO 1:PPTP-addr */ default: - /* ������ַ����, ��VLAN, L2TP��, ����������, ����ת�� */ return; } return; } -/* �����ַcopy */ void addr_reverse_memcpy(const struct streaminfo_private *stack_stream_pr, void *daddr, const void *saddr, int addrtype, int addrlen) { switch(addrtype){ @@ -1986,42 +1823,38 @@ void addr_reverse_memcpy(const struct streaminfo_private *stack_stream_pr, void } break; - case ADDR_TYPE_MAC: /* 2015-06-15 lijia add, ľ������豸���� */ + case ADDR_TYPE_MAC: { const struct layer_addr_mac *cur_stack_mac_saddr = (const struct layer_addr_mac *) saddr; struct layer_addr_mac *heap_stream_mac_daddr = (struct layer_addr_mac *) daddr; - //if (1 == sapp_global_val->config.protocol_feature.reverse_ethernet_addr_enabled) //2018-12-07 yw add, mac��ַ�а�����Ϣʱ���跭ת + //if (1 == sapp_global_val->config.protocol_feature.reverse_ethernet_addr_enabled) //2018-12-07 yw add, mac if(g_asymmetric_addr_layer_set.layer_type_index[ADDR_TYPE_MAC][stack_stream_pr->layer_index] == 0){ - /* �������ǶԳƵ�ַ����ʱ, ethernet��ip,tcpһ��, �ߵ�Դ��Ŀ�ĵ�ַ����,˫���ַ���洢��src_addr */ memcpy(heap_stream_mac_daddr->src_addr.h_source, cur_stack_mac_saddr->src_addr.h_dest, ETH_ALEN); memcpy(heap_stream_mac_daddr->src_addr.h_dest, cur_stack_mac_saddr->src_addr.h_source, ETH_ALEN); }else{ - /* �����ǶԳƵ�ַ����ʱ,������������ĸ�mac��ַ,��ʱҪ����copy 14���ֽ�, ��ջ�е�src_addr����heap��dst_addr��, ����struct ethhdr�еĵ�ַ�����ܱ� */ memcpy(&heap_stream_mac_daddr->dst_addr, &cur_stack_mac_saddr->src_addr, sizeof(struct ethhdr)); } } break; - case __ADDR_TYPE_IP_PAIR_V4: /* ��IPv4��, ͨ���ǻ�������ģʽ */ + case __ADDR_TYPE_IP_PAIR_V4: { const struct layer_addr_ipv4 *ip4_saddr = (const struct layer_addr_ipv4 *)saddr; struct layer_addr_ipv4 *ip4_daddr = (struct layer_addr_ipv4 *)daddr; ip4_daddr->saddr = ip4_saddr->daddr; - ip4_daddr->daddr = ip4_saddr->saddr; /* ֻ��IP��ַ */ - /* Note: ��IP��Ķ˿�ֵһ��Ҫ��Ϊ0, �����ʹ��δ��ʼ�����ڴ�, �ں�������ԭ��cmpaddr()������, ���ܻᵼ�����Ƚϵ�ַ��һ�����Ҳ��� */ + ip4_daddr->daddr = ip4_saddr->saddr; ip4_daddr->source = 0; ip4_daddr->dest = 0; } break; - case __ADDR_TYPE_IP_PAIR_V6: /* ��IPv6��, ͨ���ǻ�������ģʽ */ + case __ADDR_TYPE_IP_PAIR_V6: { const struct layer_addr_ipv6 *ip6_saddr = (const struct layer_addr_ipv6 *)saddr; struct layer_addr_ipv6 *ip6_daddr = (struct layer_addr_ipv6 *)daddr; memcpy(ip6_daddr->saddr, ip6_saddr->daddr, IPV6_ADDR_LEN); memcpy(ip6_daddr->daddr, ip6_saddr->saddr, IPV6_ADDR_LEN); - /* Note: ��IP��Ķ˿�ֵһ��Ҫ��Ϊ0, �����ʹ��δ��ʼ�����ڴ�, �ں�������ԭ��cmpaddr()������, ���ܻᵼ�����Ƚϵ�ַ��һ�����Ҳ��� */ ip6_daddr->source = 0; ip6_daddr->dest = 0; } @@ -2033,7 +1866,6 @@ void addr_reverse_memcpy(const struct streaminfo_private *stack_stream_pr, void struct layer_addr_vlan *dst_vlan = (struct layer_addr_vlan *)daddr; memset(dst_vlan, 0, sizeof(struct layer_addr_vlan)); - /* ��ǰstack��İ���ַ��Ϣ�̶��洢��src����, ����copy�ǽ�stack��ַ����������ĵ�ַ */ memcpy(dst_vlan->s2c_addr_array, src_vlan->c2s_addr_array, sizeof(src_vlan->c2s_addr_array)); dst_vlan->s2c_layer_num = src_vlan->c2s_layer_num; } @@ -2054,7 +1886,6 @@ void addr_reverse_memcpy(const struct streaminfo_private *stack_stream_pr, void struct layer_addr_mpls *dst_mpls = (struct layer_addr_mpls *)daddr; memset(dst_mpls, 0, sizeof(struct layer_addr_mpls)); - /* ��ǰstack��İ���ַ��Ϣ�̶��洢��src����, ����copy�ǽ�stack��ַ����������ĵ�ַ */ memcpy(dst_mpls->s2c_addr_array, current_stack_addr->c2s_addr_array, sizeof(current_stack_addr->c2s_addr_array)); dst_mpls->s2c_layer_num = current_stack_addr->c2s_layer_num; if(current_stack_addr->c2s_has_ctrl_word){ @@ -2087,7 +1918,6 @@ void addr_reverse_memcpy(const struct streaminfo_private *stack_stream_pr, void break; default: - /* ������ַ����, ����������,ֱ��copy */ memcpy(daddr, saddr, addrlen); return; } @@ -2095,11 +1925,6 @@ void addr_reverse_memcpy(const struct streaminfo_private *stack_stream_pr, void return; } -/* - ��ΪԤ�ȷ�����һЩstreamindex�ṹ, ÿ�δ�����ʱ, ��Ԥ�ȷ�����ڴ��л�ȡ, - ��malloc_and_copy_streamindex()����, ֻcopy streamindex�ṹ, û��addr.paddr, - ��Ҫ����ַ��ϢҲcopy������. -*/ int copy_ipport_union_addr(struct streaminfo *pstream_heap, struct streaminfo *pstream_stack, int reverse) { pstream_heap->addr.paddr = sapp_mem_malloc(SAPP_MEM_DYN_PADDR, pstream_stack->threadnum, pstream_stack->addr.addrlen); @@ -2173,7 +1998,6 @@ void free_thread_stream(int thread_seq) } -/* 2014-04-08 LiJia add */ void free_heap_stream_info(int mem_used_type, struct streaminfo *heap_stream, int layer) { struct streaminfo_private *heap_stream_pr = (struct streaminfo_private *)(heap_stream); @@ -2187,26 +2011,17 @@ void free_heap_stream_info(int mem_used_type, struct streaminfo *heap_stream, in pfather_pr = heap_stream_pr->pfather_pr; addr = &heap_stream->addr; - /* Ϊ�˽�ʡ�ռ�, ��ַ����ADDR_TYPE_IPV4/6ʵ�ʴ洢����һ���IP��, ����free */ if(addr->paddr){ sapp_mem_free(SAPP_MEM_DYN_PADDR, heap_stream->threadnum, addr->paddr); addr->paddr = NULL; } if(layer != 0){ - /* ���ṹ�����ڲ㼴��0��, ʵ����ͨ��malloc_and_copy_streamindex()��ȡ��Ԥ�ȷ�����ڴ�, - ����free, - pfatherָ���streaminfo�ṹ����ͨ��copy_stream_info_to_heap()��̬malloc��. - */ sapp_mem_free((sapp_mem_type_t)mem_used_type, heap_stream->threadnum, heap_stream); } return free_heap_stream_info(mem_used_type, (struct streaminfo *)pfather_pr, layer+1); } -/* 2014-12-03 lijia add for sysinfo.log - args: - action: 1:add; -1:del; -*/ static inline void update_stream_status(UCHAR threadnum, UCHAR stream_type, UCHAR stream_state, int action) { sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[threadnum]->sys_stat; @@ -2242,11 +2057,6 @@ static inline void update_stream_status(UCHAR threadnum, UCHAR stream_type, UCHA } -/* - ���ں�tilera�ܹ��µ��ڴ�����Ϊlocal��sharedģʽ, - ԭ�������߳̽�����ȫ���ڴ�һ�����������ģʽ������, - ��Ϊÿ�������߳��Լ���ʼ��. -*/ int thread_self_init(int thread_seq) { return 0; @@ -2264,19 +2074,17 @@ int get_stream_carry_tunnel_type(const struct streaminfo *this_stream, *tunnel_type = STREAM_TUNNLE_NON; } - /* ������ָ��, ע��: sapp_online���sapp_ip_port_union�治һ�� */ const struct streaminfo *pfather = this_stream->pfather; switch(this_stream->addr.addrtype){ case ADDR_TYPE_MAC: pfather = this_stream->pfather; // if(pfather != NULL){ - //mac in mac����������, ֻ��һ��overlay�ķ�ʽ. } break; case ADDR_TYPE_IPV4: - pfather = this_stream->pfather; /* IP-TCP/UDP����Ϊ��һ������, ����pfatherָ�� */ + pfather = this_stream->pfather; if(pfather != NULL){ if(__ADDR_TYPE_IP_PAIR_V4 == pfather->addr.addrtype){ *tunnel_type |= (unsigned short)STREAM_TUNNLE_IP_IN_IP; @@ -2305,7 +2113,7 @@ int get_stream_carry_tunnel_type(const struct streaminfo *this_stream, break; case ADDR_TYPE_IPV6: - pfather = this_stream->pfather; /* IP-TCP/UDP����Ϊ��һ������, ����pfatherָ�� */ + pfather = this_stream->pfather; if(pfather != NULL){ if(__ADDR_TYPE_IP_PAIR_V4 == pfather->addr.addrtype){ *tunnel_type |= (unsigned short)STREAM_TUNNLE_6OVER4; @@ -2328,22 +2136,18 @@ int get_stream_carry_tunnel_type(const struct streaminfo *this_stream, break; case ADDR_TYPE_PPTP: - /* pptp_entry()�������Ѿ�����ַ����ΪADDR_TYPE_PPTP, �϶�����PPTP���� */ *tunnel_type |= (unsigned short)STREAM_TUNNLE_PPTP; break; case ADDR_TYPE_L2TP: - /* l2tp_entry()�������Ѿ�����ַ����ΪADDR_TYPE_L2TP, �϶�����L2TP���� */ *tunnel_type |= (unsigned short)STREAM_TUNNLE_L2TP; break; case ADDR_TYPE_GPRS_TUNNEL: - /* gtp_entry()�������Ѿ�����ַ����ΪADDR_TYPE_GTP, �϶�����GTP���� */ *tunnel_type |= (unsigned short)STREAM_TUNNEL_GPRS_TUNNEL; break; } - /* 2021-01-11, �˴����Բ�����vxlan�ȷ�װ��, ֱ����pfather */ return get_stream_carry_tunnel_type(pfather, this_stream, tunnel_type); } @@ -2360,15 +2164,11 @@ void update_opposite_addr_info(struct streaminfo_private *top_stream_pr, struct switch(p_stack->stream_public.addr.addrtype) { case ADDR_TYPE_GPRS_TUNNEL: - /* GTP��ַC2S, S2C�������, ������ǰ����ַ����dir, ÿ��ջ��ı������洢��source����, ��C2S����, - ������ʱ, �Ѿ��������ڲ�TCP, UDP��������, ��GTP�ĵ�ַ����source��dest, - �˺����Ǹ��µĶԶ�ȱʧ�ĵ�ַ, �������ڲ��cur_dir��ʾ��Ҫ�����ĸ�����ĵ�ַ, �̶��ӵ�ǰ��p_stack��source����. - */ if(cur_dir == DIR_C2S){ - pstream_pr->stream_public.addr.gtp->teid_c2s = p_stack->stream_public.addr.gtp->teid_c2s;/* ע��: �˴����DZ���, ����C2S */ + pstream_pr->stream_public.addr.gtp->teid_c2s = p_stack->stream_public.addr.gtp->teid_c2s; } else{ - pstream_pr->stream_public.addr.gtp->teid_s2c = p_stack->stream_public.addr.gtp->teid_c2s;/* ע��: �˴����DZ���, ����C2S */ + pstream_pr->stream_public.addr.gtp->teid_s2c = p_stack->stream_public.addr.gtp->teid_c2s; } break; @@ -2379,7 +2179,7 @@ void update_opposite_addr_info(struct streaminfo_private *top_stream_pr, struct p_stack->stream_public.addr.mpls->c2s_addr_array, sizeof(p_stack->stream_public.addr.mpls->c2s_addr_array)); pstream_pr->stream_public.addr.mpls->c2s_layer_num = p_stack->stream_public.addr.mpls->c2s_layer_num; - if(p_stack->stream_public.addr.mpls->c2s_has_ctrl_word){//ע��, ����̶��ж�src����!! + if(p_stack->stream_public.addr.mpls->c2s_has_ctrl_word){ pstream_pr->stream_public.addr.mpls->c2s_mpls_ctrl_word = p_stack->stream_public.addr.mpls->c2s_mpls_ctrl_word; pstream_pr->stream_public.addr.mpls->c2s_has_ctrl_word = 1; } @@ -2392,7 +2192,7 @@ void update_opposite_addr_info(struct streaminfo_private *top_stream_pr, struct p_stack->stream_public.addr.mpls->c2s_addr_array, sizeof(p_stack->stream_public.addr.mpls->c2s_addr_array)); pstream_pr->stream_public.addr.mpls->s2c_layer_num = p_stack->stream_public.addr.mpls->c2s_layer_num; - if(p_stack->stream_public.addr.mpls->c2s_has_ctrl_word){ //ע��, ����̶��ж�src����!! + if(p_stack->stream_public.addr.mpls->c2s_has_ctrl_word){ pstream_pr->stream_public.addr.mpls->s2c_mpls_ctrl_word = p_stack->stream_public.addr.mpls->c2s_mpls_ctrl_word; pstream_pr->stream_public.addr.mpls->s2c_has_ctrl_word = 1; } @@ -2415,9 +2215,9 @@ void update_opposite_addr_info(struct streaminfo_private *top_stream_pr, struct } else{ memcpy(pstream_pr->stream_public.addr.vlan->s2c_addr_array, - p_stack->stream_public.addr.vlan->c2s_addr_array, //ע��, ����̶���src����!! + p_stack->stream_public.addr.vlan->c2s_addr_array, sizeof(p_stack->stream_public.addr.vlan->s2c_addr_array)); - pstream_pr->stream_public.addr.vlan->s2c_layer_num = p_stack->stream_public.addr.vlan->c2s_layer_num; //ע��, ����̶���src����!! + pstream_pr->stream_public.addr.vlan->s2c_layer_num = p_stack->stream_public.addr.vlan->c2s_layer_num; } }else{ sapp_runtime_log(RLOG_LV_INFO, "update_opposite_addr_info() error, current addrtype is vlan, but pstream->addrtype is not vlan!"); @@ -2434,11 +2234,10 @@ void update_opposite_addr_info(struct streaminfo_private *top_stream_pr, struct } else{ memcpy(&pstream_pr->stream_public.addr.mac->dst_addr, - &p_stack->stream_public.addr.mac->src_addr, //ע��, ����̶���src����!! + &p_stack->stream_public.addr.mac->src_addr, sizeof(struct ethhdr)); } }else{ - /* �����ڶ���streaminfo�ṹ�ϲ��� */ return update_opposite_addr_info(top_stream_pr, (struct streaminfo_private *) pstream_pr->pfather_pr, (struct streaminfo_private *) p_stack, cur_dir); } @@ -2450,17 +2249,13 @@ void update_opposite_addr_info(struct streaminfo_private *top_stream_pr, struct const struct layer_addr_l2tp *p_stack_addr = p_stack->stream_public.addr.l2tp; struct layer_addr_l2tp *p_stream_addr = pstream_pr->stream_public.addr.l2tp; - /* L2TP��ַC2S, S2C�������, ������ǰ����ַ����dir, ÿ��ջ��ı������洢��source����, ��C2S����, - ������ʱ, �Ѿ��������ڲ�TCP, UDP��������, ��GTP�ĵ�ַ����source��dest, - �˺����Ǹ��µĶԶ�ȱʧ�ĵ�ַ, �������ڲ��cur_dir��ʾ��Ҫ�����ĸ�����ĵ�ַ, �̶��ӵ�ǰ��p_stack��source����. - */ if(cur_dir == DIR_C2S){ p_stream_addr->l2tpun.l2tp_addr_v2.tunnelid_C2S = p_stack_addr->l2tpun.l2tp_addr_v2.tunnelid_C2S; p_stream_addr->l2tpun.l2tp_addr_v2.sessionid_C2S = p_stack_addr->l2tpun.l2tp_addr_v2.sessionid_C2S; p_stream_addr->l2tpun.l2tp_addr_v2.seq_present_C2S = p_stack_addr->l2tpun.l2tp_addr_v2.seq_present_C2S; }else{ - p_stream_addr->l2tpun.l2tp_addr_v2.tunnelid_S2C = p_stack_addr->l2tpun.l2tp_addr_v2.tunnelid_C2S; /* ע��: �˴����DZ���, ����C2S */ - p_stream_addr->l2tpun.l2tp_addr_v2.sessionid_S2C = p_stack_addr->l2tpun.l2tp_addr_v2.sessionid_C2S; /* ע��: �˴����DZ���, ����C2S */ + p_stream_addr->l2tpun.l2tp_addr_v2.tunnelid_S2C = p_stack_addr->l2tpun.l2tp_addr_v2.tunnelid_C2S; + p_stream_addr->l2tpun.l2tp_addr_v2.sessionid_S2C = p_stack_addr->l2tpun.l2tp_addr_v2.sessionid_C2S; p_stream_addr->l2tpun.l2tp_addr_v2.seq_present_S2C = p_stack_addr->l2tpun.l2tp_addr_v2.seq_present_C2S; } } @@ -2476,7 +2271,7 @@ void update_opposite_addr_info(struct streaminfo_private *top_stream_pr, struct } else{ memcpy(&pstream_pr->stream_public.addr.vxlan->S2C_vxlan_addr, - &p_stack->stream_public.addr.vxlan->C2S_vxlan_addr, //ע��, ����̶���src����!! + &p_stack->stream_public.addr.vxlan->C2S_vxlan_addr, sizeof(p_stack->stream_public.addr.vxlan->S2C_vxlan_addr)); } }else{ @@ -2487,7 +2282,6 @@ void update_opposite_addr_info(struct streaminfo_private *top_stream_pr, struct break; default: - /* ����Э��㲻�漰C2S, S2C���������ַ�ǶԳ����� */ break; } } @@ -2507,7 +2301,6 @@ static inline raw_pkt_t *sapp_raw_pkt_dup(int mem_used_type, int thread_index, c new_raw_pkt->__lib_raw_pkt_data = sapp_mem_malloc((sapp_mem_type_t)mem_used_type, thread_index, raw_pkt->__lib_raw_pkt_len); memcpy((void *)(new_raw_pkt->__lib_raw_pkt_data), raw_pkt->__lib_raw_pkt_data, raw_pkt->__lib_raw_pkt_len); - /* ����raw_pkt_dataָ�� */ hdr_offset = (char *)raw_pkt->raw_pkt_data - (char *)raw_pkt->__lib_raw_pkt_data; assert(hdr_offset <= 2048); new_raw_pkt->raw_pkt_data = (char *)new_raw_pkt->__lib_raw_pkt_data + hdr_offset; @@ -2529,7 +2322,6 @@ int update_polling_inject_context(int mem_used_type,struct streaminfo_private *p } thread_index = pstream_pr->stream_public.threadnum; - /* ���浱ǰ��C2S, S2C����ĵ�һ���� */ if(pstream_pr->stream_public.curdir == DIR_C2S) { if(NULL == pstream_pr->polling_inject_context->raw_pkt_stream_dir[DIR_C2S-1]){ @@ -2560,10 +2352,6 @@ int save_polling_inject_context(int mem_used_type, struct streaminfo_private *ps pstream_pr->polling_inject_context = (polling_inject_context_t *)sapp_mem_malloc((sapp_mem_type_t)mem_used_type, thread_index, sizeof(polling_inject_context_t)); memset(pstream_pr->polling_inject_context, 0, sizeof(polling_inject_context_t)); - /* TODO: - �˴���ÿ������ĵ�һ������������, ������Ƕ���̫���ڴ���, Ҳ��CPU, - �������flood������������!! - ����������IJ���������private�ṹ��, ��������ԭʼ�� */ if (pstream_pr->stream_public.curdir == DIR_C2S) { pstream_pr->polling_inject_context->raw_pkt_stream_dir[DIR_C2S - 1] = @@ -2623,11 +2411,6 @@ void free_polling_inject_context(int mem_used_type, struct streaminfo_private *p } -/* - ȫ����id, stream_index��ʷ���Ѿ���ʾ������Ψһid, �˴�Ҫ��֤��Ⱥ���л������ظ�, - ��λ --- ��λ - 1 | 12bit device_id | 8bit thread_id | 28bit timestamp in sec | 15bit sequence per thread -*/ unsigned long long get_global_stream_id(unsigned long long thread_seq) { #define RELATIVE_TIME_MAX (268435456L) @@ -2661,20 +2444,17 @@ struct streaminfo_private *copy_stream_info_to_heap_single_layer(int mem_used_ty memcpy(heap_stream_pr, stack_stream_pr, sizeof(struct streaminfo_private)); heap_stream = &(heap_stream_pr->stream_public); - /* ����streaminfo, pfatherӦ�����ⲿ�����ߴ���, �˴�����ΪNULL */ heap_stream_pr->pfather_pr = NULL; heap_stream_pr->stream_public.pfather = NULL; heap_addr = sapp_mem_malloc(SAPP_MEM_DYN_PADDR, stack_stream->threadnum, stack_stream->addr.addrlen); memset(heap_addr, 0, stack_stream->addr.addrlen); - /* �ϲ��ַ��ת, �Ҳ���overlay��,���ܷ���copy��ַ */ if(reverse){ heap_stream_pr->dirreverse=1; - heap_stream_pr->stream_dir = 1 ^ heap_stream_pr->layer_dir; /* lijia comment, ��"src>=dst"Ĭ�Ϲ���һ�� */ + heap_stream_pr->stream_dir = 1 ^ heap_stream_pr->layer_dir; heap_stream_pr->stream_c2s_route_dir = 1 ^ heap_stream_pr->stream_c2s_route_dir; //reverse_addr_new(heap_addr, heap_stream->addr.addrtype); - /* ��ַCOPYʱ, �����Ҫ��ת, ֱ�ӷ���COPY, ��Ҫ��memcpy, �ٽ�����ַԴ��Ŀ�ĵ�˳�� */ addr_reverse_memcpy(stack_stream_pr, heap_addr, stack_stream->addr.paddr, stack_stream->addr.addrtype, stack_stream->addr.addrlen); }else{ heap_stream_pr->stream_dir = heap_stream_pr->layer_dir; @@ -2689,15 +2469,6 @@ struct streaminfo_private *copy_stream_info_to_heap_single_layer(int mem_used_ty } -/* - 2014-04-08 LiJia add, - ÿ�����ĵ�ַ��Ϣ��ʱ����ջ�ռ�, �������غ�˿��ڴ��ַ����Ч��, - ��������ʱ, ��copy��malloc�Ķѿռ���, �����Ժ�ĵ�ַ�ȶ�. - - 2014-04-08 LiJia add new arg stream_c2s_route_dir, - ��Ϊ֮ǰ��reverse�Ķ�����ʵ�о�����, ��ʾ��ǰ���ַ��'���ַ�ǿͻ���'�����Ƿ�һ��, �Ƿ���Ҫ��ת, - ����mpls, gtp��Э���ַ�ǵ����, reverse�Ĺ���ʹ. - */ struct streaminfo_private *copy_stream_info_to_heap(int mem_used_type,const struct streaminfo_private *stack_stream_pr, int reverse) { struct streaminfo_private *heap_stream_pr; @@ -2715,7 +2486,7 @@ struct streaminfo_private *copy_stream_info_to_heap(int mem_used_type,const stru pfather_pr = stack_stream_pr->pfather_pr; if((pfather_pr != NULL) && (DEPLOYMENT_MODE_INLINE == sapp_global_val->config.packet_io.deployment_mode_bin) - && (g_overlay_layer_set[pfather_pr->stream_public.addr.addrtype][pfather_pr->layer_index] != 0)){ /* 2021-01-11 lijia add, overlay���pfather��ΪNULL, ������ɼ� */ + && (g_overlay_layer_set[pfather_pr->stream_public.addr.addrtype][pfather_pr->layer_index] != 0)){ heap_stream->pfather = NULL; }else{ heap_stream->pfather = (struct streaminfo *)heap_stream_pr->pfather_pr; @@ -2731,7 +2502,6 @@ int sapp_is_overlay_layer(const struct streaminfo_private *stream_pr, const raw_ } if((rawpkt->vlan_flipping_couple[0] && rawpkt->vlan_flipping_couple[1]) != 0){ - /* vlan flipping��ADC�Լ켰A�����豸���е�һ��ģʽ, ������overlay�� */ return 0; } @@ -2740,17 +2510,11 @@ int sapp_is_overlay_layer(const struct streaminfo_private *stream_pr, const raw_ return 1; } - /* TODO, Ŀǰ��ʱֻ��vxlanһ��overlayģʽ,���������ϵĶ�����overlay */ return 0; } -/* - �ײ����������ݰ�ʱ, ������Щ��̭����, ����Ŀ��: - 1) ʵ���ް���ʱ��̭����, ����ȷ; - 2) �����ݰ�ʱ��ǰ��֮ǰ�ľ�������, �����ǿ������ݰ�����ʱ����̭����, ��������һЩ�������ܺͽ��Ͱ�������ʱ. -*/ int polling_stream_timeout(int tid) { struct stream_list *plist=NULL; @@ -2774,7 +2538,7 @@ int polling_stream_timeout(int tid) { plist = &(G_MESA_GLOBAL_STREAM[tid]->tcpList[i]); if (plist->cnt > 0) - { /* polling�ο��ܻ�û����, ����û�д�״̬����, plist����ΪNULL */ + { ret = del_stream_by_time(plist, NULL, tid, STREAM_TYPE_TCP); if (ret > 0) { @@ -2788,16 +2552,13 @@ int polling_stream_timeout(int tid) } -/* - ���ڲ��ͨ����Ԫ���ҵ���ǰ�̵߳�streaminfo�ṹ, �˽ӿڽ������ڲ�������Ƕ�ײ�Ĵ�IPv4, IPv6��ַ! -*/ int find_streaminfo_by_addrv4(int thread_index, const struct stream_tuple4_v4 *tuplev4, enum stream_type_t streamtype, struct streaminfo *streaminfo_array[], int array_max_num) { const struct global_stream *this_thread_stream = G_MESA_GLOBAL_STREAM[thread_index]; struct streamindex **phashstream=NULL; struct streamindex *stream_hash_head = NULL; unsigned int hash_index, hash_max; - int ret, match_layer_dir; /* �������Ԫ�����˿���ΪԴ�Ĺ���һ�� */ + int ret, match_layer_dir; int tot_found_stream_num = 0; if((NULL == streaminfo_array) || (array_max_num <= 0)){ @@ -2823,7 +2584,6 @@ int find_streaminfo_by_addrv4(int thread_index, const struct stream_tuple4_v4 *t #if USE_LINUX_KERNEL_HASH_ALGO unsigned int a,b; unsigned short c,d; - /* �˴��ο�����: set_transport_addr() ,��˿���Ϊ�ͻ��� */ if(ntohs(tuplev4->source) > ntohs(tuplev4->dest)){ a = tuplev4->saddr; b = tuplev4->daddr; @@ -2900,7 +2660,7 @@ int find_streaminfo_by_addrv6(int thread_index, const struct stream_tuple4_v6 *t struct streamindex **phashstream=NULL; unsigned int hash_index, hash_max; struct streamindex *stream_hash_head = NULL; - int ret, match_layer_dir; /* �������Ԫ�����˿���ΪԴ�Ĺ���һ�� */ + int ret, match_layer_dir; int tot_found_stream_num = 0; if (STREAM_TYPE_TCP == streamtype) @@ -2920,7 +2680,6 @@ int find_streaminfo_by_addrv6(int thread_index, const struct stream_tuple4_v6 *t #if USE_LINUX_KERNEL_HASH_ALGO unsigned int a,b,c,d; unsigned int no_use_slave_hash; - /* �˴��ο�����: set_transport_addr() ,��˿���Ϊ�ͻ��� */ if(ntohs(tuple4_v6->source) > ntohs(tuple4_v6->dest)){ memcpy(&a, &tuple4_v6->saddr[12], sizeof(int)); memcpy(&b, &tuple4_v6->daddr[12], sizeof(int)); @@ -3013,7 +2772,6 @@ int init_stream_manage(int threadcount) init_stream_detail(G_MESA_GLOBAL_STREAM[i]); } - //add 20140626 ��ʼ��procject�ӿ� project_requirement_global_init(); if(stream_bridge_init() < 0){ diff --git a/src/plugin/src/plugin_manage.cpp b/src/plugin/src/plugin_manage.cpp index 93569bd..a50e90b 100644 --- a/src/plugin/src/plugin_manage.cpp +++ b/src/plugin/src/plugin_manage.cpp @@ -1,36 +1,21 @@ -#include "sapp_api.h" #include "sapp_declaration.h" #include "sapp_mem.h" -#include "sapp_private_api.h" -#include "field_stat2.h" -/* - sapp挂载插件失败后,仅写错误日志,然后继续加载下一个插件, - 即便所有插件都加载失败,仍然会处理流量,空跑�? 有时候必要的插件如果不加载,sapp运行已无意义,应该退出,这样其他监控程序可以告警�? 而仅写一条错误日志,不方便通过第三方监测程序发现问题�? - sapp新增配置文件:./etc/necessary_plug_list.conf, 加载插件失败是否退出,根据项目需求灵活选择�?*/ #ifdef __cplusplus extern "C" { #endif -/* - key : plug path; - data: fake data pointer, non-null; -*/ static MESA_htable_handle g_plug_necessary_htable; struct plug_uniq_t{ const char *plug_path; int is_necessary; - int plug_id; /* 只有protocol解析层才有�? 其他�?1 */ + int plug_id; int priority; }; -/* - key : plug name; - data: struct plug_uniq_t -*/ static MESA_htable_handle g_plug_uniq_htable; @@ -41,7 +26,7 @@ struct plug_manage_key_t{ typedef struct{ time_t init_time; - int init_state; /* 0: error; 1: succ */ + int init_state; long long time_spent_in_us; const char *plug_path; const char *plug_name; @@ -52,36 +37,11 @@ static plugin_load_state_t g_plugin_load_state[SAPP_MAX_PLUG_ENTRY_NUM]; static int plugin_load_state_num = 0; -/* - 根据插件的名称和入口函数名称, 找到入口函数在内存中的地址. - key : plug name, and plug entry name(TCP, UDP, HTTP, etc), - data: entry function addr; -*/ static MESA_htable_handle g_plug_manage_htable; int g_max_priority=0; plug_global_entry_t g_plug_global_entry[SAPP_MAX_PLUG_ENTRY_NUM]; int g_plug_global_entry_index; -/* - TODO2: - 插件获取自己的pme, 传入streaminfo和plugname, entry_type_string, - - 先从g_plug_manage_htable找到这个插件的entry函数入口地址, 这是全局�? 来自dlopen插件.so, 不会�? - - 然后在当前streaminfo的三个pdetail_private里找插件列表, 参�? MESA_get_stream_plug_pme() - - 其中有些函数可能是解析层函数入口, 可以通过 g_protocol_plug_info 比较得知; - 如果不是解析层函�? 等同于现在的MESA_get_stream_plug_pme, - - 如果是解析层函数, 需要继续递归查找挂载到当前解析层插件的业务插件列�? - 先找到解析层的pme, 但是这个私有结构都是解析插件自定义的, - 比如http_stream, 在http_stream里还有个指针, 才是业务插件函数调用链的pme, - 只有找到了这个pme, 才能转换�?stSessionFunInfo 结构, 然后通过比较appentry是否相同, 最后取出业务插件的pme. - - 但是, 解析层插件暴露给sapp平台的pme, 和业务插件对解析层的pme不是一个变�? 如何能找到解析层的业务插件pme指针??? - 而且, 一个tcp流里可能有多个http session, 每个http session又对应了一个业务插件的pme调用�? 且只有解析层插件自己知道这个结构, - 仅在sapp内部, 目前是不可能找到解析层上挂载的每个业务层插件pme�?!! -*/ int max_plug_priority_get() @@ -130,8 +90,7 @@ int plug_mange_get_entry_id(const char *plug_name, const char *plug_entry_name) static void plug_necessary_htable_free_cb(void *data) { if(data)sapp_mem_free(SAPP_MEM_FIX_PLUG_CTRL, -1, data); - //necessary htable没有实际的data, 只有key - ;//do nothing + ; } static MESA_htable_handle create_plug_necessary_htable(void) @@ -160,7 +119,6 @@ static MESA_htable_handle create_plug_necessary_htable(void) opt_int = HASH_ELIMINATE_ALGO_FIFO; MESA_htable_set_opt(htable, MHO_ELIMIMINATE_TYPE, &opt_int, sizeof(int)); - /* key是字符串, MHO_CBFUN_KEY_COMPARE, MHO_CBFUN_KEY_TO_INDEX使用htable内置的默认函�?*/ MESA_htable_set_opt(htable, MHO_CBFUN_DATA_FREE, (void *)plug_necessary_htable_free_cb, sizeof(void *)); @@ -204,7 +162,6 @@ static MESA_htable_handle create_plug_uniq_htable(void) opt_int = HASH_ELIMINATE_ALGO_FIFO; MESA_htable_set_opt(htable, MHO_ELIMIMINATE_TYPE, &opt_int, sizeof(int)); - /* key是字符串, MHO_CBFUN_KEY_COMPARE, MHO_CBFUN_KEY_TO_INDEX使用htable内置的默认函数即�?*/ MESA_htable_set_opt(htable, MHO_CBFUN_DATA_FREE, (void *)plug_uniq_htable_free_cb, sizeof(void *)); @@ -310,9 +267,6 @@ static MESA_htable_handle create_plug_manage_htable(void) MESA_htable_set_opt(htable, MHO_CBFUN_COMPLEX_KEY_FREE, (void *)&plug_manage_key_free_cb, sizeof(void *)); - /* 注意: plug_manage的data是dlopen的函数地址, 不能注册free callback */ - //MESA_htable_set_opt(htable, MHO_CBFUN_DATA_FREE, NULL, sizeof(void *)); - //MESA_htable_set_opt(htable, MHO_CBFUN_COMPLEX_KEY_FREE, (void *)&ipv4_frag_key_free, sizeof(void *)); MESA_htable_mature(htable); @@ -333,9 +287,6 @@ int plugin_is_necessary(const char *plug_path, int *priority) return 0; } -/* - 加载一个新的插�? 全局名称不能重复. -*/ int plugin_load_new_plug(const char *plug_name, const char *plug_path) { struct plug_uniq_t *plug_info; @@ -358,9 +309,6 @@ int plugin_load_new_plug(const char *plug_name, const char *plug_path) } -/* - 加载一个新的插件的entry, 一个插件可以同时有多个不同层的entry, 如TCP, UDP, HTTP, DNS�?.. -*/ int plugin_load_new_plug_entry(const char *plug_name, const char *plug_entry_type, void *entry_addr) { struct plug_manage_key_t mg_key = {}; @@ -376,9 +324,6 @@ int plugin_load_new_plug_entry(const char *plug_name, const char *plug_entry_typ return 0; } -/* - 根据插件名称和入口函数类�? 获取入口函数地址. -*/ void *plugin_get_plug_entry(const char *plug_name, const char *plug_entry_type) { struct plug_manage_key_t mg_key = {}; @@ -393,9 +338,6 @@ void *plugin_get_plug_entry(const char *plug_name, const char *plug_entry_type) } -/* - 文件内容�?/plug/conflist.inf, 但是无段落标�? -*/ static int plugin_parse_necessary_conf(void) { FILE *fp; @@ -405,7 +347,6 @@ static int plugin_parse_necessary_conf(void) fp = fopen(ABBR_NECESSARY_PLUG_CONF_FILE, "r"); if(NULL == fp){ - /* 没有此文�? 或空文件都不是错�? 表示没有必需的插�?*/ return 0; } @@ -426,9 +367,6 @@ static int plugin_parse_necessary_conf(void) -/* - 此函数有可能在不同阶段被重复调用, 先查找有没有此插件的历史记录. -*/ void plugin_load_state_update(int init_state, long long time_spent_in_us, const char *plug_path, const char *plug_name) { int i, index, bingo; @@ -450,7 +388,6 @@ void plugin_load_state_update(int init_state, long long time_spent_in_us, const } if(0 == bingo){ - /* not found history, is new plug */ index = plugin_load_state_num; plugin_load_state_num++; } @@ -459,7 +396,7 @@ void plugin_load_state_update(int init_state, long long time_spent_in_us, const if(init_state < 0){ g_plugin_load_state[index].init_state = 0; - g_plugin_load_state[index].time_spent_in_us = 0; /* 初始化失败记为0 */ + g_plugin_load_state[index].time_spent_in_us = 0; }else{ g_plugin_load_state[index].init_state = 1; g_plugin_load_state[index].time_spent_in_us = time_spent_in_us; @@ -472,7 +409,6 @@ void plugin_load_state_update(int init_state, long long time_spent_in_us, const } } -/* 对于qsort来说, item1,item2是每个数组成员的地址, 对于本例来说, 即指针的指针, 所以是plugin_load_state_t ** */ static int qsort_compare_time_spent_cb(const void *item1, const void *item2) { const plugin_load_state_t **load_state1 = (const plugin_load_state_t **)item1; @@ -483,9 +419,6 @@ static int qsort_compare_time_spent_cb(const void *item1, const void *item2) -/* - field stat注册名称时不允许用 "|:\n\r.\t<>[]#!@", 所以常见的字符里, 只能改成"_". -*/ static void sapp_plug_modify_char(char *str, int raw_char, int new_char) { char *ptr; @@ -592,9 +525,6 @@ int plugin_manage_init(void) plugin_parse_necessary_conf(); - /* index 0保留, 全为内置插件, �?udp_teredo_identify_entry(), gdev_keepalive_udp_entry()等等 - 或者是暂不支持entry_id, 而直接调�? stream_register_xxx系列函数注册的插�? - */ g_plug_global_entry[0].entry_id = 0; g_plug_global_entry[0].plug_name = sapp_strdup("inner_plug"); g_plug_global_entry[0].plug_entry_name = sapp_strdup("inner_entry"); diff --git a/src/project/stream_bridge.c b/src/project/stream_bridge.c index 59ba05c..e3ed882 100644 --- a/src/project/stream_bridge.c +++ b/src/project/stream_bridge.c @@ -2,25 +2,23 @@ extern "C" { #endif -#include "sapp_api.h" -#include "sapp_private_api.h" #include "sapp_declaration.h" #include "MESA_htable.h" #include "MESA_list.h" -#define STREAM_BRIDGE_MAGIC_SUCC (0x62726765) // "brge" 十六进制 +#define STREAM_BRIDGE_MAGIC_SUCC (0x62726765) typedef struct{ - int magic_num; /* 安全性校验, 也表示当前bridge曾经注册成功过 */ + int magic_num; int bridge_id; char bridge_name[NAME_MAX]; stream_bridge_free_cb_t *async_data_free_cb; - MESA_list_t sync_callback_fun_list; /* 支持多个接收者 */ + MESA_list_t sync_callback_fun_list; }stream_bridge_manage_t; struct stream_bridge_item{ long long value; - char valid_flag; /* 用于识别初始状态值为0, 和外部调用者设置了0. 两种值相同, 但是两个不同的状态 */ + char valid_flag; }__attribute__((packed, aligned(1))); typedef struct stream_bridge_item stream_bridge_item_t; @@ -130,7 +128,6 @@ static int stream_bridege_create_new_bridge(const char *bridge_name) } -/* 新建一个流结构时调用 */ void *stream_bridge_create_per_stream(int mem_used_type, int thread_num) { stream_bridge_item_t *stream_bridge_array; diff --git a/src/support/cpu_limit/cpu_limit.c b/src/support/cpu_limit/cpu_limit.c index cd81bac..a676392 100644 --- a/src/support/cpu_limit/cpu_limit.c +++ b/src/support/cpu_limit/cpu_limit.c @@ -1,16 +1,5 @@ -/*********************************************************************************************************************** - 本文件用于实现疑似ddos攻击时, 将某些流切换为bypass状态, 以忽略一小部分流的代价, 使大部分流还是能正常处理. - 暂时先放在sapp工程里, 尽量保持独立, 也不一定仅限于CPU, 也可以是内存, pps, bps, drop_pps等参数, - 以后可能作为一个独立的库存在. - - TODO: - 可以参考反馈控制PID算法 : - https://en.wikipedia.org/wiki/PID_controller - http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/ -***********************************************************************************************************************/ #include <stdio.h> #include <stdlib.h> -#include <stdint.h> #include <string.h> #include <unistd.h> #include <pthread.h> @@ -27,7 +16,7 @@ extern "C" { #if DEBUG_PRINT #define DPRINT(fmt, args...) printf(fmt, ## args) #else -#define DPRINT(fmt, args...) /* Don't do anything in release builds */ +#define DPRINT(fmt, args...) #endif @@ -36,53 +25,50 @@ extern "C" { #define CPUL_MAGIC_NUM (0xCC12345678LU) typedef enum{ - CL_LIMIT_STATE_PENDING = 0, //检测中, 悬而未决, 没超阈值, 无异常, 不干预外界操作 - CL_LIMIT_STATE_OBSERVE, //曾经超标过, 观察等待期, 不修改actual_limit_factor_value, 但是也不允许外界操作超过actual_limit_factor_value - CL_LIMIT_STATE_REDUCE, //2:超量, 适当降低factor的值 + CL_LIMIT_STATE_PENDING = 0, + CL_LIMIT_STATE_OBSERVE, + CL_LIMIT_STATE_REDUCE, }cl_limit_state_t; typedef enum{ - CL_STATE_INIT = 0, //初始化阶段 - CL_STATE_RUNNING = 1, //调用了start, 运行阶段 - CL_STATE_TO_BE_DESTORY = 2, //2:准备释放所有资源 + CL_STATE_INIT = 0, + CL_STATE_RUNNING = 1, + CL_STATE_TO_BE_DESTORY = 2, }cl_running_state_t; -static const double g_cpul_limit_min = 1.00; /* 测试时设了一个极低的res阈值, 无论怎么减factor, res都降不下来, 一直降到0为止, 导致无法恢复!! 先内置一个最低值 */ -static const double g_cpul_recovery_bypass_percent = 0.05; /* 在观察期内, bypass占比总数小于此值时, 认为可恢复常态 */ +static const double g_cpul_limit_min = 1.00; +static const double g_cpul_recovery_bypass_percent = 0.05; struct __cpul_mthread_stat{ cl_limit_state_t op_state; - int recent_smooth_index; //平滑平均值数组下标 - double *recent_smooth_res_value; //默认是1, 即只看最近一次的实时值, 实际看用户设置 - double realtime_res_val;//最近一次的资源占用值, 综合计算出来的 + int recent_smooth_index; + double *recent_smooth_res_value; + double realtime_res_val; - double last_time_factor_value;//最近一次用户操作的实际factor值, 比如pps, bps, link_new_create/pps等 - double actual_limit_factor_value; //本次资源限制值, 会随op_state变化 + double last_time_factor_value; + double actual_limit_factor_value; - double history_factor_value[CL_HISTORY_FACTOR_NUM]; //最近N次用户操作的实际factor值, 用于res第一次超阈值后, 选个合适的actual_limit_factor_value + double history_factor_value[CL_HISTORY_FACTOR_NUM]; unsigned int history_factor_index; - //int abnormal_observe_time; //曾经超过阈值, 但已经恢复正常了, 观察等待期时间, 单位:秒 - /* 会随时间变化, 动态更新的变量, 支持多线程 */ - time_t last_abnormal_time; /* 最后一次异常状态的时间, 0表示从来没有出现过异常, last_abnormal_time==current_time, 说明当前时刻就处于异常状态 */ + time_t last_abnormal_time; time_t last_adjust_factor_time; - volatile long long realtime_work_count; /* 实时外部应用请求cpu_limit_can_i_do()函数返回Yes, 即work的次数, 每隔 stat_interval 时间清零 */ - volatile long long realtime_bypass_count; /* 实时外部应用请求cpu_limit_can_i_do()函数返回No, 即bypass的次数, 每隔 stat_interval 时间清零 */ + volatile long long realtime_work_count; + volatile long long realtime_bypass_count; - volatile long long observe_work_count; /* 观察期外部应用请求cpu_limit_can_i_do()函数返回Yes, 即work的次数 */ - volatile long long observe_bypass_count; /* 观察期外部应用请求cpu_limit_can_i_do()函数返回No, 即bypass的次数 */ + volatile long long observe_work_count; + volatile long long observe_bypass_count; - volatile long long debug_factor_work_per_second; /* stat_interval 单位是毫秒, 如果配置了太短的时间间隔统计pps, bps等参数, 误差太大, 所以此值每秒更新一次 */ - volatile long long debug_factor_bypass_per_second; /* stat_interval 单位是毫秒, 如果配置了太短的时间间隔统计pps, bps等参数, 误差太大, 所以此值每秒更新一次 */ + volatile long long debug_factor_work_per_second; + volatile long long debug_factor_bypass_per_second; }__attribute__ ((aligned (64))); typedef struct __cpul_mthread_stat cpul_mthread_stat_t; typedef struct{ - /* 内部私有变量 */ long long header_magic; volatile cl_running_state_t running_state; pthread_t thread_id; @@ -91,18 +77,16 @@ typedef struct{ volatile int global_bypass_state; - /* 用户定义的选项或参数, 启动后固定不变 */ - char *debug_log_filename; //是否开启本地debug日志 + char *debug_log_filename; double user_trigger_value; - double factor_decrease_ratio; /* 超阈值后, factor每次降低的频率 */ - double factor_increase_ratio; /* 观察期, factor每次升高的频率 */ - /* 因为获取时间间隔太短, 经常有cpu占用率为0.0的情况, 所以不能加最低快速恢复阈值 */ - //double user_recovery_value; //低于这个值, 立即恢复正常, 不再限制 + double factor_decrease_ratio; + double factor_increase_ratio; + //double user_recovery_value; int recent_res_smooth_number; - int stat_interval; //每次获取资源间隔时间, 单位ms + int stat_interval; int recovery_observe_time; cl_get_res_t get_res_fun; - cl_get_factor_t get_factor_fun; /* TODO: 要不要这个callbakc呢? 其实从 cpu_limit_can_i_do() 函数就能获取了 */ + cl_get_factor_t get_factor_fun; void *user_arg; cl_destroy_cb_t destroy_cb_fun; int thread_count; @@ -125,7 +109,6 @@ static void cl_get_res(cpu_limit_inner_t *h) this_time_val = tmp_res_val; - /* 根据情况是否需要平滑求平均值 */ if(h->recent_res_smooth_number > 1){ this_stat->recent_smooth_res_value[this_stat->recent_smooth_index] = this_time_val; this_stat->recent_smooth_index++; @@ -159,9 +142,6 @@ static void cl_get_factor(cpu_limit_inner_t *h) } } -/* 连续超过阈值, 每次按之前限制的值倍数减少, - 因为监控CPU周期可能比较短, 避免减的太快, 每秒操作一次 -*/ static inline void cl_update_limit_factor(cpu_limit_inner_t *h, cpul_mthread_stat_t *this_stat, double differ) { if(this_stat->last_adjust_factor_time < h->current_time){ @@ -174,11 +154,6 @@ static inline void cl_update_limit_factor(cpu_limit_inner_t *h, cpul_mthread_sta } } -/* - TODO: 使用最近N次的最大值, 还是平均值呢?? - 最大值可能太抖了, - 平均值可能比较小, -*/ static inline double cl_get_history_max_factor(cpul_mthread_stat_t *this_stat) { int i; @@ -198,12 +173,6 @@ static void cl_analysis_reduce_state(cpu_limit_inner_t *h, int tid, cpul_mthread double history_factor_max_val; if(0 == this_stat->last_abnormal_time){ - /* - TODO: 此处如果之前流量很小, 瞬间忽然来了一大股流量, 导致actual_limit_factor_value很小, - 虽然bypass后cpu不会超阈值, 但是user factor被压制的太小了, 也不合实际!! - - 设置一点静默时间, 首次发现超阈值后, 先观察几秒, 测试一个平均的actual_limit_factor_value. - */ history_factor_max_val = cl_get_history_max_factor(this_stat); this_stat->actual_limit_factor_value = history_factor_max_val * h->factor_decrease_ratio; this_stat->last_abnormal_time = h->current_time; @@ -231,7 +200,6 @@ static int cl_fast_recovery(cpu_limit_inner_t *h, cpul_mthread_stat_t *this_stat recovery = 1; } }else{ - /* 测试时忽然停了流量, 计数全0时也要恢复 */ recovery = 1; } @@ -241,7 +209,6 @@ static int cl_fast_recovery(cpu_limit_inner_t *h, cpul_mthread_stat_t *this_stat static void cl_analysis_observe_state(cpu_limit_inner_t *h, int tid, cpul_mthread_stat_t *this_stat) { if(0 == this_stat->last_abnormal_time){ - /* 可能是从启动以来就没啥事, 或者刚从异常态超时恢复, 保持CL_LIMIT_STATE_PENDING状态 */ this_stat->op_state = CL_LIMIT_STATE_PENDING; return; } @@ -254,12 +221,11 @@ static void cl_analysis_observe_state(cpu_limit_inner_t *h, int tid, cpul_mthrea if((this_stat->observe_work_count + this_stat->observe_bypass_count > 0) && ((double)this_stat->observe_bypass_count/(double)(this_stat->observe_work_count + this_stat->observe_bypass_count) > g_cpul_recovery_bypass_percent)){ - this_stat->last_abnormal_time = h->current_time; /* 观察期还是有很多bypass, 认为还是异常状态, 更新last_abnormal_time */ + this_stat->last_abnormal_time = h->current_time; } - /* 在线测试发现, 某些线程的流量巨小甚至为0, 此时还一直增加actual_limit_factor_value就没有意义了, 判断一下 */ if(this_stat->observe_work_count + this_stat->observe_bypass_count > this_stat->actual_limit_factor_value*0.9){ - cl_update_limit_factor(h, this_stat, h->factor_increase_ratio); /* 每次升高一点点, 让user res在最高阈值附近小范围浮动 */ + cl_update_limit_factor(h, this_stat, h->factor_increase_ratio); } this_stat->op_state = CL_LIMIT_STATE_OBSERVE; @@ -288,7 +254,7 @@ static void cl_analysis(cpu_limit_inner_t *h) } } }else{ - cl_analysis_observe_state(h, tid, this_stat); /* 可能是从没有过攻击, 可能是刚从攻击状态bypass之后恢复过来 */ + cl_analysis_observe_state(h, tid, this_stat); } } @@ -317,16 +283,13 @@ static const char *cl_op_state_ntop(cl_limit_state_t cl_op_state) } -/* - convert time_t to time string like "YY-MM-DD HH:MM:SS". -*/ static char *cl_timet_to_str(time_t timet, char *time_str, int time_str_len) { struct tm *now; if(NULL == time_str || time_str_len <= (int)strlen("YY-MM-DD HH:MM:SS")) { - return (char *)"1970-01-01 error"; /* error! */ + return (char *)"1970-01-01 error"; } now = localtime(&timet); @@ -381,7 +344,7 @@ static void cl_debug_log(cpu_limit_inner_t *h) this_stat->realtime_res_val, this_stat->debug_factor_work_per_second + this_stat->debug_factor_bypass_per_second, this_stat->debug_factor_bypass_per_second, - "infinity"/*无限制*/); + "infinity"); }else{ fprintf(fp, "%9d %7s %9.2f %15lld %18lld %15.2f\n", tid, cl_op_state_ntop(this_stat->op_state), @@ -391,8 +354,8 @@ static void cl_debug_log(cpu_limit_inner_t *h) this_stat->actual_limit_factor_value); } - this_stat->debug_factor_work_per_second = 0; /* 每秒更新一次 */ - this_stat->debug_factor_bypass_per_second = 0; /* 每秒更新一次 */ + this_stat->debug_factor_work_per_second = 0; + this_stat->debug_factor_bypass_per_second = 0; } fprintf(fp, "-------------------------------------------------------------------------------\n"); @@ -437,7 +400,6 @@ static inline long long _cl_get_current_time_in_ms(void) extern int sapp_usleep(int usec); -/* 后台实时统计分析线程, 不占用sapp IO线程的时间片 */ static void *cl_bg_thread(void *_arg_h) { cpu_limit_inner_t *h = (cpu_limit_inner_t *)_arg_h; @@ -457,10 +419,6 @@ static void *cl_bg_thread(void *_arg_h) h->current_time = time(NULL); - /* - get和analysis都结束后, 此处为啥不能直接休眠等一会? 即usleep(h->stat_interval * 1000) ? - 因为以上函数自身耗时可能就很长, 再usleep()那么长时间, 真正usleep的时间肯定比预期的长, 就不准了. - */ while(h->last_analysis_time_ms + h->stat_interval > cur_time_ms){ sapp_usleep(10); cur_time_ms = _cl_get_current_time_in_ms(); @@ -629,7 +587,6 @@ int cpu_limit_can_i_do(cpu_limit_handle _arg_h, int thread_seq) if(this_stat->op_state == CL_LIMIT_STATE_PENDING){ can_i_do = 1; }else{ - /* 在观察期和降低阈值期间, 也不一定就是固定返回0, 看最近的factor值 */ if((double)this_stat->realtime_work_count > this_stat->actual_limit_factor_value){//超限制阈值 can_i_do = 0; }else{ |
