diff options
| author | lijia <[email protected]> | 2021-10-09 16:11:38 +0800 |
|---|---|---|
| committer | lijia <[email protected]> | 2021-10-09 16:11:38 +0800 |
| commit | 2dda42342fad6818af3618a264a5775ffb2af17d (patch) | |
| tree | b51657d174804d3894b78d2ae9e4988256ded877 | |
| parent | 90ce47ab5c82067de4b7559bb69cb9aa7d5285e6 (diff) | |
TSG-7425, TSG-7978,
修复sapp退出时未释放的内存.
增加breakpad_destroy()接口;
| -rw-r--r-- | include/private/packet_io.h | 1 | ||||
| -rw-r--r-- | include/private/packet_io_internal.h | 1 | ||||
| -rw-r--r-- | src/packet_io/packet_io.c | 18 | ||||
| -rw-r--r-- | src/packet_io/packet_io_lib_load.c | 2 | ||||
| -rw-r--r-- | src/packet_io/packet_io_pcap.c | 62 | ||||
| -rw-r--r-- | src/plugin/src/plugin_business.c | 2 | ||||
| -rw-r--r-- | src/project/stream_bridge.c | 32 | ||||
| -rw-r--r-- | src/sapp_dev/sapp_global_val.c | 2 | ||||
| -rw-r--r-- | src/sapp_dev/sapp_plug.c | 3 | ||||
| -rw-r--r-- | test/test_app_sapp.c | 62 |
10 files changed, 159 insertions, 26 deletions
diff --git a/include/private/packet_io.h b/include/private/packet_io.h index 2762d03..2c2293f 100644 --- a/include/private/packet_io.h +++ b/include/private/packet_io.h @@ -113,6 +113,7 @@ typedef struct{ int (*dl_io_send_only_thread_init)(void); /* 2020-06-01 lijia add, ������д����Ķ��������߳�, ��Ҫ���ô˽ӿڰ��ض�CPU������ */
void (*dl_io_free_send_handle)(int thread_seq, void *handle);
void (*dl_io_destroy)(void);
+ void (*dl_io_stop)(void);
void (*dl_io_device_alias_free)(unsigned int target_id, char *device_args);
}dl_io_fun_list_t;
diff --git a/include/private/packet_io_internal.h b/include/private/packet_io_internal.h index 1fc9d55..2324393 100644 --- a/include/private/packet_io_internal.h +++ b/include/private/packet_io_internal.h @@ -244,6 +244,7 @@ int packet_io_under_ddos_should_bypass(int thread_index); void update_under_ddos_stream_state(struct streaminfo *pstream);
int packet_io_under_ddos_global_status(void);
void pcap_dl_io_destroy(void);
+void pcap_dl_io_stop(void);
void pcap_dl_io_device_alias_free(unsigned int target_id, char *dev_args);
diff --git a/src/packet_io/packet_io.c b/src/packet_io/packet_io.c index 48a7410..da0642d 100644 --- a/src/packet_io/packet_io.c +++ b/src/packet_io/packet_io.c @@ -1312,6 +1312,14 @@ void packet_io_clean_thread_context(int thread_seq) pptp_per_thread_exit(thread_seq); } +/* �˳�sapp֮ǰ, ��ֹͣ�������ݰ� */ +void packet_io_stop(void) +{ + if(dl_io_fun_list.dl_io_stop){ + dl_io_fun_list.dl_io_stop(); + } +} + void packet_io_lib_destroy(void) { if(dl_io_fun_list.dl_io_destroy){ @@ -1319,6 +1327,7 @@ void packet_io_lib_destroy(void) } } + int packet_io_init(int argc, char *argv[]) { int i, ret; @@ -1382,6 +1391,10 @@ int packet_io_init(int argc, char *argv[]) return 0; } +void sapp_breakpad_destroy(void) +{ + breakpad_destroy(sapp_global_val->individual_fixed.breakpad); +} void packet_io_exit(void) { @@ -1424,7 +1437,10 @@ void packet_io_exit(void) global_stream_destroy(); sapp_dup_pkt_destroy(); - + + sapp_breakpad_destroy(); + + /****** ע��:�ͷ�ȫ�ֱ���Ҫ�������һ��!! ******/ sapp_gval_destroy(); return; diff --git a/src/packet_io/packet_io_lib_load.c b/src/packet_io/packet_io_lib_load.c index b589199..145b96c 100644 --- a/src/packet_io/packet_io_lib_load.c +++ b/src/packet_io/packet_io_lib_load.c @@ -95,6 +95,7 @@ static int packet_io_lib_load_by_mode(int cap_mode, const char *full_lib_path) dl_io_fun_list.dl_io_free_send_handle = (void (*dl_io_free_send_handle)(int thread_seq, void *handle))packet_io_symbol_load_by_mode(io_lib_handle, cap_mode, "dl_io_free_send_handle"); dl_io_fun_list.dl_io_destroy = (void (*dl_io_destroy)(void))packet_io_symbol_load_by_mode(io_lib_handle, cap_mode, "dl_io_destroy"); + dl_io_fun_list.dl_io_stop = (void (*dl_io_stop)(void))packet_io_symbol_load_by_mode(io_lib_handle, cap_mode, "dl_io_stop"); dl_io_fun_list.dl_io_device_alias_free = (void (*)(unsigned int target_id, char *device_args))packet_io_symbol_load_by_mode(io_lib_handle, cap_mode, "dl_io_device_alias_free"); return 0; } @@ -129,6 +130,7 @@ static int packet_io_lib_load_by_mode(int cap_mode, const char *no_use) dl_io_fun_list_static_link[cap_mode].dl_io_send_only_thread_init = NULL; dl_io_fun_list_static_link[cap_mode].dl_io_free_send_handle = pcap_dl_io_free_send_handle; dl_io_fun_list_static_link[cap_mode].dl_io_destroy = pcap_dl_io_destroy; + dl_io_fun_list_static_link[cap_mode].dl_io_stop = pcap_dl_io_stop; dl_io_fun_list_static_link[cap_mode].dl_io_device_alias_free = pcap_dl_io_device_alias_free; } #endif diff --git a/src/packet_io/packet_io_pcap.c b/src/packet_io/packet_io_pcap.c index b9f7e7a..6e1cb32 100644 --- a/src/packet_io/packet_io_pcap.c +++ b/src/packet_io/packet_io_pcap.c @@ -35,6 +35,7 @@ typedef enum{ static char g_pcap_up_dev_name[DEV_NAME_STR_LEN] = "dumpfile"; /* if in parallel mode, use this arg */
static char g_pcap_down_dev_name[DEV_NAME_STR_LEN];
static char g_pcap_cap_filter[CAP_FILTER_STR_LEN];
+static struct bpf_program g_pcap_bpf_filter_bin;
static int g_pcap_buf_queue_num = 10000;
static int g_pcap_cap_mode = CAP_MODEL_PCAP_ONLINE;
static int g_pcap_topology_mode = NET_CONN_PARALLEL;
@@ -56,7 +57,7 @@ static int pcap_device_down_mtu = 1500; static pcap_distmode_t g_pcap_distmode = PCAP_DISTMODE_OUTER_TUPLE2;
static pthread_t g_pcap_io_pid_up, g_pcap_io_pid_down;
-
+static volatile int g_pcap_io_stop_flag_up, g_pcap_io_stop_flag_down;
extern sapp_global_t *sapp_global_val;
extern int g_PollingFunNum;
extern int g_use_MESA_sleep_sw;
@@ -724,20 +725,18 @@ send_again: static int pcap_set_filter(pcap_t *handle, const char *filter_str)
{
- struct bpf_program bpf_filter;
-
if((NULL == handle) || (NULL == filter_str) || ('\0' == *filter_str)){
return 0;
}
- if(pcap_compile(handle, &bpf_filter, (char *)filter_str, 1, 0) < 0)
- {
+ if(pcap_compile(handle, &g_pcap_bpf_filter_bin, (char *)filter_str, 1, 0) < 0){
printf("Compile pcap filter '%s' error:%s\n", filter_str, pcap_geterr(handle));
return -1;
}
- if(pcap_setfilter(handle, &bpf_filter) < 0){
+ if(pcap_setfilter(handle, &g_pcap_bpf_filter_bin) < 0){
printf("Set pcap filter '%s' error:%s\n", filter_str, pcap_geterr(handle));
+ pcap_freecode(&g_pcap_bpf_filter_bin);
return -1;
}
@@ -787,10 +786,20 @@ static void pcap_clear_pkt_queue_left(int thread_index) int ret;
pkt_queue_t pkt_queue_node = {};
long recv_len;
+
+ while(0 == g_pcap_io_stop_flag_up){
+ sapp_usleep(1);
+ }
+
+ if(NET_CONN_SERIAL_2CARD == g_pcap_topology_mode){ /* ˫��������ģʽ */
+ while(0 == g_pcap_io_stop_flag_down){
+ sapp_usleep(1);
+ }
+ }
while(MESA_lqueue_get_count(work_thread_pool[thread_index].pkt_queue)){
- pthread_mutex_lock(&work_thread_pool[thread_index].mutex);
recv_len = sizeof(pkt_queue_t);
+ pthread_mutex_lock(&work_thread_pool[thread_index].mutex);
ret = MESA_lqueue_get_head(work_thread_pool[thread_index].pkt_queue, &pkt_queue_node, &recv_len);
pthread_mutex_unlock(&work_thread_pool[thread_index].mutex);
if(ret < 0){
@@ -826,7 +835,7 @@ static void *__pcap_work_thread(void *arg) sapp_global_val->individual_fixed.cpu_bind_core_id_per_thread[thread_num]);
while(sapp_get_current_state() < SAPP_STATE_PROCESSING){
- sapp_usleep(1000);
+ sapp_usleep(1);
}
/* for perf optimize
@@ -902,6 +911,9 @@ static void *__pcap_work_thread(void *arg) PCAP_FREE((void *)(pkt_queue_node.raw_pkt.__lib_raw_pkt_data));
}
+ /* pcapʹ���첽ģʽ, ��������п��ܻ���δ���������ݰ� */
+ pcap_clear_pkt_queue_left(thread_num);
+
libsapp_destroy_env_per_thread(thread_num);
exit:
@@ -1367,6 +1379,7 @@ static void *pcap_io_thread(void *arg) pcap_t *handle;
int pcap_ret;
char *no_use;
+ volatile int *stop_flag;
#if(__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ >= 480) /* �汾�ж�, �ܶ��ϵͳ������ */
#ifdef _GNU_SOURCE
@@ -1381,8 +1394,10 @@ static void *pcap_io_thread(void *arg) if(0 == (DIR_ROUTE_DOWN & route_dir)){
handle = pcap_up_handle;
+ stop_flag = &g_pcap_io_stop_flag_up;
}else{
handle = pcap_down_handle;
+ stop_flag = &g_pcap_io_stop_flag_down;
}
while(sapp_get_current_state() < SAPP_STATE_PROCESSING){
@@ -1411,6 +1426,8 @@ static void *pcap_io_thread(void *arg) }
}
+ *stop_flag = 1;
+ sapp_usleep(10000);
if(g_pcap_exit_cb_fun){
(*g_pcap_exit_cb_fun)();
}
@@ -1555,10 +1572,8 @@ void pcap_dl_io_run(void) return;
}
-void pcap_dl_io_destroy(void)
+void pcap_dl_io_stop(void)
{
- int i;
-
if(g_pcap_io_pid_up != 0){
pcap_breakloop(pcap_up_handle);
pthread_join(g_pcap_io_pid_up, NULL);
@@ -1568,6 +1583,12 @@ void pcap_dl_io_destroy(void) pcap_breakloop(pcap_down_handle);
pthread_join(g_pcap_io_pid_down, NULL);
}
+}
+
+
+void pcap_dl_io_destroy(void)
+{
+ int i;
if(pcap_up_handle){
pcap_close(pcap_up_handle);
@@ -1579,11 +1600,10 @@ void pcap_dl_io_destroy(void) }
for(i = 0; i < g_pcap_work_thread_num; i++){
- //pcap work threads �� wait_for_all_io_threads() �����л����߳���Դ.
- //pthread_join(work_thread_pool[i].work_tid, NULL);
-
- /* �����п��ܻ���δ���������� */
- pcap_clear_pkt_queue_left(i);
+ while(MESA_lqueue_get_count(work_thread_pool[i].pkt_queue)){
+ sapp_usleep(1);
+ }
+
MESA_lqueue_destroy(work_thread_pool[i].pkt_queue, NULL, NULL);
pthread_cond_destroy(&work_thread_pool[i].cond);
@@ -1591,9 +1611,17 @@ void pcap_dl_io_destroy(void) close(work_thread_pool[i].sd_raw_eth);
work_thread_pool[i].sd_raw_eth = -1;
}
-}
+ if(g_pcap_cap_filter[0] != '\0'){
+ pcap_freecode(&g_pcap_bpf_filter_bin);
+ memset(g_pcap_cap_filter, 0, sizeof(g_pcap_cap_filter));
+ }
+ memset(g_pcap_up_dev_name, 0, sizeof(g_pcap_up_dev_name));
+ memset(g_pcap_down_dev_name, 0, sizeof(g_pcap_down_dev_name));
+ g_pcap_io_stop_flag_up = 0;
+ g_pcap_io_stop_flag_down = 0;
+}
#ifdef __cplusplus
}
diff --git a/src/plugin/src/plugin_business.c b/src/plugin/src/plugin_business.c index fcf10a0..325b09d 100644 --- a/src/plugin/src/plugin_business.c +++ b/src/plugin/src/plugin_business.c @@ -44,7 +44,7 @@ void destroy_pluginfo_elem_bus(stBusinessPlugInfo* plug_info) {
if(plug_info->plugname != NULL)
{
- free(plug_info->plugname);
+ SAPP_GLOBAL_FREE(plug_info->plugname);
plug_info->plugname = NULL;
}
diff --git a/src/project/stream_bridge.c b/src/project/stream_bridge.c index d824539..52ff294 100644 --- a/src/project/stream_bridge.c +++ b/src/project/stream_bridge.c @@ -31,6 +31,13 @@ static stream_bridge_manage_t g_stream_bridge_manage[STREAM_BRIDGE_MAX_NUM]; static MESA_htable_handle g_stream_bridge_name2id_htable; +static void _stream_bridge_name2id_htable_free_cb(void *data) +{ + if(data){ + sapp_mem_free(SAPP_MEM_FIX_GLOBAL_STREAM, -1, data); + } +} + static MESA_htable_handle stream_bridge_name2id_htable_create(void) { MESA_htable_handle htable; @@ -58,7 +65,9 @@ static MESA_htable_handle stream_bridge_name2id_htable_create(void) MESA_htable_set_opt(htable, MHO_SCREEN_PRINT_CTRL, &opt_int, sizeof(int)); opt_int = HASH_ELIMINATE_ALGO_FIFO; - MESA_htable_set_opt(htable, MHO_ELIMIMINATE_TYPE, &opt_int, sizeof(int)); + MESA_htable_set_opt(htable, MHO_ELIMIMINATE_TYPE, &opt_int, sizeof(int)); + + MESA_htable_set_opt(htable, MHO_CBFUN_DATA_FREE, _stream_bridge_name2id_htable_free_cb, sizeof(void *)); ret = MESA_htable_mature(htable); if(ret < 0){ @@ -85,7 +94,7 @@ static int stream_bridege_create_new_bridge(const char *bridge_name) { int *bridge_id, ret; - bridge_id = (int *)malloc(sizeof(int)); + bridge_id = (int *)sapp_mem_calloc(SAPP_MEM_FIX_GLOBAL_STREAM, -1, sizeof(int)); *bridge_id = g_stream_bridge_actual_num; @@ -186,7 +195,7 @@ int stream_bridge_register_data_sync_cb(int bridge_id, stream_bridge_sync_cb_t * return -1; } - new_list_node = (struct MESA_list *)malloc(sizeof(struct MESA_list)); + new_list_node = (struct MESA_list *)sapp_mem_calloc(SAPP_MEM_FIX_GLOBAL_STREAM, -1, sizeof(struct MESA_list)); new_list_node->quiddity = cb_fun; MESA_list_add(&g_stream_bridge_manage[bridge_id].sync_callback_fun_list, new_list_node); @@ -289,9 +298,22 @@ int stream_bridge_init(void) void stream_bridge_destroy(void) { - g_stream_bridge_actual_num = 0; - memset(g_stream_bridge_manage, 0, sizeof(g_stream_bridge_manage)); + int bridge_id; + MESA_list_t *list_node, *next_node; MESA_htable_destroy(g_stream_bridge_name2id_htable, NULL); + + for(bridge_id = 0; bridge_id < g_stream_bridge_actual_num; bridge_id++){ + list_node = g_stream_bridge_manage[bridge_id].sync_callback_fun_list.nextele; + while(0 == MESA_list_is_empty(&g_stream_bridge_manage[bridge_id].sync_callback_fun_list)){ + next_node = list_node->nextele; + MESA_list_del(&g_stream_bridge_manage[bridge_id].sync_callback_fun_list, list_node); + sapp_mem_free(SAPP_MEM_FIX_GLOBAL_STREAM, -1, (void *)list_node); + list_node = next_node; + } + } + + g_stream_bridge_actual_num = 0; + memset(g_stream_bridge_manage, 0, sizeof(g_stream_bridge_manage)); g_stream_bridge_name2id_htable = NULL; } diff --git a/src/sapp_dev/sapp_global_val.c b/src/sapp_dev/sapp_global_val.c index 6605f07..4a23ec4 100644 --- a/src/sapp_dev/sapp_global_val.c +++ b/src/sapp_dev/sapp_global_val.c @@ -312,6 +312,8 @@ void sapp_gval_destroy(void) SAPP_GLOBAL_FREE(pdata->data_memory_stat_log_relative); SAPP_GLOBAL_FREE(pdata->data_memory_stat_log_absolute); + SAPP_GLOBAL_FREE(sapp_global_val->config.packet_io.input_bpf_filter); + SAPP_GLOBAL_FREE(sapp_global_val->config.library_file_path.libmarsio_file_path); SAPP_GLOBAL_FREE(sapp_global_val->config.tools.pkt_dump.bpf_filter); SAPP_GLOBAL_FREE(sapp_global_val->config.tools.pkt_dump.storge_path); diff --git a/src/sapp_dev/sapp_plug.c b/src/sapp_dev/sapp_plug.c index 4e3d8f1..87a577d 100644 --- a/src/sapp_dev/sapp_plug.c +++ b/src/sapp_dev/sapp_plug.c @@ -218,9 +218,8 @@ void libsapp_destroy_env(void) } sapp_set_current_state(SAPP_STATE_READY_TO_EXIT); - + packet_io_stop(); wait_for_all_io_threads(); - packet_io_exit(); MESA_ATOMIC_SET(g_destory_env_done, 0x7FFFF); diff --git a/test/test_app_sapp.c b/test/test_app_sapp.c index 71126b2..a9f40f0 100644 --- a/test/test_app_sapp.c +++ b/test/test_app_sapp.c @@ -22,6 +22,7 @@ typedef struct{ char str_value2[NAME_MAX]; int test_project_id; + int test_bridge_id; }test_app_val_t; /* ����һЩȫ�ֱ���, �и��ֲ�ͬ������, ��������������ݲ���, @@ -2661,6 +2662,57 @@ char test_get_rawpkt_opt_from_streaminfo(struct streaminfo *f_stream,unsigned ch return APP_STATE_GIVEME; } + +static void __stream_bridge_free_cb(const struct streaminfo *stream, int bridge_id, void *data) +{ + free(data); +} + +char stream_bridge_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq,const void *a_packet) +{ + int bridge_id; + + bridge_id = stream_bridge_build("test_bridge", "r"); + if(bridge_id < 0){ + printf("##### stream_bridge_tcp_entry(): stream_bridge_build error!\n"); + return APP_STATE_DROPME; + } + + if(OP_STATE_CLOSE == pstream->opstate){ + /* tcp�Ƚ���, �������� */ + void *data = calloc(1, 100); + strncpy(data, "abcdefg1234567", 100); + stream_bridge_async_data_put(pstream, bridge_id, data); + printf("##### tcp entry bridge put data:%s\n", data); + } + + return APP_STATE_GIVEME; +} + +char stream_bridge_tcpall_entry(struct streaminfo *pstream,void **pme, int thread_seq,const void *a_packet) +{ + int bridge_id; + + bridge_id = stream_bridge_build("test_bridge", "r"); + if(bridge_id < 0){ + printf("##### stream_bridge_tcpall_entry(): stream_bridge_build error!\n"); + return APP_STATE_DROPME; + } + + if(OP_STATE_CLOSE == pstream->pktstate){ + char *data; + data = (char *)stream_bridge_async_data_get(pstream, bridge_id); + if(data){ + printf("tcpall entry bridge get:%s\n", data); + }else{ + printf("tcpall entry bridge get data error\n"); + } + } + + return APP_STATE_GIVEME; +} + + char UDP_ENTRY(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a_packet) { //test_project_add(a_tcp,pme,thread_seq,a_packet); @@ -3365,6 +3417,16 @@ int CHAR_INIT() /* �������ڳ�ʼ��ʱ����ע��project */ g_test_app_val.test_project_id = project_producer_register("test_project", "struct", __fake_project_free_cb); + if(g_test_app_val.test_project_id < 0){ + printf("##### project_producer_register error!\n"); + return -1; + } + g_test_app_val.test_bridge_id = stream_bridge_build("test_bridge", "w"); + if(g_test_app_val.test_bridge_id < 0){ + printf("##### stream_bridge_build error!\n"); + return -1; + } + stream_bridge_register_data_free_cb(g_test_app_val.test_bridge_id, __stream_bridge_free_cb); return 1; } |
