summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-07-12 18:33:09 +0800
committeryangwei <[email protected]>2024-07-12 19:24:26 +0800
commit22585b931e6fad43a8db300a9359f6e3811ffdf4 (patch)
tree1b2e6a934c41a265fd4756aef450bcf717083f81
parentc27eacce8a0b21b0692774d90edc213dc1dd54ea (diff)
🌈 style(header file refomat): remove CN annotationv4.3.61
-rw-r--r--include/private/deal_ipv6.h28
-rw-r--r--include/private/sapp_global_val.h132
-rw-r--r--include/private/sapp_mem.h22
-rw-r--r--include/private/sapp_timer_private.h13
-rw-r--r--include/public/sapp_limits.h8
-rw-r--r--include/public/stream_inc/stream_bridge.h43
-rw-r--r--include/public/stream_inc/stream_rawpkt.h26
-rw-r--r--include/support/cpu_limit.h28
-rw-r--r--include/support/grule.h6
-rw-r--r--include/support/marsio_for_view.h218
-rw-r--r--src/config/config_parse.cpp213
-rw-r--r--src/dealpkt/deal_ipv6.c127
-rw-r--r--src/dealpkt/deal_udp.c114
-rw-r--r--src/dealpkt/stream_manage.c316
-rw-r--r--src/plugin/src/plugin_manage.cpp78
-rw-r--r--src/project/stream_bridge.c11
-rw-r--r--src/support/cpu_limit/cpu_limit.c113
17 files changed, 289 insertions, 1207 deletions
diff --git a/include/private/deal_ipv6.h b/include/private/deal_ipv6.h
index 86a8734..7089831 100644
--- a/include/private/deal_ipv6.h
+++ b/include/private/deal_ipv6.h
@@ -10,21 +10,21 @@
#define IPV6_MAXPLEN (65535)
-#define IPV6_FRAG_RESERVED_HDR_LEN (40) /* Ԥ����һ��IPv6��Ƭͷ������ */
+#define IPV6_FRAG_RESERVED_HDR_LEN (40) /* Ԥ����һ��IPv6��Ƭͷ������ */
-//#define IPV6_FRAG_TIMEOUT (60) /* ���鳬ʱʱ�� */
+//#define IPV6_FRAG_TIMEOUT (60) /* ���鳬ʱʱ�� */
/*
2015-12-02 lijia modify,
- ��ȻRFC�涨, 60�������з�Ƭ������ɾ��ǺϷ���,
- ���ʵ�����, IPv6��Ƭ�����10���ڻ�δ�������, ����Ϊ�ǹ�����Ϊ�򶪰�, ֱ��free.
+ ��ȻRFC�涨, 60�������з�Ƭ������ɾ��ǺϷ���,
+ ���ʵ�����, IPv6��Ƭ�����10���ڻ�δ�������, ����Ϊ�ǹ�����Ϊ�򶪰�, ֱ��free.
*/
-#define IPV6_FRAG_TIMEOUT (10) /* ���鳬ʱʱ�� */
+#define IPV6_FRAG_TIMEOUT (10) /* ���鳬ʱʱ�� */
-#define IPV6_FRAG_MEM_FREE_ONCE (512*1024) /* ÿ���ͷ��ڴ����� */
-#define IPV6_FRAG_MEM_HIGH_THRESH (16*1024*1024) /* �ڴ����� */
+#define IPV6_FRAG_MEM_FREE_ONCE (512*1024) /* ÿ���ͷ��ڴ����� */
+#define IPV6_FRAG_MEM_HIGH_THRESH (16*1024*1024) /* �ڴ����� */
-#define IPV6_FRAG_NUM_PER_IPQ (100) /* ͬһIPQ����Ƭ���� */
+#define IPV6_FRAG_NUM_PER_IPQ (100) /* ͬһIPQ����Ƭ���� */
#if IPV6_DEBUG
#define IPV6_PRINT(fmt, args...) printf(fmt, ##args)
@@ -86,8 +86,8 @@ struct ipv6_hop_hdr{
* fragmentation header
*/
-#define IPv6_FRAG_ISF (1) /* ������һ����Ƭ�� */
-#define IPv6_FRAG_NEW (2) /* ���յ����з�Ƭ��������ɵ��°� */
+#define IPv6_FRAG_ISF (1) /* ������һ����Ƭ�� */
+#define IPv6_FRAG_NEW (2) /* ���յ����з�Ƭ��������ɵ��°� */
#define IP6_MF (0x0001)
@@ -99,16 +99,16 @@ struct ipv6_frag_hdr{
};
struct ipv6_frag_key{
- unsigned int identification; /* ���п��ܲ�ͬ��ֵ���ڽṹ��ǰ�棬�Ƚ�ʱ���һЩ */
- int __pad__; /* ����ṹ8�ֽڶ��� */
+ unsigned int identification; /* ���п��ܲ�ͬ��ֵ���ڽṹ��ǰ�棬�Ƚ�ʱ���һЩ */
+ int __pad__; /* ����ṹ8�ֽڶ��� */
struct in6_addr ip6_src; /* source address */
struct in6_addr ip6_dst; /* dest address */
struct streaminfo_private *pfstream_pr;
};
struct ipv6_frag_private{
- unsigned char raw_next_hdr; /* ԭʼIP���ĵ�һ���ɷ�Ƭ����ͷ������ */
- int unfragmentable_len; /* ԭʼIP���IJ��ɷ�Ƭ���ֳ��� */
+ unsigned char raw_next_hdr; /* ԭʼIP���ĵ�һ���ɷ�Ƭ����ͷ������ */
+ int unfragmentable_len; /* ԭʼIP���IJ��ɷ�Ƭ���ֳ��� */
};
diff --git a/include/private/sapp_global_val.h b/include/private/sapp_global_val.h
index c6975f9..39f5923 100644
--- a/include/private/sapp_global_val.h
+++ b/include/private/sapp_global_val.h
@@ -3,7 +3,6 @@
#include <pthread.h>
#include <netinet/in.h>
-#include <limits.h>
#include "sapp_pkt_stat.h"
#include "sapp_limits.h"
#include "sapp_mem.h"
@@ -17,11 +16,10 @@ enum pkt_dump_mode{
};
-/*
- vxlan��vlan_flipping�ǿ��Թ����?,
- vxlan������������,
- vlan_flipping���ڱ����Լ�����,
-*/
+// vxlan and vlan_flipping can coexist,
+// vxlan is used for online traffic,
+// vlan_flipping is used for local self-check traffic.
+
enum overlay_mode_config{
OVERLAY_MODE_NONE = 0,
OVERLAY_MODE_VXLAN = 1,
@@ -42,10 +40,10 @@ typedef struct{
typedef struct{
int worker_threads;
- int send_only_threads_max_num; /* �������߳��������?, �Dz����̬������?, sapp�����޷�Ԥ֪, ֻ��������ֵ */
+ int send_only_threads_max_num;
int bind_mask_array_num;
long bind_mask_array[SAPP_MAX_THREADS];
- long bind_mask; /* bind_mask_array�е�ÿ��������Ϊbit_indexת�ɵ�����ֵ */
+ long bind_mask;
}sapp_config_cpu_t;
@@ -65,8 +63,8 @@ typedef struct{
char *storge_path;
int dump_all_thread_enabled;
int dump_thread_id_array_num;
- int dump_thread_id_array[SAPP_MAX_THREADS]; /* �û������ļ�ԭʼ����, ��ʽ: [0,1,2,3], ��ʾ��0,1,2,3���߳����ò��� */
- unsigned char dump_thread_id_mask[SAPP_MAX_THREADS]; /* ����ԭʼ������������������, ���߳�id��Ϊ�±�, ֵ��Ϊ0��ʾ��ǰ�߳̿�������, ֵ:{1,1,1,1} */
+ int dump_thread_id_array[SAPP_MAX_THREADS];
+ unsigned char dump_thread_id_mask[SAPP_MAX_THREADS];
int pkt_dump_ratio; /* capture one packet every 'pkt_dump_ratio' packets */
}sapp_config_tools_pktdump_t;
@@ -81,13 +79,13 @@ typedef struct{
typedef struct{
- int auto_remedy; /* ƽ̨ȫ������, ����ÿ����, ��������auto_remedy_flag, ���ȼ�����ȫ��auto_remedy */
+ int auto_remedy;
int rst_signature_enable;
int rst_num;
int rst_signature_seed1;
int rst_signature_seed2;
int link_mss;
- int remedy_kill_tcp_by_inline_device; /* ����FD����Чʱ, ����inline device�·�DROP���� */
+ int remedy_kill_tcp_by_inline_device;
}sapp_config_stream_tcp_inject_t;
@@ -102,7 +100,7 @@ typedef struct{
int meaningful_statistics_minimum_byte;
sapp_config_stream_tcp_inject_t inject;
int well_known_ports_array_num;
- unsigned short *well_known_ports_array; /* ���ڰ�data������ȷ��server�� */
+ unsigned short *well_known_ports_array;
int closing_timeout;
int opening_timeout;
int max_timeouts_per_sec;
@@ -117,7 +115,7 @@ typedef struct{
int timeout;
int meaningful_statistics_minimum_pkt;
int meaningful_statistics_minimum_byte;
- unsigned short *well_known_ports_array; /* �����½�����ȷ��server��, ����4001->8000, ʵ������OICQ��C2S�������ݰ�,֮ǰ�İ汾�ᱻ��ʶ��ΪS2C�����? */
+ unsigned short *well_known_ports_array;
int well_known_ports_array_num;
int max_timeouts_per_sec;
int max_opening_per_sec;
@@ -159,14 +157,8 @@ typedef struct{
int histogram_enabled;
char process_latency_local_file[NAME_MAX];
int process_latency_refresh_interval_s;
- int process_latency_threshold_in_us; /* �����ļ��ﵥλ��microsecond, ��Ҫ����1000 */
- /* ��ȷģʽ������, fs2����ͳ��Ҳ�dz���CPU, ÿ������Ҫ����FS_operate(),
- ���ͣ�þ�ȷģ�?, ����fs2���DZ������һ��ʱ�������?, ��Сֵ����һ��ʱ���ƽ���?, ������FS_operate()����,
- ��ȷ�Ƚ�����һЩ, ���������˵���FS_operate()�Ĵ���.
- ����pkt_latency_accurate_enable��ƽ��ֵ�����ǶԵ�, ����׼��Ͳ�׼��?.
- */
+ int process_latency_threshold_in_us;
int process_latency_clock_id;
-
int sanity_check_raw_pkt_broken_enabled;
int sanity_check_symbol_conflict_enabled;
int memory_used_stat_interval_s;
@@ -175,7 +167,7 @@ typedef struct{
typedef struct{
char type_str[NAME_MAX]; /* pag,pcap,marsio */
char name[NAME_MAX];
- enum cap_mode_t type_bin; /* ���ַ���typeת��Ϊ��������ֵ */
+ enum cap_mode_t type_bin;
}sapp_config_packet_io_interface_t;
@@ -191,10 +183,10 @@ enum __sapp_config_packet_io_deployment_mode{
SAPP_CFG_PKT_IO_DEPOLY_MODE_TRANSPARENT,
};
-#define MAX_VLAN_FLIPPING_MAP_NUM (4096) /* vlan_id���Χ��?0~4095, ���鳤����4096 */
+#define MAX_VLAN_FLIPPING_MAP_NUM (4096)
typedef struct{
- unsigned short couple_vlan_id; /* vlan flipping�dzɶԴ���, �����±��ʾһ��vlanid, Ԫ�ص�ֵ����һ��vlanid, host order */
+ unsigned short couple_vlan_id;
unsigned char this_vlan_route_location; // 'C' or 'I'
unsigned char mac_flipping_enable;
}sapp_vlan_flipping_map_t;
@@ -232,46 +224,46 @@ typedef struct{
typedef struct{
int enabled;
- int get_cpu_usage_interval; //��λ:����, milliseconds(ms)
- int smooth_avg_window; //�����N�ε�ƽ��ֵ����ʵʱֵ, ���ⶶ��
+ int get_cpu_usage_interval; // milliseconds(ms)
+ int smooth_avg_window;
double bypass_trigger_cpu_usage;
double factor_decrease_ratio;
double factor_increase_ratio;
- int recovery_observe_time; //��λ:��, second(s)
+ int recovery_observe_time;
}sapp_under_ddos_config_t;
typedef struct{
sapp_config_packet_io_tunnel_t packet_io_tunnel;
const char *input_bpf_filter;
char deployment_mode_str[NAME_MAX]; /* [mirror, inline, transparent, dumpfile] */
- enum sapp_deploment_mode_t deployment_mode_bin; /* ��������ڴ���?, ת����ֵ��ʽ, ��1:mirror; 2:transparent; 3:inline��, ���?: enum sapp_deploment_mode_t */
+ enum sapp_deploment_mode_t deployment_mode_bin;
sapp_config_packet_io_dev_t internal;
sapp_config_packet_io_dev_t external;
char pcap_dumpfile_name[NAME_MAX];
- int polling_priority; /* call sapp_recv_pkt every call polling_entry times, ���ö��ٴ�polling�����һ��recv pkt, 1��ʾ�������ȼ���ͬ */
+ int polling_priority; /* call sapp_recv_pkt every call polling_entry times */
int work_percent;
- int without_usleep; /* ���ܲ���ģʽ, �������usleep, CPU��100% */
- int inbound_route_dir; /* ��ʾ�뾳, I2C�����ֵ��?0����1 */
+ int without_usleep;
+ int inbound_route_dir;
char pcap_capture_direction[NAME_MAX]; /* in, out, inout */
char inject_pkt_mode_string[NAME_MAX];
- int inject_pkt_mode; /* ��ע�뷽ʽ������ֵ, ���?: enum send_fake_packet_mode */
+ int inject_pkt_mode;
int inject_pkt_prepend_segment_id;
- unsigned short inject_mode_inline_device_sport; /* udp socket�󶨵ı���Դ�˿�, host order, ������ */
+ unsigned short inject_mode_inline_device_sport;
char inject_mode_single_gateway_device[NAME_MAX];
char inject_mode_single_gateway_src_mac_string[20];
char inject_mode_single_gateway_dst_mac_string[20];
- char inject_mode_single_gateway_dst_mac[6]; /* gateway��MAC */
- char inject_mode_single_gateway_src_mac[6]; /* inject_mode_single_gateway_device������MAC */
- int monitor_thread_enabled; /* ����ģʽ�˳�֮ǰ, Ϊ��ijЩ�߳��ܻ�д��־, �첽�������ݵȲ���, ��sleepһ�� */
- sapp_dup_pkt_t dup_pkt_para; /* �ظ�����ʶ�� */
+ char inject_mode_single_gateway_dst_mac[6];
+ char inject_mode_single_gateway_src_mac[6];
+ int monitor_thread_enabled;
+ sapp_dup_pkt_t dup_pkt_para;
char extract_linkdir_from_mac_sntax_raw_string[32];
char extract_linkdir_from_mac_enabled;
- unsigned char extract_linkdir_from_mac_byte_index; /* ��mac��ַ�ĵڼ����ֽڻ�ȡ��·����, ��0��ʼ��11����, �ܼ�12�ֽ� */
- unsigned char extract_linkdir_from_mac_bit_value; /* ��ij���ֽڻ�ȡ��·�����bitֵ, ������index, ����ֱ�ӽ���&���� */
+ unsigned char extract_linkdir_from_mac_byte_index;
+ unsigned char extract_linkdir_from_mac_bit_value;
sapp_under_ddos_config_t under_ddos_config;
- short not_exit_for_dumpfile_mode; /* �����������˳�����, �������Բ���, ���ѭ����ȡ����� */
+ short not_exit_for_dumpfile_mode;
short infinite_loop_enabled;
short destroy_all_plug_enabled;
short dlclose_all_plug_enabled;
@@ -284,7 +276,7 @@ typedef struct{
typedef struct{
const char *cfg_files_root_dir;
- const char *cfg_main_entry_relative; /* �������ļ�, �̶���sapp.toml, ·�����Կ�-c����ָ�� */
+ const char *cfg_main_entry_relative;
const char *cfg_main_entry_absolute; /* /home/project_xxx/sapp/sapp.toml */
const char *cfg_sapp_log_relative;
@@ -308,7 +300,7 @@ typedef struct{
const char *cfg_file_inline_dev_relative;
const char *cfg_file_inline_dev_absolute;
- const char *cfg_file_necessary_plug_relative; /* ��Ҫ����б�?, �������ʧ��sapp���˳� */
+ const char *cfg_file_necessary_plug_relative;
const char *cfg_file_necessary_plug_absolute;
const char *cfg_file_stream_compare_layer_relative;
@@ -354,17 +346,17 @@ typedef struct{
}sapp_data_file_link_t;
typedef struct{
- const char *libmarsio_file_path; /* libmarsio.so�Ƕ�̬dlopen��, ��sapp���Ȳ�һ��֪�����ĸ�·��, �������ļ���ȡ */
+ const char *libmarsio_file_path;
}sapp_library_file_link_t;
typedef struct{
- int ipv6_decapsulation_enabled; /* �Ƿ����ipv6���ݰ� */
- int ipv6_send_packet_enabled; /* �Ƿ�֧�ַ���ipv6���ݰ�, ��������ϵͳipv6�ں�ģ���Ƿ����? */
- int tcp_drop_pure_ack_pkt; /* ����û�и��صĴ�ack��, ���Խ�Լһ��������ѯ, ����ҵ���������� */
- int tcp_syn_option_parse_enabled; /* �Ƿ����tcp syn��ͷ��ѡ�� */
- int skip_not_ip_layer_over_eth; /* ������ip��, ��֤�ڲ���ģʽ��, ����ͨ��ϵͳ·�ɷ���rst�� */
- int reverse_ethernet_addr_enabled; /* smac��ַ�а���������Ϣʱ���跭ת */
- int skip_gtp_S_PN_E_field_for_inject; /* GTP����ע�����ݰ�ʱ������չ�ֶ�:sequence,N-PDU, extension */
+ int ipv6_decapsulation_enabled;
+ int ipv6_send_packet_enabled;
+ int tcp_drop_pure_ack_pkt;
+ int tcp_syn_option_parse_enabled;
+ int skip_not_ip_layer_over_eth;
+ int reverse_ethernet_addr_enabled;
+ int skip_gtp_S_PN_E_field_for_inject;
int ipv4_reassembly_enabled;
int ipv6_reassembly_enabled;
int skip_gtp_layer;
@@ -412,29 +404,29 @@ typedef struct{
void *sapp_timer_handle[SAPP_MAX_THREADS];
void *sapp_standalone_timer;
time_t sapp_start_time;
- int deployment_mode_private; /* ��������sapp_global_val->config.packet_io.deployment_mode_binת���õ����ڲ�ֵ,����:NET_CONN_PARALLEL */
- unsigned char create_stream_mode; /* ����ԭ�����߼�, ֵ������stream.tcp.syn_mandatoryת���õ� */
+ int deployment_mode_private;
+ unsigned char create_stream_mode;
int packet_io_cap_level;
sapp_gval_individual_fixed_fs2_t fs2_runtime;
sapp_gval_individual_fixed_fs3_t fs3_runtime;
- pthread_t thread_obtain_id[SAPP_MAX_THREADS]; /* pthread_create���ص�id */
- pid_t thread_tid[SAPP_MAX_THREADS]; /* gdb �� top �鿴��id */
+ pthread_t thread_obtain_id[SAPP_MAX_THREADS];
+ pid_t thread_tid[SAPP_MAX_THREADS];
pthread_t thread_timer_event_id;
pthread_t thread_timer_loop_id;
- int cpu_bind_core_id_per_thread[SAPP_MAX_THREADS]; /* ���������bind_mask, ��¼ÿ��IO�����̰߳󶨵�cpu core id */
+ int cpu_bind_core_id_per_thread[SAPP_MAX_THREADS];
void *breakpad;
- char overlay_layer_def[__ADDR_TYPE_MAX][SAPP_SUPPORT_LAYER_NUM_MAX]; /* ��ʾ��ԭʼ���Ļ����Ϸ�װ������, ��vxlan, ��Щ�㲻Ӧ�õ��ò��?, ��עʱ��Ҫ���⴦�� */
- char prune_layer_def[__ADDR_TYPE_MAX][SAPP_SUPPORT_LAYER_NUM_MAX]; /* ��ʾע���ʱ��Ҫ�����IJ�?, ���ڴ�������������ļ�?: skip_not_iop_layer, ����vlan, mpls��, ����mirrorģʽ��, ������ע��㲻һ�������绷��? */
+ char overlay_layer_def[__ADDR_TYPE_MAX][SAPP_SUPPORT_LAYER_NUM_MAX];
+ char prune_layer_def[__ADDR_TYPE_MAX][SAPP_SUPPORT_LAYER_NUM_MAX];
void *under_ddos_handle;
pthread_t gdev_keepalive_log_thread_id;
}sapp_gval_individual_fixed_t;
typedef struct{
- unsigned long long count[SAPP_STAT_NUM_MAX]; /* ������, �����?, �½�������, ������������ */
- unsigned long long length[SAPP_STAT_NUM_MAX]; /* ������, �����ݰ����ֽ��� */
+ unsigned long long count[SAPP_STAT_NUM_MAX];
+ unsigned long long length[SAPP_STAT_NUM_MAX];
unsigned long long count_per_layer[__ADDR_TYPE_MAX][SAPP_SUPPORT_LAYER_NUM_MAX];
unsigned long long length_per_layer[__ADDR_TYPE_MAX][SAPP_SUPPORT_LAYER_NUM_MAX];
unsigned long long count_project_in_use[PROJECT_REQ_MAX_PLUG_NUM];
@@ -443,7 +435,7 @@ typedef struct{
typedef struct{
- int stat_count; /* һ��ʱ����, ��¼�����ݰ���ʱ����, time_cost_sum/stat_count��ƽ����ʱ */
+ int stat_count;
int min_time_cost;
int max_time_cost;
long long time_cost_sum;
@@ -456,11 +448,11 @@ typedef struct{
struct __sapp_gval_mthread{
sapp_gval_mthread_sys_stat_t sys_stat;
- unsigned short stream_seq_per_thread; /* ���ڼ���ȫ����ID */
+ unsigned short stream_seq_per_thread;
sapp_fuzzy_latency_stat_t fuzzy_pkt_latency_stat_per_thread;
sapp_fuzzy_latency_stat_t fuzzy_pkt_latency_stat_per_entry_per_thread[SAPP_MAX_PLUG_ENTRY_NUM];
- const raw_pkt_t *raw_pkt; /* ��ΪMESA_fakepacket_send_xxxϵ�к���û��raw_pkt����, Ҳû��stream_info, Ϊ����ǰ����, �����޸Ľӿ�, ����ȫ�ֱ������ڴ洢��ǰ�� */
- void *dup_pkt_distinguish_handle; /* ����������ڿ���?, inject, ipv4_tcp, ipv4_udp, ��ͬʹ��һ��bloom���? */
+ const raw_pkt_t *raw_pkt;
+ void *dup_pkt_distinguish_handle;
volatile int destory_env_done; //0:do nothing; 1:doing; 2:done
sapp_mem_used_stat_t mem_used_stat;
}__attribute__ ((aligned (64))); /* for multi-thread, must 64byte alignment */
@@ -469,8 +461,8 @@ typedef struct __sapp_gval_mthread sapp_gval_mthread_t;
struct __sapp_gval_individual_volatile{
volatile int current_state; /* refer to enum sapp_state_t */
- volatile int recv_signal_SIGTERM; /* �յ�SIGTERM�ź�, ���ŵ��˳� */
- sapp_mem_used_stat_t mem_used_stat; /* ȫ�ֱ������ʼ���Ͳ�����ڴ� */
+ volatile int recv_signal_SIGTERM;
+ sapp_mem_used_stat_t mem_used_stat;
}__attribute__ ((aligned (64)));
typedef struct __sapp_gval_individual_volatile sapp_gval_individual_volatile_t;
@@ -478,17 +470,17 @@ typedef struct __sapp_gval_individual_volatile sapp_gval_individual_volatile_t;
typedef struct{
sapp_cmd_args_val_t **cmd_args_array;
int cmd_args_num;
- char **dumpfie_list_array; /* ����--dumpfile-list����ִ�к�, �õ����ļ��б�, �ַ���ָ������ */
- int slient_mode; /* ��Ĭģʽ, ǰ̨������κ����? */
+ char **dumpfie_list_array;
+ int slient_mode;
}sapp_cla_t;
typedef struct{
sapp_cla_t cla;
sapp_config_t config;
- sapp_gval_individual_fixed_t individual_fixed; /* ��ʼ�����ٸı�ı���? */
- sapp_gval_individual_volatile_t *individual_volatile; /* �����������ʵʱ���µĶ�������? */
- sapp_gval_mthread_t *mthread_volatile[SAPP_MAX_THREADS]; /* �����������ʵʱ���µĶ��̱߳���? */
+ sapp_gval_individual_fixed_t individual_fixed;
+ sapp_gval_individual_volatile_t *individual_volatile;
+ sapp_gval_mthread_t *mthread_volatile[SAPP_MAX_THREADS];
}sapp_global_t;
extern embed_layer_t g_stream_compare_layer_set;
diff --git a/include/private/sapp_mem.h b/include/private/sapp_mem.h
index b6b6ca8..84f4107 100644
--- a/include/private/sapp_mem.h
+++ b/include/private/sapp_mem.h
@@ -5,32 +5,32 @@
extern "C" {
#endif
-#define MEM_STAT_GLOBAL_THREAD_ID -1 /* 全局变量内存的thread_id, 其实没有用, 保持接口一致, 用于非IO线程 */
+#define MEM_STAT_GLOBAL_THREAD_ID -1 /* ȫ�ֱ����ڴ��thread_id, ��ʵû����, ���ֽӿ�һ��, ���ڷ�IO�߳� */
typedef enum{
__SAPP_MEM_TYPE_INIT = 0,
- SAPP_MEM_STACK_LOCAL, /* 函数栈里临时申请的内存, 函数返回就会被释放 */
+ SAPP_MEM_STACK_LOCAL, /* ����ջ����ʱ������ڴ�, �������ؾͻᱻ�ͷ� */
SAPP_MEM_FIX_GLOBAL_VAL,
SAPP_MEM_FIX_GLOBAL_STREAM,
- SAPP_MEM_FIX_PLUG_CTRL, /* 插件管理初始化必需的相关数据结构, 跟每个流动态挂载的插件无关 */
+ SAPP_MEM_FIX_PLUG_CTRL, /* ���������ʼ�������������ݽṹ, ��ÿ������̬���صIJ���޹� */
/*******************************************
- 以上是全局变量, 或初始化后不变的内存
+ ������ȫ�ֱ���, ���ʼ���󲻱���ڴ�
*******************************************/
__SAPP_FIX_DYN_SEPARATOR,
/*******************************************
- 以下是多线程动态内存
+ �����Ƕ��̶߳�̬�ڴ�
*******************************************/
- SAPP_MEM_DYN_MEM_HDR, /* 为了增加这个统计, 增加的内存头部消耗 */
- SAPP_MEM_DYN_IP_FRAG_PKT, /* 不太容易区别ipv4和ipv6, 此处统一计数 */
+ SAPP_MEM_DYN_MEM_HDR, /* Ϊ���������ͳ��, ���ӵ��ڴ�ͷ������ */
+ SAPP_MEM_DYN_IP_FRAG_PKT, /* ��̫��������ipv4��ipv6, �˴�ͳһ���� */
SAPP_MEM_DYN_TCP_STREAM,
SAPP_MEM_DYN_UDP_STREAM,
- SAPP_MEM_DYN_TCP_HALF_STREAM, /* c2s, s2c半流结构 */
+ SAPP_MEM_DYN_TCP_HALF_STREAM, /* c2s, s2c�����ṹ */
SAPP_MEM_DYN_UDP_HALF_STREAM,
- SAPP_MEM_DYN_PLUG_CTRL, /* 每个流插件管理必需的相关数据结构, 但不包括业务插件使用的内存 */
+ SAPP_MEM_DYN_PLUG_CTRL, /* ÿ����������������������ݽṹ, ��������ҵ����ʹ�õ��ڴ� */
SAPP_MEM_DYN_TCP_UNORDER,
SAPP_MEM_DYN_TCP_SYN_OPT,
SAPP_MEM_DYN_TCP_POLLING_RAW_PKT,
@@ -39,11 +39,11 @@ typedef enum{
SAPP_MEM_DYN_UDP_DETAIL,
SAPP_MEM_DYN_TCP_FLOW_STAT,
SAPP_MEM_DYN_UDP_FLOW_STAT,
- SAPP_MEM_DYN_TCP_PROJECT, /* 仅包括project必需的管理结构, 但不包括插件在project_add时申请的内存 */
+ SAPP_MEM_DYN_TCP_PROJECT, /* ������project����Ĺ����ṹ, �������������project_addʱ������ڴ� */
SAPP_MEM_DYN_UDP_PROJECT,
SAPP_MEM_DYN_TCP_BRIDGE,
SAPP_MEM_DYN_UDP_BRIDGE,
- SAPP_MEM_DYN_PADDR, /* 每层地址所占的内存, 就不分具体协议了, 太麻烦了!! */
+ SAPP_MEM_DYN_PADDR, /* ÿ���ַ��ռ���ڴ�, �Ͳ��־���Э����, ̫�鷳��!! */
SAPP_MEM_DYN_DETAIN_PKT,
SAPP_MEM_DYN_SID_LIST,
SAPP_MEM_DYN_BLOOM_FILTER,
diff --git a/include/private/sapp_timer_private.h b/include/private/sapp_timer_private.h
index cbb92a8..ca100ac 100644
--- a/include/private/sapp_timer_private.h
+++ b/include/private/sapp_timer_private.h
@@ -18,25 +18,18 @@ enum st_ef_scope_t{
#ifdef LIBEVENT_ENABLED
#include "support/event2/event.h"
#endif
-/*
- NOTE:
- 1.ÿ���߳�ֻ��һ��ev_base, ����ǰ������߳�����, ����thread_cnt��, ���ԺͶ����߳�һ����.
- 2.add, newֻ����event�����̵߳���, ����ֻ�ڵ�ǰ�߳���Ч.
-*/
+
+
typedef struct{
volatile MESA_ATOMIC_T running;
enum st_ef_scope_t effective_mode;
-#ifdef LIBEVENT_ENABLED
struct event_base *libev_base;
-#endif
+ //struct event *libev_event[SAPP_MAX_THREADS+1];
pthread_t effective_thread_pid;
int effective_thread_index;
int event_cnt;
-
- //int thread_cnt; /* sappƽ̨ʵ�ʲ����߳���, �����stand_alone�߳�, ��̶��洢�����һ��index, ��SAPP_TIMER_MAX_THREADS */
}sapp_timer_handle_inner_t;
-/* event��Ҫʹ��set_opt���ø��ֲ���, �ýṹ�彫��׼struct event��װ, �洢��ز��� */
typedef struct{
sapp_timer_handle_inner_t *timer_handle;
#ifdef LIBEVENT_ENABLED
diff --git a/include/public/sapp_limits.h b/include/public/sapp_limits.h
index 0d1d295..a0a1db3 100644
--- a/include/public/sapp_limits.h
+++ b/include/public/sapp_limits.h
@@ -7,15 +7,15 @@
#define SAPP_MAX_THREADS MAX_THREAD_NUM
-#define SAPP_SUPPORT_LAYER_NUM_MAX (15) /* sapp平台支持的最大嵌套层数, 与struct streaminfo_private->layer_index相关 */
-#define SAPP_PRUNE_LAYER_NUM_MAX (10) /* sapp平台支持的最大修剪配置条数 */
+#define SAPP_SUPPORT_LAYER_NUM_MAX (15)
+#define SAPP_PRUNE_LAYER_NUM_MAX (10)
#ifndef MTU_MAX
#define MTU_MAX 2000
#endif
-#define SAPP_MAX_PLUG_NUM (128) /* 所有插件数量最大值 */
-#define SAPP_MAX_PLUG_ENTRY_NUM (256) /* 所有插件的entry数量最大值 */
+#define SAPP_MAX_PLUG_NUM (128)
+#define SAPP_MAX_PLUG_ENTRY_NUM (256)
#define STATS_STR_LEN (32)
diff --git a/include/public/stream_inc/stream_bridge.h b/include/public/stream_inc/stream_bridge.h
index eb00f73..a0c423f 100644
--- a/include/public/stream_inc/stream_bridge.h
+++ b/include/public/stream_inc/stream_bridge.h
@@ -5,19 +5,9 @@
extern "C" {
#endif
-#include <errno.h>
-
/***************************************** stream bridge API *************************************************
- stream_bridge_xxx接口用于在不同插件之间, 创建一个通道, 支持同步和异步两种方式互相通信, 支持多对多的关系.
-
- 同步模式采用callback注册方式, 避免直接使用extern声明函数, 动态、灵活、可扩展.
- 异步模式是在streaminfo中保留一份数据, 功能同之前的project_req_xxx系列接口.
-
- 假设插件plug A,X,Y,Z都注册同一个bridge name:"bridge_demo", bridge_id=1,
-
- plug A使用异步模式在streaminfo, bridge=1的空间存储了一份数据, receiver X,Y,Z可以在streaminfo生存周期内取数据.
-------------------
| streaminfo | plug X
|-----------------| /
@@ -29,7 +19,6 @@ extern "C" {
-------------------
- plugA发送一条同步消息, receiver X,Y,Z都可以依次收到.
-------------------- plug X
| /
@@ -42,16 +31,11 @@ extern "C" {
/*
- bridge_name: 全局唯一, 与之前的project使用不同的命名空间, 可以重名,
- 但是bridge_id与project_req_id不能通用!!!
+ bridge_name: unique name
- rw_mode类似fopen函数的参数, 只支持两个模式:
- "r": 只读,bridge_name不存在则返回错误;
- "w": bridge_name不存在则创建一个新的bridge,
- 注意, 如果其他插件已经创建了同名bridge, 再次用"w"模式打开, 不能像fopen以截断模式重新打开一个文件, 其实bridge_id是一样的!
- 建议先用"r"模式验证是否有无同名bridge;
+ "r": read only;
+ "w": bridge_name is write only;
- 返回值是bridge_id,
>=0 : success
<0 : error
*/
@@ -63,33 +47,28 @@ typedef int stream_bridge_sync_cb_t(const struct streaminfo *stream, int bridge
/*
- 注意: free函数最多只能有一个, 后面会覆盖前面的函数指针, 多次重复注册只保留最后一个!
+ free cb wille be overwrites by new free cb, if call register more than one time.
*/
int stream_bridge_register_data_free_cb(int bridge_id, stream_bridge_free_cb_t *free_cb_fun);
-/* sync回调函数可以是多个, 调用stream_bridge_sync_data_put()时, 会调用所有注册的callback函数 */
+/* every sync_cb will be trigger when stream_bridge_sync_data_put() being called */
int stream_bridge_register_data_sync_cb(int bridge_id, stream_bridge_sync_cb_t *sync_cb_fun);
/*
- 返回值:
- 0: 没有stream_bridge_sync_cb_t函数;
+ 0: without stream_bridge_sync_cb_t;
-1: error
- N: 成功调用stream_bridge_sync_cb_t函数的数量;
+ N: number of stream_bridge_sync_cb_t being called;
*/
int stream_bridge_sync_data_put(const struct streaminfo *stream, int bridge_id, void *data);
-/* 等同于之前的project_req_add_xxx, 注意如果data是malloc的内存, 要注册stream_bridge_free_cb_t, streaminfo在close时会自动free */
+/* equal to project_req_add_xxx */
int stream_bridge_async_data_put(const struct streaminfo *stream, int bridge_id, void *data);
/*
- 返回值:
- 非NULL: 插件曾经调用stream_bridge_async_data_put()存储的data值.
- NULL : 此时会产生一种歧义, 如果stream_bridge_async_data_put()就是存了一个空指针, 或者利用C的特性, 存了一个整数0,
- 如何区别是错误还是原始数据就是0?
-
- 如果返回值是NULL的情况下, 插件要再判断一下errno, errno == ENODATA (61), 说明确实没有插件曾经存储过数据, 是个错误.
+ Not NULL: put data.
+ NULL: if return NULL, need to get errno, if errno == ENODATA (61), means bridge not exist.
*/
-void *stream_bridge_async_data_get(const struct streaminfo *stream, int bridge_id); /* 等同于之前的project_get_xxx */
+void *stream_bridge_async_data_get(const struct streaminfo *stream, int bridge_id);
#ifdef __cplusplus
diff --git a/include/public/stream_inc/stream_rawpkt.h b/include/public/stream_inc/stream_rawpkt.h
index cf9f35f..7c709c2 100644
--- a/include/public/stream_inc/stream_rawpkt.h
+++ b/include/public/stream_inc/stream_rawpkt.h
@@ -24,8 +24,8 @@ enum{
RAW_PKT_GET_VXLAN_VPNID, // network-order, VPN_ID, value type is int, out_value should be int *
RAW_PKT_GET_VXLAN_LOCAL_IP, // network-order, VXLAN Local IP, value type is int, out_value should be int *
- RAW_PKT_GET_ORIGINAL_LOWEST_ETH_SMAC, /* value type is char[6],真实原始包最外层的smac地址,mirror模式下, 等同于RAW_PKT_GET_DATA, 或者使用stream->pfather自行偏移; inline + vxlan + mrtunnat模式下, 等同于RAW_PKT_GET_VXLAN_OUTER_GDEV_MAC; */
- RAW_PKT_GET_ORIGINAL_LOWEST_ETH_DMAC, /* value type is char[6],真实原始包最外层的dmac地址,mirror模式下, 等同于RAW_PKT_GET_DATA, 或者使用stream->pfather自行偏移; inline + vxlan + mrtunnat模式下, 等同于RAW_PKT_GET_VXLAN_OUTER_LOCAL_MAC; */
+ RAW_PKT_GET_ORIGINAL_LOWEST_ETH_SMAC, /* value type is char[6], */
+ RAW_PKT_GET_ORIGINAL_LOWEST_ETH_DMAC, /* value type is char[6], */
RAW_PKT_GET_ROUTE_CTX, /* get current stream route_dir route_ctx, max value size char[64] */
RAW_PKT_GET_SID_LIST, /* get current stream route_dir route_ctx, value defined in stream_control.h, struct segment_id_list */
@@ -44,7 +44,6 @@ extern "C" {
get option from raw packet.
for example:
- CHN : 获取原始包数据, (根据捕包类型的不同, 可能从MAC开始, 也可能从IP头部开始, 需要使用RAW_PKT_GET_RAW_PKT_TYPE获取);
ENG : get raw packet header, header's type depend on raw pacekt type, you should use RAW_PKT_GET_RAW_PKT_TYPE first;
void *raw_pkt_data;
@@ -57,17 +56,14 @@ for example:
error!
}
- CHN : 获取原始包总长度;
ENG : get raw packet size;
int tot_len;
get_opt_from_rawpkt(voidpkt, RAW_PKT_GET_TOT_LEN, &tot_len);
- CHN : 获取本层包头起始地址:
ENG : get this layer header;
void *this_layer_hdr;
get_opt_from_rawpkt(voidpkt, RAW_PKT_GET_THIS_LAYER_HDR, &this_layer_hdr);
- CHN : 获取原始包时间戳, 如果网卡或底层捕包库不支持时间戳功能, 值为全0:
ENG : get raw packet timestamp, maybe zero if network card or library not support.
struct timeval pkt_stamp;
get_opt_from_rawpkt(voidpkt, RAW_PKT_GET_TIMESTAMP, &pkt_stamp);
@@ -79,34 +75,22 @@ for example:
int get_opt_from_rawpkt(const void *rawpkt, int type, void *out_value);
/*
- CHN: 功能同上, 传入参数不同.
ENG: Function ibid, except args pstream.
*/
int get_rawpkt_opt_from_streaminfo(const struct streaminfo *pstream, int type, void *out_value);
/*
TCP UDP only
- 获取流在当前包中对应的l3或者l4头部起始位置,
*/
const void *get_current_layer3_header(const struct streaminfo *pstream);
const void *get_current_layer4_header(const struct streaminfo *pstream);
/*
- CHN : 数据包头部偏移函数.
- ENG :
-
- 参数:
- raw_data: 当前层的头部指针;
- raw_layer_type: 当前层的地址类型, 详见: enum addr_type_t ;
- expect_layer_type: 期望跳转到的地址类型, 详见: enum addr_type_t ;
-
- 返回值:
- NULL: 无此地址;
- NON-NULL: 对应层的头部地址.
+ NULL: layer not exist;
+ NON-NULL: layer start buff
- 举例:
- 假设当前层为Ethernet, 起始包头地址为this_layer_hdr, 想跳转到IPv6层头部:
+ Ethernet, jump to ipv6 header:
struct ip6_hdr *ip6_header;
ip6_header = MESA_jump_layer(this_layer_hdr, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
*/
diff --git a/include/support/cpu_limit.h b/include/support/cpu_limit.h
index 4f83004..39a2248 100644
--- a/include/support/cpu_limit.h
+++ b/include/support/cpu_limit.h
@@ -6,27 +6,27 @@ extern "C" {
#endif
typedef void * cpu_limit_handle;
-typedef double (*cl_get_res_t)(cpu_limit_handle h, int thread_seq, void *user_arg);//thread_seq范围: [0,CL_OPT_THREAD_COUNT-1]
-typedef double (*cl_get_factor_t)(cpu_limit_handle h, int thread_seq,void *user_arg);//thread_seq范围: [0,CL_OPT_THREAD_COUNT-1]
+typedef double (*cl_get_res_t)(cpu_limit_handle h, int thread_seq, void *user_arg);//thread_seq: [0,CL_OPT_THREAD_COUNT-1]
+typedef double (*cl_get_factor_t)(cpu_limit_handle h, int thread_seq,void *user_arg);//thread_seq: [0,CL_OPT_THREAD_COUNT-1]
typedef void (*cl_destroy_cb_t)(cpu_limit_handle h, void *user_arg);
typedef enum{
/* set options */
CL_OPT_DEBUG_LOG_FILE_NAME,
- CL_OPT_RES_TRIGGER_THRESHOLD, //double, 把资源限制在某个数值内, 比如限速到1Mbps, CPU占用率最大60%, 等等
- CL_OPT_THREAD_COUNT, //int ,是否支持多线程模式, 线程数量, 默认是1,
- CL_OPT_RES_SMOOTH_SCOPE, //int, 为了平滑资源占用统计, 避免抖动, 使用最近N次的平均值, 假如统计CPU占用率设成10, 即最近10次的CPU平均值. 如果无此选项, 默认是1
- CL_OPT_STAT_INTERVAL, //int ,获取当前资源占用时间间隔, 单位ms, 默认1000, 即1秒
- CL_OPT_OBSERVE_TIME, //int, 单位:秒, 为了避免抖动, 发现异常后, 即使降低到CL_OPT_RES_TRIGGER_THRESHOLD以下, 短时间内暂不恢复正常状态
- CL_OPT_RES_GET_FUN, // cl_get_res_t, 获取当前资源占用函数指针
- CL_OPT_FACTOR_GET_FUN, // 获取当前占用资源的操作因子数值, 比如pps, bps, new_link/s等, 函数指针
- CL_OPT_USER_ARG, //void *, 用户自定义字段
- CL_OPT_DESTROY_CALLBCAK_FUN, //释放资源callback, cl_destroy_cb_t
- CL_OPT_FACTOR_DECREASE_RATIO, //double, 超过res阈值后, 抑制factor的递减率
- CL_OPT_FACTOR_INCREASE_RATIO, //double, 抑制factor低于res阈值后, 缓慢恢复的增长率
+ CL_OPT_RES_TRIGGER_THRESHOLD,
+ CL_OPT_THREAD_COUNT,
+ CL_OPT_RES_SMOOTH_SCOPE,
+ CL_OPT_STAT_INTERVAL,
+ CL_OPT_OBSERVE_TIME,
+ CL_OPT_RES_GET_FUN,
+ CL_OPT_FACTOR_GET_FUN,
+ CL_OPT_USER_ARG,
+ CL_OPT_DESTROY_CALLBCAK_FUN,
+ CL_OPT_FACTOR_DECREASE_RATIO,
+ CL_OPT_FACTOR_INCREASE_RATIO,
/* get options */
- CL_OPT_GLOBAL_BYPASS_STATE, //int, 全局bypass状态
+ CL_OPT_GLOBAL_BYPASS_STATE,
}cpu_limit_opt;
cpu_limit_handle cpu_limit_create(void);
diff --git a/include/support/grule.h b/include/support/grule.h
index ca55909..032fc32 100644
--- a/include/support/grule.h
+++ b/include/support/grule.h
@@ -5,17 +5,13 @@
extern "C" {
#endif
-#include <stdint.h>
#include <netinet/ip.h>
typedef void * grule_hdl_t;
//typedef void * rule_item_t;
-/*
-* ע��:
-* ���е�ַ��ṹʹ��������(�����ģʽ)��������ʹ��������
-*/
+
#if __BYTE_ORDER != __LITTLE_ENDIAN
#error "machine is not little-endian"
diff --git a/include/support/marsio_for_view.h b/include/support/marsio_for_view.h
deleted file mode 100644
index 6905dd0..0000000
--- a/include/support/marsio_for_view.h
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * \brief MARSIO Userspace ZeroCopy Driver Version 4
- *
- * This is the user api header file of MARSIOv4 ZeroCopy Driver
- *
- * \author Qiuwen Lu<[email protected]>
- * Institute of Information Engineering, Chinese Academy of Sciences
- *
- * \date 2016-12-01
- */
-
-#pragma once
-
-typedef enum
-{
- /* 数据面线程数,没有缺省值 */
- MARSIO_OPT_THREAD_NUM,
- /* 数据面线程绑定掩码,没有缺省值
- * 设置该掩码后,数据面线程数选项将被忽略。
- */
- MARSIO_OPT_THREAD_MASK,
- /* 处理SIG信号,缺省值:类型:uint32_t,关闭(0)
- * 启用该选项后,将自动处理SIGINT、SIGTERM信号
- */
- MARSIO_OPT_EXIT_WHEN_ERR,
-
-} marsio_opt_type_t;
-
-typedef enum
-{
- /* 发送后不释放数据包,由应用自行释放数据包 */
- MARSIO_SEND_OPT_NO_FREE = 1 << 0,
- /* 发送时计算发包哈希值,用于分流 */
- MARSIO_SEND_OPT_REHASH = 1 << 1,
- /* 快速报文路径 */
- MARSIO_SEND_OPT_FAST = 1 << 2,
- /* 报文追踪标记 */
- MARSIO_SEND_OPT_TRACE = 1 << 3
-
-} marsio_opt_send_t;
-
-enum mr_sendpath_type
-{
- /* 去往特定虚设备的发包路径 */
- MR_SENDPATH_VDEV,
- /* 路由查表确定发包路径 */
- MR_SENDPATH_ROUTE_NORMAL,
- /* 特定设备路由查表确定发包路径 */
- MR_SENDPATH_ROUTE_SPEC_DEV,
- /* MAX标记 */
- MR_SENDPATH_MAX
-};
-
-enum mr_sendpath_option
-{
- /* 构建四层报文头 */
- MR_SENDPATH_OPT_BUILD_L4 = 0,
- /* 构建三层报文头 */
- MR_SENDPATH_OPT_BUILD_L3 = 1,
- /* 构建二层报文头 */
- MR_SENDPATH_OPT_BUILD_L2 = 2,
- /* 构建前Hook点回调 */
- MR_SENDPATH_OPT_HOOK_PREBUILD = 50,
- /* 构建后Hook点回调 */
- MR_SENDPATH_OPT_HOOK_POSTBUILD = 51,
-};
-
-enum mr_clone_options
-{
- /* 拷贝区域 */
- MR_BUFF_CLONE_DATA = 1 << 0,
- MR_BUFF_CLONE_BUFF = 1 << 1,
- MR_BUFF_CLONE_CTRLZONE = 1 << 2,
-};
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stddef.h>
-#include <netinet/in.h>
-
-#ifndef MARSIO_SOCKET_ID_ANY
-#define MARSIO_SOCKET_ID_ANY -1
-#endif
-
-#ifndef MARSIO_LCORE_ID_ANY
-#define MARSIO_LCORE_ID_ANY -1
-#endif
-
-typedef uint32_t device_id_t;
-typedef uint32_t port_id_t;
-typedef uint32_t queue_id_t;
-typedef uint32_t thread_id_t;
-typedef void marsio_buff_t;
-
-struct mr_sendpath;
-struct mr_instance;
-struct mr_vdev;
-
-struct mr_instance * marsio_create();
-struct mr_instance * marsio_current();
-
-typedef int(*fn_sendpath_hook_t)(struct mr_sendpath * sendpath,
- marsio_buff_t * mbuf[], unsigned int nr_mbuf, void * arg);
-
-int marsio_option_get(struct mr_instance * instance, int opt_type, void * out_opt, size_t out_opt_buffer);
-int marsio_option_set(struct mr_instance * instance, marsio_opt_type_t opt_type, void * opt, size_t sz_opt);
-int marsio_init(struct mr_instance * instance, const char * appsym);
-int marsio_thread_init(struct mr_instance * instance);
-int marsio_destory(struct mr_instance * instance);
-
-struct mr_vdev * marsio_open_device(struct mr_instance * instance,
- const char * devsym, unsigned int nr_rxstream, unsigned int nr_txstream);
-
-void marsio_close_device(struct mr_vdev * vdev);
-
-struct mr_vdev * marsio_device_lookup(struct mr_instance * instance, const char * devsym);
-
-int marsio_recv_burst(struct mr_vdev * vdev, queue_id_t qid, marsio_buff_t * mbufs[], int nr_mbufs);
-int marsio_recv_all_burst(struct mr_instance * instance, queue_id_t qid, marsio_buff_t * mbufs[], int nr_mbufs);
-int marsio_send_burst(struct mr_sendpath * sendpath, queue_id_t qid, marsio_buff_t * mbufs[], int nr_mbufs);
-int marsio_send_burst_with_options(struct mr_sendpath * sendpath, queue_id_t sid, marsio_buff_t * mbufs[],
- int nr_mbufs, uint16_t options);
-
-int marsio_udp_header_construct(marsio_buff_t * buff, uint16_t s_port, uint16_t d_port);
-int marsio_ipv4_header_construct(marsio_buff_t * buff, uint32_t s_ip, uint32_t d_ip, uint8_t proto);
-
-struct mr_sendpath * marsio_sendpath_create_by_droute(struct mr_vdev * dest_device, struct in_addr addr);
-struct mr_sendpath * marsio_sendpath_create_by_route(struct mr_instance * instance, struct in_addr addr);
-struct mr_sendpath * marsio_sendpath_create_by_vdev(struct mr_vdev * dest_device);
-
-struct mr_sendpath * marsio_sendpath_create(struct mr_instance * instance, int type, ...);
-int marsio_sendpath_option_set(struct mr_instance * instance, struct mr_sendpath * sendpath, int opt, ...);
-int marsio_sendpath_option_get(struct mr_instance * instance, struct mr_sendpath * sendpath, int opt, ...);
-void marsio_sendpath_destory(struct mr_sendpath * sendpath);
-
-//simply get control zone data ptr.
-void *marsio_buff_ctrlzone(marsio_buff_t *m, uint8_t id);
-
-//a safe way to read control zone data.
-void *marsio_buff_ctrlzone_data(marsio_buff_t *m, uint8_t id, uint8_t *size);
-
-//a safe way to set control zone data.
-void marsio_buff_ctrlzone_set(marsio_buff_t *m, uint8_t id, void* ptr_data, uint8_t size);
-
-void marsio_buff_reset(marsio_buff_t *m);
-
-marsio_buff_t *marsio_buff_getnext_seg(marsio_buff_t *m);
-marsio_buff_t *marsio_buff_getnext_pkt(marsio_buff_t *m);
-
-void marsio_buff_append_pkt(marsio_buff_t *head, marsio_buff_t *next);
-void marsio_buff_append_seg(marsio_buff_t *head, marsio_buff_t *next);
-void marsio_buff_chain_pkt(marsio_buff_t * pkt, marsio_buff_t * next);
-
-uint16_t marsio_buff_headroom(const marsio_buff_t *m);
-uint16_t marsio_buff_tailroom(const marsio_buff_t *m);
-
-marsio_buff_t *marsio_buff_getnext_seg(marsio_buff_t *m);
-marsio_buff_t *marsio_buff_getnext_pkt(marsio_buff_t *m);
-
-char *marsio_buff_mtod(marsio_buff_t *m);
-
-uint32_t marsio_buff_buflen(marsio_buff_t *m);
-
-uint32_t marsio_buff_datalen(marsio_buff_t *m);
-
-char *marsio_buff_prepend(marsio_buff_t *m, uint16_t len);
-
-char *marsio_buff_append(marsio_buff_t *m, uint16_t len);
-
-char *marsio_buff_adj(marsio_buff_t *m, uint16_t len);
-
-int marsio_buff_trim(marsio_buff_t *m, uint16_t len);
-
-uint16_t marsio_buff_headroom(const marsio_buff_t *m);
-
-uint16_t marsio_buff_tailroom(const marsio_buff_t *m);
-
-uint32_t marsio_get_pkt_type(marsio_buff_t *m);
-
-void marsio_pktmbuf_dump(FILE *f, const marsio_buff_t *m, unsigned dump_len);
-
-marsio_buff_t * marsio_buff_clone_deep(struct mr_instance * instance,
- marsio_buff_t * md, int socket_id, int thread_id);
-
-marsio_buff_t * marsio_buff_clone_with_options(struct mr_instance * instance,
- marsio_buff_t * md, int socket_id, int thread_id, uint16_t options);
-
-int marsio_buff_malloc_device(struct mr_vdev * vdev, marsio_buff_t *marsio_buff[],
- unsigned int nr_mbufs, int socket_id, int thread_id);
-
-int marsio_buff_malloc_global(struct mr_instance * instance, marsio_buff_t *marsio_buff[],
- unsigned int nr_mbufs, int socket_id, int thread_id);
-
-void marsio_buff_free(struct mr_instance * instance, marsio_buff_t *marsio_buff[],
- unsigned int nr_mbufs, int socket_id, int thread_id);
-
-int marsio_buff_is_ctrlbuf(marsio_buff_t * m);
-
-void marsio_buff_set_ctrlbuf(marsio_buff_t *m);
-
-
-uint64_t marsio_buff_get_timestamp(marsio_buff_t *m);
-void marsio_buff_set_timestamp(marsio_buff_t *m, uint64_t timestamp);
-int marsio_buff_get_timestamp_ex(marsio_buff_t * m, enum mr_timestamp_type ts_type, struct timespec * ts);
-
-void marsio_buff_set_rehash_index(marsio_buff_t *m, uint32_t hash);
-uint32_t marsio_buff_get_rehash_index(marsio_buff_t * m);
-
-void * marsio_shared_mem_alloc(struct mr_instance * instance, size_t len);
-void marsio_shared_mem_free(struct mr_instance * instance, void * mem);
-
-#ifdef __cplusplus
-}
-#endif
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, &section_save_ptr);
strncpy(section_string, pure_sesion_str, sizeof(section_string));
while(strtok_r(NULL, section_delim, &section_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{