diff options
| author | lijia <[email protected]> | 2021-09-15 17:54:41 +0800 |
|---|---|---|
| committer | lijia <[email protected]> | 2021-09-15 17:54:41 +0800 |
| commit | a2c7c57d258c6af4648021f24377f305631a769c (patch) | |
| tree | c92e1db05b7ae8e4617c704bcf138fdb68cfb92b | |
| parent | 4da540621d79e0779b99181549c1c4d2b30f73d5 (diff) | |
TSG-7787, 修复under ddos情况下, 没有设置stream->pdetail指针, 导致的coredump BUG.v4.2.53
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/config/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/dealpkt/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/dealpkt/deal_tcp.c | 9 | ||||
| -rw-r--r-- | src/entry/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/plugin/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/project/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/sapp_dev/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/support/MESA_sleep/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/support/MESA_socket_wrap/src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/support/cpu_limit/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/support/dpdk_rte_hash/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/support/md5/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/support/tomlc99_wrap/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/timer/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | test/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | test/Makefile | 7 | ||||
| -rw-r--r-- | test/test_app_sapp.c | 23 | ||||
| -rw-r--r-- | vendor/CMakeLists.txt | 2 |
20 files changed, 41 insertions, 26 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 05709d9..9cc10af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,6 +161,7 @@ add_definitions(${HEADER_CHECK_DEFINITIONS} set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${HEADER_CHECK_DEFINITIONS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HEADER_CHECK_DEFINITIONS}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") #for sapp_module_test option(SAPP_V4 "test for sapp v4.0" TRUE) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 2224b37..d9b443e 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -14,5 +14,6 @@ endif() add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) add_definitions(-DPLATFORM_NSDPF_PAPP=1) +add_definitions(-fPIC) add_library(common linux_kernel_jhash.c net_common.c stream_addr_inet.c sapp_log.c) diff --git a/src/config/CMakeLists.txt b/src/config/CMakeLists.txt index ecada86..80dad24 100644 --- a/src/config/CMakeLists.txt +++ b/src/config/CMakeLists.txt @@ -14,6 +14,7 @@ endif() add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) add_definitions(-DPLATFORM_NSDPF_PAPP=1) +add_definitions(-fPIC) #execute_process(COMMAND echo "" > sapp.toml.hex.array.c ${CMAKE_SOURCE_DIR}/src/config) execute_process(COMMAND xxd -i ${CMAKE_SOURCE_DIR}/bin/etc/sapp.toml ${CMAKE_SOURCE_DIR}/src/config/sapp.toml.hex.array.c diff --git a/src/dealpkt/CMakeLists.txt b/src/dealpkt/CMakeLists.txt index 59142c7..9d15fb3 100644 --- a/src/dealpkt/CMakeLists.txt +++ b/src/dealpkt/CMakeLists.txt @@ -14,6 +14,7 @@ endif() add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) add_definitions(-DPLATFORM_NSDPF_PAPP=1) +add_definitions(-fPIC) add_library(dealpkt STATIC callapp.c deal_ipv4.c deal_mpls.c deal_tcp.c hash.c plug_support.c deal_arp.c deal_ipv6.c deal_ppp.c deal_teredo.c ip_reassembly.c diff --git a/src/dealpkt/deal_tcp.c b/src/dealpkt/deal_tcp.c index d84c3ed..153e30c 100644 --- a/src/dealpkt/deal_tcp.c +++ b/src/dealpkt/deal_tcp.c @@ -852,6 +852,7 @@ static struct streamindex *tcp_add_new_stream_bydata(struct streamindex *pindex, pdetail_pr=(struct tcpdetail_private *)dictator_malloc(threadnum,sizeof(struct tcpdetail_private)); pdetail=&pdetail_pr->tcpdetail_public; memset(pdetail_pr,0,sizeof(struct tcpdetail_private)); + pstream->pdetail=(void *)pdetail_pr; #if USE_RBTREE_INSTEAD_LIST if(1 == pstream_pr->layer_dir){ @@ -2700,11 +2701,12 @@ static int deal_tcp_stream(struct streamindex *pindex, const void *this_iphdr, s local_sys_stat->length[SAPP_STAT_TCP_BYPASS_BYTES]+= tcplen; cycle_pkt_dump_by_classify(pstream->threadnum, raw_pkt, PKT_CLASSIFY_BYPASS); sapp_runtime_log(RLOG_LV_DEBUG, "TCP stream:%s under ddos bypass!", printaddr(&pstream->addr, pstream->threadnum)); + ret = PASS; }else{ ret=tcp_processallpkt(pstream,this_iphdr,this_tcphdr,tcplen,raw_pkt); } } - return ret; + return ret; } // else if(tcplen>0) else @@ -2747,13 +2749,14 @@ static int deal_tcp_stream(struct streamindex *pindex, const void *this_iphdr, s local_sys_stat->count[SAPP_STAT_TCP_BYPASS_PKTS]++; local_sys_stat->length[SAPP_STAT_TCP_BYPASS_BYTES]+= tcplen; cycle_pkt_dump_by_classify(pstream->threadnum, raw_pkt, PKT_CLASSIFY_BYPASS); - sapp_runtime_log(RLOG_LV_DEBUG, "TCP stream:%s under ddos bypass!", printaddr(&pstream->addr, pstream->threadnum)); + sapp_runtime_log(RLOG_LV_DEBUG, "TCP stream:%s under ddos bypass!", printaddr(&pstream->addr, pstream->threadnum)); + ret = PASS; }else{ ret = tcp_process_newstreambydata(pindex_tcp,this_iphdr, this_tcphdr,tcplen,raw_pkt); - return ret; } } } + return ret; } if(!pindex_tcp) diff --git a/src/entry/CMakeLists.txt b/src/entry/CMakeLists.txt index 041d238..0864c43 100644 --- a/src/entry/CMakeLists.txt +++ b/src/entry/CMakeLists.txt @@ -7,6 +7,7 @@ include_directories(${CMAKE_SOURCE_DIR}/include/support) include_directories(${MESA_SDK_PREFIX}/include) include_directories(${MESA_SDK_PREFIX}/include/MESA) +add_definitions(-fPIC) LINK_DIRECTORIES(/opt/MESA/lib) LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/lib) diff --git a/src/plugin/CMakeLists.txt b/src/plugin/CMakeLists.txt index cb8300b..32ad244 100644 --- a/src/plugin/CMakeLists.txt +++ b/src/plugin/CMakeLists.txt @@ -8,5 +8,7 @@ include_directories(${CMAKE_SOURCE_DIR}/include/support) include_directories(${MESA_SDK_PREFIX}/include) include_directories(${MESA_SDK_PREFIX}/include/MESA) +add_definitions(-fPIC) + add_library(plugctrl STATIC src/plugin_proc.c src/plugin.c src/plugin_platform.c - src/plugin_protocol.c src/plugin_business.c src/plugin_manage.c)
\ No newline at end of file + src/plugin_protocol.c src/plugin_business.c src/plugin_manage.c) diff --git a/src/project/CMakeLists.txt b/src/project/CMakeLists.txt index dfeceab..892dee6 100644 --- a/src/project/CMakeLists.txt +++ b/src/project/CMakeLists.txt @@ -9,5 +9,6 @@ include_directories(${CMAKE_SOURCE_DIR}/include/support) include_directories(${MESA_SDK_PREFIX}/include) include_directories(${MESA_SDK_PREFIX}/include/MESA) +add_definitions(-fPIC) add_library(project STATIC project_requirement.c raw_ip_frag_list.c stream_bridge.c ) diff --git a/src/sapp_dev/CMakeLists.txt b/src/sapp_dev/CMakeLists.txt index 0b36d69..3c0dcbc 100644 --- a/src/sapp_dev/CMakeLists.txt +++ b/src/sapp_dev/CMakeLists.txt @@ -7,7 +7,7 @@ include_directories(${CMAKE_SOURCE_DIR}/include/support) include_directories(${MESA_SDK_PREFIX}/include) include_directories(${MESA_SDK_PREFIX}/include/MESA) -add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) +add_definitions(-fPIC -D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) add_library(sapp_dev STATIC sapp_plug.c sapp_global_val.c sapp_init.c) diff --git a/src/support/MESA_sleep/CMakeLists.txt b/src/support/MESA_sleep/CMakeLists.txt index 09ba5de..45e5205 100644 --- a/src/support/MESA_sleep/CMakeLists.txt +++ b/src/support/MESA_sleep/CMakeLists.txt @@ -7,5 +7,6 @@ cmake_minimum_required(VERSION 2.8) #include_directories(${CMAKE_SOURCE_DIR}/dealpkt) add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) +add_definitions(-fPIC) add_library(MESA_sleep STATIC mesa_sleep_nowatchBGT.c) diff --git a/src/support/MESA_socket_wrap/src/CMakeLists.txt b/src/support/MESA_socket_wrap/src/CMakeLists.txt index 2c95be9..c57f548 100644 --- a/src/support/MESA_socket_wrap/src/CMakeLists.txt +++ b/src/support/MESA_socket_wrap/src/CMakeLists.txt @@ -6,6 +6,6 @@ cmake_minimum_required(VERSION 2.8) #include_directories(${CMAKE_SOURCE_DIR}/include/support) include_directories(${CMAKE_SOURCE_DIR}/include) -add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) +add_definitions(-fPIC -D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) add_library(MESA_socket_wrap STATIC MESA_socket_wrap.c) diff --git a/src/support/cpu_limit/CMakeLists.txt b/src/support/cpu_limit/CMakeLists.txt index f81a31b..3509719 100644 --- a/src/support/cpu_limit/CMakeLists.txt +++ b/src/support/cpu_limit/CMakeLists.txt @@ -7,6 +7,6 @@ include_directories(${CMAKE_SOURCE_DIR}/include/support) include_directories(/opt/MESA/include/MESA) include_directories(/opt/MESA/include/) -add_definitions(-D_BSD_SOURCE -D_GNU_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) +add_definitions(-D_BSD_SOURCE -D_GNU_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H -fPIC) add_library(cpu_limit STATIC cpu_limit.c) diff --git a/src/support/dpdk_rte_hash/CMakeLists.txt b/src/support/dpdk_rte_hash/CMakeLists.txt index 3a38df0..e58052d 100644 --- a/src/support/dpdk_rte_hash/CMakeLists.txt +++ b/src/support/dpdk_rte_hash/CMakeLists.txt @@ -10,6 +10,6 @@ include_directories(${CMAKE_SOURCE_DIR}/src/support/dpdk_rte_hash/generic) #set(CMAKE_C_FLAGS "-DLINK_MODE_DYNAMIC=1") set(CMAKE_C_FLAGS "-std=c99") -add_definitions(-D_BSD_SOURCE -D_GNU_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) +add_definitions(-fPIC -D_BSD_SOURCE -D_GNU_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) add_library(dpdk_ip_hash STATIC dpdk_hash_crc.c) diff --git a/src/support/md5/CMakeLists.txt b/src/support/md5/CMakeLists.txt index abd3aa7..a866e7e 100644 --- a/src/support/md5/CMakeLists.txt +++ b/src/support/md5/CMakeLists.txt @@ -6,6 +6,6 @@ cmake_minimum_required(VERSION 2.8) #include_directories(${CMAKE_SOURCE_DIR}/include/support) #include_directories(${CMAKE_SOURCE_DIR}/dealpkt) -add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) +add_definitions(-fPIC -D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) add_library(md5 STATIC md5.c) diff --git a/src/support/tomlc99_wrap/CMakeLists.txt b/src/support/tomlc99_wrap/CMakeLists.txt index 4c26d80..21cdd5b 100644 --- a/src/support/tomlc99_wrap/CMakeLists.txt +++ b/src/support/tomlc99_wrap/CMakeLists.txt @@ -7,6 +7,6 @@ include_directories(${CMAKE_SOURCE_DIR}/include/public) #set(CMAKE_C_FLAGS "-DLINK_MODE_DYNAMIC=1") set(CMAKE_C_FLAGS "-std=c99") -add_definitions(-D_BSD_SOURCE -D_GNU_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) +add_definitions(-fPIC -D_BSD_SOURCE -D_GNU_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) add_library(tomlc99_wrap STATIC toml.c tomlc99_wrap.c) diff --git a/src/timer/CMakeLists.txt b/src/timer/CMakeLists.txt index c7e5ba9..8b1261c 100644 --- a/src/timer/CMakeLists.txt +++ b/src/timer/CMakeLists.txt @@ -14,5 +14,6 @@ endif() add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) add_definitions(-DPLATFORM_NSDPF_PAPP=1) +add_definitions(-fPIC) add_library(timer sapp_timer.c) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c24be0d..57457ea 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -46,7 +46,7 @@ add_custom_command(OUTPUT libtest_phony.a COMMAND ar -x ${CMAKE_BINARY_DIR}/vendor/libevent/lib/libevent.a COMMAND ar -rc libsapp_devel.a *.o - #COMMAND cp libsapp_devel.a /opt/MESA/lib/ + #COMMAND g++ -fPIC -shared -o libsapp_devel.so *.o ) add_library(test_app_sapp SHARED test_app_sapp.c) diff --git a/test/Makefile b/test/Makefile index 56eb332..c21b723 100644 --- a/test/Makefile +++ b/test/Makefile @@ -14,7 +14,7 @@ TARGET += test_sendpacket_performance.so #TARGET += test_anti_flood_hijack #TARGET += sapp_so_run -TARGET += test_sapp_dev +TARGET += test_sapp_dev_static test_sapp_dev_dynamic INCS = @@ -58,9 +58,12 @@ inline_device_measurement.so:inline_device_measurement.c sapp_so_run:test_sapp_so.o $(CC) -o $@ -g $(INCS) $(CFLAGS) $^ -lpcap -ldl -test_sapp_dev:test_sapp_dev.c +test_sapp_dev_static:test_sapp_dev.c gcc -o $@ $^ ../build/src/sapp_dev/libsapp_dev.a -I/opt/MESA/include/MESA -I/opt/MESA/include/MESA/stream_inc -L/opt/MESA/lib -lpcap -lpthread -ldl -lMESA_htable -lMESA_prof_load -lMESA_handle_logger -lMESA_field_stat2 +test_sapp_dev_dynamic:test_sapp_dev.c + gcc -o $@ $^ -lsapp_devel -I/opt/MESA/include/MESA -I/opt/MESA/include/MESA/stream_inc -L/opt/MESA/lib -lpcap -lpthread -ldl -lMESA_htable -lMESA_prof_load -lMESA_handle_logger -lMESA_field_stat2 -lsystemd -lMESA_jump_layer + .c.o: $(CC) -c -o $@ $(CFLAGS) -I. $(INCS) $< diff --git a/test/test_app_sapp.c b/test/test_app_sapp.c index 5ed08cc..71126b2 100644 --- a/test/test_app_sapp.c +++ b/test/test_app_sapp.c @@ -20,6 +20,8 @@ typedef struct{ int ivalue2; char str_value1[NAME_MAX]; char str_value2[NAME_MAX]; + + int test_project_id; }test_app_val_t; /* ����һЩȫ�ֱ���, �и��ֲ�ͬ������, ��������������ݲ���, @@ -2199,19 +2201,8 @@ char test_project_add(struct streaminfo *pstream,void **pme, int thread_seq,cons static int __init_flag = 0; static int project_id; char *pro_value = (char *)"test project!"; - - if(0 == __init_flag){ - project_id = project_producer_register("test_project", PROJECT_VAL_TYPE_STRUCT, __test_project_cb); - if(project_id < 0){ - printf("test_project_add error, 'test_project' is not enable!\n"); - exit(0); - } - __init_flag = 1; - } - if(OP_STATE_PENDING == pstream->opstate){ - project_req_add_struct(pstream, project_id, pro_value); - } + project_req_add_struct(pstream, g_test_app_val.test_project_id, pro_value); return APP_STATE_GIVEME; } @@ -3363,10 +3354,18 @@ void CHAR_CONFIG_INIT(void) } +static void __fake_project_free_cb(int thread_seq, void *project_req_value) +{ + ; +} + int CHAR_INIT() { CHAR_CONFIG_INIT(); + /* �������ڳ�ʼ��ʱ����ע��project */ + g_test_app_val.test_project_id = project_producer_register("test_project", "struct", __fake_project_free_cb); + return 1; } diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index 04e02ff..4b5f8a2 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -18,7 +18,7 @@ include(ExternalProject) ExternalProject_Add(libevent PREFIX libevent URL ${CMAKE_CURRENT_SOURCE_DIR}/libevent-2.1.10-stable.tar.gz URL_MD5 999caf86f52943af2363bc8077f00167 - CONFIGURE_COMMAND ./configure --prefix=<INSTALL_DIR> --disable-shared --disable-samples --disable-openssl + CONFIGURE_COMMAND ./configure --prefix=<INSTALL_DIR> --enable-shared CFLAGS=-fPIC --disable-samples --disable-openssl BUILD_COMMAND make LDFLAGS="-ldl" BUILD_IN_SOURCE 1) |
